From 7dd9b5f242317561986b654c124c7116bd43802b Mon Sep 17 00:00:00 2001 From: Luciano Ciccariello Date: Mon, 25 Jan 2021 18:04:27 +0100 Subject: [PATCH 1/3] Add script to automatically format code before merging PRs --- .github/workflows/format-code.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/format-code.yml diff --git a/.github/workflows/format-code.yml b/.github/workflows/format-code.yml new file mode 100644 index 000000000..d767e707b --- /dev/null +++ b/.github/workflows/format-code.yml @@ -0,0 +1,29 @@ +name: Format code +on: + push: + pull_request: +jobs: + format-code: + runs-on: ubuntu-latest + container: + image: mcr.microsoft.com/dotnet/sdk:latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Download formatting tool + run: dotnet tool install -g dotnet-format + - name: Format source code + run: | + export PATH="$PATH:/github/home/.dotnet/tools" + dotnet format + - name: Check if files have been modified + id: git-check + run: echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi) + - name: Push changes + if: steps.git-check.outputs.modified == 'true' + run: | + git config --global user.name 'Formatting bot' + git config --global user.email 'xeeynamo@users.noreply.github.com' + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} + git commit -am "Format code" + git push From 033273b445f30c1d28f9aebbe326beea1e3e11f3 Mon Sep 17 00:00:00 2001 From: Luciano Ciccariello Date: Sun, 28 Mar 2021 13:09:41 +0100 Subject: [PATCH 2/3] Change endline from LF to CRLF because Visual Studio complains --- .editorconfig | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.editorconfig b/.editorconfig index da8f0f4ab..df97264a7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,23 +2,16 @@ root = true [*] charset = utf-8 -end_of_line = lf +end_of_line = crlf insert_final_newline = true indent_style = space indent_size = 4 tab_size = 4 -[*.md] -end_of_line = crlf - -[*.sln] -end_of_line = crlf - -[*.csproj] -end_of_line = crlf +[*.sh] +end_of_line = lf [*.cs] -end_of_line = lf csharp_new_line_before_open_brace = all csharp_new_line_before_else = true csharp_new_line_before_catch = true From 8e37db22e11cc0064d55bf12547ced6f024a7265 Mon Sep 17 00:00:00 2001 From: Formatting bot Date: Sun, 28 Mar 2021 12:32:12 +0000 Subject: [PATCH 3/3] Format code --- IteEditor/IteEntry.cs | 40 +- IteEditor/MainForm.cs | 186 +- IteEditor/Program.cs | 46 +- OpenKh.Bbs/Arc.cs | 232 +- OpenKh.Bbs/Bbsa.Entry.cs | 368 +- OpenKh.Bbs/Bbsa.Hash.cs | 118 +- OpenKh.Bbs/Bbsa.Names.cs | 64 +- OpenKh.Bbs/Bbsa.Partition.cs | 230 +- OpenKh.Bbs/Bbsa.cs | 506 +- OpenKh.Bbs/Bep.cs | 166 +- OpenKh.Bbs/Constants.cs | 896 +- OpenKh.Bbs/Ctd.cs | 402 +- OpenKh.Bbs/Epd.cs | 746 +- OpenKh.Bbs/Event.cs | 108 +- OpenKh.Bbs/FontCharacterInfo.cs | 72 +- OpenKh.Bbs/FontIconInfo.cs | 118 +- OpenKh.Bbs/FontInfo.cs | 40 +- OpenKh.Bbs/FontsArc.cs | 304 +- OpenKh.Bbs/Itb.cs | 168 +- OpenKh.Bbs/Itc.cs | 168 +- OpenKh.Bbs/Ite.cs | 242 +- OpenKh.Bbs/Messages/CtdEncoders.cs | 26 +- OpenKh.Bbs/Messages/ICtdMessageDecode.cs | 14 +- OpenKh.Bbs/Messages/ICtdMessageEncode.cs | 14 +- OpenKh.Bbs/Messages/ICtdMessageEncoder.cs | 22 +- .../Internals/InternationalCtdEncoder.cs | 372 +- .../Messages/Internals/JapaneseCtdEncoder.cs | 134 +- OpenKh.Bbs/Olo.cs | 176 +- OpenKh.Bbs/Pam.cs | 1158 +- OpenKh.Bbs/Pmo.cs | 1572 +- OpenKh.Bbs/Pmp.cs | 350 +- OpenKh.Bbs/SystemData/Command.cs | 914 +- OpenKh.Bbs/SystemData/Item.cs | 560 +- OpenKh.Command.Arc/Program.cs | 284 +- OpenKh.Command.Bar/Core.cs | 246 +- OpenKh.Command.Bar/Helpers.cs | 128 +- OpenKh.Command.Bar/Program.cs | 260 +- .../ArchiveNotFoundException.cs | 22 +- OpenKh.Command.Bbsa/Program.cs | 272 +- OpenKh.Command.CoctChanger/Program.cs | 726 +- .../Utils/DumpCoctUtil.cs | 182 +- .../Utils/ObjDumpUtil.cs | 108 +- OpenKh.Command.DoctChanger/Program.cs | 670 +- .../Utils/DumpDoctUtil.cs | 114 +- OpenKh.Command.HdAssets/Program.cs | 298 +- OpenKh.Command.IdxImg/KingdomHearts1.cs | 236 +- OpenKh.Command.IdxImg/KingdomHearts2.cs | 544 +- OpenKh.Command.IdxImg/Program.cs | 104 +- .../Interfaces/ICommonQuantizerParam.cs | 38 +- OpenKh.Command.ImgTool/Program.cs | 972 +- .../Utils/ImgdBitmapUtil.cs | 896 +- .../Utils/QuantizerFactory.cs | 152 +- OpenKh.Command.Layout/Program.cs | 332 +- OpenKh.Command.MapGen/Models/BigMesh.cs | 88 +- .../Models/BigMeshContainer.cs | 92 +- OpenKh.Command.MapGen/Models/MapGenConfig.cs | 192 +- OpenKh.Command.MapGen/Models/MaterialDef.cs | 154 +- OpenKh.Command.MapGen/Models/TextureOption.cs | 24 +- OpenKh.Command.MapGen/Program.cs | 128 +- .../Utils/BigMeshSplitter.cs | 150 +- .../Utils/CollisionBuilder.cs | 960 +- OpenKh.Command.MapGen/Utils/FileExtUtil.cs | 28 +- OpenKh.Command.MapGen/Utils/ImageResizer.cs | 160 +- OpenKh.Command.MapGen/Utils/MapBuilder.cs | 1000 +- OpenKh.Command.MapGen/Utils/MapGenUtil.cs | 542 +- .../Utils/MapVifPacketBuilder.cs | 418 +- .../Utils/SimplePatternUtil.cs | 36 +- OpenKh.Command.MsgTool/Program.cs | 172 +- OpenKh.Command.PAMtoFBXConverter/Program.cs | 1146 +- OpenKh.Command.PmoConverter/Program.cs | 684 +- OpenKh.Command.PmpConverter/Program.cs | 746 +- OpenKh.Command.SpawnScript/Program.cs | 248 +- .../Interfaces/ISpriteImageSource.cs | 52 +- OpenKh.Command.TexFooter/Models/PerTexture.cs | 22 +- .../Models/TextureAnimationIMEx.cs | 178 +- .../Models/TextureFooterDataIMEx.cs | 96 +- OpenKh.Command.TexFooter/Program.cs | 82 +- .../Subcommands/BinToYmlCommand.cs | 134 +- .../Subcommands/ExportCommand.cs | 154 +- .../Subcommands/ImportCommand.cs | 176 +- .../Subcommands/YmlToBinCommand.cs | 114 +- .../TypeConverters/UseJsonStyleArray.cs | 80 +- .../Utils/DecisionHelper.cs | 34 +- .../Utils/ExportHelper.cs | 92 +- .../Utils/SpriteBitmap.cs | 132 +- .../Utils/SpriteImageUtil.cs | 168 +- OpenKh.Common/Archives/HdAsset.cs | 316 +- OpenKh.Common/BinaryMappingExtensions.cs | 48 +- OpenKh.Common/DictionaryExtensions.cs | 84 +- OpenKh.Common/DisposableExtensions.cs | 42 +- .../CharacterNotSupportedException.cs | 22 +- .../Exceptions/InvalidFileException.cs | 46 +- OpenKh.Common/Exceptions/ParseException.cs | 28 +- OpenKh.Common/Helpers.cs | 58 +- OpenKh.Common/IsoUtility.cs | 100 +- OpenKh.Common/Log.cs | 214 +- OpenKh.Common/Ps2/Dma.cs | 156 +- OpenKh.Common/RectangleExtensions.cs | 110 +- OpenKh.Common/StreamExtensions.cs | 666 +- OpenKh.Common/Utils/BitsUtil.cs | 100 +- OpenKh.Engine.MonoGame/Extensions.cs | 162 +- .../GraphicsDeviceExtensions.cs | 68 +- OpenKh.Engine.MonoGame/IMonoGameModel.cs | 24 +- OpenKh.Engine.MonoGame/KingdomShader.cs | 252 +- OpenKh.Engine.MonoGame/KingdomTexture.cs | 194 +- OpenKh.Engine.MonoGame/MeshGroup.cs | 22 +- OpenKh.Engine.MonoGame/MeshLoader.cs | 56 +- OpenKh.Engine.MonoGame/MonoSpriteDrawing.cs | 684 +- OpenKh.Engine/Camera.cs | 406 +- .../Extensions/ImageReadExtensions.cs | 90 +- .../Extensions/Kh2FontContextExtensions.cs | 188 +- .../Extensions/SpriteDrawingExtensions.cs | 72 +- OpenKh.Engine/IEntity.cs | 42 +- OpenKh.Engine/IMessageProvider.cs | 18 +- OpenKh.Engine/Input/IInput.cs | 32 +- OpenKh.Engine/Input/IInputButtons.cs | 48 +- OpenKh.Engine/Input/IInputDevice.cs | 24 +- OpenKh.Engine/Input/InputManager.cs | 358 +- OpenKh.Engine/Kh2MessageProvider.cs | 68 +- OpenKh.Engine/MathEx.cs | 34 +- OpenKh.Engine/Motion/IModelMotion.cs | 40 +- OpenKh.Engine/Motion/IMotionEngine.cs | 14 +- OpenKh.Engine/Motion/Kh2MotionEngine.cs | 624 +- OpenKh.Engine/Parsers/Kkdf2MdlxParser.cs | 494 +- OpenKh.Engine/Parsers/MdlxParser.cs | 456 +- OpenKh.Engine/Parsers/PmoParser.cs | 206 +- OpenKh.Engine/Renders/IDebugLayoutRenderer.cs | 66 +- OpenKh.Engine/Renders/IMessageRenderer.cs | 92 +- OpenKh.Engine/Renders/ISpriteDrawing.cs | 664 +- OpenKh.Engine/Renders/Kh2MessageRenderer.cs | 501 +- OpenKh.Engine/Renders/LayoutRenderer.cs | 148 +- OpenKh.Engine/Renders/SequenceRenderer.cs | 662 +- OpenKh.Engine/TargetCamera.cs | 602 +- OpenKh.Game/AnimatedSequenceFactory.cs | 988 +- OpenKh.Game/Config.cs | 286 +- OpenKh.Game/DataContent/DummyDataContent.cs | 24 +- OpenKh.Game/DataContent/HdAssetContent.cs | 54 +- OpenKh.Game/DataContent/IdxDataContent.cs | 50 +- .../DataContent/IdxMultipleDataContent.cs | 58 +- OpenKh.Game/DataContent/ModDataContent.cs | 64 +- .../DataContent/MultipleDataContent.cs | 62 +- OpenKh.Game/DataContent/SafeDataContent.cs | 52 +- .../DataContent/StandardDataContent.cs | 60 +- OpenKh.Game/Debugging/DebugDraw.cs | 92 +- OpenKh.Game/Debugging/DebugOverlay.cs | 338 +- OpenKh.Game/Debugging/IDebug.cs | 24 +- OpenKh.Game/Debugging/IDebugConsumer.cs | 16 +- OpenKh.Game/Entities/BobEntity.cs | 44 +- OpenKh.Game/Entities/ObjectEntity.cs | 378 +- OpenKh.Game/Entities/PlayerManager.cs | 70 +- OpenKh.Game/Entities/PmpEntity.cs | 52 +- OpenKh.Game/Events/EventPlayer.cs | 606 +- OpenKh.Game/Field/BbsMap.cs | 246 +- OpenKh.Game/Field/IField.cs | 70 +- OpenKh.Game/Field/IMap.cs | 24 +- OpenKh.Game/Field/Kh2Field.cs | 1078 +- OpenKh.Game/Field/Kh2Map.cs | 242 +- OpenKh.Game/Global.cs | 18 +- OpenKh.Game/IGameContext.cs | 28 +- OpenKh.Game/Infrastructure/ArchiveManager.cs | 158 +- OpenKh.Game/Infrastructure/DeltaTimes.cs | 14 +- OpenKh.Game/Infrastructure/IDataContent.cs | 22 +- OpenKh.Game/Infrastructure/ILanguage.cs | 14 +- OpenKh.Game/Infrastructure/InputGamepad.cs | 142 +- OpenKh.Game/Infrastructure/InputKeyboard.cs | 220 +- OpenKh.Game/Infrastructure/Kernel.cs | 672 +- OpenKh.Game/Infrastructure/StateInitDesc.cs | 40 +- OpenKh.Game/Menu/IMenu.cs | 30 +- OpenKh.Game/Menu/IMenuManager.cs | 34 +- OpenKh.Game/Menu/MainMenu.cs | 640 +- OpenKh.Game/Menu/MenuBase.cs | 174 +- OpenKh.Game/Menu/MenuConfig.cs | 754 +- OpenKh.Game/Menu/MenuDebug.cs | 276 +- OpenKh.Game/Menu/MenuDebugChangePlace.cs | 232 +- OpenKh.Game/Menu/MenuDebugPlayEvent.cs | 224 +- OpenKh.Game/Menu/MenuDebugSelectPlace.cs | 284 +- OpenKh.Game/Menu/MenuStatus.cs | 910 +- OpenKh.Game/Menu/MenuTemplate.cs | 216 +- OpenKh.Game/OpenKhGame.cs | 554 +- OpenKh.Game/Program.cs | 278 +- OpenKh.Game/States/IState.cs | 26 +- OpenKh.Game/States/IStateChange.cs | 14 +- OpenKh.Game/States/MapState.cs | 366 +- OpenKh.Game/States/MenuState.cs | 570 +- OpenKh.Game/States/Title/Constants.cs | 154 +- OpenKh.Game/States/Title/ITitleMainMenu.cs | 64 +- OpenKh.Game/States/Title/ITitleSubMenu.cs | 22 +- OpenKh.Game/States/Title/NewGameMenu.cs | 392 +- OpenKh.Game/States/Title/TitleLayout.cs | 34 +- OpenKh.Game/States/Title/TitleState.cs | 836 +- OpenKh.Imaging/IImage.cs | 22 +- OpenKh.Imaging/IImageRead.cs | 32 +- OpenKh.Imaging/ImageDataHelpers.cs | 276 +- OpenKh.Imaging/ImageExtensions.cs | 48 +- OpenKh.Imaging/PixelFormat.cs | 26 +- OpenKh.Imaging/PixelFormatExtensions.cs | 38 +- OpenKh.Imaging/PngImage.cs | 698 +- OpenKh.Imaging/Tm2.cs | 1198 +- OpenKh.Kh1/Idx1.cs | 110 +- OpenKh.Kh1/Idx1Name.cs | 54 +- OpenKh.Kh1/Img1.cs | 428 +- OpenKh.Kh1/KingdomArchive.cs | 142 +- OpenKh.Kh2/Ard/AreaDataScript.cs | 2370 +- OpenKh.Kh2/Ard/Event.cs | 2104 +- OpenKh.Kh2/Ard/SpawnPoint.cs | 840 +- OpenKh.Kh2/Bar.cs | 536 +- OpenKh.Kh2/BaseTable.cs | 126 +- OpenKh.Kh2/Battle/Atkp.cs | 72 +- OpenKh.Kh2/Battle/Bons.cs | 60 +- OpenKh.Kh2/Battle/Enmp.cs | 60 +- OpenKh.Kh2/Battle/Fmlv.cs | 138 +- OpenKh.Kh2/Battle/Lvpm.cs | 40 +- OpenKh.Kh2/Battle/Lvup.cs | 108 +- OpenKh.Kh2/Battle/Plrp.cs | 54 +- OpenKh.Kh2/Battle/Przt.cs | 64 +- OpenKh.Kh2/Battle/Vtbl.cs | 52 +- OpenKh.Kh2/Coct.cs | 488 +- OpenKh.Kh2/Constants.cs | 250 +- OpenKh.Kh2/Contextes/FontContext.cs | 268 +- OpenKh.Kh2/Doct.cs | 2 +- OpenKh.Kh2/Dpd.Texture.cs | 272 +- OpenKh.Kh2/Dpd.cs | 308 +- OpenKh.Kh2/Dpx.Models.cs | 12 +- OpenKh.Kh2/Dpx.cs | 12 +- OpenKh.Kh2/Extensions/BarExtensions.cs | 194 +- .../Extensions/BoundingBoxExtensions.cs | 2 +- .../Extensions/BoundingBoxInt16Extensions.cs | 2 +- OpenKh.Kh2/Extensions/ImageReadExtensions.cs | 14 +- OpenKh.Kh2/Extensions/LayoutExtensions.cs | 90 +- OpenKh.Kh2/Extensions/SequenceExtensions.cs | 194 +- OpenKh.Kh2/Extensions/Vector3Extensions.cs | 2 +- OpenKh.Kh2/Extensions/Vector4Extensions.cs | 2 +- OpenKh.Kh2/Idx.cs | 368 +- OpenKh.Kh2/IdxDictionary.cs | 148 +- OpenKh.Kh2/IdxName.cs | 64 +- OpenKh.Kh2/Img.cs | 499 +- OpenKh.Kh2/Imgd.Create.cs | 206 +- OpenKh.Kh2/Imgd.cs | 630 +- OpenKh.Kh2/Imgz.cs | 212 +- OpenKh.Kh2/Jigsaw.cs | 44 +- OpenKh.Kh2/Jiminy/Albu.cs | 46 +- OpenKh.Kh2/Jiminy/Anse.cs | 40 +- OpenKh.Kh2/Jiminy/BaseJiminy.cs | 94 +- OpenKh.Kh2/Jiminy/Char.cs | 70 +- OpenKh.Kh2/Jiminy/Diag.cs | 44 +- OpenKh.Kh2/Jiminy/Limi.cs | 40 +- OpenKh.Kh2/Jiminy/Mini.cs | 40 +- OpenKh.Kh2/Jiminy/Puzz.cs | 90 +- OpenKh.Kh2/Jiminy/Ques.cs | 48 +- OpenKh.Kh2/Jiminy/Stor.cs | 46 +- OpenKh.Kh2/Jiminy/Worl.cs | 50 +- OpenKh.Kh2/Layout.cs | 340 +- OpenKh.Kh2/Mdlx.Map.cs | 518 +- OpenKh.Kh2/Mdlx.Model.cs | 744 +- OpenKh.Kh2/Mdlx.cs | 192 +- OpenKh.Kh2/Messages/Encoders.cs | 106 +- OpenKh.Kh2/Messages/IMessageDecode.cs | 18 +- OpenKh.Kh2/Messages/IMessageEncode.cs | 18 +- OpenKh.Kh2/Messages/IMessageEncoder.cs | 12 +- OpenKh.Kh2/Messages/Internals/BaseCmdModel.cs | 26 +- .../Messages/Internals/BaseMessageDecoder.cs | 318 +- OpenKh.Kh2/Messages/Internals/DataCmdModel.cs | 22 +- .../Internals/InternationalSystemDecode.cs | 546 +- .../Internals/InternationalSystemEncode.cs | 158 +- .../Messages/Internals/JapaneseEventDecode.cs | 879 +- .../Messages/Internals/JapaneseEventEncode.cs | 296 +- .../Internals/JapaneseSystemDecode.cs | 816 +- .../Internals/JapaneseSystemEncode.cs | 296 +- .../Messages/Internals/SimpleCmdModel.cs | 20 +- .../Messages/Internals/SingleDataCmdModel.cs | 18 +- .../Messages/Internals/TableCmdModel.cs | 30 +- OpenKh.Kh2/Messages/Internals/TextCmdModel.cs | 44 +- .../Messages/Internals/TurkishSystemDecode.cs | 546 +- .../Messages/Internals/TurkishSystemEncode.cs | 158 +- .../Messages/Internals/UnsupportedCmdModel.cs | 22 +- OpenKh.Kh2/Messages/MessageCommand.cs | 80 +- OpenKh.Kh2/Messages/MessageCommandModel.cs | 90 +- OpenKh.Kh2/Messages/MsgSerializer.Text.cs | 278 +- OpenKh.Kh2/Messages/MsgSerializer.Xml.cs | 165 +- OpenKh.Kh2/Messages/MsgSerializer.cs | 772 +- OpenKh.Kh2/Mixdata/BaseMixdata.cs | 96 +- OpenKh.Kh2/Mixdata/Cond.cs | 48 +- OpenKh.Kh2/Mixdata/Exp.cs | 28 +- OpenKh.Kh2/Mixdata/Leve.cs | 42 +- OpenKh.Kh2/Mixdata/Reci.cs | 66 +- OpenKh.Kh2/ModelTexture.cs | 560 +- OpenKh.Kh2/Models/BobDescriptor.cs | 142 +- OpenKh.Kh2/Motion.cs | 1524 +- OpenKh.Kh2/MotionSet.cs | 494 +- OpenKh.Kh2/Msg.cs | 500 +- OpenKh.Kh2/ObjectCollision.cs | 88 +- OpenKh.Kh2/Objentry.cs | 242 +- OpenKh.Kh2/Pax.cs | 360 +- OpenKh.Kh2/Places.cs | 254 +- OpenKh.Kh2/Ps2.Reform32.cs | 166 +- OpenKh.Kh2/Ps2.Reform4.cs | 276 +- OpenKh.Kh2/Ps2.Reform8.cs | 186 +- OpenKh.Kh2/Ps2.Repl.cs | 20 +- OpenKh.Kh2/Ps2.Utility.cs | 20 +- OpenKh.Kh2/RawBitmap.cs | 266 +- OpenKh.Kh2/SaveData/DriveForm.cs | 92 +- OpenKh.Kh2/SaveData/ISaveData.cs | 154 +- OpenKh.Kh2/SaveData/PartyMembers.cs | 54 +- OpenKh.Kh2/SaveData/PlaceScript.cs | 84 +- OpenKh.Kh2/SaveData/SaveCharacter.cs | 242 +- OpenKh.Kh2/SaveData/SaveDataEuropean.cs | 172 +- OpenKh.Kh2/SaveData/SaveDataFactory.cs | 274 +- OpenKh.Kh2/SaveData/SaveDataFinalMix.cs | 226 +- OpenKh.Kh2/SaveData/SaveProgress.cs | 68 +- OpenKh.Kh2/Sequence.cs | 614 +- OpenKh.Kh2/SystemData/Arif.cs | 146 +- OpenKh.Kh2/SystemData/Ftst.cs | 42 +- OpenKh.Kh2/SystemData/Item.cs | 208 +- OpenKh.Kh2/SystemData/Memt.cs | 316 +- OpenKh.Kh2/SystemData/Trsr.cs | 58 +- OpenKh.Kh2/TextureFooter/TextureAnimation.cs | 16 +- OpenKh.Kh2/TextureFooter/TextureFooterData.cs | 272 +- OpenKh.Kh2/TextureFooter/TextureFrame.cs | 16 +- .../TextureFooter/TextureFrameControl.cs | 2 +- OpenKh.Kh2/TextureFooter/TextureFrameGroup.cs | 2 +- OpenKh.Kh2/TextureFooter/UvScroll.cs | 6 +- OpenKh.Kh2/Utils/BoundingBox.cs | 2 +- OpenKh.Kh2/Utils/BoundingBoxInt16.cs | 2 +- OpenKh.Kh2/Utils/Vector3Int16.cs | 2 +- OpenKh.Kh2/WorldPoint.cs | 58 +- OpenKh.Kh2AnimEmu/Legacy/AxBone.cs | 38 +- OpenKh.Kh2AnimEmu/Mset/AnbIndir.cs | 76 +- OpenKh.Kh2AnimEmu/Mset/AnimModel.cs | 46 +- OpenKh.Kh2AnimEmu/Mset/AnimReader.cs | 514 +- .../Mset/EmuBasedAnimMatricesProvider.cs | 142 +- OpenKh.Kh2AnimEmu/Mset/EmuRunner/CustEE.cs | 3598 +- OpenKh.Kh2AnimEmu/Mset/EmuRunner/Execee.cs | 120 +- OpenKh.Kh2AnimEmu/Mset/EmuRunner/Mlink.cs | 1244 +- OpenKh.Kh2AnimEmu/Mset/EmuRunner/Mobrc1.cs | 49642 ++++++++-------- OpenKh.Kh2AnimEmu/Mset/EmuRunner/RelocMdlx.cs | 484 +- .../Mset/Interfaces/IAnimMatricesProvider.cs | 36 +- OpenKh.Kh2AnimEmu/Mset/MsetIndir.cs | 62 +- OpenKh.Kh2AnimEmu/Mset/PosTbl.cs | 152 +- OpenKh.Kh2AnimEmu/Mset/T1.cs | 48 +- OpenKh.Kh2AnimEmu/Mset/T2.cs | 52 +- OpenKh.Kh2AnimEmu/Mset/T3.cs | 54 +- OpenKh.Kh2AnimEmu/Mset/T4.cs | 46 +- OpenKh.Kh2AnimEmu/Mset/T9.cs | 48 +- OpenKh.Kh2AnimEmu/Mset/T9f.cs | 42 +- OpenKh.Patcher/Metadata.cs | 120 +- OpenKh.Patcher/PatcherException.cs | 30 +- OpenKh.Patcher/PatcherProcessor.cs | 566 +- OpenKh.Ps2/VifUnpacker.cs | 746 +- OpenKh.Ps2/VpuPacket.cs | 302 +- OpenKh.Ps2/VpuPacketExtensions.cs | 116 +- .../Models/MotionExport.cs | 68 +- OpenKh.Research.Kh2Anim/Program.cs | 122 +- .../Subcommands/BakeCommand.cs | 318 +- .../Subcommands/FryCommand.cs | 434 +- .../Subcommands/SimpleMdlxCommand.cs | 50 +- .../TypeConverters/TimelineTableConverter.cs | 74 +- .../Utils/AnbBarWrapper.cs | 26 +- OpenKh.Research.Kh2Anim/Utils/MdlxMaker.cs | 122 +- OpenKh.Tests.Commands/FileDisposer.cs | 44 +- OpenKh.Tests.Commands/MapGenTest.cs | 114 +- OpenKh.Tests.Commands/TexFooterTests.cs | 138 +- .../AnimatedSequenceFactoryTests.cs | 822 +- OpenKh.Tests.Engine/CameraTests.cs | 442 +- OpenKh.Tests.Engine/Extensions.cs | 84 +- OpenKh.Tests.Engine/Kh2EventTests.cs | 874 +- OpenKh.Tests.Engine/MdlxLoaderTests.cs | 230 +- OpenKh.Tests.Engine/SequenceRendererTest.cs | 480 +- OpenKh.Tests/Bbs/ArcTests.cs | 240 +- OpenKh.Tests/Bbs/BbsaTests.cs | 150 +- OpenKh.Tests/Bbs/CtdEncodingTests.cs | 182 +- OpenKh.Tests/Bbs/CtdTests.cs | 174 +- OpenKh.Tests/Bbs/EventTableTests.cs | 88 +- OpenKh.Tests/Bbs/FontTests.cs | 162 +- OpenKh.Tests/Bbs/PamTests.cs | 52 +- OpenKh.Tests/Bbs/PmoTests.cs | 164 +- OpenKh.Tests/Bbs/PmpTests.cs | 66 +- OpenKh.Tests/Common/BitsUtilTest.cs | 2 +- OpenKh.Tests/Common/HdAssetTests.cs | 214 +- OpenKh.Tests/Helpers.cs | 318 +- OpenKh.Tests/Imaging/ImageDecodeTests.cs | 238 +- OpenKh.Tests/Imaging/PngTests.cs | 44 +- OpenKh.Tests/Imaging/Tm2Tests.cs | 214 +- OpenKh.Tests/Kh1/Idx1Tests.cs | 34 +- OpenKh.Tests/Kh1/KingdomArchiveTests.cs | 102 +- OpenKh.Tests/Patcher/MetadataTests.cs | 52 +- OpenKh.Tests/Patcher/PatcherTests.cs | 1206 +- OpenKh.Tests/Ps2/VifTests.cs | 52 +- OpenKh.Tests/kh2/ArdTests.cs | 592 +- OpenKh.Tests/kh2/BarTests.cs | 394 +- OpenKh.Tests/kh2/BattleTests.cs | 290 +- OpenKh.Tests/kh2/BobDescTests.cs | 84 +- OpenKh.Tests/kh2/CollisionTests.cs | 2 +- OpenKh.Tests/kh2/DoctTest.cs | 2 +- OpenKh.Tests/kh2/EventTests.cs | 698 +- OpenKh.Tests/kh2/FontContextTests.cs | 158 +- OpenKh.Tests/kh2/IdxTests.cs | 214 +- OpenKh.Tests/kh2/ImageReadExtensionsTests.cs | 2 +- OpenKh.Tests/kh2/ImgTests.cs | 272 +- OpenKh.Tests/kh2/ImgdTests.cs | 482 +- OpenKh.Tests/kh2/ImgzTests.cs | 46 +- OpenKh.Tests/kh2/JigsawTests.cs | 60 +- OpenKh.Tests/kh2/JiminyTests.cs | 42 +- OpenKh.Tests/kh2/LayoutTests.cs | 192 +- OpenKh.Tests/kh2/MdlxTests.cs | 282 +- OpenKh.Tests/kh2/ModelTextureTests.cs | 340 +- OpenKh.Tests/kh2/MotionSetTests.cs | 244 +- OpenKh.Tests/kh2/MotionTests.cs | 314 +- OpenKh.Tests/kh2/MsgEncoderTests.cs | 676 +- OpenKh.Tests/kh2/MsgSerializerTests.cs | 506 +- OpenKh.Tests/kh2/MsgTests.cs | 378 +- OpenKh.Tests/kh2/ObjectCollisionTests.cs | 56 +- OpenKh.Tests/kh2/ObjentryTests.cs | 76 +- OpenKh.Tests/kh2/PlaceTests.cs | 128 +- OpenKh.Tests/kh2/SaveDataTests.cs | 50 +- OpenKh.Tests/kh2/SequenceExtensionsTests.cs | 142 +- OpenKh.Tests/kh2/SequenceTests.cs | 186 +- OpenKh.Tests/kh2/System03Tests.cs | 264 +- OpenKh.Tests/kh2/TextureFooterDataTests.cs | 94 +- OpenKh.Tests/kh2/WorldPointsTests.cs | 74 +- OpenKh.Tools.BarEditor/App.xaml.cs | 24 +- OpenKh.Tools.BarEditor/Helpers.cs | 130 +- .../Interfaces/IViewSettings.cs | 26 +- .../Models/BarEntryModel.cs | 234 +- .../Properties/AssemblyInfo.cs | 58 +- .../Services/ToolsLoaderService.cs | 122 +- OpenKh.Tools.BarEditor/ToolModule.cs | 22 +- .../ViewModels/BarViewModel.cs | 654 +- OpenKh.Tools.BarEditor/Views/BarView.xaml.cs | 100 +- OpenKh.Tools.BbsEventTableEditor/App.xaml.cs | 22 +- .../ViewModels/EventViewModel.cs | 250 +- .../ViewModels/EventsViewModel.cs | 68 +- .../ViewModels/MainViewModel.cs | 356 +- .../Views/EventsView.xaml.cs | 30 +- .../Views/MainWindow.xaml.cs | 34 +- OpenKh.Tools.BepEditor/BaseParameters.cs | 36 +- OpenKh.Tools.BepEditor/DisappearParameters.cs | 40 +- OpenKh.Tools.BepEditor/Form1.cs | 234 +- OpenKh.Tools.BepEditor/Program.cs | 46 +- .../IImGuiRenderer.cs | 14 +- OpenKh.Tools.Common.CustomImGui/ImGuiEx.cs | 520 +- .../MonoGameImGui.cs | 882 +- .../MonoGameImGuiBootstrap.cs | 202 +- OpenKh.Tools.Common/CommandHelpers.cs | 32 +- OpenKh.Tools.Common/Constants.cs | 16 +- OpenKh.Tools.Common/Controls/DrawPanel.cs | 4 +- .../Controls/KingdomTextArea.cs | 238 +- .../Controls/LayoutRendererPanel.cs | 344 +- .../Controls/SequenceRendererPanel.cs | 306 +- OpenKh.Tools.Common/Controls/Timeline.xaml.cs | 146 +- .../DependencyPropertyUtils.cs | 78 +- OpenKh.Tools.Common/ImageReadExtensions.cs | 36 +- OpenKh.Tools.Common/Imaging/GdiFormats.cs | 170 +- OpenKh.Tools.Common/Imaging/GdiImage.cs | 106 +- .../Imaging/ImageExtensions.cs | 110 +- .../Imaging/PixelFormatExtensions.cs | 102 +- OpenKh.Tools.Common/Kh2Utilities.cs | 170 +- OpenKh.Tools.Common/MessageDialog.xaml.cs | 208 +- OpenKh.Tools.Common/Models/Kh2WorldsList.cs | 48 +- .../Models/MyGenericListModel.cs | 32 +- OpenKh.Tools.Common/ProcessStream.cs | 300 +- OpenKh.Tools.Common/RelayCommand.cs | 56 +- .../SpriteDrawingDirect3D.Context.cs | 524 +- .../SpriteDrawingDirect3D.Drawing.cs | 376 +- .../SpriteDrawingDirect3D.Sharders.cs | 202 +- .../SpriteDrawingDirect3D.Surface.cs | 614 +- .../Rendering/SpriteDrawingDirect3D.cs | 198 +- OpenKh.Tools.Common/ToolConstants.cs | 16 +- OpenKh.Tools.Common/ToolInvokeDesc.cs | 52 +- OpenKh.Tools.Common/Utilities.cs | 102 +- OpenKh.Tools.CtdEditor/App.xaml.cs | 22 +- .../Interfaces/CtdDrawHandler.cs | 182 +- .../Interfaces/IDrawHandler.cs | 34 +- .../ViewModels/CharacterViewModel.cs | 124 +- .../ViewModels/CtdViewModel.cs | 186 +- .../ViewModels/FontEditorViewModel.cs | 276 +- .../ViewModels/FontEntryViewModel.cs | 42 +- .../ViewModels/MainViewModel.cs | 314 +- .../ViewModels/MessageViewModel.cs | 142 +- OpenKh.Tools.CtdEditor/Views/CtdView.xaml.cs | 30 +- .../Views/FontWindow.xaml.cs | 54 +- .../Views/MainWindow.xaml.cs | 34 +- OpenKh.Tools.DpdViewer/App.xaml.cs | 22 +- .../Models/TexturesModel.cs | 44 +- .../Properties/AssemblyInfo.cs | 58 +- .../ViewModels/DpdViewModel.cs | 202 +- .../ViewModels/TexturesViewModel.cs | 54 +- OpenKh.Tools.DpdViewer/Views/DpdView.xaml.cs | 58 +- .../Views/TexturesView.xaml.cs | 56 +- OpenKh.Tools.EpdEditor/AddDropParam.cs | 54 +- OpenKh.Tools.EpdEditor/AddExtraParam.cs | 56 +- OpenKh.Tools.EpdEditor/AddTechParam.cs | 54 +- OpenKh.Tools.EpdEditor/DropControl.cs | 36 +- OpenKh.Tools.EpdEditor/ExtraControl.cs | 36 +- OpenKh.Tools.EpdEditor/MainForm.cs | 561 +- OpenKh.Tools.EpdEditor/Program.cs | 46 +- OpenKh.Tools.EpdEditor/TechControl.cs | 36 +- OpenKh.Tools.IdxImg/App.xaml.cs | 34 +- OpenKh.Tools.IdxImg/AssemblyInfo.cs | 20 +- OpenKh.Tools.IdxImg/Extensions.cs | 20 +- OpenKh.Tools.IdxImg/ExtractProcessor.cs | 62 +- .../Interfaces/IExtractProgress.cs | 20 +- OpenKh.Tools.IdxImg/Interfaces/IIdxManager.cs | 22 +- .../Interfaces/ITreeSelectedItem.cs | 14 +- OpenKh.Tools.IdxImg/MainWindow.xaml.cs | 56 +- .../ViewModels/EntryParserModel.cs | 120 +- .../ViewModels/EntryViewModel.cs | 32 +- .../ViewModels/FileViewModel.cs | 110 +- .../ViewModels/FolderViewModel.cs | 88 +- .../ViewModels/IdxImgViewModel.cs | 252 +- .../ViewModels/IdxViewModel.cs | 128 +- .../ViewModels/NodeViewModel.cs | 32 +- .../ViewModels/RootViewModel.cs | 122 +- .../Views/ExtractProgressWindow.xaml.cs | 76 +- .../Views/FilePropertyView.xaml.cs | 30 +- OpenKh.Tools.IdxImg/Views/IdxTreeView.xaml.cs | 50 +- OpenKh.Tools.ImageViewer/App.xaml.cs | 34 +- OpenKh.Tools.ImageViewer/ImageViewerModule.cs | 28 +- .../Services/IImageContainer.cs | 28 +- .../Services/IImageFormat.cs | 40 +- .../Services/IImageFormatService.cs | 28 +- .../Services/IImageMultiple.cs | 22 +- .../Services/IImageSingle.cs | 24 +- .../ImageFormatService.GenericImageFormat.cs | 70 +- .../ImageFormatService.ImageContainer.cs | 46 +- .../ImageFormatService.MultipleImageFormat.cs | 60 +- .../ImageFormatService.SingleImageFormat.cs | 62 +- .../Services/ImageFormatService.cs | 208 +- .../Services/ImageFormatSevice.Kh2Font.cs | 88 +- .../ViewModels/ImageContainerViewModel.cs | 58 +- .../ViewModels/ImageViewModel.cs | 68 +- .../ViewModels/ImageViewerViewModel.cs | 704 +- .../Views/MainWindow.xaml.cs | 78 +- OpenKh.Tools.ItbEditor/ItbEntry.cs | 74 +- OpenKh.Tools.ItbEditor/MainForm.cs | 496 +- OpenKh.Tools.ItbEditor/Program.cs | 46 +- OpenKh.Tools.ItcEditor/ItcEntry.cs | 52 +- OpenKh.Tools.ItcEditor/MainForm.cs | 304 +- OpenKh.Tools.ItcEditor/Program.cs | 46 +- OpenKh.Tools.Kh2BattleEditor/App.xaml.cs | 34 +- .../Extensions/BarExtensions.cs | 28 +- .../Interfaces/IBattleGetChanges.cs | 22 +- .../Services/CharacterNameProvider.cs | 66 +- .../Services/EnemyNameProvider.cs | 494 +- .../Services/FormNameProvider.cs | 78 +- .../ViewModels/BonsViewModel.cs | 212 +- .../ViewModels/EnmpViewModel.cs | 222 +- .../ViewModels/FmlvViewModel.cs | 146 +- .../ViewModels/LvupViewModel.cs | 196 +- .../ViewModels/MainViewModel.cs | 408 +- .../ViewModels/PrztViewModel.cs | 220 +- .../Views/BonsView.xaml.cs | 30 +- .../Views/EnmpView.xaml.cs | 30 +- .../Views/FmlvView.xaml.cs | 30 +- .../Views/LvupView.xaml.cs | 56 +- .../Views/MainWindow.xaml.cs | 34 +- .../Views/PrztView.xaml.cs | 30 +- OpenKh.Tools.Kh2MapStudio/App.cs | 866 +- OpenKh.Tools.Kh2MapStudio/EditorSettings.cs | 210 +- OpenKh.Tools.Kh2MapStudio/ImGuiExHelpers.cs | 52 +- .../Interfaces/ILayerController.cs | 26 +- .../Interfaces/IObjEntryController.cs | 32 +- .../Interfaces/ISpawnPointController.cs | 24 +- OpenKh.Tools.Kh2MapStudio/MapRenderer.cs | 794 +- .../Models/CollisionModel.cs | 412 +- .../Models/MeshGroupModel.cs | 128 +- .../Models/SpawnPointModel.cs | 40 +- .../Models/SpawnScriptModel.cs | 130 +- .../ObjEntryController.cs | 202 +- OpenKh.Tools.Kh2MapStudio/Program.cs | 138 +- .../Windows/BobDescriptorWindow.cs | 178 +- .../Windows/CameraWindow.cs | 38 +- .../Windows/CollisionWindow.cs | 110 +- .../Windows/LayerControllerWindow.cs | 52 +- .../Windows/MeshGroupWindow.cs | 120 +- .../Windows/SpawnPointWindow.cs | 410 +- .../Windows/SpawnScriptWindow.cs | 64 +- OpenKh.Tools.Kh2PlaceEditor/App.xaml.cs | 34 +- .../Converters/EnumMatchToBooleanConverter.cs | 66 +- .../ViewModels/PlaceEditorViewModel.cs | 336 +- .../ViewModels/PlaceViewModel.cs | 122 +- .../ViewModels/PlacesViewModel.cs | 90 +- .../Views/PlaceEditorWindow.xaml.cs | 34 +- .../Views/PlacesView.xaml.cs | 30 +- OpenKh.Tools.Kh2SystemEditor/App.xaml.cs | 22 +- .../Attributes/ExportTargetAttribute.cs | 2 +- .../Converters/EnumMatchToBooleanConverter.cs | 66 +- .../Extensions/BarExtensions.cs | 30 +- .../Interfaces/IItemEntry.cs | 16 +- .../Interfaces/IItemProvider.cs | 26 +- .../Interfaces/IObjectProvider.cs | 24 +- .../Interfaces/ISystemGetChanges.cs | 22 +- .../Models/Export/ItemExport.cs | 124 +- .../Models/Export/TrsrExport.cs | 100 +- .../Models/ObjectModel.cs | 28 +- .../Utils/DictListWriteUtil.cs | 10 +- .../Utils/DictionalizeUtil.cs | 2 +- .../ViewModels/FtstViewModel.cs | 252 +- .../ViewModels/ItemViewModel.cs | 382 +- .../ViewModels/MemtViewModel.cs | 354 +- .../ViewModels/SystemEditorViewModel.cs | 736 +- .../ViewModels/TrsrViewModel.cs | 352 +- .../Views/FtstView.xaml.cs | 30 +- .../Views/ItemView.xaml.cs | 30 +- .../Views/MemtView.xaml.cs | 52 +- .../Views/SystemEditorView.xaml.cs | 38 +- .../Views/TrsrView.xaml.cs | 30 +- OpenKh.Tools.Kh2TextEditor/App.xaml.cs | 34 +- .../Converters/EnumMatchToBooleanConverter.cs | 66 +- .../Interfaces/ICurrentMessageEncoder.cs | 18 +- .../Interfaces/IInvalidateErrorCount.cs | 14 +- .../Models/MessageModel.cs | 236 +- .../Models/MessagesModel.cs | 88 +- .../Models/TextAreaModel.cs | 54 +- .../Services/ExchangeableMessage.cs | 34 +- .../Services/ITextExporter.cs | 32 +- .../Services/ITextImporter.cs | 32 +- .../Services/PlainTextExporter.cs | 48 +- .../Services/TextExporters.cs | 68 +- .../Services/TextImporters.cs | 66 +- .../Services/XmlTextExporter.cs | 68 +- .../Services/XmlTextImporter.cs | 58 +- .../Services/YamlTextExporter.cs | 58 +- .../Services/YamlTextImporter.cs | 68 +- .../Types/EncodingType.cs | 18 +- OpenKh.Tools.Kh2TextEditor/Types/FontType.cs | 16 +- .../ViewModels/MainViewModel.cs | 956 +- .../ViewModels/TextEditorViewModel.cs | 460 +- .../Views/MainWindow.xaml.cs | 48 +- .../Views/TextEditorView.xaml.cs | 56 +- OpenKh.Tools.LayoutEditor/App.cs | 1242 +- .../AppElementSelection.cs | 26 +- OpenKh.Tools.LayoutEditor/AppLayoutEditor.cs | 646 +- .../AppSequenceEditor.cs | 1428 +- .../Controls/ImSequencer.cs | 1798 +- .../Controls/MySequencer.cs | 422 +- .../DebugSequenceRenderer.cs | 170 +- .../Dialogs/ResourceSelectionDialog.cs | 148 +- .../Dialogs/SpriteEditDialog.cs | 324 +- .../Dialogs/SpriteGroupEditDialog.cs | 432 +- OpenKh.Tools.LayoutEditor/Interfaces/IApp.cs | 20 +- .../Interfaces/IEditorSettings.cs | 32 +- .../Interfaces/ISaveBar.cs | 20 +- .../Interfaces/ITextureBinder.cs | 62 +- .../Models/SpriteGroupModel.cs | 274 +- .../Models/SpriteModel.cs | 266 +- OpenKh.Tools.LayoutEditor/Program.cs | 100 +- OpenKh.Tools.LayoutEditor/Utilities.cs | 38 +- OpenKh.Tools.ModsManager/App.xaml.cs | 34 +- OpenKh.Tools.ModsManager/AssemblyInfo.cs | 20 +- .../Converters/RadioButtonToIntConverter.cs | 38 +- .../Exceptions/Exceptions.cs | 74 +- OpenKh.Tools.ModsManager/Helpers.cs | 100 +- .../Interfaces/IDebugging.cs | 16 +- .../Interfaces/IOperationDispatcher.cs | 20 +- .../Models/GameInfoModel.cs | 34 +- OpenKh.Tools.ModsManager/Models/ModModel.cs | 28 +- .../Models/ModUpdateModel.cs | 16 +- .../Services/ConfigurationService.cs | 390 +- .../Services/GameService.cs | 112 +- .../Services/ModsService.cs | 566 +- .../Services/OperationDispatcher.cs | 200 +- .../Services/Pcsx2Injector.cs | 1072 +- .../Services/Pcsx2MemoryService.cs | 332 +- .../Services/RepositoryService.cs | 208 +- .../ViewModels/MainViewModel.cs | 848 +- .../ViewModels/ModViewModel.cs | 460 +- .../ViewModels/SetupWizardViewModel.cs | 504 +- .../Views/DebuggingWindow.xaml.cs | 134 +- .../Views/InstallModProgressWindow.xaml.cs | 178 +- .../Views/InstallModView.xaml.cs | 150 +- .../Views/MainWindow.xaml.cs | 48 +- .../Views/ModDetailsView.xaml.cs | 50 +- .../Views/ModManagerView.xaml.cs | 50 +- .../Views/SetupWizardWindow.xaml.cs | 64 +- OpenKh.Tools.ObjentryEditor/App.xaml.cs | 34 +- .../Behavior/ScrollIntoViewBehavior.cs | 64 +- .../Converters/EnumDescriptionConverter.cs | 94 +- .../ViewModels/MainViewModel.cs | 208 +- .../ViewModels/ObjentryViewModel.cs | 390 +- .../Views/MainWindow.xaml.cs | 34 +- .../Views/ObjentryView.xaml.cs | 56 +- OpenKh.WinShell.IMDUtilities/IMDConvert.cs | 118 +- OpenKh.WinShell.IMDUtilities/IMDThumbnail.cs | 82 +- OpenKh.WinShell.IMDUtilities/MarshalBitmap.cs | 126 +- OpenKh.WinShell.IMZUtilities/IMZExtract.cs | 128 +- OpenKh.WinShell.IMZUtilities/IMZRepack.cs | 124 +- OpenKh.WinShell.IMZUtilities/MarshalBitmap.cs | 126 +- Playground/Program.cs | 112 +- Playground/Properties/AssemblyInfo.cs | 22 +- 689 files changed, 97877 insertions(+), 97758 deletions(-) diff --git a/IteEditor/IteEntry.cs b/IteEditor/IteEntry.cs index de7ed222a..99fc98d9f 100644 --- a/IteEditor/IteEntry.cs +++ b/IteEditor/IteEntry.cs @@ -1,20 +1,20 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; -using OpenKh.Bbs.SystemData; - -namespace OpenKh.Tools.IteEditor -{ - public partial class IteEntry : UserControl - { - public IteEntry() - { - InitializeComponent(); - ItemComboBox.DataSource = Enum.GetValues(typeof(Item.Type)); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using OpenKh.Bbs.SystemData; + +namespace OpenKh.Tools.IteEditor +{ + public partial class IteEntry : UserControl + { + public IteEntry() + { + InitializeComponent(); + ItemComboBox.DataSource = Enum.GetValues(typeof(Item.Type)); + } + } +} diff --git a/IteEditor/MainForm.cs b/IteEditor/MainForm.cs index fe6198823..3274954be 100644 --- a/IteEditor/MainForm.cs +++ b/IteEditor/MainForm.cs @@ -1,93 +1,93 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.IO; -using OpenKh.Bbs; -using OpenKh.Bbs.SystemData; - -namespace OpenKh.Tools.IteEditor -{ - public partial class MainForm : Form - { - public MainForm() - { - InitializeComponent(); - } - - public Ite ite = new Ite(); - Stream iteFile; - - private void UpdateParameters(Ite ite) - { - int cnt = 1; - for(int i = 0; i < ite.header.WeaponDataCount; i++) - { - IteEntry itEntry = new IteEntry(); - itEntry.ITE_GBox.Text = "ITC Entry " + cnt; - itEntry.ItemComboBox.SelectedItem = (Item.Type)ite.WeaponList[i].ItemID; - FlowWeapons.Controls.Add(itEntry); - cnt++; - } - - for (int i = 0; i < ite.header.FlavorDataCount; i++) - { - IteEntry itEntry = new IteEntry(); - itEntry.ITE_GBox.Text = "ITC Entry " + cnt; - itEntry.ItemComboBox.SelectedItem = (Item.Type)ite.FlavorList[i].ItemID; - FlowFlavors.Controls.Add(itEntry); - cnt++; - } - - for (int i = 0; i < ite.header.KeyItemDataCount; i++) - { - IteEntry itEntry = new IteEntry(); - itEntry.ITE_GBox.Text = "ITC Entry " + cnt; - itEntry.ItemComboBox.SelectedItem = (Item.Type)ite.KeyItemList[i].ItemID; - FlowKeyItem.Controls.Add(itEntry); - cnt++; - } - - for (int i = 0; i < ite.header.KeyItemHideDataCount; i++) - { - IteEntry itEntry = new IteEntry(); - itEntry.ITE_GBox.Text = "ITC Entry " + cnt; - itEntry.ItemComboBox.SelectedItem = (Item.Type)ite.KeyItemHideList[i].ItemID; - FlowKeyItemHide.Controls.Add(itEntry); - cnt++; - } - - for (int i = 0; i < ite.header.SynthesisDataCount; i++) - { - IteEntry itEntry = new IteEntry(); - itEntry.ITE_GBox.Text = "ITC Entry " + cnt; - itEntry.ItemComboBox.SelectedItem = (Item.Type)ite.SynthesisList[i].ItemID; - FlowSynthesis.Controls.Add(itEntry); - cnt++; - } - - } - - private void LoadITEButton_Click(object sender, EventArgs e) - { - OpenFileDialog dialog = new OpenFileDialog(); - dialog.Filter = "Item files (*.ite)|*.ite|All files (*.*)|*.*"; - DialogResult result = dialog.ShowDialog(); - - if (result == DialogResult.OK) - { - if (iteFile != null) - iteFile.Close(); - iteFile = File.OpenRead(dialog.FileName); - ite = Ite.Read(iteFile); - UpdateParameters(ite); - //SaveITEButton.Enabled = true; - } - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.IO; +using OpenKh.Bbs; +using OpenKh.Bbs.SystemData; + +namespace OpenKh.Tools.IteEditor +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + } + + public Ite ite = new Ite(); + Stream iteFile; + + private void UpdateParameters(Ite ite) + { + int cnt = 1; + for (int i = 0; i < ite.header.WeaponDataCount; i++) + { + IteEntry itEntry = new IteEntry(); + itEntry.ITE_GBox.Text = "ITC Entry " + cnt; + itEntry.ItemComboBox.SelectedItem = (Item.Type)ite.WeaponList[i].ItemID; + FlowWeapons.Controls.Add(itEntry); + cnt++; + } + + for (int i = 0; i < ite.header.FlavorDataCount; i++) + { + IteEntry itEntry = new IteEntry(); + itEntry.ITE_GBox.Text = "ITC Entry " + cnt; + itEntry.ItemComboBox.SelectedItem = (Item.Type)ite.FlavorList[i].ItemID; + FlowFlavors.Controls.Add(itEntry); + cnt++; + } + + for (int i = 0; i < ite.header.KeyItemDataCount; i++) + { + IteEntry itEntry = new IteEntry(); + itEntry.ITE_GBox.Text = "ITC Entry " + cnt; + itEntry.ItemComboBox.SelectedItem = (Item.Type)ite.KeyItemList[i].ItemID; + FlowKeyItem.Controls.Add(itEntry); + cnt++; + } + + for (int i = 0; i < ite.header.KeyItemHideDataCount; i++) + { + IteEntry itEntry = new IteEntry(); + itEntry.ITE_GBox.Text = "ITC Entry " + cnt; + itEntry.ItemComboBox.SelectedItem = (Item.Type)ite.KeyItemHideList[i].ItemID; + FlowKeyItemHide.Controls.Add(itEntry); + cnt++; + } + + for (int i = 0; i < ite.header.SynthesisDataCount; i++) + { + IteEntry itEntry = new IteEntry(); + itEntry.ITE_GBox.Text = "ITC Entry " + cnt; + itEntry.ItemComboBox.SelectedItem = (Item.Type)ite.SynthesisList[i].ItemID; + FlowSynthesis.Controls.Add(itEntry); + cnt++; + } + + } + + private void LoadITEButton_Click(object sender, EventArgs e) + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Filter = "Item files (*.ite)|*.ite|All files (*.*)|*.*"; + DialogResult result = dialog.ShowDialog(); + + if (result == DialogResult.OK) + { + if (iteFile != null) + iteFile.Close(); + iteFile = File.OpenRead(dialog.FileName); + ite = Ite.Read(iteFile); + UpdateParameters(ite); + //SaveITEButton.Enabled = true; + } + } + } +} diff --git a/IteEditor/Program.cs b/IteEditor/Program.cs index f73189ab1..78136964e 100644 --- a/IteEditor/Program.cs +++ b/IteEditor/Program.cs @@ -1,23 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace OpenKh.Tools.IteEditor -{ - static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.SetHighDpiMode(HighDpiMode.SystemAware); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace OpenKh.Tools.IteEditor +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/OpenKh.Bbs/Arc.cs b/OpenKh.Bbs/Arc.cs index 445d50e26..74a5db04d 100644 --- a/OpenKh.Bbs/Arc.cs +++ b/OpenKh.Bbs/Arc.cs @@ -1,116 +1,116 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Bbs -{ - public static class Arc - { - private const int MagicCode = 0x435241; - private const int Version = 1; - private const int MetaEntrySize = 0x20; - private const int Alignment = 0x10; - - private class Header - { - [Data] public int MagicCode { get; set; } - [Data] public short Version { get; set; } - [Data] public short EntryCount { get; set; } - [Data] public int Unused08 { get; set; } - [Data] public int Unused0c { get; set; } - } - - private class MetaEntry - { - [Data] public uint DirectoryPointer { get; set; } - [Data] public int Offset { get; set; } - [Data] public int Length { get; set; } - [Data] public int Unused { get; set; } - [Data(Count = 16)] public string Name { get; set; } - - public bool IsPointer => DirectoryPointer != 0; - } - - public class Entry - { - public bool IsLink => DirectoryPointer != 0; - public uint DirectoryPointer { get; set; } - public string Name { get; set; } - public byte[] Data { get; set; } - - public string Path - { - get - { - if (DirectoryPointer == 0) - return Name; - - var directory = Bbsa.GetDirectoryName(DirectoryPointer); - if (string.IsNullOrEmpty(directory)) - return $"{DirectoryPointer:X08}/{Name}"; - - return $"{directory}/{Name}"; - - } - } - } - - public static IEnumerable Read(Stream stream) - { - var header = BinaryMapping.ReadObject
(stream.SetPosition(0)); - - return Enumerable.Range(0, header.EntryCount) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToArray() - .Select(x => new Entry - { - DirectoryPointer = x.DirectoryPointer, - Name = x.Name, - Data = x.IsPointer ? null : stream.SetPosition(x.Offset).ReadBytes(x.Length) - }) - .ToArray(); - } - - public static void Write(this IEnumerable entries, Stream stream) - { - var myEntries = entries.ToArray(); - - stream.Position = 0; - BinaryMapping.WriteObject(stream, new Header - { - MagicCode = MagicCode, - Version = Version, - EntryCount = (short)myEntries.Length, - Unused08 = 0, - Unused0c = 0 - }); - - var dataStartOffset = (int)stream.Position + myEntries.Length * MetaEntrySize; - foreach (var entry in myEntries) - { - BinaryMapping.WriteObject(stream, new MetaEntry - { - DirectoryPointer = entry.DirectoryPointer, - Offset = entry.IsLink ? 0 : dataStartOffset, - Length = entry.IsLink ? 0 : entry.Data.Length, - Unused = 0, - Name = entry.Name - }); - - dataStartOffset += Helpers.Align(entry.Data?.Length ?? 0, Alignment); - } - - foreach (var entry in myEntries.Where(x => !x.IsLink)) - { - stream.Write(entry.Data, 0, entry.Data.Length); - stream.AlignPosition(Alignment); - } - } - - public static bool IsValid(Stream stream) => - stream.Length >= 4 && - new BinaryReader(stream.SetPosition(0)).ReadInt32() == MagicCode; - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Bbs +{ + public static class Arc + { + private const int MagicCode = 0x435241; + private const int Version = 1; + private const int MetaEntrySize = 0x20; + private const int Alignment = 0x10; + + private class Header + { + [Data] public int MagicCode { get; set; } + [Data] public short Version { get; set; } + [Data] public short EntryCount { get; set; } + [Data] public int Unused08 { get; set; } + [Data] public int Unused0c { get; set; } + } + + private class MetaEntry + { + [Data] public uint DirectoryPointer { get; set; } + [Data] public int Offset { get; set; } + [Data] public int Length { get; set; } + [Data] public int Unused { get; set; } + [Data(Count = 16)] public string Name { get; set; } + + public bool IsPointer => DirectoryPointer != 0; + } + + public class Entry + { + public bool IsLink => DirectoryPointer != 0; + public uint DirectoryPointer { get; set; } + public string Name { get; set; } + public byte[] Data { get; set; } + + public string Path + { + get + { + if (DirectoryPointer == 0) + return Name; + + var directory = Bbsa.GetDirectoryName(DirectoryPointer); + if (string.IsNullOrEmpty(directory)) + return $"{DirectoryPointer:X08}/{Name}"; + + return $"{directory}/{Name}"; + + } + } + } + + public static IEnumerable Read(Stream stream) + { + var header = BinaryMapping.ReadObject
(stream.SetPosition(0)); + + return Enumerable.Range(0, header.EntryCount) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToArray() + .Select(x => new Entry + { + DirectoryPointer = x.DirectoryPointer, + Name = x.Name, + Data = x.IsPointer ? null : stream.SetPosition(x.Offset).ReadBytes(x.Length) + }) + .ToArray(); + } + + public static void Write(this IEnumerable entries, Stream stream) + { + var myEntries = entries.ToArray(); + + stream.Position = 0; + BinaryMapping.WriteObject(stream, new Header + { + MagicCode = MagicCode, + Version = Version, + EntryCount = (short)myEntries.Length, + Unused08 = 0, + Unused0c = 0 + }); + + var dataStartOffset = (int)stream.Position + myEntries.Length * MetaEntrySize; + foreach (var entry in myEntries) + { + BinaryMapping.WriteObject(stream, new MetaEntry + { + DirectoryPointer = entry.DirectoryPointer, + Offset = entry.IsLink ? 0 : dataStartOffset, + Length = entry.IsLink ? 0 : entry.Data.Length, + Unused = 0, + Name = entry.Name + }); + + dataStartOffset += Helpers.Align(entry.Data?.Length ?? 0, Alignment); + } + + foreach (var entry in myEntries.Where(x => !x.IsLink)) + { + stream.Write(entry.Data, 0, entry.Data.Length); + stream.AlignPosition(Alignment); + } + } + + public static bool IsValid(Stream stream) => + stream.Length >= 4 && + new BinaryReader(stream.SetPosition(0)).ReadInt32() == MagicCode; + } +} diff --git a/OpenKh.Bbs/Bbsa.Entry.cs b/OpenKh.Bbs/Bbsa.Entry.cs index 75e947308..6349302e4 100644 --- a/OpenKh.Bbs/Bbsa.Entry.cs +++ b/OpenKh.Bbs/Bbsa.Entry.cs @@ -1,175 +1,193 @@ -using OpenKh.Common; -using System; -using System.IO; -using Xe.IO; - -namespace OpenKh.Bbs -{ - public partial class Bbsa - { - public class Entry - { - private const int SectorLength = 0x800; - private readonly Header bbsaHeader; - private readonly int offset; - private readonly int length; - private readonly string fileName; - private readonly string folderName; - - internal Entry( - Bbsa bbsa, - int offset, - int length, - string fileName, - string folderName, - uint fileHash, - uint folderHash) - { - bbsaHeader = bbsa._header; - this.offset = offset; - this.length = length; - this.fileName = fileName; - this.folderName = folderName; - FileHash = fileHash; - FolderHash = folderHash; - } - - public uint FileHash { get; } - public uint FolderHash { get; } - public string Name => $"{FolderName}/{FileName}"; - public bool HasCompleteName => fileName != null && folderName != null; - - public string CalculateNameWithExtension(Func bbsaLoader) - { - if (!CalculateArchiveOffset(bbsaHeader, offset, out var archiveIndex, out var physicalSector)) - return Name; - - var stream = bbsaLoader(archiveIndex); - var extension = CalculateExtension(stream, physicalSector * SectorLength); - if (extension == null) - return Name; - - return $"{Name}.{extension}"; - } - - public SubStream OpenStream(Func bbsaLoader) - { - if (!CalculateArchiveOffset(bbsaHeader, offset, out var archiveIndex, out var physicalSector)) - return null; - - var stream = bbsaLoader(archiveIndex); - var subStreamOffset = physicalSector * SectorLength; - var subStreamLength = length * SectorLength; - - if (length == 0xFFF) - { - if (IsPsmf(stream, subStreamOffset)) - subStreamLength = GetPsmfLength(stream, subStreamOffset); - } - - return new SubStream(stream, subStreamOffset, subStreamLength); - } - - private string FileName => fileName ?? $"@{FileHash:X08}"; - private string FolderName => - folderName ?? - CalculateFolderName(FolderHash) ?? - $"@{FolderHash:X08}"; - } - - private static bool IsPsmf(Stream stream, int offset) => - new BinaryReader(stream.SetPosition(offset)).ReadInt32() == 0x464D5350; - - private static int GetPsmfLength(Stream stream, int offset) - { - stream.SetPosition(offset + 12); - return (stream.ReadByte() << 24) | - (stream.ReadByte() << 16) | - (stream.ReadByte() << 8) | - (stream.ReadByte() << 0); - } - - private static bool CalculateArchiveOffset( - Header header, int offset, out int archiveIndex, out int physicalSector) - { - if (offset >= header.Archive4Sector) - { - archiveIndex = 4; - physicalSector = offset - header.Archive4Sector + 1; - } - else if (offset >= header.Archive3Sector) - { - archiveIndex = 3; - physicalSector = offset - header.Archive3Sector + 1; - } - else if (offset >= header.Archive2Sector) - { - archiveIndex = 2; - physicalSector = offset - header.Archive2Sector + 1; - } - else if (offset >= header.Archive1Sector) - { - archiveIndex = 1; - physicalSector = offset - header.Archive1Sector + 1; - } - else if (offset >= header.Archive0Sector) - { - archiveIndex = 0; - physicalSector = offset + header.Archive0Sector; - } - else - { - archiveIndex = -1; - physicalSector = -1; - return false; - } - - return true; - } - - private static string CalculateExtension(Stream stream, int offset) - { - stream.Position = offset; - var magicCode = new BinaryReader(stream).ReadUInt32(); - switch (magicCode) - { - case 0x61754C1B: return "lub"; - case 0x41264129: return "ice"; - case 0x44544340: return "ctd"; - case 0x50444540: return "edp"; - case 0x00435241: return "arc"; - case 0x44424D40: return "mbd"; - case 0x00444145: return "ead"; - case 0x07504546: return "fep"; - case 0x00425449: return "itb"; - case 0x00435449: return "itc"; - case 0x00455449: return "ite"; - case 0x004D4150: return "pam"; - case 0x004F4D50: return "pmo"; - case 0x42444553: return "scd"; - case 0x324D4954: return "tm2"; - case 0x00415854: return "txa"; - case 0x00617865: return "exa"; - default: return null; - } - } - - private static string CalculateFolderName(uint hash) - { - var category = (byte)(hash >> 24); - var world = (hash >> 16) & 0x1F; - var language = (hash >> 21) & 7; - var id = hash & 0xFFFF; - - var strWorld = world < Constants.Worlds.Length ? - Constants.Worlds[world] : null; - var strLanguage = language < Constants.Language.Length ? - Constants.Language[language] : null; - - if (!PathCategories.TryGetValue(category, out var pathCategory)) - return null; - - return string.Format(pathCategory, strLanguage, strWorld); - } - } -} +using OpenKh.Common; +using System; +using System.IO; +using Xe.IO; + +namespace OpenKh.Bbs +{ + public partial class Bbsa + { + public class Entry + { + private const int SectorLength = 0x800; + private readonly Header bbsaHeader; + private readonly int offset; + private readonly int length; + private readonly string fileName; + private readonly string folderName; + + internal Entry( + Bbsa bbsa, + int offset, + int length, + string fileName, + string folderName, + uint fileHash, + uint folderHash) + { + bbsaHeader = bbsa._header; + this.offset = offset; + this.length = length; + this.fileName = fileName; + this.folderName = folderName; + FileHash = fileHash; + FolderHash = folderHash; + } + + public uint FileHash { get; } + public uint FolderHash { get; } + public string Name => $"{FolderName}/{FileName}"; + public bool HasCompleteName => fileName != null && folderName != null; + + public string CalculateNameWithExtension(Func bbsaLoader) + { + if (!CalculateArchiveOffset(bbsaHeader, offset, out var archiveIndex, out var physicalSector)) + return Name; + + var stream = bbsaLoader(archiveIndex); + var extension = CalculateExtension(stream, physicalSector * SectorLength); + if (extension == null) + return Name; + + return $"{Name}.{extension}"; + } + + public SubStream OpenStream(Func bbsaLoader) + { + if (!CalculateArchiveOffset(bbsaHeader, offset, out var archiveIndex, out var physicalSector)) + return null; + + var stream = bbsaLoader(archiveIndex); + var subStreamOffset = physicalSector * SectorLength; + var subStreamLength = length * SectorLength; + + if (length == 0xFFF) + { + if (IsPsmf(stream, subStreamOffset)) + subStreamLength = GetPsmfLength(stream, subStreamOffset); + } + + return new SubStream(stream, subStreamOffset, subStreamLength); + } + + private string FileName => fileName ?? $"@{FileHash:X08}"; + private string FolderName => + folderName ?? + CalculateFolderName(FolderHash) ?? + $"@{FolderHash:X08}"; + } + + private static bool IsPsmf(Stream stream, int offset) => + new BinaryReader(stream.SetPosition(offset)).ReadInt32() == 0x464D5350; + + private static int GetPsmfLength(Stream stream, int offset) + { + stream.SetPosition(offset + 12); + return (stream.ReadByte() << 24) | + (stream.ReadByte() << 16) | + (stream.ReadByte() << 8) | + (stream.ReadByte() << 0); + } + + private static bool CalculateArchiveOffset( + Header header, int offset, out int archiveIndex, out int physicalSector) + { + if (offset >= header.Archive4Sector) + { + archiveIndex = 4; + physicalSector = offset - header.Archive4Sector + 1; + } + else if (offset >= header.Archive3Sector) + { + archiveIndex = 3; + physicalSector = offset - header.Archive3Sector + 1; + } + else if (offset >= header.Archive2Sector) + { + archiveIndex = 2; + physicalSector = offset - header.Archive2Sector + 1; + } + else if (offset >= header.Archive1Sector) + { + archiveIndex = 1; + physicalSector = offset - header.Archive1Sector + 1; + } + else if (offset >= header.Archive0Sector) + { + archiveIndex = 0; + physicalSector = offset + header.Archive0Sector; + } + else + { + archiveIndex = -1; + physicalSector = -1; + return false; + } + + return true; + } + + private static string CalculateExtension(Stream stream, int offset) + { + stream.Position = offset; + var magicCode = new BinaryReader(stream).ReadUInt32(); + switch (magicCode) + { + case 0x61754C1B: + return "lub"; + case 0x41264129: + return "ice"; + case 0x44544340: + return "ctd"; + case 0x50444540: + return "edp"; + case 0x00435241: + return "arc"; + case 0x44424D40: + return "mbd"; + case 0x00444145: + return "ead"; + case 0x07504546: + return "fep"; + case 0x00425449: + return "itb"; + case 0x00435449: + return "itc"; + case 0x00455449: + return "ite"; + case 0x004D4150: + return "pam"; + case 0x004F4D50: + return "pmo"; + case 0x42444553: + return "scd"; + case 0x324D4954: + return "tm2"; + case 0x00415854: + return "txa"; + case 0x00617865: + return "exa"; + default: + return null; + } + } + + private static string CalculateFolderName(uint hash) + { + var category = (byte)(hash >> 24); + var world = (hash >> 16) & 0x1F; + var language = (hash >> 21) & 7; + var id = hash & 0xFFFF; + + var strWorld = world < Constants.Worlds.Length ? + Constants.Worlds[world] : null; + var strLanguage = language < Constants.Language.Length ? + Constants.Language[language] : null; + + if (!PathCategories.TryGetValue(category, out var pathCategory)) + return null; + + return string.Format(pathCategory, strLanguage, strWorld); + } + } +} diff --git a/OpenKh.Bbs/Bbsa.Hash.cs b/OpenKh.Bbs/Bbsa.Hash.cs index 1dc130b63..65c8d6d89 100644 --- a/OpenKh.Bbs/Bbsa.Hash.cs +++ b/OpenKh.Bbs/Bbsa.Hash.cs @@ -1,59 +1,59 @@ -using System.Text; - -namespace OpenKh.Bbs -{ - public partial class Bbsa - { - private static uint[] CrcTable = new uint[] - { - 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, - 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, - 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, - 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, - 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, - 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, - 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, - 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, - 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, - 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, - 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, - 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, - 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, - 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, - 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, - 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, - 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, - 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, - 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, - 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, - 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, - 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, - 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, - 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, - 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, - 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, - 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, - 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, - 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, - 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, - 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, - 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, - }; - - public static uint GetHash(string text) => GetHash(Encoding.UTF8.GetBytes(text)); - - public static uint GetHash(byte[] data) - { - var a0 = uint.MaxValue; - - foreach (var ch in data) - { - var v0 = a0 >> 8; - var t2 = ch ^ a0; - a0 = v0 ^ CrcTable[t2 & 0xFF]; - } - - return ~a0; - } - } -} +using System.Text; + +namespace OpenKh.Bbs +{ + public partial class Bbsa + { + private static uint[] CrcTable = new uint[] + { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, + 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, + 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, + 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, + 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, + 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, + 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, + 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, + 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, + 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, + 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, + 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, + 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, + 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, + 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, + 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, + 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, + 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, + 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, + 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, + 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, + 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, + }; + + public static uint GetHash(string text) => GetHash(Encoding.UTF8.GetBytes(text)); + + public static uint GetHash(byte[] data) + { + var a0 = uint.MaxValue; + + foreach (var ch in data) + { + var v0 = a0 >> 8; + var t2 = ch ^ a0; + a0 = v0 ^ CrcTable[t2 & 0xFF]; + } + + return ~a0; + } + } +} diff --git a/OpenKh.Bbs/Bbsa.Names.cs b/OpenKh.Bbs/Bbsa.Names.cs index cf6f43840..96b9410cc 100644 --- a/OpenKh.Bbs/Bbsa.Names.cs +++ b/OpenKh.Bbs/Bbsa.Names.cs @@ -1,32 +1,32 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Bbs -{ - public partial class Bbsa - { - protected static Dictionary NameDictionary = - TryReadLines(Path.Combine(Path.GetDirectoryName(AppContext.BaseDirectory), "resources/bbsa.txt")) - .ToDictionary(x => GetHash(x), x => x); - - private static IEnumerable TryReadLines(string fileName) => - File.Exists(fileName) ? ReadLines(fileName) : new string[0]; - - private static IEnumerable ReadLines(string fileName) - { - using (var stream = File.OpenText(fileName)) - { - while (true) - { - var line = stream.ReadLine(); - if (line == null) - break; - - yield return line; - } - } - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Bbs +{ + public partial class Bbsa + { + protected static Dictionary NameDictionary = + TryReadLines(Path.Combine(Path.GetDirectoryName(AppContext.BaseDirectory), "resources/bbsa.txt")) + .ToDictionary(x => GetHash(x), x => x); + + private static IEnumerable TryReadLines(string fileName) => + File.Exists(fileName) ? ReadLines(fileName) : new string[0]; + + private static IEnumerable ReadLines(string fileName) + { + using (var stream = File.OpenText(fileName)) + { + while (true) + { + var line = stream.ReadLine(); + if (line == null) + break; + + yield return line; + } + } + } + } +} diff --git a/OpenKh.Bbs/Bbsa.Partition.cs b/OpenKh.Bbs/Bbsa.Partition.cs index f617e1456..b5750d85b 100644 --- a/OpenKh.Bbs/Bbsa.Partition.cs +++ b/OpenKh.Bbs/Bbsa.Partition.cs @@ -1,115 +1,115 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Bbs -{ - public partial class Bbsa - { - protected interface ILba - { - uint Hash { get; } - } - - protected class Partition where TLba : ILba - { - [Data] public uint Name { get; set; } - [Data] public short Count { get; set; } - [Data] public short Offset { get; set; } - public TLba[] Lba { get; set; } - - public override string ToString() => - $"{Name:X08} {Count:X04} {Offset:X04}"; - } - - protected class PartitionFileEntry : ILba - { - [Data] public uint Hash { get; set; } - [Data] public uint Info { get; set; } - public int Offset => (int)(Info >> 12); - public int Size => (int)(Info & 0xFFF); - - public override string ToString() => - $"{Hash:X08} {Offset:X06} {Size:X03}"; - - internal static PartitionFileEntry Read(Stream stream) => - BinaryMapping.ReadObject(stream); - } - - protected class ArchivePartitionEntry : ILba - { - [Data] public uint Hash { get; set; } - [Data] public short Offset { get; set; } - [Data] public byte Count { get; set; } - [Data] public byte Unknown { get; set; } - public ArcEntry[] UnknownItems { get; set; } - - public override string ToString() => - $"{Hash:X08} {Offset:X04} {Count:X02} {Unknown:X02}"; - - internal static ArchivePartitionEntry Read(Stream stream) => - BinaryMapping.ReadObject(stream); - } - - protected class ArcEntry - { - [Data] public short Unknown00 { get; set; } - [Data] public uint Hash { get; set; } - - public override string ToString() => - $"{Hash:X08} {Unknown00:X04}"; - - internal static ArcEntry Read(Stream stream) => - BinaryMapping.ReadObject(stream); - } - - private static Partition[] ReadPartitions(Stream stream, int offset, int count) - where TLba : ILba - { - stream.Position = offset; - return Enumerable.Range(0, count) - .Select(x => ReadPartition(stream)) - .ToArray(); - } - - private static Partition ReadPartition(Stream stream) - where TLba : ILba => - BinaryMapping.ReadObject>(stream); - - private static void ReadPartitionLba(IEnumerable> partitions, Stream stream, int baseOffset) - { - stream.Position = baseOffset; - foreach (var partition in partitions) - { - stream.Position = baseOffset + partition.Offset * LbaLength; - partition.Lba = Enumerable.Range(0, partition.Count) - .Select(x => PartitionFileEntry.Read(stream)).ToArray(); - } - } - - private static void ReadPartitionLba(IEnumerable> partitions, Stream stream, int baseOffset) - { - stream.Position = baseOffset; - foreach (var partition in partitions) - { - stream.Position = baseOffset + partition.Offset * LbaLength; - partition.Lba = Enumerable.Range(0, partition.Count) - .Select(x => ArchivePartitionEntry.Read(stream)).ToArray(); - } - } - - private static void ReadUnknownStruct(IEnumerable> partitions, Stream stream, int baseOffset) - { - foreach (var partition in partitions) - { - foreach (var lba in partition.Lba) - { - stream.Position = baseOffset + lba.Offset * 6; - lba.UnknownItems = Enumerable.Range(0, lba.Count) - .Select(x => ArcEntry.Read(stream)).ToArray(); - } - } - } - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Bbs +{ + public partial class Bbsa + { + protected interface ILba + { + uint Hash { get; } + } + + protected class Partition where TLba : ILba + { + [Data] public uint Name { get; set; } + [Data] public short Count { get; set; } + [Data] public short Offset { get; set; } + public TLba[] Lba { get; set; } + + public override string ToString() => + $"{Name:X08} {Count:X04} {Offset:X04}"; + } + + protected class PartitionFileEntry : ILba + { + [Data] public uint Hash { get; set; } + [Data] public uint Info { get; set; } + public int Offset => (int)(Info >> 12); + public int Size => (int)(Info & 0xFFF); + + public override string ToString() => + $"{Hash:X08} {Offset:X06} {Size:X03}"; + + internal static PartitionFileEntry Read(Stream stream) => + BinaryMapping.ReadObject(stream); + } + + protected class ArchivePartitionEntry : ILba + { + [Data] public uint Hash { get; set; } + [Data] public short Offset { get; set; } + [Data] public byte Count { get; set; } + [Data] public byte Unknown { get; set; } + public ArcEntry[] UnknownItems { get; set; } + + public override string ToString() => + $"{Hash:X08} {Offset:X04} {Count:X02} {Unknown:X02}"; + + internal static ArchivePartitionEntry Read(Stream stream) => + BinaryMapping.ReadObject(stream); + } + + protected class ArcEntry + { + [Data] public short Unknown00 { get; set; } + [Data] public uint Hash { get; set; } + + public override string ToString() => + $"{Hash:X08} {Unknown00:X04}"; + + internal static ArcEntry Read(Stream stream) => + BinaryMapping.ReadObject(stream); + } + + private static Partition[] ReadPartitions(Stream stream, int offset, int count) + where TLba : ILba + { + stream.Position = offset; + return Enumerable.Range(0, count) + .Select(x => ReadPartition(stream)) + .ToArray(); + } + + private static Partition ReadPartition(Stream stream) + where TLba : ILba => + BinaryMapping.ReadObject>(stream); + + private static void ReadPartitionLba(IEnumerable> partitions, Stream stream, int baseOffset) + { + stream.Position = baseOffset; + foreach (var partition in partitions) + { + stream.Position = baseOffset + partition.Offset * LbaLength; + partition.Lba = Enumerable.Range(0, partition.Count) + .Select(x => PartitionFileEntry.Read(stream)).ToArray(); + } + } + + private static void ReadPartitionLba(IEnumerable> partitions, Stream stream, int baseOffset) + { + stream.Position = baseOffset; + foreach (var partition in partitions) + { + stream.Position = baseOffset + partition.Offset * LbaLength; + partition.Lba = Enumerable.Range(0, partition.Count) + .Select(x => ArchivePartitionEntry.Read(stream)).ToArray(); + } + } + + private static void ReadUnknownStruct(IEnumerable> partitions, Stream stream, int baseOffset) + { + foreach (var partition in partitions) + { + foreach (var lba in partition.Lba) + { + stream.Position = baseOffset + lba.Offset * 6; + lba.UnknownItems = Enumerable.Range(0, lba.Count) + .Select(x => ArcEntry.Read(stream)).ToArray(); + } + } + } + } +} diff --git a/OpenKh.Bbs/Bbsa.cs b/OpenKh.Bbs/Bbsa.cs index 1044a8805..a4c88b984 100644 --- a/OpenKh.Bbs/Bbsa.cs +++ b/OpenKh.Bbs/Bbsa.cs @@ -1,253 +1,253 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Bbs -{ - public partial class Bbsa - { - protected static string[] KnownExtensions = new string[] { - "Arc", "Bin", "Tm2", "Pmo", - "Pam", "Pmp", "Pvd", "Bcd", - "Fep", "Frr", "Ead", "Ese", - "Lub", "Lad", "L2d", "Pst", - "Epd", "Olo", "Bep", "Txa", - "Aac", "Abc", "Scd", "Bsd", - "Seb", "Ctd", "Ecm", "Ept", - "Mss", "Nmd", "Ite", "Itb", - "Itc", "Bdd", "Bdc", "Ngd", - "Exb", "Gpd", "Exa", "Esd", - "MTX", "INF", "COD", "CLU", - "PMF", "ESE", "PTX", "" - }; - - protected static Dictionary Paths = new Dictionary - { - [0x0050414D] = "arc/map", - [0x4E455645] = "arc/event", - [0x00004350] = "arc/pc", - [0x10004350] = "arc/pc_ven", - [0x20004350] = "arc/pc_aqua", - [0x30004350] = "arc/pc_terra", - [0x4D454E45] = "arc/enemy", - [0x53534F42] = "arc/boss", - [0x0043504E] = "arc/npc", - [0x4D4D4947] = "arc/gimmick", - [0x50414557] = "arc/weapon", - [0x4D455449] = "arc/item", - [0x45464645] = "arc/effect", - [0x554E454D] = "arc/menu", - [0x00435445] = "arc/etc", - [0x00535953] = "arc/system", - [0x53455250] = "arc/preset", - [0x41455250] = "arc/preset.alpha", - [0x55424544] = "arc/debug", - }; - - protected static Dictionary PathCategories = new Dictionary - { - [0x00] = "arc_", - [0x80] = "sound/bgm", - [0xC0] = "lua", - [0x90] = "sound/se/common", - [0x91] = "sound/se/event/{1}", - [0x92] = "sound/se/footstep/{1}", - [0x93] = "sound/se/enemy", - [0x94] = "sound/se/weapon", - [0x95] = "sound/se/act", - [0xA1] = "sound/voice/{0}/event/{1}", - [0xAA] = "sound/voice/{0}/battle", - [0xD0] = "message/{0}/system", - [0xD1] = "message/{0}/map", - [0xD2] = "message/{0}/menu", - [0xD3] = "message/{0}/event", - [0xD4] = "message/{0}/mission", - [0xD5] = "message/{0}/npc_talk/{1}", - [0xD6] = "message/{0}/network", - [0xD7] = "message/{0}/battledice", - [0xD8] = "message/{0}/minigame", - [0xD9] = "message/{0}/shop", - [0xDA] = "message/{0}/playerselect", - [0xDB] = "message/{0}/report", - }; - - protected static Dictionary PathCategoriesReverse = PathCategories - .SelectMany(x => - Constants.Language.Select((l, i) => new - { - Key = (x.Key << 24) | (i << 21), - Value = x.Value.Replace("{0}", l) - }) - ) - .SelectMany(x => - Constants.Worlds.Select((w, i) => new - { - Key = x.Key | (i << 16), - Value = x.Value.Replace("{1}", w) - }) - ) - .GroupBy(x => x.Value) - .ToDictionary(x => x.Key, x => (uint)x.First().Key); - - protected static Dictionary PathsReverse = - Paths.ToDictionary(x => x.Value, x => x.Key); - - protected static string[] AllPaths = - PathsReverse - .Select(x => (x.Key + '/').ToUpper()) - .Concat(new string[] { string.Empty }) - .ToArray(); - - protected static string[] KnownExtensionsWithDot = - KnownExtensions.Select(x => ('.' + x).ToUpper()).ToArray(); - - protected class Header - { - [Data] public int MagicCode { get; set; } - [Data] public int Version { get; set; } - [Data] public short PartitionCount { get; set; } - [Data] public short Unk0a { get; set; } - [Data] public short Unk0c { get; set; } - [Data] public short DirectoryCount { get; set; } - [Data] public int PartitionOffset { get; set; } - [Data] public int DirectoryOffset { get; set; } - [Data] public short ArchivePartitionSector { get; set; } - [Data] public short Archive0Sector { get; set; } - [Data] public int TotalSectorCount { get; set; } - [Data] public int Archive1Sector { get; set; } - [Data] public int Archive2Sector { get; set; } - [Data] public int Archive3Sector { get; set; } - [Data] public int Archive4Sector { get; set; } - public Partition[] Partitions { get; set; } - } - - protected class ArchivePartitionHeader - { - [Data] public byte Unknown00 { get; set; } - [Data] public byte PartitionCount { get; set; } - [Data] public short Unknown02 { get; set; } - [Data] public short LbaStartOffset { get; set; } - [Data] public short UnknownOffset { get; set; } - public Partition[] Partitions { get; set; } - } - - protected class DirectoryEntry - { - public uint FileHash { get; set; } - public uint Info { get; set; } - public uint DirectoryHash { get; set; } - public int Offset => (int)(Info >> 12); - public int Size => (int)(Info & 0xFFF); - - public override string ToString() => - $"{DirectoryHash:X08}/{FileHash:X08} {Offset:X05} {Size:X03}"; - } - - private const int LbaLength = 8; - protected readonly Header _header; - protected readonly ArchivePartitionHeader _header2; - protected readonly DirectoryEntry[] _directoryEntries; - - protected Bbsa(Stream stream) - { - _header = BinaryMapping.ReadObject
(stream, (int)stream.Position); - _header.Partitions = ReadPartitions(stream, 0x30, _header.PartitionCount); - ReadPartitionLba(_header.Partitions, stream, _header.PartitionOffset); - - stream.Position = _header.DirectoryOffset; - var reader = new BinaryReader(stream); - _directoryEntries = Enumerable.Range(0, _header.DirectoryCount) - .Select(x => new DirectoryEntry - { - FileHash = reader.ReadUInt32(), - Info = reader.ReadUInt32(), - DirectoryHash = reader.ReadUInt32() - }).ToArray(); - - int header2Offset = _header.ArchivePartitionSector * 0x800; - stream.Position = header2Offset; - _header2 = BinaryMapping.ReadObject(stream); - _header2.Partitions = ReadPartitions(stream, header2Offset + 8, _header2.PartitionCount); - ReadPartitionLba(_header2.Partitions, stream, header2Offset + _header2.LbaStartOffset); - ReadUnknownStruct(_header2.Partitions, stream, header2Offset + _header2.UnknownOffset); - } - - public IEnumerable Files - { - get - { - foreach (var partition in _header.Partitions) - { - Paths.TryGetValue(partition.Name, out var folder); - - foreach (var lba in partition.Lba) - { - NameDictionary.TryGetValue(lba.Hash, out var fileName); - - yield return new Entry( - this, - lba.Offset, - lba.Size, - fileName, - folder, - lba.Hash, - 0); - } - } - - foreach (var file in _directoryEntries) - { - NameDictionary.TryGetValue(file.FileHash, out var fileName); - NameDictionary.TryGetValue(file.DirectoryHash, out var folderName); - - yield return new Entry( - this, - file.Offset, - file.Size, - fileName, - folderName, - file.FileHash, - file.DirectoryHash); - } - } - } - - public int GetOffset(string fileName) - { - var directory = Path.GetDirectoryName(fileName).Replace('\\', '/'); - var file = Path.GetFileName(fileName); - var name = Path.GetFileNameWithoutExtension(file); - - if (!PathsReverse.TryGetValue(directory, out var pathId)) - return -1; - - var pathInfo = _header.Partitions.FirstOrDefault(x => x.Name == pathId); - if (pathInfo == null) - return -1; - - var hash = GetHash(name.ToUpper()); - var lba = pathInfo.Lba.FirstOrDefault(x => x.Hash == hash); - if (lba == null) - return -1; - - return (lba.Offset + _header.Archive0Sector) * 0x800; - } - - public static Bbsa Read(Stream stream) => new Bbsa(stream); - - public static string GetDirectoryName(uint hash) => - Paths.TryGetValue(hash, out var path) ? path : CalculateFolderName(hash); - - public static uint GetDirectoryHash(string directory) - { - if (PathsReverse.TryGetValue(directory.ToLower(), out var hash)) - return (uint)hash; - - if (PathCategoriesReverse.TryGetValue(directory.ToLower(), out hash)) - return (uint)hash; - - return uint.MaxValue; - } - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Bbs +{ + public partial class Bbsa + { + protected static string[] KnownExtensions = new string[] { + "Arc", "Bin", "Tm2", "Pmo", + "Pam", "Pmp", "Pvd", "Bcd", + "Fep", "Frr", "Ead", "Ese", + "Lub", "Lad", "L2d", "Pst", + "Epd", "Olo", "Bep", "Txa", + "Aac", "Abc", "Scd", "Bsd", + "Seb", "Ctd", "Ecm", "Ept", + "Mss", "Nmd", "Ite", "Itb", + "Itc", "Bdd", "Bdc", "Ngd", + "Exb", "Gpd", "Exa", "Esd", + "MTX", "INF", "COD", "CLU", + "PMF", "ESE", "PTX", "" + }; + + protected static Dictionary Paths = new Dictionary + { + [0x0050414D] = "arc/map", + [0x4E455645] = "arc/event", + [0x00004350] = "arc/pc", + [0x10004350] = "arc/pc_ven", + [0x20004350] = "arc/pc_aqua", + [0x30004350] = "arc/pc_terra", + [0x4D454E45] = "arc/enemy", + [0x53534F42] = "arc/boss", + [0x0043504E] = "arc/npc", + [0x4D4D4947] = "arc/gimmick", + [0x50414557] = "arc/weapon", + [0x4D455449] = "arc/item", + [0x45464645] = "arc/effect", + [0x554E454D] = "arc/menu", + [0x00435445] = "arc/etc", + [0x00535953] = "arc/system", + [0x53455250] = "arc/preset", + [0x41455250] = "arc/preset.alpha", + [0x55424544] = "arc/debug", + }; + + protected static Dictionary PathCategories = new Dictionary + { + [0x00] = "arc_", + [0x80] = "sound/bgm", + [0xC0] = "lua", + [0x90] = "sound/se/common", + [0x91] = "sound/se/event/{1}", + [0x92] = "sound/se/footstep/{1}", + [0x93] = "sound/se/enemy", + [0x94] = "sound/se/weapon", + [0x95] = "sound/se/act", + [0xA1] = "sound/voice/{0}/event/{1}", + [0xAA] = "sound/voice/{0}/battle", + [0xD0] = "message/{0}/system", + [0xD1] = "message/{0}/map", + [0xD2] = "message/{0}/menu", + [0xD3] = "message/{0}/event", + [0xD4] = "message/{0}/mission", + [0xD5] = "message/{0}/npc_talk/{1}", + [0xD6] = "message/{0}/network", + [0xD7] = "message/{0}/battledice", + [0xD8] = "message/{0}/minigame", + [0xD9] = "message/{0}/shop", + [0xDA] = "message/{0}/playerselect", + [0xDB] = "message/{0}/report", + }; + + protected static Dictionary PathCategoriesReverse = PathCategories + .SelectMany(x => + Constants.Language.Select((l, i) => new + { + Key = (x.Key << 24) | (i << 21), + Value = x.Value.Replace("{0}", l) + }) + ) + .SelectMany(x => + Constants.Worlds.Select((w, i) => new + { + Key = x.Key | (i << 16), + Value = x.Value.Replace("{1}", w) + }) + ) + .GroupBy(x => x.Value) + .ToDictionary(x => x.Key, x => (uint)x.First().Key); + + protected static Dictionary PathsReverse = + Paths.ToDictionary(x => x.Value, x => x.Key); + + protected static string[] AllPaths = + PathsReverse + .Select(x => (x.Key + '/').ToUpper()) + .Concat(new string[] { string.Empty }) + .ToArray(); + + protected static string[] KnownExtensionsWithDot = + KnownExtensions.Select(x => ('.' + x).ToUpper()).ToArray(); + + protected class Header + { + [Data] public int MagicCode { get; set; } + [Data] public int Version { get; set; } + [Data] public short PartitionCount { get; set; } + [Data] public short Unk0a { get; set; } + [Data] public short Unk0c { get; set; } + [Data] public short DirectoryCount { get; set; } + [Data] public int PartitionOffset { get; set; } + [Data] public int DirectoryOffset { get; set; } + [Data] public short ArchivePartitionSector { get; set; } + [Data] public short Archive0Sector { get; set; } + [Data] public int TotalSectorCount { get; set; } + [Data] public int Archive1Sector { get; set; } + [Data] public int Archive2Sector { get; set; } + [Data] public int Archive3Sector { get; set; } + [Data] public int Archive4Sector { get; set; } + public Partition[] Partitions { get; set; } + } + + protected class ArchivePartitionHeader + { + [Data] public byte Unknown00 { get; set; } + [Data] public byte PartitionCount { get; set; } + [Data] public short Unknown02 { get; set; } + [Data] public short LbaStartOffset { get; set; } + [Data] public short UnknownOffset { get; set; } + public Partition[] Partitions { get; set; } + } + + protected class DirectoryEntry + { + public uint FileHash { get; set; } + public uint Info { get; set; } + public uint DirectoryHash { get; set; } + public int Offset => (int)(Info >> 12); + public int Size => (int)(Info & 0xFFF); + + public override string ToString() => + $"{DirectoryHash:X08}/{FileHash:X08} {Offset:X05} {Size:X03}"; + } + + private const int LbaLength = 8; + protected readonly Header _header; + protected readonly ArchivePartitionHeader _header2; + protected readonly DirectoryEntry[] _directoryEntries; + + protected Bbsa(Stream stream) + { + _header = BinaryMapping.ReadObject
(stream, (int)stream.Position); + _header.Partitions = ReadPartitions(stream, 0x30, _header.PartitionCount); + ReadPartitionLba(_header.Partitions, stream, _header.PartitionOffset); + + stream.Position = _header.DirectoryOffset; + var reader = new BinaryReader(stream); + _directoryEntries = Enumerable.Range(0, _header.DirectoryCount) + .Select(x => new DirectoryEntry + { + FileHash = reader.ReadUInt32(), + Info = reader.ReadUInt32(), + DirectoryHash = reader.ReadUInt32() + }).ToArray(); + + int header2Offset = _header.ArchivePartitionSector * 0x800; + stream.Position = header2Offset; + _header2 = BinaryMapping.ReadObject(stream); + _header2.Partitions = ReadPartitions(stream, header2Offset + 8, _header2.PartitionCount); + ReadPartitionLba(_header2.Partitions, stream, header2Offset + _header2.LbaStartOffset); + ReadUnknownStruct(_header2.Partitions, stream, header2Offset + _header2.UnknownOffset); + } + + public IEnumerable Files + { + get + { + foreach (var partition in _header.Partitions) + { + Paths.TryGetValue(partition.Name, out var folder); + + foreach (var lba in partition.Lba) + { + NameDictionary.TryGetValue(lba.Hash, out var fileName); + + yield return new Entry( + this, + lba.Offset, + lba.Size, + fileName, + folder, + lba.Hash, + 0); + } + } + + foreach (var file in _directoryEntries) + { + NameDictionary.TryGetValue(file.FileHash, out var fileName); + NameDictionary.TryGetValue(file.DirectoryHash, out var folderName); + + yield return new Entry( + this, + file.Offset, + file.Size, + fileName, + folderName, + file.FileHash, + file.DirectoryHash); + } + } + } + + public int GetOffset(string fileName) + { + var directory = Path.GetDirectoryName(fileName).Replace('\\', '/'); + var file = Path.GetFileName(fileName); + var name = Path.GetFileNameWithoutExtension(file); + + if (!PathsReverse.TryGetValue(directory, out var pathId)) + return -1; + + var pathInfo = _header.Partitions.FirstOrDefault(x => x.Name == pathId); + if (pathInfo == null) + return -1; + + var hash = GetHash(name.ToUpper()); + var lba = pathInfo.Lba.FirstOrDefault(x => x.Hash == hash); + if (lba == null) + return -1; + + return (lba.Offset + _header.Archive0Sector) * 0x800; + } + + public static Bbsa Read(Stream stream) => new Bbsa(stream); + + public static string GetDirectoryName(uint hash) => + Paths.TryGetValue(hash, out var path) ? path : CalculateFolderName(hash); + + public static uint GetDirectoryHash(string directory) + { + if (PathsReverse.TryGetValue(directory.ToLower(), out var hash)) + return (uint)hash; + + if (PathCategoriesReverse.TryGetValue(directory.ToLower(), out hash)) + return (uint)hash; + + return uint.MaxValue; + } + } +} diff --git a/OpenKh.Bbs/Bep.cs b/OpenKh.Bbs/Bep.cs index 823b5dbf6..665a9536f 100644 --- a/OpenKh.Bbs/Bep.cs +++ b/OpenKh.Bbs/Bep.cs @@ -1,83 +1,83 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Bbs -{ - public class Bep - { - private const uint MagicCode = 0x50454240; - private const uint version = 2; - - public class Header - { - [Data] public uint MagicCode { get; set; } - [Data] public uint version { get; set; } - [Data] public uint BaseParametersCount { get; set; } - [Data] public uint BaseParametersOffset { get; set; } - [Data] public uint DisappearParametersCount { get; set; } - [Data] public uint DisappearParametersOffset { get; set; } - } - - public class BaseParameter - { - [Data] public ushort BattleLevel { get; set; } - [Data] public ushort BaseAttack { get; set; } - [Data] public ushort Defense { get; set; } - [Data] public byte DamageCeiling { get; set; } - [Data] public byte DamageFloor { get; set; } - [Data] public uint BaseHP { get; set; } - [Data] public uint BaseEXP { get; set; } - } - - public class DisappearParameter - { - [Data] public ushort WorldID { get; set; } - [Data] public ushort RoomID { get; set; } - [Data] public float Distance { get; set; } - } - - public Header header = new Header(); - public List baseParameters = new List(); - public List disappearParameters = new List(); - - public static Bep Read(Stream stream) - { - Bep bep = new Bep(); - bep.header = BinaryMapping.ReadObject
(stream); - - stream.Seek(bep.header.BaseParametersOffset, SeekOrigin.Begin); - bep.baseParameters = new List(); - for(int c = 0; c < bep.header.BaseParametersCount; c++) - { - bep.baseParameters.Add(BinaryMapping.ReadObject(stream)); - } - - stream.Seek(bep.header.DisappearParametersOffset, SeekOrigin.Begin); - bep.disappearParameters = new List(); - for (int d = 0; d < bep.header.DisappearParametersCount; d++) - { - bep.disappearParameters.Add(BinaryMapping.ReadObject(stream)); - } - - return bep; - } - - public static void Write(Stream stream, Bep bep) - { - BinaryMapping.WriteObject
(stream, bep.header); - - for (int c = 0; c < bep.disappearParameters.Count; c++) - { - BinaryMapping.WriteObject(stream, bep.baseParameters[c]); - } - - for (int d = 0; d < bep.disappearParameters.Count; d++) - { - BinaryMapping.WriteObject(stream, bep.disappearParameters[d]); - } - } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Bbs +{ + public class Bep + { + private const uint MagicCode = 0x50454240; + private const uint version = 2; + + public class Header + { + [Data] public uint MagicCode { get; set; } + [Data] public uint version { get; set; } + [Data] public uint BaseParametersCount { get; set; } + [Data] public uint BaseParametersOffset { get; set; } + [Data] public uint DisappearParametersCount { get; set; } + [Data] public uint DisappearParametersOffset { get; set; } + } + + public class BaseParameter + { + [Data] public ushort BattleLevel { get; set; } + [Data] public ushort BaseAttack { get; set; } + [Data] public ushort Defense { get; set; } + [Data] public byte DamageCeiling { get; set; } + [Data] public byte DamageFloor { get; set; } + [Data] public uint BaseHP { get; set; } + [Data] public uint BaseEXP { get; set; } + } + + public class DisappearParameter + { + [Data] public ushort WorldID { get; set; } + [Data] public ushort RoomID { get; set; } + [Data] public float Distance { get; set; } + } + + public Header header = new Header(); + public List baseParameters = new List(); + public List disappearParameters = new List(); + + public static Bep Read(Stream stream) + { + Bep bep = new Bep(); + bep.header = BinaryMapping.ReadObject
(stream); + + stream.Seek(bep.header.BaseParametersOffset, SeekOrigin.Begin); + bep.baseParameters = new List(); + for (int c = 0; c < bep.header.BaseParametersCount; c++) + { + bep.baseParameters.Add(BinaryMapping.ReadObject(stream)); + } + + stream.Seek(bep.header.DisappearParametersOffset, SeekOrigin.Begin); + bep.disappearParameters = new List(); + for (int d = 0; d < bep.header.DisappearParametersCount; d++) + { + bep.disappearParameters.Add(BinaryMapping.ReadObject(stream)); + } + + return bep; + } + + public static void Write(Stream stream, Bep bep) + { + BinaryMapping.WriteObject
(stream, bep.header); + + for (int c = 0; c < bep.disappearParameters.Count; c++) + { + BinaryMapping.WriteObject(stream, bep.baseParameters[c]); + } + + for (int d = 0; d < bep.disappearParameters.Count; d++) + { + BinaryMapping.WriteObject(stream, bep.disappearParameters[d]); + } + } + } +} diff --git a/OpenKh.Bbs/Constants.cs b/OpenKh.Bbs/Constants.cs index 32b7212e1..0aa429b4a 100644 --- a/OpenKh.Bbs/Constants.cs +++ b/OpenKh.Bbs/Constants.cs @@ -1,448 +1,448 @@ -namespace OpenKh.Bbs -{ - public class Constants - { - public static readonly string[] Worlds = - { - "ex", "dp", "sw", "cd", - "sb", "yt", "rg", "jb", - "he", "ls", "di", "pp", - "dc", "kg", "14", "vs", - "bd", "wm", "wp", "19", - "20", "21", "22", "jf", - }; - - public static readonly string[] WorldNames = - { - "Common", - "Land of Departure", - "Dwarf Woodlands", - "Castle of Dreams", - "Enchanted Dominion", - "Mysterious Tower", - "Radiant Garden", - "Dark World", - "Olympus Coliseum", - "Deep Space", - "Destiny Island", - "Never Land", - "Disney Town", - "Keyblade Graveyard", - "Mysterious Badlands (Unused)", - "Mirage Arena", - "Command Board", - "World Map", - "WP - Winnie the Pooh", - "19 - Unused", - "20 - Unused", - "21 - Unused", - "22 - Unused", - "JF - Jump Festa", - }; - - public static readonly string[] Language = - { - "jp", "en", "fr", "it", "de", "es" - }; - - public static readonly string[] Rooms_DP = - { - "The Land of Departure", - "Forecourt", - "Great Hall", - "Ventus's Room", - "Ventus's Room", - "Mountain Path", - "Summit", - "Forecourt", - "Forecourt", - "Great Hall", - "Ruins", - "Chamber of Waking", - "Castle Oblivion", - "Character Selection", - "Forecourt", - "Ruins", - "Mountain Path" - }; - - public static readonly string[] Rooms_SW = - { - "Dwarf Woodlands", - "Mine Entrance", - "The Mine", - "Vault", - "Magic Mirror Chamber", - "Underground Waterway", - "Courtyard", - "Flower Glade", - "Deep Woods", - "Inside the Mirror", - "Cottage Clearing", - "The Cottage", - "Mountain Trail" - }; - - public static readonly string[] Rooms_CD = - { - "Castle of Dreams", - "Cinderella's Room", - "Mousehole", - "Wardrobe Room", - "Entrance", - "The Chateau", - "Forest", - "Palace Courtyard", - "Corridor", - "Ballroom", - "Foyer", - "Passage", - "Antechamber", - "Wardrobe Room", - "Mousehole", - "Wardrobe Room" - }; - - public static readonly string[] Rooms_SB = - { - "Enchanted Dominion", - "Dungeon Cell", - "Gates", - "Maleficent's Throne", - "Dungeon", - "Hall", - "Forbidden Mountain", - "Waterside", - "Forest Clearing", - "Bridge", - "Bridge", - "Audience Chamber", - "Audience Chamber", - "RESERVED", - "Hallway", - "Aurora's Chamber", - "Tower Room", - "Hall", - "Aurora's Chamber", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Hall", - "Gates" - }; - - public static readonly string[] Rooms_YT = - { - "The Mysterious Tower", - "Sorcerer's Chamber", - "Mysterious Tower", - "Entrance", - "Sorcerer's Chamber" - }; - - public static readonly string[] Rooms_RG = - { - "Radiant Garden", - "Outer Garden", - "Entryway", - "Central Square", - "Aqueduct", - "Castle Town", - "Reactor", - "Fountain Court", - "Merlin's House", - "Gardens", - "Front Doors", - "Purification Facility", - "Outer Gardens", - "Central Square", - "Central Square" - }; - - public static readonly string[] Rooms_JB = - { - "FOR EVENTS ONLY", - "Louie's Ruins", - "Court", - "Path Crossroads", - "UG Ruins Entrance", - "UG Ruins Passage 1", - "UG Ruins Passage 2", - "UG Courtyard", - "Jungle Near Ruins", - "Eminence", - "Jungle", - "Man-Village River", - "Bog", - "13", - "14", - "15", - "16", - "17", - "18", - "19", - "Realm of Darkness: Middle Zone", - "Realm of Darkness: Lower Zone", - "Realm of Darkness: Upper Zone", - "The Dark Margin", - "Cinderella's Darkness Castle", - "25", - "26", - "27", - "28", - "29", - "Destiny Islands (Noon)", - "Traverse Town 2nd District", - "Traverse Town 1st District", - "Destiny Islands (Afternoon)", - "Destiny Islands (Night)", - "Traverse Town 3rd District", - "36", - "37", - "38", - "39", - "40", - "41", - "42", - "43", - "44", - "45", - "46", - "47", - "48", - "49", - "Lanes Between", - "BLANK", - "Realm of Darkness", - "FOR wm EVENT" - }; - - public static readonly string[] Rooms_HE = - { - "Olympus Coliseum", - "Coliseum Gates", - "Vestibule", - "West Bracket", - "East Bracket", - "Town Near Thebes", - "East Bracket" - - }; - - public static readonly string[] Rooms_LS = - { - "Deep Space", - "Prison Block", - "Turo Transporter", - "Durgon Transporter", - "Ship Corridor", - "Control Room", - "Containment Pod", - "Ship Hub", - "Machinery Bay", - "Launch Deck", - "Ship Exterior", - "Outer Space", - "Ship Corridor", - "Lanes Between", - "Bay Access" - }; - - public static readonly string[] Rooms_DI = - { - "Destiny Islands", - "Island Beach", - "Island Beach", - "Island Beach", - "Main Island Beach" - }; - - public static readonly string[] Rooms_PP = - { - "Neverland", - "Cove", - "Cliff", - "Mermaid Lagoon", - "Seacoast", - "Jungle Clearing", - "Peter's Hideout", - "Gully", - "Indian Camp", - "Rainbow Falls: Base", - "Rainbow Falls: Ascent", - "Rainbow Falls: Crest", - "Skull Rock: Entrance", - "Skull Rock: Cavern", - "Night Sky" - }; - - public static readonly string[] Rooms_DC = - { - "Disney Town", - "Library", - "Main Plaza", - "Fruitball Court", - "Racecourse A", - "Raceway", - "Gizmo Gallery", - "Pete's Rec Room", - "Racecourse B", - "Racecourse C", - "Racecourse D", - "Lanes Between", - "Raceway Registration", - "Ice Cream", - "Fruitball", - "Race: Castle Course" - }; - - public static readonly string[] Rooms_KG = - { - "Keyblade Graveyard", - "Badlands", - "Seat of War", - "Twister Trench", - "Eye of the Storm", - "Eye of the Storm", - "Eye of the Storm", - "Fissure", - "Keyblade Graveyard", - "Keyblade Graveyard", - "Keyblade Graveyard", - "Will's Cage", - "Keyblade Graveyard", - "13", - "14", - "15", - "16", - "17", - "18", - "19", - "20", - "21", - "22", - "23", - "24", - "25", - "26", - "27", - "28", - "29", - "30", - "31", - "32", - "33", - "34", - "35", - "36", - "37", - "38", - "39", - "40", - "41", - "42", - "43", - "44", - "45", - "46", - "47", - "48", - "49", - "Ventus's Mind", - "Ventus's Mind", - "Ventus's Mind", - "Sora's Mind", - "Terra-Xehanort's Mind", - "Keyblade Graveyard", - "Badlands" - }; - - public static readonly string[] Rooms_VS = - { - "Mirage Arena", - "Hub", - "Coliseum", - "Arena", - "Badlands", - "Pinball", - "Ship Hub", - "Mousehole", - "Forest", - "Skull Rock", - "Audience Chamber", - "Forecourt", - "Summit", - "Launch Deck", - "Ship Exterior", - "Arena", - "Great Hall (Noon)", - "Monstro (Interior A)", - "Monstro (Exterior)", - "Monstrio (Interior B)", - "Summit (Broken)" - }; - - public static readonly string[] Rooms_BD = - { - "Command Board", - "Land of Departure BG", - "02", - "Cinderella BG", - "04", - "05", - "06", - "07", - "08", - "Lilo & Stitch BG", - "10", - "Peter Pan BG", - "Disney Castle BG", - "13", - "14", - "15", - "16", - "17", - "Winnie the Pooh BG", - "Peter Pan BG" - }; - - public static readonly string[] Rooms_WM = - { - "World Map", - "wm01" - }; - - public static readonly string[] Rooms_JF = - { - "Jump Festa (sw10)", - "Jump Festa (cd07)", - "Jump Festa (cd09)", - "Jump Festa (sb10)", - "04", - "05", - "06", - "07", - "08", - "09", - "The Town", - "Poly Partition Test", - "12" - }; - } -} +namespace OpenKh.Bbs +{ + public class Constants + { + public static readonly string[] Worlds = + { + "ex", "dp", "sw", "cd", + "sb", "yt", "rg", "jb", + "he", "ls", "di", "pp", + "dc", "kg", "14", "vs", + "bd", "wm", "wp", "19", + "20", "21", "22", "jf", + }; + + public static readonly string[] WorldNames = + { + "Common", + "Land of Departure", + "Dwarf Woodlands", + "Castle of Dreams", + "Enchanted Dominion", + "Mysterious Tower", + "Radiant Garden", + "Dark World", + "Olympus Coliseum", + "Deep Space", + "Destiny Island", + "Never Land", + "Disney Town", + "Keyblade Graveyard", + "Mysterious Badlands (Unused)", + "Mirage Arena", + "Command Board", + "World Map", + "WP - Winnie the Pooh", + "19 - Unused", + "20 - Unused", + "21 - Unused", + "22 - Unused", + "JF - Jump Festa", + }; + + public static readonly string[] Language = + { + "jp", "en", "fr", "it", "de", "es" + }; + + public static readonly string[] Rooms_DP = + { + "The Land of Departure", + "Forecourt", + "Great Hall", + "Ventus's Room", + "Ventus's Room", + "Mountain Path", + "Summit", + "Forecourt", + "Forecourt", + "Great Hall", + "Ruins", + "Chamber of Waking", + "Castle Oblivion", + "Character Selection", + "Forecourt", + "Ruins", + "Mountain Path" + }; + + public static readonly string[] Rooms_SW = + { + "Dwarf Woodlands", + "Mine Entrance", + "The Mine", + "Vault", + "Magic Mirror Chamber", + "Underground Waterway", + "Courtyard", + "Flower Glade", + "Deep Woods", + "Inside the Mirror", + "Cottage Clearing", + "The Cottage", + "Mountain Trail" + }; + + public static readonly string[] Rooms_CD = + { + "Castle of Dreams", + "Cinderella's Room", + "Mousehole", + "Wardrobe Room", + "Entrance", + "The Chateau", + "Forest", + "Palace Courtyard", + "Corridor", + "Ballroom", + "Foyer", + "Passage", + "Antechamber", + "Wardrobe Room", + "Mousehole", + "Wardrobe Room" + }; + + public static readonly string[] Rooms_SB = + { + "Enchanted Dominion", + "Dungeon Cell", + "Gates", + "Maleficent's Throne", + "Dungeon", + "Hall", + "Forbidden Mountain", + "Waterside", + "Forest Clearing", + "Bridge", + "Bridge", + "Audience Chamber", + "Audience Chamber", + "RESERVED", + "Hallway", + "Aurora's Chamber", + "Tower Room", + "Hall", + "Aurora's Chamber", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Hall", + "Gates" + }; + + public static readonly string[] Rooms_YT = + { + "The Mysterious Tower", + "Sorcerer's Chamber", + "Mysterious Tower", + "Entrance", + "Sorcerer's Chamber" + }; + + public static readonly string[] Rooms_RG = + { + "Radiant Garden", + "Outer Garden", + "Entryway", + "Central Square", + "Aqueduct", + "Castle Town", + "Reactor", + "Fountain Court", + "Merlin's House", + "Gardens", + "Front Doors", + "Purification Facility", + "Outer Gardens", + "Central Square", + "Central Square" + }; + + public static readonly string[] Rooms_JB = + { + "FOR EVENTS ONLY", + "Louie's Ruins", + "Court", + "Path Crossroads", + "UG Ruins Entrance", + "UG Ruins Passage 1", + "UG Ruins Passage 2", + "UG Courtyard", + "Jungle Near Ruins", + "Eminence", + "Jungle", + "Man-Village River", + "Bog", + "13", + "14", + "15", + "16", + "17", + "18", + "19", + "Realm of Darkness: Middle Zone", + "Realm of Darkness: Lower Zone", + "Realm of Darkness: Upper Zone", + "The Dark Margin", + "Cinderella's Darkness Castle", + "25", + "26", + "27", + "28", + "29", + "Destiny Islands (Noon)", + "Traverse Town 2nd District", + "Traverse Town 1st District", + "Destiny Islands (Afternoon)", + "Destiny Islands (Night)", + "Traverse Town 3rd District", + "36", + "37", + "38", + "39", + "40", + "41", + "42", + "43", + "44", + "45", + "46", + "47", + "48", + "49", + "Lanes Between", + "BLANK", + "Realm of Darkness", + "FOR wm EVENT" + }; + + public static readonly string[] Rooms_HE = + { + "Olympus Coliseum", + "Coliseum Gates", + "Vestibule", + "West Bracket", + "East Bracket", + "Town Near Thebes", + "East Bracket" + + }; + + public static readonly string[] Rooms_LS = + { + "Deep Space", + "Prison Block", + "Turo Transporter", + "Durgon Transporter", + "Ship Corridor", + "Control Room", + "Containment Pod", + "Ship Hub", + "Machinery Bay", + "Launch Deck", + "Ship Exterior", + "Outer Space", + "Ship Corridor", + "Lanes Between", + "Bay Access" + }; + + public static readonly string[] Rooms_DI = + { + "Destiny Islands", + "Island Beach", + "Island Beach", + "Island Beach", + "Main Island Beach" + }; + + public static readonly string[] Rooms_PP = + { + "Neverland", + "Cove", + "Cliff", + "Mermaid Lagoon", + "Seacoast", + "Jungle Clearing", + "Peter's Hideout", + "Gully", + "Indian Camp", + "Rainbow Falls: Base", + "Rainbow Falls: Ascent", + "Rainbow Falls: Crest", + "Skull Rock: Entrance", + "Skull Rock: Cavern", + "Night Sky" + }; + + public static readonly string[] Rooms_DC = + { + "Disney Town", + "Library", + "Main Plaza", + "Fruitball Court", + "Racecourse A", + "Raceway", + "Gizmo Gallery", + "Pete's Rec Room", + "Racecourse B", + "Racecourse C", + "Racecourse D", + "Lanes Between", + "Raceway Registration", + "Ice Cream", + "Fruitball", + "Race: Castle Course" + }; + + public static readonly string[] Rooms_KG = + { + "Keyblade Graveyard", + "Badlands", + "Seat of War", + "Twister Trench", + "Eye of the Storm", + "Eye of the Storm", + "Eye of the Storm", + "Fissure", + "Keyblade Graveyard", + "Keyblade Graveyard", + "Keyblade Graveyard", + "Will's Cage", + "Keyblade Graveyard", + "13", + "14", + "15", + "16", + "17", + "18", + "19", + "20", + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + "29", + "30", + "31", + "32", + "33", + "34", + "35", + "36", + "37", + "38", + "39", + "40", + "41", + "42", + "43", + "44", + "45", + "46", + "47", + "48", + "49", + "Ventus's Mind", + "Ventus's Mind", + "Ventus's Mind", + "Sora's Mind", + "Terra-Xehanort's Mind", + "Keyblade Graveyard", + "Badlands" + }; + + public static readonly string[] Rooms_VS = + { + "Mirage Arena", + "Hub", + "Coliseum", + "Arena", + "Badlands", + "Pinball", + "Ship Hub", + "Mousehole", + "Forest", + "Skull Rock", + "Audience Chamber", + "Forecourt", + "Summit", + "Launch Deck", + "Ship Exterior", + "Arena", + "Great Hall (Noon)", + "Monstro (Interior A)", + "Monstro (Exterior)", + "Monstrio (Interior B)", + "Summit (Broken)" + }; + + public static readonly string[] Rooms_BD = + { + "Command Board", + "Land of Departure BG", + "02", + "Cinderella BG", + "04", + "05", + "06", + "07", + "08", + "Lilo & Stitch BG", + "10", + "Peter Pan BG", + "Disney Castle BG", + "13", + "14", + "15", + "16", + "17", + "Winnie the Pooh BG", + "Peter Pan BG" + }; + + public static readonly string[] Rooms_WM = + { + "World Map", + "wm01" + }; + + public static readonly string[] Rooms_JF = + { + "Jump Festa (sw10)", + "Jump Festa (cd07)", + "Jump Festa (cd09)", + "Jump Festa (sb10)", + "04", + "05", + "06", + "07", + "08", + "09", + "The Town", + "Poly Partition Test", + "12" + }; + } +} diff --git a/OpenKh.Bbs/Ctd.cs b/OpenKh.Bbs/Ctd.cs index 35834cc1b..f81a8cb2a 100644 --- a/OpenKh.Bbs/Ctd.cs +++ b/OpenKh.Bbs/Ctd.cs @@ -1,201 +1,201 @@ -using OpenKh.Bbs.Messages; -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Bbs -{ - public class Ctd - { - private const int MagicCode = 0x44544340; - private const int Version = 1; - private const int HeaderLength = 0x20; - private const int Entry1Length = 0xC; - private const int Entry2Length = 0x20; - - private class Header - { - [Data] public int MagicCode { get; set; } - [Data] public int Version { get; set; } - [Data] public short Unknown08 { get; set; } - [Data] public short Unknown0a { get; set; } - [Data] public short LayoutCount { get; set; } - [Data] public short MessageCount { get; set; } - [Data] public int MessageOffset { get; set; } - [Data] public int LayoutOffset { get; set; } - [Data] public int TextOffset { get; set; } - [Data] public int Unknown1c { get; set; } - } - - private class _Message - { - [Data] public short Id { get; set; } - [Data] public short Unknown02 { get; set; } - [Data] public int Offset { get; set; } - [Data] public int Entry2Index { get; set; } - } - - public class Message - { - public short Id { get; set; } - public short Unknown02 { get; set; } - public int LayoutIndex { get; set; } - - public byte[] Data { get; set; } - - public string Text - { - get => CtdEncoders.International.ToText(Data); - set => Data = CtdEncoders.International.FromText(value); - } - - public override string ToString() => - $"{Id:X04} {Unknown02:X04} {LayoutIndex:X08}: {Text}"; - } - - public class Layout - { - [Data] public ushort DialogX { get; set; } - [Data] public ushort DialogY { get; set; } - [Data] public ushort DialogWidth { get; set; } - [Data] public ushort DialogHeight { get; set; } - [Data] public byte DialogAlignment { get; set; } - [Data] public byte DialogBorders { get; set; } - [Data] public byte TextAlignment { get; set; } - [Data] public byte Unknown0b { get; set; } - [Data] public ushort FontSize { get; set; } - [Data] public ushort HorizontalSpace { get; set; } - [Data] public ushort VerticalSpace { get; set; } - [Data] public ushort TextX { get; set; } - [Data] public ushort TextY { get; set; } - [Data] public ushort DialogHook { get; set; } - [Data] public ushort DialogHookX { get; set; } - [Data] public ushort Unknown1a { get; set; } - [Data] public ushort Unknown1c { get; set; } - [Data] public ushort Unknown1e { get; set; } - } - - public short Unknown { get; set; } - public List Messages { get; set; } - public List Layouts { get; set; } - - public string GetString(int id) - { - var entry = Messages.FirstOrDefault(x => x.Id == id); - if (entry == null) - return null; - - return entry.Text; - } - - public void Write(Stream stream) - { - var messageOffset = HeaderLength; - var layoutOffset = Helpers.Align(messageOffset + Messages.Count * Entry1Length, 16); - var textOffset = layoutOffset + Layouts.Count * Entry2Length; - - BinaryMapping.WriteObject(stream, new Header - { - MagicCode = MagicCode, - Version = Version, - Unknown08 = 0, - Unknown0a = Unknown, - LayoutCount = (short)Layouts.Count, - MessageCount = (short)Messages.Count, - MessageOffset = messageOffset, - LayoutOffset = layoutOffset, - TextOffset = textOffset, - Unknown1c = 0, - }); - - stream.Position = messageOffset; - var textStream = new MemoryStream(4096); - var nextTextOffset = textOffset; - foreach (var item in Messages) - { - textStream.Write(item.Data, 0, item.Data.Length); - textStream.WriteByte(0); - - BinaryMapping.WriteObject(stream, new _Message - { - Id = item.Id, - Unknown02 = item.Unknown02, - Offset = nextTextOffset, - Entry2Index = item.LayoutIndex - }); - - nextTextOffset += item.Data.Length + 1; - } - - stream.Position = layoutOffset; - foreach (var item in Layouts) - BinaryMapping.WriteObject(stream, item); - - stream.Position = textOffset; - foreach (var entry in Messages) - { - stream.Write(entry.Data, 0, entry.Data.Length); - stream.WriteByte(0); - } - } - - public Ctd() - { - Unknown = 0; - Messages = new List(); - Layouts = new List(); - } - - private Ctd(Stream stream) - { - var header = BinaryMapping.ReadObject
(stream); - Unknown = header.Unknown0a; - - stream.Position = header.MessageOffset; - var textEntries = Enumerable.Range(0, header.MessageCount) - .Select(x => BinaryMapping.ReadObject<_Message>(stream)) - .ToList(); - - stream.Position = header.LayoutOffset; - Layouts = Enumerable.Range(0, header.LayoutCount) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToList(); - - Messages = textEntries - .Select(x => - { - stream.SetPosition(x.Offset); - return new Message - { - Id = x.Id, - Unknown02 = x.Unknown02, - LayoutIndex = x.Entry2Index, - Data = ReadUntilTerminator(stream) - }; - }).ToList(); - } - - private byte[] ReadUntilTerminator(Stream stream) - { - var byteList = new List(100); - - while (stream.Position < stream.Length) - { - var ch = stream.ReadByte(); - if (ch <= 0) - break; - - byteList.Add((byte)ch); - } - - return byteList.ToArray(); - } - - public static Ctd Read(Stream stream) => new Ctd(stream.SetPosition(0)); - - public static bool IsValid(Stream stream) => - new BinaryReader(stream.SetPosition(0)).ReadInt32() == MagicCode; - } -} +using OpenKh.Bbs.Messages; +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Bbs +{ + public class Ctd + { + private const int MagicCode = 0x44544340; + private const int Version = 1; + private const int HeaderLength = 0x20; + private const int Entry1Length = 0xC; + private const int Entry2Length = 0x20; + + private class Header + { + [Data] public int MagicCode { get; set; } + [Data] public int Version { get; set; } + [Data] public short Unknown08 { get; set; } + [Data] public short Unknown0a { get; set; } + [Data] public short LayoutCount { get; set; } + [Data] public short MessageCount { get; set; } + [Data] public int MessageOffset { get; set; } + [Data] public int LayoutOffset { get; set; } + [Data] public int TextOffset { get; set; } + [Data] public int Unknown1c { get; set; } + } + + private class _Message + { + [Data] public short Id { get; set; } + [Data] public short Unknown02 { get; set; } + [Data] public int Offset { get; set; } + [Data] public int Entry2Index { get; set; } + } + + public class Message + { + public short Id { get; set; } + public short Unknown02 { get; set; } + public int LayoutIndex { get; set; } + + public byte[] Data { get; set; } + + public string Text + { + get => CtdEncoders.International.ToText(Data); + set => Data = CtdEncoders.International.FromText(value); + } + + public override string ToString() => + $"{Id:X04} {Unknown02:X04} {LayoutIndex:X08}: {Text}"; + } + + public class Layout + { + [Data] public ushort DialogX { get; set; } + [Data] public ushort DialogY { get; set; } + [Data] public ushort DialogWidth { get; set; } + [Data] public ushort DialogHeight { get; set; } + [Data] public byte DialogAlignment { get; set; } + [Data] public byte DialogBorders { get; set; } + [Data] public byte TextAlignment { get; set; } + [Data] public byte Unknown0b { get; set; } + [Data] public ushort FontSize { get; set; } + [Data] public ushort HorizontalSpace { get; set; } + [Data] public ushort VerticalSpace { get; set; } + [Data] public ushort TextX { get; set; } + [Data] public ushort TextY { get; set; } + [Data] public ushort DialogHook { get; set; } + [Data] public ushort DialogHookX { get; set; } + [Data] public ushort Unknown1a { get; set; } + [Data] public ushort Unknown1c { get; set; } + [Data] public ushort Unknown1e { get; set; } + } + + public short Unknown { get; set; } + public List Messages { get; set; } + public List Layouts { get; set; } + + public string GetString(int id) + { + var entry = Messages.FirstOrDefault(x => x.Id == id); + if (entry == null) + return null; + + return entry.Text; + } + + public void Write(Stream stream) + { + var messageOffset = HeaderLength; + var layoutOffset = Helpers.Align(messageOffset + Messages.Count * Entry1Length, 16); + var textOffset = layoutOffset + Layouts.Count * Entry2Length; + + BinaryMapping.WriteObject(stream, new Header + { + MagicCode = MagicCode, + Version = Version, + Unknown08 = 0, + Unknown0a = Unknown, + LayoutCount = (short)Layouts.Count, + MessageCount = (short)Messages.Count, + MessageOffset = messageOffset, + LayoutOffset = layoutOffset, + TextOffset = textOffset, + Unknown1c = 0, + }); + + stream.Position = messageOffset; + var textStream = new MemoryStream(4096); + var nextTextOffset = textOffset; + foreach (var item in Messages) + { + textStream.Write(item.Data, 0, item.Data.Length); + textStream.WriteByte(0); + + BinaryMapping.WriteObject(stream, new _Message + { + Id = item.Id, + Unknown02 = item.Unknown02, + Offset = nextTextOffset, + Entry2Index = item.LayoutIndex + }); + + nextTextOffset += item.Data.Length + 1; + } + + stream.Position = layoutOffset; + foreach (var item in Layouts) + BinaryMapping.WriteObject(stream, item); + + stream.Position = textOffset; + foreach (var entry in Messages) + { + stream.Write(entry.Data, 0, entry.Data.Length); + stream.WriteByte(0); + } + } + + public Ctd() + { + Unknown = 0; + Messages = new List(); + Layouts = new List(); + } + + private Ctd(Stream stream) + { + var header = BinaryMapping.ReadObject
(stream); + Unknown = header.Unknown0a; + + stream.Position = header.MessageOffset; + var textEntries = Enumerable.Range(0, header.MessageCount) + .Select(x => BinaryMapping.ReadObject<_Message>(stream)) + .ToList(); + + stream.Position = header.LayoutOffset; + Layouts = Enumerable.Range(0, header.LayoutCount) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToList(); + + Messages = textEntries + .Select(x => + { + stream.SetPosition(x.Offset); + return new Message + { + Id = x.Id, + Unknown02 = x.Unknown02, + LayoutIndex = x.Entry2Index, + Data = ReadUntilTerminator(stream) + }; + }).ToList(); + } + + private byte[] ReadUntilTerminator(Stream stream) + { + var byteList = new List(100); + + while (stream.Position < stream.Length) + { + var ch = stream.ReadByte(); + if (ch <= 0) + break; + + byteList.Add((byte)ch); + } + + return byteList.ToArray(); + } + + public static Ctd Read(Stream stream) => new Ctd(stream.SetPosition(0)); + + public static bool IsValid(Stream stream) => + new BinaryReader(stream.SetPosition(0)).ReadInt32() == MagicCode; + } +} diff --git a/OpenKh.Bbs/Epd.cs b/OpenKh.Bbs/Epd.cs index a72b18030..5250b9182 100644 --- a/OpenKh.Bbs/Epd.cs +++ b/OpenKh.Bbs/Epd.cs @@ -1,373 +1,373 @@ -using OpenKh.Common; -using OpenKh.Common.Utils; -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; -using System.Numerics; -using Xe.BinaryMapper; -using System.Linq; - -namespace OpenKh.Bbs -{ - public class Epd - { - private const uint MagicCode = 0x40455044; - private const uint version = 9; - - public class Header - { - [Data] public uint MagicCode { get; set; } - [Data] public uint version { get; set; } - } - - public class GeneralParameters - { - [Data] public uint StatusAilmentsFlag { get; set; } - [Data] public float Health { get; set; } - [Data] public float ExperienceMultiplier { get; set; } - [Data] public uint Size { get; set; } - [Data] public float PhysicalDamageMultiplier { get; set; } - [Data] public float FireDamageMultiplier { get; set; } - [Data] public float IceDamageMultiplier { get; set; } - [Data] public float ThunderDamageMultiplier { get; set; } - [Data] public float DarknessDamageMultiplier { get; set; } - [Data] public float NonElementalDamageMultiplier { get; set; } - } - - public struct StatusAilment - { - public bool bFly; - public bool bSmallDamageReaction; - public bool bSmallDamageReactionOnly; - public bool bHitback; - public bool dummy4; - public bool dummy5; - public bool dummy6; - public bool dummy7; - public bool dummy8; - public bool dummy9; - public bool bPoison; - public bool bSlow; - public bool bStop; - public bool bBind; - public bool bFaint; - public bool bFreeze; - public bool bBurn; - public bool bConfuse; - public bool bBlind; - public bool bDeath; - public bool bZeroGravity; - public bool bMini; - public bool bMagnet; - public bool bDegen; - public bool bSleep; - public bool dummy25; - public bool dummy26; - public bool dummy27; - public bool dummy28; - public bool dummy29; - public bool dummy30; - public bool dummy31; - } - - public class OtherParameters - { - [Data] public ushort DamageCeiling { get; set; } - [Data] public ushort DamageFloor { get; set; } - [Data] public float fWeight { get; set; } - [Data] public uint EffectivenessFlag { get; set; } - [Data] public sbyte PrizeBoxProbability { get; set; } - [Data(Count = 3)] public byte[] padding { get; set; } - [Data] public uint TechniqueParameterCount { get; set; } - [Data] public uint TechniqueParameterOffset { get; set; } - [Data] public uint DropItemsCount { get; set; } - [Data] public uint DropItemsOffset { get; set; } - [Data] public uint ExtraParametersCount { get; set; } - [Data] public uint ExtraParametersOffset { get; set; } - } - - public struct EffectivenessFlag - { - public uint Poison; - public uint Stop; - public uint Bind; - public uint Faint; - public uint Blind; - public uint Mini; - } - - public class TechniqueParameters - { - [Data] public float TechniquePowerCorrection { get; set; } - [Data] public byte TechniqueNumber { get; set; } - [Data] public byte TechniqueKind { get; set; } - [Data] public byte TechniqueAttribute { get; set; } - [Data] public byte SuccessRate { get; set; } - } - - public class DropParameters - { - [Data] public uint ItemIndex { get; set; } - [Data] public ushort ItemCount { get; set; } - [Data] public ushort Probability { get; set; } - } - - public enum DropKind - { - ITEM_KIND_HP_SMALL = 0, - ITEM_KIND_HP_BIG = 1, - ITEM_KIND_MUNNY_SMALL = 2, - ITEM_KIND_MUNNY_MIDDLE = 3, - ITEM_KIND_MUNNY_BIGL = 4, - ITEM_KIND_FOCUS_SMALL = 5, - ITEM_KIND_FOCUS_BIG = 6, - ITEM_KIND_DRAINMIST = 7, - ITEM_KIND_D_LINK = 8, - } - - public class ExtraParameters - { - [Data(Count = 12)] public string ParameterName { get; set; } - [Data] public float ParameterValue { get; set; } - } - - public enum AttackAttribute - { - ATK_ATTR_NONE = 0, - ATK_ATTR_PHYSICAL = 1, - ATK_ATTR_FIRE = 2, - ATK_ATTR_ICE = 3, - ATK_ATTR_THUNDER = 4, - ATK_ATTR_DARK = 5, - ATK_ATTR_ZERO = 6, - ATK_ATTR_SPECIAL = 7 - } - - public enum AttackKind - { - ATK_KIND_NONE = 0, - ATK_KIND_DMG_SMALL = 1, - ATK_KIND_DMG_BIG = 2, - ATK_KIND_DMG_BLOW = 3, - ATK_KIND_DMG_TOSS = 4, - ATK_KIND_DMG_BEAT = 5, - ATK_KIND_DMG_FLICK = 6, - ATK_KIND_POISON = 7, - ATK_KIND_SLOW = 8, - ATK_KIND_STOP = 9, - ATK_KIND_BIND = 10, - ATK_KIND_FAINT = 11, - ATK_KIND_FREEZE = 12, - ATK_KIND_BURN = 13, - ATK_KIND_CONFUSE = 14, - ATK_KIND_BLIND = 15, - ATK_KIND_DEATH = 16, - ATK_KIND_KILL = 17, - ATK_KIND_CAPTURE = 18, - ATK_KIND_MAGNET = 19, - ATK_KIND_ZEROGRAVITY = 20, - ATK_KIND_AERO = 21, - ATK_KIND_TORNADO = 22, - ATK_KIND_DEGENERATOR = 23, - ATK_KIND_WITHOUT = 24, - ATK_KIND_EAT = 25, - ATK_KIND_TREASURERAID = 26, - ATK_KIND_SLEEPINGDEATH = 27, - ATK_KIND_SLEEP = 28, - ATK_KIND_MAGNET_MUNNY = 29, - ATK_KIND_MAGNET_HP = 30, - ATK_KIND_MAGNET_FOCUS = 31, - ATK_KIND_MINIMUM = 32, - ATK_KIND_QUAKE = 33, - ATK_KIND_RECOVER = 34, - ATK_KIND_DISCOMMAND = 35, - ATK_KIND_DISPRIZE_M = 36, - ATK_KIND_DISPRIZE_H = 37, - ATK_KIND_DISPRIZE_F = 38, - ATK_KIND_DETONE = 39, - ATK_KIND_GM_BLOW = 40, - ATK_KIND_BLAST = 41, - ATK_KIND_MAGNESPIRAL = 42, - ATK_KIND_GLACIALARTS = 43, - ATK_KIND_TRANSCENDENCE = 44, - ATK_KIND_VENGEANCE = 45, - ATK_KIND_MAGNEBREAKER = 46, - ATK_KIND_MAGICIMPULSE_CF = 47, - ATK_KIND_MAGICIMPULSE_CFB = 48, - ATK_KIND_MAGICIMPULSE_CFBB = 49, - ATK_KIND_DMG_RISE = 50, - ATK_KIND_STUMBLE = 51, - ATK_KIND_MOUNT = 52, - ATK_KIND_IMPRISONMENT = 53, - ATK_KIND_SLOWSTOP = 54, - ATK_KIND_GATHERING = 55, - ATK_KIND_EXHAUSTED = 56 - } - - public static StatusAilment GetStatusAilment(Epd epd) - { - StatusAilment stat = new StatusAilment(); - stat.bFly = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 0); - stat.bSmallDamageReaction = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 1); - stat.bSmallDamageReactionOnly = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 2); - stat.bHitback = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 3); - stat.bPoison = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 10); - stat.bSlow = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 11); - stat.bStop = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 12); - stat.bBind = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 13); - stat.bFaint = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 14); - stat.bFreeze = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 15); - stat.bBurn = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 16); - stat.bConfuse = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 17); - stat.bBlind = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 18); - stat.bDeath = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 19); - stat.bZeroGravity = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 20); - stat.bMini = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 21); - stat.bMagnet = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 22); - stat.bDegen = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 23); - stat.bSleep = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 24); - - return stat; - } - - public static uint GetStatusAilmentFromStates(bool Fly, bool SmallDamage, bool SmallDamageOnly, bool Hitback, bool Poison, bool Slow, - bool Stop, bool Bind, bool Faint, bool Freeze, bool Burn, bool Confuse, bool Blind, bool Death, - bool ZeroGravity, bool Mini, bool Magnet, bool Degen, bool Sleep) - { - uint AilmentFlag = 0; - - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 0, Fly); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 1, SmallDamage); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 2, SmallDamageOnly); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 3, Hitback); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 10, Poison); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 11, Slow); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 12, Stop); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 13, Bind); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 14, Faint); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 15, Freeze); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 16, Burn); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 17, Confuse); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 18, Blind); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 19, Death); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 20, ZeroGravity); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 21, Mini); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 22, Magnet); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 23, Degen); - AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 24, Sleep); - - return AilmentFlag; - } - - public static uint GetEffectivenessFlagFromStates(uint Poison, uint Stop, uint Bind, uint Faint, uint Blind, uint Minimum) - { - uint Effectiveness = 0; - Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 0, 2, Poison); - Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 2, 2, Stop); - Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 4, 2, Bind); - Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 6, 2, Faint); - Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 8, 2, Blind); - Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 10, 2, Minimum); - - return Effectiveness; - } - - public static EffectivenessFlag GetEffectivenessFlag(Epd epd) - { - EffectivenessFlag flag = new EffectivenessFlag(); - int val = (int)epd.otherParameters.EffectivenessFlag; - flag.Poison = (uint)BitsUtil.Int.GetBits(val, 0, 2); - flag.Stop = (uint)BitsUtil.Int.GetBits(val, 2, 2); - flag.Bind = (uint)BitsUtil.Int.GetBits(val, 4, 2); - flag.Faint = (uint)BitsUtil.Int.GetBits(val, 6, 2); - flag.Blind = (uint)BitsUtil.Int.GetBits(val, 8, 2); - flag.Mini = (uint)BitsUtil.Int.GetBits(val, 10, 2); - - return flag; - } - - public Header header; - public GeneralParameters generalParameters; - public List AnimationList = new List(); - public OtherParameters otherParameters; - public List techniqueParameters = new List(); - public List dropParameters = new List(); - public List extraParameters = new List(); - - public static Epd Read(Stream stream) - { - Epd epd = new Epd(); - epd.header = BinaryMapping.ReadObject
(stream); - epd.generalParameters = BinaryMapping.ReadObject(stream); - BinaryReader r = new BinaryReader(stream); - - for(int i = 0; i < 18; i++) - { - char[] animName = r.ReadChars(4); - epd.AnimationList.Add(animName); - } - stream.Seek(8, SeekOrigin.Current); - - - epd.otherParameters = BinaryMapping.ReadObject(stream); - - stream.Seek(epd.otherParameters.TechniqueParameterOffset, SeekOrigin.Begin); - for(int t = 0; t < epd.otherParameters.TechniqueParameterCount; t++) - { - epd.techniqueParameters.Add(BinaryMapping.ReadObject(stream)); - } - - stream.Seek(epd.otherParameters.DropItemsOffset, SeekOrigin.Begin); - for (int t = 0; t < epd.otherParameters.DropItemsCount; t++) - { - epd.dropParameters.Add(BinaryMapping.ReadObject(stream)); - } - - stream.Seek(epd.otherParameters.ExtraParametersOffset, SeekOrigin.Begin); - for (int t = 0; t < epd.otherParameters.ExtraParametersCount; t++) - { - epd.extraParameters.Add(BinaryMapping.ReadObject(stream)); - } - - return epd; - } - - public static void Write(Stream stream, Epd epd) - { - BinaryMapping.WriteObject
(stream, epd.header); - BinaryMapping.WriteObject(stream, epd.generalParameters); - BinaryWriter w = new BinaryWriter(stream); - - foreach(char[] anim in epd.AnimationList) - { - w.Write(anim); - } - - stream.Write((uint)0); - stream.Write((uint)0); - - BinaryMapping.WriteObject(stream, epd.otherParameters); - - foreach (TechniqueParameters param in epd.techniqueParameters) - { - BinaryMapping.WriteObject(stream, param); - } - - foreach (DropParameters param in epd.dropParameters) - { - BinaryMapping.WriteObject(stream, param); - } - - foreach (ExtraParameters param in epd.extraParameters) - { - BinaryMapping.WriteObject(stream, param); - } - } - - public static bool IsValid(Stream stream) => - stream.Length >= 0x10 && - stream.SetPosition(0).ReadUInt32() == MagicCode && - stream.SetPosition(4).ReadUInt32() == version; - } -} +using OpenKh.Common; +using OpenKh.Common.Utils; +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Numerics; +using Xe.BinaryMapper; +using System.Linq; + +namespace OpenKh.Bbs +{ + public class Epd + { + private const uint MagicCode = 0x40455044; + private const uint version = 9; + + public class Header + { + [Data] public uint MagicCode { get; set; } + [Data] public uint version { get; set; } + } + + public class GeneralParameters + { + [Data] public uint StatusAilmentsFlag { get; set; } + [Data] public float Health { get; set; } + [Data] public float ExperienceMultiplier { get; set; } + [Data] public uint Size { get; set; } + [Data] public float PhysicalDamageMultiplier { get; set; } + [Data] public float FireDamageMultiplier { get; set; } + [Data] public float IceDamageMultiplier { get; set; } + [Data] public float ThunderDamageMultiplier { get; set; } + [Data] public float DarknessDamageMultiplier { get; set; } + [Data] public float NonElementalDamageMultiplier { get; set; } + } + + public struct StatusAilment + { + public bool bFly; + public bool bSmallDamageReaction; + public bool bSmallDamageReactionOnly; + public bool bHitback; + public bool dummy4; + public bool dummy5; + public bool dummy6; + public bool dummy7; + public bool dummy8; + public bool dummy9; + public bool bPoison; + public bool bSlow; + public bool bStop; + public bool bBind; + public bool bFaint; + public bool bFreeze; + public bool bBurn; + public bool bConfuse; + public bool bBlind; + public bool bDeath; + public bool bZeroGravity; + public bool bMini; + public bool bMagnet; + public bool bDegen; + public bool bSleep; + public bool dummy25; + public bool dummy26; + public bool dummy27; + public bool dummy28; + public bool dummy29; + public bool dummy30; + public bool dummy31; + } + + public class OtherParameters + { + [Data] public ushort DamageCeiling { get; set; } + [Data] public ushort DamageFloor { get; set; } + [Data] public float fWeight { get; set; } + [Data] public uint EffectivenessFlag { get; set; } + [Data] public sbyte PrizeBoxProbability { get; set; } + [Data(Count = 3)] public byte[] padding { get; set; } + [Data] public uint TechniqueParameterCount { get; set; } + [Data] public uint TechniqueParameterOffset { get; set; } + [Data] public uint DropItemsCount { get; set; } + [Data] public uint DropItemsOffset { get; set; } + [Data] public uint ExtraParametersCount { get; set; } + [Data] public uint ExtraParametersOffset { get; set; } + } + + public struct EffectivenessFlag + { + public uint Poison; + public uint Stop; + public uint Bind; + public uint Faint; + public uint Blind; + public uint Mini; + } + + public class TechniqueParameters + { + [Data] public float TechniquePowerCorrection { get; set; } + [Data] public byte TechniqueNumber { get; set; } + [Data] public byte TechniqueKind { get; set; } + [Data] public byte TechniqueAttribute { get; set; } + [Data] public byte SuccessRate { get; set; } + } + + public class DropParameters + { + [Data] public uint ItemIndex { get; set; } + [Data] public ushort ItemCount { get; set; } + [Data] public ushort Probability { get; set; } + } + + public enum DropKind + { + ITEM_KIND_HP_SMALL = 0, + ITEM_KIND_HP_BIG = 1, + ITEM_KIND_MUNNY_SMALL = 2, + ITEM_KIND_MUNNY_MIDDLE = 3, + ITEM_KIND_MUNNY_BIGL = 4, + ITEM_KIND_FOCUS_SMALL = 5, + ITEM_KIND_FOCUS_BIG = 6, + ITEM_KIND_DRAINMIST = 7, + ITEM_KIND_D_LINK = 8, + } + + public class ExtraParameters + { + [Data(Count = 12)] public string ParameterName { get; set; } + [Data] public float ParameterValue { get; set; } + } + + public enum AttackAttribute + { + ATK_ATTR_NONE = 0, + ATK_ATTR_PHYSICAL = 1, + ATK_ATTR_FIRE = 2, + ATK_ATTR_ICE = 3, + ATK_ATTR_THUNDER = 4, + ATK_ATTR_DARK = 5, + ATK_ATTR_ZERO = 6, + ATK_ATTR_SPECIAL = 7 + } + + public enum AttackKind + { + ATK_KIND_NONE = 0, + ATK_KIND_DMG_SMALL = 1, + ATK_KIND_DMG_BIG = 2, + ATK_KIND_DMG_BLOW = 3, + ATK_KIND_DMG_TOSS = 4, + ATK_KIND_DMG_BEAT = 5, + ATK_KIND_DMG_FLICK = 6, + ATK_KIND_POISON = 7, + ATK_KIND_SLOW = 8, + ATK_KIND_STOP = 9, + ATK_KIND_BIND = 10, + ATK_KIND_FAINT = 11, + ATK_KIND_FREEZE = 12, + ATK_KIND_BURN = 13, + ATK_KIND_CONFUSE = 14, + ATK_KIND_BLIND = 15, + ATK_KIND_DEATH = 16, + ATK_KIND_KILL = 17, + ATK_KIND_CAPTURE = 18, + ATK_KIND_MAGNET = 19, + ATK_KIND_ZEROGRAVITY = 20, + ATK_KIND_AERO = 21, + ATK_KIND_TORNADO = 22, + ATK_KIND_DEGENERATOR = 23, + ATK_KIND_WITHOUT = 24, + ATK_KIND_EAT = 25, + ATK_KIND_TREASURERAID = 26, + ATK_KIND_SLEEPINGDEATH = 27, + ATK_KIND_SLEEP = 28, + ATK_KIND_MAGNET_MUNNY = 29, + ATK_KIND_MAGNET_HP = 30, + ATK_KIND_MAGNET_FOCUS = 31, + ATK_KIND_MINIMUM = 32, + ATK_KIND_QUAKE = 33, + ATK_KIND_RECOVER = 34, + ATK_KIND_DISCOMMAND = 35, + ATK_KIND_DISPRIZE_M = 36, + ATK_KIND_DISPRIZE_H = 37, + ATK_KIND_DISPRIZE_F = 38, + ATK_KIND_DETONE = 39, + ATK_KIND_GM_BLOW = 40, + ATK_KIND_BLAST = 41, + ATK_KIND_MAGNESPIRAL = 42, + ATK_KIND_GLACIALARTS = 43, + ATK_KIND_TRANSCENDENCE = 44, + ATK_KIND_VENGEANCE = 45, + ATK_KIND_MAGNEBREAKER = 46, + ATK_KIND_MAGICIMPULSE_CF = 47, + ATK_KIND_MAGICIMPULSE_CFB = 48, + ATK_KIND_MAGICIMPULSE_CFBB = 49, + ATK_KIND_DMG_RISE = 50, + ATK_KIND_STUMBLE = 51, + ATK_KIND_MOUNT = 52, + ATK_KIND_IMPRISONMENT = 53, + ATK_KIND_SLOWSTOP = 54, + ATK_KIND_GATHERING = 55, + ATK_KIND_EXHAUSTED = 56 + } + + public static StatusAilment GetStatusAilment(Epd epd) + { + StatusAilment stat = new StatusAilment(); + stat.bFly = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 0); + stat.bSmallDamageReaction = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 1); + stat.bSmallDamageReactionOnly = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 2); + stat.bHitback = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 3); + stat.bPoison = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 10); + stat.bSlow = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 11); + stat.bStop = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 12); + stat.bBind = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 13); + stat.bFaint = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 14); + stat.bFreeze = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 15); + stat.bBurn = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 16); + stat.bConfuse = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 17); + stat.bBlind = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 18); + stat.bDeath = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 19); + stat.bZeroGravity = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 20); + stat.bMini = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 21); + stat.bMagnet = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 22); + stat.bDegen = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 23); + stat.bSleep = BitsUtil.Int.GetBit((int)epd.generalParameters.StatusAilmentsFlag, 24); + + return stat; + } + + public static uint GetStatusAilmentFromStates(bool Fly, bool SmallDamage, bool SmallDamageOnly, bool Hitback, bool Poison, bool Slow, + bool Stop, bool Bind, bool Faint, bool Freeze, bool Burn, bool Confuse, bool Blind, bool Death, + bool ZeroGravity, bool Mini, bool Magnet, bool Degen, bool Sleep) + { + uint AilmentFlag = 0; + + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 0, Fly); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 1, SmallDamage); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 2, SmallDamageOnly); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 3, Hitback); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 10, Poison); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 11, Slow); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 12, Stop); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 13, Bind); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 14, Faint); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 15, Freeze); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 16, Burn); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 17, Confuse); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 18, Blind); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 19, Death); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 20, ZeroGravity); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 21, Mini); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 22, Magnet); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 23, Degen); + AilmentFlag = BitsUtil.Int.SetBit(AilmentFlag, 24, Sleep); + + return AilmentFlag; + } + + public static uint GetEffectivenessFlagFromStates(uint Poison, uint Stop, uint Bind, uint Faint, uint Blind, uint Minimum) + { + uint Effectiveness = 0; + Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 0, 2, Poison); + Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 2, 2, Stop); + Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 4, 2, Bind); + Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 6, 2, Faint); + Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 8, 2, Blind); + Effectiveness = BitsUtil.Int.SetBits(Effectiveness, 10, 2, Minimum); + + return Effectiveness; + } + + public static EffectivenessFlag GetEffectivenessFlag(Epd epd) + { + EffectivenessFlag flag = new EffectivenessFlag(); + int val = (int)epd.otherParameters.EffectivenessFlag; + flag.Poison = (uint)BitsUtil.Int.GetBits(val, 0, 2); + flag.Stop = (uint)BitsUtil.Int.GetBits(val, 2, 2); + flag.Bind = (uint)BitsUtil.Int.GetBits(val, 4, 2); + flag.Faint = (uint)BitsUtil.Int.GetBits(val, 6, 2); + flag.Blind = (uint)BitsUtil.Int.GetBits(val, 8, 2); + flag.Mini = (uint)BitsUtil.Int.GetBits(val, 10, 2); + + return flag; + } + + public Header header; + public GeneralParameters generalParameters; + public List AnimationList = new List(); + public OtherParameters otherParameters; + public List techniqueParameters = new List(); + public List dropParameters = new List(); + public List extraParameters = new List(); + + public static Epd Read(Stream stream) + { + Epd epd = new Epd(); + epd.header = BinaryMapping.ReadObject
(stream); + epd.generalParameters = BinaryMapping.ReadObject(stream); + BinaryReader r = new BinaryReader(stream); + + for (int i = 0; i < 18; i++) + { + char[] animName = r.ReadChars(4); + epd.AnimationList.Add(animName); + } + stream.Seek(8, SeekOrigin.Current); + + + epd.otherParameters = BinaryMapping.ReadObject(stream); + + stream.Seek(epd.otherParameters.TechniqueParameterOffset, SeekOrigin.Begin); + for (int t = 0; t < epd.otherParameters.TechniqueParameterCount; t++) + { + epd.techniqueParameters.Add(BinaryMapping.ReadObject(stream)); + } + + stream.Seek(epd.otherParameters.DropItemsOffset, SeekOrigin.Begin); + for (int t = 0; t < epd.otherParameters.DropItemsCount; t++) + { + epd.dropParameters.Add(BinaryMapping.ReadObject(stream)); + } + + stream.Seek(epd.otherParameters.ExtraParametersOffset, SeekOrigin.Begin); + for (int t = 0; t < epd.otherParameters.ExtraParametersCount; t++) + { + epd.extraParameters.Add(BinaryMapping.ReadObject(stream)); + } + + return epd; + } + + public static void Write(Stream stream, Epd epd) + { + BinaryMapping.WriteObject
(stream, epd.header); + BinaryMapping.WriteObject(stream, epd.generalParameters); + BinaryWriter w = new BinaryWriter(stream); + + foreach (char[] anim in epd.AnimationList) + { + w.Write(anim); + } + + stream.Write((uint)0); + stream.Write((uint)0); + + BinaryMapping.WriteObject(stream, epd.otherParameters); + + foreach (TechniqueParameters param in epd.techniqueParameters) + { + BinaryMapping.WriteObject(stream, param); + } + + foreach (DropParameters param in epd.dropParameters) + { + BinaryMapping.WriteObject(stream, param); + } + + foreach (ExtraParameters param in epd.extraParameters) + { + BinaryMapping.WriteObject(stream, param); + } + } + + public static bool IsValid(Stream stream) => + stream.Length >= 0x10 && + stream.SetPosition(0).ReadUInt32() == MagicCode && + stream.SetPosition(4).ReadUInt32() == version; + } +} diff --git a/OpenKh.Bbs/Event.cs b/OpenKh.Bbs/Event.cs index c6fb36d9a..87eabda82 100644 --- a/OpenKh.Bbs/Event.cs +++ b/OpenKh.Bbs/Event.cs @@ -1,54 +1,54 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Bbs -{ - public class Event - { - private const int MagicCode = 1; - - private class Header - { - [Data] public int MagicCode { get; set; } - [Data] public int Count { get; set; } - } - - [Data] public ushort Id { get; set; } - [Data] public ushort EventIndex { get; set; } - [Data] public byte World { get; set; } - [Data] public byte Room { get; set; } - [Data] public byte EventPtn { get; set; } - [Data] public byte Opt { get; set; } - - public static bool IsValid(Stream stream) - { - var prevPosition = stream.Position; - var magicCode = new BinaryReader(stream).ReadInt32(); - stream.Position = prevPosition; - - return magicCode == MagicCode; - } - - public static List Read(Stream stream) - { - var header = BinaryMapping.ReadObject
(stream); - return Enumerable.Range(0, header.Count) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList(); - } - - public static void Write(Stream stream, IEnumerable events) - { - var list = events.ToList(); - BinaryMapping.WriteObject(stream, new Header - { - MagicCode = MagicCode, - Count = list.Count - }); - foreach (var item in list) - BinaryMapping.WriteObject(stream, item); - } - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Bbs +{ + public class Event + { + private const int MagicCode = 1; + + private class Header + { + [Data] public int MagicCode { get; set; } + [Data] public int Count { get; set; } + } + + [Data] public ushort Id { get; set; } + [Data] public ushort EventIndex { get; set; } + [Data] public byte World { get; set; } + [Data] public byte Room { get; set; } + [Data] public byte EventPtn { get; set; } + [Data] public byte Opt { get; set; } + + public static bool IsValid(Stream stream) + { + var prevPosition = stream.Position; + var magicCode = new BinaryReader(stream).ReadInt32(); + stream.Position = prevPosition; + + return magicCode == MagicCode; + } + + public static List Read(Stream stream) + { + var header = BinaryMapping.ReadObject
(stream); + return Enumerable.Range(0, header.Count) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList(); + } + + public static void Write(Stream stream, IEnumerable events) + { + var list = events.ToList(); + BinaryMapping.WriteObject(stream, new Header + { + MagicCode = MagicCode, + Count = list.Count + }); + foreach (var item in list) + BinaryMapping.WriteObject(stream, item); + } + } +} diff --git a/OpenKh.Bbs/FontCharacterInfo.cs b/OpenKh.Bbs/FontCharacterInfo.cs index dfa9a6582..53c0bb92d 100644 --- a/OpenKh.Bbs/FontCharacterInfo.cs +++ b/OpenKh.Bbs/FontCharacterInfo.cs @@ -1,36 +1,36 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Bbs -{ - public class FontCharacterInfo - { - [Data] public ushort Id { get; set; } - [Data] public ushort PositionX { get; set; } - [Data] public ushort PositionY { get; set; } - [Data] public byte Palette { get; set; } - [Data] public byte Width { get; set; } - - public static FontCharacterInfo[] Read(Stream stream) - { - var characterCount = (int)stream.Length / 8; - var charactersInfo = new FontCharacterInfo[characterCount]; - stream.Position = 0; - - for (var i = 0; i < characterCount; i++) - charactersInfo[i] = BinaryMapping.ReadObject(stream); - - return charactersInfo; - } - - public static void Write(Stream stream, IEnumerable charactersInfo) - { - stream.Position = 0; - foreach (var info in charactersInfo) - BinaryMapping.WriteObject(stream, info); - - stream.SetLength(stream.Position); - } - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Bbs +{ + public class FontCharacterInfo + { + [Data] public ushort Id { get; set; } + [Data] public ushort PositionX { get; set; } + [Data] public ushort PositionY { get; set; } + [Data] public byte Palette { get; set; } + [Data] public byte Width { get; set; } + + public static FontCharacterInfo[] Read(Stream stream) + { + var characterCount = (int)stream.Length / 8; + var charactersInfo = new FontCharacterInfo[characterCount]; + stream.Position = 0; + + for (var i = 0; i < characterCount; i++) + charactersInfo[i] = BinaryMapping.ReadObject(stream); + + return charactersInfo; + } + + public static void Write(Stream stream, IEnumerable charactersInfo) + { + stream.Position = 0; + foreach (var info in charactersInfo) + BinaryMapping.WriteObject(stream, info); + + stream.SetLength(stream.Position); + } + } +} diff --git a/OpenKh.Bbs/FontIconInfo.cs b/OpenKh.Bbs/FontIconInfo.cs index 2f30c7bdb..0affdbb37 100644 --- a/OpenKh.Bbs/FontIconInfo.cs +++ b/OpenKh.Bbs/FontIconInfo.cs @@ -1,59 +1,59 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Bbs -{ - public class FontIconInfo - { - public ushort Key { get; set; } - public byte Left { get; set; } - public byte Top { get; set; } - public byte Right { get; set; } - public byte Bottom { get; set; } - - private class MetaIcon - { - [Data] public ushort Key { get; set; } - [Data] public byte Left { get; set; } - [Data] public byte Top { get; set; } - [Data] public byte Right { get; set; } - [Data] public byte Bottom { get; set; } - [Data] public short RESERVED { get; set; } - } - - public static IEnumerable Read(Stream stream) - { - var count = stream.ReadInt32(); - return Enumerable.Range(0, count) - .Select(_ => BinaryMapping.ReadObject(stream)) - .Select(x => new FontIconInfo - { - Key = x.Key, - Left = x.Left, - Top = x.Top, - Right = x.Right, - Bottom = x.Bottom - }) - .ToArray(); - } - - public static void Write(Stream stream, IEnumerable fontIconsInfo) - { - var myFontIconsInfo = fontIconsInfo.ToArray(); - stream.Write(myFontIconsInfo.Length); - foreach (var info in myFontIconsInfo) - BinaryMapping.WriteObject(stream, new MetaIcon - { - Key = info.Key, - Left = info.Left, - Top = info.Top, - Right = info.Right, - Bottom = info.Bottom, - RESERVED = 0 - }); - } - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Bbs +{ + public class FontIconInfo + { + public ushort Key { get; set; } + public byte Left { get; set; } + public byte Top { get; set; } + public byte Right { get; set; } + public byte Bottom { get; set; } + + private class MetaIcon + { + [Data] public ushort Key { get; set; } + [Data] public byte Left { get; set; } + [Data] public byte Top { get; set; } + [Data] public byte Right { get; set; } + [Data] public byte Bottom { get; set; } + [Data] public short RESERVED { get; set; } + } + + public static IEnumerable Read(Stream stream) + { + var count = stream.ReadInt32(); + return Enumerable.Range(0, count) + .Select(_ => BinaryMapping.ReadObject(stream)) + .Select(x => new FontIconInfo + { + Key = x.Key, + Left = x.Left, + Top = x.Top, + Right = x.Right, + Bottom = x.Bottom + }) + .ToArray(); + } + + public static void Write(Stream stream, IEnumerable fontIconsInfo) + { + var myFontIconsInfo = fontIconsInfo.ToArray(); + stream.Write(myFontIconsInfo.Length); + foreach (var info in myFontIconsInfo) + BinaryMapping.WriteObject(stream, new MetaIcon + { + Key = info.Key, + Left = info.Left, + Top = info.Top, + Right = info.Right, + Bottom = info.Bottom, + RESERVED = 0 + }); + } + } +} diff --git a/OpenKh.Bbs/FontInfo.cs b/OpenKh.Bbs/FontInfo.cs index 12bf19629..6f2ce00ad 100644 --- a/OpenKh.Bbs/FontInfo.cs +++ b/OpenKh.Bbs/FontInfo.cs @@ -1,20 +1,20 @@ -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Bbs -{ - public class FontInfo - { - [Data] public short CharacterCount { get; set; } - [Data] public short ImageWidth { get; set; } - [Data] public short MaxImageHeight { get; set; } - [Data] public byte CharacterWidth { get; set; } - [Data] public byte CharacterHeight { get; set; } - - public static FontInfo Read(Stream stream) => - BinaryMapping.ReadObject(stream); - - public void Write(Stream stream) => - BinaryMapping.WriteObject(stream, this); - } -} +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Bbs +{ + public class FontInfo + { + [Data] public short CharacterCount { get; set; } + [Data] public short ImageWidth { get; set; } + [Data] public short MaxImageHeight { get; set; } + [Data] public byte CharacterWidth { get; set; } + [Data] public byte CharacterHeight { get; set; } + + public static FontInfo Read(Stream stream) => + BinaryMapping.ReadObject(stream); + + public void Write(Stream stream) => + BinaryMapping.WriteObject(stream, this); + } +} diff --git a/OpenKh.Bbs/FontsArc.cs b/OpenKh.Bbs/FontsArc.cs index 06dee6864..09b1bc4ea 100644 --- a/OpenKh.Bbs/FontsArc.cs +++ b/OpenKh.Bbs/FontsArc.cs @@ -1,152 +1,152 @@ -using OpenKh.Common; -using OpenKh.Imaging; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.Linq; - -namespace OpenKh.Bbs -{ - public class FontsArc - { - private class Image : IImageRead - { - private readonly byte[] _imageData; - private readonly byte[] _clutData; - - internal Image(string name, Arc.Entry mtx, byte[] clut, int width, int maxHeight, PixelFormat pixelFormat) - { - Name = name; - Size = new Size(width, maxHeight); - PixelFormat = pixelFormat; - - var bpp = 0; - switch (pixelFormat) - { - case PixelFormat.Indexed4: - bpp = 4; - break; - case PixelFormat.Indexed8: - bpp = 8; - break; - } - - _imageData = new byte[width * maxHeight * bpp / 8]; - Array.Copy(mtx.Data, _imageData, Math.Min(_imageData.Length, mtx.Data.Length)); - _imageData = Unswizzle(_imageData, width * bpp / 8); - if (pixelFormat == PixelFormat.Indexed4) - InvertEndianess(_imageData); - - _clutData = new byte[clut.Length]; - Array.Copy(clut, _clutData, _clutData.Length); - } - - public string Name { get; } - - public Size Size { get; } - - public PixelFormat PixelFormat { get; } - - public byte[] GetClut() => _clutData; - - public byte[] GetData() => _imageData; - } - - public class Font - { - public string Name { get; } - public IImageRead Image1 { get; } - public IImageRead Image2 { get; } - public FontInfo Info { get; } - public FontCharacterInfo[] CharactersInfo { get; } - - public Font(IEnumerable entries, string name) - { - Name = name; - - var mtx = RequireFileEntry(entries, $"{name}.mtx"); - var clu = RequireFileEntry(entries, $"{name}.clu"); - Info = new MemoryStream(RequireFileEntry(entries, $"{name}.inf").Data) - .Using(stream => FontInfo.Read(stream)); - - var clut = new byte[0x40]; - Array.Copy(clu.Data, 0, clut, 0, clut.Length); - Image1 = new Image(name, mtx, clut, Info.ImageWidth, Info.MaxImageHeight, PixelFormat.Indexed4); - - Array.Copy(clu.Data, 0x40, clut, 0, clut.Length); - Image2 = new Image(name, mtx, clut, Info.ImageWidth, Info.MaxImageHeight, PixelFormat.Indexed4); - - CharactersInfo = new MemoryStream(RequireFileEntry(entries, $"{name}.cod").Data).Using(stream => - FontCharacterInfo.Read(stream)); - } - } - - private readonly IEnumerable _entries; - - private FontsArc(Stream stream) - { - _entries = Arc.Read(stream); - - FontIcon = CreateFontIconImage(_entries, "FontIcon"); - FontCmd = new Font(_entries, "cmdfont"); - FontHelp = new Font(_entries, "helpfont"); - FontMenu = new Font(_entries, "menufont"); - FontMes = new Font(_entries, "mesfont"); - FontNumeral = new Font(_entries, "numeral"); - } - - public IImageRead FontIcon { get; } - public Font FontCmd { get; } - public Font FontHelp { get; } - public Font FontMenu { get; } - public Font FontMes { get; } - public Font FontNumeral { get; } - - private Image CreateFontIconImage(IEnumerable entries, string name) - { - var mtx = RequireFileEntry(entries, $"{name}.mtx"); - var clu = RequireFileEntry(entries, $"{name}.clu"); - var inf = new MemoryStream(RequireFileEntry(entries, $"{name}.inf").Data) - .Using(stream => FontIconInfo.Read(stream)); - - return new Image(name, mtx, clu.Data, 256, 64, PixelFormat.Indexed8); - } - - private static Arc.Entry RequireFileEntry(IEnumerable entries, string name) - { - var entry = entries.FirstOrDefault(x => x.Name == name); - if (entry == null) - throw new FileNotFoundException($"ARC does not contain the required file {name}.", name); - - return entry; - } - - private static byte[] Unswizzle(byte[] data, int width) - { - var dst = new byte[data.Length]; - - for (var i = 0; i < data.Length; i += 16) - { - var srcIndex = i; - var dstIndex = srcIndex % 0x10; - dstIndex += srcIndex / 0x10 % 8 * width; - dstIndex += srcIndex / 0x80 % (width / 16) * 16; - dstIndex += srcIndex / (width * 8) * width * 8; - - Array.Copy(data, srcIndex, dst, dstIndex, 16); - } - - return dst; - } - - private static void InvertEndianess(byte[] data) - { - for (var i = 0; i < data.Length; i++) - data[i] = (byte)(((data[i] & 15) << 4) | (data[i] >> 4)); - } - - public static bool IsValid(Stream stream) => Arc.IsValid(stream); - public static FontsArc Read(Stream stream) => new FontsArc(stream); - } -} +using OpenKh.Common; +using OpenKh.Imaging; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; + +namespace OpenKh.Bbs +{ + public class FontsArc + { + private class Image : IImageRead + { + private readonly byte[] _imageData; + private readonly byte[] _clutData; + + internal Image(string name, Arc.Entry mtx, byte[] clut, int width, int maxHeight, PixelFormat pixelFormat) + { + Name = name; + Size = new Size(width, maxHeight); + PixelFormat = pixelFormat; + + var bpp = 0; + switch (pixelFormat) + { + case PixelFormat.Indexed4: + bpp = 4; + break; + case PixelFormat.Indexed8: + bpp = 8; + break; + } + + _imageData = new byte[width * maxHeight * bpp / 8]; + Array.Copy(mtx.Data, _imageData, Math.Min(_imageData.Length, mtx.Data.Length)); + _imageData = Unswizzle(_imageData, width * bpp / 8); + if (pixelFormat == PixelFormat.Indexed4) + InvertEndianess(_imageData); + + _clutData = new byte[clut.Length]; + Array.Copy(clut, _clutData, _clutData.Length); + } + + public string Name { get; } + + public Size Size { get; } + + public PixelFormat PixelFormat { get; } + + public byte[] GetClut() => _clutData; + + public byte[] GetData() => _imageData; + } + + public class Font + { + public string Name { get; } + public IImageRead Image1 { get; } + public IImageRead Image2 { get; } + public FontInfo Info { get; } + public FontCharacterInfo[] CharactersInfo { get; } + + public Font(IEnumerable entries, string name) + { + Name = name; + + var mtx = RequireFileEntry(entries, $"{name}.mtx"); + var clu = RequireFileEntry(entries, $"{name}.clu"); + Info = new MemoryStream(RequireFileEntry(entries, $"{name}.inf").Data) + .Using(stream => FontInfo.Read(stream)); + + var clut = new byte[0x40]; + Array.Copy(clu.Data, 0, clut, 0, clut.Length); + Image1 = new Image(name, mtx, clut, Info.ImageWidth, Info.MaxImageHeight, PixelFormat.Indexed4); + + Array.Copy(clu.Data, 0x40, clut, 0, clut.Length); + Image2 = new Image(name, mtx, clut, Info.ImageWidth, Info.MaxImageHeight, PixelFormat.Indexed4); + + CharactersInfo = new MemoryStream(RequireFileEntry(entries, $"{name}.cod").Data).Using(stream => + FontCharacterInfo.Read(stream)); + } + } + + private readonly IEnumerable _entries; + + private FontsArc(Stream stream) + { + _entries = Arc.Read(stream); + + FontIcon = CreateFontIconImage(_entries, "FontIcon"); + FontCmd = new Font(_entries, "cmdfont"); + FontHelp = new Font(_entries, "helpfont"); + FontMenu = new Font(_entries, "menufont"); + FontMes = new Font(_entries, "mesfont"); + FontNumeral = new Font(_entries, "numeral"); + } + + public IImageRead FontIcon { get; } + public Font FontCmd { get; } + public Font FontHelp { get; } + public Font FontMenu { get; } + public Font FontMes { get; } + public Font FontNumeral { get; } + + private Image CreateFontIconImage(IEnumerable entries, string name) + { + var mtx = RequireFileEntry(entries, $"{name}.mtx"); + var clu = RequireFileEntry(entries, $"{name}.clu"); + var inf = new MemoryStream(RequireFileEntry(entries, $"{name}.inf").Data) + .Using(stream => FontIconInfo.Read(stream)); + + return new Image(name, mtx, clu.Data, 256, 64, PixelFormat.Indexed8); + } + + private static Arc.Entry RequireFileEntry(IEnumerable entries, string name) + { + var entry = entries.FirstOrDefault(x => x.Name == name); + if (entry == null) + throw new FileNotFoundException($"ARC does not contain the required file {name}.", name); + + return entry; + } + + private static byte[] Unswizzle(byte[] data, int width) + { + var dst = new byte[data.Length]; + + for (var i = 0; i < data.Length; i += 16) + { + var srcIndex = i; + var dstIndex = srcIndex % 0x10; + dstIndex += srcIndex / 0x10 % 8 * width; + dstIndex += srcIndex / 0x80 % (width / 16) * 16; + dstIndex += srcIndex / (width * 8) * width * 8; + + Array.Copy(data, srcIndex, dst, dstIndex, 16); + } + + return dst; + } + + private static void InvertEndianess(byte[] data) + { + for (var i = 0; i < data.Length; i++) + data[i] = (byte)(((data[i] & 15) << 4) | (data[i] >> 4)); + } + + public static bool IsValid(Stream stream) => Arc.IsValid(stream); + public static FontsArc Read(Stream stream) => new FontsArc(stream); + } +} diff --git a/OpenKh.Bbs/Itb.cs b/OpenKh.Bbs/Itb.cs index 71349b3fc..d88dcff80 100644 --- a/OpenKh.Bbs/Itb.cs +++ b/OpenKh.Bbs/Itb.cs @@ -1,84 +1,84 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; -using Xe.BinaryMapper; -using OpenKh.Common; - -namespace OpenKh.Bbs -{ - public class Itb - { - private const uint MagicCode = 0x425449; - private const ushort version = 1; - - public class Header - { - [Data] public uint MagicCode { get; set; } - [Data] public ushort Version { get; set; } - [Data] public ushort Padding1 { get; set; } - [Data] public ushort ItemsTotal { get; set; } - [Data] public ushort Padding { get; set; } - [Data] public byte ItemCountDP { get; set; } - [Data] public byte ItemCountSW { get; set; } - [Data] public byte ItemCountCD { get; set; } - [Data] public byte ItemCountSB { get; set; } - [Data] public byte ItemCountYT { get; set; } - [Data] public byte ItemCountRG { get; set; } - [Data] public byte ItemCountJB { get; set; } - [Data] public byte ItemCountHE { get; set; } - [Data] public byte ItemCountLS { get; set; } - [Data] public byte ItemCountDI { get; set; } - [Data] public byte ItemCountPP { get; set; } - [Data] public byte ItemCountDC { get; set; } - [Data] public byte ItemCountKG { get; set; } - [Data] public byte ItemCountVS { get; set; } - [Data] public byte ItemCountBD { get; set; } - [Data] public byte ItemCountWM { get; set; } - } - - public class ITBData - { - [Data] public ushort TreasureBoxID { get; set; } - [Data] public ushort ItemID { get; set; } - [Data] public byte ItemKind { get; set; } - [Data] public byte WorldID { get; set; } - [Data] public byte ReportID { get; set; } - [Data] public byte Padding3 { get; set; } - } - - public Header header = new Header(); - public List AllITB = new List(); - - public static Itb Read(Stream stream) - { - Itb itb = new Itb(); - - itb.header = BinaryMapping.ReadObject
(stream); - - itb.AllITB = new List(); - - for (int i = 0; i < itb.header.ItemsTotal; i++) - { - itb.AllITB.Add(BinaryMapping.ReadObject(stream)); - } - - return itb; - } - - public static void Write(Stream stream, Itb itb) - { - BinaryMapping.WriteObject
(stream, itb.header); - - for (int i = 0; i < itb.header.ItemsTotal; i++) - { - BinaryMapping.WriteObject(stream, itb.AllITB[i]); - } - } - - public static bool IsValid(Stream stream) => - stream.Length >= 0x1C && - stream.SetPosition(0).ReadUInt32() == MagicCode && - stream.SetPosition(0).ReadUInt16() == version; - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using Xe.BinaryMapper; +using OpenKh.Common; + +namespace OpenKh.Bbs +{ + public class Itb + { + private const uint MagicCode = 0x425449; + private const ushort version = 1; + + public class Header + { + [Data] public uint MagicCode { get; set; } + [Data] public ushort Version { get; set; } + [Data] public ushort Padding1 { get; set; } + [Data] public ushort ItemsTotal { get; set; } + [Data] public ushort Padding { get; set; } + [Data] public byte ItemCountDP { get; set; } + [Data] public byte ItemCountSW { get; set; } + [Data] public byte ItemCountCD { get; set; } + [Data] public byte ItemCountSB { get; set; } + [Data] public byte ItemCountYT { get; set; } + [Data] public byte ItemCountRG { get; set; } + [Data] public byte ItemCountJB { get; set; } + [Data] public byte ItemCountHE { get; set; } + [Data] public byte ItemCountLS { get; set; } + [Data] public byte ItemCountDI { get; set; } + [Data] public byte ItemCountPP { get; set; } + [Data] public byte ItemCountDC { get; set; } + [Data] public byte ItemCountKG { get; set; } + [Data] public byte ItemCountVS { get; set; } + [Data] public byte ItemCountBD { get; set; } + [Data] public byte ItemCountWM { get; set; } + } + + public class ITBData + { + [Data] public ushort TreasureBoxID { get; set; } + [Data] public ushort ItemID { get; set; } + [Data] public byte ItemKind { get; set; } + [Data] public byte WorldID { get; set; } + [Data] public byte ReportID { get; set; } + [Data] public byte Padding3 { get; set; } + } + + public Header header = new Header(); + public List AllITB = new List(); + + public static Itb Read(Stream stream) + { + Itb itb = new Itb(); + + itb.header = BinaryMapping.ReadObject
(stream); + + itb.AllITB = new List(); + + for (int i = 0; i < itb.header.ItemsTotal; i++) + { + itb.AllITB.Add(BinaryMapping.ReadObject(stream)); + } + + return itb; + } + + public static void Write(Stream stream, Itb itb) + { + BinaryMapping.WriteObject
(stream, itb.header); + + for (int i = 0; i < itb.header.ItemsTotal; i++) + { + BinaryMapping.WriteObject(stream, itb.AllITB[i]); + } + } + + public static bool IsValid(Stream stream) => + stream.Length >= 0x1C && + stream.SetPosition(0).ReadUInt32() == MagicCode && + stream.SetPosition(0).ReadUInt16() == version; + } +} diff --git a/OpenKh.Bbs/Itc.cs b/OpenKh.Bbs/Itc.cs index d9a75b3a7..aad89eed3 100644 --- a/OpenKh.Bbs/Itc.cs +++ b/OpenKh.Bbs/Itc.cs @@ -1,84 +1,84 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; -using Xe.BinaryMapper; -using OpenKh.Common; - -namespace OpenKh.Bbs -{ - public class Itc - { - private const uint MagicCode = 0x435449; - private const ushort version = 1; - - public class Header - { - [Data] public uint MagicCode { get; set; } - [Data] public ushort Version { get; set; } - [Data] public ushort Padding1 { get; set; } - [Data] public ushort ItemsTotal { get; set; } - [Data] public ushort Padding { get; set; } - [Data] public byte ItemCountDP { get; set; } - [Data] public byte ItemCountSW { get; set; } - [Data] public byte ItemCountCD { get; set; } - [Data] public byte ItemCountSB { get; set; } - [Data] public byte ItemCountYT { get; set; } - [Data] public byte ItemCountRG { get; set; } - [Data] public byte ItemCountJB { get; set; } - [Data] public byte ItemCountHE { get; set; } - [Data] public byte ItemCountLS { get; set; } - [Data] public byte ItemCountDI { get; set; } - [Data] public byte ItemCountPP { get; set; } - [Data] public byte ItemCountDC { get; set; } - [Data] public byte ItemCountKG { get; set; } - [Data] public byte ItemCountVS { get; set; } - [Data] public byte ItemCountBD { get; set; } - [Data] public byte ItemCountWM { get; set; } - } - - public class ITCData - { - [Data] public ushort CollectionID { get; set; } - [Data] public ushort ItemID { get; set; } - [Data] public byte WorldID { get; set; } - [Data] public byte Padding1 { get; set; } - [Data] public byte Padding2 { get; set; } - [Data] public byte Padding3 { get; set; } - } - - public Header header = new Header(); - public List AllITC = new List(); - - public static Itc Read(Stream stream) - { - Itc itc = new Itc(); - - itc.header = BinaryMapping.ReadObject
(stream); - - itc.AllITC = new List(); - - for(int i = 0; i < itc.header.ItemsTotal; i++) - { - itc.AllITC.Add(BinaryMapping.ReadObject(stream)); - } - - return itc; - } - - public static void Write(Stream stream, Itc itc) - { - BinaryMapping.WriteObject
(stream, itc.header); - - for (int i = 0; i < itc.header.ItemsTotal; i++) - { - BinaryMapping.WriteObject(stream, itc.AllITC[i]); - } - } - - public static bool IsValid(Stream stream) => - stream.Length >= 0x1C && - stream.SetPosition(0).ReadUInt32() == MagicCode && - stream.SetPosition(0).ReadUInt16() == version; - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using Xe.BinaryMapper; +using OpenKh.Common; + +namespace OpenKh.Bbs +{ + public class Itc + { + private const uint MagicCode = 0x435449; + private const ushort version = 1; + + public class Header + { + [Data] public uint MagicCode { get; set; } + [Data] public ushort Version { get; set; } + [Data] public ushort Padding1 { get; set; } + [Data] public ushort ItemsTotal { get; set; } + [Data] public ushort Padding { get; set; } + [Data] public byte ItemCountDP { get; set; } + [Data] public byte ItemCountSW { get; set; } + [Data] public byte ItemCountCD { get; set; } + [Data] public byte ItemCountSB { get; set; } + [Data] public byte ItemCountYT { get; set; } + [Data] public byte ItemCountRG { get; set; } + [Data] public byte ItemCountJB { get; set; } + [Data] public byte ItemCountHE { get; set; } + [Data] public byte ItemCountLS { get; set; } + [Data] public byte ItemCountDI { get; set; } + [Data] public byte ItemCountPP { get; set; } + [Data] public byte ItemCountDC { get; set; } + [Data] public byte ItemCountKG { get; set; } + [Data] public byte ItemCountVS { get; set; } + [Data] public byte ItemCountBD { get; set; } + [Data] public byte ItemCountWM { get; set; } + } + + public class ITCData + { + [Data] public ushort CollectionID { get; set; } + [Data] public ushort ItemID { get; set; } + [Data] public byte WorldID { get; set; } + [Data] public byte Padding1 { get; set; } + [Data] public byte Padding2 { get; set; } + [Data] public byte Padding3 { get; set; } + } + + public Header header = new Header(); + public List AllITC = new List(); + + public static Itc Read(Stream stream) + { + Itc itc = new Itc(); + + itc.header = BinaryMapping.ReadObject
(stream); + + itc.AllITC = new List(); + + for (int i = 0; i < itc.header.ItemsTotal; i++) + { + itc.AllITC.Add(BinaryMapping.ReadObject(stream)); + } + + return itc; + } + + public static void Write(Stream stream, Itc itc) + { + BinaryMapping.WriteObject
(stream, itc.header); + + for (int i = 0; i < itc.header.ItemsTotal; i++) + { + BinaryMapping.WriteObject(stream, itc.AllITC[i]); + } + } + + public static bool IsValid(Stream stream) => + stream.Length >= 0x1C && + stream.SetPosition(0).ReadUInt32() == MagicCode && + stream.SetPosition(0).ReadUInt16() == version; + } +} diff --git a/OpenKh.Bbs/Ite.cs b/OpenKh.Bbs/Ite.cs index 902a079c9..016f5789d 100644 --- a/OpenKh.Bbs/Ite.cs +++ b/OpenKh.Bbs/Ite.cs @@ -1,121 +1,121 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; -using Xe.BinaryMapper; -using OpenKh.Common; - -namespace OpenKh.Bbs -{ - public class Ite - { - private const uint MagicCode = 0x455449; - private const ushort version = 1; - - public class Header - { - [Data] public uint MagicCode { get; set; } - [Data] public ushort Version { get; set; } - [Data] public ushort Padding1 { get; set; } - [Data] public ushort WeaponDataCount { get; set; } - [Data] public ushort FlavorDataCount { get; set; } - [Data] public ushort KeyItemDataCount { get; set; } - [Data] public ushort KeyItemHideDataCount { get; set; } - [Data] public ushort SynthesisDataCount { get; set; } - [Data] public ushort Padding { get; set; } - } - - public class ITEData - { - [Data] public ushort ItemID { get; set; } - [Data] public byte Padding1 { get; set; } - [Data] public byte Padding2 { get; set; } - } - - public Header header; - public List WeaponList = new List(); - public List FlavorList = new List(); - public List KeyItemList = new List(); - public List KeyItemHideList = new List(); - public List SynthesisList = new List(); - - public static Ite Read(Stream stream) - { - Ite ite = new Ite(); - - ite.header = BinaryMapping.ReadObject
(stream); - - // Weapon. - for(int i = 0; i < ite.header.WeaponDataCount; i++) - { - ite.WeaponList.Add(BinaryMapping.ReadObject(stream)); - } - - // Flavor. - for (int i = 0; i < ite.header.FlavorDataCount; i++) - { - ite.FlavorList.Add(BinaryMapping.ReadObject(stream)); - } - - // Key Item. - for (int i = 0; i < ite.header.KeyItemDataCount; i++) - { - ite.KeyItemList.Add(BinaryMapping.ReadObject(stream)); - } - - // Key Item Hide. - for (int i = 0; i < ite.header.KeyItemHideDataCount; i++) - { - ite.KeyItemHideList.Add(BinaryMapping.ReadObject(stream)); - } - - // Synthesis. - for (int i = 0; i < ite.header.SynthesisDataCount; i++) - { - ite.SynthesisList.Add(BinaryMapping.ReadObject(stream)); - } - - return ite; - } - - public static void Write(Stream stream, Ite ite) - { - BinaryMapping.WriteObject
(stream, ite.header); - - // Weapon. - for (int i = 0; i < ite.header.WeaponDataCount; i++) - { - BinaryMapping.WriteObject(stream, ite.WeaponList[i]); - } - - // Flavor. - for (int i = 0; i < ite.header.FlavorDataCount; i++) - { - BinaryMapping.WriteObject(stream, ite.FlavorList[i]); - } - - // Key Item. - for (int i = 0; i < ite.header.KeyItemDataCount; i++) - { - BinaryMapping.WriteObject(stream, ite.KeyItemList[i]); - } - - // Key Item Hide. - for (int i = 0; i < ite.header.KeyItemHideDataCount; i++) - { - BinaryMapping.WriteObject(stream, ite.KeyItemHideList[i]); - } - - // Synthesis. - for (int i = 0; i < ite.header.SynthesisDataCount; i++) - { - BinaryMapping.WriteObject(stream, ite.SynthesisList[i]); - } - } - - public static bool IsValid(Stream stream) => - stream.Length >= 0x1C && - stream.SetPosition(0).ReadUInt32() == MagicCode && - stream.SetPosition(0).ReadUInt16() == version; - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using Xe.BinaryMapper; +using OpenKh.Common; + +namespace OpenKh.Bbs +{ + public class Ite + { + private const uint MagicCode = 0x455449; + private const ushort version = 1; + + public class Header + { + [Data] public uint MagicCode { get; set; } + [Data] public ushort Version { get; set; } + [Data] public ushort Padding1 { get; set; } + [Data] public ushort WeaponDataCount { get; set; } + [Data] public ushort FlavorDataCount { get; set; } + [Data] public ushort KeyItemDataCount { get; set; } + [Data] public ushort KeyItemHideDataCount { get; set; } + [Data] public ushort SynthesisDataCount { get; set; } + [Data] public ushort Padding { get; set; } + } + + public class ITEData + { + [Data] public ushort ItemID { get; set; } + [Data] public byte Padding1 { get; set; } + [Data] public byte Padding2 { get; set; } + } + + public Header header; + public List WeaponList = new List(); + public List FlavorList = new List(); + public List KeyItemList = new List(); + public List KeyItemHideList = new List(); + public List SynthesisList = new List(); + + public static Ite Read(Stream stream) + { + Ite ite = new Ite(); + + ite.header = BinaryMapping.ReadObject
(stream); + + // Weapon. + for (int i = 0; i < ite.header.WeaponDataCount; i++) + { + ite.WeaponList.Add(BinaryMapping.ReadObject(stream)); + } + + // Flavor. + for (int i = 0; i < ite.header.FlavorDataCount; i++) + { + ite.FlavorList.Add(BinaryMapping.ReadObject(stream)); + } + + // Key Item. + for (int i = 0; i < ite.header.KeyItemDataCount; i++) + { + ite.KeyItemList.Add(BinaryMapping.ReadObject(stream)); + } + + // Key Item Hide. + for (int i = 0; i < ite.header.KeyItemHideDataCount; i++) + { + ite.KeyItemHideList.Add(BinaryMapping.ReadObject(stream)); + } + + // Synthesis. + for (int i = 0; i < ite.header.SynthesisDataCount; i++) + { + ite.SynthesisList.Add(BinaryMapping.ReadObject(stream)); + } + + return ite; + } + + public static void Write(Stream stream, Ite ite) + { + BinaryMapping.WriteObject
(stream, ite.header); + + // Weapon. + for (int i = 0; i < ite.header.WeaponDataCount; i++) + { + BinaryMapping.WriteObject(stream, ite.WeaponList[i]); + } + + // Flavor. + for (int i = 0; i < ite.header.FlavorDataCount; i++) + { + BinaryMapping.WriteObject(stream, ite.FlavorList[i]); + } + + // Key Item. + for (int i = 0; i < ite.header.KeyItemDataCount; i++) + { + BinaryMapping.WriteObject(stream, ite.KeyItemList[i]); + } + + // Key Item Hide. + for (int i = 0; i < ite.header.KeyItemHideDataCount; i++) + { + BinaryMapping.WriteObject(stream, ite.KeyItemHideList[i]); + } + + // Synthesis. + for (int i = 0; i < ite.header.SynthesisDataCount; i++) + { + BinaryMapping.WriteObject(stream, ite.SynthesisList[i]); + } + } + + public static bool IsValid(Stream stream) => + stream.Length >= 0x1C && + stream.SetPosition(0).ReadUInt32() == MagicCode && + stream.SetPosition(0).ReadUInt16() == version; + } +} diff --git a/OpenKh.Bbs/Messages/CtdEncoders.cs b/OpenKh.Bbs/Messages/CtdEncoders.cs index cf007e7f9..1ab91f54b 100644 --- a/OpenKh.Bbs/Messages/CtdEncoders.cs +++ b/OpenKh.Bbs/Messages/CtdEncoders.cs @@ -1,13 +1,13 @@ -using OpenKh.Bbs.Messages.Internals; - -namespace OpenKh.Bbs.Messages -{ - public static class CtdEncoders - { - public static ICtdMessageEncoder International { get; } = - new InternationalCtdEncoder(); - - public static ICtdMessageEncoder Japanese { get; } = - new InternationalCtdEncoder(); - } -} +using OpenKh.Bbs.Messages.Internals; + +namespace OpenKh.Bbs.Messages +{ + public static class CtdEncoders + { + public static ICtdMessageEncoder International { get; } = + new InternationalCtdEncoder(); + + public static ICtdMessageEncoder Japanese { get; } = + new InternationalCtdEncoder(); + } +} diff --git a/OpenKh.Bbs/Messages/ICtdMessageDecode.cs b/OpenKh.Bbs/Messages/ICtdMessageDecode.cs index 8c8fe708d..091e12418 100644 --- a/OpenKh.Bbs/Messages/ICtdMessageDecode.cs +++ b/OpenKh.Bbs/Messages/ICtdMessageDecode.cs @@ -1,7 +1,7 @@ -namespace OpenKh.Bbs.Messages -{ - public interface ICtdMessageDecode - { - string ToText(byte[] data); - } -} +namespace OpenKh.Bbs.Messages +{ + public interface ICtdMessageDecode + { + string ToText(byte[] data); + } +} diff --git a/OpenKh.Bbs/Messages/ICtdMessageEncode.cs b/OpenKh.Bbs/Messages/ICtdMessageEncode.cs index 68fe6527e..9486f08bf 100644 --- a/OpenKh.Bbs/Messages/ICtdMessageEncode.cs +++ b/OpenKh.Bbs/Messages/ICtdMessageEncode.cs @@ -1,7 +1,7 @@ -namespace OpenKh.Bbs.Messages -{ - public interface ICtdMessageEncode - { - byte[] FromText(string text); - } -} +namespace OpenKh.Bbs.Messages +{ + public interface ICtdMessageEncode + { + byte[] FromText(string text); + } +} diff --git a/OpenKh.Bbs/Messages/ICtdMessageEncoder.cs b/OpenKh.Bbs/Messages/ICtdMessageEncoder.cs index fa973bee3..6dcdbf48a 100644 --- a/OpenKh.Bbs/Messages/ICtdMessageEncoder.cs +++ b/OpenKh.Bbs/Messages/ICtdMessageEncoder.cs @@ -1,11 +1,11 @@ -using System.Collections.Generic; - -namespace OpenKh.Bbs.Messages -{ - public interface ICtdMessageEncoder : ICtdMessageDecode, ICtdMessageEncode - { - IEnumerable ToUcs(IEnumerable data); - - IEnumerable FromUcs(IEnumerable ucs); - } -} +using System.Collections.Generic; + +namespace OpenKh.Bbs.Messages +{ + public interface ICtdMessageEncoder : ICtdMessageDecode, ICtdMessageEncode + { + IEnumerable ToUcs(IEnumerable data); + + IEnumerable FromUcs(IEnumerable ucs); + } +} diff --git a/OpenKh.Bbs/Messages/Internals/InternationalCtdEncoder.cs b/OpenKh.Bbs/Messages/Internals/InternationalCtdEncoder.cs index 38b5fe596..936b6437b 100644 --- a/OpenKh.Bbs/Messages/Internals/InternationalCtdEncoder.cs +++ b/OpenKh.Bbs/Messages/Internals/InternationalCtdEncoder.cs @@ -1,184 +1,188 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace OpenKh.Bbs.Messages.Internals -{ - internal class InternationalCtdEncoder : ICtdMessageEncoder - { - private static readonly ushort[] _jisToUcs = new ushort[0x60] - { - 0x81a1, 0x8149, 0x8168, 0x8194, 0x8190, 0x8193, 0x8195, 0x8166, - 0x8169, 0x816a, 0x8196, 0x817b, 0x8143, 0x817c, 0x8144, 0x815e, - 0x824f, 0x8250, 0x8251, 0x8252, 0x8253, 0x8254, 0x8255, 0x8256, - 0x8257, 0x8258, 0x8146, 0x8147, 0x8183, 0x8181, 0x8184, 0x8148, - 0x8197, 0x8260, 0x8261, 0x8262, 0x8263, 0x8264, 0x8265, 0x8266, - 0x8267, 0x8268, 0x8269, 0x826a, 0x826b, 0x826c, 0x826d, 0x826e, - 0x826f, 0x8270, 0x8271, 0x8272, 0x8273, 0x8274, 0x8275, 0x8276, - 0x8277, 0x8278, 0x8279, 0x816d, 0x818f, 0x816e, 0x814f, 0x8151, - 0x99c9, 0x8281, 0x8282, 0x8283, 0x8284, 0x8285, 0x8286, 0x8287, - 0x8288, 0x8289, 0x828a, 0x828b, 0x828c, 0x828d, 0x828e, 0x828f, - 0x8290, 0x8291, 0x8292, 0x8293, 0x8294, 0x8295, 0x8296, 0x8297, - 0x8298, 0x8299, 0x829a, 0x816f, 0x8162, 0x8170, 0x8160, 0x007f, - }; - - private static readonly string _mapping0 = - " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[¥]^_`abcdefghijklmnopqrstuvwxyz{|}~"; - private static readonly string _mapping81 = - " 、。,.·:;?!_____^¯__________–-_/\\~-|…‥‘’“”()__[]{}⟨⟩⟪⟫「」『』__+-±×·÷=≠<>≤≥∞∴♂♀°′″_¥$¢£%#&*@§☆★○●◎◇◆□■△▲▽▼※〒→←↑↓________________________________________________________________________♪†‡¶________"; - private static readonly string _mapping99 = - "ÀÁÂÄÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖŒÙÚÛÜßàáâäæçèéêëìíîïñòóôõöùúûüœ¿¡‚„—°«»≤≥❤¹²³⁴⁵£€§·¢¨‘’©®™‾ₐ"; - private static readonly Dictionary _mappingF1 = new Dictionary - { - [0xae] = "button-triangle", - [0xaf] = "button-circle", - [0xb0] = "button-square", - [0xb1] = "button-cross", - [0xb2] = "button-analog", - [0xb3] = "button-r", - [0xb4] = "button-l", - [0xc3] = "button-dpad", - [0xc4] = "button-dpad-h", - [0xc5] = "button-dpad-v", - }; - private static readonly Dictionary _mappingF9 = new Dictionary - { - [0x41] = "default", - [0x58] = "white", - [0x59] = "yellow", - }; - - private static readonly Dictionary _inverseMapping = _mapping0 - .Select((x, i) => new { Ch = x, Data = i + 0x20 }) - .Concat(_mapping81.Select((x, i) => new { Ch = x, Data = 0x8190 + i })) - .Concat(_mapping99.Select((x, i) => new { Ch = x, Data = 0x9980 + i })) - .GroupBy(x => x.Ch) - .Select(x => x.First()) - .ToDictionary(x => x.Ch, x => x.Data); - - public string ToText(byte[] data) - { - var builder = new StringBuilder(data.Length * 3 / 2); - for (var i = 0; i < data.Length;) - { - builder.Append(GetCharacter(data, ref i)); - } - - return builder.ToString(); - } - - public byte[] FromText(string text) - { - var encoded = new List(text.Length * 3 / 2); - foreach (var ch in text) - { - if (ch >= 0x20) - { - var data = _inverseMapping[ch]; - - if (data < 0x100) - encoded.Add((byte)data); - else - { - encoded.Add((byte)(data >> 8)); - encoded.Add((byte)(data & 0xFF)); - } - } - else - encoded.Add((byte)ch); - } - - return encoded.ToArray(); - } - - private static string GetCharacter(byte[] data, ref int index) - { - var ch = data[index++]; - - if (ch >= 0x00 && ch < 0x20) - return $"{(char)ch}"; - - if (ch >= 0x20 && ch < 0x80) - return $"{_mapping0[ch - 0x20]}"; - - var param = data[index++]; - switch (ch) - { - case 0x81: - param -= 0x40; - return $"{_mapping81[param]}"; - case 0x99: - return $"{_mapping99[param - 0x80]}"; - default: - return GetCommand(ch, param); - } - } - - private static string GetCommand(byte command, byte param) - { - string name; - string value; - - switch (command) - { - case 0xf1: - name = "icon"; - value = _mappingF1[param]; - break; - case 0xf9: - name = "color"; - value = _mappingF9[param]; - break; - default: - throw new Exception($"Data \"{command:X02} {param:X02}\" cannot be decoded."); - } - - return $"{{:{name} {value}}}"; - } - - public IEnumerable ToUcs(IEnumerable data) - { - var enumerator = data.GetEnumerator(); - while (enumerator.MoveNext()) - { - var ch = enumerator.Current; - if (ch < 0x21) yield return ch; - else if (ch < 0x80) yield return _jisToUcs[ch - 0x20]; - else if (ch < 0xa0) - { - if (!enumerator.MoveNext()) - yield break; - else - yield return (ushort)((ch << 8) | enumerator.Current); - } - else if (ch < 0xe0) yield return ch; // TODO convert 0xa0-0xdf characters to UCS - else if (ch < 0xf0) - { - if (!enumerator.MoveNext()) - yield break; - else - yield return (ushort)((ch << 8) | enumerator.Current); - } - else yield return ch; - } - } - - public IEnumerable FromUcs(IEnumerable ucs) - { - foreach (var ch in ucs) - { - var index = 0x20; - foreach (var digit in _jisToUcs) - { - if (ch == digit) - yield return (byte)index; - index++; - } - - yield return (byte)(ch >> 8); - yield return (byte)(ch & 0xff); - } - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenKh.Bbs.Messages.Internals +{ + internal class InternationalCtdEncoder : ICtdMessageEncoder + { + private static readonly ushort[] _jisToUcs = new ushort[0x60] + { + 0x81a1, 0x8149, 0x8168, 0x8194, 0x8190, 0x8193, 0x8195, 0x8166, + 0x8169, 0x816a, 0x8196, 0x817b, 0x8143, 0x817c, 0x8144, 0x815e, + 0x824f, 0x8250, 0x8251, 0x8252, 0x8253, 0x8254, 0x8255, 0x8256, + 0x8257, 0x8258, 0x8146, 0x8147, 0x8183, 0x8181, 0x8184, 0x8148, + 0x8197, 0x8260, 0x8261, 0x8262, 0x8263, 0x8264, 0x8265, 0x8266, + 0x8267, 0x8268, 0x8269, 0x826a, 0x826b, 0x826c, 0x826d, 0x826e, + 0x826f, 0x8270, 0x8271, 0x8272, 0x8273, 0x8274, 0x8275, 0x8276, + 0x8277, 0x8278, 0x8279, 0x816d, 0x818f, 0x816e, 0x814f, 0x8151, + 0x99c9, 0x8281, 0x8282, 0x8283, 0x8284, 0x8285, 0x8286, 0x8287, + 0x8288, 0x8289, 0x828a, 0x828b, 0x828c, 0x828d, 0x828e, 0x828f, + 0x8290, 0x8291, 0x8292, 0x8293, 0x8294, 0x8295, 0x8296, 0x8297, + 0x8298, 0x8299, 0x829a, 0x816f, 0x8162, 0x8170, 0x8160, 0x007f, + }; + + private static readonly string _mapping0 = + " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[¥]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + private static readonly string _mapping81 = + " 、。,.·:;?!_____^¯__________–-_/\\~-|…‥‘’“”()__[]{}⟨⟩⟪⟫「」『』__+-±×·÷=≠<>≤≥∞∴♂♀°′″_¥$¢£%#&*@§☆★○●◎◇◆□■△▲▽▼※〒→←↑↓________________________________________________________________________♪†‡¶________"; + private static readonly string _mapping99 = + "ÀÁÂÄÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖŒÙÚÛÜßàáâäæçèéêëìíîïñòóôõöùúûüœ¿¡‚„—°«»≤≥❤¹²³⁴⁵£€§·¢¨‘’©®™‾ₐ"; + private static readonly Dictionary _mappingF1 = new Dictionary + { + [0xae] = "button-triangle", + [0xaf] = "button-circle", + [0xb0] = "button-square", + [0xb1] = "button-cross", + [0xb2] = "button-analog", + [0xb3] = "button-r", + [0xb4] = "button-l", + [0xc3] = "button-dpad", + [0xc4] = "button-dpad-h", + [0xc5] = "button-dpad-v", + }; + private static readonly Dictionary _mappingF9 = new Dictionary + { + [0x41] = "default", + [0x58] = "white", + [0x59] = "yellow", + }; + + private static readonly Dictionary _inverseMapping = _mapping0 + .Select((x, i) => new { Ch = x, Data = i + 0x20 }) + .Concat(_mapping81.Select((x, i) => new { Ch = x, Data = 0x8190 + i })) + .Concat(_mapping99.Select((x, i) => new { Ch = x, Data = 0x9980 + i })) + .GroupBy(x => x.Ch) + .Select(x => x.First()) + .ToDictionary(x => x.Ch, x => x.Data); + + public string ToText(byte[] data) + { + var builder = new StringBuilder(data.Length * 3 / 2); + for (var i = 0; i < data.Length;) + { + builder.Append(GetCharacter(data, ref i)); + } + + return builder.ToString(); + } + + public byte[] FromText(string text) + { + var encoded = new List(text.Length * 3 / 2); + foreach (var ch in text) + { + if (ch >= 0x20) + { + var data = _inverseMapping[ch]; + + if (data < 0x100) + encoded.Add((byte)data); + else + { + encoded.Add((byte)(data >> 8)); + encoded.Add((byte)(data & 0xFF)); + } + } + else + encoded.Add((byte)ch); + } + + return encoded.ToArray(); + } + + private static string GetCharacter(byte[] data, ref int index) + { + var ch = data[index++]; + + if (ch >= 0x00 && ch < 0x20) + return $"{(char)ch}"; + + if (ch >= 0x20 && ch < 0x80) + return $"{_mapping0[ch - 0x20]}"; + + var param = data[index++]; + switch (ch) + { + case 0x81: + param -= 0x40; + return $"{_mapping81[param]}"; + case 0x99: + return $"{_mapping99[param - 0x80]}"; + default: + return GetCommand(ch, param); + } + } + + private static string GetCommand(byte command, byte param) + { + string name; + string value; + + switch (command) + { + case 0xf1: + name = "icon"; + value = _mappingF1[param]; + break; + case 0xf9: + name = "color"; + value = _mappingF9[param]; + break; + default: + throw new Exception($"Data \"{command:X02} {param:X02}\" cannot be decoded."); + } + + return $"{{:{name} {value}}}"; + } + + public IEnumerable ToUcs(IEnumerable data) + { + var enumerator = data.GetEnumerator(); + while (enumerator.MoveNext()) + { + var ch = enumerator.Current; + if (ch < 0x21) + yield return ch; + else if (ch < 0x80) + yield return _jisToUcs[ch - 0x20]; + else if (ch < 0xa0) + { + if (!enumerator.MoveNext()) + yield break; + else + yield return (ushort)((ch << 8) | enumerator.Current); + } + else if (ch < 0xe0) + yield return ch; // TODO convert 0xa0-0xdf characters to UCS + else if (ch < 0xf0) + { + if (!enumerator.MoveNext()) + yield break; + else + yield return (ushort)((ch << 8) | enumerator.Current); + } + else + yield return ch; + } + } + + public IEnumerable FromUcs(IEnumerable ucs) + { + foreach (var ch in ucs) + { + var index = 0x20; + foreach (var digit in _jisToUcs) + { + if (ch == digit) + yield return (byte)index; + index++; + } + + yield return (byte)(ch >> 8); + yield return (byte)(ch & 0xff); + } + } + } +} diff --git a/OpenKh.Bbs/Messages/Internals/JapaneseCtdEncoder.cs b/OpenKh.Bbs/Messages/Internals/JapaneseCtdEncoder.cs index 75a2592c6..6bab4fdf3 100644 --- a/OpenKh.Bbs/Messages/Internals/JapaneseCtdEncoder.cs +++ b/OpenKh.Bbs/Messages/Internals/JapaneseCtdEncoder.cs @@ -1,67 +1,67 @@ -using System.Collections.Generic; - -namespace OpenKh.Bbs.Messages.Internals -{ - internal class JapaneseCtdEncoder : ICtdMessageEncoder - { - private static readonly string[] _encoding = new string[] - { - " 、。,.・:;?!゛゜´`¨^ ̄_ヽヾゝゞ〃仝々〆〇ー―‐/\~∥|…‥‘’“”()〔〕[]{}〈〉《》「」『』【】+-±×・÷=≠<>≦≧∞∴♂♀°′″℃¥$¢£%#&*@§☆★○●◎◇◆□■△▲▽▼※〒→←↑↓〓・・・・・・・・・・・∈∋⊆⊇⊂⊃∪∩・・・・・・・・∧∨¬⇒⇔∀∃・・・・・・・・・・・∠⊥⌒∂∇≡≒≪≫√∽∝∵∫∬・・・・・・・ʼn♯♭♪†‡¶・・・・◯・・・", -"・・・・・・・・・・・・・・・0123456789・・・・・・・ABCDEFGHIJKLMNOPQRSTUVWXYZ・・・・・・・abcdefghijklmnopqrstuvwxyz・・・・ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをん・・・・・・・・・・・・・・", -"ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミ・ムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶ・・・・・・・・ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ・・・・・・・・αβγδεζηθικλμνξοπρστυφχψω・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・", -"АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ・・・・・・・・・・・・・・・абвгдеёжзийклмн・опрстуфхцчшщъыьэюя・・・・・・・・・・・・・─│┌┐┘└├┬┤┴┼━┃┏┓┛┗┣┳┫┻╋┠┯┨┷┿┝┰┥┸╂・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・", -"・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・", -"・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・", -"①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ・㍉㌔㌢㍍㌘㌧㌃㌶㍑㍗㌍㌦㌣㌫㍊㌻㎜㎝㎞㎎㎏㏄㎡・・・・・・・・㍻・〝〟№㏍℡㊤㊥㊦㊧㊨㈱㈲㈹㍾㍽㍼≒≡∫∮∑√⊥∠∟⊿∵∩∪・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・", -"・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・亜唖娃阿哀愛挨姶逢葵茜穐悪握渥旭葦芦鯵梓圧斡扱宛姐虻飴絢綾鮎或粟袷安庵按暗案闇鞍杏以伊位依偉囲夷委威尉惟意慰易椅為畏異移維緯胃萎衣謂違遺医井亥域育郁磯一壱溢逸稲茨芋鰯允印咽員因姻引飲淫胤蔭・・・", -"院陰隠韻吋右宇烏羽迂雨卯鵜窺丑碓臼渦嘘唄欝蔚鰻姥厩浦瓜閏噂云運雲荏餌叡営嬰影映曳栄永泳洩瑛盈穎頴英衛詠鋭液疫益駅悦謁越閲榎厭円・園堰奄宴延怨掩援沿演炎焔煙燕猿縁艶苑薗遠鉛鴛塩於汚甥凹央奥往応押旺横欧殴王翁襖鴬鴎黄岡沖荻億屋憶臆桶牡乙俺卸恩温穏音下化仮何伽価佳加可嘉夏嫁家寡科暇果架歌河火珂禍禾稼箇花苛茄荷華菓蝦課嘩貨迦過霞蚊俄峨我牙画臥芽蛾賀雅餓駕介会解回塊壊廻快怪悔恢懐戒拐改・・・", -"魁晦械海灰界皆絵芥蟹開階貝凱劾外咳害崖慨概涯碍蓋街該鎧骸浬馨蛙垣柿蛎鈎劃嚇各廓拡撹格核殻獲確穫覚角赫較郭閣隔革学岳楽額顎掛笠樫・橿梶鰍潟割喝恰括活渇滑葛褐轄且鰹叶椛樺鞄株兜竃蒲釜鎌噛鴨栢茅萱粥刈苅瓦乾侃冠寒刊勘勧巻喚堪姦完官寛干幹患感慣憾換敢柑桓棺款歓汗漢澗潅環甘監看竿管簡緩缶翰肝艦莞観諌貫還鑑間閑関陥韓館舘丸含岸巌玩癌眼岩翫贋雁頑顔願企伎危喜器基奇嬉寄岐希幾忌揮机旗既期棋棄・・・", -"機帰毅気汽畿祈季稀紀徽規記貴起軌輝飢騎鬼亀偽儀妓宜戯技擬欺犠疑祇義蟻誼議掬菊鞠吉吃喫桔橘詰砧杵黍却客脚虐逆丘久仇休及吸宮弓急救・朽求汲泣灸球究窮笈級糾給旧牛去居巨拒拠挙渠虚許距鋸漁禦魚亨享京供侠僑兇競共凶協匡卿叫喬境峡強彊怯恐恭挟教橋況狂狭矯胸脅興蕎郷鏡響饗驚仰凝尭暁業局曲極玉桐粁僅勤均巾錦斤欣欽琴禁禽筋緊芹菌衿襟謹近金吟銀九倶句区狗玖矩苦躯駆駈駒具愚虞喰空偶寓遇隅串櫛釧屑屈・・・", -"掘窟沓靴轡窪熊隈粂栗繰桑鍬勲君薫訓群軍郡卦袈祁係傾刑兄啓圭珪型契形径恵慶慧憩掲携敬景桂渓畦稽系経継繋罫茎荊蛍計詣警軽頚鶏芸迎鯨・劇戟撃激隙桁傑欠決潔穴結血訣月件倹倦健兼券剣喧圏堅嫌建憲懸拳捲検権牽犬献研硯絹県肩見謙賢軒遣鍵険顕験鹸元原厳幻弦減源玄現絃舷言諺限乎個古呼固姑孤己庫弧戸故枯湖狐糊袴股胡菰虎誇跨鈷雇顧鼓五互伍午呉吾娯後御悟梧檎瑚碁語誤護醐乞鯉交佼侯候倖光公功効勾厚口向・・・", -"后喉坑垢好孔孝宏工巧巷幸広庚康弘恒慌抗拘控攻昂晃更杭校梗構江洪浩港溝甲皇硬稿糠紅紘絞綱耕考肯肱腔膏航荒行衡講貢購郊酵鉱砿鋼閤降・項香高鴻剛劫号合壕拷濠豪轟麹克刻告国穀酷鵠黒獄漉腰甑忽惚骨狛込此頃今困坤墾婚恨懇昏昆根梱混痕紺艮魂些佐叉唆嵯左差査沙瑳砂詐鎖裟坐座挫債催再最哉塞妻宰彩才採栽歳済災采犀砕砦祭斎細菜裁載際剤在材罪財冴坂阪堺榊肴咲崎埼碕鷺作削咋搾昨朔柵窄策索錯桜鮭笹匙冊刷・・・", -"察拶撮擦札殺薩雑皐鯖捌錆鮫皿晒三傘参山惨撒散桟燦珊産算纂蚕讃賛酸餐斬暫残仕仔伺使刺司史嗣四士始姉姿子屍市師志思指支孜斯施旨枝止・死氏獅祉私糸紙紫肢脂至視詞詩試誌諮資賜雌飼歯事似侍児字寺慈持時次滋治爾璽痔磁示而耳自蒔辞汐鹿式識鴫竺軸宍雫七叱執失嫉室悉湿漆疾質実蔀篠偲柴芝屡蕊縞舎写射捨赦斜煮社紗者謝車遮蛇邪借勺尺杓灼爵酌釈錫若寂弱惹主取守手朱殊狩珠種腫趣酒首儒受呪寿授樹綬需囚収周・・・", -"宗就州修愁拾洲秀秋終繍習臭舟蒐衆襲讐蹴輯週酋酬集醜什住充十従戎柔汁渋獣縦重銃叔夙宿淑祝縮粛塾熟出術述俊峻春瞬竣舜駿准循旬楯殉淳・準潤盾純巡遵醇順処初所暑曙渚庶緒署書薯藷諸助叙女序徐恕鋤除傷償勝匠升召哨商唱嘗奨妾娼宵将小少尚庄床廠彰承抄招掌捷昇昌昭晶松梢樟樵沼消渉湘焼焦照症省硝礁祥称章笑粧紹肖菖蒋蕉衝裳訟証詔詳象賞醤鉦鍾鐘障鞘上丈丞乗冗剰城場壌嬢常情擾条杖浄状畳穣蒸譲醸錠嘱埴飾・・・", -"拭植殖燭織職色触食蝕辱尻伸信侵唇娠寝審心慎振新晋森榛浸深申疹真神秦紳臣芯薪親診身辛進針震人仁刃塵壬尋甚尽腎訊迅陣靭笥諏須酢図厨・逗吹垂帥推水炊睡粋翠衰遂酔錐錘随瑞髄崇嵩数枢趨雛据杉椙菅頗雀裾澄摺寸世瀬畝是凄制勢姓征性成政整星晴棲栖正清牲生盛精聖声製西誠誓請逝醒青静斉税脆隻席惜戚斥昔析石積籍績脊責赤跡蹟碩切拙接摂折設窃節説雪絶舌蝉仙先千占宣専尖川戦扇撰栓栴泉浅洗染潜煎煽旋穿箭線・・・", -"繊羨腺舛船薦詮賎践選遷銭銑閃鮮前善漸然全禅繕膳糎噌塑岨措曾曽楚狙疏疎礎祖租粗素組蘇訴阻遡鼠僧創双叢倉喪壮奏爽宋層匝惣想捜掃挿掻・操早曹巣槍槽漕燥争痩相窓糟総綜聡草荘葬蒼藻装走送遭鎗霜騒像増憎臓蔵贈造促側則即息捉束測足速俗属賊族続卒袖其揃存孫尊損村遜他多太汰詑唾堕妥惰打柁舵楕陀駄騨体堆対耐岱帯待怠態戴替泰滞胎腿苔袋貸退逮隊黛鯛代台大第醍題鷹滝瀧卓啄宅托択拓沢濯琢託鐸濁諾茸凧蛸只・・・", -"叩但達辰奪脱巽竪辿棚谷狸鱈樽誰丹単嘆坦担探旦歎淡湛炭短端箪綻耽胆蛋誕鍛団壇弾断暖檀段男談値知地弛恥智池痴稚置致蜘遅馳築畜竹筑蓄・逐秩窒茶嫡着中仲宙忠抽昼柱注虫衷註酎鋳駐樗瀦猪苧著貯丁兆凋喋寵帖帳庁弔張彫徴懲挑暢朝潮牒町眺聴脹腸蝶調諜超跳銚長頂鳥勅捗直朕沈珍賃鎮陳津墜椎槌追鎚痛通塚栂掴槻佃漬柘辻蔦綴鍔椿潰坪壷嬬紬爪吊釣鶴亭低停偵剃貞呈堤定帝底庭廷弟悌抵挺提梯汀碇禎程締艇訂諦蹄逓・・・", -"邸鄭釘鼎泥摘擢敵滴的笛適鏑溺哲徹撤轍迭鉄典填天展店添纏甜貼転顛点伝殿澱田電兎吐堵塗妬屠徒斗杜渡登菟賭途都鍍砥砺努度土奴怒倒党冬・凍刀唐塔塘套宕島嶋悼投搭東桃梼棟盗淘湯涛灯燈当痘祷等答筒糖統到董蕩藤討謄豆踏逃透鐙陶頭騰闘働動同堂導憧撞洞瞳童胴萄道銅峠鴇匿得徳涜特督禿篤毒独読栃橡凸突椴届鳶苫寅酉瀞噸屯惇敦沌豚遁頓呑曇鈍奈那内乍凪薙謎灘捺鍋楢馴縄畷南楠軟難汝二尼弐迩匂賑肉虹廿日乳入・・・", -"如尿韮任妊忍認濡禰祢寧葱猫熱年念捻撚燃粘乃廼之埜嚢悩濃納能脳膿農覗蚤巴把播覇杷波派琶破婆罵芭馬俳廃拝排敗杯盃牌背肺輩配倍培媒梅・楳煤狽買売賠陪這蝿秤矧萩伯剥博拍柏泊白箔粕舶薄迫曝漠爆縛莫駁麦函箱硲箸肇筈櫨幡肌畑畠八鉢溌発醗髪伐罰抜筏閥鳩噺塙蛤隼伴判半反叛帆搬斑板氾汎版犯班畔繁般藩販範釆煩頒飯挽晩番盤磐蕃蛮匪卑否妃庇彼悲扉批披斐比泌疲皮碑秘緋罷肥被誹費避非飛樋簸備尾微枇毘琵眉美・・・", -"鼻柊稗匹疋髭彦膝菱肘弼必畢筆逼桧姫媛紐百謬俵彪標氷漂瓢票表評豹廟描病秒苗錨鋲蒜蛭鰭品彬斌浜瀕貧賓頻敏瓶不付埠夫婦富冨布府怖扶敷・斧普浮父符腐膚芙譜負賦赴阜附侮撫武舞葡蕪部封楓風葺蕗伏副復幅服福腹複覆淵弗払沸仏物鮒分吻噴墳憤扮焚奮粉糞紛雰文聞丙併兵塀幣平弊柄並蔽閉陛米頁僻壁癖碧別瞥蔑箆偏変片篇編辺返遍便勉娩弁鞭保舗鋪圃捕歩甫補輔穂募墓慕戊暮母簿菩倣俸包呆報奉宝峰峯崩庖抱捧放方朋・・・", -"法泡烹砲縫胞芳萌蓬蜂褒訪豊邦鋒飽鳳鵬乏亡傍剖坊妨帽忘忙房暴望某棒冒紡肪膨謀貌貿鉾防吠頬北僕卜墨撲朴牧睦穆釦勃没殆堀幌奔本翻凡盆・摩磨魔麻埋妹昧枚毎哩槙幕膜枕鮪柾鱒桝亦俣又抹末沫迄侭繭麿万慢満漫蔓味未魅巳箕岬密蜜湊蓑稔脈妙粍民眠務夢無牟矛霧鵡椋婿娘冥名命明盟迷銘鳴姪牝滅免棉綿緬面麺摸模茂妄孟毛猛盲網耗蒙儲木黙目杢勿餅尤戻籾貰問悶紋門匁也冶夜爺耶野弥矢厄役約薬訳躍靖柳薮鑓愉愈油癒・・・", -"諭輸唯佑優勇友宥幽悠憂揖有柚湧涌猶猷由祐裕誘遊邑郵雄融夕予余与誉輿預傭幼妖容庸揚揺擁曜楊様洋溶熔用窯羊耀葉蓉要謡踊遥陽養慾抑欲・沃浴翌翼淀羅螺裸来莱頼雷洛絡落酪乱卵嵐欄濫藍蘭覧利吏履李梨理璃痢裏裡里離陸律率立葎掠略劉流溜琉留硫粒隆竜龍侶慮旅虜了亮僚両凌寮料梁涼猟療瞭稜糧良諒遼量陵領力緑倫厘林淋燐琳臨輪隣鱗麟瑠塁涙累類令伶例冷励嶺怜玲礼苓鈴隷零霊麗齢暦歴列劣烈裂廉恋憐漣煉簾練聯・・・", -"蓮連錬呂魯櫓炉賂路露労婁廊弄朗楼榔浪漏牢狼篭老聾蝋郎六麓禄肋録論倭和話歪賄脇惑枠鷲亙亘鰐詫藁蕨椀湾碗腕・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・弌丐丕个丱丶丼丿乂乖乘亂亅豫亊舒弍于亞亟亠亢亰亳亶从仍仄仆仂仗仞仭仟价伉佚估佛佝佗佇佶侈侏侘佻佩佰侑佯來侖儘俔俟俎俘俛俑俚俐俤俥倚倨倔倪倥倅伜俶倡倩倬俾俯們倆偃假會偕偐偈做偖偬偸傀傚傅傴傲・・・", -"僉僊傳僂僖僞僥僭僣僮價僵儉儁儂儖儕儔儚儡儺儷儼儻儿兀兒兌兔兢竸兩兪兮冀冂囘册冉冏冑冓冕冖冤冦冢冩冪冫决冱冲冰况冽凅凉凛几處凩凭・凰凵凾刄刋刔刎刧刪刮刳刹剏剄剋剌剞剔剪剴剩剳剿剽劍劔劒剱劈劑辨辧劬劭劼劵勁勍勗勞勣勦飭勠勳勵勸勹匆匈甸匍匐匏匕匚匣匯匱匳匸區卆卅丗卉卍凖卞卩卮夘卻卷厂厖厠厦厥厮厰厶參簒雙叟曼燮叮叨叭叺吁吽呀听吭吼吮吶吩吝呎咏呵咎呟呱呷呰咒呻咀呶咄咐咆哇咢咸咥咬哄哈咨・・・", -"咫哂咤咾咼哘哥哦唏唔哽哮哭哺哢唹啀啣啌售啜啅啖啗唸唳啝喙喀咯喊喟啻啾喘喞單啼喃喩喇喨嗚嗅嗟嗄嗜嗤嗔嘔嗷嘖嗾嗽嘛嗹噎噐營嘴嘶嘲嘸・噫噤嘯噬噪嚆嚀嚊嚠嚔嚏嚥嚮嚶嚴囂嚼囁囃囀囈囎囑囓囗囮囹圀囿圄圉圈國圍圓團圖嗇圜圦圷圸坎圻址坏坩埀垈坡坿垉垓垠垳垤垪垰埃埆埔埒埓堊埖埣堋堙堝塲堡塢塋塰毀塒堽塹墅墹墟墫墺壞墻墸墮壅壓壑壗壙壘壥壜壤壟壯壺壹壻壼壽夂夊夐夛梦夥夬夭夲夸夾竒奕奐奎奚奘奢奠奧奬奩・・・", -"奸妁妝佞侫妣妲姆姨姜妍姙姚娥娟娑娜娉娚婀婬婉娵娶婢婪媚媼媾嫋嫂媽嫣嫗嫦嫩嫖嫺嫻嬌嬋嬖嬲嫐嬪嬶嬾孃孅孀孑孕孚孛孥孩孰孳孵學斈孺宀・它宦宸寃寇寉寔寐寤實寢寞寥寫寰寶寳尅將專對尓尠尢尨尸尹屁屆屎屓屐屏孱屬屮乢屶屹岌岑岔妛岫岻岶岼岷峅岾峇峙峩峽峺峭嶌峪崋崕崗嵜崟崛崑崔崢崚崙崘嵌嵒嵎嵋嵬嵳嵶嶇嶄嶂嶢嶝嶬嶮嶽嶐嶷嶼巉巍巓巒巖巛巫已巵帋帚帙帑帛帶帷幄幃幀幎幗幔幟幢幤幇幵并幺麼广庠廁廂廈廐廏・・・", -"廖廣廝廚廛廢廡廨廩廬廱廳廰廴廸廾弃弉彝彜弋弑弖弩弭弸彁彈彌彎弯彑彖彗彙彡彭彳彷徃徂彿徊很徑徇從徙徘徠徨徭徼忖忻忤忸忱忝悳忿怡恠・怙怐怩怎怱怛怕怫怦怏怺恚恁恪恷恟恊恆恍恣恃恤恂恬恫恙悁悍惧悃悚悄悛悖悗悒悧悋惡悸惠惓悴忰悽惆悵惘慍愕愆惶惷愀惴惺愃愡惻惱愍愎慇愾愨愧慊愿愼愬愴愽慂慄慳慷慘慙慚慫慴慯慥慱慟慝慓慵憙憖憇憬憔憚憊憑憫憮懌懊應懷懈懃懆憺懋罹懍懦懣懶懺懴懿懽懼懾戀戈戉戍戌戔戛・・・", -"戞戡截戮戰戲戳扁扎扞扣扛扠扨扼抂抉找抒抓抖拔抃抔拗拑抻拏拿拆擔拈拜拌拊拂拇抛拉挌拮拱挧挂挈拯拵捐挾捍搜捏掖掎掀掫捶掣掏掉掟掵捫・捩掾揩揀揆揣揉插揶揄搖搴搆搓搦搶攝搗搨搏摧摯摶摎攪撕撓撥撩撈撼據擒擅擇撻擘擂擱擧舉擠擡抬擣擯攬擶擴擲擺攀擽攘攜攅攤攣攫攴攵攷收攸畋效敖敕敍敘敞敝敲數斂斃變斛斟斫斷旃旆旁旄旌旒旛旙无旡旱杲昊昃旻杳昵昶昴昜晏晄晉晁晞晝晤晧晨晟晢晰暃暈暎暉暄暘暝曁暹曉暾暼・・・", -"曄暸曖曚曠昿曦曩曰曵曷朏朖朞朦朧霸朮朿朶杁朸朷杆杞杠杙杣杤枉杰枩杼杪枌枋枦枡枅枷柯枴柬枳柩枸柤柞柝柢柮枹柎柆柧檜栞框栩桀桍栲桎・梳栫桙档桷桿梟梏梭梔條梛梃檮梹桴梵梠梺椏梍桾椁棊椈棘椢椦棡椌棍棔棧棕椶椒椄棗棣椥棹棠棯椨椪椚椣椡棆楹楷楜楸楫楔楾楮椹楴椽楙椰楡楞楝榁楪榲榮槐榿槁槓榾槎寨槊槝榻槃榧樮榑榠榜榕榴槞槨樂樛槿權槹槲槧樅榱樞槭樔槫樊樒櫁樣樓橄樌橲樶橸橇橢橙橦橈樸樢檐檍檠檄檢檣・・・", -"檗蘗檻櫃櫂檸檳檬櫞櫑櫟檪櫚櫪櫻欅蘖櫺欒欖鬱欟欸欷盜欹飮歇歃歉歐歙歔歛歟歡歸歹歿殀殄殃殍殘殕殞殤殪殫殯殲殱殳殷殼毆毋毓毟毬毫毳毯・麾氈氓气氛氤氣汞汕汢汪沂沍沚沁沛汾汨汳沒沐泄泱泓沽泗泅泝沮沱沾沺泛泯泙泪洟衍洶洫洽洸洙洵洳洒洌浣涓浤浚浹浙涎涕濤涅淹渕渊涵淇淦涸淆淬淞淌淨淒淅淺淙淤淕淪淮渭湮渮渙湲湟渾渣湫渫湶湍渟湃渺湎渤滿渝游溂溪溘滉溷滓溽溯滄溲滔滕溏溥滂溟潁漑灌滬滸滾漿滲漱滯漲滌・・・", - }; - - internal JapaneseCtdEncoder() - { - throw new System.NotImplementedException(); - } - - public string ToText(byte[] data) - { - throw new System.NotImplementedException(); - } - - public byte[] FromText(string text) - { - throw new System.NotImplementedException(); - } - - public IEnumerable FromUcs(IEnumerable ucs) - { - throw new System.NotImplementedException(); - } - - public IEnumerable ToUcs(IEnumerable data) - { - throw new System.NotImplementedException(); - } - } -} +using System.Collections.Generic; + +namespace OpenKh.Bbs.Messages.Internals +{ + internal class JapaneseCtdEncoder : ICtdMessageEncoder + { + private static readonly string[] _encoding = new string[] + { + " 、。,.・:;?!゛゜´`¨^ ̄_ヽヾゝゞ〃仝々〆〇ー―‐/\~∥|…‥‘’“”()〔〕[]{}〈〉《》「」『』【】+-±×・÷=≠<>≦≧∞∴♂♀°′″℃¥$¢£%#&*@§☆★○●◎◇◆□■△▲▽▼※〒→←↑↓〓・・・・・・・・・・・∈∋⊆⊇⊂⊃∪∩・・・・・・・・∧∨¬⇒⇔∀∃・・・・・・・・・・・∠⊥⌒∂∇≡≒≪≫√∽∝∵∫∬・・・・・・・ʼn♯♭♪†‡¶・・・・◯・・・", +"・・・・・・・・・・・・・・・0123456789・・・・・・・ABCDEFGHIJKLMNOPQRSTUVWXYZ・・・・・・・abcdefghijklmnopqrstuvwxyz・・・・ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをん・・・・・・・・・・・・・・", +"ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミ・ムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶ・・・・・・・・ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ・・・・・・・・αβγδεζηθικλμνξοπρστυφχψω・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・", +"АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ・・・・・・・・・・・・・・・абвгдеёжзийклмн・опрстуфхцчшщъыьэюя・・・・・・・・・・・・・─│┌┐┘└├┬┤┴┼━┃┏┓┛┗┣┳┫┻╋┠┯┨┷┿┝┰┥┸╂・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・", +"・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・", +"・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・", +"①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ・㍉㌔㌢㍍㌘㌧㌃㌶㍑㍗㌍㌦㌣㌫㍊㌻㎜㎝㎞㎎㎏㏄㎡・・・・・・・・㍻・〝〟№㏍℡㊤㊥㊦㊧㊨㈱㈲㈹㍾㍽㍼≒≡∫∮∑√⊥∠∟⊿∵∩∪・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・", +"・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・亜唖娃阿哀愛挨姶逢葵茜穐悪握渥旭葦芦鯵梓圧斡扱宛姐虻飴絢綾鮎或粟袷安庵按暗案闇鞍杏以伊位依偉囲夷委威尉惟意慰易椅為畏異移維緯胃萎衣謂違遺医井亥域育郁磯一壱溢逸稲茨芋鰯允印咽員因姻引飲淫胤蔭・・・", +"院陰隠韻吋右宇烏羽迂雨卯鵜窺丑碓臼渦嘘唄欝蔚鰻姥厩浦瓜閏噂云運雲荏餌叡営嬰影映曳栄永泳洩瑛盈穎頴英衛詠鋭液疫益駅悦謁越閲榎厭円・園堰奄宴延怨掩援沿演炎焔煙燕猿縁艶苑薗遠鉛鴛塩於汚甥凹央奥往応押旺横欧殴王翁襖鴬鴎黄岡沖荻億屋憶臆桶牡乙俺卸恩温穏音下化仮何伽価佳加可嘉夏嫁家寡科暇果架歌河火珂禍禾稼箇花苛茄荷華菓蝦課嘩貨迦過霞蚊俄峨我牙画臥芽蛾賀雅餓駕介会解回塊壊廻快怪悔恢懐戒拐改・・・", +"魁晦械海灰界皆絵芥蟹開階貝凱劾外咳害崖慨概涯碍蓋街該鎧骸浬馨蛙垣柿蛎鈎劃嚇各廓拡撹格核殻獲確穫覚角赫較郭閣隔革学岳楽額顎掛笠樫・橿梶鰍潟割喝恰括活渇滑葛褐轄且鰹叶椛樺鞄株兜竃蒲釜鎌噛鴨栢茅萱粥刈苅瓦乾侃冠寒刊勘勧巻喚堪姦完官寛干幹患感慣憾換敢柑桓棺款歓汗漢澗潅環甘監看竿管簡緩缶翰肝艦莞観諌貫還鑑間閑関陥韓館舘丸含岸巌玩癌眼岩翫贋雁頑顔願企伎危喜器基奇嬉寄岐希幾忌揮机旗既期棋棄・・・", +"機帰毅気汽畿祈季稀紀徽規記貴起軌輝飢騎鬼亀偽儀妓宜戯技擬欺犠疑祇義蟻誼議掬菊鞠吉吃喫桔橘詰砧杵黍却客脚虐逆丘久仇休及吸宮弓急救・朽求汲泣灸球究窮笈級糾給旧牛去居巨拒拠挙渠虚許距鋸漁禦魚亨享京供侠僑兇競共凶協匡卿叫喬境峡強彊怯恐恭挟教橋況狂狭矯胸脅興蕎郷鏡響饗驚仰凝尭暁業局曲極玉桐粁僅勤均巾錦斤欣欽琴禁禽筋緊芹菌衿襟謹近金吟銀九倶句区狗玖矩苦躯駆駈駒具愚虞喰空偶寓遇隅串櫛釧屑屈・・・", +"掘窟沓靴轡窪熊隈粂栗繰桑鍬勲君薫訓群軍郡卦袈祁係傾刑兄啓圭珪型契形径恵慶慧憩掲携敬景桂渓畦稽系経継繋罫茎荊蛍計詣警軽頚鶏芸迎鯨・劇戟撃激隙桁傑欠決潔穴結血訣月件倹倦健兼券剣喧圏堅嫌建憲懸拳捲検権牽犬献研硯絹県肩見謙賢軒遣鍵険顕験鹸元原厳幻弦減源玄現絃舷言諺限乎個古呼固姑孤己庫弧戸故枯湖狐糊袴股胡菰虎誇跨鈷雇顧鼓五互伍午呉吾娯後御悟梧檎瑚碁語誤護醐乞鯉交佼侯候倖光公功効勾厚口向・・・", +"后喉坑垢好孔孝宏工巧巷幸広庚康弘恒慌抗拘控攻昂晃更杭校梗構江洪浩港溝甲皇硬稿糠紅紘絞綱耕考肯肱腔膏航荒行衡講貢購郊酵鉱砿鋼閤降・項香高鴻剛劫号合壕拷濠豪轟麹克刻告国穀酷鵠黒獄漉腰甑忽惚骨狛込此頃今困坤墾婚恨懇昏昆根梱混痕紺艮魂些佐叉唆嵯左差査沙瑳砂詐鎖裟坐座挫債催再最哉塞妻宰彩才採栽歳済災采犀砕砦祭斎細菜裁載際剤在材罪財冴坂阪堺榊肴咲崎埼碕鷺作削咋搾昨朔柵窄策索錯桜鮭笹匙冊刷・・・", +"察拶撮擦札殺薩雑皐鯖捌錆鮫皿晒三傘参山惨撒散桟燦珊産算纂蚕讃賛酸餐斬暫残仕仔伺使刺司史嗣四士始姉姿子屍市師志思指支孜斯施旨枝止・死氏獅祉私糸紙紫肢脂至視詞詩試誌諮資賜雌飼歯事似侍児字寺慈持時次滋治爾璽痔磁示而耳自蒔辞汐鹿式識鴫竺軸宍雫七叱執失嫉室悉湿漆疾質実蔀篠偲柴芝屡蕊縞舎写射捨赦斜煮社紗者謝車遮蛇邪借勺尺杓灼爵酌釈錫若寂弱惹主取守手朱殊狩珠種腫趣酒首儒受呪寿授樹綬需囚収周・・・", +"宗就州修愁拾洲秀秋終繍習臭舟蒐衆襲讐蹴輯週酋酬集醜什住充十従戎柔汁渋獣縦重銃叔夙宿淑祝縮粛塾熟出術述俊峻春瞬竣舜駿准循旬楯殉淳・準潤盾純巡遵醇順処初所暑曙渚庶緒署書薯藷諸助叙女序徐恕鋤除傷償勝匠升召哨商唱嘗奨妾娼宵将小少尚庄床廠彰承抄招掌捷昇昌昭晶松梢樟樵沼消渉湘焼焦照症省硝礁祥称章笑粧紹肖菖蒋蕉衝裳訟証詔詳象賞醤鉦鍾鐘障鞘上丈丞乗冗剰城場壌嬢常情擾条杖浄状畳穣蒸譲醸錠嘱埴飾・・・", +"拭植殖燭織職色触食蝕辱尻伸信侵唇娠寝審心慎振新晋森榛浸深申疹真神秦紳臣芯薪親診身辛進針震人仁刃塵壬尋甚尽腎訊迅陣靭笥諏須酢図厨・逗吹垂帥推水炊睡粋翠衰遂酔錐錘随瑞髄崇嵩数枢趨雛据杉椙菅頗雀裾澄摺寸世瀬畝是凄制勢姓征性成政整星晴棲栖正清牲生盛精聖声製西誠誓請逝醒青静斉税脆隻席惜戚斥昔析石積籍績脊責赤跡蹟碩切拙接摂折設窃節説雪絶舌蝉仙先千占宣専尖川戦扇撰栓栴泉浅洗染潜煎煽旋穿箭線・・・", +"繊羨腺舛船薦詮賎践選遷銭銑閃鮮前善漸然全禅繕膳糎噌塑岨措曾曽楚狙疏疎礎祖租粗素組蘇訴阻遡鼠僧創双叢倉喪壮奏爽宋層匝惣想捜掃挿掻・操早曹巣槍槽漕燥争痩相窓糟総綜聡草荘葬蒼藻装走送遭鎗霜騒像増憎臓蔵贈造促側則即息捉束測足速俗属賊族続卒袖其揃存孫尊損村遜他多太汰詑唾堕妥惰打柁舵楕陀駄騨体堆対耐岱帯待怠態戴替泰滞胎腿苔袋貸退逮隊黛鯛代台大第醍題鷹滝瀧卓啄宅托択拓沢濯琢託鐸濁諾茸凧蛸只・・・", +"叩但達辰奪脱巽竪辿棚谷狸鱈樽誰丹単嘆坦担探旦歎淡湛炭短端箪綻耽胆蛋誕鍛団壇弾断暖檀段男談値知地弛恥智池痴稚置致蜘遅馳築畜竹筑蓄・逐秩窒茶嫡着中仲宙忠抽昼柱注虫衷註酎鋳駐樗瀦猪苧著貯丁兆凋喋寵帖帳庁弔張彫徴懲挑暢朝潮牒町眺聴脹腸蝶調諜超跳銚長頂鳥勅捗直朕沈珍賃鎮陳津墜椎槌追鎚痛通塚栂掴槻佃漬柘辻蔦綴鍔椿潰坪壷嬬紬爪吊釣鶴亭低停偵剃貞呈堤定帝底庭廷弟悌抵挺提梯汀碇禎程締艇訂諦蹄逓・・・", +"邸鄭釘鼎泥摘擢敵滴的笛適鏑溺哲徹撤轍迭鉄典填天展店添纏甜貼転顛点伝殿澱田電兎吐堵塗妬屠徒斗杜渡登菟賭途都鍍砥砺努度土奴怒倒党冬・凍刀唐塔塘套宕島嶋悼投搭東桃梼棟盗淘湯涛灯燈当痘祷等答筒糖統到董蕩藤討謄豆踏逃透鐙陶頭騰闘働動同堂導憧撞洞瞳童胴萄道銅峠鴇匿得徳涜特督禿篤毒独読栃橡凸突椴届鳶苫寅酉瀞噸屯惇敦沌豚遁頓呑曇鈍奈那内乍凪薙謎灘捺鍋楢馴縄畷南楠軟難汝二尼弐迩匂賑肉虹廿日乳入・・・", +"如尿韮任妊忍認濡禰祢寧葱猫熱年念捻撚燃粘乃廼之埜嚢悩濃納能脳膿農覗蚤巴把播覇杷波派琶破婆罵芭馬俳廃拝排敗杯盃牌背肺輩配倍培媒梅・楳煤狽買売賠陪這蝿秤矧萩伯剥博拍柏泊白箔粕舶薄迫曝漠爆縛莫駁麦函箱硲箸肇筈櫨幡肌畑畠八鉢溌発醗髪伐罰抜筏閥鳩噺塙蛤隼伴判半反叛帆搬斑板氾汎版犯班畔繁般藩販範釆煩頒飯挽晩番盤磐蕃蛮匪卑否妃庇彼悲扉批披斐比泌疲皮碑秘緋罷肥被誹費避非飛樋簸備尾微枇毘琵眉美・・・", +"鼻柊稗匹疋髭彦膝菱肘弼必畢筆逼桧姫媛紐百謬俵彪標氷漂瓢票表評豹廟描病秒苗錨鋲蒜蛭鰭品彬斌浜瀕貧賓頻敏瓶不付埠夫婦富冨布府怖扶敷・斧普浮父符腐膚芙譜負賦赴阜附侮撫武舞葡蕪部封楓風葺蕗伏副復幅服福腹複覆淵弗払沸仏物鮒分吻噴墳憤扮焚奮粉糞紛雰文聞丙併兵塀幣平弊柄並蔽閉陛米頁僻壁癖碧別瞥蔑箆偏変片篇編辺返遍便勉娩弁鞭保舗鋪圃捕歩甫補輔穂募墓慕戊暮母簿菩倣俸包呆報奉宝峰峯崩庖抱捧放方朋・・・", +"法泡烹砲縫胞芳萌蓬蜂褒訪豊邦鋒飽鳳鵬乏亡傍剖坊妨帽忘忙房暴望某棒冒紡肪膨謀貌貿鉾防吠頬北僕卜墨撲朴牧睦穆釦勃没殆堀幌奔本翻凡盆・摩磨魔麻埋妹昧枚毎哩槙幕膜枕鮪柾鱒桝亦俣又抹末沫迄侭繭麿万慢満漫蔓味未魅巳箕岬密蜜湊蓑稔脈妙粍民眠務夢無牟矛霧鵡椋婿娘冥名命明盟迷銘鳴姪牝滅免棉綿緬面麺摸模茂妄孟毛猛盲網耗蒙儲木黙目杢勿餅尤戻籾貰問悶紋門匁也冶夜爺耶野弥矢厄役約薬訳躍靖柳薮鑓愉愈油癒・・・", +"諭輸唯佑優勇友宥幽悠憂揖有柚湧涌猶猷由祐裕誘遊邑郵雄融夕予余与誉輿預傭幼妖容庸揚揺擁曜楊様洋溶熔用窯羊耀葉蓉要謡踊遥陽養慾抑欲・沃浴翌翼淀羅螺裸来莱頼雷洛絡落酪乱卵嵐欄濫藍蘭覧利吏履李梨理璃痢裏裡里離陸律率立葎掠略劉流溜琉留硫粒隆竜龍侶慮旅虜了亮僚両凌寮料梁涼猟療瞭稜糧良諒遼量陵領力緑倫厘林淋燐琳臨輪隣鱗麟瑠塁涙累類令伶例冷励嶺怜玲礼苓鈴隷零霊麗齢暦歴列劣烈裂廉恋憐漣煉簾練聯・・・", +"蓮連錬呂魯櫓炉賂路露労婁廊弄朗楼榔浪漏牢狼篭老聾蝋郎六麓禄肋録論倭和話歪賄脇惑枠鷲亙亘鰐詫藁蕨椀湾碗腕・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・弌丐丕个丱丶丼丿乂乖乘亂亅豫亊舒弍于亞亟亠亢亰亳亶从仍仄仆仂仗仞仭仟价伉佚估佛佝佗佇佶侈侏侘佻佩佰侑佯來侖儘俔俟俎俘俛俑俚俐俤俥倚倨倔倪倥倅伜俶倡倩倬俾俯們倆偃假會偕偐偈做偖偬偸傀傚傅傴傲・・・", +"僉僊傳僂僖僞僥僭僣僮價僵儉儁儂儖儕儔儚儡儺儷儼儻儿兀兒兌兔兢竸兩兪兮冀冂囘册冉冏冑冓冕冖冤冦冢冩冪冫决冱冲冰况冽凅凉凛几處凩凭・凰凵凾刄刋刔刎刧刪刮刳刹剏剄剋剌剞剔剪剴剩剳剿剽劍劔劒剱劈劑辨辧劬劭劼劵勁勍勗勞勣勦飭勠勳勵勸勹匆匈甸匍匐匏匕匚匣匯匱匳匸區卆卅丗卉卍凖卞卩卮夘卻卷厂厖厠厦厥厮厰厶參簒雙叟曼燮叮叨叭叺吁吽呀听吭吼吮吶吩吝呎咏呵咎呟呱呷呰咒呻咀呶咄咐咆哇咢咸咥咬哄哈咨・・・", +"咫哂咤咾咼哘哥哦唏唔哽哮哭哺哢唹啀啣啌售啜啅啖啗唸唳啝喙喀咯喊喟啻啾喘喞單啼喃喩喇喨嗚嗅嗟嗄嗜嗤嗔嘔嗷嘖嗾嗽嘛嗹噎噐營嘴嘶嘲嘸・噫噤嘯噬噪嚆嚀嚊嚠嚔嚏嚥嚮嚶嚴囂嚼囁囃囀囈囎囑囓囗囮囹圀囿圄圉圈國圍圓團圖嗇圜圦圷圸坎圻址坏坩埀垈坡坿垉垓垠垳垤垪垰埃埆埔埒埓堊埖埣堋堙堝塲堡塢塋塰毀塒堽塹墅墹墟墫墺壞墻墸墮壅壓壑壗壙壘壥壜壤壟壯壺壹壻壼壽夂夊夐夛梦夥夬夭夲夸夾竒奕奐奎奚奘奢奠奧奬奩・・・", +"奸妁妝佞侫妣妲姆姨姜妍姙姚娥娟娑娜娉娚婀婬婉娵娶婢婪媚媼媾嫋嫂媽嫣嫗嫦嫩嫖嫺嫻嬌嬋嬖嬲嫐嬪嬶嬾孃孅孀孑孕孚孛孥孩孰孳孵學斈孺宀・它宦宸寃寇寉寔寐寤實寢寞寥寫寰寶寳尅將專對尓尠尢尨尸尹屁屆屎屓屐屏孱屬屮乢屶屹岌岑岔妛岫岻岶岼岷峅岾峇峙峩峽峺峭嶌峪崋崕崗嵜崟崛崑崔崢崚崙崘嵌嵒嵎嵋嵬嵳嵶嶇嶄嶂嶢嶝嶬嶮嶽嶐嶷嶼巉巍巓巒巖巛巫已巵帋帚帙帑帛帶帷幄幃幀幎幗幔幟幢幤幇幵并幺麼广庠廁廂廈廐廏・・・", +"廖廣廝廚廛廢廡廨廩廬廱廳廰廴廸廾弃弉彝彜弋弑弖弩弭弸彁彈彌彎弯彑彖彗彙彡彭彳彷徃徂彿徊很徑徇從徙徘徠徨徭徼忖忻忤忸忱忝悳忿怡恠・怙怐怩怎怱怛怕怫怦怏怺恚恁恪恷恟恊恆恍恣恃恤恂恬恫恙悁悍惧悃悚悄悛悖悗悒悧悋惡悸惠惓悴忰悽惆悵惘慍愕愆惶惷愀惴惺愃愡惻惱愍愎慇愾愨愧慊愿愼愬愴愽慂慄慳慷慘慙慚慫慴慯慥慱慟慝慓慵憙憖憇憬憔憚憊憑憫憮懌懊應懷懈懃懆憺懋罹懍懦懣懶懺懴懿懽懼懾戀戈戉戍戌戔戛・・・", +"戞戡截戮戰戲戳扁扎扞扣扛扠扨扼抂抉找抒抓抖拔抃抔拗拑抻拏拿拆擔拈拜拌拊拂拇抛拉挌拮拱挧挂挈拯拵捐挾捍搜捏掖掎掀掫捶掣掏掉掟掵捫・捩掾揩揀揆揣揉插揶揄搖搴搆搓搦搶攝搗搨搏摧摯摶摎攪撕撓撥撩撈撼據擒擅擇撻擘擂擱擧舉擠擡抬擣擯攬擶擴擲擺攀擽攘攜攅攤攣攫攴攵攷收攸畋效敖敕敍敘敞敝敲數斂斃變斛斟斫斷旃旆旁旄旌旒旛旙无旡旱杲昊昃旻杳昵昶昴昜晏晄晉晁晞晝晤晧晨晟晢晰暃暈暎暉暄暘暝曁暹曉暾暼・・・", +"曄暸曖曚曠昿曦曩曰曵曷朏朖朞朦朧霸朮朿朶杁朸朷杆杞杠杙杣杤枉杰枩杼杪枌枋枦枡枅枷柯枴柬枳柩枸柤柞柝柢柮枹柎柆柧檜栞框栩桀桍栲桎・梳栫桙档桷桿梟梏梭梔條梛梃檮梹桴梵梠梺椏梍桾椁棊椈棘椢椦棡椌棍棔棧棕椶椒椄棗棣椥棹棠棯椨椪椚椣椡棆楹楷楜楸楫楔楾楮椹楴椽楙椰楡楞楝榁楪榲榮槐榿槁槓榾槎寨槊槝榻槃榧樮榑榠榜榕榴槞槨樂樛槿權槹槲槧樅榱樞槭樔槫樊樒櫁樣樓橄樌橲樶橸橇橢橙橦橈樸樢檐檍檠檄檢檣・・・", +"檗蘗檻櫃櫂檸檳檬櫞櫑櫟檪櫚櫪櫻欅蘖櫺欒欖鬱欟欸欷盜欹飮歇歃歉歐歙歔歛歟歡歸歹歿殀殄殃殍殘殕殞殤殪殫殯殲殱殳殷殼毆毋毓毟毬毫毳毯・麾氈氓气氛氤氣汞汕汢汪沂沍沚沁沛汾汨汳沒沐泄泱泓沽泗泅泝沮沱沾沺泛泯泙泪洟衍洶洫洽洸洙洵洳洒洌浣涓浤浚浹浙涎涕濤涅淹渕渊涵淇淦涸淆淬淞淌淨淒淅淺淙淤淕淪淮渭湮渮渙湲湟渾渣湫渫湶湍渟湃渺湎渤滿渝游溂溪溘滉溷滓溽溯滄溲滔滕溏溥滂溟潁漑灌滬滸滾漿滲漱滯漲滌・・・", + }; + + internal JapaneseCtdEncoder() + { + throw new System.NotImplementedException(); + } + + public string ToText(byte[] data) + { + throw new System.NotImplementedException(); + } + + public byte[] FromText(string text) + { + throw new System.NotImplementedException(); + } + + public IEnumerable FromUcs(IEnumerable ucs) + { + throw new System.NotImplementedException(); + } + + public IEnumerable ToUcs(IEnumerable data) + { + throw new System.NotImplementedException(); + } + } +} diff --git a/OpenKh.Bbs/Olo.cs b/OpenKh.Bbs/Olo.cs index ade23357e..3c856a862 100644 --- a/OpenKh.Bbs/Olo.cs +++ b/OpenKh.Bbs/Olo.cs @@ -1,88 +1,88 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Bbs -{ - public class Olo - { - public Dictionary SpawnObjectList = new Dictionary() - { - {"g01ex00", "Savepoint"}, - {"g02ex00", "Examine Actor (To place on static object)"}, - {"g03ex00", "Crown (Puzzle)"}, - - {"p01ex00", "Ventus (PC)"}, - {"p02ex00", "Aqua (PC)"}, - {"p03ex00", "Terra (PC)"}, - {"p11ex00", "Ventus Armor (PC)"}, - {"p12ex00", "Aqua Armor (PC)"}, - {"p13ex00", "Terra Armor (PC)"}, - {"p41ex00", "Ventus Armor Helmetless (PC)"}, - {"p42ex00", "Aqua Armor Helmetless (PC)"}, - {"p43ex00", "Terra Armor Helmetless (PC)"}, - - {"n10ex00", "Moogle Shop 1"}, - {"n11ex00", "Moogle Shop 2"}, - {"n12ex00", "Moogle Shop 3"}, - {"n13ex00", "Moogle Shop 4"}, - }; - - private const int MagicCode = 0x4F4C4F40; // Always @OLO - - private struct UnkStruct - { - [Data] public int unk1 { get; set; } // 0x1 for bosses - 0x2 execute special code. SHOP-SAVE-TALK NECESSARY FOR OBJECTS TO APPEAR - [Data] public int ExtraDataOffset { get; set; } - } - - private struct OLOInfo - { - - } - - // Y-Axis is UP. - private struct SpawnStruct - { - [Data] public int UnknownVal1 { get; set; } - [Data] public float PositionX { get; set; } - [Data] public float PositionY { get; set; } - [Data] public float PositionZ { get; set; } - [Data] public float RotationX { get; set; } - [Data] public float RotationY { get; set; } - [Data] public float RotationZ { get; set; } // Yaw - } - - private readonly Header _header; - - private class Header - { - [Data] public int MagicCode { get; set; } - [Data] public short unkStructNumber1 { get; set; } // Pretty much always 5. - [Data] public short unkStructNumber2 { get; set; } - [Data] public int NumObjectsToSpawn { get; set; } - [Data] public int HeaderLength { get; set; } - [Data] public List UnkData { get; set; } // Repeats by unkStructNumber1. - [Data] public int padding { get; set; } - } - - [Data] public List ObjectsLoaded { get; set; } - - private Olo() - { - - } - - public static bool IsValid(Stream stream) - { - var prevPosition = stream.Position; - var magicCode = new BinaryReader(stream).ReadInt32(); - stream.Position = prevPosition; - - return magicCode == MagicCode; - } - - public static List Read(Stream stream) => - BinaryMapping.ReadObject(stream).ObjectsLoaded; - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Bbs +{ + public class Olo + { + public Dictionary SpawnObjectList = new Dictionary() + { + {"g01ex00", "Savepoint"}, + {"g02ex00", "Examine Actor (To place on static object)"}, + {"g03ex00", "Crown (Puzzle)"}, + + {"p01ex00", "Ventus (PC)"}, + {"p02ex00", "Aqua (PC)"}, + {"p03ex00", "Terra (PC)"}, + {"p11ex00", "Ventus Armor (PC)"}, + {"p12ex00", "Aqua Armor (PC)"}, + {"p13ex00", "Terra Armor (PC)"}, + {"p41ex00", "Ventus Armor Helmetless (PC)"}, + {"p42ex00", "Aqua Armor Helmetless (PC)"}, + {"p43ex00", "Terra Armor Helmetless (PC)"}, + + {"n10ex00", "Moogle Shop 1"}, + {"n11ex00", "Moogle Shop 2"}, + {"n12ex00", "Moogle Shop 3"}, + {"n13ex00", "Moogle Shop 4"}, + }; + + private const int MagicCode = 0x4F4C4F40; // Always @OLO + + private struct UnkStruct + { + [Data] public int unk1 { get; set; } // 0x1 for bosses - 0x2 execute special code. SHOP-SAVE-TALK NECESSARY FOR OBJECTS TO APPEAR + [Data] public int ExtraDataOffset { get; set; } + } + + private struct OLOInfo + { + + } + + // Y-Axis is UP. + private struct SpawnStruct + { + [Data] public int UnknownVal1 { get; set; } + [Data] public float PositionX { get; set; } + [Data] public float PositionY { get; set; } + [Data] public float PositionZ { get; set; } + [Data] public float RotationX { get; set; } + [Data] public float RotationY { get; set; } + [Data] public float RotationZ { get; set; } // Yaw + } + + private readonly Header _header; + + private class Header + { + [Data] public int MagicCode { get; set; } + [Data] public short unkStructNumber1 { get; set; } // Pretty much always 5. + [Data] public short unkStructNumber2 { get; set; } + [Data] public int NumObjectsToSpawn { get; set; } + [Data] public int HeaderLength { get; set; } + [Data] public List UnkData { get; set; } // Repeats by unkStructNumber1. + [Data] public int padding { get; set; } + } + + [Data] public List ObjectsLoaded { get; set; } + + private Olo() + { + + } + + public static bool IsValid(Stream stream) + { + var prevPosition = stream.Position; + var magicCode = new BinaryReader(stream).ReadInt32(); + stream.Position = prevPosition; + + return magicCode == MagicCode; + } + + public static List Read(Stream stream) => + BinaryMapping.ReadObject(stream).ObjectsLoaded; + } +} diff --git a/OpenKh.Bbs/Pam.cs b/OpenKh.Bbs/Pam.cs index 0afcaab37..08cf7ee25 100644 --- a/OpenKh.Bbs/Pam.cs +++ b/OpenKh.Bbs/Pam.cs @@ -1,579 +1,579 @@ -using OpenKh.Common; -using OpenKh.Imaging; - -using System; -using System.Collections.Generic; -using System.IO; -using System.Numerics; -using Xe.BinaryMapper; -using System.Linq; -using System.Text; -using OpenKh.Common.Utils; - -namespace OpenKh.Bbs -{ - public class Pam - { - private const uint MagicCode = 0x4D4150; - - public class Header - { - [Data] public uint MagicCode { get; set; } - [Data] public uint AnimationCount { get; set; } - [Data(Count = 6)] public byte[] Padding { get; set; } - [Data] public ushort Version { get; set; } - } - - public class AnimationEntry - { - [Data] public uint AnimationOffset { get; set; } - [Data(Count = 12)] public string AnimationName { get; set; } - } - - public class AnimationHeader - { - [Data] public ushort Flag { get; set; } - [Data] public byte Framerate { get; set; } - [Data] public byte InterpFrameCount { get; set; } - [Data] public ushort LoopFrame { get; set; } - [Data] public byte BoneCount { get; set; } - [Data] public byte Padding { get; set; } - [Data] public ushort FrameCount { get; set; } - [Data] public ushort ReturnFrame { get; set; } - } - - public struct AnimationFlag - { - [Data] public bool TranslationX { get; set; } - [Data] public bool TranslationY { get; set; } - [Data] public bool TranslationZ { get; set; } - [Data] public bool RotationX { get; set; } - [Data] public bool RotationY { get; set; } - [Data] public bool RotationZ { get; set; } - [Data] public bool ScaleX { get; set; } - [Data] public bool ScaleY { get; set; } - [Data] public bool ScaleZ { get; set; } - } - - public static AnimationFlag GetAnimFlags(ushort Flag) - { - AnimationFlag flag = new AnimationFlag(); - - flag.TranslationX = BitsUtil.Int.GetBit(Flag, 0); - flag.TranslationY = BitsUtil.Int.GetBit(Flag, 1); - flag.TranslationZ = BitsUtil.Int.GetBit(Flag, 2); - flag.RotationX = BitsUtil.Int.GetBit(Flag, 3); - flag.RotationY = BitsUtil.Int.GetBit(Flag, 4); - flag.RotationZ = BitsUtil.Int.GetBit(Flag, 5); - flag.ScaleX = BitsUtil.Int.GetBit(Flag, 6); - flag.ScaleY = BitsUtil.Int.GetBit(Flag, 7); - flag.ScaleZ = BitsUtil.Int.GetBit(Flag, 8); - - return flag; - } - - public class ChannelHeader - { - [Data] public float MaxValue { get; set; } - [Data] public float MinValue { get; set; } - [Data] public byte KeyframeCount_8bits { get; set; } - [Data] public ushort KeyframeCount_16bits { get; set; } - } - - public class KeyframeEntry - { - [Data] public byte FrameID_8bits { get; set; } - [Data] public ushort FrameID_16bits { get; set; } - [Data] public ushort Value { get; set; } - } - - public class AnimationData - { - [Data] public ChannelHeader Header { get; set; } - [Data] public List Keyframes { get; set; } - } - - public class BoneChannel - { - [Data] public AnimationData TranslationX { get; set; } - [Data] public AnimationData TranslationY { get; set; } - [Data] public AnimationData TranslationZ { get; set; } - [Data] public AnimationData RotationX { get; set; } - [Data] public AnimationData RotationY { get; set; } - [Data] public AnimationData RotationZ { get; set; } - [Data] public AnimationData ScaleX { get; set; } - [Data] public AnimationData ScaleY { get; set; } - [Data] public AnimationData ScaleZ { get; set; } - } - - public class AnimationInfo - { - [Data] public List ChannelFlags { get; set; } - [Data] public AnimationEntry AnimEntry { get; set; } - [Data] public AnimationHeader AnimHeader { get; set; } - [Data] public List BoneChannels { get; set; } - } - - - public Header header = new Header(); - public List animList = new List(); - - public static Pam Read(Stream stream) - { - Pam pam = new Pam(); - - pam.header = BinaryMapping.ReadObject
(stream); - pam.animList = new List(); - - for(int i = 0; i < pam.header.AnimationCount; i++) - { - pam.animList.Add(new AnimationInfo()); - pam.animList[i].AnimEntry = BinaryMapping.ReadObject(stream); - } - - // Get all anims in PAM pack. - for(int j = 0; j < pam.animList.Count; j++) - { - stream.Seek(pam.animList[j].AnimEntry.AnimationOffset, SeekOrigin.Begin); - pam.animList[j].AnimHeader = BinaryMapping.ReadObject(stream); - - byte BoneNum = pam.animList[j].AnimHeader.BoneCount; - ushort frameNum = pam.animList[j].AnimHeader.FrameCount; - - pam.animList[j].ChannelFlags = new List(); - - // Channel Flags - for (int k = 0; k < BoneNum; k++) - { - pam.animList[j].ChannelFlags.Add(stream.ReadUInt16()); - } - - pam.animList[j].BoneChannels = new List(); - - // Channel Header & Data - for (int l = 0; l < BoneNum; l++) - { - BoneChannel boneChannel = new BoneChannel(); - AnimationFlag flg = GetAnimFlags(pam.animList[j].ChannelFlags[l]); - ushort frameCnt = pam.animList[j].AnimHeader.FrameCount; - - /** TRANSLATION **/ - - if (flg.TranslationX) - { - ushort keyframeCnt = 0; - boneChannel.TranslationX = new AnimationData(); - boneChannel.TranslationX.Header = new ChannelHeader(); - boneChannel.TranslationX.Header.MaxValue = stream.ReadFloat(); - boneChannel.TranslationX.Header.MinValue = stream.ReadFloat(); - if (frameCnt > 255) - { - keyframeCnt = boneChannel.TranslationX.Header.KeyframeCount_16bits = stream.ReadUInt16(); - } - else - { - keyframeCnt = boneChannel.TranslationX.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); - } - - if(keyframeCnt != 1) - { - boneChannel.TranslationX.Keyframes = new List(); - for (ushort z = 0; z < keyframeCnt; z++) - { - KeyframeEntry ent = new KeyframeEntry(); - if (keyframeCnt == frameCnt) - { - ent.FrameID_16bits = z; - ent.Value = stream.ReadUInt16(); - boneChannel.TranslationX.Keyframes.Add(ent); - } - else - { - if (frameCnt > 255) - { - ent.FrameID_16bits = stream.ReadUInt16(); - } - else - { - ent.FrameID_8bits = (byte)stream.ReadByte(); - } - ent.Value = stream.ReadUInt16(); - boneChannel.TranslationX.Keyframes.Add(ent); - } - } - } - } - - if (flg.TranslationY) - { - ushort keyframeCnt = 0; - boneChannel.TranslationY = new AnimationData(); - boneChannel.TranslationY.Header = new ChannelHeader(); - boneChannel.TranslationY.Header.MaxValue = stream.ReadFloat(); - boneChannel.TranslationY.Header.MinValue = stream.ReadFloat(); - if (frameCnt > 255) - { - keyframeCnt = boneChannel.TranslationY.Header.KeyframeCount_16bits = stream.ReadUInt16(); - } - else - { - keyframeCnt = boneChannel.TranslationY.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); - } - - if (keyframeCnt != 1) - { - boneChannel.TranslationY.Keyframes = new List(); - for (ushort z = 0; z < keyframeCnt; z++) - { - KeyframeEntry ent = new KeyframeEntry(); - - if (keyframeCnt == frameCnt) - { - ent.FrameID_16bits = z; - ent.Value = stream.ReadUInt16(); - boneChannel.TranslationY.Keyframes.Add(ent); - } - else - { - if (frameCnt > 255) - { - ent.FrameID_16bits = stream.ReadUInt16(); - } - else - { - ent.FrameID_8bits = (byte)stream.ReadByte(); - } - ent.Value = stream.ReadUInt16(); - boneChannel.TranslationY.Keyframes.Add(ent); - } - } - } - } - - if (flg.TranslationZ) - { - ushort keyframeCnt = 0; - boneChannel.TranslationZ = new AnimationData(); - boneChannel.TranslationZ.Header = new ChannelHeader(); - boneChannel.TranslationZ.Header.MaxValue = stream.ReadFloat(); - boneChannel.TranslationZ.Header.MinValue = stream.ReadFloat(); - if (frameCnt > 255) - { - keyframeCnt = boneChannel.TranslationZ.Header.KeyframeCount_16bits = stream.ReadUInt16(); - } - else - { - keyframeCnt = boneChannel.TranslationZ.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); - } - - if (keyframeCnt != 1) - { - boneChannel.TranslationZ.Keyframes = new List(); - for (ushort z = 0; z < keyframeCnt; z++) - { - KeyframeEntry ent = new KeyframeEntry(); - if (keyframeCnt == frameCnt) - { - ent.FrameID_16bits = z; - ent.Value = stream.ReadUInt16(); - boneChannel.TranslationZ.Keyframes.Add(ent); - } - else - { - if (frameCnt > 255) - { - ent.FrameID_16bits = stream.ReadUInt16(); - } - else - { - ent.FrameID_8bits = (byte)stream.ReadByte(); - } - ent.Value = stream.ReadUInt16(); - boneChannel.TranslationZ.Keyframes.Add(ent); - } - } - } - } - - /** ROTATION **/ - - if (flg.RotationX) - { - ushort keyframeCnt = 0; - boneChannel.RotationX = new AnimationData(); - boneChannel.RotationX.Header = new ChannelHeader(); - boneChannel.RotationX.Header.MaxValue = stream.ReadFloat(); - boneChannel.RotationX.Header.MinValue = stream.ReadFloat(); - if (frameCnt > 255) - { - keyframeCnt = boneChannel.RotationX.Header.KeyframeCount_16bits = stream.ReadUInt16(); - } - else - { - keyframeCnt = boneChannel.RotationX.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); - } - - if (keyframeCnt != 1) - { - boneChannel.RotationX.Keyframes = new List(); - for (ushort z = 0; z < keyframeCnt; z++) - { - KeyframeEntry ent = new KeyframeEntry(); - if (keyframeCnt == frameCnt) - { - ent.FrameID_16bits = z; - ent.Value = stream.ReadUInt16(); - boneChannel.RotationX.Keyframes.Add(ent); - } - else - { - if (frameCnt > 255) - { - ent.FrameID_16bits = stream.ReadUInt16(); - } - else - { - ent.FrameID_8bits = (byte)stream.ReadByte(); - } - ent.Value = stream.ReadUInt16(); - boneChannel.RotationX.Keyframes.Add(ent); - } - } - } - } - - if (flg.RotationY) - { - ushort keyframeCnt = 0; - boneChannel.RotationY = new AnimationData(); - boneChannel.RotationY.Header = new ChannelHeader(); - boneChannel.RotationY.Header.MaxValue = stream.ReadFloat(); - boneChannel.RotationY.Header.MinValue = stream.ReadFloat(); - if (frameCnt > 255) - { - keyframeCnt = boneChannel.RotationY.Header.KeyframeCount_16bits = stream.ReadUInt16(); - } - else - { - keyframeCnt = boneChannel.RotationY.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); - } - - if (keyframeCnt != 1) - { - boneChannel.RotationY.Keyframes = new List(); - for (ushort z = 0; z < keyframeCnt; z++) - { - KeyframeEntry ent = new KeyframeEntry(); - if (keyframeCnt == frameCnt) - { - ent.FrameID_16bits = z; - ent.Value = stream.ReadUInt16(); - boneChannel.RotationY.Keyframes.Add(ent); - } - else - { - if (frameCnt > 255) - { - ent.FrameID_16bits = stream.ReadUInt16(); - } - else - { - ent.FrameID_8bits = (byte)stream.ReadByte(); - } - ent.Value = stream.ReadUInt16(); - boneChannel.RotationY.Keyframes.Add(ent); - } - } - } - } - - if (flg.RotationZ) - { - ushort keyframeCnt = 0; - boneChannel.RotationZ = new AnimationData(); - boneChannel.RotationZ.Header = new ChannelHeader(); - boneChannel.RotationZ.Header.MaxValue = stream.ReadFloat(); - boneChannel.RotationZ.Header.MinValue = stream.ReadFloat(); - if (frameCnt > 255) - { - keyframeCnt = boneChannel.RotationZ.Header.KeyframeCount_16bits = stream.ReadUInt16(); - } - else - { - keyframeCnt = boneChannel.RotationZ.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); - } - - if (keyframeCnt != 1) - { - boneChannel.RotationZ.Keyframes = new List(); - for (ushort z = 0; z < keyframeCnt; z++) - { - KeyframeEntry ent = new KeyframeEntry(); - if (keyframeCnt == frameCnt) - { - ent.FrameID_16bits = z; - ent.Value = stream.ReadUInt16(); - boneChannel.RotationZ.Keyframes.Add(ent); - } - else - { - if (frameCnt > 255) - { - ent.FrameID_16bits = stream.ReadUInt16(); - } - else - { - ent.FrameID_8bits = (byte)stream.ReadByte(); - } - ent.Value = stream.ReadUInt16(); - boneChannel.RotationZ.Keyframes.Add(ent); - } - } - } - } - - /** SCALE **/ - - if (flg.ScaleX) - { - ushort keyframeCnt = 0; - boneChannel.ScaleX = new AnimationData(); - boneChannel.ScaleX.Header = new ChannelHeader(); - boneChannel.ScaleX.Header.MaxValue = stream.ReadFloat(); - boneChannel.ScaleX.Header.MinValue = stream.ReadFloat(); - if (frameCnt > 255) - { - keyframeCnt = boneChannel.ScaleX.Header.KeyframeCount_16bits = stream.ReadUInt16(); - } - else - { - keyframeCnt = boneChannel.ScaleX.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); - } - - if (keyframeCnt != 1) - { - boneChannel.ScaleX.Keyframes = new List(); - for (ushort z = 0; z < keyframeCnt; z++) - { - KeyframeEntry ent = new KeyframeEntry(); - if (keyframeCnt == frameCnt) - { - ent.FrameID_16bits = z; - ent.Value = stream.ReadUInt16(); - boneChannel.ScaleX.Keyframes.Add(ent); - } - else - { - if (frameCnt > 255) - { - ent.FrameID_16bits = stream.ReadUInt16(); - } - else - { - ent.FrameID_8bits = (byte)stream.ReadByte(); - } - ent.Value = stream.ReadUInt16(); - boneChannel.ScaleX.Keyframes.Add(ent); - } - } - } - } - - if (flg.ScaleY) - { - ushort keyframeCnt = 0; - boneChannel.ScaleY = new AnimationData(); - boneChannel.ScaleY.Header = new ChannelHeader(); - boneChannel.ScaleY.Header.MaxValue = stream.ReadFloat(); - boneChannel.ScaleY.Header.MinValue = stream.ReadFloat(); - if (frameCnt > 255) - { - keyframeCnt = boneChannel.ScaleY.Header.KeyframeCount_16bits = stream.ReadUInt16(); - } - else - { - keyframeCnt = boneChannel.ScaleY.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); - } - - if (keyframeCnt != 1) - { - boneChannel.ScaleY.Keyframes = new List(); - for (ushort z = 0; z < keyframeCnt; z++) - { - KeyframeEntry ent = new KeyframeEntry(); - if (keyframeCnt == frameCnt) - { - ent.FrameID_16bits = z; - ent.Value = stream.ReadUInt16(); - boneChannel.ScaleY.Keyframes.Add(ent); - } - else - { - if (frameCnt > 255) - { - ent.FrameID_16bits = stream.ReadUInt16(); - } - else - { - ent.FrameID_8bits = (byte)stream.ReadByte(); - } - ent.Value = stream.ReadUInt16(); - boneChannel.ScaleY.Keyframes.Add(ent); - } - } - } - } - - if (flg.ScaleZ) - { - ushort keyframeCnt = 0; - boneChannel.ScaleZ = new AnimationData(); - boneChannel.ScaleZ.Header = new ChannelHeader(); - boneChannel.ScaleZ.Header.MaxValue = stream.ReadFloat(); - boneChannel.ScaleZ.Header.MinValue = stream.ReadFloat(); - if (frameCnt > 255) - { - keyframeCnt = boneChannel.ScaleZ.Header.KeyframeCount_16bits = stream.ReadUInt16(); - } - else - { - keyframeCnt = boneChannel.ScaleZ.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); - } - - if (keyframeCnt != 1) - { - boneChannel.ScaleZ.Keyframes = new List(); - for (ushort z = 0; z < keyframeCnt; z++) - { - KeyframeEntry ent = new KeyframeEntry(); - if (keyframeCnt == frameCnt) - { - ent.FrameID_16bits = z; - ent.Value = stream.ReadUInt16(); - boneChannel.ScaleZ.Keyframes.Add(ent); - } - else - { - if (frameCnt > 255) - { - ent.FrameID_16bits = stream.ReadUInt16(); - } - else - { - ent.FrameID_8bits = (byte)stream.ReadByte(); - } - ent.Value = stream.ReadUInt16(); - boneChannel.ScaleZ.Keyframes.Add(ent); - } - } - } - } - - pam.animList[j].BoneChannels.Add(boneChannel); - } - } - - return pam; - } - } -} +using OpenKh.Common; +using OpenKh.Imaging; + +using System; +using System.Collections.Generic; +using System.IO; +using System.Numerics; +using Xe.BinaryMapper; +using System.Linq; +using System.Text; +using OpenKh.Common.Utils; + +namespace OpenKh.Bbs +{ + public class Pam + { + private const uint MagicCode = 0x4D4150; + + public class Header + { + [Data] public uint MagicCode { get; set; } + [Data] public uint AnimationCount { get; set; } + [Data(Count = 6)] public byte[] Padding { get; set; } + [Data] public ushort Version { get; set; } + } + + public class AnimationEntry + { + [Data] public uint AnimationOffset { get; set; } + [Data(Count = 12)] public string AnimationName { get; set; } + } + + public class AnimationHeader + { + [Data] public ushort Flag { get; set; } + [Data] public byte Framerate { get; set; } + [Data] public byte InterpFrameCount { get; set; } + [Data] public ushort LoopFrame { get; set; } + [Data] public byte BoneCount { get; set; } + [Data] public byte Padding { get; set; } + [Data] public ushort FrameCount { get; set; } + [Data] public ushort ReturnFrame { get; set; } + } + + public struct AnimationFlag + { + [Data] public bool TranslationX { get; set; } + [Data] public bool TranslationY { get; set; } + [Data] public bool TranslationZ { get; set; } + [Data] public bool RotationX { get; set; } + [Data] public bool RotationY { get; set; } + [Data] public bool RotationZ { get; set; } + [Data] public bool ScaleX { get; set; } + [Data] public bool ScaleY { get; set; } + [Data] public bool ScaleZ { get; set; } + } + + public static AnimationFlag GetAnimFlags(ushort Flag) + { + AnimationFlag flag = new AnimationFlag(); + + flag.TranslationX = BitsUtil.Int.GetBit(Flag, 0); + flag.TranslationY = BitsUtil.Int.GetBit(Flag, 1); + flag.TranslationZ = BitsUtil.Int.GetBit(Flag, 2); + flag.RotationX = BitsUtil.Int.GetBit(Flag, 3); + flag.RotationY = BitsUtil.Int.GetBit(Flag, 4); + flag.RotationZ = BitsUtil.Int.GetBit(Flag, 5); + flag.ScaleX = BitsUtil.Int.GetBit(Flag, 6); + flag.ScaleY = BitsUtil.Int.GetBit(Flag, 7); + flag.ScaleZ = BitsUtil.Int.GetBit(Flag, 8); + + return flag; + } + + public class ChannelHeader + { + [Data] public float MaxValue { get; set; } + [Data] public float MinValue { get; set; } + [Data] public byte KeyframeCount_8bits { get; set; } + [Data] public ushort KeyframeCount_16bits { get; set; } + } + + public class KeyframeEntry + { + [Data] public byte FrameID_8bits { get; set; } + [Data] public ushort FrameID_16bits { get; set; } + [Data] public ushort Value { get; set; } + } + + public class AnimationData + { + [Data] public ChannelHeader Header { get; set; } + [Data] public List Keyframes { get; set; } + } + + public class BoneChannel + { + [Data] public AnimationData TranslationX { get; set; } + [Data] public AnimationData TranslationY { get; set; } + [Data] public AnimationData TranslationZ { get; set; } + [Data] public AnimationData RotationX { get; set; } + [Data] public AnimationData RotationY { get; set; } + [Data] public AnimationData RotationZ { get; set; } + [Data] public AnimationData ScaleX { get; set; } + [Data] public AnimationData ScaleY { get; set; } + [Data] public AnimationData ScaleZ { get; set; } + } + + public class AnimationInfo + { + [Data] public List ChannelFlags { get; set; } + [Data] public AnimationEntry AnimEntry { get; set; } + [Data] public AnimationHeader AnimHeader { get; set; } + [Data] public List BoneChannels { get; set; } + } + + + public Header header = new Header(); + public List animList = new List(); + + public static Pam Read(Stream stream) + { + Pam pam = new Pam(); + + pam.header = BinaryMapping.ReadObject
(stream); + pam.animList = new List(); + + for (int i = 0; i < pam.header.AnimationCount; i++) + { + pam.animList.Add(new AnimationInfo()); + pam.animList[i].AnimEntry = BinaryMapping.ReadObject(stream); + } + + // Get all anims in PAM pack. + for (int j = 0; j < pam.animList.Count; j++) + { + stream.Seek(pam.animList[j].AnimEntry.AnimationOffset, SeekOrigin.Begin); + pam.animList[j].AnimHeader = BinaryMapping.ReadObject(stream); + + byte BoneNum = pam.animList[j].AnimHeader.BoneCount; + ushort frameNum = pam.animList[j].AnimHeader.FrameCount; + + pam.animList[j].ChannelFlags = new List(); + + // Channel Flags + for (int k = 0; k < BoneNum; k++) + { + pam.animList[j].ChannelFlags.Add(stream.ReadUInt16()); + } + + pam.animList[j].BoneChannels = new List(); + + // Channel Header & Data + for (int l = 0; l < BoneNum; l++) + { + BoneChannel boneChannel = new BoneChannel(); + AnimationFlag flg = GetAnimFlags(pam.animList[j].ChannelFlags[l]); + ushort frameCnt = pam.animList[j].AnimHeader.FrameCount; + + /** TRANSLATION **/ + + if (flg.TranslationX) + { + ushort keyframeCnt = 0; + boneChannel.TranslationX = new AnimationData(); + boneChannel.TranslationX.Header = new ChannelHeader(); + boneChannel.TranslationX.Header.MaxValue = stream.ReadFloat(); + boneChannel.TranslationX.Header.MinValue = stream.ReadFloat(); + if (frameCnt > 255) + { + keyframeCnt = boneChannel.TranslationX.Header.KeyframeCount_16bits = stream.ReadUInt16(); + } + else + { + keyframeCnt = boneChannel.TranslationX.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); + } + + if (keyframeCnt != 1) + { + boneChannel.TranslationX.Keyframes = new List(); + for (ushort z = 0; z < keyframeCnt; z++) + { + KeyframeEntry ent = new KeyframeEntry(); + if (keyframeCnt == frameCnt) + { + ent.FrameID_16bits = z; + ent.Value = stream.ReadUInt16(); + boneChannel.TranslationX.Keyframes.Add(ent); + } + else + { + if (frameCnt > 255) + { + ent.FrameID_16bits = stream.ReadUInt16(); + } + else + { + ent.FrameID_8bits = (byte)stream.ReadByte(); + } + ent.Value = stream.ReadUInt16(); + boneChannel.TranslationX.Keyframes.Add(ent); + } + } + } + } + + if (flg.TranslationY) + { + ushort keyframeCnt = 0; + boneChannel.TranslationY = new AnimationData(); + boneChannel.TranslationY.Header = new ChannelHeader(); + boneChannel.TranslationY.Header.MaxValue = stream.ReadFloat(); + boneChannel.TranslationY.Header.MinValue = stream.ReadFloat(); + if (frameCnt > 255) + { + keyframeCnt = boneChannel.TranslationY.Header.KeyframeCount_16bits = stream.ReadUInt16(); + } + else + { + keyframeCnt = boneChannel.TranslationY.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); + } + + if (keyframeCnt != 1) + { + boneChannel.TranslationY.Keyframes = new List(); + for (ushort z = 0; z < keyframeCnt; z++) + { + KeyframeEntry ent = new KeyframeEntry(); + + if (keyframeCnt == frameCnt) + { + ent.FrameID_16bits = z; + ent.Value = stream.ReadUInt16(); + boneChannel.TranslationY.Keyframes.Add(ent); + } + else + { + if (frameCnt > 255) + { + ent.FrameID_16bits = stream.ReadUInt16(); + } + else + { + ent.FrameID_8bits = (byte)stream.ReadByte(); + } + ent.Value = stream.ReadUInt16(); + boneChannel.TranslationY.Keyframes.Add(ent); + } + } + } + } + + if (flg.TranslationZ) + { + ushort keyframeCnt = 0; + boneChannel.TranslationZ = new AnimationData(); + boneChannel.TranslationZ.Header = new ChannelHeader(); + boneChannel.TranslationZ.Header.MaxValue = stream.ReadFloat(); + boneChannel.TranslationZ.Header.MinValue = stream.ReadFloat(); + if (frameCnt > 255) + { + keyframeCnt = boneChannel.TranslationZ.Header.KeyframeCount_16bits = stream.ReadUInt16(); + } + else + { + keyframeCnt = boneChannel.TranslationZ.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); + } + + if (keyframeCnt != 1) + { + boneChannel.TranslationZ.Keyframes = new List(); + for (ushort z = 0; z < keyframeCnt; z++) + { + KeyframeEntry ent = new KeyframeEntry(); + if (keyframeCnt == frameCnt) + { + ent.FrameID_16bits = z; + ent.Value = stream.ReadUInt16(); + boneChannel.TranslationZ.Keyframes.Add(ent); + } + else + { + if (frameCnt > 255) + { + ent.FrameID_16bits = stream.ReadUInt16(); + } + else + { + ent.FrameID_8bits = (byte)stream.ReadByte(); + } + ent.Value = stream.ReadUInt16(); + boneChannel.TranslationZ.Keyframes.Add(ent); + } + } + } + } + + /** ROTATION **/ + + if (flg.RotationX) + { + ushort keyframeCnt = 0; + boneChannel.RotationX = new AnimationData(); + boneChannel.RotationX.Header = new ChannelHeader(); + boneChannel.RotationX.Header.MaxValue = stream.ReadFloat(); + boneChannel.RotationX.Header.MinValue = stream.ReadFloat(); + if (frameCnt > 255) + { + keyframeCnt = boneChannel.RotationX.Header.KeyframeCount_16bits = stream.ReadUInt16(); + } + else + { + keyframeCnt = boneChannel.RotationX.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); + } + + if (keyframeCnt != 1) + { + boneChannel.RotationX.Keyframes = new List(); + for (ushort z = 0; z < keyframeCnt; z++) + { + KeyframeEntry ent = new KeyframeEntry(); + if (keyframeCnt == frameCnt) + { + ent.FrameID_16bits = z; + ent.Value = stream.ReadUInt16(); + boneChannel.RotationX.Keyframes.Add(ent); + } + else + { + if (frameCnt > 255) + { + ent.FrameID_16bits = stream.ReadUInt16(); + } + else + { + ent.FrameID_8bits = (byte)stream.ReadByte(); + } + ent.Value = stream.ReadUInt16(); + boneChannel.RotationX.Keyframes.Add(ent); + } + } + } + } + + if (flg.RotationY) + { + ushort keyframeCnt = 0; + boneChannel.RotationY = new AnimationData(); + boneChannel.RotationY.Header = new ChannelHeader(); + boneChannel.RotationY.Header.MaxValue = stream.ReadFloat(); + boneChannel.RotationY.Header.MinValue = stream.ReadFloat(); + if (frameCnt > 255) + { + keyframeCnt = boneChannel.RotationY.Header.KeyframeCount_16bits = stream.ReadUInt16(); + } + else + { + keyframeCnt = boneChannel.RotationY.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); + } + + if (keyframeCnt != 1) + { + boneChannel.RotationY.Keyframes = new List(); + for (ushort z = 0; z < keyframeCnt; z++) + { + KeyframeEntry ent = new KeyframeEntry(); + if (keyframeCnt == frameCnt) + { + ent.FrameID_16bits = z; + ent.Value = stream.ReadUInt16(); + boneChannel.RotationY.Keyframes.Add(ent); + } + else + { + if (frameCnt > 255) + { + ent.FrameID_16bits = stream.ReadUInt16(); + } + else + { + ent.FrameID_8bits = (byte)stream.ReadByte(); + } + ent.Value = stream.ReadUInt16(); + boneChannel.RotationY.Keyframes.Add(ent); + } + } + } + } + + if (flg.RotationZ) + { + ushort keyframeCnt = 0; + boneChannel.RotationZ = new AnimationData(); + boneChannel.RotationZ.Header = new ChannelHeader(); + boneChannel.RotationZ.Header.MaxValue = stream.ReadFloat(); + boneChannel.RotationZ.Header.MinValue = stream.ReadFloat(); + if (frameCnt > 255) + { + keyframeCnt = boneChannel.RotationZ.Header.KeyframeCount_16bits = stream.ReadUInt16(); + } + else + { + keyframeCnt = boneChannel.RotationZ.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); + } + + if (keyframeCnt != 1) + { + boneChannel.RotationZ.Keyframes = new List(); + for (ushort z = 0; z < keyframeCnt; z++) + { + KeyframeEntry ent = new KeyframeEntry(); + if (keyframeCnt == frameCnt) + { + ent.FrameID_16bits = z; + ent.Value = stream.ReadUInt16(); + boneChannel.RotationZ.Keyframes.Add(ent); + } + else + { + if (frameCnt > 255) + { + ent.FrameID_16bits = stream.ReadUInt16(); + } + else + { + ent.FrameID_8bits = (byte)stream.ReadByte(); + } + ent.Value = stream.ReadUInt16(); + boneChannel.RotationZ.Keyframes.Add(ent); + } + } + } + } + + /** SCALE **/ + + if (flg.ScaleX) + { + ushort keyframeCnt = 0; + boneChannel.ScaleX = new AnimationData(); + boneChannel.ScaleX.Header = new ChannelHeader(); + boneChannel.ScaleX.Header.MaxValue = stream.ReadFloat(); + boneChannel.ScaleX.Header.MinValue = stream.ReadFloat(); + if (frameCnt > 255) + { + keyframeCnt = boneChannel.ScaleX.Header.KeyframeCount_16bits = stream.ReadUInt16(); + } + else + { + keyframeCnt = boneChannel.ScaleX.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); + } + + if (keyframeCnt != 1) + { + boneChannel.ScaleX.Keyframes = new List(); + for (ushort z = 0; z < keyframeCnt; z++) + { + KeyframeEntry ent = new KeyframeEntry(); + if (keyframeCnt == frameCnt) + { + ent.FrameID_16bits = z; + ent.Value = stream.ReadUInt16(); + boneChannel.ScaleX.Keyframes.Add(ent); + } + else + { + if (frameCnt > 255) + { + ent.FrameID_16bits = stream.ReadUInt16(); + } + else + { + ent.FrameID_8bits = (byte)stream.ReadByte(); + } + ent.Value = stream.ReadUInt16(); + boneChannel.ScaleX.Keyframes.Add(ent); + } + } + } + } + + if (flg.ScaleY) + { + ushort keyframeCnt = 0; + boneChannel.ScaleY = new AnimationData(); + boneChannel.ScaleY.Header = new ChannelHeader(); + boneChannel.ScaleY.Header.MaxValue = stream.ReadFloat(); + boneChannel.ScaleY.Header.MinValue = stream.ReadFloat(); + if (frameCnt > 255) + { + keyframeCnt = boneChannel.ScaleY.Header.KeyframeCount_16bits = stream.ReadUInt16(); + } + else + { + keyframeCnt = boneChannel.ScaleY.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); + } + + if (keyframeCnt != 1) + { + boneChannel.ScaleY.Keyframes = new List(); + for (ushort z = 0; z < keyframeCnt; z++) + { + KeyframeEntry ent = new KeyframeEntry(); + if (keyframeCnt == frameCnt) + { + ent.FrameID_16bits = z; + ent.Value = stream.ReadUInt16(); + boneChannel.ScaleY.Keyframes.Add(ent); + } + else + { + if (frameCnt > 255) + { + ent.FrameID_16bits = stream.ReadUInt16(); + } + else + { + ent.FrameID_8bits = (byte)stream.ReadByte(); + } + ent.Value = stream.ReadUInt16(); + boneChannel.ScaleY.Keyframes.Add(ent); + } + } + } + } + + if (flg.ScaleZ) + { + ushort keyframeCnt = 0; + boneChannel.ScaleZ = new AnimationData(); + boneChannel.ScaleZ.Header = new ChannelHeader(); + boneChannel.ScaleZ.Header.MaxValue = stream.ReadFloat(); + boneChannel.ScaleZ.Header.MinValue = stream.ReadFloat(); + if (frameCnt > 255) + { + keyframeCnt = boneChannel.ScaleZ.Header.KeyframeCount_16bits = stream.ReadUInt16(); + } + else + { + keyframeCnt = boneChannel.ScaleZ.Header.KeyframeCount_8bits = (byte)stream.ReadByte(); + } + + if (keyframeCnt != 1) + { + boneChannel.ScaleZ.Keyframes = new List(); + for (ushort z = 0; z < keyframeCnt; z++) + { + KeyframeEntry ent = new KeyframeEntry(); + if (keyframeCnt == frameCnt) + { + ent.FrameID_16bits = z; + ent.Value = stream.ReadUInt16(); + boneChannel.ScaleZ.Keyframes.Add(ent); + } + else + { + if (frameCnt > 255) + { + ent.FrameID_16bits = stream.ReadUInt16(); + } + else + { + ent.FrameID_8bits = (byte)stream.ReadByte(); + } + ent.Value = stream.ReadUInt16(); + boneChannel.ScaleZ.Keyframes.Add(ent); + } + } + } + } + + pam.animList[j].BoneChannels.Add(boneChannel); + } + } + + return pam; + } + } +} diff --git a/OpenKh.Bbs/Pmo.cs b/OpenKh.Bbs/Pmo.cs index c0989531d..b05487d73 100644 --- a/OpenKh.Bbs/Pmo.cs +++ b/OpenKh.Bbs/Pmo.cs @@ -1,784 +1,788 @@ -using OpenKh.Common; -using OpenKh.Imaging; - -using System; -using System.Collections.Generic; -using System.IO; -using System.Numerics; -using Xe.BinaryMapper; -using System.Linq; - -namespace OpenKh.Bbs -{ - public class Pmo - { - private static readonly IBinaryMapping Mapping = - MappingConfiguration.DefaultConfiguration() - .ForTypeMatrix4x4() - .Build(); - - private const UInt32 MagicCode = 0x4F4D50; - - public class Header - { - [Data] public UInt32 MagicCode { get; set; } - [Data] public byte Number { get; set; } - [Data] public byte Group { get; set; } - [Data] public byte Version { get; set; } - [Data] public byte Padding { get; set; } - [Data] public ushort TextureCount { get; set; } - [Data] public ushort Unk0A { get; set; } - [Data] public UInt32 SkeletonOffset { get; set; } - [Data] public UInt32 MeshOffset0 { get; set; } - [Data] public ushort TriangleCount { get; set; } - [Data] public ushort VertexCount { get; set; } - [Data] public float ModelScale { get; set; } - [Data] public UInt32 MeshOffset1 { get; set; } - [Data(Count = 32)] public float[] BoundingBox { get; set; } - } - - public class TextureInfo - { - [Data] public UInt32 TextureOffset { get; set; } - [Data(Count = 12)] public string TextureName { get; set; } - [Data(Count = 4)] public UInt32[] Unknown { get; set; } - } - - public class MeshSection - { - [Data] public ushort VertexCount { get; set; } - [Data] public byte TextureID { get; set; } - [Data] public byte VertexSize { get; set; } // In bytes. - [Data] public UInt32 VertexFlags { get; set; } - [Data] public byte Group { get; set; } - [Data] public byte TriangleStripCount { get; set; } - [Data] public ushort Attribute { get; set; } - } - - public enum VertexAttribute - { - ATTRIBUTE_BLEND_NONE = 0, - ATTRIBUTE_NOMATERIAL = 1, - ATTRIBUTE_GLARE = 2, - ATTRIBUTE_BACK = 4, - ATTRIBUTE_DIVIDE = 8, - ATTRIBUTE_TEXALPHA = 16, - ATTRIBUTE_FLAG_SHIFT = 24, - ATTRIBUTE_PRIM_SHIFT = 28, - ATTRIBUTE_BLEND_SEMITRANS = 32, - ATTRIBUTE_BLEND_ADD = 64, - ATTRIBUTE_BLEND_SUB = 96, - ATTRIBUTE_BLEND_MASK = 224, - ATTRIBUTE_8 = 256, - ATTRIBUTE_9 = 512, - ATTRIBUTE_DROPSHADOW = 1024, - ATTRIBUTE_ENVMAP = 2048, - ATTRIBUTE_12 = 4096, - ATTRIBUTE_13 = 8192, - ATTRIBUTE_14 = 16384, - ATTRIBUTE_15 = 32768, - ATTRIBUTE_COLOR = 16777216, - ATTRIBUTE_NOWEIGHT = 33554432, - } - - // Fields starting with _ have a temporary name. - public class SkeletonHeader - { - [Data] public uint MagicValue { get; set; } - [Data] public uint Padding1 { get; set; } - [Data] public ushort BoneCount { get; set; } - [Data] public ushort Padding2 { get; set; } - [Data] public ushort SkinnedBoneCount { get; set; } - [Data] public ushort nStdBone { get; set; } - } - - public class BoneData - { - [Data] public ushort BoneIndex { get; set; } - [Data] public ushort Padding1 { get; set; } - [Data] public ushort ParentBoneIndex { get; set; } - [Data] public ushort Padding2 { get; set; } - [Data] public ushort SkinnedBoneIndex { get; set; } - [Data] public ushort Padding3 { get; set; } - [Data] public uint Padding4 { get; set; } - [Data(Count = 16)] public string JointName { get; set; } - [Data] public Matrix4x4 Transform { get; set; } - [Data] public Matrix4x4 InverseTransform { get; set; } - } - - public class MeshSectionOptional1 - { - [Data(Count = 8)] public byte[] SectionBoneIndices { get; set; } // Only present if header.SkeletonOffset != 0 - } - public class MeshSectionOptional2 - { - [Data] public UInt32 DiffuseColor { get; set; } // Only present if vertexFlags.DiffuseColor & 1 - } - - public enum CoordinateFormat - { - NO_VERTEX, - NORMALIZED_8_BITS, - NORMALIZED_16_BITS, - FLOAT_32_BITS - } - - public enum ColorFormat - { - NO_COLOR, - BGR_5650_16BITS = 4, - ABGR_5551_16BITS, - ABGR_4444_16BITS, - ABGR_8888_32BITS, - } - - public enum PrimitiveType - { - PRIMITIVE_POINT, - PRIMITIVE_LINE, - PRIMITIVE_LINE_STRIP, - PRIMITIVE_TRIANGLE, - PRIMITIVE_TRIANGLE_STRIP, - PRIMITIVE_TRIANGLE_FAN, - PRIMITIVE_QUAD - } - - public class VertexFlags - { - public CoordinateFormat TextureCoordinateFormat; - public ColorFormat ColorFormat; - public CoordinateFormat NormalFormat; // Unused - public CoordinateFormat PositionFormat; - public CoordinateFormat WeightFormat; - public byte IndicesFormat; // Unused - public bool Unused1; - public byte SkinningWeightsCount; - public bool Unused2; - public byte MorphWeightsCount; // Unused - public byte Unused3; - public bool SkipTransformPipeline; // Unused - public bool UniformDiffuseFlag; - public byte Unknown1; - public PrimitiveType Primitive; - } - - public static VertexFlags GetFlags(MeshSection meshSec) - { - VertexFlags flags = new VertexFlags(); - flags.TextureCoordinateFormat = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 0, 2); - flags.ColorFormat = (ColorFormat)GetBitFieldRange(meshSec.VertexFlags, 2, 3); - flags.NormalFormat = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 5, 2); - flags.PositionFormat = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 7, 2); - flags.WeightFormat = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 9, 2); - flags.IndicesFormat = (byte)GetBitFieldRange(meshSec.VertexFlags, 11, 2); - flags.Unused1 = (byte)GetBitFieldRange(meshSec.VertexFlags, 13, 1) == 1; - flags.SkinningWeightsCount = (byte)GetBitFieldRange(meshSec.VertexFlags, 14, 3); - flags.Unused2 = (byte)GetBitFieldRange(meshSec.VertexFlags, 17, 1) == 1; - flags.MorphWeightsCount = (byte)GetBitFieldRange(meshSec.VertexFlags, 18, 3); - flags.Unused3 = (byte)GetBitFieldRange(meshSec.VertexFlags, 21, 2); - flags.SkipTransformPipeline = (byte)GetBitFieldRange(meshSec.VertexFlags, 23, 1) == 1; - flags.UniformDiffuseFlag = (byte)GetBitFieldRange(meshSec.VertexFlags, 24, 1) == 1; - flags.Unknown1 = (byte)GetBitFieldRange(meshSec.VertexFlags, 25, 3); - flags.Primitive = (PrimitiveType)GetBitFieldRange(meshSec.VertexFlags, 28, 4); - - return flags; - } - - public static UInt32 GetBitFieldRange(UInt32 value, int start = 0, int length = 1) - { - UInt32 bit = value << 32 - (start+length); - bit >>= 32 - length; - return bit; - } - - public class WeightData - { - [Data] public CoordinateFormat coordFormart { get; set; } - [Data] public List weights { get; set; } - } - - public class MeshChunks - { - [Data] public bool IsTextureOpaque { get; set; } - [Data] public int MeshNumber { get; set; } - [Data] public MeshSection SectionInfo { get; set; } - [Data] public MeshSectionOptional1 SectionInfo_opt1 { get; set; } - [Data] public MeshSectionOptional2 SectionInfo_opt2 { get; set; } - [Data] public UInt16[] TriangleStripValues { get; set; } - [Data] public int TextureID { get; set; } - [Data] public List jointWeights { get; set; } - [Data] public List textureCoordinates { get; set; } - [Data] public List colors { get; set; } - [Data] public List vertices { get; set; } - [Data] public List Indices { get; set; } - - public MeshChunks() - { - IsTextureOpaque = true; - MeshNumber = 0; - TriangleStripValues = new UInt16[0]; - TextureID = 0; - jointWeights = new List(); - textureCoordinates = new List(); - colors = new List(); - vertices = new List(); - Indices = new List(); - } - } - - // PMO Header. - public Header header { get; set; } - // Data block for textures. The order will reflect their texture index. - public TextureInfo[] textureInfo { get; set; } - // Texture data blobs. - public List texturesData = new List(); - // Header of the skeleton. - public SkeletonHeader skeletonHeader { get; set; } - // Joints present in the skeleton. - public BoneData[] boneList; - - public List Meshes = new List(); - - public uint PMO_StartPosition = 0; - - public static void ReadHeader(Stream stream, Pmo pmo) - { - pmo.header = Mapping.ReadObject
(stream); - } - - public static void ReadTextureSection(Stream stream, Pmo pmo) - { - pmo.textureInfo = new TextureInfo[pmo.header.TextureCount]; - for (ushort i = 0; i < pmo.header.TextureCount; i++) - pmo.textureInfo[i] = Mapping.ReadObject(stream); - } - - public static void ReadMeshData(Stream stream, Pmo pmo, int MeshNumber = 0) - { - // Go to mesh position. - if(MeshNumber == 0) stream.Seek(pmo.PMO_StartPosition + pmo.header.MeshOffset0, SeekOrigin.Begin); - else stream.Seek(pmo.PMO_StartPosition + pmo.header.MeshOffset1, SeekOrigin.Begin); - - UInt16 VertCnt = 0xFFFF; - - while (VertCnt > 0) - { - MeshChunks meshChunk = new MeshChunks(); - meshChunk.MeshNumber = MeshNumber; - - meshChunk.SectionInfo = Mapping.ReadObject(stream); - - // Exit if Vertex Count is zero. - if (meshChunk.SectionInfo.VertexCount <= 0) - break; - - meshChunk.TextureID = meshChunk.SectionInfo.TextureID; - VertexFlags flags = GetFlags(meshChunk.SectionInfo); - - bool isColorFlagRisen = flags.UniformDiffuseFlag; - - if (pmo.header.SkeletonOffset != 0) - meshChunk.SectionInfo_opt1 = Mapping.ReadObject(stream); - if (isColorFlagRisen) - meshChunk.SectionInfo_opt2 = Mapping.ReadObject(stream); - if (meshChunk.SectionInfo.TriangleStripCount > 0) - { - meshChunk.TriangleStripValues = new UInt16[meshChunk.SectionInfo.TriangleStripCount]; - for (int i = 0; i < meshChunk.SectionInfo.TriangleStripCount; i++) - { - meshChunk.TriangleStripValues[i] = stream.ReadUInt16(); - } - } - - // Get Formats. - CoordinateFormat TexCoordFormat = flags.TextureCoordinateFormat; - CoordinateFormat VertexPositionFormat = flags.PositionFormat; - CoordinateFormat WeightFormat = flags.WeightFormat; - ColorFormat ColorFormat = flags.ColorFormat; - UInt32 SkinningWeightsCount = flags.SkinningWeightsCount; - BinaryReader r = new BinaryReader(stream); - long positionAfterHeader = stream.Position; - - if (meshChunk.SectionInfo.TriangleStripCount > 0) - { - int vertInd = 0; - for (int p = 0; p < meshChunk.SectionInfo.TriangleStripCount; p++) - { - for (int s = 0; s < (meshChunk.TriangleStripValues[p] - 2); s++) - { - if (s % 2 == 0) - { - meshChunk.Indices.Add(vertInd + s + 0); - meshChunk.Indices.Add(vertInd + s + 1); - meshChunk.Indices.Add(vertInd + s + 2); - } - else - { - meshChunk.Indices.Add(vertInd + s + 0); - meshChunk.Indices.Add(vertInd + s + 2); - meshChunk.Indices.Add(vertInd + s + 1); - } - } - - vertInd += meshChunk.TriangleStripValues[p]; - } - } - else - { - if (flags.Primitive == PrimitiveType.PRIMITIVE_TRIANGLE_STRIP) - { - for (int s = 0; s < (meshChunk.SectionInfo.VertexCount - 2); s++) - { - if (s % 2 == 0) - { - meshChunk.Indices.Add(s + 0); - meshChunk.Indices.Add(s + 1); - meshChunk.Indices.Add(s + 2); - } - else - { - meshChunk.Indices.Add(s + 1); - meshChunk.Indices.Add(s + 0); - meshChunk.Indices.Add(s + 2); - } - } - } - } - - for (int v = 0; v < meshChunk.SectionInfo.VertexCount; v++) - { - long vertexStartPos = stream.Position; - int vertexIncreaseAmount = 0; - - // Vertex Weights. - if(pmo.header.SkeletonOffset != 0 && WeightFormat != CoordinateFormat.NO_VERTEX) - { - WeightData WeightList = new WeightData(); - WeightList.weights = new List(); - WeightList.coordFormart = WeightFormat; - - for (int i = 0; i < (SkinningWeightsCount + 1); i++) - { - switch (WeightFormat) - { - case CoordinateFormat.NORMALIZED_8_BITS: - WeightList.weights.Add(stream.ReadByte() / 128.0f); - break; - case CoordinateFormat.NORMALIZED_16_BITS: - WeightList.weights.Add(stream.ReadUInt16() / 32768.0f); - break; - case CoordinateFormat.FLOAT_32_BITS: - WeightList.weights.Add(stream.ReadFloat()); - break; - case CoordinateFormat.NO_VERTEX: - break; - } - } - - meshChunk.jointWeights.Add(WeightList); - } - - Vector2 currentTexCoord = new Vector2(0, 0); - - switch (TexCoordFormat) - { - case CoordinateFormat.NORMALIZED_8_BITS: - currentTexCoord.X = stream.ReadByte() / 128.0f; - currentTexCoord.Y = stream.ReadByte() / 128.0f; - meshChunk.textureCoordinates.Add(currentTexCoord); - break; - case CoordinateFormat.NORMALIZED_16_BITS: - vertexIncreaseAmount = ((0x2 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x1)) & 0x1); - stream.Seek(vertexIncreaseAmount, SeekOrigin.Current); - - currentTexCoord.X = stream.ReadUInt16() / 32768.0f; - currentTexCoord.Y = stream.ReadUInt16() / 32768.0f; - meshChunk.textureCoordinates.Add(currentTexCoord); - break; - case CoordinateFormat.FLOAT_32_BITS: - vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); - stream.Seek(vertexIncreaseAmount, SeekOrigin.Current); - - currentTexCoord.X = stream.ReadFloat(); - currentTexCoord.Y = stream.ReadFloat(); - meshChunk.textureCoordinates.Add(currentTexCoord); - break; - case CoordinateFormat.NO_VERTEX: - meshChunk.textureCoordinates.Add(currentTexCoord); - break; - } - - Vector4 col; - - if (isColorFlagRisen) - { - uint c = meshChunk.SectionInfo_opt2.DiffuseColor; - col.X = c % 0x100; - col.Y = (c >> 8) % 0x100; - col.Z = (c >> 16) % 0x100; - col.W = (c >> 24) % 0x100; - - meshChunk.colors.Add(col); - } - else - { - switch (ColorFormat) - { - case Pmo.ColorFormat.NO_COLOR: - meshChunk.colors.Add(new Vector4(0xFF, 0xFF, 0xFF, 0xFF)); - break; - case Pmo.ColorFormat.BGR_5650_16BITS: - stream.ReadUInt16(); - break; - case Pmo.ColorFormat.ABGR_5551_16BITS: - stream.ReadUInt16(); - break; - case Pmo.ColorFormat.ABGR_4444_16BITS: - stream.ReadUInt16(); - break; - case Pmo.ColorFormat.ABGR_8888_32BITS: - vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); - stream.Seek(vertexIncreaseAmount, SeekOrigin.Current); - - col.X = stream.ReadByte(); - col.Y = stream.ReadByte(); - col.Z = stream.ReadByte(); - col.W = stream.ReadByte(); - meshChunk.colors.Add(col); - break; - } - } - - Vector3 currentVertex; - - // Handle triangles and triangle strips. - switch (VertexPositionFormat) - { - case CoordinateFormat.NORMALIZED_8_BITS: - currentVertex.X = r.ReadSByte() / 128.0f; - currentVertex.Y = r.ReadSByte() / 128.0f; - currentVertex.Z = r.ReadSByte() / 128.0f; - meshChunk.vertices.Add(currentVertex); - break; - case CoordinateFormat.NORMALIZED_16_BITS: - vertexIncreaseAmount = ((0x2 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x1)) & 0x1); - stream.Seek(vertexIncreaseAmount, SeekOrigin.Current); - - currentVertex.X = (float)stream.ReadInt16() / 32768.0f; - currentVertex.Y = (float)stream.ReadInt16() / 32768.0f; - currentVertex.Z = (float)stream.ReadInt16() / 32768.0f; - meshChunk.vertices.Add(currentVertex); - break; - case CoordinateFormat.FLOAT_32_BITS: - vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); - stream.Seek(vertexIncreaseAmount, SeekOrigin.Current); - - currentVertex.X = stream.ReadFloat(); - currentVertex.Y = stream.ReadFloat(); - currentVertex.Z = stream.ReadFloat(); - meshChunk.vertices.Add(currentVertex); - break; - } - - stream.Seek(vertexStartPos + meshChunk.SectionInfo.VertexSize, SeekOrigin.Begin); - - if (flags.Primitive == PrimitiveType.PRIMITIVE_TRIANGLE) - { - meshChunk.Indices.Add(v); - } - } - - VertCnt = meshChunk.SectionInfo.VertexCount; - pmo.Meshes.Add(meshChunk); - - // Find position of next data chunk. - stream.Seek(positionAfterHeader + (meshChunk.SectionInfo.VertexCount * meshChunk.SectionInfo.VertexSize), SeekOrigin.Begin); - stream.Seek(stream.Position % 4, SeekOrigin.Current); - } - } - - public static Pmo Read(Stream stream) - { - Pmo pmo = new Pmo(); - pmo.PMO_StartPosition = (uint)stream.Position; - - ReadHeader(stream, pmo); - ReadTextureSection(stream, pmo); - - // Read all data - if (pmo.header.MeshOffset0 != 0) ReadMeshData(stream, pmo, 0); - if (pmo.header.MeshOffset1 != 0) ReadMeshData(stream, pmo, 1); - - // Read textures. - for (int i = 0; i < pmo.textureInfo.Length; i++) - { - if(pmo.textureInfo[i].TextureOffset != 0) - { - stream.Seek(pmo.textureInfo[i].TextureOffset + 0x10, SeekOrigin.Begin); - uint tm2size = stream.ReadUInt32() + 0x10; - stream.Seek(pmo.textureInfo[i].TextureOffset, SeekOrigin.Begin); - Tm2 tm2 = Tm2.Read(stream, true).First(); - - pmo.texturesData.Add(tm2); - } - } - - // Read Skeleton. - if(pmo.header.SkeletonOffset != 0) - { - stream.Seek(pmo.PMO_StartPosition + pmo.header.SkeletonOffset, SeekOrigin.Begin); - pmo.skeletonHeader = Mapping.ReadObject(stream); - pmo.boneList = new BoneData[pmo.skeletonHeader.BoneCount]; - for (int j = 0; j < pmo.skeletonHeader.BoneCount; j++) - { - pmo.boneList[j] = Mapping.ReadObject(stream); - } - } - - return pmo; - } - - private List TextureOffsets = new List(); - - public static void Write(Stream stream, Pmo pmo) - { - stream.Position = 0; - - WriteHeaderData(stream, pmo); - WriteMeshData(stream, pmo); - WriteTextureData(stream, pmo); - WriteTextureOffsets(stream, pmo); - - if (pmo.header.SkeletonOffset != 0) - { - stream.Seek(pmo.header.SkeletonOffset, SeekOrigin.Begin); - Mapping.WriteObject(stream, pmo.skeletonHeader); - - for (int joint = 0; joint < pmo.boneList.Length; joint++) - { - Mapping.WriteObject(stream, pmo.boneList[joint]); - } - } - } - - public static void WriteHeaderData(Stream stream, Pmo pmo) - { - Mapping.WriteObject(stream, pmo.header); - - for (int i = 0; i < pmo.header.TextureCount; i++) - { - Mapping.WriteObject(stream, pmo.textureInfo[i]); - } - } - - public static void WriteTextureData(Stream stream, Pmo pmo) - { - // Write textures. - for (int t = 0; t < pmo.texturesData.Count; t++) - { - pmo.TextureOffsets.Add((uint)stream.Position); - List tm2list = new List(); - tm2list.Add(pmo.texturesData[t]); - Tm2.Write(stream, tm2list); - } - } - - public static void WriteTextureOffsets(Stream stream, Pmo pmo) - { - // Go back to write tm2 offsets. - for (int p = 0; p < pmo.texturesData.Count; p++) - { - stream.Seek(0xA0 + (p * 0x20), SeekOrigin.Begin); - stream.Write(pmo.TextureOffsets[p]); - } - } - - public static void WriteMeshData(Stream stream, Pmo pmo) - { - bool hasSwappedToSecondModel = false; - - // Write Mesh Data. - for (int j = 0; j < pmo.Meshes.Count; j++) - { - if (!hasSwappedToSecondModel && pmo.Meshes[j].MeshNumber == 1 && pmo.header.MeshOffset0 != 0) - { - hasSwappedToSecondModel = true; - - for (uint b = 0; b < 0xC; b++) - stream.Write((byte)0x00); - - for (uint b = 0; stream.Position % 0x10 != 0; b++) - stream.Write((byte)0x00); - } - - MeshChunks chunk = pmo.Meshes[j]; - - Mapping.WriteObject(stream, chunk.SectionInfo); - if (chunk.SectionInfo_opt1 != null) - Mapping.WriteObject(stream, chunk.SectionInfo_opt1); - if (chunk.SectionInfo_opt2 != null) - Mapping.WriteObject(stream, chunk.SectionInfo_opt2); - - if (chunk.TriangleStripValues.Length > 0) - { - for (int z = 0; z < chunk.TriangleStripValues.Length; z++) - { - stream.Write((ushort)chunk.TriangleStripValues[z]); - } - } - - for (int k = 0; k < pmo.Meshes[j].SectionInfo.VertexCount; k++) - { - long vertexStartPos = stream.Position; - int vertexIncreaseAmount = 0; - - VertexFlags flags = Pmo.GetFlags(chunk.SectionInfo); - - // Write Joints. - if (flags.WeightFormat != CoordinateFormat.NO_VERTEX) - { - for (int w = 0; w < flags.SkinningWeightsCount + 1; w++) - { - int currentIndex = w + (k * (flags.SkinningWeightsCount + 1)); - - switch (flags.WeightFormat) - { - case CoordinateFormat.NORMALIZED_8_BITS: - stream.Write((byte)(chunk.jointWeights[k].weights[currentIndex] * 127.0f)); - break; - case CoordinateFormat.NORMALIZED_16_BITS: - stream.Write((byte)(chunk.jointWeights[k].weights[currentIndex] * 32767.0f)); - break; - case CoordinateFormat.FLOAT_32_BITS: - StreamExtensions.Write(stream, chunk.jointWeights[k].weights[currentIndex]); - break; - } - } - } - - // Write Texture Coords. - switch (flags.TextureCoordinateFormat) - { - case CoordinateFormat.NORMALIZED_8_BITS: - stream.Write((byte)(chunk.textureCoordinates[k].X * 128.0f)); - stream.Write((byte)(chunk.textureCoordinates[k].Y * 128.0f)); - break; - case CoordinateFormat.NORMALIZED_16_BITS: - vertexIncreaseAmount = ((0x2 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x1)) & 0x1); - for (int a = 0; a < vertexIncreaseAmount; a++) - stream.Write((byte)0xAB); - - stream.Write((ushort)(chunk.textureCoordinates[k].X * 32768.0f)); - stream.Write((ushort)(chunk.textureCoordinates[k].Y * 32768.0f)); - break; - case CoordinateFormat.FLOAT_32_BITS: - vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); - for (int a = 0; a < vertexIncreaseAmount; a++) - stream.Write((byte)0xAB); - - StreamExtensions.Write(stream, chunk.textureCoordinates[k].X); - StreamExtensions.Write(stream, chunk.textureCoordinates[k].Y); - break; - } - - // Write colors. - switch (flags.ColorFormat) - { - case Pmo.ColorFormat.NO_COLOR: - break; - case Pmo.ColorFormat.BGR_5650_16BITS: - break; - case Pmo.ColorFormat.ABGR_5551_16BITS: - break; - case Pmo.ColorFormat.ABGR_4444_16BITS: - break; - case Pmo.ColorFormat.ABGR_8888_32BITS: - vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); - for (int a = 0; a < vertexIncreaseAmount; a++) - stream.Write((byte)0xAB); - - stream.Write((byte)(chunk.colors[k].X)); - stream.Write((byte)(chunk.colors[k].Y)); - stream.Write((byte)(chunk.colors[k].Z)); - stream.Write((byte)(chunk.colors[k].W)); - break; - } - - // Write vertices. - switch (flags.PositionFormat) - { - case CoordinateFormat.NORMALIZED_8_BITS: - StreamExtensions.Write(stream, (sbyte)(chunk.vertices[k].X * 128.0f)); - StreamExtensions.Write(stream, (sbyte)(chunk.vertices[k].Y * 128.0f)); - StreamExtensions.Write(stream, (sbyte)(chunk.vertices[k].Z * 128.0f)); - break; - case CoordinateFormat.NORMALIZED_16_BITS: - vertexIncreaseAmount = ((0x2 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x1)) & 0x1); - for (int a = 0; a < vertexIncreaseAmount; a++) - stream.Write((byte)0xAB); - - StreamExtensions.Write(stream, (short)(chunk.vertices[k].X * 32768.0f)); - StreamExtensions.Write(stream, (short)(chunk.vertices[k].Y * 32768.0f)); - StreamExtensions.Write(stream, (short)(chunk.vertices[k].Z * 32768.0f)); - break; - case CoordinateFormat.FLOAT_32_BITS: - vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); - for (int a = 0; a < vertexIncreaseAmount; a++) - stream.Write((byte)0xAB); - - StreamExtensions.Write(stream, chunk.vertices[k].X); - StreamExtensions.Write(stream, chunk.vertices[k].Y); - StreamExtensions.Write(stream, chunk.vertices[k].Z); - break; - } - - int padding = ((int)vertexStartPos + chunk.SectionInfo.VertexSize) - (int)stream.Position; - for (int p = 0; p < padding; p++) - stream.Write((byte)0xAB); - } - - // Remainder. - uint remainder = (uint)stream.Position % 4; - for (int p = 0; p < remainder; p++) - stream.Write((byte)0x00); - - if (j == (pmo.Meshes.Count - 1)) - { - for (uint b = 0; b < 0xC; b++) - { - try - { - stream.Write((byte)0x00); - } - catch (Exception ex) - { - ex.ToString(); - } - } - - - int pd = (int)stream.Position % 0x10; - - for (int n = 0; pd != 0 ; n++) - { - try - { - stream.Write((byte)0x00); - } - catch (Exception ex) - { - ex.ToString(); - } - - pd = (int)stream.Position % 0x10; - } - } - } - } - - // Can't be shorter than the header size. - public static bool IsValid(Stream stream) => - stream.Length >= 0xA0 && - stream.SetPosition(0).ReadUInt32() == MagicCode; - } -} +using OpenKh.Common; +using OpenKh.Imaging; + +using System; +using System.Collections.Generic; +using System.IO; +using System.Numerics; +using Xe.BinaryMapper; +using System.Linq; + +namespace OpenKh.Bbs +{ + public class Pmo + { + private static readonly IBinaryMapping Mapping = + MappingConfiguration.DefaultConfiguration() + .ForTypeMatrix4x4() + .Build(); + + private const UInt32 MagicCode = 0x4F4D50; + + public class Header + { + [Data] public UInt32 MagicCode { get; set; } + [Data] public byte Number { get; set; } + [Data] public byte Group { get; set; } + [Data] public byte Version { get; set; } + [Data] public byte Padding { get; set; } + [Data] public ushort TextureCount { get; set; } + [Data] public ushort Unk0A { get; set; } + [Data] public UInt32 SkeletonOffset { get; set; } + [Data] public UInt32 MeshOffset0 { get; set; } + [Data] public ushort TriangleCount { get; set; } + [Data] public ushort VertexCount { get; set; } + [Data] public float ModelScale { get; set; } + [Data] public UInt32 MeshOffset1 { get; set; } + [Data(Count = 32)] public float[] BoundingBox { get; set; } + } + + public class TextureInfo + { + [Data] public UInt32 TextureOffset { get; set; } + [Data(Count = 12)] public string TextureName { get; set; } + [Data(Count = 4)] public UInt32[] Unknown { get; set; } + } + + public class MeshSection + { + [Data] public ushort VertexCount { get; set; } + [Data] public byte TextureID { get; set; } + [Data] public byte VertexSize { get; set; } // In bytes. + [Data] public UInt32 VertexFlags { get; set; } + [Data] public byte Group { get; set; } + [Data] public byte TriangleStripCount { get; set; } + [Data] public ushort Attribute { get; set; } + } + + public enum VertexAttribute + { + ATTRIBUTE_BLEND_NONE = 0, + ATTRIBUTE_NOMATERIAL = 1, + ATTRIBUTE_GLARE = 2, + ATTRIBUTE_BACK = 4, + ATTRIBUTE_DIVIDE = 8, + ATTRIBUTE_TEXALPHA = 16, + ATTRIBUTE_FLAG_SHIFT = 24, + ATTRIBUTE_PRIM_SHIFT = 28, + ATTRIBUTE_BLEND_SEMITRANS = 32, + ATTRIBUTE_BLEND_ADD = 64, + ATTRIBUTE_BLEND_SUB = 96, + ATTRIBUTE_BLEND_MASK = 224, + ATTRIBUTE_8 = 256, + ATTRIBUTE_9 = 512, + ATTRIBUTE_DROPSHADOW = 1024, + ATTRIBUTE_ENVMAP = 2048, + ATTRIBUTE_12 = 4096, + ATTRIBUTE_13 = 8192, + ATTRIBUTE_14 = 16384, + ATTRIBUTE_15 = 32768, + ATTRIBUTE_COLOR = 16777216, + ATTRIBUTE_NOWEIGHT = 33554432, + } + + // Fields starting with _ have a temporary name. + public class SkeletonHeader + { + [Data] public uint MagicValue { get; set; } + [Data] public uint Padding1 { get; set; } + [Data] public ushort BoneCount { get; set; } + [Data] public ushort Padding2 { get; set; } + [Data] public ushort SkinnedBoneCount { get; set; } + [Data] public ushort nStdBone { get; set; } + } + + public class BoneData + { + [Data] public ushort BoneIndex { get; set; } + [Data] public ushort Padding1 { get; set; } + [Data] public ushort ParentBoneIndex { get; set; } + [Data] public ushort Padding2 { get; set; } + [Data] public ushort SkinnedBoneIndex { get; set; } + [Data] public ushort Padding3 { get; set; } + [Data] public uint Padding4 { get; set; } + [Data(Count = 16)] public string JointName { get; set; } + [Data] public Matrix4x4 Transform { get; set; } + [Data] public Matrix4x4 InverseTransform { get; set; } + } + + public class MeshSectionOptional1 + { + [Data(Count = 8)] public byte[] SectionBoneIndices { get; set; } // Only present if header.SkeletonOffset != 0 + } + public class MeshSectionOptional2 + { + [Data] public UInt32 DiffuseColor { get; set; } // Only present if vertexFlags.DiffuseColor & 1 + } + + public enum CoordinateFormat + { + NO_VERTEX, + NORMALIZED_8_BITS, + NORMALIZED_16_BITS, + FLOAT_32_BITS + } + + public enum ColorFormat + { + NO_COLOR, + BGR_5650_16BITS = 4, + ABGR_5551_16BITS, + ABGR_4444_16BITS, + ABGR_8888_32BITS, + } + + public enum PrimitiveType + { + PRIMITIVE_POINT, + PRIMITIVE_LINE, + PRIMITIVE_LINE_STRIP, + PRIMITIVE_TRIANGLE, + PRIMITIVE_TRIANGLE_STRIP, + PRIMITIVE_TRIANGLE_FAN, + PRIMITIVE_QUAD + } + + public class VertexFlags + { + public CoordinateFormat TextureCoordinateFormat; + public ColorFormat ColorFormat; + public CoordinateFormat NormalFormat; // Unused + public CoordinateFormat PositionFormat; + public CoordinateFormat WeightFormat; + public byte IndicesFormat; // Unused + public bool Unused1; + public byte SkinningWeightsCount; + public bool Unused2; + public byte MorphWeightsCount; // Unused + public byte Unused3; + public bool SkipTransformPipeline; // Unused + public bool UniformDiffuseFlag; + public byte Unknown1; + public PrimitiveType Primitive; + } + + public static VertexFlags GetFlags(MeshSection meshSec) + { + VertexFlags flags = new VertexFlags(); + flags.TextureCoordinateFormat = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 0, 2); + flags.ColorFormat = (ColorFormat)GetBitFieldRange(meshSec.VertexFlags, 2, 3); + flags.NormalFormat = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 5, 2); + flags.PositionFormat = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 7, 2); + flags.WeightFormat = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 9, 2); + flags.IndicesFormat = (byte)GetBitFieldRange(meshSec.VertexFlags, 11, 2); + flags.Unused1 = (byte)GetBitFieldRange(meshSec.VertexFlags, 13, 1) == 1; + flags.SkinningWeightsCount = (byte)GetBitFieldRange(meshSec.VertexFlags, 14, 3); + flags.Unused2 = (byte)GetBitFieldRange(meshSec.VertexFlags, 17, 1) == 1; + flags.MorphWeightsCount = (byte)GetBitFieldRange(meshSec.VertexFlags, 18, 3); + flags.Unused3 = (byte)GetBitFieldRange(meshSec.VertexFlags, 21, 2); + flags.SkipTransformPipeline = (byte)GetBitFieldRange(meshSec.VertexFlags, 23, 1) == 1; + flags.UniformDiffuseFlag = (byte)GetBitFieldRange(meshSec.VertexFlags, 24, 1) == 1; + flags.Unknown1 = (byte)GetBitFieldRange(meshSec.VertexFlags, 25, 3); + flags.Primitive = (PrimitiveType)GetBitFieldRange(meshSec.VertexFlags, 28, 4); + + return flags; + } + + public static UInt32 GetBitFieldRange(UInt32 value, int start = 0, int length = 1) + { + UInt32 bit = value << 32 - (start + length); + bit >>= 32 - length; + return bit; + } + + public class WeightData + { + [Data] public CoordinateFormat coordFormart { get; set; } + [Data] public List weights { get; set; } + } + + public class MeshChunks + { + [Data] public bool IsTextureOpaque { get; set; } + [Data] public int MeshNumber { get; set; } + [Data] public MeshSection SectionInfo { get; set; } + [Data] public MeshSectionOptional1 SectionInfo_opt1 { get; set; } + [Data] public MeshSectionOptional2 SectionInfo_opt2 { get; set; } + [Data] public UInt16[] TriangleStripValues { get; set; } + [Data] public int TextureID { get; set; } + [Data] public List jointWeights { get; set; } + [Data] public List textureCoordinates { get; set; } + [Data] public List colors { get; set; } + [Data] public List vertices { get; set; } + [Data] public List Indices { get; set; } + + public MeshChunks() + { + IsTextureOpaque = true; + MeshNumber = 0; + TriangleStripValues = new UInt16[0]; + TextureID = 0; + jointWeights = new List(); + textureCoordinates = new List(); + colors = new List(); + vertices = new List(); + Indices = new List(); + } + } + + // PMO Header. + public Header header { get; set; } + // Data block for textures. The order will reflect their texture index. + public TextureInfo[] textureInfo { get; set; } + // Texture data blobs. + public List texturesData = new List(); + // Header of the skeleton. + public SkeletonHeader skeletonHeader { get; set; } + // Joints present in the skeleton. + public BoneData[] boneList; + + public List Meshes = new List(); + + public uint PMO_StartPosition = 0; + + public static void ReadHeader(Stream stream, Pmo pmo) + { + pmo.header = Mapping.ReadObject
(stream); + } + + public static void ReadTextureSection(Stream stream, Pmo pmo) + { + pmo.textureInfo = new TextureInfo[pmo.header.TextureCount]; + for (ushort i = 0; i < pmo.header.TextureCount; i++) + pmo.textureInfo[i] = Mapping.ReadObject(stream); + } + + public static void ReadMeshData(Stream stream, Pmo pmo, int MeshNumber = 0) + { + // Go to mesh position. + if (MeshNumber == 0) + stream.Seek(pmo.PMO_StartPosition + pmo.header.MeshOffset0, SeekOrigin.Begin); + else + stream.Seek(pmo.PMO_StartPosition + pmo.header.MeshOffset1, SeekOrigin.Begin); + + UInt16 VertCnt = 0xFFFF; + + while (VertCnt > 0) + { + MeshChunks meshChunk = new MeshChunks(); + meshChunk.MeshNumber = MeshNumber; + + meshChunk.SectionInfo = Mapping.ReadObject(stream); + + // Exit if Vertex Count is zero. + if (meshChunk.SectionInfo.VertexCount <= 0) + break; + + meshChunk.TextureID = meshChunk.SectionInfo.TextureID; + VertexFlags flags = GetFlags(meshChunk.SectionInfo); + + bool isColorFlagRisen = flags.UniformDiffuseFlag; + + if (pmo.header.SkeletonOffset != 0) + meshChunk.SectionInfo_opt1 = Mapping.ReadObject(stream); + if (isColorFlagRisen) + meshChunk.SectionInfo_opt2 = Mapping.ReadObject(stream); + if (meshChunk.SectionInfo.TriangleStripCount > 0) + { + meshChunk.TriangleStripValues = new UInt16[meshChunk.SectionInfo.TriangleStripCount]; + for (int i = 0; i < meshChunk.SectionInfo.TriangleStripCount; i++) + { + meshChunk.TriangleStripValues[i] = stream.ReadUInt16(); + } + } + + // Get Formats. + CoordinateFormat TexCoordFormat = flags.TextureCoordinateFormat; + CoordinateFormat VertexPositionFormat = flags.PositionFormat; + CoordinateFormat WeightFormat = flags.WeightFormat; + ColorFormat ColorFormat = flags.ColorFormat; + UInt32 SkinningWeightsCount = flags.SkinningWeightsCount; + BinaryReader r = new BinaryReader(stream); + long positionAfterHeader = stream.Position; + + if (meshChunk.SectionInfo.TriangleStripCount > 0) + { + int vertInd = 0; + for (int p = 0; p < meshChunk.SectionInfo.TriangleStripCount; p++) + { + for (int s = 0; s < (meshChunk.TriangleStripValues[p] - 2); s++) + { + if (s % 2 == 0) + { + meshChunk.Indices.Add(vertInd + s + 0); + meshChunk.Indices.Add(vertInd + s + 1); + meshChunk.Indices.Add(vertInd + s + 2); + } + else + { + meshChunk.Indices.Add(vertInd + s + 0); + meshChunk.Indices.Add(vertInd + s + 2); + meshChunk.Indices.Add(vertInd + s + 1); + } + } + + vertInd += meshChunk.TriangleStripValues[p]; + } + } + else + { + if (flags.Primitive == PrimitiveType.PRIMITIVE_TRIANGLE_STRIP) + { + for (int s = 0; s < (meshChunk.SectionInfo.VertexCount - 2); s++) + { + if (s % 2 == 0) + { + meshChunk.Indices.Add(s + 0); + meshChunk.Indices.Add(s + 1); + meshChunk.Indices.Add(s + 2); + } + else + { + meshChunk.Indices.Add(s + 1); + meshChunk.Indices.Add(s + 0); + meshChunk.Indices.Add(s + 2); + } + } + } + } + + for (int v = 0; v < meshChunk.SectionInfo.VertexCount; v++) + { + long vertexStartPos = stream.Position; + int vertexIncreaseAmount = 0; + + // Vertex Weights. + if (pmo.header.SkeletonOffset != 0 && WeightFormat != CoordinateFormat.NO_VERTEX) + { + WeightData WeightList = new WeightData(); + WeightList.weights = new List(); + WeightList.coordFormart = WeightFormat; + + for (int i = 0; i < (SkinningWeightsCount + 1); i++) + { + switch (WeightFormat) + { + case CoordinateFormat.NORMALIZED_8_BITS: + WeightList.weights.Add(stream.ReadByte() / 128.0f); + break; + case CoordinateFormat.NORMALIZED_16_BITS: + WeightList.weights.Add(stream.ReadUInt16() / 32768.0f); + break; + case CoordinateFormat.FLOAT_32_BITS: + WeightList.weights.Add(stream.ReadFloat()); + break; + case CoordinateFormat.NO_VERTEX: + break; + } + } + + meshChunk.jointWeights.Add(WeightList); + } + + Vector2 currentTexCoord = new Vector2(0, 0); + + switch (TexCoordFormat) + { + case CoordinateFormat.NORMALIZED_8_BITS: + currentTexCoord.X = stream.ReadByte() / 128.0f; + currentTexCoord.Y = stream.ReadByte() / 128.0f; + meshChunk.textureCoordinates.Add(currentTexCoord); + break; + case CoordinateFormat.NORMALIZED_16_BITS: + vertexIncreaseAmount = ((0x2 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x1)) & 0x1); + stream.Seek(vertexIncreaseAmount, SeekOrigin.Current); + + currentTexCoord.X = stream.ReadUInt16() / 32768.0f; + currentTexCoord.Y = stream.ReadUInt16() / 32768.0f; + meshChunk.textureCoordinates.Add(currentTexCoord); + break; + case CoordinateFormat.FLOAT_32_BITS: + vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); + stream.Seek(vertexIncreaseAmount, SeekOrigin.Current); + + currentTexCoord.X = stream.ReadFloat(); + currentTexCoord.Y = stream.ReadFloat(); + meshChunk.textureCoordinates.Add(currentTexCoord); + break; + case CoordinateFormat.NO_VERTEX: + meshChunk.textureCoordinates.Add(currentTexCoord); + break; + } + + Vector4 col; + + if (isColorFlagRisen) + { + uint c = meshChunk.SectionInfo_opt2.DiffuseColor; + col.X = c % 0x100; + col.Y = (c >> 8) % 0x100; + col.Z = (c >> 16) % 0x100; + col.W = (c >> 24) % 0x100; + + meshChunk.colors.Add(col); + } + else + { + switch (ColorFormat) + { + case Pmo.ColorFormat.NO_COLOR: + meshChunk.colors.Add(new Vector4(0xFF, 0xFF, 0xFF, 0xFF)); + break; + case Pmo.ColorFormat.BGR_5650_16BITS: + stream.ReadUInt16(); + break; + case Pmo.ColorFormat.ABGR_5551_16BITS: + stream.ReadUInt16(); + break; + case Pmo.ColorFormat.ABGR_4444_16BITS: + stream.ReadUInt16(); + break; + case Pmo.ColorFormat.ABGR_8888_32BITS: + vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); + stream.Seek(vertexIncreaseAmount, SeekOrigin.Current); + + col.X = stream.ReadByte(); + col.Y = stream.ReadByte(); + col.Z = stream.ReadByte(); + col.W = stream.ReadByte(); + meshChunk.colors.Add(col); + break; + } + } + + Vector3 currentVertex; + + // Handle triangles and triangle strips. + switch (VertexPositionFormat) + { + case CoordinateFormat.NORMALIZED_8_BITS: + currentVertex.X = r.ReadSByte() / 128.0f; + currentVertex.Y = r.ReadSByte() / 128.0f; + currentVertex.Z = r.ReadSByte() / 128.0f; + meshChunk.vertices.Add(currentVertex); + break; + case CoordinateFormat.NORMALIZED_16_BITS: + vertexIncreaseAmount = ((0x2 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x1)) & 0x1); + stream.Seek(vertexIncreaseAmount, SeekOrigin.Current); + + currentVertex.X = (float)stream.ReadInt16() / 32768.0f; + currentVertex.Y = (float)stream.ReadInt16() / 32768.0f; + currentVertex.Z = (float)stream.ReadInt16() / 32768.0f; + meshChunk.vertices.Add(currentVertex); + break; + case CoordinateFormat.FLOAT_32_BITS: + vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); + stream.Seek(vertexIncreaseAmount, SeekOrigin.Current); + + currentVertex.X = stream.ReadFloat(); + currentVertex.Y = stream.ReadFloat(); + currentVertex.Z = stream.ReadFloat(); + meshChunk.vertices.Add(currentVertex); + break; + } + + stream.Seek(vertexStartPos + meshChunk.SectionInfo.VertexSize, SeekOrigin.Begin); + + if (flags.Primitive == PrimitiveType.PRIMITIVE_TRIANGLE) + { + meshChunk.Indices.Add(v); + } + } + + VertCnt = meshChunk.SectionInfo.VertexCount; + pmo.Meshes.Add(meshChunk); + + // Find position of next data chunk. + stream.Seek(positionAfterHeader + (meshChunk.SectionInfo.VertexCount * meshChunk.SectionInfo.VertexSize), SeekOrigin.Begin); + stream.Seek(stream.Position % 4, SeekOrigin.Current); + } + } + + public static Pmo Read(Stream stream) + { + Pmo pmo = new Pmo(); + pmo.PMO_StartPosition = (uint)stream.Position; + + ReadHeader(stream, pmo); + ReadTextureSection(stream, pmo); + + // Read all data + if (pmo.header.MeshOffset0 != 0) + ReadMeshData(stream, pmo, 0); + if (pmo.header.MeshOffset1 != 0) + ReadMeshData(stream, pmo, 1); + + // Read textures. + for (int i = 0; i < pmo.textureInfo.Length; i++) + { + if (pmo.textureInfo[i].TextureOffset != 0) + { + stream.Seek(pmo.textureInfo[i].TextureOffset + 0x10, SeekOrigin.Begin); + uint tm2size = stream.ReadUInt32() + 0x10; + stream.Seek(pmo.textureInfo[i].TextureOffset, SeekOrigin.Begin); + Tm2 tm2 = Tm2.Read(stream, true).First(); + + pmo.texturesData.Add(tm2); + } + } + + // Read Skeleton. + if (pmo.header.SkeletonOffset != 0) + { + stream.Seek(pmo.PMO_StartPosition + pmo.header.SkeletonOffset, SeekOrigin.Begin); + pmo.skeletonHeader = Mapping.ReadObject(stream); + pmo.boneList = new BoneData[pmo.skeletonHeader.BoneCount]; + for (int j = 0; j < pmo.skeletonHeader.BoneCount; j++) + { + pmo.boneList[j] = Mapping.ReadObject(stream); + } + } + + return pmo; + } + + private List TextureOffsets = new List(); + + public static void Write(Stream stream, Pmo pmo) + { + stream.Position = 0; + + WriteHeaderData(stream, pmo); + WriteMeshData(stream, pmo); + WriteTextureData(stream, pmo); + WriteTextureOffsets(stream, pmo); + + if (pmo.header.SkeletonOffset != 0) + { + stream.Seek(pmo.header.SkeletonOffset, SeekOrigin.Begin); + Mapping.WriteObject(stream, pmo.skeletonHeader); + + for (int joint = 0; joint < pmo.boneList.Length; joint++) + { + Mapping.WriteObject(stream, pmo.boneList[joint]); + } + } + } + + public static void WriteHeaderData(Stream stream, Pmo pmo) + { + Mapping.WriteObject(stream, pmo.header); + + for (int i = 0; i < pmo.header.TextureCount; i++) + { + Mapping.WriteObject(stream, pmo.textureInfo[i]); + } + } + + public static void WriteTextureData(Stream stream, Pmo pmo) + { + // Write textures. + for (int t = 0; t < pmo.texturesData.Count; t++) + { + pmo.TextureOffsets.Add((uint)stream.Position); + List tm2list = new List(); + tm2list.Add(pmo.texturesData[t]); + Tm2.Write(stream, tm2list); + } + } + + public static void WriteTextureOffsets(Stream stream, Pmo pmo) + { + // Go back to write tm2 offsets. + for (int p = 0; p < pmo.texturesData.Count; p++) + { + stream.Seek(0xA0 + (p * 0x20), SeekOrigin.Begin); + stream.Write(pmo.TextureOffsets[p]); + } + } + + public static void WriteMeshData(Stream stream, Pmo pmo) + { + bool hasSwappedToSecondModel = false; + + // Write Mesh Data. + for (int j = 0; j < pmo.Meshes.Count; j++) + { + if (!hasSwappedToSecondModel && pmo.Meshes[j].MeshNumber == 1 && pmo.header.MeshOffset0 != 0) + { + hasSwappedToSecondModel = true; + + for (uint b = 0; b < 0xC; b++) + stream.Write((byte)0x00); + + for (uint b = 0; stream.Position % 0x10 != 0; b++) + stream.Write((byte)0x00); + } + + MeshChunks chunk = pmo.Meshes[j]; + + Mapping.WriteObject(stream, chunk.SectionInfo); + if (chunk.SectionInfo_opt1 != null) + Mapping.WriteObject(stream, chunk.SectionInfo_opt1); + if (chunk.SectionInfo_opt2 != null) + Mapping.WriteObject(stream, chunk.SectionInfo_opt2); + + if (chunk.TriangleStripValues.Length > 0) + { + for (int z = 0; z < chunk.TriangleStripValues.Length; z++) + { + stream.Write((ushort)chunk.TriangleStripValues[z]); + } + } + + for (int k = 0; k < pmo.Meshes[j].SectionInfo.VertexCount; k++) + { + long vertexStartPos = stream.Position; + int vertexIncreaseAmount = 0; + + VertexFlags flags = Pmo.GetFlags(chunk.SectionInfo); + + // Write Joints. + if (flags.WeightFormat != CoordinateFormat.NO_VERTEX) + { + for (int w = 0; w < flags.SkinningWeightsCount + 1; w++) + { + int currentIndex = w + (k * (flags.SkinningWeightsCount + 1)); + + switch (flags.WeightFormat) + { + case CoordinateFormat.NORMALIZED_8_BITS: + stream.Write((byte)(chunk.jointWeights[k].weights[currentIndex] * 127.0f)); + break; + case CoordinateFormat.NORMALIZED_16_BITS: + stream.Write((byte)(chunk.jointWeights[k].weights[currentIndex] * 32767.0f)); + break; + case CoordinateFormat.FLOAT_32_BITS: + StreamExtensions.Write(stream, chunk.jointWeights[k].weights[currentIndex]); + break; + } + } + } + + // Write Texture Coords. + switch (flags.TextureCoordinateFormat) + { + case CoordinateFormat.NORMALIZED_8_BITS: + stream.Write((byte)(chunk.textureCoordinates[k].X * 128.0f)); + stream.Write((byte)(chunk.textureCoordinates[k].Y * 128.0f)); + break; + case CoordinateFormat.NORMALIZED_16_BITS: + vertexIncreaseAmount = ((0x2 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x1)) & 0x1); + for (int a = 0; a < vertexIncreaseAmount; a++) + stream.Write((byte)0xAB); + + stream.Write((ushort)(chunk.textureCoordinates[k].X * 32768.0f)); + stream.Write((ushort)(chunk.textureCoordinates[k].Y * 32768.0f)); + break; + case CoordinateFormat.FLOAT_32_BITS: + vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); + for (int a = 0; a < vertexIncreaseAmount; a++) + stream.Write((byte)0xAB); + + StreamExtensions.Write(stream, chunk.textureCoordinates[k].X); + StreamExtensions.Write(stream, chunk.textureCoordinates[k].Y); + break; + } + + // Write colors. + switch (flags.ColorFormat) + { + case Pmo.ColorFormat.NO_COLOR: + break; + case Pmo.ColorFormat.BGR_5650_16BITS: + break; + case Pmo.ColorFormat.ABGR_5551_16BITS: + break; + case Pmo.ColorFormat.ABGR_4444_16BITS: + break; + case Pmo.ColorFormat.ABGR_8888_32BITS: + vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); + for (int a = 0; a < vertexIncreaseAmount; a++) + stream.Write((byte)0xAB); + + stream.Write((byte)(chunk.colors[k].X)); + stream.Write((byte)(chunk.colors[k].Y)); + stream.Write((byte)(chunk.colors[k].Z)); + stream.Write((byte)(chunk.colors[k].W)); + break; + } + + // Write vertices. + switch (flags.PositionFormat) + { + case CoordinateFormat.NORMALIZED_8_BITS: + StreamExtensions.Write(stream, (sbyte)(chunk.vertices[k].X * 128.0f)); + StreamExtensions.Write(stream, (sbyte)(chunk.vertices[k].Y * 128.0f)); + StreamExtensions.Write(stream, (sbyte)(chunk.vertices[k].Z * 128.0f)); + break; + case CoordinateFormat.NORMALIZED_16_BITS: + vertexIncreaseAmount = ((0x2 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x1)) & 0x1); + for (int a = 0; a < vertexIncreaseAmount; a++) + stream.Write((byte)0xAB); + + StreamExtensions.Write(stream, (short)(chunk.vertices[k].X * 32768.0f)); + StreamExtensions.Write(stream, (short)(chunk.vertices[k].Y * 32768.0f)); + StreamExtensions.Write(stream, (short)(chunk.vertices[k].Z * 32768.0f)); + break; + case CoordinateFormat.FLOAT_32_BITS: + vertexIncreaseAmount = ((0x4 - (Convert.ToInt32(stream.Position - vertexStartPos) & 0x3)) & 0x3); + for (int a = 0; a < vertexIncreaseAmount; a++) + stream.Write((byte)0xAB); + + StreamExtensions.Write(stream, chunk.vertices[k].X); + StreamExtensions.Write(stream, chunk.vertices[k].Y); + StreamExtensions.Write(stream, chunk.vertices[k].Z); + break; + } + + int padding = ((int)vertexStartPos + chunk.SectionInfo.VertexSize) - (int)stream.Position; + for (int p = 0; p < padding; p++) + stream.Write((byte)0xAB); + } + + // Remainder. + uint remainder = (uint)stream.Position % 4; + for (int p = 0; p < remainder; p++) + stream.Write((byte)0x00); + + if (j == (pmo.Meshes.Count - 1)) + { + for (uint b = 0; b < 0xC; b++) + { + try + { + stream.Write((byte)0x00); + } + catch (Exception ex) + { + ex.ToString(); + } + } + + + int pd = (int)stream.Position % 0x10; + + for (int n = 0; pd != 0; n++) + { + try + { + stream.Write((byte)0x00); + } + catch (Exception ex) + { + ex.ToString(); + } + + pd = (int)stream.Position % 0x10; + } + } + } + } + + // Can't be shorter than the header size. + public static bool IsValid(Stream stream) => + stream.Length >= 0xA0 && + stream.SetPosition(0).ReadUInt32() == MagicCode; + } +} diff --git a/OpenKh.Bbs/Pmp.cs b/OpenKh.Bbs/Pmp.cs index 7e8a408ca..832a8d2aa 100644 --- a/OpenKh.Bbs/Pmp.cs +++ b/OpenKh.Bbs/Pmp.cs @@ -1,175 +1,175 @@ -using Microsoft.VisualBasic.CompilerServices; -using OpenKh.Common; -using OpenKh.Common.Utils; -using OpenKh.Imaging; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Numerics; -using Xe.BinaryMapper; - -namespace OpenKh.Bbs -{ - - public class Pmp - { - private static readonly IBinaryMapping Mapping = - MappingConfiguration.DefaultConfiguration() - .ForType(x => new Vector3( - x.Reader.ReadSingle(), - x.Reader.ReadSingle(), - x.Reader.ReadSingle()), - x => - { - var vector = (Vector3)x.Item; - x.Writer.Write(vector.X); - x.Writer.Write(vector.Y); - x.Writer.Write(vector.Z); - }) - .Build(); - - private const UInt32 MagicCode = 0x504D50; - - public class Header - { - [Data] public UInt32 MagicCode { get; set; } - [Data] public ushort Version { get; set; } - [Data(Count = 2)] public int[] Padding { get; set; } - [Data] public byte Padding2 { get; set; } - [Data] public byte MapFlag { get; set; } - [Data] public ushort ObjectCount { get; set; } - [Data] public ushort ModelCount { get; set; } - [Data] public uint Padding3 { get; set; } - [Data] public ushort Padding4 { get; set; } - [Data] public ushort TextureCount { get; set; } - [Data] public uint TextureListOffset { get; set; } - } - - public enum MapFlags - { - FLAG_NONE = 0, - FLAG_DISPOFF = 1, - FLAG_PRESETOFF = 2, - FLAG_SYSPRESETOFF = 4 - } - - public class ObjectInfo - { - [Data] public float PositionX { get; set; } - [Data] public float PositionY { get; set; } - [Data] public float PositionZ { get; set; } - [Data] public float RotationX { get; set; } - [Data] public float RotationY { get; set; } - [Data] public float RotationZ { get; set; } - [Data] public float ScaleX { get; set; } - [Data] public float ScaleY { get; set; } - [Data] public float ScaleZ { get; set; } - [Data] public uint PMO_Offset { get; set; } - [Data] public uint Unk1 { get; set; } - [Data] public ushort ObjectFlags { get; set; } - [Data] public ushort ObjectID { get; set; } - } - - public class PMPTextureInfo - { - [Data] public uint Offset { get; set; } - [Data(Count = 12)] public string TextureName { get; set; } - [Data] public float AnimateUV_X { get; set; } - [Data] public float AnimateUV_Y { get; set; } - [Data(Count = 2)] public uint[] Unknown { get; set; } - } - - public Header header = new Header(); - public List objectInfo = new List(); - public List PmoList = new List(); - public List TextureDataList = new List(); - public List TextureList = new List(); - public List hasDifferentMatrix = new List(); - - public static Pmp Read(Stream stream) - { - Pmp pmp = new Pmp(); - pmp.header = BinaryMapping.ReadObject
(stream); - - // Read Object List. - for(int i = 0; i < pmp.header.ObjectCount; i++) - { - pmp.objectInfo.Add(Mapping.ReadObject(stream)); - pmp.hasDifferentMatrix.Add(BitsUtil.Int.GetBit(pmp.objectInfo[i].ObjectFlags, 0)); - } - - // Read PMO list. - for (int p = 0; p < pmp.header.ObjectCount; p++) - { - ObjectInfo currentPmoInfo = pmp.objectInfo[p]; - if(currentPmoInfo.PMO_Offset != 0) - { - stream.Seek(currentPmoInfo.PMO_Offset, SeekOrigin.Begin); - pmp.PmoList.Add(Pmo.Read(stream)); - } - } - - stream.Seek(pmp.header.TextureListOffset, SeekOrigin.Begin); - - for(int t = 0; t < pmp.header.TextureCount; t++) - { - pmp.TextureList.Add(BinaryMapping.ReadObject(stream)); - } - - // Read textures. - for (int k = 0; k < pmp.TextureList.Count; k++) - { - stream.Seek(pmp.TextureList[k].Offset + 0x10, SeekOrigin.Begin); - uint tm2size = stream.ReadUInt32() + 0x10; - stream.Seek(pmp.TextureList[k].Offset, SeekOrigin.Begin); - - pmp.TextureDataList.Add(Tm2.Read(stream, true).First()); - } - - return pmp; - } - - public static void Write(Stream stream, Pmp pmp) - { - stream.Position = 0; - BinaryMapping.WriteObject
(stream, pmp.header); - - for(int i = 0; i < pmp.objectInfo.Count; i++) - { - BinaryMapping.WriteObject(stream, pmp.objectInfo[i]); - } - - List nPmoList = pmp.PmoList; - nPmoList.Sort((l, r) => l.PMO_StartPosition.CompareTo(r.PMO_StartPosition)); - - for(int p = 0; p < nPmoList.Count; p++) - { - BinaryMapping.WriteObject(stream, nPmoList[p].header); - - for(int g = 0; g < nPmoList[p].textureInfo.Length; g++) - { - BinaryMapping.WriteObject(stream, nPmoList[p].textureInfo[g]); - } - - Pmo.WriteMeshData(stream, nPmoList[p]); - } - - for(int tl = 0; tl < pmp.TextureList.Count; tl++) - { - BinaryMapping.WriteObject(stream, pmp.TextureList[tl]); - } - - for (int td = 0; td < pmp.TextureList.Count; td++) - { - List l = new List(); - l.Add(pmp.TextureDataList[td]); - Tm2.Write(stream, l); - } - } - - public static bool IsValid(Stream stream) => - stream.Length >= 0x20 && - stream.SetPosition(0).ReadUInt32() == MagicCode; - } -} +using Microsoft.VisualBasic.CompilerServices; +using OpenKh.Common; +using OpenKh.Common.Utils; +using OpenKh.Imaging; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Numerics; +using Xe.BinaryMapper; + +namespace OpenKh.Bbs +{ + + public class Pmp + { + private static readonly IBinaryMapping Mapping = + MappingConfiguration.DefaultConfiguration() + .ForType(x => new Vector3( + x.Reader.ReadSingle(), + x.Reader.ReadSingle(), + x.Reader.ReadSingle()), + x => + { + var vector = (Vector3)x.Item; + x.Writer.Write(vector.X); + x.Writer.Write(vector.Y); + x.Writer.Write(vector.Z); + }) + .Build(); + + private const UInt32 MagicCode = 0x504D50; + + public class Header + { + [Data] public UInt32 MagicCode { get; set; } + [Data] public ushort Version { get; set; } + [Data(Count = 2)] public int[] Padding { get; set; } + [Data] public byte Padding2 { get; set; } + [Data] public byte MapFlag { get; set; } + [Data] public ushort ObjectCount { get; set; } + [Data] public ushort ModelCount { get; set; } + [Data] public uint Padding3 { get; set; } + [Data] public ushort Padding4 { get; set; } + [Data] public ushort TextureCount { get; set; } + [Data] public uint TextureListOffset { get; set; } + } + + public enum MapFlags + { + FLAG_NONE = 0, + FLAG_DISPOFF = 1, + FLAG_PRESETOFF = 2, + FLAG_SYSPRESETOFF = 4 + } + + public class ObjectInfo + { + [Data] public float PositionX { get; set; } + [Data] public float PositionY { get; set; } + [Data] public float PositionZ { get; set; } + [Data] public float RotationX { get; set; } + [Data] public float RotationY { get; set; } + [Data] public float RotationZ { get; set; } + [Data] public float ScaleX { get; set; } + [Data] public float ScaleY { get; set; } + [Data] public float ScaleZ { get; set; } + [Data] public uint PMO_Offset { get; set; } + [Data] public uint Unk1 { get; set; } + [Data] public ushort ObjectFlags { get; set; } + [Data] public ushort ObjectID { get; set; } + } + + public class PMPTextureInfo + { + [Data] public uint Offset { get; set; } + [Data(Count = 12)] public string TextureName { get; set; } + [Data] public float AnimateUV_X { get; set; } + [Data] public float AnimateUV_Y { get; set; } + [Data(Count = 2)] public uint[] Unknown { get; set; } + } + + public Header header = new Header(); + public List objectInfo = new List(); + public List PmoList = new List(); + public List TextureDataList = new List(); + public List TextureList = new List(); + public List hasDifferentMatrix = new List(); + + public static Pmp Read(Stream stream) + { + Pmp pmp = new Pmp(); + pmp.header = BinaryMapping.ReadObject
(stream); + + // Read Object List. + for (int i = 0; i < pmp.header.ObjectCount; i++) + { + pmp.objectInfo.Add(Mapping.ReadObject(stream)); + pmp.hasDifferentMatrix.Add(BitsUtil.Int.GetBit(pmp.objectInfo[i].ObjectFlags, 0)); + } + + // Read PMO list. + for (int p = 0; p < pmp.header.ObjectCount; p++) + { + ObjectInfo currentPmoInfo = pmp.objectInfo[p]; + if (currentPmoInfo.PMO_Offset != 0) + { + stream.Seek(currentPmoInfo.PMO_Offset, SeekOrigin.Begin); + pmp.PmoList.Add(Pmo.Read(stream)); + } + } + + stream.Seek(pmp.header.TextureListOffset, SeekOrigin.Begin); + + for (int t = 0; t < pmp.header.TextureCount; t++) + { + pmp.TextureList.Add(BinaryMapping.ReadObject(stream)); + } + + // Read textures. + for (int k = 0; k < pmp.TextureList.Count; k++) + { + stream.Seek(pmp.TextureList[k].Offset + 0x10, SeekOrigin.Begin); + uint tm2size = stream.ReadUInt32() + 0x10; + stream.Seek(pmp.TextureList[k].Offset, SeekOrigin.Begin); + + pmp.TextureDataList.Add(Tm2.Read(stream, true).First()); + } + + return pmp; + } + + public static void Write(Stream stream, Pmp pmp) + { + stream.Position = 0; + BinaryMapping.WriteObject
(stream, pmp.header); + + for (int i = 0; i < pmp.objectInfo.Count; i++) + { + BinaryMapping.WriteObject(stream, pmp.objectInfo[i]); + } + + List nPmoList = pmp.PmoList; + nPmoList.Sort((l, r) => l.PMO_StartPosition.CompareTo(r.PMO_StartPosition)); + + for (int p = 0; p < nPmoList.Count; p++) + { + BinaryMapping.WriteObject(stream, nPmoList[p].header); + + for (int g = 0; g < nPmoList[p].textureInfo.Length; g++) + { + BinaryMapping.WriteObject(stream, nPmoList[p].textureInfo[g]); + } + + Pmo.WriteMeshData(stream, nPmoList[p]); + } + + for (int tl = 0; tl < pmp.TextureList.Count; tl++) + { + BinaryMapping.WriteObject(stream, pmp.TextureList[tl]); + } + + for (int td = 0; td < pmp.TextureList.Count; td++) + { + List l = new List(); + l.Add(pmp.TextureDataList[td]); + Tm2.Write(stream, l); + } + } + + public static bool IsValid(Stream stream) => + stream.Length >= 0x20 && + stream.SetPosition(0).ReadUInt32() == MagicCode; + } +} diff --git a/OpenKh.Bbs/SystemData/Command.cs b/OpenKh.Bbs/SystemData/Command.cs index df3a8d512..744a8f9cd 100644 --- a/OpenKh.Bbs/SystemData/Command.cs +++ b/OpenKh.Bbs/SystemData/Command.cs @@ -1,457 +1,457 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Bbs.SystemData -{ - public class Command - { - public enum Type : ushort - { - COMMAND_KIND_None = 0, - COMMAND_KIND_Attack = 1, - COMMAND_KIND_Blitz01 = 2, - COMMAND_KIND_Blitz02 = 3, - COMMAND_KIND_Blitz03 = 4, - COMMAND_KIND_Blitz04 = 5, - COMMAND_KIND_Blitz05 = 6, - COMMAND_KIND_Blitz06 = 7, - COMMAND_KIND_Barrage07 = 8, - COMMAND_KIND_Barrage08 = 9, - COMMAND_KIND_Barrage09 = 10, - COMMAND_KIND_Barrage10 = 11, - COMMAND_KIND_Barrage11 = 12, - COMMAND_KIND_Barrage12 = 13, - COMMAND_KIND_Barrage13 = 14, - COMMAND_KIND_Barrage14 = 15, - COMMAND_KIND_Combo15 = 16, - COMMAND_KIND_Finish = 17, - COMMAND_KIND_FatalMode = 18, - COMMAND_KIND_MagicWish = 19, - COMMAND_KIND_FireBlazer = 21, - COMMAND_KIND_DiamondDust = 22, - COMMAND_KIND_Cyclone = 24, - COMMAND_KIND_BladeCharge = 25, - COMMAND_KIND_GhostDrive = 28, - COMMAND_KIND_DarkImpulse = 30, - COMMAND_KIND_IceBlast = 32, - COMMAND_KIND_DLink1 = 33, - COMMAND_KIND_DLink2 = 34, - COMMAND_KIND_DLink3 = 35, - COMMAND_KIND_DLink4 = 36, - COMMAND_KIND_DLink5 = 37, - COMMAND_KIND_DLink6 = 38, - COMMAND_KIND_DLink7 = 39, - COMMAND_KIND_DLink8 = 40, - COMMAND_KIND_DLink9 = 41, - COMMAND_KIND_DLink10 = 42, - COMMAND_KIND_DLink11 = 43, - COMMAND_KIND_DLink12 = 44, - COMMAND_KIND_DLink13 = 45, - COMMAND_KIND_Combo17 = 46, - COMMAND_KIND_DLink17 = 47, - COMMAND_KIND_DLink1R = 48, - COMMAND_KIND_DLink2R = 49, - COMMAND_KIND_DLink3R = 50, - COMMAND_KIND_DLink4R = 51, - COMMAND_KIND_DLink5R = 52, - COMMAND_KIND_DLink6R = 53, - COMMAND_KIND_DLink7R = 54, - COMMAND_KIND_DLink8R = 55, - COMMAND_KIND_DLink9R = 56, - COMMAND_KIND_DLink10R = 57, - COMMAND_KIND_DLink11R = 58, - COMMAND_KIND_DLink12R = 59, - COMMAND_KIND_DLink13R = 60, - COMMAND_KIND_FinishV01 = 61, - COMMAND_KIND_FinishA02 = 62, - COMMAND_KIND_FinishT03 = 63, - COMMAND_KIND_FinishV11 = 64, - COMMAND_KIND_FinishA12 = 65, - COMMAND_KIND_FinishT13 = 66, - COMMAND_KIND_FinishC14 = 67, - COMMAND_KIND_FinishC15 = 68, - COMMAND_KIND_FinishV21 = 69, - COMMAND_KIND_FinishA22 = 70, - COMMAND_KIND_FinishT23 = 71, - COMMAND_KIND_FinishC24 = 72, - COMMAND_KIND_FinishC25 = 73, - COMMAND_KIND_FinishC26 = 74, - COMMAND_KIND_FinishC27 = 75, - COMMAND_KIND_FinishV31 = 76, - COMMAND_KIND_FinishA32 = 77, - COMMAND_KIND_FinishT33 = 78, - COMMAND_KIND_FinishC34 = 79, - COMMAND_KIND_FinishC35 = 80, - COMMAND_KIND_FinishC36 = 81, - COMMAND_KIND_FinishV41 = 82, - COMMAND_KIND_FinishA42 = 83, - COMMAND_KIND_FinishT43 = 84, - COMMAND_KIND_FinishC44 = 85, - COMMAND_KIND_FinishC45 = 86, - COMMAND_KIND_FinishC46 = 87, - COMMAND_KIND_FinishV51 = 88, - COMMAND_KIND_FinishA52 = 89, - COMMAND_KIND_FinishT53 = 90, - COMMAND_KIND_AerialBreak = 91, - COMMAND_KIND_FinalBreak = 92, - COMMAND_KIND_CosmicArts = 93, - COMMAND_KIND_Catastrophe = 94, - COMMAND_KIND_FireRush = 96, - COMMAND_KIND_DarkCatalyst = 97, - COMMAND_KIND_FreezeRaid = 102, - COMMAND_KIND_Judgement = 105, - COMMAND_KIND_FireBlitz = 106, - COMMAND_KIND_AerialSlam = 109, - COMMAND_KIND_LastArcanum = 111, - COMMAND_KIND_BlizzardBlade = 115, - COMMAND_KIND_FireStrike = 118, - COMMAND_KIND_ConfuseStrike = 119, - COMMAND_KIND_BindStrike = 120, - COMMAND_KIND_BrutalForce = 122, - COMMAND_KIND_MagneSpiral = 123, - COMMAND_KIND_Kamaitachi = 125, - COMMAND_KIND_Kishikaisei = 126, - COMMAND_KIND_MagneBreaker = 127, - COMMAND_KIND_GaiaImpact = 128, - COMMAND_KIND_BreakTime = 130, - COMMAND_KIND_Fire = 131, - COMMAND_KIND_Fira = 132, - COMMAND_KIND_Firaga = 133, - COMMAND_KIND_DarkFiraga = 134, - COMMAND_KIND_FiragaStorm = 135, - COMMAND_KIND_Blizzard = 138, - COMMAND_KIND_Blizzara = 139, - COMMAND_KIND_Blizzaga = 140, - COMMAND_KIND_Cure = 146, - COMMAND_KIND_Cura = 147, - COMMAND_KIND_Curaga = 148, - COMMAND_KIND_Esuna = 149, - COMMAND_KIND_DetoneShield = 150, - COMMAND_KIND_DetoneSquare = 151, - COMMAND_KIND_DetoneChaser = 152, - COMMAND_KIND_Magne = 156, - COMMAND_KIND_Magnera = 157, - COMMAND_KIND_Magnega = 158, - COMMAND_KIND_MunnyMagne = 159, - COMMAND_KIND_HpMagne = 160, - COMMAND_KIND_FocusMagne = 161, - COMMAND_KIND_Aero = 162, - COMMAND_KIND_Aera = 163, - COMMAND_KIND_Aeroga = 164, - COMMAND_KIND_Degenerate = 165, - COMMAND_KIND_Holy = 166, - COMMAND_KIND_Freeze = 167, - COMMAND_KIND_GlacialArts = 168, - COMMAND_KIND_IceBarrage = 169, - COMMAND_KIND_FiragaBurst = 170, - COMMAND_KIND_MegaFlare = 172, - COMMAND_KIND_Meteor = 175, - COMMAND_KIND_Minimum = 177, - COMMAND_KIND_BlackOut = 178, - COMMAND_KIND_FiragaSpark = 179, - COMMAND_KIND_Confuse = 180, - COMMAND_KIND_Bind = 181, - COMMAND_KIND_Poison = 182, - COMMAND_KIND_Stop = 184, - COMMAND_KIND_Stopga = 186, - COMMAND_KIND_Stopra = 185, - COMMAND_KIND_HiPotion = 189, - COMMAND_KIND_Ether = 191, - COMMAND_KIND_Elixir = 194, - COMMAND_KIND_LastElixir = 195, - COMMAND_KIND_BalloonLetter = 196, - COMMAND_KIND_Ice1 = 197, - COMMAND_KIND_Ice2 = 198, - COMMAND_KIND_Ice3 = 199, - COMMAND_KIND_Ice4 = 200, - COMMAND_KIND_Ice5 = 201, - COMMAND_KIND_Ice6 = 202, - COMMAND_KIND_Ice7 = 203, - COMMAND_KIND_Ice8 = 204, - COMMAND_KIND_Ice9 = 205, - COMMAND_KIND_Ice10 = 206, - COMMAND_KIND_Ice11 = 207, - COMMAND_KIND_Ice12 = 208, - COMMAND_KIND_Ice13 = 209, - COMMAND_KIND_Ice14 = 210, - COMMAND_KIND_FriendCure = 211, - COMMAND_KIND_FriendCura = 212, - COMMAND_KIND_FriendCuraga = 213, - COMMAND_KIND_FriendEsuna = 214, - COMMAND_KIND_Confetti = 215, - COMMAND_KIND_Cracker = 216, - COMMAND_KIND_GutsPose = 218, - COMMAND_KIND_DeckScramble = 219, - COMMAND_KIND_Banish = 220, - COMMAND_KIND_Gold = 224, - COMMAND_KIND_DeckFinish = 226, - COMMAND_KIND_DeckDarkVolley = 227, - COMMAND_KIND_HolyStorm = 228, - COMMAND_KIND_FairyStep = 230, - COMMAND_KIND_FairyCure = 232, - COMMAND_KIND_DwarfDoc = 233, - COMMAND_KIND_DwarfGrumpy = 234, - COMMAND_KIND_DwarfSneezy = 235, - COMMAND_KIND_DwarfHappy = 236, - COMMAND_KIND_DwarfSleepy = 237, - COMMAND_KIND_DwarfBashful = 238, - COMMAND_KIND_DwarfDopey = 239, - COMMAND_KIND_DarkAxis = 240, - COMMAND_KIND_DarkSplicer = 241, - COMMAND_KIND_Illusion1 = 242, - COMMAND_KIND_Illusion2 = 243, - COMMAND_KIND_Illusion3 = 244, - COMMAND_KIND_Illusion4 = 245, - COMMAND_KIND_Illusion5 = 246, - COMMAND_KIND_DeckEnd = 247, - COMMAND_KIND_MOVE_START = 248, - COMMAND_KIND_Jump = 249, - COMMAND_KIND_HiJump = 250, - COMMAND_KIND_DodgeRoll = 251, - COMMAND_KIND_FireRoll = 254, - COMMAND_KIND_AirSlide = 255, - COMMAND_KIND_IceSlide = 256, - COMMAND_KIND_Glide = 258, - COMMAND_KIND_FireGlide = 260, - COMMAND_KIND_HomingSlide = 261, - COMMAND_KIND_Guard = 265, - COMMAND_KIND_HealGuard = 266, - COMMAND_KIND_FocusGuard = 267, - COMMAND_KIND_HealReflect = 271, - COMMAND_KIND_FocusReflect = 272, - COMMAND_KIND_ConfuseReflect = 273, - COMMAND_KIND_GuardSlash = 275, - COMMAND_KIND_GuardImpact = 276, - COMMAND_KIND_BackBreaker = 277, - COMMAND_KIND_CounterRaid = 279, - COMMAND_KIND_CounterBlitz = 280, - COMMAND_KIND_CounterCharge = 281, - COMMAND_KIND_AirRecovery = 282, - COMMAND_KIND_MOVE_END = 283, - COMMAND_KIND_FlameSpark = 285, - COMMAND_KIND_ChaosGunner = 286, - COMMAND_KIND_BubbleBlaster = 287, - COMMAND_KIND_DarkVolley = 288, - COMMAND_KIND_BioBarrage = 291, - COMMAND_KIND_IceSlider = 295, - COMMAND_KIND_DarkCannon = 298, - COMMAND_KIND_BladeBallista = 301, - COMMAND_KIND_Check = 305, - COMMAND_KIND_Cover = 308, - COMMAND_KIND_Goto = 309, - COMMAND_KIND_Goal = 310, - COMMAND_KIND_Call = 311, - COMMAND_KIND_LastDance = 312, - COMMAND_KIND_BraveRevenge = 314, - COMMAND_KIND_BraveSlash = 315, - COMMAND_KIND_BoulderBreaker = 317, - COMMAND_KIND_HolyFlood = 321, - COMMAND_KIND_DualLimit = 322, - COMMAND_KIND_HangOn = 323, - COMMAND_KIND_FairyMagic = 325, - COMMAND_KIND_action25 = 327, - COMMAND_KIND_action26 = 328, - COMMAND_KIND_HealLight = 329, - COMMAND_KIND_DebugJump = 336, - COMMAND_KIND_StyleNormal = 337, - COMMAND_KIND_StyleFatalMode = 338, - COMMAND_KIND_StyleMagicWish = 339, - COMMAND_KIND_StyleSpeedRave = 340, - COMMAND_KIND_StyleFireBlazer = 341, - COMMAND_KIND_StyleDiamondDust = 342, - COMMAND_KIND_StyleThunderBolt = 343, - COMMAND_KIND_StyleCyclone = 344, - COMMAND_KIND_StyleBladeCharge = 345, - COMMAND_KIND_StyleSkyRider = 346, - COMMAND_KIND_StyleRockBreaker = 347, - COMMAND_KIND_StyleGhostDrive = 348, - COMMAND_KIND_StyleRhythmMixer = 349, - COMMAND_KIND_StyleDarkImpulse = 350, - COMMAND_KIND_StyleWingBlade = 351, - COMMAND_KIND_StyleIceBlast = 352, - COMMAND_KIND_StyleEnd = 353, - COMMAND_KIND_LINK_START = 354, - COMMAND_KIND_LinkDonald = 356, - COMMAND_KIND_LinkKing = 355, - COMMAND_KIND_LinkGoofy = 357, - COMMAND_KIND_LinkStitch = 358, - COMMAND_KIND_LinkPan = 359, - COMMAND_KIND_LinkMaleficent = 360, - COMMAND_KIND_LinkAqua = 365, - COMMAND_KIND_LinkCinderella = 361, - COMMAND_KIND_LinkSnowWhite = 362, - COMMAND_KIND_LinkZack = 363, - COMMAND_KIND_LinkPete = 364, - COMMAND_KIND_LinkVentus = 366, - COMMAND_KIND_LinkTerra = 367, - COMMAND_KIND_LinkArmoredAqua = 368, - COMMAND_KIND_LinkArmoredVentus = 369, - COMMAND_KIND_LinkArmoredTerra = 370, - COMMAND_KIND_LinkVanitas = 371, - COMMAND_KIND_LinkKingR = 372, - COMMAND_KIND_LinkDonaldR = 373, - COMMAND_KIND_LinkGoofyR = 374, - COMMAND_KIND_LinkStitchR = 375, - COMMAND_KIND_LinkPanR = 376, - COMMAND_KIND_LinkMaleficentR = 377, - COMMAND_KIND_LinkCinderellaR = 378, - COMMAND_KIND_LinkSnowWhiteR = 379, - COMMAND_KIND_LinkZackR = 380, - COMMAND_KIND_LinkPeteR = 381, - COMMAND_KIND_LinkAquaR = 382, - COMMAND_KIND_LinkVentusR = 383, - COMMAND_KIND_LinkTerraR = 384, - COMMAND_KIND_LinkPC1 = 385, - COMMAND_KIND_LinkPC2 = 386, - COMMAND_KIND_LinkPC3 = 387, - COMMAND_KIND_LinkPC4 = 388, - COMMAND_KIND_LinkPC5 = 389, - COMMAND_KIND_LinkPC6 = 390, - COMMAND_KIND_LinkPC7 = 391, - COMMAND_KIND_LinkPC8 = 392, - COMMAND_KIND_LinkEnd = 393, - COMMAND_KIND_IllusionNull = 394, - COMMAND_KIND_IllusionTypeM = 395, - COMMAND_KIND_IllusionTypeS = 396, - COMMAND_KIND_IllusionTypeB = 397, - COMMAND_KIND_IllusionTypeP = 398, - COMMAND_KIND_IllusionTypeI = 399, - COMMAND_KIND_IllusionEnd = 400, - COMMAND_KIND_IllusionAttack1 = 401, - COMMAND_KIND_IllusionAttack2 = 402, - COMMAND_KIND_IllusionAttack3 = 403, - COMMAND_KIND_IllusionAttack4 = 404, - COMMAND_KIND_IllusionAttack5 = 405, - COMMAND_KIND_IllusionFinish1 = 406, - COMMAND_KIND_IllusionFinish2 = 407, - COMMAND_KIND_IllusionFinish3 = 408, - COMMAND_KIND_IllusionFinish4 = 409, - COMMAND_KIND_IllusionFinish5 = 410, - COMMAND_KIND_IllusionDeck1 = 411, - COMMAND_KIND_IllusionDeck2 = 412, - COMMAND_KIND_IllusionDeck3 = 413, - COMMAND_KIND_IllusionDeck4 = 414, - COMMAND_KIND_IllusionDeck5 = 415, - COMMAND_KIND_IllusionAction1 = 416, - COMMAND_KIND_IllusionAction2 = 417, - COMMAND_KIND_IllusionAction3 = 418, - COMMAND_KIND_IllusionAction4 = 419, - COMMAND_KIND_IllusionAction5 = 420, - COMMAND_KIND_ENCHANT_START = 421, - COMMAND_KIND_ENCHANT_END = 450, - COMMAND_KIND_End = 498, - - - - - - COMMAND_KIND_Midareuchi = 110, - - COMMAND_KIND_MegePotion = 190, - COMMAND_KIND_MegaEther = 192, - - - - COMMAND_KIND_NetAccess = 330, - COMMAND_KIND_NetCancel = 333, - COMMAND_KIND_NetExchange = 334, - COMMAND_KIND_NetReady = 332, - COMMAND_KIND_NetStart = 335, - COMMAND_KIND_NetWarp = 331, - COMMAND_KIND_Open = 304, - COMMAND_KIND_PRIZE_END = 497, - COMMAND_KIND_PRIZE_START = 482, - COMMAND_KIND_PhotonCharge = 294, - - COMMAND_KIND_PoisonBlade = 113, - COMMAND_KIND_PoisonGuard = 269, - COMMAND_KIND_Potion = 188, - COMMAND_KIND_Provoke = 217, - COMMAND_KIND_PsychicsPulse = 293, - COMMAND_KIND_PunishKitty = 324, - COMMAND_KIND_Quake = 173, - COMMAND_KIND_QuickRoll = 253, - COMMAND_KIND_RagingCharge = 221, - COMMAND_KIND_RagingStorm = 171, - COMMAND_KIND_Ragnarock = 289, - COMMAND_KIND_RainbowShower = 292, - COMMAND_KIND_Reflect = 270, - COMMAND_KIND_ReflectBlitz = 107, - COMMAND_KIND_ReflectPulse = 278, - COMMAND_KIND_ReflectRaid = 104, - COMMAND_KIND_Remedy = 193, - COMMAND_KIND_RhythmMixer = 29, - COMMAND_KIND_RockBreaker = 27, - COMMAND_KIND_Rush = 95, - COMMAND_KIND_SHOOT_END = 302, - COMMAND_KIND_SHOOT_REG = 18, - COMMAND_KIND_SHOOT_START = 283, - COMMAND_KIND_STYLE_END = 353, - COMMAND_KIND_STYLE_START = 337, - COMMAND_KIND_Salvation = 124, - COMMAND_KIND_Save = 302, - COMMAND_KIND_ShadowRunner = 297, - COMMAND_KIND_ShinyBloom = 300, - COMMAND_KIND_ShockGuard = 268, - COMMAND_KIND_ShootLock = 283, - COMMAND_KIND_Shop = 306, - COMMAND_KIND_SkyRider = 26, - COMMAND_KIND_SkyVault = 264, - COMMAND_KIND_Sleple = 187, - COMMAND_KIND_Slide = 248, - COMMAND_KIND_SlideTurn = 257, - COMMAND_KIND_SlotBlade = 117, - COMMAND_KIND_Slow = 183, - COMMAND_KIND_SlowFiraga = 137, - COMMAND_KIND_SonicImpact = 263, - COMMAND_KIND_SonicRave = 98, - COMMAND_KIND_SpeedRave = 20, - COMMAND_KIND_StarBurst = 284, - COMMAND_KIND_StitchShoot = 319, - COMMAND_KIND_StitchStrike = 320, - - COMMAND_KIND_StopReflect = 274, - COMMAND_KIND_StormShock = 290, - COMMAND_KIND_StrikeRaid = 101, - COMMAND_KIND_StunBlade = 116, - - - COMMAND_KIND_SuperGlide = 259, - COMMAND_KIND_Sutemi = 129, - COMMAND_KIND_SwingSlash = 318, - COMMAND_KIND_Talk = 303, - COMMAND_KIND_Tereport = 262, - COMMAND_KIND_Thundaga = 144, - COMMAND_KIND_ThundagaShot = 145, - COMMAND_KIND_Thunder = 142, - COMMAND_KIND_ThunderBlitz = 108, - COMMAND_KIND_ThunderBolt = 23, - COMMAND_KIND_ThunderRoll = 252, - COMMAND_KIND_Thundra = 143, - COMMAND_KIND_TimeSplicer = 112, - COMMAND_KIND_Tornado = 174, - COMMAND_KIND_TornadoStrike = 121, - COMMAND_KIND_Transcendence = 176, - COMMAND_KIND_TreasureRaid = 103, - COMMAND_KIND_TrinityLimit = 223, - COMMAND_KIND_TripleBlizzaga = 141, - COMMAND_KIND_TripleFiraga = 136, - COMMAND_KIND_TurnOver = 326, - COMMAND_KIND_UltimaCannon = 299, - COMMAND_KIND_Vengeance = 99, - COMMAND_KIND_Voltage = 222, - COMMAND_KIND_WarpDrive = 296, - COMMAND_KIND_WhiteSilence = 316, - COMMAND_KIND_WingBlade = 31, - COMMAND_KIND_WishBlade = 114, - COMMAND_KIND_WishShot = 231, - COMMAND_KIND_WishTurn = 229, - COMMAND_KIND_Zantetsuken = 100, - COMMAND_KIND_ZeroGraviga = 155, - COMMAND_KIND_ZeroGravira = 154, - COMMAND_KIND_ZeroGravity = 153, - COMMAND_KIND_action5 = 307, - } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Bbs.SystemData +{ + public class Command + { + public enum Type : ushort + { + COMMAND_KIND_None = 0, + COMMAND_KIND_Attack = 1, + COMMAND_KIND_Blitz01 = 2, + COMMAND_KIND_Blitz02 = 3, + COMMAND_KIND_Blitz03 = 4, + COMMAND_KIND_Blitz04 = 5, + COMMAND_KIND_Blitz05 = 6, + COMMAND_KIND_Blitz06 = 7, + COMMAND_KIND_Barrage07 = 8, + COMMAND_KIND_Barrage08 = 9, + COMMAND_KIND_Barrage09 = 10, + COMMAND_KIND_Barrage10 = 11, + COMMAND_KIND_Barrage11 = 12, + COMMAND_KIND_Barrage12 = 13, + COMMAND_KIND_Barrage13 = 14, + COMMAND_KIND_Barrage14 = 15, + COMMAND_KIND_Combo15 = 16, + COMMAND_KIND_Finish = 17, + COMMAND_KIND_FatalMode = 18, + COMMAND_KIND_MagicWish = 19, + COMMAND_KIND_FireBlazer = 21, + COMMAND_KIND_DiamondDust = 22, + COMMAND_KIND_Cyclone = 24, + COMMAND_KIND_BladeCharge = 25, + COMMAND_KIND_GhostDrive = 28, + COMMAND_KIND_DarkImpulse = 30, + COMMAND_KIND_IceBlast = 32, + COMMAND_KIND_DLink1 = 33, + COMMAND_KIND_DLink2 = 34, + COMMAND_KIND_DLink3 = 35, + COMMAND_KIND_DLink4 = 36, + COMMAND_KIND_DLink5 = 37, + COMMAND_KIND_DLink6 = 38, + COMMAND_KIND_DLink7 = 39, + COMMAND_KIND_DLink8 = 40, + COMMAND_KIND_DLink9 = 41, + COMMAND_KIND_DLink10 = 42, + COMMAND_KIND_DLink11 = 43, + COMMAND_KIND_DLink12 = 44, + COMMAND_KIND_DLink13 = 45, + COMMAND_KIND_Combo17 = 46, + COMMAND_KIND_DLink17 = 47, + COMMAND_KIND_DLink1R = 48, + COMMAND_KIND_DLink2R = 49, + COMMAND_KIND_DLink3R = 50, + COMMAND_KIND_DLink4R = 51, + COMMAND_KIND_DLink5R = 52, + COMMAND_KIND_DLink6R = 53, + COMMAND_KIND_DLink7R = 54, + COMMAND_KIND_DLink8R = 55, + COMMAND_KIND_DLink9R = 56, + COMMAND_KIND_DLink10R = 57, + COMMAND_KIND_DLink11R = 58, + COMMAND_KIND_DLink12R = 59, + COMMAND_KIND_DLink13R = 60, + COMMAND_KIND_FinishV01 = 61, + COMMAND_KIND_FinishA02 = 62, + COMMAND_KIND_FinishT03 = 63, + COMMAND_KIND_FinishV11 = 64, + COMMAND_KIND_FinishA12 = 65, + COMMAND_KIND_FinishT13 = 66, + COMMAND_KIND_FinishC14 = 67, + COMMAND_KIND_FinishC15 = 68, + COMMAND_KIND_FinishV21 = 69, + COMMAND_KIND_FinishA22 = 70, + COMMAND_KIND_FinishT23 = 71, + COMMAND_KIND_FinishC24 = 72, + COMMAND_KIND_FinishC25 = 73, + COMMAND_KIND_FinishC26 = 74, + COMMAND_KIND_FinishC27 = 75, + COMMAND_KIND_FinishV31 = 76, + COMMAND_KIND_FinishA32 = 77, + COMMAND_KIND_FinishT33 = 78, + COMMAND_KIND_FinishC34 = 79, + COMMAND_KIND_FinishC35 = 80, + COMMAND_KIND_FinishC36 = 81, + COMMAND_KIND_FinishV41 = 82, + COMMAND_KIND_FinishA42 = 83, + COMMAND_KIND_FinishT43 = 84, + COMMAND_KIND_FinishC44 = 85, + COMMAND_KIND_FinishC45 = 86, + COMMAND_KIND_FinishC46 = 87, + COMMAND_KIND_FinishV51 = 88, + COMMAND_KIND_FinishA52 = 89, + COMMAND_KIND_FinishT53 = 90, + COMMAND_KIND_AerialBreak = 91, + COMMAND_KIND_FinalBreak = 92, + COMMAND_KIND_CosmicArts = 93, + COMMAND_KIND_Catastrophe = 94, + COMMAND_KIND_FireRush = 96, + COMMAND_KIND_DarkCatalyst = 97, + COMMAND_KIND_FreezeRaid = 102, + COMMAND_KIND_Judgement = 105, + COMMAND_KIND_FireBlitz = 106, + COMMAND_KIND_AerialSlam = 109, + COMMAND_KIND_LastArcanum = 111, + COMMAND_KIND_BlizzardBlade = 115, + COMMAND_KIND_FireStrike = 118, + COMMAND_KIND_ConfuseStrike = 119, + COMMAND_KIND_BindStrike = 120, + COMMAND_KIND_BrutalForce = 122, + COMMAND_KIND_MagneSpiral = 123, + COMMAND_KIND_Kamaitachi = 125, + COMMAND_KIND_Kishikaisei = 126, + COMMAND_KIND_MagneBreaker = 127, + COMMAND_KIND_GaiaImpact = 128, + COMMAND_KIND_BreakTime = 130, + COMMAND_KIND_Fire = 131, + COMMAND_KIND_Fira = 132, + COMMAND_KIND_Firaga = 133, + COMMAND_KIND_DarkFiraga = 134, + COMMAND_KIND_FiragaStorm = 135, + COMMAND_KIND_Blizzard = 138, + COMMAND_KIND_Blizzara = 139, + COMMAND_KIND_Blizzaga = 140, + COMMAND_KIND_Cure = 146, + COMMAND_KIND_Cura = 147, + COMMAND_KIND_Curaga = 148, + COMMAND_KIND_Esuna = 149, + COMMAND_KIND_DetoneShield = 150, + COMMAND_KIND_DetoneSquare = 151, + COMMAND_KIND_DetoneChaser = 152, + COMMAND_KIND_Magne = 156, + COMMAND_KIND_Magnera = 157, + COMMAND_KIND_Magnega = 158, + COMMAND_KIND_MunnyMagne = 159, + COMMAND_KIND_HpMagne = 160, + COMMAND_KIND_FocusMagne = 161, + COMMAND_KIND_Aero = 162, + COMMAND_KIND_Aera = 163, + COMMAND_KIND_Aeroga = 164, + COMMAND_KIND_Degenerate = 165, + COMMAND_KIND_Holy = 166, + COMMAND_KIND_Freeze = 167, + COMMAND_KIND_GlacialArts = 168, + COMMAND_KIND_IceBarrage = 169, + COMMAND_KIND_FiragaBurst = 170, + COMMAND_KIND_MegaFlare = 172, + COMMAND_KIND_Meteor = 175, + COMMAND_KIND_Minimum = 177, + COMMAND_KIND_BlackOut = 178, + COMMAND_KIND_FiragaSpark = 179, + COMMAND_KIND_Confuse = 180, + COMMAND_KIND_Bind = 181, + COMMAND_KIND_Poison = 182, + COMMAND_KIND_Stop = 184, + COMMAND_KIND_Stopga = 186, + COMMAND_KIND_Stopra = 185, + COMMAND_KIND_HiPotion = 189, + COMMAND_KIND_Ether = 191, + COMMAND_KIND_Elixir = 194, + COMMAND_KIND_LastElixir = 195, + COMMAND_KIND_BalloonLetter = 196, + COMMAND_KIND_Ice1 = 197, + COMMAND_KIND_Ice2 = 198, + COMMAND_KIND_Ice3 = 199, + COMMAND_KIND_Ice4 = 200, + COMMAND_KIND_Ice5 = 201, + COMMAND_KIND_Ice6 = 202, + COMMAND_KIND_Ice7 = 203, + COMMAND_KIND_Ice8 = 204, + COMMAND_KIND_Ice9 = 205, + COMMAND_KIND_Ice10 = 206, + COMMAND_KIND_Ice11 = 207, + COMMAND_KIND_Ice12 = 208, + COMMAND_KIND_Ice13 = 209, + COMMAND_KIND_Ice14 = 210, + COMMAND_KIND_FriendCure = 211, + COMMAND_KIND_FriendCura = 212, + COMMAND_KIND_FriendCuraga = 213, + COMMAND_KIND_FriendEsuna = 214, + COMMAND_KIND_Confetti = 215, + COMMAND_KIND_Cracker = 216, + COMMAND_KIND_GutsPose = 218, + COMMAND_KIND_DeckScramble = 219, + COMMAND_KIND_Banish = 220, + COMMAND_KIND_Gold = 224, + COMMAND_KIND_DeckFinish = 226, + COMMAND_KIND_DeckDarkVolley = 227, + COMMAND_KIND_HolyStorm = 228, + COMMAND_KIND_FairyStep = 230, + COMMAND_KIND_FairyCure = 232, + COMMAND_KIND_DwarfDoc = 233, + COMMAND_KIND_DwarfGrumpy = 234, + COMMAND_KIND_DwarfSneezy = 235, + COMMAND_KIND_DwarfHappy = 236, + COMMAND_KIND_DwarfSleepy = 237, + COMMAND_KIND_DwarfBashful = 238, + COMMAND_KIND_DwarfDopey = 239, + COMMAND_KIND_DarkAxis = 240, + COMMAND_KIND_DarkSplicer = 241, + COMMAND_KIND_Illusion1 = 242, + COMMAND_KIND_Illusion2 = 243, + COMMAND_KIND_Illusion3 = 244, + COMMAND_KIND_Illusion4 = 245, + COMMAND_KIND_Illusion5 = 246, + COMMAND_KIND_DeckEnd = 247, + COMMAND_KIND_MOVE_START = 248, + COMMAND_KIND_Jump = 249, + COMMAND_KIND_HiJump = 250, + COMMAND_KIND_DodgeRoll = 251, + COMMAND_KIND_FireRoll = 254, + COMMAND_KIND_AirSlide = 255, + COMMAND_KIND_IceSlide = 256, + COMMAND_KIND_Glide = 258, + COMMAND_KIND_FireGlide = 260, + COMMAND_KIND_HomingSlide = 261, + COMMAND_KIND_Guard = 265, + COMMAND_KIND_HealGuard = 266, + COMMAND_KIND_FocusGuard = 267, + COMMAND_KIND_HealReflect = 271, + COMMAND_KIND_FocusReflect = 272, + COMMAND_KIND_ConfuseReflect = 273, + COMMAND_KIND_GuardSlash = 275, + COMMAND_KIND_GuardImpact = 276, + COMMAND_KIND_BackBreaker = 277, + COMMAND_KIND_CounterRaid = 279, + COMMAND_KIND_CounterBlitz = 280, + COMMAND_KIND_CounterCharge = 281, + COMMAND_KIND_AirRecovery = 282, + COMMAND_KIND_MOVE_END = 283, + COMMAND_KIND_FlameSpark = 285, + COMMAND_KIND_ChaosGunner = 286, + COMMAND_KIND_BubbleBlaster = 287, + COMMAND_KIND_DarkVolley = 288, + COMMAND_KIND_BioBarrage = 291, + COMMAND_KIND_IceSlider = 295, + COMMAND_KIND_DarkCannon = 298, + COMMAND_KIND_BladeBallista = 301, + COMMAND_KIND_Check = 305, + COMMAND_KIND_Cover = 308, + COMMAND_KIND_Goto = 309, + COMMAND_KIND_Goal = 310, + COMMAND_KIND_Call = 311, + COMMAND_KIND_LastDance = 312, + COMMAND_KIND_BraveRevenge = 314, + COMMAND_KIND_BraveSlash = 315, + COMMAND_KIND_BoulderBreaker = 317, + COMMAND_KIND_HolyFlood = 321, + COMMAND_KIND_DualLimit = 322, + COMMAND_KIND_HangOn = 323, + COMMAND_KIND_FairyMagic = 325, + COMMAND_KIND_action25 = 327, + COMMAND_KIND_action26 = 328, + COMMAND_KIND_HealLight = 329, + COMMAND_KIND_DebugJump = 336, + COMMAND_KIND_StyleNormal = 337, + COMMAND_KIND_StyleFatalMode = 338, + COMMAND_KIND_StyleMagicWish = 339, + COMMAND_KIND_StyleSpeedRave = 340, + COMMAND_KIND_StyleFireBlazer = 341, + COMMAND_KIND_StyleDiamondDust = 342, + COMMAND_KIND_StyleThunderBolt = 343, + COMMAND_KIND_StyleCyclone = 344, + COMMAND_KIND_StyleBladeCharge = 345, + COMMAND_KIND_StyleSkyRider = 346, + COMMAND_KIND_StyleRockBreaker = 347, + COMMAND_KIND_StyleGhostDrive = 348, + COMMAND_KIND_StyleRhythmMixer = 349, + COMMAND_KIND_StyleDarkImpulse = 350, + COMMAND_KIND_StyleWingBlade = 351, + COMMAND_KIND_StyleIceBlast = 352, + COMMAND_KIND_StyleEnd = 353, + COMMAND_KIND_LINK_START = 354, + COMMAND_KIND_LinkDonald = 356, + COMMAND_KIND_LinkKing = 355, + COMMAND_KIND_LinkGoofy = 357, + COMMAND_KIND_LinkStitch = 358, + COMMAND_KIND_LinkPan = 359, + COMMAND_KIND_LinkMaleficent = 360, + COMMAND_KIND_LinkAqua = 365, + COMMAND_KIND_LinkCinderella = 361, + COMMAND_KIND_LinkSnowWhite = 362, + COMMAND_KIND_LinkZack = 363, + COMMAND_KIND_LinkPete = 364, + COMMAND_KIND_LinkVentus = 366, + COMMAND_KIND_LinkTerra = 367, + COMMAND_KIND_LinkArmoredAqua = 368, + COMMAND_KIND_LinkArmoredVentus = 369, + COMMAND_KIND_LinkArmoredTerra = 370, + COMMAND_KIND_LinkVanitas = 371, + COMMAND_KIND_LinkKingR = 372, + COMMAND_KIND_LinkDonaldR = 373, + COMMAND_KIND_LinkGoofyR = 374, + COMMAND_KIND_LinkStitchR = 375, + COMMAND_KIND_LinkPanR = 376, + COMMAND_KIND_LinkMaleficentR = 377, + COMMAND_KIND_LinkCinderellaR = 378, + COMMAND_KIND_LinkSnowWhiteR = 379, + COMMAND_KIND_LinkZackR = 380, + COMMAND_KIND_LinkPeteR = 381, + COMMAND_KIND_LinkAquaR = 382, + COMMAND_KIND_LinkVentusR = 383, + COMMAND_KIND_LinkTerraR = 384, + COMMAND_KIND_LinkPC1 = 385, + COMMAND_KIND_LinkPC2 = 386, + COMMAND_KIND_LinkPC3 = 387, + COMMAND_KIND_LinkPC4 = 388, + COMMAND_KIND_LinkPC5 = 389, + COMMAND_KIND_LinkPC6 = 390, + COMMAND_KIND_LinkPC7 = 391, + COMMAND_KIND_LinkPC8 = 392, + COMMAND_KIND_LinkEnd = 393, + COMMAND_KIND_IllusionNull = 394, + COMMAND_KIND_IllusionTypeM = 395, + COMMAND_KIND_IllusionTypeS = 396, + COMMAND_KIND_IllusionTypeB = 397, + COMMAND_KIND_IllusionTypeP = 398, + COMMAND_KIND_IllusionTypeI = 399, + COMMAND_KIND_IllusionEnd = 400, + COMMAND_KIND_IllusionAttack1 = 401, + COMMAND_KIND_IllusionAttack2 = 402, + COMMAND_KIND_IllusionAttack3 = 403, + COMMAND_KIND_IllusionAttack4 = 404, + COMMAND_KIND_IllusionAttack5 = 405, + COMMAND_KIND_IllusionFinish1 = 406, + COMMAND_KIND_IllusionFinish2 = 407, + COMMAND_KIND_IllusionFinish3 = 408, + COMMAND_KIND_IllusionFinish4 = 409, + COMMAND_KIND_IllusionFinish5 = 410, + COMMAND_KIND_IllusionDeck1 = 411, + COMMAND_KIND_IllusionDeck2 = 412, + COMMAND_KIND_IllusionDeck3 = 413, + COMMAND_KIND_IllusionDeck4 = 414, + COMMAND_KIND_IllusionDeck5 = 415, + COMMAND_KIND_IllusionAction1 = 416, + COMMAND_KIND_IllusionAction2 = 417, + COMMAND_KIND_IllusionAction3 = 418, + COMMAND_KIND_IllusionAction4 = 419, + COMMAND_KIND_IllusionAction5 = 420, + COMMAND_KIND_ENCHANT_START = 421, + COMMAND_KIND_ENCHANT_END = 450, + COMMAND_KIND_End = 498, + + + + + + COMMAND_KIND_Midareuchi = 110, + + COMMAND_KIND_MegePotion = 190, + COMMAND_KIND_MegaEther = 192, + + + + COMMAND_KIND_NetAccess = 330, + COMMAND_KIND_NetCancel = 333, + COMMAND_KIND_NetExchange = 334, + COMMAND_KIND_NetReady = 332, + COMMAND_KIND_NetStart = 335, + COMMAND_KIND_NetWarp = 331, + COMMAND_KIND_Open = 304, + COMMAND_KIND_PRIZE_END = 497, + COMMAND_KIND_PRIZE_START = 482, + COMMAND_KIND_PhotonCharge = 294, + + COMMAND_KIND_PoisonBlade = 113, + COMMAND_KIND_PoisonGuard = 269, + COMMAND_KIND_Potion = 188, + COMMAND_KIND_Provoke = 217, + COMMAND_KIND_PsychicsPulse = 293, + COMMAND_KIND_PunishKitty = 324, + COMMAND_KIND_Quake = 173, + COMMAND_KIND_QuickRoll = 253, + COMMAND_KIND_RagingCharge = 221, + COMMAND_KIND_RagingStorm = 171, + COMMAND_KIND_Ragnarock = 289, + COMMAND_KIND_RainbowShower = 292, + COMMAND_KIND_Reflect = 270, + COMMAND_KIND_ReflectBlitz = 107, + COMMAND_KIND_ReflectPulse = 278, + COMMAND_KIND_ReflectRaid = 104, + COMMAND_KIND_Remedy = 193, + COMMAND_KIND_RhythmMixer = 29, + COMMAND_KIND_RockBreaker = 27, + COMMAND_KIND_Rush = 95, + COMMAND_KIND_SHOOT_END = 302, + COMMAND_KIND_SHOOT_REG = 18, + COMMAND_KIND_SHOOT_START = 283, + COMMAND_KIND_STYLE_END = 353, + COMMAND_KIND_STYLE_START = 337, + COMMAND_KIND_Salvation = 124, + COMMAND_KIND_Save = 302, + COMMAND_KIND_ShadowRunner = 297, + COMMAND_KIND_ShinyBloom = 300, + COMMAND_KIND_ShockGuard = 268, + COMMAND_KIND_ShootLock = 283, + COMMAND_KIND_Shop = 306, + COMMAND_KIND_SkyRider = 26, + COMMAND_KIND_SkyVault = 264, + COMMAND_KIND_Sleple = 187, + COMMAND_KIND_Slide = 248, + COMMAND_KIND_SlideTurn = 257, + COMMAND_KIND_SlotBlade = 117, + COMMAND_KIND_Slow = 183, + COMMAND_KIND_SlowFiraga = 137, + COMMAND_KIND_SonicImpact = 263, + COMMAND_KIND_SonicRave = 98, + COMMAND_KIND_SpeedRave = 20, + COMMAND_KIND_StarBurst = 284, + COMMAND_KIND_StitchShoot = 319, + COMMAND_KIND_StitchStrike = 320, + + COMMAND_KIND_StopReflect = 274, + COMMAND_KIND_StormShock = 290, + COMMAND_KIND_StrikeRaid = 101, + COMMAND_KIND_StunBlade = 116, + + + COMMAND_KIND_SuperGlide = 259, + COMMAND_KIND_Sutemi = 129, + COMMAND_KIND_SwingSlash = 318, + COMMAND_KIND_Talk = 303, + COMMAND_KIND_Tereport = 262, + COMMAND_KIND_Thundaga = 144, + COMMAND_KIND_ThundagaShot = 145, + COMMAND_KIND_Thunder = 142, + COMMAND_KIND_ThunderBlitz = 108, + COMMAND_KIND_ThunderBolt = 23, + COMMAND_KIND_ThunderRoll = 252, + COMMAND_KIND_Thundra = 143, + COMMAND_KIND_TimeSplicer = 112, + COMMAND_KIND_Tornado = 174, + COMMAND_KIND_TornadoStrike = 121, + COMMAND_KIND_Transcendence = 176, + COMMAND_KIND_TreasureRaid = 103, + COMMAND_KIND_TrinityLimit = 223, + COMMAND_KIND_TripleBlizzaga = 141, + COMMAND_KIND_TripleFiraga = 136, + COMMAND_KIND_TurnOver = 326, + COMMAND_KIND_UltimaCannon = 299, + COMMAND_KIND_Vengeance = 99, + COMMAND_KIND_Voltage = 222, + COMMAND_KIND_WarpDrive = 296, + COMMAND_KIND_WhiteSilence = 316, + COMMAND_KIND_WingBlade = 31, + COMMAND_KIND_WishBlade = 114, + COMMAND_KIND_WishShot = 231, + COMMAND_KIND_WishTurn = 229, + COMMAND_KIND_Zantetsuken = 100, + COMMAND_KIND_ZeroGraviga = 155, + COMMAND_KIND_ZeroGravira = 154, + COMMAND_KIND_ZeroGravity = 153, + COMMAND_KIND_action5 = 307, + } + } +} diff --git a/OpenKh.Bbs/SystemData/Item.cs b/OpenKh.Bbs/SystemData/Item.cs index 985aed5ea..47ee2cec7 100644 --- a/OpenKh.Bbs/SystemData/Item.cs +++ b/OpenKh.Bbs/SystemData/Item.cs @@ -1,280 +1,280 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Bbs.SystemData -{ - public class Item - { - public enum Type : ushort - { - DUMMY = 0, - Ventus_WaywardWind = 1, - Ventus_TreasureTrove = 2, - Ventus_StrokeOfMidnight = 3, - Ventus_FairyStars = 4, - Ventus_VictoryLine = 5, - Ventus_MarkOfAHero = 6, - Ventus_Hyperdrive = 7, - Ventus_PixiePetal = 8, - Ventus_UltimaWeapon = 9, - Ventus_Sweetstrack = 10, - Ventus_LightSeeker = 11, - WEP_KEY_BLADE_VE_12 = 12, - Ventus_FrolicFlame = 13, - Ventus_LostMemory = 14, - WEP_KEY_BLADE_VE_15 = 15, - Ventus_VoidGear = 16, - Ventus_NoName = 17, - Ventus_CrownUnlimit = 18, - Terra_EarthShaker = 256, - Terra_TreasureTrove = 257, - Terra_StrokeOfMidnight = 258, - Terra_FairyStars = 259, - Terra_VictoryLine = 260, - Terra_MarkOfAHero = 261, - Terra_Hyperdrive = 262, - Terra_PixiePetal = 263, - Terra_UltimaWeapon = 264, - Terra_Sweetstack = 265, - Terra_Darkgnaw = 266, - Terra_EndsOfEarth = 267, - Terra_ChaosRipper = 268, - Terra_VoidGear = 272, - Terra_NoName = 273, - Terra_CrownUnlimit = 274, - WEP_KEY_BLADE_TE_17 = 275, - WEP_KEY_BLADE_TE_18 = 276, - Aqua_Rainfell = 512, - Aqua_TreasureTrove = 513, - Aqua_StrokeOfMidnight = 514, - Aqua_FairyStars = 515, - Aqua_VictoryLine = 516, - Aqua_MarkOfAHero = 517, - Aqua_Hyperdrive = 518, - Aqua_PixiePetal = 519, - Aqua_UltimaWeapon = 520, - Aqua_Sweetstack = 521, - Aqua_DestinysEmbrace = 522, - Aqua_Stormfall = 523, - Aqua_Brightcrest = 524, - WEP_KEY_BLADE_AQ_14 = 528, - WEP_KEY_BLADE_AQ_15 = 529, - WEP_KEY_BLADE_AQ_16 = 530, - Aqua_NoName = 531, - Aqua_CrownUnlimit = 532, - Aqua_MasterKeeper = 533, - Minimap_DwarfWoodlands = 7680, - Minimap_EnchantedDominion = 7681, - Minimap_RadiantGarden = 7682, - Minimap_DisneyTown = 7683, - Minimap_DeepSpace = 7684, - Minimap_OlympusColiseum = 7685, - Minimap_Neverland = 7686, - Minimap_KeybladeGraveyard = 7687, - Minimap_LandOfDeparture = 7688, - Minimap_CastleOfDreams = 7689, - XehanortLetter = 7690, - XehanortReport12 = 7691, - XehanortReport01 = 7692, - XehanortReport02 = 7693, - XehanortReport03 = 7694, - XehanortReport04 = 7695, - XehanortReport05 = 7696, - XehanortReport06 = 7697, - XehanortReport07 = 7698, - XehanortReport08 = 7699, - XehanortReport09 = 7700, - XehanortReport10 = 7701, - XehanortReport11 = 7702, - HID_COLLECTION_VE_0 = 7703, - Ventus_MickeySticker = 7704, - Ventus_MinnieSticker = 7705, - Ventus_HueySticker = 7706, - Ventus_DeweySticker = 7707, - Ventus_LouieSticker = 7708, - Ventus_RainbowSticker = 7709, - Ventus_ChipSticker = 7710, - Ventus_DaleSticker = 7711, - Ventus_FireworksSticker1 = 7712, - Ventus_FireworksSticker2 = 7713, - Ventus_IceCreamSticker1 = 7714, - Ventus_IceCreamSticker2 = 7715, - Ventus_IceCreamSticker3 = 7716, - Ventus_IceCreamSticker4 = 7717, - Ventus_IceCreamSticker5 = 7718, - Ventus_IceCreamSticker6 = 7719, - Ventus_BalloonSticker = 7720, - Ventus_UFOSticker = 7721, - Ventus_ConfettiSticker1 = 7722, - Ventus_ConfettiSticker2 = 7723, - HID_COLLECTION_VE_21 = 7724, - HID_COLLECTION_VE_22 = 7725, - HID_COLLECTION_VE_23 = 7726, - HID_COLLECTION_VE_24 = 7727, - HID_COLLECTION_VE_25 = 7728, - HID_COLLECTION_VE_26 = 7729, - HID_COLLECTION_VE_27 = 7730, - HID_COLLECTION_VE_28 = 7731, - HID_COLLECTION_VE_29 = 7732, - HID_COLLECTION_TE_0 = 7733, - Terra_PeteSticker = 7734, - Terra_HueySticker = 7735, - Terra_DeweySticker = 7736, - Terra_DeweySticker2 = 7737, - Terra_RainbowSticker = 7738, - Terra_AirplaneSticker = 7739, - Terra_ChipSticker = 7740, - Terra_DaleSticker = 7741, - Terra_FlyingBalloonSticker1 = 7742, - Terra_FlyingBalloonSticker2 = 7743, - Terra_FlyingBalloonSticker3 = 7744, - Terra_FlyingBalloonSticker4 = 7745, - Terra_BalloonSticker1 = 7746, - Terra_BalloonSticker2 = 7747, - Terra_TrafficConeSticker1 = 7748, - Terra_TrafficConeSticker2 = 7749, - Terra_TrafficConeSticker3 = 7750, - Terra_BalloonSticker3 = 7751, - Terra_BalloonSticker4 = 7752, - Terra_UFOSticker = 7753, - HID_COLLECTION_TE_21 = 7754, - HID_COLLECTION_TE_22 = 7755, - HID_COLLECTION_TE_23 = 7756, - HID_COLLECTION_TE_24 = 7757, - HID_COLLECTION_TE_25 = 7758, - HID_COLLECTION_TE_26 = 7759, - HID_COLLECTION_TE_27 = 7760, - HID_COLLECTION_TE_28 = 7761, - HID_COLLECTION_TE_29 = 7762, - HID_COLLECTION_AQ_0 = 7763, - HID_COLLECTION_AQ_1 = 7764, - HID_COLLECTION_AQ_2 = 7765, - HID_COLLECTION_AQ_3 = 7766, - HID_COLLECTION_AQ_4 = 7767, - HID_COLLECTION_AQ_5 = 7768, - HID_COLLECTION_AQ_6 = 7769, - HID_COLLECTION_AQ_7 = 7770, - HID_COLLECTION_AQ_8 = 7771, - HID_COLLECTION_AQ_9 = 7772, - HID_COLLECTION_AQ_10 = 7773, - HID_COLLECTION_AQ_11 = 7774, - HID_COLLECTION_AQ_12 = 7775, - HID_COLLECTION_AQ_13 = 7776, - HID_COLLECTION_AQ_14 = 7777, - HID_COLLECTION_AQ_15 = 7778, - HID_COLLECTION_AQ_16 = 7779, - HID_COLLECTION_AQ_17 = 7780, - HID_COLLECTION_AQ_18 = 7781, - HID_COLLECTION_AQ_19 = 7782, - Aqua_BubbleSticker = 7783, - HID_COLLECTION_AQ_21 = 7784, - HID_COLLECTION_AQ_22 = 7785, - HID_COLLECTION_AQ_23 = 7786, - HID_COLLECTION_AQ_24 = 7787, - HID_COLLECTION_AQ_25 = 7788, - HID_COLLECTION_AQ_26 = 7789, - HID_COLLECTION_AQ_27 = 7790, - HID_COLLECTION_AQ_28 = 7791, - HID_COLLECTION_AQ_29 = 7792, - Minimmap_RealmOfDarkness = 7793, - KEY_RIBBON = 7936, - KEY_WHITE_BUTTON = 7937, - KEY_PINK_CLOTH = 7938, - KEY_WHITE_LACE = 7939, - KEY_PINK_THREAD = 7940, - KEY_BTL_TICKET_A = 7942, - KEY_BTL_TICKET_B = 7943, - KEY_BTL_TICKET_C = 7944, - KEY_BTL_TICKET_D = 7945, - KEY_BTL_TICKET_E = 7946, - KEY_BTL_TICKET_F = 7947, - KEY_BTL_TICKET_G = 7948, - KEY_BTL_TICKET_H = 7949, - KEY_BTL_TICKET_I = 7950, - KEY_BTL_TICKET_J = 7951, - KEY_BlockRecipe = 7952, - KEY_ActionRecipe = 7953, - KEY_MagicRecipe = 7954, - KEY_MegaMagicRecipe = 7955, - KEY_GigaMagicRecipe = 7956, - KEY_AttackRecipe = 7957, - KEY_MegaAttackRecipe = 7958, - KEY_GigaAttackRecipe = 7959, - KEY_StarShard = 7962, - KEY_DisneyTownPass = 7963, - KEY_WayfinderVentus = 7964, - KEY_WayfinderStitch = 7965, - KEY_WayfinderAqua = 7967, - KEY_WayfinderTerra = 7968, - SYNTH_ShimmeringCrystal = 12800, - SYNTH_ShimmeringOre = 12801, - SYNTH_FleetingCrystal = 12802, - SYNTH_FleetingOre = 12803, - SYNTH_PulsingCrystal = 12804, - SYNTH_PulsingOre = 12805, - SYNTH_WellspringCrystal = 12806, - SYNTH_WellspringOre = 12807, - SYNTH_SoothingCrystal = 12808, - SYNTH_SoothingOre = 12809, - SYNTH_HungryCrystal = 12810, - SYNTH_HungryOre = 12811, - SYNTH_AboundingCrystal = 12812, - SYNTH_AboundingOre = 12813, - SYNTH_ChaosCrystal = 12814, - SYNTH_SecretGem = 12815, - FLA_DANCE_LEMON = 17920, - FLA_BALLOON_MELON = 17921, - FLA_FANTASY_PEACH = 17922, - FLA_HERO_ORANGE = 17923, - FLA_BOTTLED_STRAWBERRY = 17925, - FLA_DREAMY_APPLE = 17926, - FLA_MELODY_GRAPE = 17927, - FLA_OPEN_SESAME = 17928, - FLA_JEWELRY_BEAN = 17929, - FLA_WILDE_NUTS = 17930, - FLA_LARGE_DROP_ALMOND = 17931, - FLA_MYSTERY_BEAN = 17932, - FLA_SECRET_RASPBERRY = 17933, - FLA_CRYSTAL_SUGAR = 17934, - FLA_MERMAID_SALT = 17935, - FLA_STEEPLE_PEPPER = 17936, - FLA_TOON_CURRY = 17937, - FLA_HAMMING_MINT = 17938, - FLA_TREASURE_HONEY = 17939, - FLA_ROZE_HANEY = 17940, - FLA_GOLD_JAM = 17941, - FLA_SHOOTING_STAR_SIRUP = 17942, - FLA_RAINBOW_SIRUP = 17943, - FLA_OPEN_AIR_JELLY = 17944, - FLA_SOFTLY_CREAM = 17946, - FLA_MYSTERY_CREAM = 17947, - FLA_SOYMILK = 17948, - FLA_ROMAN_MILK = 17949, - FLA_MOOGLE_COFFEE = 17950, - FLA_CRYSTAL_SODA = 17951, - FLA_JET_SODA = 17952, - FLA_ROCKET_SODA_POP = 17953, - FLA_GALAXY_CARAMEL = 17955, - FLA_VALENTINE_CHOCOLATE = 17956, - FLA_LIGHTNING_CANDY = 17959, - FLA_FLEECY_CLOUDS_CANDY = 17960, - FLA_FLOWER_GUMMY = 17961, - FLA_BIRTHDAY_CAKE = 17962, - FLA_WEDDING_CAKE = 17963, - FLA_FOREST_CASTELLA = 17964, - FLA_MARSHMALLOW = 17965, - FLA_STARRYSKY_DROP = 17966, - } - - public enum Kind : sbyte - { - ITEM_UNKNOWN = -1, - ITEM_WEAPON = 0, - ITEM_FLAVOR = 1, - ITEM_HID = 2, - ITEM_KEY = 3, - ITEM_ALCHEMY = 4 - } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Bbs.SystemData +{ + public class Item + { + public enum Type : ushort + { + DUMMY = 0, + Ventus_WaywardWind = 1, + Ventus_TreasureTrove = 2, + Ventus_StrokeOfMidnight = 3, + Ventus_FairyStars = 4, + Ventus_VictoryLine = 5, + Ventus_MarkOfAHero = 6, + Ventus_Hyperdrive = 7, + Ventus_PixiePetal = 8, + Ventus_UltimaWeapon = 9, + Ventus_Sweetstrack = 10, + Ventus_LightSeeker = 11, + WEP_KEY_BLADE_VE_12 = 12, + Ventus_FrolicFlame = 13, + Ventus_LostMemory = 14, + WEP_KEY_BLADE_VE_15 = 15, + Ventus_VoidGear = 16, + Ventus_NoName = 17, + Ventus_CrownUnlimit = 18, + Terra_EarthShaker = 256, + Terra_TreasureTrove = 257, + Terra_StrokeOfMidnight = 258, + Terra_FairyStars = 259, + Terra_VictoryLine = 260, + Terra_MarkOfAHero = 261, + Terra_Hyperdrive = 262, + Terra_PixiePetal = 263, + Terra_UltimaWeapon = 264, + Terra_Sweetstack = 265, + Terra_Darkgnaw = 266, + Terra_EndsOfEarth = 267, + Terra_ChaosRipper = 268, + Terra_VoidGear = 272, + Terra_NoName = 273, + Terra_CrownUnlimit = 274, + WEP_KEY_BLADE_TE_17 = 275, + WEP_KEY_BLADE_TE_18 = 276, + Aqua_Rainfell = 512, + Aqua_TreasureTrove = 513, + Aqua_StrokeOfMidnight = 514, + Aqua_FairyStars = 515, + Aqua_VictoryLine = 516, + Aqua_MarkOfAHero = 517, + Aqua_Hyperdrive = 518, + Aqua_PixiePetal = 519, + Aqua_UltimaWeapon = 520, + Aqua_Sweetstack = 521, + Aqua_DestinysEmbrace = 522, + Aqua_Stormfall = 523, + Aqua_Brightcrest = 524, + WEP_KEY_BLADE_AQ_14 = 528, + WEP_KEY_BLADE_AQ_15 = 529, + WEP_KEY_BLADE_AQ_16 = 530, + Aqua_NoName = 531, + Aqua_CrownUnlimit = 532, + Aqua_MasterKeeper = 533, + Minimap_DwarfWoodlands = 7680, + Minimap_EnchantedDominion = 7681, + Minimap_RadiantGarden = 7682, + Minimap_DisneyTown = 7683, + Minimap_DeepSpace = 7684, + Minimap_OlympusColiseum = 7685, + Minimap_Neverland = 7686, + Minimap_KeybladeGraveyard = 7687, + Minimap_LandOfDeparture = 7688, + Minimap_CastleOfDreams = 7689, + XehanortLetter = 7690, + XehanortReport12 = 7691, + XehanortReport01 = 7692, + XehanortReport02 = 7693, + XehanortReport03 = 7694, + XehanortReport04 = 7695, + XehanortReport05 = 7696, + XehanortReport06 = 7697, + XehanortReport07 = 7698, + XehanortReport08 = 7699, + XehanortReport09 = 7700, + XehanortReport10 = 7701, + XehanortReport11 = 7702, + HID_COLLECTION_VE_0 = 7703, + Ventus_MickeySticker = 7704, + Ventus_MinnieSticker = 7705, + Ventus_HueySticker = 7706, + Ventus_DeweySticker = 7707, + Ventus_LouieSticker = 7708, + Ventus_RainbowSticker = 7709, + Ventus_ChipSticker = 7710, + Ventus_DaleSticker = 7711, + Ventus_FireworksSticker1 = 7712, + Ventus_FireworksSticker2 = 7713, + Ventus_IceCreamSticker1 = 7714, + Ventus_IceCreamSticker2 = 7715, + Ventus_IceCreamSticker3 = 7716, + Ventus_IceCreamSticker4 = 7717, + Ventus_IceCreamSticker5 = 7718, + Ventus_IceCreamSticker6 = 7719, + Ventus_BalloonSticker = 7720, + Ventus_UFOSticker = 7721, + Ventus_ConfettiSticker1 = 7722, + Ventus_ConfettiSticker2 = 7723, + HID_COLLECTION_VE_21 = 7724, + HID_COLLECTION_VE_22 = 7725, + HID_COLLECTION_VE_23 = 7726, + HID_COLLECTION_VE_24 = 7727, + HID_COLLECTION_VE_25 = 7728, + HID_COLLECTION_VE_26 = 7729, + HID_COLLECTION_VE_27 = 7730, + HID_COLLECTION_VE_28 = 7731, + HID_COLLECTION_VE_29 = 7732, + HID_COLLECTION_TE_0 = 7733, + Terra_PeteSticker = 7734, + Terra_HueySticker = 7735, + Terra_DeweySticker = 7736, + Terra_DeweySticker2 = 7737, + Terra_RainbowSticker = 7738, + Terra_AirplaneSticker = 7739, + Terra_ChipSticker = 7740, + Terra_DaleSticker = 7741, + Terra_FlyingBalloonSticker1 = 7742, + Terra_FlyingBalloonSticker2 = 7743, + Terra_FlyingBalloonSticker3 = 7744, + Terra_FlyingBalloonSticker4 = 7745, + Terra_BalloonSticker1 = 7746, + Terra_BalloonSticker2 = 7747, + Terra_TrafficConeSticker1 = 7748, + Terra_TrafficConeSticker2 = 7749, + Terra_TrafficConeSticker3 = 7750, + Terra_BalloonSticker3 = 7751, + Terra_BalloonSticker4 = 7752, + Terra_UFOSticker = 7753, + HID_COLLECTION_TE_21 = 7754, + HID_COLLECTION_TE_22 = 7755, + HID_COLLECTION_TE_23 = 7756, + HID_COLLECTION_TE_24 = 7757, + HID_COLLECTION_TE_25 = 7758, + HID_COLLECTION_TE_26 = 7759, + HID_COLLECTION_TE_27 = 7760, + HID_COLLECTION_TE_28 = 7761, + HID_COLLECTION_TE_29 = 7762, + HID_COLLECTION_AQ_0 = 7763, + HID_COLLECTION_AQ_1 = 7764, + HID_COLLECTION_AQ_2 = 7765, + HID_COLLECTION_AQ_3 = 7766, + HID_COLLECTION_AQ_4 = 7767, + HID_COLLECTION_AQ_5 = 7768, + HID_COLLECTION_AQ_6 = 7769, + HID_COLLECTION_AQ_7 = 7770, + HID_COLLECTION_AQ_8 = 7771, + HID_COLLECTION_AQ_9 = 7772, + HID_COLLECTION_AQ_10 = 7773, + HID_COLLECTION_AQ_11 = 7774, + HID_COLLECTION_AQ_12 = 7775, + HID_COLLECTION_AQ_13 = 7776, + HID_COLLECTION_AQ_14 = 7777, + HID_COLLECTION_AQ_15 = 7778, + HID_COLLECTION_AQ_16 = 7779, + HID_COLLECTION_AQ_17 = 7780, + HID_COLLECTION_AQ_18 = 7781, + HID_COLLECTION_AQ_19 = 7782, + Aqua_BubbleSticker = 7783, + HID_COLLECTION_AQ_21 = 7784, + HID_COLLECTION_AQ_22 = 7785, + HID_COLLECTION_AQ_23 = 7786, + HID_COLLECTION_AQ_24 = 7787, + HID_COLLECTION_AQ_25 = 7788, + HID_COLLECTION_AQ_26 = 7789, + HID_COLLECTION_AQ_27 = 7790, + HID_COLLECTION_AQ_28 = 7791, + HID_COLLECTION_AQ_29 = 7792, + Minimmap_RealmOfDarkness = 7793, + KEY_RIBBON = 7936, + KEY_WHITE_BUTTON = 7937, + KEY_PINK_CLOTH = 7938, + KEY_WHITE_LACE = 7939, + KEY_PINK_THREAD = 7940, + KEY_BTL_TICKET_A = 7942, + KEY_BTL_TICKET_B = 7943, + KEY_BTL_TICKET_C = 7944, + KEY_BTL_TICKET_D = 7945, + KEY_BTL_TICKET_E = 7946, + KEY_BTL_TICKET_F = 7947, + KEY_BTL_TICKET_G = 7948, + KEY_BTL_TICKET_H = 7949, + KEY_BTL_TICKET_I = 7950, + KEY_BTL_TICKET_J = 7951, + KEY_BlockRecipe = 7952, + KEY_ActionRecipe = 7953, + KEY_MagicRecipe = 7954, + KEY_MegaMagicRecipe = 7955, + KEY_GigaMagicRecipe = 7956, + KEY_AttackRecipe = 7957, + KEY_MegaAttackRecipe = 7958, + KEY_GigaAttackRecipe = 7959, + KEY_StarShard = 7962, + KEY_DisneyTownPass = 7963, + KEY_WayfinderVentus = 7964, + KEY_WayfinderStitch = 7965, + KEY_WayfinderAqua = 7967, + KEY_WayfinderTerra = 7968, + SYNTH_ShimmeringCrystal = 12800, + SYNTH_ShimmeringOre = 12801, + SYNTH_FleetingCrystal = 12802, + SYNTH_FleetingOre = 12803, + SYNTH_PulsingCrystal = 12804, + SYNTH_PulsingOre = 12805, + SYNTH_WellspringCrystal = 12806, + SYNTH_WellspringOre = 12807, + SYNTH_SoothingCrystal = 12808, + SYNTH_SoothingOre = 12809, + SYNTH_HungryCrystal = 12810, + SYNTH_HungryOre = 12811, + SYNTH_AboundingCrystal = 12812, + SYNTH_AboundingOre = 12813, + SYNTH_ChaosCrystal = 12814, + SYNTH_SecretGem = 12815, + FLA_DANCE_LEMON = 17920, + FLA_BALLOON_MELON = 17921, + FLA_FANTASY_PEACH = 17922, + FLA_HERO_ORANGE = 17923, + FLA_BOTTLED_STRAWBERRY = 17925, + FLA_DREAMY_APPLE = 17926, + FLA_MELODY_GRAPE = 17927, + FLA_OPEN_SESAME = 17928, + FLA_JEWELRY_BEAN = 17929, + FLA_WILDE_NUTS = 17930, + FLA_LARGE_DROP_ALMOND = 17931, + FLA_MYSTERY_BEAN = 17932, + FLA_SECRET_RASPBERRY = 17933, + FLA_CRYSTAL_SUGAR = 17934, + FLA_MERMAID_SALT = 17935, + FLA_STEEPLE_PEPPER = 17936, + FLA_TOON_CURRY = 17937, + FLA_HAMMING_MINT = 17938, + FLA_TREASURE_HONEY = 17939, + FLA_ROZE_HANEY = 17940, + FLA_GOLD_JAM = 17941, + FLA_SHOOTING_STAR_SIRUP = 17942, + FLA_RAINBOW_SIRUP = 17943, + FLA_OPEN_AIR_JELLY = 17944, + FLA_SOFTLY_CREAM = 17946, + FLA_MYSTERY_CREAM = 17947, + FLA_SOYMILK = 17948, + FLA_ROMAN_MILK = 17949, + FLA_MOOGLE_COFFEE = 17950, + FLA_CRYSTAL_SODA = 17951, + FLA_JET_SODA = 17952, + FLA_ROCKET_SODA_POP = 17953, + FLA_GALAXY_CARAMEL = 17955, + FLA_VALENTINE_CHOCOLATE = 17956, + FLA_LIGHTNING_CANDY = 17959, + FLA_FLEECY_CLOUDS_CANDY = 17960, + FLA_FLOWER_GUMMY = 17961, + FLA_BIRTHDAY_CAKE = 17962, + FLA_WEDDING_CAKE = 17963, + FLA_FOREST_CASTELLA = 17964, + FLA_MARSHMALLOW = 17965, + FLA_STARRYSKY_DROP = 17966, + } + + public enum Kind : sbyte + { + ITEM_UNKNOWN = -1, + ITEM_WEAPON = 0, + ITEM_FLAVOR = 1, + ITEM_HID = 2, + ITEM_KEY = 3, + ITEM_ALCHEMY = 4 + } + } +} diff --git a/OpenKh.Command.Arc/Program.cs b/OpenKh.Command.Arc/Program.cs index 247234f06..e506f41b0 100644 --- a/OpenKh.Command.Arc/Program.cs +++ b/OpenKh.Command.Arc/Program.cs @@ -1,142 +1,142 @@ -using OpenKh.Common; -using McMaster.Extensions.CommandLineUtils; -using System; -using System.IO; -using System.Linq; -using System.Reflection; -using System.ComponentModel.DataAnnotations; - -namespace OpenKh.Command.Arc -{ - [Command("OpenKh.Command.Arc")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - class Program - { - static void Main(string[] args) - { - try - { - CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - } - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - [Required] - [Argument(0, "ARC file", "The ARC file to pack or unpack")] - public string FileName { get; } - - [Required] - [Argument(1, "ARC directory", "The ARC directory used as destination for unpakcing or source for packing")] - public string DirectoryName { get; } - - [Option(ShortName = "p", LongName = "pack", Description = "Pack ARC")] - public bool Pack { get; } - - private void OnExecute() - { - try - { - if (Pack) - Repack(FileName, DirectoryName); - else - Unpack(FileName, DirectoryName); - } - catch (Exception ex) - { - Console.WriteLine($"ERROR: {ex.Message}"); - } - } - - private static void Unpack(string inputFile, string outputDirectory) - { - if (!File.Exists(inputFile)) - throw new FileNotFoundException("The specified file name cannot be found", inputFile); - - var entries = File.OpenRead(inputFile).Using(stream => - { - if (!Bbs.Arc.IsValid(stream)) - throw new InvalidDataException("The specified ARC file is not valid"); - - return Bbs.Arc.Read(stream); - }); - - if (string.IsNullOrEmpty(outputDirectory)) - outputDirectory = Path.Combine(Path.GetDirectoryName(inputFile), Path.GetFileNameWithoutExtension(inputFile)); - Directory.CreateDirectory(outputDirectory); - - foreach (var entry in entries.Where(x => !x.IsLink)) - { - Console.WriteLine(entry.Name); - - File.Create(Path.Combine(outputDirectory, entry.Name)).Using(stream => - { - stream.Write(entry.Data, 0, entry.Data.Length); - }); - } - - File.CreateText(Path.Combine(outputDirectory, "@ARC.txt")).Using(stream => - { - foreach (var entry in entries) - { - stream.WriteLine(entry.IsLink ? $"@{entry.Path}" : entry.Name); - } - }); - } - - private static void Repack(string outputFile, string inputDirectory) - { - if (!Directory.Exists(inputDirectory)) - throw new DirectoryNotFoundException("The specified input directory cannot be found"); - - var arcEntriesFileName = Path.Combine(inputDirectory, "@ARC.txt"); - if (!File.Exists(arcEntriesFileName)) - throw new FileNotFoundException("The @ARC.txt descriptor cannot be found in the specified directory", arcEntriesFileName); - - var entries = File.ReadAllLines(arcEntriesFileName) - .Select(x => GetEntry(inputDirectory, x)); - - File.Create(outputFile).Using(stream => Bbs.Arc.Write(entries, stream)); - - } - - private static Bbs.Arc.Entry GetEntry(string baseDirectory, string entryName) - { - if (entryName.FirstOrDefault() == '@') - { - var linkFileName = entryName.Substring(1); - var directoryName = Path.GetDirectoryName(linkFileName).Replace('\\', '/'); - var fileName = Path.GetFileName(linkFileName); - - var directoryPointer = Bbs.Bbsa.GetDirectoryHash(directoryName); - if (directoryPointer == uint.MaxValue) - throw new DirectoryNotFoundException($"The directory {directoryName} cannot be recognized by BBS engine."); - - return new Bbs.Arc.Entry - { - DirectoryPointer = directoryPointer, - Name = fileName - }; - } - else - { - var fileName = Path.Combine(baseDirectory, entryName); - return new Bbs.Arc.Entry - { - DirectoryPointer = 0, - Data = File.ReadAllBytes(fileName), - Name = entryName - }; - } - } - } -} +using OpenKh.Common; +using McMaster.Extensions.CommandLineUtils; +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using System.ComponentModel.DataAnnotations; + +namespace OpenKh.Command.Arc +{ + [Command("OpenKh.Command.Arc")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + class Program + { + static void Main(string[] args) + { + try + { + CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + } + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + [Required] + [Argument(0, "ARC file", "The ARC file to pack or unpack")] + public string FileName { get; } + + [Required] + [Argument(1, "ARC directory", "The ARC directory used as destination for unpakcing or source for packing")] + public string DirectoryName { get; } + + [Option(ShortName = "p", LongName = "pack", Description = "Pack ARC")] + public bool Pack { get; } + + private void OnExecute() + { + try + { + if (Pack) + Repack(FileName, DirectoryName); + else + Unpack(FileName, DirectoryName); + } + catch (Exception ex) + { + Console.WriteLine($"ERROR: {ex.Message}"); + } + } + + private static void Unpack(string inputFile, string outputDirectory) + { + if (!File.Exists(inputFile)) + throw new FileNotFoundException("The specified file name cannot be found", inputFile); + + var entries = File.OpenRead(inputFile).Using(stream => + { + if (!Bbs.Arc.IsValid(stream)) + throw new InvalidDataException("The specified ARC file is not valid"); + + return Bbs.Arc.Read(stream); + }); + + if (string.IsNullOrEmpty(outputDirectory)) + outputDirectory = Path.Combine(Path.GetDirectoryName(inputFile), Path.GetFileNameWithoutExtension(inputFile)); + Directory.CreateDirectory(outputDirectory); + + foreach (var entry in entries.Where(x => !x.IsLink)) + { + Console.WriteLine(entry.Name); + + File.Create(Path.Combine(outputDirectory, entry.Name)).Using(stream => + { + stream.Write(entry.Data, 0, entry.Data.Length); + }); + } + + File.CreateText(Path.Combine(outputDirectory, "@ARC.txt")).Using(stream => + { + foreach (var entry in entries) + { + stream.WriteLine(entry.IsLink ? $"@{entry.Path}" : entry.Name); + } + }); + } + + private static void Repack(string outputFile, string inputDirectory) + { + if (!Directory.Exists(inputDirectory)) + throw new DirectoryNotFoundException("The specified input directory cannot be found"); + + var arcEntriesFileName = Path.Combine(inputDirectory, "@ARC.txt"); + if (!File.Exists(arcEntriesFileName)) + throw new FileNotFoundException("The @ARC.txt descriptor cannot be found in the specified directory", arcEntriesFileName); + + var entries = File.ReadAllLines(arcEntriesFileName) + .Select(x => GetEntry(inputDirectory, x)); + + File.Create(outputFile).Using(stream => Bbs.Arc.Write(entries, stream)); + + } + + private static Bbs.Arc.Entry GetEntry(string baseDirectory, string entryName) + { + if (entryName.FirstOrDefault() == '@') + { + var linkFileName = entryName.Substring(1); + var directoryName = Path.GetDirectoryName(linkFileName).Replace('\\', '/'); + var fileName = Path.GetFileName(linkFileName); + + var directoryPointer = Bbs.Bbsa.GetDirectoryHash(directoryName); + if (directoryPointer == uint.MaxValue) + throw new DirectoryNotFoundException($"The directory {directoryName} cannot be recognized by BBS engine."); + + return new Bbs.Arc.Entry + { + DirectoryPointer = directoryPointer, + Name = fileName + }; + } + else + { + var fileName = Path.Combine(baseDirectory, entryName); + return new Bbs.Arc.Entry + { + DirectoryPointer = 0, + Data = File.ReadAllBytes(fileName), + Name = entryName + }; + } + } + } +} diff --git a/OpenKh.Command.Bar/Core.cs b/OpenKh.Command.Bar/Core.cs index 43478437c..a0ca16e3c 100644 --- a/OpenKh.Command.Bar/Core.cs +++ b/OpenKh.Command.Bar/Core.cs @@ -1,123 +1,123 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Command.Bar -{ - public static class Core - { - internal class BarRoot - { - [JsonProperty] public string OriginalFileName { get; set; } - [JsonProperty] public Kh2.Bar.MotionsetType Motionset { get; set; } - [JsonProperty] public List Entries { get; set; } - } - - internal class BarDesc - { - [JsonProperty] public string FileName { get; set; } - [JsonProperty] public string InternalName { get; set; } - [JsonProperty] public int TypeId { get; set; } - [JsonProperty] public int LinkIndex { get; set; } - [JsonIgnore] public Stream Stream { get; set; } - - public override string ToString() => FileName; - } - - private const string InvalidBarText = "The specified file is not a BAR file."; - internal static readonly Exception InvalidBarFileException = new InvalidDataException(InvalidBarText); - - public static Kh2.Bar ReadEntries(string fileName) - { - using var stream = File.OpenRead(fileName); - if (!Kh2.Bar.IsValid(stream)) - throw InvalidBarFileException; - - stream.Position = 0; - return Kh2.Bar.Read(stream); - } - - public static void ExportProject(string inputFileName, string outputFolder, bool suppress = false) - { - var binarc = ReadEntries(inputFileName); - var project = new BarRoot - { - OriginalFileName = Path.GetFileName(inputFileName), - Motionset = binarc.Motionset, - Entries = binarc - .Select(x => new BarDesc - { - FileName = $"{x.Name}.{Helpers.GetSuggestedExtension(x.Type)}", - InternalName = x.Name, - TypeId = (int)x.Type, - LinkIndex = x.Index, - Stream = x.Stream, - }) - .ToList() - }; - - foreach (var entryGroup in project.Entries - .Where(x => x.LinkIndex == 0) - .GroupBy(x => $"{x.InternalName}_{x.TypeId}")) - { - var items = entryGroup.ToArray(); - if (items.Length > 1) - { - for (var i = 0; i < items.Length; i++) - { - var ext = Helpers.GetSuggestedExtension((Kh2.Bar.EntryType)items[0].TypeId); - items[i].FileName = $"{items[0].InternalName}_{i}.{ext}"; - } - } - } - - if (!suppress) - { - var fileNameWithExt = Path.GetFileName(inputFileName); - var projectFileName = Path.Combine(outputFolder, $"{fileNameWithExt}.json"); - if (!Directory.Exists(outputFolder)) - Directory.CreateDirectory(outputFolder); - - File.WriteAllText(projectFileName, JsonConvert.SerializeObject(project, Formatting.Indented)); - } - - foreach (var entry in project.Entries.Where(x => x.LinkIndex == 0)) - { - var outputFileName = Path.Combine(outputFolder, entry.FileName); - - using var stream = File.Create(outputFileName); - entry.Stream.Position = 0; - entry.Stream.CopyTo(stream); - } - } - - public static Kh2.Bar ImportProject(string inputProjectName, out string originalFileName) - { - var baseDirectory = Path.GetDirectoryName(inputProjectName); - var project = JsonConvert.DeserializeObject(File.ReadAllText(inputProjectName)); - originalFileName = project.OriginalFileName; - - var streams = project.Entries - .Where(x => x.LinkIndex == 0) - .ToDictionary(x => x.FileName, - x => File.OpenRead(Path.Combine(baseDirectory, x.FileName))); - - var binarc = new Kh2.Bar - { - Motionset = project.Motionset - }; - binarc.AddRange(project.Entries - .Select(x => new Kh2.Bar.Entry - { - Name = x.InternalName, - Type = (Kh2.Bar.EntryType)x.TypeId, - Index = x.LinkIndex, - Stream = x.LinkIndex == 0 ? streams[x.FileName] : null - })); - - return binarc; - } - } -} +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Command.Bar +{ + public static class Core + { + internal class BarRoot + { + [JsonProperty] public string OriginalFileName { get; set; } + [JsonProperty] public Kh2.Bar.MotionsetType Motionset { get; set; } + [JsonProperty] public List Entries { get; set; } + } + + internal class BarDesc + { + [JsonProperty] public string FileName { get; set; } + [JsonProperty] public string InternalName { get; set; } + [JsonProperty] public int TypeId { get; set; } + [JsonProperty] public int LinkIndex { get; set; } + [JsonIgnore] public Stream Stream { get; set; } + + public override string ToString() => FileName; + } + + private const string InvalidBarText = "The specified file is not a BAR file."; + internal static readonly Exception InvalidBarFileException = new InvalidDataException(InvalidBarText); + + public static Kh2.Bar ReadEntries(string fileName) + { + using var stream = File.OpenRead(fileName); + if (!Kh2.Bar.IsValid(stream)) + throw InvalidBarFileException; + + stream.Position = 0; + return Kh2.Bar.Read(stream); + } + + public static void ExportProject(string inputFileName, string outputFolder, bool suppress = false) + { + var binarc = ReadEntries(inputFileName); + var project = new BarRoot + { + OriginalFileName = Path.GetFileName(inputFileName), + Motionset = binarc.Motionset, + Entries = binarc + .Select(x => new BarDesc + { + FileName = $"{x.Name}.{Helpers.GetSuggestedExtension(x.Type)}", + InternalName = x.Name, + TypeId = (int)x.Type, + LinkIndex = x.Index, + Stream = x.Stream, + }) + .ToList() + }; + + foreach (var entryGroup in project.Entries + .Where(x => x.LinkIndex == 0) + .GroupBy(x => $"{x.InternalName}_{x.TypeId}")) + { + var items = entryGroup.ToArray(); + if (items.Length > 1) + { + for (var i = 0; i < items.Length; i++) + { + var ext = Helpers.GetSuggestedExtension((Kh2.Bar.EntryType)items[0].TypeId); + items[i].FileName = $"{items[0].InternalName}_{i}.{ext}"; + } + } + } + + if (!suppress) + { + var fileNameWithExt = Path.GetFileName(inputFileName); + var projectFileName = Path.Combine(outputFolder, $"{fileNameWithExt}.json"); + if (!Directory.Exists(outputFolder)) + Directory.CreateDirectory(outputFolder); + + File.WriteAllText(projectFileName, JsonConvert.SerializeObject(project, Formatting.Indented)); + } + + foreach (var entry in project.Entries.Where(x => x.LinkIndex == 0)) + { + var outputFileName = Path.Combine(outputFolder, entry.FileName); + + using var stream = File.Create(outputFileName); + entry.Stream.Position = 0; + entry.Stream.CopyTo(stream); + } + } + + public static Kh2.Bar ImportProject(string inputProjectName, out string originalFileName) + { + var baseDirectory = Path.GetDirectoryName(inputProjectName); + var project = JsonConvert.DeserializeObject(File.ReadAllText(inputProjectName)); + originalFileName = project.OriginalFileName; + + var streams = project.Entries + .Where(x => x.LinkIndex == 0) + .ToDictionary(x => x.FileName, + x => File.OpenRead(Path.Combine(baseDirectory, x.FileName))); + + var binarc = new Kh2.Bar + { + Motionset = project.Motionset + }; + binarc.AddRange(project.Entries + .Select(x => new Kh2.Bar.Entry + { + Name = x.InternalName, + Type = (Kh2.Bar.EntryType)x.TypeId, + Index = x.LinkIndex, + Stream = x.LinkIndex == 0 ? streams[x.FileName] : null + })); + + return binarc; + } + } +} diff --git a/OpenKh.Command.Bar/Helpers.cs b/OpenKh.Command.Bar/Helpers.cs index 15422c595..5f21767cd 100644 --- a/OpenKh.Command.Bar/Helpers.cs +++ b/OpenKh.Command.Bar/Helpers.cs @@ -1,64 +1,64 @@ -using static OpenKh.Kh2.Bar; -using System.Collections.Generic; - -namespace OpenKh.Command.Bar -{ - public class Helpers - { - private static readonly string DefaultExtension = "bin"; - - private static readonly Dictionary SuggestedExtensions = - new Dictionary - { - [EntryType.Dummy] = "dummy", - [EntryType.Binary] = "bin", - [EntryType.List] = "list", - [EntryType.Bdx] = "bdx", - [EntryType.Model] = "model", - [EntryType.DrawOctalTree] = "ocd", - [EntryType.CollisionOctalTree] = "occ", - [EntryType.ModelTexture] = "texture", - [EntryType.Dpx] = "dpx", - [EntryType.Motion] = "motion", - [EntryType.Tim2] = "tm2", - [EntryType.CameraOctalTree] = "och", - [EntryType.AreaDataSpawn] = "spawn", - [EntryType.AreaDataScript] = "script", - [EntryType.FogColor] = "fog", - [EntryType.ColorOctalTree] = "ocl", - [EntryType.MotionTriggers] = "triggers", - [EntryType.Anb] = "anb", - [EntryType.Pax] = "pax", - [EntryType.MapCollision2] = "owa", - [EntryType.Motionset] = "mset", - [EntryType.BgObjPlacement] = "bop", - [EntryType.Event] = "event", - [EntryType.ModelCollision] = "collision", - [EntryType.Imgd] = "imd", - [EntryType.Seqd] = "sqd", - [EntryType.Layout] = "lad", - [EntryType.Imgz] = "imz", - [EntryType.AnimationMap] = "mapanim", - [EntryType.Seb] = "seb", - [EntryType.Wd] = "wd", - [EntryType.Unknown33] = "unk33", - [EntryType.IopVoice] = "iopvoice", - [EntryType.RawBitmap] = "rgb", - [EntryType.MemoryCard] = "memcard", - [EntryType.WrappedCollisionData] = "coctwrapped", - [EntryType.Unknown39] = "unk39", - [EntryType.Unknown40] = "unk40", - [EntryType.Unknown41] = "unk41", - [EntryType.Minigame] = "minigame", - [EntryType.JimiData] = "jimidata", - [EntryType.Progress] = "progress", - [EntryType.Synthesis] = "synthesis", - [EntryType.BarUnknown] = "bar", - [EntryType.Vibration] = "vibration", - [EntryType.Vag] = "vag", - }; - - public static string GetSuggestedExtension(EntryType type) => - SuggestedExtensions.TryGetValue(type, out var ext) ? ext : DefaultExtension; - } -} +using static OpenKh.Kh2.Bar; +using System.Collections.Generic; + +namespace OpenKh.Command.Bar +{ + public class Helpers + { + private static readonly string DefaultExtension = "bin"; + + private static readonly Dictionary SuggestedExtensions = + new Dictionary + { + [EntryType.Dummy] = "dummy", + [EntryType.Binary] = "bin", + [EntryType.List] = "list", + [EntryType.Bdx] = "bdx", + [EntryType.Model] = "model", + [EntryType.DrawOctalTree] = "ocd", + [EntryType.CollisionOctalTree] = "occ", + [EntryType.ModelTexture] = "texture", + [EntryType.Dpx] = "dpx", + [EntryType.Motion] = "motion", + [EntryType.Tim2] = "tm2", + [EntryType.CameraOctalTree] = "och", + [EntryType.AreaDataSpawn] = "spawn", + [EntryType.AreaDataScript] = "script", + [EntryType.FogColor] = "fog", + [EntryType.ColorOctalTree] = "ocl", + [EntryType.MotionTriggers] = "triggers", + [EntryType.Anb] = "anb", + [EntryType.Pax] = "pax", + [EntryType.MapCollision2] = "owa", + [EntryType.Motionset] = "mset", + [EntryType.BgObjPlacement] = "bop", + [EntryType.Event] = "event", + [EntryType.ModelCollision] = "collision", + [EntryType.Imgd] = "imd", + [EntryType.Seqd] = "sqd", + [EntryType.Layout] = "lad", + [EntryType.Imgz] = "imz", + [EntryType.AnimationMap] = "mapanim", + [EntryType.Seb] = "seb", + [EntryType.Wd] = "wd", + [EntryType.Unknown33] = "unk33", + [EntryType.IopVoice] = "iopvoice", + [EntryType.RawBitmap] = "rgb", + [EntryType.MemoryCard] = "memcard", + [EntryType.WrappedCollisionData] = "coctwrapped", + [EntryType.Unknown39] = "unk39", + [EntryType.Unknown40] = "unk40", + [EntryType.Unknown41] = "unk41", + [EntryType.Minigame] = "minigame", + [EntryType.JimiData] = "jimidata", + [EntryType.Progress] = "progress", + [EntryType.Synthesis] = "synthesis", + [EntryType.BarUnknown] = "bar", + [EntryType.Vibration] = "vibration", + [EntryType.Vag] = "vag", + }; + + public static string GetSuggestedExtension(EntryType type) => + SuggestedExtensions.TryGetValue(type, out var ext) ? ext : DefaultExtension; + } +} diff --git a/OpenKh.Command.Bar/Program.cs b/OpenKh.Command.Bar/Program.cs index 6d32338bb..9ace73f92 100644 --- a/OpenKh.Command.Bar/Program.cs +++ b/OpenKh.Command.Bar/Program.cs @@ -1,130 +1,130 @@ -using McMaster.Extensions.CommandLineUtils; -using Newtonsoft.Json; -using System; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Reflection; - -namespace OpenKh.Command.Bar -{ - [Command("OpenKh.Command.Bar")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - [Subcommand( - typeof(UnpackCommand), - typeof(PackCommand), - typeof(ListCommand))] - class Program - { - private const string InputProjectDesc = "BAR project file (eg. P_EX100.json)."; - private const string InputBarDesc = "Kingdom Hearts II BAR file."; - private const string OutputBarDesc = "Name of the BAR file that will be created."; - private const string OutputDirDesc = "Path where the content will be extracted."; - private const string SuppressProjectCreationDesc = "Do not generate a project when unpacking."; - - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - return 2; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return -1; - } - } - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - [Command(Description = "Unpack the content of a BAR file and generate a project")] - private class UnpackCommand - { - [Required] - [FileExists] - [Argument(0, Description = InputBarDesc)] - public string InputBar { get; set; } - - [Option(CommandOptionType.SingleValue, Description = OutputDirDesc, ShortName = "o", LongName = "output")] - public string OutputDir { get; set; } - - [Option(CommandOptionType.NoValue, Description = SuppressProjectCreationDesc, ShortName = "s", LongName = "skip")] - public bool SuppressProjectCreation { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - if (string.IsNullOrEmpty(OutputDir)) - { - var fileNameWithoutExt = Path.GetFileNameWithoutExtension(InputBar); - OutputDir = Path.Combine(Path.GetDirectoryName(InputBar), fileNameWithoutExt); - } - - Core.ExportProject(InputBar, OutputDir, SuppressProjectCreation); - - return 0; - } - } - - [Command(Description = "Repack a BAR from its project file")] - private class PackCommand - { - [Required] - [FileExists] - [Argument(0, Description = InputProjectDesc)] - public string InputProject { get; set; } - - [Option(CommandOptionType.SingleValue, Description = OutputBarDesc, ShortName = "o", LongName = "output")] - public string OutputFile { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var baseDirectory = Path.GetDirectoryName(InputProject); - var binarc = Core.ImportProject(InputProject, out var originalFileName); - - if (string.IsNullOrEmpty(OutputFile)) - OutputFile = Path.Combine(baseDirectory, originalFileName); - - if (!File.Exists(OutputFile) && Directory.Exists(OutputFile) && - File.GetAttributes(OutputFile).HasFlag(FileAttributes.Directory)) - OutputFile = Path.Combine(OutputFile, originalFileName); - - using var outputStream = File.Create(OutputFile); - Kh2.Bar.Write(outputStream, binarc); - - foreach (var entry in binarc) - entry.Stream?.Dispose(); - - return 0; - } - } - - [Command(Description = "Print content of a BAR file")] - private class ListCommand - { - [Required] - [FileExists] - [Argument(0, Description = InputBarDesc)] - public string InputBar { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - using var stream = File.OpenRead(InputBar); - foreach (var entry in Kh2.Bar.Read(stream)) - Console.WriteLine($"{entry.Name}, {entry.Type}, {entry.Index}"); - - return 0; - } - } - } -} +using McMaster.Extensions.CommandLineUtils; +using Newtonsoft.Json; +using System; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Reflection; + +namespace OpenKh.Command.Bar +{ + [Command("OpenKh.Command.Bar")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + [Subcommand( + typeof(UnpackCommand), + typeof(PackCommand), + typeof(ListCommand))] + class Program + { + private const string InputProjectDesc = "BAR project file (eg. P_EX100.json)."; + private const string InputBarDesc = "Kingdom Hearts II BAR file."; + private const string OutputBarDesc = "Name of the BAR file that will be created."; + private const string OutputDirDesc = "Path where the content will be extracted."; + private const string SuppressProjectCreationDesc = "Do not generate a project when unpacking."; + + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + return 2; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return -1; + } + } + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + [Command(Description = "Unpack the content of a BAR file and generate a project")] + private class UnpackCommand + { + [Required] + [FileExists] + [Argument(0, Description = InputBarDesc)] + public string InputBar { get; set; } + + [Option(CommandOptionType.SingleValue, Description = OutputDirDesc, ShortName = "o", LongName = "output")] + public string OutputDir { get; set; } + + [Option(CommandOptionType.NoValue, Description = SuppressProjectCreationDesc, ShortName = "s", LongName = "skip")] + public bool SuppressProjectCreation { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + if (string.IsNullOrEmpty(OutputDir)) + { + var fileNameWithoutExt = Path.GetFileNameWithoutExtension(InputBar); + OutputDir = Path.Combine(Path.GetDirectoryName(InputBar), fileNameWithoutExt); + } + + Core.ExportProject(InputBar, OutputDir, SuppressProjectCreation); + + return 0; + } + } + + [Command(Description = "Repack a BAR from its project file")] + private class PackCommand + { + [Required] + [FileExists] + [Argument(0, Description = InputProjectDesc)] + public string InputProject { get; set; } + + [Option(CommandOptionType.SingleValue, Description = OutputBarDesc, ShortName = "o", LongName = "output")] + public string OutputFile { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var baseDirectory = Path.GetDirectoryName(InputProject); + var binarc = Core.ImportProject(InputProject, out var originalFileName); + + if (string.IsNullOrEmpty(OutputFile)) + OutputFile = Path.Combine(baseDirectory, originalFileName); + + if (!File.Exists(OutputFile) && Directory.Exists(OutputFile) && + File.GetAttributes(OutputFile).HasFlag(FileAttributes.Directory)) + OutputFile = Path.Combine(OutputFile, originalFileName); + + using var outputStream = File.Create(OutputFile); + Kh2.Bar.Write(outputStream, binarc); + + foreach (var entry in binarc) + entry.Stream?.Dispose(); + + return 0; + } + } + + [Command(Description = "Print content of a BAR file")] + private class ListCommand + { + [Required] + [FileExists] + [Argument(0, Description = InputBarDesc)] + public string InputBar { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + using var stream = File.OpenRead(InputBar); + foreach (var entry in Kh2.Bar.Read(stream)) + Console.WriteLine($"{entry.Name}, {entry.Type}, {entry.Index}"); + + return 0; + } + } + } +} diff --git a/OpenKh.Command.Bbsa/ArchiveNotFoundException.cs b/OpenKh.Command.Bbsa/ArchiveNotFoundException.cs index be456a50b..67d21c261 100644 --- a/OpenKh.Command.Bbsa/ArchiveNotFoundException.cs +++ b/OpenKh.Command.Bbsa/ArchiveNotFoundException.cs @@ -1,11 +1,11 @@ -using System; - -namespace OpenKh.Command.Bbsa -{ - public class ArchiveNotFoundException : ArgumentException - { - public ArchiveNotFoundException(string path, int archiveIndex) : - base($"The path {path} does not contain BBS{archiveIndex}.DAT.") - { } - } -} +using System; + +namespace OpenKh.Command.Bbsa +{ + public class ArchiveNotFoundException : ArgumentException + { + public ArchiveNotFoundException(string path, int archiveIndex) : + base($"The path {path} does not contain BBS{archiveIndex}.DAT.") + { } + } +} diff --git a/OpenKh.Command.Bbsa/Program.cs b/OpenKh.Command.Bbsa/Program.cs index f58ae3ff2..c61074c4f 100644 --- a/OpenKh.Command.Bbsa/Program.cs +++ b/OpenKh.Command.Bbsa/Program.cs @@ -1,136 +1,136 @@ -using McMaster.Extensions.CommandLineUtils; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Linq; -using System.Reflection; - -namespace OpenKh.Command.Bbsa -{ - [Command("OpenKh.Command.Bbsa")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - [Subcommand(typeof(ExtractCommand), typeof(ListCommand))] - public class Program - { - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - return 2; - } - catch (ArchiveNotFoundException e) - { - Console.WriteLine(e.Message); - return 3; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return -1; - } - } - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - private class ExtractCommand - { - [Required] - [DirectoryExists] - [Argument(0, Description = "Required. Path where the various BBSAx.DAT files are located")] - public string InputPath { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Path where the content will be extracted", ShortName = "o", LongName = "output")] - public string OutputDir { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Archive file name prefix. By default it is 'BBS'.", ShortName = "p", LongName = "prefix")] - public string ArchivePrefix { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var prefix = ArchivePrefix ?? "BBS"; - - if (!DoesContainBbsa(InputPath, prefix)) - throw new ArchiveNotFoundException(InputPath, 0); - - var bbsaFileNames = Enumerable.Range(0, 5) - .Select(x => Path.Combine(InputPath, $"{prefix}{x}.DAT")); - - var outputDir = OutputDir ?? Path.Combine(Path.GetDirectoryName(InputPath), prefix); - - ExtractArchives(bbsaFileNames, outputDir); - return 0; - } - - private static void ExtractArchives(IEnumerable bbsaFileNames, string outputDir) - { - var streams = bbsaFileNames - .Select(x => File.OpenRead(x)) - .ToArray(); - - var bbsa = Bbs.Bbsa.Read(streams[0]); - foreach (var file in bbsa.Files) - { - var name = file.CalculateNameWithExtension(i => streams[i]); - var bbsaFileStream = file.OpenStream(i => streams[i]); - if (bbsaFileStream == null) - continue; - - var destinationFileName = Path.Combine(outputDir, name); - var destinationFolder = Path.GetDirectoryName(destinationFileName); - if (!Directory.Exists(destinationFolder)) - Directory.CreateDirectory(destinationFolder); - - Console.WriteLine(name); - - using (var outStream = File.Create(destinationFileName)) - bbsaFileStream.CopyTo(outStream); - } - } - } - - private class ListCommand - { - [Required] - [DirectoryExists] - [Argument(0, Description = "Required. Path where the various BBSAx.DAT files are located")] - public string InputPath { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Archive file name prefix. By default it is 'BBS'.", ShortName = "p", LongName = "prefix")] - public string ArchivePrefix { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var prefix = ArchivePrefix ?? "BBS"; - - if (!DoesContainBbsa(InputPath, prefix)) - throw new ArchiveNotFoundException(InputPath, 0); - - var bbsaFileName = Path.Combine(InputPath, $"{prefix}{0}.DAT"); - using var stream = File.OpenRead(bbsaFileName); - var bbsa = Bbs.Bbsa.Read(stream); - foreach (var file in bbsa.Files) - { - Console.WriteLine(file.Name); - } - - return 0; - } - } - - private static bool DoesContainBbsa(string path, string prefix) => - File.Exists(Path.Combine(path, $"{prefix}{0}.DAT")); - } -} +using McMaster.Extensions.CommandLineUtils; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace OpenKh.Command.Bbsa +{ + [Command("OpenKh.Command.Bbsa")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + [Subcommand(typeof(ExtractCommand), typeof(ListCommand))] + public class Program + { + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + return 2; + } + catch (ArchiveNotFoundException e) + { + Console.WriteLine(e.Message); + return 3; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return -1; + } + } + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + private class ExtractCommand + { + [Required] + [DirectoryExists] + [Argument(0, Description = "Required. Path where the various BBSAx.DAT files are located")] + public string InputPath { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Path where the content will be extracted", ShortName = "o", LongName = "output")] + public string OutputDir { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Archive file name prefix. By default it is 'BBS'.", ShortName = "p", LongName = "prefix")] + public string ArchivePrefix { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var prefix = ArchivePrefix ?? "BBS"; + + if (!DoesContainBbsa(InputPath, prefix)) + throw new ArchiveNotFoundException(InputPath, 0); + + var bbsaFileNames = Enumerable.Range(0, 5) + .Select(x => Path.Combine(InputPath, $"{prefix}{x}.DAT")); + + var outputDir = OutputDir ?? Path.Combine(Path.GetDirectoryName(InputPath), prefix); + + ExtractArchives(bbsaFileNames, outputDir); + return 0; + } + + private static void ExtractArchives(IEnumerable bbsaFileNames, string outputDir) + { + var streams = bbsaFileNames + .Select(x => File.OpenRead(x)) + .ToArray(); + + var bbsa = Bbs.Bbsa.Read(streams[0]); + foreach (var file in bbsa.Files) + { + var name = file.CalculateNameWithExtension(i => streams[i]); + var bbsaFileStream = file.OpenStream(i => streams[i]); + if (bbsaFileStream == null) + continue; + + var destinationFileName = Path.Combine(outputDir, name); + var destinationFolder = Path.GetDirectoryName(destinationFileName); + if (!Directory.Exists(destinationFolder)) + Directory.CreateDirectory(destinationFolder); + + Console.WriteLine(name); + + using (var outStream = File.Create(destinationFileName)) + bbsaFileStream.CopyTo(outStream); + } + } + } + + private class ListCommand + { + [Required] + [DirectoryExists] + [Argument(0, Description = "Required. Path where the various BBSAx.DAT files are located")] + public string InputPath { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Archive file name prefix. By default it is 'BBS'.", ShortName = "p", LongName = "prefix")] + public string ArchivePrefix { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var prefix = ArchivePrefix ?? "BBS"; + + if (!DoesContainBbsa(InputPath, prefix)) + throw new ArchiveNotFoundException(InputPath, 0); + + var bbsaFileName = Path.Combine(InputPath, $"{prefix}{0}.DAT"); + using var stream = File.OpenRead(bbsaFileName); + var bbsa = Bbs.Bbsa.Read(stream); + foreach (var file in bbsa.Files) + { + Console.WriteLine(file.Name); + } + + return 0; + } + } + + private static bool DoesContainBbsa(string path, string prefix) => + File.Exists(Path.Combine(path, $"{prefix}{0}.DAT")); + } +} diff --git a/OpenKh.Command.CoctChanger/Program.cs b/OpenKh.Command.CoctChanger/Program.cs index 8a2fab664..05087e765 100644 --- a/OpenKh.Command.CoctChanger/Program.cs +++ b/OpenKh.Command.CoctChanger/Program.cs @@ -1,363 +1,363 @@ -using McMaster.Extensions.CommandLineUtils; -using McMaster.Extensions.CommandLineUtils.Conventions; -using OpenKh.Command.CoctChanger.Utils; -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Kh2.Utils; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Net.Http.Headers; -using System.Numerics; -using System.Reflection; -using System.Text; - -namespace OpenKh.Command.CoctChanger -{ - [Command("OpenKh.Command.CoctChanger")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - [Subcommand(typeof(CreateRoomCoctCommand), typeof(UseThisCoctCommand), typeof(ShowStatsCommand) - , typeof(DumpCoctCommand))] - class Program - { - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - return 1; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return 1; - } - } - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - [HelpOption] - [Command(Description = "coct file: create single closed room")] - private class CreateRoomCoctCommand - { - [Required] - [Argument(0, Description = "Output coct")] - public string CoctOut { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "bbox in model 3D space: minX,Y,Z,maxX,Y,Z (default: ...)", ShortName = "b", LongName = "bbox")] - public string BBox { get; set; } = "-1000,-1000,-1000,1000,1500,1000"; - - protected int OnExecute(CommandLineApplication app) - { - var coct = new Coct(); - - var bbox = BBox.Split(',') - .Select(one => short.Parse(one)) - .ToArray(); - - var invMinX = bbox[0]; - var invMinY = bbox[1]; - var invMinZ = bbox[2]; - var invMaxX = bbox[3]; - var invMaxY = bbox[4]; - var invMaxZ = bbox[5]; - - var minX = -invMinX; - var minY = -invMinY; - var minZ = -invMinZ; - var maxX = -invMaxX; - var maxY = -invMaxY; - var maxZ = -invMaxZ; - - var builder = new Coct.BuildHelper(coct); - - // (forwardVec) - // +Z - // A / +Y (upVec) - // | / - // |/ - // +--> +X (rightVec) - - // 7 == 6 top - // | | top - // 4 == 5 top - // - // 3 == 2 bottom - // | | bottom - // 0 == 1 bottom - - var table4Idxes = new short[] - { - builder.AllocateVertex(minX, minY, minZ, 1), - builder.AllocateVertex(maxX, minY, minZ, 1), - builder.AllocateVertex(maxX, minY, maxZ, 1), - builder.AllocateVertex(minX, minY, maxZ, 1), - builder.AllocateVertex(minX, maxY, minZ, 1), - builder.AllocateVertex(maxX, maxY, minZ, 1), - builder.AllocateVertex(maxX, maxY, maxZ, 1), - builder.AllocateVertex(minX, maxY, maxZ, 1), - }; - - // side: - // 0 bottom - // 1 top - // 2 west - // 3 east - // 4 south - // 5 north - - var planes = new Plane[] - { - new Plane( 0,-1, 0,+minY), //bottom - new Plane( 0,+1, 0,-maxY), //up - new Plane(-1, 0, 0,+minX), //west - new Plane(+1, 0, 0,-maxX), //east - new Plane( 0, 0,-1,+minZ), //south - new Plane( 0, 0,+1,-maxZ), //north - }; - - var faceVertexOrders = new int[,] - { - {0,1,2,3}, //bottom - {4,7,6,5}, //top - {3,7,4,0}, //west - {1,5,6,2}, //east - {2,6,7,3}, //south - {0,4,5,1}, //north - }; - - var collisionMesh = new Coct.CollisionMesh - { - Collisions = new List() - }; - - for (var side = 0; side < 6; side++) - { - var collision = new Coct.Collision - { - Ground = 0, - FloorLevel = 0, - Vertex1 = table4Idxes[faceVertexOrders[side, 0]], - Vertex2 = table4Idxes[faceVertexOrders[side, 1]], - Vertex3 = table4Idxes[faceVertexOrders[side, 2]], - Vertex4 = table4Idxes[faceVertexOrders[side, 3]], - Plane = planes[side], - BoundingBox = BoundingBoxInt16.Invalid, - Attributes = new Coct.Attributes() { Flags = 0x3F1 }, - }; - coct.Complete(collision); - collisionMesh.Collisions.Add(collision); - } - - coct.Complete(collisionMesh); - - coct.CompleteAndAdd( - new Coct.CollisionNode - { - Meshes = new List() { collisionMesh } - } - ); - - var buff = new MemoryStream(); - coct.Write(buff); - buff.Position = 0; - File.WriteAllBytes(CoctOut, buff.ToArray()); - - return 0; - } - } - - class ShortVertex3 - { - public short X { get; set; } - public short Y { get; set; } - public short Z { get; set; } - } - - class ShortBBox - { - public ShortVertex3 Min { get; set; } - public ShortVertex3 Max { get; set; } - } - - [HelpOption] - [Command(Description = "map file: replace coct with your coct")] - private class UseThisCoctCommand - { - [Required] - [DirectoryExists] - [Argument(0, Description = "Input map dir")] - public string Input { get; set; } - - [Required] - [DirectoryExists] - [Argument(1, Description = "Output map dir")] - public string Output { get; set; } - - [Required] - [FileExists] - [Argument(2, Description = "COCT file input")] - public string CoctIn { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var coctBin = File.ReadAllBytes(CoctIn); - - foreach (var mapIn in Directory.GetFiles(Input, "*.map")) - { - Console.WriteLine(mapIn); - - var mapOut = Path.Combine(Output, Path.GetFileName(mapIn)); - - var entries = File.OpenRead(mapIn).Using(s => Bar.Read(s)) - .Select( - it => - { - if (it.Type == Bar.EntryType.CollisionOctalTree) - { - it.Stream = new MemoryStream(coctBin, false); - } - - return it; - } - ) - .ToArray(); - - File.Create(mapOut).Using(s => Bar.Write(s, entries)); - } - return 0; - } - } - - [HelpOption] - [Command(Description = "coct file: show stats")] - private class ShowStatsCommand - { - private class Report - { - public int NodeCount; - public int LeafCount; - public int TreeDepth; - public int MeshCount; - public int CollisionCount; - public int VertexCount; - } - - [Required] - [FileExists] - [Argument(0, Description = "Input map/coct file (decided by file extension: `.map` or not)")] - public string InputFile { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var isMap = Path.GetExtension(InputFile).ToLowerInvariant() == ".map"; - - if (isMap) - { - foreach (var entry in File.OpenRead(InputFile).Using(Bar.Read) - .Where(entry => false - || entry.Type == Bar.EntryType.CollisionOctalTree - || entry.Type == Bar.EntryType.CameraOctalTree - || entry.Type == Bar.EntryType.ColorOctalTree - || entry.Type == Bar.EntryType.MapCollision2 - || entry.Type == Bar.EntryType.ModelCollision - ) - ) - { - Console.WriteLine($"# {entry.Name}:{entry.Index} ({entry.Type})"); - PrintSummary(Coct.Read(entry.Stream)); - Console.WriteLine(); - } - } - else - { - PrintSummary(File.OpenRead(InputFile).Using(Coct.Read)); - } - - return 0; - } - - private void PrintSummary(Coct coct) - { - var report = new Report(); - GenerateReport(coct, 1, 0, report); - - Console.WriteLine($"Node count: {report.NodeCount,8:#,##0}"); - Console.WriteLine($"Leaf count: {report.LeafCount,8:#,##0}"); - Console.WriteLine($"Tree depth: {report.TreeDepth,8:#,##0}"); - Console.WriteLine($"Mesh count: {report.MeshCount,8:#,##0}"); - Console.WriteLine($"Coll count: {report.CollisionCount,8:#,##0}"); - Console.WriteLine($"Vert count: {report.VertexCount,8:#,##0}"); - } - - private static void GenerateReport(Coct coct, int depth, int index, Report report) - { - if (index == -1) - return; - - report.NodeCount++; - report.TreeDepth = Math.Max(report.TreeDepth, depth); - var node = coct.Nodes[index]; - if (node.Child1 >= 0) - { - var childDepth = depth + 1; - GenerateReport(coct, childDepth, node.Child1, report); - GenerateReport(coct, childDepth, node.Child2, report); - GenerateReport(coct, childDepth, node.Child3, report); - GenerateReport(coct, childDepth, node.Child4, report); - GenerateReport(coct, childDepth, node.Child5, report); - GenerateReport(coct, childDepth, node.Child6, report); - GenerateReport(coct, childDepth, node.Child7, report); - GenerateReport(coct, childDepth, node.Child8, report); - } - else - report.LeafCount++; - - foreach (var mesh in node.Meshes) - { - report.MeshCount++; - foreach (var collision in mesh.Collisions) - { - report.CollisionCount++; - report.VertexCount += 3; - if (collision.Vertex4 >= 0) - report.VertexCount++; - } - } - } - } - - [HelpOption] - [Command(Description = "coct file: dump")] - private class DumpCoctCommand - { - [Required] - [FileExists] - [Argument(0, Description = "COCT file input")] - public string CoctIn { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var coct = File.OpenRead(CoctIn).Using(Coct.Read); - - new DumpCoctUtil(coct, Console.Out); - - return 0; - } - } - } -} +using McMaster.Extensions.CommandLineUtils; +using McMaster.Extensions.CommandLineUtils.Conventions; +using OpenKh.Command.CoctChanger.Utils; +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Kh2.Utils; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Net.Http.Headers; +using System.Numerics; +using System.Reflection; +using System.Text; + +namespace OpenKh.Command.CoctChanger +{ + [Command("OpenKh.Command.CoctChanger")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + [Subcommand(typeof(CreateRoomCoctCommand), typeof(UseThisCoctCommand), typeof(ShowStatsCommand) + , typeof(DumpCoctCommand))] + class Program + { + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + return 1; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return 1; + } + } + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + [HelpOption] + [Command(Description = "coct file: create single closed room")] + private class CreateRoomCoctCommand + { + [Required] + [Argument(0, Description = "Output coct")] + public string CoctOut { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "bbox in model 3D space: minX,Y,Z,maxX,Y,Z (default: ...)", ShortName = "b", LongName = "bbox")] + public string BBox { get; set; } = "-1000,-1000,-1000,1000,1500,1000"; + + protected int OnExecute(CommandLineApplication app) + { + var coct = new Coct(); + + var bbox = BBox.Split(',') + .Select(one => short.Parse(one)) + .ToArray(); + + var invMinX = bbox[0]; + var invMinY = bbox[1]; + var invMinZ = bbox[2]; + var invMaxX = bbox[3]; + var invMaxY = bbox[4]; + var invMaxZ = bbox[5]; + + var minX = -invMinX; + var minY = -invMinY; + var minZ = -invMinZ; + var maxX = -invMaxX; + var maxY = -invMaxY; + var maxZ = -invMaxZ; + + var builder = new Coct.BuildHelper(coct); + + // (forwardVec) + // +Z + // A / +Y (upVec) + // | / + // |/ + // +--> +X (rightVec) + + // 7 == 6 top + // | | top + // 4 == 5 top + // + // 3 == 2 bottom + // | | bottom + // 0 == 1 bottom + + var table4Idxes = new short[] + { + builder.AllocateVertex(minX, minY, minZ, 1), + builder.AllocateVertex(maxX, minY, minZ, 1), + builder.AllocateVertex(maxX, minY, maxZ, 1), + builder.AllocateVertex(minX, minY, maxZ, 1), + builder.AllocateVertex(minX, maxY, minZ, 1), + builder.AllocateVertex(maxX, maxY, minZ, 1), + builder.AllocateVertex(maxX, maxY, maxZ, 1), + builder.AllocateVertex(minX, maxY, maxZ, 1), + }; + + // side: + // 0 bottom + // 1 top + // 2 west + // 3 east + // 4 south + // 5 north + + var planes = new Plane[] + { + new Plane( 0,-1, 0,+minY), //bottom + new Plane( 0,+1, 0,-maxY), //up + new Plane(-1, 0, 0,+minX), //west + new Plane(+1, 0, 0,-maxX), //east + new Plane( 0, 0,-1,+minZ), //south + new Plane( 0, 0,+1,-maxZ), //north + }; + + var faceVertexOrders = new int[,] + { + {0,1,2,3}, //bottom + {4,7,6,5}, //top + {3,7,4,0}, //west + {1,5,6,2}, //east + {2,6,7,3}, //south + {0,4,5,1}, //north + }; + + var collisionMesh = new Coct.CollisionMesh + { + Collisions = new List() + }; + + for (var side = 0; side < 6; side++) + { + var collision = new Coct.Collision + { + Ground = 0, + FloorLevel = 0, + Vertex1 = table4Idxes[faceVertexOrders[side, 0]], + Vertex2 = table4Idxes[faceVertexOrders[side, 1]], + Vertex3 = table4Idxes[faceVertexOrders[side, 2]], + Vertex4 = table4Idxes[faceVertexOrders[side, 3]], + Plane = planes[side], + BoundingBox = BoundingBoxInt16.Invalid, + Attributes = new Coct.Attributes() { Flags = 0x3F1 }, + }; + coct.Complete(collision); + collisionMesh.Collisions.Add(collision); + } + + coct.Complete(collisionMesh); + + coct.CompleteAndAdd( + new Coct.CollisionNode + { + Meshes = new List() { collisionMesh } + } + ); + + var buff = new MemoryStream(); + coct.Write(buff); + buff.Position = 0; + File.WriteAllBytes(CoctOut, buff.ToArray()); + + return 0; + } + } + + class ShortVertex3 + { + public short X { get; set; } + public short Y { get; set; } + public short Z { get; set; } + } + + class ShortBBox + { + public ShortVertex3 Min { get; set; } + public ShortVertex3 Max { get; set; } + } + + [HelpOption] + [Command(Description = "map file: replace coct with your coct")] + private class UseThisCoctCommand + { + [Required] + [DirectoryExists] + [Argument(0, Description = "Input map dir")] + public string Input { get; set; } + + [Required] + [DirectoryExists] + [Argument(1, Description = "Output map dir")] + public string Output { get; set; } + + [Required] + [FileExists] + [Argument(2, Description = "COCT file input")] + public string CoctIn { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var coctBin = File.ReadAllBytes(CoctIn); + + foreach (var mapIn in Directory.GetFiles(Input, "*.map")) + { + Console.WriteLine(mapIn); + + var mapOut = Path.Combine(Output, Path.GetFileName(mapIn)); + + var entries = File.OpenRead(mapIn).Using(s => Bar.Read(s)) + .Select( + it => + { + if (it.Type == Bar.EntryType.CollisionOctalTree) + { + it.Stream = new MemoryStream(coctBin, false); + } + + return it; + } + ) + .ToArray(); + + File.Create(mapOut).Using(s => Bar.Write(s, entries)); + } + return 0; + } + } + + [HelpOption] + [Command(Description = "coct file: show stats")] + private class ShowStatsCommand + { + private class Report + { + public int NodeCount; + public int LeafCount; + public int TreeDepth; + public int MeshCount; + public int CollisionCount; + public int VertexCount; + } + + [Required] + [FileExists] + [Argument(0, Description = "Input map/coct file (decided by file extension: `.map` or not)")] + public string InputFile { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var isMap = Path.GetExtension(InputFile).ToLowerInvariant() == ".map"; + + if (isMap) + { + foreach (var entry in File.OpenRead(InputFile).Using(Bar.Read) + .Where(entry => false + || entry.Type == Bar.EntryType.CollisionOctalTree + || entry.Type == Bar.EntryType.CameraOctalTree + || entry.Type == Bar.EntryType.ColorOctalTree + || entry.Type == Bar.EntryType.MapCollision2 + || entry.Type == Bar.EntryType.ModelCollision + ) + ) + { + Console.WriteLine($"# {entry.Name}:{entry.Index} ({entry.Type})"); + PrintSummary(Coct.Read(entry.Stream)); + Console.WriteLine(); + } + } + else + { + PrintSummary(File.OpenRead(InputFile).Using(Coct.Read)); + } + + return 0; + } + + private void PrintSummary(Coct coct) + { + var report = new Report(); + GenerateReport(coct, 1, 0, report); + + Console.WriteLine($"Node count: {report.NodeCount,8:#,##0}"); + Console.WriteLine($"Leaf count: {report.LeafCount,8:#,##0}"); + Console.WriteLine($"Tree depth: {report.TreeDepth,8:#,##0}"); + Console.WriteLine($"Mesh count: {report.MeshCount,8:#,##0}"); + Console.WriteLine($"Coll count: {report.CollisionCount,8:#,##0}"); + Console.WriteLine($"Vert count: {report.VertexCount,8:#,##0}"); + } + + private static void GenerateReport(Coct coct, int depth, int index, Report report) + { + if (index == -1) + return; + + report.NodeCount++; + report.TreeDepth = Math.Max(report.TreeDepth, depth); + var node = coct.Nodes[index]; + if (node.Child1 >= 0) + { + var childDepth = depth + 1; + GenerateReport(coct, childDepth, node.Child1, report); + GenerateReport(coct, childDepth, node.Child2, report); + GenerateReport(coct, childDepth, node.Child3, report); + GenerateReport(coct, childDepth, node.Child4, report); + GenerateReport(coct, childDepth, node.Child5, report); + GenerateReport(coct, childDepth, node.Child6, report); + GenerateReport(coct, childDepth, node.Child7, report); + GenerateReport(coct, childDepth, node.Child8, report); + } + else + report.LeafCount++; + + foreach (var mesh in node.Meshes) + { + report.MeshCount++; + foreach (var collision in mesh.Collisions) + { + report.CollisionCount++; + report.VertexCount += 3; + if (collision.Vertex4 >= 0) + report.VertexCount++; + } + } + } + } + + [HelpOption] + [Command(Description = "coct file: dump")] + private class DumpCoctCommand + { + [Required] + [FileExists] + [Argument(0, Description = "COCT file input")] + public string CoctIn { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var coct = File.OpenRead(CoctIn).Using(Coct.Read); + + new DumpCoctUtil(coct, Console.Out); + + return 0; + } + } + } +} diff --git a/OpenKh.Command.CoctChanger/Utils/DumpCoctUtil.cs b/OpenKh.Command.CoctChanger/Utils/DumpCoctUtil.cs index 5acc57af2..c509f833b 100644 --- a/OpenKh.Command.CoctChanger/Utils/DumpCoctUtil.cs +++ b/OpenKh.Command.CoctChanger/Utils/DumpCoctUtil.cs @@ -1,91 +1,91 @@ -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -namespace OpenKh.Command.CoctChanger.Utils -{ - public class DumpCoctUtil - { - private readonly Coct coct; - private readonly TextWriter writer; - - public DumpCoctUtil(Coct coct, TextWriter writer) - { - this.coct = coct; - this.writer = writer; - - if (coct.Nodes.Any()) - { - DumpNode(0, 0); - } - } - - private void DumpNode(int index, int indent) - { - if (index == -1) - { - return; - } - - var node = coct.Nodes[index]; - writer.WriteLine($"{new string(' ', indent)}{ObjDumpUtil.FormatObj(node, it => it.BoundingBox)}"); - - foreach (var mesh in node.Meshes) - { - DumpMeshInfo(mesh, indent + 1); - } - - DumpNode(node.Child1, indent + 1); - DumpNode(node.Child2, indent + 1); - DumpNode(node.Child3, indent + 1); - DumpNode(node.Child4, indent + 1); - DumpNode(node.Child5, indent + 1); - DumpNode(node.Child6, indent + 1); - DumpNode(node.Child7, indent + 1); - DumpNode(node.Child8, indent + 1); - } - - private void DumpMeshInfo(Coct.CollisionMesh mesh, int indent) - { - writer.WriteLine($"{new string(' ', indent)}{ObjDumpUtil.FormatObj(mesh, it => it.BoundingBox, it => it.Visibility, it => it.Group)}"); - - foreach (var face in mesh.Collisions) - { - DumpFace(face, indent + 1); - } - } - - private void DumpFace(Coct.Collision face, int indent) - { - var dump = ObjDumpUtil.FormatObj(face - , it => it.BoundingBox - , it => it.Plane - , it => it.Ground - , it => it.FloorLevel - ) - .Add( - "Attributes", - face.Attributes.Flags.ToString("X8") - ) - .Add( - "Vertices", - string.Join( - ", ", - new int[] { - face.Vertex1, - face.Vertex2, - face.Vertex3, - face.Vertex4, - } - .Where(it => it != -1) - .Select(it => coct.VertexList[it]) - ) - ); - writer.WriteLine($"{new string(' ', indent)}{dump}"); - } - } -} +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Text; + +namespace OpenKh.Command.CoctChanger.Utils +{ + public class DumpCoctUtil + { + private readonly Coct coct; + private readonly TextWriter writer; + + public DumpCoctUtil(Coct coct, TextWriter writer) + { + this.coct = coct; + this.writer = writer; + + if (coct.Nodes.Any()) + { + DumpNode(0, 0); + } + } + + private void DumpNode(int index, int indent) + { + if (index == -1) + { + return; + } + + var node = coct.Nodes[index]; + writer.WriteLine($"{new string(' ', indent)}{ObjDumpUtil.FormatObj(node, it => it.BoundingBox)}"); + + foreach (var mesh in node.Meshes) + { + DumpMeshInfo(mesh, indent + 1); + } + + DumpNode(node.Child1, indent + 1); + DumpNode(node.Child2, indent + 1); + DumpNode(node.Child3, indent + 1); + DumpNode(node.Child4, indent + 1); + DumpNode(node.Child5, indent + 1); + DumpNode(node.Child6, indent + 1); + DumpNode(node.Child7, indent + 1); + DumpNode(node.Child8, indent + 1); + } + + private void DumpMeshInfo(Coct.CollisionMesh mesh, int indent) + { + writer.WriteLine($"{new string(' ', indent)}{ObjDumpUtil.FormatObj(mesh, it => it.BoundingBox, it => it.Visibility, it => it.Group)}"); + + foreach (var face in mesh.Collisions) + { + DumpFace(face, indent + 1); + } + } + + private void DumpFace(Coct.Collision face, int indent) + { + var dump = ObjDumpUtil.FormatObj(face + , it => it.BoundingBox + , it => it.Plane + , it => it.Ground + , it => it.FloorLevel + ) + .Add( + "Attributes", + face.Attributes.Flags.ToString("X8") + ) + .Add( + "Vertices", + string.Join( + ", ", + new int[] { + face.Vertex1, + face.Vertex2, + face.Vertex3, + face.Vertex4, + } + .Where(it => it != -1) + .Select(it => coct.VertexList[it]) + ) + ); + writer.WriteLine($"{new string(' ', indent)}{dump}"); + } + } +} diff --git a/OpenKh.Command.CoctChanger/Utils/ObjDumpUtil.cs b/OpenKh.Command.CoctChanger/Utils/ObjDumpUtil.cs index 5472361a9..0bdfc0885 100644 --- a/OpenKh.Command.CoctChanger/Utils/ObjDumpUtil.cs +++ b/OpenKh.Command.CoctChanger/Utils/ObjDumpUtil.cs @@ -1,54 +1,54 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Linq.Expressions; -using System.Numerics; -using System.Text; - -namespace OpenKh.Command.CoctChanger.Utils -{ - class ObjDumpUtil - { - private Type type; - private List list; - - public override string ToString() => $"[{type.Name}] {string.Join("; ", list)}"; - - public static ObjDumpUtil FormatObj( - T item, - params Expression>[] expressions - ) - { - return new ObjDumpUtil - { - type = typeof(T), - list = expressions - .Select(expression => $"{GetMemberName(expression)}={expression.Compile().Invoke(item)}") - .ToList() - }; - } - - private static string GetMemberName(LambdaExpression expression) - { - if (expression.Body is UnaryExpression unary && unary.NodeType == ExpressionType.Convert) - { - if (unary.Operand is MemberExpression binary) - { - return binary.Member.Name; - } - } - else if (expression.Body is MemberExpression binary) - { - return binary.Member.Name; - } - return "?"; - } - - public ObjDumpUtil Add(string name, object value) - { - list.Add($"{name}={value}"); - return this; - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Numerics; +using System.Text; + +namespace OpenKh.Command.CoctChanger.Utils +{ + class ObjDumpUtil + { + private Type type; + private List list; + + public override string ToString() => $"[{type.Name}] {string.Join("; ", list)}"; + + public static ObjDumpUtil FormatObj( + T item, + params Expression>[] expressions + ) + { + return new ObjDumpUtil + { + type = typeof(T), + list = expressions + .Select(expression => $"{GetMemberName(expression)}={expression.Compile().Invoke(item)}") + .ToList() + }; + } + + private static string GetMemberName(LambdaExpression expression) + { + if (expression.Body is UnaryExpression unary && unary.NodeType == ExpressionType.Convert) + { + if (unary.Operand is MemberExpression binary) + { + return binary.Member.Name; + } + } + else if (expression.Body is MemberExpression binary) + { + return binary.Member.Name; + } + return "?"; + } + + public ObjDumpUtil Add(string name, object value) + { + list.Add($"{name}={value}"); + return this; + } + } +} diff --git a/OpenKh.Command.DoctChanger/Program.cs b/OpenKh.Command.DoctChanger/Program.cs index 796104af5..e18b5f83e 100644 --- a/OpenKh.Command.DoctChanger/Program.cs +++ b/OpenKh.Command.DoctChanger/Program.cs @@ -1,335 +1,335 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Kh2; -using OpenKh.Common; -using System; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Reflection; -using System.Linq; -using OpenKh.Kh2.Utils; -using OpenKh.Command.DoctChanger.Utils; - -namespace OpenKh.Command.DoctChanger -{ - [Command("OpenKh.Command.DoctChanger")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - [Subcommand(typeof(UseThisDoctCommand), typeof(CreateDoctForMapCommand) - , typeof(CreateDummyDoctCommand) - , typeof(ReadDoctCommand), typeof(ReadMapDoctCommand) - , typeof(ShowStatsCommand) - , typeof(DumpDoctCommand))] - class Program - { - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - return 1; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return 1; - } - } - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - - [HelpOption] - [Command(Description = "map file: replace doct with your doct")] - private class UseThisDoctCommand - { - [Required] - [DirectoryExists] - [Argument(0, Description = "Input map dir")] - public string Input { get; set; } - - [Required] - [DirectoryExists] - [Argument(1, Description = "Output map dir")] - public string Output { get; set; } - - [Required] - [FileExists] - [Argument(2, Description = "DOCT file input")] - public string DoctIn { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var doctBin = File.ReadAllBytes(DoctIn); - - foreach (var mapIn in Directory.GetFiles(Input, "*.map")) - { - Console.WriteLine(mapIn); - - var mapOut = Path.Combine(Output, Path.GetFileName(mapIn)); - - var entries = File.OpenRead(mapIn).Using(s => Bar.Read(s)) - .Select( - it => - { - if (it.Type == Bar.EntryType.DrawOctalTree) - { - it.Stream = new MemoryStream(doctBin, false); - } - - return it; - } - ) - .ToArray(); - - File.Create(mapOut).Using(s => Bar.Write(s, entries)); - } - return 0; - } - } - - private static void SummaryDoct(Doct doct, string file, TextWriter writer) - { - writer.WriteLine($"# DOCT ({Path.GetFileName(file)})"); - writer.WriteLine(); - writer.WriteLine($"- Version: {doct.Header.Version}"); - writer.WriteLine($"- Unk2: {doct.Header.Unk2}"); - writer.WriteLine(); - - writer.WriteLine("## Entry1"); - writer.WriteLine(); - writer.WriteLine("```"); - - foreach (var pair in doct.Entry1List.Select((it, index) => (it, index))) - { - writer.WriteLine($"{pair.index,4}:{pair.it}"); - } - writer.WriteLine("```"); - - writer.WriteLine(); - - writer.WriteLine("## Entry2"); - writer.WriteLine(); - writer.WriteLine("```"); - - foreach (var pair in doct.Entry2List.Select((it, index) => (it, index))) - { - writer.WriteLine($"{pair.index,4}:{pair.it}"); - } - - writer.WriteLine("```"); - } - - [HelpOption] - [Command(Description = "doct file: read")] - private class ReadDoctCommand - { - [Required] - [FileExists] - [Argument(0, Description = "DOCT file input")] - public string DoctIn { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var doct = File.OpenRead(DoctIn).Using(s => Doct.Read(s)); - - SummaryDoct(doct, DoctIn, Console.Out); - - return 0; - } - } - - [HelpOption] - [Command(Description = "doct file: dump")] - private class DumpDoctCommand - { - [Required] - [FileExists] - [Argument(0, Description = "DOCT file input")] - public string DoctIn { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var doct = File.OpenRead(DoctIn).Using(s => Doct.Read(s)); - - new DumpDoctUtil(doct, Console.Out); - - return 0; - } - } - - [HelpOption] - [Command(Description = "map file: read doct")] - private class ReadMapDoctCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Map file input")] - public string MapIn { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var doctBin = File.ReadAllBytes(MapIn); - - var entries = File.OpenRead(MapIn).Using(s => Bar.Read(s)); - - var doctEntry = entries.Single(it => it.Type == Bar.EntryType.DrawOctalTree); - - var doct = Doct.Read(doctEntry.Stream); - - SummaryDoct(doct, MapIn, Console.Out); - - return 0; - } - } - - [HelpOption] - [Command(Description = "doct file: create dummy")] - private class CreateDummyDoctCommand - { - [Required] - [Argument(0, Description = "DOCT file output")] - public string DoctOut { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var doct = new Doct(); - - doct.Entry1List.Add(new Doct.Entry1 { }); - doct.Entry2List.Add(new Doct.Entry2 { }); - - File.Create(DoctOut).Using(s => Doct.Write(s, doct)); - - return 0; - } - } - - [HelpOption] - [Command(Description = "map file: create and set unoptimized doct for rendering entire map")] - private class CreateDoctForMapCommand - { - [Required] - [Argument(0, Description = "Map file input")] - public string MapIn { get; set; } - - [Argument(1, Description = "Map file output. Default output is same file name at current folder")] - public string MapOut { get; set; } - - private static bool IsMapModel(Bar.Entry entry) => entry.Type == Bar.EntryType.Model && entry.Name == "MAP"; - private static bool IsDoct(Bar.Entry entry) => entry.Type == Bar.EntryType.DrawOctalTree; - - protected int OnExecute(CommandLineApplication app) - { - MapOut = Path.GetFullPath(MapOut ?? Path.GetFileName(MapIn)); - - Console.WriteLine($"Output map file: {MapOut}"); - - var entries = File.OpenRead(MapIn).Using(s => Bar.Read(s).ToArray()); - - var mapModel = Mdlx.Read(entries.Single(IsMapModel).Stream); - - var numVifPackets = mapModel.MapModel.VifPackets.Count; - var numAlb2Groups = mapModel.MapModel.vifPacketRenderingGroup.Count; - - Console.WriteLine($"numVifPackets: {numVifPackets:#,##0}"); - Console.WriteLine($"numAlb2Groups: {numAlb2Groups:#,##0}"); - - Console.WriteLine($"Note: this tool will build a unoptimized doct that renders all ALB2 {numAlb2Groups:#,##0} groups."); - - var doctStream = new MemoryStream(); - { - var doct = new Doct(); - - doct.Entry1List.Add( - new Doct.Entry1 - { - Entry2Index = 0, - Entry2LastIndex = Convert.ToUInt16(numAlb2Groups), // max 65535 - } - ); - - const float WorldBounds = 18000; - - doct.Entry2List.AddRange( - Enumerable.Range(0, numAlb2Groups) - .Select( - index => new Doct.Entry2 - { - BoundingBox = new BoundingBox( - new System.Numerics.Vector3(-WorldBounds), - new System.Numerics.Vector3(WorldBounds) - ) - } - ) - ); - - Doct.Write(doctStream, doct); - - doctStream.Position = 0; - } - - foreach (var entry in entries.Where(IsDoct)) - { - Console.WriteLine("DOCT entry replaced."); - entry.Stream = doctStream; - } - - File.Create(MapOut).Using(s => Bar.Write(s, entries)); - - Console.WriteLine("Output map file is written successfully."); - return 0; - } - } - - [HelpOption] - [Command(Description = "doct file: show stats")] - private class ShowStatsCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Input map/doct file (decided by file extension: `.map` or not)")] - public string InputFile { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var isMap = Path.GetExtension(InputFile).ToLowerInvariant() == ".map"; - - if (isMap) - { - foreach (var entry in File.OpenRead(InputFile).Using(Bar.Read) - .Where(entry => false - || entry.Type == Bar.EntryType.DrawOctalTree - ) - ) - { - Console.WriteLine($"# {entry.Name}:{entry.Index} ({entry.Type})"); - PrintSummary(Doct.Read(entry.Stream)); - Console.WriteLine(); - } - } - else - { - PrintSummary(File.OpenRead(InputFile).Using(Doct.Read)); - } - - return 0; - } - - private void PrintSummary(Doct coct) - { - Console.WriteLine($"{coct.Entry1List.Count,8:#,##0} drawing mesh groups."); - Console.WriteLine($"{coct.Entry2List.Count,8:#,##0} drawing meshes."); - } - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Kh2; +using OpenKh.Common; +using System; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Reflection; +using System.Linq; +using OpenKh.Kh2.Utils; +using OpenKh.Command.DoctChanger.Utils; + +namespace OpenKh.Command.DoctChanger +{ + [Command("OpenKh.Command.DoctChanger")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + [Subcommand(typeof(UseThisDoctCommand), typeof(CreateDoctForMapCommand) + , typeof(CreateDummyDoctCommand) + , typeof(ReadDoctCommand), typeof(ReadMapDoctCommand) + , typeof(ShowStatsCommand) + , typeof(DumpDoctCommand))] + class Program + { + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + return 1; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return 1; + } + } + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + + [HelpOption] + [Command(Description = "map file: replace doct with your doct")] + private class UseThisDoctCommand + { + [Required] + [DirectoryExists] + [Argument(0, Description = "Input map dir")] + public string Input { get; set; } + + [Required] + [DirectoryExists] + [Argument(1, Description = "Output map dir")] + public string Output { get; set; } + + [Required] + [FileExists] + [Argument(2, Description = "DOCT file input")] + public string DoctIn { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var doctBin = File.ReadAllBytes(DoctIn); + + foreach (var mapIn in Directory.GetFiles(Input, "*.map")) + { + Console.WriteLine(mapIn); + + var mapOut = Path.Combine(Output, Path.GetFileName(mapIn)); + + var entries = File.OpenRead(mapIn).Using(s => Bar.Read(s)) + .Select( + it => + { + if (it.Type == Bar.EntryType.DrawOctalTree) + { + it.Stream = new MemoryStream(doctBin, false); + } + + return it; + } + ) + .ToArray(); + + File.Create(mapOut).Using(s => Bar.Write(s, entries)); + } + return 0; + } + } + + private static void SummaryDoct(Doct doct, string file, TextWriter writer) + { + writer.WriteLine($"# DOCT ({Path.GetFileName(file)})"); + writer.WriteLine(); + writer.WriteLine($"- Version: {doct.Header.Version}"); + writer.WriteLine($"- Unk2: {doct.Header.Unk2}"); + writer.WriteLine(); + + writer.WriteLine("## Entry1"); + writer.WriteLine(); + writer.WriteLine("```"); + + foreach (var pair in doct.Entry1List.Select((it, index) => (it, index))) + { + writer.WriteLine($"{pair.index,4}:{pair.it}"); + } + writer.WriteLine("```"); + + writer.WriteLine(); + + writer.WriteLine("## Entry2"); + writer.WriteLine(); + writer.WriteLine("```"); + + foreach (var pair in doct.Entry2List.Select((it, index) => (it, index))) + { + writer.WriteLine($"{pair.index,4}:{pair.it}"); + } + + writer.WriteLine("```"); + } + + [HelpOption] + [Command(Description = "doct file: read")] + private class ReadDoctCommand + { + [Required] + [FileExists] + [Argument(0, Description = "DOCT file input")] + public string DoctIn { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var doct = File.OpenRead(DoctIn).Using(s => Doct.Read(s)); + + SummaryDoct(doct, DoctIn, Console.Out); + + return 0; + } + } + + [HelpOption] + [Command(Description = "doct file: dump")] + private class DumpDoctCommand + { + [Required] + [FileExists] + [Argument(0, Description = "DOCT file input")] + public string DoctIn { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var doct = File.OpenRead(DoctIn).Using(s => Doct.Read(s)); + + new DumpDoctUtil(doct, Console.Out); + + return 0; + } + } + + [HelpOption] + [Command(Description = "map file: read doct")] + private class ReadMapDoctCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Map file input")] + public string MapIn { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var doctBin = File.ReadAllBytes(MapIn); + + var entries = File.OpenRead(MapIn).Using(s => Bar.Read(s)); + + var doctEntry = entries.Single(it => it.Type == Bar.EntryType.DrawOctalTree); + + var doct = Doct.Read(doctEntry.Stream); + + SummaryDoct(doct, MapIn, Console.Out); + + return 0; + } + } + + [HelpOption] + [Command(Description = "doct file: create dummy")] + private class CreateDummyDoctCommand + { + [Required] + [Argument(0, Description = "DOCT file output")] + public string DoctOut { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var doct = new Doct(); + + doct.Entry1List.Add(new Doct.Entry1 { }); + doct.Entry2List.Add(new Doct.Entry2 { }); + + File.Create(DoctOut).Using(s => Doct.Write(s, doct)); + + return 0; + } + } + + [HelpOption] + [Command(Description = "map file: create and set unoptimized doct for rendering entire map")] + private class CreateDoctForMapCommand + { + [Required] + [Argument(0, Description = "Map file input")] + public string MapIn { get; set; } + + [Argument(1, Description = "Map file output. Default output is same file name at current folder")] + public string MapOut { get; set; } + + private static bool IsMapModel(Bar.Entry entry) => entry.Type == Bar.EntryType.Model && entry.Name == "MAP"; + private static bool IsDoct(Bar.Entry entry) => entry.Type == Bar.EntryType.DrawOctalTree; + + protected int OnExecute(CommandLineApplication app) + { + MapOut = Path.GetFullPath(MapOut ?? Path.GetFileName(MapIn)); + + Console.WriteLine($"Output map file: {MapOut}"); + + var entries = File.OpenRead(MapIn).Using(s => Bar.Read(s).ToArray()); + + var mapModel = Mdlx.Read(entries.Single(IsMapModel).Stream); + + var numVifPackets = mapModel.MapModel.VifPackets.Count; + var numAlb2Groups = mapModel.MapModel.vifPacketRenderingGroup.Count; + + Console.WriteLine($"numVifPackets: {numVifPackets:#,##0}"); + Console.WriteLine($"numAlb2Groups: {numAlb2Groups:#,##0}"); + + Console.WriteLine($"Note: this tool will build a unoptimized doct that renders all ALB2 {numAlb2Groups:#,##0} groups."); + + var doctStream = new MemoryStream(); + { + var doct = new Doct(); + + doct.Entry1List.Add( + new Doct.Entry1 + { + Entry2Index = 0, + Entry2LastIndex = Convert.ToUInt16(numAlb2Groups), // max 65535 + } + ); + + const float WorldBounds = 18000; + + doct.Entry2List.AddRange( + Enumerable.Range(0, numAlb2Groups) + .Select( + index => new Doct.Entry2 + { + BoundingBox = new BoundingBox( + new System.Numerics.Vector3(-WorldBounds), + new System.Numerics.Vector3(WorldBounds) + ) + } + ) + ); + + Doct.Write(doctStream, doct); + + doctStream.Position = 0; + } + + foreach (var entry in entries.Where(IsDoct)) + { + Console.WriteLine("DOCT entry replaced."); + entry.Stream = doctStream; + } + + File.Create(MapOut).Using(s => Bar.Write(s, entries)); + + Console.WriteLine("Output map file is written successfully."); + return 0; + } + } + + [HelpOption] + [Command(Description = "doct file: show stats")] + private class ShowStatsCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Input map/doct file (decided by file extension: `.map` or not)")] + public string InputFile { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var isMap = Path.GetExtension(InputFile).ToLowerInvariant() == ".map"; + + if (isMap) + { + foreach (var entry in File.OpenRead(InputFile).Using(Bar.Read) + .Where(entry => false + || entry.Type == Bar.EntryType.DrawOctalTree + ) + ) + { + Console.WriteLine($"# {entry.Name}:{entry.Index} ({entry.Type})"); + PrintSummary(Doct.Read(entry.Stream)); + Console.WriteLine(); + } + } + else + { + PrintSummary(File.OpenRead(InputFile).Using(Doct.Read)); + } + + return 0; + } + + private void PrintSummary(Doct coct) + { + Console.WriteLine($"{coct.Entry1List.Count,8:#,##0} drawing mesh groups."); + Console.WriteLine($"{coct.Entry2List.Count,8:#,##0} drawing meshes."); + } + } + } +} diff --git a/OpenKh.Command.DoctChanger/Utils/DumpDoctUtil.cs b/OpenKh.Command.DoctChanger/Utils/DumpDoctUtil.cs index 7ce6b167c..f7c749894 100644 --- a/OpenKh.Command.DoctChanger/Utils/DumpDoctUtil.cs +++ b/OpenKh.Command.DoctChanger/Utils/DumpDoctUtil.cs @@ -1,57 +1,57 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenKh.Kh2; -using System.IO; -using System.Linq; - -namespace OpenKh.Command.DoctChanger.Utils -{ - public class DumpDoctUtil - { - private readonly Doct doct; - private readonly TextWriter writer; - - public DumpDoctUtil(Doct doct, TextWriter writer) - { - this.doct = doct; - this.writer = writer; - - if (doct.Entry1List.Any()) - { - DumpEntry1(0, 0); - } - } - - private void DumpEntry1(int index, int indent) - { - if (index == -1) - { - return; - } - - var entry = doct.Entry1List[index]; - writer.WriteLine($"{new string(' ', indent)}[Entry1] {nameof(entry.Unk)}={entry.Unk}; {nameof(entry.BoundingBox)}={entry.BoundingBox}"); - - for (var idx = entry.Entry2Index; idx < entry.Entry2LastIndex; idx++) - { - DumpEntry2(idx, indent + 1); - } - - DumpEntry1(entry.Child1, indent + 1); - DumpEntry1(entry.Child2, indent + 1); - DumpEntry1(entry.Child3, indent + 1); - DumpEntry1(entry.Child4, indent + 1); - DumpEntry1(entry.Child5, indent + 1); - DumpEntry1(entry.Child6, indent + 1); - DumpEntry1(entry.Child7, indent + 1); - DumpEntry1(entry.Child8, indent + 1); - } - - private void DumpEntry2(int index, int indent) - { - var entry = doct.Entry2List[index]; - writer.WriteLine($"{new string(' ', indent)}[Entry2] {nameof(entry.Flags)}={entry.Flags}; {nameof(entry.BoundingBox)}={entry.BoundingBox}"); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using OpenKh.Kh2; +using System.IO; +using System.Linq; + +namespace OpenKh.Command.DoctChanger.Utils +{ + public class DumpDoctUtil + { + private readonly Doct doct; + private readonly TextWriter writer; + + public DumpDoctUtil(Doct doct, TextWriter writer) + { + this.doct = doct; + this.writer = writer; + + if (doct.Entry1List.Any()) + { + DumpEntry1(0, 0); + } + } + + private void DumpEntry1(int index, int indent) + { + if (index == -1) + { + return; + } + + var entry = doct.Entry1List[index]; + writer.WriteLine($"{new string(' ', indent)}[Entry1] {nameof(entry.Unk)}={entry.Unk}; {nameof(entry.BoundingBox)}={entry.BoundingBox}"); + + for (var idx = entry.Entry2Index; idx < entry.Entry2LastIndex; idx++) + { + DumpEntry2(idx, indent + 1); + } + + DumpEntry1(entry.Child1, indent + 1); + DumpEntry1(entry.Child2, indent + 1); + DumpEntry1(entry.Child3, indent + 1); + DumpEntry1(entry.Child4, indent + 1); + DumpEntry1(entry.Child5, indent + 1); + DumpEntry1(entry.Child6, indent + 1); + DumpEntry1(entry.Child7, indent + 1); + DumpEntry1(entry.Child8, indent + 1); + } + + private void DumpEntry2(int index, int indent) + { + var entry = doct.Entry2List[index]; + writer.WriteLine($"{new string(' ', indent)}[Entry2] {nameof(entry.Flags)}={entry.Flags}; {nameof(entry.BoundingBox)}={entry.BoundingBox}"); + } + } +} diff --git a/OpenKh.Command.HdAssets/Program.cs b/OpenKh.Command.HdAssets/Program.cs index bf6f4dd80..6f3881683 100644 --- a/OpenKh.Command.HdAssets/Program.cs +++ b/OpenKh.Command.HdAssets/Program.cs @@ -1,149 +1,149 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Common.Archives; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Linq; -using System.Reflection; - -namespace OpenKh.Command.HdAssets -{ - [Command("OpenKh.Command.HdAsset")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - [Subcommand( - typeof(ExtractCommand), - typeof(StripCommand))] - class Program - { - private const string DefaultPrefix = "_ASSET_"; - - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - return 2; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return -1; - } - } - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - [Command(Description = "Extract ReMIX assets into an asset folder.")] - private class ExtractCommand - { - [Required] - [Argument(0, Description = "Input file or directory of 1.5/2.5 ReMIX assets")] - public string Input { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Prefix used as extraction directory. By default it is '_ASSET_'", ShortName = "p", LongName = "prefix")] - public string Prefix { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Execute the command recursively for all the sub-folders", ShortName = "r", LongName = "recursive")] - public bool Recursive { get; set; } - - protected void OnExecute(CommandLineApplication app) - { - var prefix = Prefix ?? DefaultPrefix; - - foreach (var filePath in GetFiles(Input, Recursive, prefix)) - { - using (var stream = File.OpenRead(filePath)) - { - HdAsset asset; - - try - { - // Avoid to crash on files that are not a ReMIX asset - asset = HdAsset.Read(stream); - } - catch - { - // Not a ReMIX asset - continue; - } - - var directoryName = Path.GetDirectoryName(filePath); - Console.Write(filePath); - - foreach (var entry in asset.Entries) - { - var outDir = Path.GetFileNameWithoutExtension(filePath); - var outFileName = Path.Combine(directoryName, $"{prefix}{outDir}", entry.Name); - Directory.CreateDirectory(Path.GetDirectoryName(outFileName)); - - using (var outStream = File.Create(outFileName)) - { - entry.Stream.Position = 0; - entry.Stream.CopyTo(outStream); - } - } - } - } - } - } - - [Command(Description = "Modify ReMIX assets by unwrapping them from their HD textures, effectly making them compatible with the original games.")] - private class StripCommand - { - [Required] - [Argument(0, Description = "Input file or directory of 1.5/2.5 ReMIX assets")] - public string Input { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Execute the command recursively for all the sub-folders", ShortName = "r", LongName = "recursive")] - public bool Recursive { get; set; } - - protected void OnExecute(CommandLineApplication app) - { - foreach (var filePath in GetFiles(Input, Recursive, DefaultPrefix)) - { - HdAsset asset; - using (var stream = File.OpenRead(filePath)) - { - - try - { - // Avoid to crash on files that are not a ReMIX asset - asset = HdAsset.Read(stream); - } - catch - { - // Not a ReMIX asset - continue; - } - } - - using (var stream = File.Create(filePath)) - asset.Stream.CopyTo(stream); - } - } - } - - private static string[] GetFiles(string input, bool recursive, string excludePrefix) - { - if (File.Exists(input)) - return new string[] { input }; - else if (Directory.Exists(input)) - return Directory.GetFiles(input, "*", - recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); - else - throw new FileNotFoundException(null, input); - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Common.Archives; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace OpenKh.Command.HdAssets +{ + [Command("OpenKh.Command.HdAsset")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + [Subcommand( + typeof(ExtractCommand), + typeof(StripCommand))] + class Program + { + private const string DefaultPrefix = "_ASSET_"; + + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + return 2; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return -1; + } + } + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + [Command(Description = "Extract ReMIX assets into an asset folder.")] + private class ExtractCommand + { + [Required] + [Argument(0, Description = "Input file or directory of 1.5/2.5 ReMIX assets")] + public string Input { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Prefix used as extraction directory. By default it is '_ASSET_'", ShortName = "p", LongName = "prefix")] + public string Prefix { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Execute the command recursively for all the sub-folders", ShortName = "r", LongName = "recursive")] + public bool Recursive { get; set; } + + protected void OnExecute(CommandLineApplication app) + { + var prefix = Prefix ?? DefaultPrefix; + + foreach (var filePath in GetFiles(Input, Recursive, prefix)) + { + using (var stream = File.OpenRead(filePath)) + { + HdAsset asset; + + try + { + // Avoid to crash on files that are not a ReMIX asset + asset = HdAsset.Read(stream); + } + catch + { + // Not a ReMIX asset + continue; + } + + var directoryName = Path.GetDirectoryName(filePath); + Console.Write(filePath); + + foreach (var entry in asset.Entries) + { + var outDir = Path.GetFileNameWithoutExtension(filePath); + var outFileName = Path.Combine(directoryName, $"{prefix}{outDir}", entry.Name); + Directory.CreateDirectory(Path.GetDirectoryName(outFileName)); + + using (var outStream = File.Create(outFileName)) + { + entry.Stream.Position = 0; + entry.Stream.CopyTo(outStream); + } + } + } + } + } + } + + [Command(Description = "Modify ReMIX assets by unwrapping them from their HD textures, effectly making them compatible with the original games.")] + private class StripCommand + { + [Required] + [Argument(0, Description = "Input file or directory of 1.5/2.5 ReMIX assets")] + public string Input { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Execute the command recursively for all the sub-folders", ShortName = "r", LongName = "recursive")] + public bool Recursive { get; set; } + + protected void OnExecute(CommandLineApplication app) + { + foreach (var filePath in GetFiles(Input, Recursive, DefaultPrefix)) + { + HdAsset asset; + using (var stream = File.OpenRead(filePath)) + { + + try + { + // Avoid to crash on files that are not a ReMIX asset + asset = HdAsset.Read(stream); + } + catch + { + // Not a ReMIX asset + continue; + } + } + + using (var stream = File.Create(filePath)) + asset.Stream.CopyTo(stream); + } + } + } + + private static string[] GetFiles(string input, bool recursive, string excludePrefix) + { + if (File.Exists(input)) + return new string[] { input }; + else if (Directory.Exists(input)) + return Directory.GetFiles(input, "*", + recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); + else + throw new FileNotFoundException(null, input); + } + } +} diff --git a/OpenKh.Command.IdxImg/KingdomHearts1.cs b/OpenKh.Command.IdxImg/KingdomHearts1.cs index affabd73f..1c1348af1 100644 --- a/OpenKh.Command.IdxImg/KingdomHearts1.cs +++ b/OpenKh.Command.IdxImg/KingdomHearts1.cs @@ -1,118 +1,118 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Common; -using OpenKh.Kh1; -using System; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Linq; - -namespace OpenKh.Command.IdxImg -{ - partial class Program - { - [Command("kh1", Description = "Make operation on Kingdom Hearts 1 ISO file."), - Subcommand(typeof(ExtractCommand)), - Subcommand(typeof(ListCommand))] - private class KingdomHearts1 - { - private const int IsoBlockAlign = 0x800; - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - private class ExtractCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Path to the Kingdom Hearts ISO file")] - public string InputIso { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Path where the content will be extracted", ShortName = "o", LongName = "output")] - public string OutputDir { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Do not extract files that are already found in the destination directory", ShortName = "n")] - public bool DoNotExtractAgain { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var outputDir = OutputDir ?? Path.Combine(Path.GetDirectoryName(InputIso), "extract"); - using var stream = File.OpenRead(InputIso); - - var firstBlock = IsoUtility.GetFileOffset(stream, "SYSTEM.CNF;1"); - if (firstBlock == -1) - throw new IOException("The file specified seems to not be a valid PlayStation 2 ISO."); - - var kingdomIdxBlock = IsoUtility.GetFileOffset(stream, "KINGDOM.IDX;1"); - if (kingdomIdxBlock == -1) - throw new IOException("The file specified seems to not be a Kingdom Hearts 1 ISO"); - - var idx = Idx1.Read(stream.SetPosition(kingdomIdxBlock * IsoBlockAlign)); - var img = new Img1(stream, idx, firstBlock); - - ExtractIdx(img, outputDir, DoNotExtractAgain); - return 0; - } - - public static void ExtractIdx( - Img1 img, - string basePath, - bool doNotExtractAgain) - { - foreach (var entry in img.Entries) - { - var fileName = entry.Key; - if (fileName == null) - fileName = $"@noname/{entry.Value.Hash:X08}"; - - var outputFile = Path.Combine(basePath, fileName); - if (doNotExtractAgain && File.Exists(outputFile)) - continue; - - var outputDir = Path.GetDirectoryName(outputFile); - if (Directory.Exists(outputDir) == false) - Directory.CreateDirectory(outputDir); - - Console.WriteLine(fileName); - using var file = File.Create(outputFile); - img.FileOpen(entry.Value).CopyTo(file); - } - } - } - - private class ListCommand - { - private Program Parent { get; set; } - - [Required] - [FileExists] - [Argument(0, Description = "Path to the Kingdom Hearts ISO file")] - public string InputIso { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Sort file list by their position in the ISO", ShortName = "s", LongName = "sort")] - public bool Sort { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - using var stream = File.OpenRead(InputIso); - - var firstBlock = IsoUtility.GetFileOffset(stream, "SYSTEM.CNF;1"); - if (firstBlock == -1) - throw new IOException("The file specified seems to not be a valid PlayStation 2 ISO."); - - var kingdomIdxBlock = IsoUtility.GetFileOffset(stream, "KINGDOM.IDX;1"); - if (kingdomIdxBlock == -1) - throw new IOException("The file specified seems to not be a Kingdom Hearts 1 ISO"); - - var idx = Idx1.Read(stream.SetPosition(kingdomIdxBlock * IsoBlockAlign)); - foreach (var entry in idx.OrderBy(x => x.IsoBlock)) - Console.WriteLine(Idx1Name.Lookup(entry) ?? $"@{entry.Hash:X08}"); - - return 0; - } - } - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Common; +using OpenKh.Kh1; +using System; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; + +namespace OpenKh.Command.IdxImg +{ + partial class Program + { + [Command("kh1", Description = "Make operation on Kingdom Hearts 1 ISO file."), + Subcommand(typeof(ExtractCommand)), + Subcommand(typeof(ListCommand))] + private class KingdomHearts1 + { + private const int IsoBlockAlign = 0x800; + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + private class ExtractCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Path to the Kingdom Hearts ISO file")] + public string InputIso { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Path where the content will be extracted", ShortName = "o", LongName = "output")] + public string OutputDir { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Do not extract files that are already found in the destination directory", ShortName = "n")] + public bool DoNotExtractAgain { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var outputDir = OutputDir ?? Path.Combine(Path.GetDirectoryName(InputIso), "extract"); + using var stream = File.OpenRead(InputIso); + + var firstBlock = IsoUtility.GetFileOffset(stream, "SYSTEM.CNF;1"); + if (firstBlock == -1) + throw new IOException("The file specified seems to not be a valid PlayStation 2 ISO."); + + var kingdomIdxBlock = IsoUtility.GetFileOffset(stream, "KINGDOM.IDX;1"); + if (kingdomIdxBlock == -1) + throw new IOException("The file specified seems to not be a Kingdom Hearts 1 ISO"); + + var idx = Idx1.Read(stream.SetPosition(kingdomIdxBlock * IsoBlockAlign)); + var img = new Img1(stream, idx, firstBlock); + + ExtractIdx(img, outputDir, DoNotExtractAgain); + return 0; + } + + public static void ExtractIdx( + Img1 img, + string basePath, + bool doNotExtractAgain) + { + foreach (var entry in img.Entries) + { + var fileName = entry.Key; + if (fileName == null) + fileName = $"@noname/{entry.Value.Hash:X08}"; + + var outputFile = Path.Combine(basePath, fileName); + if (doNotExtractAgain && File.Exists(outputFile)) + continue; + + var outputDir = Path.GetDirectoryName(outputFile); + if (Directory.Exists(outputDir) == false) + Directory.CreateDirectory(outputDir); + + Console.WriteLine(fileName); + using var file = File.Create(outputFile); + img.FileOpen(entry.Value).CopyTo(file); + } + } + } + + private class ListCommand + { + private Program Parent { get; set; } + + [Required] + [FileExists] + [Argument(0, Description = "Path to the Kingdom Hearts ISO file")] + public string InputIso { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Sort file list by their position in the ISO", ShortName = "s", LongName = "sort")] + public bool Sort { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + using var stream = File.OpenRead(InputIso); + + var firstBlock = IsoUtility.GetFileOffset(stream, "SYSTEM.CNF;1"); + if (firstBlock == -1) + throw new IOException("The file specified seems to not be a valid PlayStation 2 ISO."); + + var kingdomIdxBlock = IsoUtility.GetFileOffset(stream, "KINGDOM.IDX;1"); + if (kingdomIdxBlock == -1) + throw new IOException("The file specified seems to not be a Kingdom Hearts 1 ISO"); + + var idx = Idx1.Read(stream.SetPosition(kingdomIdxBlock * IsoBlockAlign)); + foreach (var entry in idx.OrderBy(x => x.IsoBlock)) + Console.WriteLine(Idx1Name.Lookup(entry) ?? $"@{entry.Hash:X08}"); + + return 0; + } + } + } + } +} diff --git a/OpenKh.Command.IdxImg/KingdomHearts2.cs b/OpenKh.Command.IdxImg/KingdomHearts2.cs index 33864ec21..c0e21c5b7 100644 --- a/OpenKh.Command.IdxImg/KingdomHearts2.cs +++ b/OpenKh.Command.IdxImg/KingdomHearts2.cs @@ -1,272 +1,272 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Common; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Linq; -using Xe.IO; - -namespace OpenKh.Command.IdxImg -{ - partial class Program - { - [Command("kh2", Description = "Make operation on Kingdom Hearts 2 ISO/IDX files."), - Subcommand(typeof(ExtractCommand)), - Subcommand(typeof(InjectCommand)), - Subcommand(typeof(ListCommand))] - private class KingdomHearts2 - { - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - private class ExtractCommand - { - private Program Parent { get; set; } - - [Required] - [FileExists] - [Argument(0, Description = "Kingdom Hearts II IDX file")] - public string InputIdx { get; set; } - - [FileExists] - [Option(CommandOptionType.SingleValue, Description = "Custom Kingdom Hearts II IMG file", ShortName = "m", LongName = "img")] - public string InputImg { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Path where the content will be extracted", ShortName = "o", LongName = "output")] - public string OutputDir { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Extract all the sub-IDX recursively", ShortName = "r", LongName = "recursive")] - public bool Recursive { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Split sub-IDX when extracting recursively", ShortName = "s", LongName = "split")] - public bool Split { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Do not extract files that are already found in the destination directory", ShortName = "n")] - public bool DoNotExtractAgain { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var inputImg = InputImg ?? InputIdx.Replace(".idx", ".img", StringComparison.InvariantCultureIgnoreCase); - var outputDir = OutputDir ?? Path.Combine(Path.GetDirectoryName(inputImg), "extract"); - - var idxEntries = OpenIdx(InputIdx); - - using (var imgStream = File.OpenRead(inputImg)) - { - var img = new Img(imgStream, idxEntries, false); - var idxName = Path.GetFileNameWithoutExtension(InputIdx); - - var subIdxPath = ExtractIdx( - img, - idxEntries, - Recursive && Split ? Path.Combine(outputDir, "KH2") : outputDir, - DoNotExtractAgain); - if (Recursive) - { - foreach (var idxFileName in subIdxPath) - { - idxName = Path.GetFileNameWithoutExtension(idxFileName); - ExtractIdx( - img, - OpenIdx(idxFileName), - Split ? Path.Combine(outputDir, idxName) : outputDir, - DoNotExtractAgain); - } - } - } - - return 0; - } - - public static List ExtractIdx( - Img img, - IEnumerable idxEntries, - string basePath, - bool doNotExtractAgain) - { - var idxs = new List(); - - foreach (var entry in idxEntries) - { - var fileName = IdxName.Lookup(entry); - if (fileName == null) - fileName = $"@noname/{entry.Hash32:X08}-{entry.Hash16:X04}"; - - var outputFile = Path.Combine(basePath, fileName); - if (doNotExtractAgain && File.Exists(outputFile)) - continue; - - var outputDir = Path.GetDirectoryName(outputFile); - if (Directory.Exists(outputDir) == false) - Directory.CreateDirectory(outputDir); - - Console.WriteLine(fileName); - using (var file = File.Create(outputFile)) - img.FileOpen(entry).CopyTo(file); - - if (Path.GetExtension(fileName) == ".idx") - idxs.Add(outputFile); - } - - return idxs; - } - } - - private class ListCommand - { - private Program Parent { get; set; } - - [Required] - [FileExists] - [Argument(0, Description = "Kingdom Hearts II IDX file, paired with a IMG")] - public string InputIdx { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Sort file list by their position in the IMG", ShortName = "s", LongName = "sort")] - public bool Sort { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var entries = OpenIdx(InputIdx); - if (Sort) - entries = entries.OrderBy(x => x.Offset); - - foreach (var entry in entries) - Console.WriteLine(IdxName.Lookup(entry) ?? $"@{entry.Hash32:X08}-{entry.Hash16:X04}"); - - return 0; - } - } - - [Command(Description = "Patch an ISO by injecting a single file in the IMG, without repacking. Useful for quick testing.")] - private class InjectCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Kingdom Hearts II ISO file that contains the game files")] - public string InputIso { get; set; } - - [Required] - [FileExists] - [Argument(1, Description = "File to inject")] - public string InputFile { get; set; } - - [Required] - [Argument(2, Description = "IDX file path (eg. msg/jp/sys.bar)")] - public string FilePath { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Do not compress the file to inject", ShortName = "u", LongName = "uncompressed")] - public bool Uncompressed { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "ISO block for KH2.IDX. Determined automatically by default.", ShortName = "idx", LongName = "idx-offset")] - public int IdxIsoBlock { get; set; } = -1; - - [Option(CommandOptionType.SingleValue, Description = "ISO block for KH2.IMG. Determined automatically by default", ShortName = "img", LongName = "img-offset")] - public int ImgIsoBlock { get; set; } = -1; - - protected int OnExecute(CommandLineApplication app) - { - const long EsitmatedMaximumImgFileSize = 4L * 1024 * 1024 * 1024; // 4GB - const int EsitmatedMaximumIdxFileSize = 600 * 1024; // 600KB - const int EstimatedMaximumIdxEntryAmountToBeValid = EsitmatedMaximumIdxFileSize / 0x10 - 4; - - using var isoStream = File.Open(InputIso, FileMode.Open, FileAccess.ReadWrite); - - - if (IdxIsoBlock == -1 || ImgIsoBlock == -1) - { - var bufferedStream = new BufferedStream(isoStream); - IdxIsoBlock = IsoUtility.GetFileOffset(bufferedStream, "KH2.IDX;1"); - ImgIsoBlock = IsoUtility.GetFileOffset(bufferedStream, "KH2.IMG;1"); - - if (IdxIsoBlock == -1 || ImgIsoBlock == -1) - throw new IOException("Could not determine the LBA Offsets of KH2.IDX or KH2.IMG, is this ISO valid?"); - } - - var idxStream = OpenIsoSubStream(isoStream, IdxIsoBlock, EsitmatedMaximumIdxFileSize); - using var imgStream = OpenIsoSubStream(isoStream, ImgIsoBlock, EsitmatedMaximumImgFileSize); - - var idxEntryCount = idxStream.ReadInt32(); - if (idxEntryCount > EstimatedMaximumIdxEntryAmountToBeValid) - throw new CustomException("There is a high chance that the IDX block is not valid, therefore the injection will terminate to avoid corruption."); - - var idxEntries = Idx.Read(idxStream.SetPosition(0)); - var entry = idxEntries.FirstOrDefault(x => x.Hash32 == Idx.GetHash32(FilePath) && x.Hash16 == Idx.GetHash16(FilePath)); - if (entry == null) - { - idxStream = GetIdxStreamWhichContainsTargetedFile(idxEntries, imgStream, FilePath); - if (idxStream == null) - throw new CustomException($"The file {FilePath} has not been found inside the KH2.IDX, therefore the injection will terminate."); - - idxEntries = Idx.Read(idxStream.SetPosition(0)); - entry = idxEntries.FirstOrDefault(x => x.Hash32 == Idx.GetHash32(FilePath) && x.Hash16 == Idx.GetHash16(FilePath)); - } - - var inputData = File.ReadAllBytes(InputFile); - var decompressedLength = inputData.Length; - if (Uncompressed == false) - inputData = Img.Compress(inputData); - - var blockCountRequired = (inputData.Length + 0x7ff) / 0x800 - 1; - if (blockCountRequired > entry.BlockLength) - throw new CustomException($"The file to inject is too big: the actual is {inputData.Length} but the maximum allowed is {GetLength(entry.BlockLength)}."); - - imgStream.SetPosition(GetOffset(entry.Offset)); - // Clean completely the content of the previous file to not mess up the decompression - imgStream.Write(new byte[GetLength(entry.BlockLength)]); - - imgStream.SetPosition(GetOffset(entry.Offset)); - imgStream.Write(inputData); - - entry.IsCompressed = !Uncompressed; - entry.Length = decompressedLength; - // we are intentionally not patching entry.BlockLength because it would not allow to insert back bigger files. - - Idx.Write(idxStream.SetPosition(0), idxEntries); - - return 0; - } - - private Stream GetIdxStreamWhichContainsTargetedFile(List idxEntries, Stream imgStream, string fileName) - { - var idxDictionary = new IdxDictionary { idxEntries }; - - foreach (var innerIdx in Img.InternalIdxs) - { - if (idxDictionary.TryGetEntry(innerIdx, out var innerIdxEntry)) - { - var innerIdxStream = OpenIsoSubStream(imgStream, innerIdxEntry.Offset, innerIdxEntry.Length); - var innerIdxDictionary = new IdxDictionary - { - Idx.Read(innerIdxStream) - }; - - if (innerIdxDictionary.Exists(fileName)) - return innerIdxStream; - } - } - - return null; - } - - private static Stream OpenIsoSubStream(Stream isoStream, long blockOffset, long length) => - new SubStream(isoStream, blockOffset * 0x800, length); - private static long GetOffset(long blockOffset) => blockOffset * 0x800; - private static int GetLength(int blockLength) => blockLength * 0x800 + 0x800; - } - - private static IEnumerable OpenIdx(string fileName) - { - using var idxStream = File.OpenRead(fileName); - if (!Idx.IsValid(idxStream)) - throw new CustomException($"The IDX {fileName} is invalid or not recognized."); - - return Idx.Read(idxStream); - } - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Common; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; +using Xe.IO; + +namespace OpenKh.Command.IdxImg +{ + partial class Program + { + [Command("kh2", Description = "Make operation on Kingdom Hearts 2 ISO/IDX files."), + Subcommand(typeof(ExtractCommand)), + Subcommand(typeof(InjectCommand)), + Subcommand(typeof(ListCommand))] + private class KingdomHearts2 + { + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + private class ExtractCommand + { + private Program Parent { get; set; } + + [Required] + [FileExists] + [Argument(0, Description = "Kingdom Hearts II IDX file")] + public string InputIdx { get; set; } + + [FileExists] + [Option(CommandOptionType.SingleValue, Description = "Custom Kingdom Hearts II IMG file", ShortName = "m", LongName = "img")] + public string InputImg { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Path where the content will be extracted", ShortName = "o", LongName = "output")] + public string OutputDir { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Extract all the sub-IDX recursively", ShortName = "r", LongName = "recursive")] + public bool Recursive { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Split sub-IDX when extracting recursively", ShortName = "s", LongName = "split")] + public bool Split { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Do not extract files that are already found in the destination directory", ShortName = "n")] + public bool DoNotExtractAgain { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var inputImg = InputImg ?? InputIdx.Replace(".idx", ".img", StringComparison.InvariantCultureIgnoreCase); + var outputDir = OutputDir ?? Path.Combine(Path.GetDirectoryName(inputImg), "extract"); + + var idxEntries = OpenIdx(InputIdx); + + using (var imgStream = File.OpenRead(inputImg)) + { + var img = new Img(imgStream, idxEntries, false); + var idxName = Path.GetFileNameWithoutExtension(InputIdx); + + var subIdxPath = ExtractIdx( + img, + idxEntries, + Recursive && Split ? Path.Combine(outputDir, "KH2") : outputDir, + DoNotExtractAgain); + if (Recursive) + { + foreach (var idxFileName in subIdxPath) + { + idxName = Path.GetFileNameWithoutExtension(idxFileName); + ExtractIdx( + img, + OpenIdx(idxFileName), + Split ? Path.Combine(outputDir, idxName) : outputDir, + DoNotExtractAgain); + } + } + } + + return 0; + } + + public static List ExtractIdx( + Img img, + IEnumerable idxEntries, + string basePath, + bool doNotExtractAgain) + { + var idxs = new List(); + + foreach (var entry in idxEntries) + { + var fileName = IdxName.Lookup(entry); + if (fileName == null) + fileName = $"@noname/{entry.Hash32:X08}-{entry.Hash16:X04}"; + + var outputFile = Path.Combine(basePath, fileName); + if (doNotExtractAgain && File.Exists(outputFile)) + continue; + + var outputDir = Path.GetDirectoryName(outputFile); + if (Directory.Exists(outputDir) == false) + Directory.CreateDirectory(outputDir); + + Console.WriteLine(fileName); + using (var file = File.Create(outputFile)) + img.FileOpen(entry).CopyTo(file); + + if (Path.GetExtension(fileName) == ".idx") + idxs.Add(outputFile); + } + + return idxs; + } + } + + private class ListCommand + { + private Program Parent { get; set; } + + [Required] + [FileExists] + [Argument(0, Description = "Kingdom Hearts II IDX file, paired with a IMG")] + public string InputIdx { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Sort file list by their position in the IMG", ShortName = "s", LongName = "sort")] + public bool Sort { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var entries = OpenIdx(InputIdx); + if (Sort) + entries = entries.OrderBy(x => x.Offset); + + foreach (var entry in entries) + Console.WriteLine(IdxName.Lookup(entry) ?? $"@{entry.Hash32:X08}-{entry.Hash16:X04}"); + + return 0; + } + } + + [Command(Description = "Patch an ISO by injecting a single file in the IMG, without repacking. Useful for quick testing.")] + private class InjectCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Kingdom Hearts II ISO file that contains the game files")] + public string InputIso { get; set; } + + [Required] + [FileExists] + [Argument(1, Description = "File to inject")] + public string InputFile { get; set; } + + [Required] + [Argument(2, Description = "IDX file path (eg. msg/jp/sys.bar)")] + public string FilePath { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Do not compress the file to inject", ShortName = "u", LongName = "uncompressed")] + public bool Uncompressed { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "ISO block for KH2.IDX. Determined automatically by default.", ShortName = "idx", LongName = "idx-offset")] + public int IdxIsoBlock { get; set; } = -1; + + [Option(CommandOptionType.SingleValue, Description = "ISO block for KH2.IMG. Determined automatically by default", ShortName = "img", LongName = "img-offset")] + public int ImgIsoBlock { get; set; } = -1; + + protected int OnExecute(CommandLineApplication app) + { + const long EsitmatedMaximumImgFileSize = 4L * 1024 * 1024 * 1024; // 4GB + const int EsitmatedMaximumIdxFileSize = 600 * 1024; // 600KB + const int EstimatedMaximumIdxEntryAmountToBeValid = EsitmatedMaximumIdxFileSize / 0x10 - 4; + + using var isoStream = File.Open(InputIso, FileMode.Open, FileAccess.ReadWrite); + + + if (IdxIsoBlock == -1 || ImgIsoBlock == -1) + { + var bufferedStream = new BufferedStream(isoStream); + IdxIsoBlock = IsoUtility.GetFileOffset(bufferedStream, "KH2.IDX;1"); + ImgIsoBlock = IsoUtility.GetFileOffset(bufferedStream, "KH2.IMG;1"); + + if (IdxIsoBlock == -1 || ImgIsoBlock == -1) + throw new IOException("Could not determine the LBA Offsets of KH2.IDX or KH2.IMG, is this ISO valid?"); + } + + var idxStream = OpenIsoSubStream(isoStream, IdxIsoBlock, EsitmatedMaximumIdxFileSize); + using var imgStream = OpenIsoSubStream(isoStream, ImgIsoBlock, EsitmatedMaximumImgFileSize); + + var idxEntryCount = idxStream.ReadInt32(); + if (idxEntryCount > EstimatedMaximumIdxEntryAmountToBeValid) + throw new CustomException("There is a high chance that the IDX block is not valid, therefore the injection will terminate to avoid corruption."); + + var idxEntries = Idx.Read(idxStream.SetPosition(0)); + var entry = idxEntries.FirstOrDefault(x => x.Hash32 == Idx.GetHash32(FilePath) && x.Hash16 == Idx.GetHash16(FilePath)); + if (entry == null) + { + idxStream = GetIdxStreamWhichContainsTargetedFile(idxEntries, imgStream, FilePath); + if (idxStream == null) + throw new CustomException($"The file {FilePath} has not been found inside the KH2.IDX, therefore the injection will terminate."); + + idxEntries = Idx.Read(idxStream.SetPosition(0)); + entry = idxEntries.FirstOrDefault(x => x.Hash32 == Idx.GetHash32(FilePath) && x.Hash16 == Idx.GetHash16(FilePath)); + } + + var inputData = File.ReadAllBytes(InputFile); + var decompressedLength = inputData.Length; + if (Uncompressed == false) + inputData = Img.Compress(inputData); + + var blockCountRequired = (inputData.Length + 0x7ff) / 0x800 - 1; + if (blockCountRequired > entry.BlockLength) + throw new CustomException($"The file to inject is too big: the actual is {inputData.Length} but the maximum allowed is {GetLength(entry.BlockLength)}."); + + imgStream.SetPosition(GetOffset(entry.Offset)); + // Clean completely the content of the previous file to not mess up the decompression + imgStream.Write(new byte[GetLength(entry.BlockLength)]); + + imgStream.SetPosition(GetOffset(entry.Offset)); + imgStream.Write(inputData); + + entry.IsCompressed = !Uncompressed; + entry.Length = decompressedLength; + // we are intentionally not patching entry.BlockLength because it would not allow to insert back bigger files. + + Idx.Write(idxStream.SetPosition(0), idxEntries); + + return 0; + } + + private Stream GetIdxStreamWhichContainsTargetedFile(List idxEntries, Stream imgStream, string fileName) + { + var idxDictionary = new IdxDictionary { idxEntries }; + + foreach (var innerIdx in Img.InternalIdxs) + { + if (idxDictionary.TryGetEntry(innerIdx, out var innerIdxEntry)) + { + var innerIdxStream = OpenIsoSubStream(imgStream, innerIdxEntry.Offset, innerIdxEntry.Length); + var innerIdxDictionary = new IdxDictionary + { + Idx.Read(innerIdxStream) + }; + + if (innerIdxDictionary.Exists(fileName)) + return innerIdxStream; + } + } + + return null; + } + + private static Stream OpenIsoSubStream(Stream isoStream, long blockOffset, long length) => + new SubStream(isoStream, blockOffset * 0x800, length); + private static long GetOffset(long blockOffset) => blockOffset * 0x800; + private static int GetLength(int blockLength) => blockLength * 0x800 + 0x800; + } + + private static IEnumerable OpenIdx(string fileName) + { + using var idxStream = File.OpenRead(fileName); + if (!Idx.IsValid(idxStream)) + throw new CustomException($"The IDX {fileName} is invalid or not recognized."); + + return Idx.Read(idxStream); + } + } + } +} diff --git a/OpenKh.Command.IdxImg/Program.cs b/OpenKh.Command.IdxImg/Program.cs index 8888e3251..848b842f5 100644 --- a/OpenKh.Command.IdxImg/Program.cs +++ b/OpenKh.Command.IdxImg/Program.cs @@ -1,52 +1,52 @@ -using McMaster.Extensions.CommandLineUtils; -using System; -using System.IO; -using System.Reflection; - -namespace OpenKh.Command.IdxImg -{ - [Command("OpenKh.Command.IdxImg")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - [Subcommand(typeof(KingdomHearts1), typeof(KingdomHearts2))] - partial class Program - { - class CustomException : Exception - { - public CustomException(string message) : - base(message) - { } - } - - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - return 2; - } - catch (CustomException e) - { - Console.WriteLine(e.Message); - return 1; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return -1; - } - } - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - } -} +using McMaster.Extensions.CommandLineUtils; +using System; +using System.IO; +using System.Reflection; + +namespace OpenKh.Command.IdxImg +{ + [Command("OpenKh.Command.IdxImg")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + [Subcommand(typeof(KingdomHearts1), typeof(KingdomHearts2))] + partial class Program + { + class CustomException : Exception + { + public CustomException(string message) : + base(message) + { } + } + + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + return 2; + } + catch (CustomException e) + { + Console.WriteLine(e.Message); + return 1; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return -1; + } + } + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + } +} diff --git a/OpenKh.Command.ImgTool/Interfaces/ICommonQuantizerParam.cs b/OpenKh.Command.ImgTool/Interfaces/ICommonQuantizerParam.cs index a46f3cebf..b8031cdd1 100644 --- a/OpenKh.Command.ImgTool/Interfaces/ICommonQuantizerParam.cs +++ b/OpenKh.Command.ImgTool/Interfaces/ICommonQuantizerParam.cs @@ -1,19 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Command.ImgTool.Interfaces -{ - public interface ICommonQuantizerParam - { - /// - /// 4 or 8 - /// - public int BitsPerPixel { get; } - - /// - /// Invoke pngquant.exe, if true - /// - public bool PngQuant { get; } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Command.ImgTool.Interfaces +{ + public interface ICommonQuantizerParam + { + /// + /// 4 or 8 + /// + public int BitsPerPixel { get; } + + /// + /// Invoke pngquant.exe, if true + /// + public bool PngQuant { get; } + } +} diff --git a/OpenKh.Command.ImgTool/Program.cs b/OpenKh.Command.ImgTool/Program.cs index add2ece70..431fc0291 100644 --- a/OpenKh.Command.ImgTool/Program.cs +++ b/OpenKh.Command.ImgTool/Program.cs @@ -1,486 +1,486 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Command.ImgTool.Interfaces; -using OpenKh.Command.ImgTool.Utils; -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Kh2.Utils; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Net.Http.Headers; -using System.Reflection; -using System.Text; -using System.Text.Json; -using System.Text.Json.Serialization; -using System.Threading.Tasks.Dataflow; - -namespace OpenKh.Command.ImgTool -{ - [Command("OpenKh.Command.ImgTool")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - [Subcommand(typeof(UnimdCommand), typeof(UnimzCommand), typeof(ImdCommand), typeof(ImzCommand) - , typeof(ScanImdCommand), typeof(ScanImzCommand) - , typeof(FixImzCommand), typeof(SwapImzPixelCommand))] - class Program - { - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - return 1; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return 1; - } - } - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - [HelpOption] - [Command(Description = "imd file -> png file")] - private class UnimdCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Input imd")] - public string ImdFile { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Output png. Default is current dir, and file extension to png.", ShortName = "o", LongName = "output")] - public string OutputPng { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var inputFile = ImdFile; - var outputFile = OutputPng ?? Path.GetFullPath(Path.GetFileName(Path.ChangeExtension(inputFile, ".png"))); - - Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); - - using (var stream = File.OpenRead(inputFile)) - { - var imgd = Imgd.Read(stream); - var bitmap = ImgdBitmapUtil.ToBitmap(imgd); - bitmap.Save(outputFile); - } - return 0; - } - } - - [HelpOption] - [Command(Description = "imz file -> png or imd files")] - private class UnimzCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Input imz")] - public string ImzFile { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Output dir. Default is current dir.", ShortName = "o", LongName = "output")] - public string OutputDir { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Export as imd instead of png", ShortName = "m", LongName = "imd")] - public bool ExportImd { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var inputFile = ImzFile; - var outputDir = OutputDir ?? Environment.CurrentDirectory; - - using (var stream = File.OpenRead(inputFile)) - { - var pairs = Imgz.Read(stream).Select((imgd, index) => (imgd, index)); - - Directory.CreateDirectory(outputDir); - - foreach (var (imgd, index) in pairs) - { - if (ExportImd) - { - var outputFile = Path.Combine(outputDir, $"{Path.GetFileNameWithoutExtension(inputFile)}-{1 + index}.imd"); - - var buffer = new MemoryStream(); - imgd.Write(buffer); - File.WriteAllBytes(outputFile, buffer.ToArray()); - } - else - { - var outputFile = Path.Combine(outputDir, $"{Path.GetFileNameWithoutExtension(inputFile)}-{1 + index}.png"); - - var bitmap = ImgdBitmapUtil.ToBitmap(imgd); - bitmap.Save(outputFile); - } - } - } - return 0; - } - } - - [HelpOption] - [Command(Description = "png file -> imd file")] - private class ImdCommand : ICommonQuantizerParam - { - [Required] - [FileExists] - [Argument(0, Description = "Input png")] - public string PngFile { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Output imd. Default is current dir, and file extension to imd.", ShortName = "o", LongName = "output")] - public string OutputImd { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Set bits per pixel: 4, 8, or 32", ShortName = "b", LongName = "bpp")] - public int BitsPerPixel { get; set; } = 8; - - [Option(CommandOptionType.NoValue, Description = "Use `pngquant.exe` -- lossy PNG compressor. Download `pngquant.exe` and place it beside this program, current directory, or PATH.", ShortName = "p", LongName = "pngquant")] - public bool PngQuant { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Use embedded nQuant.Core color quantizer. This is default selection.", ShortName = "n", LongName = "nquant")] - public bool nQuant { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Enable swizzle.", ShortName = "s", LongName = "swizzle")] - public bool Swizzle { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var inputFile = PngFile; - var outputFile = OutputImd ?? Path.GetFullPath(Path.GetFileName(Path.ChangeExtension(inputFile, ".imd"))); - - Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); - - // Alpha enabled png → always 32 bpp - using (var bitmap = new Bitmap(inputFile)) - { - var imgd = ImgdBitmapUtil.ToImgd(bitmap, BitsPerPixel, QuantizerFactory.MakeFrom(this), Swizzle); - - var buffer = new MemoryStream(); - imgd.Write(buffer); - File.WriteAllBytes(outputFile, buffer.ToArray()); - } - return 0; - } - } - - [HelpOption] - [Command(Description = "png, imd or imz files -> imz file")] - private class ImzCommand : ICommonQuantizerParam - { - [Required] - [Option(CommandOptionType.MultipleValue, Description = "Input png/imd/imz file", ShortName = "i", LongName = "input")] - public string[] InputFile { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Output imz file. Default is current dir, and first file extension to imz.", ShortName = "o", LongName = "output")] - public string OutputImz { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Set bits per pixel for every png: 4, 8, or 32", ShortName = "b", LongName = "bpp")] - public int BitsPerPixel { get; set; } = 8; - - [Option(CommandOptionType.NoValue, Description = "Use `pngquant.exe` -- lossy PNG compressor. Download `pngquant.exe` and deploy it beside this program, current directory, or PATH.", ShortName = "p", LongName = "pngquant")] - public bool PngQuant { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Use embedded nQuant.Core color quantizer. This is default selection.", ShortName = "n", LongName = "nquant")] - public bool nQuant { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Try to append to imz", ShortName = "a", LongName = "append")] - public bool Append { get; set; } - - [Option(CommandOptionType.NoValue, Description = "Enable swizzle for png input.", ShortName = "s", LongName = "swizzle")] - public bool Swizzle { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - OutputImz = OutputImz ?? Path.GetFullPath(Path.GetFileName(Path.ChangeExtension(InputFile.First(), ".imz"))); - - Directory.CreateDirectory(Path.GetDirectoryName(OutputImz)); - - var prependImgdList = (Append && File.Exists(OutputImz)) - ? File.OpenRead(OutputImz).Using(stream => Imgz.Read(stream).ToArray()) - : new Imgd[0]; - - var buffer = new MemoryStream(); - Imgz.Write( - buffer, - prependImgdList - .Concat( - InputFile - .SelectMany(imdFile => ImgdBitmapUtil.FromFileToImgdList(imdFile, BitsPerPixel, QuantizerFactory.MakeFrom(this), Swizzle)) - ) - .ToArray() - ); - File.WriteAllBytes(OutputImz, buffer.ToArray()); - - return 0; - } - } - - [HelpOption] - [Command(Description = "imd file -> display summary")] - private class ScanImdCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Input imd file")] - public string InputFile { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var target = File.OpenRead(InputFile).Using(stream => Imgd.Read(stream)); - - Console.WriteLine( - FormatterFactory.GetFormatterPairs() - .First() - .FormatToString(ImgdSummary.From(target)) - ); - - return 0; - } - } - - [HelpOption] - [Command(Description = "imz file -> display summary")] - private class ScanImzCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Input imz file")] - public string InputFile { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - var targets = File.OpenRead(InputFile).Using(stream => Imgz.Read(stream).ToArray()); - - Console.WriteLine( - FormatterFactory.GetFormatterPairs() - .First() - .FormatToString( - targets - .Select(one => ImgdSummary.From(one)) - .Select((one, index) => (one, index)) - .ToDictionary( - pair => pair.index.ToString(), - pair => pair.one - ) - ) - ); - - return 0; - } - } - - class FormatterPair - { - internal string Type; - internal Func FormatToString; - } - - class FormatterFactory - { - internal static IEnumerable GetFormatterPairs() => new FormatterPair[] - { - new FormatterPair - { - Type = "yaml", - FormatToString = - (obj) => new YamlDotNet.Serialization.SerializerBuilder() - .Build() - .Serialize(obj), - }, - new FormatterPair - { - Type = "json", - FormatToString = - (obj) => JsonSerializer.Serialize( - obj, - new JsonSerializerOptions - { - WriteIndented = true - } - ), - }, - }; - } - - class ImgdSanityChecking - { - internal static int? GetExpectedDataLen(Imgd it) - { - switch (it.PixelFormat) - { - case Imaging.PixelFormat.Indexed4: - return (it.Size.Width * it.Size.Height + 1) / 2; - case Imaging.PixelFormat.Indexed8: - return (it.Size.Width * it.Size.Height); - case Imaging.PixelFormat.Rgb888: - return (3 * it.Size.Width * it.Size.Height); - case Imaging.PixelFormat.Rgba8888: - case Imaging.PixelFormat.Rgbx8888: - return (4 * it.Size.Width * it.Size.Height); - } - return null; - } - } - - class ImgdSummary - { - public string PixelFormat { get; private set; } - public int Width { get; private set; } - public int Height { get; private set; } - public bool IsSwizzled { get; private set; } - public int? ExpectedDataLen { get; private set; } - public int ActualDataLen { get; private set; } - public int? ActualClutLen { get; private set; } - - internal static ImgdSummary From(Imgd it) - { - return new ImgdSummary - { - PixelFormat = it.PixelFormat.ToString(), - Width = it.Size.Width, - Height = it.Size.Height, - IsSwizzled = it.IsSwizzled, - ExpectedDataLen = ImgdSanityChecking.GetExpectedDataLen(it), - ActualDataLen = it.Data.Length, - ActualClutLen = it.Clut?.Length, - }; - } - } - - [HelpOption] - [Command(Description = "imz file -> imz file (fix 4-bpp doubled bitmap size)")] - private class FixImzCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Input (and output) imz file")] - public string InputFile { get; set; } - - [Option(CommandOptionType.SingleOrNoValue, Description = "Output imz file. Default is input imz.", ShortName = "o", LongName = "output")] - public string OutputImz { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - OutputImz = OutputImz ?? InputFile; - - Directory.CreateDirectory(Path.GetDirectoryName(OutputImz)); - - var images = File.OpenRead(OutputImz).Using(stream => Imgz.Read(stream).ToArray()); - - var fixedCount = 0; - - var fixedImages = images - .Select( - image => - { - var expetectedLen = ImgdSanityChecking.GetExpectedDataLen(image); - if (true - && expetectedLen != null - && expetectedLen < image.Data.Length - && Imaging.PixelFormat.Indexed4 == image.PixelFormat - ) - { - var fixedData = new byte[expetectedLen.Value]; - - Buffer.BlockCopy(image.Data, 0, fixedData, 0, expetectedLen.Value); - - fixedCount++; - - return new Imgd( - image.Size, - image.PixelFormat, - fixedData, - image.Clut, - isSwizzled: false - ); - } - else - { - return image; - } - } - ) - .ToArray(); - - var buffer = new MemoryStream(); - - Imgz.Write(buffer, fixedImages); - - File.WriteAllBytes(OutputImz, buffer.ToArray()); - - Console.WriteLine($"Fixed {fixedCount} images."); - - return 0; - } - } - - [HelpOption] - [Command(Description = "imz file -> imz file (swap 4-bpp hi/lo pixel)")] - private class SwapImzPixelCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Input (and output) imz file")] - public string InputFile { get; set; } - - [Option(CommandOptionType.SingleOrNoValue, Description = "Output imz file. Default is input imz.", ShortName = "o", LongName = "output")] - public string OutputImz { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - OutputImz = OutputImz ?? InputFile; - - Directory.CreateDirectory(Path.GetDirectoryName(OutputImz)); - - var images = File.OpenRead(OutputImz).Using(stream => Imgz.Read(stream).ToArray()); - - var fixedCount = 0; - - var fixedImages = images - .Select( - image => - { - if (Imaging.PixelFormat.Indexed4 == image.PixelFormat) - { - var data = image.Data; - - for (var x = 0; x < data.Length; x++) - { - var swap = data[x]; - data[x] = (byte)((swap << 4) | (swap >> 4)); - } - - fixedCount++; - } - return image; - } - ) - .ToArray(); - - var buffer = new MemoryStream(); - - Imgz.Write(buffer, fixedImages); - - File.WriteAllBytes(OutputImz, buffer.ToArray()); - - Console.WriteLine($"Applied to {fixedCount} images."); - - return 0; - } - } - - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Command.ImgTool.Interfaces; +using OpenKh.Command.ImgTool.Utils; +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Kh2.Utils; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Net.Http.Headers; +using System.Reflection; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Threading.Tasks.Dataflow; + +namespace OpenKh.Command.ImgTool +{ + [Command("OpenKh.Command.ImgTool")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + [Subcommand(typeof(UnimdCommand), typeof(UnimzCommand), typeof(ImdCommand), typeof(ImzCommand) + , typeof(ScanImdCommand), typeof(ScanImzCommand) + , typeof(FixImzCommand), typeof(SwapImzPixelCommand))] + class Program + { + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + return 1; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return 1; + } + } + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + [HelpOption] + [Command(Description = "imd file -> png file")] + private class UnimdCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Input imd")] + public string ImdFile { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Output png. Default is current dir, and file extension to png.", ShortName = "o", LongName = "output")] + public string OutputPng { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var inputFile = ImdFile; + var outputFile = OutputPng ?? Path.GetFullPath(Path.GetFileName(Path.ChangeExtension(inputFile, ".png"))); + + Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); + + using (var stream = File.OpenRead(inputFile)) + { + var imgd = Imgd.Read(stream); + var bitmap = ImgdBitmapUtil.ToBitmap(imgd); + bitmap.Save(outputFile); + } + return 0; + } + } + + [HelpOption] + [Command(Description = "imz file -> png or imd files")] + private class UnimzCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Input imz")] + public string ImzFile { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Output dir. Default is current dir.", ShortName = "o", LongName = "output")] + public string OutputDir { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Export as imd instead of png", ShortName = "m", LongName = "imd")] + public bool ExportImd { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var inputFile = ImzFile; + var outputDir = OutputDir ?? Environment.CurrentDirectory; + + using (var stream = File.OpenRead(inputFile)) + { + var pairs = Imgz.Read(stream).Select((imgd, index) => (imgd, index)); + + Directory.CreateDirectory(outputDir); + + foreach (var (imgd, index) in pairs) + { + if (ExportImd) + { + var outputFile = Path.Combine(outputDir, $"{Path.GetFileNameWithoutExtension(inputFile)}-{1 + index}.imd"); + + var buffer = new MemoryStream(); + imgd.Write(buffer); + File.WriteAllBytes(outputFile, buffer.ToArray()); + } + else + { + var outputFile = Path.Combine(outputDir, $"{Path.GetFileNameWithoutExtension(inputFile)}-{1 + index}.png"); + + var bitmap = ImgdBitmapUtil.ToBitmap(imgd); + bitmap.Save(outputFile); + } + } + } + return 0; + } + } + + [HelpOption] + [Command(Description = "png file -> imd file")] + private class ImdCommand : ICommonQuantizerParam + { + [Required] + [FileExists] + [Argument(0, Description = "Input png")] + public string PngFile { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Output imd. Default is current dir, and file extension to imd.", ShortName = "o", LongName = "output")] + public string OutputImd { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Set bits per pixel: 4, 8, or 32", ShortName = "b", LongName = "bpp")] + public int BitsPerPixel { get; set; } = 8; + + [Option(CommandOptionType.NoValue, Description = "Use `pngquant.exe` -- lossy PNG compressor. Download `pngquant.exe` and place it beside this program, current directory, or PATH.", ShortName = "p", LongName = "pngquant")] + public bool PngQuant { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Use embedded nQuant.Core color quantizer. This is default selection.", ShortName = "n", LongName = "nquant")] + public bool nQuant { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Enable swizzle.", ShortName = "s", LongName = "swizzle")] + public bool Swizzle { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var inputFile = PngFile; + var outputFile = OutputImd ?? Path.GetFullPath(Path.GetFileName(Path.ChangeExtension(inputFile, ".imd"))); + + Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); + + // Alpha enabled png → always 32 bpp + using (var bitmap = new Bitmap(inputFile)) + { + var imgd = ImgdBitmapUtil.ToImgd(bitmap, BitsPerPixel, QuantizerFactory.MakeFrom(this), Swizzle); + + var buffer = new MemoryStream(); + imgd.Write(buffer); + File.WriteAllBytes(outputFile, buffer.ToArray()); + } + return 0; + } + } + + [HelpOption] + [Command(Description = "png, imd or imz files -> imz file")] + private class ImzCommand : ICommonQuantizerParam + { + [Required] + [Option(CommandOptionType.MultipleValue, Description = "Input png/imd/imz file", ShortName = "i", LongName = "input")] + public string[] InputFile { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Output imz file. Default is current dir, and first file extension to imz.", ShortName = "o", LongName = "output")] + public string OutputImz { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Set bits per pixel for every png: 4, 8, or 32", ShortName = "b", LongName = "bpp")] + public int BitsPerPixel { get; set; } = 8; + + [Option(CommandOptionType.NoValue, Description = "Use `pngquant.exe` -- lossy PNG compressor. Download `pngquant.exe` and deploy it beside this program, current directory, or PATH.", ShortName = "p", LongName = "pngquant")] + public bool PngQuant { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Use embedded nQuant.Core color quantizer. This is default selection.", ShortName = "n", LongName = "nquant")] + public bool nQuant { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Try to append to imz", ShortName = "a", LongName = "append")] + public bool Append { get; set; } + + [Option(CommandOptionType.NoValue, Description = "Enable swizzle for png input.", ShortName = "s", LongName = "swizzle")] + public bool Swizzle { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + OutputImz = OutputImz ?? Path.GetFullPath(Path.GetFileName(Path.ChangeExtension(InputFile.First(), ".imz"))); + + Directory.CreateDirectory(Path.GetDirectoryName(OutputImz)); + + var prependImgdList = (Append && File.Exists(OutputImz)) + ? File.OpenRead(OutputImz).Using(stream => Imgz.Read(stream).ToArray()) + : new Imgd[0]; + + var buffer = new MemoryStream(); + Imgz.Write( + buffer, + prependImgdList + .Concat( + InputFile + .SelectMany(imdFile => ImgdBitmapUtil.FromFileToImgdList(imdFile, BitsPerPixel, QuantizerFactory.MakeFrom(this), Swizzle)) + ) + .ToArray() + ); + File.WriteAllBytes(OutputImz, buffer.ToArray()); + + return 0; + } + } + + [HelpOption] + [Command(Description = "imd file -> display summary")] + private class ScanImdCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Input imd file")] + public string InputFile { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var target = File.OpenRead(InputFile).Using(stream => Imgd.Read(stream)); + + Console.WriteLine( + FormatterFactory.GetFormatterPairs() + .First() + .FormatToString(ImgdSummary.From(target)) + ); + + return 0; + } + } + + [HelpOption] + [Command(Description = "imz file -> display summary")] + private class ScanImzCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Input imz file")] + public string InputFile { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + var targets = File.OpenRead(InputFile).Using(stream => Imgz.Read(stream).ToArray()); + + Console.WriteLine( + FormatterFactory.GetFormatterPairs() + .First() + .FormatToString( + targets + .Select(one => ImgdSummary.From(one)) + .Select((one, index) => (one, index)) + .ToDictionary( + pair => pair.index.ToString(), + pair => pair.one + ) + ) + ); + + return 0; + } + } + + class FormatterPair + { + internal string Type; + internal Func FormatToString; + } + + class FormatterFactory + { + internal static IEnumerable GetFormatterPairs() => new FormatterPair[] + { + new FormatterPair + { + Type = "yaml", + FormatToString = + (obj) => new YamlDotNet.Serialization.SerializerBuilder() + .Build() + .Serialize(obj), + }, + new FormatterPair + { + Type = "json", + FormatToString = + (obj) => JsonSerializer.Serialize( + obj, + new JsonSerializerOptions + { + WriteIndented = true + } + ), + }, + }; + } + + class ImgdSanityChecking + { + internal static int? GetExpectedDataLen(Imgd it) + { + switch (it.PixelFormat) + { + case Imaging.PixelFormat.Indexed4: + return (it.Size.Width * it.Size.Height + 1) / 2; + case Imaging.PixelFormat.Indexed8: + return (it.Size.Width * it.Size.Height); + case Imaging.PixelFormat.Rgb888: + return (3 * it.Size.Width * it.Size.Height); + case Imaging.PixelFormat.Rgba8888: + case Imaging.PixelFormat.Rgbx8888: + return (4 * it.Size.Width * it.Size.Height); + } + return null; + } + } + + class ImgdSummary + { + public string PixelFormat { get; private set; } + public int Width { get; private set; } + public int Height { get; private set; } + public bool IsSwizzled { get; private set; } + public int? ExpectedDataLen { get; private set; } + public int ActualDataLen { get; private set; } + public int? ActualClutLen { get; private set; } + + internal static ImgdSummary From(Imgd it) + { + return new ImgdSummary + { + PixelFormat = it.PixelFormat.ToString(), + Width = it.Size.Width, + Height = it.Size.Height, + IsSwizzled = it.IsSwizzled, + ExpectedDataLen = ImgdSanityChecking.GetExpectedDataLen(it), + ActualDataLen = it.Data.Length, + ActualClutLen = it.Clut?.Length, + }; + } + } + + [HelpOption] + [Command(Description = "imz file -> imz file (fix 4-bpp doubled bitmap size)")] + private class FixImzCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Input (and output) imz file")] + public string InputFile { get; set; } + + [Option(CommandOptionType.SingleOrNoValue, Description = "Output imz file. Default is input imz.", ShortName = "o", LongName = "output")] + public string OutputImz { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + OutputImz = OutputImz ?? InputFile; + + Directory.CreateDirectory(Path.GetDirectoryName(OutputImz)); + + var images = File.OpenRead(OutputImz).Using(stream => Imgz.Read(stream).ToArray()); + + var fixedCount = 0; + + var fixedImages = images + .Select( + image => + { + var expetectedLen = ImgdSanityChecking.GetExpectedDataLen(image); + if (true + && expetectedLen != null + && expetectedLen < image.Data.Length + && Imaging.PixelFormat.Indexed4 == image.PixelFormat + ) + { + var fixedData = new byte[expetectedLen.Value]; + + Buffer.BlockCopy(image.Data, 0, fixedData, 0, expetectedLen.Value); + + fixedCount++; + + return new Imgd( + image.Size, + image.PixelFormat, + fixedData, + image.Clut, + isSwizzled: false + ); + } + else + { + return image; + } + } + ) + .ToArray(); + + var buffer = new MemoryStream(); + + Imgz.Write(buffer, fixedImages); + + File.WriteAllBytes(OutputImz, buffer.ToArray()); + + Console.WriteLine($"Fixed {fixedCount} images."); + + return 0; + } + } + + [HelpOption] + [Command(Description = "imz file -> imz file (swap 4-bpp hi/lo pixel)")] + private class SwapImzPixelCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Input (and output) imz file")] + public string InputFile { get; set; } + + [Option(CommandOptionType.SingleOrNoValue, Description = "Output imz file. Default is input imz.", ShortName = "o", LongName = "output")] + public string OutputImz { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + OutputImz = OutputImz ?? InputFile; + + Directory.CreateDirectory(Path.GetDirectoryName(OutputImz)); + + var images = File.OpenRead(OutputImz).Using(stream => Imgz.Read(stream).ToArray()); + + var fixedCount = 0; + + var fixedImages = images + .Select( + image => + { + if (Imaging.PixelFormat.Indexed4 == image.PixelFormat) + { + var data = image.Data; + + for (var x = 0; x < data.Length; x++) + { + var swap = data[x]; + data[x] = (byte)((swap << 4) | (swap >> 4)); + } + + fixedCount++; + } + return image; + } + ) + .ToArray(); + + var buffer = new MemoryStream(); + + Imgz.Write(buffer, fixedImages); + + File.WriteAllBytes(OutputImz, buffer.ToArray()); + + Console.WriteLine($"Applied to {fixedCount} images."); + + return 0; + } + } + + } +} diff --git a/OpenKh.Command.ImgTool/Utils/ImgdBitmapUtil.cs b/OpenKh.Command.ImgTool/Utils/ImgdBitmapUtil.cs index a570ac80f..f00935ef5 100644 --- a/OpenKh.Command.ImgTool/Utils/ImgdBitmapUtil.cs +++ b/OpenKh.Command.ImgTool/Utils/ImgdBitmapUtil.cs @@ -1,448 +1,448 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using OpenKh.Common; -using OpenKh.Kh2; -using static System.Drawing.Imaging.PixelFormat; - -namespace OpenKh.Kh2.Utils -{ - public class ImgdBitmapUtil - { - public static Bitmap ToBitmap(Imgd imgd) - { - switch (imgd.PixelFormat) - { - case Imaging.PixelFormat.Indexed4: - { - var bitmap = new Bitmap(imgd.Size.Width, imgd.Size.Height, PixelFormat.Format4bppIndexed); - var dest = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, bitmap.PixelFormat); - try - { - var sourceBits = imgd.GetData(); - var sourceWidth = imgd.Size.Width; - var sourceStride = ((sourceWidth + 1) / 2) & (~1); - for (int y = 0; y < bitmap.Height; y++) - { - Marshal.Copy(sourceBits, sourceStride * y, dest.Scan0 + dest.Stride * y, sourceStride); - } - } - finally - { - bitmap.UnlockBits(dest); - } - - { - var clut = imgd.GetClut(); - var palette = bitmap.Palette; - for (int index = 0; index < 16; index++) - { - palette.Entries[index] = Color.FromArgb( - clut[4 * index + 3], - clut[4 * index + 0], - clut[4 * index + 1], - clut[4 * index + 2] - ); - } - bitmap.Palette = palette; - } - - return bitmap; - } - case Imaging.PixelFormat.Indexed8: - { - var bitmap = new Bitmap(imgd.Size.Width, imgd.Size.Height, PixelFormat.Format8bppIndexed); - var dest = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, bitmap.PixelFormat); - try - { - var sourceBits = imgd.GetData(); - var sourceWidth = imgd.Size.Width; - for (int y = 0; y < bitmap.Height; y++) - { - Marshal.Copy(sourceBits, sourceWidth * y, dest.Scan0 + dest.Stride * y, sourceWidth); - } - } - finally - { - bitmap.UnlockBits(dest); - } - - { - var clut = imgd.GetClut(); - var palette = bitmap.Palette; - for (int index = 0; index < 256; index++) - { - palette.Entries[index] = Color.FromArgb( - clut[4 * index + 3], - clut[4 * index + 0], - clut[4 * index + 1], - clut[4 * index + 2] - ); - } - bitmap.Palette = palette; - } - - return bitmap; - } - case Imaging.PixelFormat.Rgba8888: - { - var bitmap = new Bitmap(imgd.Size.Width, imgd.Size.Height, PixelFormat.Format32bppPArgb); - var dest = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, bitmap.PixelFormat); - try - { - var sourceBits = imgd.GetData(); - var sourceWidth = 4 * imgd.Size.Width; - for (int y = 0; y < bitmap.Height; y++) - { - Marshal.Copy(sourceBits, sourceWidth * y, dest.Scan0 + dest.Stride * y, sourceWidth); - } - } - finally - { - bitmap.UnlockBits(dest); - } - - return bitmap; - } - } - throw new NotSupportedException($"{imgd.PixelFormat} not recognized!"); - } - - class ReadAs32bppPixels - { - public ReadAs32bppPixels(Bitmap bitmap) - { - Width = bitmap.Width; - Height = bitmap.Height; - - var src = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); - var srcBits = new byte[src.Stride * src.Height]; - try - { - Marshal.Copy(src.Scan0, srcBits, 0, srcBits.Length); - } - finally - { - bitmap.UnlockBits(src); - } - - Pixels = new List(Width * Height); - - for (int y = 0; y < Height; y++) - { - for (int x = 0; x < Width; x++) - { - Pixels.Add(BitConverter.ToUInt32(srcBits, src.Stride * y + 4 * x)); - } - } - - } - - public List Pixels { get; } - public int Width { get; } - public int Height { get; } - } - - static class PaletteColorUsageCounter - { - public static bool IfMaxColorCountIsOver(List pixels, int maxColors) - { - return pixels - .GroupBy(pixel => pixel) - .Count() > maxColors; - } - } - - class PaletteGenerator - { - public PaletteGenerator(List pixels, int maxColors) - { - MostUsedPixels = pixels - .GroupBy(pixel => pixel) - .OrderByDescending(group => group.Count()) - .Select(group => group.Key) - .Take(maxColors) - .ToArray(); - - MaxUsedColors = pixels - .Distinct() - .Count(); - } - - public uint[] MostUsedPixels { get; } - public int MaxUsedColors { get; } - - public int FindNearest(uint pixel) - { - int found = Array.IndexOf(MostUsedPixels, pixel); - if (found == -1) - { - var a = (byte)(pixel >> 0); - var b = (byte)(pixel >> 8); - var c = (byte)(pixel >> 16); - var d = (byte)(pixel >> 24); - - int minDistance = int.MaxValue; - for (int index = 0; index < MostUsedPixels.Length; index++) - { - var target = MostUsedPixels[index]; - var A = (byte)(target >> 0); - var B = (byte)(target >> 8); - var C = (byte)(target >> 16); - var D = (byte)(target >> 24); - var distance = Math.Abs((int)a - A) + Math.Abs((int)b - B) + Math.Abs((int)c - C) + Math.Abs((int)d - D); - if (distance < minDistance) - { - found = index; - minDistance = distance; - } - } - } - return found; - } - } - - public static Imgd ToImgd(Bitmap bitmap, int bpp, Func quantizer, bool swizzle = false) - { - if (quantizer != null) - { - var firstSrc = new ReadAs32bppPixels(bitmap); - - if (PaletteColorUsageCounter.IfMaxColorCountIsOver(firstSrc.Pixels, 1 << bpp)) - { - bitmap = quantizer(bitmap); - } - } - - switch (bpp) - { - case 4: - { - const int maxColors = 16; - - var src = new ReadAs32bppPixels(bitmap); - - var newPalette = new PaletteGenerator(src.Pixels, maxColors); - - if (newPalette.MaxUsedColors > newPalette.MostUsedPixels.Length) - { - Console.WriteLine( - $"Trimming color palette entry count from {newPalette.MaxUsedColors} to ${newPalette.MostUsedPixels.Length}" - ); - } - - var destBits = new byte[(src.Width * src.Height + 1) / 2]; - var clut = new byte[4 * maxColors]; - - for (int index = 0; index < newPalette.MostUsedPixels.Length; index++) - { - var pixel = newPalette.MostUsedPixels[index]; - - clut[4 * index + 0] = (byte)(pixel >> 16); - clut[4 * index + 1] = (byte)(pixel >> 8); - clut[4 * index + 2] = (byte)(pixel >> 0); - clut[4 * index + 3] = (byte)(pixel >> 24); - } - - var srcPointer = 0; - var destPointer = 0; - - for (int y = 0; y < src.Height; y++) - { - for (int x = 0; x < src.Width; x++) - { - var newPixel = newPalette.FindNearest(src.Pixels[srcPointer++]) & 15; - if (0 == (x & 1)) - { - // first pixel: hi byte - destBits[destPointer] = (byte)(newPixel << 4); - } - else - { - // second pixel: lo byte - destBits[destPointer++] |= (byte)(newPixel); - } - } - } - - return Imgd.Create(bitmap.Size, Imaging.PixelFormat.Indexed4, destBits, clut, swizzle); - } - case 8: - { - const int maxColors = 256; - - var src = new ReadAs32bppPixels(bitmap); - - var newPalette = new PaletteGenerator(src.Pixels, maxColors); - - if (newPalette.MaxUsedColors > newPalette.MostUsedPixels.Length) - { - Console.WriteLine( - $"Trimming color palette entry count from {newPalette.MaxUsedColors} to ${newPalette.MostUsedPixels.Length}" - ); - } - - var destBits = new byte[src.Width * src.Height]; - var clut = new byte[4 * maxColors]; - - for (int index = 0; index < newPalette.MostUsedPixels.Length; index++) - { - var pixel = newPalette.MostUsedPixels[index]; - - clut[4 * index + 0] = (byte)(pixel >> 16); - clut[4 * index + 1] = (byte)(pixel >> 8); - clut[4 * index + 2] = (byte)(pixel >> 0); - clut[4 * index + 3] = (byte)(pixel >> 24); - } - - var srcPointer = 0; - var destPointer = 0; - - for (int y = 0; y < src.Height; y++) - { - for (int x = 0; x < src.Width; x++) - { - destBits[destPointer++] = (byte)newPalette.FindNearest(src.Pixels[srcPointer++]); - } - } - - return Imgd.Create(bitmap.Size, Imaging.PixelFormat.Indexed8, destBits, clut, swizzle); - } - case 32: - { - var src = new ReadAs32bppPixels(bitmap); - - var destBits = new byte[4 * src.Width * src.Height]; - - var srcPointer = 0; - var destPointer = 0; - - for (int y = 0; y < src.Height; y++) - { - for (int x = 0; x < src.Width; x++) - { - var pixel = src.Pixels[srcPointer++]; - - destBits[destPointer + 0] = (byte)(pixel >> 16); - destBits[destPointer + 1] = (byte)(pixel >> 8); - destBits[destPointer + 2] = (byte)(pixel >> 0); - destBits[destPointer + 3] = (byte)(pixel >> 24); - - destPointer += 4; - } - } - - return Imgd.Create(bitmap.Size, Imaging.PixelFormat.Rgba8888, destBits, new byte[0], swizzle); - } - } - throw new NotSupportedException($"BitsPerPixel {bpp} not recognized!"); - } - - public static IEnumerable FromFileToImgdList(string anyFile, int bitsPerPixel, Func quantizer, bool swizzle) - { - switch (Path.GetExtension(anyFile).ToLowerInvariant()) - { - case ".png": - { - yield return new Bitmap(anyFile).Using(bitmap => ToImgd(bitmap, bitsPerPixel, quantizer, swizzle)); - break; - } - case ".imd": - { - yield return File.OpenRead(anyFile).Using(stream => Imgd.Read(stream)); - break; - } - case ".imz": - { - foreach (var imgd in File.OpenRead(anyFile).Using(stream => Imgz.Read(stream))) - { - yield return imgd; - } - break; - } - } - } - - public static Imgd ToImgd(Bitmap bitmap) - { - switch (bitmap.PixelFormat) - { - case PixelFormat.Format4bppIndexed: - { - var destHeight = bitmap.Height; - var destStride = (bitmap.Width + 1) & (~1); - var destBits = new byte[destStride * destHeight]; - var src = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.ReadOnly, bitmap.PixelFormat); - try - { - for (int y = 0; y < bitmap.Height; y++) - { - Marshal.Copy(src.Scan0 + src.Stride * y, destBits, destStride * y, destStride); - } - } - finally - { - bitmap.UnlockBits(src); - } - - var clut = new byte[4 * 16]; - { - var palette = bitmap.Palette; - for (int index = 0; index < 16; index++) - { - var color = palette.Entries[index]; - - clut[4 * index + 0] = color.R; - clut[4 * index + 1] = color.G; - clut[4 * index + 2] = color.B; - clut[4 * index + 3] = color.A; - } - bitmap.Palette = palette; - } - - return Imgd.Create(bitmap.Size, Imaging.PixelFormat.Indexed4, destBits, clut, false); - } - case PixelFormat.Format8bppIndexed: - { - var destHeight = bitmap.Height; - var destStride = bitmap.Width; - var destBits = new byte[destStride * destHeight]; - var src = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.ReadOnly, bitmap.PixelFormat); - try - { - for (int y = 0; y < bitmap.Height; y++) - { - Marshal.Copy(src.Scan0 + src.Stride * y, destBits, destStride * y, destStride); - } - } - finally - { - bitmap.UnlockBits(src); - } - - var clut = new byte[4 * 256]; - { - var palette = bitmap.Palette; - for (int index = 0; index < 256; index++) - { - var color = palette.Entries[index]; - - clut[4 * index + 0] = color.R; - clut[4 * index + 1] = color.G; - clut[4 * index + 2] = color.B; - clut[4 * index + 3] = color.A; - } - bitmap.Palette = palette; - } - - return Imgd.Create(bitmap.Size, Imaging.PixelFormat.Indexed4, destBits, clut, false); - } - } - throw new NotSupportedException($"{bitmap.PixelFormat} not recognized!"); - } - } -} +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using OpenKh.Common; +using OpenKh.Kh2; +using static System.Drawing.Imaging.PixelFormat; + +namespace OpenKh.Kh2.Utils +{ + public class ImgdBitmapUtil + { + public static Bitmap ToBitmap(Imgd imgd) + { + switch (imgd.PixelFormat) + { + case Imaging.PixelFormat.Indexed4: + { + var bitmap = new Bitmap(imgd.Size.Width, imgd.Size.Height, PixelFormat.Format4bppIndexed); + var dest = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, bitmap.PixelFormat); + try + { + var sourceBits = imgd.GetData(); + var sourceWidth = imgd.Size.Width; + var sourceStride = ((sourceWidth + 1) / 2) & (~1); + for (int y = 0; y < bitmap.Height; y++) + { + Marshal.Copy(sourceBits, sourceStride * y, dest.Scan0 + dest.Stride * y, sourceStride); + } + } + finally + { + bitmap.UnlockBits(dest); + } + + { + var clut = imgd.GetClut(); + var palette = bitmap.Palette; + for (int index = 0; index < 16; index++) + { + palette.Entries[index] = Color.FromArgb( + clut[4 * index + 3], + clut[4 * index + 0], + clut[4 * index + 1], + clut[4 * index + 2] + ); + } + bitmap.Palette = palette; + } + + return bitmap; + } + case Imaging.PixelFormat.Indexed8: + { + var bitmap = new Bitmap(imgd.Size.Width, imgd.Size.Height, PixelFormat.Format8bppIndexed); + var dest = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, bitmap.PixelFormat); + try + { + var sourceBits = imgd.GetData(); + var sourceWidth = imgd.Size.Width; + for (int y = 0; y < bitmap.Height; y++) + { + Marshal.Copy(sourceBits, sourceWidth * y, dest.Scan0 + dest.Stride * y, sourceWidth); + } + } + finally + { + bitmap.UnlockBits(dest); + } + + { + var clut = imgd.GetClut(); + var palette = bitmap.Palette; + for (int index = 0; index < 256; index++) + { + palette.Entries[index] = Color.FromArgb( + clut[4 * index + 3], + clut[4 * index + 0], + clut[4 * index + 1], + clut[4 * index + 2] + ); + } + bitmap.Palette = palette; + } + + return bitmap; + } + case Imaging.PixelFormat.Rgba8888: + { + var bitmap = new Bitmap(imgd.Size.Width, imgd.Size.Height, PixelFormat.Format32bppPArgb); + var dest = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, bitmap.PixelFormat); + try + { + var sourceBits = imgd.GetData(); + var sourceWidth = 4 * imgd.Size.Width; + for (int y = 0; y < bitmap.Height; y++) + { + Marshal.Copy(sourceBits, sourceWidth * y, dest.Scan0 + dest.Stride * y, sourceWidth); + } + } + finally + { + bitmap.UnlockBits(dest); + } + + return bitmap; + } + } + throw new NotSupportedException($"{imgd.PixelFormat} not recognized!"); + } + + class ReadAs32bppPixels + { + public ReadAs32bppPixels(Bitmap bitmap) + { + Width = bitmap.Width; + Height = bitmap.Height; + + var src = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); + var srcBits = new byte[src.Stride * src.Height]; + try + { + Marshal.Copy(src.Scan0, srcBits, 0, srcBits.Length); + } + finally + { + bitmap.UnlockBits(src); + } + + Pixels = new List(Width * Height); + + for (int y = 0; y < Height; y++) + { + for (int x = 0; x < Width; x++) + { + Pixels.Add(BitConverter.ToUInt32(srcBits, src.Stride * y + 4 * x)); + } + } + + } + + public List Pixels { get; } + public int Width { get; } + public int Height { get; } + } + + static class PaletteColorUsageCounter + { + public static bool IfMaxColorCountIsOver(List pixels, int maxColors) + { + return pixels + .GroupBy(pixel => pixel) + .Count() > maxColors; + } + } + + class PaletteGenerator + { + public PaletteGenerator(List pixels, int maxColors) + { + MostUsedPixels = pixels + .GroupBy(pixel => pixel) + .OrderByDescending(group => group.Count()) + .Select(group => group.Key) + .Take(maxColors) + .ToArray(); + + MaxUsedColors = pixels + .Distinct() + .Count(); + } + + public uint[] MostUsedPixels { get; } + public int MaxUsedColors { get; } + + public int FindNearest(uint pixel) + { + int found = Array.IndexOf(MostUsedPixels, pixel); + if (found == -1) + { + var a = (byte)(pixel >> 0); + var b = (byte)(pixel >> 8); + var c = (byte)(pixel >> 16); + var d = (byte)(pixel >> 24); + + int minDistance = int.MaxValue; + for (int index = 0; index < MostUsedPixels.Length; index++) + { + var target = MostUsedPixels[index]; + var A = (byte)(target >> 0); + var B = (byte)(target >> 8); + var C = (byte)(target >> 16); + var D = (byte)(target >> 24); + var distance = Math.Abs((int)a - A) + Math.Abs((int)b - B) + Math.Abs((int)c - C) + Math.Abs((int)d - D); + if (distance < minDistance) + { + found = index; + minDistance = distance; + } + } + } + return found; + } + } + + public static Imgd ToImgd(Bitmap bitmap, int bpp, Func quantizer, bool swizzle = false) + { + if (quantizer != null) + { + var firstSrc = new ReadAs32bppPixels(bitmap); + + if (PaletteColorUsageCounter.IfMaxColorCountIsOver(firstSrc.Pixels, 1 << bpp)) + { + bitmap = quantizer(bitmap); + } + } + + switch (bpp) + { + case 4: + { + const int maxColors = 16; + + var src = new ReadAs32bppPixels(bitmap); + + var newPalette = new PaletteGenerator(src.Pixels, maxColors); + + if (newPalette.MaxUsedColors > newPalette.MostUsedPixels.Length) + { + Console.WriteLine( + $"Trimming color palette entry count from {newPalette.MaxUsedColors} to ${newPalette.MostUsedPixels.Length}" + ); + } + + var destBits = new byte[(src.Width * src.Height + 1) / 2]; + var clut = new byte[4 * maxColors]; + + for (int index = 0; index < newPalette.MostUsedPixels.Length; index++) + { + var pixel = newPalette.MostUsedPixels[index]; + + clut[4 * index + 0] = (byte)(pixel >> 16); + clut[4 * index + 1] = (byte)(pixel >> 8); + clut[4 * index + 2] = (byte)(pixel >> 0); + clut[4 * index + 3] = (byte)(pixel >> 24); + } + + var srcPointer = 0; + var destPointer = 0; + + for (int y = 0; y < src.Height; y++) + { + for (int x = 0; x < src.Width; x++) + { + var newPixel = newPalette.FindNearest(src.Pixels[srcPointer++]) & 15; + if (0 == (x & 1)) + { + // first pixel: hi byte + destBits[destPointer] = (byte)(newPixel << 4); + } + else + { + // second pixel: lo byte + destBits[destPointer++] |= (byte)(newPixel); + } + } + } + + return Imgd.Create(bitmap.Size, Imaging.PixelFormat.Indexed4, destBits, clut, swizzle); + } + case 8: + { + const int maxColors = 256; + + var src = new ReadAs32bppPixels(bitmap); + + var newPalette = new PaletteGenerator(src.Pixels, maxColors); + + if (newPalette.MaxUsedColors > newPalette.MostUsedPixels.Length) + { + Console.WriteLine( + $"Trimming color palette entry count from {newPalette.MaxUsedColors} to ${newPalette.MostUsedPixels.Length}" + ); + } + + var destBits = new byte[src.Width * src.Height]; + var clut = new byte[4 * maxColors]; + + for (int index = 0; index < newPalette.MostUsedPixels.Length; index++) + { + var pixel = newPalette.MostUsedPixels[index]; + + clut[4 * index + 0] = (byte)(pixel >> 16); + clut[4 * index + 1] = (byte)(pixel >> 8); + clut[4 * index + 2] = (byte)(pixel >> 0); + clut[4 * index + 3] = (byte)(pixel >> 24); + } + + var srcPointer = 0; + var destPointer = 0; + + for (int y = 0; y < src.Height; y++) + { + for (int x = 0; x < src.Width; x++) + { + destBits[destPointer++] = (byte)newPalette.FindNearest(src.Pixels[srcPointer++]); + } + } + + return Imgd.Create(bitmap.Size, Imaging.PixelFormat.Indexed8, destBits, clut, swizzle); + } + case 32: + { + var src = new ReadAs32bppPixels(bitmap); + + var destBits = new byte[4 * src.Width * src.Height]; + + var srcPointer = 0; + var destPointer = 0; + + for (int y = 0; y < src.Height; y++) + { + for (int x = 0; x < src.Width; x++) + { + var pixel = src.Pixels[srcPointer++]; + + destBits[destPointer + 0] = (byte)(pixel >> 16); + destBits[destPointer + 1] = (byte)(pixel >> 8); + destBits[destPointer + 2] = (byte)(pixel >> 0); + destBits[destPointer + 3] = (byte)(pixel >> 24); + + destPointer += 4; + } + } + + return Imgd.Create(bitmap.Size, Imaging.PixelFormat.Rgba8888, destBits, new byte[0], swizzle); + } + } + throw new NotSupportedException($"BitsPerPixel {bpp} not recognized!"); + } + + public static IEnumerable FromFileToImgdList(string anyFile, int bitsPerPixel, Func quantizer, bool swizzle) + { + switch (Path.GetExtension(anyFile).ToLowerInvariant()) + { + case ".png": + { + yield return new Bitmap(anyFile).Using(bitmap => ToImgd(bitmap, bitsPerPixel, quantizer, swizzle)); + break; + } + case ".imd": + { + yield return File.OpenRead(anyFile).Using(stream => Imgd.Read(stream)); + break; + } + case ".imz": + { + foreach (var imgd in File.OpenRead(anyFile).Using(stream => Imgz.Read(stream))) + { + yield return imgd; + } + break; + } + } + } + + public static Imgd ToImgd(Bitmap bitmap) + { + switch (bitmap.PixelFormat) + { + case PixelFormat.Format4bppIndexed: + { + var destHeight = bitmap.Height; + var destStride = (bitmap.Width + 1) & (~1); + var destBits = new byte[destStride * destHeight]; + var src = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.ReadOnly, bitmap.PixelFormat); + try + { + for (int y = 0; y < bitmap.Height; y++) + { + Marshal.Copy(src.Scan0 + src.Stride * y, destBits, destStride * y, destStride); + } + } + finally + { + bitmap.UnlockBits(src); + } + + var clut = new byte[4 * 16]; + { + var palette = bitmap.Palette; + for (int index = 0; index < 16; index++) + { + var color = palette.Entries[index]; + + clut[4 * index + 0] = color.R; + clut[4 * index + 1] = color.G; + clut[4 * index + 2] = color.B; + clut[4 * index + 3] = color.A; + } + bitmap.Palette = palette; + } + + return Imgd.Create(bitmap.Size, Imaging.PixelFormat.Indexed4, destBits, clut, false); + } + case PixelFormat.Format8bppIndexed: + { + var destHeight = bitmap.Height; + var destStride = bitmap.Width; + var destBits = new byte[destStride * destHeight]; + var src = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.ReadOnly, bitmap.PixelFormat); + try + { + for (int y = 0; y < bitmap.Height; y++) + { + Marshal.Copy(src.Scan0 + src.Stride * y, destBits, destStride * y, destStride); + } + } + finally + { + bitmap.UnlockBits(src); + } + + var clut = new byte[4 * 256]; + { + var palette = bitmap.Palette; + for (int index = 0; index < 256; index++) + { + var color = palette.Entries[index]; + + clut[4 * index + 0] = color.R; + clut[4 * index + 1] = color.G; + clut[4 * index + 2] = color.B; + clut[4 * index + 3] = color.A; + } + bitmap.Palette = palette; + } + + return Imgd.Create(bitmap.Size, Imaging.PixelFormat.Indexed4, destBits, clut, false); + } + } + throw new NotSupportedException($"{bitmap.PixelFormat} not recognized!"); + } + } +} diff --git a/OpenKh.Command.ImgTool/Utils/QuantizerFactory.cs b/OpenKh.Command.ImgTool/Utils/QuantizerFactory.cs index b1d411012..afe2521d8 100644 --- a/OpenKh.Command.ImgTool/Utils/QuantizerFactory.cs +++ b/OpenKh.Command.ImgTool/Utils/QuantizerFactory.cs @@ -1,76 +1,76 @@ -using nQuant; -using OpenKh.Command.ImgTool.Interfaces; -using System; -using System.Diagnostics; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; - -namespace OpenKh.Command.ImgTool.Utils -{ - public class QuantizerFactory - { - private class CommonQuantizerParam : ICommonQuantizerParam - { - public int BitsPerPixel { get; set; } - - public bool PngQuant { get; set; } - } - - public static Func MakeFrom(int BitsPerPixel, bool InvokePngquant) => - MakeFrom( - new CommonQuantizerParam - { - BitsPerPixel = BitsPerPixel, - PngQuant = InvokePngquant, - } - ); - - public static Func MakeFrom(ICommonQuantizerParam param) - { - return bitmap => - { - switch (param.BitsPerPixel) - { - case 4: - case 8: - { - var maxColors = 1 << param.BitsPerPixel; - - if (param.PngQuant) - { - var psi = new ProcessStartInfo("pngquant.exe", $"{maxColors} -") - { - CreateNoWindow = true, - UseShellExecute = false, - RedirectStandardInput = true, - RedirectStandardOutput = true, - }; - using var p = Process.Start(psi); - using (var temp = new MemoryStream()) - { - bitmap.Save(temp, ImageFormat.Png); - temp.Position = 0; - temp.CopyTo(p.StandardInput.BaseStream); - p.StandardInput.BaseStream.Close(); // prevent pngquant from blocking. - } - var newBitmap = new Bitmap(p.StandardOutput.BaseStream); - return newBitmap; - } - else - { - return (Bitmap)new WuQuantizer().QuantizeImage( - new Bitmap(bitmap), // make sure it is 32 bpp, not 24 bpp - alphaThreshold: -1, - alphaFader: 1, - maxColors - ); - // I believe that nQuant never throws exception. - } - } - } - return bitmap; - }; - } - } -} +using nQuant; +using OpenKh.Command.ImgTool.Interfaces; +using System; +using System.Diagnostics; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; + +namespace OpenKh.Command.ImgTool.Utils +{ + public class QuantizerFactory + { + private class CommonQuantizerParam : ICommonQuantizerParam + { + public int BitsPerPixel { get; set; } + + public bool PngQuant { get; set; } + } + + public static Func MakeFrom(int BitsPerPixel, bool InvokePngquant) => + MakeFrom( + new CommonQuantizerParam + { + BitsPerPixel = BitsPerPixel, + PngQuant = InvokePngquant, + } + ); + + public static Func MakeFrom(ICommonQuantizerParam param) + { + return bitmap => + { + switch (param.BitsPerPixel) + { + case 4: + case 8: + { + var maxColors = 1 << param.BitsPerPixel; + + if (param.PngQuant) + { + var psi = new ProcessStartInfo("pngquant.exe", $"{maxColors} -") + { + CreateNoWindow = true, + UseShellExecute = false, + RedirectStandardInput = true, + RedirectStandardOutput = true, + }; + using var p = Process.Start(psi); + using (var temp = new MemoryStream()) + { + bitmap.Save(temp, ImageFormat.Png); + temp.Position = 0; + temp.CopyTo(p.StandardInput.BaseStream); + p.StandardInput.BaseStream.Close(); // prevent pngquant from blocking. + } + var newBitmap = new Bitmap(p.StandardOutput.BaseStream); + return newBitmap; + } + else + { + return (Bitmap)new WuQuantizer().QuantizeImage( + new Bitmap(bitmap), // make sure it is 32 bpp, not 24 bpp + alphaThreshold: -1, + alphaFader: 1, + maxColors + ); + // I believe that nQuant never throws exception. + } + } + } + return bitmap; + }; + } + } +} diff --git a/OpenKh.Command.Layout/Program.cs b/OpenKh.Command.Layout/Program.cs index 051cde9aa..032e0dd1e 100644 --- a/OpenKh.Command.Layout/Program.cs +++ b/OpenKh.Command.Layout/Program.cs @@ -1,166 +1,166 @@ -using OpenKh.Kh2; -using McMaster.Extensions.CommandLineUtils; -using System; -using System.IO; -using System.Reflection; -using System.ComponentModel.DataAnnotations; - -namespace OpenKh.Command.Layout -{ - [Command("OpenKh.Command.Layout")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - [Subcommand( - typeof(UnlayoutCommand), - typeof(RelayoutCommand), - typeof(UnsequenceCommand), - typeof(ResequenceCommand))] - class Program - { - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (InvalidFileException e) - { - Console.WriteLine(e.Message); - return 3; - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - return 2; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return -1; - } - } - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - private static string ChangeExtension(string fileName, string newExtension) - { - var path = Path.GetDirectoryName(fileName); - var fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileName); - - return Path.Combine(path, $"{fileNameWithoutExt}.{newExtension}"); - } - - private static int Serialize( - string inputFileName, - string outputFileName, - Func isValid, - Func read) - { - using var inStream = File.OpenRead(inputFileName); - if (!isValid(inStream)) - throw new InvalidFileException(inputFileName, typeof(T).Name.ToLower()); - inStream.Position = 0; - - if (string.IsNullOrEmpty(outputFileName)) - outputFileName = ChangeExtension(inputFileName, "yml"); - - using var outStream = File.CreateText(outputFileName); - new YamlDotNet.Serialization.Serializer().Serialize(outStream, read(inStream)); - - return 0; - } - - private static int Deserialize( - string inputFileName, - string outputFileName, - string extension, - Action write) - { - var item = new YamlDotNet.Serialization.Deserializer() - .Deserialize(File.ReadAllText(inputFileName)); - - if (string.IsNullOrEmpty(outputFileName)) - outputFileName = ChangeExtension(inputFileName, extension); - - using var outStream = File.Create(outputFileName); - write(item, outStream); - - return 0; - } - - [Command("unlayout", Description = "Deserialize a Kingdom Hearts II layout file to YAML")] - private class UnlayoutCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Kingdom Hearts II layout file")] - public string Input { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Output file", ShortName = "o", LongName = "output")] - public string Output { get; set; } - - protected int OnExecute(CommandLineApplication app) => - Serialize(Input, Output, Kh2.Layout.IsValid, Kh2.Layout.Read); - } - - [Command("relayout", Description = "Serialize a YAML to Kingdom Hearts II layout")] - private class RelayoutCommand - { - [Required] - [FileExists] - [Argument(0, Description = "File name of YAML representatiof a layout")] - public string Input { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Output file", ShortName = "o", LongName = "output")] - public string Output { get; set; } - - protected int OnExecute(CommandLineApplication app) => - Deserialize(Input, Output, "layout", (x, s) => x.Write(s)); - } - - [Command("unsequence", Description = "Deserialize a Kingdom Hearts II sequence file to YAML")] - private class UnsequenceCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Kingdom Hearts II sequence file")] - public string Input { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Output file", ShortName = "o", LongName = "output")] - public string Output { get; set; } - - protected int OnExecute(CommandLineApplication app) => - Serialize(Input, Output, Sequence.IsValid, Sequence.Read); - } - - [Command("resequence", Description = "Serialize a YAML to Kingdom Hearts II sequence")] - private class ResequenceCommand - { - [Required] - [FileExists] - [Argument(0, Description = "File name of YAML representatiof a sequence")] - public string Input { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Output file", ShortName = "o", LongName = "output")] - public string Output { get; set; } - - protected int OnExecute(CommandLineApplication app) => - Deserialize(Input, Output, "sequence", (x, s) => x.Write(s)); - } - } - - internal class InvalidFileException : Exception - { - public InvalidFileException(string fileName, string type) : - base($"The file {fileName} is not recognized as type {type}.") - { - - } - } -} +using OpenKh.Kh2; +using McMaster.Extensions.CommandLineUtils; +using System; +using System.IO; +using System.Reflection; +using System.ComponentModel.DataAnnotations; + +namespace OpenKh.Command.Layout +{ + [Command("OpenKh.Command.Layout")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + [Subcommand( + typeof(UnlayoutCommand), + typeof(RelayoutCommand), + typeof(UnsequenceCommand), + typeof(ResequenceCommand))] + class Program + { + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (InvalidFileException e) + { + Console.WriteLine(e.Message); + return 3; + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + return 2; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return -1; + } + } + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + private static string ChangeExtension(string fileName, string newExtension) + { + var path = Path.GetDirectoryName(fileName); + var fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileName); + + return Path.Combine(path, $"{fileNameWithoutExt}.{newExtension}"); + } + + private static int Serialize( + string inputFileName, + string outputFileName, + Func isValid, + Func read) + { + using var inStream = File.OpenRead(inputFileName); + if (!isValid(inStream)) + throw new InvalidFileException(inputFileName, typeof(T).Name.ToLower()); + inStream.Position = 0; + + if (string.IsNullOrEmpty(outputFileName)) + outputFileName = ChangeExtension(inputFileName, "yml"); + + using var outStream = File.CreateText(outputFileName); + new YamlDotNet.Serialization.Serializer().Serialize(outStream, read(inStream)); + + return 0; + } + + private static int Deserialize( + string inputFileName, + string outputFileName, + string extension, + Action write) + { + var item = new YamlDotNet.Serialization.Deserializer() + .Deserialize(File.ReadAllText(inputFileName)); + + if (string.IsNullOrEmpty(outputFileName)) + outputFileName = ChangeExtension(inputFileName, extension); + + using var outStream = File.Create(outputFileName); + write(item, outStream); + + return 0; + } + + [Command("unlayout", Description = "Deserialize a Kingdom Hearts II layout file to YAML")] + private class UnlayoutCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Kingdom Hearts II layout file")] + public string Input { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Output file", ShortName = "o", LongName = "output")] + public string Output { get; set; } + + protected int OnExecute(CommandLineApplication app) => + Serialize(Input, Output, Kh2.Layout.IsValid, Kh2.Layout.Read); + } + + [Command("relayout", Description = "Serialize a YAML to Kingdom Hearts II layout")] + private class RelayoutCommand + { + [Required] + [FileExists] + [Argument(0, Description = "File name of YAML representatiof a layout")] + public string Input { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Output file", ShortName = "o", LongName = "output")] + public string Output { get; set; } + + protected int OnExecute(CommandLineApplication app) => + Deserialize(Input, Output, "layout", (x, s) => x.Write(s)); + } + + [Command("unsequence", Description = "Deserialize a Kingdom Hearts II sequence file to YAML")] + private class UnsequenceCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Kingdom Hearts II sequence file")] + public string Input { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Output file", ShortName = "o", LongName = "output")] + public string Output { get; set; } + + protected int OnExecute(CommandLineApplication app) => + Serialize(Input, Output, Sequence.IsValid, Sequence.Read); + } + + [Command("resequence", Description = "Serialize a YAML to Kingdom Hearts II sequence")] + private class ResequenceCommand + { + [Required] + [FileExists] + [Argument(0, Description = "File name of YAML representatiof a sequence")] + public string Input { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Output file", ShortName = "o", LongName = "output")] + public string Output { get; set; } + + protected int OnExecute(CommandLineApplication app) => + Deserialize(Input, Output, "sequence", (x, s) => x.Write(s)); + } + } + + internal class InvalidFileException : Exception + { + public InvalidFileException(string fileName, string type) : + base($"The file {fileName} is not recognized as type {type}.") + { + + } + } +} diff --git a/OpenKh.Command.MapGen/Models/BigMesh.cs b/OpenKh.Command.MapGen/Models/BigMesh.cs index 15d17b514..2b4cdaa1e 100644 --- a/OpenKh.Command.MapGen/Models/BigMesh.cs +++ b/OpenKh.Command.MapGen/Models/BigMesh.cs @@ -1,44 +1,44 @@ -using OpenKh.Command.MapGen.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; -using Xe.Graphics; -using static OpenKh.Command.MapGen.Models.MapGenConfig; - -namespace OpenKh.Command.MapGen.Models -{ - /// - /// - /// - /// - /// tripletIndicesList.Count == uvList.Count == vertexColorList.Count - /// - public class BigMesh - { - public List vertexList = new List(); - public List triangleStripList = new List(); - - /// - /// -1 if nodraw flag set - /// - public int textureIndex = -1; - - public MaterialDef matDef; - - public List vifPacketIndices = new List(); - - public class TriangleStrip - { - public List vertexIndices = new List(); - public List uvList = new List(); - - /// - /// vertex color rgba is directly written. - /// 128 is PS2's max. 255 is doubled intensity. - /// - public List vertexColorList = new List(); - } - } -} +using OpenKh.Command.MapGen.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using Xe.Graphics; +using static OpenKh.Command.MapGen.Models.MapGenConfig; + +namespace OpenKh.Command.MapGen.Models +{ + /// + /// + /// + /// + /// tripletIndicesList.Count == uvList.Count == vertexColorList.Count + /// + public class BigMesh + { + public List vertexList = new List(); + public List triangleStripList = new List(); + + /// + /// -1 if nodraw flag set + /// + public int textureIndex = -1; + + public MaterialDef matDef; + + public List vifPacketIndices = new List(); + + public class TriangleStrip + { + public List vertexIndices = new List(); + public List uvList = new List(); + + /// + /// vertex color rgba is directly written. + /// 128 is PS2's max. 255 is doubled intensity. + /// + public List vertexColorList = new List(); + } + } +} diff --git a/OpenKh.Command.MapGen/Models/BigMeshContainer.cs b/OpenKh.Command.MapGen/Models/BigMeshContainer.cs index b08a961ce..d4d1b84d8 100644 --- a/OpenKh.Command.MapGen/Models/BigMeshContainer.cs +++ b/OpenKh.Command.MapGen/Models/BigMeshContainer.cs @@ -1,46 +1,46 @@ -using Assimp; -using OpenKh.Command.MapGen.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using static OpenKh.Command.MapGen.Models.MapGenConfig; - -namespace OpenKh.Command.MapGen.Models -{ - public class BigMeshContainer - { - public List MeshList { get; } = new List(); - - public List AllocatedMaterialDefs { get; } = new List(); - - public BigMesh AllocateBigMeshForMaterial(MaterialDef matDef) - { - var it = MeshList.Find(it => it.matDef == matDef); - if (it == null) - { - var textureIndex = -1; - if (!matDef.nodraw) - { - textureIndex = AllocatedMaterialDefs.Count; - AllocatedMaterialDefs.Add(matDef); - } - - var newOne = new BigMesh - { - matDef = matDef, - textureIndex = textureIndex, - }; - MeshList.Add(newOne); - return newOne; - } - else - { - return it; - } - } - - public IEnumerable GetMaterialDefList() => - MeshList.Select(one => one.matDef); - } -} +using Assimp; +using OpenKh.Command.MapGen.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using static OpenKh.Command.MapGen.Models.MapGenConfig; + +namespace OpenKh.Command.MapGen.Models +{ + public class BigMeshContainer + { + public List MeshList { get; } = new List(); + + public List AllocatedMaterialDefs { get; } = new List(); + + public BigMesh AllocateBigMeshForMaterial(MaterialDef matDef) + { + var it = MeshList.Find(it => it.matDef == matDef); + if (it == null) + { + var textureIndex = -1; + if (!matDef.nodraw) + { + textureIndex = AllocatedMaterialDefs.Count; + AllocatedMaterialDefs.Add(matDef); + } + + var newOne = new BigMesh + { + matDef = matDef, + textureIndex = textureIndex, + }; + MeshList.Add(newOne); + return newOne; + } + else + { + return it; + } + } + + public IEnumerable GetMaterialDefList() => + MeshList.Select(one => one.matDef); + } +} diff --git a/OpenKh.Command.MapGen/Models/MapGenConfig.cs b/OpenKh.Command.MapGen/Models/MapGenConfig.cs index 614945158..a219c7907 100644 --- a/OpenKh.Command.MapGen/Models/MapGenConfig.cs +++ b/OpenKh.Command.MapGen/Models/MapGenConfig.cs @@ -1,96 +1,96 @@ -using OpenKh.Command.MapGen.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace OpenKh.Command.MapGen.Models -{ - public class MapGenConfig - { - /// - /// Input 3D model file - /// - public string inputFile { get; set; } - - /// - /// Output `.map` file - /// - public string outputFile { get; set; } - - public float scale { get; set; } = 1; - - public string[] imageDirs { get; set; } = new string[] { "images" }; - - /// - /// options for imgtool if needed - /// - public string imgtoolOptions { get; set; } - - /// - /// The material set for matching 3D model's material name - /// - public List materials { get; set; } = new List(); - - public List addFiles { get; set; } = new List(); - - public bool skipConversionIfExists { get; set; } - - public float[] applyMatrix { get; set; } - - public TextureOptions textureOptions { get; set; } = new TextureOptions(); - - public class AddFile - { - public string name { get; set; } - public int type { get; set; } - public string fromFile { get; set; } - public int index { get; set; } - } - - public BarConfig bar { get; set; } - - public class BarConfig - { - public BarEntryConfig model { get; set; } - public BarEntryConfig texture { get; set; } - public BarEntryConfig coct { get; set; } - public BarEntryConfig doct { get; set; } - } - - public class BarEntryConfig - { - public string name { get; set; } - public string toFile { get; set; } - } - - public bool disableTriangleStripsOptimization { get; set; } - - public bool disableBSPCollisionBuilder { get; set; } - - public byte? maxColorIntensity { get; set; } - - public byte? maxAlpha { get; set; } - - public bool reuseImd { get; set; } - - public List uvscList { get; set; } = new List(); - - public class UvscItem - { - /// - /// 0 to 15 - /// - public int index { get; set; } - public float u { get; set; } - public float v { get; set; } - } - - public MaterialDef FindMaterial(string name) - { - return materials - .FirstOrDefault(one => SimplePatternUtil.CreateFrom(one.name).IsMatch(name)); - } - } -} +using OpenKh.Command.MapGen.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace OpenKh.Command.MapGen.Models +{ + public class MapGenConfig + { + /// + /// Input 3D model file + /// + public string inputFile { get; set; } + + /// + /// Output `.map` file + /// + public string outputFile { get; set; } + + public float scale { get; set; } = 1; + + public string[] imageDirs { get; set; } = new string[] { "images" }; + + /// + /// options for imgtool if needed + /// + public string imgtoolOptions { get; set; } + + /// + /// The material set for matching 3D model's material name + /// + public List materials { get; set; } = new List(); + + public List addFiles { get; set; } = new List(); + + public bool skipConversionIfExists { get; set; } + + public float[] applyMatrix { get; set; } + + public TextureOptions textureOptions { get; set; } = new TextureOptions(); + + public class AddFile + { + public string name { get; set; } + public int type { get; set; } + public string fromFile { get; set; } + public int index { get; set; } + } + + public BarConfig bar { get; set; } + + public class BarConfig + { + public BarEntryConfig model { get; set; } + public BarEntryConfig texture { get; set; } + public BarEntryConfig coct { get; set; } + public BarEntryConfig doct { get; set; } + } + + public class BarEntryConfig + { + public string name { get; set; } + public string toFile { get; set; } + } + + public bool disableTriangleStripsOptimization { get; set; } + + public bool disableBSPCollisionBuilder { get; set; } + + public byte? maxColorIntensity { get; set; } + + public byte? maxAlpha { get; set; } + + public bool reuseImd { get; set; } + + public List uvscList { get; set; } = new List(); + + public class UvscItem + { + /// + /// 0 to 15 + /// + public int index { get; set; } + public float u { get; set; } + public float v { get; set; } + } + + public MaterialDef FindMaterial(string name) + { + return materials + .FirstOrDefault(one => SimplePatternUtil.CreateFrom(one.name).IsMatch(name)); + } + } +} diff --git a/OpenKh.Command.MapGen/Models/MaterialDef.cs b/OpenKh.Command.MapGen/Models/MaterialDef.cs index 17104e6f7..9229749bf 100644 --- a/OpenKh.Command.MapGen/Models/MaterialDef.cs +++ b/OpenKh.Command.MapGen/Models/MaterialDef.cs @@ -1,77 +1,77 @@ -using Microsoft.VisualBasic.CompilerServices; -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Command.MapGen.Models -{ - public class MaterialDef - { - /// - /// model's material name matching by simple pattern - /// - public string name { get; set; } - - /// - /// do not render - /// - public bool ignore { get; set; } - - /// - /// texture from png file - /// - public string fromFile { get; set; } - - /// - /// use if reuseImd: Path.ChangeExtension(fromFile3, ".imd") - /// - public string fromFile2 { get; set; } - - /// - /// texture from png file (diffuse map with texture file source) - /// - public string fromFile3 { get; set; } - - /// - /// Have not collision - /// - public bool noclip { get; set; } = false; - - /// - /// Have not rendered - /// - public bool nodraw { get; set; } = false; - - /// - /// surfaceFlags if has collision - /// - public int surfaceFlags { get; set; } = 0x3f1; - - /// - /// Intensity: PS2'S 128 is Windows's 255. - /// - public byte? maxColorIntensity { get; set; } - - /// - /// Intensity: PS2'S 128 is Windows's 255. - /// - public byte? maxAlpha { get; set; } - - /// - /// options for imgtool if needed - /// - public string imgtoolOptions { get; set; } - - public TextureOptions textureOptions { get; set; } = new TextureOptions(); - - public short? transparentFlag { get; set; } - - public int? uvscIndex { get; set; } - - public static MaterialDef CreateFallbackFor(string name) => - new MaterialDef - { - name = name, - }; - } -} +using Microsoft.VisualBasic.CompilerServices; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Command.MapGen.Models +{ + public class MaterialDef + { + /// + /// model's material name matching by simple pattern + /// + public string name { get; set; } + + /// + /// do not render + /// + public bool ignore { get; set; } + + /// + /// texture from png file + /// + public string fromFile { get; set; } + + /// + /// use if reuseImd: Path.ChangeExtension(fromFile3, ".imd") + /// + public string fromFile2 { get; set; } + + /// + /// texture from png file (diffuse map with texture file source) + /// + public string fromFile3 { get; set; } + + /// + /// Have not collision + /// + public bool noclip { get; set; } = false; + + /// + /// Have not rendered + /// + public bool nodraw { get; set; } = false; + + /// + /// surfaceFlags if has collision + /// + public int surfaceFlags { get; set; } = 0x3f1; + + /// + /// Intensity: PS2'S 128 is Windows's 255. + /// + public byte? maxColorIntensity { get; set; } + + /// + /// Intensity: PS2'S 128 is Windows's 255. + /// + public byte? maxAlpha { get; set; } + + /// + /// options for imgtool if needed + /// + public string imgtoolOptions { get; set; } + + public TextureOptions textureOptions { get; set; } = new TextureOptions(); + + public short? transparentFlag { get; set; } + + public int? uvscIndex { get; set; } + + public static MaterialDef CreateFallbackFor(string name) => + new MaterialDef + { + name = name, + }; + } +} diff --git a/OpenKh.Command.MapGen/Models/TextureOption.cs b/OpenKh.Command.MapGen/Models/TextureOption.cs index 98344d0db..9ef0d3b60 100644 --- a/OpenKh.Command.MapGen/Models/TextureOption.cs +++ b/OpenKh.Command.MapGen/Models/TextureOption.cs @@ -1,12 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Command.MapGen.Models -{ - public class TextureOptions - { - public string addressU { get; set; } - public string addressV { get; set; } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Command.MapGen.Models +{ + public class TextureOptions + { + public string addressU { get; set; } + public string addressV { get; set; } + } +} diff --git a/OpenKh.Command.MapGen/Program.cs b/OpenKh.Command.MapGen/Program.cs index 8b8a43657..797fa4725 100644 --- a/OpenKh.Command.MapGen/Program.cs +++ b/OpenKh.Command.MapGen/Program.cs @@ -1,64 +1,64 @@ -using McMaster.Extensions.CommandLineUtils; -using System; -using System.IO; -using System.Reflection; -using System.ComponentModel.DataAnnotations; -using OpenKh.Common.Exceptions; -using OpenKh.Command.MapGen.Utils; -using NLog; - -namespace OpenKh.Command.MapGen -{ - [Command("OpenKh.Command.MapGen")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - class Program - { - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (InvalidFileException e) - { - Console.WriteLine(e.Message); - return 3; - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - return 2; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return -1; - } - } - - [Required] - [FileExists] - [Argument(0, Description = "Input file: mapdef.yml or model.{fbx,dae}")] - public string InputFile { get; set; } - - [Argument(1, Description = "Output map file")] - public string OutputMap { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - try - { - new MapGenUtil().Run(InputFile, OutputMap); - - return 0; - } - finally - { - LogManager.Shutdown(); - } - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - } -} +using McMaster.Extensions.CommandLineUtils; +using System; +using System.IO; +using System.Reflection; +using System.ComponentModel.DataAnnotations; +using OpenKh.Common.Exceptions; +using OpenKh.Command.MapGen.Utils; +using NLog; + +namespace OpenKh.Command.MapGen +{ + [Command("OpenKh.Command.MapGen")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + class Program + { + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (InvalidFileException e) + { + Console.WriteLine(e.Message); + return 3; + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + return 2; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return -1; + } + } + + [Required] + [FileExists] + [Argument(0, Description = "Input file: mapdef.yml or model.{fbx,dae}")] + public string InputFile { get; set; } + + [Argument(1, Description = "Output map file")] + public string OutputMap { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + try + { + new MapGenUtil().Run(InputFile, OutputMap); + + return 0; + } + finally + { + LogManager.Shutdown(); + } + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + } +} diff --git a/OpenKh.Command.MapGen/Utils/BigMeshSplitter.cs b/OpenKh.Command.MapGen/Utils/BigMeshSplitter.cs index acee9f6bc..04778cd7d 100644 --- a/OpenKh.Command.MapGen/Utils/BigMeshSplitter.cs +++ b/OpenKh.Command.MapGen/Utils/BigMeshSplitter.cs @@ -1,75 +1,75 @@ -using OpenKh.Command.MapGen.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace OpenKh.Command.MapGen.Utils -{ - public static class BigMeshSplitter - { - private const int MaxVertCount = 71; - - public static IEnumerable Split(BigMesh bigMesh) - { - var stripIndex = 0; - var maxStrip = bigMesh.triangleStripList.Count; - while (stripIndex < maxStrip) - { - var smallMesh = new BigMesh - { - textureIndex = bigMesh.textureIndex, - matDef = bigMesh.matDef, - }; - - var localIndexMap = new Dictionary(); - var countStocked = 0; - for (; stripIndex < maxStrip; stripIndex++) - { - var triStrip = bigMesh.triangleStripList[stripIndex]; - - if (countStocked + triStrip.vertexIndices.Count > MaxVertCount) - { - break; - } - - var newTriStrip = new BigMesh.TriangleStrip - { - uvList = triStrip.uvList.ToList(), - vertexColorList = triStrip.vertexColorList.ToList(), - vertexIndices = triStrip.vertexIndices - .Select(gi => MapToLocal(localIndexMap, gi)) - .ToList(), - }; - - smallMesh.triangleStripList.Add(newTriStrip); - - countStocked += newTriStrip.vertexIndices.Count; - } - - var globalIndexMap = localIndexMap - .ToDictionary(pair => pair.Value, pair => pair.Key); - - smallMesh.textureIndex = bigMesh.textureIndex; - - for (int loop = 0; loop < localIndexMap.Count; loop++) - { - var globalIndex = globalIndexMap[loop]; - smallMesh.vertexList.Add(bigMesh.vertexList[globalIndex]); - } - - yield return smallMesh; - } - } - - private static int MapToLocal(IDictionary dict, int index) - { - if (!dict.TryGetValue(index, out int localIndex)) - { - localIndex = dict.Count; - dict[index] = localIndex; - } - return localIndex; - } - } -} +using OpenKh.Command.MapGen.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenKh.Command.MapGen.Utils +{ + public static class BigMeshSplitter + { + private const int MaxVertCount = 71; + + public static IEnumerable Split(BigMesh bigMesh) + { + var stripIndex = 0; + var maxStrip = bigMesh.triangleStripList.Count; + while (stripIndex < maxStrip) + { + var smallMesh = new BigMesh + { + textureIndex = bigMesh.textureIndex, + matDef = bigMesh.matDef, + }; + + var localIndexMap = new Dictionary(); + var countStocked = 0; + for (; stripIndex < maxStrip; stripIndex++) + { + var triStrip = bigMesh.triangleStripList[stripIndex]; + + if (countStocked + triStrip.vertexIndices.Count > MaxVertCount) + { + break; + } + + var newTriStrip = new BigMesh.TriangleStrip + { + uvList = triStrip.uvList.ToList(), + vertexColorList = triStrip.vertexColorList.ToList(), + vertexIndices = triStrip.vertexIndices + .Select(gi => MapToLocal(localIndexMap, gi)) + .ToList(), + }; + + smallMesh.triangleStripList.Add(newTriStrip); + + countStocked += newTriStrip.vertexIndices.Count; + } + + var globalIndexMap = localIndexMap + .ToDictionary(pair => pair.Value, pair => pair.Key); + + smallMesh.textureIndex = bigMesh.textureIndex; + + for (int loop = 0; loop < localIndexMap.Count; loop++) + { + var globalIndex = globalIndexMap[loop]; + smallMesh.vertexList.Add(bigMesh.vertexList[globalIndex]); + } + + yield return smallMesh; + } + } + + private static int MapToLocal(IDictionary dict, int index) + { + if (!dict.TryGetValue(index, out int localIndex)) + { + localIndex = dict.Count; + dict[index] = localIndex; + } + return localIndex; + } + } +} diff --git a/OpenKh.Command.MapGen/Utils/CollisionBuilder.cs b/OpenKh.Command.MapGen/Utils/CollisionBuilder.cs index a9b9181ca..1502674e7 100644 --- a/OpenKh.Command.MapGen/Utils/CollisionBuilder.cs +++ b/OpenKh.Command.MapGen/Utils/CollisionBuilder.cs @@ -1,480 +1,480 @@ -using OpenKh.Command.MapGen.Models; -using OpenKh.Kh2; -using System; -using System.Buffers.Binary; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; -using static OpenKh.Kh2.Coct; - -namespace OpenKh.Command.MapGen.Utils -{ - public class CollisionBuilder - { - public readonly Coct coct = new Coct(); - public readonly Doct doct = new Doct(); - - public List vifPacketRenderingGroup { get; } = new List(); - - public CollisionBuilder(IEnumerable bigMeshes, bool disableBSPCollisionBuilder) - { - if (disableBSPCollisionBuilder) - { - PerMeshClipRendering(bigMeshes); - } - else - { - UseBinarySeparatedPartitions(bigMeshes); - } - } - - class CenterPointedMesh - { - public BigMesh bigMesh; - - public Vector3 centerPoint; - - public CenterPointedMesh(BigMesh bigMesh) - { - this.bigMesh = bigMesh; - - centerPoint = GetCenter( - bigMesh.triangleStripList - .SelectMany(triangleStrip => triangleStrip.vertexIndices) - .Select(index => bigMesh.vertexList[index]) - ); - } - - public override string ToString() => centerPoint.ToString(); - - private static Vector3 GetCenter(IEnumerable positions) - { - double x = 0, y = 0, z = 0; - int n = 0; - foreach (var one in positions) - { - ++n; - x += one.X; - y += one.Y; - z += one.Z; - } - return new Vector3( - (float)(x / n), - (float)(y / n), - (float)(z / n) - ); - } - } - - /// - /// Binary separated partitions - /// - class BSP - { - public CenterPointedMesh[] Points { get; } - - public BSP(CenterPointedMesh[] points) - { - Points = points; - } - - public override string ToString() => $"{Points.Length:#,##0} points"; - - public BSP[] Split() - { - if (Points.Length >= 20) - { - var range = new Range(Points); - if (range.yLen >= range.xLen) - { - if (range.zLen >= range.yLen) - { - // z-cut - return new BSP[] - { - new BSP(Points.Where(it => it.centerPoint.Z >= range.zCenter).ToArray()), - new BSP(Points.Where(it => it.centerPoint.Z < range.zCenter).ToArray()), - }; - } - else - { - // y-cut - return new BSP[] - { - new BSP(Points.Where(it => it.centerPoint.Y >= range.yCenter).ToArray()), - new BSP(Points.Where(it => it.centerPoint.Y < range.yCenter).ToArray()), - }; - } - } - else - { - // x-cut - return new BSP[] - { - new BSP(Points.Where(it => it.centerPoint.X >= range.xCenter).ToArray()), - new BSP(Points.Where(it => it.centerPoint.X < range.xCenter).ToArray()), - }; - } - } - return new BSP[] { this }; - } - - class Range - { - public float xMin = float.MaxValue; - public float xMax = float.MinValue; - public float yMin = float.MaxValue; - public float yMax = float.MinValue; - public float zMin = float.MaxValue; - public float zMax = float.MinValue; - - public float xLen; - public float yLen; - public float zLen; - - public float xCenter; - public float yCenter; - public float zCenter; - - public Range(CenterPointedMesh[] points) - { - foreach (var point in points) - { - var position = point.centerPoint; - xMin = Math.Min(xMin, position.X); - xMax = Math.Max(xMax, position.X); - yMin = Math.Min(yMin, position.Y); - yMax = Math.Max(yMax, position.Y); - zMin = Math.Min(zMin, position.Z); - zMax = Math.Max(zMax, position.Z); - } - xLen = (xMax - xMin); - yLen = (yMax - yMin); - zLen = (zMax - zMin); - xCenter = (xMax + xMin) / 2; - yCenter = (yMax + yMin) / 2; - zCenter = (zMax + zMin) / 2; - } - } - } - - class BSPWalker - { - private Coct coct; - private BuildHelper helper; - - public List vifPacketRenderingGroup = new List(); - public List collisionMeshList = new List(); - - public BSPWalker(BSP bsp, Coct coct, BuildHelper helper) - { - this.coct = coct; - this.helper = helper; - - JoinResult( - Walk(bsp), - null - ); - } - - class WalkResult - { - internal int? groupIndex; - internal CollisionMesh? mesh; - - public override string ToString() => $"group({groupIndex}) mesh({mesh})"; - } - - private WalkResult Walk(BSP bsp) - { - var pair = bsp.Split(); - if (pair.Length == 2) - { - return JoinResult( - Walk(pair[0]), - Walk(pair[1]) - ); - } - else - { - var collisionMesh = new CollisionMesh - { - Collisions = new List() - }; - - var vifPacketIndices = new List(); - - foreach (var point in pair[0].Points) - { - var mesh = point.bigMesh; - - vifPacketIndices.AddRange(mesh.vifPacketIndices); - - foreach (var set in TriangleStripsToTriangleFans(mesh.triangleStripList)) - { - var quad = set.Count == 4; - - var v1 = mesh.vertexList[set[0]]; - var v2 = mesh.vertexList[set[1]]; - var v3 = mesh.vertexList[set[2]]; - var v4 = quad ? mesh.vertexList[set[3]] : Vector3.Zero; - - collisionMesh.Collisions.Add(coct.Complete( - new Collision - { - Vertex1 = helper.AllocateVertex(v1.X, -v1.Y, -v1.Z), // why -Y and -Z ? - Vertex2 = helper.AllocateVertex(v2.X, -v2.Y, -v2.Z), - Vertex3 = helper.AllocateVertex(v3.X, -v3.Y, -v3.Z), - Vertex4 = Convert.ToInt16(quad ? helper.AllocateVertex(v4.X, -v4.Y, -v4.Z) : -1), - Attributes = new Attributes() { Flags = mesh.matDef.surfaceFlags } - }, - inflate: 1 - )); - } - } - - coct.Complete(collisionMesh); - - collisionMeshList.Add(collisionMesh); - - vifPacketRenderingGroup.Add( - vifPacketIndices - .Distinct() - .ToArray() - ); - - return new WalkResult - { - mesh = collisionMesh, - }; - } - } - - private WalkResult JoinResult(WalkResult left, WalkResult right) - { - var groupChildren = new List(); - - if (left.mesh != null) - { - groupChildren.Add(coct.Nodes.Count); - - coct.CompleteAndAdd( - new CollisionNode - { - Meshes = new List { left.mesh } - } - ); - } - else if (left.groupIndex.HasValue) - { - groupChildren.Add(left.groupIndex.Value); - } - - if (right == null) - { - // skip - } - else if (right.mesh != null) - { - groupChildren.Add(coct.Nodes.Count); - - coct.CompleteAndAdd( - new CollisionNode - { - Meshes = new List { right.mesh } - } - ); - } - else if (right.groupIndex.HasValue) - { - groupChildren.Add(right.groupIndex.Value); - } - - var firstIdx1 = coct.Nodes.Count; - - coct.CompleteAndAdd( - new CollisionNode - { - Meshes = new List(), - Child1 = Convert.ToInt16((groupChildren.Count >= 1) ? groupChildren[0] : -1), - Child2 = Convert.ToInt16((groupChildren.Count >= 2) ? groupChildren[1] : -1), - } - ); - - return new WalkResult - { - groupIndex = firstIdx1, - }; - } - } - - private void UseBinarySeparatedPartitions(IEnumerable bigMeshes) - { - var bsp = new BSP( - bigMeshes - .Where(mesh => !mesh.matDef.noclip) - .Select(mesh => new CenterPointedMesh(mesh)) - .ToArray() - ); - - var helper = new BuildHelper(coct); - var walker = new BSPWalker(bsp, coct, helper); - - vifPacketRenderingGroup.AddRange(walker.vifPacketRenderingGroup); - - coct.ReverseMeshGroup(); - - // Entry2 index is tightly coupled to vifPacketRenderingGroup's index. - // Thus do not add Entry2 unplanned. - - CreateDoctFromCoct(walker.collisionMeshList); - } - - private void CreateDoctFromCoct(IList vifPacketRenderingGroupIndexMatched) - { - // directly mapping: - // coctMesh → doct.Entry2 - // coctMeshGroup → doct.Entry1 - - var coctMeshList = new List(); - - foreach (var coctMeshGroup in coct.Nodes) - { - var vifPacketIndices = coctMeshGroup.Meshes - .Select(it => vifPacketRenderingGroupIndexMatched.IndexOf(it)) - .ToArray(); - - var minIdx = 0; - var maxIdx = 0; - if (vifPacketIndices.Length != 0) - { - minIdx = vifPacketIndices.Min(); - maxIdx = vifPacketIndices.Max() + 1; - } - - doct.Entry1List.Add( - new Doct.Entry1 - { - Child1 = coctMeshGroup.Child1, - Child2 = coctMeshGroup.Child2, - Child3 = coctMeshGroup.Child3, - Child4 = coctMeshGroup.Child4, - Child5 = coctMeshGroup.Child5, - Child6 = coctMeshGroup.Child6, - Child7 = coctMeshGroup.Child7, - Child8 = coctMeshGroup.Child8, - BoundingBox = coctMeshGroup.BoundingBox.ToBoundingBox(), - Entry2Index = (ushort)minIdx, - Entry2LastIndex = (ushort)maxIdx, - } - ); - } - - foreach (var coctMesh in vifPacketRenderingGroupIndexMatched) - { - doct.Add( - new Doct.Entry2 - { - BoundingBox = coctMesh.BoundingBox - .ToBoundingBox(), - } - ); - } - } - - private void PerMeshClipRendering(IEnumerable bigMeshes) - { - var meshList = new List(); - - var helper = new BuildHelper(coct); - - foreach (var mesh in bigMeshes.Where(it => !it.matDef.noclip)) - { - var collisionMesh = new CollisionMesh - { - Collisions = new List() - }; - - var vifPacketIndices = new List(mesh.vifPacketIndices); - - foreach (var set in TriangleStripsToTriangleFans(mesh.triangleStripList)) - { - var quad = set.Count == 4; - - var v1 = mesh.vertexList[set[0]]; - var v2 = mesh.vertexList[set[1]]; - var v3 = mesh.vertexList[set[2]]; - var v4 = quad ? mesh.vertexList[set[3]] : Vector3.Zero; - - collisionMesh.Collisions.Add(coct.Complete( - new Collision - { - Vertex1 = helper.AllocateVertex(v1.X, -v1.Y, -v1.Z), // why -Y and -Z ? - Vertex2 = helper.AllocateVertex(v2.X, -v2.Y, -v2.Z), - Vertex3 = helper.AllocateVertex(v3.X, -v3.Y, -v3.Z), - Vertex4 = Convert.ToInt16(quad ? helper.AllocateVertex(v4.X, -v4.Y, -v4.Z) : -1), - Attributes = new Attributes() { Flags = mesh.matDef.surfaceFlags } - }, - inflate: 1 - )); - } - - vifPacketRenderingGroup.Add( - vifPacketIndices - .Distinct() - .ToArray() - ); - - coct.Complete(collisionMesh); - meshList.Add(collisionMesh); - } - - coct.CompleteAndAdd( - new CollisionNode - { - Meshes = meshList - } - ); - - // Entry2 index is tightly coupled to vifPacketRenderingGroup's index. - // Thus do not add Entry2 unplanned. - - CreateDoctFromCoct(meshList); - } - - private static IEnumerable> TriangleStripsToTriangleFans(IList list) - { - foreach (var set in list) - { - var cx = set.vertexIndices.Count; - if (cx == 3) - { - yield return set.vertexIndices; - } - if (cx >= 4) - { - for (int x = 4; x <= cx; x += 2) - { - yield return new int[] - { - set.vertexIndices[x - 4 + 0], - set.vertexIndices[x - 4 + 1], - set.vertexIndices[x - 4 + 3], - set.vertexIndices[x - 4 + 2], - }; - if (x + 1 == cx) - { - yield return new int[] - { - set.vertexIndices[x - 2 + 0], - set.vertexIndices[x - 2 + 1], - set.vertexIndices[x - 2 + 2], - }; - } - } - } - } - } - } -} +using OpenKh.Command.MapGen.Models; +using OpenKh.Kh2; +using System; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using static OpenKh.Kh2.Coct; + +namespace OpenKh.Command.MapGen.Utils +{ + public class CollisionBuilder + { + public readonly Coct coct = new Coct(); + public readonly Doct doct = new Doct(); + + public List vifPacketRenderingGroup { get; } = new List(); + + public CollisionBuilder(IEnumerable bigMeshes, bool disableBSPCollisionBuilder) + { + if (disableBSPCollisionBuilder) + { + PerMeshClipRendering(bigMeshes); + } + else + { + UseBinarySeparatedPartitions(bigMeshes); + } + } + + class CenterPointedMesh + { + public BigMesh bigMesh; + + public Vector3 centerPoint; + + public CenterPointedMesh(BigMesh bigMesh) + { + this.bigMesh = bigMesh; + + centerPoint = GetCenter( + bigMesh.triangleStripList + .SelectMany(triangleStrip => triangleStrip.vertexIndices) + .Select(index => bigMesh.vertexList[index]) + ); + } + + public override string ToString() => centerPoint.ToString(); + + private static Vector3 GetCenter(IEnumerable positions) + { + double x = 0, y = 0, z = 0; + int n = 0; + foreach (var one in positions) + { + ++n; + x += one.X; + y += one.Y; + z += one.Z; + } + return new Vector3( + (float)(x / n), + (float)(y / n), + (float)(z / n) + ); + } + } + + /// + /// Binary separated partitions + /// + class BSP + { + public CenterPointedMesh[] Points { get; } + + public BSP(CenterPointedMesh[] points) + { + Points = points; + } + + public override string ToString() => $"{Points.Length:#,##0} points"; + + public BSP[] Split() + { + if (Points.Length >= 20) + { + var range = new Range(Points); + if (range.yLen >= range.xLen) + { + if (range.zLen >= range.yLen) + { + // z-cut + return new BSP[] + { + new BSP(Points.Where(it => it.centerPoint.Z >= range.zCenter).ToArray()), + new BSP(Points.Where(it => it.centerPoint.Z < range.zCenter).ToArray()), + }; + } + else + { + // y-cut + return new BSP[] + { + new BSP(Points.Where(it => it.centerPoint.Y >= range.yCenter).ToArray()), + new BSP(Points.Where(it => it.centerPoint.Y < range.yCenter).ToArray()), + }; + } + } + else + { + // x-cut + return new BSP[] + { + new BSP(Points.Where(it => it.centerPoint.X >= range.xCenter).ToArray()), + new BSP(Points.Where(it => it.centerPoint.X < range.xCenter).ToArray()), + }; + } + } + return new BSP[] { this }; + } + + class Range + { + public float xMin = float.MaxValue; + public float xMax = float.MinValue; + public float yMin = float.MaxValue; + public float yMax = float.MinValue; + public float zMin = float.MaxValue; + public float zMax = float.MinValue; + + public float xLen; + public float yLen; + public float zLen; + + public float xCenter; + public float yCenter; + public float zCenter; + + public Range(CenterPointedMesh[] points) + { + foreach (var point in points) + { + var position = point.centerPoint; + xMin = Math.Min(xMin, position.X); + xMax = Math.Max(xMax, position.X); + yMin = Math.Min(yMin, position.Y); + yMax = Math.Max(yMax, position.Y); + zMin = Math.Min(zMin, position.Z); + zMax = Math.Max(zMax, position.Z); + } + xLen = (xMax - xMin); + yLen = (yMax - yMin); + zLen = (zMax - zMin); + xCenter = (xMax + xMin) / 2; + yCenter = (yMax + yMin) / 2; + zCenter = (zMax + zMin) / 2; + } + } + } + + class BSPWalker + { + private Coct coct; + private BuildHelper helper; + + public List vifPacketRenderingGroup = new List(); + public List collisionMeshList = new List(); + + public BSPWalker(BSP bsp, Coct coct, BuildHelper helper) + { + this.coct = coct; + this.helper = helper; + + JoinResult( + Walk(bsp), + null + ); + } + + class WalkResult + { + internal int? groupIndex; + internal CollisionMesh? mesh; + + public override string ToString() => $"group({groupIndex}) mesh({mesh})"; + } + + private WalkResult Walk(BSP bsp) + { + var pair = bsp.Split(); + if (pair.Length == 2) + { + return JoinResult( + Walk(pair[0]), + Walk(pair[1]) + ); + } + else + { + var collisionMesh = new CollisionMesh + { + Collisions = new List() + }; + + var vifPacketIndices = new List(); + + foreach (var point in pair[0].Points) + { + var mesh = point.bigMesh; + + vifPacketIndices.AddRange(mesh.vifPacketIndices); + + foreach (var set in TriangleStripsToTriangleFans(mesh.triangleStripList)) + { + var quad = set.Count == 4; + + var v1 = mesh.vertexList[set[0]]; + var v2 = mesh.vertexList[set[1]]; + var v3 = mesh.vertexList[set[2]]; + var v4 = quad ? mesh.vertexList[set[3]] : Vector3.Zero; + + collisionMesh.Collisions.Add(coct.Complete( + new Collision + { + Vertex1 = helper.AllocateVertex(v1.X, -v1.Y, -v1.Z), // why -Y and -Z ? + Vertex2 = helper.AllocateVertex(v2.X, -v2.Y, -v2.Z), + Vertex3 = helper.AllocateVertex(v3.X, -v3.Y, -v3.Z), + Vertex4 = Convert.ToInt16(quad ? helper.AllocateVertex(v4.X, -v4.Y, -v4.Z) : -1), + Attributes = new Attributes() { Flags = mesh.matDef.surfaceFlags } + }, + inflate: 1 + )); + } + } + + coct.Complete(collisionMesh); + + collisionMeshList.Add(collisionMesh); + + vifPacketRenderingGroup.Add( + vifPacketIndices + .Distinct() + .ToArray() + ); + + return new WalkResult + { + mesh = collisionMesh, + }; + } + } + + private WalkResult JoinResult(WalkResult left, WalkResult right) + { + var groupChildren = new List(); + + if (left.mesh != null) + { + groupChildren.Add(coct.Nodes.Count); + + coct.CompleteAndAdd( + new CollisionNode + { + Meshes = new List { left.mesh } + } + ); + } + else if (left.groupIndex.HasValue) + { + groupChildren.Add(left.groupIndex.Value); + } + + if (right == null) + { + // skip + } + else if (right.mesh != null) + { + groupChildren.Add(coct.Nodes.Count); + + coct.CompleteAndAdd( + new CollisionNode + { + Meshes = new List { right.mesh } + } + ); + } + else if (right.groupIndex.HasValue) + { + groupChildren.Add(right.groupIndex.Value); + } + + var firstIdx1 = coct.Nodes.Count; + + coct.CompleteAndAdd( + new CollisionNode + { + Meshes = new List(), + Child1 = Convert.ToInt16((groupChildren.Count >= 1) ? groupChildren[0] : -1), + Child2 = Convert.ToInt16((groupChildren.Count >= 2) ? groupChildren[1] : -1), + } + ); + + return new WalkResult + { + groupIndex = firstIdx1, + }; + } + } + + private void UseBinarySeparatedPartitions(IEnumerable bigMeshes) + { + var bsp = new BSP( + bigMeshes + .Where(mesh => !mesh.matDef.noclip) + .Select(mesh => new CenterPointedMesh(mesh)) + .ToArray() + ); + + var helper = new BuildHelper(coct); + var walker = new BSPWalker(bsp, coct, helper); + + vifPacketRenderingGroup.AddRange(walker.vifPacketRenderingGroup); + + coct.ReverseMeshGroup(); + + // Entry2 index is tightly coupled to vifPacketRenderingGroup's index. + // Thus do not add Entry2 unplanned. + + CreateDoctFromCoct(walker.collisionMeshList); + } + + private void CreateDoctFromCoct(IList vifPacketRenderingGroupIndexMatched) + { + // directly mapping: + // coctMesh → doct.Entry2 + // coctMeshGroup → doct.Entry1 + + var coctMeshList = new List(); + + foreach (var coctMeshGroup in coct.Nodes) + { + var vifPacketIndices = coctMeshGroup.Meshes + .Select(it => vifPacketRenderingGroupIndexMatched.IndexOf(it)) + .ToArray(); + + var minIdx = 0; + var maxIdx = 0; + if (vifPacketIndices.Length != 0) + { + minIdx = vifPacketIndices.Min(); + maxIdx = vifPacketIndices.Max() + 1; + } + + doct.Entry1List.Add( + new Doct.Entry1 + { + Child1 = coctMeshGroup.Child1, + Child2 = coctMeshGroup.Child2, + Child3 = coctMeshGroup.Child3, + Child4 = coctMeshGroup.Child4, + Child5 = coctMeshGroup.Child5, + Child6 = coctMeshGroup.Child6, + Child7 = coctMeshGroup.Child7, + Child8 = coctMeshGroup.Child8, + BoundingBox = coctMeshGroup.BoundingBox.ToBoundingBox(), + Entry2Index = (ushort)minIdx, + Entry2LastIndex = (ushort)maxIdx, + } + ); + } + + foreach (var coctMesh in vifPacketRenderingGroupIndexMatched) + { + doct.Add( + new Doct.Entry2 + { + BoundingBox = coctMesh.BoundingBox + .ToBoundingBox(), + } + ); + } + } + + private void PerMeshClipRendering(IEnumerable bigMeshes) + { + var meshList = new List(); + + var helper = new BuildHelper(coct); + + foreach (var mesh in bigMeshes.Where(it => !it.matDef.noclip)) + { + var collisionMesh = new CollisionMesh + { + Collisions = new List() + }; + + var vifPacketIndices = new List(mesh.vifPacketIndices); + + foreach (var set in TriangleStripsToTriangleFans(mesh.triangleStripList)) + { + var quad = set.Count == 4; + + var v1 = mesh.vertexList[set[0]]; + var v2 = mesh.vertexList[set[1]]; + var v3 = mesh.vertexList[set[2]]; + var v4 = quad ? mesh.vertexList[set[3]] : Vector3.Zero; + + collisionMesh.Collisions.Add(coct.Complete( + new Collision + { + Vertex1 = helper.AllocateVertex(v1.X, -v1.Y, -v1.Z), // why -Y and -Z ? + Vertex2 = helper.AllocateVertex(v2.X, -v2.Y, -v2.Z), + Vertex3 = helper.AllocateVertex(v3.X, -v3.Y, -v3.Z), + Vertex4 = Convert.ToInt16(quad ? helper.AllocateVertex(v4.X, -v4.Y, -v4.Z) : -1), + Attributes = new Attributes() { Flags = mesh.matDef.surfaceFlags } + }, + inflate: 1 + )); + } + + vifPacketRenderingGroup.Add( + vifPacketIndices + .Distinct() + .ToArray() + ); + + coct.Complete(collisionMesh); + meshList.Add(collisionMesh); + } + + coct.CompleteAndAdd( + new CollisionNode + { + Meshes = meshList + } + ); + + // Entry2 index is tightly coupled to vifPacketRenderingGroup's index. + // Thus do not add Entry2 unplanned. + + CreateDoctFromCoct(meshList); + } + + private static IEnumerable> TriangleStripsToTriangleFans(IList list) + { + foreach (var set in list) + { + var cx = set.vertexIndices.Count; + if (cx == 3) + { + yield return set.vertexIndices; + } + if (cx >= 4) + { + for (int x = 4; x <= cx; x += 2) + { + yield return new int[] + { + set.vertexIndices[x - 4 + 0], + set.vertexIndices[x - 4 + 1], + set.vertexIndices[x - 4 + 3], + set.vertexIndices[x - 4 + 2], + }; + if (x + 1 == cx) + { + yield return new int[] + { + set.vertexIndices[x - 2 + 0], + set.vertexIndices[x - 2 + 1], + set.vertexIndices[x - 2 + 2], + }; + } + } + } + } + } + } +} diff --git a/OpenKh.Command.MapGen/Utils/FileExtUtil.cs b/OpenKh.Command.MapGen/Utils/FileExtUtil.cs index 0e4555088..908f8e5e9 100644 --- a/OpenKh.Command.MapGen/Utils/FileExtUtil.cs +++ b/OpenKh.Command.MapGen/Utils/FileExtUtil.cs @@ -1,14 +1,14 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace OpenKh.Command.MapGen.Utils -{ - static class FileExtUtil - { - public static bool IsExtension(string path, string ext) => - Path.GetExtension(path).Equals(ext, StringComparison.InvariantCultureIgnoreCase); - - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace OpenKh.Command.MapGen.Utils +{ + static class FileExtUtil + { + public static bool IsExtension(string path, string ext) => + Path.GetExtension(path).Equals(ext, StringComparison.InvariantCultureIgnoreCase); + + } +} diff --git a/OpenKh.Command.MapGen/Utils/ImageResizer.cs b/OpenKh.Command.MapGen/Utils/ImageResizer.cs index e721f11c0..be91d78a1 100644 --- a/OpenKh.Command.MapGen/Utils/ImageResizer.cs +++ b/OpenKh.Command.MapGen/Utils/ImageResizer.cs @@ -1,80 +1,80 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Runtime.Versioning; -using System.Text; -using NLog; -using OpenKh.Kh2; - -namespace OpenKh.Command.MapGen.Utils -{ - class ImageResizer - { - private static readonly int[] AllowedTextureWidthList = new int[] { 128, 256, 512 }; - private static readonly int[] AllowedTextureHeightList = new int[] { 64, 128, 256, 512 }; - private static Logger logger = LogManager.GetCurrentClassLogger(); - - public static Imgd NormalizeImageSize(Imgd imgd) - { - if (false - || !AllowedTextureWidthList.Contains(imgd.Size.Width) - || !AllowedTextureHeightList.Contains(imgd.Size.Height) - ) - { - var newWidth = (imgd.Size.Width <= 128) ? 128 - : (imgd.Size.Width <= 256) ? 256 - : 512; - - var newHeight = (imgd.Size.Height <= 64) ? 64 - : (imgd.Size.Height <= 128) ? 128 - : (imgd.Size.Height <= 256) ? 256 - : 512; - - var width = imgd.Size.Width; - var height = imgd.Size.Height; - - logger.Info($"This image will be resized due to comformance of texture size. Resizing from ({width}, {height}) to ({newWidth}, {newHeight})."); - - if (imgd.PixelFormat == Imaging.PixelFormat.Indexed8) - { - var bits = imgd.GetData(); - var newBits = new byte[newWidth * newHeight]; - var dstToSrcX = Enumerable.Range(0, newWidth) - .Select(xPos => (int)(xPos / (float)newWidth * width)) - .ToArray(); - var dstToSrcY = Enumerable.Range(0, newHeight) - .Select(yPos => (int)(yPos / (float)newHeight * height)) - .ToArray(); - - for (var y = 0; y < newHeight; y++) - { - var dstOffset = newWidth * y; - var srcOffset = width * dstToSrcY[y]; - - for (var x = 0; x < newWidth; x++) - { - newBits[dstOffset + x] = bits[srcOffset + dstToSrcX[x]]; - } - } - - return new Imgd( - new Size(newWidth, newHeight), - Imaging.PixelFormat.Indexed8, - newBits, - imgd.GetClut(), - false - ); - } - else - { - throw new NotSupportedException($"{imgd}"); - } - } - else - { - return imgd; - } - } - } -} +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Runtime.Versioning; +using System.Text; +using NLog; +using OpenKh.Kh2; + +namespace OpenKh.Command.MapGen.Utils +{ + class ImageResizer + { + private static readonly int[] AllowedTextureWidthList = new int[] { 128, 256, 512 }; + private static readonly int[] AllowedTextureHeightList = new int[] { 64, 128, 256, 512 }; + private static Logger logger = LogManager.GetCurrentClassLogger(); + + public static Imgd NormalizeImageSize(Imgd imgd) + { + if (false + || !AllowedTextureWidthList.Contains(imgd.Size.Width) + || !AllowedTextureHeightList.Contains(imgd.Size.Height) + ) + { + var newWidth = (imgd.Size.Width <= 128) ? 128 + : (imgd.Size.Width <= 256) ? 256 + : 512; + + var newHeight = (imgd.Size.Height <= 64) ? 64 + : (imgd.Size.Height <= 128) ? 128 + : (imgd.Size.Height <= 256) ? 256 + : 512; + + var width = imgd.Size.Width; + var height = imgd.Size.Height; + + logger.Info($"This image will be resized due to comformance of texture size. Resizing from ({width}, {height}) to ({newWidth}, {newHeight})."); + + if (imgd.PixelFormat == Imaging.PixelFormat.Indexed8) + { + var bits = imgd.GetData(); + var newBits = new byte[newWidth * newHeight]; + var dstToSrcX = Enumerable.Range(0, newWidth) + .Select(xPos => (int)(xPos / (float)newWidth * width)) + .ToArray(); + var dstToSrcY = Enumerable.Range(0, newHeight) + .Select(yPos => (int)(yPos / (float)newHeight * height)) + .ToArray(); + + for (var y = 0; y < newHeight; y++) + { + var dstOffset = newWidth * y; + var srcOffset = width * dstToSrcY[y]; + + for (var x = 0; x < newWidth; x++) + { + newBits[dstOffset + x] = bits[srcOffset + dstToSrcX[x]]; + } + } + + return new Imgd( + new Size(newWidth, newHeight), + Imaging.PixelFormat.Indexed8, + newBits, + imgd.GetClut(), + false + ); + } + else + { + throw new NotSupportedException($"{imgd}"); + } + } + else + { + return imgd; + } + } + } +} diff --git a/OpenKh.Command.MapGen/Utils/MapBuilder.cs b/OpenKh.Command.MapGen/Utils/MapBuilder.cs index ae56380be..2f498295b 100644 --- a/OpenKh.Command.MapGen/Utils/MapBuilder.cs +++ b/OpenKh.Command.MapGen/Utils/MapBuilder.cs @@ -1,500 +1,500 @@ -using NLog; -using OpenKh.Command.MapGen.Models; -using OpenKh.Kh2; -using OpenKh.Kh2.TextureFooter; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Numerics; -using Xe.Graphics; -using Matrix4x4 = System.Numerics.Matrix4x4; - -namespace OpenKh.Command.MapGen.Utils -{ - public class MapBuilder - { - private const int MaxVertCount = 71; - - private Mdlx.M4 mapModel; - private BigMeshContainer bigMeshContainer; - private List smallMeshList = new List(); - private ModelTexture modelTex; - private CollisionBuilder collisionBuilder; - private Logger logger = LogManager.GetCurrentClassLogger(); - private readonly MapGenConfig config; - - public MapBuilder(string modelFile, MapGenConfig config, Func imageLoader) - { - this.config = config; - - ConvertModelIntoMapModel(modelFile, config); - - logger.Debug($"Starting collision plane builder."); - - collisionBuilder = new CollisionBuilder(smallMeshList, config.disableBSPCollisionBuilder); - - if (collisionBuilder.vifPacketRenderingGroup != null) - { - logger.Debug($"Updating vifPacketRenderingGroup builder."); - - mapModel.vifPacketRenderingGroup = collisionBuilder.vifPacketRenderingGroup; - - logger.Debug($"Output: {mapModel.vifPacketRenderingGroup.Count:#,##0} groups."); - } - - logger.Debug($"Output: {collisionBuilder.coct.Nodes.Count:#,##0} collision mesh groups"); - - { - var matDefList = bigMeshContainer.AllocatedMaterialDefs; - var imageSets = matDefList - .Select(matDef => new ImageSet { image = imageLoader(matDef), matDef = matDef, }) - .ToArray(); - - var footerData = new MemoryStream(); - { - var footer = new TextureFooterData(); - foreach (var uvscItem in config.uvscList) - { - footer.UvscList.Add( - new UvScroll - { - TextureIndex = uvscItem.index, - UScrollSpeed = uvscItem.u, - VScrollSpeed = uvscItem.v, - } - ); - } - footer.Write(footerData); - } - - var build = new ModelTexture.Build - { - images = imageSets - .Select(set => set.image) - .ToArray(), - - offsetData = null, // auto serial number map - - textureTransfer = null, // auto create - - gsInfo = imageSets - .Select( - set => - { - var gsInfo = new ModelTexture.UserGsInfo(set.image); - gsInfo.AddressMode.AddressU = - Enum.Parse( - set.matDef.textureOptions.addressU - ?? config.textureOptions.addressU - ?? "Repeat" - ); - gsInfo.AddressMode.AddressV = - Enum.Parse( - set.matDef.textureOptions.addressV - ?? config.textureOptions.addressV - ?? "Repeat" - ); - return gsInfo; - } - ) - .ToArray(), - - footerData = footerData.ToArray(), - }; - - modelTex = new ModelTexture(build); - } - } - - class ImageSet - { - public Imgd image; - public MaterialDef matDef; - } - - private void ConvertModelIntoMapModel(string modelFile, MapGenConfig config) - { - logger.Debug($"Loading 3D model file \"{modelFile}\" using Assimp."); - - var assimp = new Assimp.AssimpContext(); - var scene = assimp.ImportFile(modelFile, Assimp.PostProcessSteps.PreTransformVertices); - - bigMeshContainer = new BigMeshContainer(); - - var scale = config.scale; - - Matrix4x4 matrix = Matrix4x4.Identity; - - if (config.applyMatrix != null) - { - var m = config.applyMatrix; - - if (m.Length == 16) - { - matrix = new Matrix4x4( - m[0], m[1], m[2], m[3], - m[4], m[5], m[6], m[7], - m[8], m[9], m[10], m[11], - m[12], m[13], m[14], m[15] - ); - - logger.Debug($"Apply matrix: {matrix}"); - } - } - else - { - matrix *= scale; - } - - logger.Debug($"Starting triangle strip conversion for {scene.Meshes.Count} meshes."); - - foreach (var inputMesh in scene.Meshes) - { - logger.Debug($"Mesh: {inputMesh.Name} ({inputMesh.FaceCount:#,##0} faces, {inputMesh.VertexCount:#,##0} vertices)"); - - var modelMat = scene.Materials[inputMesh.MaterialIndex]; - - var matDef = config.FindMaterial(modelMat.Name ?? "default") ?? MaterialDef.CreateFallbackFor(modelMat.Name); - if (matDef.ignore) - { - logger.Info($"This mesh \"{inputMesh.Name}\" is not rendered due to ignore flag of material \"{modelMat.Name}\"."); - continue; - } - - var kh2Mesh = bigMeshContainer.AllocateBigMeshForMaterial(matDef); - - var diffuseTextureFile = modelMat.TextureDiffuse.FilePath; - if (!string.IsNullOrEmpty(diffuseTextureFile)) - { - if (config.reuseImd) - { - logger.Debug($"The mesh \"{inputMesh.Name}\" material \"{matDef.name}\" has filepath \"{diffuseTextureFile}\" for diffuse texture. It will be associated with material's fromFile3. Setting preferable imd file to fromFile2 due to reuseImd flag."); - - matDef.fromFile2 = Path.ChangeExtension(diffuseTextureFile, ".imd"); - matDef.fromFile3 = diffuseTextureFile; - } - else - { - logger.Debug($"The mesh \"{inputMesh.Name}\" material \"{matDef.name}\" has filepath \"{diffuseTextureFile}\" for diffuse texture. It will be associated with material's fromFile2."); - - matDef.fromFile3 = diffuseTextureFile; - } - } - - var kh2BaseVert = kh2Mesh.vertexList.Count; - - List vertexToLocal = new List(); - - foreach (var inputVertex in inputMesh.Vertices) - { - var vertex = Vector3.Transform( - new Vector3(inputVertex.X, inputVertex.Y, inputVertex.Z), - matrix - ); - - var index = kh2Mesh.vertexList.IndexOf(vertex); - if (index < 0) - { - index = kh2Mesh.vertexList.Count; - kh2Mesh.vertexList.Add(vertex); - } - - vertexToLocal.Add(index); - } - - var localFaces = inputMesh.Faces - .Select( - set => set.Indices - .Select(index => new VertPair { uvColorIndex = index, vertexIndex = vertexToLocal[index] }) - .ToArray() - ) - .ToArray(); - - var inputTexCoords = inputMesh.TextureCoordinateChannels.First(); - var inputVertexColorList = inputMesh.VertexColorChannels.First(); - - var hasVertexColor = inputMesh.VertexColorChannelCount >= 1; - - var maxIntensity = matDef.maxColorIntensity - ?? config.maxColorIntensity - ?? 128; - var maxAlpha = matDef.maxAlpha - ?? config.maxAlpha - ?? 128; - - var triConverter = - config.disableTriangleStripsOptimization - ? (TriangleFansToTriangleStripsConverter)TriangleFansToTriangleStripsNoOpts - : (TriangleFansToTriangleStripsConverter)TriangleFansToTriangleStripsOptimized; - - foreach (var triStripInput in triConverter(localFaces)) - { - var triStripOut = new BigMesh.TriangleStrip(); - - foreach (var vertPair in triStripInput) - { - triStripOut.vertexIndices.Add(kh2BaseVert + vertPair.vertexIndex); - - triStripOut.uvList.Add(Get2DCoord(inputTexCoords[vertPair.uvColorIndex])); - - if (hasVertexColor) - { - triStripOut.vertexColorList.Add(ConvertVertexColor(inputVertexColorList[vertPair.uvColorIndex], maxIntensity, maxAlpha)); - } - else - { - triStripOut.vertexColorList.Add(new Color(maxIntensity, maxIntensity, maxIntensity, maxAlpha)); - } - } - - kh2Mesh.triangleStripList.Add(triStripOut); - } - - logger.Debug($"Output: {kh2Mesh.vertexList.Count:#,##0} vertices, {kh2Mesh.triangleStripList.Count:#,##0} triangle strips."); - } - - logger.Debug($"The conversion has done."); - - logger.Debug($"Starting mesh splitter and vif packets builder."); - - mapModel = new Mdlx.M4 - { - VifPackets = new List(), - }; - - foreach (var bigMesh in bigMeshContainer.MeshList - .Where(it => it.textureIndex != -1) - ) - { - foreach (var smallMesh in BigMeshSplitter.Split(bigMesh)) - { - var dmaPack = new MapVifPacketBuilder(smallMesh); - - smallMeshList.Add(smallMesh); - - bigMesh.vifPacketIndices.Add(Convert.ToUInt16(mapModel.VifPackets.Count)); - smallMesh.vifPacketIndices.Add(Convert.ToUInt16(mapModel.VifPackets.Count)); - - mapModel.VifPackets.Add( - new Mdlx.VifPacketDescriptor - { - VifPacket = dmaPack.vifPacket.ToArray(), - TextureId = smallMesh.textureIndex, - DmaPerVif = new ushort[] { - dmaPack.firstVifPacketQwc, - 0, - }, - IsTransparentFlag = smallMesh.matDef.transparentFlag ?? 0, - EnableUvsc = smallMesh.matDef.uvscIndex.HasValue, - UvscIndex = smallMesh.matDef.uvscIndex ?? 0, - } - ); - } - } - - logger.Debug($"Output: {mapModel.VifPackets.Count:#,##0} vif packets."); - - logger.Debug($"The builder has done."); - - logger.Debug($"Starting vifPacketRenderingGroup builder."); - - // first group: render all - - mapModel.vifPacketRenderingGroup = new List( - new ushort[][] { - Enumerable.Range(0, mapModel.VifPackets.Count) - .Select(it => Convert.ToUInt16(it)) - .ToArray() - } - ); - - logger.Debug($"Output: {mapModel.vifPacketRenderingGroup.Count:#,##0} groups."); - - mapModel.DmaChainIndexRemapTable = new List( - Enumerable.Range(0, mapModel.VifPackets.Count) - .Select(it => Convert.ToUInt16(it)) - .ToArray() - ); - } - - class VertPair - { - /// - /// compacted vertex index - /// - public int vertexIndex; - - /// - /// uv and vertex color index - /// - public int uvColorIndex; - - public override string ToString() => $"{vertexIndex}"; - } - - private delegate IEnumerable> TriangleFansToTriangleStripsConverter(VertPair[][] faces); - - private IEnumerable> TriangleFansToTriangleStripsNoOpts(VertPair[][] faces) => faces; - - private IEnumerable> TriangleFansToTriangleStripsOptimized(VertPair[][] faces) - { - var list = faces - .SelectMany(face => TriangleFanToTriangleStrips(face)) - .Select(it => it.ToList()) - .ToList(); - - while (true) - { - var anyOutnerJoin = false; - - for (int x = 0; x < list.Count; x++) - { - while (true) - { - var anyInnerJoin = false; - - var v0 = list[x][0].vertexIndex; - var v1 = list[x][1].vertexIndex; - var v2 = list[x][list[x].Count - 2].vertexIndex; - var v3 = list[x][list[x].Count - 1].vertexIndex; - - for (int y = x + 1; y < list.Count; y++) - { - if (list[y][0].vertexIndex == v2 && list[y][1].vertexIndex == v3 && list[x].Count + list[y].Count - 2 < MaxVertCount) - { - list[x].AddRange(list[y].Skip(2)); - list.RemoveAt(y); - y--; - anyInnerJoin = true; - break; - } - if (list[y][list[y].Count - 2].vertexIndex == v0 && list[y][list[y].Count - 1].vertexIndex == v1 && list[x].Count + list[y].Count - 2 < MaxVertCount) - { - list[x].InsertRange(0, list[y].SkipLast(2)); - list.RemoveAt(y); - y--; - anyInnerJoin = true; - break; - } - } - - anyOutnerJoin |= anyInnerJoin; - - if (!anyInnerJoin) - { - break; - } - } - } - - if (!anyOutnerJoin) - { - break; - } - } - return list; - } - - private static IEnumerable> TriangleFanToTriangleStrips(IList list) - { - switch (list.Count) - { - case 3: - yield return list; - break; - case 4: - yield return new VertPair[] { list[0], list[1], list[3], list[2] }; - break; - default: - throw new NotSupportedException(); - } - } - - private static Color ConvertVertexColor(Assimp.Color4D clr, byte maxColorIntensity, byte maxAlpha) => new Color( - (byte)Math.Min(255, clr.R * maxColorIntensity), - (byte)Math.Min(255, clr.G * maxColorIntensity), - (byte)Math.Min(255, clr.B * maxColorIntensity), - (byte)Math.Min(255, clr.A * maxAlpha) - ); - - private static Vector2 Get2DCoord(Assimp.Vector3D vector3D) => new Vector2(vector3D.X, 1 - vector3D.Y); - - - public List GetBarEntries(Action trySaveTo = null) - { - var entries = new List(); - - { - var mapBin = new MemoryStream(); - Mdlx.CreateFromMapModel(mapModel).Write(mapBin); - mapBin.Position = 0; - - entries.Add( - new Bar.Entry - { - Name = config.bar?.model?.name ?? "MAP", - Type = Bar.EntryType.Model, - Stream = mapBin, - } - ); - - trySaveTo?.Invoke(config.bar?.model?.toFile, mapBin); - } - - { - var texBin = new MemoryStream(); - modelTex.Write(texBin); - texBin.Position = 0; - - entries.Add( - new Bar.Entry - { - Name = config.bar?.texture?.name ?? "MAP", - Type = Bar.EntryType.ModelTexture, - Stream = texBin, - } - ); - - trySaveTo?.Invoke(config.bar?.texture?.toFile, texBin); - } - - { - var doctBin = new MemoryStream(); - collisionBuilder.doct.Write(doctBin); - doctBin.Position = 0; - - entries.Add( - new Bar.Entry - { - Name = config.bar?.doct?.name ?? "eh_1", - Type = Bar.EntryType.DrawOctalTree, - Stream = doctBin, - } - ); - - trySaveTo?.Invoke(config.bar?.doct?.toFile, doctBin); - } - - { - var coctBin = new MemoryStream(); - collisionBuilder.coct.Write(coctBin); - coctBin.Position = 0; - - entries.Add( - new Bar.Entry - { - Name = config.bar?.coct?.name ?? "ID_e", - Type = Bar.EntryType.CollisionOctalTree, - Stream = coctBin, - } - ); - - trySaveTo?.Invoke(config.bar?.coct?.toFile, coctBin); - } - - return entries; - } - - } -} +using NLog; +using OpenKh.Command.MapGen.Models; +using OpenKh.Kh2; +using OpenKh.Kh2.TextureFooter; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Numerics; +using Xe.Graphics; +using Matrix4x4 = System.Numerics.Matrix4x4; + +namespace OpenKh.Command.MapGen.Utils +{ + public class MapBuilder + { + private const int MaxVertCount = 71; + + private Mdlx.M4 mapModel; + private BigMeshContainer bigMeshContainer; + private List smallMeshList = new List(); + private ModelTexture modelTex; + private CollisionBuilder collisionBuilder; + private Logger logger = LogManager.GetCurrentClassLogger(); + private readonly MapGenConfig config; + + public MapBuilder(string modelFile, MapGenConfig config, Func imageLoader) + { + this.config = config; + + ConvertModelIntoMapModel(modelFile, config); + + logger.Debug($"Starting collision plane builder."); + + collisionBuilder = new CollisionBuilder(smallMeshList, config.disableBSPCollisionBuilder); + + if (collisionBuilder.vifPacketRenderingGroup != null) + { + logger.Debug($"Updating vifPacketRenderingGroup builder."); + + mapModel.vifPacketRenderingGroup = collisionBuilder.vifPacketRenderingGroup; + + logger.Debug($"Output: {mapModel.vifPacketRenderingGroup.Count:#,##0} groups."); + } + + logger.Debug($"Output: {collisionBuilder.coct.Nodes.Count:#,##0} collision mesh groups"); + + { + var matDefList = bigMeshContainer.AllocatedMaterialDefs; + var imageSets = matDefList + .Select(matDef => new ImageSet { image = imageLoader(matDef), matDef = matDef, }) + .ToArray(); + + var footerData = new MemoryStream(); + { + var footer = new TextureFooterData(); + foreach (var uvscItem in config.uvscList) + { + footer.UvscList.Add( + new UvScroll + { + TextureIndex = uvscItem.index, + UScrollSpeed = uvscItem.u, + VScrollSpeed = uvscItem.v, + } + ); + } + footer.Write(footerData); + } + + var build = new ModelTexture.Build + { + images = imageSets + .Select(set => set.image) + .ToArray(), + + offsetData = null, // auto serial number map + + textureTransfer = null, // auto create + + gsInfo = imageSets + .Select( + set => + { + var gsInfo = new ModelTexture.UserGsInfo(set.image); + gsInfo.AddressMode.AddressU = + Enum.Parse( + set.matDef.textureOptions.addressU + ?? config.textureOptions.addressU + ?? "Repeat" + ); + gsInfo.AddressMode.AddressV = + Enum.Parse( + set.matDef.textureOptions.addressV + ?? config.textureOptions.addressV + ?? "Repeat" + ); + return gsInfo; + } + ) + .ToArray(), + + footerData = footerData.ToArray(), + }; + + modelTex = new ModelTexture(build); + } + } + + class ImageSet + { + public Imgd image; + public MaterialDef matDef; + } + + private void ConvertModelIntoMapModel(string modelFile, MapGenConfig config) + { + logger.Debug($"Loading 3D model file \"{modelFile}\" using Assimp."); + + var assimp = new Assimp.AssimpContext(); + var scene = assimp.ImportFile(modelFile, Assimp.PostProcessSteps.PreTransformVertices); + + bigMeshContainer = new BigMeshContainer(); + + var scale = config.scale; + + Matrix4x4 matrix = Matrix4x4.Identity; + + if (config.applyMatrix != null) + { + var m = config.applyMatrix; + + if (m.Length == 16) + { + matrix = new Matrix4x4( + m[0], m[1], m[2], m[3], + m[4], m[5], m[6], m[7], + m[8], m[9], m[10], m[11], + m[12], m[13], m[14], m[15] + ); + + logger.Debug($"Apply matrix: {matrix}"); + } + } + else + { + matrix *= scale; + } + + logger.Debug($"Starting triangle strip conversion for {scene.Meshes.Count} meshes."); + + foreach (var inputMesh in scene.Meshes) + { + logger.Debug($"Mesh: {inputMesh.Name} ({inputMesh.FaceCount:#,##0} faces, {inputMesh.VertexCount:#,##0} vertices)"); + + var modelMat = scene.Materials[inputMesh.MaterialIndex]; + + var matDef = config.FindMaterial(modelMat.Name ?? "default") ?? MaterialDef.CreateFallbackFor(modelMat.Name); + if (matDef.ignore) + { + logger.Info($"This mesh \"{inputMesh.Name}\" is not rendered due to ignore flag of material \"{modelMat.Name}\"."); + continue; + } + + var kh2Mesh = bigMeshContainer.AllocateBigMeshForMaterial(matDef); + + var diffuseTextureFile = modelMat.TextureDiffuse.FilePath; + if (!string.IsNullOrEmpty(diffuseTextureFile)) + { + if (config.reuseImd) + { + logger.Debug($"The mesh \"{inputMesh.Name}\" material \"{matDef.name}\" has filepath \"{diffuseTextureFile}\" for diffuse texture. It will be associated with material's fromFile3. Setting preferable imd file to fromFile2 due to reuseImd flag."); + + matDef.fromFile2 = Path.ChangeExtension(diffuseTextureFile, ".imd"); + matDef.fromFile3 = diffuseTextureFile; + } + else + { + logger.Debug($"The mesh \"{inputMesh.Name}\" material \"{matDef.name}\" has filepath \"{diffuseTextureFile}\" for diffuse texture. It will be associated with material's fromFile2."); + + matDef.fromFile3 = diffuseTextureFile; + } + } + + var kh2BaseVert = kh2Mesh.vertexList.Count; + + List vertexToLocal = new List(); + + foreach (var inputVertex in inputMesh.Vertices) + { + var vertex = Vector3.Transform( + new Vector3(inputVertex.X, inputVertex.Y, inputVertex.Z), + matrix + ); + + var index = kh2Mesh.vertexList.IndexOf(vertex); + if (index < 0) + { + index = kh2Mesh.vertexList.Count; + kh2Mesh.vertexList.Add(vertex); + } + + vertexToLocal.Add(index); + } + + var localFaces = inputMesh.Faces + .Select( + set => set.Indices + .Select(index => new VertPair { uvColorIndex = index, vertexIndex = vertexToLocal[index] }) + .ToArray() + ) + .ToArray(); + + var inputTexCoords = inputMesh.TextureCoordinateChannels.First(); + var inputVertexColorList = inputMesh.VertexColorChannels.First(); + + var hasVertexColor = inputMesh.VertexColorChannelCount >= 1; + + var maxIntensity = matDef.maxColorIntensity + ?? config.maxColorIntensity + ?? 128; + var maxAlpha = matDef.maxAlpha + ?? config.maxAlpha + ?? 128; + + var triConverter = + config.disableTriangleStripsOptimization + ? (TriangleFansToTriangleStripsConverter)TriangleFansToTriangleStripsNoOpts + : (TriangleFansToTriangleStripsConverter)TriangleFansToTriangleStripsOptimized; + + foreach (var triStripInput in triConverter(localFaces)) + { + var triStripOut = new BigMesh.TriangleStrip(); + + foreach (var vertPair in triStripInput) + { + triStripOut.vertexIndices.Add(kh2BaseVert + vertPair.vertexIndex); + + triStripOut.uvList.Add(Get2DCoord(inputTexCoords[vertPair.uvColorIndex])); + + if (hasVertexColor) + { + triStripOut.vertexColorList.Add(ConvertVertexColor(inputVertexColorList[vertPair.uvColorIndex], maxIntensity, maxAlpha)); + } + else + { + triStripOut.vertexColorList.Add(new Color(maxIntensity, maxIntensity, maxIntensity, maxAlpha)); + } + } + + kh2Mesh.triangleStripList.Add(triStripOut); + } + + logger.Debug($"Output: {kh2Mesh.vertexList.Count:#,##0} vertices, {kh2Mesh.triangleStripList.Count:#,##0} triangle strips."); + } + + logger.Debug($"The conversion has done."); + + logger.Debug($"Starting mesh splitter and vif packets builder."); + + mapModel = new Mdlx.M4 + { + VifPackets = new List(), + }; + + foreach (var bigMesh in bigMeshContainer.MeshList + .Where(it => it.textureIndex != -1) + ) + { + foreach (var smallMesh in BigMeshSplitter.Split(bigMesh)) + { + var dmaPack = new MapVifPacketBuilder(smallMesh); + + smallMeshList.Add(smallMesh); + + bigMesh.vifPacketIndices.Add(Convert.ToUInt16(mapModel.VifPackets.Count)); + smallMesh.vifPacketIndices.Add(Convert.ToUInt16(mapModel.VifPackets.Count)); + + mapModel.VifPackets.Add( + new Mdlx.VifPacketDescriptor + { + VifPacket = dmaPack.vifPacket.ToArray(), + TextureId = smallMesh.textureIndex, + DmaPerVif = new ushort[] { + dmaPack.firstVifPacketQwc, + 0, + }, + IsTransparentFlag = smallMesh.matDef.transparentFlag ?? 0, + EnableUvsc = smallMesh.matDef.uvscIndex.HasValue, + UvscIndex = smallMesh.matDef.uvscIndex ?? 0, + } + ); + } + } + + logger.Debug($"Output: {mapModel.VifPackets.Count:#,##0} vif packets."); + + logger.Debug($"The builder has done."); + + logger.Debug($"Starting vifPacketRenderingGroup builder."); + + // first group: render all + + mapModel.vifPacketRenderingGroup = new List( + new ushort[][] { + Enumerable.Range(0, mapModel.VifPackets.Count) + .Select(it => Convert.ToUInt16(it)) + .ToArray() + } + ); + + logger.Debug($"Output: {mapModel.vifPacketRenderingGroup.Count:#,##0} groups."); + + mapModel.DmaChainIndexRemapTable = new List( + Enumerable.Range(0, mapModel.VifPackets.Count) + .Select(it => Convert.ToUInt16(it)) + .ToArray() + ); + } + + class VertPair + { + /// + /// compacted vertex index + /// + public int vertexIndex; + + /// + /// uv and vertex color index + /// + public int uvColorIndex; + + public override string ToString() => $"{vertexIndex}"; + } + + private delegate IEnumerable> TriangleFansToTriangleStripsConverter(VertPair[][] faces); + + private IEnumerable> TriangleFansToTriangleStripsNoOpts(VertPair[][] faces) => faces; + + private IEnumerable> TriangleFansToTriangleStripsOptimized(VertPair[][] faces) + { + var list = faces + .SelectMany(face => TriangleFanToTriangleStrips(face)) + .Select(it => it.ToList()) + .ToList(); + + while (true) + { + var anyOutnerJoin = false; + + for (int x = 0; x < list.Count; x++) + { + while (true) + { + var anyInnerJoin = false; + + var v0 = list[x][0].vertexIndex; + var v1 = list[x][1].vertexIndex; + var v2 = list[x][list[x].Count - 2].vertexIndex; + var v3 = list[x][list[x].Count - 1].vertexIndex; + + for (int y = x + 1; y < list.Count; y++) + { + if (list[y][0].vertexIndex == v2 && list[y][1].vertexIndex == v3 && list[x].Count + list[y].Count - 2 < MaxVertCount) + { + list[x].AddRange(list[y].Skip(2)); + list.RemoveAt(y); + y--; + anyInnerJoin = true; + break; + } + if (list[y][list[y].Count - 2].vertexIndex == v0 && list[y][list[y].Count - 1].vertexIndex == v1 && list[x].Count + list[y].Count - 2 < MaxVertCount) + { + list[x].InsertRange(0, list[y].SkipLast(2)); + list.RemoveAt(y); + y--; + anyInnerJoin = true; + break; + } + } + + anyOutnerJoin |= anyInnerJoin; + + if (!anyInnerJoin) + { + break; + } + } + } + + if (!anyOutnerJoin) + { + break; + } + } + return list; + } + + private static IEnumerable> TriangleFanToTriangleStrips(IList list) + { + switch (list.Count) + { + case 3: + yield return list; + break; + case 4: + yield return new VertPair[] { list[0], list[1], list[3], list[2] }; + break; + default: + throw new NotSupportedException(); + } + } + + private static Color ConvertVertexColor(Assimp.Color4D clr, byte maxColorIntensity, byte maxAlpha) => new Color( + (byte)Math.Min(255, clr.R * maxColorIntensity), + (byte)Math.Min(255, clr.G * maxColorIntensity), + (byte)Math.Min(255, clr.B * maxColorIntensity), + (byte)Math.Min(255, clr.A * maxAlpha) + ); + + private static Vector2 Get2DCoord(Assimp.Vector3D vector3D) => new Vector2(vector3D.X, 1 - vector3D.Y); + + + public List GetBarEntries(Action trySaveTo = null) + { + var entries = new List(); + + { + var mapBin = new MemoryStream(); + Mdlx.CreateFromMapModel(mapModel).Write(mapBin); + mapBin.Position = 0; + + entries.Add( + new Bar.Entry + { + Name = config.bar?.model?.name ?? "MAP", + Type = Bar.EntryType.Model, + Stream = mapBin, + } + ); + + trySaveTo?.Invoke(config.bar?.model?.toFile, mapBin); + } + + { + var texBin = new MemoryStream(); + modelTex.Write(texBin); + texBin.Position = 0; + + entries.Add( + new Bar.Entry + { + Name = config.bar?.texture?.name ?? "MAP", + Type = Bar.EntryType.ModelTexture, + Stream = texBin, + } + ); + + trySaveTo?.Invoke(config.bar?.texture?.toFile, texBin); + } + + { + var doctBin = new MemoryStream(); + collisionBuilder.doct.Write(doctBin); + doctBin.Position = 0; + + entries.Add( + new Bar.Entry + { + Name = config.bar?.doct?.name ?? "eh_1", + Type = Bar.EntryType.DrawOctalTree, + Stream = doctBin, + } + ); + + trySaveTo?.Invoke(config.bar?.doct?.toFile, doctBin); + } + + { + var coctBin = new MemoryStream(); + collisionBuilder.coct.Write(coctBin); + coctBin.Position = 0; + + entries.Add( + new Bar.Entry + { + Name = config.bar?.coct?.name ?? "ID_e", + Type = Bar.EntryType.CollisionOctalTree, + Stream = coctBin, + } + ); + + trySaveTo?.Invoke(config.bar?.coct?.toFile, coctBin); + } + + return entries; + } + + } +} diff --git a/OpenKh.Command.MapGen/Utils/MapGenUtil.cs b/OpenKh.Command.MapGen/Utils/MapGenUtil.cs index c4e98546e..2949275a0 100644 --- a/OpenKh.Command.MapGen/Utils/MapGenUtil.cs +++ b/OpenKh.Command.MapGen/Utils/MapGenUtil.cs @@ -1,271 +1,271 @@ -using NLog; -using OpenKh.Command.MapGen.Models; -using OpenKh.Kh2; -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Drawing; - -namespace OpenKh.Command.MapGen.Utils -{ - public class MapGenUtil - { - private readonly Logger logger = LogManager.GetCurrentClassLogger(); - - public void Run(string inputFile, string outputMap) - { - var yamlReader = new YamlDotNet.Serialization.DeserializerBuilder() - .IgnoreUnmatchedProperties() - .Build(); - - MapBuilder builder; - MapGenConfig config; - string baseDir; - string outMapFile; - - if (FileExtUtil.IsExtension(inputFile, ".yml")) - { - var ymlFile = Path.GetFullPath(inputFile); - baseDir = Path.GetDirectoryName(ymlFile); - - logger.Debug($"ymlFile is \"{ymlFile}\""); - logger.Debug($"baseDir is \"{baseDir}\""); - - config = yamlReader.Deserialize(File.ReadAllText(ymlFile)); - - var modelFile = Path.Combine(baseDir, config.inputFile); - outMapFile = Path.GetFullPath(outputMap ?? Path.Combine(baseDir, config.outputFile)); - - builder = new MapBuilder(modelFile, config, CreateImageLoader(baseDir, config, FileLoader)); - } - else - { - var modelFile = Path.GetFullPath(inputFile); - baseDir = Path.GetDirectoryName(modelFile); - var ymlFile = Path.Combine(baseDir, "mapdef.yml"); - outMapFile = Path.GetFullPath(outputMap ?? Path.Combine(baseDir, Path.ChangeExtension(inputFile, ".map"))); - - logger.Debug($"ymlFile is \"{ymlFile}\""); - logger.Debug($"baseDir is \"{baseDir}\""); - - config = File.Exists(ymlFile) - ? yamlReader.Deserialize(File.ReadAllText(ymlFile)) - : new MapGenConfig(); - - builder = new MapBuilder(modelFile, config, CreateImageLoader(baseDir, config, FileLoader)); - } - - logger.Debug("Building map file structure."); - - var buff = new MemoryStream(); - - void trySaveTo(string toFile, MemoryStream stream) - { - if (!string.IsNullOrWhiteSpace(toFile)) - { - toFile = Path.Combine(baseDir, toFile); - - logger.Debug($"Writing raw data to \"{toFile}\"."); - - Directory.CreateDirectory(Path.GetDirectoryName(toFile)); - - File.WriteAllBytes(toFile, stream.ToArray()); - } - } - - Bar.Write( - buff, - builder.GetBarEntries(trySaveTo) - .Concat(LoadAdditionalBarEntries(config, CreateRawFileLoader(baseDir))) - .ToArray() - ); - - logger.Debug($"Writing to \"{outMapFile}\"."); - - File.WriteAllBytes(outMapFile, buff.ToArray()); - - logger.Debug("Done"); - } - - - private Func CreateRawFileLoader(string baseDir) - { - return fileName => - { - var filePath = Path.Combine(baseDir, fileName); - - logger.Debug($"Going to load file from \"{filePath}\""); - - return File.ReadAllBytes(filePath); - }; - } - - private IEnumerable LoadAdditionalBarEntries(MapGenConfig config, Func fileLoader) - { - foreach (var addFile in config.addFiles) - { - var data = fileLoader(addFile.fromFile); - yield return new Bar.Entry - { - Name = addFile.name, - Type = (Bar.EntryType)addFile.type, - Stream = new MemoryStream(data), - Index = addFile.index, - }; - } - } - - private Imgd FileLoader(string filePath, MaterialDef matDef, MapGenConfig config) - { - logger.Debug($"Load image from \"{filePath}\""); - - if (FileExtUtil.IsExtension(filePath, ".imd")) - { - return ImageResizer.NormalizeImageSize(File.OpenRead(filePath).Using(s => Imgd.Read(s))); - } - if (FileExtUtil.IsExtension(filePath, ".png")) - { - var imdFile = Path.ChangeExtension(filePath, ".imd"); - - if (config.skipConversionIfExists && File.Exists(imdFile)) - { - logger.Debug($"Skipping png to imd conversion, due to imd file existence and skipConversionIfExists option."); - } - else - { - try - { - logger.Debug($"Using ImgTool for png to imd conversion."); - - var imgtoolOptions = matDef.imgtoolOptions ?? config.imgtoolOptions ?? "-b 8"; - - var result = new RunCmd( - "OpenKh.Command.ImgTool.exe", - $"imd \"{filePath}\" -o \"{imdFile}\" {imgtoolOptions}" - ); - - if (result.ExitCode != 0) - { - throw new Exception($"ImgTool failed ({result.ExitCode})"); - } - } - catch (Win32Exception ex) - { - throw new Exception("ImgTool failed.", ex); - } - } - - return FileLoader(imdFile, matDef, config); - } - - throw new NotSupportedException(Path.GetExtension(filePath)); - } - - class RunCmd - { - private Process p; - - public string App => p.StartInfo.FileName; - public int ExitCode => p.ExitCode; - - public RunCmd(string app, string arg) - { - var psi = new ProcessStartInfo(app, arg); - psi.UseShellExecute = false; - var p = Process.Start(psi); - p.WaitForExit(); - this.p = p; - } - } - - private Func CreateImageLoader(string baseDir, MapGenConfig config, Func fileLoader) - { - return (matDef) => - { - logger.Debug($"Going to load material \"{matDef.name}\"."); - - var fileNames = new string[] { - matDef.fromFile, - matDef.fromFile2, - matDef.fromFile3, - matDef.name + ".imd", - matDef.name + ".png", - } - .Where(it => !string.IsNullOrWhiteSpace(it)) - .ToList(); - - var allImageDirs = new string[] { } - .Concat( - (config.imageDirs ?? new string[0]) - .Select(imageDir => Path.Combine(baseDir, imageDir)) - ) - .Concat( - new string[] { baseDir } - ) - .ToArray(); - - var pathList = - allImageDirs - .SelectMany( - imageDir => fileNames.Select(fileName => Path.Combine(imageDir, fileName)) - ) - .ToArray(); - - var found = pathList - .FirstOrDefault(File.Exists); - - Imgd loaded = null; - - if (found != null && File.Exists(found)) - { - try - { - loaded = fileLoader(found, matDef, config); - } - catch (Exception ex) - { - logger.Warn(ex, "Load image failed!"); - } - } - - if (loaded == null) - { - logger.Warn($"File not found of material \"{matDef.name}\", or error thrown. Using fallback image instead."); - - // fallback - var pixels = new byte[128 * 128]; - for (int x = 0; x < pixels.Length; x++) - { - var y = x / 128; - var set = 0 != ((1 & (x / 8)) ^ (1 & (y / 8))); - pixels[x] = (byte)(set ? 255 : 95); - } - - var palette = new byte[4 * 256]; - for (int x = 0; x < 256; x++) - { - var v = (byte)x; - palette[4 * x + 0] = v; - palette[4 * x + 1] = v; - palette[4 * x + 2] = v; - palette[4 * x + 3] = 255; - } - - return Imgd.Create( - new Size(128, 128), - Imaging.PixelFormat.Indexed8, - pixels, - palette, - false - ); - } - - return loaded; - }; - } - } -} +using NLog; +using OpenKh.Command.MapGen.Models; +using OpenKh.Kh2; +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Drawing; + +namespace OpenKh.Command.MapGen.Utils +{ + public class MapGenUtil + { + private readonly Logger logger = LogManager.GetCurrentClassLogger(); + + public void Run(string inputFile, string outputMap) + { + var yamlReader = new YamlDotNet.Serialization.DeserializerBuilder() + .IgnoreUnmatchedProperties() + .Build(); + + MapBuilder builder; + MapGenConfig config; + string baseDir; + string outMapFile; + + if (FileExtUtil.IsExtension(inputFile, ".yml")) + { + var ymlFile = Path.GetFullPath(inputFile); + baseDir = Path.GetDirectoryName(ymlFile); + + logger.Debug($"ymlFile is \"{ymlFile}\""); + logger.Debug($"baseDir is \"{baseDir}\""); + + config = yamlReader.Deserialize(File.ReadAllText(ymlFile)); + + var modelFile = Path.Combine(baseDir, config.inputFile); + outMapFile = Path.GetFullPath(outputMap ?? Path.Combine(baseDir, config.outputFile)); + + builder = new MapBuilder(modelFile, config, CreateImageLoader(baseDir, config, FileLoader)); + } + else + { + var modelFile = Path.GetFullPath(inputFile); + baseDir = Path.GetDirectoryName(modelFile); + var ymlFile = Path.Combine(baseDir, "mapdef.yml"); + outMapFile = Path.GetFullPath(outputMap ?? Path.Combine(baseDir, Path.ChangeExtension(inputFile, ".map"))); + + logger.Debug($"ymlFile is \"{ymlFile}\""); + logger.Debug($"baseDir is \"{baseDir}\""); + + config = File.Exists(ymlFile) + ? yamlReader.Deserialize(File.ReadAllText(ymlFile)) + : new MapGenConfig(); + + builder = new MapBuilder(modelFile, config, CreateImageLoader(baseDir, config, FileLoader)); + } + + logger.Debug("Building map file structure."); + + var buff = new MemoryStream(); + + void trySaveTo(string toFile, MemoryStream stream) + { + if (!string.IsNullOrWhiteSpace(toFile)) + { + toFile = Path.Combine(baseDir, toFile); + + logger.Debug($"Writing raw data to \"{toFile}\"."); + + Directory.CreateDirectory(Path.GetDirectoryName(toFile)); + + File.WriteAllBytes(toFile, stream.ToArray()); + } + } + + Bar.Write( + buff, + builder.GetBarEntries(trySaveTo) + .Concat(LoadAdditionalBarEntries(config, CreateRawFileLoader(baseDir))) + .ToArray() + ); + + logger.Debug($"Writing to \"{outMapFile}\"."); + + File.WriteAllBytes(outMapFile, buff.ToArray()); + + logger.Debug("Done"); + } + + + private Func CreateRawFileLoader(string baseDir) + { + return fileName => + { + var filePath = Path.Combine(baseDir, fileName); + + logger.Debug($"Going to load file from \"{filePath}\""); + + return File.ReadAllBytes(filePath); + }; + } + + private IEnumerable LoadAdditionalBarEntries(MapGenConfig config, Func fileLoader) + { + foreach (var addFile in config.addFiles) + { + var data = fileLoader(addFile.fromFile); + yield return new Bar.Entry + { + Name = addFile.name, + Type = (Bar.EntryType)addFile.type, + Stream = new MemoryStream(data), + Index = addFile.index, + }; + } + } + + private Imgd FileLoader(string filePath, MaterialDef matDef, MapGenConfig config) + { + logger.Debug($"Load image from \"{filePath}\""); + + if (FileExtUtil.IsExtension(filePath, ".imd")) + { + return ImageResizer.NormalizeImageSize(File.OpenRead(filePath).Using(s => Imgd.Read(s))); + } + if (FileExtUtil.IsExtension(filePath, ".png")) + { + var imdFile = Path.ChangeExtension(filePath, ".imd"); + + if (config.skipConversionIfExists && File.Exists(imdFile)) + { + logger.Debug($"Skipping png to imd conversion, due to imd file existence and skipConversionIfExists option."); + } + else + { + try + { + logger.Debug($"Using ImgTool for png to imd conversion."); + + var imgtoolOptions = matDef.imgtoolOptions ?? config.imgtoolOptions ?? "-b 8"; + + var result = new RunCmd( + "OpenKh.Command.ImgTool.exe", + $"imd \"{filePath}\" -o \"{imdFile}\" {imgtoolOptions}" + ); + + if (result.ExitCode != 0) + { + throw new Exception($"ImgTool failed ({result.ExitCode})"); + } + } + catch (Win32Exception ex) + { + throw new Exception("ImgTool failed.", ex); + } + } + + return FileLoader(imdFile, matDef, config); + } + + throw new NotSupportedException(Path.GetExtension(filePath)); + } + + class RunCmd + { + private Process p; + + public string App => p.StartInfo.FileName; + public int ExitCode => p.ExitCode; + + public RunCmd(string app, string arg) + { + var psi = new ProcessStartInfo(app, arg); + psi.UseShellExecute = false; + var p = Process.Start(psi); + p.WaitForExit(); + this.p = p; + } + } + + private Func CreateImageLoader(string baseDir, MapGenConfig config, Func fileLoader) + { + return (matDef) => + { + logger.Debug($"Going to load material \"{matDef.name}\"."); + + var fileNames = new string[] { + matDef.fromFile, + matDef.fromFile2, + matDef.fromFile3, + matDef.name + ".imd", + matDef.name + ".png", + } + .Where(it => !string.IsNullOrWhiteSpace(it)) + .ToList(); + + var allImageDirs = new string[] { } + .Concat( + (config.imageDirs ?? new string[0]) + .Select(imageDir => Path.Combine(baseDir, imageDir)) + ) + .Concat( + new string[] { baseDir } + ) + .ToArray(); + + var pathList = + allImageDirs + .SelectMany( + imageDir => fileNames.Select(fileName => Path.Combine(imageDir, fileName)) + ) + .ToArray(); + + var found = pathList + .FirstOrDefault(File.Exists); + + Imgd loaded = null; + + if (found != null && File.Exists(found)) + { + try + { + loaded = fileLoader(found, matDef, config); + } + catch (Exception ex) + { + logger.Warn(ex, "Load image failed!"); + } + } + + if (loaded == null) + { + logger.Warn($"File not found of material \"{matDef.name}\", or error thrown. Using fallback image instead."); + + // fallback + var pixels = new byte[128 * 128]; + for (int x = 0; x < pixels.Length; x++) + { + var y = x / 128; + var set = 0 != ((1 & (x / 8)) ^ (1 & (y / 8))); + pixels[x] = (byte)(set ? 255 : 95); + } + + var palette = new byte[4 * 256]; + for (int x = 0; x < 256; x++) + { + var v = (byte)x; + palette[4 * x + 0] = v; + palette[4 * x + 1] = v; + palette[4 * x + 2] = v; + palette[4 * x + 3] = 255; + } + + return Imgd.Create( + new Size(128, 128), + Imaging.PixelFormat.Indexed8, + pixels, + palette, + false + ); + } + + return loaded; + }; + } + } +} diff --git a/OpenKh.Command.MapGen/Utils/MapVifPacketBuilder.cs b/OpenKh.Command.MapGen/Utils/MapVifPacketBuilder.cs index 5f050f438..bb58bb164 100644 --- a/OpenKh.Command.MapGen/Utils/MapVifPacketBuilder.cs +++ b/OpenKh.Command.MapGen/Utils/MapVifPacketBuilder.cs @@ -1,209 +1,209 @@ -using OpenKh.Common; -using OpenKh.Command.MapGen.Models; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using Xe.BinaryMapper; -using OpenKh.Kh2; -using System.Linq; -using McMaster.Extensions.CommandLineUtils.Conventions; - -namespace OpenKh.Command.MapGen.Utils -{ - class MapVifPacketBuilder - { - public MemoryStream vifPacket = new MemoryStream(); - - public ushort firstVifPacketQwc; - - public MapVifPacketBuilder( - BigMesh mesh - ) - { - var nLarge = mesh.triangleStripList.Sum(it => it.vertexIndices.Count); - var nSmall = mesh.vertexList.Count; - - var top = new TopHeader - { - numVertIdx = nLarge, - offVertIdx = 4, - - numClrVert = nLarge, - offClrVert = 4 + nLarge, - - numPosVert = nSmall, - offPosVert = 4 + nLarge + nLarge, - }; - - { - var writer = new BinaryWriter(vifPacket); - - writer.Write(0x01000101); // stcycl cl 01 wl 01 - writer.Write(0x6C048000); // unpack V4-32 c 4 a 000 usn 0 flg 1 m 0 - BinaryMapping.WriteObject(vifPacket, top); - - vifPacket.AlignPosition(4); - - { - // write uv - var off = 4; - var num = Convert.ToByte(nLarge); - writer.Write(0x01000101); // stcycl cl 01 wl 01 - writer.Write((int)(0x65008000 | off | (num << 16))); // unpack V2-16 c 14 a 004 usn 0 flg 1 m 0 - foreach (var one in mesh.triangleStripList.SelectMany(it => it.uvList)) - { - writer.Write(Convert.ToInt16(Math.Max(-32768, Math.Min(32767, (one.X * 4096))))); - writer.Write(Convert.ToInt16(Math.Max(-32768, Math.Min(32767, (one.Y * 4096))))); - } - } - - vifPacket.AlignPosition(4); - - { - // write idx - var off = 4; - var num = Convert.ToByte(nLarge); - writer.Write(0x20000000); // stmask 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 3 - writer.Write(0xcfcfcfcf); - writer.Write(0x01000101); // stcycl cl 01 wl 01 - writer.Write((int)(0x7200C000 | off | (num << 16))); // unpack S-8 c 14 a 004 usn 1 flg 1 m 1 - foreach (var one in mesh.triangleStripList.SelectMany(it => it.vertexIndices)) - { - writer.Write(Convert.ToByte(one)); - } - } - - vifPacket.AlignPosition(4); - - { - // write flags - var off = 4; - var num = Convert.ToByte(nLarge); - writer.Write(0x20000000); // stmask 3 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 - writer.Write(0x3f3f3f3f); - writer.Write(0x01000101); // stcycl cl 01 wl 01 - writer.Write((int)(0x7200C000 | off | (num << 16))); // unpack S-8 c 14 a 004 usn 1 flg 1 m 1 - - foreach (var triStrip in mesh.triangleStripList) - { - var count = triStrip.vertexIndices.Count; - if (count >= 1) - { - writer.Write((byte)0x10); - if (count >= 2) - { - writer.Write((byte)0x10); - for (var x = 2; x < count; x++) - { - if (0 == (x & 1)) - { - writer.Write((byte)0x20); - } - else - { - writer.Write((byte)0x30); - } - } - } - } - } - } - - vifPacket.AlignPosition(4); - - { - // write vertex color list - var off = 4 + nLarge; - var num = Convert.ToByte(nLarge); - writer.Write(0x20000000); // stmask 3 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 - writer.Write(0x3f3f3f3f); - writer.Write(0x01000101); // stcycl cl 01 wl 01 - writer.Write((int)(0x6E00C000 | off | (num << 16))); // unpack V4-8 c 14 a 012 usn 1 flg 1 m 0 - foreach (var color in mesh.triangleStripList.SelectMany(it => it.vertexColorList)) - { - writer.Write(color.r); - writer.Write(color.g); - writer.Write(color.b); - writer.Write(color.a); - } - } - - vifPacket.AlignPosition(4); - - { - // write vertices - var off = 4 + nLarge + nLarge; - var num = Convert.ToByte(nSmall); - writer.Write(0x31000000); // stcol 3f800000 3f800000 3f800000 3f800000 - writer.Write(0x3f800000); - writer.Write(0x3f800000); - writer.Write(0x3f800000); - writer.Write(0x3f800000); - writer.Write(0x20000000); // stmask 3 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 - writer.Write(0x80808080); - writer.Write(0x01000101); // stcycl cl 01 wl 01 - writer.Write((int)(0x78008000 | off | (num << 16))); // unpack V3-32 c 9 a 020 usn 0 flg 1 m 1 - foreach (var one in mesh.vertexList) - { - writer.Write(one.X); - writer.Write(one.Y); - writer.Write(one.Z); - } - } - - vifPacket.AlignPosition(4); - - writer.Write(0x17000000); // mscnt - } - - Align16Plus8(vifPacket); - - firstVifPacketQwc = Convert.ToUInt16(vifPacket.Length / 16); - - vifPacket.Write(new byte[8], 0, 8); // write later 8 bytes of the follwing dma (id=RET) packet. - } - - private void Align16Plus8(Stream stream) - { - stream.Position = stream.Length; - var fill = new byte[(16 - ((int)(stream.Length - 8) & 15)) & 15]; - stream.Write(fill, 0, fill.Length); - } - - private static byte ToPs2Alpha(byte data) => (byte)((data + 1) / 2); - - class DmaSourceChainTag - { - [Data] public ushort qwc { get; set; } - [Data] public ushort idFlg { get; set; } - [Data] public uint addr { get; set; } - } - - /// - /// VPU1 map program header - /// - class TopHeader - { - [Data] public int unk1 { get; set; } - [Data] public int unk2 { get; set; } - [Data] public int unk3 { get; set; } - [Data] public int unk4 { get; set; } - - [Data] public int numVertIdx { get; set; } - [Data] public int offVertIdx { get; set; } - [Data] public int unk5 { get; set; } - [Data] public int unk6 { get; set; } - - [Data] public int numClrVert { get; set; } - [Data] public int offClrVert { get; set; } - [Data] public int unk7 { get; set; } - [Data] public int unk8 { get; set; } - - [Data] public int numPosVert { get; set; } - [Data] public int offPosVert { get; set; } - [Data] public int unk9 { get; set; } - [Data] public int unk10 { get; set; } - } - } -} +using OpenKh.Common; +using OpenKh.Command.MapGen.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using Xe.BinaryMapper; +using OpenKh.Kh2; +using System.Linq; +using McMaster.Extensions.CommandLineUtils.Conventions; + +namespace OpenKh.Command.MapGen.Utils +{ + class MapVifPacketBuilder + { + public MemoryStream vifPacket = new MemoryStream(); + + public ushort firstVifPacketQwc; + + public MapVifPacketBuilder( + BigMesh mesh + ) + { + var nLarge = mesh.triangleStripList.Sum(it => it.vertexIndices.Count); + var nSmall = mesh.vertexList.Count; + + var top = new TopHeader + { + numVertIdx = nLarge, + offVertIdx = 4, + + numClrVert = nLarge, + offClrVert = 4 + nLarge, + + numPosVert = nSmall, + offPosVert = 4 + nLarge + nLarge, + }; + + { + var writer = new BinaryWriter(vifPacket); + + writer.Write(0x01000101); // stcycl cl 01 wl 01 + writer.Write(0x6C048000); // unpack V4-32 c 4 a 000 usn 0 flg 1 m 0 + BinaryMapping.WriteObject(vifPacket, top); + + vifPacket.AlignPosition(4); + + { + // write uv + var off = 4; + var num = Convert.ToByte(nLarge); + writer.Write(0x01000101); // stcycl cl 01 wl 01 + writer.Write((int)(0x65008000 | off | (num << 16))); // unpack V2-16 c 14 a 004 usn 0 flg 1 m 0 + foreach (var one in mesh.triangleStripList.SelectMany(it => it.uvList)) + { + writer.Write(Convert.ToInt16(Math.Max(-32768, Math.Min(32767, (one.X * 4096))))); + writer.Write(Convert.ToInt16(Math.Max(-32768, Math.Min(32767, (one.Y * 4096))))); + } + } + + vifPacket.AlignPosition(4); + + { + // write idx + var off = 4; + var num = Convert.ToByte(nLarge); + writer.Write(0x20000000); // stmask 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 3 + writer.Write(0xcfcfcfcf); + writer.Write(0x01000101); // stcycl cl 01 wl 01 + writer.Write((int)(0x7200C000 | off | (num << 16))); // unpack S-8 c 14 a 004 usn 1 flg 1 m 1 + foreach (var one in mesh.triangleStripList.SelectMany(it => it.vertexIndices)) + { + writer.Write(Convert.ToByte(one)); + } + } + + vifPacket.AlignPosition(4); + + { + // write flags + var off = 4; + var num = Convert.ToByte(nLarge); + writer.Write(0x20000000); // stmask 3 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 + writer.Write(0x3f3f3f3f); + writer.Write(0x01000101); // stcycl cl 01 wl 01 + writer.Write((int)(0x7200C000 | off | (num << 16))); // unpack S-8 c 14 a 004 usn 1 flg 1 m 1 + + foreach (var triStrip in mesh.triangleStripList) + { + var count = triStrip.vertexIndices.Count; + if (count >= 1) + { + writer.Write((byte)0x10); + if (count >= 2) + { + writer.Write((byte)0x10); + for (var x = 2; x < count; x++) + { + if (0 == (x & 1)) + { + writer.Write((byte)0x20); + } + else + { + writer.Write((byte)0x30); + } + } + } + } + } + } + + vifPacket.AlignPosition(4); + + { + // write vertex color list + var off = 4 + nLarge; + var num = Convert.ToByte(nLarge); + writer.Write(0x20000000); // stmask 3 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 + writer.Write(0x3f3f3f3f); + writer.Write(0x01000101); // stcycl cl 01 wl 01 + writer.Write((int)(0x6E00C000 | off | (num << 16))); // unpack V4-8 c 14 a 012 usn 1 flg 1 m 0 + foreach (var color in mesh.triangleStripList.SelectMany(it => it.vertexColorList)) + { + writer.Write(color.r); + writer.Write(color.g); + writer.Write(color.b); + writer.Write(color.a); + } + } + + vifPacket.AlignPosition(4); + + { + // write vertices + var off = 4 + nLarge + nLarge; + var num = Convert.ToByte(nSmall); + writer.Write(0x31000000); // stcol 3f800000 3f800000 3f800000 3f800000 + writer.Write(0x3f800000); + writer.Write(0x3f800000); + writer.Write(0x3f800000); + writer.Write(0x3f800000); + writer.Write(0x20000000); // stmask 3 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 + writer.Write(0x80808080); + writer.Write(0x01000101); // stcycl cl 01 wl 01 + writer.Write((int)(0x78008000 | off | (num << 16))); // unpack V3-32 c 9 a 020 usn 0 flg 1 m 1 + foreach (var one in mesh.vertexList) + { + writer.Write(one.X); + writer.Write(one.Y); + writer.Write(one.Z); + } + } + + vifPacket.AlignPosition(4); + + writer.Write(0x17000000); // mscnt + } + + Align16Plus8(vifPacket); + + firstVifPacketQwc = Convert.ToUInt16(vifPacket.Length / 16); + + vifPacket.Write(new byte[8], 0, 8); // write later 8 bytes of the follwing dma (id=RET) packet. + } + + private void Align16Plus8(Stream stream) + { + stream.Position = stream.Length; + var fill = new byte[(16 - ((int)(stream.Length - 8) & 15)) & 15]; + stream.Write(fill, 0, fill.Length); + } + + private static byte ToPs2Alpha(byte data) => (byte)((data + 1) / 2); + + class DmaSourceChainTag + { + [Data] public ushort qwc { get; set; } + [Data] public ushort idFlg { get; set; } + [Data] public uint addr { get; set; } + } + + /// + /// VPU1 map program header + /// + class TopHeader + { + [Data] public int unk1 { get; set; } + [Data] public int unk2 { get; set; } + [Data] public int unk3 { get; set; } + [Data] public int unk4 { get; set; } + + [Data] public int numVertIdx { get; set; } + [Data] public int offVertIdx { get; set; } + [Data] public int unk5 { get; set; } + [Data] public int unk6 { get; set; } + + [Data] public int numClrVert { get; set; } + [Data] public int offClrVert { get; set; } + [Data] public int unk7 { get; set; } + [Data] public int unk8 { get; set; } + + [Data] public int numPosVert { get; set; } + [Data] public int offPosVert { get; set; } + [Data] public int unk9 { get; set; } + [Data] public int unk10 { get; set; } + } + } +} diff --git a/OpenKh.Command.MapGen/Utils/SimplePatternUtil.cs b/OpenKh.Command.MapGen/Utils/SimplePatternUtil.cs index 3df1e7ee7..f0a3e7f24 100644 --- a/OpenKh.Command.MapGen/Utils/SimplePatternUtil.cs +++ b/OpenKh.Command.MapGen/Utils/SimplePatternUtil.cs @@ -1,18 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Text.RegularExpressions; - -namespace OpenKh.Command.MapGen.Utils -{ - public static class SimplePatternUtil - { - internal static Regex CreateFrom(string name) => - new Regex( - ("^" + Regex.Escape(name) + "$") - .Replace("\\*", ".*") - .Replace("\\?", ".?"), - RegexOptions.IgnoreCase | RegexOptions.CultureInvariant - ); - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; + +namespace OpenKh.Command.MapGen.Utils +{ + public static class SimplePatternUtil + { + internal static Regex CreateFrom(string name) => + new Regex( + ("^" + Regex.Escape(name) + "$") + .Replace("\\*", ".*") + .Replace("\\?", ".?"), + RegexOptions.IgnoreCase | RegexOptions.CultureInvariant + ); + } +} diff --git a/OpenKh.Command.MsgTool/Program.cs b/OpenKh.Command.MsgTool/Program.cs index 11e228720..f8650790f 100644 --- a/OpenKh.Command.MsgTool/Program.cs +++ b/OpenKh.Command.MsgTool/Program.cs @@ -1,86 +1,86 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using McMaster.Extensions.CommandLineUtils; -using System; -using System.IO; -using System.Xml.Linq; -using System.Reflection; -using System.ComponentModel.DataAnnotations; -using System.Collections.Generic; - -namespace OpenKh.Command.MsgTool -{ - [Command("OpenKh.Command.MsgTool")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - class Program - { - private static readonly Dictionary Encoders = new Dictionary() - { - ["eusys"] = Kh2.Messages.Encoders.InternationalSystem, - ["euevt"] = Kh2.Messages.Encoders.InternationalSystem, - ["jpsys"] = Kh2.Messages.Encoders.JapaneseSystem, - ["jpevt"] = Kh2.Messages.Encoders.JapaneseEvent, - }; - - static void Main(string[] args) - { - try - { - CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - } - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - [Required] - [Option(ShortName = "i", LongName = "input", Description = "MSG file (almost all the files inside msg/{language}/ are considered MSGs)")] - public string Input { get; } - - [Required] - [AllowedValues("eusys", "euevt", "jpsys", "jpevt")] - [Option(ShortName = "e", LongName = "encoder", Description = "Specify which encoder should be used")] - public string Encoder { get; } - - private void OnExecute() - { - var outputFileName = Input.Replace(".bar", ".xml", StringComparison.InvariantCultureIgnoreCase); - - using (var stream = File.OpenRead(Input)) - { - var barEntries = Bar.Read(stream); - foreach (Bar.Entry barEntry in barEntries) - { - if (barEntry.Type == Bar.EntryType.List) - { - barEntry.Stream.Position = 0; - ConvertMsgToXml(barEntry.Stream, outputFileName, Encoders[Encoder]); - - break; - } - } - } - } - - private void ConvertMsgToXml(Stream inStream, string fileName, IMessageEncoder encoder) - { - using (var outStream = File.Create(fileName)) - ConvertMsgToXml(inStream, outStream, encoder); - } - - private void ConvertMsgToXml(Stream inStream, Stream outStream, IMessageEncoder encoder) - { - var root = MsgSerializer.SerializeXEntries(Msg.Read(inStream), encoder, true); - var document = new XDocument(root); - document.Save(outStream); - } - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using McMaster.Extensions.CommandLineUtils; +using System; +using System.IO; +using System.Xml.Linq; +using System.Reflection; +using System.ComponentModel.DataAnnotations; +using System.Collections.Generic; + +namespace OpenKh.Command.MsgTool +{ + [Command("OpenKh.Command.MsgTool")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + class Program + { + private static readonly Dictionary Encoders = new Dictionary() + { + ["eusys"] = Kh2.Messages.Encoders.InternationalSystem, + ["euevt"] = Kh2.Messages.Encoders.InternationalSystem, + ["jpsys"] = Kh2.Messages.Encoders.JapaneseSystem, + ["jpevt"] = Kh2.Messages.Encoders.JapaneseEvent, + }; + + static void Main(string[] args) + { + try + { + CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + } + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + [Required] + [Option(ShortName = "i", LongName = "input", Description = "MSG file (almost all the files inside msg/{language}/ are considered MSGs)")] + public string Input { get; } + + [Required] + [AllowedValues("eusys", "euevt", "jpsys", "jpevt")] + [Option(ShortName = "e", LongName = "encoder", Description = "Specify which encoder should be used")] + public string Encoder { get; } + + private void OnExecute() + { + var outputFileName = Input.Replace(".bar", ".xml", StringComparison.InvariantCultureIgnoreCase); + + using (var stream = File.OpenRead(Input)) + { + var barEntries = Bar.Read(stream); + foreach (Bar.Entry barEntry in barEntries) + { + if (barEntry.Type == Bar.EntryType.List) + { + barEntry.Stream.Position = 0; + ConvertMsgToXml(barEntry.Stream, outputFileName, Encoders[Encoder]); + + break; + } + } + } + } + + private void ConvertMsgToXml(Stream inStream, string fileName, IMessageEncoder encoder) + { + using (var outStream = File.Create(fileName)) + ConvertMsgToXml(inStream, outStream, encoder); + } + + private void ConvertMsgToXml(Stream inStream, Stream outStream, IMessageEncoder encoder) + { + var root = MsgSerializer.SerializeXEntries(Msg.Read(inStream), encoder, true); + var document = new XDocument(root); + document.Save(outStream); + } + } +} diff --git a/OpenKh.Command.PAMtoFBXConverter/Program.cs b/OpenKh.Command.PAMtoFBXConverter/Program.cs index b87b411f9..02269920c 100644 --- a/OpenKh.Command.PAMtoFBXConverter/Program.cs +++ b/OpenKh.Command.PAMtoFBXConverter/Program.cs @@ -1,573 +1,573 @@ -using OpenKh.Engine.Parsers; -using OpenKh.Imaging; - -using McMaster.Extensions.CommandLineUtils; -using System; -using System.IO; -using System.Linq; -using System.Reflection; -using System.ComponentModel.DataAnnotations; -using OpenKh.Bbs; -using System.Collections.Generic; -using System.Numerics; -using OpenKh.Common.Utils; -using Assimp; - -namespace OpenKh.Command.PAMtoFBXConverter -{ - [Command("OpenKh.Command.PAMtoFBXConverter")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - class Program - { - static void Main(string[] args) - { - try - { - CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - } - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - [Required] - [Argument(0, "PMO File", "The PMO to use as a base for the conversion.")] - public string PMO_FileName { get; } - - [Required] - [Argument(1, "PAM File", "The PAM animation set to use for the conversion.")] - public string PAM_FileName { get; } - - private void OnExecute() - { - try - { - Convert(PMO_FileName, PAM_FileName); - } - catch (Exception ex) - { - Console.WriteLine($"ERROR: {ex.Message}"); - } - } - - private static void Convert(string PMO_Path, string PAM_Path) - { - Stream pmoStream = File.OpenRead(PMO_Path); - Stream pamStream = File.OpenRead(PAM_Path); - Pmo pmo = Pmo.Read(pmoStream); - Pam pam = Pam.Read(pamStream); - - Assimp.Scene nScene = GetPMOScene(pmo); - List FBXAnims = PAMtoFBXAnim(pmo, pam); - nScene.Animations.AddRange(FBXAnims); - - pmoStream.Close(); - pamStream.Close(); - - using var ctx = new AssimpContext(); - ctx.ExportFile(nScene, "Test.fbx", "fbx"); - - } - - private static Assimp.Scene GetPMOScene(Pmo pmo) - { - Assimp.Scene scene = new Assimp.Scene(); - scene.RootNode = new Assimp.Node("root"); - - // Add materials. - List matList = new List(); - for(int t = 0; t < pmo.header.TextureCount; t++) - { - Material mat = new Material(); - mat.Clear(); - mat.Name = pmo.textureInfo[t].TextureName; - scene.Materials.Add(mat); - } - - // Add skeleton. - List Skeleton = new List(); - for (int b = 0; b < pmo.skeletonHeader.BoneCount; b++) - { - Pmo.BoneData bn = pmo.boneList[b]; - - Assimp.Matrix4x4 mtx = new Assimp.Matrix4x4(); - mtx.A1 = bn.Transform.M11; - mtx.A2 = bn.Transform.M12; - mtx.A3 = bn.Transform.M13; - mtx.A4 = bn.Transform.M14; - mtx.B1 = bn.Transform.M21; - mtx.B2 = bn.Transform.M22; - mtx.B3 = bn.Transform.M23; - mtx.B4 = bn.Transform.M24; - mtx.C1 = bn.Transform.M31; - mtx.C2 = bn.Transform.M32; - mtx.C3 = bn.Transform.M33; - mtx.C4 = bn.Transform.M34; - mtx.D1 = bn.Transform.M41; - mtx.D2 = bn.Transform.M42; - mtx.D3 = bn.Transform.M43; - mtx.D4 = bn.Transform.M44; - - Assimp.Matrix4x4 nd_mtx = mtx; - nd_mtx.Transpose(); - if (bn.ParentBoneIndex == 0xFFFF) - { - - Node curNode = new Node(bn.JointName); - curNode.Transform = nd_mtx; - scene.RootNode.Children.Add(curNode); - Skeleton.Add(curNode); - } - else - { - Node curNode = new Node(bn.JointName, Skeleton[bn.ParentBoneIndex]); - - nd_mtx.A4 *= 100.0f; - nd_mtx.B4 *= 100.0f; - nd_mtx.C4 *= 100.0f; - - curNode.Transform = nd_mtx; - Skeleton.Add(curNode); - scene.RootNode.FindNode(Skeleton[bn.ParentBoneIndex].Name).Children.Add(curNode); - } - } - - // Add meshes. - for (int i = 0; i < pmo.Meshes.Count; i++) - { - Assimp.Mesh mesh = new Assimp.Mesh($"Mesh{i}", Assimp.PrimitiveType.Triangle); - Pmo.MeshChunks chunk = pmo.Meshes[i]; - - // Add vertices, vertex color and normals. - for (int j = 0; j < chunk.vertices.Count; j++) - { - mesh.Vertices.Add(new Assimp.Vector3D( - chunk.vertices[j].X * pmo.header.ModelScale * 100.0f, - chunk.vertices[j].Y * pmo.header.ModelScale * 100.0f, - chunk.vertices[j].Z * pmo.header.ModelScale * 100.0f)); - - mesh.VertexColorChannels[0].Add(new Color4D(1.0f, 1.0f, 1.0f, 1.0f)); - mesh.Normals.Add(new Vector3D()); - - } - mesh.SetIndices(chunk.Indices.ToArray(), 3); - mesh.MaterialIndex = chunk.SectionInfo.TextureID; - scene.Meshes.Add(mesh); - - for (int v = 0; v < chunk.vertices.Count; v++) - { - // Build bone influences. - for (int z = 0; z < chunk.SectionInfo_opt1.SectionBoneIndices.Length; z++) - { - if(chunk.SectionInfo_opt1.SectionBoneIndices[z] != 0xFF) - { - Pmo.BoneData currentBone = new Pmo.BoneData(); - - int currentIndex = chunk.SectionInfo_opt1.SectionBoneIndices[z]; - currentBone = pmo.boneList[currentIndex]; - - string boneName = currentBone.JointName; - Assimp.Matrix4x4 mtx = new Assimp.Matrix4x4(); - mtx.A1 = currentBone.Transform.M11; - mtx.A2 = currentBone.Transform.M12; - mtx.A3 = currentBone.Transform.M13; - mtx.A4 = currentBone.Transform.M14; - mtx.B1 = currentBone.Transform.M21; - mtx.B2 = currentBone.Transform.M22; - mtx.B3 = currentBone.Transform.M23; - mtx.B4 = currentBone.Transform.M24; - mtx.C1 = currentBone.Transform.M31; - mtx.C2 = currentBone.Transform.M32; - mtx.C3 = currentBone.Transform.M33; - mtx.C4 = currentBone.Transform.M34; - mtx.D1 = currentBone.Transform.M41; - mtx.D2 = currentBone.Transform.M42; - mtx.D3 = currentBone.Transform.M43; - mtx.D4 = currentBone.Transform.M44; - Matrix3x3 mtx3 = new Matrix3x3(mtx); - - mtx.Transpose(); - - mtx.A4 *= 100.0f; - mtx.B4 *= 100.0f; - mtx.C4 *= 100.0f; - - - mtx3.Transpose(); - - List weight = new List(); - - VertexWeight vW = new VertexWeight(); - vW.VertexID = v; - - float currentWeight = chunk.jointWeights[v].weights[z]; - - switch (chunk.jointWeights[v].coordFormart) - { - case Pmo.CoordinateFormat.NO_VERTEX: - break; - case Pmo.CoordinateFormat.NORMALIZED_8_BITS: - currentWeight *= 127.0f; - currentWeight /= 128.0f; - break; - case Pmo.CoordinateFormat.NORMALIZED_16_BITS: - currentWeight *= 32767.0f; - currentWeight /= 32768.0f; - break; - case Pmo.CoordinateFormat.FLOAT_32_BITS: - break; - } - - vW.Weight = currentWeight; - weight.Add(vW); - - Bone tempBone = scene.Meshes[i].Bones.Find(x => x.Name == boneName); - int boneInd = scene.Meshes[i].Bones.FindIndex(0, x => x.Name == boneName); - - if (tempBone == null) - { - Bone bone = new Bone(boneName, mtx3, weight.ToArray()); - scene.Meshes[i].Bones.Add(bone); - } - else - { - scene.Meshes[i].Bones[boneInd].VertexWeights.Add(vW); - } - } - } - } - } - - scene.RootNode.MeshIndices.AddRange(Enumerable.Range(0, scene.MeshCount)); - - return scene; - } - - private static List PAMtoFBXAnim(Pmo pmo, Pam pam) - { - List animationList = new List(); - - for(int i = 0; i < pam.header.AnimationCount; i++) - { - Assimp.Animation anim = new Assimp.Animation(); - anim.Name = pam.animList[i].AnimEntry.AnimationName; - anim.DurationInTicks = pam.animList[i].AnimHeader.FrameCount; - anim.TicksPerSecond = pam.animList[i].AnimHeader.Framerate; - - //anim.MeshAnimationChannels[0].MeshKeys.Add(new MeshKey(anim.DurationInTicks / 2, new Vector3D(0, 0, 100))); - - for (int b = 0; b < pam.animList[i].AnimHeader.BoneCount; b++) - { - Pam.BoneChannel chann = pam.animList[i].BoneChannels[b]; - - anim.NodeAnimationChannels.Add(new NodeAnimationChannel()); - anim.NodeAnimationChannels[b].NodeName = pmo.boneList[b].JointName; - ChannelData dat = GetChannelKeyframes(chann, anim.DurationInTicks); - - //AddTranslationAtKeyframe(anim.NodeAnimationChannels[b].PositionKeys, 0, new Vector3D(), anim.TicksPerSecond); - // Position - /*if(dat.transData != null) - { - foreach (ChannelTranslationData trans in dat.transData) - { - AddTranslationAtKeyframe(anim.NodeAnimationChannels[b].PositionKeys, trans.keyframeID, trans.Translation, anim.TicksPerSecond); - } - }*/ - - /*if (dat.rotData != null) - { - // Rotation - foreach (ChannelRotationData trans in dat.rotData) - { - AddRotationAtKeyframe(anim.NodeAnimationChannels[b].RotationKeys, trans.keyframeID, trans.Rotation, anim.TicksPerSecond); - } - }*/ - - } - - animationList.Add(anim); - } - - return animationList; - } - - private static void AddTranslationAtKeyframe(List Keys, int keyframe, Vector3D value, double framerate = 30.0) - { - double frametick = 1.0 / framerate; - double keyframeTime = frametick * keyframe; - Keys.Add(new VectorKey(keyframeTime, value)); - } - - private static void AddRotationAtKeyframe(List Keys, int keyframe, Assimp.Quaternion value, double framerate = 30.0) - { - double frametick = 1.0 / framerate; - double keyframeTime = frametick * keyframe; - Keys.Add(new QuaternionKey(keyframeTime, value)); - } - - public class ChannelTranslationData - { - public int keyframeID = 0; - public Vector3D Translation = new Vector3D(); - } - - public class ChannelRotationData - { - public int keyframeID = 0; - public Assimp.Quaternion Rotation = new Assimp.Quaternion(); - } - - public class ChannelData - { - public ChannelTranslationData[] transData; - public ChannelRotationData[] rotData; - } - - private static ChannelData GetChannelKeyframes(Pam.BoneChannel channel, double animFrameCount) - { - ChannelData channData = new ChannelData(); - int keyCount = 0; - - // Translation X - if (channel.TranslationX != null) - { - keyCount = channel.TranslationX.Header.KeyframeCount_16bits + channel.TranslationX.Header.KeyframeCount_8bits; - channData.transData = new ChannelTranslationData[keyCount]; - - if (keyCount == 1) - { - channData.transData = new ChannelTranslationData[1]; - channData.transData[0] = new ChannelTranslationData(); - channData.transData[0].keyframeID = 0; - channData.transData[0].Translation.X = channel.TranslationX.Header.MaxValue; - } - else - { - if (keyCount == animFrameCount) - { - for (int i = 0; i < keyCount; i++) - { - channData.transData[i] = new ChannelTranslationData(); - channData.transData[i].keyframeID = i; - channData.transData[i].Translation.X = channel.TranslationX.Keyframes[i].Value; - } - } - - if (keyCount < animFrameCount) - { - channData.transData = new ChannelTranslationData[channel.TranslationX.Keyframes.Count]; - for (int i = 0; i < channel.TranslationX.Keyframes.Count; i++) - { - channData.transData[i] = new ChannelTranslationData(); - channData.transData[i].keyframeID = channel.TranslationX.Keyframes[i].FrameID_16bits + channel.TranslationX.Keyframes[i].FrameID_8bits; - channData.transData[i].Translation.X = channel.TranslationX.Keyframes[i].Value; - } - } - } - } - - if (channel.TranslationY != null) - { - // Translation Y - keyCount = channel.TranslationY.Header.KeyframeCount_16bits + channel.TranslationY.Header.KeyframeCount_8bits; - channData.transData = new ChannelTranslationData[keyCount]; - - if (keyCount == 1) - { - channData.transData = new ChannelTranslationData[1]; - channData.transData[0] = new ChannelTranslationData(); - channData.transData[0].keyframeID = 0; - channData.transData[0].Translation.Y = channel.TranslationY.Header.MaxValue; - } - else - { - if (keyCount == animFrameCount) - { - for (int i = 0; i < keyCount; i++) - { - channData.transData[i] = new ChannelTranslationData(); - channData.transData[i].keyframeID = i; - channData.transData[i].Translation.Y = channel.TranslationY.Keyframes[i].Value; - } - } - - if (keyCount < animFrameCount) - { - channData.transData = new ChannelTranslationData[channel.TranslationY.Keyframes.Count]; - for (int i = 0; i < channel.TranslationY.Keyframes.Count; i++) - { - channData.transData[i] = new ChannelTranslationData(); - channData.transData[i].keyframeID = channel.TranslationY.Keyframes[i].FrameID_16bits + channel.TranslationY.Keyframes[i].FrameID_8bits; - channData.transData[i].Translation.Y = channel.TranslationY.Keyframes[i].Value; - } - } - } - } - - if (channel.TranslationZ != null) - { - // Translation Z - keyCount = channel.TranslationZ.Header.KeyframeCount_16bits + channel.TranslationZ.Header.KeyframeCount_8bits; - channData.transData = new ChannelTranslationData[keyCount]; - - if (keyCount == 1) - { - channData.transData = new ChannelTranslationData[1]; - channData.transData[0] = new ChannelTranslationData(); - channData.transData[0].keyframeID = 0; - channData.transData[0].Translation.Z = channel.TranslationZ.Header.MaxValue; - } - else - { - if (keyCount == animFrameCount) - { - for (int i = 0; i < keyCount; i++) - { - channData.transData[i] = new ChannelTranslationData(); - channData.transData[i].keyframeID = i; - channData.transData[i].Translation.Z = channel.TranslationZ.Keyframes[i].Value; - } - } - - if (keyCount < animFrameCount) - { - channData.transData = new ChannelTranslationData[channel.TranslationZ.Keyframes.Count]; - for (int i = 0; i < channel.TranslationZ.Keyframes.Count; i++) - { - channData.transData[i] = new ChannelTranslationData(); - channData.transData[i].keyframeID = channel.TranslationZ.Keyframes[i].FrameID_16bits + channel.TranslationZ.Keyframes[i].FrameID_8bits; - channData.transData[i].Translation.Z = channel.TranslationZ.Keyframes[i].Value; - } - } - } - } - - if (channel.RotationX != null) - { - // Rotation X - keyCount = channel.RotationX.Header.KeyframeCount_16bits + channel.RotationX.Header.KeyframeCount_8bits; - channData.rotData = new ChannelRotationData[keyCount]; - - if (keyCount == 1) - { - channData.rotData = new ChannelRotationData[1]; - channData.rotData[0] = new ChannelRotationData(); - channData.rotData[0].keyframeID = 0; - channData.rotData[0].Rotation.X = channel.RotationX.Header.MaxValue; - } - else - { - if (keyCount == animFrameCount) - { - for (int i = 0; i < keyCount; i++) - { - channData.rotData[i] = new ChannelRotationData(); - channData.rotData[i].keyframeID = i; - channData.rotData[i].Rotation.X = channel.RotationX.Keyframes[i].Value; - } - } - - if (keyCount < animFrameCount) - { - channData.rotData = new ChannelRotationData[channel.RotationX.Keyframes.Count]; - for (int i = 0; i < channel.RotationX.Keyframes.Count; i++) - { - channData.rotData[i] = new ChannelRotationData(); - channData.rotData[i].keyframeID = channel.RotationX.Keyframes[i].FrameID_16bits + channel.RotationX.Keyframes[i].FrameID_8bits; - channData.rotData[i].Rotation.X = channel.RotationX.Keyframes[i].Value; - } - } - } - } - - - if (channel.RotationY != null) - { - // Rotation Y - keyCount = channel.RotationY.Header.KeyframeCount_16bits + channel.RotationY.Header.KeyframeCount_8bits; - channData.rotData = new ChannelRotationData[keyCount]; - - if (keyCount == 1) - { - channData.rotData = new ChannelRotationData[1]; - channData.rotData[0] = new ChannelRotationData(); - channData.rotData[0].keyframeID = 0; - channData.rotData[0].Rotation.Y = channel.RotationY.Header.MaxValue; - } - else - { - if (keyCount == animFrameCount) - { - for (int i = 0; i < keyCount; i++) - { - channData.rotData[i] = new ChannelRotationData(); - channData.rotData[i].keyframeID = i; - channData.rotData[i].Rotation.Y = channel.RotationY.Keyframes[i].Value; - } - } - - if (keyCount < animFrameCount) - { - channData.rotData = new ChannelRotationData[channel.RotationY.Keyframes.Count]; - for (int i = 0; i < channel.RotationY.Keyframes.Count; i++) - { - channData.rotData[i] = new ChannelRotationData(); - channData.rotData[i].keyframeID = channel.RotationY.Keyframes[i].FrameID_16bits + channel.RotationY.Keyframes[i].FrameID_8bits; - channData.rotData[i].Rotation.Y = channel.RotationY.Keyframes[i].Value; - } - } - } - - } - - if (channel.RotationZ != null) - { - // Rotation Z - keyCount = channel.RotationZ.Header.KeyframeCount_16bits + channel.RotationZ.Header.KeyframeCount_8bits; - channData.rotData = new ChannelRotationData[keyCount]; - - if (keyCount == 1) - { - channData.rotData = new ChannelRotationData[1]; - channData.rotData[0] = new ChannelRotationData(); - channData.rotData[0].keyframeID = 0; - channData.rotData[0].Rotation.Z = channel.RotationZ.Header.MaxValue; - } - else - { - if (keyCount == animFrameCount) - { - for (int i = 0; i < keyCount; i++) - { - channData.rotData[i] = new ChannelRotationData(); - channData.rotData[i].keyframeID = i; - channData.rotData[i].Rotation.Z = channel.RotationZ.Keyframes[i].Value; - } - } - - if (keyCount < animFrameCount) - { - channData.rotData = new ChannelRotationData[channel.RotationZ.Keyframes.Count]; - for (int i = 0; i < channel.RotationZ.Keyframes.Count; i++) - { - channData.rotData[i] = new ChannelRotationData(); - channData.rotData[i].keyframeID = channel.RotationZ.Keyframes[i].FrameID_16bits + channel.RotationZ.Keyframes[i].FrameID_8bits; - channData.rotData[i].Rotation.Z = channel.RotationZ.Keyframes[i].Value; - } - } - } - - } - - return channData; - } - } -} +using OpenKh.Engine.Parsers; +using OpenKh.Imaging; + +using McMaster.Extensions.CommandLineUtils; +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using System.ComponentModel.DataAnnotations; +using OpenKh.Bbs; +using System.Collections.Generic; +using System.Numerics; +using OpenKh.Common.Utils; +using Assimp; + +namespace OpenKh.Command.PAMtoFBXConverter +{ + [Command("OpenKh.Command.PAMtoFBXConverter")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + class Program + { + static void Main(string[] args) + { + try + { + CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + } + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + [Required] + [Argument(0, "PMO File", "The PMO to use as a base for the conversion.")] + public string PMO_FileName { get; } + + [Required] + [Argument(1, "PAM File", "The PAM animation set to use for the conversion.")] + public string PAM_FileName { get; } + + private void OnExecute() + { + try + { + Convert(PMO_FileName, PAM_FileName); + } + catch (Exception ex) + { + Console.WriteLine($"ERROR: {ex.Message}"); + } + } + + private static void Convert(string PMO_Path, string PAM_Path) + { + Stream pmoStream = File.OpenRead(PMO_Path); + Stream pamStream = File.OpenRead(PAM_Path); + Pmo pmo = Pmo.Read(pmoStream); + Pam pam = Pam.Read(pamStream); + + Assimp.Scene nScene = GetPMOScene(pmo); + List FBXAnims = PAMtoFBXAnim(pmo, pam); + nScene.Animations.AddRange(FBXAnims); + + pmoStream.Close(); + pamStream.Close(); + + using var ctx = new AssimpContext(); + ctx.ExportFile(nScene, "Test.fbx", "fbx"); + + } + + private static Assimp.Scene GetPMOScene(Pmo pmo) + { + Assimp.Scene scene = new Assimp.Scene(); + scene.RootNode = new Assimp.Node("root"); + + // Add materials. + List matList = new List(); + for (int t = 0; t < pmo.header.TextureCount; t++) + { + Material mat = new Material(); + mat.Clear(); + mat.Name = pmo.textureInfo[t].TextureName; + scene.Materials.Add(mat); + } + + // Add skeleton. + List Skeleton = new List(); + for (int b = 0; b < pmo.skeletonHeader.BoneCount; b++) + { + Pmo.BoneData bn = pmo.boneList[b]; + + Assimp.Matrix4x4 mtx = new Assimp.Matrix4x4(); + mtx.A1 = bn.Transform.M11; + mtx.A2 = bn.Transform.M12; + mtx.A3 = bn.Transform.M13; + mtx.A4 = bn.Transform.M14; + mtx.B1 = bn.Transform.M21; + mtx.B2 = bn.Transform.M22; + mtx.B3 = bn.Transform.M23; + mtx.B4 = bn.Transform.M24; + mtx.C1 = bn.Transform.M31; + mtx.C2 = bn.Transform.M32; + mtx.C3 = bn.Transform.M33; + mtx.C4 = bn.Transform.M34; + mtx.D1 = bn.Transform.M41; + mtx.D2 = bn.Transform.M42; + mtx.D3 = bn.Transform.M43; + mtx.D4 = bn.Transform.M44; + + Assimp.Matrix4x4 nd_mtx = mtx; + nd_mtx.Transpose(); + if (bn.ParentBoneIndex == 0xFFFF) + { + + Node curNode = new Node(bn.JointName); + curNode.Transform = nd_mtx; + scene.RootNode.Children.Add(curNode); + Skeleton.Add(curNode); + } + else + { + Node curNode = new Node(bn.JointName, Skeleton[bn.ParentBoneIndex]); + + nd_mtx.A4 *= 100.0f; + nd_mtx.B4 *= 100.0f; + nd_mtx.C4 *= 100.0f; + + curNode.Transform = nd_mtx; + Skeleton.Add(curNode); + scene.RootNode.FindNode(Skeleton[bn.ParentBoneIndex].Name).Children.Add(curNode); + } + } + + // Add meshes. + for (int i = 0; i < pmo.Meshes.Count; i++) + { + Assimp.Mesh mesh = new Assimp.Mesh($"Mesh{i}", Assimp.PrimitiveType.Triangle); + Pmo.MeshChunks chunk = pmo.Meshes[i]; + + // Add vertices, vertex color and normals. + for (int j = 0; j < chunk.vertices.Count; j++) + { + mesh.Vertices.Add(new Assimp.Vector3D( + chunk.vertices[j].X * pmo.header.ModelScale * 100.0f, + chunk.vertices[j].Y * pmo.header.ModelScale * 100.0f, + chunk.vertices[j].Z * pmo.header.ModelScale * 100.0f)); + + mesh.VertexColorChannels[0].Add(new Color4D(1.0f, 1.0f, 1.0f, 1.0f)); + mesh.Normals.Add(new Vector3D()); + + } + mesh.SetIndices(chunk.Indices.ToArray(), 3); + mesh.MaterialIndex = chunk.SectionInfo.TextureID; + scene.Meshes.Add(mesh); + + for (int v = 0; v < chunk.vertices.Count; v++) + { + // Build bone influences. + for (int z = 0; z < chunk.SectionInfo_opt1.SectionBoneIndices.Length; z++) + { + if (chunk.SectionInfo_opt1.SectionBoneIndices[z] != 0xFF) + { + Pmo.BoneData currentBone = new Pmo.BoneData(); + + int currentIndex = chunk.SectionInfo_opt1.SectionBoneIndices[z]; + currentBone = pmo.boneList[currentIndex]; + + string boneName = currentBone.JointName; + Assimp.Matrix4x4 mtx = new Assimp.Matrix4x4(); + mtx.A1 = currentBone.Transform.M11; + mtx.A2 = currentBone.Transform.M12; + mtx.A3 = currentBone.Transform.M13; + mtx.A4 = currentBone.Transform.M14; + mtx.B1 = currentBone.Transform.M21; + mtx.B2 = currentBone.Transform.M22; + mtx.B3 = currentBone.Transform.M23; + mtx.B4 = currentBone.Transform.M24; + mtx.C1 = currentBone.Transform.M31; + mtx.C2 = currentBone.Transform.M32; + mtx.C3 = currentBone.Transform.M33; + mtx.C4 = currentBone.Transform.M34; + mtx.D1 = currentBone.Transform.M41; + mtx.D2 = currentBone.Transform.M42; + mtx.D3 = currentBone.Transform.M43; + mtx.D4 = currentBone.Transform.M44; + Matrix3x3 mtx3 = new Matrix3x3(mtx); + + mtx.Transpose(); + + mtx.A4 *= 100.0f; + mtx.B4 *= 100.0f; + mtx.C4 *= 100.0f; + + + mtx3.Transpose(); + + List weight = new List(); + + VertexWeight vW = new VertexWeight(); + vW.VertexID = v; + + float currentWeight = chunk.jointWeights[v].weights[z]; + + switch (chunk.jointWeights[v].coordFormart) + { + case Pmo.CoordinateFormat.NO_VERTEX: + break; + case Pmo.CoordinateFormat.NORMALIZED_8_BITS: + currentWeight *= 127.0f; + currentWeight /= 128.0f; + break; + case Pmo.CoordinateFormat.NORMALIZED_16_BITS: + currentWeight *= 32767.0f; + currentWeight /= 32768.0f; + break; + case Pmo.CoordinateFormat.FLOAT_32_BITS: + break; + } + + vW.Weight = currentWeight; + weight.Add(vW); + + Bone tempBone = scene.Meshes[i].Bones.Find(x => x.Name == boneName); + int boneInd = scene.Meshes[i].Bones.FindIndex(0, x => x.Name == boneName); + + if (tempBone == null) + { + Bone bone = new Bone(boneName, mtx3, weight.ToArray()); + scene.Meshes[i].Bones.Add(bone); + } + else + { + scene.Meshes[i].Bones[boneInd].VertexWeights.Add(vW); + } + } + } + } + } + + scene.RootNode.MeshIndices.AddRange(Enumerable.Range(0, scene.MeshCount)); + + return scene; + } + + private static List PAMtoFBXAnim(Pmo pmo, Pam pam) + { + List animationList = new List(); + + for (int i = 0; i < pam.header.AnimationCount; i++) + { + Assimp.Animation anim = new Assimp.Animation(); + anim.Name = pam.animList[i].AnimEntry.AnimationName; + anim.DurationInTicks = pam.animList[i].AnimHeader.FrameCount; + anim.TicksPerSecond = pam.animList[i].AnimHeader.Framerate; + + //anim.MeshAnimationChannels[0].MeshKeys.Add(new MeshKey(anim.DurationInTicks / 2, new Vector3D(0, 0, 100))); + + for (int b = 0; b < pam.animList[i].AnimHeader.BoneCount; b++) + { + Pam.BoneChannel chann = pam.animList[i].BoneChannels[b]; + + anim.NodeAnimationChannels.Add(new NodeAnimationChannel()); + anim.NodeAnimationChannels[b].NodeName = pmo.boneList[b].JointName; + ChannelData dat = GetChannelKeyframes(chann, anim.DurationInTicks); + + //AddTranslationAtKeyframe(anim.NodeAnimationChannels[b].PositionKeys, 0, new Vector3D(), anim.TicksPerSecond); + // Position + /*if(dat.transData != null) + { + foreach (ChannelTranslationData trans in dat.transData) + { + AddTranslationAtKeyframe(anim.NodeAnimationChannels[b].PositionKeys, trans.keyframeID, trans.Translation, anim.TicksPerSecond); + } + }*/ + + /*if (dat.rotData != null) + { + // Rotation + foreach (ChannelRotationData trans in dat.rotData) + { + AddRotationAtKeyframe(anim.NodeAnimationChannels[b].RotationKeys, trans.keyframeID, trans.Rotation, anim.TicksPerSecond); + } + }*/ + + } + + animationList.Add(anim); + } + + return animationList; + } + + private static void AddTranslationAtKeyframe(List Keys, int keyframe, Vector3D value, double framerate = 30.0) + { + double frametick = 1.0 / framerate; + double keyframeTime = frametick * keyframe; + Keys.Add(new VectorKey(keyframeTime, value)); + } + + private static void AddRotationAtKeyframe(List Keys, int keyframe, Assimp.Quaternion value, double framerate = 30.0) + { + double frametick = 1.0 / framerate; + double keyframeTime = frametick * keyframe; + Keys.Add(new QuaternionKey(keyframeTime, value)); + } + + public class ChannelTranslationData + { + public int keyframeID = 0; + public Vector3D Translation = new Vector3D(); + } + + public class ChannelRotationData + { + public int keyframeID = 0; + public Assimp.Quaternion Rotation = new Assimp.Quaternion(); + } + + public class ChannelData + { + public ChannelTranslationData[] transData; + public ChannelRotationData[] rotData; + } + + private static ChannelData GetChannelKeyframes(Pam.BoneChannel channel, double animFrameCount) + { + ChannelData channData = new ChannelData(); + int keyCount = 0; + + // Translation X + if (channel.TranslationX != null) + { + keyCount = channel.TranslationX.Header.KeyframeCount_16bits + channel.TranslationX.Header.KeyframeCount_8bits; + channData.transData = new ChannelTranslationData[keyCount]; + + if (keyCount == 1) + { + channData.transData = new ChannelTranslationData[1]; + channData.transData[0] = new ChannelTranslationData(); + channData.transData[0].keyframeID = 0; + channData.transData[0].Translation.X = channel.TranslationX.Header.MaxValue; + } + else + { + if (keyCount == animFrameCount) + { + for (int i = 0; i < keyCount; i++) + { + channData.transData[i] = new ChannelTranslationData(); + channData.transData[i].keyframeID = i; + channData.transData[i].Translation.X = channel.TranslationX.Keyframes[i].Value; + } + } + + if (keyCount < animFrameCount) + { + channData.transData = new ChannelTranslationData[channel.TranslationX.Keyframes.Count]; + for (int i = 0; i < channel.TranslationX.Keyframes.Count; i++) + { + channData.transData[i] = new ChannelTranslationData(); + channData.transData[i].keyframeID = channel.TranslationX.Keyframes[i].FrameID_16bits + channel.TranslationX.Keyframes[i].FrameID_8bits; + channData.transData[i].Translation.X = channel.TranslationX.Keyframes[i].Value; + } + } + } + } + + if (channel.TranslationY != null) + { + // Translation Y + keyCount = channel.TranslationY.Header.KeyframeCount_16bits + channel.TranslationY.Header.KeyframeCount_8bits; + channData.transData = new ChannelTranslationData[keyCount]; + + if (keyCount == 1) + { + channData.transData = new ChannelTranslationData[1]; + channData.transData[0] = new ChannelTranslationData(); + channData.transData[0].keyframeID = 0; + channData.transData[0].Translation.Y = channel.TranslationY.Header.MaxValue; + } + else + { + if (keyCount == animFrameCount) + { + for (int i = 0; i < keyCount; i++) + { + channData.transData[i] = new ChannelTranslationData(); + channData.transData[i].keyframeID = i; + channData.transData[i].Translation.Y = channel.TranslationY.Keyframes[i].Value; + } + } + + if (keyCount < animFrameCount) + { + channData.transData = new ChannelTranslationData[channel.TranslationY.Keyframes.Count]; + for (int i = 0; i < channel.TranslationY.Keyframes.Count; i++) + { + channData.transData[i] = new ChannelTranslationData(); + channData.transData[i].keyframeID = channel.TranslationY.Keyframes[i].FrameID_16bits + channel.TranslationY.Keyframes[i].FrameID_8bits; + channData.transData[i].Translation.Y = channel.TranslationY.Keyframes[i].Value; + } + } + } + } + + if (channel.TranslationZ != null) + { + // Translation Z + keyCount = channel.TranslationZ.Header.KeyframeCount_16bits + channel.TranslationZ.Header.KeyframeCount_8bits; + channData.transData = new ChannelTranslationData[keyCount]; + + if (keyCount == 1) + { + channData.transData = new ChannelTranslationData[1]; + channData.transData[0] = new ChannelTranslationData(); + channData.transData[0].keyframeID = 0; + channData.transData[0].Translation.Z = channel.TranslationZ.Header.MaxValue; + } + else + { + if (keyCount == animFrameCount) + { + for (int i = 0; i < keyCount; i++) + { + channData.transData[i] = new ChannelTranslationData(); + channData.transData[i].keyframeID = i; + channData.transData[i].Translation.Z = channel.TranslationZ.Keyframes[i].Value; + } + } + + if (keyCount < animFrameCount) + { + channData.transData = new ChannelTranslationData[channel.TranslationZ.Keyframes.Count]; + for (int i = 0; i < channel.TranslationZ.Keyframes.Count; i++) + { + channData.transData[i] = new ChannelTranslationData(); + channData.transData[i].keyframeID = channel.TranslationZ.Keyframes[i].FrameID_16bits + channel.TranslationZ.Keyframes[i].FrameID_8bits; + channData.transData[i].Translation.Z = channel.TranslationZ.Keyframes[i].Value; + } + } + } + } + + if (channel.RotationX != null) + { + // Rotation X + keyCount = channel.RotationX.Header.KeyframeCount_16bits + channel.RotationX.Header.KeyframeCount_8bits; + channData.rotData = new ChannelRotationData[keyCount]; + + if (keyCount == 1) + { + channData.rotData = new ChannelRotationData[1]; + channData.rotData[0] = new ChannelRotationData(); + channData.rotData[0].keyframeID = 0; + channData.rotData[0].Rotation.X = channel.RotationX.Header.MaxValue; + } + else + { + if (keyCount == animFrameCount) + { + for (int i = 0; i < keyCount; i++) + { + channData.rotData[i] = new ChannelRotationData(); + channData.rotData[i].keyframeID = i; + channData.rotData[i].Rotation.X = channel.RotationX.Keyframes[i].Value; + } + } + + if (keyCount < animFrameCount) + { + channData.rotData = new ChannelRotationData[channel.RotationX.Keyframes.Count]; + for (int i = 0; i < channel.RotationX.Keyframes.Count; i++) + { + channData.rotData[i] = new ChannelRotationData(); + channData.rotData[i].keyframeID = channel.RotationX.Keyframes[i].FrameID_16bits + channel.RotationX.Keyframes[i].FrameID_8bits; + channData.rotData[i].Rotation.X = channel.RotationX.Keyframes[i].Value; + } + } + } + } + + + if (channel.RotationY != null) + { + // Rotation Y + keyCount = channel.RotationY.Header.KeyframeCount_16bits + channel.RotationY.Header.KeyframeCount_8bits; + channData.rotData = new ChannelRotationData[keyCount]; + + if (keyCount == 1) + { + channData.rotData = new ChannelRotationData[1]; + channData.rotData[0] = new ChannelRotationData(); + channData.rotData[0].keyframeID = 0; + channData.rotData[0].Rotation.Y = channel.RotationY.Header.MaxValue; + } + else + { + if (keyCount == animFrameCount) + { + for (int i = 0; i < keyCount; i++) + { + channData.rotData[i] = new ChannelRotationData(); + channData.rotData[i].keyframeID = i; + channData.rotData[i].Rotation.Y = channel.RotationY.Keyframes[i].Value; + } + } + + if (keyCount < animFrameCount) + { + channData.rotData = new ChannelRotationData[channel.RotationY.Keyframes.Count]; + for (int i = 0; i < channel.RotationY.Keyframes.Count; i++) + { + channData.rotData[i] = new ChannelRotationData(); + channData.rotData[i].keyframeID = channel.RotationY.Keyframes[i].FrameID_16bits + channel.RotationY.Keyframes[i].FrameID_8bits; + channData.rotData[i].Rotation.Y = channel.RotationY.Keyframes[i].Value; + } + } + } + + } + + if (channel.RotationZ != null) + { + // Rotation Z + keyCount = channel.RotationZ.Header.KeyframeCount_16bits + channel.RotationZ.Header.KeyframeCount_8bits; + channData.rotData = new ChannelRotationData[keyCount]; + + if (keyCount == 1) + { + channData.rotData = new ChannelRotationData[1]; + channData.rotData[0] = new ChannelRotationData(); + channData.rotData[0].keyframeID = 0; + channData.rotData[0].Rotation.Z = channel.RotationZ.Header.MaxValue; + } + else + { + if (keyCount == animFrameCount) + { + for (int i = 0; i < keyCount; i++) + { + channData.rotData[i] = new ChannelRotationData(); + channData.rotData[i].keyframeID = i; + channData.rotData[i].Rotation.Z = channel.RotationZ.Keyframes[i].Value; + } + } + + if (keyCount < animFrameCount) + { + channData.rotData = new ChannelRotationData[channel.RotationZ.Keyframes.Count]; + for (int i = 0; i < channel.RotationZ.Keyframes.Count; i++) + { + channData.rotData[i] = new ChannelRotationData(); + channData.rotData[i].keyframeID = channel.RotationZ.Keyframes[i].FrameID_16bits + channel.RotationZ.Keyframes[i].FrameID_8bits; + channData.rotData[i].Rotation.Z = channel.RotationZ.Keyframes[i].Value; + } + } + } + + } + + return channData; + } + } +} diff --git a/OpenKh.Command.PmoConverter/Program.cs b/OpenKh.Command.PmoConverter/Program.cs index 41aea18a2..485617a4e 100644 --- a/OpenKh.Command.PmoConverter/Program.cs +++ b/OpenKh.Command.PmoConverter/Program.cs @@ -1,341 +1,343 @@ -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Parsers; -using OpenKh.Imaging; - -using McMaster.Extensions.CommandLineUtils; -using System; -using System.IO; -using System.Linq; -using System.Reflection; -using System.ComponentModel.DataAnnotations; -using OpenKh.Bbs; -using System.Collections.Generic; -using System.Numerics; -using OpenKh.Common.Utils; - -namespace OpenKh.Command.PmoConverter -{ - [Command("OpenKh.Command.PmoConverter")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - class Program - { - static void Main(string[] args) - { - try - { - CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - } - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - [Required] - [Argument(0, "Convert File", "The file to convert to PMO.")] - public string FileName { get; } - - [Required] - [Argument(1, "Converted File", "The resulting converted PMO.")] - public string outFileName { get; } - - public static List TexList { get; set; } - public static List TextureData { get; set; } - - private void OnExecute() - { - try - { - Convert(FileName, outFileName); - } - catch (Exception ex) - { - Console.WriteLine($"ERROR: {ex.Message}"); - } - } - - private static void Convert(string fileIn, string fileOut) - { - MeshGroup p = FromFbx(fileIn); - Pmo pmo = MeshGroup2PMO(p); - using Stream stream = File.Create(fileOut); - Pmo.Write(stream, pmo); - stream.Close(); - } - - private static Pmo MeshGroup2PMO(MeshGroup meshGroup) - { - Pmo pmo = new Pmo(); - - List Descriptors = meshGroup.MeshDescriptors; - - // Max 65K vertices. - uint descriptorVertexCount = 0; - uint indicesVertexCount = 0; - foreach(MeshDescriptor d in Descriptors) - { - descriptorVertexCount += (uint)d.Vertices.Length; - indicesVertexCount += (uint)d.Indices.Length; - } - - // Mesh data. - for (int i = 0; i < Descriptors.Count; i++) - { - MeshDescriptor desc = Descriptors[i]; - int[] vertIndices = desc.Indices; - Pmo.MeshChunks chunk = new Pmo.MeshChunks(); - - // Obtain info for PMO Vertex Flag. - bool UsesUniformColor = UsesUniformDiffuseFlag(desc); - Pmo.CoordinateFormat TextureCoordinateFormat = GetTextureCoordinateFormat(desc); - Pmo.CoordinateFormat VertexFormat = GetVertexFormat(desc); - - chunk.SectionInfo = new Pmo.MeshSection(); - chunk.SectionInfo.Attribute = 0; - chunk.SectionInfo.VertexCount = (ushort)desc.Vertices.Length; - chunk.SectionInfo.TextureID = (byte)desc.TextureIndex; - chunk.SectionInfo.VertexFlags = 0x30000000; // 0011 000 0 0 00 000 0 000 0 00 00 11 00 000 01 - - // Set extra flags. - if (UsesUniformColor) - { - var UniformColor = (uint)(Math.Min(byte.MaxValue, desc.Vertices[0].A * 256f)); - UniformColor += (uint)(Math.Min(byte.MaxValue, desc.Vertices[0].B * 256f)) << 8; - UniformColor += (uint)(Math.Min(byte.MaxValue, desc.Vertices[0].G * 256f)) << 16; - UniformColor += (uint)(Math.Min(byte.MaxValue, desc.Vertices[0].R * 256f)) << 24; - chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBit(chunk.SectionInfo.VertexFlags, 24, true); - chunk.SectionInfo_opt2 = new Pmo.MeshSectionOptional2(); - chunk.SectionInfo_opt2.DiffuseColor = UniformColor; - } - else - chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 2, 3, (uint)0x7); - chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 0, 2, (uint)TextureCoordinateFormat); - chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 7, 2, (uint)VertexFormat); - - chunk.SectionInfo.VertexSize += 0; // Weights. - chunk.SectionInfo.VertexSize += (TextureCoordinateFormat == Pmo.CoordinateFormat.FLOAT_32_BITS) ? (byte)8 : (byte)((int)TextureCoordinateFormat * 2); // Texture Coordinates - if (chunk.SectionInfo.VertexSize % 4 != 0) - chunk.SectionInfo.VertexSize += 2; - chunk.SectionInfo.VertexSize += UsesUniformColor ? (byte)0 : (byte)4; // VertexColor - chunk.SectionInfo.VertexSize += (VertexFormat == Pmo.CoordinateFormat.FLOAT_32_BITS) ? (byte)12 : (byte)((int)VertexFormat * 3); // Vertices - - - for (int v = 0; v < desc.Indices.Length; v++) - { - int index = vertIndices[v]; - - Vector4 Color = new Vector4(); - Color.X = desc.Vertices[index].R * 2; - Color.Y = desc.Vertices[index].G * 2; - Color.Z = desc.Vertices[index].B * 2; - Color.W = desc.Vertices[index].A * 2; - chunk.colors.Add(Color); - - Vector3 vec; - vec.X = desc.Vertices[index].X / 10000.0f; - vec.Y = desc.Vertices[index].Y / 10000.0f; - vec.Z = desc.Vertices[index].Z / 10000.0f; - chunk.vertices.Add(vec); - - Vector2 Coords; - Coords.X = desc.Vertices[index].Tu; - Coords.Y = desc.Vertices[index].Tv; - chunk.textureCoordinates.Add(Coords); - } - - pmo.Meshes.Add(chunk); - } - - // Header. - pmo.header = new Pmo.Header(); - pmo.header.MagicCode = 0x4F4D50; - pmo.header.TextureCount = (ushort)TextureData.Count; // TODO. - pmo.header.Unk0A = 0x80; - pmo.header.MeshOffset0 = 0xA0 + ((uint)pmo.header.TextureCount * 0x20); - pmo.header.VertexCount = (ushort)indicesVertexCount; - pmo.header.TriangleCount = (ushort)indicesVertexCount; - pmo.header.TriangleCount /= 3; - pmo.header.ModelScale = 1.0f; - pmo.header.BoundingBox = new float[32]; - - // Texture block. - if(TextureData.Count > 0) - { - pmo.textureInfo = new Pmo.TextureInfo[TextureData.Count]; - - for (int t = 0; t < TextureData.Count; t++) - { - Tm2 tm = TextureData[t]; - pmo.textureInfo[t] = new Pmo.TextureInfo(); - pmo.textureInfo[t].TextureName = TexList[t]; - pmo.textureInfo[t].Unknown = new UInt32[4]; - pmo.texturesData.Add( TextureData[t] ); - } - } - - return pmo; - } - - public static bool UsesUniformDiffuseFlag(MeshDescriptor desc) - { - bool bDiffuseFlag = true; - Vector4 InitialColor = new Vector4(desc.Vertices[0].R, desc.Vertices[0].G, desc.Vertices[0].B, desc.Vertices[0].A); - Vector4 CompareColor = new Vector4(); - - foreach(PositionColoredTextured vert in desc.Vertices) - { - CompareColor = new Vector4(vert.R, vert.G, vert.B, vert.A); - - if (CompareColor != InitialColor) - return false; - } - - return bDiffuseFlag; - } - - public static Pmo.CoordinateFormat GetTextureCoordinateFormat(MeshDescriptor desc) - { - Vector2 ResizedVector = new Vector2(); - - // Check if 0 bits per coordinate. - bool is0bits = true; - foreach (PositionColoredTextured vert in desc.Vertices) - { - ResizedVector = new Vector2(vert.Tu, vert.Tv); - - if (ResizedVector.X != 0 || ResizedVector.Y != 0) - { - is0bits = false; - break; - } - } - if (is0bits) - return Pmo.CoordinateFormat.NO_VERTEX; - - // Check if 8 bits per coordinate. - bool is8bits = true; - foreach (PositionColoredTextured vert in desc.Vertices) - { - ResizedVector = new Vector2(vert.Tu * 128.0f, vert.Tv * 128.0f); - - if (ResizedVector.X > 255 || ResizedVector.Y > 255) - { - is8bits = false; - break; - } - } - if (is8bits) - return Pmo.CoordinateFormat.NORMALIZED_8_BITS; - - // Check if 16 bits per coordinate. - bool is16bits = true; - foreach (PositionColoredTextured vert in desc.Vertices) - { - ResizedVector = new Vector2(vert.Tu * 32768.0f, vert.Tv * 32768.0f); - - if (ResizedVector.X > 65535 || ResizedVector.Y > 65535) - { - is16bits = false; - break; - } - } - if (is16bits) - return Pmo.CoordinateFormat.NORMALIZED_16_BITS; - - return Pmo.CoordinateFormat.FLOAT_32_BITS; - } - - public static Pmo.CoordinateFormat GetVertexFormat(MeshDescriptor desc) - { - Vector3 ResizedVector = new Vector3(); - - // Check if 8 bits per coordinate. - bool is8bits = true; - foreach (PositionColoredTextured vert in desc.Vertices) - { - ResizedVector = new Vector3(((vert.X / 100.0f) * 128.0f), ((vert.Y / 100.0f) * 128.0f), ((vert.Z / 100.0f) * 128.0f)); - - if (ResizedVector.X > 255 || ResizedVector.Y > 255 || ResizedVector.Z > 255) - { - is8bits = false; - break; - } - } - if (is8bits) return Pmo.CoordinateFormat.NORMALIZED_8_BITS; - - // Check if 16 bits per coordinate. - bool is16bits = true; - foreach (PositionColoredTextured vert in desc.Vertices) - { - ResizedVector = new Vector3(((vert.X / 100.0f) * 32768.0f), ((vert.Y / 100.0f) * 32768.0f), ((vert.Z / 100.0f) * 32768.0f)); - - if (ResizedVector.X > 65535 || ResizedVector.Y > 65535 || ResizedVector.Z > 65535) - { - is16bits = false; - break; - } - } - if (is16bits) return Pmo.CoordinateFormat.NORMALIZED_16_BITS; - - return Pmo.CoordinateFormat.FLOAT_32_BITS; - } - - public static MeshGroup FromFbx(string filePath) - { - const float Scale = 1.0f; - var assimp = new Assimp.AssimpContext(); - var scene = assimp.ImportFile(filePath, Assimp.PostProcessSteps.PreTransformVertices); - var baseFilePath = Path.GetDirectoryName(filePath); - TexList = new List(); - TextureData = new List(); - - foreach(Assimp.Material mat in scene.Materials) - { - TexList.Add(Path.GetFileName(mat.TextureDiffuse.FilePath)); - Stream str = File.OpenRead(TexList[TexList.Count - 1]); - - PngImage png = new PngImage(str); - Tm2 tmImage = Tm2.Create(png); - TextureData.Add(tmImage); - } - - int childCount = scene.RootNode.ChildCount; - - return new MeshGroup() - { - MeshDescriptors = scene.Meshes - .Select(x => - { - var vertices = new PositionColoredTextured[x.Vertices.Count]; - for (var i = 0; i < vertices.Length; i++) - { - vertices[i].X = x.Vertices[i].X * Scale; - vertices[i].Y = x.Vertices[i].Y * Scale; - vertices[i].Z = x.Vertices[i].Z * Scale; - vertices[i].Tu = x.TextureCoordinateChannels[0][i].X; - vertices[i].Tv = 1.0f - x.TextureCoordinateChannels[0][i].Y; - vertices[i].R = 1.0f; - vertices[i].G = 1.0f; - vertices[i].B = 1.0f; - vertices[i].A = 1.0f; - } - - return new MeshDescriptor - { - Vertices = vertices, - Indices = x.GetIndices(), - IsOpaque = true, - TextureIndex = x.MaterialIndex - }; - }).ToList() - }; - } - } -} +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Parsers; +using OpenKh.Imaging; + +using McMaster.Extensions.CommandLineUtils; +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using System.ComponentModel.DataAnnotations; +using OpenKh.Bbs; +using System.Collections.Generic; +using System.Numerics; +using OpenKh.Common.Utils; + +namespace OpenKh.Command.PmoConverter +{ + [Command("OpenKh.Command.PmoConverter")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + class Program + { + static void Main(string[] args) + { + try + { + CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + } + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + [Required] + [Argument(0, "Convert File", "The file to convert to PMO.")] + public string FileName { get; } + + [Required] + [Argument(1, "Converted File", "The resulting converted PMO.")] + public string outFileName { get; } + + public static List TexList { get; set; } + public static List TextureData { get; set; } + + private void OnExecute() + { + try + { + Convert(FileName, outFileName); + } + catch (Exception ex) + { + Console.WriteLine($"ERROR: {ex.Message}"); + } + } + + private static void Convert(string fileIn, string fileOut) + { + MeshGroup p = FromFbx(fileIn); + Pmo pmo = MeshGroup2PMO(p); + using Stream stream = File.Create(fileOut); + Pmo.Write(stream, pmo); + stream.Close(); + } + + private static Pmo MeshGroup2PMO(MeshGroup meshGroup) + { + Pmo pmo = new Pmo(); + + List Descriptors = meshGroup.MeshDescriptors; + + // Max 65K vertices. + uint descriptorVertexCount = 0; + uint indicesVertexCount = 0; + foreach (MeshDescriptor d in Descriptors) + { + descriptorVertexCount += (uint)d.Vertices.Length; + indicesVertexCount += (uint)d.Indices.Length; + } + + // Mesh data. + for (int i = 0; i < Descriptors.Count; i++) + { + MeshDescriptor desc = Descriptors[i]; + int[] vertIndices = desc.Indices; + Pmo.MeshChunks chunk = new Pmo.MeshChunks(); + + // Obtain info for PMO Vertex Flag. + bool UsesUniformColor = UsesUniformDiffuseFlag(desc); + Pmo.CoordinateFormat TextureCoordinateFormat = GetTextureCoordinateFormat(desc); + Pmo.CoordinateFormat VertexFormat = GetVertexFormat(desc); + + chunk.SectionInfo = new Pmo.MeshSection(); + chunk.SectionInfo.Attribute = 0; + chunk.SectionInfo.VertexCount = (ushort)desc.Vertices.Length; + chunk.SectionInfo.TextureID = (byte)desc.TextureIndex; + chunk.SectionInfo.VertexFlags = 0x30000000; // 0011 000 0 0 00 000 0 000 0 00 00 11 00 000 01 + + // Set extra flags. + if (UsesUniformColor) + { + var UniformColor = (uint)(Math.Min(byte.MaxValue, desc.Vertices[0].A * 256f)); + UniformColor += (uint)(Math.Min(byte.MaxValue, desc.Vertices[0].B * 256f)) << 8; + UniformColor += (uint)(Math.Min(byte.MaxValue, desc.Vertices[0].G * 256f)) << 16; + UniformColor += (uint)(Math.Min(byte.MaxValue, desc.Vertices[0].R * 256f)) << 24; + chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBit(chunk.SectionInfo.VertexFlags, 24, true); + chunk.SectionInfo_opt2 = new Pmo.MeshSectionOptional2(); + chunk.SectionInfo_opt2.DiffuseColor = UniformColor; + } + else + chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 2, 3, (uint)0x7); + chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 0, 2, (uint)TextureCoordinateFormat); + chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 7, 2, (uint)VertexFormat); + + chunk.SectionInfo.VertexSize += 0; // Weights. + chunk.SectionInfo.VertexSize += (TextureCoordinateFormat == Pmo.CoordinateFormat.FLOAT_32_BITS) ? (byte)8 : (byte)((int)TextureCoordinateFormat * 2); // Texture Coordinates + if (chunk.SectionInfo.VertexSize % 4 != 0) + chunk.SectionInfo.VertexSize += 2; + chunk.SectionInfo.VertexSize += UsesUniformColor ? (byte)0 : (byte)4; // VertexColor + chunk.SectionInfo.VertexSize += (VertexFormat == Pmo.CoordinateFormat.FLOAT_32_BITS) ? (byte)12 : (byte)((int)VertexFormat * 3); // Vertices + + + for (int v = 0; v < desc.Indices.Length; v++) + { + int index = vertIndices[v]; + + Vector4 Color = new Vector4(); + Color.X = desc.Vertices[index].R * 2; + Color.Y = desc.Vertices[index].G * 2; + Color.Z = desc.Vertices[index].B * 2; + Color.W = desc.Vertices[index].A * 2; + chunk.colors.Add(Color); + + Vector3 vec; + vec.X = desc.Vertices[index].X / 10000.0f; + vec.Y = desc.Vertices[index].Y / 10000.0f; + vec.Z = desc.Vertices[index].Z / 10000.0f; + chunk.vertices.Add(vec); + + Vector2 Coords; + Coords.X = desc.Vertices[index].Tu; + Coords.Y = desc.Vertices[index].Tv; + chunk.textureCoordinates.Add(Coords); + } + + pmo.Meshes.Add(chunk); + } + + // Header. + pmo.header = new Pmo.Header(); + pmo.header.MagicCode = 0x4F4D50; + pmo.header.TextureCount = (ushort)TextureData.Count; // TODO. + pmo.header.Unk0A = 0x80; + pmo.header.MeshOffset0 = 0xA0 + ((uint)pmo.header.TextureCount * 0x20); + pmo.header.VertexCount = (ushort)indicesVertexCount; + pmo.header.TriangleCount = (ushort)indicesVertexCount; + pmo.header.TriangleCount /= 3; + pmo.header.ModelScale = 1.0f; + pmo.header.BoundingBox = new float[32]; + + // Texture block. + if (TextureData.Count > 0) + { + pmo.textureInfo = new Pmo.TextureInfo[TextureData.Count]; + + for (int t = 0; t < TextureData.Count; t++) + { + Tm2 tm = TextureData[t]; + pmo.textureInfo[t] = new Pmo.TextureInfo(); + pmo.textureInfo[t].TextureName = TexList[t]; + pmo.textureInfo[t].Unknown = new UInt32[4]; + pmo.texturesData.Add(TextureData[t]); + } + } + + return pmo; + } + + public static bool UsesUniformDiffuseFlag(MeshDescriptor desc) + { + bool bDiffuseFlag = true; + Vector4 InitialColor = new Vector4(desc.Vertices[0].R, desc.Vertices[0].G, desc.Vertices[0].B, desc.Vertices[0].A); + Vector4 CompareColor = new Vector4(); + + foreach (PositionColoredTextured vert in desc.Vertices) + { + CompareColor = new Vector4(vert.R, vert.G, vert.B, vert.A); + + if (CompareColor != InitialColor) + return false; + } + + return bDiffuseFlag; + } + + public static Pmo.CoordinateFormat GetTextureCoordinateFormat(MeshDescriptor desc) + { + Vector2 ResizedVector = new Vector2(); + + // Check if 0 bits per coordinate. + bool is0bits = true; + foreach (PositionColoredTextured vert in desc.Vertices) + { + ResizedVector = new Vector2(vert.Tu, vert.Tv); + + if (ResizedVector.X != 0 || ResizedVector.Y != 0) + { + is0bits = false; + break; + } + } + if (is0bits) + return Pmo.CoordinateFormat.NO_VERTEX; + + // Check if 8 bits per coordinate. + bool is8bits = true; + foreach (PositionColoredTextured vert in desc.Vertices) + { + ResizedVector = new Vector2(vert.Tu * 128.0f, vert.Tv * 128.0f); + + if (ResizedVector.X > 255 || ResizedVector.Y > 255) + { + is8bits = false; + break; + } + } + if (is8bits) + return Pmo.CoordinateFormat.NORMALIZED_8_BITS; + + // Check if 16 bits per coordinate. + bool is16bits = true; + foreach (PositionColoredTextured vert in desc.Vertices) + { + ResizedVector = new Vector2(vert.Tu * 32768.0f, vert.Tv * 32768.0f); + + if (ResizedVector.X > 65535 || ResizedVector.Y > 65535) + { + is16bits = false; + break; + } + } + if (is16bits) + return Pmo.CoordinateFormat.NORMALIZED_16_BITS; + + return Pmo.CoordinateFormat.FLOAT_32_BITS; + } + + public static Pmo.CoordinateFormat GetVertexFormat(MeshDescriptor desc) + { + Vector3 ResizedVector = new Vector3(); + + // Check if 8 bits per coordinate. + bool is8bits = true; + foreach (PositionColoredTextured vert in desc.Vertices) + { + ResizedVector = new Vector3(((vert.X / 100.0f) * 128.0f), ((vert.Y / 100.0f) * 128.0f), ((vert.Z / 100.0f) * 128.0f)); + + if (ResizedVector.X > 255 || ResizedVector.Y > 255 || ResizedVector.Z > 255) + { + is8bits = false; + break; + } + } + if (is8bits) + return Pmo.CoordinateFormat.NORMALIZED_8_BITS; + + // Check if 16 bits per coordinate. + bool is16bits = true; + foreach (PositionColoredTextured vert in desc.Vertices) + { + ResizedVector = new Vector3(((vert.X / 100.0f) * 32768.0f), ((vert.Y / 100.0f) * 32768.0f), ((vert.Z / 100.0f) * 32768.0f)); + + if (ResizedVector.X > 65535 || ResizedVector.Y > 65535 || ResizedVector.Z > 65535) + { + is16bits = false; + break; + } + } + if (is16bits) + return Pmo.CoordinateFormat.NORMALIZED_16_BITS; + + return Pmo.CoordinateFormat.FLOAT_32_BITS; + } + + public static MeshGroup FromFbx(string filePath) + { + const float Scale = 1.0f; + var assimp = new Assimp.AssimpContext(); + var scene = assimp.ImportFile(filePath, Assimp.PostProcessSteps.PreTransformVertices); + var baseFilePath = Path.GetDirectoryName(filePath); + TexList = new List(); + TextureData = new List(); + + foreach (Assimp.Material mat in scene.Materials) + { + TexList.Add(Path.GetFileName(mat.TextureDiffuse.FilePath)); + Stream str = File.OpenRead(TexList[TexList.Count - 1]); + + PngImage png = new PngImage(str); + Tm2 tmImage = Tm2.Create(png); + TextureData.Add(tmImage); + } + + int childCount = scene.RootNode.ChildCount; + + return new MeshGroup() + { + MeshDescriptors = scene.Meshes + .Select(x => + { + var vertices = new PositionColoredTextured[x.Vertices.Count]; + for (var i = 0; i < vertices.Length; i++) + { + vertices[i].X = x.Vertices[i].X * Scale; + vertices[i].Y = x.Vertices[i].Y * Scale; + vertices[i].Z = x.Vertices[i].Z * Scale; + vertices[i].Tu = x.TextureCoordinateChannels[0][i].X; + vertices[i].Tv = 1.0f - x.TextureCoordinateChannels[0][i].Y; + vertices[i].R = 1.0f; + vertices[i].G = 1.0f; + vertices[i].B = 1.0f; + vertices[i].A = 1.0f; + } + + return new MeshDescriptor + { + Vertices = vertices, + Indices = x.GetIndices(), + IsOpaque = true, + TextureIndex = x.MaterialIndex + }; + }).ToList() + }; + } + } +} diff --git a/OpenKh.Command.PmpConverter/Program.cs b/OpenKh.Command.PmpConverter/Program.cs index d0bf952cf..fcd5d0472 100644 --- a/OpenKh.Command.PmpConverter/Program.cs +++ b/OpenKh.Command.PmpConverter/Program.cs @@ -1,373 +1,373 @@ -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Parsers; -using OpenKh.Imaging; - -using System; -using McMaster.Extensions.CommandLineUtils; -using System.IO; -using System.Reflection; -using System.ComponentModel.DataAnnotations; -using OpenKh.Bbs; -using System.Collections.Generic; -using System.Numerics; -using OpenKh.Common.Utils; -using Assimp; - -namespace OpenKh.Command.PmpConverter -{ - [Command("OpenKh.Command.PmpConverter")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - class Program - { - static void Main(string[] args) - { - try - { - CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - } - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - [Required] - [Argument(0, "Convert File", "The file to convert to PMP.")] - public string FileName { get; } - - [Required] - [Argument(1, "Converted File", "The resulting converted PMP.")] - public string outFileName { get; } - - public static List TexList { get; set; } - public static List TextureData { get; set; } - - private void OnExecute() - { - try - { - Convert(FileName, outFileName); - } - catch (Exception ex) - { - Console.WriteLine($"ERROR: {ex.Message}"); - } - } - - private static void Convert(string fileIn, string fileOut) - { - List p = FromFbx(fileIn); - Pmp pmp = MeshGroupList2PMP(p); - using Stream stream = File.Create(fileOut); - Pmp.Write(stream, pmp); - stream.Close(); - } - - private static Pmp MeshGroupList2PMP(List meshGroup) - { - Pmp pmp = new Pmp(); - pmp.header.Padding = new int[2]; - pmp.PmoList = new List(); - pmp.objectInfo = new List(); - pmp.TextureList = new List(); - pmp.TextureDataList = new List(); - - Pmo pmo = new Pmo(); - - foreach (MeshGroup group in meshGroup) - { - List Descriptors = group.MeshDescriptors; - List textureIndices = new List(); - - // Max 65K vertices. - ushort descriptorVertexCount = 0; - foreach (MeshDescriptor d in Descriptors) - { - descriptorVertexCount += (ushort)d.Vertices.Length; - textureIndices.Add(d.TextureIndex); - } - - // Mesh data. - for (int i = 0; i < Descriptors.Count; i++) - { - MeshDescriptor desc = Descriptors[i]; - Pmo.MeshChunks chunk = new Pmo.MeshChunks(); - - // Obtain info for PMO Vertex Flag. - bool UsesUniformColor = UsesUniformDiffuseFlag(desc); - Pmo.CoordinateFormat TextureCoordinateFormat = GetTextureCoordinateFormat(desc); - Pmo.CoordinateFormat VertexFormat = GetVertexFormat(desc); - - chunk.SectionInfo = new Pmo.MeshSection(); - chunk.SectionInfo.Attribute = 0; - chunk.SectionInfo.VertexCount = (ushort)desc.Vertices.Length; - chunk.SectionInfo.TextureID = (byte)desc.TextureIndex; - chunk.SectionInfo.VertexFlags = 0x30000000; // 0011 000 0 0 00 000 0 000 0 00 00 11 00 000 01 - - // Set extra flags. - if (UsesUniformColor) - { - var UniformColor = (uint)(desc.Vertices[0].A / 255f); - UniformColor += (uint)(desc.Vertices[0].B / 255f) << 8; - UniformColor += (uint)(desc.Vertices[0].G / 255f) << 16; - UniformColor += (uint)(desc.Vertices[0].R / 255f) << 24; - chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBit(chunk.SectionInfo.VertexFlags, 24, true); - chunk.SectionInfo_opt2 = new Pmo.MeshSectionOptional2(); - chunk.SectionInfo_opt2.DiffuseColor = UniformColor; - } - else - chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 2, 3, (uint)0x7); - chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 0, 2, (uint)TextureCoordinateFormat); - chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 7, 2, (uint)VertexFormat); - - chunk.SectionInfo.VertexSize += 0; // Weights. - chunk.SectionInfo.VertexSize += (TextureCoordinateFormat == Pmo.CoordinateFormat.FLOAT_32_BITS) ? (byte)8 : (byte)((int)TextureCoordinateFormat * 2); // Texture Coordinates - if (chunk.SectionInfo.VertexSize % 4 != 0) - chunk.SectionInfo.VertexSize += 2; - chunk.SectionInfo.VertexSize += UsesUniformColor ? (byte)0 : (byte)4; // VertexColor - chunk.SectionInfo.VertexSize += (VertexFormat == Pmo.CoordinateFormat.FLOAT_32_BITS) ? (byte)12 : (byte)((int)VertexFormat * 3); // Vertices - - - for (int v = 0; v < desc.Vertices.Length; v++) - { - Vector4 Color = new Vector4(); - Color.X = desc.Vertices[v].R; - Color.Y = desc.Vertices[v].G; - Color.Z = desc.Vertices[v].B; - Color.W = desc.Vertices[v].A; - chunk.colors.Add(Color); - - Vector3 vec; - vec.X = desc.Vertices[v].X / 10000.0f; - vec.Y = desc.Vertices[v].Y / 10000.0f; - vec.Z = desc.Vertices[v].Z / 10000.0f; - chunk.vertices.Add(vec); - - Vector2 Coords; - Coords.X = desc.Vertices[v].Tu; - Coords.Y = desc.Vertices[v].Tv; - chunk.textureCoordinates.Add(Coords); - } - - pmo.Meshes.Add(chunk); - } - - // Header. - pmo.header = new Pmo.Header(); - pmo.header.MagicCode = 0x4F4D50; - pmo.header.TextureCount = (ushort)TextureData.Count; // TODO. - pmo.header.Unk0A = 0x80; - pmo.header.MeshOffset0 = 0xA0 + ((uint)pmo.header.TextureCount * 0x20); - pmo.header.VertexCount = descriptorVertexCount; - pmo.header.TriangleCount = pmo.header.VertexCount; - pmo.header.TriangleCount /= 3; - pmo.header.ModelScale = 1.0f; - pmo.header.BoundingBox = new float[32]; - - // Texture block. - if (textureIndices.Count > 0) - { - pmo.textureInfo = new Pmo.TextureInfo[textureIndices.Count]; - - for (int t = 0; t < textureIndices.Count; t++) - { - Tm2 tm = TextureData[textureIndices[t]]; - pmo.textureInfo[t] = new Pmo.TextureInfo(); - pmo.textureInfo[t].TextureName = TexList[textureIndices[t]]; - pmo.textureInfo[t].Unknown = new UInt32[4]; - pmo.texturesData.Add(tm); - - Pmp.PMPTextureInfo pmpInfo = new Pmp.PMPTextureInfo(); - pmpInfo.TextureName = pmo.textureInfo[t].TextureName; - pmpInfo.Unknown = new uint[4]; - pmp.TextureList.Add(pmpInfo); - } - } - - Pmp.ObjectInfo info = new Pmp.ObjectInfo(); - info.PMO_Offset = 0x20 + (0x30 * (uint)meshGroup.Count) + 0; - - pmp.PmoList.Add(pmo); - pmp.objectInfo.Add(info); - } - - pmp.TextureDataList = TextureData; - - return pmp; - } - - public static bool UsesUniformDiffuseFlag(MeshDescriptor desc) - { - bool bDiffuseFlag = true; - Vector4 InitialColor = new Vector4(desc.Vertices[0].R, desc.Vertices[0].G, desc.Vertices[0].B, desc.Vertices[0].A); - Vector4 CompareColor = new Vector4(); - - foreach (PositionColoredTextured vert in desc.Vertices) - { - CompareColor = new Vector4(vert.R, vert.G, vert.B, vert.A); - - if (CompareColor != InitialColor) - return false; - } - - return bDiffuseFlag; - } - - public static Pmo.CoordinateFormat GetTextureCoordinateFormat(MeshDescriptor desc) - { - Vector2 ResizedVector = new Vector2(); - - // Check if 0 bits per coordinate. - bool is0bits = true; - foreach (PositionColoredTextured vert in desc.Vertices) - { - ResizedVector = new Vector2(vert.Tu, vert.Tv); - - if (ResizedVector.X != 0 || ResizedVector.Y != 0) - { - is0bits = false; - break; - } - } - if (is0bits) - return Pmo.CoordinateFormat.NO_VERTEX; - - // Check if 8 bits per coordinate. - bool is8bits = true; - foreach (PositionColoredTextured vert in desc.Vertices) - { - ResizedVector = new Vector2(vert.Tu * 128.0f, vert.Tv * 128.0f); - - if (ResizedVector.X > 255 || ResizedVector.Y > 255) - { - is8bits = false; - break; - } - } - if (is8bits) - return Pmo.CoordinateFormat.NORMALIZED_8_BITS; - - // Check if 16 bits per coordinate. - bool is16bits = true; - foreach (PositionColoredTextured vert in desc.Vertices) - { - ResizedVector = new Vector2(vert.Tu * 32767.0f, vert.Tv * 32767.0f); - - if (ResizedVector.X > 65535 || ResizedVector.Y > 65535) - { - is16bits = false; - break; - } - } - if (is16bits) - return Pmo.CoordinateFormat.NORMALIZED_16_BITS; - - return Pmo.CoordinateFormat.FLOAT_32_BITS; - } - - public static Pmo.CoordinateFormat GetVertexFormat(MeshDescriptor desc) - { - Vector3 ResizedVector = new Vector3(); - - // Check if 8 bits per coordinate. - bool is8bits = true; - foreach (PositionColoredTextured vert in desc.Vertices) - { - ResizedVector = new Vector3(((vert.X / 100.0f) * 128.0f), ((vert.Y / 100.0f) * 128.0f), ((vert.Z / 100.0f) * 128.0f)); - - if (ResizedVector.X > 255 || ResizedVector.Y > 255 || ResizedVector.Z > 255) - { - is8bits = false; - break; - } - } - if (is8bits) - return Pmo.CoordinateFormat.NORMALIZED_8_BITS; - - // Check if 16 bits per coordinate. - bool is16bits = true; - foreach (PositionColoredTextured vert in desc.Vertices) - { - ResizedVector = new Vector3(((vert.X / 100.0f) * 32767.0f), ((vert.Y / 100.0f) * 32767.0f), ((vert.Z / 100.0f) * 32767.0f)); - - if (ResizedVector.X > 65535 || ResizedVector.Y > 65535 || ResizedVector.Z > 65535) - { - is16bits = false; - break; - } - } - if (is16bits) - return Pmo.CoordinateFormat.NORMALIZED_16_BITS; - - return Pmo.CoordinateFormat.FLOAT_32_BITS; - } - - public static List FromFbx(string filePath) - { - List group = new List(); - - const float Scale = 1.0f; - var assimp = new Assimp.AssimpContext(); - var scene = assimp.ImportFile(filePath, Assimp.PostProcessSteps.PreTransformVertices); - var baseFilePath = Path.GetDirectoryName(filePath); - TexList = new List(); - TextureData = new List(); - - foreach (Assimp.Material mat in scene.Materials) - { - TexList.Add(Path.GetFileName(mat.TextureDiffuse.FilePath)); - Stream str = File.OpenRead(TexList[TexList.Count - 1]); - - PngImage png = new PngImage(str); - Tm2 tmImage = Tm2.Create(png); - TextureData.Add(tmImage); - } - - for(int i = 0; i < scene.RootNode.ChildCount; i++) - { - Node child = scene.RootNode.Children[i]; - MeshGroup currentMeshGroup = new MeshGroup(); - currentMeshGroup.MeshDescriptors = new List(); - - // Get meshes by ID. - foreach(int j in child.MeshIndices) - { - MeshDescriptor meshDescriptor = new MeshDescriptor(); - Mesh x = scene.Meshes[j]; - - var vertices = new PositionColoredTextured[x.Vertices.Count]; - for (var k = 0; k < vertices.Length; k++) - { - vertices[k].X = x.Vertices[k].X * Scale; - vertices[k].Y = x.Vertices[k].Y * Scale; - vertices[k].Z = x.Vertices[k].Z * Scale; - vertices[k].Tu = x.TextureCoordinateChannels[0][k].X; - vertices[k].Tv = 1.0f - x.TextureCoordinateChannels[0][k].Y; - vertices[k].R = 0xFF; - vertices[k].G = 0xFF; - vertices[k].B = 0xFF; - vertices[k].A = 0xFF; - } - - meshDescriptor.Vertices = vertices; - meshDescriptor.Indices = x.GetIndices(); - meshDescriptor.IsOpaque = false; - meshDescriptor.TextureIndex = x.MaterialIndex; - - currentMeshGroup.MeshDescriptors.Add(meshDescriptor); - } - - group.Add(currentMeshGroup); - } - - return group; - } - } -} +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Parsers; +using OpenKh.Imaging; + +using System; +using McMaster.Extensions.CommandLineUtils; +using System.IO; +using System.Reflection; +using System.ComponentModel.DataAnnotations; +using OpenKh.Bbs; +using System.Collections.Generic; +using System.Numerics; +using OpenKh.Common.Utils; +using Assimp; + +namespace OpenKh.Command.PmpConverter +{ + [Command("OpenKh.Command.PmpConverter")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + class Program + { + static void Main(string[] args) + { + try + { + CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + } + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + [Required] + [Argument(0, "Convert File", "The file to convert to PMP.")] + public string FileName { get; } + + [Required] + [Argument(1, "Converted File", "The resulting converted PMP.")] + public string outFileName { get; } + + public static List TexList { get; set; } + public static List TextureData { get; set; } + + private void OnExecute() + { + try + { + Convert(FileName, outFileName); + } + catch (Exception ex) + { + Console.WriteLine($"ERROR: {ex.Message}"); + } + } + + private static void Convert(string fileIn, string fileOut) + { + List p = FromFbx(fileIn); + Pmp pmp = MeshGroupList2PMP(p); + using Stream stream = File.Create(fileOut); + Pmp.Write(stream, pmp); + stream.Close(); + } + + private static Pmp MeshGroupList2PMP(List meshGroup) + { + Pmp pmp = new Pmp(); + pmp.header.Padding = new int[2]; + pmp.PmoList = new List(); + pmp.objectInfo = new List(); + pmp.TextureList = new List(); + pmp.TextureDataList = new List(); + + Pmo pmo = new Pmo(); + + foreach (MeshGroup group in meshGroup) + { + List Descriptors = group.MeshDescriptors; + List textureIndices = new List(); + + // Max 65K vertices. + ushort descriptorVertexCount = 0; + foreach (MeshDescriptor d in Descriptors) + { + descriptorVertexCount += (ushort)d.Vertices.Length; + textureIndices.Add(d.TextureIndex); + } + + // Mesh data. + for (int i = 0; i < Descriptors.Count; i++) + { + MeshDescriptor desc = Descriptors[i]; + Pmo.MeshChunks chunk = new Pmo.MeshChunks(); + + // Obtain info for PMO Vertex Flag. + bool UsesUniformColor = UsesUniformDiffuseFlag(desc); + Pmo.CoordinateFormat TextureCoordinateFormat = GetTextureCoordinateFormat(desc); + Pmo.CoordinateFormat VertexFormat = GetVertexFormat(desc); + + chunk.SectionInfo = new Pmo.MeshSection(); + chunk.SectionInfo.Attribute = 0; + chunk.SectionInfo.VertexCount = (ushort)desc.Vertices.Length; + chunk.SectionInfo.TextureID = (byte)desc.TextureIndex; + chunk.SectionInfo.VertexFlags = 0x30000000; // 0011 000 0 0 00 000 0 000 0 00 00 11 00 000 01 + + // Set extra flags. + if (UsesUniformColor) + { + var UniformColor = (uint)(desc.Vertices[0].A / 255f); + UniformColor += (uint)(desc.Vertices[0].B / 255f) << 8; + UniformColor += (uint)(desc.Vertices[0].G / 255f) << 16; + UniformColor += (uint)(desc.Vertices[0].R / 255f) << 24; + chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBit(chunk.SectionInfo.VertexFlags, 24, true); + chunk.SectionInfo_opt2 = new Pmo.MeshSectionOptional2(); + chunk.SectionInfo_opt2.DiffuseColor = UniformColor; + } + else + chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 2, 3, (uint)0x7); + chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 0, 2, (uint)TextureCoordinateFormat); + chunk.SectionInfo.VertexFlags = BitsUtil.Int.SetBits(chunk.SectionInfo.VertexFlags, 7, 2, (uint)VertexFormat); + + chunk.SectionInfo.VertexSize += 0; // Weights. + chunk.SectionInfo.VertexSize += (TextureCoordinateFormat == Pmo.CoordinateFormat.FLOAT_32_BITS) ? (byte)8 : (byte)((int)TextureCoordinateFormat * 2); // Texture Coordinates + if (chunk.SectionInfo.VertexSize % 4 != 0) + chunk.SectionInfo.VertexSize += 2; + chunk.SectionInfo.VertexSize += UsesUniformColor ? (byte)0 : (byte)4; // VertexColor + chunk.SectionInfo.VertexSize += (VertexFormat == Pmo.CoordinateFormat.FLOAT_32_BITS) ? (byte)12 : (byte)((int)VertexFormat * 3); // Vertices + + + for (int v = 0; v < desc.Vertices.Length; v++) + { + Vector4 Color = new Vector4(); + Color.X = desc.Vertices[v].R; + Color.Y = desc.Vertices[v].G; + Color.Z = desc.Vertices[v].B; + Color.W = desc.Vertices[v].A; + chunk.colors.Add(Color); + + Vector3 vec; + vec.X = desc.Vertices[v].X / 10000.0f; + vec.Y = desc.Vertices[v].Y / 10000.0f; + vec.Z = desc.Vertices[v].Z / 10000.0f; + chunk.vertices.Add(vec); + + Vector2 Coords; + Coords.X = desc.Vertices[v].Tu; + Coords.Y = desc.Vertices[v].Tv; + chunk.textureCoordinates.Add(Coords); + } + + pmo.Meshes.Add(chunk); + } + + // Header. + pmo.header = new Pmo.Header(); + pmo.header.MagicCode = 0x4F4D50; + pmo.header.TextureCount = (ushort)TextureData.Count; // TODO. + pmo.header.Unk0A = 0x80; + pmo.header.MeshOffset0 = 0xA0 + ((uint)pmo.header.TextureCount * 0x20); + pmo.header.VertexCount = descriptorVertexCount; + pmo.header.TriangleCount = pmo.header.VertexCount; + pmo.header.TriangleCount /= 3; + pmo.header.ModelScale = 1.0f; + pmo.header.BoundingBox = new float[32]; + + // Texture block. + if (textureIndices.Count > 0) + { + pmo.textureInfo = new Pmo.TextureInfo[textureIndices.Count]; + + for (int t = 0; t < textureIndices.Count; t++) + { + Tm2 tm = TextureData[textureIndices[t]]; + pmo.textureInfo[t] = new Pmo.TextureInfo(); + pmo.textureInfo[t].TextureName = TexList[textureIndices[t]]; + pmo.textureInfo[t].Unknown = new UInt32[4]; + pmo.texturesData.Add(tm); + + Pmp.PMPTextureInfo pmpInfo = new Pmp.PMPTextureInfo(); + pmpInfo.TextureName = pmo.textureInfo[t].TextureName; + pmpInfo.Unknown = new uint[4]; + pmp.TextureList.Add(pmpInfo); + } + } + + Pmp.ObjectInfo info = new Pmp.ObjectInfo(); + info.PMO_Offset = 0x20 + (0x30 * (uint)meshGroup.Count) + 0; + + pmp.PmoList.Add(pmo); + pmp.objectInfo.Add(info); + } + + pmp.TextureDataList = TextureData; + + return pmp; + } + + public static bool UsesUniformDiffuseFlag(MeshDescriptor desc) + { + bool bDiffuseFlag = true; + Vector4 InitialColor = new Vector4(desc.Vertices[0].R, desc.Vertices[0].G, desc.Vertices[0].B, desc.Vertices[0].A); + Vector4 CompareColor = new Vector4(); + + foreach (PositionColoredTextured vert in desc.Vertices) + { + CompareColor = new Vector4(vert.R, vert.G, vert.B, vert.A); + + if (CompareColor != InitialColor) + return false; + } + + return bDiffuseFlag; + } + + public static Pmo.CoordinateFormat GetTextureCoordinateFormat(MeshDescriptor desc) + { + Vector2 ResizedVector = new Vector2(); + + // Check if 0 bits per coordinate. + bool is0bits = true; + foreach (PositionColoredTextured vert in desc.Vertices) + { + ResizedVector = new Vector2(vert.Tu, vert.Tv); + + if (ResizedVector.X != 0 || ResizedVector.Y != 0) + { + is0bits = false; + break; + } + } + if (is0bits) + return Pmo.CoordinateFormat.NO_VERTEX; + + // Check if 8 bits per coordinate. + bool is8bits = true; + foreach (PositionColoredTextured vert in desc.Vertices) + { + ResizedVector = new Vector2(vert.Tu * 128.0f, vert.Tv * 128.0f); + + if (ResizedVector.X > 255 || ResizedVector.Y > 255) + { + is8bits = false; + break; + } + } + if (is8bits) + return Pmo.CoordinateFormat.NORMALIZED_8_BITS; + + // Check if 16 bits per coordinate. + bool is16bits = true; + foreach (PositionColoredTextured vert in desc.Vertices) + { + ResizedVector = new Vector2(vert.Tu * 32767.0f, vert.Tv * 32767.0f); + + if (ResizedVector.X > 65535 || ResizedVector.Y > 65535) + { + is16bits = false; + break; + } + } + if (is16bits) + return Pmo.CoordinateFormat.NORMALIZED_16_BITS; + + return Pmo.CoordinateFormat.FLOAT_32_BITS; + } + + public static Pmo.CoordinateFormat GetVertexFormat(MeshDescriptor desc) + { + Vector3 ResizedVector = new Vector3(); + + // Check if 8 bits per coordinate. + bool is8bits = true; + foreach (PositionColoredTextured vert in desc.Vertices) + { + ResizedVector = new Vector3(((vert.X / 100.0f) * 128.0f), ((vert.Y / 100.0f) * 128.0f), ((vert.Z / 100.0f) * 128.0f)); + + if (ResizedVector.X > 255 || ResizedVector.Y > 255 || ResizedVector.Z > 255) + { + is8bits = false; + break; + } + } + if (is8bits) + return Pmo.CoordinateFormat.NORMALIZED_8_BITS; + + // Check if 16 bits per coordinate. + bool is16bits = true; + foreach (PositionColoredTextured vert in desc.Vertices) + { + ResizedVector = new Vector3(((vert.X / 100.0f) * 32767.0f), ((vert.Y / 100.0f) * 32767.0f), ((vert.Z / 100.0f) * 32767.0f)); + + if (ResizedVector.X > 65535 || ResizedVector.Y > 65535 || ResizedVector.Z > 65535) + { + is16bits = false; + break; + } + } + if (is16bits) + return Pmo.CoordinateFormat.NORMALIZED_16_BITS; + + return Pmo.CoordinateFormat.FLOAT_32_BITS; + } + + public static List FromFbx(string filePath) + { + List group = new List(); + + const float Scale = 1.0f; + var assimp = new Assimp.AssimpContext(); + var scene = assimp.ImportFile(filePath, Assimp.PostProcessSteps.PreTransformVertices); + var baseFilePath = Path.GetDirectoryName(filePath); + TexList = new List(); + TextureData = new List(); + + foreach (Assimp.Material mat in scene.Materials) + { + TexList.Add(Path.GetFileName(mat.TextureDiffuse.FilePath)); + Stream str = File.OpenRead(TexList[TexList.Count - 1]); + + PngImage png = new PngImage(str); + Tm2 tmImage = Tm2.Create(png); + TextureData.Add(tmImage); + } + + for (int i = 0; i < scene.RootNode.ChildCount; i++) + { + Node child = scene.RootNode.Children[i]; + MeshGroup currentMeshGroup = new MeshGroup(); + currentMeshGroup.MeshDescriptors = new List(); + + // Get meshes by ID. + foreach (int j in child.MeshIndices) + { + MeshDescriptor meshDescriptor = new MeshDescriptor(); + Mesh x = scene.Meshes[j]; + + var vertices = new PositionColoredTextured[x.Vertices.Count]; + for (var k = 0; k < vertices.Length; k++) + { + vertices[k].X = x.Vertices[k].X * Scale; + vertices[k].Y = x.Vertices[k].Y * Scale; + vertices[k].Z = x.Vertices[k].Z * Scale; + vertices[k].Tu = x.TextureCoordinateChannels[0][k].X; + vertices[k].Tv = 1.0f - x.TextureCoordinateChannels[0][k].Y; + vertices[k].R = 0xFF; + vertices[k].G = 0xFF; + vertices[k].B = 0xFF; + vertices[k].A = 0xFF; + } + + meshDescriptor.Vertices = vertices; + meshDescriptor.Indices = x.GetIndices(); + meshDescriptor.IsOpaque = false; + meshDescriptor.TextureIndex = x.MaterialIndex; + + currentMeshGroup.MeshDescriptors.Add(meshDescriptor); + } + + group.Add(currentMeshGroup); + } + + return group; + } + } +} diff --git a/OpenKh.Command.SpawnScript/Program.cs b/OpenKh.Command.SpawnScript/Program.cs index e04e3bd21..4fd024ae7 100644 --- a/OpenKh.Command.SpawnScript/Program.cs +++ b/OpenKh.Command.SpawnScript/Program.cs @@ -1,124 +1,124 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Common; -using OpenKh.Kh2.Ard; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Reflection; - -namespace OpenKh.Command.SpawnScript -{ - [Command("OpenKh.Command.SpawnScript")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - [Subcommand( - typeof(DecompileCommand), - typeof(CompileCommand), - typeof(UnpointCommand), - typeof(RepointCommand))] - class Program - { - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file or path {e.FileName} cannot be found. The program will now exit."); - return 2; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return -1; - } - } - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - private class DecompileCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Spawnscript to decompile")] - public string InputPath { get; set; } - - [Option(CommandOptionType.SingleValue, ShortName = "o", LongName = "output", Description = "Output file as text")] - public string OutputPath { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - OutputPath ??= Path.Combine(Path.GetDirectoryName(InputPath), $"{Path.GetFileNameWithoutExtension(InputPath)}.txt"); - var spawnScript = File.OpenRead(InputPath).Using(AreaDataScript.Read); - File.WriteAllText(OutputPath, AreaDataScript.Decompile(spawnScript)); - return 0; - } - } - - private class CompileCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Spawnscript source code to compile")] - public string InputPath { get; set; } - - [Option(CommandOptionType.SingleValue, ShortName = "o", LongName = "output", Description = "Output file as spawnscript")] - public string OutputPath { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - OutputPath ??= Path.Combine(Path.GetDirectoryName(InputPath), $"{Path.GetFileNameWithoutExtension(InputPath)}.spawnscript"); - var spawnScript = AreaDataScript.Compile(File.ReadAllText(InputPath)); - File.Create(OutputPath).Using(stream => AreaDataScript.Write(stream, spawnScript)); - return 0; - } - } - - private class UnpointCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Spawnpoint file to deserialize")] - public string InputPath { get; set; } - - [Option(CommandOptionType.SingleValue, ShortName = "o", LongName = "output", Description = "Output file as YAML")] - public string OutputPath { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - OutputPath ??= Path.Combine(Path.GetDirectoryName(InputPath), $"{Path.GetFileNameWithoutExtension(InputPath)}.yml"); - var spawnPoint = File.OpenRead(InputPath).Using(Kh2.Ard.SpawnPoint.Read); - File.WriteAllText(OutputPath, Helpers.YamlSerialize(spawnPoint)); - return 0; - } - } - - private class RepointCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Spawnpoint file previously deserialized as YAML")] - public string InputPath { get; set; } - - [Option(CommandOptionType.SingleValue, ShortName = "o", LongName = "output", Description = "Output file as spawnpoint")] - public string OutputPath { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - OutputPath ??= Path.Combine(Path.GetDirectoryName(InputPath), $"{Path.GetFileNameWithoutExtension(InputPath)}.spawnpoint"); - var spawnPoint = Helpers.YamlDeserialize>(File.ReadAllText(InputPath)); - File.Create(OutputPath).Using(stream => Kh2.Ard.SpawnPoint.Write(stream, spawnPoint)); - return 0; - } - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Common; +using OpenKh.Kh2.Ard; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Reflection; + +namespace OpenKh.Command.SpawnScript +{ + [Command("OpenKh.Command.SpawnScript")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + [Subcommand( + typeof(DecompileCommand), + typeof(CompileCommand), + typeof(UnpointCommand), + typeof(RepointCommand))] + class Program + { + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file or path {e.FileName} cannot be found. The program will now exit."); + return 2; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return -1; + } + } + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + private class DecompileCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Spawnscript to decompile")] + public string InputPath { get; set; } + + [Option(CommandOptionType.SingleValue, ShortName = "o", LongName = "output", Description = "Output file as text")] + public string OutputPath { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + OutputPath ??= Path.Combine(Path.GetDirectoryName(InputPath), $"{Path.GetFileNameWithoutExtension(InputPath)}.txt"); + var spawnScript = File.OpenRead(InputPath).Using(AreaDataScript.Read); + File.WriteAllText(OutputPath, AreaDataScript.Decompile(spawnScript)); + return 0; + } + } + + private class CompileCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Spawnscript source code to compile")] + public string InputPath { get; set; } + + [Option(CommandOptionType.SingleValue, ShortName = "o", LongName = "output", Description = "Output file as spawnscript")] + public string OutputPath { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + OutputPath ??= Path.Combine(Path.GetDirectoryName(InputPath), $"{Path.GetFileNameWithoutExtension(InputPath)}.spawnscript"); + var spawnScript = AreaDataScript.Compile(File.ReadAllText(InputPath)); + File.Create(OutputPath).Using(stream => AreaDataScript.Write(stream, spawnScript)); + return 0; + } + } + + private class UnpointCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Spawnpoint file to deserialize")] + public string InputPath { get; set; } + + [Option(CommandOptionType.SingleValue, ShortName = "o", LongName = "output", Description = "Output file as YAML")] + public string OutputPath { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + OutputPath ??= Path.Combine(Path.GetDirectoryName(InputPath), $"{Path.GetFileNameWithoutExtension(InputPath)}.yml"); + var spawnPoint = File.OpenRead(InputPath).Using(Kh2.Ard.SpawnPoint.Read); + File.WriteAllText(OutputPath, Helpers.YamlSerialize(spawnPoint)); + return 0; + } + } + + private class RepointCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Spawnpoint file previously deserialized as YAML")] + public string InputPath { get; set; } + + [Option(CommandOptionType.SingleValue, ShortName = "o", LongName = "output", Description = "Output file as spawnpoint")] + public string OutputPath { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + OutputPath ??= Path.Combine(Path.GetDirectoryName(InputPath), $"{Path.GetFileNameWithoutExtension(InputPath)}.spawnpoint"); + var spawnPoint = Helpers.YamlDeserialize>(File.ReadAllText(InputPath)); + File.Create(OutputPath).Using(stream => Kh2.Ard.SpawnPoint.Write(stream, spawnPoint)); + return 0; + } + } + } +} diff --git a/OpenKh.Command.TexFooter/Interfaces/ISpriteImageSource.cs b/OpenKh.Command.TexFooter/Interfaces/ISpriteImageSource.cs index 040b2653d..ce4af869a 100644 --- a/OpenKh.Command.TexFooter/Interfaces/ISpriteImageSource.cs +++ b/OpenKh.Command.TexFooter/Interfaces/ISpriteImageSource.cs @@ -1,26 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Text; - -namespace OpenKh.Command.TexFooter.Interfaces -{ - public interface ISpriteImageSource - { - /// - /// Only 4 or 8 - /// - int BitsPerPixel { get; } - - /// - /// Width is 32, 64, or such. - /// - Size Size { get; } - - /// - /// For 4bpp: pass swapped data. 0x12 0x34 is [2, 1, 4, 3] - /// For 8bpp: pass platform native data. 0x12 0x34 is [0x12, 0x34] - /// - byte[] Data { get; } - } -} +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Text; + +namespace OpenKh.Command.TexFooter.Interfaces +{ + public interface ISpriteImageSource + { + /// + /// Only 4 or 8 + /// + int BitsPerPixel { get; } + + /// + /// Width is 32, 64, or such. + /// + Size Size { get; } + + /// + /// For 4bpp: pass swapped data. 0x12 0x34 is [2, 1, 4, 3] + /// For 8bpp: pass platform native data. 0x12 0x34 is [0x12, 0x34] + /// + byte[] Data { get; } + } +} diff --git a/OpenKh.Command.TexFooter/Models/PerTexture.cs b/OpenKh.Command.TexFooter/Models/PerTexture.cs index db7341a77..0c1e40a04 100644 --- a/OpenKh.Command.TexFooter/Models/PerTexture.cs +++ b/OpenKh.Command.TexFooter/Models/PerTexture.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Command.TexFooter.Models -{ - public class PerTexture - { - public Dictionary Textures { get; set; } = new Dictionary(); - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Command.TexFooter.Models +{ + public class PerTexture + { + public Dictionary Textures { get; set; } = new Dictionary(); + } +} diff --git a/OpenKh.Command.TexFooter/Models/TextureAnimationIMEx.cs b/OpenKh.Command.TexFooter/Models/TextureAnimationIMEx.cs index 7390bc661..f90c36abb 100644 --- a/OpenKh.Command.TexFooter/Models/TextureAnimationIMEx.cs +++ b/OpenKh.Command.TexFooter/Models/TextureAnimationIMEx.cs @@ -1,89 +1,89 @@ -using OpenKh.Kh2.TextureFooter; -using System; -using System.Linq; -using System.Collections.Generic; -using System.Text; -using YamlDotNet.Core; -using YamlDotNet.Serialization; -using OpenKh.Imaging; -using OpenKh.Command.TexFooter.Interfaces; - -namespace OpenKh.Command.TexFooter.Models -{ - public class TextureAnimationIMEx - { - public ushort Unk1 { get; set; } - public ushort TextureIndex { get; set; } - public ushort FrameStride { get; set; } - public ushort BaseSlotIndex { get; set; } - - public string SpriteImageFile { get; set; } - public ushort NumSpritesInImageData { get; set; } - public ushort UOffsetInBaseImage { get; set; } - public ushort VOffsetInBaseImage { get; set; } - - public int DefaultAnimationIndex { get; set; } - - public short[] SlotTable { get; set; } - public TextureFrameGroup[] FrameGroupList { get; set; } - - internal TextureAnimation _source; - - public TextureAnimationIMEx() - { - - } - - public TextureAnimationIMEx(TextureAnimation src) - { - _source = src; - - Unk1 = src.Unk1; - TextureIndex = src.TextureIndex; - FrameStride = src.FrameStride; - BaseSlotIndex = src.BaseSlotIndex; - NumSpritesInImageData = src.NumSpritesInImageData; - UOffsetInBaseImage = src.UOffsetInBaseImage; - VOffsetInBaseImage = src.VOffsetInBaseImage; - DefaultAnimationIndex = src.DefaultAnimationIndex; - SlotTable = src.SlotTable; - FrameGroupList = src.FrameGroupList; - } - - public TextureAnimation ConvertBack(Func imageLoader) - { - var spriteImage = imageLoader(SpriteImageFile); - var bitsPerPixel = spriteImage.BitsPerPixel; - - var back = new TextureAnimation - { - Unk1 = Unk1, - TextureIndex = TextureIndex, - FrameStride = FrameStride, - BitsPerPixel = Convert.ToUInt16(bitsPerPixel), - BaseSlotIndex = BaseSlotIndex, - MaximumSlotIndex = Convert.ToUInt16(BaseSlotIndex + SlotTable.Length - 1), - - NumAnimations = Convert.ToUInt16(FrameGroupList.Length), - NumSpritesInImageData = NumSpritesInImageData, - UOffsetInBaseImage = UOffsetInBaseImage, - VOffsetInBaseImage = VOffsetInBaseImage, - SpriteWidth = Convert.ToUInt16(spriteImage.Size.Width), - SpriteHeight = Convert.ToUInt16(spriteImage.Size.Height / NumSpritesInImageData), - - OffsetSlotTable = 0, - - OffsetAnimationTable = 0, - - OffsetSpriteImage = 0, - DefaultAnimationIndex = DefaultAnimationIndex, - - SlotTable = SlotTable, - FrameGroupList = FrameGroupList, - SpriteImage = spriteImage.Data, - }; - - return back; - } - } -} +using OpenKh.Kh2.TextureFooter; +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text; +using YamlDotNet.Core; +using YamlDotNet.Serialization; +using OpenKh.Imaging; +using OpenKh.Command.TexFooter.Interfaces; + +namespace OpenKh.Command.TexFooter.Models +{ + public class TextureAnimationIMEx + { + public ushort Unk1 { get; set; } + public ushort TextureIndex { get; set; } + public ushort FrameStride { get; set; } + public ushort BaseSlotIndex { get; set; } + + public string SpriteImageFile { get; set; } + public ushort NumSpritesInImageData { get; set; } + public ushort UOffsetInBaseImage { get; set; } + public ushort VOffsetInBaseImage { get; set; } + + public int DefaultAnimationIndex { get; set; } + + public short[] SlotTable { get; set; } + public TextureFrameGroup[] FrameGroupList { get; set; } + + internal TextureAnimation _source; + + public TextureAnimationIMEx() + { + + } + + public TextureAnimationIMEx(TextureAnimation src) + { + _source = src; + + Unk1 = src.Unk1; + TextureIndex = src.TextureIndex; + FrameStride = src.FrameStride; + BaseSlotIndex = src.BaseSlotIndex; + NumSpritesInImageData = src.NumSpritesInImageData; + UOffsetInBaseImage = src.UOffsetInBaseImage; + VOffsetInBaseImage = src.VOffsetInBaseImage; + DefaultAnimationIndex = src.DefaultAnimationIndex; + SlotTable = src.SlotTable; + FrameGroupList = src.FrameGroupList; + } + + public TextureAnimation ConvertBack(Func imageLoader) + { + var spriteImage = imageLoader(SpriteImageFile); + var bitsPerPixel = spriteImage.BitsPerPixel; + + var back = new TextureAnimation + { + Unk1 = Unk1, + TextureIndex = TextureIndex, + FrameStride = FrameStride, + BitsPerPixel = Convert.ToUInt16(bitsPerPixel), + BaseSlotIndex = BaseSlotIndex, + MaximumSlotIndex = Convert.ToUInt16(BaseSlotIndex + SlotTable.Length - 1), + + NumAnimations = Convert.ToUInt16(FrameGroupList.Length), + NumSpritesInImageData = NumSpritesInImageData, + UOffsetInBaseImage = UOffsetInBaseImage, + VOffsetInBaseImage = VOffsetInBaseImage, + SpriteWidth = Convert.ToUInt16(spriteImage.Size.Width), + SpriteHeight = Convert.ToUInt16(spriteImage.Size.Height / NumSpritesInImageData), + + OffsetSlotTable = 0, + + OffsetAnimationTable = 0, + + OffsetSpriteImage = 0, + DefaultAnimationIndex = DefaultAnimationIndex, + + SlotTable = SlotTable, + FrameGroupList = FrameGroupList, + SpriteImage = spriteImage.Data, + }; + + return back; + } + } +} diff --git a/OpenKh.Command.TexFooter/Models/TextureFooterDataIMEx.cs b/OpenKh.Command.TexFooter/Models/TextureFooterDataIMEx.cs index 6f7165212..115af6d2c 100644 --- a/OpenKh.Command.TexFooter/Models/TextureFooterDataIMEx.cs +++ b/OpenKh.Command.TexFooter/Models/TextureFooterDataIMEx.cs @@ -1,48 +1,48 @@ -using OpenKh.Command.TexFooter.Interfaces; -using OpenKh.Imaging; -using OpenKh.Kh2.TextureFooter; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace OpenKh.Command.TexFooter.Models -{ - public class TextureFooterDataIMEx - { - public List UvscList { get; set; } - public List TextureAnimationList { get; set; } - public byte[] UnkFooter { get; set; } - public bool ShouldEmitDMYAtFirst { get; set; } - public bool ShouldEmitKN5 { get; set; } - - public TextureFooterDataIMEx() - { - - } - - public TextureFooterDataIMEx(TextureFooterData footerData) - { - UvscList = footerData.UvscList.ToList(); - TextureAnimationList = footerData.TextureAnimationList.Select(it => new TextureAnimationIMEx(it)).ToList(); - UnkFooter = footerData.UnkFooter; - ShouldEmitDMYAtFirst = footerData.ShouldEmitDMYAtFirst; - ShouldEmitKN5 = footerData.ShouldEmitKN5; - } - - public TextureFooterData ConvertBackTo(Func imageLoader, TextureFooterData back) - { - back.UvscList.Clear(); - back.UvscList.AddRange(UvscList); - back.TextureAnimationList.Clear(); - back.TextureAnimationList.AddRange( - TextureAnimationList - .Select(texa => texa.ConvertBack(imageLoader)) - ); - back.UnkFooter = UnkFooter; - back.ShouldEmitDMYAtFirst = ShouldEmitDMYAtFirst; - back.ShouldEmitKN5 = ShouldEmitKN5; - return back; - } - } -} +using OpenKh.Command.TexFooter.Interfaces; +using OpenKh.Imaging; +using OpenKh.Kh2.TextureFooter; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenKh.Command.TexFooter.Models +{ + public class TextureFooterDataIMEx + { + public List UvscList { get; set; } + public List TextureAnimationList { get; set; } + public byte[] UnkFooter { get; set; } + public bool ShouldEmitDMYAtFirst { get; set; } + public bool ShouldEmitKN5 { get; set; } + + public TextureFooterDataIMEx() + { + + } + + public TextureFooterDataIMEx(TextureFooterData footerData) + { + UvscList = footerData.UvscList.ToList(); + TextureAnimationList = footerData.TextureAnimationList.Select(it => new TextureAnimationIMEx(it)).ToList(); + UnkFooter = footerData.UnkFooter; + ShouldEmitDMYAtFirst = footerData.ShouldEmitDMYAtFirst; + ShouldEmitKN5 = footerData.ShouldEmitKN5; + } + + public TextureFooterData ConvertBackTo(Func imageLoader, TextureFooterData back) + { + back.UvscList.Clear(); + back.UvscList.AddRange(UvscList); + back.TextureAnimationList.Clear(); + back.TextureAnimationList.AddRange( + TextureAnimationList + .Select(texa => texa.ConvertBack(imageLoader)) + ); + back.UnkFooter = UnkFooter; + back.ShouldEmitDMYAtFirst = ShouldEmitDMYAtFirst; + back.ShouldEmitKN5 = ShouldEmitKN5; + return back; + } + } +} diff --git a/OpenKh.Command.TexFooter/Program.cs b/OpenKh.Command.TexFooter/Program.cs index ef5a51cea..8c62b3fb8 100644 --- a/OpenKh.Command.TexFooter/Program.cs +++ b/OpenKh.Command.TexFooter/Program.cs @@ -1,41 +1,41 @@ -using McMaster.Extensions.CommandLineUtils; -using System; -using System.IO; -using System.Reflection; -using OpenKh.Command.TexFooter.Subcommands; - -namespace OpenKh.Command.TexFooter -{ - [Command("OpenKh.Command.TexFooter")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - [Subcommand(typeof(ExportCommand), typeof(ImportCommand), typeof(YmlToBinCommand), typeof(BinToYmlCommand))] - class Program - { - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - return 1; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return 1; - } - } - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - } -} +using McMaster.Extensions.CommandLineUtils; +using System; +using System.IO; +using System.Reflection; +using OpenKh.Command.TexFooter.Subcommands; + +namespace OpenKh.Command.TexFooter +{ + [Command("OpenKh.Command.TexFooter")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + [Subcommand(typeof(ExportCommand), typeof(ImportCommand), typeof(YmlToBinCommand), typeof(BinToYmlCommand))] + class Program + { + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + return 1; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return 1; + } + } + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + } +} diff --git a/OpenKh.Command.TexFooter/Subcommands/BinToYmlCommand.cs b/OpenKh.Command.TexFooter/Subcommands/BinToYmlCommand.cs index b3362f2ab..2946592fa 100644 --- a/OpenKh.Command.TexFooter/Subcommands/BinToYmlCommand.cs +++ b/OpenKh.Command.TexFooter/Subcommands/BinToYmlCommand.cs @@ -1,67 +1,67 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Command.TexFooter.Models; -using OpenKh.Command.TexFooter.TypeConverters; -using OpenKh.Command.TexFooter.Utils; -using OpenKh.Common; -using OpenKh.Kh2.TextureFooter; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Linq; -using System.Text; -using YamlDotNet.Serialization; - -namespace OpenKh.Command.TexFooter.Subcommands -{ - [HelpOption] - [Command(Description = "texture footer bin -> yml")] - class BinToYmlCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Bin file")] - public string BinFile { get; set; } - - [Argument(1, Description = "Output dir")] - public string OutputDir { get; set; } - - protected int OnExecute(CommandLineApplication app) => Execute(); - - public int Execute() - { - var footer = File.OpenRead(BinFile).Using(TextureFooterData.Read); - - var outDir = Path.Combine( - Path.GetDirectoryName(BinFile), - OutputDir ?? "." - ); - var baseName = Path.GetFileNameWithoutExtension(BinFile); - - Directory.CreateDirectory(outDir); - - File.WriteAllText( - Path.Combine(outDir, $"{baseName}.footer.yml"), - new SerializerBuilder() - .WithTypeConverter(new UseJsonStyleArray()) - .WithTypeConverter(new UseJsonStyleArray()) - .WithAttributeOverride(it => it.Data, new YamlIgnoreAttribute()) - .Build() - .Serialize( - ExportHelper.AlsoExportImages( - outDir, - baseName, - new PerTexture - { - Textures = { - ["MAP"] = new TextureFooterDataIMEx(footer) - }, - } - ) - ) - ); - - return 0; - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Command.TexFooter.Models; +using OpenKh.Command.TexFooter.TypeConverters; +using OpenKh.Command.TexFooter.Utils; +using OpenKh.Common; +using OpenKh.Kh2.TextureFooter; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; +using System.Text; +using YamlDotNet.Serialization; + +namespace OpenKh.Command.TexFooter.Subcommands +{ + [HelpOption] + [Command(Description = "texture footer bin -> yml")] + class BinToYmlCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Bin file")] + public string BinFile { get; set; } + + [Argument(1, Description = "Output dir")] + public string OutputDir { get; set; } + + protected int OnExecute(CommandLineApplication app) => Execute(); + + public int Execute() + { + var footer = File.OpenRead(BinFile).Using(TextureFooterData.Read); + + var outDir = Path.Combine( + Path.GetDirectoryName(BinFile), + OutputDir ?? "." + ); + var baseName = Path.GetFileNameWithoutExtension(BinFile); + + Directory.CreateDirectory(outDir); + + File.WriteAllText( + Path.Combine(outDir, $"{baseName}.footer.yml"), + new SerializerBuilder() + .WithTypeConverter(new UseJsonStyleArray()) + .WithTypeConverter(new UseJsonStyleArray()) + .WithAttributeOverride(it => it.Data, new YamlIgnoreAttribute()) + .Build() + .Serialize( + ExportHelper.AlsoExportImages( + outDir, + baseName, + new PerTexture + { + Textures = { + ["MAP"] = new TextureFooterDataIMEx(footer) + }, + } + ) + ) + ); + + return 0; + } + } +} diff --git a/OpenKh.Command.TexFooter/Subcommands/ExportCommand.cs b/OpenKh.Command.TexFooter/Subcommands/ExportCommand.cs index f99b4183b..0b4d38290 100644 --- a/OpenKh.Command.TexFooter/Subcommands/ExportCommand.cs +++ b/OpenKh.Command.TexFooter/Subcommands/ExportCommand.cs @@ -1,77 +1,77 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Command.TexFooter.Models; -using OpenKh.Command.TexFooter.TypeConverters; -using OpenKh.Command.TexFooter.Utils; -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Kh2.TextureFooter; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Drawing.Imaging; -using System.IO; -using System.Linq; -using System.Text; -using YamlDotNet.Serialization; - -namespace OpenKh.Command.TexFooter.Subcommands -{ - [HelpOption] - [Command(Description = "map file: export map or mdlx texture footer. map -> yml")] - public class ExportCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Map file")] - public string MapFile { get; set; } - - [Argument(1, Description = "Output dir")] - public string OutputDir { get; set; } - - protected int OnExecute(CommandLineApplication app) => Execute(); - - public int Execute() - { - var perTexture = new PerTexture(); - - var barEntries = File.OpenRead(MapFile).Using(Bar.Read); - foreach (var entry in barEntries - .Where(entry => entry.Type == Bar.EntryType.ModelTexture && ModelTexture.IsValid(entry.Stream)) - ) - { - entry.Stream.SetPosition(0); - - var modelTexture = ModelTexture.Read(entry.Stream); - - if (modelTexture.Images == null || !modelTexture.Images.Any()) - { - return 1; - } - - var footerData = modelTexture.TextureFooterData; - - perTexture.Textures[entry.Name] = new TextureFooterDataIMEx(footerData); - } - - var outDir = Path.Combine( - Path.GetDirectoryName(MapFile), - OutputDir ?? "." - ); - var baseName = Path.GetFileNameWithoutExtension(MapFile); - - Directory.CreateDirectory(outDir); - - File.WriteAllText( - Path.Combine(outDir, $"{baseName}.footer.yml"), - new SerializerBuilder() - .WithTypeConverter(new UseJsonStyleArray()) - .WithTypeConverter(new UseJsonStyleArray()) - .WithAttributeOverride(it => it.Data, new YamlIgnoreAttribute()) - .Build() - .Serialize(ExportHelper.AlsoExportImages(outDir, baseName, perTexture)) - ); - - return 0; - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Command.TexFooter.Models; +using OpenKh.Command.TexFooter.TypeConverters; +using OpenKh.Command.TexFooter.Utils; +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Kh2.TextureFooter; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Drawing.Imaging; +using System.IO; +using System.Linq; +using System.Text; +using YamlDotNet.Serialization; + +namespace OpenKh.Command.TexFooter.Subcommands +{ + [HelpOption] + [Command(Description = "map file: export map or mdlx texture footer. map -> yml")] + public class ExportCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Map file")] + public string MapFile { get; set; } + + [Argument(1, Description = "Output dir")] + public string OutputDir { get; set; } + + protected int OnExecute(CommandLineApplication app) => Execute(); + + public int Execute() + { + var perTexture = new PerTexture(); + + var barEntries = File.OpenRead(MapFile).Using(Bar.Read); + foreach (var entry in barEntries + .Where(entry => entry.Type == Bar.EntryType.ModelTexture && ModelTexture.IsValid(entry.Stream)) + ) + { + entry.Stream.SetPosition(0); + + var modelTexture = ModelTexture.Read(entry.Stream); + + if (modelTexture.Images == null || !modelTexture.Images.Any()) + { + return 1; + } + + var footerData = modelTexture.TextureFooterData; + + perTexture.Textures[entry.Name] = new TextureFooterDataIMEx(footerData); + } + + var outDir = Path.Combine( + Path.GetDirectoryName(MapFile), + OutputDir ?? "." + ); + var baseName = Path.GetFileNameWithoutExtension(MapFile); + + Directory.CreateDirectory(outDir); + + File.WriteAllText( + Path.Combine(outDir, $"{baseName}.footer.yml"), + new SerializerBuilder() + .WithTypeConverter(new UseJsonStyleArray()) + .WithTypeConverter(new UseJsonStyleArray()) + .WithAttributeOverride(it => it.Data, new YamlIgnoreAttribute()) + .Build() + .Serialize(ExportHelper.AlsoExportImages(outDir, baseName, perTexture)) + ); + + return 0; + } + } +} diff --git a/OpenKh.Command.TexFooter/Subcommands/ImportCommand.cs b/OpenKh.Command.TexFooter/Subcommands/ImportCommand.cs index 0b63d511b..ff7a83b42 100644 --- a/OpenKh.Command.TexFooter/Subcommands/ImportCommand.cs +++ b/OpenKh.Command.TexFooter/Subcommands/ImportCommand.cs @@ -1,88 +1,88 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Command.TexFooter.Models; -using OpenKh.Command.TexFooter.Utils; -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Kh2.TextureFooter; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Linq; -using System.Text; -using YamlDotNet.Serialization; - -namespace OpenKh.Command.TexFooter.Subcommands -{ - [HelpOption] - [Command(Description = "map file: import map or mdlx texture footer. yml -> map")] - public class ImportCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Map file (in and out)")] - public string MapFile { get; set; } - - [Argument(1, Description = "YML file (`P_EX100.footer.yml`)")] - public string YmlFile { get; set; } - - protected int OnExecute(CommandLineApplication app) => Execute(); - - public int Execute() - { - var outDir = Path.GetDirectoryName(MapFile); - var baseName = Path.GetFileNameWithoutExtension(MapFile); - - var perTexture = new DeserializerBuilder() - .IgnoreUnmatchedProperties() - .WithAttributeOverride(it => it.Data, new YamlIgnoreAttribute()) - .Build() - .Deserialize(File.ReadAllText(Path.Combine(outDir, YmlFile ?? $"{baseName}.footer.yml"))); - - var anyChanges = false; - - var barEntries = File.OpenRead(MapFile).Using(Bar.Read); - foreach (var entry in barEntries - .Where(entry => entry.Type == Bar.EntryType.ModelTexture - && ModelTexture.IsValid(entry.Stream) - && perTexture.Textures.ContainsKey(entry.Name) - ) - ) - { - var model = perTexture.Textures[entry.Name]; - - entry.Stream.SetPosition(0); - - var modelTexture = ModelTexture.Read(entry.Stream); - - model.ConvertBackTo( - pngFile => - { - return new SpriteBitmap(Path.Combine(outDir, pngFile)); - }, - modelTexture.TextureFooterData - ); - - { - var buffer = new MemoryStream(); - modelTexture.Write(buffer); - buffer.Position = 0; - - entry.Stream = buffer; - } - - anyChanges |= true; - } - - if (anyChanges) - { - var buffer = new MemoryStream(); - Bar.Write(buffer, barEntries); - - File.WriteAllBytes(MapFile, buffer.ToArray()); - } - - return 0; - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Command.TexFooter.Models; +using OpenKh.Command.TexFooter.Utils; +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Kh2.TextureFooter; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; +using System.Text; +using YamlDotNet.Serialization; + +namespace OpenKh.Command.TexFooter.Subcommands +{ + [HelpOption] + [Command(Description = "map file: import map or mdlx texture footer. yml -> map")] + public class ImportCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Map file (in and out)")] + public string MapFile { get; set; } + + [Argument(1, Description = "YML file (`P_EX100.footer.yml`)")] + public string YmlFile { get; set; } + + protected int OnExecute(CommandLineApplication app) => Execute(); + + public int Execute() + { + var outDir = Path.GetDirectoryName(MapFile); + var baseName = Path.GetFileNameWithoutExtension(MapFile); + + var perTexture = new DeserializerBuilder() + .IgnoreUnmatchedProperties() + .WithAttributeOverride(it => it.Data, new YamlIgnoreAttribute()) + .Build() + .Deserialize(File.ReadAllText(Path.Combine(outDir, YmlFile ?? $"{baseName}.footer.yml"))); + + var anyChanges = false; + + var barEntries = File.OpenRead(MapFile).Using(Bar.Read); + foreach (var entry in barEntries + .Where(entry => entry.Type == Bar.EntryType.ModelTexture + && ModelTexture.IsValid(entry.Stream) + && perTexture.Textures.ContainsKey(entry.Name) + ) + ) + { + var model = perTexture.Textures[entry.Name]; + + entry.Stream.SetPosition(0); + + var modelTexture = ModelTexture.Read(entry.Stream); + + model.ConvertBackTo( + pngFile => + { + return new SpriteBitmap(Path.Combine(outDir, pngFile)); + }, + modelTexture.TextureFooterData + ); + + { + var buffer = new MemoryStream(); + modelTexture.Write(buffer); + buffer.Position = 0; + + entry.Stream = buffer; + } + + anyChanges |= true; + } + + if (anyChanges) + { + var buffer = new MemoryStream(); + Bar.Write(buffer, barEntries); + + File.WriteAllBytes(MapFile, buffer.ToArray()); + } + + return 0; + } + } +} diff --git a/OpenKh.Command.TexFooter/Subcommands/YmlToBinCommand.cs b/OpenKh.Command.TexFooter/Subcommands/YmlToBinCommand.cs index e312519f1..654d72ec0 100644 --- a/OpenKh.Command.TexFooter/Subcommands/YmlToBinCommand.cs +++ b/OpenKh.Command.TexFooter/Subcommands/YmlToBinCommand.cs @@ -1,57 +1,57 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Command.TexFooter.Models; -using OpenKh.Command.TexFooter.Utils; -using OpenKh.Kh2.TextureFooter; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Linq; -using System.Text; -using YamlDotNet.Serialization; - -namespace OpenKh.Command.TexFooter.Subcommands -{ - [HelpOption] - [Command(Description = "yml -> texture footer bin")] - class YmlToBinCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Yml file")] - public string YmlFile { get; set; } - - [Argument(1, Description = "Bin file")] - public string BinFile { get; set; } - - protected int OnExecute(CommandLineApplication app) => Execute(); - - public int Execute() - { - var perTexture = new DeserializerBuilder() - .IgnoreUnmatchedProperties() - .WithAttributeOverride(it => it.Data, new YamlIgnoreAttribute()) - .Build() - .Deserialize(File.ReadAllText(Path.Combine(YmlFile))); - - var model = perTexture.Textures.Single(); - - var baseDir = Path.GetDirectoryName(YmlFile); - - var footer = new TextureFooterData(); - model.Value.ConvertBackTo( - pngFile => - { - return new SpriteBitmap(Path.Combine(baseDir, pngFile)); - }, - footer - ); - - var toFile = new MemoryStream(); - footer.Write(toFile); - - File.WriteAllBytes(BinFile ?? Path.ChangeExtension(YmlFile, ".bin"), toFile.ToArray()); - return 0; - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Command.TexFooter.Models; +using OpenKh.Command.TexFooter.Utils; +using OpenKh.Kh2.TextureFooter; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; +using System.Text; +using YamlDotNet.Serialization; + +namespace OpenKh.Command.TexFooter.Subcommands +{ + [HelpOption] + [Command(Description = "yml -> texture footer bin")] + class YmlToBinCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Yml file")] + public string YmlFile { get; set; } + + [Argument(1, Description = "Bin file")] + public string BinFile { get; set; } + + protected int OnExecute(CommandLineApplication app) => Execute(); + + public int Execute() + { + var perTexture = new DeserializerBuilder() + .IgnoreUnmatchedProperties() + .WithAttributeOverride(it => it.Data, new YamlIgnoreAttribute()) + .Build() + .Deserialize(File.ReadAllText(Path.Combine(YmlFile))); + + var model = perTexture.Textures.Single(); + + var baseDir = Path.GetDirectoryName(YmlFile); + + var footer = new TextureFooterData(); + model.Value.ConvertBackTo( + pngFile => + { + return new SpriteBitmap(Path.Combine(baseDir, pngFile)); + }, + footer + ); + + var toFile = new MemoryStream(); + footer.Write(toFile); + + File.WriteAllBytes(BinFile ?? Path.ChangeExtension(YmlFile, ".bin"), toFile.ToArray()); + return 0; + } + } +} diff --git a/OpenKh.Command.TexFooter/TypeConverters/UseJsonStyleArray.cs b/OpenKh.Command.TexFooter/TypeConverters/UseJsonStyleArray.cs index 65f231438..c0397b3ff 100644 --- a/OpenKh.Command.TexFooter/TypeConverters/UseJsonStyleArray.cs +++ b/OpenKh.Command.TexFooter/TypeConverters/UseJsonStyleArray.cs @@ -1,40 +1,40 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Text; -using YamlDotNet.Core; -using YamlDotNet.Core.Events; -using YamlDotNet.Serialization; - -namespace OpenKh.Command.TexFooter.TypeConverters -{ - class UseJsonStyleArray : IYamlTypeConverter - { - public bool Accepts(Type type) - { - return type.HasElementType && type.GetElementType() == typeof(T); - } - - public object ReadYaml(IParser parser, Type type) - { - throw new NotImplementedException(); - } - - public void WriteYaml(IEmitter emitter, object value, Type type) - { - if (value == null) - { - emitter.Emit(new Scalar(null, null, "null", ScalarStyle.Plain, true, false)); - } - else - { - emitter.Emit(new SequenceStart(null, null, true, SequenceStyle.Flow)); - foreach (var it in (IEnumerable)value) - { - emitter.Emit(new Scalar((it == null) ? null : (it + ""))); - } - emitter.Emit(new SequenceEnd()); - } - } - } -} +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using YamlDotNet.Core; +using YamlDotNet.Core.Events; +using YamlDotNet.Serialization; + +namespace OpenKh.Command.TexFooter.TypeConverters +{ + class UseJsonStyleArray : IYamlTypeConverter + { + public bool Accepts(Type type) + { + return type.HasElementType && type.GetElementType() == typeof(T); + } + + public object ReadYaml(IParser parser, Type type) + { + throw new NotImplementedException(); + } + + public void WriteYaml(IEmitter emitter, object value, Type type) + { + if (value == null) + { + emitter.Emit(new Scalar(null, null, "null", ScalarStyle.Plain, true, false)); + } + else + { + emitter.Emit(new SequenceStart(null, null, true, SequenceStyle.Flow)); + foreach (var it in (IEnumerable)value) + { + emitter.Emit(new Scalar((it == null) ? null : (it + ""))); + } + emitter.Emit(new SequenceEnd()); + } + } + } +} diff --git a/OpenKh.Command.TexFooter/Utils/DecisionHelper.cs b/OpenKh.Command.TexFooter/Utils/DecisionHelper.cs index 5756e3f72..a3677decb 100644 --- a/OpenKh.Command.TexFooter/Utils/DecisionHelper.cs +++ b/OpenKh.Command.TexFooter/Utils/DecisionHelper.cs @@ -1,17 +1,17 @@ -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace OpenKh.Command.TexFooter.Utils -{ - internal static class DecisionHelper - { - internal static bool IsModelFile(List barEntries) - { - var model = barEntries.First(it => it.Type == Bar.EntryType.Model); - return !Mdlx.Read(model.Stream).IsMap; - } - } -} +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenKh.Command.TexFooter.Utils +{ + internal static class DecisionHelper + { + internal static bool IsModelFile(List barEntries) + { + var model = barEntries.First(it => it.Type == Bar.EntryType.Model); + return !Mdlx.Read(model.Stream).IsMap; + } + } +} diff --git a/OpenKh.Command.TexFooter/Utils/ExportHelper.cs b/OpenKh.Command.TexFooter/Utils/ExportHelper.cs index 70c73c0ab..760974ad8 100644 --- a/OpenKh.Command.TexFooter/Utils/ExportHelper.cs +++ b/OpenKh.Command.TexFooter/Utils/ExportHelper.cs @@ -1,46 +1,46 @@ -using OpenKh.Command.TexFooter.Models; -using System; -using System.Collections.Generic; -using System.Drawing.Imaging; -using System.IO; -using System.Linq; -using System.Text; - -namespace OpenKh.Command.TexFooter.Utils -{ - static class ExportHelper - { - internal static PerTexture AlsoExportImages(string outDir, string baseName, PerTexture perTexture) - { - foreach (var pair in perTexture.Textures) - { - var key = pair.Key; - var textureFooterData = pair.Value; - - textureFooterData.TextureAnimationList? - .Select((it, index) => (it, index)) - .ToList() - .ForEach( - pair => - { - var src = pair.it._source; - var bitmap = SpriteImageUtil.ToBitmap( - src.BitsPerPixel, - src.SpriteWidth, - src.SpriteHeight, - src.NumSpritesInImageData, - src.SpriteStride, - src.SpriteImage - ); - var pngFile = Path.Combine(outDir, $"{baseName}.footer-{key}-{pair.index}.png"); - bitmap.Save(pngFile, ImageFormat.Png); - - pair.it.SpriteImageFile = "./" + Path.GetFileName(pngFile); - } - ); - } - - return perTexture; - } - } -} +using OpenKh.Command.TexFooter.Models; +using System; +using System.Collections.Generic; +using System.Drawing.Imaging; +using System.IO; +using System.Linq; +using System.Text; + +namespace OpenKh.Command.TexFooter.Utils +{ + static class ExportHelper + { + internal static PerTexture AlsoExportImages(string outDir, string baseName, PerTexture perTexture) + { + foreach (var pair in perTexture.Textures) + { + var key = pair.Key; + var textureFooterData = pair.Value; + + textureFooterData.TextureAnimationList? + .Select((it, index) => (it, index)) + .ToList() + .ForEach( + pair => + { + var src = pair.it._source; + var bitmap = SpriteImageUtil.ToBitmap( + src.BitsPerPixel, + src.SpriteWidth, + src.SpriteHeight, + src.NumSpritesInImageData, + src.SpriteStride, + src.SpriteImage + ); + var pngFile = Path.Combine(outDir, $"{baseName}.footer-{key}-{pair.index}.png"); + bitmap.Save(pngFile, ImageFormat.Png); + + pair.it.SpriteImageFile = "./" + Path.GetFileName(pngFile); + } + ); + } + + return perTexture; + } + } +} diff --git a/OpenKh.Command.TexFooter/Utils/SpriteBitmap.cs b/OpenKh.Command.TexFooter/Utils/SpriteBitmap.cs index b54f2f32b..8c65367cb 100644 --- a/OpenKh.Command.TexFooter/Utils/SpriteBitmap.cs +++ b/OpenKh.Command.TexFooter/Utils/SpriteBitmap.cs @@ -1,66 +1,66 @@ -using OpenKh.Command.TexFooter.Interfaces; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; -using System.Runtime.InteropServices; -using System.Text; - -namespace OpenKh.Command.TexFooter.Utils -{ - public class SpriteBitmap : ISpriteImageSource - { - public SpriteBitmap(string pngFile) - { - using Bitmap bitmap = new Bitmap(pngFile); - - var bitmapData = bitmap.LockBits( - new Rectangle(Point.Empty, bitmap.Size), - ImageLockMode.WriteOnly, - bitmap.PixelFormat - ); - try - { - Data = new byte[bitmapData.Stride * bitmapData.Height]; - Marshal.Copy(bitmapData.Scan0, Data, 0, Data.Length); - } - finally - { - bitmap.UnlockBits(bitmapData); - } - - switch (bitmap.PixelFormat) - { - case PixelFormat.Format8bppIndexed: - BitsPerPixel = 8; - break; - - case PixelFormat.Format4bppIndexed: - BitsPerPixel = 4; - - PerformSwapPixelOrder(Data); - break; - - default: - throw new NotSupportedException($"PixelFormat: {bitmap.PixelFormat} ≠ 4 or 8"); - } - - Size = bitmap.Size; - } - - private static void PerformSwapPixelOrder(byte[] dst) - { - for (int x = 0; x < dst.Length; x++) - { - var b = dst[x]; - dst[x] = (byte)(b << 4 | b >> 4); - } - } - - public int BitsPerPixel { get; } - - public Size Size { get; } - - public byte[] Data { get; } - } -} +using OpenKh.Command.TexFooter.Interfaces; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; +using System.Text; + +namespace OpenKh.Command.TexFooter.Utils +{ + public class SpriteBitmap : ISpriteImageSource + { + public SpriteBitmap(string pngFile) + { + using Bitmap bitmap = new Bitmap(pngFile); + + var bitmapData = bitmap.LockBits( + new Rectangle(Point.Empty, bitmap.Size), + ImageLockMode.WriteOnly, + bitmap.PixelFormat + ); + try + { + Data = new byte[bitmapData.Stride * bitmapData.Height]; + Marshal.Copy(bitmapData.Scan0, Data, 0, Data.Length); + } + finally + { + bitmap.UnlockBits(bitmapData); + } + + switch (bitmap.PixelFormat) + { + case PixelFormat.Format8bppIndexed: + BitsPerPixel = 8; + break; + + case PixelFormat.Format4bppIndexed: + BitsPerPixel = 4; + + PerformSwapPixelOrder(Data); + break; + + default: + throw new NotSupportedException($"PixelFormat: {bitmap.PixelFormat} ≠ 4 or 8"); + } + + Size = bitmap.Size; + } + + private static void PerformSwapPixelOrder(byte[] dst) + { + for (int x = 0; x < dst.Length; x++) + { + var b = dst[x]; + dst[x] = (byte)(b << 4 | b >> 4); + } + } + + public int BitsPerPixel { get; } + + public Size Size { get; } + + public byte[] Data { get; } + } +} diff --git a/OpenKh.Command.TexFooter/Utils/SpriteImageUtil.cs b/OpenKh.Command.TexFooter/Utils/SpriteImageUtil.cs index 068754b30..1db5dc7f6 100644 --- a/OpenKh.Command.TexFooter/Utils/SpriteImageUtil.cs +++ b/OpenKh.Command.TexFooter/Utils/SpriteImageUtil.cs @@ -1,84 +1,84 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; - -namespace OpenKh.Command.TexFooter.Utils -{ - static class SpriteImageUtil - { - public static Bitmap ToBitmap( - int BitsPerPixel, - int SpriteWidth, - int SpriteHeight, - int NumSpritesInImageData, - int SpriteStride, - byte[] SpriteImage - ) - { - if (BitsPerPixel != 4 && BitsPerPixel != 8) - { - throw new NotSupportedException($"BitsPerPixel: {BitsPerPixel} ≠ 4 or 8"); - } - - var pixFmt = (BitsPerPixel == 8) ? PixelFormat.Format8bppIndexed : PixelFormat.Format4bppIndexed; - - var bitmap = new Bitmap(SpriteWidth, SpriteHeight * NumSpritesInImageData, pixFmt); - var bitmapData = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, pixFmt); - try - { - if (SpriteStride != bitmapData.Stride) - { - throw new NotSupportedException($"Stride: {SpriteStride} ≠ {bitmapData.Stride}"); - } - - if (BitsPerPixel == 8) - { - Marshal.Copy(SpriteImage, 0, bitmapData.Scan0, bitmapData.Stride * bitmapData.Height); - } - else - { - Marshal.Copy(SwapPixelOrder(SpriteImage), 0, bitmapData.Scan0, bitmapData.Stride * bitmapData.Height); - } - } - finally - { - bitmap.UnlockBits(bitmapData); - } - var palette = bitmap.Palette; - if (BitsPerPixel == 8) - { - Enumerable.Range(0, 256).ToList().ForEach( - index => palette.Entries[index] = Color.FromArgb(index, index, index) - ); - } - else - { - Enumerable.Range(0, 16).ToList().ForEach( - index => - { - var light = Math.Min(255, 16 * index); - palette.Entries[index] = Color.FromArgb(light, light, light); - } - ); - } - bitmap.Palette = palette; - - return bitmap; - } - - private static byte[] SwapPixelOrder(byte[] src) - { - var dst = new byte[src.Length]; - for (int x = 0; x < dst.Length; x++) - { - var b = src[x]; - dst[x] = (byte)(b << 4 | b >> 4); - } - return dst; - } - } -} +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; + +namespace OpenKh.Command.TexFooter.Utils +{ + static class SpriteImageUtil + { + public static Bitmap ToBitmap( + int BitsPerPixel, + int SpriteWidth, + int SpriteHeight, + int NumSpritesInImageData, + int SpriteStride, + byte[] SpriteImage + ) + { + if (BitsPerPixel != 4 && BitsPerPixel != 8) + { + throw new NotSupportedException($"BitsPerPixel: {BitsPerPixel} ≠ 4 or 8"); + } + + var pixFmt = (BitsPerPixel == 8) ? PixelFormat.Format8bppIndexed : PixelFormat.Format4bppIndexed; + + var bitmap = new Bitmap(SpriteWidth, SpriteHeight * NumSpritesInImageData, pixFmt); + var bitmapData = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, pixFmt); + try + { + if (SpriteStride != bitmapData.Stride) + { + throw new NotSupportedException($"Stride: {SpriteStride} ≠ {bitmapData.Stride}"); + } + + if (BitsPerPixel == 8) + { + Marshal.Copy(SpriteImage, 0, bitmapData.Scan0, bitmapData.Stride * bitmapData.Height); + } + else + { + Marshal.Copy(SwapPixelOrder(SpriteImage), 0, bitmapData.Scan0, bitmapData.Stride * bitmapData.Height); + } + } + finally + { + bitmap.UnlockBits(bitmapData); + } + var palette = bitmap.Palette; + if (BitsPerPixel == 8) + { + Enumerable.Range(0, 256).ToList().ForEach( + index => palette.Entries[index] = Color.FromArgb(index, index, index) + ); + } + else + { + Enumerable.Range(0, 16).ToList().ForEach( + index => + { + var light = Math.Min(255, 16 * index); + palette.Entries[index] = Color.FromArgb(light, light, light); + } + ); + } + bitmap.Palette = palette; + + return bitmap; + } + + private static byte[] SwapPixelOrder(byte[] src) + { + var dst = new byte[src.Length]; + for (int x = 0; x < dst.Length; x++) + { + var b = src[x]; + dst[x] = (byte)(b << 4 | b >> 4); + } + return dst; + } + } +} diff --git a/OpenKh.Common/Archives/HdAsset.cs b/OpenKh.Common/Archives/HdAsset.cs index fa675064f..48df8c158 100644 --- a/OpenKh.Common/Archives/HdAsset.cs +++ b/OpenKh.Common/Archives/HdAsset.cs @@ -1,158 +1,158 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Common.Archives -{ - public class HdAsset - { - private class Header - { - [Data] public int OriginalLength { get; set; } - [Data] public int AssetCount { get; set; } - [Data] public int Unused08 { get; set; } - [Data] public int Unused0c { get; set; } - } - - private class HeaderEntry - { - [Data(Count = 0x20)] public string Name { get; set; } - [Data] public int Offset { get; set; } - [Data] public int Flags { get; set; } - [Data] public int Length { get; set; } - [Data] public int Unused { get; set; } - } - - public class Entry - { - private Stream stream; - - public string Name { get; set; } - public Stream Stream - { - get => stream; - set => stream = value ?? throw new ArgumentNullException(nameof(Stream)); - } - public int Flags { get; set; } - - public Entry() - { - Stream = new MemoryStream(); - } - } - - private readonly Header _header; - private Stream stream; - private List entries; - - /// - /// Original file stream, without the ReMIX assets - /// - public Stream Stream - { - get => stream; - set => stream = value ?? throw new ArgumentNullException(nameof(Stream)); - } - - public List Entries - { - get => entries; - set => entries = value ?? throw new ArgumentNullException(nameof(Entries)); - } - - public HdAsset() - { - _header = new Header(); - Stream = new MemoryStream(); - Entries = new List(); - } - - private HdAsset(Stream stream) - { - _header = BinaryMapping.ReadObject
(stream); - var entries = Enumerable.Range(0, _header.AssetCount) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList(); - - Stream = new MemoryStream(_header.OriginalLength); - stream.Copy(Stream, _header.OriginalLength); - Stream.Position = 0; - - Entries = entries.Select(x => new Entry - { - Name = x.Name, - Stream = GetSubStreamCopy(stream, x.Offset, x.Length).SetPosition(0), - Flags = x.Flags, - }).ToList(); - } - - public void Write(Stream stream) - { - _header.OriginalLength = (int)Stream.Length; - _header.AssetCount = Entries.Count; - var entries = Entries.Select(x => new HeaderEntry - { - Name = x.Name, - Offset = -1, - Length = (int)x.Stream.Length, - Flags = x.Flags, - Unused = 0 - }).ToList(); - - Stream.SetPosition(0).CopyTo(stream.SetPosition(0x10 + Entries.Count * 0x30)); - for (var i = 0; i < Entries.Count; i++) - { - entries[i].Offset = (int)stream.Position; - - var srcStream = Entries[i].Stream; - srcStream.Position = 0; - srcStream.CopyTo(stream); - } - - stream.Position = 0; - BinaryMapping.WriteObject(stream, _header); - foreach (var entry in entries) - BinaryMapping.WriteObject(stream, entry); - } - - private Stream GetSubStreamCopy(Stream stream, int offset, int length) - { - var outStream = new MemoryStream(length); - stream.Position = offset; - stream.Copy(outStream, length); - return outStream; - } - - public static HdAsset Read(Stream stream) => new HdAsset(stream); - - public static bool IsValid(Stream stream) - { - const int MinimumPossibleSizeForHeader = 0x10; - const int EstimatedMaximumPossibleSizeForOriginalAsset = 32 * 1024 * 1024; - const int EstimatedMaximumPossibleRemasteredAssetCount = 1024; - - if (stream.Length < MinimumPossibleSizeForHeader) - return false; - - var originalAssetLength = stream.ReadInt32(); - if (originalAssetLength > EstimatedMaximumPossibleSizeForOriginalAsset) - return false; - - var assetCount = stream.ReadInt32(); - if (assetCount >= EstimatedMaximumPossibleRemasteredAssetCount) - return false; - - if (stream.ReadInt32() != 0) - return false; - if (stream.ReadInt32() != 0) - return false; - - if (originalAssetLength + MinimumPossibleSizeForHeader > stream.Length) - return false; - - return true; - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Common.Archives +{ + public class HdAsset + { + private class Header + { + [Data] public int OriginalLength { get; set; } + [Data] public int AssetCount { get; set; } + [Data] public int Unused08 { get; set; } + [Data] public int Unused0c { get; set; } + } + + private class HeaderEntry + { + [Data(Count = 0x20)] public string Name { get; set; } + [Data] public int Offset { get; set; } + [Data] public int Flags { get; set; } + [Data] public int Length { get; set; } + [Data] public int Unused { get; set; } + } + + public class Entry + { + private Stream stream; + + public string Name { get; set; } + public Stream Stream + { + get => stream; + set => stream = value ?? throw new ArgumentNullException(nameof(Stream)); + } + public int Flags { get; set; } + + public Entry() + { + Stream = new MemoryStream(); + } + } + + private readonly Header _header; + private Stream stream; + private List entries; + + /// + /// Original file stream, without the ReMIX assets + /// + public Stream Stream + { + get => stream; + set => stream = value ?? throw new ArgumentNullException(nameof(Stream)); + } + + public List Entries + { + get => entries; + set => entries = value ?? throw new ArgumentNullException(nameof(Entries)); + } + + public HdAsset() + { + _header = new Header(); + Stream = new MemoryStream(); + Entries = new List(); + } + + private HdAsset(Stream stream) + { + _header = BinaryMapping.ReadObject
(stream); + var entries = Enumerable.Range(0, _header.AssetCount) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList(); + + Stream = new MemoryStream(_header.OriginalLength); + stream.Copy(Stream, _header.OriginalLength); + Stream.Position = 0; + + Entries = entries.Select(x => new Entry + { + Name = x.Name, + Stream = GetSubStreamCopy(stream, x.Offset, x.Length).SetPosition(0), + Flags = x.Flags, + }).ToList(); + } + + public void Write(Stream stream) + { + _header.OriginalLength = (int)Stream.Length; + _header.AssetCount = Entries.Count; + var entries = Entries.Select(x => new HeaderEntry + { + Name = x.Name, + Offset = -1, + Length = (int)x.Stream.Length, + Flags = x.Flags, + Unused = 0 + }).ToList(); + + Stream.SetPosition(0).CopyTo(stream.SetPosition(0x10 + Entries.Count * 0x30)); + for (var i = 0; i < Entries.Count; i++) + { + entries[i].Offset = (int)stream.Position; + + var srcStream = Entries[i].Stream; + srcStream.Position = 0; + srcStream.CopyTo(stream); + } + + stream.Position = 0; + BinaryMapping.WriteObject(stream, _header); + foreach (var entry in entries) + BinaryMapping.WriteObject(stream, entry); + } + + private Stream GetSubStreamCopy(Stream stream, int offset, int length) + { + var outStream = new MemoryStream(length); + stream.Position = offset; + stream.Copy(outStream, length); + return outStream; + } + + public static HdAsset Read(Stream stream) => new HdAsset(stream); + + public static bool IsValid(Stream stream) + { + const int MinimumPossibleSizeForHeader = 0x10; + const int EstimatedMaximumPossibleSizeForOriginalAsset = 32 * 1024 * 1024; + const int EstimatedMaximumPossibleRemasteredAssetCount = 1024; + + if (stream.Length < MinimumPossibleSizeForHeader) + return false; + + var originalAssetLength = stream.ReadInt32(); + if (originalAssetLength > EstimatedMaximumPossibleSizeForOriginalAsset) + return false; + + var assetCount = stream.ReadInt32(); + if (assetCount >= EstimatedMaximumPossibleRemasteredAssetCount) + return false; + + if (stream.ReadInt32() != 0) + return false; + if (stream.ReadInt32() != 0) + return false; + + if (originalAssetLength + MinimumPossibleSizeForHeader > stream.Length) + return false; + + return true; + } + } +} diff --git a/OpenKh.Common/BinaryMappingExtensions.cs b/OpenKh.Common/BinaryMappingExtensions.cs index 6b0f02dc2..9d0b3a805 100644 --- a/OpenKh.Common/BinaryMappingExtensions.cs +++ b/OpenKh.Common/BinaryMappingExtensions.cs @@ -1,24 +1,24 @@ -using System.Numerics; -using Xe.BinaryMapper; - -namespace OpenKh.Common -{ - public static class BinaryMapperExtensions - { - public static MappingConfiguration ForTypeVector2(this MappingConfiguration cfg) => - cfg.ForType(x => x.Reader.BaseStream.ReadVector2(), - x => x.Writer.BaseStream.Write((Vector2)x.Item)); - - public static MappingConfiguration ForTypeVector3(this MappingConfiguration cfg) => - cfg.ForType(x => x.Reader.BaseStream.ReadVector3(), - x => x.Writer.BaseStream.Write((Vector3)x.Item)); - - public static MappingConfiguration ForTypeVector4(this MappingConfiguration cfg) => - cfg.ForType(x => x.Reader.BaseStream.ReadVector4(), - x => x.Writer.BaseStream.Write((Vector4)x.Item)); - - public static MappingConfiguration ForTypeMatrix4x4(this MappingConfiguration cfg) => - cfg.ForType(x => x.Reader.BaseStream.ReadMatrix4x4(), - x => x.Writer.BaseStream.Write((Matrix4x4)x.Item)); - } -} +using System.Numerics; +using Xe.BinaryMapper; + +namespace OpenKh.Common +{ + public static class BinaryMapperExtensions + { + public static MappingConfiguration ForTypeVector2(this MappingConfiguration cfg) => + cfg.ForType(x => x.Reader.BaseStream.ReadVector2(), + x => x.Writer.BaseStream.Write((Vector2)x.Item)); + + public static MappingConfiguration ForTypeVector3(this MappingConfiguration cfg) => + cfg.ForType(x => x.Reader.BaseStream.ReadVector3(), + x => x.Writer.BaseStream.Write((Vector3)x.Item)); + + public static MappingConfiguration ForTypeVector4(this MappingConfiguration cfg) => + cfg.ForType(x => x.Reader.BaseStream.ReadVector4(), + x => x.Writer.BaseStream.Write((Vector4)x.Item)); + + public static MappingConfiguration ForTypeMatrix4x4(this MappingConfiguration cfg) => + cfg.ForType(x => x.Reader.BaseStream.ReadMatrix4x4(), + x => x.Writer.BaseStream.Write((Matrix4x4)x.Item)); + } +} diff --git a/OpenKh.Common/DictionaryExtensions.cs b/OpenKh.Common/DictionaryExtensions.cs index 1ccb040aa..da5c4b2c1 100644 --- a/OpenKh.Common/DictionaryExtensions.cs +++ b/OpenKh.Common/DictionaryExtensions.cs @@ -1,42 +1,42 @@ -using System.Collections.Generic; - -namespace OpenKh.Common -{ - public static class DictionaryExtensions - { - public static string GetString( - this IDictionary dic, string key, string defaultValue) => - dic.TryGetValue(key, out var value) ? value : defaultValue; - - public static int GetInt( - this IDictionary dic, string key, int defaultValue) => - int.TryParse(dic.GetSetting(key, string.Empty), out var value) ? value : defaultValue; - - public static bool GetBool( - this IDictionary dic, string key, bool defaultValue) => - bool.TryParse(dic.GetSetting(key, string.Empty), out var value) ? value : defaultValue; - - public static double GetDouble( - this IDictionary dic, string key, double defaultValue) => - double.TryParse(dic.GetSetting(key, string.Empty), out var value) ? value : defaultValue; - - public static T GetSetting( - this IDictionary dic, string key, T defaultValue) - { - var type = typeof(T); - if (type == typeof(string)) - return (T)(object)dic.GetString(key, (string)(object)defaultValue); - if (type == typeof(int)) - return int.TryParse(dic.GetSetting(key, string.Empty), out var value) ? - (T)(object)value : defaultValue; - if (type == typeof(bool)) - return bool.TryParse(dic.GetSetting(key, string.Empty), out var value) ? - (T)(object)value : defaultValue; - if (type == typeof(double)) - return double.TryParse(dic.GetSetting(key, string.Empty), out var value) ? - (T)(object)value : defaultValue; - - return defaultValue; - } - } -} +using System.Collections.Generic; + +namespace OpenKh.Common +{ + public static class DictionaryExtensions + { + public static string GetString( + this IDictionary dic, string key, string defaultValue) => + dic.TryGetValue(key, out var value) ? value : defaultValue; + + public static int GetInt( + this IDictionary dic, string key, int defaultValue) => + int.TryParse(dic.GetSetting(key, string.Empty), out var value) ? value : defaultValue; + + public static bool GetBool( + this IDictionary dic, string key, bool defaultValue) => + bool.TryParse(dic.GetSetting(key, string.Empty), out var value) ? value : defaultValue; + + public static double GetDouble( + this IDictionary dic, string key, double defaultValue) => + double.TryParse(dic.GetSetting(key, string.Empty), out var value) ? value : defaultValue; + + public static T GetSetting( + this IDictionary dic, string key, T defaultValue) + { + var type = typeof(T); + if (type == typeof(string)) + return (T)(object)dic.GetString(key, (string)(object)defaultValue); + if (type == typeof(int)) + return int.TryParse(dic.GetSetting(key, string.Empty), out var value) ? + (T)(object)value : defaultValue; + if (type == typeof(bool)) + return bool.TryParse(dic.GetSetting(key, string.Empty), out var value) ? + (T)(object)value : defaultValue; + if (type == typeof(double)) + return double.TryParse(dic.GetSetting(key, string.Empty), out var value) ? + (T)(object)value : defaultValue; + + return defaultValue; + } + } +} diff --git a/OpenKh.Common/DisposableExtensions.cs b/OpenKh.Common/DisposableExtensions.cs index 732820c8b..7d50e0143 100644 --- a/OpenKh.Common/DisposableExtensions.cs +++ b/OpenKh.Common/DisposableExtensions.cs @@ -1,21 +1,21 @@ -using System; - -namespace OpenKh.Common -{ - public static class DisposableExtensions - { - public static void Using(this T disposable, Action action) - where T : IDisposable - { - using (disposable) - action(disposable); - } - - public static TResult Using(this T disposable, Func func) - where T : IDisposable - { - using (disposable) - return func(disposable); - } - } -} +using System; + +namespace OpenKh.Common +{ + public static class DisposableExtensions + { + public static void Using(this T disposable, Action action) + where T : IDisposable + { + using (disposable) + action(disposable); + } + + public static TResult Using(this T disposable, Func func) + where T : IDisposable + { + using (disposable) + return func(disposable); + } + } +} diff --git a/OpenKh.Common/Exceptions/CharacterNotSupportedException.cs b/OpenKh.Common/Exceptions/CharacterNotSupportedException.cs index 266951b51..564d9bf75 100644 --- a/OpenKh.Common/Exceptions/CharacterNotSupportedException.cs +++ b/OpenKh.Common/Exceptions/CharacterNotSupportedException.cs @@ -1,11 +1,11 @@ -using System; - -namespace OpenKh.Common.Exceptions -{ - public class CharacterNotSupportedException : ArgumentException - { - public CharacterNotSupportedException(char ch) : - base($"The character {ch} it is not supported by the specified encoding.") - { } - } -} +using System; + +namespace OpenKh.Common.Exceptions +{ + public class CharacterNotSupportedException : ArgumentException + { + public CharacterNotSupportedException(char ch) : + base($"The character {ch} it is not supported by the specified encoding.") + { } + } +} diff --git a/OpenKh.Common/Exceptions/InvalidFileException.cs b/OpenKh.Common/Exceptions/InvalidFileException.cs index 18fd1ab51..73d477ea9 100644 --- a/OpenKh.Common/Exceptions/InvalidFileException.cs +++ b/OpenKh.Common/Exceptions/InvalidFileException.cs @@ -1,23 +1,23 @@ -using System; - -namespace OpenKh.Common.Exceptions -{ - public class InvalidFileException : InvalidFileException - { - public InvalidFileException() : - base(typeof(T)) - { } - } - - - public class InvalidFileException : Exception - { - public InvalidFileException(Type type) : - base($"The specified file is not recognized as {type.Name}.") - { } - - public InvalidFileException() : - base("The specified file is not recognized.") - { } - } -} +using System; + +namespace OpenKh.Common.Exceptions +{ + public class InvalidFileException : InvalidFileException + { + public InvalidFileException() : + base(typeof(T)) + { } + } + + + public class InvalidFileException : Exception + { + public InvalidFileException(Type type) : + base($"The specified file is not recognized as {type.Name}.") + { } + + public InvalidFileException() : + base("The specified file is not recognized.") + { } + } +} diff --git a/OpenKh.Common/Exceptions/ParseException.cs b/OpenKh.Common/Exceptions/ParseException.cs index 94fbea46e..5fc8d159b 100644 --- a/OpenKh.Common/Exceptions/ParseException.cs +++ b/OpenKh.Common/Exceptions/ParseException.cs @@ -1,14 +1,14 @@ -using System; - -namespace OpenKh.Common.Exceptions -{ - public class ParseException : Exception - { - public ParseException(string value, int index, string reason) : - base(GetExceptionMessage(value, index, reason)) - { } - - private static string GetExceptionMessage(string value, int index, string reason) => - $"Parse error on {value} at {index} due to the following reason:\n{reason}"; - } -} +using System; + +namespace OpenKh.Common.Exceptions +{ + public class ParseException : Exception + { + public ParseException(string value, int index, string reason) : + base(GetExceptionMessage(value, index, reason)) + { } + + private static string GetExceptionMessage(string value, int index, string reason) => + $"Parse error on {value} at {index} due to the following reason:\n{reason}"; + } +} diff --git a/OpenKh.Common/Helpers.cs b/OpenKh.Common/Helpers.cs index 010fac896..750877e05 100644 --- a/OpenKh.Common/Helpers.cs +++ b/OpenKh.Common/Helpers.cs @@ -1,29 +1,29 @@ -using System.IO; - -namespace OpenKh.Common -{ - public class Helpers - { - public static int Align(int offset, int alignment) - { - var misalignment = offset % alignment; - return misalignment > 0 ? offset + alignment - misalignment : offset; - } - - public static string[] GetContent(string path, bool recursive = false) - { - if (File.Exists(path)) - return new string[] { path }; - if (Directory.Exists(path)) - return new string[0]; - - return Directory.GetFiles(path, "*", recursive ? - SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); - } - - public static string YamlSerialize(T obj) => - new YamlDotNet.Serialization.Serializer().Serialize(obj); - public static T YamlDeserialize(string content) => - new YamlDotNet.Serialization.Deserializer().Deserialize(content); - } -} +using System.IO; + +namespace OpenKh.Common +{ + public class Helpers + { + public static int Align(int offset, int alignment) + { + var misalignment = offset % alignment; + return misalignment > 0 ? offset + alignment - misalignment : offset; + } + + public static string[] GetContent(string path, bool recursive = false) + { + if (File.Exists(path)) + return new string[] { path }; + if (Directory.Exists(path)) + return new string[0]; + + return Directory.GetFiles(path, "*", recursive ? + SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); + } + + public static string YamlSerialize(T obj) => + new YamlDotNet.Serialization.Serializer().Serialize(obj); + public static T YamlDeserialize(string content) => + new YamlDotNet.Serialization.Deserializer().Deserialize(content); + } +} diff --git a/OpenKh.Common/IsoUtility.cs b/OpenKh.Common/IsoUtility.cs index ad9871fc1..8aaa43cc3 100644 --- a/OpenKh.Common/IsoUtility.cs +++ b/OpenKh.Common/IsoUtility.cs @@ -1,50 +1,50 @@ -using System; -using System.IO; -using System.Linq; -using System.Text; - -namespace OpenKh.Common -{ - public static class IsoUtility - { - private const int BlockLength = 0x800; - - public static int GetFileOffset(Stream isoStream, string fileName) - { - const uint basePosition = 0x105 * BlockLength; // un-needly hardcoded? - - var fileNameData = Encoding.UTF8.GetBytes(fileName); - isoStream.SetPosition(basePosition); - for (int i = 0; i < 0x500; i++) - { - if (isoStream.ReadByte() != 1) - continue; - - var stringLength = isoStream.ReadByte(); - if (stringLength != fileNameData.Length) - continue; - - var currentPosition = isoStream.Position; - if (isoStream.ReadBytes(stringLength).SequenceEqual(fileNameData)) - { - isoStream.SetPosition(currentPosition - 0x1B); - - var blockStack = isoStream.ReadBytes(0x04); - var blockCorrectEndian = new byte[0x04] - { - blockStack[3], - blockStack[2], - blockStack[1], - blockStack[0] - }; - - return BitConverter.ToInt32(blockCorrectEndian, 0); - } - - isoStream.Position = currentPosition + 1; - } - - return -1; - } - } -} +using System; +using System.IO; +using System.Linq; +using System.Text; + +namespace OpenKh.Common +{ + public static class IsoUtility + { + private const int BlockLength = 0x800; + + public static int GetFileOffset(Stream isoStream, string fileName) + { + const uint basePosition = 0x105 * BlockLength; // un-needly hardcoded? + + var fileNameData = Encoding.UTF8.GetBytes(fileName); + isoStream.SetPosition(basePosition); + for (int i = 0; i < 0x500; i++) + { + if (isoStream.ReadByte() != 1) + continue; + + var stringLength = isoStream.ReadByte(); + if (stringLength != fileNameData.Length) + continue; + + var currentPosition = isoStream.Position; + if (isoStream.ReadBytes(stringLength).SequenceEqual(fileNameData)) + { + isoStream.SetPosition(currentPosition - 0x1B); + + var blockStack = isoStream.ReadBytes(0x04); + var blockCorrectEndian = new byte[0x04] + { + blockStack[3], + blockStack[2], + blockStack[1], + blockStack[0] + }; + + return BitConverter.ToInt32(blockCorrectEndian, 0); + } + + isoStream.Position = currentPosition + 1; + } + + return -1; + } + } +} diff --git a/OpenKh.Common/Log.cs b/OpenKh.Common/Log.cs index 96a9a49f5..88687d393 100644 --- a/OpenKh.Common/Log.cs +++ b/OpenKh.Common/Log.cs @@ -1,107 +1,107 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace OpenKh.Common -{ - public static class Log - { - public static readonly string AppName = NormalizeName(Assembly.GetEntryAssembly().ManifestModule.ToString()); - private static readonly string LogFileName = $"{AppName}.log"; - private static readonly Task _taskLog; - private static readonly Stopwatch _stopwatch = Stopwatch.StartNew(); - private static readonly StreamWriter _logWriter = new StreamWriter(LogFileName, false, Encoding.UTF8, 65536); - private static readonly Queue<(long ms, string tag, string fmt, object[] args)> _logQueue = - new Queue<(long, string, string, object[])>(); - private static readonly CancellationTokenSource _cancellationTokenSrc = new CancellationTokenSource(); - - public delegate void LogDispatch(long ms, string tag, string message); - public static event LogDispatch OnLogDispatch; - - public static void Info(string fmt, params object[] args) => LogText("INF", fmt, args); - public static void Warn(string fmt, params object[] args) => LogText("WRN", fmt, args); - public static void Err(string fmt, params object[] args) => LogText("ERR", fmt, args); - - static Log() - { - _taskLog = Task.Run(LogWriterListener, _cancellationTokenSrc.Token); - OnLogDispatch += (long ms, string tag, string message) => - { - var str = $"[{(ms / 1000):D3}.{(ms % 1000):D3}] {tag} {message}"; - Console.Error.WriteLine(str); - _logWriter.WriteLine(str); - }; - } - - public static void Close() - { - _cancellationTokenSrc.Cancel(); - _cancellationTokenSrc.Token.WaitHandle.WaitOne(); - _cancellationTokenSrc.Dispose(); - Flush(); - } - - private static void Flush() - { - const int Timeout = 3000; - - var timeoutStopwatch = Stopwatch.StartNew(); - do - { - lock (_logQueue) - { - if (_logQueue.Count == 0) - { - _logWriter.Flush(); - return; - } - } - } while (timeoutStopwatch.ElapsedMilliseconds < Timeout); - - throw new TimeoutException("Could not flush logs within the time limit"); - } - - private static void LogText(string tag, string fmt, object[] args) - { - var ms = _stopwatch.ElapsedMilliseconds; - lock (_logQueue) - _logQueue.Enqueue((ms, tag, fmt, args)); - } - - private static void LogWriterListener() - { - while (!_cancellationTokenSrc.IsCancellationRequested) - { - DequeueAllLogs(); - Thread.Sleep(1); - } - - DequeueAllLogs(); - } - - private static void DequeueAllLogs() - { - lock (_logQueue) - { - while (_logQueue.Count > 0) - { - var evt = _logQueue.Dequeue(); - OnLogDispatch(evt.ms, evt.tag, string.Format(evt.fmt, evt.args)); - } - } - } - - private static string NormalizeName(string name) - { - if (name.EndsWith(".dll") || name.EndsWith(".exe")) - return name.Substring(0, name.Length - 4); - - return name; - } - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace OpenKh.Common +{ + public static class Log + { + public static readonly string AppName = NormalizeName(Assembly.GetEntryAssembly().ManifestModule.ToString()); + private static readonly string LogFileName = $"{AppName}.log"; + private static readonly Task _taskLog; + private static readonly Stopwatch _stopwatch = Stopwatch.StartNew(); + private static readonly StreamWriter _logWriter = new StreamWriter(LogFileName, false, Encoding.UTF8, 65536); + private static readonly Queue<(long ms, string tag, string fmt, object[] args)> _logQueue = + new Queue<(long, string, string, object[])>(); + private static readonly CancellationTokenSource _cancellationTokenSrc = new CancellationTokenSource(); + + public delegate void LogDispatch(long ms, string tag, string message); + public static event LogDispatch OnLogDispatch; + + public static void Info(string fmt, params object[] args) => LogText("INF", fmt, args); + public static void Warn(string fmt, params object[] args) => LogText("WRN", fmt, args); + public static void Err(string fmt, params object[] args) => LogText("ERR", fmt, args); + + static Log() + { + _taskLog = Task.Run(LogWriterListener, _cancellationTokenSrc.Token); + OnLogDispatch += (long ms, string tag, string message) => + { + var str = $"[{(ms / 1000):D3}.{(ms % 1000):D3}] {tag} {message}"; + Console.Error.WriteLine(str); + _logWriter.WriteLine(str); + }; + } + + public static void Close() + { + _cancellationTokenSrc.Cancel(); + _cancellationTokenSrc.Token.WaitHandle.WaitOne(); + _cancellationTokenSrc.Dispose(); + Flush(); + } + + private static void Flush() + { + const int Timeout = 3000; + + var timeoutStopwatch = Stopwatch.StartNew(); + do + { + lock (_logQueue) + { + if (_logQueue.Count == 0) + { + _logWriter.Flush(); + return; + } + } + } while (timeoutStopwatch.ElapsedMilliseconds < Timeout); + + throw new TimeoutException("Could not flush logs within the time limit"); + } + + private static void LogText(string tag, string fmt, object[] args) + { + var ms = _stopwatch.ElapsedMilliseconds; + lock (_logQueue) + _logQueue.Enqueue((ms, tag, fmt, args)); + } + + private static void LogWriterListener() + { + while (!_cancellationTokenSrc.IsCancellationRequested) + { + DequeueAllLogs(); + Thread.Sleep(1); + } + + DequeueAllLogs(); + } + + private static void DequeueAllLogs() + { + lock (_logQueue) + { + while (_logQueue.Count > 0) + { + var evt = _logQueue.Dequeue(); + OnLogDispatch(evt.ms, evt.tag, string.Format(evt.fmt, evt.args)); + } + } + } + + private static string NormalizeName(string name) + { + if (name.EndsWith(".dll") || name.EndsWith(".exe")) + return name.Substring(0, name.Length - 4); + + return name; + } + } +} diff --git a/OpenKh.Common/Ps2/Dma.cs b/OpenKh.Common/Ps2/Dma.cs index 0d1d829eb..0115cbbab 100644 --- a/OpenKh.Common/Ps2/Dma.cs +++ b/OpenKh.Common/Ps2/Dma.cs @@ -1,78 +1,78 @@ -using Xe.BinaryMapper; - -namespace OpenKh.Common.Ps2 -{ - /// - /// EE User Manual, 6.3.2 - /// - public enum VifOpcode : byte - { - NOP = 0b00000000, - STCYCL = 0b00000001, - OFFSET = 0b00000010, - BASE = 0b00000011, - ITOP = 0b00000100, - STMOD = 0b00000101, - MSKPATH3 = 0b00000110, - MARK = 0b00000111, - FLUSHE = 0b00010000, - FLUSH = 0b00010001, - FLUSHA = 0b00010011, - MSCAL = 0b00010100, - MSCALF = 0b00010101, - MSCNT = 0b00010111, - STMASK = 0b00100000, - STROW = 0b00110000, - STCOL = 0b00110001, - MPG = 0b01001010, - DIRECT = 0b01010000, - DIRECTH = 0b01010001 - } - - /// - /// EE User Manual, 6.3.2 - /// - public class VifCode - { - [Data] public byte Cmd { get; set; } - [Data] public byte Num { get; set; } - [Data] public ushort Immediate { get; set; } - - public VifOpcode Opcode - { - get => (VifOpcode)(Cmd & 7); - set => Cmd = (byte)((byte)value | (Interrupt ? 0x80 : 0)); - } - - public bool Interrupt - { - get => (Cmd >> 7) != 0; - set => Cmd = (byte)((byte)Opcode | (value ? 0x80 : 0)); - } - } - - /// - /// EE User Manual, 5.6 - /// - public class DmaTag - { - /// - /// Quadword count; packet size - /// - [Data] public ushort Qwc { get; set; } - [Data] public ushort Param { get; set; } - [Data] public int Address { get; set; } - - public int TagId - { - get => (Param >> 12) & 7; - set => Param = (ushort)(((value & 7) << 12) | (Irq ? 0x8000 : 0)); - } - - public bool Irq - { - get => (Param >> 15) != 0; - set => Param = (ushort)((TagId << 12) | (value ? 0x8000 : 0)); - } - } -} +using Xe.BinaryMapper; + +namespace OpenKh.Common.Ps2 +{ + /// + /// EE User Manual, 6.3.2 + /// + public enum VifOpcode : byte + { + NOP = 0b00000000, + STCYCL = 0b00000001, + OFFSET = 0b00000010, + BASE = 0b00000011, + ITOP = 0b00000100, + STMOD = 0b00000101, + MSKPATH3 = 0b00000110, + MARK = 0b00000111, + FLUSHE = 0b00010000, + FLUSH = 0b00010001, + FLUSHA = 0b00010011, + MSCAL = 0b00010100, + MSCALF = 0b00010101, + MSCNT = 0b00010111, + STMASK = 0b00100000, + STROW = 0b00110000, + STCOL = 0b00110001, + MPG = 0b01001010, + DIRECT = 0b01010000, + DIRECTH = 0b01010001 + } + + /// + /// EE User Manual, 6.3.2 + /// + public class VifCode + { + [Data] public byte Cmd { get; set; } + [Data] public byte Num { get; set; } + [Data] public ushort Immediate { get; set; } + + public VifOpcode Opcode + { + get => (VifOpcode)(Cmd & 7); + set => Cmd = (byte)((byte)value | (Interrupt ? 0x80 : 0)); + } + + public bool Interrupt + { + get => (Cmd >> 7) != 0; + set => Cmd = (byte)((byte)Opcode | (value ? 0x80 : 0)); + } + } + + /// + /// EE User Manual, 5.6 + /// + public class DmaTag + { + /// + /// Quadword count; packet size + /// + [Data] public ushort Qwc { get; set; } + [Data] public ushort Param { get; set; } + [Data] public int Address { get; set; } + + public int TagId + { + get => (Param >> 12) & 7; + set => Param = (ushort)(((value & 7) << 12) | (Irq ? 0x8000 : 0)); + } + + public bool Irq + { + get => (Param >> 15) != 0; + set => Param = (ushort)((TagId << 12) | (value ? 0x8000 : 0)); + } + } +} diff --git a/OpenKh.Common/RectangleExtensions.cs b/OpenKh.Common/RectangleExtensions.cs index 9f7680245..86eaa3b4d 100644 --- a/OpenKh.Common/RectangleExtensions.cs +++ b/OpenKh.Common/RectangleExtensions.cs @@ -1,53 +1,57 @@ -using System; -using System.Drawing; - -namespace OpenKh.Common -{ - public static class RectangleExtensions - { - public static Rectangle FlipX(this Rectangle rectangle) => - Rectangle.FromLTRB(rectangle.Right, rectangle.Top, rectangle.Left, rectangle.Bottom); - - public static Rectangle FlipY(this Rectangle rectangle) => - Rectangle.FromLTRB(rectangle.Left, rectangle.Bottom, rectangle.Right, rectangle.Top); - - public static Rectangle GetVisibility(this Rectangle rectangle) - { - if (rectangle.Width == 0 || rectangle.Height == 0) - return Rectangle.Empty; - - if (rectangle.Width < 0) rectangle = rectangle.FlipX(); - if (rectangle.Height < 0) rectangle = rectangle.FlipY(); - - return rectangle; - } - - public static Rectangle Union(this Rectangle rect, Rectangle rectangle) - { - rect = rect.GetVisibility(); - rectangle = rectangle.GetVisibility(); - - if (rect.IsEmpty) return rectangle; - if (rectangle.IsEmpty) return rect; - - return Rectangle.FromLTRB( - Math.Min(rect.Left, rectangle.Left), - Math.Min(rect.Top, rectangle.Top), - Math.Max(rect.Right, rectangle.Right), - Math.Max(rect.Bottom, rectangle.Bottom)); - } - - public static Rectangle Traslate(this Rectangle rect, int x, int y) => - new Rectangle(rect.X + x, rect.Y + y, rect.Width, rect.Height); - - public static Rectangle Multiply(this Rectangle rect, float x, float y) => - Rectangle.FromLTRB( - (int)Math.Round(rect.Left * x), - (int)Math.Round(rect.Top * y), - (int)Math.Round(rect.Right * x), - (int)Math.Round(rect.Bottom * y)); - - public static RectangleF ToRectangleF(this Rectangle rectangle) => - new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); - } -} +using System; +using System.Drawing; + +namespace OpenKh.Common +{ + public static class RectangleExtensions + { + public static Rectangle FlipX(this Rectangle rectangle) => + Rectangle.FromLTRB(rectangle.Right, rectangle.Top, rectangle.Left, rectangle.Bottom); + + public static Rectangle FlipY(this Rectangle rectangle) => + Rectangle.FromLTRB(rectangle.Left, rectangle.Bottom, rectangle.Right, rectangle.Top); + + public static Rectangle GetVisibility(this Rectangle rectangle) + { + if (rectangle.Width == 0 || rectangle.Height == 0) + return Rectangle.Empty; + + if (rectangle.Width < 0) + rectangle = rectangle.FlipX(); + if (rectangle.Height < 0) + rectangle = rectangle.FlipY(); + + return rectangle; + } + + public static Rectangle Union(this Rectangle rect, Rectangle rectangle) + { + rect = rect.GetVisibility(); + rectangle = rectangle.GetVisibility(); + + if (rect.IsEmpty) + return rectangle; + if (rectangle.IsEmpty) + return rect; + + return Rectangle.FromLTRB( + Math.Min(rect.Left, rectangle.Left), + Math.Min(rect.Top, rectangle.Top), + Math.Max(rect.Right, rectangle.Right), + Math.Max(rect.Bottom, rectangle.Bottom)); + } + + public static Rectangle Traslate(this Rectangle rect, int x, int y) => + new Rectangle(rect.X + x, rect.Y + y, rect.Width, rect.Height); + + public static Rectangle Multiply(this Rectangle rect, float x, float y) => + Rectangle.FromLTRB( + (int)Math.Round(rect.Left * x), + (int)Math.Round(rect.Top * y), + (int)Math.Round(rect.Right * x), + (int)Math.Round(rect.Bottom * y)); + + public static RectangleF ToRectangleF(this Rectangle rectangle) => + new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); + } +} diff --git a/OpenKh.Common/StreamExtensions.cs b/OpenKh.Common/StreamExtensions.cs index a036247ce..0fc03c200 100644 --- a/OpenKh.Common/StreamExtensions.cs +++ b/OpenKh.Common/StreamExtensions.cs @@ -1,333 +1,333 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Numerics; -using System.Text; -using Xe.BinaryMapper; - -namespace OpenKh.Common -{ - public static class StreamExtensions - { - private static readonly InvalidDataException ReadSeekException = new InvalidDataException($"Stream must be readable and seekable."); - private static readonly InvalidDataException WriteSeekException = new InvalidDataException($"Stream must be writable and seekable."); - private static readonly Func InvalidHeaderLengthException = (minHeaderLength) => - new InvalidDataException($"Invalid header: stream must be at least {minHeaderLength} bytes long."); - - public static T FromBegin(this T stream) where T : Stream => stream.SetPosition(0); - - public static T SetPosition(this T stream, long position) where T : Stream - { - stream.Seek(position, SeekOrigin.Begin); - return stream; - } - - public static T MustReadAndSeek(this T stream) where T : Stream - { - if (!stream.CanRead || !stream.CanSeek) - throw ReadSeekException; - return stream; - } - - public static T MustWriteAndSeek(this T stream) where T : Stream - { - if (!stream.CanWrite || !stream.CanSeek) - throw WriteSeekException; - return stream; - } - - public static T MustHaveHeaderLengthOf(this T stream, long minHeaderLength) where T : Stream - { - if (stream.Length < minHeaderLength) - throw InvalidHeaderLengthException(minHeaderLength); - return stream; - } - - public static T AlignPosition(this T stream, int alignValue) where T : Stream => - stream.SetPosition(Helpers.Align((int)stream.Position, alignValue)); - - public static List ReadList(this Stream stream, int offset, int count) - where T : class - { - stream.Position = offset; - return stream.ReadList(count); - } - - public static List ReadList(this Stream stream, int count) - where T : class - { - return Enumerable.Range(0, count) - .Select(x => BinaryMapping.ReadObject(stream, (int)stream.Position)) - .ToList(); - } - - unsafe public static short ReadInt16(this Stream stream) - { - var buffer = new byte[2]; - stream.Read(buffer, 0, 2); - fixed (byte* ptr = buffer) - return *(short*)ptr; - } - - unsafe public static ushort ReadUInt16(this Stream stream) - { - var buffer = new byte[2]; - stream.Read(buffer, 0, 2); - fixed (byte* ptr = buffer) - return *(ushort*)ptr; - } - - unsafe public static int ReadInt32(this Stream stream) - { - var buffer = new byte[4]; - stream.Read(buffer, 0, 4); - fixed (byte* ptr = buffer) - return *(int*)ptr; - } - - unsafe public static uint ReadUInt32(this Stream stream) - { - var buffer = new byte[4]; - stream.Read(buffer, 0, 4); - fixed (byte* ptr = buffer) - return *(uint*)ptr; - } - - unsafe public static long ReadInt64(this Stream stream) - { - var buffer = new byte[8]; - stream.Read(buffer, 0, 8); - fixed (byte* ptr = buffer) - return *(long*)ptr; - } - - unsafe public static ulong ReadUInt64(this Stream stream) - { - var buffer = new byte[8]; - stream.Read(buffer, 0, 8); - fixed (byte* ptr = buffer) - return *(ulong*)ptr; - } - - unsafe public static float ReadSingle(this Stream stream) - { - var buffer = new byte[4]; - stream.Read(buffer, 0, 4); - fixed (byte* ptr = buffer) - return *(float*)ptr; - } - - unsafe public static float ReadFloat(this Stream stream) => stream.ReadSingle(); - - unsafe public static double ReadDouble(this Stream stream) - { - var buffer = new byte[8]; - stream.Read(buffer, 0, 8); - fixed (byte* ptr = buffer) - return *(double*)ptr; - } - - unsafe public static Vector2 ReadVector2(this Stream stream) - { - var buffer = new byte[2 * sizeof(float)]; - stream.Read(buffer, 0, 2 * sizeof(float)); - fixed (byte* ptr = buffer) - return *(Vector2*)ptr; - } - - unsafe public static Vector3 ReadVector3(this Stream stream) - { - var buffer = new byte[3 * sizeof(float)]; - stream.Read(buffer, 0, 3 * sizeof(float)); - fixed (byte* ptr = buffer) - return *(Vector3*)ptr; - } - - unsafe public static Vector4 ReadVector4(this Stream stream) - { - var buffer = new byte[4 * sizeof(float)]; - stream.Read(buffer, 0, 4 * sizeof(float)); - fixed (byte* ptr = buffer) - return *(Vector4*)ptr; - } - - unsafe public static Matrix4x4 ReadMatrix4x4(this Stream stream) - { - var buffer = new byte[4 * 4 * sizeof(float)]; - stream.Read(buffer, 0, 4 * 4 * sizeof(float)); - fixed (byte* ptr = buffer) - return *(Matrix4x4*)ptr; - } - - public static List ReadInt32List(this Stream stream, int offset, int count) - { - stream.Position = offset; - return stream.ReadInt32List(count); - } - - public static List ReadInt32List(this Stream stream, int count) - { - var reader = new BinaryReader(stream); - return Enumerable.Range(0, count) - .Select(x => reader.ReadInt32()) - .ToList(); - } - - public static byte[] ReadBytes(this Stream stream) => - stream.ReadBytes((int)(stream.Length - stream.Position)); - - public static byte[] ReadBytes(this Stream stream, int length) - { - var data = new byte[length]; - stream.Read(data, 0, length); - return data; - } - - public static byte[] ReadAllBytes(this Stream stream) - { - var data = stream.SetPosition(0).ReadBytes(); - stream.Position = 0; - return data; - } - - public static string ReadString(this Stream stream, int maxLength, Encoding encoding) - { - var data = stream.ReadBytes(maxLength); - var terminatorIndex = Array.FindIndex(data, x => x == 0); - return encoding.GetString(data, 0, terminatorIndex < 0 ? maxLength : terminatorIndex); - } - - public static byte PeekByte(this Stream stream) => stream.Peek(x => (byte)x.ReadByte()); - public static short PeekInt16(this Stream stream) => stream.Peek(x => x.ReadInt16()); - public static ushort PeekUInt16(this Stream stream) => stream.Peek(x => x.ReadUInt16()); - public static int PeekInt32(this Stream stream) => stream.Peek(x => x.ReadInt32()); - public static uint PeekUInt32(this Stream stream) => stream.Peek(x => x.ReadUInt32()); - public static long PeekInt64(this Stream stream) => stream.Peek(x => x.ReadInt64()); - public static ulong PeekUInt64(this Stream stream) => stream.Peek(x => x.ReadUInt64()); - - public static T Peek(this Stream stream, Func func) - { - var currentPosition = stream.Position; - var result = func(stream); - stream.SetPosition(currentPosition); - return result; - } - - public static int WriteList(this Stream stream, IEnumerable items) - where T : class - { - var oldPosition = (int)stream.Position; - foreach (var item in items) - BinaryMapping.WriteObject(stream, item, oldPosition); - - return (int)stream.Position - oldPosition; - } - - public static void Write(this Stream stream, byte[] data) => - stream.Write(data, 0, data.Length); - - public static int Write(this Stream stream, IEnumerable items) - { - var oldPosition = (int)stream.Position; - var writer = new BinaryWriter(stream); - foreach (var item in items) - writer.Write(item); - - return (int)stream.Position - oldPosition; - } - - unsafe public static void Write(this Stream stream, byte value) => stream.WriteByte(value); - unsafe public static void Write(this Stream stream, sbyte value) => stream.WriteByte((byte)value); - unsafe public static void Write(this Stream stream, char value) => stream.WriteByte((byte)value); - unsafe public static void Write(this Stream stream, short value) - { - var buffer = new byte[2]; - fixed (byte* ptr = buffer) - *(short*)ptr = value; - stream.Write(buffer, 0, 2); - } - unsafe public static void Write(this Stream stream, ushort value) - { - var buffer = new byte[2]; - fixed (byte* ptr = buffer) - *(ushort*)ptr = value; - stream.Write(buffer, 0, 2); - } - unsafe public static void Write(this Stream stream, int value) - { - var buffer = new byte[4]; - fixed (byte* ptr = buffer) - *(int*)ptr = value; - stream.Write(buffer, 0, 4); - } - unsafe public static void Write(this Stream stream, uint value) - { - var buffer = new byte[4]; - fixed (byte* ptr = buffer) - *(uint*)ptr = value; - stream.Write(buffer, 0, 4); - } - unsafe public static void Write(this Stream stream, long value) - { - var buffer = new byte[8]; - fixed (byte* ptr = buffer) - *(long*)ptr = value; - stream.Write(buffer, 0, 8); - } - unsafe public static void Write(this Stream stream, ulong value) - { - var buffer = new byte[8]; - fixed (byte* ptr = buffer) - *(ulong*)ptr = value; - stream.Write(buffer, 0, 8); - } - unsafe public static void Write(this Stream stream, float value) - { - var buffer = new byte[4]; - fixed (byte* ptr = buffer) - *(float*)ptr = value; - stream.Write(buffer, 0, 4); - } - unsafe public static void Write(this Stream stream, Vector2 value) - { - var buffer = new byte[2 * sizeof(float)]; - fixed (byte* ptr = buffer) - *(Vector2*)ptr = value; - stream.Write(buffer, 0, 2 * sizeof(float)); - } - unsafe public static void Write(this Stream stream, Vector3 value) - { - var buffer = new byte[3 * sizeof(float)]; - fixed (byte* ptr = buffer) - *(Vector3*)ptr = value; - stream.Write(buffer, 0, 3 * sizeof(float)); - } - unsafe public static void Write(this Stream stream, Vector4 value) - { - var buffer = new byte[4 * sizeof(float)]; - fixed (byte* ptr = buffer) - *(Vector4*)ptr = value; - stream.Write(buffer, 0, 4 * sizeof(float)); - } - unsafe public static void Write(this Stream stream, Matrix4x4 value) - { - var buffer = new byte[4 * 4 * sizeof(float)]; - fixed (byte* ptr = buffer) - *(Matrix4x4*)ptr = value; - stream.Write(buffer, 0, 4 * 4 * sizeof(float)); - } - - public static void Copy(this Stream source, Stream destination, int length, int bufferSize = 65536) - { - int read; - byte[] buffer = new byte[Math.Min(length, bufferSize)]; - - while ((read = source.Read(buffer, 0, Math.Min(length, bufferSize))) != 0) - { - destination.Write(buffer, 0, read); - length -= read; - } - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Numerics; +using System.Text; +using Xe.BinaryMapper; + +namespace OpenKh.Common +{ + public static class StreamExtensions + { + private static readonly InvalidDataException ReadSeekException = new InvalidDataException($"Stream must be readable and seekable."); + private static readonly InvalidDataException WriteSeekException = new InvalidDataException($"Stream must be writable and seekable."); + private static readonly Func InvalidHeaderLengthException = (minHeaderLength) => + new InvalidDataException($"Invalid header: stream must be at least {minHeaderLength} bytes long."); + + public static T FromBegin(this T stream) where T : Stream => stream.SetPosition(0); + + public static T SetPosition(this T stream, long position) where T : Stream + { + stream.Seek(position, SeekOrigin.Begin); + return stream; + } + + public static T MustReadAndSeek(this T stream) where T : Stream + { + if (!stream.CanRead || !stream.CanSeek) + throw ReadSeekException; + return stream; + } + + public static T MustWriteAndSeek(this T stream) where T : Stream + { + if (!stream.CanWrite || !stream.CanSeek) + throw WriteSeekException; + return stream; + } + + public static T MustHaveHeaderLengthOf(this T stream, long minHeaderLength) where T : Stream + { + if (stream.Length < minHeaderLength) + throw InvalidHeaderLengthException(minHeaderLength); + return stream; + } + + public static T AlignPosition(this T stream, int alignValue) where T : Stream => + stream.SetPosition(Helpers.Align((int)stream.Position, alignValue)); + + public static List ReadList(this Stream stream, int offset, int count) + where T : class + { + stream.Position = offset; + return stream.ReadList(count); + } + + public static List ReadList(this Stream stream, int count) + where T : class + { + return Enumerable.Range(0, count) + .Select(x => BinaryMapping.ReadObject(stream, (int)stream.Position)) + .ToList(); + } + + unsafe public static short ReadInt16(this Stream stream) + { + var buffer = new byte[2]; + stream.Read(buffer, 0, 2); + fixed (byte* ptr = buffer) + return *(short*)ptr; + } + + unsafe public static ushort ReadUInt16(this Stream stream) + { + var buffer = new byte[2]; + stream.Read(buffer, 0, 2); + fixed (byte* ptr = buffer) + return *(ushort*)ptr; + } + + unsafe public static int ReadInt32(this Stream stream) + { + var buffer = new byte[4]; + stream.Read(buffer, 0, 4); + fixed (byte* ptr = buffer) + return *(int*)ptr; + } + + unsafe public static uint ReadUInt32(this Stream stream) + { + var buffer = new byte[4]; + stream.Read(buffer, 0, 4); + fixed (byte* ptr = buffer) + return *(uint*)ptr; + } + + unsafe public static long ReadInt64(this Stream stream) + { + var buffer = new byte[8]; + stream.Read(buffer, 0, 8); + fixed (byte* ptr = buffer) + return *(long*)ptr; + } + + unsafe public static ulong ReadUInt64(this Stream stream) + { + var buffer = new byte[8]; + stream.Read(buffer, 0, 8); + fixed (byte* ptr = buffer) + return *(ulong*)ptr; + } + + unsafe public static float ReadSingle(this Stream stream) + { + var buffer = new byte[4]; + stream.Read(buffer, 0, 4); + fixed (byte* ptr = buffer) + return *(float*)ptr; + } + + unsafe public static float ReadFloat(this Stream stream) => stream.ReadSingle(); + + unsafe public static double ReadDouble(this Stream stream) + { + var buffer = new byte[8]; + stream.Read(buffer, 0, 8); + fixed (byte* ptr = buffer) + return *(double*)ptr; + } + + unsafe public static Vector2 ReadVector2(this Stream stream) + { + var buffer = new byte[2 * sizeof(float)]; + stream.Read(buffer, 0, 2 * sizeof(float)); + fixed (byte* ptr = buffer) + return *(Vector2*)ptr; + } + + unsafe public static Vector3 ReadVector3(this Stream stream) + { + var buffer = new byte[3 * sizeof(float)]; + stream.Read(buffer, 0, 3 * sizeof(float)); + fixed (byte* ptr = buffer) + return *(Vector3*)ptr; + } + + unsafe public static Vector4 ReadVector4(this Stream stream) + { + var buffer = new byte[4 * sizeof(float)]; + stream.Read(buffer, 0, 4 * sizeof(float)); + fixed (byte* ptr = buffer) + return *(Vector4*)ptr; + } + + unsafe public static Matrix4x4 ReadMatrix4x4(this Stream stream) + { + var buffer = new byte[4 * 4 * sizeof(float)]; + stream.Read(buffer, 0, 4 * 4 * sizeof(float)); + fixed (byte* ptr = buffer) + return *(Matrix4x4*)ptr; + } + + public static List ReadInt32List(this Stream stream, int offset, int count) + { + stream.Position = offset; + return stream.ReadInt32List(count); + } + + public static List ReadInt32List(this Stream stream, int count) + { + var reader = new BinaryReader(stream); + return Enumerable.Range(0, count) + .Select(x => reader.ReadInt32()) + .ToList(); + } + + public static byte[] ReadBytes(this Stream stream) => + stream.ReadBytes((int)(stream.Length - stream.Position)); + + public static byte[] ReadBytes(this Stream stream, int length) + { + var data = new byte[length]; + stream.Read(data, 0, length); + return data; + } + + public static byte[] ReadAllBytes(this Stream stream) + { + var data = stream.SetPosition(0).ReadBytes(); + stream.Position = 0; + return data; + } + + public static string ReadString(this Stream stream, int maxLength, Encoding encoding) + { + var data = stream.ReadBytes(maxLength); + var terminatorIndex = Array.FindIndex(data, x => x == 0); + return encoding.GetString(data, 0, terminatorIndex < 0 ? maxLength : terminatorIndex); + } + + public static byte PeekByte(this Stream stream) => stream.Peek(x => (byte)x.ReadByte()); + public static short PeekInt16(this Stream stream) => stream.Peek(x => x.ReadInt16()); + public static ushort PeekUInt16(this Stream stream) => stream.Peek(x => x.ReadUInt16()); + public static int PeekInt32(this Stream stream) => stream.Peek(x => x.ReadInt32()); + public static uint PeekUInt32(this Stream stream) => stream.Peek(x => x.ReadUInt32()); + public static long PeekInt64(this Stream stream) => stream.Peek(x => x.ReadInt64()); + public static ulong PeekUInt64(this Stream stream) => stream.Peek(x => x.ReadUInt64()); + + public static T Peek(this Stream stream, Func func) + { + var currentPosition = stream.Position; + var result = func(stream); + stream.SetPosition(currentPosition); + return result; + } + + public static int WriteList(this Stream stream, IEnumerable items) + where T : class + { + var oldPosition = (int)stream.Position; + foreach (var item in items) + BinaryMapping.WriteObject(stream, item, oldPosition); + + return (int)stream.Position - oldPosition; + } + + public static void Write(this Stream stream, byte[] data) => + stream.Write(data, 0, data.Length); + + public static int Write(this Stream stream, IEnumerable items) + { + var oldPosition = (int)stream.Position; + var writer = new BinaryWriter(stream); + foreach (var item in items) + writer.Write(item); + + return (int)stream.Position - oldPosition; + } + + unsafe public static void Write(this Stream stream, byte value) => stream.WriteByte(value); + unsafe public static void Write(this Stream stream, sbyte value) => stream.WriteByte((byte)value); + unsafe public static void Write(this Stream stream, char value) => stream.WriteByte((byte)value); + unsafe public static void Write(this Stream stream, short value) + { + var buffer = new byte[2]; + fixed (byte* ptr = buffer) + *(short*)ptr = value; + stream.Write(buffer, 0, 2); + } + unsafe public static void Write(this Stream stream, ushort value) + { + var buffer = new byte[2]; + fixed (byte* ptr = buffer) + *(ushort*)ptr = value; + stream.Write(buffer, 0, 2); + } + unsafe public static void Write(this Stream stream, int value) + { + var buffer = new byte[4]; + fixed (byte* ptr = buffer) + *(int*)ptr = value; + stream.Write(buffer, 0, 4); + } + unsafe public static void Write(this Stream stream, uint value) + { + var buffer = new byte[4]; + fixed (byte* ptr = buffer) + *(uint*)ptr = value; + stream.Write(buffer, 0, 4); + } + unsafe public static void Write(this Stream stream, long value) + { + var buffer = new byte[8]; + fixed (byte* ptr = buffer) + *(long*)ptr = value; + stream.Write(buffer, 0, 8); + } + unsafe public static void Write(this Stream stream, ulong value) + { + var buffer = new byte[8]; + fixed (byte* ptr = buffer) + *(ulong*)ptr = value; + stream.Write(buffer, 0, 8); + } + unsafe public static void Write(this Stream stream, float value) + { + var buffer = new byte[4]; + fixed (byte* ptr = buffer) + *(float*)ptr = value; + stream.Write(buffer, 0, 4); + } + unsafe public static void Write(this Stream stream, Vector2 value) + { + var buffer = new byte[2 * sizeof(float)]; + fixed (byte* ptr = buffer) + *(Vector2*)ptr = value; + stream.Write(buffer, 0, 2 * sizeof(float)); + } + unsafe public static void Write(this Stream stream, Vector3 value) + { + var buffer = new byte[3 * sizeof(float)]; + fixed (byte* ptr = buffer) + *(Vector3*)ptr = value; + stream.Write(buffer, 0, 3 * sizeof(float)); + } + unsafe public static void Write(this Stream stream, Vector4 value) + { + var buffer = new byte[4 * sizeof(float)]; + fixed (byte* ptr = buffer) + *(Vector4*)ptr = value; + stream.Write(buffer, 0, 4 * sizeof(float)); + } + unsafe public static void Write(this Stream stream, Matrix4x4 value) + { + var buffer = new byte[4 * 4 * sizeof(float)]; + fixed (byte* ptr = buffer) + *(Matrix4x4*)ptr = value; + stream.Write(buffer, 0, 4 * 4 * sizeof(float)); + } + + public static void Copy(this Stream source, Stream destination, int length, int bufferSize = 65536) + { + int read; + byte[] buffer = new byte[Math.Min(length, bufferSize)]; + + while ((read = source.Read(buffer, 0, Math.Min(length, bufferSize))) != 0) + { + destination.Write(buffer, 0, read); + length -= read; + } + } + } +} diff --git a/OpenKh.Common/Utils/BitsUtil.cs b/OpenKh.Common/Utils/BitsUtil.cs index 33dbe712e..69e745612 100644 --- a/OpenKh.Common/Utils/BitsUtil.cs +++ b/OpenKh.Common/Utils/BitsUtil.cs @@ -1,30 +1,30 @@ -namespace OpenKh.Common.Utils -{ - public static class BitsUtil - { - public class Int - { - public static bool GetBit(int Data, int position) => GetBits(Data, position, 1) != 0; - - public static int SetBit(int Data, int position, bool value) => SetBits(Data, position, 1, value ? 1 : 0); - public static uint SetBit(uint Data, int position, bool value) => SetBits(Data, position, 1, (uint)(value ? 1 : 0)); - - public static int GetBits(int Data, int position, int size) - { - var mask = (1 << size) - 1; - return (Data >> position) & mask; - } - - public static int SetBits(int Data, int position, int size, int value) - { - var mask = (int)((1 << size) - 1U); - return (Data & ~(mask << position) | ((value & mask) << position)); - } - - public static uint SetBits(uint Data, int position, int size, uint value) - { - var mask = (int)((1 << size) - 1U); - return (uint)(Data & ~(mask << position) | ((value & mask) << position)); +namespace OpenKh.Common.Utils +{ + public static class BitsUtil + { + public class Int + { + public static bool GetBit(int Data, int position) => GetBits(Data, position, 1) != 0; + + public static int SetBit(int Data, int position, bool value) => SetBits(Data, position, 1, value ? 1 : 0); + public static uint SetBit(uint Data, int position, bool value) => SetBits(Data, position, 1, (uint)(value ? 1 : 0)); + + public static int GetBits(int Data, int position, int size) + { + var mask = (1 << size) - 1; + return (Data >> position) & mask; + } + + public static int SetBits(int Data, int position, int size, int value) + { + var mask = (int)((1 << size) - 1U); + return (Data & ~(mask << position) | ((value & mask) << position)); + } + + public static uint SetBits(uint Data, int position, int size, uint value) + { + var mask = (int)((1 << size) - 1U); + return (uint)(Data & ~(mask << position) | ((value & mask) << position)); } public static int SignExtend(int value, int position, int bit) @@ -39,26 +39,26 @@ public static int SignExtend(int value, int position, int bit) { return value; } - } - } - - public class Long - { - public static bool GetBit(long Data, int position) => GetBits(Data, position, 1) != 0; - - public static long SetBit(long Data, int position, bool value) => SetBits(Data, position, 1, value ? 1 : 0); - - public static long GetBits(long Data, int position, int size) - { - var mask = (1 << size) - 1; - return (Data >> position) & mask; - } - - public static long SetBits(long Data, int position, int size, int value) - { - var mask = (1 << size) - 1U; - return Data & ~(mask << position) | ((value & mask) << position); - } - } - } -} + } + } + + public class Long + { + public static bool GetBit(long Data, int position) => GetBits(Data, position, 1) != 0; + + public static long SetBit(long Data, int position, bool value) => SetBits(Data, position, 1, value ? 1 : 0); + + public static long GetBits(long Data, int position, int size) + { + var mask = (1 << size) - 1; + return (Data >> position) & mask; + } + + public static long SetBits(long Data, int position, int size, int value) + { + var mask = (1 << size) - 1U; + return Data & ~(mask << position) | ((value & mask) << position); + } + } + } +} diff --git a/OpenKh.Engine.MonoGame/Extensions.cs b/OpenKh.Engine.MonoGame/Extensions.cs index 95890f520..92fc4e697 100644 --- a/OpenKh.Engine.MonoGame/Extensions.cs +++ b/OpenKh.Engine.MonoGame/Extensions.cs @@ -1,81 +1,81 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Engine.Extensions; -using OpenKh.Engine.Renders; -using OpenKh.Imaging; -using OpenKh.Kh2; - -namespace OpenKh.Engine.MonoGame -{ - public static class Extensions - { - public static Texture2D CreateTexture(this IImageRead image, GraphicsDevice graphicsDevice) - { - var size = image.Size; - var texture = new Texture2D(graphicsDevice, size.Width, size.Height); - texture.SetData(image.AsBgra8888()); - - return texture; - } - - public static void SetRenderTexture(this KingdomShader shader, EffectPass pass, IKingdomTexture texture) - { - if (shader.Texture0 != texture.Texture2D) - { - shader.Texture0 = texture.Texture2D; - switch (texture.AddressU) - { - case ModelTexture.TextureWrapMode.Clamp: - shader.SetTextureRegionUDefault(); - shader.TextureWrapModeU = TextureWrapMode.Clamp; - break; - case ModelTexture.TextureWrapMode.Repeat: - shader.SetTextureRegionUDefault(); - shader.TextureWrapModeU = TextureWrapMode.Repeat; - break; - case ModelTexture.TextureWrapMode.RegionClamp: - shader.SetTextureRegionU(texture.RegionU); - shader.TextureWrapModeU = TextureWrapMode.Clamp; - break; - case ModelTexture.TextureWrapMode.RegionRepeat: - shader.SetTextureRegionU(texture.RegionU); - shader.TextureWrapModeU = TextureWrapMode.Repeat; - break; - } - switch (texture.AddressV) - { - case ModelTexture.TextureWrapMode.Clamp: - shader.SetTextureRegionVDefault(); - shader.TextureWrapModeV = TextureWrapMode.Clamp; - break; - case ModelTexture.TextureWrapMode.Repeat: - shader.SetTextureRegionVDefault(); - shader.TextureWrapModeV = TextureWrapMode.Repeat; - break; - case ModelTexture.TextureWrapMode.RegionClamp: - shader.SetTextureRegionV(texture.RegionV); - shader.TextureWrapModeV = TextureWrapMode.Clamp; - break; - case ModelTexture.TextureWrapMode.RegionRepeat: - shader.SetTextureRegionV(texture.RegionV); - shader.TextureWrapModeV = TextureWrapMode.Repeat; - break; - } - - pass.Apply(); - } - } - - public static void SetRenderTexture(this KingdomShader shader, EffectPass pass, Texture2D texture) - { - if (shader.Texture0 != texture) - { - shader.Texture0 = texture; - shader.SetTextureRegionVDefault(); - shader.SetTextureRegionUDefault(); - shader.TextureWrapModeU = TextureWrapMode.Clamp; - shader.TextureWrapModeV = TextureWrapMode.Clamp; - pass.Apply(); - } - } - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Engine.Extensions; +using OpenKh.Engine.Renders; +using OpenKh.Imaging; +using OpenKh.Kh2; + +namespace OpenKh.Engine.MonoGame +{ + public static class Extensions + { + public static Texture2D CreateTexture(this IImageRead image, GraphicsDevice graphicsDevice) + { + var size = image.Size; + var texture = new Texture2D(graphicsDevice, size.Width, size.Height); + texture.SetData(image.AsBgra8888()); + + return texture; + } + + public static void SetRenderTexture(this KingdomShader shader, EffectPass pass, IKingdomTexture texture) + { + if (shader.Texture0 != texture.Texture2D) + { + shader.Texture0 = texture.Texture2D; + switch (texture.AddressU) + { + case ModelTexture.TextureWrapMode.Clamp: + shader.SetTextureRegionUDefault(); + shader.TextureWrapModeU = TextureWrapMode.Clamp; + break; + case ModelTexture.TextureWrapMode.Repeat: + shader.SetTextureRegionUDefault(); + shader.TextureWrapModeU = TextureWrapMode.Repeat; + break; + case ModelTexture.TextureWrapMode.RegionClamp: + shader.SetTextureRegionU(texture.RegionU); + shader.TextureWrapModeU = TextureWrapMode.Clamp; + break; + case ModelTexture.TextureWrapMode.RegionRepeat: + shader.SetTextureRegionU(texture.RegionU); + shader.TextureWrapModeU = TextureWrapMode.Repeat; + break; + } + switch (texture.AddressV) + { + case ModelTexture.TextureWrapMode.Clamp: + shader.SetTextureRegionVDefault(); + shader.TextureWrapModeV = TextureWrapMode.Clamp; + break; + case ModelTexture.TextureWrapMode.Repeat: + shader.SetTextureRegionVDefault(); + shader.TextureWrapModeV = TextureWrapMode.Repeat; + break; + case ModelTexture.TextureWrapMode.RegionClamp: + shader.SetTextureRegionV(texture.RegionV); + shader.TextureWrapModeV = TextureWrapMode.Clamp; + break; + case ModelTexture.TextureWrapMode.RegionRepeat: + shader.SetTextureRegionV(texture.RegionV); + shader.TextureWrapModeV = TextureWrapMode.Repeat; + break; + } + + pass.Apply(); + } + } + + public static void SetRenderTexture(this KingdomShader shader, EffectPass pass, Texture2D texture) + { + if (shader.Texture0 != texture) + { + shader.Texture0 = texture; + shader.SetTextureRegionVDefault(); + shader.SetTextureRegionUDefault(); + shader.TextureWrapModeU = TextureWrapMode.Clamp; + shader.TextureWrapModeV = TextureWrapMode.Clamp; + pass.Apply(); + } + } + } +} diff --git a/OpenKh.Engine.MonoGame/GraphicsDeviceExtensions.cs b/OpenKh.Engine.MonoGame/GraphicsDeviceExtensions.cs index 3e6c9d9c1..2fd9f2bd9 100644 --- a/OpenKh.Engine.MonoGame/GraphicsDeviceExtensions.cs +++ b/OpenKh.Engine.MonoGame/GraphicsDeviceExtensions.cs @@ -1,34 +1,34 @@ -using Microsoft.Xna.Framework.Graphics; - -namespace OpenKh.Engine.MonoGame -{ - public static class GraphicsDeviceExtensions - { - public static void RenderMeshNew(this GraphicsDevice graphics, KingdomShader shader, - EffectPass pass, IMonoGameModel model, bool passRenderOpaque) - { - if (model?.MeshDescriptors == null) - return; - - foreach (var meshDescriptor in model.MeshDescriptors) - { - if (meshDescriptor.Indices.Length == 0 || meshDescriptor.IsOpaque != passRenderOpaque) - continue; - - var textureIndex = meshDescriptor.TextureIndex & 0xffff; - if (textureIndex < model.Textures.Length) - shader.SetRenderTexture(pass, model.Textures[textureIndex]); - - graphics.DrawUserIndexedPrimitives( - PrimitiveType.TriangleList, - meshDescriptor.Vertices, - 0, - meshDescriptor.Vertices.Length, - meshDescriptor.Indices, - 0, - meshDescriptor.Indices.Length / 3, - MeshLoader.PositionColoredTexturedVertexDeclaration); - } - } - } -} +using Microsoft.Xna.Framework.Graphics; + +namespace OpenKh.Engine.MonoGame +{ + public static class GraphicsDeviceExtensions + { + public static void RenderMeshNew(this GraphicsDevice graphics, KingdomShader shader, + EffectPass pass, IMonoGameModel model, bool passRenderOpaque) + { + if (model?.MeshDescriptors == null) + return; + + foreach (var meshDescriptor in model.MeshDescriptors) + { + if (meshDescriptor.Indices.Length == 0 || meshDescriptor.IsOpaque != passRenderOpaque) + continue; + + var textureIndex = meshDescriptor.TextureIndex & 0xffff; + if (textureIndex < model.Textures.Length) + shader.SetRenderTexture(pass, model.Textures[textureIndex]); + + graphics.DrawUserIndexedPrimitives( + PrimitiveType.TriangleList, + meshDescriptor.Vertices, + 0, + meshDescriptor.Vertices.Length, + meshDescriptor.Indices, + 0, + meshDescriptor.Indices.Length / 3, + MeshLoader.PositionColoredTexturedVertexDeclaration); + } + } + } +} diff --git a/OpenKh.Engine.MonoGame/IMonoGameModel.cs b/OpenKh.Engine.MonoGame/IMonoGameModel.cs index 03a5348c1..b6e031031 100644 --- a/OpenKh.Engine.MonoGame/IMonoGameModel.cs +++ b/OpenKh.Engine.MonoGame/IMonoGameModel.cs @@ -1,12 +1,12 @@ -using OpenKh.Engine.Parsers; -using System.Collections.Generic; - -namespace OpenKh.Engine.MonoGame -{ - public interface IMonoGameModel - { - List MeshDescriptors { get; } - - IKingdomTexture[] Textures { get; } - } -} +using OpenKh.Engine.Parsers; +using System.Collections.Generic; + +namespace OpenKh.Engine.MonoGame +{ + public interface IMonoGameModel + { + List MeshDescriptors { get; } + + IKingdomTexture[] Textures { get; } + } +} diff --git a/OpenKh.Engine.MonoGame/KingdomShader.cs b/OpenKh.Engine.MonoGame/KingdomShader.cs index 04de20771..9352c4290 100644 --- a/OpenKh.Engine.MonoGame/KingdomShader.cs +++ b/OpenKh.Engine.MonoGame/KingdomShader.cs @@ -1,126 +1,126 @@ -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Engine.Renders; -using System; -using System.Numerics; -using System.Runtime.CompilerServices; -using xna = Microsoft.Xna.Framework; - -namespace OpenKh.Engine.MonoGame -{ - public class KingdomShader : IDisposable - { - private static Matrix4x4 MatrixIdentity = Matrix4x4.Identity; - public static Vector2 DefaultTextureRegion = new Vector2(0, 1); - - private readonly EffectParameter _modelViewParameter; - private readonly EffectParameter _worldViewParameter; - private readonly EffectParameter _projectionViewParameter; - private readonly EffectParameter _parameterTextureRegionU; - private readonly EffectParameter _parameterTextureRegionV; - private readonly EffectParameter _parameterTextureWrapModeU; - private readonly EffectParameter _parameterTextureWrapModeV; - private readonly EffectParameter _parameterTexture0; - private readonly EffectParameter _parameterUseAlphaMask; - - public KingdomShader(ContentManager contentManager) - { - Effect = contentManager.Load("KingdomShader"); - _modelViewParameter = Effect.Parameters["ModelView"]; - _worldViewParameter = Effect.Parameters["WorldView"]; - _projectionViewParameter = Effect.Parameters["ProjectionView"]; - _parameterTextureRegionU = Effect.Parameters["TextureRegionU"]; - _parameterTextureRegionV = Effect.Parameters["TextureRegionV"]; - _parameterTextureWrapModeU = Effect.Parameters["TextureWrapModeU"]; - _parameterTextureWrapModeV = Effect.Parameters["TextureWrapModeV"]; - _parameterTexture0 = Effect.Parameters["Texture0"]; - _parameterUseAlphaMask = Effect.Parameters["UseAlphaMask"]; - - SetModelViewIdentity(); - SetWorldViewIdentity(); - SetProjectionViewIdentity(); - SetTextureRegionUDefault(); - SetTextureRegionVDefault(); - TextureWrapModeU = TextureWrapMode.Clamp; - TextureWrapModeV = TextureWrapMode.Clamp; - } - - public Effect Effect { get; } - - public void SetModelViewIdentity() => - _modelViewParameter.SetValue(Unsafe.As(ref MatrixIdentity)); - - public void SetModelView(Matrix4x4 matrix) => - _modelViewParameter.SetValue(Unsafe.As(ref matrix)); - - public void SetModelView(ref Matrix4x4 matrix) => - _modelViewParameter.SetValue(Unsafe.As(ref matrix)); - - public void SetWorldViewIdentity() => - _worldViewParameter.SetValue(Unsafe.As(ref MatrixIdentity)); - - public void SetWorldView(Matrix4x4 matrix) => - _worldViewParameter.SetValue(Unsafe.As(ref matrix)); - - public void SetWorldView(ref Matrix4x4 matrix) => - _worldViewParameter.SetValue(Unsafe.As(ref matrix)); - - public void SetProjectionViewIdentity() => - _projectionViewParameter.SetValue(Unsafe.As(ref MatrixIdentity)); - - public void SetProjectionView(Matrix4x4 matrix) => - _projectionViewParameter.SetValue(Unsafe.As(ref matrix)); - - public void SetProjectionView(ref Matrix4x4 matrix) => - _projectionViewParameter.SetValue(Unsafe.As(ref matrix)); - - public Texture2D Texture0 - { - get => _parameterTexture0.GetValueTexture2D(); - set => _parameterTexture0.SetValue(value); - } - - public void SetTextureRegionU(Vector2 vector) => - _parameterTextureRegionU.SetValue(Unsafe.As(ref vector)); - public void SetTextureRegionU(ref Vector2 vector) => - _parameterTextureRegionU.SetValue(Unsafe.As(ref vector)); - public void SetTextureRegionUDefault() => - _parameterTextureRegionU.SetValue(Unsafe.As(ref DefaultTextureRegion)); - - public void SetTextureRegionV(Vector2 vector) => - _parameterTextureRegionV.SetValue(Unsafe.As(ref vector)); - public void SetTextureRegionV(ref Vector2 vector) => - _parameterTextureRegionV.SetValue(Unsafe.As(ref vector)); - public void SetTextureRegionVDefault() => - _parameterTextureRegionV.SetValue(Unsafe.As(ref DefaultTextureRegion)); - - public TextureWrapMode TextureWrapModeU - { - get => (TextureWrapMode)_parameterTextureWrapModeU.GetValueInt32(); - set => _parameterTextureWrapModeU.SetValue((int)value); - } - - public TextureWrapMode TextureWrapModeV - { - get => (TextureWrapMode)_parameterTextureWrapModeV.GetValueInt32(); - set => _parameterTextureWrapModeV.SetValue((int)value); - } - - public bool UseAlphaMask - { - get => _parameterUseAlphaMask.GetValueBoolean(); - set => _parameterUseAlphaMask.SetValue(value); - } - - public void Pass(Action action) - { - foreach (var pass in Effect.CurrentTechnique.Passes) - action(pass); - } - - public void Dispose() - { - Effect?.Dispose(); - } - } -} +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Engine.Renders; +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using xna = Microsoft.Xna.Framework; + +namespace OpenKh.Engine.MonoGame +{ + public class KingdomShader : IDisposable + { + private static Matrix4x4 MatrixIdentity = Matrix4x4.Identity; + public static Vector2 DefaultTextureRegion = new Vector2(0, 1); + + private readonly EffectParameter _modelViewParameter; + private readonly EffectParameter _worldViewParameter; + private readonly EffectParameter _projectionViewParameter; + private readonly EffectParameter _parameterTextureRegionU; + private readonly EffectParameter _parameterTextureRegionV; + private readonly EffectParameter _parameterTextureWrapModeU; + private readonly EffectParameter _parameterTextureWrapModeV; + private readonly EffectParameter _parameterTexture0; + private readonly EffectParameter _parameterUseAlphaMask; + + public KingdomShader(ContentManager contentManager) + { + Effect = contentManager.Load("KingdomShader"); + _modelViewParameter = Effect.Parameters["ModelView"]; + _worldViewParameter = Effect.Parameters["WorldView"]; + _projectionViewParameter = Effect.Parameters["ProjectionView"]; + _parameterTextureRegionU = Effect.Parameters["TextureRegionU"]; + _parameterTextureRegionV = Effect.Parameters["TextureRegionV"]; + _parameterTextureWrapModeU = Effect.Parameters["TextureWrapModeU"]; + _parameterTextureWrapModeV = Effect.Parameters["TextureWrapModeV"]; + _parameterTexture0 = Effect.Parameters["Texture0"]; + _parameterUseAlphaMask = Effect.Parameters["UseAlphaMask"]; + + SetModelViewIdentity(); + SetWorldViewIdentity(); + SetProjectionViewIdentity(); + SetTextureRegionUDefault(); + SetTextureRegionVDefault(); + TextureWrapModeU = TextureWrapMode.Clamp; + TextureWrapModeV = TextureWrapMode.Clamp; + } + + public Effect Effect { get; } + + public void SetModelViewIdentity() => + _modelViewParameter.SetValue(Unsafe.As(ref MatrixIdentity)); + + public void SetModelView(Matrix4x4 matrix) => + _modelViewParameter.SetValue(Unsafe.As(ref matrix)); + + public void SetModelView(ref Matrix4x4 matrix) => + _modelViewParameter.SetValue(Unsafe.As(ref matrix)); + + public void SetWorldViewIdentity() => + _worldViewParameter.SetValue(Unsafe.As(ref MatrixIdentity)); + + public void SetWorldView(Matrix4x4 matrix) => + _worldViewParameter.SetValue(Unsafe.As(ref matrix)); + + public void SetWorldView(ref Matrix4x4 matrix) => + _worldViewParameter.SetValue(Unsafe.As(ref matrix)); + + public void SetProjectionViewIdentity() => + _projectionViewParameter.SetValue(Unsafe.As(ref MatrixIdentity)); + + public void SetProjectionView(Matrix4x4 matrix) => + _projectionViewParameter.SetValue(Unsafe.As(ref matrix)); + + public void SetProjectionView(ref Matrix4x4 matrix) => + _projectionViewParameter.SetValue(Unsafe.As(ref matrix)); + + public Texture2D Texture0 + { + get => _parameterTexture0.GetValueTexture2D(); + set => _parameterTexture0.SetValue(value); + } + + public void SetTextureRegionU(Vector2 vector) => + _parameterTextureRegionU.SetValue(Unsafe.As(ref vector)); + public void SetTextureRegionU(ref Vector2 vector) => + _parameterTextureRegionU.SetValue(Unsafe.As(ref vector)); + public void SetTextureRegionUDefault() => + _parameterTextureRegionU.SetValue(Unsafe.As(ref DefaultTextureRegion)); + + public void SetTextureRegionV(Vector2 vector) => + _parameterTextureRegionV.SetValue(Unsafe.As(ref vector)); + public void SetTextureRegionV(ref Vector2 vector) => + _parameterTextureRegionV.SetValue(Unsafe.As(ref vector)); + public void SetTextureRegionVDefault() => + _parameterTextureRegionV.SetValue(Unsafe.As(ref DefaultTextureRegion)); + + public TextureWrapMode TextureWrapModeU + { + get => (TextureWrapMode)_parameterTextureWrapModeU.GetValueInt32(); + set => _parameterTextureWrapModeU.SetValue((int)value); + } + + public TextureWrapMode TextureWrapModeV + { + get => (TextureWrapMode)_parameterTextureWrapModeV.GetValueInt32(); + set => _parameterTextureWrapModeV.SetValue((int)value); + } + + public bool UseAlphaMask + { + get => _parameterUseAlphaMask.GetValueBoolean(); + set => _parameterUseAlphaMask.SetValue(value); + } + + public void Pass(Action action) + { + foreach (var pass in Effect.CurrentTechnique.Passes) + action(pass); + } + + public void Dispose() + { + Effect?.Dispose(); + } + } +} diff --git a/OpenKh.Engine.MonoGame/KingdomTexture.cs b/OpenKh.Engine.MonoGame/KingdomTexture.cs index a7bc1aec0..941819076 100644 --- a/OpenKh.Engine.MonoGame/KingdomTexture.cs +++ b/OpenKh.Engine.MonoGame/KingdomTexture.cs @@ -1,97 +1,97 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Imaging; -using System; -using System.IO; -using System.Numerics; - -namespace OpenKh.Engine.MonoGame -{ - public interface IKingdomTexture : IDisposable - { - Texture2D Texture2D { get; } - ModelTexture.TextureWrapMode AddressU { get; } - ModelTexture.TextureWrapMode AddressV { get; } - Vector2 RegionU { get; } - Vector2 RegionV { get; } - } - - public class PngKingdomTexture : IKingdomTexture - { - private static readonly Vector2 DefaultRegion = new Vector2(0, 1); - - public PngKingdomTexture(string filePath, GraphicsDevice graphics) - { - Texture2D = File.OpenRead(filePath) - .Using(x => Texture2D.FromStream(graphics, x)); - } - - public Texture2D Texture2D { get; } - - public ModelTexture.TextureWrapMode AddressU => ModelTexture.TextureWrapMode.Repeat; - public ModelTexture.TextureWrapMode AddressV => ModelTexture.TextureWrapMode.Repeat; - - public Vector2 RegionU => DefaultRegion; - public Vector2 RegionV => DefaultRegion; - - public void Dispose() - { - Texture2D?.Dispose(); - } - } - - public class Tim2KingdomTexture : IKingdomTexture - { - private static readonly Vector2 DefaultRegion = new Vector2(0, 1); - - public Tim2KingdomTexture(Tm2 tm2, GraphicsDevice graphics) - { - Texture2D = tm2.CreateTexture(graphics); - } - - public Texture2D Texture2D { get; } - - public ModelTexture.TextureWrapMode AddressU => ModelTexture.TextureWrapMode.Repeat; - public ModelTexture.TextureWrapMode AddressV => ModelTexture.TextureWrapMode.Repeat; - - public Vector2 RegionU => DefaultRegion; - public Vector2 RegionV => DefaultRegion; - - public void Dispose() - { - Texture2D?.Dispose(); - } - } - - public class KingdomTexture : IKingdomTexture - { - public KingdomTexture(ModelTexture.Texture texture, GraphicsDevice graphics) - { - ModelTexture = texture; - Texture2D = texture.CreateTexture(graphics); - } - - public ModelTexture.Texture ModelTexture { get; } - public Texture2D Texture2D { get; } - - public Vector2 RegionU => new Vector2( - (float)Math.Min(ModelTexture.TextureAddressMode.Left, ModelTexture.TextureAddressMode.Right) / Texture2D.Width, - (float)Math.Max(ModelTexture.TextureAddressMode.Left, ModelTexture.TextureAddressMode.Right) / Texture2D.Width); - - public Vector2 RegionV => new Vector2( - (float)Math.Min(ModelTexture.TextureAddressMode.Top, ModelTexture.TextureAddressMode.Bottom) / Texture2D.Height, - (float)Math.Max(ModelTexture.TextureAddressMode.Top, ModelTexture.TextureAddressMode.Bottom) / Texture2D.Height); - - public ModelTexture.TextureWrapMode AddressU => - ModelTexture.TextureAddressMode.AddressU; - - public ModelTexture.TextureWrapMode AddressV => - ModelTexture.TextureAddressMode.AddressV; - - public void Dispose() - { - Texture2D?.Dispose(); - } - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Imaging; +using System; +using System.IO; +using System.Numerics; + +namespace OpenKh.Engine.MonoGame +{ + public interface IKingdomTexture : IDisposable + { + Texture2D Texture2D { get; } + ModelTexture.TextureWrapMode AddressU { get; } + ModelTexture.TextureWrapMode AddressV { get; } + Vector2 RegionU { get; } + Vector2 RegionV { get; } + } + + public class PngKingdomTexture : IKingdomTexture + { + private static readonly Vector2 DefaultRegion = new Vector2(0, 1); + + public PngKingdomTexture(string filePath, GraphicsDevice graphics) + { + Texture2D = File.OpenRead(filePath) + .Using(x => Texture2D.FromStream(graphics, x)); + } + + public Texture2D Texture2D { get; } + + public ModelTexture.TextureWrapMode AddressU => ModelTexture.TextureWrapMode.Repeat; + public ModelTexture.TextureWrapMode AddressV => ModelTexture.TextureWrapMode.Repeat; + + public Vector2 RegionU => DefaultRegion; + public Vector2 RegionV => DefaultRegion; + + public void Dispose() + { + Texture2D?.Dispose(); + } + } + + public class Tim2KingdomTexture : IKingdomTexture + { + private static readonly Vector2 DefaultRegion = new Vector2(0, 1); + + public Tim2KingdomTexture(Tm2 tm2, GraphicsDevice graphics) + { + Texture2D = tm2.CreateTexture(graphics); + } + + public Texture2D Texture2D { get; } + + public ModelTexture.TextureWrapMode AddressU => ModelTexture.TextureWrapMode.Repeat; + public ModelTexture.TextureWrapMode AddressV => ModelTexture.TextureWrapMode.Repeat; + + public Vector2 RegionU => DefaultRegion; + public Vector2 RegionV => DefaultRegion; + + public void Dispose() + { + Texture2D?.Dispose(); + } + } + + public class KingdomTexture : IKingdomTexture + { + public KingdomTexture(ModelTexture.Texture texture, GraphicsDevice graphics) + { + ModelTexture = texture; + Texture2D = texture.CreateTexture(graphics); + } + + public ModelTexture.Texture ModelTexture { get; } + public Texture2D Texture2D { get; } + + public Vector2 RegionU => new Vector2( + (float)Math.Min(ModelTexture.TextureAddressMode.Left, ModelTexture.TextureAddressMode.Right) / Texture2D.Width, + (float)Math.Max(ModelTexture.TextureAddressMode.Left, ModelTexture.TextureAddressMode.Right) / Texture2D.Width); + + public Vector2 RegionV => new Vector2( + (float)Math.Min(ModelTexture.TextureAddressMode.Top, ModelTexture.TextureAddressMode.Bottom) / Texture2D.Height, + (float)Math.Max(ModelTexture.TextureAddressMode.Top, ModelTexture.TextureAddressMode.Bottom) / Texture2D.Height); + + public ModelTexture.TextureWrapMode AddressU => + ModelTexture.TextureAddressMode.AddressU; + + public ModelTexture.TextureWrapMode AddressV => + ModelTexture.TextureAddressMode.AddressV; + + public void Dispose() + { + Texture2D?.Dispose(); + } + } +} diff --git a/OpenKh.Engine.MonoGame/MeshGroup.cs b/OpenKh.Engine.MonoGame/MeshGroup.cs index f1142a918..688905061 100644 --- a/OpenKh.Engine.MonoGame/MeshGroup.cs +++ b/OpenKh.Engine.MonoGame/MeshGroup.cs @@ -1,11 +1,11 @@ -using OpenKh.Engine.Parsers; -using System.Collections.Generic; - -namespace OpenKh.Engine.MonoGame -{ - public class MeshGroup : IMonoGameModel - { - public IKingdomTexture[] Textures { get; set; } - public List MeshDescriptors { get; set; } - } -} +using OpenKh.Engine.Parsers; +using System.Collections.Generic; + +namespace OpenKh.Engine.MonoGame +{ + public class MeshGroup : IMonoGameModel + { + public IKingdomTexture[] Textures { get; set; } + public List MeshDescriptors { get; set; } + } +} diff --git a/OpenKh.Engine.MonoGame/MeshLoader.cs b/OpenKh.Engine.MonoGame/MeshLoader.cs index 6579a546e..656416d28 100644 --- a/OpenKh.Engine.MonoGame/MeshLoader.cs +++ b/OpenKh.Engine.MonoGame/MeshLoader.cs @@ -1,28 +1,28 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Engine.Motion; -using OpenKh.Engine.Parsers; -using OpenKh.Kh2; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Engine.MonoGame -{ - public static class MeshLoader - { - public static VertexDeclaration PositionColoredTexturedVertexDeclaration = - new VertexDeclaration(36, new VertexElement[] - { - new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), - new VertexElement(12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0), - new VertexElement(20, VertexElementFormat.Vector4, VertexElementUsage.Color, 0), - }); - - public static IModelMotion FromKH2(Mdlx model) => - model != null ? new MdlxParser(model) : null; - - public static IEnumerable LoadTextures( - this ModelTexture texture, GraphicsDevice graphics) => texture?.Images? - .Select(texture => new KingdomTexture(texture, graphics)).ToArray() ?? - new KingdomTexture[0]; - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Engine.Motion; +using OpenKh.Engine.Parsers; +using OpenKh.Kh2; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Engine.MonoGame +{ + public static class MeshLoader + { + public static VertexDeclaration PositionColoredTexturedVertexDeclaration = + new VertexDeclaration(36, new VertexElement[] + { + new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), + new VertexElement(12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0), + new VertexElement(20, VertexElementFormat.Vector4, VertexElementUsage.Color, 0), + }); + + public static IModelMotion FromKH2(Mdlx model) => + model != null ? new MdlxParser(model) : null; + + public static IEnumerable LoadTextures( + this ModelTexture texture, GraphicsDevice graphics) => texture?.Images? + .Select(texture => new KingdomTexture(texture, graphics)).ToArray() ?? + new KingdomTexture[0]; + } +} diff --git a/OpenKh.Engine.MonoGame/MonoSpriteDrawing.cs b/OpenKh.Engine.MonoGame/MonoSpriteDrawing.cs index e9149e7e4..e3c68438d 100644 --- a/OpenKh.Engine.MonoGame/MonoSpriteDrawing.cs +++ b/OpenKh.Engine.MonoGame/MonoSpriteDrawing.cs @@ -1,342 +1,342 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Engine.Extensions; -using OpenKh.Engine.Renders; -using OpenKh.Imaging; -using System.Linq; -using System.Numerics; -using xna = Microsoft.Xna.Framework; - -namespace OpenKh.Engine.MonoGame -{ - public class MonoSpriteDrawing : ISpriteDrawing - { - public class CSpriteTexture : ISpriteTexture - { - public CSpriteTexture(RenderTarget2D texture) - { - Texture = texture; - } - - public RenderTarget2D Texture { get; } - - public int Width => Texture.Width; - - public int Height => Texture.Height; - - public void Dispose() - { - Texture.Dispose(); - } - - public IMappedResource Map() - { - throw new System.NotImplementedException(); - } - } - - private struct MyVertex : IVertexType - { - public static readonly VertexDeclaration VertexDeclaration = new VertexDeclaration - ( - new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), - new VertexElement(12, VertexElementFormat.Vector4, VertexElementUsage.Color, 0), - new VertexElement(28, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) - ); - - public Vector3 Position; - public ColorF Color; - public Vector2 TextureCoordinate; - - VertexDeclaration IVertexType.VertexDeclaration => VertexDeclaration; - - public MyVertex(Vector3 position, ColorF color, Vector2 textureCoordinate) - { - Position = position; - Color = color; - TextureCoordinate = textureCoordinate; - } - } - - // This size should be enough to pack enough 2D graphics at once - private const int MaxSpriteCountPerDraw = 8000; - private static readonly byte[] WhiteBitmap = Enumerable.Range(0, 2 * 2 * sizeof(int)).Select(x => byte.MaxValue).ToArray(); - private static readonly BlendState BlendStateDefault = new BlendState() - { - ColorSourceBlend = Blend.SourceAlpha, - AlphaSourceBlend = Blend.SourceAlpha, - ColorDestinationBlend = Blend.InverseSourceAlpha, - AlphaDestinationBlend = Blend.InverseSourceAlpha, - ColorBlendFunction = BlendFunction.Add, - AlphaBlendFunction = BlendFunction.Add, - BlendFactor = xna.Color.White, - MultiSampleMask = int.MaxValue, - IndependentBlendEnable = false - }; - private static readonly BlendState BlendStateAdditive = new BlendState() - { - ColorSourceBlend = Blend.SourceAlpha, - AlphaSourceBlend = Blend.SourceAlpha, - ColorDestinationBlend = Blend.One, - AlphaDestinationBlend = Blend.One, - ColorBlendFunction = BlendFunction.Add, - AlphaBlendFunction = BlendFunction.Add, - BlendFactor = xna.Color.White, - MultiSampleMask = int.MaxValue, - IndependentBlendEnable = false - }; - private static readonly BlendState BlendStateDifference = new BlendState() - { - ColorSourceBlend = Blend.SourceAlpha, - AlphaSourceBlend = Blend.SourceAlpha, - ColorDestinationBlend = Blend.InverseSourceAlpha, - AlphaDestinationBlend = Blend.InverseSourceAlpha, - ColorBlendFunction = BlendFunction.ReverseSubtract, - AlphaBlendFunction = BlendFunction.ReverseSubtract, - BlendFactor = xna.Color.White, - MultiSampleMask = int.MaxValue, - IndependentBlendEnable = false, - }; - - private readonly GraphicsDevice _graphicsDevice; - private readonly KingdomShader _shader; - - private readonly Texture2D _defaultTexture; - private readonly SamplerState _samplerState; - private readonly RasterizerState _rasterizerState; - private readonly DepthStencilState _depthStencilState; - private readonly VertexBuffer _vertexBuffer; - private readonly IndexBuffer _indexBuffer; - private readonly MyVertex[] _vertices; - private int _currentSpriteIndex; - - private Texture2D _lastTextureUsed; - private BlendState _lastBlendState; - private Matrix4x4 _projectionView; - - private Vector2 _textureRegionU; - private Vector2 _textureRegionV; - private TextureWrapMode _textureWrapU; - private TextureWrapMode _textureWrapV; - private ISpriteTexture destinationTexture; - - public MonoSpriteDrawing(GraphicsDevice graphicsDevice, KingdomShader shader) - { - _graphicsDevice = graphicsDevice; - _shader = shader; - - _defaultTexture = new Texture2D(_graphicsDevice, 2, 2); - _defaultTexture.SetData(WhiteBitmap); - - _samplerState = new SamplerState - { - AddressU = TextureAddressMode.Clamp, - AddressV = TextureAddressMode.Clamp, - AddressW = TextureAddressMode.Clamp, - Filter = TextureFilter.Linear - }; - - _rasterizerState = new RasterizerState() - { - CullMode = CullMode.None, - ScissorTestEnable = false, - DepthClipEnable = false, - }; - - _depthStencilState = new DepthStencilState() - { - DepthBufferEnable = false - }; - - _vertexBuffer = new VertexBuffer(graphicsDevice, MyVertex.VertexDeclaration, MaxSpriteCountPerDraw * 4, BufferUsage.WriteOnly); - _indexBuffer = CreateIndexBufferForSprites(graphicsDevice, MaxSpriteCountPerDraw); - _vertices = new MyVertex[MaxSpriteCountPerDraw * 4]; - _currentSpriteIndex = 0; - } - - public ISpriteTexture DestinationTexture - { - get => destinationTexture; - set - { - destinationTexture = value; - if (value != null) - { - var myTextureWrapper = value as CSpriteTexture; - _graphicsDevice.SetRenderTarget(myTextureWrapper.Texture); - } - else - _graphicsDevice.SetRenderTarget(null); - } - } - - public void Dispose() - { - _defaultTexture?.Dispose(); - _vertexBuffer.Dispose(); - _indexBuffer.Dispose(); - } - - public ISpriteTexture CreateSpriteTexture(IImageRead image) - { - var size = image.Size; - var texture = new RenderTarget2D(_graphicsDevice, size.Width, size.Height); - texture.SetData(image.AsBgra8888()); - - return new CSpriteTexture(texture); - } - - public ISpriteTexture CreateSpriteTexture(int width, int height) => - new CSpriteTexture(new RenderTarget2D(_graphicsDevice, width, height)); - - public void SetViewport(float left, float right, float top, float bottom) - { - _projectionView = Matrix4x4.CreateOrthographicOffCenter(left, right, bottom, top, -1000.0f, +1000.0f); - } - - public void Clear(ColorF color) => - _graphicsDevice.Clear(new xna.Color(color.R, color.G, color.B, color.A)); - - public void AppendSprite(SpriteDrawingContext context) - { - switch (context.BlendMode) - { - case BlendMode.Default: - SetBlendState(BlendStateDefault); - break; - case BlendMode.Add: - SetBlendState(BlendStateAdditive); - break; - case BlendMode.Subtract: - SetBlendState(BlendStateDifference); - break; - default: - SetBlendState(BlendStateDefault); - break; - } - - var texture = (context.SpriteTexture as CSpriteTexture)?.Texture; - var tw = 1f / texture?.Width ?? 1f; - var th = 1f / texture?.Height ?? 1f; - - var textureRegionU = new Vector2(context.TextureRegionLeft * tw, context.TextureRegionRight * tw); - var textureRegionV = new Vector2(context.TextureRegionTop * th, context.TextureRegionBottom * th); - if (context.TextureWrapU == TextureWrapMode.Default) - textureRegionU = new Vector2(0, 1); - if (context.TextureWrapV == TextureWrapMode.Default) - textureRegionV = new Vector2(0, 1); - - if (_textureRegionU != textureRegionU || - _textureRegionV != textureRegionV || - _textureWrapU != context.TextureWrapU || - _textureWrapV != context.TextureWrapV) - Flush(); - - var vertexIndex = PrepareVertices(texture); - - _textureRegionU = textureRegionU; - _textureRegionV = textureRegionV; - _textureWrapU = context.TextureWrapU; - _textureWrapV = context.TextureWrapV; - - _vertices[vertexIndex + 0].Position = new Vector3(context.Vec0.X, context.Vec0.Y, 0.0f); - _vertices[vertexIndex + 0].Color = context.Color0; - _vertices[vertexIndex + 0].TextureCoordinate = new Vector2(context.SourceLeft * tw + context.TextureHorizontalShift, context.SourceTop * th + context.TextureVerticalShift); - - _vertices[vertexIndex + 1].Position = new Vector3(context.Vec1.X, context.Vec1.Y, 0.0f); - _vertices[vertexIndex + 1].Color = context.Color1; - _vertices[vertexIndex + 1].TextureCoordinate = new Vector2(context.SourceRight * tw + context.TextureHorizontalShift, context.SourceTop * th + context.TextureVerticalShift); - - _vertices[vertexIndex + 2].Position = new Vector3(context.Vec2.X, context.Vec2.Y, 0.0f); - _vertices[vertexIndex + 2].Color = context.Color2; - _vertices[vertexIndex + 2].TextureCoordinate = new Vector2(context.SourceLeft * tw + context.TextureHorizontalShift, context.SourceBottom * th + context.TextureVerticalShift); - - _vertices[vertexIndex + 3].Position = new Vector3(context.Vec3.X, context.Vec3.Y, 0.0f); - _vertices[vertexIndex + 3].Color = context.Color3; - _vertices[vertexIndex + 3].TextureCoordinate = new Vector2(context.SourceRight * tw + context.TextureHorizontalShift, context.SourceBottom * th + context.TextureVerticalShift); - - PushVertices(); - } - - public void Flush() - { - if (_currentSpriteIndex <= 0) - return; - - _graphicsDevice.SamplerStates[0] = _samplerState; - _graphicsDevice.RasterizerState = _rasterizerState; - _graphicsDevice.BlendState = _lastBlendState; - _graphicsDevice.DepthStencilState = _depthStencilState; - _graphicsDevice.SetVertexBuffer(_vertexBuffer); - _graphicsDevice.Indices = _indexBuffer; - - _vertexBuffer.SetData(_vertices, 0, 4 * _currentSpriteIndex); - _shader.Pass(pass => - { - _shader.Texture0 = _lastTextureUsed; - _shader.SetProjectionView(ref _projectionView); - _shader.SetWorldViewIdentity(); - _shader.SetModelViewIdentity(); - _shader.SetTextureRegionU(ref _textureRegionU); - _shader.SetTextureRegionV(ref _textureRegionV); - _shader.TextureWrapModeU = _textureWrapU; - _shader.TextureWrapModeV = _textureWrapV; - pass.Apply(); - - _graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _currentSpriteIndex * 2); - }); - - _currentSpriteIndex = 0; - } - - private int PrepareVertices(Texture2D texture) - { - texture ??= _defaultTexture; - if (_lastTextureUsed != texture) - { - Flush(); - _lastTextureUsed = texture; - } - - if (_currentSpriteIndex >= MaxSpriteCountPerDraw) - Flush(); - - return _currentSpriteIndex++ * 4; - } - - private void PushVertices() - { - // right now it does not do anything. - } - - private void SetBlendState(BlendState blendState) - { - if (_lastBlendState != blendState) - { - Flush(); - _lastBlendState = blendState; - } - } - - private static IndexBuffer CreateIndexBufferForSprites(GraphicsDevice graphicsDevice, int spriteCount) - { - var indexBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.ThirtyTwoBits, spriteCount * 6, BufferUsage.WriteOnly); - var indices = new int[spriteCount * 6]; - for (int spriteIndex = 0, vertexIndex = 0; - spriteIndex < spriteCount; - spriteIndex++, vertexIndex += 4) - { - var i = spriteIndex * 6; - indices[i + 0] = vertexIndex + 0; - indices[i + 1] = vertexIndex + 1; - indices[i + 2] = vertexIndex + 2; - indices[i + 3] = vertexIndex + 1; - indices[i + 4] = vertexIndex + 2; - indices[i + 5] = vertexIndex + 3; - } - - indexBuffer.SetData(indices); - - return indexBuffer; - } - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Engine.Extensions; +using OpenKh.Engine.Renders; +using OpenKh.Imaging; +using System.Linq; +using System.Numerics; +using xna = Microsoft.Xna.Framework; + +namespace OpenKh.Engine.MonoGame +{ + public class MonoSpriteDrawing : ISpriteDrawing + { + public class CSpriteTexture : ISpriteTexture + { + public CSpriteTexture(RenderTarget2D texture) + { + Texture = texture; + } + + public RenderTarget2D Texture { get; } + + public int Width => Texture.Width; + + public int Height => Texture.Height; + + public void Dispose() + { + Texture.Dispose(); + } + + public IMappedResource Map() + { + throw new System.NotImplementedException(); + } + } + + private struct MyVertex : IVertexType + { + public static readonly VertexDeclaration VertexDeclaration = new VertexDeclaration + ( + new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), + new VertexElement(12, VertexElementFormat.Vector4, VertexElementUsage.Color, 0), + new VertexElement(28, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) + ); + + public Vector3 Position; + public ColorF Color; + public Vector2 TextureCoordinate; + + VertexDeclaration IVertexType.VertexDeclaration => VertexDeclaration; + + public MyVertex(Vector3 position, ColorF color, Vector2 textureCoordinate) + { + Position = position; + Color = color; + TextureCoordinate = textureCoordinate; + } + } + + // This size should be enough to pack enough 2D graphics at once + private const int MaxSpriteCountPerDraw = 8000; + private static readonly byte[] WhiteBitmap = Enumerable.Range(0, 2 * 2 * sizeof(int)).Select(x => byte.MaxValue).ToArray(); + private static readonly BlendState BlendStateDefault = new BlendState() + { + ColorSourceBlend = Blend.SourceAlpha, + AlphaSourceBlend = Blend.SourceAlpha, + ColorDestinationBlend = Blend.InverseSourceAlpha, + AlphaDestinationBlend = Blend.InverseSourceAlpha, + ColorBlendFunction = BlendFunction.Add, + AlphaBlendFunction = BlendFunction.Add, + BlendFactor = xna.Color.White, + MultiSampleMask = int.MaxValue, + IndependentBlendEnable = false + }; + private static readonly BlendState BlendStateAdditive = new BlendState() + { + ColorSourceBlend = Blend.SourceAlpha, + AlphaSourceBlend = Blend.SourceAlpha, + ColorDestinationBlend = Blend.One, + AlphaDestinationBlend = Blend.One, + ColorBlendFunction = BlendFunction.Add, + AlphaBlendFunction = BlendFunction.Add, + BlendFactor = xna.Color.White, + MultiSampleMask = int.MaxValue, + IndependentBlendEnable = false + }; + private static readonly BlendState BlendStateDifference = new BlendState() + { + ColorSourceBlend = Blend.SourceAlpha, + AlphaSourceBlend = Blend.SourceAlpha, + ColorDestinationBlend = Blend.InverseSourceAlpha, + AlphaDestinationBlend = Blend.InverseSourceAlpha, + ColorBlendFunction = BlendFunction.ReverseSubtract, + AlphaBlendFunction = BlendFunction.ReverseSubtract, + BlendFactor = xna.Color.White, + MultiSampleMask = int.MaxValue, + IndependentBlendEnable = false, + }; + + private readonly GraphicsDevice _graphicsDevice; + private readonly KingdomShader _shader; + + private readonly Texture2D _defaultTexture; + private readonly SamplerState _samplerState; + private readonly RasterizerState _rasterizerState; + private readonly DepthStencilState _depthStencilState; + private readonly VertexBuffer _vertexBuffer; + private readonly IndexBuffer _indexBuffer; + private readonly MyVertex[] _vertices; + private int _currentSpriteIndex; + + private Texture2D _lastTextureUsed; + private BlendState _lastBlendState; + private Matrix4x4 _projectionView; + + private Vector2 _textureRegionU; + private Vector2 _textureRegionV; + private TextureWrapMode _textureWrapU; + private TextureWrapMode _textureWrapV; + private ISpriteTexture destinationTexture; + + public MonoSpriteDrawing(GraphicsDevice graphicsDevice, KingdomShader shader) + { + _graphicsDevice = graphicsDevice; + _shader = shader; + + _defaultTexture = new Texture2D(_graphicsDevice, 2, 2); + _defaultTexture.SetData(WhiteBitmap); + + _samplerState = new SamplerState + { + AddressU = TextureAddressMode.Clamp, + AddressV = TextureAddressMode.Clamp, + AddressW = TextureAddressMode.Clamp, + Filter = TextureFilter.Linear + }; + + _rasterizerState = new RasterizerState() + { + CullMode = CullMode.None, + ScissorTestEnable = false, + DepthClipEnable = false, + }; + + _depthStencilState = new DepthStencilState() + { + DepthBufferEnable = false + }; + + _vertexBuffer = new VertexBuffer(graphicsDevice, MyVertex.VertexDeclaration, MaxSpriteCountPerDraw * 4, BufferUsage.WriteOnly); + _indexBuffer = CreateIndexBufferForSprites(graphicsDevice, MaxSpriteCountPerDraw); + _vertices = new MyVertex[MaxSpriteCountPerDraw * 4]; + _currentSpriteIndex = 0; + } + + public ISpriteTexture DestinationTexture + { + get => destinationTexture; + set + { + destinationTexture = value; + if (value != null) + { + var myTextureWrapper = value as CSpriteTexture; + _graphicsDevice.SetRenderTarget(myTextureWrapper.Texture); + } + else + _graphicsDevice.SetRenderTarget(null); + } + } + + public void Dispose() + { + _defaultTexture?.Dispose(); + _vertexBuffer.Dispose(); + _indexBuffer.Dispose(); + } + + public ISpriteTexture CreateSpriteTexture(IImageRead image) + { + var size = image.Size; + var texture = new RenderTarget2D(_graphicsDevice, size.Width, size.Height); + texture.SetData(image.AsBgra8888()); + + return new CSpriteTexture(texture); + } + + public ISpriteTexture CreateSpriteTexture(int width, int height) => + new CSpriteTexture(new RenderTarget2D(_graphicsDevice, width, height)); + + public void SetViewport(float left, float right, float top, float bottom) + { + _projectionView = Matrix4x4.CreateOrthographicOffCenter(left, right, bottom, top, -1000.0f, +1000.0f); + } + + public void Clear(ColorF color) => + _graphicsDevice.Clear(new xna.Color(color.R, color.G, color.B, color.A)); + + public void AppendSprite(SpriteDrawingContext context) + { + switch (context.BlendMode) + { + case BlendMode.Default: + SetBlendState(BlendStateDefault); + break; + case BlendMode.Add: + SetBlendState(BlendStateAdditive); + break; + case BlendMode.Subtract: + SetBlendState(BlendStateDifference); + break; + default: + SetBlendState(BlendStateDefault); + break; + } + + var texture = (context.SpriteTexture as CSpriteTexture)?.Texture; + var tw = 1f / texture?.Width ?? 1f; + var th = 1f / texture?.Height ?? 1f; + + var textureRegionU = new Vector2(context.TextureRegionLeft * tw, context.TextureRegionRight * tw); + var textureRegionV = new Vector2(context.TextureRegionTop * th, context.TextureRegionBottom * th); + if (context.TextureWrapU == TextureWrapMode.Default) + textureRegionU = new Vector2(0, 1); + if (context.TextureWrapV == TextureWrapMode.Default) + textureRegionV = new Vector2(0, 1); + + if (_textureRegionU != textureRegionU || + _textureRegionV != textureRegionV || + _textureWrapU != context.TextureWrapU || + _textureWrapV != context.TextureWrapV) + Flush(); + + var vertexIndex = PrepareVertices(texture); + + _textureRegionU = textureRegionU; + _textureRegionV = textureRegionV; + _textureWrapU = context.TextureWrapU; + _textureWrapV = context.TextureWrapV; + + _vertices[vertexIndex + 0].Position = new Vector3(context.Vec0.X, context.Vec0.Y, 0.0f); + _vertices[vertexIndex + 0].Color = context.Color0; + _vertices[vertexIndex + 0].TextureCoordinate = new Vector2(context.SourceLeft * tw + context.TextureHorizontalShift, context.SourceTop * th + context.TextureVerticalShift); + + _vertices[vertexIndex + 1].Position = new Vector3(context.Vec1.X, context.Vec1.Y, 0.0f); + _vertices[vertexIndex + 1].Color = context.Color1; + _vertices[vertexIndex + 1].TextureCoordinate = new Vector2(context.SourceRight * tw + context.TextureHorizontalShift, context.SourceTop * th + context.TextureVerticalShift); + + _vertices[vertexIndex + 2].Position = new Vector3(context.Vec2.X, context.Vec2.Y, 0.0f); + _vertices[vertexIndex + 2].Color = context.Color2; + _vertices[vertexIndex + 2].TextureCoordinate = new Vector2(context.SourceLeft * tw + context.TextureHorizontalShift, context.SourceBottom * th + context.TextureVerticalShift); + + _vertices[vertexIndex + 3].Position = new Vector3(context.Vec3.X, context.Vec3.Y, 0.0f); + _vertices[vertexIndex + 3].Color = context.Color3; + _vertices[vertexIndex + 3].TextureCoordinate = new Vector2(context.SourceRight * tw + context.TextureHorizontalShift, context.SourceBottom * th + context.TextureVerticalShift); + + PushVertices(); + } + + public void Flush() + { + if (_currentSpriteIndex <= 0) + return; + + _graphicsDevice.SamplerStates[0] = _samplerState; + _graphicsDevice.RasterizerState = _rasterizerState; + _graphicsDevice.BlendState = _lastBlendState; + _graphicsDevice.DepthStencilState = _depthStencilState; + _graphicsDevice.SetVertexBuffer(_vertexBuffer); + _graphicsDevice.Indices = _indexBuffer; + + _vertexBuffer.SetData(_vertices, 0, 4 * _currentSpriteIndex); + _shader.Pass(pass => + { + _shader.Texture0 = _lastTextureUsed; + _shader.SetProjectionView(ref _projectionView); + _shader.SetWorldViewIdentity(); + _shader.SetModelViewIdentity(); + _shader.SetTextureRegionU(ref _textureRegionU); + _shader.SetTextureRegionV(ref _textureRegionV); + _shader.TextureWrapModeU = _textureWrapU; + _shader.TextureWrapModeV = _textureWrapV; + pass.Apply(); + + _graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _currentSpriteIndex * 2); + }); + + _currentSpriteIndex = 0; + } + + private int PrepareVertices(Texture2D texture) + { + texture ??= _defaultTexture; + if (_lastTextureUsed != texture) + { + Flush(); + _lastTextureUsed = texture; + } + + if (_currentSpriteIndex >= MaxSpriteCountPerDraw) + Flush(); + + return _currentSpriteIndex++ * 4; + } + + private void PushVertices() + { + // right now it does not do anything. + } + + private void SetBlendState(BlendState blendState) + { + if (_lastBlendState != blendState) + { + Flush(); + _lastBlendState = blendState; + } + } + + private static IndexBuffer CreateIndexBufferForSprites(GraphicsDevice graphicsDevice, int spriteCount) + { + var indexBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.ThirtyTwoBits, spriteCount * 6, BufferUsage.WriteOnly); + var indices = new int[spriteCount * 6]; + for (int spriteIndex = 0, vertexIndex = 0; + spriteIndex < spriteCount; + spriteIndex++, vertexIndex += 4) + { + var i = spriteIndex * 6; + indices[i + 0] = vertexIndex + 0; + indices[i + 1] = vertexIndex + 1; + indices[i + 2] = vertexIndex + 2; + indices[i + 3] = vertexIndex + 1; + indices[i + 4] = vertexIndex + 2; + indices[i + 5] = vertexIndex + 3; + } + + indexBuffer.SetData(indices); + + return indexBuffer; + } + } +} diff --git a/OpenKh.Engine/Camera.cs b/OpenKh.Engine/Camera.cs index 35bdcc03a..36144fa67 100644 --- a/OpenKh.Engine/Camera.cs +++ b/OpenKh.Engine/Camera.cs @@ -1,203 +1,203 @@ -using System; -using System.Numerics; - -namespace OpenKh.Engine -{ - public class Camera - { - private bool _isEventMode; - private float _fov; - private float _aspectRatio; - private Vector3 _cameraPosition; - private Vector3 _cameraLookAt; - private Vector3 _cameraLookAtX; - private Vector3 _cameraLookAtY; - private Vector3 _cameraLookAtZ; - private Vector3 _cameraUp; - private Matrix4x4 _projection; - private Matrix4x4 _world; - private bool _isProjectionInvalidated; - private bool _isWorldInvalidated; - private Vector3 _cameraYpr; - - public bool IsEventMode - { - get => _isEventMode; - set - { - if (_isEventMode == value) - return; - - _isEventMode = value; - InvalidateProjection(); - } - } - - public float FieldOfView - { - get => _fov; - set - { - if (_fov == value) - return; - _fov = value; - InvalidateProjection(); - } - } - - public float AspectRatio - { - get => _aspectRatio; - set - { - if (_aspectRatio == value) - return; - _aspectRatio = value; - InvalidateProjection(); - } - } - - public Vector3 CameraPosition - { - get => _cameraPosition; - set - { - _cameraPosition = value; - CameraLookAt = CameraPosition + CameraLookAtX; - InvalidateWorld(); - } - } - - public Vector3 CameraLookAt - { - get => _cameraLookAt; - set - { - _cameraLookAt = value; - InvalidateWorld(); - } - } - - public Vector3 CameraLookAtX - { - get => _cameraLookAtX; - set - { - _cameraLookAtX = value; - CameraLookAt = CameraPosition + CameraLookAtX; - InvalidateWorld(); - } - } - - public Vector3 CameraLookAtY - { - get => _cameraLookAtY; - set - { - _cameraLookAtY = value; - InvalidateWorld(); - } - } - - public Vector3 CameraLookAtZ - { - get => _cameraLookAtZ; - set - { - _cameraLookAtZ = value; - InvalidateWorld(); - } - } - - public Vector3 CameraUp - { - get => _cameraUp; - set - { - _cameraUp = value; - InvalidateWorld(); - } - } - - public Vector3 CameraRotationYawPitchRoll - { - get => _cameraYpr; - set - { - _cameraYpr = value; - var matrix = Matrix4x4.CreateFromYawPitchRoll( - (float)(value.X * Math.PI / 180.0), - (float)(value.Y * Math.PI / 180.0), - (float)(value.Z * Math.PI / 180.0)); - CameraLookAtX = Vector3.Transform(new Vector3(1, 0, 0), matrix); - CameraLookAtY = Vector3.Transform(new Vector3(0, 0, 1), matrix); - CameraLookAtZ = Vector3.Transform(new Vector3(0, 1, 0), matrix); - } - } - - public Matrix4x4 Projection - { - get - { - if (_isProjectionInvalidated) - CalculateProjection(); - return _projection; - } - } - - public Matrix4x4 World - { - get - { - if (_isWorldInvalidated) - CalculateWorld(); - return _world; - } - } - - public Camera() - { - FieldOfView = 1.5f; - AspectRatio = 640f / 480f; - CameraUp = new Vector3(0, 1, 0); - CameraRotationYawPitchRoll = new Vector3(-90, 0, 10); - } - - private void InvalidateProjection() => _isProjectionInvalidated = true; - private void ValidateProjection() => _isProjectionInvalidated = false; - private void InvalidateWorld() => _isWorldInvalidated = true; - private void ValidateWorld() => _isWorldInvalidated = false; - - private void CalculateProjection() - { - const float NearClipPlane = 1f; - const float FarClipPlane = 4000000f; - - if (!_isEventMode) - { - const double ReferenceWidth = 640f; - const double ReferenceHeight = 480f; - - var srcz = ReferenceWidth / 2.0 / Math.Tan(_fov / 2.0); - var actualAspectRatio = 1.0 / _aspectRatio / (ReferenceHeight / ReferenceWidth); - var width = ReferenceWidth / (srcz * actualAspectRatio); - var height = ReferenceHeight / srcz; - _projection = Matrix4x4.CreatePerspective((float)width, (float)height, NearClipPlane, FarClipPlane); - } - else - _projection = Matrix4x4.CreatePerspectiveFieldOfView(_fov, _aspectRatio, NearClipPlane, FarClipPlane); - - ValidateProjection(); - } - - private void CalculateWorld() - { - _world = Matrix4x4.CreateLookAt( - new Vector3(-CameraPosition.X, CameraPosition.Y, CameraPosition.Z), - new Vector3(-CameraLookAt.X, CameraLookAt.Y, CameraLookAt.Z), - CameraUp); - - ValidateWorld(); - } - } -} +using System; +using System.Numerics; + +namespace OpenKh.Engine +{ + public class Camera + { + private bool _isEventMode; + private float _fov; + private float _aspectRatio; + private Vector3 _cameraPosition; + private Vector3 _cameraLookAt; + private Vector3 _cameraLookAtX; + private Vector3 _cameraLookAtY; + private Vector3 _cameraLookAtZ; + private Vector3 _cameraUp; + private Matrix4x4 _projection; + private Matrix4x4 _world; + private bool _isProjectionInvalidated; + private bool _isWorldInvalidated; + private Vector3 _cameraYpr; + + public bool IsEventMode + { + get => _isEventMode; + set + { + if (_isEventMode == value) + return; + + _isEventMode = value; + InvalidateProjection(); + } + } + + public float FieldOfView + { + get => _fov; + set + { + if (_fov == value) + return; + _fov = value; + InvalidateProjection(); + } + } + + public float AspectRatio + { + get => _aspectRatio; + set + { + if (_aspectRatio == value) + return; + _aspectRatio = value; + InvalidateProjection(); + } + } + + public Vector3 CameraPosition + { + get => _cameraPosition; + set + { + _cameraPosition = value; + CameraLookAt = CameraPosition + CameraLookAtX; + InvalidateWorld(); + } + } + + public Vector3 CameraLookAt + { + get => _cameraLookAt; + set + { + _cameraLookAt = value; + InvalidateWorld(); + } + } + + public Vector3 CameraLookAtX + { + get => _cameraLookAtX; + set + { + _cameraLookAtX = value; + CameraLookAt = CameraPosition + CameraLookAtX; + InvalidateWorld(); + } + } + + public Vector3 CameraLookAtY + { + get => _cameraLookAtY; + set + { + _cameraLookAtY = value; + InvalidateWorld(); + } + } + + public Vector3 CameraLookAtZ + { + get => _cameraLookAtZ; + set + { + _cameraLookAtZ = value; + InvalidateWorld(); + } + } + + public Vector3 CameraUp + { + get => _cameraUp; + set + { + _cameraUp = value; + InvalidateWorld(); + } + } + + public Vector3 CameraRotationYawPitchRoll + { + get => _cameraYpr; + set + { + _cameraYpr = value; + var matrix = Matrix4x4.CreateFromYawPitchRoll( + (float)(value.X * Math.PI / 180.0), + (float)(value.Y * Math.PI / 180.0), + (float)(value.Z * Math.PI / 180.0)); + CameraLookAtX = Vector3.Transform(new Vector3(1, 0, 0), matrix); + CameraLookAtY = Vector3.Transform(new Vector3(0, 0, 1), matrix); + CameraLookAtZ = Vector3.Transform(new Vector3(0, 1, 0), matrix); + } + } + + public Matrix4x4 Projection + { + get + { + if (_isProjectionInvalidated) + CalculateProjection(); + return _projection; + } + } + + public Matrix4x4 World + { + get + { + if (_isWorldInvalidated) + CalculateWorld(); + return _world; + } + } + + public Camera() + { + FieldOfView = 1.5f; + AspectRatio = 640f / 480f; + CameraUp = new Vector3(0, 1, 0); + CameraRotationYawPitchRoll = new Vector3(-90, 0, 10); + } + + private void InvalidateProjection() => _isProjectionInvalidated = true; + private void ValidateProjection() => _isProjectionInvalidated = false; + private void InvalidateWorld() => _isWorldInvalidated = true; + private void ValidateWorld() => _isWorldInvalidated = false; + + private void CalculateProjection() + { + const float NearClipPlane = 1f; + const float FarClipPlane = 4000000f; + + if (!_isEventMode) + { + const double ReferenceWidth = 640f; + const double ReferenceHeight = 480f; + + var srcz = ReferenceWidth / 2.0 / Math.Tan(_fov / 2.0); + var actualAspectRatio = 1.0 / _aspectRatio / (ReferenceHeight / ReferenceWidth); + var width = ReferenceWidth / (srcz * actualAspectRatio); + var height = ReferenceHeight / srcz; + _projection = Matrix4x4.CreatePerspective((float)width, (float)height, NearClipPlane, FarClipPlane); + } + else + _projection = Matrix4x4.CreatePerspectiveFieldOfView(_fov, _aspectRatio, NearClipPlane, FarClipPlane); + + ValidateProjection(); + } + + private void CalculateWorld() + { + _world = Matrix4x4.CreateLookAt( + new Vector3(-CameraPosition.X, CameraPosition.Y, CameraPosition.Z), + new Vector3(-CameraLookAt.X, CameraLookAt.Y, CameraLookAt.Z), + CameraUp); + + ValidateWorld(); + } + } +} diff --git a/OpenKh.Engine/Extensions/ImageReadExtensions.cs b/OpenKh.Engine/Extensions/ImageReadExtensions.cs index 7d822ae27..7c8aa9c33 100644 --- a/OpenKh.Engine/Extensions/ImageReadExtensions.cs +++ b/OpenKh.Engine/Extensions/ImageReadExtensions.cs @@ -1,45 +1,45 @@ -using OpenKh.Imaging; -using System; - -namespace OpenKh.Engine.Extensions -{ - public static class ImageReadExtensions - { - private static readonly byte[] Bgra = new byte[] { 2, 1, 0, 3 }; - private static readonly byte[] Rgba = new byte[] { 0, 1, 2, 3 }; - - public static byte[] AsBgra8888(this IImageRead image) - { - switch (image.PixelFormat) - { - case PixelFormat.Indexed4: - return ImageDataHelpers.FromIndexed4ToBitmap32( - image.GetData(), image.GetClut(), Bgra); - case PixelFormat.Indexed8: - return ImageDataHelpers.FromIndexed8ToBitmap32( - image.GetData(), image.GetClut(), Bgra); - case PixelFormat.Rgba8888: - return ImageDataHelpers.FromBitmap32(image.GetData(), Rgba); - default: - throw new ArgumentException($"The pixel format {image.PixelFormat} is not supported."); - } - } - - public static byte[] AsRgba8888(this IImageRead image) - { - switch (image.PixelFormat) - { - case PixelFormat.Indexed4: - return ImageDataHelpers.FromIndexed4ToBitmap32( - image.GetData(), image.GetClut(), Rgba); - case PixelFormat.Indexed8: - return ImageDataHelpers.FromIndexed8ToBitmap32( - image.GetData(), image.GetClut(), Rgba); - case PixelFormat.Rgba8888: - return ImageDataHelpers.FromBitmap32(image.GetData(), Bgra); - default: - throw new ArgumentException($"The pixel format {image.PixelFormat} is not supported."); - } - } - } -} +using OpenKh.Imaging; +using System; + +namespace OpenKh.Engine.Extensions +{ + public static class ImageReadExtensions + { + private static readonly byte[] Bgra = new byte[] { 2, 1, 0, 3 }; + private static readonly byte[] Rgba = new byte[] { 0, 1, 2, 3 }; + + public static byte[] AsBgra8888(this IImageRead image) + { + switch (image.PixelFormat) + { + case PixelFormat.Indexed4: + return ImageDataHelpers.FromIndexed4ToBitmap32( + image.GetData(), image.GetClut(), Bgra); + case PixelFormat.Indexed8: + return ImageDataHelpers.FromIndexed8ToBitmap32( + image.GetData(), image.GetClut(), Bgra); + case PixelFormat.Rgba8888: + return ImageDataHelpers.FromBitmap32(image.GetData(), Rgba); + default: + throw new ArgumentException($"The pixel format {image.PixelFormat} is not supported."); + } + } + + public static byte[] AsRgba8888(this IImageRead image) + { + switch (image.PixelFormat) + { + case PixelFormat.Indexed4: + return ImageDataHelpers.FromIndexed4ToBitmap32( + image.GetData(), image.GetClut(), Rgba); + case PixelFormat.Indexed8: + return ImageDataHelpers.FromIndexed8ToBitmap32( + image.GetData(), image.GetClut(), Rgba); + case PixelFormat.Rgba8888: + return ImageDataHelpers.FromBitmap32(image.GetData(), Bgra); + default: + throw new ArgumentException($"The pixel format {image.PixelFormat} is not supported."); + } + } + } +} diff --git a/OpenKh.Engine/Extensions/Kh2FontContextExtensions.cs b/OpenKh.Engine/Extensions/Kh2FontContextExtensions.cs index c5e640728..3ed70be0a 100644 --- a/OpenKh.Engine/Extensions/Kh2FontContextExtensions.cs +++ b/OpenKh.Engine/Extensions/Kh2FontContextExtensions.cs @@ -1,94 +1,94 @@ -using OpenKh.Engine.Renders; -using OpenKh.Kh2; -using OpenKh.Kh2.Contextes; -using OpenKh.Kh2.Messages; - -namespace OpenKh.Engine.Extensions -{ - public static class Kh2FontContextExtensions - { - public static RenderingMessageContext ToKh2EuSystemTextContext(this FontContext fontContext) => - new RenderingMessageContext - { - Font = fontContext.ImageSystem, - Font2 = fontContext.ImageSystem2, - Icon = fontContext.ImageIcon, - FontSpacing = fontContext.SpacingSystem, - IconSpacing = fontContext.SpacingIcon, - Encoder = Encoders.InternationalSystem, - FontWidth = Constants.FontEuropeanSystemWidth, - FontHeight = Constants.FontEuropeanSystemHeight, - TableHeight = Constants.FontTableSystemHeight, - }; - - public static RenderingMessageContext ToKh2EuEventTextContext(this FontContext fontContext) => - new RenderingMessageContext - { - Font = fontContext.ImageEvent, - Font2 = fontContext.ImageEvent2, - Icon = fontContext.ImageIcon, - FontSpacing = fontContext.SpacingEvent, - IconSpacing = fontContext.SpacingIcon, - Encoder = Encoders.InternationalSystem, - FontWidth = Constants.FontEuropeanEventWidth, - FontHeight = Constants.FontEuropeanEventHeight, - TableHeight = Constants.FontTableEventHeight, - }; - - public static RenderingMessageContext ToKh2TRSystemTextContext(this FontContext fontContext) => - new RenderingMessageContext - { - Font = fontContext.ImageSystem, - Font2 = fontContext.ImageSystem2, - Icon = fontContext.ImageIcon, - FontSpacing = fontContext.SpacingSystem, - IconSpacing = fontContext.SpacingIcon, - Encoder = Encoders.TurkishSystem, - FontWidth = Constants.FontEuropeanSystemWidth, - FontHeight = Constants.FontEuropeanSystemHeight, - TableHeight = Constants.FontTableSystemHeight, - }; - - public static RenderingMessageContext ToKh2TREventTextContext(this FontContext fontContext) => - new RenderingMessageContext - { - Font = fontContext.ImageEvent, - Font2 = fontContext.ImageEvent2, - Icon = fontContext.ImageIcon, - FontSpacing = fontContext.SpacingEvent, - IconSpacing = fontContext.SpacingIcon, - Encoder = Encoders.TurkishSystem, - FontWidth = Constants.FontEuropeanEventWidth, - FontHeight = Constants.FontEuropeanEventHeight, - TableHeight = Constants.FontTableEventHeight, - }; - - public static RenderingMessageContext ToKh2JpSystemTextContext(this FontContext fontContext) => - new RenderingMessageContext - { - Font = fontContext.ImageSystem, - Font2 = fontContext.ImageSystem2, - Icon = fontContext.ImageIcon, - FontSpacing = fontContext.SpacingSystem, - IconSpacing = fontContext.SpacingIcon, - Encoder = Encoders.JapaneseSystem, - FontWidth = Constants.FontJapaneseSystemWidth, - FontHeight = Constants.FontJapaneseSystemHeight, - TableHeight = Constants.FontTableSystemHeight, - }; - - public static RenderingMessageContext ToKh2JpEventTextContext(this FontContext fontContext) => - new RenderingMessageContext - { - Font = fontContext.ImageEvent, - Font2 = fontContext.ImageEvent2, - Icon = fontContext.ImageIcon, - FontSpacing = fontContext.SpacingEvent, - IconSpacing = fontContext.SpacingIcon, - Encoder = Encoders.JapaneseEvent, - FontWidth = Constants.FontJapaneseEventWidth, - FontHeight = Constants.FontJapaneseEventHeight, - TableHeight = Constants.FontTableEventHeight, - }; - } -} +using OpenKh.Engine.Renders; +using OpenKh.Kh2; +using OpenKh.Kh2.Contextes; +using OpenKh.Kh2.Messages; + +namespace OpenKh.Engine.Extensions +{ + public static class Kh2FontContextExtensions + { + public static RenderingMessageContext ToKh2EuSystemTextContext(this FontContext fontContext) => + new RenderingMessageContext + { + Font = fontContext.ImageSystem, + Font2 = fontContext.ImageSystem2, + Icon = fontContext.ImageIcon, + FontSpacing = fontContext.SpacingSystem, + IconSpacing = fontContext.SpacingIcon, + Encoder = Encoders.InternationalSystem, + FontWidth = Constants.FontEuropeanSystemWidth, + FontHeight = Constants.FontEuropeanSystemHeight, + TableHeight = Constants.FontTableSystemHeight, + }; + + public static RenderingMessageContext ToKh2EuEventTextContext(this FontContext fontContext) => + new RenderingMessageContext + { + Font = fontContext.ImageEvent, + Font2 = fontContext.ImageEvent2, + Icon = fontContext.ImageIcon, + FontSpacing = fontContext.SpacingEvent, + IconSpacing = fontContext.SpacingIcon, + Encoder = Encoders.InternationalSystem, + FontWidth = Constants.FontEuropeanEventWidth, + FontHeight = Constants.FontEuropeanEventHeight, + TableHeight = Constants.FontTableEventHeight, + }; + + public static RenderingMessageContext ToKh2TRSystemTextContext(this FontContext fontContext) => + new RenderingMessageContext + { + Font = fontContext.ImageSystem, + Font2 = fontContext.ImageSystem2, + Icon = fontContext.ImageIcon, + FontSpacing = fontContext.SpacingSystem, + IconSpacing = fontContext.SpacingIcon, + Encoder = Encoders.TurkishSystem, + FontWidth = Constants.FontEuropeanSystemWidth, + FontHeight = Constants.FontEuropeanSystemHeight, + TableHeight = Constants.FontTableSystemHeight, + }; + + public static RenderingMessageContext ToKh2TREventTextContext(this FontContext fontContext) => + new RenderingMessageContext + { + Font = fontContext.ImageEvent, + Font2 = fontContext.ImageEvent2, + Icon = fontContext.ImageIcon, + FontSpacing = fontContext.SpacingEvent, + IconSpacing = fontContext.SpacingIcon, + Encoder = Encoders.TurkishSystem, + FontWidth = Constants.FontEuropeanEventWidth, + FontHeight = Constants.FontEuropeanEventHeight, + TableHeight = Constants.FontTableEventHeight, + }; + + public static RenderingMessageContext ToKh2JpSystemTextContext(this FontContext fontContext) => + new RenderingMessageContext + { + Font = fontContext.ImageSystem, + Font2 = fontContext.ImageSystem2, + Icon = fontContext.ImageIcon, + FontSpacing = fontContext.SpacingSystem, + IconSpacing = fontContext.SpacingIcon, + Encoder = Encoders.JapaneseSystem, + FontWidth = Constants.FontJapaneseSystemWidth, + FontHeight = Constants.FontJapaneseSystemHeight, + TableHeight = Constants.FontTableSystemHeight, + }; + + public static RenderingMessageContext ToKh2JpEventTextContext(this FontContext fontContext) => + new RenderingMessageContext + { + Font = fontContext.ImageEvent, + Font2 = fontContext.ImageEvent2, + Icon = fontContext.ImageIcon, + FontSpacing = fontContext.SpacingEvent, + IconSpacing = fontContext.SpacingIcon, + Encoder = Encoders.JapaneseEvent, + FontWidth = Constants.FontJapaneseEventWidth, + FontHeight = Constants.FontJapaneseEventHeight, + TableHeight = Constants.FontTableEventHeight, + }; + } +} diff --git a/OpenKh.Engine/Extensions/SpriteDrawingExtensions.cs b/OpenKh.Engine/Extensions/SpriteDrawingExtensions.cs index e6ae78818..97d896926 100644 --- a/OpenKh.Engine/Extensions/SpriteDrawingExtensions.cs +++ b/OpenKh.Engine/Extensions/SpriteDrawingExtensions.cs @@ -1,36 +1,36 @@ -using OpenKh.Engine.Renders; - -namespace OpenKh.Engine.Extensions -{ - public static class SpriteDrawingExtensions - { - public static void SetProjection(this ISpriteDrawing spriteDrawing, - float width, float height, float internalWidth, float internalHeight, float ratio) - { - var heightRatio = internalHeight / height; - width *= heightRatio; - height *= heightRatio; - width *= ratio; - - var left = (internalWidth - width) / 2; - spriteDrawing.SetViewport(left, width + left, 0, height); - } - - public static void FillRectangle(this ISpriteDrawing drawing, float x, float y, float width, float height, ColorF color) - { - drawing.AppendSprite(new SpriteDrawingContext() - .Source(0, 0, 1, 1) - .Position(x, y) - .DestinationSize(width, height) - .Color(color)); - } - - public static void DrawRectangle(this ISpriteDrawing drawing, float x, float y, float width, float height, ColorF color, float thickness = 1.0f) - { - drawing.FillRectangle(x, y, width, thickness, color); - drawing.FillRectangle(x, y + height - 1, width - 1, thickness, color); - drawing.FillRectangle(x, y, thickness, height, color); - drawing.FillRectangle(x + width - 1, y, thickness, height, color); - } - } -} +using OpenKh.Engine.Renders; + +namespace OpenKh.Engine.Extensions +{ + public static class SpriteDrawingExtensions + { + public static void SetProjection(this ISpriteDrawing spriteDrawing, + float width, float height, float internalWidth, float internalHeight, float ratio) + { + var heightRatio = internalHeight / height; + width *= heightRatio; + height *= heightRatio; + width *= ratio; + + var left = (internalWidth - width) / 2; + spriteDrawing.SetViewport(left, width + left, 0, height); + } + + public static void FillRectangle(this ISpriteDrawing drawing, float x, float y, float width, float height, ColorF color) + { + drawing.AppendSprite(new SpriteDrawingContext() + .Source(0, 0, 1, 1) + .Position(x, y) + .DestinationSize(width, height) + .Color(color)); + } + + public static void DrawRectangle(this ISpriteDrawing drawing, float x, float y, float width, float height, ColorF color, float thickness = 1.0f) + { + drawing.FillRectangle(x, y, width, thickness, color); + drawing.FillRectangle(x, y + height - 1, width - 1, thickness, color); + drawing.FillRectangle(x, y, thickness, height, color); + drawing.FillRectangle(x + width - 1, y, thickness, height, color); + } + } +} diff --git a/OpenKh.Engine/IEntity.cs b/OpenKh.Engine/IEntity.cs index 4cd1e1a03..247a687b3 100644 --- a/OpenKh.Engine/IEntity.cs +++ b/OpenKh.Engine/IEntity.cs @@ -1,21 +1,21 @@ -using System.Numerics; - -namespace OpenKh.Engine -{ - public interface IEntity - { - Vector3 Position { get; } - Vector3 Rotation { get; } - Vector3 Scaling { get; } - } - - public static class EntityExtensions - { - public static Matrix4x4 GetMatrix(this IEntity entity) => - Matrix4x4.CreateRotationX(entity.Rotation.X) * - Matrix4x4.CreateRotationY(entity.Rotation.Y) * - Matrix4x4.CreateRotationZ(entity.Rotation.Z) * - Matrix4x4.CreateScale(entity.Scaling.X, entity.Scaling.Y, entity.Scaling.Z) * - Matrix4x4.CreateTranslation(entity.Position.X, entity.Position.Y, entity.Position.Z); - } -} +using System.Numerics; + +namespace OpenKh.Engine +{ + public interface IEntity + { + Vector3 Position { get; } + Vector3 Rotation { get; } + Vector3 Scaling { get; } + } + + public static class EntityExtensions + { + public static Matrix4x4 GetMatrix(this IEntity entity) => + Matrix4x4.CreateRotationX(entity.Rotation.X) * + Matrix4x4.CreateRotationY(entity.Rotation.Y) * + Matrix4x4.CreateRotationZ(entity.Rotation.Z) * + Matrix4x4.CreateScale(entity.Scaling.X, entity.Scaling.Y, entity.Scaling.Z) * + Matrix4x4.CreateTranslation(entity.Position.X, entity.Position.Y, entity.Position.Z); + } +} diff --git a/OpenKh.Engine/IMessageProvider.cs b/OpenKh.Engine/IMessageProvider.cs index 63877e940..720e11f97 100644 --- a/OpenKh.Engine/IMessageProvider.cs +++ b/OpenKh.Engine/IMessageProvider.cs @@ -1,9 +1,9 @@ -namespace OpenKh.Engine -{ - public interface IMessageProvider - { - string GetString(ushort id); - - void SetString(ushort id, string text); - } -} +namespace OpenKh.Engine +{ + public interface IMessageProvider + { + string GetString(ushort id); + + void SetString(ushort id, string text); + } +} diff --git a/OpenKh.Engine/Input/IInput.cs b/OpenKh.Engine/Input/IInput.cs index e77f87eb5..9d45b54b3 100644 --- a/OpenKh.Engine/Input/IInput.cs +++ b/OpenKh.Engine/Input/IInput.cs @@ -1,16 +1,16 @@ -using System.Numerics; - -namespace OpenKh.Engine.Input -{ - public interface IInput - { - IInputButtons Pressed { get; } - IInputButtons Released { get; } - IInputButtons Repeated { get; } - IInputButtons Triggered { get; } - Vector3 AxisLeft { get; } - Vector3 AxisRight { get; } - - void Update(double deltaTime); - } -} +using System.Numerics; + +namespace OpenKh.Engine.Input +{ + public interface IInput + { + IInputButtons Pressed { get; } + IInputButtons Released { get; } + IInputButtons Repeated { get; } + IInputButtons Triggered { get; } + Vector3 AxisLeft { get; } + Vector3 AxisRight { get; } + + void Update(double deltaTime); + } +} diff --git a/OpenKh.Engine/Input/IInputButtons.cs b/OpenKh.Engine/Input/IInputButtons.cs index 6115905db..f2e3168da 100644 --- a/OpenKh.Engine/Input/IInputButtons.cs +++ b/OpenKh.Engine/Input/IInputButtons.cs @@ -1,24 +1,24 @@ -namespace OpenKh.Engine.Input -{ - public interface IInputButtons - { - bool Up { get; } - bool Down { get; } - bool Left { get; } - bool Right { get; } - bool FaceDown { get; } - bool FaceRight { get; } - bool FaceLeft { get; } - bool FaceUp { get; } - bool SpecialLeft { get; } - bool SpecialRight { get; } - bool L1 { get; } - bool L2 { get; } - bool L3 { get; } - bool R1 { get; } - bool R2 { get; } - bool R3 { get; } - bool Confirm { get; } - bool Cancel { get; } - } -} +namespace OpenKh.Engine.Input +{ + public interface IInputButtons + { + bool Up { get; } + bool Down { get; } + bool Left { get; } + bool Right { get; } + bool FaceDown { get; } + bool FaceRight { get; } + bool FaceLeft { get; } + bool FaceUp { get; } + bool SpecialLeft { get; } + bool SpecialRight { get; } + bool L1 { get; } + bool L2 { get; } + bool L3 { get; } + bool R1 { get; } + bool R2 { get; } + bool R3 { get; } + bool Confirm { get; } + bool Cancel { get; } + } +} diff --git a/OpenKh.Engine/Input/IInputDevice.cs b/OpenKh.Engine/Input/IInputDevice.cs index 390dd7fe0..f1e88ca66 100644 --- a/OpenKh.Engine/Input/IInputDevice.cs +++ b/OpenKh.Engine/Input/IInputDevice.cs @@ -1,12 +1,12 @@ -using System.Numerics; - -namespace OpenKh.Engine.Input -{ - public interface IInputDevice : IInputButtons - { - Vector3 AnalogLeft { get; } - Vector3 AnalogRight { get; } - - void Update(); - } -} +using System.Numerics; + +namespace OpenKh.Engine.Input +{ + public interface IInputDevice : IInputButtons + { + Vector3 AnalogLeft { get; } + Vector3 AnalogRight { get; } + + void Update(); + } +} diff --git a/OpenKh.Engine/Input/InputManager.cs b/OpenKh.Engine/Input/InputManager.cs index 20d8a74d6..681d94a1b 100644 --- a/OpenKh.Engine/Input/InputManager.cs +++ b/OpenKh.Engine/Input/InputManager.cs @@ -1,179 +1,179 @@ -using System.Numerics; - -namespace OpenKh.Engine.Input -{ - public class InputManager : IInput - { - private enum Button - { - Up, - Down, - Left, - Right, - FaceDown, - FaceRight, - FaceLeft, - FaceUp, - SpecialLeft, - SpecialRight, - L1, - L2, - L3, - R1, - R2, - R3, - Confirm, - Cancel, - } - - private class Buttons : IInputButtons - { - public uint Raw; - - public bool Up => (Raw & (1 << (int)Button.Up)) != 0; - public bool Down => (Raw & (1 << (int)Button.Down)) != 0; - public bool Left => (Raw & (1 << (int)Button.Left)) != 0; - public bool Right => (Raw & (1 << (int)Button.Right)) != 0; - public bool FaceDown => (Raw & (1 << (int)Button.FaceDown)) != 0; - public bool FaceRight => (Raw & (1 << (int)Button.FaceRight)) != 0; - public bool FaceLeft => (Raw & (1 << (int)Button.FaceLeft)) != 0; - public bool FaceUp => (Raw & (1 << (int)Button.FaceUp)) != 0; - public bool SpecialLeft => (Raw & (1 << (int)Button.SpecialLeft)) != 0; - public bool SpecialRight => (Raw & (1 << (int)Button.SpecialRight)) != 0; - public bool L1 => (Raw & (1 << (int)Button.L1)) != 0; - public bool L2 => (Raw & (1 << (int)Button.L2)) != 0; - public bool L3 => (Raw & (1 << (int)Button.L3)) != 0; - public bool R1 => (Raw & (1 << (int)Button.R1)) != 0; - public bool R2 => (Raw & (1 << (int)Button.R2)) != 0; - public bool R3 => (Raw & (1 << (int)Button.R3)) != 0; - public bool Confirm => (Raw & (1 << 16)) != 0; - public bool Cancel => (Raw & (1 << 17)) != 0; - - public void MakeConfirmCancel(Button confirmMask, Button cancelMask) - { - Raw &= ~(1U << (int)Button.Confirm); - Raw &= ~(1U << (int)Button.Cancel); - - if ((Raw & (1 << (int)confirmMask)) != 0) - Raw |= (1U << (int)Button.Confirm); - if ((Raw & (1 << (int)cancelMask)) != 0) - Raw |= (1U << (int)Button.Cancel); - - } - } - - private const float ContinuousRepeatTime = 0.05f; - private const float MinimumRepeatTime = 1f / 3f - ContinuousRepeatTime; - - private readonly Button _buttonConfirmMask; - private readonly Button _buttonCancelMask; - private readonly IInputDevice[] _devices; - private readonly Buttons _pressed = new Buttons(); - private readonly Buttons _released = new Buttons(); - private readonly Buttons _triggered = new Buttons(); - private readonly Buttons _repeated = new Buttons(); - private float[] _repeatTimers = new float[sizeof(uint) * 8]; - - public IInputButtons Pressed => _pressed; - public IInputButtons Released => _released; - public IInputButtons Triggered => _triggered; - public IInputButtons Repeated => _repeated; - public Vector3 AxisLeft { get; private set; } - public Vector3 AxisRight { get; private set; } - - public InputManager(bool japaneseStyleButtons, params IInputDevice[] devices) - { - _buttonConfirmMask = japaneseStyleButtons ? Button.FaceRight : Button.FaceDown; - _buttonCancelMask = japaneseStyleButtons ? Button.FaceDown : Button.FaceRight; - _devices = devices; - } - - public void Update(double deltaTime) - { - foreach (var device in _devices) - device.Update(); - - var previouslyPressed = _pressed.Raw; - var pressedNow = 0U; - AxisLeft = Vector3.Zero; - AxisRight = Vector3.Zero; - foreach (var device in _devices) - { - if (device.Up) - pressedNow |= 1 << (int)Button.Up; - if (device.Down) - pressedNow |= 1 << (int)Button.Down; - if (device.Left) - pressedNow |= 1 << (int)Button.Left; - if (device.Right) - pressedNow |= 1 << (int)Button.Right; - if (device.FaceDown) - pressedNow |= 1 << (int)Button.FaceDown; - if (device.FaceRight) - pressedNow |= 1 << (int)Button.FaceRight; - if (device.FaceLeft) - pressedNow |= 1 << (int)Button.FaceLeft; - if (device.FaceUp) - pressedNow |= 1 << (int)Button.FaceUp; - if (device.SpecialLeft) - pressedNow |= 1 << (int)Button.SpecialLeft; - if (device.SpecialRight) - pressedNow |= 1 << (int)Button.SpecialRight; - if (device.L1) - pressedNow |= 1 << (int)Button.L1; - if (device.L2) - pressedNow |= 1 << (int)Button.L2; - if (device.L3) - pressedNow |= 1 << (int)Button.L3; - if (device.R1) - pressedNow |= 1 << (int)Button.R1; - if (device.R2) - pressedNow |= 1 << (int)Button.R2; - if (device.R3) - pressedNow |= 1 << (int)Button.R3; - - if (device.AnalogLeft != Vector3.Zero) - AxisLeft = device.AnalogLeft; - if (device.AnalogRight != Vector3.Zero) - AxisRight = device.AnalogRight; - } - - _pressed.Raw = pressedNow; - _released.Raw = (pressedNow ^ previouslyPressed) & ~pressedNow; - _triggered.Raw = (pressedNow ^ previouslyPressed) & pressedNow; - - _repeated.Raw = 0; - for (var i = 0; i < _repeatTimers.Length; i++) - { - var flag = 1U << i; - var isPressed = (_pressed.Raw & flag) != 0; - if (isPressed) - { - _repeatTimers[i] += (float)deltaTime; - if (_repeatTimers[i] >= MinimumRepeatTime) - { - var continuousRepeatTimer = _repeatTimers[i] - MinimumRepeatTime; - if (continuousRepeatTimer >= ContinuousRepeatTime) - { - continuousRepeatTimer %= ContinuousRepeatTime; - _repeated.Raw |= flag; - } - - _repeatTimers[i] = MinimumRepeatTime + continuousRepeatTimer; - } - else if (isPressed) - { - _repeated.Raw |= _triggered.Raw & flag; - } - } - else - _repeatTimers[i] = 0f; - } - - _pressed.MakeConfirmCancel(_buttonConfirmMask, _buttonCancelMask); - _released.MakeConfirmCancel(_buttonConfirmMask, _buttonCancelMask); - _triggered.MakeConfirmCancel(_buttonConfirmMask, _buttonCancelMask); - _repeated.MakeConfirmCancel(_buttonConfirmMask, _buttonCancelMask); - } - } -} +using System.Numerics; + +namespace OpenKh.Engine.Input +{ + public class InputManager : IInput + { + private enum Button + { + Up, + Down, + Left, + Right, + FaceDown, + FaceRight, + FaceLeft, + FaceUp, + SpecialLeft, + SpecialRight, + L1, + L2, + L3, + R1, + R2, + R3, + Confirm, + Cancel, + } + + private class Buttons : IInputButtons + { + public uint Raw; + + public bool Up => (Raw & (1 << (int)Button.Up)) != 0; + public bool Down => (Raw & (1 << (int)Button.Down)) != 0; + public bool Left => (Raw & (1 << (int)Button.Left)) != 0; + public bool Right => (Raw & (1 << (int)Button.Right)) != 0; + public bool FaceDown => (Raw & (1 << (int)Button.FaceDown)) != 0; + public bool FaceRight => (Raw & (1 << (int)Button.FaceRight)) != 0; + public bool FaceLeft => (Raw & (1 << (int)Button.FaceLeft)) != 0; + public bool FaceUp => (Raw & (1 << (int)Button.FaceUp)) != 0; + public bool SpecialLeft => (Raw & (1 << (int)Button.SpecialLeft)) != 0; + public bool SpecialRight => (Raw & (1 << (int)Button.SpecialRight)) != 0; + public bool L1 => (Raw & (1 << (int)Button.L1)) != 0; + public bool L2 => (Raw & (1 << (int)Button.L2)) != 0; + public bool L3 => (Raw & (1 << (int)Button.L3)) != 0; + public bool R1 => (Raw & (1 << (int)Button.R1)) != 0; + public bool R2 => (Raw & (1 << (int)Button.R2)) != 0; + public bool R3 => (Raw & (1 << (int)Button.R3)) != 0; + public bool Confirm => (Raw & (1 << 16)) != 0; + public bool Cancel => (Raw & (1 << 17)) != 0; + + public void MakeConfirmCancel(Button confirmMask, Button cancelMask) + { + Raw &= ~(1U << (int)Button.Confirm); + Raw &= ~(1U << (int)Button.Cancel); + + if ((Raw & (1 << (int)confirmMask)) != 0) + Raw |= (1U << (int)Button.Confirm); + if ((Raw & (1 << (int)cancelMask)) != 0) + Raw |= (1U << (int)Button.Cancel); + + } + } + + private const float ContinuousRepeatTime = 0.05f; + private const float MinimumRepeatTime = 1f / 3f - ContinuousRepeatTime; + + private readonly Button _buttonConfirmMask; + private readonly Button _buttonCancelMask; + private readonly IInputDevice[] _devices; + private readonly Buttons _pressed = new Buttons(); + private readonly Buttons _released = new Buttons(); + private readonly Buttons _triggered = new Buttons(); + private readonly Buttons _repeated = new Buttons(); + private float[] _repeatTimers = new float[sizeof(uint) * 8]; + + public IInputButtons Pressed => _pressed; + public IInputButtons Released => _released; + public IInputButtons Triggered => _triggered; + public IInputButtons Repeated => _repeated; + public Vector3 AxisLeft { get; private set; } + public Vector3 AxisRight { get; private set; } + + public InputManager(bool japaneseStyleButtons, params IInputDevice[] devices) + { + _buttonConfirmMask = japaneseStyleButtons ? Button.FaceRight : Button.FaceDown; + _buttonCancelMask = japaneseStyleButtons ? Button.FaceDown : Button.FaceRight; + _devices = devices; + } + + public void Update(double deltaTime) + { + foreach (var device in _devices) + device.Update(); + + var previouslyPressed = _pressed.Raw; + var pressedNow = 0U; + AxisLeft = Vector3.Zero; + AxisRight = Vector3.Zero; + foreach (var device in _devices) + { + if (device.Up) + pressedNow |= 1 << (int)Button.Up; + if (device.Down) + pressedNow |= 1 << (int)Button.Down; + if (device.Left) + pressedNow |= 1 << (int)Button.Left; + if (device.Right) + pressedNow |= 1 << (int)Button.Right; + if (device.FaceDown) + pressedNow |= 1 << (int)Button.FaceDown; + if (device.FaceRight) + pressedNow |= 1 << (int)Button.FaceRight; + if (device.FaceLeft) + pressedNow |= 1 << (int)Button.FaceLeft; + if (device.FaceUp) + pressedNow |= 1 << (int)Button.FaceUp; + if (device.SpecialLeft) + pressedNow |= 1 << (int)Button.SpecialLeft; + if (device.SpecialRight) + pressedNow |= 1 << (int)Button.SpecialRight; + if (device.L1) + pressedNow |= 1 << (int)Button.L1; + if (device.L2) + pressedNow |= 1 << (int)Button.L2; + if (device.L3) + pressedNow |= 1 << (int)Button.L3; + if (device.R1) + pressedNow |= 1 << (int)Button.R1; + if (device.R2) + pressedNow |= 1 << (int)Button.R2; + if (device.R3) + pressedNow |= 1 << (int)Button.R3; + + if (device.AnalogLeft != Vector3.Zero) + AxisLeft = device.AnalogLeft; + if (device.AnalogRight != Vector3.Zero) + AxisRight = device.AnalogRight; + } + + _pressed.Raw = pressedNow; + _released.Raw = (pressedNow ^ previouslyPressed) & ~pressedNow; + _triggered.Raw = (pressedNow ^ previouslyPressed) & pressedNow; + + _repeated.Raw = 0; + for (var i = 0; i < _repeatTimers.Length; i++) + { + var flag = 1U << i; + var isPressed = (_pressed.Raw & flag) != 0; + if (isPressed) + { + _repeatTimers[i] += (float)deltaTime; + if (_repeatTimers[i] >= MinimumRepeatTime) + { + var continuousRepeatTimer = _repeatTimers[i] - MinimumRepeatTime; + if (continuousRepeatTimer >= ContinuousRepeatTime) + { + continuousRepeatTimer %= ContinuousRepeatTime; + _repeated.Raw |= flag; + } + + _repeatTimers[i] = MinimumRepeatTime + continuousRepeatTimer; + } + else if (isPressed) + { + _repeated.Raw |= _triggered.Raw & flag; + } + } + else + _repeatTimers[i] = 0f; + } + + _pressed.MakeConfirmCancel(_buttonConfirmMask, _buttonCancelMask); + _released.MakeConfirmCancel(_buttonConfirmMask, _buttonCancelMask); + _triggered.MakeConfirmCancel(_buttonConfirmMask, _buttonCancelMask); + _repeated.MakeConfirmCancel(_buttonConfirmMask, _buttonCancelMask); + } + } +} diff --git a/OpenKh.Engine/Kh2MessageProvider.cs b/OpenKh.Engine/Kh2MessageProvider.cs index 94427af88..058171210 100644 --- a/OpenKh.Engine/Kh2MessageProvider.cs +++ b/OpenKh.Engine/Kh2MessageProvider.cs @@ -1,34 +1,34 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Engine -{ - public class Kh2MessageProvider : IMessageProvider - { - private Dictionary _messages = new Dictionary(); - - public IMessageEncoder Encoder { get; set; } = Encoders.InternationalSystem; - - public byte[] GetMessage(ushort id) - { - if (_messages.TryGetValue(id & 0x7fff, out var data)) - return data; - - if (_messages.TryGetValue(Msg.FallbackMessage, out data)) - return data; - - return new byte[0]; - } - - public string GetString(ushort id) => - MsgSerializer.SerializeText(Encoder.Decode(GetMessage(id))); - - public void SetString(ushort id, string text) => - _messages[id] = Encoder.Encode(MsgSerializer.DeserializeText(text).ToList()); - - public void Load(List entries) => - _messages = entries.ToDictionary(x => x.Id, x => x.Data); - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Engine +{ + public class Kh2MessageProvider : IMessageProvider + { + private Dictionary _messages = new Dictionary(); + + public IMessageEncoder Encoder { get; set; } = Encoders.InternationalSystem; + + public byte[] GetMessage(ushort id) + { + if (_messages.TryGetValue(id & 0x7fff, out var data)) + return data; + + if (_messages.TryGetValue(Msg.FallbackMessage, out data)) + return data; + + return new byte[0]; + } + + public string GetString(ushort id) => + MsgSerializer.SerializeText(Encoder.Decode(GetMessage(id))); + + public void SetString(ushort id, string text) => + _messages[id] = Encoder.Encode(MsgSerializer.DeserializeText(text).ToList()); + + public void Load(List entries) => + _messages = entries.ToDictionary(x => x.Id, x => x.Data); + } +} diff --git a/OpenKh.Engine/MathEx.cs b/OpenKh.Engine/MathEx.cs index fdae3030b..9f30482cd 100644 --- a/OpenKh.Engine/MathEx.cs +++ b/OpenKh.Engine/MathEx.cs @@ -1,17 +1,17 @@ -namespace OpenKh.Engine -{ - public static class MathEx - { - public static float Lerp(float firstFloat, float secondFloat, float by) - { - return firstFloat * (1 - by) + secondFloat * by; - } - - public static float CubicHermite(float t, float p0, float p1, float m0, float m1) - { - var t2 = t * t; - var t3 = t2 * t; - return (2 * t3 - 3 * t2 + 1) * p0 + (t3 - 2 * t2 + t) * m0 + (-2 * t3 + 3 * t2) * p1 + (t3 - t2) * m1; - } - } -} +namespace OpenKh.Engine +{ + public static class MathEx + { + public static float Lerp(float firstFloat, float secondFloat, float by) + { + return firstFloat * (1 - by) + secondFloat * by; + } + + public static float CubicHermite(float t, float p0, float p1, float m0, float m1) + { + var t2 = t * t; + var t3 = t2 * t; + return (2 * t3 - 3 * t2 + 1) * p0 + (t3 - 2 * t2 + t) * m0 + (-2 * t3 + 3 * t2) * p1 + (t3 - t2) * m1; + } + } +} diff --git a/OpenKh.Engine/Motion/IModelMotion.cs b/OpenKh.Engine/Motion/IModelMotion.cs index 3e0a5459a..190e15682 100644 --- a/OpenKh.Engine/Motion/IModelMotion.cs +++ b/OpenKh.Engine/Motion/IModelMotion.cs @@ -1,20 +1,20 @@ -using OpenKh.Engine.Parsers; -using OpenKh.Kh2; -using System.Collections.Generic; -using System.Numerics; - -namespace OpenKh.Engine.Motion -{ - public interface IModelMotion - { - List MeshDescriptors { get; } - - List Bones { get; } // Not a very good practice, but it's temporary - - Matrix4x4[] InitialPose { get; } - - Matrix4x4[] CurrentPose { get; } - - void ApplyMotion(Matrix4x4[] matrices); - } -} +using OpenKh.Engine.Parsers; +using OpenKh.Kh2; +using System.Collections.Generic; +using System.Numerics; + +namespace OpenKh.Engine.Motion +{ + public interface IModelMotion + { + List MeshDescriptors { get; } + + List Bones { get; } // Not a very good practice, but it's temporary + + Matrix4x4[] InitialPose { get; } + + Matrix4x4[] CurrentPose { get; } + + void ApplyMotion(Matrix4x4[] matrices); + } +} diff --git a/OpenKh.Engine/Motion/IMotionEngine.cs b/OpenKh.Engine/Motion/IMotionEngine.cs index 743c81fdf..7eec63f6a 100644 --- a/OpenKh.Engine/Motion/IMotionEngine.cs +++ b/OpenKh.Engine/Motion/IMotionEngine.cs @@ -1,7 +1,7 @@ -namespace OpenKh.Engine.Motion -{ - public interface IMotionEngine - { - void ApplyMotion(IModelMotion model, float time); - } -} +namespace OpenKh.Engine.Motion +{ + public interface IMotionEngine + { + void ApplyMotion(IModelMotion model, float time); + } +} diff --git a/OpenKh.Engine/Motion/Kh2MotionEngine.cs b/OpenKh.Engine/Motion/Kh2MotionEngine.cs index 9a2e8ceb4..35c5a79f5 100644 --- a/OpenKh.Engine/Motion/Kh2MotionEngine.cs +++ b/OpenKh.Engine/Motion/Kh2MotionEngine.cs @@ -1,312 +1,312 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; - -namespace OpenKh.Engine.Motion -{ - public class Kh2MotionEngine : IMotionEngine - { - private readonly Bar _binarc; - private int _animationIndex; - private int _slotIndex; - private Kh2.Motion _motion; - - public Kh2MotionEngine() - { - _binarc = null; - _animationIndex = -1; - } - - public Kh2MotionEngine(Bar binarc) - { - _binarc = binarc; - _animationIndex = -1; - } - - public int AnimationCount => _binarc?.Count ?? 0; - - public int CurrentAnimationIndex - { - get => _animationIndex; - set - { - if (_animationIndex == value) - return; - - _animationIndex = value; - if (_binarc == null) - { - Console.Error.WriteLine($"Does not have a MSET."); - return; - } - - _slotIndex = _binarc.Motionset == Bar.MotionsetType.Default ? _animationIndex : - MotionSet.GetMotionSetIndex(_binarc, (MotionSet.MotionName)_animationIndex, false, false); - if (_slotIndex >= 0 && _binarc[_slotIndex].Stream.Length > 0) - { - var subEntries = Bar.Read(_binarc[_slotIndex].Stream.SetPosition(0)); - var animationDataEntry = subEntries.FirstOrDefault(x => x.Type == Bar.EntryType.Motion); - if (animationDataEntry != null) - _motion = Kh2.Motion.Read(animationDataEntry.Stream.SetPosition(0)); - else - Console.Error.WriteLine($"MSET animation {CurrentAnimationIndex} ({CurrentAnimationShortName}) does not contain any {Bar.EntryType.Motion}"); - - var animationBinaryEntry = subEntries.FirstOrDefault(x => x.Type == Bar.EntryType.MotionTriggers); - if (animationDataEntry != null) - { - // We do not have any ANB parser - } - else - Console.Error.WriteLine($"MSET animation {CurrentAnimationIndex} ({CurrentAnimationShortName}) does not contain any {Bar.EntryType.MotionTriggers}"); - } - else - { - Console.Error.WriteLine($"MSET animation {_animationIndex} ({CurrentAnimationShortName}) not found. Falling back to T-pose."); - _slotIndex = -1; - _motion = null; - } - } - } - - public int CurrentSlotIndex => _slotIndex; - - public string CurrentAnimationShortName => - _animationIndex >= 0 ? ((MotionSet.MotionName)_animationIndex).ToString() : "dummy"; - - public Kh2.Motion CurrentMotion => _motion; - - public void ApplyMotion(IModelMotion model, float time) - { - if (CurrentMotion == null) - model.ApplyMotion(model.InitialPose); - else if (CurrentMotion.IsRaw) - ApplyRawMotion(model, CurrentMotion.Raw, time); - else - ApplyInterpolatedMotion(model, CurrentMotion.Interpolated, time); - } - - private void ApplyRawMotion(IModelMotion model, Kh2.Motion.RawMotion motion, float time) - { - var absoluteFrame = (int)Math.Floor(motion.FramePerSecond * time); - var actualFrame = absoluteFrame % motion.Matrices.Count; - model.ApplyMotion(motion.Matrices[actualFrame]); - } - - public static void ApplyInterpolatedMotion(IModelMotion model, Kh2.Motion.InterpolatedMotion motion, float time) - { - var absoluteFrame = (float)Math.Floor(60.0f * time); - var actualFrame = (int)Loop(motion.FrameCount * 2, motion.FrameEnd * 2, absoluteFrame); - - var boneList = model.Bones; - var matrices = new Matrix4x4[boneList.Count]; - - var totalBoneCount = Math.Max(motion.BoneCount, model.Bones.Count) + motion.IKHelpers.Count; - var sourceTranslations = new Vector3[totalBoneCount]; - var sourceRotations = new Quaternion[totalBoneCount]; - var absTranslationList = new Vector3[totalBoneCount]; - var absRotationList = new Quaternion[totalBoneCount]; - - for (var i = 0; i < model.Bones.Count; i++) - { - var bone = model.Bones[i]; - sourceRotations[i].X = bone.RotationX; - sourceRotations[i].Y = bone.RotationY; - sourceRotations[i].Z = bone.RotationZ; - sourceTranslations[i].X = bone.TranslationX; - sourceTranslations[i].Y = bone.TranslationY; - sourceTranslations[i].Z = bone.TranslationZ; - } - - foreach (var pose in motion.StaticPose) - { - switch (pose.Channel) - { - case 3: - sourceRotations[pose.BoneIndex].X = pose.Value; - break; - case 4: - sourceRotations[pose.BoneIndex].Y = pose.Value; - break; - case 5: - sourceRotations[pose.BoneIndex].Z = pose.Value; - break; - case 6: - sourceTranslations[pose.BoneIndex].X = pose.Value; - break; - case 7: - sourceTranslations[pose.BoneIndex].Y = pose.Value; - break; - case 8: - sourceTranslations[pose.BoneIndex].Z = pose.Value; - break; - } - } - - foreach (var animation in motion.ModelBoneAnimation) - { - // Check if it would be better to use a linear or binary search - if (true || animation.TimelineCount < 4) - { - for (var index = animation.TimelineCount - 1; index >= 0; index--) - { - - if (actualFrame >= motion.Timeline[animation.TimelineStartIndex + index].KeyFrame) - { - PerformInterpolation(motion.Timeline, animation, sourceTranslations, sourceRotations, actualFrame, index); - break; - } - } - } - else - { - // If there are two keyframes, just interpolate between 0 and 1 - if (animation.TimelineCount < 3) - { - PerformInterpolation(motion.Timeline, animation, sourceTranslations, sourceRotations, actualFrame, 0); - continue; - } - - var left = 0; - var right = animation.TimelineCount - 1; - while (true) - { - var mid = (left + right) / 2; - var keyFrame = motion.Timeline[animation.TimelineStartIndex + mid].KeyFrame; - if (actualFrame >= keyFrame) - { - if (actualFrame <= keyFrame) - { - PerformInterpolation(motion.Timeline, animation, sourceTranslations, sourceRotations, actualFrame, mid); - break; - } - - left = mid; - } - else - right = mid; - - if (right - left <= 1) - { - PerformInterpolation(motion.Timeline, animation, sourceTranslations, sourceRotations, actualFrame, right - 1); - break; - } - } - } - } - - for (int x = 0; x < matrices.Length; x++) - { - Quaternion absRotation; - Vector3 absTranslation; - var oneBone = boneList[x]; - var parent = oneBone.Parent; - if (parent < 0) - { - absRotation = Quaternion.Identity; - absTranslation = Vector3.Zero; - } - else - { - absRotation = absRotationList[parent]; - absTranslation = absTranslationList[parent]; - } - - var localTranslation = Vector3.Transform(sourceTranslations[x], Matrix4x4.CreateFromQuaternion(absRotation)); - absTranslationList[x] = absTranslation + localTranslation; - - var localRotation = Quaternion.Identity; - localRotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitZ, sourceRotations[x].Z); - localRotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitY, sourceRotations[x].Y); - localRotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitX, sourceRotations[x].X); - absRotationList[x] = absRotation * localRotation; - } - - for (int x = 0; x < matrices.Length; x++) - { - var absMatrix = Matrix4x4.Identity; - absMatrix *= Matrix4x4.CreateFromQuaternion(absRotationList[x]); - absMatrix *= Matrix4x4.CreateTranslation(absTranslationList[x]); - matrices[x] = absMatrix; - } - - model.ApplyMotion(matrices); - } - - private static void PerformInterpolation( - IList timelines, - Kh2.Motion.BoneAnimationTable animation, - Vector3[] sourceTranslations, - Quaternion[] sourceRotations, - int actualFrame, - int currentIndex) - { - var left = timelines[animation.TimelineStartIndex + currentIndex]; - var right = currentIndex < animation.TimelineCount - 1 - ? timelines[animation.TimelineStartIndex + currentIndex + 1] - : timelines[animation.TimelineStartIndex]; - - var timeDiff = right.KeyFrame - left.KeyFrame; - var n = (actualFrame - left.KeyFrame) / timeDiff; - float value; - switch (left.Interpolation) - { - case Kh2.Motion.Interpolation.Nearest: - value = left.Value; - break; - case Kh2.Motion.Interpolation.Linear: - value = MathEx.Lerp(left.Value, right.Value, n); - break; - case Kh2.Motion.Interpolation.Hermite: - case Kh2.Motion.Interpolation.Hermite3: // Unknown why (and where) it is used - case Kh2.Motion.Interpolation.Hermite4: // Unknown why (and where) it is used - value = MathEx.CubicHermite( - n, left.Value, right.Value, - left.TangentEaseIn, left.TangentEaseOut); - break; - default: - value = 0; - break; - } - - switch (animation.Channel) - { - case 3: - sourceRotations[animation.JointIndex].X = value; - break; - case 4: - sourceRotations[animation.JointIndex].Y = value; - break; - case 5: - sourceRotations[animation.JointIndex].Z = value; - break; - case 6: - sourceTranslations[animation.JointIndex].X = value; - break; - case 7: - sourceTranslations[animation.JointIndex].Y = value; - break; - case 8: - sourceTranslations[animation.JointIndex].Z = value; - break; - } - } - - public void UseCustomMotion(Kh2.Motion motion) => _motion = motion; - - private static float Loop(float min, float max, float val) - { - if (val < max) - return val; - if (max <= min) - return min; - - var mod = (val - min) % (max - min); - if (mod < 0) - mod += max - min; - return min + mod; - } - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; + +namespace OpenKh.Engine.Motion +{ + public class Kh2MotionEngine : IMotionEngine + { + private readonly Bar _binarc; + private int _animationIndex; + private int _slotIndex; + private Kh2.Motion _motion; + + public Kh2MotionEngine() + { + _binarc = null; + _animationIndex = -1; + } + + public Kh2MotionEngine(Bar binarc) + { + _binarc = binarc; + _animationIndex = -1; + } + + public int AnimationCount => _binarc?.Count ?? 0; + + public int CurrentAnimationIndex + { + get => _animationIndex; + set + { + if (_animationIndex == value) + return; + + _animationIndex = value; + if (_binarc == null) + { + Console.Error.WriteLine($"Does not have a MSET."); + return; + } + + _slotIndex = _binarc.Motionset == Bar.MotionsetType.Default ? _animationIndex : + MotionSet.GetMotionSetIndex(_binarc, (MotionSet.MotionName)_animationIndex, false, false); + if (_slotIndex >= 0 && _binarc[_slotIndex].Stream.Length > 0) + { + var subEntries = Bar.Read(_binarc[_slotIndex].Stream.SetPosition(0)); + var animationDataEntry = subEntries.FirstOrDefault(x => x.Type == Bar.EntryType.Motion); + if (animationDataEntry != null) + _motion = Kh2.Motion.Read(animationDataEntry.Stream.SetPosition(0)); + else + Console.Error.WriteLine($"MSET animation {CurrentAnimationIndex} ({CurrentAnimationShortName}) does not contain any {Bar.EntryType.Motion}"); + + var animationBinaryEntry = subEntries.FirstOrDefault(x => x.Type == Bar.EntryType.MotionTriggers); + if (animationDataEntry != null) + { + // We do not have any ANB parser + } + else + Console.Error.WriteLine($"MSET animation {CurrentAnimationIndex} ({CurrentAnimationShortName}) does not contain any {Bar.EntryType.MotionTriggers}"); + } + else + { + Console.Error.WriteLine($"MSET animation {_animationIndex} ({CurrentAnimationShortName}) not found. Falling back to T-pose."); + _slotIndex = -1; + _motion = null; + } + } + } + + public int CurrentSlotIndex => _slotIndex; + + public string CurrentAnimationShortName => + _animationIndex >= 0 ? ((MotionSet.MotionName)_animationIndex).ToString() : "dummy"; + + public Kh2.Motion CurrentMotion => _motion; + + public void ApplyMotion(IModelMotion model, float time) + { + if (CurrentMotion == null) + model.ApplyMotion(model.InitialPose); + else if (CurrentMotion.IsRaw) + ApplyRawMotion(model, CurrentMotion.Raw, time); + else + ApplyInterpolatedMotion(model, CurrentMotion.Interpolated, time); + } + + private void ApplyRawMotion(IModelMotion model, Kh2.Motion.RawMotion motion, float time) + { + var absoluteFrame = (int)Math.Floor(motion.FramePerSecond * time); + var actualFrame = absoluteFrame % motion.Matrices.Count; + model.ApplyMotion(motion.Matrices[actualFrame]); + } + + public static void ApplyInterpolatedMotion(IModelMotion model, Kh2.Motion.InterpolatedMotion motion, float time) + { + var absoluteFrame = (float)Math.Floor(60.0f * time); + var actualFrame = (int)Loop(motion.FrameCount * 2, motion.FrameEnd * 2, absoluteFrame); + + var boneList = model.Bones; + var matrices = new Matrix4x4[boneList.Count]; + + var totalBoneCount = Math.Max(motion.BoneCount, model.Bones.Count) + motion.IKHelpers.Count; + var sourceTranslations = new Vector3[totalBoneCount]; + var sourceRotations = new Quaternion[totalBoneCount]; + var absTranslationList = new Vector3[totalBoneCount]; + var absRotationList = new Quaternion[totalBoneCount]; + + for (var i = 0; i < model.Bones.Count; i++) + { + var bone = model.Bones[i]; + sourceRotations[i].X = bone.RotationX; + sourceRotations[i].Y = bone.RotationY; + sourceRotations[i].Z = bone.RotationZ; + sourceTranslations[i].X = bone.TranslationX; + sourceTranslations[i].Y = bone.TranslationY; + sourceTranslations[i].Z = bone.TranslationZ; + } + + foreach (var pose in motion.StaticPose) + { + switch (pose.Channel) + { + case 3: + sourceRotations[pose.BoneIndex].X = pose.Value; + break; + case 4: + sourceRotations[pose.BoneIndex].Y = pose.Value; + break; + case 5: + sourceRotations[pose.BoneIndex].Z = pose.Value; + break; + case 6: + sourceTranslations[pose.BoneIndex].X = pose.Value; + break; + case 7: + sourceTranslations[pose.BoneIndex].Y = pose.Value; + break; + case 8: + sourceTranslations[pose.BoneIndex].Z = pose.Value; + break; + } + } + + foreach (var animation in motion.ModelBoneAnimation) + { + // Check if it would be better to use a linear or binary search + if (true || animation.TimelineCount < 4) + { + for (var index = animation.TimelineCount - 1; index >= 0; index--) + { + + if (actualFrame >= motion.Timeline[animation.TimelineStartIndex + index].KeyFrame) + { + PerformInterpolation(motion.Timeline, animation, sourceTranslations, sourceRotations, actualFrame, index); + break; + } + } + } + else + { + // If there are two keyframes, just interpolate between 0 and 1 + if (animation.TimelineCount < 3) + { + PerformInterpolation(motion.Timeline, animation, sourceTranslations, sourceRotations, actualFrame, 0); + continue; + } + + var left = 0; + var right = animation.TimelineCount - 1; + while (true) + { + var mid = (left + right) / 2; + var keyFrame = motion.Timeline[animation.TimelineStartIndex + mid].KeyFrame; + if (actualFrame >= keyFrame) + { + if (actualFrame <= keyFrame) + { + PerformInterpolation(motion.Timeline, animation, sourceTranslations, sourceRotations, actualFrame, mid); + break; + } + + left = mid; + } + else + right = mid; + + if (right - left <= 1) + { + PerformInterpolation(motion.Timeline, animation, sourceTranslations, sourceRotations, actualFrame, right - 1); + break; + } + } + } + } + + for (int x = 0; x < matrices.Length; x++) + { + Quaternion absRotation; + Vector3 absTranslation; + var oneBone = boneList[x]; + var parent = oneBone.Parent; + if (parent < 0) + { + absRotation = Quaternion.Identity; + absTranslation = Vector3.Zero; + } + else + { + absRotation = absRotationList[parent]; + absTranslation = absTranslationList[parent]; + } + + var localTranslation = Vector3.Transform(sourceTranslations[x], Matrix4x4.CreateFromQuaternion(absRotation)); + absTranslationList[x] = absTranslation + localTranslation; + + var localRotation = Quaternion.Identity; + localRotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitZ, sourceRotations[x].Z); + localRotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitY, sourceRotations[x].Y); + localRotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitX, sourceRotations[x].X); + absRotationList[x] = absRotation * localRotation; + } + + for (int x = 0; x < matrices.Length; x++) + { + var absMatrix = Matrix4x4.Identity; + absMatrix *= Matrix4x4.CreateFromQuaternion(absRotationList[x]); + absMatrix *= Matrix4x4.CreateTranslation(absTranslationList[x]); + matrices[x] = absMatrix; + } + + model.ApplyMotion(matrices); + } + + private static void PerformInterpolation( + IList timelines, + Kh2.Motion.BoneAnimationTable animation, + Vector3[] sourceTranslations, + Quaternion[] sourceRotations, + int actualFrame, + int currentIndex) + { + var left = timelines[animation.TimelineStartIndex + currentIndex]; + var right = currentIndex < animation.TimelineCount - 1 + ? timelines[animation.TimelineStartIndex + currentIndex + 1] + : timelines[animation.TimelineStartIndex]; + + var timeDiff = right.KeyFrame - left.KeyFrame; + var n = (actualFrame - left.KeyFrame) / timeDiff; + float value; + switch (left.Interpolation) + { + case Kh2.Motion.Interpolation.Nearest: + value = left.Value; + break; + case Kh2.Motion.Interpolation.Linear: + value = MathEx.Lerp(left.Value, right.Value, n); + break; + case Kh2.Motion.Interpolation.Hermite: + case Kh2.Motion.Interpolation.Hermite3: // Unknown why (and where) it is used + case Kh2.Motion.Interpolation.Hermite4: // Unknown why (and where) it is used + value = MathEx.CubicHermite( + n, left.Value, right.Value, + left.TangentEaseIn, left.TangentEaseOut); + break; + default: + value = 0; + break; + } + + switch (animation.Channel) + { + case 3: + sourceRotations[animation.JointIndex].X = value; + break; + case 4: + sourceRotations[animation.JointIndex].Y = value; + break; + case 5: + sourceRotations[animation.JointIndex].Z = value; + break; + case 6: + sourceTranslations[animation.JointIndex].X = value; + break; + case 7: + sourceTranslations[animation.JointIndex].Y = value; + break; + case 8: + sourceTranslations[animation.JointIndex].Z = value; + break; + } + } + + public void UseCustomMotion(Kh2.Motion motion) => _motion = motion; + + private static float Loop(float min, float max, float val) + { + if (val < max) + return val; + if (max <= min) + return min; + + var mod = (val - min) % (max - min); + if (mod < 0) + mod += max - min; + return min + mod; + } + } +} diff --git a/OpenKh.Engine/Parsers/Kkdf2MdlxParser.cs b/OpenKh.Engine/Parsers/Kkdf2MdlxParser.cs index 002d7a6ab..d18e36640 100644 --- a/OpenKh.Engine/Parsers/Kkdf2MdlxParser.cs +++ b/OpenKh.Engine/Parsers/Kkdf2MdlxParser.cs @@ -1,247 +1,247 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Ps2; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Numerics; - -namespace OpenKh.Engine.Parsers -{ - public class Kkdf2MdlxParser - { - private class ImmutableMesh - { - public Mdlx.DmaChain DmaChain { get; } - public List VpuPackets { get; } - - public int TextureIndex => DmaChain.TextureIndex; - public bool IsOpaque => (DmaChain.RenderFlags & 1) == 0; - - public ImmutableMesh(Mdlx.DmaChain dmaChain) - { - DmaChain = dmaChain; - VpuPackets = dmaChain.DmaVifs - .Select(dmaVif => - { - var unpacker = new VifUnpacker(dmaVif.VifPacket); - unpacker.Run(); - - using (var stream = new MemoryStream(unpacker.Memory)) - return VpuPacket.Read(stream); - }) - .ToList(); - } - } - - private class VertexRef - { - public int vertexIndex, uvIndex; - - public VertexRef(int vertexIndex, int uvIndex) - { - this.vertexIndex = vertexIndex; - this.uvIndex = uvIndex; - } - } - - private class TriangleRef - { - public TriangleRef(VertexRef one, VertexRef two, VertexRef three) - { - list = new VertexRef[] { one, two, three }; - } - - public VertexRef[] list; - public int textureIndex; - public bool isOpaque; - } - - private class ExportedMesh - { - public class Part - { - public int TextureIndex; - public bool IsOpaque; - public List triangleRefList = new List(); - } - - public List partList = new List(); - public List positionList = new List(); - public List uvList = new List(); - - public List vertices; - public List vertexAssignments; - } - - private readonly List immultableMeshList; - private readonly ExportedMesh immutableExportedMesh; - - /// - /// Build immutable parts from a submodel. - /// - /// - public Kkdf2MdlxParser(Mdlx.SubModel submodel) - { - immultableMeshList = submodel.DmaChains - .Select(x => new ImmutableMesh(x)) - .ToList(); - - immutableExportedMesh = PreProcessVerticesAndBuildModel(); - } - - private ExportedMesh PreProcessVerticesAndBuildModel() - { - var exportedMesh = new ExportedMesh(); - exportedMesh.vertexAssignments = new List(); - exportedMesh.vertices = new List(); - - int vertexBaseIndex = 0; - int uvBaseIndex = 0; - VertexRef[] ringBuffer = new VertexRef[4]; - int ringIndex = 0; - int[] triangleOrder = new int[] { 1, 3, 2 }; - foreach (ImmutableMesh meshRoot in immultableMeshList) - { - for (int i = 0; i < meshRoot.VpuPackets.Count; i++) - { - VpuPacket mesh = meshRoot.VpuPackets[i]; - var part = new ExportedMesh.Part - { - TextureIndex = meshRoot.TextureIndex, - IsOpaque = meshRoot.IsOpaque, - }; - - for (int x = 0; x < mesh.Indices.Length; x++) - { - var indexAssign = mesh.Indices[x]; - - VertexRef vertexRef = new VertexRef( - vertexBaseIndex + indexAssign.Index, - uvBaseIndex + x - ); - ringBuffer[ringIndex] = vertexRef; - ringIndex = (ringIndex + 1) & 3; - var flag = indexAssign.Function; - if (flag == VpuPacket.VertexFunction.DrawTriangle || - flag == VpuPacket.VertexFunction.DrawTriangleDoubleSided) - { - var triRef = new TriangleRef( - ringBuffer[(ringIndex - triangleOrder[0]) & 3], - ringBuffer[(ringIndex - triangleOrder[1]) & 3], - ringBuffer[(ringIndex - triangleOrder[2]) & 3] - ); - part.triangleRefList.Add(triRef); - } - if (flag == VpuPacket.VertexFunction.DrawTriangleInverse || - flag == VpuPacket.VertexFunction.DrawTriangleDoubleSided) - { - var triRef = new TriangleRef( - ringBuffer[(ringIndex - triangleOrder[0]) & 3], - ringBuffer[(ringIndex - triangleOrder[2]) & 3], - ringBuffer[(ringIndex - triangleOrder[1]) & 3] - ); - part.triangleRefList.Add(triRef); - } - } - - var vertices = mesh.Vertices - .Select(vertex => new Vector4(vertex.X, vertex.Y, vertex.Z, vertex.W)) - .ToArray(); - exportedMesh.vertices.Add(vertices); - - var matrixIndexList = meshRoot.DmaChain.DmaVifs[i].Alaxi; - var vertexAssignmentsList = mesh.GetWeightedVertices(mesh.GetFromMatrixIndices(matrixIndexList)); - exportedMesh.vertexAssignments.Add(vertexAssignmentsList); - - exportedMesh.uvList.AddRange( - mesh.Indices.Select(x => - new Vector2(x.U / 16 / 256.0f, x.V / 16 / 256.0f)) - ); - - exportedMesh.partList.Add(part); - - vertexBaseIndex += vertexAssignmentsList.Length; - uvBaseIndex += mesh.Indices.Length; - } - } - - return exportedMesh; - } - - public List ProcessVerticesAndBuildModel(Matrix4x4[] matrices) - { - immutableExportedMesh.positionList.Clear(); - for (var i = 0; i < immutableExportedMesh.vertexAssignments.Count; i++) - { - var vertexAssignments = immutableExportedMesh.vertexAssignments[i]; - var vertices = immutableExportedMesh.vertices[i]; - - immutableExportedMesh.positionList.AddRange( - vertexAssignments.Select( - vertexAssigns => - { - Vector3 finalPos = Vector3.Zero; - if (vertexAssigns.Length == 1) - { - // single joint - finalPos = Vector3.Transform( - ToVector3(vertices[vertexAssigns[0].VertexIndex]), - matrices[vertexAssigns[0].MatrixIndex]); - } - else - { - // multiple joints, using rawPos.W as blend weights - foreach (var vertexAssign in vertexAssigns) - { - finalPos += ToVector3( - Vector4.Transform( - vertices[vertexAssign.VertexIndex], - matrices[vertexAssign.MatrixIndex] - )); - } - } - return finalPos; - } - ) - ); - } - - var newList = new List(); - foreach (var part in immutableExportedMesh.partList) - { - var vertices = new List(); - var indices = new List(); - - int triangleRefCount = part.triangleRefList.Count; - for (int triIndex = 0; triIndex < triangleRefCount; triIndex++) - { - TriangleRef triRef = part.triangleRefList[triIndex]; - for (int i = 0; i < triRef.list.Length; i++) - { - VertexRef vertRef = triRef.list[i]; - indices.Add(vertices.Count); - vertices.Add(new PositionColoredTextured( - immutableExportedMesh.positionList[vertRef.vertexIndex], - immutableExportedMesh.uvList[vertRef.uvIndex], - 1.0f, 1.0f, 1.0f, 1.0f)); - } - } - - newList.Add( - new MeshDescriptor - { - IsOpaque = part.IsOpaque, - TextureIndex = part.TextureIndex, - Vertices = vertices.ToArray(), - Indices = indices.ToArray(), - } - ); - } - - return newList; - } - - private static Vector3 ToVector3(Vector4 pos) => new Vector3(pos.X, pos.Y, pos.Z); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Ps2; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Numerics; + +namespace OpenKh.Engine.Parsers +{ + public class Kkdf2MdlxParser + { + private class ImmutableMesh + { + public Mdlx.DmaChain DmaChain { get; } + public List VpuPackets { get; } + + public int TextureIndex => DmaChain.TextureIndex; + public bool IsOpaque => (DmaChain.RenderFlags & 1) == 0; + + public ImmutableMesh(Mdlx.DmaChain dmaChain) + { + DmaChain = dmaChain; + VpuPackets = dmaChain.DmaVifs + .Select(dmaVif => + { + var unpacker = new VifUnpacker(dmaVif.VifPacket); + unpacker.Run(); + + using (var stream = new MemoryStream(unpacker.Memory)) + return VpuPacket.Read(stream); + }) + .ToList(); + } + } + + private class VertexRef + { + public int vertexIndex, uvIndex; + + public VertexRef(int vertexIndex, int uvIndex) + { + this.vertexIndex = vertexIndex; + this.uvIndex = uvIndex; + } + } + + private class TriangleRef + { + public TriangleRef(VertexRef one, VertexRef two, VertexRef three) + { + list = new VertexRef[] { one, two, three }; + } + + public VertexRef[] list; + public int textureIndex; + public bool isOpaque; + } + + private class ExportedMesh + { + public class Part + { + public int TextureIndex; + public bool IsOpaque; + public List triangleRefList = new List(); + } + + public List partList = new List(); + public List positionList = new List(); + public List uvList = new List(); + + public List vertices; + public List vertexAssignments; + } + + private readonly List immultableMeshList; + private readonly ExportedMesh immutableExportedMesh; + + /// + /// Build immutable parts from a submodel. + /// + /// + public Kkdf2MdlxParser(Mdlx.SubModel submodel) + { + immultableMeshList = submodel.DmaChains + .Select(x => new ImmutableMesh(x)) + .ToList(); + + immutableExportedMesh = PreProcessVerticesAndBuildModel(); + } + + private ExportedMesh PreProcessVerticesAndBuildModel() + { + var exportedMesh = new ExportedMesh(); + exportedMesh.vertexAssignments = new List(); + exportedMesh.vertices = new List(); + + int vertexBaseIndex = 0; + int uvBaseIndex = 0; + VertexRef[] ringBuffer = new VertexRef[4]; + int ringIndex = 0; + int[] triangleOrder = new int[] { 1, 3, 2 }; + foreach (ImmutableMesh meshRoot in immultableMeshList) + { + for (int i = 0; i < meshRoot.VpuPackets.Count; i++) + { + VpuPacket mesh = meshRoot.VpuPackets[i]; + var part = new ExportedMesh.Part + { + TextureIndex = meshRoot.TextureIndex, + IsOpaque = meshRoot.IsOpaque, + }; + + for (int x = 0; x < mesh.Indices.Length; x++) + { + var indexAssign = mesh.Indices[x]; + + VertexRef vertexRef = new VertexRef( + vertexBaseIndex + indexAssign.Index, + uvBaseIndex + x + ); + ringBuffer[ringIndex] = vertexRef; + ringIndex = (ringIndex + 1) & 3; + var flag = indexAssign.Function; + if (flag == VpuPacket.VertexFunction.DrawTriangle || + flag == VpuPacket.VertexFunction.DrawTriangleDoubleSided) + { + var triRef = new TriangleRef( + ringBuffer[(ringIndex - triangleOrder[0]) & 3], + ringBuffer[(ringIndex - triangleOrder[1]) & 3], + ringBuffer[(ringIndex - triangleOrder[2]) & 3] + ); + part.triangleRefList.Add(triRef); + } + if (flag == VpuPacket.VertexFunction.DrawTriangleInverse || + flag == VpuPacket.VertexFunction.DrawTriangleDoubleSided) + { + var triRef = new TriangleRef( + ringBuffer[(ringIndex - triangleOrder[0]) & 3], + ringBuffer[(ringIndex - triangleOrder[2]) & 3], + ringBuffer[(ringIndex - triangleOrder[1]) & 3] + ); + part.triangleRefList.Add(triRef); + } + } + + var vertices = mesh.Vertices + .Select(vertex => new Vector4(vertex.X, vertex.Y, vertex.Z, vertex.W)) + .ToArray(); + exportedMesh.vertices.Add(vertices); + + var matrixIndexList = meshRoot.DmaChain.DmaVifs[i].Alaxi; + var vertexAssignmentsList = mesh.GetWeightedVertices(mesh.GetFromMatrixIndices(matrixIndexList)); + exportedMesh.vertexAssignments.Add(vertexAssignmentsList); + + exportedMesh.uvList.AddRange( + mesh.Indices.Select(x => + new Vector2(x.U / 16 / 256.0f, x.V / 16 / 256.0f)) + ); + + exportedMesh.partList.Add(part); + + vertexBaseIndex += vertexAssignmentsList.Length; + uvBaseIndex += mesh.Indices.Length; + } + } + + return exportedMesh; + } + + public List ProcessVerticesAndBuildModel(Matrix4x4[] matrices) + { + immutableExportedMesh.positionList.Clear(); + for (var i = 0; i < immutableExportedMesh.vertexAssignments.Count; i++) + { + var vertexAssignments = immutableExportedMesh.vertexAssignments[i]; + var vertices = immutableExportedMesh.vertices[i]; + + immutableExportedMesh.positionList.AddRange( + vertexAssignments.Select( + vertexAssigns => + { + Vector3 finalPos = Vector3.Zero; + if (vertexAssigns.Length == 1) + { + // single joint + finalPos = Vector3.Transform( + ToVector3(vertices[vertexAssigns[0].VertexIndex]), + matrices[vertexAssigns[0].MatrixIndex]); + } + else + { + // multiple joints, using rawPos.W as blend weights + foreach (var vertexAssign in vertexAssigns) + { + finalPos += ToVector3( + Vector4.Transform( + vertices[vertexAssign.VertexIndex], + matrices[vertexAssign.MatrixIndex] + )); + } + } + return finalPos; + } + ) + ); + } + + var newList = new List(); + foreach (var part in immutableExportedMesh.partList) + { + var vertices = new List(); + var indices = new List(); + + int triangleRefCount = part.triangleRefList.Count; + for (int triIndex = 0; triIndex < triangleRefCount; triIndex++) + { + TriangleRef triRef = part.triangleRefList[triIndex]; + for (int i = 0; i < triRef.list.Length; i++) + { + VertexRef vertRef = triRef.list[i]; + indices.Add(vertices.Count); + vertices.Add(new PositionColoredTextured( + immutableExportedMesh.positionList[vertRef.vertexIndex], + immutableExportedMesh.uvList[vertRef.uvIndex], + 1.0f, 1.0f, 1.0f, 1.0f)); + } + } + + newList.Add( + new MeshDescriptor + { + IsOpaque = part.IsOpaque, + TextureIndex = part.TextureIndex, + Vertices = vertices.ToArray(), + Indices = indices.ToArray(), + } + ); + } + + return newList; + } + + private static Vector3 ToVector3(Vector4 pos) => new Vector3(pos.X, pos.Y, pos.Z); + } +} diff --git a/OpenKh.Engine/Parsers/MdlxParser.cs b/OpenKh.Engine/Parsers/MdlxParser.cs index b3f5116b4..e783a910c 100644 --- a/OpenKh.Engine/Parsers/MdlxParser.cs +++ b/OpenKh.Engine/Parsers/MdlxParser.cs @@ -1,228 +1,228 @@ -using OpenKh.Common; -using OpenKh.Engine.Motion; -using OpenKh.Kh2; -using OpenKh.Ps2; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Numerics; -using System.Runtime.InteropServices; - -namespace OpenKh.Engine.Parsers -{ - [StructLayout(LayoutKind.Sequential, Pack = 4)] - public struct PositionColoredTextured - { - public float X, Y, Z; - public float Tu, Tv; - public float R, G, B, A; - - public PositionColoredTextured(float x, float y, float z, float tu, float tv, float r, float g, float b, float a) - { - X = x; - Y = y; - Z = z; - Tu = tu; - Tv = tv; - R = r; - G = g; - B = b; - A = a; - } - - public PositionColoredTextured(Vector3 pos, Vector2 uv, float r, float g, float b, float a) - { - X = pos.X; - Y = pos.Y; - Z = pos.Z; - Tu = uv.X; - Tv = uv.Y; - R = r; - G = g; - B = b; - A = a; - } - } - - public class MeshDescriptor - { - public PositionColoredTextured[] Vertices; - public int[] Indices; - public int TextureIndex; - public bool IsOpaque; - } - - public class MdlxParser : IModelMotion - { - private readonly Kkdf2MdlxParser _parsedModel; - - public MdlxParser(Mdlx mdlx) - { - if (IsEntity(mdlx)) - { - InitialPose = BuildTPoseMatrices(mdlx.SubModels.First(), Matrix4x4.Identity); - Bones = mdlx.SubModels.First().Bones; - _parsedModel = new Kkdf2MdlxParser(mdlx.SubModels.First()); - MeshDescriptors = _parsedModel.ProcessVerticesAndBuildModel(InitialPose); - } - else if (IsMap(mdlx)) - { - MeshDescriptors = mdlx.MapModel.VifPackets - .Select(vifPacket => Parse(vifPacket)) - .ToList(); - } - } - - public void ApplyMotion(Matrix4x4[] matrices) - { - CurrentPose = matrices; - MeshDescriptors = _parsedModel.ProcessVerticesAndBuildModel(matrices); - } - - private static bool IsEntity(Mdlx mdlx) => mdlx.SubModels != null; - - private static bool IsMap(Mdlx mdlx) => mdlx.MapModel != null; - - public List MeshDescriptors { get; private set; } - - public List Bones { get; private set; } - - public Matrix4x4[] InitialPose { get; set; } - - public Matrix4x4[] CurrentPose { get; private set; } - - private static MeshDescriptor Parse(Mdlx.VifPacketDescriptor vifPacketDescriptor) - { - var vertices = new List(); - var indices = new List(); - var unpacker = new VifUnpacker(vifPacketDescriptor.VifPacket); - - var indexBuffer = new int[4]; - var recentIndex = 0; - while (unpacker.Run() != VifUnpacker.State.End) - { - var vpu = new MemoryStream(unpacker.Memory, false) - .Using(stream => VpuPacket.Read(stream)); - - var baseVertexIndex = vertices.Count; - for (var i = 0; i < vpu.Indices.Length; i++) - { - var vertexIndex = vpu.Indices[i]; - var position = new Vector3( - vpu.Vertices[vertexIndex.Index].X, - vpu.Vertices[vertexIndex.Index].Y, - vpu.Vertices[vertexIndex.Index].Z); - - int colorR, colorG, colorB, colorA; - if (vpu.Colors.Length != 0) - { - colorR = vpu.Colors[i].R; - colorG = vpu.Colors[i].G; - colorB = vpu.Colors[i].B; - colorA = vpu.Colors[i].A; - } - else - { - colorR = 0x80; - colorG = 0x80; - colorB = 0x80; - colorA = 0x80; - } - - vertices.Add(new PositionColoredTextured( - vpu.Vertices[vertexIndex.Index].X, - vpu.Vertices[vertexIndex.Index].Y, - vpu.Vertices[vertexIndex.Index].Z, - (short)(ushort)vertexIndex.U / 4096.0f, - (short)(ushort)vertexIndex.V / 4096.0f, - colorR / 128f, - colorG / 128f, - colorB / 128f, - colorA / 128f)); - - indexBuffer[(recentIndex++) & 3] = baseVertexIndex + i; - switch (vertexIndex.Function) - { - case VpuPacket.VertexFunction.DrawTriangleDoubleSided: - indices.Add(indexBuffer[(recentIndex - 1) & 3]); - indices.Add(indexBuffer[(recentIndex - 3) & 3]); - indices.Add(indexBuffer[(recentIndex - 2) & 3]); - indices.Add(indexBuffer[(recentIndex - 1) & 3]); - indices.Add(indexBuffer[(recentIndex - 2) & 3]); - indices.Add(indexBuffer[(recentIndex - 3) & 3]); - break; - case VpuPacket.VertexFunction.Stock: - break; - case VpuPacket.VertexFunction.DrawTriangle: - indices.Add(indexBuffer[(recentIndex - 1) & 3]); - indices.Add(indexBuffer[(recentIndex - 3) & 3]); - indices.Add(indexBuffer[(recentIndex - 2) & 3]); - break; - case VpuPacket.VertexFunction.DrawTriangleInverse: - indices.Add(indexBuffer[(recentIndex - 1) & 3]); - indices.Add(indexBuffer[(recentIndex - 2) & 3]); - indices.Add(indexBuffer[(recentIndex - 3) & 3]); - break; - } - } - } - - return new MeshDescriptor - { - Vertices = vertices.ToArray(), - Indices = indices.ToArray(), - TextureIndex = vifPacketDescriptor.TextureId, - IsOpaque = vifPacketDescriptor.IsTransparentFlag == 0, - }; - } - - private static Matrix4x4[] BuildTPoseMatrices(Mdlx.SubModel model, Matrix4x4 initialMatrix) - { - var boneList = model.Bones.ToArray(); - var matrices = new Matrix4x4[boneList.Length]; - { - var absTranslationList = new Vector3[matrices.Length]; - var absRotationList = new Quaternion[matrices.Length]; - for (int x = 0; x < matrices.Length; x++) - { - Quaternion absRotation; - Vector3 absTranslation; - var oneBone = boneList[x]; - var parent = oneBone.Parent; - if (parent < 0) - { - absRotation = Quaternion.Identity; - absTranslation = Vector3.Zero; - } - else - { - absRotation = absRotationList[parent]; - absTranslation = absTranslationList[parent]; - } - - var localTranslation = Vector3.Transform(new Vector3(oneBone.TranslationX, oneBone.TranslationY, oneBone.TranslationZ), Matrix4x4.CreateFromQuaternion(absRotation)); - absTranslationList[x] = absTranslation + localTranslation; - - var localRotation = Quaternion.Identity; - if (oneBone.RotationZ != 0) - localRotation *= (Quaternion.CreateFromAxisAngle(Vector3.UnitZ, oneBone.RotationZ)); - if (oneBone.RotationY != 0) - localRotation *= (Quaternion.CreateFromAxisAngle(Vector3.UnitY, oneBone.RotationY)); - if (oneBone.RotationX != 0) - localRotation *= (Quaternion.CreateFromAxisAngle(Vector3.UnitX, oneBone.RotationX)); - absRotationList[x] = absRotation * localRotation; - } - for (int x = 0; x < matrices.Length; x++) - { - var absMatrix = initialMatrix; - absMatrix *= Matrix4x4.CreateFromQuaternion(absRotationList[x]); - absMatrix *= Matrix4x4.CreateTranslation(absTranslationList[x]); - matrices[x] = absMatrix; - } - } - - return matrices; - } - } -} +using OpenKh.Common; +using OpenKh.Engine.Motion; +using OpenKh.Kh2; +using OpenKh.Ps2; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Numerics; +using System.Runtime.InteropServices; + +namespace OpenKh.Engine.Parsers +{ + [StructLayout(LayoutKind.Sequential, Pack = 4)] + public struct PositionColoredTextured + { + public float X, Y, Z; + public float Tu, Tv; + public float R, G, B, A; + + public PositionColoredTextured(float x, float y, float z, float tu, float tv, float r, float g, float b, float a) + { + X = x; + Y = y; + Z = z; + Tu = tu; + Tv = tv; + R = r; + G = g; + B = b; + A = a; + } + + public PositionColoredTextured(Vector3 pos, Vector2 uv, float r, float g, float b, float a) + { + X = pos.X; + Y = pos.Y; + Z = pos.Z; + Tu = uv.X; + Tv = uv.Y; + R = r; + G = g; + B = b; + A = a; + } + } + + public class MeshDescriptor + { + public PositionColoredTextured[] Vertices; + public int[] Indices; + public int TextureIndex; + public bool IsOpaque; + } + + public class MdlxParser : IModelMotion + { + private readonly Kkdf2MdlxParser _parsedModel; + + public MdlxParser(Mdlx mdlx) + { + if (IsEntity(mdlx)) + { + InitialPose = BuildTPoseMatrices(mdlx.SubModels.First(), Matrix4x4.Identity); + Bones = mdlx.SubModels.First().Bones; + _parsedModel = new Kkdf2MdlxParser(mdlx.SubModels.First()); + MeshDescriptors = _parsedModel.ProcessVerticesAndBuildModel(InitialPose); + } + else if (IsMap(mdlx)) + { + MeshDescriptors = mdlx.MapModel.VifPackets + .Select(vifPacket => Parse(vifPacket)) + .ToList(); + } + } + + public void ApplyMotion(Matrix4x4[] matrices) + { + CurrentPose = matrices; + MeshDescriptors = _parsedModel.ProcessVerticesAndBuildModel(matrices); + } + + private static bool IsEntity(Mdlx mdlx) => mdlx.SubModels != null; + + private static bool IsMap(Mdlx mdlx) => mdlx.MapModel != null; + + public List MeshDescriptors { get; private set; } + + public List Bones { get; private set; } + + public Matrix4x4[] InitialPose { get; set; } + + public Matrix4x4[] CurrentPose { get; private set; } + + private static MeshDescriptor Parse(Mdlx.VifPacketDescriptor vifPacketDescriptor) + { + var vertices = new List(); + var indices = new List(); + var unpacker = new VifUnpacker(vifPacketDescriptor.VifPacket); + + var indexBuffer = new int[4]; + var recentIndex = 0; + while (unpacker.Run() != VifUnpacker.State.End) + { + var vpu = new MemoryStream(unpacker.Memory, false) + .Using(stream => VpuPacket.Read(stream)); + + var baseVertexIndex = vertices.Count; + for (var i = 0; i < vpu.Indices.Length; i++) + { + var vertexIndex = vpu.Indices[i]; + var position = new Vector3( + vpu.Vertices[vertexIndex.Index].X, + vpu.Vertices[vertexIndex.Index].Y, + vpu.Vertices[vertexIndex.Index].Z); + + int colorR, colorG, colorB, colorA; + if (vpu.Colors.Length != 0) + { + colorR = vpu.Colors[i].R; + colorG = vpu.Colors[i].G; + colorB = vpu.Colors[i].B; + colorA = vpu.Colors[i].A; + } + else + { + colorR = 0x80; + colorG = 0x80; + colorB = 0x80; + colorA = 0x80; + } + + vertices.Add(new PositionColoredTextured( + vpu.Vertices[vertexIndex.Index].X, + vpu.Vertices[vertexIndex.Index].Y, + vpu.Vertices[vertexIndex.Index].Z, + (short)(ushort)vertexIndex.U / 4096.0f, + (short)(ushort)vertexIndex.V / 4096.0f, + colorR / 128f, + colorG / 128f, + colorB / 128f, + colorA / 128f)); + + indexBuffer[(recentIndex++) & 3] = baseVertexIndex + i; + switch (vertexIndex.Function) + { + case VpuPacket.VertexFunction.DrawTriangleDoubleSided: + indices.Add(indexBuffer[(recentIndex - 1) & 3]); + indices.Add(indexBuffer[(recentIndex - 3) & 3]); + indices.Add(indexBuffer[(recentIndex - 2) & 3]); + indices.Add(indexBuffer[(recentIndex - 1) & 3]); + indices.Add(indexBuffer[(recentIndex - 2) & 3]); + indices.Add(indexBuffer[(recentIndex - 3) & 3]); + break; + case VpuPacket.VertexFunction.Stock: + break; + case VpuPacket.VertexFunction.DrawTriangle: + indices.Add(indexBuffer[(recentIndex - 1) & 3]); + indices.Add(indexBuffer[(recentIndex - 3) & 3]); + indices.Add(indexBuffer[(recentIndex - 2) & 3]); + break; + case VpuPacket.VertexFunction.DrawTriangleInverse: + indices.Add(indexBuffer[(recentIndex - 1) & 3]); + indices.Add(indexBuffer[(recentIndex - 2) & 3]); + indices.Add(indexBuffer[(recentIndex - 3) & 3]); + break; + } + } + } + + return new MeshDescriptor + { + Vertices = vertices.ToArray(), + Indices = indices.ToArray(), + TextureIndex = vifPacketDescriptor.TextureId, + IsOpaque = vifPacketDescriptor.IsTransparentFlag == 0, + }; + } + + private static Matrix4x4[] BuildTPoseMatrices(Mdlx.SubModel model, Matrix4x4 initialMatrix) + { + var boneList = model.Bones.ToArray(); + var matrices = new Matrix4x4[boneList.Length]; + { + var absTranslationList = new Vector3[matrices.Length]; + var absRotationList = new Quaternion[matrices.Length]; + for (int x = 0; x < matrices.Length; x++) + { + Quaternion absRotation; + Vector3 absTranslation; + var oneBone = boneList[x]; + var parent = oneBone.Parent; + if (parent < 0) + { + absRotation = Quaternion.Identity; + absTranslation = Vector3.Zero; + } + else + { + absRotation = absRotationList[parent]; + absTranslation = absTranslationList[parent]; + } + + var localTranslation = Vector3.Transform(new Vector3(oneBone.TranslationX, oneBone.TranslationY, oneBone.TranslationZ), Matrix4x4.CreateFromQuaternion(absRotation)); + absTranslationList[x] = absTranslation + localTranslation; + + var localRotation = Quaternion.Identity; + if (oneBone.RotationZ != 0) + localRotation *= (Quaternion.CreateFromAxisAngle(Vector3.UnitZ, oneBone.RotationZ)); + if (oneBone.RotationY != 0) + localRotation *= (Quaternion.CreateFromAxisAngle(Vector3.UnitY, oneBone.RotationY)); + if (oneBone.RotationX != 0) + localRotation *= (Quaternion.CreateFromAxisAngle(Vector3.UnitX, oneBone.RotationX)); + absRotationList[x] = absRotation * localRotation; + } + for (int x = 0; x < matrices.Length; x++) + { + var absMatrix = initialMatrix; + absMatrix *= Matrix4x4.CreateFromQuaternion(absRotationList[x]); + absMatrix *= Matrix4x4.CreateTranslation(absTranslationList[x]); + matrices[x] = absMatrix; + } + } + + return matrices; + } + } +} diff --git a/OpenKh.Engine/Parsers/PmoParser.cs b/OpenKh.Engine/Parsers/PmoParser.cs index 97b4a546a..2968f3334 100644 --- a/OpenKh.Engine/Parsers/PmoParser.cs +++ b/OpenKh.Engine/Parsers/PmoParser.cs @@ -1,103 +1,103 @@ -using System; -using System.Collections.Generic; -using OpenKh.Engine.Motion; -using OpenKh.Kh2; -using OpenKh.Bbs; -using System.Numerics; - -namespace OpenKh.Engine.Parsers -{ - public class PmoParser : IModelMotion - { - private readonly Pmo aPmo; - - public PmoParser(Pmo pmo, float Scale) - { - aPmo = pmo; - MeshDescriptors = new List(); - MeshDescriptor currentMesh = new MeshDescriptor(); - - for (int x = 0; x < pmo.Meshes.Count; x++) - { - var vertices = new PositionColoredTextured[pmo.Meshes[x].vertices.Count]; - for (var i = 0; i < vertices.Length; i++) - { - Vector4 color; - - color.X = pmo.Meshes[x].colors[i].X / 128.0f; - color.Y = pmo.Meshes[x].colors[i].Y / 128.0f; - color.Z = pmo.Meshes[x].colors[i].Z / 128.0f; - color.W = pmo.Meshes[x].colors[i].W / 128.0f; - - vertices[i].X = pmo.Meshes[x].vertices[i].X * pmo.header.ModelScale * Scale; - vertices[i].Y = pmo.Meshes[x].vertices[i].Y * pmo.header.ModelScale * Scale; - vertices[i].Z = pmo.Meshes[x].vertices[i].Z * pmo.header.ModelScale * Scale; - vertices[i].Tu = pmo.Meshes[x].textureCoordinates[i].X; - vertices[i].Tv = pmo.Meshes[x].textureCoordinates[i].Y; - vertices[i].R = color.X; - vertices[i].G = color.Y; - vertices[i].B = color.Z; - vertices[i].A = color.W; - } - - currentMesh = new MeshDescriptor() - { - Vertices = vertices, - Indices = pmo.Meshes[x].Indices.ToArray(), - TextureIndex = pmo.Meshes[x].TextureID, - IsOpaque = false - }; - - MeshDescriptors.Add(currentMesh); - } - - if (pmo.header.SkeletonOffset != 0) - { - List matrices = new List(); - List skeleton = new List(); - - foreach (Pmo.BoneData boneData in pmo.boneList) - { - Matrix4x4 mtx = boneData.Transform; - Matrix4x4 mtx_nd = Matrix4x4.Transpose(mtx); - - matrices.Add(mtx_nd); - - Mdlx.Bone otherBone = new Mdlx.Bone(); - otherBone.Index = boneData.BoneIndex; - otherBone.Parent = (boneData.ParentBoneIndex == 0xFFFF) ? 0 : boneData.ParentBoneIndex; - otherBone.TranslationX = mtx_nd.Translation.X; - otherBone.TranslationY = mtx_nd.Translation.Y; - otherBone.TranslationZ = mtx_nd.Translation.Z; - otherBone.TranslationW = mtx_nd.M14; - otherBone.RotationX = mtx_nd.M21; - otherBone.RotationY = mtx_nd.M22; - otherBone.RotationZ = mtx_nd.M23; - otherBone.RotationW = mtx_nd.M24; - otherBone.ScaleX = mtx_nd.M31; - otherBone.ScaleY = mtx_nd.M32; - otherBone.ScaleZ = mtx_nd.M33; - otherBone.ScaleW = mtx_nd.M34; - - skeleton.Add(otherBone); - } - - Bones = skeleton; - InitialPose = matrices.ToArray(); - CurrentPose = InitialPose; - } - } - - public List MeshDescriptors { get; private set; } - - public List Bones { get; private set; } - - public Matrix4x4[] InitialPose { get; set; } - public Matrix4x4[] CurrentPose { get; private set; } - - public void ApplyMotion(Matrix4x4[] matrices) - { - - } - } -} +using System; +using System.Collections.Generic; +using OpenKh.Engine.Motion; +using OpenKh.Kh2; +using OpenKh.Bbs; +using System.Numerics; + +namespace OpenKh.Engine.Parsers +{ + public class PmoParser : IModelMotion + { + private readonly Pmo aPmo; + + public PmoParser(Pmo pmo, float Scale) + { + aPmo = pmo; + MeshDescriptors = new List(); + MeshDescriptor currentMesh = new MeshDescriptor(); + + for (int x = 0; x < pmo.Meshes.Count; x++) + { + var vertices = new PositionColoredTextured[pmo.Meshes[x].vertices.Count]; + for (var i = 0; i < vertices.Length; i++) + { + Vector4 color; + + color.X = pmo.Meshes[x].colors[i].X / 128.0f; + color.Y = pmo.Meshes[x].colors[i].Y / 128.0f; + color.Z = pmo.Meshes[x].colors[i].Z / 128.0f; + color.W = pmo.Meshes[x].colors[i].W / 128.0f; + + vertices[i].X = pmo.Meshes[x].vertices[i].X * pmo.header.ModelScale * Scale; + vertices[i].Y = pmo.Meshes[x].vertices[i].Y * pmo.header.ModelScale * Scale; + vertices[i].Z = pmo.Meshes[x].vertices[i].Z * pmo.header.ModelScale * Scale; + vertices[i].Tu = pmo.Meshes[x].textureCoordinates[i].X; + vertices[i].Tv = pmo.Meshes[x].textureCoordinates[i].Y; + vertices[i].R = color.X; + vertices[i].G = color.Y; + vertices[i].B = color.Z; + vertices[i].A = color.W; + } + + currentMesh = new MeshDescriptor() + { + Vertices = vertices, + Indices = pmo.Meshes[x].Indices.ToArray(), + TextureIndex = pmo.Meshes[x].TextureID, + IsOpaque = false + }; + + MeshDescriptors.Add(currentMesh); + } + + if (pmo.header.SkeletonOffset != 0) + { + List matrices = new List(); + List skeleton = new List(); + + foreach (Pmo.BoneData boneData in pmo.boneList) + { + Matrix4x4 mtx = boneData.Transform; + Matrix4x4 mtx_nd = Matrix4x4.Transpose(mtx); + + matrices.Add(mtx_nd); + + Mdlx.Bone otherBone = new Mdlx.Bone(); + otherBone.Index = boneData.BoneIndex; + otherBone.Parent = (boneData.ParentBoneIndex == 0xFFFF) ? 0 : boneData.ParentBoneIndex; + otherBone.TranslationX = mtx_nd.Translation.X; + otherBone.TranslationY = mtx_nd.Translation.Y; + otherBone.TranslationZ = mtx_nd.Translation.Z; + otherBone.TranslationW = mtx_nd.M14; + otherBone.RotationX = mtx_nd.M21; + otherBone.RotationY = mtx_nd.M22; + otherBone.RotationZ = mtx_nd.M23; + otherBone.RotationW = mtx_nd.M24; + otherBone.ScaleX = mtx_nd.M31; + otherBone.ScaleY = mtx_nd.M32; + otherBone.ScaleZ = mtx_nd.M33; + otherBone.ScaleW = mtx_nd.M34; + + skeleton.Add(otherBone); + } + + Bones = skeleton; + InitialPose = matrices.ToArray(); + CurrentPose = InitialPose; + } + } + + public List MeshDescriptors { get; private set; } + + public List Bones { get; private set; } + + public Matrix4x4[] InitialPose { get; set; } + public Matrix4x4[] CurrentPose { get; private set; } + + public void ApplyMotion(Matrix4x4[] matrices) + { + + } + } +} diff --git a/OpenKh.Engine/Renders/IDebugLayoutRenderer.cs b/OpenKh.Engine/Renders/IDebugLayoutRenderer.cs index df72ef678..250bab046 100644 --- a/OpenKh.Engine/Renders/IDebugLayoutRenderer.cs +++ b/OpenKh.Engine/Renders/IDebugLayoutRenderer.cs @@ -1,33 +1,33 @@ -using System.Drawing; - -namespace OpenKh.Engine.Renders -{ - public interface IDebugLayoutRenderer - { - bool IsSequenceGroupVisible(int index); - bool IsSequencePropertyVisible(int index); - Color GetSequenceGroupBlendColor(int index); - Color GetSequencePropertyBlendColor(int index); - } - - public interface IDebugSequenceRenderer - { - ColorF GetAnimationBlendColor(int index); - } - - public class DefaultDebugLayoutRenderer : IDebugLayoutRenderer - { - private static readonly Color DefaultColor = Color.White; - - public bool IsSequenceGroupVisible(int index) => true; - public bool IsSequencePropertyVisible(int index) => true; - - public Color GetSequenceGroupBlendColor(int index) => DefaultColor; - public Color GetSequencePropertyBlendColor(int index) => DefaultColor; - } - - public class DefaultDebugSequenceRenderer : IDebugSequenceRenderer - { - public ColorF GetAnimationBlendColor(int index) => ColorF.White; - } -} +using System.Drawing; + +namespace OpenKh.Engine.Renders +{ + public interface IDebugLayoutRenderer + { + bool IsSequenceGroupVisible(int index); + bool IsSequencePropertyVisible(int index); + Color GetSequenceGroupBlendColor(int index); + Color GetSequencePropertyBlendColor(int index); + } + + public interface IDebugSequenceRenderer + { + ColorF GetAnimationBlendColor(int index); + } + + public class DefaultDebugLayoutRenderer : IDebugLayoutRenderer + { + private static readonly Color DefaultColor = Color.White; + + public bool IsSequenceGroupVisible(int index) => true; + public bool IsSequencePropertyVisible(int index) => true; + + public Color GetSequenceGroupBlendColor(int index) => DefaultColor; + public Color GetSequencePropertyBlendColor(int index) => DefaultColor; + } + + public class DefaultDebugSequenceRenderer : IDebugSequenceRenderer + { + public ColorF GetAnimationBlendColor(int index) => ColorF.White; + } +} diff --git a/OpenKh.Engine/Renders/IMessageRenderer.cs b/OpenKh.Engine/Renders/IMessageRenderer.cs index 429c5f717..cfd4fc47f 100644 --- a/OpenKh.Engine/Renders/IMessageRenderer.cs +++ b/OpenKh.Engine/Renders/IMessageRenderer.cs @@ -1,46 +1,46 @@ -namespace OpenKh.Engine.Renders -{ - public class DrawContext - { - public bool IgnoreDraw; - public double xStart; - public double x; - public double y; - public ColorF Color; - public double WidthMultiplier; - public double Scale; - public double Width; - public double Height; - public double WindowWidth; - - public float ScaleX => (float)(WidthMultiplier * Scale * GlobalScale); - - // A scale of 0.85 is the one that is apparently used in-game - public double GlobalScale { get; set; } = 0.85; - - public DrawContext() - { - Reset(); - } - - public void Reset() - { - Color = new ColorF(1.0f, 1.0f, 1.0f, 1.0f); - WidthMultiplier = 1.0; - Scale = 1.0; - } - - public void NewLine(int fontHeight) - { - x = xStart; - y += fontHeight * Scale; - } - } - - public interface IMessageRenderer - { - void Draw(DrawContext context, string message); - - void Draw(DrawContext context, byte[] data); - } -} +namespace OpenKh.Engine.Renders +{ + public class DrawContext + { + public bool IgnoreDraw; + public double xStart; + public double x; + public double y; + public ColorF Color; + public double WidthMultiplier; + public double Scale; + public double Width; + public double Height; + public double WindowWidth; + + public float ScaleX => (float)(WidthMultiplier * Scale * GlobalScale); + + // A scale of 0.85 is the one that is apparently used in-game + public double GlobalScale { get; set; } = 0.85; + + public DrawContext() + { + Reset(); + } + + public void Reset() + { + Color = new ColorF(1.0f, 1.0f, 1.0f, 1.0f); + WidthMultiplier = 1.0; + Scale = 1.0; + } + + public void NewLine(int fontHeight) + { + x = xStart; + y += fontHeight * Scale; + } + } + + public interface IMessageRenderer + { + void Draw(DrawContext context, string message); + + void Draw(DrawContext context, byte[] data); + } +} diff --git a/OpenKh.Engine/Renders/ISpriteDrawing.cs b/OpenKh.Engine/Renders/ISpriteDrawing.cs index ac397141b..6afc3d899 100644 --- a/OpenKh.Engine/Renders/ISpriteDrawing.cs +++ b/OpenKh.Engine/Renders/ISpriteDrawing.cs @@ -1,332 +1,332 @@ -using OpenKh.Imaging; -using System; -using System.Numerics; - -namespace OpenKh.Engine.Renders -{ - public enum BlendMode - { - Default, - Add, - Subtract, - } - - public enum TextureWrapMode - { - Default = 0, - Clamp = 1, - Repeat = 2, - } - - public struct ColorF - { - public static readonly ColorF Black = new ColorF(0.0f, 0.0f, 0.0f, 1.0f); - public static readonly ColorF White = new ColorF(1.0f, 1.0f, 1.0f, 1.0f); - - public float R, G, B, A; - - public ColorF(float r, float g, float b, float a) - { - R = r; - G = g; - B = b; - A = a; - } - - public static ColorF operator +(ColorF colorA, ColorF colorB) => new ColorF - { - R = colorA.R + colorB.R, - G = colorA.G + colorB.G, - B = colorA.B + colorB.B, - A = colorA.A + colorB.A - }; - - public static ColorF operator *(ColorF colorA, ColorF colorB) => new ColorF - { - R = colorA.R * colorB.R, - G = colorA.G * colorB.G, - B = colorA.B * colorB.B, - A = colorA.A * colorB.A - }; - - public static ColorF FromRgba(int r, int g, int b, int a) => new ColorF - { - R = r / 255.0f, - G = g / 255.0f, - B = b / 255.0f, - A = a / 255.0f, - }; - - public static ColorF FromRgba(int rgba) => new ColorF - { - R = ((rgba >> 0) & 0xff) / 255.0f, - G = ((rgba >> 8) & 0xff) / 255.0f, - B = ((rgba >> 16) & 0xff) / 255.0f, - A = ((rgba >> 24) & 0xff) / 255.0f, - }; - - public static ColorF FromRgba(uint rgba) => new ColorF - { - R = ((rgba >> 0) & 0xff) / 255.0f, - G = ((rgba >> 8) & 0xff) / 255.0f, - B = ((rgba >> 16) & 0xff) / 255.0f, - A = ((rgba >> 24) & 0xff) / 255.0f, - }; - - public static ColorF operator *(ColorF color, float scalar) => new ColorF - ( - color.R * scalar, - color.G * scalar, - color.B * scalar, - color.A * scalar - ); - - public static ColorF operator /(ColorF color, float scalar) => new ColorF - ( - color.R / scalar, - color.G / scalar, - color.B / scalar, - color.A / scalar - ); - - public override string ToString() => $"({R}, {G}, {B}, {A})"; - } - - public static class ColorFExtensions - { - public static uint ToRgba(this ColorF rgba) => - ((uint)(rgba.R * 255f) << 0) | - ((uint)(rgba.G * 255f) << 8) | - ((uint)(rgba.B * 255f) << 16) | - ((uint)(rgba.A * 255f) << 24); - } - - public class SpriteDrawingContext - { - public float SourceLeft { get; set; } - public float SourceTop { get; set; } - public float SourceRight { get; set; } - public float SourceBottom { get; set; } - - public Vector2 Vec0 { get; set;} - public Vector2 Vec1 { get; set;} - public Vector2 Vec2 { get; set;} - public Vector2 Vec3 { get; set; } - - public ColorF Color0 { get; set; } - public ColorF Color1 { get; set; } - public ColorF Color2 { get; set; } - public ColorF Color3 { get; set; } - - public ISpriteTexture SpriteTexture { get; set; } - public BlendMode BlendMode { get; set; } - - public TextureWrapMode TextureWrapU { get; set; } = TextureWrapMode.Default; - public TextureWrapMode TextureWrapV { get; set; } = TextureWrapMode.Default; - public float TextureHorizontalShift { get; set; } - public float TextureVerticalShift { get; set; } - public float TextureRegionLeft { get; set; } - public float TextureRegionRight { get; set; } - public float TextureRegionTop { get; set; } - public float TextureRegionBottom { get; set; } - } - - public static class SpriteDrawingContextExtensions - { - private static readonly ColorF ColorWhite = new ColorF(1.0f, 1.0f, 1.0f, 1.0f); - - public static SpriteDrawingContext SourceLTRB(this SpriteDrawingContext context, float left, float top, float right, float bottom) - { - context.SourceLeft = left; - context.SourceTop = top; - context.SourceRight = right; - context.SourceBottom = bottom; - return context; - } - - public static SpriteDrawingContext Source(this SpriteDrawingContext context, float x, float y, float width, float height) - { - context.SourceLeft = x; - context.SourceTop = y; - context.SourceRight = x + width; - context.SourceBottom = y + height; - return context; - } - - public static SpriteDrawingContext Position(this SpriteDrawingContext context, float x, float y) - { - var width = context.Vec3.X - context.Vec0.X; - var height = context.Vec3.Y - context.Vec0.Y; - context.Vec0 = new Vector2(x, y); - context.Vec1 = new Vector2(x + width, y); - context.Vec2 = new Vector2(x, y + height); - context.Vec3 = new Vector2(x + width, y + height); - return context; - } - - public static SpriteDrawingContext Traslate(this SpriteDrawingContext context, float x, float y) - { - var v = new Vector2(x, y); - context.Vec0 += v; - context.Vec1 += v; - context.Vec2 += v; - context.Vec3 += v; - return context; - } - - public static SpriteDrawingContext MatchSourceSize(this SpriteDrawingContext context) => - context.DestinationSize( - Math.Abs(context.SourceRight - context.SourceLeft), - Math.Abs(context.SourceBottom - context.SourceTop)); - - public static SpriteDrawingContext DestinationSize(this SpriteDrawingContext context, float width, float height) - { - context.Vec1 = new Vector2(context.Vec0.X + width, context.Vec0.Y); - context.Vec2 = new Vector2(context.Vec0.X, context.Vec0.Y + height); - context.Vec3 = new Vector2(context.Vec0.X + width, context.Vec0.Y + height); - return context; - } - - public static SpriteDrawingContext ScaleSize(this SpriteDrawingContext context, float scale) - { - var matrix = Matrix4x4.CreateScale(scale); - context.Vec0 = Vector2.Transform(context.Vec0, matrix); - context.Vec1 = Vector2.Transform(context.Vec1, matrix); - context.Vec2 = Vector2.Transform(context.Vec2, matrix); - context.Vec3 = Vector2.Transform(context.Vec3, matrix); - return context; - } - - public static SpriteDrawingContext ScaleSize(this SpriteDrawingContext context, float scaleX, float scaleY) - { - var matrix = Matrix4x4.CreateScale(scaleX, scaleY, 1.0f); - context.Vec0 = Vector2.Transform(context.Vec0, matrix); - context.Vec1 = Vector2.Transform(context.Vec1, matrix); - context.Vec2 = Vector2.Transform(context.Vec2, matrix); - context.Vec3 = Vector2.Transform(context.Vec3, matrix); - return context; - } - - public static SpriteDrawingContext RotateX(this SpriteDrawingContext context, float rotation) - { - var matrix = Matrix4x4.CreateRotationX(rotation); - context.Vec0 = Vector2.Transform(context.Vec0, matrix); - context.Vec1 = Vector2.Transform(context.Vec1, matrix); - context.Vec2 = Vector2.Transform(context.Vec2, matrix); - context.Vec3 = Vector2.Transform(context.Vec3, matrix); - return context; - } - - public static SpriteDrawingContext RotateY(this SpriteDrawingContext context, float rotation) - { - var matrix = Matrix4x4.CreateRotationY(rotation); - context.Vec0 = Vector2.Transform(context.Vec0, matrix); - context.Vec1 = Vector2.Transform(context.Vec1, matrix); - context.Vec2 = Vector2.Transform(context.Vec2, matrix); - context.Vec3 = Vector2.Transform(context.Vec3, matrix); - return context; - } - - public static SpriteDrawingContext RotateZ(this SpriteDrawingContext context, float rotation) - { - var matrix = Matrix4x4.CreateRotationZ(rotation); - context.Vec0 = Vector2.Transform(context.Vec0, matrix); - context.Vec1 = Vector2.Transform(context.Vec1, matrix); - context.Vec2 = Vector2.Transform(context.Vec2, matrix); - context.Vec3 = Vector2.Transform(context.Vec3, matrix); - return context; - } - - public static SpriteDrawingContext ColorDefault(this SpriteDrawingContext context) - { - context.Color0 = ColorWhite; - context.Color1 = ColorWhite; - context.Color2 = ColorWhite; - context.Color3 = ColorWhite; - return context; - } - - public static SpriteDrawingContext Color(this SpriteDrawingContext context, ColorF color) - { - context.Color0 = color; - context.Color1 = color; - context.Color2 = color; - context.Color3 = color; - return context; - } - - public static SpriteDrawingContext ColorAdd(this SpriteDrawingContext context, ColorF color) - { - context.Color0 += color; - context.Color1 += color; - context.Color2 += color; - context.Color3 += color; - return context; - } - - public static SpriteDrawingContext ColorMultiply(this SpriteDrawingContext context, ColorF color) - { - context.Color0 *= color; - context.Color1 *= color; - context.Color2 *= color; - context.Color3 *= color; - return context; - } - - public static SpriteDrawingContext SpriteTexture(this SpriteDrawingContext context, ISpriteTexture spriteTexture) - { - context.SpriteTexture = spriteTexture; - return context; - } - - public static SpriteDrawingContext TextureWrapHorizontal(this SpriteDrawingContext context, TextureWrapMode mode, float left, float right) - { - context.TextureWrapU = mode; - context.TextureRegionLeft = left; - context.TextureRegionRight = right; - return context; - } - - public static SpriteDrawingContext TextureWrapVertical(this SpriteDrawingContext context, TextureWrapMode mode, float top, float bottom) - { - context.TextureWrapV = mode; - context.TextureRegionTop = top; - context.TextureRegionBottom = bottom; - return context; - } - } - - public interface IMappedResource : IDisposable - { - IntPtr Data { get; } - - int Stride { get; } - - int Length { get; } - } - - public interface ISpriteTexture : IDisposable - { - int Width { get; } - int Height { get; } - - IMappedResource Map(); - } - - public interface ISpriteDrawing : IDisposable - { - ISpriteTexture DestinationTexture { get; set; } - - ISpriteTexture CreateSpriteTexture(IImageRead image); - - ISpriteTexture CreateSpriteTexture(int width, int height); - - void SetViewport(float left, float right, float top, float bottom); - - void Clear(ColorF color); - - void AppendSprite(SpriteDrawingContext context); - - void Flush(); - } -} +using OpenKh.Imaging; +using System; +using System.Numerics; + +namespace OpenKh.Engine.Renders +{ + public enum BlendMode + { + Default, + Add, + Subtract, + } + + public enum TextureWrapMode + { + Default = 0, + Clamp = 1, + Repeat = 2, + } + + public struct ColorF + { + public static readonly ColorF Black = new ColorF(0.0f, 0.0f, 0.0f, 1.0f); + public static readonly ColorF White = new ColorF(1.0f, 1.0f, 1.0f, 1.0f); + + public float R, G, B, A; + + public ColorF(float r, float g, float b, float a) + { + R = r; + G = g; + B = b; + A = a; + } + + public static ColorF operator +(ColorF colorA, ColorF colorB) => new ColorF + { + R = colorA.R + colorB.R, + G = colorA.G + colorB.G, + B = colorA.B + colorB.B, + A = colorA.A + colorB.A + }; + + public static ColorF operator *(ColorF colorA, ColorF colorB) => new ColorF + { + R = colorA.R * colorB.R, + G = colorA.G * colorB.G, + B = colorA.B * colorB.B, + A = colorA.A * colorB.A + }; + + public static ColorF FromRgba(int r, int g, int b, int a) => new ColorF + { + R = r / 255.0f, + G = g / 255.0f, + B = b / 255.0f, + A = a / 255.0f, + }; + + public static ColorF FromRgba(int rgba) => new ColorF + { + R = ((rgba >> 0) & 0xff) / 255.0f, + G = ((rgba >> 8) & 0xff) / 255.0f, + B = ((rgba >> 16) & 0xff) / 255.0f, + A = ((rgba >> 24) & 0xff) / 255.0f, + }; + + public static ColorF FromRgba(uint rgba) => new ColorF + { + R = ((rgba >> 0) & 0xff) / 255.0f, + G = ((rgba >> 8) & 0xff) / 255.0f, + B = ((rgba >> 16) & 0xff) / 255.0f, + A = ((rgba >> 24) & 0xff) / 255.0f, + }; + + public static ColorF operator *(ColorF color, float scalar) => new ColorF + ( + color.R * scalar, + color.G * scalar, + color.B * scalar, + color.A * scalar + ); + + public static ColorF operator /(ColorF color, float scalar) => new ColorF + ( + color.R / scalar, + color.G / scalar, + color.B / scalar, + color.A / scalar + ); + + public override string ToString() => $"({R}, {G}, {B}, {A})"; + } + + public static class ColorFExtensions + { + public static uint ToRgba(this ColorF rgba) => + ((uint)(rgba.R * 255f) << 0) | + ((uint)(rgba.G * 255f) << 8) | + ((uint)(rgba.B * 255f) << 16) | + ((uint)(rgba.A * 255f) << 24); + } + + public class SpriteDrawingContext + { + public float SourceLeft { get; set; } + public float SourceTop { get; set; } + public float SourceRight { get; set; } + public float SourceBottom { get; set; } + + public Vector2 Vec0 { get; set; } + public Vector2 Vec1 { get; set; } + public Vector2 Vec2 { get; set; } + public Vector2 Vec3 { get; set; } + + public ColorF Color0 { get; set; } + public ColorF Color1 { get; set; } + public ColorF Color2 { get; set; } + public ColorF Color3 { get; set; } + + public ISpriteTexture SpriteTexture { get; set; } + public BlendMode BlendMode { get; set; } + + public TextureWrapMode TextureWrapU { get; set; } = TextureWrapMode.Default; + public TextureWrapMode TextureWrapV { get; set; } = TextureWrapMode.Default; + public float TextureHorizontalShift { get; set; } + public float TextureVerticalShift { get; set; } + public float TextureRegionLeft { get; set; } + public float TextureRegionRight { get; set; } + public float TextureRegionTop { get; set; } + public float TextureRegionBottom { get; set; } + } + + public static class SpriteDrawingContextExtensions + { + private static readonly ColorF ColorWhite = new ColorF(1.0f, 1.0f, 1.0f, 1.0f); + + public static SpriteDrawingContext SourceLTRB(this SpriteDrawingContext context, float left, float top, float right, float bottom) + { + context.SourceLeft = left; + context.SourceTop = top; + context.SourceRight = right; + context.SourceBottom = bottom; + return context; + } + + public static SpriteDrawingContext Source(this SpriteDrawingContext context, float x, float y, float width, float height) + { + context.SourceLeft = x; + context.SourceTop = y; + context.SourceRight = x + width; + context.SourceBottom = y + height; + return context; + } + + public static SpriteDrawingContext Position(this SpriteDrawingContext context, float x, float y) + { + var width = context.Vec3.X - context.Vec0.X; + var height = context.Vec3.Y - context.Vec0.Y; + context.Vec0 = new Vector2(x, y); + context.Vec1 = new Vector2(x + width, y); + context.Vec2 = new Vector2(x, y + height); + context.Vec3 = new Vector2(x + width, y + height); + return context; + } + + public static SpriteDrawingContext Traslate(this SpriteDrawingContext context, float x, float y) + { + var v = new Vector2(x, y); + context.Vec0 += v; + context.Vec1 += v; + context.Vec2 += v; + context.Vec3 += v; + return context; + } + + public static SpriteDrawingContext MatchSourceSize(this SpriteDrawingContext context) => + context.DestinationSize( + Math.Abs(context.SourceRight - context.SourceLeft), + Math.Abs(context.SourceBottom - context.SourceTop)); + + public static SpriteDrawingContext DestinationSize(this SpriteDrawingContext context, float width, float height) + { + context.Vec1 = new Vector2(context.Vec0.X + width, context.Vec0.Y); + context.Vec2 = new Vector2(context.Vec0.X, context.Vec0.Y + height); + context.Vec3 = new Vector2(context.Vec0.X + width, context.Vec0.Y + height); + return context; + } + + public static SpriteDrawingContext ScaleSize(this SpriteDrawingContext context, float scale) + { + var matrix = Matrix4x4.CreateScale(scale); + context.Vec0 = Vector2.Transform(context.Vec0, matrix); + context.Vec1 = Vector2.Transform(context.Vec1, matrix); + context.Vec2 = Vector2.Transform(context.Vec2, matrix); + context.Vec3 = Vector2.Transform(context.Vec3, matrix); + return context; + } + + public static SpriteDrawingContext ScaleSize(this SpriteDrawingContext context, float scaleX, float scaleY) + { + var matrix = Matrix4x4.CreateScale(scaleX, scaleY, 1.0f); + context.Vec0 = Vector2.Transform(context.Vec0, matrix); + context.Vec1 = Vector2.Transform(context.Vec1, matrix); + context.Vec2 = Vector2.Transform(context.Vec2, matrix); + context.Vec3 = Vector2.Transform(context.Vec3, matrix); + return context; + } + + public static SpriteDrawingContext RotateX(this SpriteDrawingContext context, float rotation) + { + var matrix = Matrix4x4.CreateRotationX(rotation); + context.Vec0 = Vector2.Transform(context.Vec0, matrix); + context.Vec1 = Vector2.Transform(context.Vec1, matrix); + context.Vec2 = Vector2.Transform(context.Vec2, matrix); + context.Vec3 = Vector2.Transform(context.Vec3, matrix); + return context; + } + + public static SpriteDrawingContext RotateY(this SpriteDrawingContext context, float rotation) + { + var matrix = Matrix4x4.CreateRotationY(rotation); + context.Vec0 = Vector2.Transform(context.Vec0, matrix); + context.Vec1 = Vector2.Transform(context.Vec1, matrix); + context.Vec2 = Vector2.Transform(context.Vec2, matrix); + context.Vec3 = Vector2.Transform(context.Vec3, matrix); + return context; + } + + public static SpriteDrawingContext RotateZ(this SpriteDrawingContext context, float rotation) + { + var matrix = Matrix4x4.CreateRotationZ(rotation); + context.Vec0 = Vector2.Transform(context.Vec0, matrix); + context.Vec1 = Vector2.Transform(context.Vec1, matrix); + context.Vec2 = Vector2.Transform(context.Vec2, matrix); + context.Vec3 = Vector2.Transform(context.Vec3, matrix); + return context; + } + + public static SpriteDrawingContext ColorDefault(this SpriteDrawingContext context) + { + context.Color0 = ColorWhite; + context.Color1 = ColorWhite; + context.Color2 = ColorWhite; + context.Color3 = ColorWhite; + return context; + } + + public static SpriteDrawingContext Color(this SpriteDrawingContext context, ColorF color) + { + context.Color0 = color; + context.Color1 = color; + context.Color2 = color; + context.Color3 = color; + return context; + } + + public static SpriteDrawingContext ColorAdd(this SpriteDrawingContext context, ColorF color) + { + context.Color0 += color; + context.Color1 += color; + context.Color2 += color; + context.Color3 += color; + return context; + } + + public static SpriteDrawingContext ColorMultiply(this SpriteDrawingContext context, ColorF color) + { + context.Color0 *= color; + context.Color1 *= color; + context.Color2 *= color; + context.Color3 *= color; + return context; + } + + public static SpriteDrawingContext SpriteTexture(this SpriteDrawingContext context, ISpriteTexture spriteTexture) + { + context.SpriteTexture = spriteTexture; + return context; + } + + public static SpriteDrawingContext TextureWrapHorizontal(this SpriteDrawingContext context, TextureWrapMode mode, float left, float right) + { + context.TextureWrapU = mode; + context.TextureRegionLeft = left; + context.TextureRegionRight = right; + return context; + } + + public static SpriteDrawingContext TextureWrapVertical(this SpriteDrawingContext context, TextureWrapMode mode, float top, float bottom) + { + context.TextureWrapV = mode; + context.TextureRegionTop = top; + context.TextureRegionBottom = bottom; + return context; + } + } + + public interface IMappedResource : IDisposable + { + IntPtr Data { get; } + + int Stride { get; } + + int Length { get; } + } + + public interface ISpriteTexture : IDisposable + { + int Width { get; } + int Height { get; } + + IMappedResource Map(); + } + + public interface ISpriteDrawing : IDisposable + { + ISpriteTexture DestinationTexture { get; set; } + + ISpriteTexture CreateSpriteTexture(IImageRead image); + + ISpriteTexture CreateSpriteTexture(int width, int height); + + void SetViewport(float left, float right, float top, float bottom); + + void Clear(ColorF color); + + void AppendSprite(SpriteDrawingContext context); + + void Flush(); + } +} diff --git a/OpenKh.Engine/Renders/Kh2MessageRenderer.cs b/OpenKh.Engine/Renders/Kh2MessageRenderer.cs index 1ff32f5ba..d13b39f36 100644 --- a/OpenKh.Engine/Renders/Kh2MessageRenderer.cs +++ b/OpenKh.Engine/Renders/Kh2MessageRenderer.cs @@ -1,249 +1,252 @@ -using OpenKh.Engine.Extensions; -using OpenKh.Imaging; -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using System; -using System.Collections.Generic; - -namespace OpenKh.Engine.Renders -{ - public class RenderingMessageContext - { - public IImageRead Font { get; set; } - public IImageRead Font2 { get; set; } - public IImageRead Icon { get; set; } - public byte[] FontSpacing { get; set; } - public byte[] IconSpacing { get; set; } - public IMessageEncoder Encoder { get; set; } - - public int FontWidth { get; set; } - public int FontHeight { get; set; } - public int TableHeight { get; set; } - } - - public class Kh2MessageRenderer : IMessageRenderer, IDisposable - { - private const int IconWidth = Constants.FontIconWidth; - private const int IconHeight = Constants.FontIconHeight; - - private readonly ISpriteDrawing _drawing; - private readonly RenderingMessageContext _msgContext; - - private readonly byte[] _fontSpacing; - private readonly byte[] _iconSpacing; - private readonly IImageRead _imageFont; - private readonly IImageRead _imageFont2; - private readonly IImageRead _imageIcon; - private readonly ISpriteTexture _spriteFont; - private readonly ISpriteTexture _spriteFont2; - private readonly ISpriteTexture _spriteIcon; - private readonly int _charPerRow; - private readonly int _iconPerRow; - private readonly int _tableHeight; - private readonly int _charTableHeight; - private readonly IMessageEncode _encode; - - public Kh2MessageRenderer( - ISpriteDrawing drawing, - RenderingMessageContext context) - { - _drawing = drawing; - _msgContext = context; - - _fontSpacing = context.FontSpacing; - _iconSpacing = context.IconSpacing; - _imageFont = context.Font; - _imageFont2 = context.Font2; - _imageIcon = context.Icon; - _charPerRow = context.Font?.Size.Width / context.FontWidth ?? 1; - _iconPerRow = context.Icon?.Size.Width / IconWidth ?? 1; - _tableHeight = context.TableHeight; - _charTableHeight = context.TableHeight / context.FontHeight * context.FontHeight; - _encode = context.Encoder; - - if (_imageFont != null) InitializeSurface(ref _spriteFont, _imageFont); - if (_imageFont2 != null) InitializeSurface(ref _spriteFont2, _imageFont2); - if (_imageIcon != null) InitializeSurface(ref _spriteIcon, _imageIcon); - } - - public void Draw(DrawContext drawContext, string message) => - Draw(drawContext, MsgSerializer.DeserializeText(message)); - - public void Draw(DrawContext drawContext, byte[] data) - { - var commands = _msgContext.Encoder.Decode(data); - Draw(drawContext, commands); - } - - public void Draw(DrawContext drawContext, IEnumerable commands) - { - if (commands == null) - return; - - foreach (var command in commands) - Draw(drawContext, command); - } - - private void Draw(DrawContext context, MessageCommandModel command) - { - if (command.Command == MessageCommand.PrintText) - DrawText(context, command); - else if (command.Command == MessageCommand.PrintComplex) - DrawText(context, command); - else if (command.Command == MessageCommand.PrintIcon) - DrawIcon(context, command.Data[0]); - else if (command.Command == MessageCommand.Color) - SetColor(context, command.Data); - else if (command.Command == MessageCommand.Reset) - context.Reset(); - else if (command.Command == MessageCommand.Clear) - { - context.NewLine(_msgContext.FontHeight); - context.y += 4; - _drawing.FillRectangle( - 8, - (float)context.y, - Math.Max(1.0f, (float)(context.WindowWidth - 16)), - 2, - ColorF.White); - context.y += 4; - } - else if (command.Command == MessageCommand.Position) - { - context.x = command.PositionX; - context.y = command.PositionY; - } - else if (command.Command == MessageCommand.TextWidth) - context.WidthMultiplier = command.TextWidth; - else if (command.Command == MessageCommand.TextScale) - context.Scale = command.TextScale; - else if (command.Command == MessageCommand.Tabulation) - context.x += 16; // TODO this is not the real tabulation size - - context.Width = Math.Max(context.Width, context.x); - context.Height = Math.Max(context.Height, context.y + _msgContext.FontHeight * context.Scale); - } - - private void SetColor(DrawContext context, byte[] data) - { - context.Color.R = data[0] / 255.0f; - context.Color.G = data[1] / 255.0f; - context.Color.B = data[2] / 255.0f; - context.Color.A = data[3] / 128.0f; - } - - private void DrawText(DrawContext context, MessageCommandModel command) - { - if (_msgContext.Encoder == null) - return; - - var data = _msgContext.Encoder.Encode(new List - { - command - }); - - DrawText(context, data); - } - - private void DrawText(DrawContext context, byte[] data) - { - for (int i = 0; i < data.Length; i++) - { - byte ch = data[i]; - int spacing; - - if (ch >= 0x20) - { - int chIndex = ch - 0x20; - if (!context.IgnoreDraw) - DrawChar(context, chIndex); - spacing = _fontSpacing?[chIndex] ?? _msgContext.FontWidth; - } - else if (ch >= 0x19 && ch <= 0x1f) - { - int chIndex = data[++i] + (ch - 0x19) * 0x100 + 0xE0; - if (!context.IgnoreDraw) - DrawChar(context, chIndex); - spacing = _fontSpacing?[chIndex] ?? _msgContext.FontWidth; - } - else if (ch == 1) - { - spacing = 6; - } - else if (ch == 2) - { - context.NewLine(_msgContext.FontHeight); - spacing = 0; - } - else - { - spacing = 0; - } - - context.x += spacing * context.ScaleX; - } - } - - private void DrawIcon(DrawContext context, byte index) - { - if (_spriteIcon != null) - DrawIcon(context, (index % _iconPerRow) * IconWidth, (index / _iconPerRow) * IconHeight); - - context.x += _iconSpacing?[index] ?? IconWidth; - } - - protected void DrawChar(DrawContext context, int index) - { - DrawChar(context, (index % _charPerRow) * _msgContext.FontWidth, (index / _charPerRow) * _msgContext.FontHeight); - } - - protected void DrawChar(DrawContext context, int sourceX, int sourceY) - { - ISpriteTexture spriteTexture; - - var tableIndex = sourceY / _charTableHeight; - sourceY %= _charTableHeight; - - if ((tableIndex & 1) != 0) - spriteTexture = _spriteFont2; - else - spriteTexture = _spriteFont; - - if ((tableIndex & 2) != 0) - sourceY += _tableHeight; - - if (spriteTexture == null) - return; - - DrawImageScale(context, spriteTexture, sourceX, sourceY, _msgContext.FontWidth, _msgContext.FontHeight); - } - - protected void DrawIcon(DrawContext context, int sourceX, int sourceY) => - DrawImage(_spriteIcon, context.x, context.y, sourceX, sourceY, IconWidth, IconHeight, 1.0, 1.0, new ColorF(1.0f, 1.0f, 1.0f, 1.0f)); - - protected void DrawImageScale(DrawContext context, ISpriteTexture texture, int sourceX, int sourceY, int width, int height) => - DrawImage(texture, context.x, context.y, sourceX, sourceY, width, height, context.ScaleX, context.Scale, context.Color); - - protected void DrawImage(ISpriteTexture texture, double x, double y, int sourceX, int sourceY, int width, int height, double scaleX, double scaleY, ColorF color) => - _drawing.AppendSprite(new SpriteDrawingContext() - .Source(sourceX, sourceY, width, height) - .MatchSourceSize() - .ScaleSize((float)scaleX, (float)scaleY) - .Traslate((float)x, (float)y) - .Color(color) - .SpriteTexture(texture)); - - private void InitializeSurface(ref ISpriteTexture spriteTexture, IImageRead image) - { - spriteTexture?.Dispose(); - spriteTexture = _drawing?.CreateSpriteTexture(image); - } - - public void Dispose() - { - _spriteFont?.Dispose(); - _spriteFont2?.Dispose(); - _spriteIcon?.Dispose(); - } - } -} +using OpenKh.Engine.Extensions; +using OpenKh.Imaging; +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using System; +using System.Collections.Generic; + +namespace OpenKh.Engine.Renders +{ + public class RenderingMessageContext + { + public IImageRead Font { get; set; } + public IImageRead Font2 { get; set; } + public IImageRead Icon { get; set; } + public byte[] FontSpacing { get; set; } + public byte[] IconSpacing { get; set; } + public IMessageEncoder Encoder { get; set; } + + public int FontWidth { get; set; } + public int FontHeight { get; set; } + public int TableHeight { get; set; } + } + + public class Kh2MessageRenderer : IMessageRenderer, IDisposable + { + private const int IconWidth = Constants.FontIconWidth; + private const int IconHeight = Constants.FontIconHeight; + + private readonly ISpriteDrawing _drawing; + private readonly RenderingMessageContext _msgContext; + + private readonly byte[] _fontSpacing; + private readonly byte[] _iconSpacing; + private readonly IImageRead _imageFont; + private readonly IImageRead _imageFont2; + private readonly IImageRead _imageIcon; + private readonly ISpriteTexture _spriteFont; + private readonly ISpriteTexture _spriteFont2; + private readonly ISpriteTexture _spriteIcon; + private readonly int _charPerRow; + private readonly int _iconPerRow; + private readonly int _tableHeight; + private readonly int _charTableHeight; + private readonly IMessageEncode _encode; + + public Kh2MessageRenderer( + ISpriteDrawing drawing, + RenderingMessageContext context) + { + _drawing = drawing; + _msgContext = context; + + _fontSpacing = context.FontSpacing; + _iconSpacing = context.IconSpacing; + _imageFont = context.Font; + _imageFont2 = context.Font2; + _imageIcon = context.Icon; + _charPerRow = context.Font?.Size.Width / context.FontWidth ?? 1; + _iconPerRow = context.Icon?.Size.Width / IconWidth ?? 1; + _tableHeight = context.TableHeight; + _charTableHeight = context.TableHeight / context.FontHeight * context.FontHeight; + _encode = context.Encoder; + + if (_imageFont != null) + InitializeSurface(ref _spriteFont, _imageFont); + if (_imageFont2 != null) + InitializeSurface(ref _spriteFont2, _imageFont2); + if (_imageIcon != null) + InitializeSurface(ref _spriteIcon, _imageIcon); + } + + public void Draw(DrawContext drawContext, string message) => + Draw(drawContext, MsgSerializer.DeserializeText(message)); + + public void Draw(DrawContext drawContext, byte[] data) + { + var commands = _msgContext.Encoder.Decode(data); + Draw(drawContext, commands); + } + + public void Draw(DrawContext drawContext, IEnumerable commands) + { + if (commands == null) + return; + + foreach (var command in commands) + Draw(drawContext, command); + } + + private void Draw(DrawContext context, MessageCommandModel command) + { + if (command.Command == MessageCommand.PrintText) + DrawText(context, command); + else if (command.Command == MessageCommand.PrintComplex) + DrawText(context, command); + else if (command.Command == MessageCommand.PrintIcon) + DrawIcon(context, command.Data[0]); + else if (command.Command == MessageCommand.Color) + SetColor(context, command.Data); + else if (command.Command == MessageCommand.Reset) + context.Reset(); + else if (command.Command == MessageCommand.Clear) + { + context.NewLine(_msgContext.FontHeight); + context.y += 4; + _drawing.FillRectangle( + 8, + (float)context.y, + Math.Max(1.0f, (float)(context.WindowWidth - 16)), + 2, + ColorF.White); + context.y += 4; + } + else if (command.Command == MessageCommand.Position) + { + context.x = command.PositionX; + context.y = command.PositionY; + } + else if (command.Command == MessageCommand.TextWidth) + context.WidthMultiplier = command.TextWidth; + else if (command.Command == MessageCommand.TextScale) + context.Scale = command.TextScale; + else if (command.Command == MessageCommand.Tabulation) + context.x += 16; // TODO this is not the real tabulation size + + context.Width = Math.Max(context.Width, context.x); + context.Height = Math.Max(context.Height, context.y + _msgContext.FontHeight * context.Scale); + } + + private void SetColor(DrawContext context, byte[] data) + { + context.Color.R = data[0] / 255.0f; + context.Color.G = data[1] / 255.0f; + context.Color.B = data[2] / 255.0f; + context.Color.A = data[3] / 128.0f; + } + + private void DrawText(DrawContext context, MessageCommandModel command) + { + if (_msgContext.Encoder == null) + return; + + var data = _msgContext.Encoder.Encode(new List + { + command + }); + + DrawText(context, data); + } + + private void DrawText(DrawContext context, byte[] data) + { + for (int i = 0; i < data.Length; i++) + { + byte ch = data[i]; + int spacing; + + if (ch >= 0x20) + { + int chIndex = ch - 0x20; + if (!context.IgnoreDraw) + DrawChar(context, chIndex); + spacing = _fontSpacing?[chIndex] ?? _msgContext.FontWidth; + } + else if (ch >= 0x19 && ch <= 0x1f) + { + int chIndex = data[++i] + (ch - 0x19) * 0x100 + 0xE0; + if (!context.IgnoreDraw) + DrawChar(context, chIndex); + spacing = _fontSpacing?[chIndex] ?? _msgContext.FontWidth; + } + else if (ch == 1) + { + spacing = 6; + } + else if (ch == 2) + { + context.NewLine(_msgContext.FontHeight); + spacing = 0; + } + else + { + spacing = 0; + } + + context.x += spacing * context.ScaleX; + } + } + + private void DrawIcon(DrawContext context, byte index) + { + if (_spriteIcon != null) + DrawIcon(context, (index % _iconPerRow) * IconWidth, (index / _iconPerRow) * IconHeight); + + context.x += _iconSpacing?[index] ?? IconWidth; + } + + protected void DrawChar(DrawContext context, int index) + { + DrawChar(context, (index % _charPerRow) * _msgContext.FontWidth, (index / _charPerRow) * _msgContext.FontHeight); + } + + protected void DrawChar(DrawContext context, int sourceX, int sourceY) + { + ISpriteTexture spriteTexture; + + var tableIndex = sourceY / _charTableHeight; + sourceY %= _charTableHeight; + + if ((tableIndex & 1) != 0) + spriteTexture = _spriteFont2; + else + spriteTexture = _spriteFont; + + if ((tableIndex & 2) != 0) + sourceY += _tableHeight; + + if (spriteTexture == null) + return; + + DrawImageScale(context, spriteTexture, sourceX, sourceY, _msgContext.FontWidth, _msgContext.FontHeight); + } + + protected void DrawIcon(DrawContext context, int sourceX, int sourceY) => + DrawImage(_spriteIcon, context.x, context.y, sourceX, sourceY, IconWidth, IconHeight, 1.0, 1.0, new ColorF(1.0f, 1.0f, 1.0f, 1.0f)); + + protected void DrawImageScale(DrawContext context, ISpriteTexture texture, int sourceX, int sourceY, int width, int height) => + DrawImage(texture, context.x, context.y, sourceX, sourceY, width, height, context.ScaleX, context.Scale, context.Color); + + protected void DrawImage(ISpriteTexture texture, double x, double y, int sourceX, int sourceY, int width, int height, double scaleX, double scaleY, ColorF color) => + _drawing.AppendSprite(new SpriteDrawingContext() + .Source(sourceX, sourceY, width, height) + .MatchSourceSize() + .ScaleSize((float)scaleX, (float)scaleY) + .Traslate((float)x, (float)y) + .Color(color) + .SpriteTexture(texture)); + + private void InitializeSurface(ref ISpriteTexture spriteTexture, IImageRead image) + { + spriteTexture?.Dispose(); + spriteTexture = _drawing?.CreateSpriteTexture(image); + } + + public void Dispose() + { + _spriteFont?.Dispose(); + _spriteFont2?.Dispose(); + _spriteIcon?.Dispose(); + } + } +} diff --git a/OpenKh.Engine/Renders/LayoutRenderer.cs b/OpenKh.Engine/Renders/LayoutRenderer.cs index 3b6d7052b..8e0f9c18a 100644 --- a/OpenKh.Engine/Renders/LayoutRenderer.cs +++ b/OpenKh.Engine/Renders/LayoutRenderer.cs @@ -1,74 +1,74 @@ -using OpenKh.Engine.Renders; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Engine.Renderers -{ - public class LayoutRenderer - { - private readonly Layout layout; - private readonly ISpriteDrawing drawing; - private readonly ISpriteTexture[] surfaces; - private int selectedSequenceGroupIndex; - private IDebugLayoutRenderer _debugLayoutRenderer; - - public int SelectedSequenceGroupIndex - { - get => selectedSequenceGroupIndex; - set - { - if (value < 0 || value >= layout.SequenceGroups.Count) - throw new ArgumentOutOfRangeException(nameof(value), - "Cannot be negative or greater than the amount of sequence groups."); - - selectedSequenceGroupIndex = value; - } - } - - public int FrameIndex { get; set; } - public bool IsLastFrame => FrameIndex > layout.GetFrameLengthFromSequenceGroup(selectedSequenceGroupIndex); - - public LayoutRenderer(Layout layout, ISpriteDrawing drawing, IEnumerable surfaces) - { - this.layout = layout; - this.drawing = drawing; - this.surfaces = surfaces.ToArray(); - _debugLayoutRenderer = new DefaultDebugLayoutRenderer(); - } - - public void SetDebugLayoutRenderer(IDebugLayoutRenderer debugLayoutRenderer) => - _debugLayoutRenderer = debugLayoutRenderer; - - public void Draw() - { - if (!_debugLayoutRenderer.IsSequenceGroupVisible(selectedSequenceGroupIndex)) - return; - DrawLayoutGroup(layout.SequenceGroups[selectedSequenceGroupIndex]); - } - - private void DrawLayoutGroup(Layout.SequenceGroup sequencGroup) - { - for (var i = 0; i < sequencGroup.Sequences.Count; i++) - { - if (!_debugLayoutRenderer.IsSequencePropertyVisible(i)) - continue; - DrawLayout(sequencGroup.Sequences[i]); - } - } - - private void DrawLayout(Layout.SequenceProperty l1) - { - var currentFrameIndex = FrameIndex - l1.ShowAtFrame; - if (currentFrameIndex < 0) - return; - - var sequence = layout.SequenceItems[l1.SequenceIndex]; - var surface = surfaces[l1.TextureIndex]; - var sequenceRenderer = new SequenceRenderer(sequence, drawing, surface); - sequenceRenderer.Draw(l1.AnimationGroup, currentFrameIndex, l1.PositionX, l1.PositionY); - } - } -} +using OpenKh.Engine.Renders; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Engine.Renderers +{ + public class LayoutRenderer + { + private readonly Layout layout; + private readonly ISpriteDrawing drawing; + private readonly ISpriteTexture[] surfaces; + private int selectedSequenceGroupIndex; + private IDebugLayoutRenderer _debugLayoutRenderer; + + public int SelectedSequenceGroupIndex + { + get => selectedSequenceGroupIndex; + set + { + if (value < 0 || value >= layout.SequenceGroups.Count) + throw new ArgumentOutOfRangeException(nameof(value), + "Cannot be negative or greater than the amount of sequence groups."); + + selectedSequenceGroupIndex = value; + } + } + + public int FrameIndex { get; set; } + public bool IsLastFrame => FrameIndex > layout.GetFrameLengthFromSequenceGroup(selectedSequenceGroupIndex); + + public LayoutRenderer(Layout layout, ISpriteDrawing drawing, IEnumerable surfaces) + { + this.layout = layout; + this.drawing = drawing; + this.surfaces = surfaces.ToArray(); + _debugLayoutRenderer = new DefaultDebugLayoutRenderer(); + } + + public void SetDebugLayoutRenderer(IDebugLayoutRenderer debugLayoutRenderer) => + _debugLayoutRenderer = debugLayoutRenderer; + + public void Draw() + { + if (!_debugLayoutRenderer.IsSequenceGroupVisible(selectedSequenceGroupIndex)) + return; + DrawLayoutGroup(layout.SequenceGroups[selectedSequenceGroupIndex]); + } + + private void DrawLayoutGroup(Layout.SequenceGroup sequencGroup) + { + for (var i = 0; i < sequencGroup.Sequences.Count; i++) + { + if (!_debugLayoutRenderer.IsSequencePropertyVisible(i)) + continue; + DrawLayout(sequencGroup.Sequences[i]); + } + } + + private void DrawLayout(Layout.SequenceProperty l1) + { + var currentFrameIndex = FrameIndex - l1.ShowAtFrame; + if (currentFrameIndex < 0) + return; + + var sequence = layout.SequenceItems[l1.SequenceIndex]; + var surface = surfaces[l1.TextureIndex]; + var sequenceRenderer = new SequenceRenderer(sequence, drawing, surface); + sequenceRenderer.Draw(l1.AnimationGroup, currentFrameIndex, l1.PositionX, l1.PositionY); + } + } +} diff --git a/OpenKh.Engine/Renders/SequenceRenderer.cs b/OpenKh.Engine/Renders/SequenceRenderer.cs index 218837108..901a99764 100644 --- a/OpenKh.Engine/Renders/SequenceRenderer.cs +++ b/OpenKh.Engine/Renders/SequenceRenderer.cs @@ -1,331 +1,331 @@ -using OpenKh.Engine.Renders; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Engine.Renderers -{ - public enum TextAnchor - { - BottomLeft, - BottomCenter, - BottomRight, - Center, - TopCenter, - TopLeft - } - - public class SequenceRenderer - { - public class ChildContext - { - public float PositionX { get; set; } - public float PositionY { get; set; } - public ColorF Color { get; set; } - public float TextPositionX { get; set; } - public float TextPositionY { get; set; } - public float TextScale { get; set; } - public float UiSize { get; set; } - public float UiPadding { get; set; } - } - - private class Context - { - public int GlobalFrameIndex { get; set; } - public int FrameIndex { get; set; } - public float PositionX { get; set; } - public float PositionY { get; set; } - public float PivotX { get; set; } - public float PivotY { get; set; } - public float ScaleX { get; set; } - public float ScaleY { get; set; } - public float RotationX { get; set; } - public float RotationY { get; set; } - public float RotationZ { get; set; } - public ColorF Color { get; set; } - public int ColorBlendMode { get; set; } - public float Left { get; set; } - public float Top { get; set; } - public float Right { get; set; } - public float Bottom { get; set; } - - public Context Clone() => new Context - { - GlobalFrameIndex = GlobalFrameIndex, - FrameIndex = FrameIndex, - PositionX = PositionX, - PositionY = PositionY, - PivotX = PivotX, - PivotY = PivotY, - ScaleX = ScaleX, - ScaleY = ScaleY, - RotationX = RotationX, - RotationY = RotationY, - RotationZ = RotationZ, - Color = Color, - ColorBlendMode = ColorBlendMode, - Left = Left, - Top = Top, - Right = Right, - Bottom = Bottom - }; - } - - private readonly ISpriteDrawing drawing; - private readonly ISpriteTexture surface; - - public Sequence Sequence { get; } - public ChildContext CurrentChildContext { get; } = new ChildContext(); - - public SequenceRenderer(Sequence sequence, ISpriteDrawing drawing, ISpriteTexture surface) - { - this.drawing = drawing; - this.surface = surface; - Sequence = sequence; - DebugSequenceRenderer = new DefaultDebugSequenceRenderer(); - } - - public IDebugSequenceRenderer DebugSequenceRenderer { get; set; } - - public bool Draw(int animationGroupIndex, int frameIndex, float positionX, float positionY, float alpha = 1f) => - DrawAnimationGroup(new Context - { - GlobalFrameIndex = frameIndex, - FrameIndex = frameIndex, - PositionX = positionX, - PositionY = positionY, - Color = new ColorF(1f, 1f, 1f, alpha) - }, Sequence.AnimationGroups[animationGroupIndex]); - - public int GetActualFrame(Sequence.AnimationGroup animationGroup, int frameIndex) - { - CurrentChildContext.TextPositionX = animationGroup.TextPositionX; - CurrentChildContext.TextPositionY = animationGroup.TextPositionY; - CurrentChildContext.TextScale = animationGroup.TextScale; - CurrentChildContext.UiSize = animationGroup.LightPositionX; - CurrentChildContext.UiPadding = animationGroup.UiPadding; - - if (animationGroup.DoNotLoop != 0) - return frameIndex; - - var frameEnd = animationGroup.LoopEnd; - if (frameEnd == 0 && animationGroup.Animations.Count > 0) - frameEnd = animationGroup.Animations.Max(x => x.FrameEnd); - - return Loop(animationGroup.LoopStart, frameEnd, frameIndex); - } - - private bool DrawAnimationGroup(Context contextParent, Sequence.AnimationGroup animationGroup) - { - var context = contextParent.Clone(); - context.FrameIndex = GetActualFrame(animationGroup, context.FrameIndex); - - for (int i = 0; i < animationGroup.Animations.Count; i++) - { - DrawAnimation(context, animationGroup.Animations[i], i); - } - - if (animationGroup.Animations.Count == 0) - return false; - return animationGroup.DoNotLoop == 0 || - context.FrameIndex < animationGroup.Animations.Max(x => x.FrameEnd); - } - - private void DrawAnimation(Context contextParent, Sequence.Animation animation, int index) - { - // 0000 0001 = (0 = EASE IN/OUT INTERPOLATION, 1 = LINEAR INTERPOLATION) - // 0000 0008 = (0 = BOUNCING START FROM CENTER, 1 = BOUNCING START FROM X / MOVE FROM Y) - // 0000 0010 = (0 = ENABLE BOUNCING, 1 = IGNORE BOUNCING) - // 0000 0020 = (0 = ENABLE ROTATION, 1 = IGNORE ROTATION) - // 0000 0040 = (0 = ENABLE SCALING, 1 = IGNORE SCALING) - // 0000 0080 = (0 = ENABLE COLOR FADING, 1 = IGNORE COLOR FADING) - // 0000 0400 = (0 = ENABLE COLOR MASKING, 1 = IGNORE COLOR MASKING) - // 0000 4000 = (0 = ENABLE XYB, 1 = IGNORE XYB) - - if (contextParent.FrameIndex < animation.FrameStart || contextParent.FrameIndex > animation.FrameEnd) - return; - - var context = contextParent.Clone(); - var delta = (double)(context.FrameIndex - animation.FrameStart) / (animation.FrameEnd - animation.FrameStart); - - float t; - - // loc_23B030 - if ((animation.Flags & Sequence.DisableCurveFlag) != 0) - t = (float)delta; - else - t = (float)((Math.Sin(delta * Math.PI - Math.PI / 2.0) + 1.0) / 2.0); - - context.ColorBlendMode = animation.ColorBlend; - - var translateX = Lerp(t, animation.TranslateXStart, animation.TranslateXEnd); - var translateY = Lerp(t, animation.TranslateYStart, animation.TranslateYEnd); - if ((animation.Flags & Sequence.TranslationInterpolationFlag) == 0) - { - context.PositionX += translateX; - context.PositionY += translateY; - } - else - { - context.PositionX += animation.TranslateXStart; - context.PositionY += animation.TranslateYStart; - } - - if ((animation.Flags & Sequence.ScalingDisableFlag) == 0) - { - var scale = Lerp(t, animation.ScaleStart, animation.ScaleEnd); - var scaleX = Lerp(t, animation.ScaleXStart, animation.ScaleXEnd); - var scaleY = Lerp(t, animation.ScaleYStart, animation.ScaleYEnd); - context.ScaleX = scale * scaleX; - context.ScaleY = scale * scaleY; - } - else - { - context.ScaleX = 1.0f; - context.ScaleY = 1.0f; - } - - if ((animation.Flags & Sequence.ColorMaskFlag) == 0) - { - if ((animation.Flags & Sequence.ColorInterpolationFlag) == 0) - { - context.Color *= Lerp(t, - ConvertColor(animation.ColorStart), - ConvertColor(animation.ColorEnd)); - } - else - { - context.Color *= ConvertColor(animation.ColorStart); - } - } - else - context.Color *= new ColorF(1, 1, 1, 1); - - if ((animation.Flags & Sequence.RotationDisableFlag) == 0) - { - context.RotationX = Lerp(t, animation.RotationXStart, animation.RotationXEnd); - context.RotationY = Lerp(t, animation.RotationYStart, animation.RotationYEnd); - context.RotationZ = Lerp(t, animation.RotationZStart, animation.RotationZEnd); - } - - if ((animation.Flags & Sequence.PivotDisableFlag) == 0) - { - context.PivotX += Lerp(t, animation.PivotXStart, animation.PivotXEnd); - context.PivotY += Lerp(t, animation.PivotYStart, animation.PivotYEnd); - } - - if ((animation.Flags & Sequence.BounceDisableFlag) == 0) - { - var bounceXValue = (float)Math.Sin(Lerp(delta * animation.BounceXCount, 0, Math.PI)); - var bounceYValue = (float)Math.Sin(Lerp(delta * animation.BounceYCount, 0, Math.PI)); - - context.PositionX += bounceXValue * Lerp(t, animation.BounceXStart, animation.BounceXEnd); - context.PositionY += bounceYValue * Lerp(t, animation.BounceYStart, animation.BounceYEnd); - } - - context.Color *= DebugSequenceRenderer.GetAnimationBlendColor(index); - - if ((animation.Flags & Sequence.IsActiveFlag) != 0) - { - CurrentChildContext.PositionX = context.PositionX + context.PivotX; - CurrentChildContext.PositionY = context.PositionY + context.PivotY; - CurrentChildContext.Color = context.Color; - - // Horrible hack. Basically if TranslationFlag disallow to us the translation - // animation, the frame group just uses Translate*Start, but the attached - // child context still needs to use the animation. - if ((animation.Flags & Sequence.TranslationInterpolationFlag) != 0) - { - CurrentChildContext.PositionX += translateX - animation.TranslateXStart; - CurrentChildContext.PositionY += translateY - animation.TranslateYStart; - } - } - - // CALCULATE TRANSOFRMATIONS AND INTERPOLATIONS - DrawFrameGroup(context, Sequence.SpriteGroups[animation.SpriteGroupIndex]); - } - - private void DrawFrameGroup(Context context, List spriteGroup) - { - foreach (var spritePart in spriteGroup) - { - DrawFrameExtended(context, spritePart); - } - } - - private void DrawFrameExtended(Context contextParent, Sequence.SpritePart frameEx) - { - var context = contextParent.Clone(); - context.Left = frameEx.Left; - context.Top = frameEx.Top; - context.Right = frameEx.Right; - context.Bottom = frameEx.Bottom; - - DrawFrame(context, Sequence.Sprites[frameEx.SpriteIndex]); - } - - private void DrawFrame(Context context, Sequence.Sprite frame) - { - var drawContext = new SpriteDrawingContext() - .SpriteTexture(surface) - .SourceLTRB(frame.Left, frame.Top, frame.Right, frame.Bottom) - .Position(context.Left, context.Top) - .DestinationSize(context.Right - context.Left, context.Bottom - context.Top) - .Traslate(context.PivotX, context.PivotY) - .ScaleSize(context.ScaleX, context.ScaleY) - .RotateX(-context.RotationX) - .RotateY(-context.RotationY) - .RotateZ(-context.RotationZ) - .Traslate(context.PositionX, context.PositionY); - - drawContext.Color0 = ConvertColor(frame.ColorLeft); - drawContext.Color1 = ConvertColor(frame.ColorTop); - drawContext.Color2 = ConvertColor(frame.ColorRight); - drawContext.Color3 = ConvertColor(frame.ColorBottom); - drawContext.ColorMultiply(context.Color); - drawContext.BlendMode = (BlendMode)context.ColorBlendMode; - - if (frame.UTranslation != 0) // HACK to increase performance - { - drawContext.TextureWrapHorizontal(TextureWrapMode.Repeat, Math.Min(frame.Left, frame.Right), Math.Max(frame.Left, frame.Right)); - drawContext.TextureHorizontalShift = frame.UTranslation * context.GlobalFrameIndex; - } - - if (frame.VTranslation != 0) // HACK to increase performance - { - drawContext.TextureWrapVertical(TextureWrapMode.Repeat, Math.Min(frame.Top, frame.Bottom), Math.Max(frame.Top, frame.Bottom)); - drawContext.TextureVerticalShift = frame.VTranslation * context.GlobalFrameIndex; - } - - drawing.AppendSprite(drawContext); - } - - private static ColorF ConvertColor(uint color) => new ColorF( - ((color >> 0) & 0xFF) / 128.0f, - ((color >> 8) & 0xFF) / 128.0f, - ((color >> 16) & 0xFF) / 128.0f, - ((color >> 24) & 0xFF) / 128.0f); - - private static float Lerp(float m, float x1, float x2) => (x1 * (1.0f - m) + x2 * m); - private static double Lerp(double m, double x1, double x2) => (x1 * (1.0 - m) + x2 * m); - private static ColorF Lerp(double m, ColorF x1, ColorF x2) => new ColorF( - (float)Lerp(m, x1.R, x2.R), - (float)Lerp(m, x1.G, x2.G), - (float)Lerp(m, x1.B, x2.B), - (float)Lerp(m, x1.A, x2.A)); - - private static int Loop(int min, int max, int val) - { - if (val < max) - return val; - if (max <= min) - return min; - - var mod = (val - min) % (max - min); - if (mod < 0) - mod += max - min; - return min + mod; - } - } -} +using OpenKh.Engine.Renders; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Engine.Renderers +{ + public enum TextAnchor + { + BottomLeft, + BottomCenter, + BottomRight, + Center, + TopCenter, + TopLeft + } + + public class SequenceRenderer + { + public class ChildContext + { + public float PositionX { get; set; } + public float PositionY { get; set; } + public ColorF Color { get; set; } + public float TextPositionX { get; set; } + public float TextPositionY { get; set; } + public float TextScale { get; set; } + public float UiSize { get; set; } + public float UiPadding { get; set; } + } + + private class Context + { + public int GlobalFrameIndex { get; set; } + public int FrameIndex { get; set; } + public float PositionX { get; set; } + public float PositionY { get; set; } + public float PivotX { get; set; } + public float PivotY { get; set; } + public float ScaleX { get; set; } + public float ScaleY { get; set; } + public float RotationX { get; set; } + public float RotationY { get; set; } + public float RotationZ { get; set; } + public ColorF Color { get; set; } + public int ColorBlendMode { get; set; } + public float Left { get; set; } + public float Top { get; set; } + public float Right { get; set; } + public float Bottom { get; set; } + + public Context Clone() => new Context + { + GlobalFrameIndex = GlobalFrameIndex, + FrameIndex = FrameIndex, + PositionX = PositionX, + PositionY = PositionY, + PivotX = PivotX, + PivotY = PivotY, + ScaleX = ScaleX, + ScaleY = ScaleY, + RotationX = RotationX, + RotationY = RotationY, + RotationZ = RotationZ, + Color = Color, + ColorBlendMode = ColorBlendMode, + Left = Left, + Top = Top, + Right = Right, + Bottom = Bottom + }; + } + + private readonly ISpriteDrawing drawing; + private readonly ISpriteTexture surface; + + public Sequence Sequence { get; } + public ChildContext CurrentChildContext { get; } = new ChildContext(); + + public SequenceRenderer(Sequence sequence, ISpriteDrawing drawing, ISpriteTexture surface) + { + this.drawing = drawing; + this.surface = surface; + Sequence = sequence; + DebugSequenceRenderer = new DefaultDebugSequenceRenderer(); + } + + public IDebugSequenceRenderer DebugSequenceRenderer { get; set; } + + public bool Draw(int animationGroupIndex, int frameIndex, float positionX, float positionY, float alpha = 1f) => + DrawAnimationGroup(new Context + { + GlobalFrameIndex = frameIndex, + FrameIndex = frameIndex, + PositionX = positionX, + PositionY = positionY, + Color = new ColorF(1f, 1f, 1f, alpha) + }, Sequence.AnimationGroups[animationGroupIndex]); + + public int GetActualFrame(Sequence.AnimationGroup animationGroup, int frameIndex) + { + CurrentChildContext.TextPositionX = animationGroup.TextPositionX; + CurrentChildContext.TextPositionY = animationGroup.TextPositionY; + CurrentChildContext.TextScale = animationGroup.TextScale; + CurrentChildContext.UiSize = animationGroup.LightPositionX; + CurrentChildContext.UiPadding = animationGroup.UiPadding; + + if (animationGroup.DoNotLoop != 0) + return frameIndex; + + var frameEnd = animationGroup.LoopEnd; + if (frameEnd == 0 && animationGroup.Animations.Count > 0) + frameEnd = animationGroup.Animations.Max(x => x.FrameEnd); + + return Loop(animationGroup.LoopStart, frameEnd, frameIndex); + } + + private bool DrawAnimationGroup(Context contextParent, Sequence.AnimationGroup animationGroup) + { + var context = contextParent.Clone(); + context.FrameIndex = GetActualFrame(animationGroup, context.FrameIndex); + + for (int i = 0; i < animationGroup.Animations.Count; i++) + { + DrawAnimation(context, animationGroup.Animations[i], i); + } + + if (animationGroup.Animations.Count == 0) + return false; + return animationGroup.DoNotLoop == 0 || + context.FrameIndex < animationGroup.Animations.Max(x => x.FrameEnd); + } + + private void DrawAnimation(Context contextParent, Sequence.Animation animation, int index) + { + // 0000 0001 = (0 = EASE IN/OUT INTERPOLATION, 1 = LINEAR INTERPOLATION) + // 0000 0008 = (0 = BOUNCING START FROM CENTER, 1 = BOUNCING START FROM X / MOVE FROM Y) + // 0000 0010 = (0 = ENABLE BOUNCING, 1 = IGNORE BOUNCING) + // 0000 0020 = (0 = ENABLE ROTATION, 1 = IGNORE ROTATION) + // 0000 0040 = (0 = ENABLE SCALING, 1 = IGNORE SCALING) + // 0000 0080 = (0 = ENABLE COLOR FADING, 1 = IGNORE COLOR FADING) + // 0000 0400 = (0 = ENABLE COLOR MASKING, 1 = IGNORE COLOR MASKING) + // 0000 4000 = (0 = ENABLE XYB, 1 = IGNORE XYB) + + if (contextParent.FrameIndex < animation.FrameStart || contextParent.FrameIndex > animation.FrameEnd) + return; + + var context = contextParent.Clone(); + var delta = (double)(context.FrameIndex - animation.FrameStart) / (animation.FrameEnd - animation.FrameStart); + + float t; + + // loc_23B030 + if ((animation.Flags & Sequence.DisableCurveFlag) != 0) + t = (float)delta; + else + t = (float)((Math.Sin(delta * Math.PI - Math.PI / 2.0) + 1.0) / 2.0); + + context.ColorBlendMode = animation.ColorBlend; + + var translateX = Lerp(t, animation.TranslateXStart, animation.TranslateXEnd); + var translateY = Lerp(t, animation.TranslateYStart, animation.TranslateYEnd); + if ((animation.Flags & Sequence.TranslationInterpolationFlag) == 0) + { + context.PositionX += translateX; + context.PositionY += translateY; + } + else + { + context.PositionX += animation.TranslateXStart; + context.PositionY += animation.TranslateYStart; + } + + if ((animation.Flags & Sequence.ScalingDisableFlag) == 0) + { + var scale = Lerp(t, animation.ScaleStart, animation.ScaleEnd); + var scaleX = Lerp(t, animation.ScaleXStart, animation.ScaleXEnd); + var scaleY = Lerp(t, animation.ScaleYStart, animation.ScaleYEnd); + context.ScaleX = scale * scaleX; + context.ScaleY = scale * scaleY; + } + else + { + context.ScaleX = 1.0f; + context.ScaleY = 1.0f; + } + + if ((animation.Flags & Sequence.ColorMaskFlag) == 0) + { + if ((animation.Flags & Sequence.ColorInterpolationFlag) == 0) + { + context.Color *= Lerp(t, + ConvertColor(animation.ColorStart), + ConvertColor(animation.ColorEnd)); + } + else + { + context.Color *= ConvertColor(animation.ColorStart); + } + } + else + context.Color *= new ColorF(1, 1, 1, 1); + + if ((animation.Flags & Sequence.RotationDisableFlag) == 0) + { + context.RotationX = Lerp(t, animation.RotationXStart, animation.RotationXEnd); + context.RotationY = Lerp(t, animation.RotationYStart, animation.RotationYEnd); + context.RotationZ = Lerp(t, animation.RotationZStart, animation.RotationZEnd); + } + + if ((animation.Flags & Sequence.PivotDisableFlag) == 0) + { + context.PivotX += Lerp(t, animation.PivotXStart, animation.PivotXEnd); + context.PivotY += Lerp(t, animation.PivotYStart, animation.PivotYEnd); + } + + if ((animation.Flags & Sequence.BounceDisableFlag) == 0) + { + var bounceXValue = (float)Math.Sin(Lerp(delta * animation.BounceXCount, 0, Math.PI)); + var bounceYValue = (float)Math.Sin(Lerp(delta * animation.BounceYCount, 0, Math.PI)); + + context.PositionX += bounceXValue * Lerp(t, animation.BounceXStart, animation.BounceXEnd); + context.PositionY += bounceYValue * Lerp(t, animation.BounceYStart, animation.BounceYEnd); + } + + context.Color *= DebugSequenceRenderer.GetAnimationBlendColor(index); + + if ((animation.Flags & Sequence.IsActiveFlag) != 0) + { + CurrentChildContext.PositionX = context.PositionX + context.PivotX; + CurrentChildContext.PositionY = context.PositionY + context.PivotY; + CurrentChildContext.Color = context.Color; + + // Horrible hack. Basically if TranslationFlag disallow to us the translation + // animation, the frame group just uses Translate*Start, but the attached + // child context still needs to use the animation. + if ((animation.Flags & Sequence.TranslationInterpolationFlag) != 0) + { + CurrentChildContext.PositionX += translateX - animation.TranslateXStart; + CurrentChildContext.PositionY += translateY - animation.TranslateYStart; + } + } + + // CALCULATE TRANSOFRMATIONS AND INTERPOLATIONS + DrawFrameGroup(context, Sequence.SpriteGroups[animation.SpriteGroupIndex]); + } + + private void DrawFrameGroup(Context context, List spriteGroup) + { + foreach (var spritePart in spriteGroup) + { + DrawFrameExtended(context, spritePart); + } + } + + private void DrawFrameExtended(Context contextParent, Sequence.SpritePart frameEx) + { + var context = contextParent.Clone(); + context.Left = frameEx.Left; + context.Top = frameEx.Top; + context.Right = frameEx.Right; + context.Bottom = frameEx.Bottom; + + DrawFrame(context, Sequence.Sprites[frameEx.SpriteIndex]); + } + + private void DrawFrame(Context context, Sequence.Sprite frame) + { + var drawContext = new SpriteDrawingContext() + .SpriteTexture(surface) + .SourceLTRB(frame.Left, frame.Top, frame.Right, frame.Bottom) + .Position(context.Left, context.Top) + .DestinationSize(context.Right - context.Left, context.Bottom - context.Top) + .Traslate(context.PivotX, context.PivotY) + .ScaleSize(context.ScaleX, context.ScaleY) + .RotateX(-context.RotationX) + .RotateY(-context.RotationY) + .RotateZ(-context.RotationZ) + .Traslate(context.PositionX, context.PositionY); + + drawContext.Color0 = ConvertColor(frame.ColorLeft); + drawContext.Color1 = ConvertColor(frame.ColorTop); + drawContext.Color2 = ConvertColor(frame.ColorRight); + drawContext.Color3 = ConvertColor(frame.ColorBottom); + drawContext.ColorMultiply(context.Color); + drawContext.BlendMode = (BlendMode)context.ColorBlendMode; + + if (frame.UTranslation != 0) // HACK to increase performance + { + drawContext.TextureWrapHorizontal(TextureWrapMode.Repeat, Math.Min(frame.Left, frame.Right), Math.Max(frame.Left, frame.Right)); + drawContext.TextureHorizontalShift = frame.UTranslation * context.GlobalFrameIndex; + } + + if (frame.VTranslation != 0) // HACK to increase performance + { + drawContext.TextureWrapVertical(TextureWrapMode.Repeat, Math.Min(frame.Top, frame.Bottom), Math.Max(frame.Top, frame.Bottom)); + drawContext.TextureVerticalShift = frame.VTranslation * context.GlobalFrameIndex; + } + + drawing.AppendSprite(drawContext); + } + + private static ColorF ConvertColor(uint color) => new ColorF( + ((color >> 0) & 0xFF) / 128.0f, + ((color >> 8) & 0xFF) / 128.0f, + ((color >> 16) & 0xFF) / 128.0f, + ((color >> 24) & 0xFF) / 128.0f); + + private static float Lerp(float m, float x1, float x2) => (x1 * (1.0f - m) + x2 * m); + private static double Lerp(double m, double x1, double x2) => (x1 * (1.0 - m) + x2 * m); + private static ColorF Lerp(double m, ColorF x1, ColorF x2) => new ColorF( + (float)Lerp(m, x1.R, x2.R), + (float)Lerp(m, x1.G, x2.G), + (float)Lerp(m, x1.B, x2.B), + (float)Lerp(m, x1.A, x2.A)); + + private static int Loop(int min, int max, int val) + { + if (val < max) + return val; + if (max <= min) + return min; + + var mod = (val - min) % (max - min); + if (mod < 0) + mod += max - min; + return min + mod; + } + } +} diff --git a/OpenKh.Engine/TargetCamera.cs b/OpenKh.Engine/TargetCamera.cs index f0a38f077..f69501ebb 100644 --- a/OpenKh.Engine/TargetCamera.cs +++ b/OpenKh.Engine/TargetCamera.cs @@ -1,301 +1,301 @@ -using OpenKh.Common; -using System; -using System.Numerics; - -namespace OpenKh.Engine -{ - public static class VectorHelpers - { - public static Vector3 ToVector3(this Vector4 v) => - new Vector3(v.X, v.Y, v.Z); - - public static Vector3 Invert(this Vector3 v) => - new Vector3(-v.X, -v.Y, -v.Z); - } - - public class TargetCamera - { - private class CameraMode - { - public float Fov { get; set; } - public float Radius { get; set; } - public float LockRadius { get; set; } - public float RadiusMin { get; set; } - public float RadiusMax { get; set; } - public float ObjectiveUpCurve { get; set; } - } - - private const float FovDefault = 1.5f; - private const float FovClose = (float)(Math.PI / (FovDefault * 2f)); - private static readonly CameraMode CameraOutDoor = new CameraMode - { - Fov = 1.5f, - Radius = 420f, - LockRadius = 380f, - RadiusMin = 250f, - RadiusMax = 500f, - ObjectiveUpCurve = 0.008f - }; - private static readonly CameraMode CameraInDoor = new CameraMode - { - Fov = FovClose, - Radius = 600f, - LockRadius = 520f, - RadiusMin = 400f, - RadiusMax = 700f, - ObjectiveUpCurve = 0.005f - }; - private static readonly CameraMode CameraCrowd = new CameraMode - { - Fov = FovClose, - Radius = 600f, - LockRadius = 520f, - RadiusMin = 400f, - RadiusMax = 700f, - ObjectiveUpCurve = 0.005f - }; - private static readonly CameraMode CameraLightCycle = new CameraMode - { - Fov = FovClose, - Radius = 600f, - LockRadius = 520f, - RadiusMin = 400f, - RadiusMax = 633f, - ObjectiveUpCurve = 0.005f - }; - private static readonly CameraMode[] CameraTypes = new CameraMode[] - { - CameraOutDoor, - CameraInDoor, - CameraCrowd, - CameraLightCycle, - }; - - private Vector4 m_eyeTarget; - private Vector3 _targetPositionPrev; - private int _type; - - public TargetCamera(Camera camera) - { - Camera = camera; - Type = 0; - Interpolate = true; - } - - public Camera Camera { get; } - public bool Interpolate { get; set; } - public Vector4 At { get; set; } - public Vector4 Eye { get; set; } - public Vector4 FovV { get; set; } - public float Fov { get; set; } - public float Roll { get; set; } - public float Radius { get; set; } - public float YRotation { get; set; } - public float BackYRotation { get; set; } - - public Vector4 EyeTarget - { - get => m_eyeTarget; - set => m_eyeTarget = value; - } - - public Vector4 EyeTargetPrev { get; set; } - public Vector4 AtTarget { get; set; } - public Vector4 AtTargetPrev { get; set; } - public Vector4 FovVTarget { get; set; } - public Vector4 FovVTargetPrev { get; set; } - public float Yaw { get; set; } - public float Pitch { get; set; } - public float ObjectiveInitRadius { get; set; } - public float ObjectiveLockRadius { get; set; } - public float ObjectiveRadiusMin { get; set; } - public float ObjectiveRadiusMax { get; set; } - public float ObjectiveUpCurve { get; set; } - public float DefaultFov { get; set; } - public float DefaultRoll { get; set; } - - public int Type - { - get => _type; - set - { - Log.Info("{0}.{1}={2}", nameof(TargetCamera), nameof(Type), value); - if (value < 0 || value >= CameraTypes.Length) - Log.Err("{0}.{1}={2} not valid", nameof(TargetCamera), nameof(Type), value); - - _type = value; - var cameraMode = CameraTypes[value]; - Fov = DefaultFov = cameraMode.Fov; - Radius = ObjectiveInitRadius = cameraMode.Radius; - ObjectiveLockRadius = cameraMode.LockRadius; - ObjectiveRadiusMin = cameraMode.RadiusMin; - ObjectiveRadiusMax = cameraMode.RadiusMax; - ObjectiveUpCurve = cameraMode.ObjectiveUpCurve; - } - } - - public void Update(IEntity objTarget, double deltaTime, bool isYRotationLocked = false) - { - var targetPosition = objTarget.Position; - - AtTarget = new Vector4( - targetPosition.X, - -targetPosition.Y - 170f, - -targetPosition.Z, - 1f); - - // This is not really the right way to know if the focused entity is actually moving - var isEntityMoving = targetPosition.X != _targetPositionPrev.X || - targetPosition.Z != _targetPositionPrev.Z; - _targetPositionPrev = targetPosition; - if (isEntityMoving && !isYRotationLocked) - { - AdjustHorizontalRotation(objTarget, deltaTime); - AdjustVerticalDefaultRotation(deltaTime); - } - - CalculateEyeTarget(AtTarget, false, deltaTime); - FovVTarget = new Vector4(Fov, WarpRadians(Roll), 0f, 1f); - - if (Interpolate) - { - At = InterpolateVector(At, AtTarget, AtTargetPrev, 30.0 * deltaTime * 0.1f, 2.5f, 0.5f, 1.0f); - Eye = InterpolateVector(Eye, EyeTarget, EyeTargetPrev, 30.0 * deltaTime * 0.07f, 2.5f, 0.5f, 1.0f); - FovV = InterpolateVector(FovV, FovVTarget, FovVTargetPrev, 30.0 * deltaTime * 0.07f, 2.5f, 0.5f, 0.001f); - } - else - { - Eye = EyeTarget; - At = AtTarget; - FovV = FovVTarget; - } - - EyeTargetPrev = EyeTarget; - AtTargetPrev = AtTarget; - FovVTargetPrev = FovVTarget; - - Camera.FieldOfView = Fov; - Camera.CameraPosition = Eye.ToVector3().Invert(); - Camera.CameraLookAt = At.ToVector3().Invert(); - } - - public void InstantlyRotateCameraToEntity(IEntity objTarget) => - YRotation = BackYRotation = GetYRotation(objTarget); - - private float GetYRotation(IEntity objTarget) => - WarpRadians((float)(Math.PI * 2 - objTarget.Rotation.Y)); - - private void AdjustVerticalDefaultRotation(double deltaTime) => - AdjustVerticalRotation(ObjectiveInitRadius, deltaTime / 2.0); - - private void AdjustVerticalLockonRotation(double deltaTime) => - AdjustVerticalRotation(ObjectiveLockRadius, deltaTime); - - private void AdjustVerticalRotation(float objectiveRadius, double deltaTime) - { - if (Math.Abs(Radius - objectiveRadius) >= 1.0) - { - if (Radius > objectiveRadius) - { - Radius = (float)(Radius - deltaTime * 60); - if (Radius <= ObjectiveRadiusMin) - Radius = ObjectiveRadiusMin; - } - else - { - Radius = (float)(Radius + deltaTime * 60); - if (Radius >= ObjectiveRadiusMax) - Radius = ObjectiveRadiusMax; - } - } - } - - private void AdjustHorizontalRotation(IEntity objTarget, double deltaTime) - { - const double Speed = Math.PI / 720.0; - const double PlayerSpeedMul = Speed / 25.0; - const float analogX = 0f; - const float analogY = 0f; - const float analogW = 1f; - const float playerSpeed = 8f; // ??? - float objYRotation = GetYRotation(objTarget); - var deltaFrame = deltaTime * 60.0; - - var speed = (Math.Abs(analogX) + 1.0) * (Math.Abs(analogY) + 1.0) * analogW * 4.0 * - ((PlayerSpeedMul * (playerSpeed - 8.0)) + Speed) * deltaFrame; - var rotation = InterpolateYRotation(YRotation, objYRotation, speed); - YRotation = BackYRotation = rotation; - } - - private void CalculateEyeTarget(Vector4 atTarget, bool interpolate, double deltaTime) - { - const double TurnSpeed = 10.4719752; - - var radiusDiff = Radius - ObjectiveRadiusMin; - if (interpolate) - YRotation = InterpolateYRotation(YRotation, BackYRotation, TurnSpeed * deltaTime); - else - YRotation = BackYRotation; - - EyeTarget = atTarget + Vector4.Transform( - new Vector4(0, 0, Radius, 0), Matrix4x4.CreateRotationY(YRotation)); - m_eyeTarget.Y = -((radiusDiff * radiusDiff * ObjectiveUpCurve) - (atTarget.Y + 150.0f)); - } - - private Vector4 InterpolateVector( - Vector4 dst, Vector4 src, Vector4 srcPrev, - double deltaTime, - float springConst, - float dampConst, - float springLen) - { - var vDiff = dst - src; - var vectorLength = vDiff.Length(); - if (vectorLength == 0) - return dst; - - var v0 = vDiff * Vector4.Multiply(srcPrev - src, (float)deltaTime); - var f0 = v0.X + v0.Y + v0.Z; - var f2 = (springConst * (springLen - vectorLength)) + dampConst * f0 / vectorLength; - return dst + Vector4.Multiply(vDiff, (float)(1f / vectorLength * f2 * deltaTime)); - } - - private float InterpolateYRotation(float src, float dst, double speed) - { - var diff = dst - src; - double actualSpeed; - if (WarpRadians(diff) >= -speed) - { - if (WarpRadians(diff) <= speed) - actualSpeed = WarpRadians(diff); - else - actualSpeed = speed; - } - else - actualSpeed = -speed; - - return WarpRadians((float)(src + actualSpeed)); - } - - private float WarpRadians(float radians) - { - const float PI_2 = (float)(Math.PI * 2); - if (radians < -Math.PI) - { - do - { - radians += PI_2; - } while (radians < -Math.PI); - } - else if (Math.PI < radians) - { - do - { - radians -= PI_2; - } while (radians > Math.PI); - } - - return radians; - } - } -} +using OpenKh.Common; +using System; +using System.Numerics; + +namespace OpenKh.Engine +{ + public static class VectorHelpers + { + public static Vector3 ToVector3(this Vector4 v) => + new Vector3(v.X, v.Y, v.Z); + + public static Vector3 Invert(this Vector3 v) => + new Vector3(-v.X, -v.Y, -v.Z); + } + + public class TargetCamera + { + private class CameraMode + { + public float Fov { get; set; } + public float Radius { get; set; } + public float LockRadius { get; set; } + public float RadiusMin { get; set; } + public float RadiusMax { get; set; } + public float ObjectiveUpCurve { get; set; } + } + + private const float FovDefault = 1.5f; + private const float FovClose = (float)(Math.PI / (FovDefault * 2f)); + private static readonly CameraMode CameraOutDoor = new CameraMode + { + Fov = 1.5f, + Radius = 420f, + LockRadius = 380f, + RadiusMin = 250f, + RadiusMax = 500f, + ObjectiveUpCurve = 0.008f + }; + private static readonly CameraMode CameraInDoor = new CameraMode + { + Fov = FovClose, + Radius = 600f, + LockRadius = 520f, + RadiusMin = 400f, + RadiusMax = 700f, + ObjectiveUpCurve = 0.005f + }; + private static readonly CameraMode CameraCrowd = new CameraMode + { + Fov = FovClose, + Radius = 600f, + LockRadius = 520f, + RadiusMin = 400f, + RadiusMax = 700f, + ObjectiveUpCurve = 0.005f + }; + private static readonly CameraMode CameraLightCycle = new CameraMode + { + Fov = FovClose, + Radius = 600f, + LockRadius = 520f, + RadiusMin = 400f, + RadiusMax = 633f, + ObjectiveUpCurve = 0.005f + }; + private static readonly CameraMode[] CameraTypes = new CameraMode[] + { + CameraOutDoor, + CameraInDoor, + CameraCrowd, + CameraLightCycle, + }; + + private Vector4 m_eyeTarget; + private Vector3 _targetPositionPrev; + private int _type; + + public TargetCamera(Camera camera) + { + Camera = camera; + Type = 0; + Interpolate = true; + } + + public Camera Camera { get; } + public bool Interpolate { get; set; } + public Vector4 At { get; set; } + public Vector4 Eye { get; set; } + public Vector4 FovV { get; set; } + public float Fov { get; set; } + public float Roll { get; set; } + public float Radius { get; set; } + public float YRotation { get; set; } + public float BackYRotation { get; set; } + + public Vector4 EyeTarget + { + get => m_eyeTarget; + set => m_eyeTarget = value; + } + + public Vector4 EyeTargetPrev { get; set; } + public Vector4 AtTarget { get; set; } + public Vector4 AtTargetPrev { get; set; } + public Vector4 FovVTarget { get; set; } + public Vector4 FovVTargetPrev { get; set; } + public float Yaw { get; set; } + public float Pitch { get; set; } + public float ObjectiveInitRadius { get; set; } + public float ObjectiveLockRadius { get; set; } + public float ObjectiveRadiusMin { get; set; } + public float ObjectiveRadiusMax { get; set; } + public float ObjectiveUpCurve { get; set; } + public float DefaultFov { get; set; } + public float DefaultRoll { get; set; } + + public int Type + { + get => _type; + set + { + Log.Info("{0}.{1}={2}", nameof(TargetCamera), nameof(Type), value); + if (value < 0 || value >= CameraTypes.Length) + Log.Err("{0}.{1}={2} not valid", nameof(TargetCamera), nameof(Type), value); + + _type = value; + var cameraMode = CameraTypes[value]; + Fov = DefaultFov = cameraMode.Fov; + Radius = ObjectiveInitRadius = cameraMode.Radius; + ObjectiveLockRadius = cameraMode.LockRadius; + ObjectiveRadiusMin = cameraMode.RadiusMin; + ObjectiveRadiusMax = cameraMode.RadiusMax; + ObjectiveUpCurve = cameraMode.ObjectiveUpCurve; + } + } + + public void Update(IEntity objTarget, double deltaTime, bool isYRotationLocked = false) + { + var targetPosition = objTarget.Position; + + AtTarget = new Vector4( + targetPosition.X, + -targetPosition.Y - 170f, + -targetPosition.Z, + 1f); + + // This is not really the right way to know if the focused entity is actually moving + var isEntityMoving = targetPosition.X != _targetPositionPrev.X || + targetPosition.Z != _targetPositionPrev.Z; + _targetPositionPrev = targetPosition; + if (isEntityMoving && !isYRotationLocked) + { + AdjustHorizontalRotation(objTarget, deltaTime); + AdjustVerticalDefaultRotation(deltaTime); + } + + CalculateEyeTarget(AtTarget, false, deltaTime); + FovVTarget = new Vector4(Fov, WarpRadians(Roll), 0f, 1f); + + if (Interpolate) + { + At = InterpolateVector(At, AtTarget, AtTargetPrev, 30.0 * deltaTime * 0.1f, 2.5f, 0.5f, 1.0f); + Eye = InterpolateVector(Eye, EyeTarget, EyeTargetPrev, 30.0 * deltaTime * 0.07f, 2.5f, 0.5f, 1.0f); + FovV = InterpolateVector(FovV, FovVTarget, FovVTargetPrev, 30.0 * deltaTime * 0.07f, 2.5f, 0.5f, 0.001f); + } + else + { + Eye = EyeTarget; + At = AtTarget; + FovV = FovVTarget; + } + + EyeTargetPrev = EyeTarget; + AtTargetPrev = AtTarget; + FovVTargetPrev = FovVTarget; + + Camera.FieldOfView = Fov; + Camera.CameraPosition = Eye.ToVector3().Invert(); + Camera.CameraLookAt = At.ToVector3().Invert(); + } + + public void InstantlyRotateCameraToEntity(IEntity objTarget) => + YRotation = BackYRotation = GetYRotation(objTarget); + + private float GetYRotation(IEntity objTarget) => + WarpRadians((float)(Math.PI * 2 - objTarget.Rotation.Y)); + + private void AdjustVerticalDefaultRotation(double deltaTime) => + AdjustVerticalRotation(ObjectiveInitRadius, deltaTime / 2.0); + + private void AdjustVerticalLockonRotation(double deltaTime) => + AdjustVerticalRotation(ObjectiveLockRadius, deltaTime); + + private void AdjustVerticalRotation(float objectiveRadius, double deltaTime) + { + if (Math.Abs(Radius - objectiveRadius) >= 1.0) + { + if (Radius > objectiveRadius) + { + Radius = (float)(Radius - deltaTime * 60); + if (Radius <= ObjectiveRadiusMin) + Radius = ObjectiveRadiusMin; + } + else + { + Radius = (float)(Radius + deltaTime * 60); + if (Radius >= ObjectiveRadiusMax) + Radius = ObjectiveRadiusMax; + } + } + } + + private void AdjustHorizontalRotation(IEntity objTarget, double deltaTime) + { + const double Speed = Math.PI / 720.0; + const double PlayerSpeedMul = Speed / 25.0; + const float analogX = 0f; + const float analogY = 0f; + const float analogW = 1f; + const float playerSpeed = 8f; // ??? + float objYRotation = GetYRotation(objTarget); + var deltaFrame = deltaTime * 60.0; + + var speed = (Math.Abs(analogX) + 1.0) * (Math.Abs(analogY) + 1.0) * analogW * 4.0 * + ((PlayerSpeedMul * (playerSpeed - 8.0)) + Speed) * deltaFrame; + var rotation = InterpolateYRotation(YRotation, objYRotation, speed); + YRotation = BackYRotation = rotation; + } + + private void CalculateEyeTarget(Vector4 atTarget, bool interpolate, double deltaTime) + { + const double TurnSpeed = 10.4719752; + + var radiusDiff = Radius - ObjectiveRadiusMin; + if (interpolate) + YRotation = InterpolateYRotation(YRotation, BackYRotation, TurnSpeed * deltaTime); + else + YRotation = BackYRotation; + + EyeTarget = atTarget + Vector4.Transform( + new Vector4(0, 0, Radius, 0), Matrix4x4.CreateRotationY(YRotation)); + m_eyeTarget.Y = -((radiusDiff * radiusDiff * ObjectiveUpCurve) - (atTarget.Y + 150.0f)); + } + + private Vector4 InterpolateVector( + Vector4 dst, Vector4 src, Vector4 srcPrev, + double deltaTime, + float springConst, + float dampConst, + float springLen) + { + var vDiff = dst - src; + var vectorLength = vDiff.Length(); + if (vectorLength == 0) + return dst; + + var v0 = vDiff * Vector4.Multiply(srcPrev - src, (float)deltaTime); + var f0 = v0.X + v0.Y + v0.Z; + var f2 = (springConst * (springLen - vectorLength)) + dampConst * f0 / vectorLength; + return dst + Vector4.Multiply(vDiff, (float)(1f / vectorLength * f2 * deltaTime)); + } + + private float InterpolateYRotation(float src, float dst, double speed) + { + var diff = dst - src; + double actualSpeed; + if (WarpRadians(diff) >= -speed) + { + if (WarpRadians(diff) <= speed) + actualSpeed = WarpRadians(diff); + else + actualSpeed = speed; + } + else + actualSpeed = -speed; + + return WarpRadians((float)(src + actualSpeed)); + } + + private float WarpRadians(float radians) + { + const float PI_2 = (float)(Math.PI * 2); + if (radians < -Math.PI) + { + do + { + radians += PI_2; + } while (radians < -Math.PI); + } + else if (Math.PI < radians) + { + do + { + radians -= PI_2; + } while (radians > Math.PI); + } + + return radians; + } + } +} diff --git a/OpenKh.Game/AnimatedSequenceFactory.cs b/OpenKh.Game/AnimatedSequenceFactory.cs index 4643f36dd..413610725 100644 --- a/OpenKh.Game/AnimatedSequenceFactory.cs +++ b/OpenKh.Game/AnimatedSequenceFactory.cs @@ -1,494 +1,494 @@ -using OpenKh.Engine; -using OpenKh.Engine.Renderers; -using OpenKh.Engine.Renders; -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Game -{ - internal enum AnimationFlagsDefinitions - { - TextTranslateX, - NoChildTranslationX, - ChildStackHorizontally, - StackNextChildHorizontally, - StackNextChildVertically, - TextIgnoreColor, - TextIgnoreScaling, - } - - [Flags] - public enum AnimationFlags - { - None, - TextTranslateX = 1 << AnimationFlagsDefinitions.TextTranslateX, - NoChildTranslationX = 1 << AnimationFlagsDefinitions.NoChildTranslationX, - ChildStackHorizontally = 1 << AnimationFlagsDefinitions.ChildStackHorizontally, - StackNextChildHorizontally = 1 << AnimationFlagsDefinitions.StackNextChildHorizontally, - StackNextChildVertically = 1 << AnimationFlagsDefinitions.StackNextChildVertically, - TextIgnoreColor = 1 << AnimationFlagsDefinitions.TextIgnoreColor, - TextIgnoreScaling = 1 << AnimationFlagsDefinitions.TextIgnoreScaling, - } - - public interface IAnimatedSequence - { - bool IsEnd { get; } - TextAnchor TextAnchor { get; set; } - int FrameIndex { get; set; } - - void Update(double deltaTime); - void Draw(float x, float y); - - void Begin(); - void Skip(); - void End(); - - void SetMessage(ushort id); - void SetMessage(string text); - } - - public class AnimatedSequenceDesc - { - public const int DefaultStacking = int.MinValue; - - public float X { get; set; } - public float Y { get; set; } - public AnimationFlags Flags { get; set; } - public TextAnchor TextAnchor { get; set; } - public ushort MessageId { get; set; } - public string MessageText { get; set; } - public int SequenceIndexLoop { get; set; } = -1; - public int SequenceIndexStart { get; set; } = -1; - public int SequenceIndexEnd { get; set; } = -1; - public int StackIndex { get; set; } - public int StackWidth { get; set; } - public int StackHeight { get; set; } - public List Children { get; set; } - } - - public class AnimatedSequenceFactory - { - private class RootAnimatedSequence : IAnimatedSequence - { - private int _frameIndex; - - public List Children { get; set; } - - public bool IsEnd => Children.All(x => x.IsEnd); - public TextAnchor TextAnchor { get; set; } - public int FrameIndex - { - get => _frameIndex; - set - { - _frameIndex = value; - foreach (var item in Children) - item.FrameIndex = value; - } - } - - public void Update(double deltaTime) - { - _frameIndex++; - foreach (var item in Children) - item.Update(deltaTime); - } - - public void Draw(float x, float y) - { - foreach (var item in Children) - { - item.Draw(x, y); - } - } - - public void Begin() - { - foreach (var item in Children) - item.Begin(); - } - - public void Skip() - { - foreach (var item in Children) - item.Skip(); - } - - public void End() - { - foreach (var item in Children) - item.End(); - } - - public void SetMessage(ushort id) - { - } - - public void SetMessage(string text) - { - } - } - - private class AnimatedSequence : IAnimatedSequence - { - private static ColorF DefaultColor = new ColorF(1f, 1f, 1f, 1f); - private readonly Sequence _sequence; - private readonly SequenceRenderer _renderer; - private readonly IMessageProvider _messageProvider; - private readonly IMessageRenderer _messageRenderer; - private readonly IMessageEncode _messageEncode; - private int _anim; - private int _frame; - private bool _isRunning; - private byte[] _message; - - public int SequenceIndexLoop { get; } - public int SequenceIndexStart { get; } - public int SequenceIndexEnd { get; } - public List Children { get; set; } - - public bool IsEnd { get; private set; } - - public float PositionX { get; set; } - public float PositionY { get; set; } - public int StackIndex { get; set; } - public int StackWidth { get; set; } - public int StackHeight { get; set; } - public TextAnchor TextAnchor { get; set; } - public AnimationFlags Flags { get; set; } - public int FrameIndex - { - get => _frame; - set - { - _frame = value; - foreach (var item in Children) - item.FrameIndex = value; - } - } - - public Sequence.AnimationGroup AnimGroup => - _sequence.AnimationGroups[_anim]; - - public float UiSize => AnimGroup.UiPadding; - - public AnimatedSequence( - ISpriteDrawing drawing, - IMessageProvider messageProvider, - IMessageRenderer messageRenderer, - IMessageEncode messageEncode, - Sequence sequence, - ISpriteTexture texture, - int loop, int start, int end) - { - _sequence = sequence; - _renderer = new SequenceRenderer( - sequence, drawing, texture); - _messageEncode = messageEncode; - _messageProvider = messageProvider; - _messageRenderer = messageRenderer; - SequenceIndexLoop = loop; - SequenceIndexStart = start; - SequenceIndexEnd = end; - } - - public void Update(double deltaTime) - { - if (!IsEnd) - _frame++; - - foreach (var child in Children) - child.Update(deltaTime); - } - - public void Draw(float x, float y) => - Draw(new SequenceRenderer.ChildContext - { - PositionX = x, - PositionY = y, - Color = DefaultColor - }); - - private void Draw(SequenceRenderer.ChildContext context) - { - if (_anim == -1) - return; - - var anotherPosX = (StackWidth != AnimatedSequenceDesc.DefaultStacking ? - StackWidth : AnimGroup.TextPositionX) * StackIndex; - var anotherPosY = (StackHeight != AnimatedSequenceDesc.DefaultStacking ? - StackHeight : AnimGroup.TextPositionX) * StackIndex; - - if (!_renderer.Draw( - _anim, - _frame, - PositionX + anotherPosX + context.PositionX, - PositionY + anotherPosY + context.PositionY, - context.Color.A)) - { - if (_isRunning) - { - _anim = SequenceIndexLoop; - _frame = 0; - } - else - IsEnd = true; - } - - var childContext = _renderer.CurrentChildContext; - - if (_message != null) - { - const float UiTextScale = 0.7f; - float textScale = context.TextScale == 0 || Flags.HasFlag(AnimationFlags.TextIgnoreScaling) ? - UiTextScale : (context.TextScale / 22f); - - var fakeTextDrawContext = new DrawContext - { - Scale = textScale, - IgnoreDraw = true, - }; - _messageRenderer.Draw(fakeTextDrawContext, _message); - var width = (float)fakeTextDrawContext.Width; - var height = (float)fakeTextDrawContext.Height; - - float xPos, yPos; - switch (TextAnchor) - { - default: - case TextAnchor.BottomLeft: - xPos = 0; - yPos = 0; - break; - case TextAnchor.BottomCenter: - xPos = -width / 2; - yPos = 0; - break; - case TextAnchor.BottomRight: - xPos = context.UiSize - width; - yPos = 0; - break; - case TextAnchor.Center: - xPos = -width / 2; - yPos = -height / 2; - break; - case TextAnchor.TopCenter: - xPos = -width / 2; - yPos = -height; - break; - case TextAnchor.TopLeft: - xPos = 0; - yPos = -height; - break; - } - - if (!Flags.HasFlag(AnimationFlags.TextTranslateX)) - xPos += childContext.TextPositionX; - - var textColor = childContext.Color; - if (Flags.HasFlag(AnimationFlags.TextIgnoreColor)) - textColor = new ColorF(1f, 1f, 1f, textColor.A); - - const float ShadowDistance = 1.5f; - const float ShadowOpacity = 0.75f; - _messageRenderer.Draw(new DrawContext - { - xStart = childContext.PositionX + xPos + ShadowDistance, - x = childContext.PositionX + xPos + ShadowDistance, - y = childContext.PositionY + childContext.TextPositionY + yPos + ShadowDistance, - Color = new ColorF(0, 0, 0, textColor.A * ShadowOpacity), - Scale = textScale, - WidthMultiplier = 1.0f, - }, _message); - - _messageRenderer.Draw(new DrawContext - { - xStart = childContext.PositionX + xPos, - x = childContext.PositionX + xPos, - y = childContext.PositionY + childContext.TextPositionY + yPos, - Color = textColor, - Scale = textScale, - WidthMultiplier = 1.0f, - }, _message); - } - - childContext.PositionX = Flags.HasFlag(AnimationFlags.NoChildTranslationX) ? - context.PositionX : childContext.PositionX; - - var originalPosY = childContext.PositionY; - for (var i = 0; i < Children.Count; i++) - { - var child = Children[i] as AnimatedSequence; - childContext.PositionY = originalPosY + childContext.UiPadding * child.StackIndex; - - child.Draw(childContext); - - if (Flags.HasFlag(AnimationFlags.ChildStackHorizontally)) - childContext.PositionX += childContext.UiSize; - - if (Flags.HasFlag(AnimationFlags.StackNextChildHorizontally)) - childContext.PositionX += child.UiSize; - if (Flags.HasFlag(AnimationFlags.StackNextChildVertically)) - originalPosY += child.UiSize; - } - } - - public void Begin() - { - foreach (var child in Children) - child.Begin(); - - _anim = SequenceIndexStart >= 0 ? - SequenceIndexStart : - SequenceIndexLoop; - - _frame = 0; - if (_anim < 0) - { - _anim = SequenceIndexEnd; - _isRunning = false; - IsEnd = _anim < 0; - } - else - { - _isRunning = true; - IsEnd = false; - } - } - - public void End() - { - foreach (var child in Children) - child.End(); - - _isRunning = false; - if (SequenceIndexEnd >= 0) - { - _anim = SequenceIndexEnd; - IsEnd = false; - _frame = 0; - } - else - IsEnd = true; - } - - public void Skip() - { - foreach (var child in Children) - child.Skip(); - if (_isRunning) - { - if (_anim == SequenceIndexStart) - { - _anim = SequenceIndexLoop; - _frame = 0; - } - } - else - IsEnd = true; - } - - public void SetMessage(ushort id) => - SetMessage(_messageProvider.GetString(id)); - - public void SetMessage(string text) - { - var s = MsgSerializer.DeserializeText(text).ToList(); - _message = _messageEncode.Encode(s); - } - } - - private readonly ISpriteDrawing _drawing; - private readonly IMessageProvider _messageProvider; - private readonly IMessageRenderer _messageRenderer; - private readonly IMessageEncode _messageEncode; - private readonly Sequence _sequence; - private readonly ISpriteTexture _texture; - - public AnimatedSequenceFactory( - ISpriteDrawing drawing, - IMessageProvider messageProvider, - IMessageRenderer messageRenderer, - IMessageEncode messageEncode, - Sequence sequence, - ISpriteTexture texture) - { - _drawing = drawing; - _messageProvider = messageProvider; - _messageRenderer = messageRenderer; - _messageEncode = messageEncode; - _sequence = sequence; - _texture = texture; - } - - public IAnimatedSequence Create(IEnumerable descs) => - new RootAnimatedSequence - { - Children = descs.Select(x => Create(x) as AnimatedSequence).ToList() - }; - - public IAnimatedSequence Create(AnimatedSequenceDesc desc) - { - var animSeq = new AnimatedSequence( - _drawing, - _messageProvider, - _messageRenderer, - _messageEncode, - _sequence, - _texture, - desc.SequenceIndexLoop, - desc.SequenceIndexStart, - desc.SequenceIndexEnd) - { - PositionX = desc.X, - PositionY = desc.Y, - Flags = desc.Flags, - StackIndex = desc.StackIndex, - StackWidth = desc.StackWidth, - StackHeight = desc.StackHeight, - TextAnchor = desc.TextAnchor, - Children = desc.Children? - .Select(Create) - .Cast() - .ToList() ?? new List() - }; - if (!string.IsNullOrEmpty(desc.MessageText)) - animSeq.SetMessage(desc.MessageText); - else if (desc.MessageId > 0) - animSeq.SetMessage(desc.MessageId); - - return animSeq; - } - } - - static class AnimatedSequenceFactoryExtensions - { - public static IAnimatedSequence FromStaticIndex( - this AnimatedSequenceFactory factory, int animationIndex) => - factory.Create(new AnimatedSequenceDesc - { - SequenceIndexLoop = animationIndex - }); - - public static IAnimatedSequence FromAnimatedIndex( - this AnimatedSequenceFactory factory, int animationIndex) => - factory.Create(new AnimatedSequenceDesc - { - SequenceIndexStart = animationIndex, - SequenceIndexLoop = animationIndex + 1, - SequenceIndexEnd = animationIndex + 2, - }); - - public static IAnimatedSequence FromAnimatedIndex( - this AnimatedSequenceFactory factory, int start, int loop, int end) => - factory.Create(new AnimatedSequenceDesc - { - SequenceIndexStart = start, - SequenceIndexLoop = loop, - SequenceIndexEnd = end, - }); - } -} +using OpenKh.Engine; +using OpenKh.Engine.Renderers; +using OpenKh.Engine.Renders; +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Game +{ + internal enum AnimationFlagsDefinitions + { + TextTranslateX, + NoChildTranslationX, + ChildStackHorizontally, + StackNextChildHorizontally, + StackNextChildVertically, + TextIgnoreColor, + TextIgnoreScaling, + } + + [Flags] + public enum AnimationFlags + { + None, + TextTranslateX = 1 << AnimationFlagsDefinitions.TextTranslateX, + NoChildTranslationX = 1 << AnimationFlagsDefinitions.NoChildTranslationX, + ChildStackHorizontally = 1 << AnimationFlagsDefinitions.ChildStackHorizontally, + StackNextChildHorizontally = 1 << AnimationFlagsDefinitions.StackNextChildHorizontally, + StackNextChildVertically = 1 << AnimationFlagsDefinitions.StackNextChildVertically, + TextIgnoreColor = 1 << AnimationFlagsDefinitions.TextIgnoreColor, + TextIgnoreScaling = 1 << AnimationFlagsDefinitions.TextIgnoreScaling, + } + + public interface IAnimatedSequence + { + bool IsEnd { get; } + TextAnchor TextAnchor { get; set; } + int FrameIndex { get; set; } + + void Update(double deltaTime); + void Draw(float x, float y); + + void Begin(); + void Skip(); + void End(); + + void SetMessage(ushort id); + void SetMessage(string text); + } + + public class AnimatedSequenceDesc + { + public const int DefaultStacking = int.MinValue; + + public float X { get; set; } + public float Y { get; set; } + public AnimationFlags Flags { get; set; } + public TextAnchor TextAnchor { get; set; } + public ushort MessageId { get; set; } + public string MessageText { get; set; } + public int SequenceIndexLoop { get; set; } = -1; + public int SequenceIndexStart { get; set; } = -1; + public int SequenceIndexEnd { get; set; } = -1; + public int StackIndex { get; set; } + public int StackWidth { get; set; } + public int StackHeight { get; set; } + public List Children { get; set; } + } + + public class AnimatedSequenceFactory + { + private class RootAnimatedSequence : IAnimatedSequence + { + private int _frameIndex; + + public List Children { get; set; } + + public bool IsEnd => Children.All(x => x.IsEnd); + public TextAnchor TextAnchor { get; set; } + public int FrameIndex + { + get => _frameIndex; + set + { + _frameIndex = value; + foreach (var item in Children) + item.FrameIndex = value; + } + } + + public void Update(double deltaTime) + { + _frameIndex++; + foreach (var item in Children) + item.Update(deltaTime); + } + + public void Draw(float x, float y) + { + foreach (var item in Children) + { + item.Draw(x, y); + } + } + + public void Begin() + { + foreach (var item in Children) + item.Begin(); + } + + public void Skip() + { + foreach (var item in Children) + item.Skip(); + } + + public void End() + { + foreach (var item in Children) + item.End(); + } + + public void SetMessage(ushort id) + { + } + + public void SetMessage(string text) + { + } + } + + private class AnimatedSequence : IAnimatedSequence + { + private static ColorF DefaultColor = new ColorF(1f, 1f, 1f, 1f); + private readonly Sequence _sequence; + private readonly SequenceRenderer _renderer; + private readonly IMessageProvider _messageProvider; + private readonly IMessageRenderer _messageRenderer; + private readonly IMessageEncode _messageEncode; + private int _anim; + private int _frame; + private bool _isRunning; + private byte[] _message; + + public int SequenceIndexLoop { get; } + public int SequenceIndexStart { get; } + public int SequenceIndexEnd { get; } + public List Children { get; set; } + + public bool IsEnd { get; private set; } + + public float PositionX { get; set; } + public float PositionY { get; set; } + public int StackIndex { get; set; } + public int StackWidth { get; set; } + public int StackHeight { get; set; } + public TextAnchor TextAnchor { get; set; } + public AnimationFlags Flags { get; set; } + public int FrameIndex + { + get => _frame; + set + { + _frame = value; + foreach (var item in Children) + item.FrameIndex = value; + } + } + + public Sequence.AnimationGroup AnimGroup => + _sequence.AnimationGroups[_anim]; + + public float UiSize => AnimGroup.UiPadding; + + public AnimatedSequence( + ISpriteDrawing drawing, + IMessageProvider messageProvider, + IMessageRenderer messageRenderer, + IMessageEncode messageEncode, + Sequence sequence, + ISpriteTexture texture, + int loop, int start, int end) + { + _sequence = sequence; + _renderer = new SequenceRenderer( + sequence, drawing, texture); + _messageEncode = messageEncode; + _messageProvider = messageProvider; + _messageRenderer = messageRenderer; + SequenceIndexLoop = loop; + SequenceIndexStart = start; + SequenceIndexEnd = end; + } + + public void Update(double deltaTime) + { + if (!IsEnd) + _frame++; + + foreach (var child in Children) + child.Update(deltaTime); + } + + public void Draw(float x, float y) => + Draw(new SequenceRenderer.ChildContext + { + PositionX = x, + PositionY = y, + Color = DefaultColor + }); + + private void Draw(SequenceRenderer.ChildContext context) + { + if (_anim == -1) + return; + + var anotherPosX = (StackWidth != AnimatedSequenceDesc.DefaultStacking ? + StackWidth : AnimGroup.TextPositionX) * StackIndex; + var anotherPosY = (StackHeight != AnimatedSequenceDesc.DefaultStacking ? + StackHeight : AnimGroup.TextPositionX) * StackIndex; + + if (!_renderer.Draw( + _anim, + _frame, + PositionX + anotherPosX + context.PositionX, + PositionY + anotherPosY + context.PositionY, + context.Color.A)) + { + if (_isRunning) + { + _anim = SequenceIndexLoop; + _frame = 0; + } + else + IsEnd = true; + } + + var childContext = _renderer.CurrentChildContext; + + if (_message != null) + { + const float UiTextScale = 0.7f; + float textScale = context.TextScale == 0 || Flags.HasFlag(AnimationFlags.TextIgnoreScaling) ? + UiTextScale : (context.TextScale / 22f); + + var fakeTextDrawContext = new DrawContext + { + Scale = textScale, + IgnoreDraw = true, + }; + _messageRenderer.Draw(fakeTextDrawContext, _message); + var width = (float)fakeTextDrawContext.Width; + var height = (float)fakeTextDrawContext.Height; + + float xPos, yPos; + switch (TextAnchor) + { + default: + case TextAnchor.BottomLeft: + xPos = 0; + yPos = 0; + break; + case TextAnchor.BottomCenter: + xPos = -width / 2; + yPos = 0; + break; + case TextAnchor.BottomRight: + xPos = context.UiSize - width; + yPos = 0; + break; + case TextAnchor.Center: + xPos = -width / 2; + yPos = -height / 2; + break; + case TextAnchor.TopCenter: + xPos = -width / 2; + yPos = -height; + break; + case TextAnchor.TopLeft: + xPos = 0; + yPos = -height; + break; + } + + if (!Flags.HasFlag(AnimationFlags.TextTranslateX)) + xPos += childContext.TextPositionX; + + var textColor = childContext.Color; + if (Flags.HasFlag(AnimationFlags.TextIgnoreColor)) + textColor = new ColorF(1f, 1f, 1f, textColor.A); + + const float ShadowDistance = 1.5f; + const float ShadowOpacity = 0.75f; + _messageRenderer.Draw(new DrawContext + { + xStart = childContext.PositionX + xPos + ShadowDistance, + x = childContext.PositionX + xPos + ShadowDistance, + y = childContext.PositionY + childContext.TextPositionY + yPos + ShadowDistance, + Color = new ColorF(0, 0, 0, textColor.A * ShadowOpacity), + Scale = textScale, + WidthMultiplier = 1.0f, + }, _message); + + _messageRenderer.Draw(new DrawContext + { + xStart = childContext.PositionX + xPos, + x = childContext.PositionX + xPos, + y = childContext.PositionY + childContext.TextPositionY + yPos, + Color = textColor, + Scale = textScale, + WidthMultiplier = 1.0f, + }, _message); + } + + childContext.PositionX = Flags.HasFlag(AnimationFlags.NoChildTranslationX) ? + context.PositionX : childContext.PositionX; + + var originalPosY = childContext.PositionY; + for (var i = 0; i < Children.Count; i++) + { + var child = Children[i] as AnimatedSequence; + childContext.PositionY = originalPosY + childContext.UiPadding * child.StackIndex; + + child.Draw(childContext); + + if (Flags.HasFlag(AnimationFlags.ChildStackHorizontally)) + childContext.PositionX += childContext.UiSize; + + if (Flags.HasFlag(AnimationFlags.StackNextChildHorizontally)) + childContext.PositionX += child.UiSize; + if (Flags.HasFlag(AnimationFlags.StackNextChildVertically)) + originalPosY += child.UiSize; + } + } + + public void Begin() + { + foreach (var child in Children) + child.Begin(); + + _anim = SequenceIndexStart >= 0 ? + SequenceIndexStart : + SequenceIndexLoop; + + _frame = 0; + if (_anim < 0) + { + _anim = SequenceIndexEnd; + _isRunning = false; + IsEnd = _anim < 0; + } + else + { + _isRunning = true; + IsEnd = false; + } + } + + public void End() + { + foreach (var child in Children) + child.End(); + + _isRunning = false; + if (SequenceIndexEnd >= 0) + { + _anim = SequenceIndexEnd; + IsEnd = false; + _frame = 0; + } + else + IsEnd = true; + } + + public void Skip() + { + foreach (var child in Children) + child.Skip(); + if (_isRunning) + { + if (_anim == SequenceIndexStart) + { + _anim = SequenceIndexLoop; + _frame = 0; + } + } + else + IsEnd = true; + } + + public void SetMessage(ushort id) => + SetMessage(_messageProvider.GetString(id)); + + public void SetMessage(string text) + { + var s = MsgSerializer.DeserializeText(text).ToList(); + _message = _messageEncode.Encode(s); + } + } + + private readonly ISpriteDrawing _drawing; + private readonly IMessageProvider _messageProvider; + private readonly IMessageRenderer _messageRenderer; + private readonly IMessageEncode _messageEncode; + private readonly Sequence _sequence; + private readonly ISpriteTexture _texture; + + public AnimatedSequenceFactory( + ISpriteDrawing drawing, + IMessageProvider messageProvider, + IMessageRenderer messageRenderer, + IMessageEncode messageEncode, + Sequence sequence, + ISpriteTexture texture) + { + _drawing = drawing; + _messageProvider = messageProvider; + _messageRenderer = messageRenderer; + _messageEncode = messageEncode; + _sequence = sequence; + _texture = texture; + } + + public IAnimatedSequence Create(IEnumerable descs) => + new RootAnimatedSequence + { + Children = descs.Select(x => Create(x) as AnimatedSequence).ToList() + }; + + public IAnimatedSequence Create(AnimatedSequenceDesc desc) + { + var animSeq = new AnimatedSequence( + _drawing, + _messageProvider, + _messageRenderer, + _messageEncode, + _sequence, + _texture, + desc.SequenceIndexLoop, + desc.SequenceIndexStart, + desc.SequenceIndexEnd) + { + PositionX = desc.X, + PositionY = desc.Y, + Flags = desc.Flags, + StackIndex = desc.StackIndex, + StackWidth = desc.StackWidth, + StackHeight = desc.StackHeight, + TextAnchor = desc.TextAnchor, + Children = desc.Children? + .Select(Create) + .Cast() + .ToList() ?? new List() + }; + if (!string.IsNullOrEmpty(desc.MessageText)) + animSeq.SetMessage(desc.MessageText); + else if (desc.MessageId > 0) + animSeq.SetMessage(desc.MessageId); + + return animSeq; + } + } + + static class AnimatedSequenceFactoryExtensions + { + public static IAnimatedSequence FromStaticIndex( + this AnimatedSequenceFactory factory, int animationIndex) => + factory.Create(new AnimatedSequenceDesc + { + SequenceIndexLoop = animationIndex + }); + + public static IAnimatedSequence FromAnimatedIndex( + this AnimatedSequenceFactory factory, int animationIndex) => + factory.Create(new AnimatedSequenceDesc + { + SequenceIndexStart = animationIndex, + SequenceIndexLoop = animationIndex + 1, + SequenceIndexEnd = animationIndex + 2, + }); + + public static IAnimatedSequence FromAnimatedIndex( + this AnimatedSequenceFactory factory, int start, int loop, int end) => + factory.Create(new AnimatedSequenceDesc + { + SequenceIndexStart = start, + SequenceIndexLoop = loop, + SequenceIndexEnd = end, + }); + } +} diff --git a/OpenKh.Game/Config.cs b/OpenKh.Game/Config.cs index bee158cf7..aa5f74402 100644 --- a/OpenKh.Game/Config.cs +++ b/OpenKh.Game/Config.cs @@ -1,143 +1,143 @@ -using OpenKh.Common; -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; -using YamlDotNet.Serialization; - -namespace OpenKh.Game -{ - public static class Config - { - private class ActualConfig - { - public int resolutionWidth { get; set; } = 0; - public int resolutionHeight { get; set; } = 0; - public float resolutionBoost { get; set; } = 2.0f; - public bool isFullScreen { get; set; } = false; - public string dataPath { get; set; } = "./data"; - public string modPath { get; set; } = "./mod"; - public string savePath { get; set; } = "./save"; - public string lastSave { get; set; } = "BISLPM-66675FM-00"; - public int regionId { get; set; } = -1; - public bool enforceInternationalTextEncoding { get; set; } = false; - public string idxFilePath { get; set; } = "KH2.IDX"; - public string imgFilePath { get; set; } = "KH2.IMG"; - public bool debugMode { get; set; } = true; - public float gameSpeed { get; set; } = 1.0f; - - internal static ActualConfig Default() => new ActualConfig(); - - internal static ActualConfig ReadFromFile(string filePath) => - new DeserializerBuilder() - .Build() - .Deserialize(File.ReadAllText(filePath)); - - internal void WriteToFile(string filePath) - { - using var writer = new StreamWriter(filePath); - - new SerializerBuilder() - .Build() - .Serialize(writer, this); - } - } - - private const string ConfigFilePath = "./config.yml"; - private static readonly string ActualConfigFilePath = Path.GetFullPath("./config.yml"); - private static ActualConfig _config = ActualConfig.Default(); - private static CancellationTokenSource _tokenSource; - - public delegate void ConfigurationChange(); - public static event ConfigurationChange OnConfigurationChange; - - public static int ResolutionWidth { get => _config.resolutionWidth; set => _config.resolutionWidth = value; } - public static int ResolutionHeight { get => _config.resolutionHeight; set => _config.resolutionHeight = value; } - public static float ResolutionBoost { get => _config.resolutionBoost; set => _config.resolutionBoost = value; } - public static bool IsFullScreen { get => _config.isFullScreen; set => _config.isFullScreen = value; } - public static string DataPath { get => _config.dataPath; set => _config.dataPath = value; } - public static string ModPath { get => _config.modPath; set => _config.modPath = value; } - public static string SavePath { get => _config.savePath; set => _config.savePath = value; } - public static string LastSave { get => _config.lastSave; set => _config.lastSave = value; } - public static int RegionId { get => _config.regionId; set => _config.regionId = value; } - public static bool EnforceInternationalTextEncoding { get => _config.enforceInternationalTextEncoding; set => _config.enforceInternationalTextEncoding = value; } - public static string IdxFilePath { get => _config.idxFilePath; set => _config.idxFilePath = value; } - public static string ImgFilePath { get => _config.imgFilePath; set => _config.imgFilePath = value; } - public static bool DebugMode { get => _config.debugMode; set => _config.debugMode = value; } - public static float GameSpeed { get => _config.gameSpeed; set => _config.gameSpeed = value; } - - private static void InternalOpen() - { - if (!File.Exists(ConfigFilePath)) - { - Log.Info("Configuration file not found at {0}. Creating default configuraiton.", ActualConfigFilePath); - Save(); - } - else - { - Log.Info("Load configuration file from {0}", ActualConfigFilePath); - try - { - _config = ActualConfig.ReadFromFile(ActualConfigFilePath) ?? ActualConfig.Default(); - } - catch (Exception ex) - { - // Do not close the entire game for silly reasons - Log.Err(ex.Message); - } - } - } - - private static void InternalSave() - { - _config.WriteToFile(ActualConfigFilePath); - } - - public static void Open() - { - InternalOpen(); - InternalSave(); // expand the config with the new structure - } - - public static void Listen() - { - if (_tokenSource != null) - return; - - _tokenSource = new CancellationTokenSource(); - Task.Run(() => - { - using var fsWatcher = new FileSystemWatcher() - { - Path = Path.GetDirectoryName(ActualConfigFilePath), - Filter = Path.GetFileName(ActualConfigFilePath), - NotifyFilter = NotifyFilters.LastWrite, - EnableRaisingEvents = true, - }; - - fsWatcher.Changed += (object sender, FileSystemEventArgs e) => - { - Log.Info("Configuration file has changed"); - Thread.Sleep(50); - InternalOpen(); - OnConfigurationChange?.Invoke(); - }; - - while (!_tokenSource.Token.IsCancellationRequested) - Thread.Sleep(1000); - - }, _tokenSource.Token); - } - - public static void Save() - { - Log.Info("Save configuration file to {0}, ActualConfigFilePath"); - InternalSave(); - } - - public static void Close() - { - _tokenSource?.Dispose(); - } - } -} +using OpenKh.Common; +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using YamlDotNet.Serialization; + +namespace OpenKh.Game +{ + public static class Config + { + private class ActualConfig + { + public int resolutionWidth { get; set; } = 0; + public int resolutionHeight { get; set; } = 0; + public float resolutionBoost { get; set; } = 2.0f; + public bool isFullScreen { get; set; } = false; + public string dataPath { get; set; } = "./data"; + public string modPath { get; set; } = "./mod"; + public string savePath { get; set; } = "./save"; + public string lastSave { get; set; } = "BISLPM-66675FM-00"; + public int regionId { get; set; } = -1; + public bool enforceInternationalTextEncoding { get; set; } = false; + public string idxFilePath { get; set; } = "KH2.IDX"; + public string imgFilePath { get; set; } = "KH2.IMG"; + public bool debugMode { get; set; } = true; + public float gameSpeed { get; set; } = 1.0f; + + internal static ActualConfig Default() => new ActualConfig(); + + internal static ActualConfig ReadFromFile(string filePath) => + new DeserializerBuilder() + .Build() + .Deserialize(File.ReadAllText(filePath)); + + internal void WriteToFile(string filePath) + { + using var writer = new StreamWriter(filePath); + + new SerializerBuilder() + .Build() + .Serialize(writer, this); + } + } + + private const string ConfigFilePath = "./config.yml"; + private static readonly string ActualConfigFilePath = Path.GetFullPath("./config.yml"); + private static ActualConfig _config = ActualConfig.Default(); + private static CancellationTokenSource _tokenSource; + + public delegate void ConfigurationChange(); + public static event ConfigurationChange OnConfigurationChange; + + public static int ResolutionWidth { get => _config.resolutionWidth; set => _config.resolutionWidth = value; } + public static int ResolutionHeight { get => _config.resolutionHeight; set => _config.resolutionHeight = value; } + public static float ResolutionBoost { get => _config.resolutionBoost; set => _config.resolutionBoost = value; } + public static bool IsFullScreen { get => _config.isFullScreen; set => _config.isFullScreen = value; } + public static string DataPath { get => _config.dataPath; set => _config.dataPath = value; } + public static string ModPath { get => _config.modPath; set => _config.modPath = value; } + public static string SavePath { get => _config.savePath; set => _config.savePath = value; } + public static string LastSave { get => _config.lastSave; set => _config.lastSave = value; } + public static int RegionId { get => _config.regionId; set => _config.regionId = value; } + public static bool EnforceInternationalTextEncoding { get => _config.enforceInternationalTextEncoding; set => _config.enforceInternationalTextEncoding = value; } + public static string IdxFilePath { get => _config.idxFilePath; set => _config.idxFilePath = value; } + public static string ImgFilePath { get => _config.imgFilePath; set => _config.imgFilePath = value; } + public static bool DebugMode { get => _config.debugMode; set => _config.debugMode = value; } + public static float GameSpeed { get => _config.gameSpeed; set => _config.gameSpeed = value; } + + private static void InternalOpen() + { + if (!File.Exists(ConfigFilePath)) + { + Log.Info("Configuration file not found at {0}. Creating default configuraiton.", ActualConfigFilePath); + Save(); + } + else + { + Log.Info("Load configuration file from {0}", ActualConfigFilePath); + try + { + _config = ActualConfig.ReadFromFile(ActualConfigFilePath) ?? ActualConfig.Default(); + } + catch (Exception ex) + { + // Do not close the entire game for silly reasons + Log.Err(ex.Message); + } + } + } + + private static void InternalSave() + { + _config.WriteToFile(ActualConfigFilePath); + } + + public static void Open() + { + InternalOpen(); + InternalSave(); // expand the config with the new structure + } + + public static void Listen() + { + if (_tokenSource != null) + return; + + _tokenSource = new CancellationTokenSource(); + Task.Run(() => + { + using var fsWatcher = new FileSystemWatcher() + { + Path = Path.GetDirectoryName(ActualConfigFilePath), + Filter = Path.GetFileName(ActualConfigFilePath), + NotifyFilter = NotifyFilters.LastWrite, + EnableRaisingEvents = true, + }; + + fsWatcher.Changed += (object sender, FileSystemEventArgs e) => + { + Log.Info("Configuration file has changed"); + Thread.Sleep(50); + InternalOpen(); + OnConfigurationChange?.Invoke(); + }; + + while (!_tokenSource.Token.IsCancellationRequested) + Thread.Sleep(1000); + + }, _tokenSource.Token); + } + + public static void Save() + { + Log.Info("Save configuration file to {0}, ActualConfigFilePath"); + InternalSave(); + } + + public static void Close() + { + _tokenSource?.Dispose(); + } + } +} diff --git a/OpenKh.Game/DataContent/DummyDataContent.cs b/OpenKh.Game/DataContent/DummyDataContent.cs index dc628a89a..b763a5bb8 100644 --- a/OpenKh.Game/DataContent/DummyDataContent.cs +++ b/OpenKh.Game/DataContent/DummyDataContent.cs @@ -1,12 +1,12 @@ -using OpenKh.Game.Infrastructure; -using System.IO; - -namespace OpenKh.Game.DataContent -{ - public class DummyDataContent : IDataContent - { - public bool FileExists(string fileName) => false; - - public Stream FileOpen(string fileName) => null; - } -} +using OpenKh.Game.Infrastructure; +using System.IO; + +namespace OpenKh.Game.DataContent +{ + public class DummyDataContent : IDataContent + { + public bool FileExists(string fileName) => false; + + public Stream FileOpen(string fileName) => null; + } +} diff --git a/OpenKh.Game/DataContent/HdAssetContent.cs b/OpenKh.Game/DataContent/HdAssetContent.cs index 6f1ffe1e6..7b317cab0 100644 --- a/OpenKh.Game/DataContent/HdAssetContent.cs +++ b/OpenKh.Game/DataContent/HdAssetContent.cs @@ -1,27 +1,27 @@ -using OpenKh.Common.Archives; -using OpenKh.Game.Infrastructure; -using System.IO; - -namespace OpenKh.Game.DataContent -{ - public class HdAssetContent : IDataContent - { - private readonly IDataContent _innerDataContext; - - public HdAssetContent(IDataContent innerDataContext) - { - _innerDataContext = innerDataContext; - } - - public bool FileExists(string fileName) => _innerDataContext.FileExists(fileName); - - public Stream FileOpen(string fileName) - { - var stream = _innerDataContext.FileOpen(fileName); - if (stream == null) - return null; - - return HdAsset.Read(stream).Stream; - } - } -} +using OpenKh.Common.Archives; +using OpenKh.Game.Infrastructure; +using System.IO; + +namespace OpenKh.Game.DataContent +{ + public class HdAssetContent : IDataContent + { + private readonly IDataContent _innerDataContext; + + public HdAssetContent(IDataContent innerDataContext) + { + _innerDataContext = innerDataContext; + } + + public bool FileExists(string fileName) => _innerDataContext.FileExists(fileName); + + public Stream FileOpen(string fileName) + { + var stream = _innerDataContext.FileOpen(fileName); + if (stream == null) + return null; + + return HdAsset.Read(stream).Stream; + } + } +} diff --git a/OpenKh.Game/DataContent/IdxDataContent.cs b/OpenKh.Game/DataContent/IdxDataContent.cs index 5d628b08f..a2c69f813 100644 --- a/OpenKh.Game/DataContent/IdxDataContent.cs +++ b/OpenKh.Game/DataContent/IdxDataContent.cs @@ -1,25 +1,25 @@ -using System.IO; -using OpenKh.Common; -using OpenKh.Game.Infrastructure; -using OpenKh.Kh2; - -namespace OpenKh.Game.DataContent -{ - public class IdxDataContent : IDataContent - { - private readonly Img _img; - - public IdxDataContent(Stream idxStream, Stream imgStream) - { - _img = new Img(imgStream, Idx.Read(idxStream), false); - } - - public bool FileExists(string fileName) => _img.FileExists(fileName); - - public Stream FileOpen(string path) - { - Log.Info("Load IDX file {0}", path); - return _img.TryFileOpen(path, out var stream) ? stream : null; - } - } -} +using System.IO; +using OpenKh.Common; +using OpenKh.Game.Infrastructure; +using OpenKh.Kh2; + +namespace OpenKh.Game.DataContent +{ + public class IdxDataContent : IDataContent + { + private readonly Img _img; + + public IdxDataContent(Stream idxStream, Stream imgStream) + { + _img = new Img(imgStream, Idx.Read(idxStream), false); + } + + public bool FileExists(string fileName) => _img.FileExists(fileName); + + public Stream FileOpen(string path) + { + Log.Info("Load IDX file {0}", path); + return _img.TryFileOpen(path, out var stream) ? stream : null; + } + } +} diff --git a/OpenKh.Game/DataContent/IdxMultipleDataContent.cs b/OpenKh.Game/DataContent/IdxMultipleDataContent.cs index 9714d4c99..298029c6e 100644 --- a/OpenKh.Game/DataContent/IdxMultipleDataContent.cs +++ b/OpenKh.Game/DataContent/IdxMultipleDataContent.cs @@ -1,29 +1,29 @@ -using OpenKh.Common; -using OpenKh.Game.Infrastructure; -using OpenKh.Kh2; -using System.IO; -using System.Linq; - -namespace OpenKh.Game.DataContent -{ - public class IdxMultipleDataContent : IDataContent - { - private readonly MultipleDataContent _dataContent; - - public IdxMultipleDataContent(IDataContent baseDataContent, Stream imgStream) - { - var dataContents = Constants.WorldIds - .Select(worldId => $"000{worldId}.idx") - .Select(fileName => baseDataContent.FileOpen(fileName)) - .Where(stream => stream != null) - .Select(stream => stream.Using(s => new IdxDataContent(s, imgStream))) - .ToArray(); - - _dataContent = new MultipleDataContent(dataContents); - } - - public bool FileExists(string fileName) => _dataContent.FileExists(fileName); - - public Stream FileOpen(string path) => _dataContent.FileOpen(path); - } -} +using OpenKh.Common; +using OpenKh.Game.Infrastructure; +using OpenKh.Kh2; +using System.IO; +using System.Linq; + +namespace OpenKh.Game.DataContent +{ + public class IdxMultipleDataContent : IDataContent + { + private readonly MultipleDataContent _dataContent; + + public IdxMultipleDataContent(IDataContent baseDataContent, Stream imgStream) + { + var dataContents = Constants.WorldIds + .Select(worldId => $"000{worldId}.idx") + .Select(fileName => baseDataContent.FileOpen(fileName)) + .Where(stream => stream != null) + .Select(stream => stream.Using(s => new IdxDataContent(s, imgStream))) + .ToArray(); + + _dataContent = new MultipleDataContent(dataContents); + } + + public bool FileExists(string fileName) => _dataContent.FileExists(fileName); + + public Stream FileOpen(string path) => _dataContent.FileOpen(path); + } +} diff --git a/OpenKh.Game/DataContent/ModDataContent.cs b/OpenKh.Game/DataContent/ModDataContent.cs index 5871f435b..77079d5c2 100644 --- a/OpenKh.Game/DataContent/ModDataContent.cs +++ b/OpenKh.Game/DataContent/ModDataContent.cs @@ -1,32 +1,32 @@ -using OpenKh.Common; -using OpenKh.Game.Infrastructure; -using System.IO; - -namespace OpenKh.Game.DataContent -{ - public class ModDataContent : IDataContent - { - private readonly string _modPath; - - public ModDataContent(string modPath) - { - _modPath = modPath; - } - - public bool FileExists(string fileName) => File.Exists(GetPath(fileName)); - - public Stream FileOpen(string path) - { - var fileName = GetPath(path); - if (File.Exists(fileName)) - { - Log.Info("Load mod {0}", path); - return File.OpenRead(fileName); - } - - return null; - } - - private string GetPath(string path) => Path.Combine(_modPath, path); - } -} +using OpenKh.Common; +using OpenKh.Game.Infrastructure; +using System.IO; + +namespace OpenKh.Game.DataContent +{ + public class ModDataContent : IDataContent + { + private readonly string _modPath; + + public ModDataContent(string modPath) + { + _modPath = modPath; + } + + public bool FileExists(string fileName) => File.Exists(GetPath(fileName)); + + public Stream FileOpen(string path) + { + var fileName = GetPath(path); + if (File.Exists(fileName)) + { + Log.Info("Load mod {0}", path); + return File.OpenRead(fileName); + } + + return null; + } + + private string GetPath(string path) => Path.Combine(_modPath, path); + } +} diff --git a/OpenKh.Game/DataContent/MultipleDataContent.cs b/OpenKh.Game/DataContent/MultipleDataContent.cs index 4c48b37d7..1e7e3aed1 100644 --- a/OpenKh.Game/DataContent/MultipleDataContent.cs +++ b/OpenKh.Game/DataContent/MultipleDataContent.cs @@ -1,31 +1,31 @@ -using OpenKh.Game.Infrastructure; -using System.IO; -using System.Linq; - -namespace OpenKh.Game.DataContent -{ - public class MultipleDataContent : IDataContent - { - private readonly IDataContent[] _dataContents; - - public MultipleDataContent(params IDataContent[] dataContents) - { - _dataContents = dataContents; - } - - public bool FileExists(string fileName) => - _dataContents.Any(x => x.FileExists(fileName)); - - public Stream FileOpen(string path) - { - foreach (var dataContent in _dataContents) - { - var stream = dataContent.FileOpen(path); - if (stream != null) - return stream; - } - - return null; - } - } -} +using OpenKh.Game.Infrastructure; +using System.IO; +using System.Linq; + +namespace OpenKh.Game.DataContent +{ + public class MultipleDataContent : IDataContent + { + private readonly IDataContent[] _dataContents; + + public MultipleDataContent(params IDataContent[] dataContents) + { + _dataContents = dataContents; + } + + public bool FileExists(string fileName) => + _dataContents.Any(x => x.FileExists(fileName)); + + public Stream FileOpen(string path) + { + foreach (var dataContent in _dataContents) + { + var stream = dataContent.FileOpen(path); + if (stream != null) + return stream; + } + + return null; + } + } +} diff --git a/OpenKh.Game/DataContent/SafeDataContent.cs b/OpenKh.Game/DataContent/SafeDataContent.cs index 20e02759e..6bf5705e7 100644 --- a/OpenKh.Game/DataContent/SafeDataContent.cs +++ b/OpenKh.Game/DataContent/SafeDataContent.cs @@ -1,26 +1,26 @@ -using OpenKh.Game.Infrastructure; -using System.IO; - -namespace OpenKh.Game.DataContent -{ - public class SafeDataContent : IDataContent - { - private readonly IDataContent _innerDataContext; - - public SafeDataContent(IDataContent innerDataContext) - { - _innerDataContext = innerDataContext; - } - - public bool FileExists(string fileName) => _innerDataContext.FileExists(fileName); - - public Stream FileOpen(string fileName) - { - var stream = _innerDataContext.FileOpen(fileName); - if (stream == null) - throw new FileNotFoundException(fileName); - - return stream; - } - } -} +using OpenKh.Game.Infrastructure; +using System.IO; + +namespace OpenKh.Game.DataContent +{ + public class SafeDataContent : IDataContent + { + private readonly IDataContent _innerDataContext; + + public SafeDataContent(IDataContent innerDataContext) + { + _innerDataContext = innerDataContext; + } + + public bool FileExists(string fileName) => _innerDataContext.FileExists(fileName); + + public Stream FileOpen(string fileName) + { + var stream = _innerDataContext.FileOpen(fileName); + if (stream == null) + throw new FileNotFoundException(fileName); + + return stream; + } + } +} diff --git a/OpenKh.Game/DataContent/StandardDataContent.cs b/OpenKh.Game/DataContent/StandardDataContent.cs index 364597b3e..c9278c4cb 100644 --- a/OpenKh.Game/DataContent/StandardDataContent.cs +++ b/OpenKh.Game/DataContent/StandardDataContent.cs @@ -1,30 +1,30 @@ -using System.IO; -using OpenKh.Common; -using OpenKh.Game.Infrastructure; - -namespace OpenKh.Game.DataContent -{ - public class StandardDataContent : IDataContent - { - private readonly string _baseDirectory; - - public StandardDataContent(string baseDirectory) - { - _baseDirectory = baseDirectory; - } - - public bool FileExists(string fileName) => File.Exists(GetPath(fileName)); - - public Stream FileOpen(string path) - { - Log.Info("Load file {0}", path); - var fileName = GetPath(path); - if (File.Exists(fileName)) - return File.OpenRead(fileName); - - return null; - } - - private string GetPath(string path) => Path.Combine(_baseDirectory, path); - } -} +using System.IO; +using OpenKh.Common; +using OpenKh.Game.Infrastructure; + +namespace OpenKh.Game.DataContent +{ + public class StandardDataContent : IDataContent + { + private readonly string _baseDirectory; + + public StandardDataContent(string baseDirectory) + { + _baseDirectory = baseDirectory; + } + + public bool FileExists(string fileName) => File.Exists(GetPath(fileName)); + + public Stream FileOpen(string path) + { + Log.Info("Load file {0}", path); + var fileName = GetPath(path); + if (File.Exists(fileName)) + return File.OpenRead(fileName); + + return null; + } + + private string GetPath(string path) => Path.Combine(_baseDirectory, path); + } +} diff --git a/OpenKh.Game/Debugging/DebugDraw.cs b/OpenKh.Game/Debugging/DebugDraw.cs index 233e6468f..f229ca03d 100644 --- a/OpenKh.Game/Debugging/DebugDraw.cs +++ b/OpenKh.Game/Debugging/DebugDraw.cs @@ -1,46 +1,46 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Numerics; -using xna = Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace OpenKh.Game.Debugging -{ - class DebugDraw - { - public static void DrawLine(GraphicsDevice graphics, Vector3 start, Vector3 end, Vector3 color) - { - DrawLine(graphics, new xna.Vector3(start.X, start.Y, start.Z), new xna.Vector3(end.X, end.Y, end.Z), new xna.Color(color.X, color.Y, color.Z)); - } - - public static void DrawLine(GraphicsDevice graphics, Vector3 start, Vector3 end, xna.Color color) - { - DrawLine(graphics, new xna.Vector3(start.X, start.Y, start.Z), new xna.Vector3(end.X, end.Y, end.Z), color); - } - - public static void DrawLine(GraphicsDevice graphics, xna.Vector3 start, xna.Vector3 end, xna.Color color) - { - var prevState = graphics.DepthStencilState; - graphics.DepthStencilState = DepthStencilState.None; - graphics.DrawUserPrimitives( - PrimitiveType.LineList, - new VertexPositionColor[] - { - new VertexPositionColor - { - Position = start, - Color = color - }, - new VertexPositionColor - { - Position = end, - Color = color - } - }, - 0, 1 - ); - graphics.DepthStencilState = prevState; - } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.Numerics; +using xna = Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace OpenKh.Game.Debugging +{ + class DebugDraw + { + public static void DrawLine(GraphicsDevice graphics, Vector3 start, Vector3 end, Vector3 color) + { + DrawLine(graphics, new xna.Vector3(start.X, start.Y, start.Z), new xna.Vector3(end.X, end.Y, end.Z), new xna.Color(color.X, color.Y, color.Z)); + } + + public static void DrawLine(GraphicsDevice graphics, Vector3 start, Vector3 end, xna.Color color) + { + DrawLine(graphics, new xna.Vector3(start.X, start.Y, start.Z), new xna.Vector3(end.X, end.Y, end.Z), color); + } + + public static void DrawLine(GraphicsDevice graphics, xna.Vector3 start, xna.Vector3 end, xna.Color color) + { + var prevState = graphics.DepthStencilState; + graphics.DepthStencilState = DepthStencilState.None; + graphics.DrawUserPrimitives( + PrimitiveType.LineList, + new VertexPositionColor[] + { + new VertexPositionColor + { + Position = start, + Color = color + }, + new VertexPositionColor + { + Position = end, + Color = color + } + }, + 0, 1 + ); + graphics.DepthStencilState = prevState; + } + } +} diff --git a/OpenKh.Game/Debugging/DebugOverlay.cs b/OpenKh.Game/Debugging/DebugOverlay.cs index 122a7133f..cac48ee04 100644 --- a/OpenKh.Game/Debugging/DebugOverlay.cs +++ b/OpenKh.Game/Debugging/DebugOverlay.cs @@ -1,169 +1,169 @@ -using Microsoft.Xna.Framework; -using OpenKh.Engine.Extensions; -using OpenKh.Engine.Input; -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Renders; -using OpenKh.Game.Infrastructure; -using OpenKh.Game.States; -using OpenKh.Kh2.Messages; -using System; -using System.Collections.Generic; - -namespace OpenKh.Game.Debugging -{ - // Most of the stuff here is copied from OpenKh.Tools.Common\Controls\KingdomTextArea.cs - public class DebugOverlay : IState, IDebug - { - private IDataContent _dataContent; - private ArchiveManager _archiveManager; - private Kernel _kernel; - private IInput _input; - private GraphicsDeviceManager _graphics; - private KingdomShader _shader; - private readonly IStateChange _stateChange; - private bool _overrideExternalDebugFeatures = false; - - private ISpriteDrawing _drawing; - private IMessageEncoder _encoder; - private IMessageRenderer _messageRenderer; - private DrawContext _messageDrawContext; - - public DebugOverlay(IStateChange stateChange) - { - _stateChange = stateChange; - - } - - public Action OnUpdate { get; set; } - public Action OnDraw { get; set; } - public int State { set => _stateChange.State = value; } - - public void Initialize(StateInitDesc initDesc) - { - _dataContent = initDesc.DataContent; - _archiveManager = initDesc.ArchiveManager; - _kernel = initDesc.Kernel; - _input = initDesc.Input; - _graphics = initDesc.GraphicsDevice; - - _shader = new KingdomShader(initDesc.ContentManager); - - var viewport = initDesc.GraphicsDevice.GraphicsDevice.Viewport; - _drawing = new MonoSpriteDrawing(_graphics.GraphicsDevice, _shader); - _drawing.SetProjection( - viewport.Width, - viewport.Height, - Global.ResolutionWidth, - Global.ResolutionHeight, - 1.0f); - - var messageContext = _kernel.SystemMessageContext; - _encoder = messageContext.Encoder; - _messageRenderer = new Kh2MessageRenderer(_drawing, messageContext); - } - - public void Destroy() - { - _shader.Dispose(); - _drawing.Dispose(); - // TODO destroy textures created by Kh2MessageRenderer - } - - public void Update(DeltaTimes deltaTimes) - { - DebugUpdate(this); - if (!_overrideExternalDebugFeatures) - OnUpdate?.Invoke(this); - } - - public void Draw(DeltaTimes deltaTimes) - { - // Small hack to avoid weird stuff happening: - // basically SpriteBatch sets its own stuff in the GraphicsDevice, - // making 3D models to look weird. Here we are backing up the states - // before SpriteBatch reset them as its own will, to restore them later. - var blendState = _graphics.GraphicsDevice.BlendState; - - _messageDrawContext = new DrawContext - { - IgnoreDraw = false, - - x = 0, - y = 0, - xStart = 0, - Width = 0, - Height = 0, - WindowWidth = 512, - - Scale = 1, - WidthMultiplier = 1, - Color = new ColorF(1.0f, 1.0f, 1.0f, 1.0f) - }; - - DebugDraw(this); - if (!_overrideExternalDebugFeatures) - OnDraw?.Invoke(this); - _drawing.Flush(); - - // small hack: see first comment of the method - _graphics.GraphicsDevice.BlendState = blendState; - } - - public void Print(string text) - { - Print(_encoder.Encode(new List() - { - new MessageCommandModel() - { - Command = MessageCommand.PrintText, - Text = text - } - })); - } - - public void Print(ushort messageId) => - Print(_kernel.MessageProvider.GetMessage(messageId)); - - public void Println(string text) - { - if (_kernel.Language == Kh2.Constants.Regions[0]) - // Force to use uppercase to display text correctly with JP - text = text.ToUpper(); - - Print(text); - EmitNewLine(); - } - - public void Println(ushort messageId) - { - Print(messageId); - EmitNewLine(); - } - - private void Print(byte[] data) - { - _messageDrawContext.WidthMultiplier = 1.2f; - _messageRenderer.Draw(_messageDrawContext, data); - } - - private void EmitNewLine() - { - Print(_encoder.Encode(new List() - { - new MessageCommandModel() - { - Command = MessageCommand.PrintText, - Text = "\n" - } - })); - } - - public void DebugUpdate(IDebug debug) - { - } - - public void DebugDraw(IDebug debug) - { - } - } -} +using Microsoft.Xna.Framework; +using OpenKh.Engine.Extensions; +using OpenKh.Engine.Input; +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Renders; +using OpenKh.Game.Infrastructure; +using OpenKh.Game.States; +using OpenKh.Kh2.Messages; +using System; +using System.Collections.Generic; + +namespace OpenKh.Game.Debugging +{ + // Most of the stuff here is copied from OpenKh.Tools.Common\Controls\KingdomTextArea.cs + public class DebugOverlay : IState, IDebug + { + private IDataContent _dataContent; + private ArchiveManager _archiveManager; + private Kernel _kernel; + private IInput _input; + private GraphicsDeviceManager _graphics; + private KingdomShader _shader; + private readonly IStateChange _stateChange; + private bool _overrideExternalDebugFeatures = false; + + private ISpriteDrawing _drawing; + private IMessageEncoder _encoder; + private IMessageRenderer _messageRenderer; + private DrawContext _messageDrawContext; + + public DebugOverlay(IStateChange stateChange) + { + _stateChange = stateChange; + + } + + public Action OnUpdate { get; set; } + public Action OnDraw { get; set; } + public int State { set => _stateChange.State = value; } + + public void Initialize(StateInitDesc initDesc) + { + _dataContent = initDesc.DataContent; + _archiveManager = initDesc.ArchiveManager; + _kernel = initDesc.Kernel; + _input = initDesc.Input; + _graphics = initDesc.GraphicsDevice; + + _shader = new KingdomShader(initDesc.ContentManager); + + var viewport = initDesc.GraphicsDevice.GraphicsDevice.Viewport; + _drawing = new MonoSpriteDrawing(_graphics.GraphicsDevice, _shader); + _drawing.SetProjection( + viewport.Width, + viewport.Height, + Global.ResolutionWidth, + Global.ResolutionHeight, + 1.0f); + + var messageContext = _kernel.SystemMessageContext; + _encoder = messageContext.Encoder; + _messageRenderer = new Kh2MessageRenderer(_drawing, messageContext); + } + + public void Destroy() + { + _shader.Dispose(); + _drawing.Dispose(); + // TODO destroy textures created by Kh2MessageRenderer + } + + public void Update(DeltaTimes deltaTimes) + { + DebugUpdate(this); + if (!_overrideExternalDebugFeatures) + OnUpdate?.Invoke(this); + } + + public void Draw(DeltaTimes deltaTimes) + { + // Small hack to avoid weird stuff happening: + // basically SpriteBatch sets its own stuff in the GraphicsDevice, + // making 3D models to look weird. Here we are backing up the states + // before SpriteBatch reset them as its own will, to restore them later. + var blendState = _graphics.GraphicsDevice.BlendState; + + _messageDrawContext = new DrawContext + { + IgnoreDraw = false, + + x = 0, + y = 0, + xStart = 0, + Width = 0, + Height = 0, + WindowWidth = 512, + + Scale = 1, + WidthMultiplier = 1, + Color = new ColorF(1.0f, 1.0f, 1.0f, 1.0f) + }; + + DebugDraw(this); + if (!_overrideExternalDebugFeatures) + OnDraw?.Invoke(this); + _drawing.Flush(); + + // small hack: see first comment of the method + _graphics.GraphicsDevice.BlendState = blendState; + } + + public void Print(string text) + { + Print(_encoder.Encode(new List() + { + new MessageCommandModel() + { + Command = MessageCommand.PrintText, + Text = text + } + })); + } + + public void Print(ushort messageId) => + Print(_kernel.MessageProvider.GetMessage(messageId)); + + public void Println(string text) + { + if (_kernel.Language == Kh2.Constants.Regions[0]) + // Force to use uppercase to display text correctly with JP + text = text.ToUpper(); + + Print(text); + EmitNewLine(); + } + + public void Println(ushort messageId) + { + Print(messageId); + EmitNewLine(); + } + + private void Print(byte[] data) + { + _messageDrawContext.WidthMultiplier = 1.2f; + _messageRenderer.Draw(_messageDrawContext, data); + } + + private void EmitNewLine() + { + Print(_encoder.Encode(new List() + { + new MessageCommandModel() + { + Command = MessageCommand.PrintText, + Text = "\n" + } + })); + } + + public void DebugUpdate(IDebug debug) + { + } + + public void DebugDraw(IDebug debug) + { + } + } +} diff --git a/OpenKh.Game/Debugging/IDebug.cs b/OpenKh.Game/Debugging/IDebug.cs index 631b34bc3..7306d5c3f 100644 --- a/OpenKh.Game/Debugging/IDebug.cs +++ b/OpenKh.Game/Debugging/IDebug.cs @@ -1,12 +1,12 @@ -using OpenKh.Game.States; - -namespace OpenKh.Game.Debugging -{ - public interface IDebug : IStateChange - { - void Print(string text); - void Print(ushort messageId); - void Println(string text); - void Println(ushort messageId); - } -} +using OpenKh.Game.States; + +namespace OpenKh.Game.Debugging +{ + public interface IDebug : IStateChange + { + void Print(string text); + void Print(ushort messageId); + void Println(string text); + void Println(ushort messageId); + } +} diff --git a/OpenKh.Game/Debugging/IDebugConsumer.cs b/OpenKh.Game/Debugging/IDebugConsumer.cs index 0c3c46e4e..70fe11e8e 100644 --- a/OpenKh.Game/Debugging/IDebugConsumer.cs +++ b/OpenKh.Game/Debugging/IDebugConsumer.cs @@ -1,8 +1,8 @@ -namespace OpenKh.Game.Debugging -{ - public interface IDebugConsumer - { - public void DebugUpdate(IDebug debug); - public void DebugDraw(IDebug debug); - } -} +namespace OpenKh.Game.Debugging +{ + public interface IDebugConsumer + { + public void DebugUpdate(IDebug debug); + public void DebugDraw(IDebug debug); + } +} diff --git a/OpenKh.Game/Entities/BobEntity.cs b/OpenKh.Game/Entities/BobEntity.cs index 4d234ec0f..f328a661a 100644 --- a/OpenKh.Game/Entities/BobEntity.cs +++ b/OpenKh.Game/Entities/BobEntity.cs @@ -1,22 +1,22 @@ -using OpenKh.Engine; -using OpenKh.Kh2.Models; -using System.Numerics; - -namespace OpenKh.Game.Entities -{ - public class BobEntity : IEntity - { - public BobEntity(BobDescriptor bobDesc) - { - BobIndex = bobDesc.BobIndex; - Position = new Vector3(bobDesc.PositionX, -bobDesc.PositionY, -bobDesc.PositionZ); - Rotation = new Vector3(bobDesc.RotationX, bobDesc.RotationY, bobDesc.RotationZ); - Scaling = new Vector3(bobDesc.ScalingX, bobDesc.ScalingY, bobDesc.ScalingZ); - } - - public int BobIndex { get; set; } - public Vector3 Position { get; set; } - public Vector3 Rotation { get; set; } - public Vector3 Scaling { get; set; } - } -} +using OpenKh.Engine; +using OpenKh.Kh2.Models; +using System.Numerics; + +namespace OpenKh.Game.Entities +{ + public class BobEntity : IEntity + { + public BobEntity(BobDescriptor bobDesc) + { + BobIndex = bobDesc.BobIndex; + Position = new Vector3(bobDesc.PositionX, -bobDesc.PositionY, -bobDesc.PositionZ); + Rotation = new Vector3(bobDesc.RotationX, bobDesc.RotationY, bobDesc.RotationZ); + Scaling = new Vector3(bobDesc.ScalingX, bobDesc.ScalingY, bobDesc.ScalingZ); + } + + public int BobIndex { get; set; } + public Vector3 Position { get; set; } + public Vector3 Rotation { get; set; } + public Vector3 Scaling { get; set; } + } +} diff --git a/OpenKh.Game/Entities/ObjectEntity.cs b/OpenKh.Game/Entities/ObjectEntity.cs index 9020766df..c3e8aa8bf 100644 --- a/OpenKh.Game/Entities/ObjectEntity.cs +++ b/OpenKh.Game/Entities/ObjectEntity.cs @@ -1,189 +1,189 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Motion; -using OpenKh.Common; -using OpenKh.Game.Infrastructure; -using OpenKh.Bbs; -using OpenKh.Kh2; -using OpenKh.Kh2.Ard; -using OpenKh.Kh2.Extensions; -using System.IO; -using System.Linq; -using System.Collections.Generic; -using OpenKh.Engine.Parsers; -using OpenKh.Engine; -using System.Numerics; - -namespace OpenKh.Game.Entities -{ - public class ObjectEntity : IEntity, IMonoGameModel - { - private Mdlx _model; - public List ObjectCollisions { get; set; } - - public ObjectEntity(Kernel kernel, int objectId) - { - Kernel = kernel; - ObjectId = objectId; - Scaling = new Vector3(1, 1, 1); - } - - public Kernel Kernel { get; } - - public int ObjectId { get; } - - public string ObjectName => Kernel.ObjEntries - .FirstOrDefault(x => x.ObjectId == ObjectId)?.ModelName; - - public bool IsPlayer { get; set; } - - public bool IsMeshLoaded => Model != null; - - public IModelMotion Model { get; private set; } - - public Kh2MotionEngine Motion { get; set; } - - public List MeshDescriptors => Model?.MeshDescriptors; - - public IKingdomTexture[] Textures { get; private set; } - - public bool IsVisible { get; set; } = true; - - public Vector3 Position { get; set; } - - public Vector3 Rotation { get; set; } - - public Vector3 Scaling { get; set; } - - public float Time { get; set; } - - public float MotionTime { get; set; } - - public void LoadMesh(GraphicsDevice graphics) - { - var objEntry = Kernel.ObjEntries.FirstOrDefault(x => x.ObjectId == ObjectId); - if (objEntry == null) - { - Log.Warn("Object ID {0} not found.", ObjectId); - return; - } - - IsPlayer = objEntry.ObjectType == Objentry.Type.PLAYER; - - var modelName = $"obj/{objEntry.ModelName}.mdlx"; - using var stream = Kernel.DataContent.FileOpen(modelName); - var entries = Bar.Read(stream); - _model = entries.ForEntry(x => x.Type == Bar.EntryType.Model, Mdlx.Read); - Model = MeshLoader.FromKH2(_model); - - var texture = entries.ForEntry("tim_", Bar.EntryType.ModelTexture, ModelTexture.Read); - Textures = texture.LoadTextures(graphics).ToArray(); - - ObjectCollisions = entries.ForEntry(x => x.Type == Bar.EntryType.ModelCollision && x.Stream.Length > 0, - ObjectCollision.Read) ?? new List(); - - try - { - var msetName = $"obj/{objEntry.AnimationName}"; - if (Kernel.DataContent.FileExists(msetName)) - { - var msetEntries = Kernel.DataContent.FileOpen(msetName).Using(Bar.Read); - Motion = new Kh2MotionEngine(msetEntries) - { - CurrentAnimationIndex = 0 - }; - } - else - { - Motion = new Kh2MotionEngine(); - Log.Warn("MSET {0} does not exist", objEntry.AnimationName); - } - } - catch (System.NotImplementedException) - { - Motion = null; - } - } - - public void Update(float deltaTime) - { - Time += deltaTime; - MotionTime += deltaTime; - Motion?.ApplyMotion(Model, MotionTime); - } - - public void SetMotion(Motion motion) - { - MotionTime = 0; - Motion?.UseCustomMotion(motion); - } - - public static MeshGroup FromFbx(GraphicsDevice graphics, string filePath) - { - const float Scale = 96.0f; - var assimp = new Assimp.AssimpContext(); - var scene = assimp.ImportFile(filePath, Assimp.PostProcessSteps.PreTransformVertices); - var baseFilePath = Path.GetDirectoryName(filePath); - - return new MeshGroup() - { - MeshDescriptors = scene.Meshes - .Select(x => - { - var vertices = new PositionColoredTextured[x.Vertices.Count]; - for (var i = 0; i < vertices.Length; i++) - { - vertices[i].X = x.Vertices[i].X * Scale; - vertices[i].Y = x.Vertices[i].Y * Scale; - vertices[i].Z = x.Vertices[i].Z * Scale; - vertices[i].Tu = x.TextureCoordinateChannels[0][i].X; - vertices[i].Tv = 1.0f - x.TextureCoordinateChannels[0][i].Y; - vertices[i].R = 1.0f; - vertices[i].G = 1.0f; - vertices[i].B = 1.0f; - vertices[i].A = 1.0f; - } - - return new MeshDescriptor - { - Vertices = vertices, - Indices = x.Faces.SelectMany(f => f.Indices).ToArray(), - IsOpaque = true, - TextureIndex = x.MaterialIndex - }; - }).ToList(), - Textures = scene.Materials.Select(x => - { - var path = Path.Join(baseFilePath, $"{x.Name}.png"); - return new PngKingdomTexture(path, graphics); - }).ToArray(), - }; - } - - public static (IModelMotion, IKingdomTexture[]) BBSMeshLoader(GraphicsDevice graphics, string FilePath, IModelMotion Model, IKingdomTexture[] Textures) - { - const float Scale = 100.0f; - var file = File.OpenRead(FilePath); - Pmo pmo = Pmo.Read(file); - Model = new PmoParser(pmo, Scale); - - List BbsTextures = new List(); - Textures = new IKingdomTexture[pmo.header.TextureCount]; - - for (int i = 0; i < pmo.header.TextureCount; i++) - { - BbsTextures.Add(new Tim2KingdomTexture(pmo.texturesData[i], graphics)); - Textures[i] = BbsTextures[i]; - } - - return (Model, Textures); - } - - public static ObjectEntity FromSpawnPoint(Kernel kernel, SpawnPoint.Entity spawnPoint) => - new ObjectEntity(kernel, kernel.GetRealObjectId(spawnPoint.ObjectId)) - { - Position = new Vector3(spawnPoint.PositionX, -spawnPoint.PositionY, -spawnPoint.PositionZ), - Rotation = new Vector3(spawnPoint.RotationX, spawnPoint.RotationY, spawnPoint.RotationZ), - }; - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Motion; +using OpenKh.Common; +using OpenKh.Game.Infrastructure; +using OpenKh.Bbs; +using OpenKh.Kh2; +using OpenKh.Kh2.Ard; +using OpenKh.Kh2.Extensions; +using System.IO; +using System.Linq; +using System.Collections.Generic; +using OpenKh.Engine.Parsers; +using OpenKh.Engine; +using System.Numerics; + +namespace OpenKh.Game.Entities +{ + public class ObjectEntity : IEntity, IMonoGameModel + { + private Mdlx _model; + public List ObjectCollisions { get; set; } + + public ObjectEntity(Kernel kernel, int objectId) + { + Kernel = kernel; + ObjectId = objectId; + Scaling = new Vector3(1, 1, 1); + } + + public Kernel Kernel { get; } + + public int ObjectId { get; } + + public string ObjectName => Kernel.ObjEntries + .FirstOrDefault(x => x.ObjectId == ObjectId)?.ModelName; + + public bool IsPlayer { get; set; } + + public bool IsMeshLoaded => Model != null; + + public IModelMotion Model { get; private set; } + + public Kh2MotionEngine Motion { get; set; } + + public List MeshDescriptors => Model?.MeshDescriptors; + + public IKingdomTexture[] Textures { get; private set; } + + public bool IsVisible { get; set; } = true; + + public Vector3 Position { get; set; } + + public Vector3 Rotation { get; set; } + + public Vector3 Scaling { get; set; } + + public float Time { get; set; } + + public float MotionTime { get; set; } + + public void LoadMesh(GraphicsDevice graphics) + { + var objEntry = Kernel.ObjEntries.FirstOrDefault(x => x.ObjectId == ObjectId); + if (objEntry == null) + { + Log.Warn("Object ID {0} not found.", ObjectId); + return; + } + + IsPlayer = objEntry.ObjectType == Objentry.Type.PLAYER; + + var modelName = $"obj/{objEntry.ModelName}.mdlx"; + using var stream = Kernel.DataContent.FileOpen(modelName); + var entries = Bar.Read(stream); + _model = entries.ForEntry(x => x.Type == Bar.EntryType.Model, Mdlx.Read); + Model = MeshLoader.FromKH2(_model); + + var texture = entries.ForEntry("tim_", Bar.EntryType.ModelTexture, ModelTexture.Read); + Textures = texture.LoadTextures(graphics).ToArray(); + + ObjectCollisions = entries.ForEntry(x => x.Type == Bar.EntryType.ModelCollision && x.Stream.Length > 0, + ObjectCollision.Read) ?? new List(); + + try + { + var msetName = $"obj/{objEntry.AnimationName}"; + if (Kernel.DataContent.FileExists(msetName)) + { + var msetEntries = Kernel.DataContent.FileOpen(msetName).Using(Bar.Read); + Motion = new Kh2MotionEngine(msetEntries) + { + CurrentAnimationIndex = 0 + }; + } + else + { + Motion = new Kh2MotionEngine(); + Log.Warn("MSET {0} does not exist", objEntry.AnimationName); + } + } + catch (System.NotImplementedException) + { + Motion = null; + } + } + + public void Update(float deltaTime) + { + Time += deltaTime; + MotionTime += deltaTime; + Motion?.ApplyMotion(Model, MotionTime); + } + + public void SetMotion(Motion motion) + { + MotionTime = 0; + Motion?.UseCustomMotion(motion); + } + + public static MeshGroup FromFbx(GraphicsDevice graphics, string filePath) + { + const float Scale = 96.0f; + var assimp = new Assimp.AssimpContext(); + var scene = assimp.ImportFile(filePath, Assimp.PostProcessSteps.PreTransformVertices); + var baseFilePath = Path.GetDirectoryName(filePath); + + return new MeshGroup() + { + MeshDescriptors = scene.Meshes + .Select(x => + { + var vertices = new PositionColoredTextured[x.Vertices.Count]; + for (var i = 0; i < vertices.Length; i++) + { + vertices[i].X = x.Vertices[i].X * Scale; + vertices[i].Y = x.Vertices[i].Y * Scale; + vertices[i].Z = x.Vertices[i].Z * Scale; + vertices[i].Tu = x.TextureCoordinateChannels[0][i].X; + vertices[i].Tv = 1.0f - x.TextureCoordinateChannels[0][i].Y; + vertices[i].R = 1.0f; + vertices[i].G = 1.0f; + vertices[i].B = 1.0f; + vertices[i].A = 1.0f; + } + + return new MeshDescriptor + { + Vertices = vertices, + Indices = x.Faces.SelectMany(f => f.Indices).ToArray(), + IsOpaque = true, + TextureIndex = x.MaterialIndex + }; + }).ToList(), + Textures = scene.Materials.Select(x => + { + var path = Path.Join(baseFilePath, $"{x.Name}.png"); + return new PngKingdomTexture(path, graphics); + }).ToArray(), + }; + } + + public static (IModelMotion, IKingdomTexture[]) BBSMeshLoader(GraphicsDevice graphics, string FilePath, IModelMotion Model, IKingdomTexture[] Textures) + { + const float Scale = 100.0f; + var file = File.OpenRead(FilePath); + Pmo pmo = Pmo.Read(file); + Model = new PmoParser(pmo, Scale); + + List BbsTextures = new List(); + Textures = new IKingdomTexture[pmo.header.TextureCount]; + + for (int i = 0; i < pmo.header.TextureCount; i++) + { + BbsTextures.Add(new Tim2KingdomTexture(pmo.texturesData[i], graphics)); + Textures[i] = BbsTextures[i]; + } + + return (Model, Textures); + } + + public static ObjectEntity FromSpawnPoint(Kernel kernel, SpawnPoint.Entity spawnPoint) => + new ObjectEntity(kernel, kernel.GetRealObjectId(spawnPoint.ObjectId)) + { + Position = new Vector3(spawnPoint.PositionX, -spawnPoint.PositionY, -spawnPoint.PositionZ), + Rotation = new Vector3(spawnPoint.RotationX, spawnPoint.RotationY, spawnPoint.RotationZ), + }; + } +} diff --git a/OpenKh.Game/Entities/PlayerManager.cs b/OpenKh.Game/Entities/PlayerManager.cs index 023502ecb..7eeeff40d 100644 --- a/OpenKh.Game/Entities/PlayerManager.cs +++ b/OpenKh.Game/Entities/PlayerManager.cs @@ -1,35 +1,35 @@ -using OpenKh.Engine.Input; -using OpenKh.Game.Infrastructure; -using OpenKh.Kh2; -using System; -using System.Numerics; - -namespace OpenKh.Game.Entities -{ - public class PlayerManager - { - public static void ProcessPlayer(IInput input, ObjectEntity entity, float rotation, double deltaTime) - { - const float Speed = 500f; - var move = new Vector3(input.AxisLeft.X, 0, -input.AxisLeft.Y); - - if (move != Vector3.Zero) - { - var finalMove = Vector3.Transform(move * Speed, Matrix4x4.CreateRotationY(-rotation + (float)Math.PI)); - var angle = Math.Atan2(finalMove.X, finalMove.Z); - entity.Position += new Vector3((float)(finalMove.X * deltaTime), 0, (float)(finalMove.Z * deltaTime)); - entity.Rotation = new Vector3(0, (float)angle, 0); - - var actualSpeed = move.Length(); - if (actualSpeed < 0.5) - entity.Motion.CurrentAnimationIndex = (int)MotionSet.MotionName.WALK; - else - entity.Motion.CurrentAnimationIndex = (int)MotionSet.MotionName.RUN; - } - else - { - entity.Motion.CurrentAnimationIndex = (int)MotionSet.MotionName.IDLE; - } - } - } -} +using OpenKh.Engine.Input; +using OpenKh.Game.Infrastructure; +using OpenKh.Kh2; +using System; +using System.Numerics; + +namespace OpenKh.Game.Entities +{ + public class PlayerManager + { + public static void ProcessPlayer(IInput input, ObjectEntity entity, float rotation, double deltaTime) + { + const float Speed = 500f; + var move = new Vector3(input.AxisLeft.X, 0, -input.AxisLeft.Y); + + if (move != Vector3.Zero) + { + var finalMove = Vector3.Transform(move * Speed, Matrix4x4.CreateRotationY(-rotation + (float)Math.PI)); + var angle = Math.Atan2(finalMove.X, finalMove.Z); + entity.Position += new Vector3((float)(finalMove.X * deltaTime), 0, (float)(finalMove.Z * deltaTime)); + entity.Rotation = new Vector3(0, (float)angle, 0); + + var actualSpeed = move.Length(); + if (actualSpeed < 0.5) + entity.Motion.CurrentAnimationIndex = (int)MotionSet.MotionName.WALK; + else + entity.Motion.CurrentAnimationIndex = (int)MotionSet.MotionName.RUN; + } + else + { + entity.Motion.CurrentAnimationIndex = (int)MotionSet.MotionName.IDLE; + } + } + } +} diff --git a/OpenKh.Game/Entities/PmpEntity.cs b/OpenKh.Game/Entities/PmpEntity.cs index 3ebd6598e..d2a5d45a7 100644 --- a/OpenKh.Game/Entities/PmpEntity.cs +++ b/OpenKh.Game/Entities/PmpEntity.cs @@ -1,26 +1,26 @@ -using OpenKh.Bbs; -using System.IO; -using System.Collections.Generic; -using OpenKh.Engine; -using System.Numerics; -using System; - -namespace OpenKh.Game.Entities -{ - public class PmpEntity : IEntity - { - public PmpEntity(int pmoIndex, Vector3 pmoPosition, Vector3 pmoRotation, Vector3 pmoScale) - { - Index = pmoIndex; - Position = pmoPosition * 100.0f; - Rotation = pmoRotation; - Scaling = pmoScale; - } - - public int Index { get; set; } - public Vector3 Position { get; set; } - public Vector3 Rotation { get; set; } - public Vector3 Scaling { get; set; } - public bool DifferentMatrix { get; set; } - } -} +using OpenKh.Bbs; +using System.IO; +using System.Collections.Generic; +using OpenKh.Engine; +using System.Numerics; +using System; + +namespace OpenKh.Game.Entities +{ + public class PmpEntity : IEntity + { + public PmpEntity(int pmoIndex, Vector3 pmoPosition, Vector3 pmoRotation, Vector3 pmoScale) + { + Index = pmoIndex; + Position = pmoPosition * 100.0f; + Rotation = pmoRotation; + Scaling = pmoScale; + } + + public int Index { get; set; } + public Vector3 Position { get; set; } + public Vector3 Rotation { get; set; } + public Vector3 Scaling { get; set; } + public bool DifferentMatrix { get; set; } + } +} diff --git a/OpenKh.Game/Events/EventPlayer.cs b/OpenKh.Game/Events/EventPlayer.cs index 49ffc9bef..0ba68ef92 100644 --- a/OpenKh.Game/Events/EventPlayer.cs +++ b/OpenKh.Game/Events/EventPlayer.cs @@ -1,303 +1,303 @@ -using OpenKh.Engine; -using OpenKh.Game.Field; -using OpenKh.Game.Infrastructure; -using System.Collections.Generic; -using System.Numerics; -using System.Text; -using static OpenKh.Kh2.Ard.Event; - -namespace OpenKh.Game.Events -{ - public class EventPlayer - { - private const int FramesPerSecond = 30; - private const float TimeMul = 1.0f / FramesPerSecond; - private readonly IField _field; - private readonly IList _eventEntries; - private readonly IList _cameras = new List(); - private readonly Dictionary _actors = new Dictionary(); - - private double _secondsPrev; - private double _seconds; - private int _cameraId; - private int _eventDuration; - - public bool IsEnd { get; private set; } - - public EventPlayer(IField field, IList eventEntries) - { - _field = field; - _eventEntries = eventEntries; - } - - public void Initialize() - { - IsEnd = false; - foreach (var entry in _eventEntries) - { - switch (entry) - { - case SetEndFrame item: - _eventDuration = item.EndFrame; - break; - case ReadAssets assets: - foreach (var assetEntry in assets.Set) - { - switch (assetEntry) - { - case ReadActor item: - _actors[item.ActorId] = item.Name; - _field.AddActor(item.ActorId, item.ObjectId); - _field.SetActorVisibility(item.ActorId, false); - break; - } - } - - // Double for-loop to ensure to load actors first, then - // animations to prevent crashes. - foreach (var assetEntry in assets.Set) - { - switch (assetEntry) - { - case ReadMotion item: - _field.SetActorAnimation( - item.ActorId, - GetAnmPath(item.ActorId, item.Name)); - _field.SetActorVisibility(item.ActorId, item.UnknownIndex == 0); - break; - } - } - break; - case EventStart item: - _field.FadeFromBlack(item.FadeIn * TimeMul); - break; - case SetCameraData item: - _cameras.Add(item); - break; - } - } - - _cameraId = 0; - } - - public void Update(double deltaTime) - { - _seconds += deltaTime; - - var nFrame = (int)(_seconds * FramesPerSecond); - var nPrevFrame = (int)(_secondsPrev * FramesPerSecond); - var cameraFrameTime = _seconds; - - if (nFrame >= _eventDuration) - { - IsEnd = true; - return; - } - - foreach (var entry in _eventEntries) - { - switch (entry) - { - case SeqActorPosition item: - if (item.Frame > nPrevFrame && item.Frame <= nFrame) - { - _field.SetActorPosition( - item.ActorId, - item.PositionX, - item.PositionY, - -item.PositionZ, - item.RotationY); - } - break; - case SeqPlayAnimation item: - if (item.FrameStart > nPrevFrame && item.FrameStart <= nFrame) - { - _field.SetActorAnimation( - item.ActorId, GetAnmPath(item.ActorId, item.Path)); - _field.SetActorVisibility(item.ActorId, true); - } - break; - case SeqActorLeave item: - if (item.Frame > nPrevFrame && item.Frame <= nFrame) - _field.SetActorVisibility(item.ActorId, false); - break; - case SeqCamera item: - if (nFrame >= item.FrameStart && nFrame < item.FrameEnd) - { - _cameraId = item.CameraId; - var frameLength = item.FrameEnd - item.FrameStart; - cameraFrameTime = (_seconds * FramesPerSecond - item.FrameStart) / 30f; - } - break; - case SeqFade item: - if (item.FrameIndex > nPrevFrame && item.FrameIndex <= nFrame) - { - switch (item.Type) - { - case SeqFade.FadeType.FromBlack: - case SeqFade.FadeType.FromBlackVariant: - _field.FadeFromBlack(item.Duration * TimeMul); - break; - case SeqFade.FadeType.FromWhite: - case SeqFade.FadeType.FromWhiteVariant: - _field.FadeFromWhite(item.Duration * TimeMul); - break; - case SeqFade.FadeType.ToBlack: - case SeqFade.FadeType.ToBlackVariant: - _field.FadeToBlack(item.Duration * TimeMul); - break; - case SeqFade.FadeType.ToWhite: - case SeqFade.FadeType.ToWhiteVariant: - _field.FadeToWhite(item.Duration * TimeMul); - break; - } - } - break; - case SeqSubtitle item: - if (nFrame >= item.FrameStart && nPrevFrame < item.FrameStart) - { - if (item.HideFlag == 0) - _field.ShowSubtitle(item.Index, (ushort)item.MessageId); - else if (item.HideFlag != 0) - _field.HideSubtitle(item.Index); - } - break; - } - } - - if (_cameraId < _cameras.Count) - { - var curCamera = _cameras[_cameraId]; - _field.SetCamera( - new Vector3( - (float)GetCameraValue(cameraFrameTime, curCamera.PositionX, null), - (float)GetCameraValue(cameraFrameTime, curCamera.PositionY, null), - (float)GetCameraValue(cameraFrameTime, curCamera.PositionZ, null)), - new Vector3( - (float)GetCameraValue(cameraFrameTime, curCamera.LookAtX, null), - (float)GetCameraValue(cameraFrameTime, curCamera.LookAtY, null), - (float)GetCameraValue(cameraFrameTime, curCamera.LookAtZ, null)), - (float)GetCameraValue(cameraFrameTime, curCamera.FieldOfView, null), - (float)GetCameraValue(cameraFrameTime, curCamera.Roll, null)); - } - - _secondsPrev = _seconds; - } - - private string GetAnmPath(int actorId, string name) - { - var sb = new StringBuilder(); - var split = name.Split("anm_")[1].Split("/"); - - sb.Append(split[0]); - sb.Append("/"); - sb.Append(_actors[actorId]); - sb.Append("/"); - sb.Append(split[1]); - return sb.ToString(); - } - - private static double GetCameraValue( - double time, - IList keyFrames, - SetCameraData.CameraKeys prevKey) - { - if (keyFrames.Count == 0) - return 0.0; - - if (keyFrames.Count == 1) - return keyFrames[0].Value; - - const int First = 0; - var Last = keyFrames.Count - 1; - - var m = time + 1.0 / 60.0; - var currentFrameIndex = (int)(m * 512.0); - if (currentFrameIndex > keyFrames[First].KeyFrame - 0x10000000) - { - if (currentFrameIndex < keyFrames[Last].KeyFrame) - { - // Do a binary search through all the key frames - var left = First; - var right = Last; - if (right <= 1) - return InterpolateCamera(right - 1, m, keyFrames, prevKey); - - while (true) - { - var mid = (left + right) / 2; - if (currentFrameIndex >= keyFrames[mid].KeyFrame) - { - if (currentFrameIndex <= keyFrames[mid].KeyFrame) - return keyFrames[mid].Value; - left = mid; - } - else - right = mid; - - if (right - left <= 1) - return InterpolateCamera(right - 1, m, keyFrames, prevKey); - } - } - - double tangent; - var keyFrameDistance = keyFrames[Last].KeyFrame - keyFrames[Last - 1].KeyFrame; - if (keyFrames[Last].Interpolation != Kh2.Motion.Interpolation.Linear || keyFrameDistance == 0) - tangent = keyFrames[Last].TangentEaseOut; - else - tangent = (keyFrames[Last].Value - keyFrames[Last - 1].Value) / keyFrameDistance; - return ((currentFrameIndex - (keyFrames[Last].KeyFrame + 0x10000000) + 0x10000000) * tangent) + keyFrames[Last].Value; - } - else - { - double tangent; - var keyFrameDistance = keyFrames[First + 1].KeyFrame - keyFrames[First].KeyFrame; - if (keyFrames[First].Interpolation != Kh2.Motion.Interpolation.Linear || keyFrameDistance == 0) - tangent = keyFrames[First].TangentEaseIn; - else - tangent = (keyFrames[First + 1].Value - keyFrames[First].Value) / keyFrameDistance; - return -(((keyFrames[First].KeyFrame - currentFrameIndex - 0x10000000) * tangent) - keyFrames[First].Value); - } - } - - private static double InterpolateCamera( - int keyFrameIndex, - double time, - IList keyFrames, - SetCameraData.CameraKeys prevKey) - { - const double N = 1.0 / 512.0; - var curKeyFrame = keyFrames[keyFrameIndex]; - var nextKeyFrame = keyFrames[keyFrameIndex + 1]; - if (prevKey != null) - prevKey.TangentEaseOut = curKeyFrame.TangentEaseOut; - - var t = time - curKeyFrame.KeyFrame * N; - var tx = (nextKeyFrame.KeyFrame - curKeyFrame.KeyFrame) * N; - switch (curKeyFrame.Interpolation) - { - case Kh2.Motion.Interpolation.Nearest: - return curKeyFrame.Value; - case Kh2.Motion.Interpolation.Linear: - return curKeyFrame.Value + ((nextKeyFrame.Value - curKeyFrame.Value) * t / tx); - case Kh2.Motion.Interpolation.Hermite: - case (Kh2.Motion.Interpolation)3: - case (Kh2.Motion.Interpolation)4: - var itx = 1.0 / tx; - // Perform a cubic hermite interpolation - var p0 = curKeyFrame.Value; - var p1 = nextKeyFrame.Value; - var m0 = curKeyFrame.TangentEaseOut; - var m1 = nextKeyFrame.TangentEaseIn; - var t2 = t * t * itx; - var t3 = t * t * t * itx * itx; - return p0 * (2 * t3 * itx - 3 * t2 * itx + 1) + - m0 * (t3 - 2 * t2 + t) + - p1 * (-2 * t3 * itx + 3 * t2 * itx) + - m1 * (t3 - t2); - default: - return 0; - } - } - } -} +using OpenKh.Engine; +using OpenKh.Game.Field; +using OpenKh.Game.Infrastructure; +using System.Collections.Generic; +using System.Numerics; +using System.Text; +using static OpenKh.Kh2.Ard.Event; + +namespace OpenKh.Game.Events +{ + public class EventPlayer + { + private const int FramesPerSecond = 30; + private const float TimeMul = 1.0f / FramesPerSecond; + private readonly IField _field; + private readonly IList _eventEntries; + private readonly IList _cameras = new List(); + private readonly Dictionary _actors = new Dictionary(); + + private double _secondsPrev; + private double _seconds; + private int _cameraId; + private int _eventDuration; + + public bool IsEnd { get; private set; } + + public EventPlayer(IField field, IList eventEntries) + { + _field = field; + _eventEntries = eventEntries; + } + + public void Initialize() + { + IsEnd = false; + foreach (var entry in _eventEntries) + { + switch (entry) + { + case SetEndFrame item: + _eventDuration = item.EndFrame; + break; + case ReadAssets assets: + foreach (var assetEntry in assets.Set) + { + switch (assetEntry) + { + case ReadActor item: + _actors[item.ActorId] = item.Name; + _field.AddActor(item.ActorId, item.ObjectId); + _field.SetActorVisibility(item.ActorId, false); + break; + } + } + + // Double for-loop to ensure to load actors first, then + // animations to prevent crashes. + foreach (var assetEntry in assets.Set) + { + switch (assetEntry) + { + case ReadMotion item: + _field.SetActorAnimation( + item.ActorId, + GetAnmPath(item.ActorId, item.Name)); + _field.SetActorVisibility(item.ActorId, item.UnknownIndex == 0); + break; + } + } + break; + case EventStart item: + _field.FadeFromBlack(item.FadeIn * TimeMul); + break; + case SetCameraData item: + _cameras.Add(item); + break; + } + } + + _cameraId = 0; + } + + public void Update(double deltaTime) + { + _seconds += deltaTime; + + var nFrame = (int)(_seconds * FramesPerSecond); + var nPrevFrame = (int)(_secondsPrev * FramesPerSecond); + var cameraFrameTime = _seconds; + + if (nFrame >= _eventDuration) + { + IsEnd = true; + return; + } + + foreach (var entry in _eventEntries) + { + switch (entry) + { + case SeqActorPosition item: + if (item.Frame > nPrevFrame && item.Frame <= nFrame) + { + _field.SetActorPosition( + item.ActorId, + item.PositionX, + item.PositionY, + -item.PositionZ, + item.RotationY); + } + break; + case SeqPlayAnimation item: + if (item.FrameStart > nPrevFrame && item.FrameStart <= nFrame) + { + _field.SetActorAnimation( + item.ActorId, GetAnmPath(item.ActorId, item.Path)); + _field.SetActorVisibility(item.ActorId, true); + } + break; + case SeqActorLeave item: + if (item.Frame > nPrevFrame && item.Frame <= nFrame) + _field.SetActorVisibility(item.ActorId, false); + break; + case SeqCamera item: + if (nFrame >= item.FrameStart && nFrame < item.FrameEnd) + { + _cameraId = item.CameraId; + var frameLength = item.FrameEnd - item.FrameStart; + cameraFrameTime = (_seconds * FramesPerSecond - item.FrameStart) / 30f; + } + break; + case SeqFade item: + if (item.FrameIndex > nPrevFrame && item.FrameIndex <= nFrame) + { + switch (item.Type) + { + case SeqFade.FadeType.FromBlack: + case SeqFade.FadeType.FromBlackVariant: + _field.FadeFromBlack(item.Duration * TimeMul); + break; + case SeqFade.FadeType.FromWhite: + case SeqFade.FadeType.FromWhiteVariant: + _field.FadeFromWhite(item.Duration * TimeMul); + break; + case SeqFade.FadeType.ToBlack: + case SeqFade.FadeType.ToBlackVariant: + _field.FadeToBlack(item.Duration * TimeMul); + break; + case SeqFade.FadeType.ToWhite: + case SeqFade.FadeType.ToWhiteVariant: + _field.FadeToWhite(item.Duration * TimeMul); + break; + } + } + break; + case SeqSubtitle item: + if (nFrame >= item.FrameStart && nPrevFrame < item.FrameStart) + { + if (item.HideFlag == 0) + _field.ShowSubtitle(item.Index, (ushort)item.MessageId); + else if (item.HideFlag != 0) + _field.HideSubtitle(item.Index); + } + break; + } + } + + if (_cameraId < _cameras.Count) + { + var curCamera = _cameras[_cameraId]; + _field.SetCamera( + new Vector3( + (float)GetCameraValue(cameraFrameTime, curCamera.PositionX, null), + (float)GetCameraValue(cameraFrameTime, curCamera.PositionY, null), + (float)GetCameraValue(cameraFrameTime, curCamera.PositionZ, null)), + new Vector3( + (float)GetCameraValue(cameraFrameTime, curCamera.LookAtX, null), + (float)GetCameraValue(cameraFrameTime, curCamera.LookAtY, null), + (float)GetCameraValue(cameraFrameTime, curCamera.LookAtZ, null)), + (float)GetCameraValue(cameraFrameTime, curCamera.FieldOfView, null), + (float)GetCameraValue(cameraFrameTime, curCamera.Roll, null)); + } + + _secondsPrev = _seconds; + } + + private string GetAnmPath(int actorId, string name) + { + var sb = new StringBuilder(); + var split = name.Split("anm_")[1].Split("/"); + + sb.Append(split[0]); + sb.Append("/"); + sb.Append(_actors[actorId]); + sb.Append("/"); + sb.Append(split[1]); + return sb.ToString(); + } + + private static double GetCameraValue( + double time, + IList keyFrames, + SetCameraData.CameraKeys prevKey) + { + if (keyFrames.Count == 0) + return 0.0; + + if (keyFrames.Count == 1) + return keyFrames[0].Value; + + const int First = 0; + var Last = keyFrames.Count - 1; + + var m = time + 1.0 / 60.0; + var currentFrameIndex = (int)(m * 512.0); + if (currentFrameIndex > keyFrames[First].KeyFrame - 0x10000000) + { + if (currentFrameIndex < keyFrames[Last].KeyFrame) + { + // Do a binary search through all the key frames + var left = First; + var right = Last; + if (right <= 1) + return InterpolateCamera(right - 1, m, keyFrames, prevKey); + + while (true) + { + var mid = (left + right) / 2; + if (currentFrameIndex >= keyFrames[mid].KeyFrame) + { + if (currentFrameIndex <= keyFrames[mid].KeyFrame) + return keyFrames[mid].Value; + left = mid; + } + else + right = mid; + + if (right - left <= 1) + return InterpolateCamera(right - 1, m, keyFrames, prevKey); + } + } + + double tangent; + var keyFrameDistance = keyFrames[Last].KeyFrame - keyFrames[Last - 1].KeyFrame; + if (keyFrames[Last].Interpolation != Kh2.Motion.Interpolation.Linear || keyFrameDistance == 0) + tangent = keyFrames[Last].TangentEaseOut; + else + tangent = (keyFrames[Last].Value - keyFrames[Last - 1].Value) / keyFrameDistance; + return ((currentFrameIndex - (keyFrames[Last].KeyFrame + 0x10000000) + 0x10000000) * tangent) + keyFrames[Last].Value; + } + else + { + double tangent; + var keyFrameDistance = keyFrames[First + 1].KeyFrame - keyFrames[First].KeyFrame; + if (keyFrames[First].Interpolation != Kh2.Motion.Interpolation.Linear || keyFrameDistance == 0) + tangent = keyFrames[First].TangentEaseIn; + else + tangent = (keyFrames[First + 1].Value - keyFrames[First].Value) / keyFrameDistance; + return -(((keyFrames[First].KeyFrame - currentFrameIndex - 0x10000000) * tangent) - keyFrames[First].Value); + } + } + + private static double InterpolateCamera( + int keyFrameIndex, + double time, + IList keyFrames, + SetCameraData.CameraKeys prevKey) + { + const double N = 1.0 / 512.0; + var curKeyFrame = keyFrames[keyFrameIndex]; + var nextKeyFrame = keyFrames[keyFrameIndex + 1]; + if (prevKey != null) + prevKey.TangentEaseOut = curKeyFrame.TangentEaseOut; + + var t = time - curKeyFrame.KeyFrame * N; + var tx = (nextKeyFrame.KeyFrame - curKeyFrame.KeyFrame) * N; + switch (curKeyFrame.Interpolation) + { + case Kh2.Motion.Interpolation.Nearest: + return curKeyFrame.Value; + case Kh2.Motion.Interpolation.Linear: + return curKeyFrame.Value + ((nextKeyFrame.Value - curKeyFrame.Value) * t / tx); + case Kh2.Motion.Interpolation.Hermite: + case (Kh2.Motion.Interpolation)3: + case (Kh2.Motion.Interpolation)4: + var itx = 1.0 / tx; + // Perform a cubic hermite interpolation + var p0 = curKeyFrame.Value; + var p1 = nextKeyFrame.Value; + var m0 = curKeyFrame.TangentEaseOut; + var m1 = nextKeyFrame.TangentEaseIn; + var t2 = t * t * itx; + var t3 = t * t * t * itx * itx; + return p0 * (2 * t3 * itx - 3 * t2 * itx + 1) + + m0 * (t3 - 2 * t2 + t) + + p1 * (-2 * t3 * itx + 3 * t2 * itx) + + m1 * (t3 - t2); + default: + return 0; + } + } + } +} diff --git a/OpenKh.Game/Field/BbsMap.cs b/OpenKh.Game/Field/BbsMap.cs index f685522af..2a77ba1c3 100644 --- a/OpenKh.Game/Field/BbsMap.cs +++ b/OpenKh.Game/Field/BbsMap.cs @@ -1,123 +1,123 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Bbs; -using OpenKh.Common; -using OpenKh.Engine; -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Parsers; -using OpenKh.Game.Entities; -using System; -using System.Collections.Generic; -using System.IO; -using System.Numerics; - -namespace OpenKh.Game.Field -{ - public class BbsMap : IMap, IDisposable - { - private readonly GraphicsDevice _graphics; - private List _pmpEntities = new List(); - private List _pmpModels = new List(); - - public BbsMap(GraphicsDevice graphics, string filePath) - { - _graphics = graphics; - - var pmp = File.OpenRead(filePath).Using(Pmp.Read); - var group = new List(); - - int pmoIndex = 0; - for (int i = 0; i < pmp.objectInfo.Count; i++) - { - Pmp.ObjectInfo currentInfo = pmp.objectInfo[i]; - - if (currentInfo.PMO_Offset != 0) - { - var pmpEntity = new PmpEntity(pmoIndex, - new Vector3(currentInfo.PositionX, currentInfo.PositionY, currentInfo.PositionZ), - new Vector3(currentInfo.RotationX, currentInfo.RotationY, currentInfo.RotationZ), - new Vector3(currentInfo.ScaleX, currentInfo.ScaleY, currentInfo.ScaleZ)); - pmpEntity.DifferentMatrix = pmp.hasDifferentMatrix[pmoIndex]; - - var pParser = new PmoParser(pmp.PmoList[pmoIndex], 100.0f); - var textures = new List(); - - var meshGroup = new MeshGroup(); - meshGroup.MeshDescriptors = pParser.MeshDescriptors; - meshGroup.Textures = new IKingdomTexture[pmp.PmoList[pmoIndex].header.TextureCount]; - - for (int j = 0; j < pmp.PmoList[pmoIndex].header.TextureCount; j++) - { - textures.Add(new Tim2KingdomTexture(pmp.PmoList[pmoIndex].texturesData[j], graphics)); - meshGroup.Textures[j] = textures[j]; - } - - _pmpEntities.Add(pmpEntity); - _pmpModels.Add(meshGroup); - pmoIndex++; - } - } - } - - public void Dispose() - { - foreach (var model in _pmpModels) - { - foreach (var texture in model.Textures) - texture.Dispose(); - } - } - - public void Render(Camera camera, KingdomShader shader, EffectPass pass, bool passRenderOpaque) - { - if (passRenderOpaque == true) - // we know that all the meshes will not be opaque anyway - return; - - var worldView = camera.World; - var specialWorldView = worldView; - specialWorldView.M14 = 0; - specialWorldView.M24 = 0; - specialWorldView.M34 = 0; - specialWorldView.M41 = 0; - specialWorldView.M42 = 0; - specialWorldView.M43 = 0; - specialWorldView.M44 = 1; - - var originalDepthStencilState = _graphics.DepthStencilState; - var originalResterizerState = _graphics.RasterizerState; - foreach (var entity in _pmpEntities) - { - if (entity.DifferentMatrix) - { - shader.SetWorldView(ref specialWorldView); - _graphics.DepthStencilState = DepthStencilState.DepthRead; - } - else - { - shader.SetWorldView(ref worldView); - _graphics.DepthStencilState = DepthStencilState.Default; - } - - int AxisNumberChanged = 0; - AxisNumberChanged += Convert.ToInt32(entity.Scaling.X < 0); - AxisNumberChanged += Convert.ToInt32(entity.Scaling.Y < 0); - AxisNumberChanged += Convert.ToInt32(entity.Scaling.Z < 0); - - if (AxisNumberChanged == 1 || AxisNumberChanged == 3) - _graphics.RasterizerState = RasterizerState.CullCounterClockwise; - else - _graphics.RasterizerState = RasterizerState.CullClockwise; - - - shader.SetModelView(entity.GetMatrix()); - shader.UseAlphaMask = true; - pass.Apply(); - - _graphics.RenderMeshNew(shader, pass, _pmpModels[entity.Index], passRenderOpaque); - } - - _graphics.DepthStencilState = originalDepthStencilState; - _graphics.RasterizerState = originalResterizerState; - } - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Bbs; +using OpenKh.Common; +using OpenKh.Engine; +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Parsers; +using OpenKh.Game.Entities; +using System; +using System.Collections.Generic; +using System.IO; +using System.Numerics; + +namespace OpenKh.Game.Field +{ + public class BbsMap : IMap, IDisposable + { + private readonly GraphicsDevice _graphics; + private List _pmpEntities = new List(); + private List _pmpModels = new List(); + + public BbsMap(GraphicsDevice graphics, string filePath) + { + _graphics = graphics; + + var pmp = File.OpenRead(filePath).Using(Pmp.Read); + var group = new List(); + + int pmoIndex = 0; + for (int i = 0; i < pmp.objectInfo.Count; i++) + { + Pmp.ObjectInfo currentInfo = pmp.objectInfo[i]; + + if (currentInfo.PMO_Offset != 0) + { + var pmpEntity = new PmpEntity(pmoIndex, + new Vector3(currentInfo.PositionX, currentInfo.PositionY, currentInfo.PositionZ), + new Vector3(currentInfo.RotationX, currentInfo.RotationY, currentInfo.RotationZ), + new Vector3(currentInfo.ScaleX, currentInfo.ScaleY, currentInfo.ScaleZ)); + pmpEntity.DifferentMatrix = pmp.hasDifferentMatrix[pmoIndex]; + + var pParser = new PmoParser(pmp.PmoList[pmoIndex], 100.0f); + var textures = new List(); + + var meshGroup = new MeshGroup(); + meshGroup.MeshDescriptors = pParser.MeshDescriptors; + meshGroup.Textures = new IKingdomTexture[pmp.PmoList[pmoIndex].header.TextureCount]; + + for (int j = 0; j < pmp.PmoList[pmoIndex].header.TextureCount; j++) + { + textures.Add(new Tim2KingdomTexture(pmp.PmoList[pmoIndex].texturesData[j], graphics)); + meshGroup.Textures[j] = textures[j]; + } + + _pmpEntities.Add(pmpEntity); + _pmpModels.Add(meshGroup); + pmoIndex++; + } + } + } + + public void Dispose() + { + foreach (var model in _pmpModels) + { + foreach (var texture in model.Textures) + texture.Dispose(); + } + } + + public void Render(Camera camera, KingdomShader shader, EffectPass pass, bool passRenderOpaque) + { + if (passRenderOpaque == true) + // we know that all the meshes will not be opaque anyway + return; + + var worldView = camera.World; + var specialWorldView = worldView; + specialWorldView.M14 = 0; + specialWorldView.M24 = 0; + specialWorldView.M34 = 0; + specialWorldView.M41 = 0; + specialWorldView.M42 = 0; + specialWorldView.M43 = 0; + specialWorldView.M44 = 1; + + var originalDepthStencilState = _graphics.DepthStencilState; + var originalResterizerState = _graphics.RasterizerState; + foreach (var entity in _pmpEntities) + { + if (entity.DifferentMatrix) + { + shader.SetWorldView(ref specialWorldView); + _graphics.DepthStencilState = DepthStencilState.DepthRead; + } + else + { + shader.SetWorldView(ref worldView); + _graphics.DepthStencilState = DepthStencilState.Default; + } + + int AxisNumberChanged = 0; + AxisNumberChanged += Convert.ToInt32(entity.Scaling.X < 0); + AxisNumberChanged += Convert.ToInt32(entity.Scaling.Y < 0); + AxisNumberChanged += Convert.ToInt32(entity.Scaling.Z < 0); + + if (AxisNumberChanged == 1 || AxisNumberChanged == 3) + _graphics.RasterizerState = RasterizerState.CullCounterClockwise; + else + _graphics.RasterizerState = RasterizerState.CullClockwise; + + + shader.SetModelView(entity.GetMatrix()); + shader.UseAlphaMask = true; + pass.Apply(); + + _graphics.RenderMeshNew(shader, pass, _pmpModels[entity.Index], passRenderOpaque); + } + + _graphics.DepthStencilState = originalDepthStencilState; + _graphics.RasterizerState = originalResterizerState; + } + } +} diff --git a/OpenKh.Game/Field/IField.cs b/OpenKh.Game/Field/IField.cs index 1ca4922b1..eb8a4e217 100644 --- a/OpenKh.Game/Field/IField.cs +++ b/OpenKh.Game/Field/IField.cs @@ -1,35 +1,35 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Engine; -using OpenKh.Engine.MonoGame; -using System.Collections.Generic; -using System.Numerics; - -namespace OpenKh.Game.Field -{ - public interface IField - { - List Events { get; } - - void Update(double deltaTime); - void Draw(); - - void PlayEvent(string eventName); - - void Render(Camera camera, KingdomShader shader, EffectPass pass, bool passRenderOpaque); - void AddActor(int actorId, int objectId); - void SetActorPosition(int actorId, float x, float y, float z, float rotation); - void SetActorAnimation(int actorId, string path); - void SetActorVisibility(int actorId, bool visibility); - void RemoveAllActors(); - - void SetCamera(Vector3 position, Vector3 lookAt, float fieldOfView, float roll); - - void FadeToBlack(float seconds); - void FadeToWhite(float seconds); - void FadeFromBlack(float seconds); - void FadeFromWhite(float seconds); - - void ShowSubtitle(int subtitleId, ushort messageId); - void HideSubtitle(int subtitleId); - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Engine; +using OpenKh.Engine.MonoGame; +using System.Collections.Generic; +using System.Numerics; + +namespace OpenKh.Game.Field +{ + public interface IField + { + List Events { get; } + + void Update(double deltaTime); + void Draw(); + + void PlayEvent(string eventName); + + void Render(Camera camera, KingdomShader shader, EffectPass pass, bool passRenderOpaque); + void AddActor(int actorId, int objectId); + void SetActorPosition(int actorId, float x, float y, float z, float rotation); + void SetActorAnimation(int actorId, string path); + void SetActorVisibility(int actorId, bool visibility); + void RemoveAllActors(); + + void SetCamera(Vector3 position, Vector3 lookAt, float fieldOfView, float roll); + + void FadeToBlack(float seconds); + void FadeToWhite(float seconds); + void FadeFromBlack(float seconds); + void FadeFromWhite(float seconds); + + void ShowSubtitle(int subtitleId, ushort messageId); + void HideSubtitle(int subtitleId); + } +} diff --git a/OpenKh.Game/Field/IMap.cs b/OpenKh.Game/Field/IMap.cs index 689f63516..5e7f0874d 100644 --- a/OpenKh.Game/Field/IMap.cs +++ b/OpenKh.Game/Field/IMap.cs @@ -1,12 +1,12 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Engine; -using OpenKh.Engine.MonoGame; -using System; - -namespace OpenKh.Game.Field -{ - public interface IMap : IDisposable - { - void Render(Camera camera, KingdomShader shader, EffectPass pass, bool passRenderOpaque); - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Engine; +using OpenKh.Engine.MonoGame; +using System; + +namespace OpenKh.Game.Field +{ + public interface IMap : IDisposable + { + void Render(Camera camera, KingdomShader shader, EffectPass pass, bool passRenderOpaque); + } +} diff --git a/OpenKh.Game/Field/Kh2Field.cs b/OpenKh.Game/Field/Kh2Field.cs index dcb10b250..f15a355f6 100644 --- a/OpenKh.Game/Field/Kh2Field.cs +++ b/OpenKh.Game/Field/Kh2Field.cs @@ -1,539 +1,539 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Common; -using OpenKh.Engine; -using OpenKh.Engine.Extensions; -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Renders; -using OpenKh.Game.Entities; -using OpenKh.Game.Events; -using OpenKh.Game.Infrastructure; -using OpenKh.Kh2; -using OpenKh.Kh2.Ard; -using OpenKh.Kh2.Extensions; -using System; -using System.Collections.Generic; -using System.Linq; -using n = System.Numerics; -using OpenKh.Engine.Input; - -namespace OpenKh.Game.Field -{ - public class Kh2Field : IField - { - private readonly Kernel _kernel; - private readonly Camera _camera; - private readonly TargetCamera _targetCamera; - private readonly GraphicsDevice _graphicsDevice; - private readonly KingdomShader _shader; - private readonly IInput _input; - private readonly Kh2MessageRenderer _messageRenderer; - private readonly DrawContext _messageDrawContext; - private readonly Kh2MessageProvider _eventMessageProvider; - private readonly List _actors = new List(); - private readonly Dictionary _actorIds = new Dictionary(); - private readonly Dictionary _subtitleData = new Dictionary(); - private readonly MonoSpriteDrawing _drawing; - private Bar _binarcAreaData; - private IMap _map; - private EventPlayer _eventPlayer; - private int _spawnScriptMap; - private int _spawnScriptBtl; - private int _spawnScriptEvt; - private bool _isFreeCam; - private bool _isEventPause; - - private bool _isFading; - private float _fadeCurrent; - private float _fadeGoal; - private Color _fadeCurrentColor; - private Color _fadeStartColor; - private Color _fadeEndColor; - - public List Events { get; private set; } - - public Kh2Field( - Kernel kernel, - Camera camera, - Dictionary settings, - GraphicsDevice graphicsDevice, - KingdomShader shader, - IInput input) - { - _kernel = kernel; - _camera = camera; - _targetCamera = new TargetCamera(_camera); - _graphicsDevice = graphicsDevice; - _shader = shader; - _input = input; - - var viewport = graphicsDevice.Viewport; - _drawing = new MonoSpriteDrawing(graphicsDevice, _shader); - _drawing.SetProjection( - viewport.Width, - viewport.Height, - Global.ResolutionWidth, - Global.ResolutionHeight, - 1.0f); - _messageRenderer = new Kh2MessageRenderer(_drawing, _kernel.EventMessageContext); - _messageDrawContext = new DrawContext - { - IgnoreDraw = false, - - x = 0, - y = 0, - xStart = 0, - Width = 0, - Height = 0, - WindowWidth = 512, - - Scale = 1, - WidthMultiplier = 1, - Color = new ColorF(1.0f, 1.0f, 1.0f, 1.0f) - }; - _eventMessageProvider = new Kh2MessageProvider(); - - _spawnScriptMap = settings.GetInt("SpawnScriptMap", -1); - _spawnScriptBtl = settings.GetInt("SpawnScriptBtl", -1); - _spawnScriptEvt = settings.GetInt("SpawnScriptEvt", -1); - FadeFromBlack(1.0f); - } - - public void UnloadMap() - { - _map?.Dispose(); - RemoveAllActors(); - _eventPlayer = null; - } - - public void LoadArea(int world, int area) - { - Log.Info("Area={0},{1}", world, area); - - UnloadMap(); - LoadAreaData(world, area); - // TODO load voices (eg. voice/us/battle/nm0_jack.vsb) - // TODO load field2d (eg. field2d/jp/nm0field.2dd) - // TODO load command (eg. field2d/jp/nm1command.2dd) - _map = new Kh2Map(_graphicsDevice, _kernel, world, area); // new BbsMap(_graphicsDevice, @"PATH_TO_PMP"); - LoadMsg(world); - // TODO load libretto (eg. libretto-nm.bar) - // TODO load effect - // TODO load magics - // TODO load prize - // TODO load prizebox - // TODO load entities - // TODO load summons - // TODO load mission - // TODO dispatch entity loading here, not in LoadAreaData - - if (world >= 0 && world < _kernel.AreaInfo.Count) - { - var worldInfos = _kernel.AreaInfo[world]; - if (area >= 0 && area < worldInfos.Count) - { - var areaInfo = worldInfos[area]; - var isKnown = (areaInfo.Flags & 1) != 0; - var isInDoor = (areaInfo.Flags & 2) != 0; - var isMonochrome = (areaInfo.Flags & 4) != 0; - var hasNoShadow = (areaInfo.Flags & 8) != 0; - var hasGlow = (areaInfo.Flags & 16) != 0; - - _targetCamera.Type = isInDoor ? 1 : 0; - } - else - Log.Err("Area {0} can not be found in AreaInfo for world {1}", area, world); - } - else - Log.Err("World {0} can not be found in AreaInfo", world); - } - - private void LoadAreaData(int world, int area) - { - string fileName; - if (_kernel.IsReMix) - fileName = $"ard/{_kernel.Language}/{Constants.WorldIds[world]}{area:D02}.ard"; - else - fileName = $"ard/{Constants.WorldIds[world]}{area:D02}.ard"; - - _binarcAreaData = _kernel.DataContent.FileOpen(fileName).Using(Bar.Read); - Events = _binarcAreaData - .Where(x => x.Type == Bar.EntryType.Event) - .Select(x => x.Name) - .ToList(); - - Log.Info($"Loading spawn {_kernel.SpawnName}"); - RunSpawnScript(_binarcAreaData, "map", _spawnScriptMap >= 0 ? _spawnScriptMap : _kernel.SpawnMap); - RunSpawnScript(_binarcAreaData, "btl", _spawnScriptBtl >= 0 ? _spawnScriptBtl : _kernel.SpawnBtl); - RunSpawnScript(_binarcAreaData, "evt", _spawnScriptEvt >= 0 ? _spawnScriptEvt : _kernel.SpawnEvt); - // TODO units (or entities) should be spawn later, not in RunSpawnScript. This is because - // we want to avoid to load entities that can be potentially not used. - } - - private void LoadMsg(int world) => _kernel.DataContent - .FileOpen($"msg/{_kernel.Language}/{Constants.WorldIds[world]}.bar") - .Using(stream => Bar.Read(stream)) - .ForEntry(x => x.Type == Bar.EntryType.List, stream => - { - _eventMessageProvider.Load(Msg.Read(stream)); - return true; - }); - - public void PlayEvent(string eventName) - { - _actorIds.Clear(); - _subtitleData.Clear(); - _binarcAreaData.ForEntry(eventName, Bar.EntryType.Event, stream => - { - _eventPlayer = new EventPlayer(this, Event.Read(stream)); - RemoveAllActors(); - - _eventPlayer.Initialize(); - }); - } - - public void Update(double deltaTime) - { - var isPlayingEvent = _eventPlayer != null && _isEventPause == false; - _camera.IsEventMode = isPlayingEvent; - _isEventPause = _input.Pressed.R2; - _isFreeCam = _input.Pressed.L2; - - if (isPlayingEvent) - { - _eventPlayer.Update(deltaTime); - if (_eventPlayer.IsEnd) - { - FadeFromBlack(1); - _eventPlayer = null; - } - } - - IEntity playerEntity = null; - foreach (var entity in _actors.Where(x => x.IsMeshLoaded && x.IsVisible)) - { - if (!isPlayingEvent && !_kernel.DebugMode && entity.IsPlayer) - { - playerEntity = entity; - PlayerManager.ProcessPlayer(_input, entity, _targetCamera.YRotation, deltaTime); - } - - entity.Update((float)deltaTime); - } - - if (!isPlayingEvent && !_kernel.DebugMode && playerEntity != null) - { - const float RadiusSpeed = 480f; - const double YSpeed = Math.PI; - - var analogY = 0f; - var radius = 0f; - var yRotation = 0f; - analogY = -_input.AxisRight.X; - radius -= (float)(_input.AxisRight.Y * RadiusSpeed * deltaTime); - - yRotation -= (float)(YSpeed * analogY * deltaTime); - - _targetCamera.Radius = Math.Min( - Math.Max(_targetCamera.Radius + radius, _targetCamera.ObjectiveRadiusMin), - _targetCamera.ObjectiveRadiusMax); - _targetCamera.BackYRotation += yRotation; - - _targetCamera.Update(playerEntity, deltaTime, Math.Abs(analogY) >= 0.9f); - } - - if (_isFading) - { - UpdateFade(deltaTime); - } - } - - public void Draw() - { - foreach (var subtitle in _subtitleData) - if (subtitle.Value != null) - DrawSubtitle(subtitle.Value); - - if (_fadeCurrentColor.A > 0) - DrawFade(); - } - - public void Render(Camera camera, KingdomShader shader, EffectPass pass, bool passRenderOpaque) - { - _map.Render(camera, shader, pass, passRenderOpaque); - - foreach (var actor in _actors.Where(x => x.IsVisible)) - { - shader.SetModelView(actor.GetMatrix()); - pass.Apply(); - - _graphicsDevice.RenderMeshNew(shader, pass, actor, passRenderOpaque); - - if (_kernel.DebugMode) - { - var matrixArray = actor.Model?.CurrentPose; - if (matrixArray != null) - { - foreach (var bone in actor.Model.Bones) - { - if (bone.Parent > 0) - { - var bonePos = matrixArray[bone.Index].Translation; - var parentPos = matrixArray[bone.Parent].Translation; - Debugging.DebugDraw.DrawLine(_graphicsDevice, bonePos, parentPos, Color.Red); - } - } - } - } - } - } - - public void AddActor(int actorId, int objectId) - { - var entity = new ObjectEntity(_kernel, _kernel.GetRealObjectId(objectId)); - entity.LoadMesh(_graphicsDevice); - - _actors.Add(entity); - _actorIds[actorId] = entity; - } - - public void SetActorPosition(int actorId, float x, float y, float z, float rotation) - { - var actor = _actorIds[actorId]; - actor.Position = new n.Vector3(x, y, z); - actor.Rotation = new n.Vector3(0, (float)(rotation * Math.PI / 180), 0); - } - - public void SetActorAnimation(int actorId, string path) - { - var realPath = GetAnbPath(path); - if (_kernel.DataContent.FileExists(realPath)) - { - var binarc = _kernel.DataContent.FileOpen(realPath).Using(Bar.Read); - binarc.ForEntry(x => x.Type == Bar.EntryType.Motion, stream => - { - _actorIds[actorId].SetMotion(Motion.Read(stream)); - return true; - }); - } - else - { - _actorIds[actorId].SetMotion(null); - } - } - - public void SetActorVisibility(int actorId, bool visibility) - { - _actorIds[actorId].IsVisible = visibility; - } - - public void AddActor(SpawnPoint.Entity entityDesc) - { - var entity = ObjectEntity.FromSpawnPoint(_kernel, entityDesc); - entity.LoadMesh(_graphicsDevice); - - _actors.Add(entity); - } - - public void RemoveAllActors() - { - foreach (var actor in _actors) - { - foreach (var texture in actor.Textures) - texture.Dispose(); - } - - _actorIds.Clear(); - _actors.Clear(); - } - - public void SetCamera( - n.Vector3 position, - n.Vector3 lookAt, - float fieldOfView, - float roll) - { - if (_isFreeCam == true) - return; - - _camera.CameraPosition = new n.Vector3(-position.X, position.Y, position.Z); - _camera.CameraLookAt = new n.Vector3(-lookAt.X, lookAt.Y, lookAt.Z); - _camera.FieldOfView = (float)(fieldOfView * Math.PI / 180); - } - - public void FadeToBlack(float seconds) - { - _isFading = true; - _fadeCurrent = 0; - _fadeGoal = seconds; - _fadeStartColor = new Color(0, 0, 0, 0.0f); - _fadeEndColor = new Color(0, 0, 0, 1.0f); - _fadeCurrentColor = _fadeStartColor; - } - - public void FadeToWhite(float seconds) - { - _isFading = true; - _fadeCurrent = 0; - _fadeGoal = seconds; - _fadeStartColor = new Color(1, 1, 1, 0.0f); - _fadeEndColor = new Color(1, 1, 1, 1.0f); - } - - public void FadeFromBlack(float seconds) - { - _isFading = true; - _fadeCurrent = 0; - _fadeGoal = seconds; - _fadeStartColor = new Color(0, 0, 0, 1.0f); - _fadeEndColor = new Color(0, 0, 0, 0.0f); - } - - public void FadeFromWhite(float seconds) - { - _isFading = true; - _fadeCurrent = 0; - _fadeGoal = seconds; - _fadeStartColor = new Color(1, 1, 1, 1.0f); - _fadeEndColor = new Color(1, 1, 1, 0.0f); - } - - private void UpdateFade(double deltaTime) - { - _fadeCurrent += (float)deltaTime; - if (_fadeCurrent >= _fadeGoal) - { - _fadeCurrent = _fadeGoal; - _isFading = false; - } - - _fadeCurrentColor.A = (byte)MathEx.Lerp( - _fadeStartColor.A, - _fadeEndColor.A, - _fadeCurrent / _fadeGoal); - } - - private void DrawFade() - { - const float Size = 5000f; - _shader.Pass(pass => - { - _graphicsDevice.BlendState = BlendState.AlphaBlend; - - _shader.UseAlphaMask = true; - _shader.SetProjectionViewIdentity(); - _shader.SetWorldViewIdentity(); - _shader.SetModelViewIdentity(); - pass.Apply(); - - _graphicsDevice.DrawUserPrimitives( - PrimitiveType.TriangleStrip, - new VertexPositionColor[] - { - new VertexPositionColor - { - Position = new Vector3(-Size, -Size, 0), - Color = _fadeCurrentColor - }, - new VertexPositionColor - { - Position = new Vector3(Size, -Size, 0), - Color = _fadeCurrentColor - }, - new VertexPositionColor - { - Position = new Vector3(-Size, Size, 0), - Color = _fadeCurrentColor - }, - new VertexPositionColor - { - Position = new Vector3(Size, Size, 0), - Color = _fadeCurrentColor - }, - }, 0, 2); - }); - } - - public void ShowSubtitle(int subtitleId, ushort messageId) - { - var msgProvider = messageId < 0x8000 ? - _eventMessageProvider : _kernel.MessageProvider; - _subtitleData[subtitleId] = msgProvider.GetMessage(messageId); - } - - public void HideSubtitle(int subtitleId) - { - _subtitleData[subtitleId] = null; - } - - private void DrawSubtitle(byte[] data) - { - _messageDrawContext.GlobalScale = 1.0f; - _messageDrawContext.WidthMultiplier = 1.2f; - _messageDrawContext.IgnoreDraw = true; - _messageDrawContext.x = 0; - _messageDrawContext.y = 0; - _messageDrawContext.Width = 0; - _messageRenderer.Draw(_messageDrawContext, data); - - _messageDrawContext.GlobalScale = 1.0f; - _messageDrawContext.WidthMultiplier = 1.2f; - _messageDrawContext.x = (_messageDrawContext.WindowWidth - _messageDrawContext.Width) / 2f; - _messageDrawContext.y = 350; - _messageDrawContext.IgnoreDraw = false; - _messageRenderer.Draw(_messageDrawContext, data); - - _drawing.Flush(); - } - - private void RunSpawnScript( - IEnumerable barEntries, string spawnScriptName, int programId) - { - var script = barEntries.ForEntry(spawnScriptName, Bar.EntryType.AreaDataScript, stream => - AreaDataScript.Read(stream, programId)); - if (script == null) - return; - - foreach (var function in script) - { - switch (function) - { - case AreaDataScript.Spawn spawn: - Log.Info("Loading spawn {0}", spawn.SpawnSet); - var spawnPoints = barEntries.ForEntry(spawn.SpawnSet, Bar.EntryType.AreaDataSpawn, SpawnPoint.Read); - if (spawnPoints != null) - { - foreach (var spawnPoint in spawnPoints) - { - foreach (var desc in spawnPoint.Entities) - { - if (desc.SpawnType == 0 || desc.SpawnArgument == _kernel.Entrance) - AddActor(desc); - } - } - } - else - Log.Warn("Unable to find spawn \"{0}\".", spawn); - break; - } - } - } - - private string GetAnbPath(string path) - { - if (_kernel.IsReMix) - { - switch (_kernel.RegionId) - { - case (int)Constants.RegionId.Japanese: - case (int)Constants.RegionId.FinalMix: - return $"anm/fm/{path}.anb"; - default: - return $"anm/us/{path}.anb"; - } - } - else - return $"anm/{path}.anb"; - } - } -} +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Common; +using OpenKh.Engine; +using OpenKh.Engine.Extensions; +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Renders; +using OpenKh.Game.Entities; +using OpenKh.Game.Events; +using OpenKh.Game.Infrastructure; +using OpenKh.Kh2; +using OpenKh.Kh2.Ard; +using OpenKh.Kh2.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; +using n = System.Numerics; +using OpenKh.Engine.Input; + +namespace OpenKh.Game.Field +{ + public class Kh2Field : IField + { + private readonly Kernel _kernel; + private readonly Camera _camera; + private readonly TargetCamera _targetCamera; + private readonly GraphicsDevice _graphicsDevice; + private readonly KingdomShader _shader; + private readonly IInput _input; + private readonly Kh2MessageRenderer _messageRenderer; + private readonly DrawContext _messageDrawContext; + private readonly Kh2MessageProvider _eventMessageProvider; + private readonly List _actors = new List(); + private readonly Dictionary _actorIds = new Dictionary(); + private readonly Dictionary _subtitleData = new Dictionary(); + private readonly MonoSpriteDrawing _drawing; + private Bar _binarcAreaData; + private IMap _map; + private EventPlayer _eventPlayer; + private int _spawnScriptMap; + private int _spawnScriptBtl; + private int _spawnScriptEvt; + private bool _isFreeCam; + private bool _isEventPause; + + private bool _isFading; + private float _fadeCurrent; + private float _fadeGoal; + private Color _fadeCurrentColor; + private Color _fadeStartColor; + private Color _fadeEndColor; + + public List Events { get; private set; } + + public Kh2Field( + Kernel kernel, + Camera camera, + Dictionary settings, + GraphicsDevice graphicsDevice, + KingdomShader shader, + IInput input) + { + _kernel = kernel; + _camera = camera; + _targetCamera = new TargetCamera(_camera); + _graphicsDevice = graphicsDevice; + _shader = shader; + _input = input; + + var viewport = graphicsDevice.Viewport; + _drawing = new MonoSpriteDrawing(graphicsDevice, _shader); + _drawing.SetProjection( + viewport.Width, + viewport.Height, + Global.ResolutionWidth, + Global.ResolutionHeight, + 1.0f); + _messageRenderer = new Kh2MessageRenderer(_drawing, _kernel.EventMessageContext); + _messageDrawContext = new DrawContext + { + IgnoreDraw = false, + + x = 0, + y = 0, + xStart = 0, + Width = 0, + Height = 0, + WindowWidth = 512, + + Scale = 1, + WidthMultiplier = 1, + Color = new ColorF(1.0f, 1.0f, 1.0f, 1.0f) + }; + _eventMessageProvider = new Kh2MessageProvider(); + + _spawnScriptMap = settings.GetInt("SpawnScriptMap", -1); + _spawnScriptBtl = settings.GetInt("SpawnScriptBtl", -1); + _spawnScriptEvt = settings.GetInt("SpawnScriptEvt", -1); + FadeFromBlack(1.0f); + } + + public void UnloadMap() + { + _map?.Dispose(); + RemoveAllActors(); + _eventPlayer = null; + } + + public void LoadArea(int world, int area) + { + Log.Info("Area={0},{1}", world, area); + + UnloadMap(); + LoadAreaData(world, area); + // TODO load voices (eg. voice/us/battle/nm0_jack.vsb) + // TODO load field2d (eg. field2d/jp/nm0field.2dd) + // TODO load command (eg. field2d/jp/nm1command.2dd) + _map = new Kh2Map(_graphicsDevice, _kernel, world, area); // new BbsMap(_graphicsDevice, @"PATH_TO_PMP"); + LoadMsg(world); + // TODO load libretto (eg. libretto-nm.bar) + // TODO load effect + // TODO load magics + // TODO load prize + // TODO load prizebox + // TODO load entities + // TODO load summons + // TODO load mission + // TODO dispatch entity loading here, not in LoadAreaData + + if (world >= 0 && world < _kernel.AreaInfo.Count) + { + var worldInfos = _kernel.AreaInfo[world]; + if (area >= 0 && area < worldInfos.Count) + { + var areaInfo = worldInfos[area]; + var isKnown = (areaInfo.Flags & 1) != 0; + var isInDoor = (areaInfo.Flags & 2) != 0; + var isMonochrome = (areaInfo.Flags & 4) != 0; + var hasNoShadow = (areaInfo.Flags & 8) != 0; + var hasGlow = (areaInfo.Flags & 16) != 0; + + _targetCamera.Type = isInDoor ? 1 : 0; + } + else + Log.Err("Area {0} can not be found in AreaInfo for world {1}", area, world); + } + else + Log.Err("World {0} can not be found in AreaInfo", world); + } + + private void LoadAreaData(int world, int area) + { + string fileName; + if (_kernel.IsReMix) + fileName = $"ard/{_kernel.Language}/{Constants.WorldIds[world]}{area:D02}.ard"; + else + fileName = $"ard/{Constants.WorldIds[world]}{area:D02}.ard"; + + _binarcAreaData = _kernel.DataContent.FileOpen(fileName).Using(Bar.Read); + Events = _binarcAreaData + .Where(x => x.Type == Bar.EntryType.Event) + .Select(x => x.Name) + .ToList(); + + Log.Info($"Loading spawn {_kernel.SpawnName}"); + RunSpawnScript(_binarcAreaData, "map", _spawnScriptMap >= 0 ? _spawnScriptMap : _kernel.SpawnMap); + RunSpawnScript(_binarcAreaData, "btl", _spawnScriptBtl >= 0 ? _spawnScriptBtl : _kernel.SpawnBtl); + RunSpawnScript(_binarcAreaData, "evt", _spawnScriptEvt >= 0 ? _spawnScriptEvt : _kernel.SpawnEvt); + // TODO units (or entities) should be spawn later, not in RunSpawnScript. This is because + // we want to avoid to load entities that can be potentially not used. + } + + private void LoadMsg(int world) => _kernel.DataContent + .FileOpen($"msg/{_kernel.Language}/{Constants.WorldIds[world]}.bar") + .Using(stream => Bar.Read(stream)) + .ForEntry(x => x.Type == Bar.EntryType.List, stream => + { + _eventMessageProvider.Load(Msg.Read(stream)); + return true; + }); + + public void PlayEvent(string eventName) + { + _actorIds.Clear(); + _subtitleData.Clear(); + _binarcAreaData.ForEntry(eventName, Bar.EntryType.Event, stream => + { + _eventPlayer = new EventPlayer(this, Event.Read(stream)); + RemoveAllActors(); + + _eventPlayer.Initialize(); + }); + } + + public void Update(double deltaTime) + { + var isPlayingEvent = _eventPlayer != null && _isEventPause == false; + _camera.IsEventMode = isPlayingEvent; + _isEventPause = _input.Pressed.R2; + _isFreeCam = _input.Pressed.L2; + + if (isPlayingEvent) + { + _eventPlayer.Update(deltaTime); + if (_eventPlayer.IsEnd) + { + FadeFromBlack(1); + _eventPlayer = null; + } + } + + IEntity playerEntity = null; + foreach (var entity in _actors.Where(x => x.IsMeshLoaded && x.IsVisible)) + { + if (!isPlayingEvent && !_kernel.DebugMode && entity.IsPlayer) + { + playerEntity = entity; + PlayerManager.ProcessPlayer(_input, entity, _targetCamera.YRotation, deltaTime); + } + + entity.Update((float)deltaTime); + } + + if (!isPlayingEvent && !_kernel.DebugMode && playerEntity != null) + { + const float RadiusSpeed = 480f; + const double YSpeed = Math.PI; + + var analogY = 0f; + var radius = 0f; + var yRotation = 0f; + analogY = -_input.AxisRight.X; + radius -= (float)(_input.AxisRight.Y * RadiusSpeed * deltaTime); + + yRotation -= (float)(YSpeed * analogY * deltaTime); + + _targetCamera.Radius = Math.Min( + Math.Max(_targetCamera.Radius + radius, _targetCamera.ObjectiveRadiusMin), + _targetCamera.ObjectiveRadiusMax); + _targetCamera.BackYRotation += yRotation; + + _targetCamera.Update(playerEntity, deltaTime, Math.Abs(analogY) >= 0.9f); + } + + if (_isFading) + { + UpdateFade(deltaTime); + } + } + + public void Draw() + { + foreach (var subtitle in _subtitleData) + if (subtitle.Value != null) + DrawSubtitle(subtitle.Value); + + if (_fadeCurrentColor.A > 0) + DrawFade(); + } + + public void Render(Camera camera, KingdomShader shader, EffectPass pass, bool passRenderOpaque) + { + _map.Render(camera, shader, pass, passRenderOpaque); + + foreach (var actor in _actors.Where(x => x.IsVisible)) + { + shader.SetModelView(actor.GetMatrix()); + pass.Apply(); + + _graphicsDevice.RenderMeshNew(shader, pass, actor, passRenderOpaque); + + if (_kernel.DebugMode) + { + var matrixArray = actor.Model?.CurrentPose; + if (matrixArray != null) + { + foreach (var bone in actor.Model.Bones) + { + if (bone.Parent > 0) + { + var bonePos = matrixArray[bone.Index].Translation; + var parentPos = matrixArray[bone.Parent].Translation; + Debugging.DebugDraw.DrawLine(_graphicsDevice, bonePos, parentPos, Color.Red); + } + } + } + } + } + } + + public void AddActor(int actorId, int objectId) + { + var entity = new ObjectEntity(_kernel, _kernel.GetRealObjectId(objectId)); + entity.LoadMesh(_graphicsDevice); + + _actors.Add(entity); + _actorIds[actorId] = entity; + } + + public void SetActorPosition(int actorId, float x, float y, float z, float rotation) + { + var actor = _actorIds[actorId]; + actor.Position = new n.Vector3(x, y, z); + actor.Rotation = new n.Vector3(0, (float)(rotation * Math.PI / 180), 0); + } + + public void SetActorAnimation(int actorId, string path) + { + var realPath = GetAnbPath(path); + if (_kernel.DataContent.FileExists(realPath)) + { + var binarc = _kernel.DataContent.FileOpen(realPath).Using(Bar.Read); + binarc.ForEntry(x => x.Type == Bar.EntryType.Motion, stream => + { + _actorIds[actorId].SetMotion(Motion.Read(stream)); + return true; + }); + } + else + { + _actorIds[actorId].SetMotion(null); + } + } + + public void SetActorVisibility(int actorId, bool visibility) + { + _actorIds[actorId].IsVisible = visibility; + } + + public void AddActor(SpawnPoint.Entity entityDesc) + { + var entity = ObjectEntity.FromSpawnPoint(_kernel, entityDesc); + entity.LoadMesh(_graphicsDevice); + + _actors.Add(entity); + } + + public void RemoveAllActors() + { + foreach (var actor in _actors) + { + foreach (var texture in actor.Textures) + texture.Dispose(); + } + + _actorIds.Clear(); + _actors.Clear(); + } + + public void SetCamera( + n.Vector3 position, + n.Vector3 lookAt, + float fieldOfView, + float roll) + { + if (_isFreeCam == true) + return; + + _camera.CameraPosition = new n.Vector3(-position.X, position.Y, position.Z); + _camera.CameraLookAt = new n.Vector3(-lookAt.X, lookAt.Y, lookAt.Z); + _camera.FieldOfView = (float)(fieldOfView * Math.PI / 180); + } + + public void FadeToBlack(float seconds) + { + _isFading = true; + _fadeCurrent = 0; + _fadeGoal = seconds; + _fadeStartColor = new Color(0, 0, 0, 0.0f); + _fadeEndColor = new Color(0, 0, 0, 1.0f); + _fadeCurrentColor = _fadeStartColor; + } + + public void FadeToWhite(float seconds) + { + _isFading = true; + _fadeCurrent = 0; + _fadeGoal = seconds; + _fadeStartColor = new Color(1, 1, 1, 0.0f); + _fadeEndColor = new Color(1, 1, 1, 1.0f); + } + + public void FadeFromBlack(float seconds) + { + _isFading = true; + _fadeCurrent = 0; + _fadeGoal = seconds; + _fadeStartColor = new Color(0, 0, 0, 1.0f); + _fadeEndColor = new Color(0, 0, 0, 0.0f); + } + + public void FadeFromWhite(float seconds) + { + _isFading = true; + _fadeCurrent = 0; + _fadeGoal = seconds; + _fadeStartColor = new Color(1, 1, 1, 1.0f); + _fadeEndColor = new Color(1, 1, 1, 0.0f); + } + + private void UpdateFade(double deltaTime) + { + _fadeCurrent += (float)deltaTime; + if (_fadeCurrent >= _fadeGoal) + { + _fadeCurrent = _fadeGoal; + _isFading = false; + } + + _fadeCurrentColor.A = (byte)MathEx.Lerp( + _fadeStartColor.A, + _fadeEndColor.A, + _fadeCurrent / _fadeGoal); + } + + private void DrawFade() + { + const float Size = 5000f; + _shader.Pass(pass => + { + _graphicsDevice.BlendState = BlendState.AlphaBlend; + + _shader.UseAlphaMask = true; + _shader.SetProjectionViewIdentity(); + _shader.SetWorldViewIdentity(); + _shader.SetModelViewIdentity(); + pass.Apply(); + + _graphicsDevice.DrawUserPrimitives( + PrimitiveType.TriangleStrip, + new VertexPositionColor[] + { + new VertexPositionColor + { + Position = new Vector3(-Size, -Size, 0), + Color = _fadeCurrentColor + }, + new VertexPositionColor + { + Position = new Vector3(Size, -Size, 0), + Color = _fadeCurrentColor + }, + new VertexPositionColor + { + Position = new Vector3(-Size, Size, 0), + Color = _fadeCurrentColor + }, + new VertexPositionColor + { + Position = new Vector3(Size, Size, 0), + Color = _fadeCurrentColor + }, + }, 0, 2); + }); + } + + public void ShowSubtitle(int subtitleId, ushort messageId) + { + var msgProvider = messageId < 0x8000 ? + _eventMessageProvider : _kernel.MessageProvider; + _subtitleData[subtitleId] = msgProvider.GetMessage(messageId); + } + + public void HideSubtitle(int subtitleId) + { + _subtitleData[subtitleId] = null; + } + + private void DrawSubtitle(byte[] data) + { + _messageDrawContext.GlobalScale = 1.0f; + _messageDrawContext.WidthMultiplier = 1.2f; + _messageDrawContext.IgnoreDraw = true; + _messageDrawContext.x = 0; + _messageDrawContext.y = 0; + _messageDrawContext.Width = 0; + _messageRenderer.Draw(_messageDrawContext, data); + + _messageDrawContext.GlobalScale = 1.0f; + _messageDrawContext.WidthMultiplier = 1.2f; + _messageDrawContext.x = (_messageDrawContext.WindowWidth - _messageDrawContext.Width) / 2f; + _messageDrawContext.y = 350; + _messageDrawContext.IgnoreDraw = false; + _messageRenderer.Draw(_messageDrawContext, data); + + _drawing.Flush(); + } + + private void RunSpawnScript( + IEnumerable barEntries, string spawnScriptName, int programId) + { + var script = barEntries.ForEntry(spawnScriptName, Bar.EntryType.AreaDataScript, stream => + AreaDataScript.Read(stream, programId)); + if (script == null) + return; + + foreach (var function in script) + { + switch (function) + { + case AreaDataScript.Spawn spawn: + Log.Info("Loading spawn {0}", spawn.SpawnSet); + var spawnPoints = barEntries.ForEntry(spawn.SpawnSet, Bar.EntryType.AreaDataSpawn, SpawnPoint.Read); + if (spawnPoints != null) + { + foreach (var spawnPoint in spawnPoints) + { + foreach (var desc in spawnPoint.Entities) + { + if (desc.SpawnType == 0 || desc.SpawnArgument == _kernel.Entrance) + AddActor(desc); + } + } + } + else + Log.Warn("Unable to find spawn \"{0}\".", spawn); + break; + } + } + } + + private string GetAnbPath(string path) + { + if (_kernel.IsReMix) + { + switch (_kernel.RegionId) + { + case (int)Constants.RegionId.Japanese: + case (int)Constants.RegionId.FinalMix: + return $"anm/fm/{path}.anb"; + default: + return $"anm/us/{path}.anb"; + } + } + else + return $"anm/{path}.anb"; + } + } +} diff --git a/OpenKh.Game/Field/Kh2Map.cs b/OpenKh.Game/Field/Kh2Map.cs index 9809ad7d3..ba3f5e70a 100644 --- a/OpenKh.Game/Field/Kh2Map.cs +++ b/OpenKh.Game/Field/Kh2Map.cs @@ -1,121 +1,121 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Common; -using OpenKh.Engine; -using OpenKh.Engine.MonoGame; -using OpenKh.Game.Entities; -using OpenKh.Game.Infrastructure; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using OpenKh.Kh2.Models; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Game.Field -{ - public class Kh2Map : IMap, IDisposable - { - private static readonly MeshGroup Empty = new MeshGroup - { - MeshDescriptors = new List(0), - Textures = new IKingdomTexture[0] - }; - - private readonly GraphicsDevice _graphics; - private readonly MeshGroup _mapMeshGroup; - private readonly MeshGroup _skybox0MeshGroup; - private readonly MeshGroup _skybox1MeshGroup; - private readonly List _bobEntities; - private readonly List _bobModels; - - public Coct CollisionOctalTree { get; } - public Coct ColorOctalTree { get; } - public Coct CameraOctalTree { get; } - public Doct DrawOctalTree { get; } - - public Kh2Map(GraphicsDevice graphics, Kernel kernel, int world, int area) : - this(graphics, kernel.DataContent, kernel.GetMapFileName(world, area)) - { } - - public Kh2Map(GraphicsDevice graphics, IDataContent content, string path) - { - _graphics = graphics; - - var binarc = content.FileOpen(path).Using(Bar.Read); - _skybox0MeshGroup = FromMdlx(graphics, binarc, "SK0") ?? Empty; - _skybox1MeshGroup = FromMdlx(graphics, binarc, "SK1") ?? Empty; - _mapMeshGroup = FromMdlx(graphics, binarc, "MAP") ?? Empty; - - CollisionOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.CollisionOctalTree, Coct.Read); - ColorOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.ColorOctalTree, Coct.Read); - CameraOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.CameraOctalTree, Coct.Read); - DrawOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.DrawOctalTree, Doct.Read); - - _bobEntities = binarc.ForEntry(x => x.Type == Bar.EntryType.BgObjPlacement, BobDescriptor.Read)? - .Select(x => new BobEntity(x)).ToList() ?? new List(); - - var bobModels = binarc.ForEntries("BOB", Bar.EntryType.Model, Mdlx.Read).ToList(); - var bobTextures = binarc.ForEntries("BOB", Bar.EntryType.ModelTexture, ModelTexture.Read).ToList(); - - _bobModels = new List(bobModels.Count); - for (var i = 0; i < bobModels.Count; i++) - { - _bobModels.Add(new MeshGroup - { - MeshDescriptors = MeshLoader.FromKH2(bobModels[i]).MeshDescriptors, - Textures = bobTextures[i].LoadTextures(graphics).ToArray() - }); - } - } - - public void Render(Camera camera, KingdomShader shader, EffectPass pass, bool passRenderOpaque) - { - shader.SetModelViewIdentity(); - pass.Apply(); - - _graphics.RenderMeshNew(shader, pass, _skybox0MeshGroup, passRenderOpaque); - _graphics.RenderMeshNew(shader, pass, _skybox1MeshGroup, passRenderOpaque); - _graphics.RenderMeshNew(shader, pass, _mapMeshGroup, passRenderOpaque); - - foreach (var bob in _bobEntities) - { - shader.SetModelView(bob.GetMatrix()); - pass.Apply(); - - _graphics.RenderMeshNew(shader, pass, _bobModels[bob.BobIndex], passRenderOpaque); - } - } - - public void Dispose() - { - Action clearMeshGroup = (meshGroup) => - { - foreach (var texture in meshGroup.Textures) - texture.Dispose(); - }; - - clearMeshGroup(_mapMeshGroup); - clearMeshGroup(_skybox0MeshGroup); - clearMeshGroup(_skybox1MeshGroup); - foreach (var bobModel in _bobModels) - clearMeshGroup(bobModel); - } - - private static MeshGroup FromMdlx(GraphicsDevice graphics, IEnumerable entries, string name) - { - var model = entries.ForEntry(name, Bar.EntryType.Model, Mdlx.Read); - if (model == null) - return null; - - var textures = entries.ForEntry(name, Bar.EntryType.ModelTexture, ModelTexture.Read); - if (model == null) - return null; - - return new MeshGroup - { - MeshDescriptors = MeshLoader.FromKH2(model).MeshDescriptors, - Textures = textures.LoadTextures(graphics).ToArray() - }; - } - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Common; +using OpenKh.Engine; +using OpenKh.Engine.MonoGame; +using OpenKh.Game.Entities; +using OpenKh.Game.Infrastructure; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using OpenKh.Kh2.Models; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Game.Field +{ + public class Kh2Map : IMap, IDisposable + { + private static readonly MeshGroup Empty = new MeshGroup + { + MeshDescriptors = new List(0), + Textures = new IKingdomTexture[0] + }; + + private readonly GraphicsDevice _graphics; + private readonly MeshGroup _mapMeshGroup; + private readonly MeshGroup _skybox0MeshGroup; + private readonly MeshGroup _skybox1MeshGroup; + private readonly List _bobEntities; + private readonly List _bobModels; + + public Coct CollisionOctalTree { get; } + public Coct ColorOctalTree { get; } + public Coct CameraOctalTree { get; } + public Doct DrawOctalTree { get; } + + public Kh2Map(GraphicsDevice graphics, Kernel kernel, int world, int area) : + this(graphics, kernel.DataContent, kernel.GetMapFileName(world, area)) + { } + + public Kh2Map(GraphicsDevice graphics, IDataContent content, string path) + { + _graphics = graphics; + + var binarc = content.FileOpen(path).Using(Bar.Read); + _skybox0MeshGroup = FromMdlx(graphics, binarc, "SK0") ?? Empty; + _skybox1MeshGroup = FromMdlx(graphics, binarc, "SK1") ?? Empty; + _mapMeshGroup = FromMdlx(graphics, binarc, "MAP") ?? Empty; + + CollisionOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.CollisionOctalTree, Coct.Read); + ColorOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.ColorOctalTree, Coct.Read); + CameraOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.CameraOctalTree, Coct.Read); + DrawOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.DrawOctalTree, Doct.Read); + + _bobEntities = binarc.ForEntry(x => x.Type == Bar.EntryType.BgObjPlacement, BobDescriptor.Read)? + .Select(x => new BobEntity(x)).ToList() ?? new List(); + + var bobModels = binarc.ForEntries("BOB", Bar.EntryType.Model, Mdlx.Read).ToList(); + var bobTextures = binarc.ForEntries("BOB", Bar.EntryType.ModelTexture, ModelTexture.Read).ToList(); + + _bobModels = new List(bobModels.Count); + for (var i = 0; i < bobModels.Count; i++) + { + _bobModels.Add(new MeshGroup + { + MeshDescriptors = MeshLoader.FromKH2(bobModels[i]).MeshDescriptors, + Textures = bobTextures[i].LoadTextures(graphics).ToArray() + }); + } + } + + public void Render(Camera camera, KingdomShader shader, EffectPass pass, bool passRenderOpaque) + { + shader.SetModelViewIdentity(); + pass.Apply(); + + _graphics.RenderMeshNew(shader, pass, _skybox0MeshGroup, passRenderOpaque); + _graphics.RenderMeshNew(shader, pass, _skybox1MeshGroup, passRenderOpaque); + _graphics.RenderMeshNew(shader, pass, _mapMeshGroup, passRenderOpaque); + + foreach (var bob in _bobEntities) + { + shader.SetModelView(bob.GetMatrix()); + pass.Apply(); + + _graphics.RenderMeshNew(shader, pass, _bobModels[bob.BobIndex], passRenderOpaque); + } + } + + public void Dispose() + { + Action clearMeshGroup = (meshGroup) => + { + foreach (var texture in meshGroup.Textures) + texture.Dispose(); + }; + + clearMeshGroup(_mapMeshGroup); + clearMeshGroup(_skybox0MeshGroup); + clearMeshGroup(_skybox1MeshGroup); + foreach (var bobModel in _bobModels) + clearMeshGroup(bobModel); + } + + private static MeshGroup FromMdlx(GraphicsDevice graphics, IEnumerable entries, string name) + { + var model = entries.ForEntry(name, Bar.EntryType.Model, Mdlx.Read); + if (model == null) + return null; + + var textures = entries.ForEntry(name, Bar.EntryType.ModelTexture, ModelTexture.Read); + if (model == null) + return null; + + return new MeshGroup + { + MeshDescriptors = MeshLoader.FromKH2(model).MeshDescriptors, + Textures = textures.LoadTextures(graphics).ToArray() + }; + } + } +} diff --git a/OpenKh.Game/Global.cs b/OpenKh.Game/Global.cs index 1a522c505..55f65afd2 100644 --- a/OpenKh.Game/Global.cs +++ b/OpenKh.Game/Global.cs @@ -1,9 +1,9 @@ -namespace OpenKh.Game -{ - public class Global - { - public const int ResolutionWidth = 512; - public const int ResolutionHeight = 416; - public const int ResolutionRemixWidth = 684; - } -} +namespace OpenKh.Game +{ + public class Global + { + public const int ResolutionWidth = 512; + public const int ResolutionHeight = 416; + public const int ResolutionRemixWidth = 684; + } +} diff --git a/OpenKh.Game/IGameContext.cs b/OpenKh.Game/IGameContext.cs index 018cc0dd4..1e7b14af8 100644 --- a/OpenKh.Game/IGameContext.cs +++ b/OpenKh.Game/IGameContext.cs @@ -1,14 +1,14 @@ -using OpenKh.Game.Field; -using OpenKh.Game.Infrastructure; - -namespace OpenKh.Game -{ - public interface IGameContext - { - public Kernel Kernel { get; } - public IField Field { get; } - - void LoadTitleScreen(); - void LoadPlace(int worldId, int placeId, int spawnIndex); - } -} +using OpenKh.Game.Field; +using OpenKh.Game.Infrastructure; + +namespace OpenKh.Game +{ + public interface IGameContext + { + public Kernel Kernel { get; } + public IField Field { get; } + + void LoadTitleScreen(); + void LoadPlace(int worldId, int placeId, int spawnIndex); + } +} diff --git a/OpenKh.Game/Infrastructure/ArchiveManager.cs b/OpenKh.Game/Infrastructure/ArchiveManager.cs index 15c559f8d..3a9cced5c 100644 --- a/OpenKh.Game/Infrastructure/ArchiveManager.cs +++ b/OpenKh.Game/Infrastructure/ArchiveManager.cs @@ -1,76 +1,82 @@ -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.IO; - -namespace OpenKh.Game.Infrastructure -{ - public class ArchiveManager - { - private class Entry - { - public Stream Stream { get; set; } - public object Object { get; set; } - } - - private readonly Dictionary> getters = new Dictionary> - { - [Bar.EntryType.Layout] = entry => Layout.Read(entry.Stream), - [Bar.EntryType.Seqd] = entry => Sequence.Read(entry.Stream), - [Bar.EntryType.Imgd] = entry => Imgd.Read(entry.Stream), - [Bar.EntryType.Imgz] = entry => new Imgz(entry.Stream), - [Bar.EntryType.Model] = entry => Mdlx.Read(entry.Stream), - [Bar.EntryType.ModelTexture] = entry => ModelTexture.Read(entry.Stream), - }; - - private readonly Dictionary<(string name, Bar.EntryType type), Entry> archives; - private readonly IDataContent dataContent; - - public ArchiveManager(IDataContent dataContent) - { - archives = new Dictionary<(string name, Bar.EntryType type), Entry>(); - this.dataContent = dataContent; - } - - public void LoadArchive(string fileName) - { - using var stream = dataContent.FileOpen(fileName); - LoadArchive(Bar.Read(stream)); - } - - public void LoadArchive(List entries) - { - foreach (var entry in entries) - archives[(entry.Name, entry.Type)] = new Entry - { - Stream = entry.Stream - }; - } - - public T Get(string resourceName) - where T : class - { - if (typeof(T) == typeof(Layout)) return GetItem(resourceName, Bar.EntryType.Layout); - if (typeof(T) == typeof(Sequence)) return GetItem(resourceName, Bar.EntryType.Seqd); - if (typeof(T) == typeof(Imgd)) return GetItem(resourceName, Bar.EntryType.Imgd); - if (typeof(T) == typeof(Imgz)) return GetItem(resourceName, Bar.EntryType.Imgz); - if (typeof(T) == typeof(Mdlx)) return GetItem(resourceName, Bar.EntryType.Model); - if (typeof(T) == typeof(ModelTexture)) return GetItem(resourceName, Bar.EntryType.ModelTexture); - return null; - } - - private T GetItem(string resourceName, Bar.EntryType type) - where T : class - { - if (!archives.TryGetValue((resourceName, type), out var entry)) - return null; - - if (entry.Object is T item) - return item; - - entry.Stream.Position = 0; - entry.Object = getters[type](entry); - return entry.Object as T; - } - } -} +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.IO; + +namespace OpenKh.Game.Infrastructure +{ + public class ArchiveManager + { + private class Entry + { + public Stream Stream { get; set; } + public object Object { get; set; } + } + + private readonly Dictionary> getters = new Dictionary> + { + [Bar.EntryType.Layout] = entry => Layout.Read(entry.Stream), + [Bar.EntryType.Seqd] = entry => Sequence.Read(entry.Stream), + [Bar.EntryType.Imgd] = entry => Imgd.Read(entry.Stream), + [Bar.EntryType.Imgz] = entry => new Imgz(entry.Stream), + [Bar.EntryType.Model] = entry => Mdlx.Read(entry.Stream), + [Bar.EntryType.ModelTexture] = entry => ModelTexture.Read(entry.Stream), + }; + + private readonly Dictionary<(string name, Bar.EntryType type), Entry> archives; + private readonly IDataContent dataContent; + + public ArchiveManager(IDataContent dataContent) + { + archives = new Dictionary<(string name, Bar.EntryType type), Entry>(); + this.dataContent = dataContent; + } + + public void LoadArchive(string fileName) + { + using var stream = dataContent.FileOpen(fileName); + LoadArchive(Bar.Read(stream)); + } + + public void LoadArchive(List entries) + { + foreach (var entry in entries) + archives[(entry.Name, entry.Type)] = new Entry + { + Stream = entry.Stream + }; + } + + public T Get(string resourceName) + where T : class + { + if (typeof(T) == typeof(Layout)) + return GetItem(resourceName, Bar.EntryType.Layout); + if (typeof(T) == typeof(Sequence)) + return GetItem(resourceName, Bar.EntryType.Seqd); + if (typeof(T) == typeof(Imgd)) + return GetItem(resourceName, Bar.EntryType.Imgd); + if (typeof(T) == typeof(Imgz)) + return GetItem(resourceName, Bar.EntryType.Imgz); + if (typeof(T) == typeof(Mdlx)) + return GetItem(resourceName, Bar.EntryType.Model); + if (typeof(T) == typeof(ModelTexture)) + return GetItem(resourceName, Bar.EntryType.ModelTexture); + return null; + } + + private T GetItem(string resourceName, Bar.EntryType type) + where T : class + { + if (!archives.TryGetValue((resourceName, type), out var entry)) + return null; + + if (entry.Object is T item) + return item; + + entry.Stream.Position = 0; + entry.Object = getters[type](entry); + return entry.Object as T; + } + } +} diff --git a/OpenKh.Game/Infrastructure/DeltaTimes.cs b/OpenKh.Game/Infrastructure/DeltaTimes.cs index 4e0008a37..725dd154a 100644 --- a/OpenKh.Game/Infrastructure/DeltaTimes.cs +++ b/OpenKh.Game/Infrastructure/DeltaTimes.cs @@ -1,7 +1,7 @@ -namespace OpenKh.Game.Infrastructure -{ - public class DeltaTimes - { - public double DeltaTime { get; set; } - } -} +namespace OpenKh.Game.Infrastructure +{ + public class DeltaTimes + { + public double DeltaTime { get; set; } + } +} diff --git a/OpenKh.Game/Infrastructure/IDataContent.cs b/OpenKh.Game/Infrastructure/IDataContent.cs index bd1dc5395..e484f4028 100644 --- a/OpenKh.Game/Infrastructure/IDataContent.cs +++ b/OpenKh.Game/Infrastructure/IDataContent.cs @@ -1,11 +1,11 @@ -using System.IO; - -namespace OpenKh.Game.Infrastructure -{ - public interface IDataContent - { - bool FileExists(string fileName); - - Stream FileOpen(string fileName); - } -} +using System.IO; + +namespace OpenKh.Game.Infrastructure +{ + public interface IDataContent + { + bool FileExists(string fileName); + + Stream FileOpen(string fileName); + } +} diff --git a/OpenKh.Game/Infrastructure/ILanguage.cs b/OpenKh.Game/Infrastructure/ILanguage.cs index 90094ac68..8411258d4 100644 --- a/OpenKh.Game/Infrastructure/ILanguage.cs +++ b/OpenKh.Game/Infrastructure/ILanguage.cs @@ -1,7 +1,7 @@ -namespace OpenKh.Game.Infrastructure -{ - public interface ILanguage - { - string Language { get; } - } -} +namespace OpenKh.Game.Infrastructure +{ + public interface ILanguage + { + string Language { get; } + } +} diff --git a/OpenKh.Game/Infrastructure/InputGamepad.cs b/OpenKh.Game/Infrastructure/InputGamepad.cs index b38fcdfa0..1742d7160 100644 --- a/OpenKh.Game/Infrastructure/InputGamepad.cs +++ b/OpenKh.Game/Infrastructure/InputGamepad.cs @@ -1,71 +1,71 @@ -using Microsoft.Xna.Framework.Input; -using OpenKh.Engine.Input; -using System; -using System.Numerics; - -namespace OpenKh.Game.Infrastructure -{ - public class InputGamepad : IInputDevice - { - private const float AxisDeadZone = 0.1f; - private const float TriggerDeadZone = 0.8f; - - public Vector3 AnalogLeft { get; private set; } - public Vector3 AnalogRight { get; private set; } - public bool Up { get; private set; } - public bool Down { get; private set; } - public bool Left { get; private set; } - public bool Right { get; private set; } - public bool FaceDown { get; private set; } - public bool FaceRight { get; private set; } - public bool FaceLeft { get; private set; } - public bool FaceUp { get; private set; } - public bool SpecialLeft { get; private set; } - public bool SpecialRight { get; private set; } - public bool L1 { get; private set; } - public bool L2 { get; private set; } - public bool L3 { get; private set; } - public bool R1 { get; private set; } - public bool R2 { get; private set; } - public bool R3 { get; private set; } - public bool Confirm => false; - public bool Cancel => false; - - public void Update() - { - var state = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One); - Up = state.DPad.Up == ButtonState.Pressed; - Down = state.DPad.Down == ButtonState.Pressed; - Left = state.DPad.Left == ButtonState.Pressed; - Right = state.DPad.Right == ButtonState.Pressed; - FaceDown = state.Buttons.A == ButtonState.Pressed; - FaceRight = state.Buttons.B == ButtonState.Pressed; - FaceLeft = state.Buttons.X == ButtonState.Pressed; - FaceUp = state.Buttons.Y == ButtonState.Pressed; - SpecialLeft = state.Buttons.Back == ButtonState.Pressed; - SpecialRight = state.Buttons.Start == ButtonState.Pressed; - L1 = state.Buttons.LeftShoulder == ButtonState.Pressed; - L3 = state.Buttons.LeftStick == ButtonState.Pressed; - R1 = state.Buttons.RightStick == ButtonState.Pressed; - R3 = state.Buttons.RightStick == ButtonState.Pressed; - - AnalogLeft = new Vector3( - ExcludeAxisDeadZone(state.ThumbSticks.Left.X), - ExcludeAxisDeadZone(state.ThumbSticks.Left.Y), - ExcludeAxisDeadZone(state.Triggers.Left)); - AnalogRight = new Vector3( - ExcludeAxisDeadZone(state.ThumbSticks.Right.X), - ExcludeAxisDeadZone(state.ThumbSticks.Right.Y), - ExcludeAxisDeadZone(state.Triggers.Right)); - - L2 = ExcludeTriggerDeadZone(AnalogLeft.Z); - R2 = ExcludeTriggerDeadZone(AnalogRight.Z); - } - - private static float ExcludeAxisDeadZone(float value) => - Math.Abs(value) < AxisDeadZone ? 0 : value; - - private static bool ExcludeTriggerDeadZone(float value) => - Math.Abs(value) >= TriggerDeadZone; - } -} +using Microsoft.Xna.Framework.Input; +using OpenKh.Engine.Input; +using System; +using System.Numerics; + +namespace OpenKh.Game.Infrastructure +{ + public class InputGamepad : IInputDevice + { + private const float AxisDeadZone = 0.1f; + private const float TriggerDeadZone = 0.8f; + + public Vector3 AnalogLeft { get; private set; } + public Vector3 AnalogRight { get; private set; } + public bool Up { get; private set; } + public bool Down { get; private set; } + public bool Left { get; private set; } + public bool Right { get; private set; } + public bool FaceDown { get; private set; } + public bool FaceRight { get; private set; } + public bool FaceLeft { get; private set; } + public bool FaceUp { get; private set; } + public bool SpecialLeft { get; private set; } + public bool SpecialRight { get; private set; } + public bool L1 { get; private set; } + public bool L2 { get; private set; } + public bool L3 { get; private set; } + public bool R1 { get; private set; } + public bool R2 { get; private set; } + public bool R3 { get; private set; } + public bool Confirm => false; + public bool Cancel => false; + + public void Update() + { + var state = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One); + Up = state.DPad.Up == ButtonState.Pressed; + Down = state.DPad.Down == ButtonState.Pressed; + Left = state.DPad.Left == ButtonState.Pressed; + Right = state.DPad.Right == ButtonState.Pressed; + FaceDown = state.Buttons.A == ButtonState.Pressed; + FaceRight = state.Buttons.B == ButtonState.Pressed; + FaceLeft = state.Buttons.X == ButtonState.Pressed; + FaceUp = state.Buttons.Y == ButtonState.Pressed; + SpecialLeft = state.Buttons.Back == ButtonState.Pressed; + SpecialRight = state.Buttons.Start == ButtonState.Pressed; + L1 = state.Buttons.LeftShoulder == ButtonState.Pressed; + L3 = state.Buttons.LeftStick == ButtonState.Pressed; + R1 = state.Buttons.RightStick == ButtonState.Pressed; + R3 = state.Buttons.RightStick == ButtonState.Pressed; + + AnalogLeft = new Vector3( + ExcludeAxisDeadZone(state.ThumbSticks.Left.X), + ExcludeAxisDeadZone(state.ThumbSticks.Left.Y), + ExcludeAxisDeadZone(state.Triggers.Left)); + AnalogRight = new Vector3( + ExcludeAxisDeadZone(state.ThumbSticks.Right.X), + ExcludeAxisDeadZone(state.ThumbSticks.Right.Y), + ExcludeAxisDeadZone(state.Triggers.Right)); + + L2 = ExcludeTriggerDeadZone(AnalogLeft.Z); + R2 = ExcludeTriggerDeadZone(AnalogRight.Z); + } + + private static float ExcludeAxisDeadZone(float value) => + Math.Abs(value) < AxisDeadZone ? 0 : value; + + private static bool ExcludeTriggerDeadZone(float value) => + Math.Abs(value) >= TriggerDeadZone; + } +} diff --git a/OpenKh.Game/Infrastructure/InputKeyboard.cs b/OpenKh.Game/Infrastructure/InputKeyboard.cs index 5d1708602..c55692212 100644 --- a/OpenKh.Game/Infrastructure/InputKeyboard.cs +++ b/OpenKh.Game/Infrastructure/InputKeyboard.cs @@ -1,110 +1,110 @@ -using Microsoft.Xna.Framework.Input; -using OpenKh.Engine.Input; -using System.Numerics; - -namespace OpenKh.Game.Infrastructure -{ - public class InputKeyboard : IInputDevice - { - private static readonly Keys[] ButtonBindings = new Keys[] - { - Keys.Up, - Keys.Down, - Keys.Left, - Keys.Right, - Keys.L, // FaceDown - Keys.K, // FaceRight - Keys.O, // FaceLeft - Keys.P, // FaceUp - Keys.Space, // SpecialLeft - Keys.Enter, // SpecialRight - Keys.U, // L1 - Keys.LeftShift, // L2 - Keys.D8, // L3 - Keys.I, // R1 - Keys.Tab, // R2 - Keys.D9, // R3 - - }; - private static readonly Keys[] AnalogBindings = new Keys[] - { - // Left - Keys.W, - Keys.S, - Keys.D, - Keys.A, - - // Right - Keys.Up, - Keys.Down, - Keys.Right, - Keys.Left, - }; - - public Vector3 AnalogLeft { get; private set; } - public Vector3 AnalogRight { get; private set; } - public bool Up { get; private set; } - public bool Down { get; private set; } - public bool Left { get; private set; } - public bool Right { get; private set; } - public bool FaceDown { get; private set; } - public bool FaceRight { get; private set; } - public bool FaceLeft { get; private set; } - public bool FaceUp { get; private set; } - public bool SpecialLeft { get; private set; } - public bool SpecialRight { get; private set; } - public bool L1 { get; private set; } - public bool L2 { get; private set; } - public bool L3 { get; private set; } - public bool R1 { get; private set; } - public bool R2 { get; private set; } - public bool R3 { get; private set; } - public bool Confirm => false; - public bool Cancel => false; - - public void Update() - { - var state = Keyboard.GetState(); - Up = state.IsKeyDown(ButtonBindings[0]); - Down = state.IsKeyDown(ButtonBindings[1]); - Left = state.IsKeyDown(ButtonBindings[2]); - Right = state.IsKeyDown(ButtonBindings[3]); - FaceDown = state.IsKeyDown(ButtonBindings[4]); - FaceRight = state.IsKeyDown(ButtonBindings[5]); - FaceLeft = state.IsKeyDown(ButtonBindings[6]); - FaceUp = state.IsKeyDown(ButtonBindings[7]); - SpecialLeft = state.IsKeyDown(ButtonBindings[8]); - SpecialRight = state.IsKeyDown(ButtonBindings[9]); - L1 = state.IsKeyDown(ButtonBindings[10]); - L2 = state.IsKeyDown(ButtonBindings[11]); - L3 = state.IsKeyDown(ButtonBindings[12]); - R1 = state.IsKeyDown(ButtonBindings[13]); - R2 = state.IsKeyDown(ButtonBindings[14]); - R3 = state.IsKeyDown(ButtonBindings[15]); - - float lx = 0f, ly = 0f, lz; - float rx = 0f, ry = 0f, rz; - if (state.IsKeyDown(AnalogBindings[0])) - ly += 1; - if (state.IsKeyDown(AnalogBindings[1])) - ly -= 1; - if (state.IsKeyDown(AnalogBindings[2])) - lx += 1; - if (state.IsKeyDown(AnalogBindings[3])) - lx -= 1; - lz = L2 ? 1f : 0f; - if (state.IsKeyDown(AnalogBindings[4])) - ry += 1; - if (state.IsKeyDown(AnalogBindings[5])) - ry -= 1; - if (state.IsKeyDown(AnalogBindings[6])) - rx += 1; - if (state.IsKeyDown(AnalogBindings[7])) - rx -= 1; - rz = R2 ? 1f : 0f; - - AnalogLeft = new Vector3(lx, ly, lz); - AnalogRight = new Vector3(rx, ry, rz); - } - } -} +using Microsoft.Xna.Framework.Input; +using OpenKh.Engine.Input; +using System.Numerics; + +namespace OpenKh.Game.Infrastructure +{ + public class InputKeyboard : IInputDevice + { + private static readonly Keys[] ButtonBindings = new Keys[] + { + Keys.Up, + Keys.Down, + Keys.Left, + Keys.Right, + Keys.L, // FaceDown + Keys.K, // FaceRight + Keys.O, // FaceLeft + Keys.P, // FaceUp + Keys.Space, // SpecialLeft + Keys.Enter, // SpecialRight + Keys.U, // L1 + Keys.LeftShift, // L2 + Keys.D8, // L3 + Keys.I, // R1 + Keys.Tab, // R2 + Keys.D9, // R3 + + }; + private static readonly Keys[] AnalogBindings = new Keys[] + { + // Left + Keys.W, + Keys.S, + Keys.D, + Keys.A, + + // Right + Keys.Up, + Keys.Down, + Keys.Right, + Keys.Left, + }; + + public Vector3 AnalogLeft { get; private set; } + public Vector3 AnalogRight { get; private set; } + public bool Up { get; private set; } + public bool Down { get; private set; } + public bool Left { get; private set; } + public bool Right { get; private set; } + public bool FaceDown { get; private set; } + public bool FaceRight { get; private set; } + public bool FaceLeft { get; private set; } + public bool FaceUp { get; private set; } + public bool SpecialLeft { get; private set; } + public bool SpecialRight { get; private set; } + public bool L1 { get; private set; } + public bool L2 { get; private set; } + public bool L3 { get; private set; } + public bool R1 { get; private set; } + public bool R2 { get; private set; } + public bool R3 { get; private set; } + public bool Confirm => false; + public bool Cancel => false; + + public void Update() + { + var state = Keyboard.GetState(); + Up = state.IsKeyDown(ButtonBindings[0]); + Down = state.IsKeyDown(ButtonBindings[1]); + Left = state.IsKeyDown(ButtonBindings[2]); + Right = state.IsKeyDown(ButtonBindings[3]); + FaceDown = state.IsKeyDown(ButtonBindings[4]); + FaceRight = state.IsKeyDown(ButtonBindings[5]); + FaceLeft = state.IsKeyDown(ButtonBindings[6]); + FaceUp = state.IsKeyDown(ButtonBindings[7]); + SpecialLeft = state.IsKeyDown(ButtonBindings[8]); + SpecialRight = state.IsKeyDown(ButtonBindings[9]); + L1 = state.IsKeyDown(ButtonBindings[10]); + L2 = state.IsKeyDown(ButtonBindings[11]); + L3 = state.IsKeyDown(ButtonBindings[12]); + R1 = state.IsKeyDown(ButtonBindings[13]); + R2 = state.IsKeyDown(ButtonBindings[14]); + R3 = state.IsKeyDown(ButtonBindings[15]); + + float lx = 0f, ly = 0f, lz; + float rx = 0f, ry = 0f, rz; + if (state.IsKeyDown(AnalogBindings[0])) + ly += 1; + if (state.IsKeyDown(AnalogBindings[1])) + ly -= 1; + if (state.IsKeyDown(AnalogBindings[2])) + lx += 1; + if (state.IsKeyDown(AnalogBindings[3])) + lx -= 1; + lz = L2 ? 1f : 0f; + if (state.IsKeyDown(AnalogBindings[4])) + ry += 1; + if (state.IsKeyDown(AnalogBindings[5])) + ry -= 1; + if (state.IsKeyDown(AnalogBindings[6])) + rx += 1; + if (state.IsKeyDown(AnalogBindings[7])) + rx -= 1; + rz = R2 ? 1f : 0f; + + AnalogLeft = new Vector3(lx, ly, lz); + AnalogRight = new Vector3(rx, ry, rz); + } + } +} diff --git a/OpenKh.Game/Infrastructure/Kernel.cs b/OpenKh.Game/Infrastructure/Kernel.cs index 97d0f3923..679b79745 100644 --- a/OpenKh.Game/Infrastructure/Kernel.cs +++ b/OpenKh.Game/Infrastructure/Kernel.cs @@ -1,336 +1,336 @@ -using OpenKh.Common; -using OpenKh.Common.Archives; -using OpenKh.Engine; -using OpenKh.Engine.Extensions; -using OpenKh.Engine.Renders; -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Kh2.Battle; -using OpenKh.Kh2.Contextes; -using OpenKh.Kh2.Extensions; -using OpenKh.Kh2.SaveData; -using OpenKh.Kh2.SystemData; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Game.Infrastructure -{ - public class Kernel : ILanguage - { - private readonly int _regionId; - - public bool IsFinalMix { get; } - public bool IsReMix { get; } - public int RegionId - { - get => Config.RegionId == -1 ? _regionId : Config.RegionId; - set => Config.RegionId = value; - } - public string Language => Constants.Languages[RegionId]; - public string Region => Constants.Regions[RegionId]; - public IDataContent DataContent { get; } - public FontContext FontContext { get; } - public RenderingMessageContext SystemMessageContext { get; set; } - public RenderingMessageContext EventMessageContext { get; set; } - public Kh2MessageProvider MessageProvider { get; } - - public ISaveData SaveData { get; private set; } - public List ObjEntries { get; } - public Dictionary> Places { get; } - - public bool DebugMode { get; set; } - - public int World - { - get => SaveData.WorldId; - set => SaveData.WorldId = (byte)value; - } - public int Area - { - get => SaveData.RoomId; - set => SaveData.RoomId = (byte)value; - } - public int Entrance - { - get => SaveData.SpawnId; - set => SaveData.SpawnId = (byte)value; - } - - public int SpawnMap => GetPlaceScript()?.Map ?? 0; - public int SpawnBtl => GetPlaceScript()?.Battle ?? 0; - public int SpawnEvt => GetPlaceScript()?.Event ?? 0; - public string SpawnName - { - get - { - var map = SpawnMap; - var btl = SpawnBtl; - var evt = SpawnEvt; - var strMap = map >= 0x19 ? map.ToString() : $"{(char)(map + 0x41)}"; - var strBtl = btl >= 0x19 ? map.ToString() : $"{(char)(btl + 0x41)}"; - var strEvt = evt >= 0x19 ? map.ToString() : $"{(char)(evt + 0x41)}"; - return $"{strMap}/{strBtl}/{strEvt}"; - } - } - - // System - public List> AreaInfo { get; private set; } - public List Ftst { get; private set; } - public Item Item { get; private set; } - public Memt MemberTable { get; private set; } - public List Trsr { get; private set; } - - // Battle - public List Fmlv { get; private set; } - public List Lvup { get; private set; } - - // 00worldpoint - public List WorldPoints { get; private set; } - - public Kernel(IDataContent dataContent) - { - Log.Info("Initialize kernel"); - DataContent = dataContent; - - FontContext = new FontContext(); - MessageProvider = new Kh2MessageProvider(); - _regionId = DetectRegion(dataContent); - Log.Info("Region={0} Language={1}", Region, Language); - - IsReMix = IsReMixFileExists(dataContent, Region); - Log.Info("ReMIX={0}", IsReMix); - - IsFinalMix = IsReMix || RegionId == (int)Constants.RegionId.FinalMix; - Log.Info("Final Mix={0}", IsFinalMix); - - // Load files in the same order as KH2 does - ObjEntries = LoadFile("00objentry.bin", stream => Objentry.Read(stream)); - // 00progress - LoadSystem("03system.bin"); - LoadBattle("00battle.bin"); - // 00common - LoadWorldPoint("00worldpoint.bin"); - // 07localset - // 12soundinfo - // 14mission - - LoadFontImage($"msg/{Language}/fontimage.bar"); - LoadFontInfo($"msg/{Language}/fontinfo.bar"); - Places = LoadFile($"msg/{Language}/place.bin", stream => Place.Read(stream)); - LoadMessage("sys"); - // 15jigsaw - - if (Language == "jp" && Config.EnforceInternationalTextEncoding == false) - { - Log.Info($"Use Japanese text encoding"); - SystemMessageContext = FontContext.ToKh2JpSystemTextContext(); - EventMessageContext = FontContext.ToKh2JpEventTextContext(); - } - else - { - Log.Info($"Use International text encoding"); - SystemMessageContext = FontContext.ToKh2EuSystemTextContext(); - EventMessageContext = FontContext.ToKh2EuEventTextContext(); - } - MessageProvider.Encoder = SystemMessageContext.Encoder; - SaveData = new SaveFinalMix() - { - WorldId = 2, - RoomId = 0, - SpawnId = 0, - Characters = Enumerable.Range(0, 13).Select(x => new CharacterFinalMix - { - Abilities = Enumerable.Range(0, 80).Select(x => (ushort)0).ToArray() - }).ToArray(), - DriveForms = Enumerable.Range(0, 10).Select(x => new DriveFormFinalMix - { - Abilities = Enumerable.Range(0, 24).Select(x => (ushort)0).ToArray() - }).ToArray(), - }; - } - - public string GetMapFileName(int worldIndex, int placeIndex) => IsReMix - ? $"map/{Constants.WorldIds[worldIndex]}{placeIndex:D02}.map" - : $"map/{Language}/{Constants.WorldIds[worldIndex]}{placeIndex:D02}.map"; - - public void LoadSaveData(string fileName) - { - var savePath = Path.Combine(Config.SavePath, fileName); - Log.Info("Attempting to load save {0}...", savePath); - if (File.Exists(savePath)) - File.OpenRead(savePath).Using(LoadSaveData); - else - Log.Warn("Save {0} not found", savePath); - } - - public bool LoadSaveData(Stream stream) - { - if (!SaveDataFactory.IsValid(stream)) - { - Log.Warn("Specified save game is not valid"); - return false; - } - - SaveData = SaveDataFactory.Read(stream); - Log.Info($"Save read successful. IsFinalMix={SaveData.IsFinalMix}"); - return true; - } - - private T LoadFile(string fileName, Func action) - { - using var stream = DataContent.FileOpen(fileName); - return action(stream); - } - - private void LoadSystem(string fileName) - { - var bar = DataContent.FileOpen(fileName).Using(stream => Bar.Read(stream)); - - AreaInfo = bar.ForEntry("arif", Bar.EntryType.List, Kh2.SystemData.Arif.Read); - Ftst = bar.ForEntry("ftst", Bar.EntryType.List, Kh2.SystemData.Ftst.Read); - Item = bar.ForEntry("item", Bar.EntryType.List, Kh2.SystemData.Item.Read); - MemberTable = bar.ForEntry("memt", Bar.EntryType.List, Kh2.SystemData.Memt.Read); - Trsr = bar.ForEntry("tsrs", Bar.EntryType.List, Kh2.SystemData.Trsr.Read); - } - - private void LoadBattle(string fileName) - { - var bar = DataContent.FileOpen(fileName).Using(stream => Bar.Read(stream)); - - Fmlv = bar.ForEntry("fmlv", Bar.EntryType.List, Kh2.Battle.Fmlv.Read); - Lvup = bar.ForEntry("lvup", Bar.EntryType.List, Kh2.Battle.Lvup.Read)?.Characters; - } - - private void LoadWorldPoint(string fileName) - { - WorldPoints = DataContent.FileOpen(fileName).Using(stream => WorldPoint.Read(stream)); - } - - private void LoadFontInfo(string fileName) - { - var bar = DataContent.FileOpen(fileName).Using(Bar.Read); - FontContext.Read(bar); - } - - private void LoadFontImage(string fileName) => - LoadFontInfo(fileName); - - private void LoadMessage(string worldId) - { - var messageBar = DataContent.FileOpen($"msg/{Language}/sys.bar") - .Using(stream => Bar.Read(stream)); - - MessageProvider.Load(messageBar.ForEntry(worldId, Bar.EntryType.List, Msg.Read)); - } - - private static int DetectRegion(IDataContent dataContent) - { - for (var i = 0; i < Constants.Regions.Length; i++) - { - var testFileName = $"menu/{Constants.Regions[i]}/title.2ld"; - if (dataContent.FileExists(testFileName)) - { - Log.Info("Region ID candidate: {0}", i); - return i; - } - } - - throw new Exception("Unable to detect any region for the game. Some files are potentially missing."); - } - - public static bool IsReMixFileExists(IDataContent dataContent, string region) - { - var testFileName = $"menu/{region}/titlejf.2ld"; - return dataContent.FileExists(testFileName); - } - - public static bool IsReMixFileHasHdAssetHeader(IDataContent dataContent, string region) - { - var testFileName = $"menu/{region}/titlejf.2ld"; - var stream = dataContent.FileOpen(testFileName); - if (stream == null) - return false; - - using (stream) - return HdAsset.IsValid(stream); - } - - public int GetRealObjectId(int objectId) - { - const int PLAYER = 0x236; - const int FRIEND_1 = 0x237; - const int FRIEND_2 = 0x238; - const int ACTOR_SORA = 0x23B; - const int ACTOR_SORA_H = 0x23C; - - if (IsFinalMix) - { - switch (objectId) - { - case PLAYER: - case ACTOR_SORA: - return GetRealObjectId(objectId, (int)MemberFinalMix.Sora); - case FRIEND_1: - return GetRealObjectId(objectId, (int)MemberFinalMix.Donald); - case FRIEND_2: - return GetRealObjectId(objectId, (int)MemberFinalMix.Goofy); - case ACTOR_SORA_H: - return GetRealObjectId(objectId, (int)MemberFinalMix.SoraHighPoly); - default: - return objectId; - } - } - else - { - switch (objectId) - { - case PLAYER: - case ACTOR_SORA: - return GetRealObjectId(objectId, (int)MemberVanilla.Sora); - case FRIEND_1: - return GetRealObjectId(objectId, (int)MemberVanilla.Donald); - case FRIEND_2: - return GetRealObjectId(objectId, (int)MemberVanilla.Goofy); - case ACTOR_SORA_H: - return GetRealObjectId(objectId, (int)MemberVanilla.SoraHighPoly); - default: - return objectId; - } - } - } - - private int GetRealObjectId(int objectId, int memberIndex) - { - if ((MemberTable?.Entries?.Count ?? 0) == 0) - return objectId; - - var defaultMemberTableEntry = MemberTable.Entries[0]; - var memberTableEntry = MemberTable.Entries - .FirstOrDefault(x => x.WorldId == World); - - if (memberIndex >= memberTableEntry.Members.Length) - return objectId; - - if (memberTableEntry.Members[memberIndex] != 0) - return memberTableEntry.Members[memberIndex]; - - if (defaultMemberTableEntry.Members[memberIndex] != 0) - return defaultMemberTableEntry.Members[memberIndex]; - - return objectId; - } - - private IPlaceScript GetPlaceScript() - { - var index = World * Constants.MaxAreaPerWorldCount + Area; - if (SaveData == null || - Area >= Constants.MaxAreaPerWorldCount || - index >= SaveData.PlaceScripts.Length) - return null; - - return SaveData.PlaceScripts[index]; - } - } -} +using OpenKh.Common; +using OpenKh.Common.Archives; +using OpenKh.Engine; +using OpenKh.Engine.Extensions; +using OpenKh.Engine.Renders; +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Kh2.Battle; +using OpenKh.Kh2.Contextes; +using OpenKh.Kh2.Extensions; +using OpenKh.Kh2.SaveData; +using OpenKh.Kh2.SystemData; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Game.Infrastructure +{ + public class Kernel : ILanguage + { + private readonly int _regionId; + + public bool IsFinalMix { get; } + public bool IsReMix { get; } + public int RegionId + { + get => Config.RegionId == -1 ? _regionId : Config.RegionId; + set => Config.RegionId = value; + } + public string Language => Constants.Languages[RegionId]; + public string Region => Constants.Regions[RegionId]; + public IDataContent DataContent { get; } + public FontContext FontContext { get; } + public RenderingMessageContext SystemMessageContext { get; set; } + public RenderingMessageContext EventMessageContext { get; set; } + public Kh2MessageProvider MessageProvider { get; } + + public ISaveData SaveData { get; private set; } + public List ObjEntries { get; } + public Dictionary> Places { get; } + + public bool DebugMode { get; set; } + + public int World + { + get => SaveData.WorldId; + set => SaveData.WorldId = (byte)value; + } + public int Area + { + get => SaveData.RoomId; + set => SaveData.RoomId = (byte)value; + } + public int Entrance + { + get => SaveData.SpawnId; + set => SaveData.SpawnId = (byte)value; + } + + public int SpawnMap => GetPlaceScript()?.Map ?? 0; + public int SpawnBtl => GetPlaceScript()?.Battle ?? 0; + public int SpawnEvt => GetPlaceScript()?.Event ?? 0; + public string SpawnName + { + get + { + var map = SpawnMap; + var btl = SpawnBtl; + var evt = SpawnEvt; + var strMap = map >= 0x19 ? map.ToString() : $"{(char)(map + 0x41)}"; + var strBtl = btl >= 0x19 ? map.ToString() : $"{(char)(btl + 0x41)}"; + var strEvt = evt >= 0x19 ? map.ToString() : $"{(char)(evt + 0x41)}"; + return $"{strMap}/{strBtl}/{strEvt}"; + } + } + + // System + public List> AreaInfo { get; private set; } + public List Ftst { get; private set; } + public Item Item { get; private set; } + public Memt MemberTable { get; private set; } + public List Trsr { get; private set; } + + // Battle + public List Fmlv { get; private set; } + public List Lvup { get; private set; } + + // 00worldpoint + public List WorldPoints { get; private set; } + + public Kernel(IDataContent dataContent) + { + Log.Info("Initialize kernel"); + DataContent = dataContent; + + FontContext = new FontContext(); + MessageProvider = new Kh2MessageProvider(); + _regionId = DetectRegion(dataContent); + Log.Info("Region={0} Language={1}", Region, Language); + + IsReMix = IsReMixFileExists(dataContent, Region); + Log.Info("ReMIX={0}", IsReMix); + + IsFinalMix = IsReMix || RegionId == (int)Constants.RegionId.FinalMix; + Log.Info("Final Mix={0}", IsFinalMix); + + // Load files in the same order as KH2 does + ObjEntries = LoadFile("00objentry.bin", stream => Objentry.Read(stream)); + // 00progress + LoadSystem("03system.bin"); + LoadBattle("00battle.bin"); + // 00common + LoadWorldPoint("00worldpoint.bin"); + // 07localset + // 12soundinfo + // 14mission + + LoadFontImage($"msg/{Language}/fontimage.bar"); + LoadFontInfo($"msg/{Language}/fontinfo.bar"); + Places = LoadFile($"msg/{Language}/place.bin", stream => Place.Read(stream)); + LoadMessage("sys"); + // 15jigsaw + + if (Language == "jp" && Config.EnforceInternationalTextEncoding == false) + { + Log.Info($"Use Japanese text encoding"); + SystemMessageContext = FontContext.ToKh2JpSystemTextContext(); + EventMessageContext = FontContext.ToKh2JpEventTextContext(); + } + else + { + Log.Info($"Use International text encoding"); + SystemMessageContext = FontContext.ToKh2EuSystemTextContext(); + EventMessageContext = FontContext.ToKh2EuEventTextContext(); + } + MessageProvider.Encoder = SystemMessageContext.Encoder; + SaveData = new SaveFinalMix() + { + WorldId = 2, + RoomId = 0, + SpawnId = 0, + Characters = Enumerable.Range(0, 13).Select(x => new CharacterFinalMix + { + Abilities = Enumerable.Range(0, 80).Select(x => (ushort)0).ToArray() + }).ToArray(), + DriveForms = Enumerable.Range(0, 10).Select(x => new DriveFormFinalMix + { + Abilities = Enumerable.Range(0, 24).Select(x => (ushort)0).ToArray() + }).ToArray(), + }; + } + + public string GetMapFileName(int worldIndex, int placeIndex) => IsReMix + ? $"map/{Constants.WorldIds[worldIndex]}{placeIndex:D02}.map" + : $"map/{Language}/{Constants.WorldIds[worldIndex]}{placeIndex:D02}.map"; + + public void LoadSaveData(string fileName) + { + var savePath = Path.Combine(Config.SavePath, fileName); + Log.Info("Attempting to load save {0}...", savePath); + if (File.Exists(savePath)) + File.OpenRead(savePath).Using(LoadSaveData); + else + Log.Warn("Save {0} not found", savePath); + } + + public bool LoadSaveData(Stream stream) + { + if (!SaveDataFactory.IsValid(stream)) + { + Log.Warn("Specified save game is not valid"); + return false; + } + + SaveData = SaveDataFactory.Read(stream); + Log.Info($"Save read successful. IsFinalMix={SaveData.IsFinalMix}"); + return true; + } + + private T LoadFile(string fileName, Func action) + { + using var stream = DataContent.FileOpen(fileName); + return action(stream); + } + + private void LoadSystem(string fileName) + { + var bar = DataContent.FileOpen(fileName).Using(stream => Bar.Read(stream)); + + AreaInfo = bar.ForEntry("arif", Bar.EntryType.List, Kh2.SystemData.Arif.Read); + Ftst = bar.ForEntry("ftst", Bar.EntryType.List, Kh2.SystemData.Ftst.Read); + Item = bar.ForEntry("item", Bar.EntryType.List, Kh2.SystemData.Item.Read); + MemberTable = bar.ForEntry("memt", Bar.EntryType.List, Kh2.SystemData.Memt.Read); + Trsr = bar.ForEntry("tsrs", Bar.EntryType.List, Kh2.SystemData.Trsr.Read); + } + + private void LoadBattle(string fileName) + { + var bar = DataContent.FileOpen(fileName).Using(stream => Bar.Read(stream)); + + Fmlv = bar.ForEntry("fmlv", Bar.EntryType.List, Kh2.Battle.Fmlv.Read); + Lvup = bar.ForEntry("lvup", Bar.EntryType.List, Kh2.Battle.Lvup.Read)?.Characters; + } + + private void LoadWorldPoint(string fileName) + { + WorldPoints = DataContent.FileOpen(fileName).Using(stream => WorldPoint.Read(stream)); + } + + private void LoadFontInfo(string fileName) + { + var bar = DataContent.FileOpen(fileName).Using(Bar.Read); + FontContext.Read(bar); + } + + private void LoadFontImage(string fileName) => + LoadFontInfo(fileName); + + private void LoadMessage(string worldId) + { + var messageBar = DataContent.FileOpen($"msg/{Language}/sys.bar") + .Using(stream => Bar.Read(stream)); + + MessageProvider.Load(messageBar.ForEntry(worldId, Bar.EntryType.List, Msg.Read)); + } + + private static int DetectRegion(IDataContent dataContent) + { + for (var i = 0; i < Constants.Regions.Length; i++) + { + var testFileName = $"menu/{Constants.Regions[i]}/title.2ld"; + if (dataContent.FileExists(testFileName)) + { + Log.Info("Region ID candidate: {0}", i); + return i; + } + } + + throw new Exception("Unable to detect any region for the game. Some files are potentially missing."); + } + + public static bool IsReMixFileExists(IDataContent dataContent, string region) + { + var testFileName = $"menu/{region}/titlejf.2ld"; + return dataContent.FileExists(testFileName); + } + + public static bool IsReMixFileHasHdAssetHeader(IDataContent dataContent, string region) + { + var testFileName = $"menu/{region}/titlejf.2ld"; + var stream = dataContent.FileOpen(testFileName); + if (stream == null) + return false; + + using (stream) + return HdAsset.IsValid(stream); + } + + public int GetRealObjectId(int objectId) + { + const int PLAYER = 0x236; + const int FRIEND_1 = 0x237; + const int FRIEND_2 = 0x238; + const int ACTOR_SORA = 0x23B; + const int ACTOR_SORA_H = 0x23C; + + if (IsFinalMix) + { + switch (objectId) + { + case PLAYER: + case ACTOR_SORA: + return GetRealObjectId(objectId, (int)MemberFinalMix.Sora); + case FRIEND_1: + return GetRealObjectId(objectId, (int)MemberFinalMix.Donald); + case FRIEND_2: + return GetRealObjectId(objectId, (int)MemberFinalMix.Goofy); + case ACTOR_SORA_H: + return GetRealObjectId(objectId, (int)MemberFinalMix.SoraHighPoly); + default: + return objectId; + } + } + else + { + switch (objectId) + { + case PLAYER: + case ACTOR_SORA: + return GetRealObjectId(objectId, (int)MemberVanilla.Sora); + case FRIEND_1: + return GetRealObjectId(objectId, (int)MemberVanilla.Donald); + case FRIEND_2: + return GetRealObjectId(objectId, (int)MemberVanilla.Goofy); + case ACTOR_SORA_H: + return GetRealObjectId(objectId, (int)MemberVanilla.SoraHighPoly); + default: + return objectId; + } + } + } + + private int GetRealObjectId(int objectId, int memberIndex) + { + if ((MemberTable?.Entries?.Count ?? 0) == 0) + return objectId; + + var defaultMemberTableEntry = MemberTable.Entries[0]; + var memberTableEntry = MemberTable.Entries + .FirstOrDefault(x => x.WorldId == World); + + if (memberIndex >= memberTableEntry.Members.Length) + return objectId; + + if (memberTableEntry.Members[memberIndex] != 0) + return memberTableEntry.Members[memberIndex]; + + if (defaultMemberTableEntry.Members[memberIndex] != 0) + return defaultMemberTableEntry.Members[memberIndex]; + + return objectId; + } + + private IPlaceScript GetPlaceScript() + { + var index = World * Constants.MaxAreaPerWorldCount + Area; + if (SaveData == null || + Area >= Constants.MaxAreaPerWorldCount || + index >= SaveData.PlaceScripts.Length) + return null; + + return SaveData.PlaceScripts[index]; + } + } +} diff --git a/OpenKh.Game/Infrastructure/StateInitDesc.cs b/OpenKh.Game/Infrastructure/StateInitDesc.cs index 4a3b45b47..b860a6988 100644 --- a/OpenKh.Game/Infrastructure/StateInitDesc.cs +++ b/OpenKh.Game/Infrastructure/StateInitDesc.cs @@ -1,20 +1,20 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; -using OpenKh.Engine.Input; -using OpenKh.Game.States; -using System.Collections.Generic; - -namespace OpenKh.Game.Infrastructure -{ - public class StateInitDesc - { - public IDataContent DataContent { get; set; } - public ArchiveManager ArchiveManager { get; set; } - public Kernel Kernel { get; set; } - public IInput Input { get; set; } - public ContentManager ContentManager { get; set; } - public GraphicsDeviceManager GraphicsDevice { get; set; } - public IStateChange StateChange { get; set; } - public Dictionary StateSettings { get; set; } - } -} +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using OpenKh.Engine.Input; +using OpenKh.Game.States; +using System.Collections.Generic; + +namespace OpenKh.Game.Infrastructure +{ + public class StateInitDesc + { + public IDataContent DataContent { get; set; } + public ArchiveManager ArchiveManager { get; set; } + public Kernel Kernel { get; set; } + public IInput Input { get; set; } + public ContentManager ContentManager { get; set; } + public GraphicsDeviceManager GraphicsDevice { get; set; } + public IStateChange StateChange { get; set; } + public Dictionary StateSettings { get; set; } + } +} diff --git a/OpenKh.Game/Menu/IMenu.cs b/OpenKh.Game/Menu/IMenu.cs index 06a6c1699..1a37a8900 100644 --- a/OpenKh.Game/Menu/IMenu.cs +++ b/OpenKh.Game/Menu/IMenu.cs @@ -1,15 +1,15 @@ -namespace OpenKh.Game.Menu -{ - public interface IMenu - { - ushort MenuNameId { get; } - bool IsClosed { get; } - - void Open(); - void Close(); - void Push(IMenu subMenu); - - void Update(double deltaTime); - void Draw(); - } -} +namespace OpenKh.Game.Menu +{ + public interface IMenu + { + ushort MenuNameId { get; } + bool IsClosed { get; } + + void Open(); + void Close(); + void Push(IMenu subMenu); + + void Update(double deltaTime); + void Draw(); + } +} diff --git a/OpenKh.Game/Menu/IMenuManager.cs b/OpenKh.Game/Menu/IMenuManager.cs index 88d0590eb..71ca25153 100644 --- a/OpenKh.Game/Menu/IMenuManager.cs +++ b/OpenKh.Game/Menu/IMenuManager.cs @@ -1,17 +1,17 @@ -using OpenKh.Engine.Input; - -namespace OpenKh.Game.Menu -{ - public interface IMenuManager - { - IGameContext GameContext { get; } - AnimatedSequenceFactory SequenceFactory { get; } - IInput Input { get; } - - void PushSubMenuDescription(ushort messageId); - void PushSubMenuDescription(string message); - void PopSubMenuDescription(); - void SetElementDescription(ushort messageId); - void CloseAllMenu(); - } -} +using OpenKh.Engine.Input; + +namespace OpenKh.Game.Menu +{ + public interface IMenuManager + { + IGameContext GameContext { get; } + AnimatedSequenceFactory SequenceFactory { get; } + IInput Input { get; } + + void PushSubMenuDescription(ushort messageId); + void PushSubMenuDescription(string message); + void PopSubMenuDescription(); + void SetElementDescription(ushort messageId); + void CloseAllMenu(); + } +} diff --git a/OpenKh.Game/Menu/MainMenu.cs b/OpenKh.Game/Menu/MainMenu.cs index 1daf5d2c3..1b02a667e 100644 --- a/OpenKh.Game/Menu/MainMenu.cs +++ b/OpenKh.Game/Menu/MainMenu.cs @@ -1,320 +1,320 @@ -using OpenKh.Engine.Input; -using OpenKh.Engine.Renderers; -using OpenKh.Game.Infrastructure; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Game.Menu -{ - public class MainMenu : MenuBase - { - private const int MaxCharacterCount = 4; - private const int MaxMenuElementCount = 8; - private const int CharacterHpBar = 98; - private const int CharacterMpBar = 99; - private const int MsgLv = 0x39FC; - private const int MsgHp = 0x39FD; - private const int MsgMp = 0x39FE; - private static readonly ushort[] MenuOptions = new ushort[MaxMenuElementCount] - { - 0x844b, // Items - 0x844d, // Abilities - 0x8451, // Customize - 0x844e, // Party - 0x844f, // Status - 0x8450, // Journal - 0x8450, // Journal - 0xb617, // Config - }; - private static readonly ushort[] CharacterNames = new ushort[MaxCharacterCount] - { - 0x851f, // Sora - 0x8520, // Donald - 0x8521, // Goofy - 0x852c, // Riku - }; - - private IAnimatedSequence _backgroundSeq; - private IAnimatedSequence _menuSeq; - private IAnimatedSequence _characterSeq; - - private int _optionCount = 0; - private int _optionSelected = 0; - private bool _isDebugMenuVisible; - - public override ushort MenuNameId => 0; - protected override bool IsEnd => - _backgroundSeq.IsEnd && - _menuSeq.IsEnd && - _characterSeq.IsEnd; - - public int SelectedOption - { - get => _optionSelected; - set - { - if (_optionCount == 0) - return; - - _optionSelected = value; - if (_optionSelected < 0) - _optionSelected += _optionCount; - _optionSelected %= _optionCount; - - InvalidateMenu(); - } - } - - public bool IsDebugMenuVisible - { - get => _isDebugMenuVisible; - set - { - if (_isDebugMenuVisible != value) - { - _isDebugMenuVisible = value; - InvalidateMenu(); - } - } - } - - public MainMenu(IMenuManager menuManager) : base(menuManager) - { - InitializeMenu(); - } - - private void InvalidateMenu() - { - var frame = _menuSeq.FrameIndex; - _menuSeq = InitializeMenuOptions(true); - _menuSeq.Begin(); - _menuSeq.FrameIndex = frame; - } - - private void InitializeMenu() - { - _backgroundSeq = SequenceFactory.Create(new AnimatedSequenceDesc - { - SequenceIndexStart = 46, - SequenceIndexLoop = 47, - SequenceIndexEnd = 48, - }); - _menuSeq = InitializeMenuOptions(); - - _characterSeq = SequenceFactory.Create(Enumerable.Range(0, 5) - .Select(i => new AnimatedSequenceDesc - { - SequenceIndexStart = 101, - SequenceIndexLoop = 102, - SequenceIndexEnd = 103, - StackIndex = i + 1, - StackWidth = AnimatedSequenceDesc.DefaultStacking, - Children = new List() - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = 93, - Children = new List() - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = 124, - MessageText = "Donald", - Flags = AnimationFlags.TextIgnoreColor, - TextAnchor = TextAnchor.BottomCenter, - }, - new AnimatedSequenceDesc() - { - SequenceIndexLoop = 90, - Children = new List() - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = 124, - MessageId = MsgLv, - TextAnchor = TextAnchor.BottomLeft, - }, - new AnimatedSequenceDesc - { - SequenceIndexLoop = 124, - MessageText = "99", - TextAnchor = TextAnchor.BottomRight, - }, - new AnimatedSequenceDesc() - { - StackIndex = 1, - SequenceIndexLoop = 121, - MessageId = MsgHp, - TextAnchor = TextAnchor.BottomLeft, - }, - new AnimatedSequenceDesc() - { - StackIndex = 1, - SequenceIndexLoop = 121, - MessageText = "60/60", - TextAnchor = TextAnchor.BottomRight, - }, - new AnimatedSequenceDesc() - { - StackIndex = 1, - SequenceIndexLoop = CharacterHpBar, - TextAnchor = TextAnchor.BottomLeft, - }, - new AnimatedSequenceDesc() - { - StackIndex = 2, - SequenceIndexLoop = 118, - MessageId = MsgMp, - TextAnchor = TextAnchor.BottomLeft, - }, - new AnimatedSequenceDesc() - { - StackIndex = 2, - SequenceIndexLoop = 118, - MessageText = "120/120", - TextAnchor = TextAnchor.BottomRight, - }, - new AnimatedSequenceDesc() - { - StackIndex = 2, - SequenceIndexLoop = CharacterMpBar, - TextAnchor = TextAnchor.BottomLeft, - }, - } - }, - } - } - } - }) - ); - } - - protected override void ProcessInput(IInput input) - { - if (input.Repeated.Up) - SelectedOption--; - if (input.Repeated.Down) - SelectedOption++; - if (input.Triggered.Confirm) - { - switch (SelectedOption) - { - case 4: - Push(new MenuStatus(MenuManager)); - break; - case 6: - if (_isDebugMenuVisible) - Push(new MenuDebug(MenuManager)); - else - Push(new MenuConfig(MenuManager)); - break; - default: - Push(new MenuTemplate(MenuManager, 0)); - break; - } - } - else if (input.Triggered.Cancel) - MenuManager.CloseAllMenu(); - - IsDebugMenuVisible = input.Pressed.R2; - } - - private IAnimatedSequence InitializeMenuOptions(bool skipIntro = false) - { - const int MenuOptionsBitfields = 0xbf; - var menuDesc = new List(); - var menuOptions = MenuOptionsBitfields; - - _optionCount = 0; - for (int bitIndex = 0; menuOptions > 0; bitIndex++) - { - var bitMask = 1 << bitIndex; - if ((menuOptions & bitMask) == 0) - continue; - menuOptions -= bitMask; - if (_optionCount >= MenuOptions.Length) - break; - - string overrideTextField = null; - if (bitIndex == 7 && _isDebugMenuVisible) - overrideTextField = MenuDebug.Name; - - AnimatedSequenceDesc desc = _optionCount != _optionSelected - ? new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 133, - SequenceIndexLoop = 134, - SequenceIndexEnd = 135, - StackIndex = _optionCount, - StackWidth = 0, - StackHeight = AnimatedSequenceDesc.DefaultStacking, - MessageId = MenuOptions[bitIndex], - MessageText = overrideTextField, - Flags = AnimationFlags.TextTranslateX, - } - : new AnimatedSequenceDesc - { - SequenceIndexLoop = 132, - SequenceIndexEnd = 135, - StackIndex = _optionCount, - StackWidth = 0, - StackHeight = AnimatedSequenceDesc.DefaultStacking, - MessageId = MenuOptions[bitIndex], - MessageText = overrideTextField, - Flags = AnimationFlags.TextTranslateX | - AnimationFlags.ChildStackHorizontally, - Children = new List - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = 25, - TextAnchor = TextAnchor.BottomLeft, - Flags = AnimationFlags.NoChildTranslationX, - }, - new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 27, - SequenceIndexLoop = 28, - SequenceIndexEnd = 29, - } - } - }; - menuDesc.Add(desc); - - _optionCount++; - } - - return SequenceFactory.Create(menuDesc); - } - - public override void Open() - { - _backgroundSeq.Begin(); - _menuSeq.Begin(); - _characterSeq.Begin(); - base.Open(); - } - - public override void Close() - { - _backgroundSeq.End(); - _menuSeq.End(); - _characterSeq.End(); - base.Close(); - } - - protected override void MyUpdate(double deltaTime) - { - _backgroundSeq.Update(deltaTime); - _menuSeq.Update(deltaTime); - _characterSeq.Update(deltaTime); - } - - protected override void MyDraw() - { - _backgroundSeq.Draw(0, 0); - _menuSeq.Draw(0, 0); - _characterSeq.Draw(0, 0); - } - } -} +using OpenKh.Engine.Input; +using OpenKh.Engine.Renderers; +using OpenKh.Game.Infrastructure; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Game.Menu +{ + public class MainMenu : MenuBase + { + private const int MaxCharacterCount = 4; + private const int MaxMenuElementCount = 8; + private const int CharacterHpBar = 98; + private const int CharacterMpBar = 99; + private const int MsgLv = 0x39FC; + private const int MsgHp = 0x39FD; + private const int MsgMp = 0x39FE; + private static readonly ushort[] MenuOptions = new ushort[MaxMenuElementCount] + { + 0x844b, // Items + 0x844d, // Abilities + 0x8451, // Customize + 0x844e, // Party + 0x844f, // Status + 0x8450, // Journal + 0x8450, // Journal + 0xb617, // Config + }; + private static readonly ushort[] CharacterNames = new ushort[MaxCharacterCount] + { + 0x851f, // Sora + 0x8520, // Donald + 0x8521, // Goofy + 0x852c, // Riku + }; + + private IAnimatedSequence _backgroundSeq; + private IAnimatedSequence _menuSeq; + private IAnimatedSequence _characterSeq; + + private int _optionCount = 0; + private int _optionSelected = 0; + private bool _isDebugMenuVisible; + + public override ushort MenuNameId => 0; + protected override bool IsEnd => + _backgroundSeq.IsEnd && + _menuSeq.IsEnd && + _characterSeq.IsEnd; + + public int SelectedOption + { + get => _optionSelected; + set + { + if (_optionCount == 0) + return; + + _optionSelected = value; + if (_optionSelected < 0) + _optionSelected += _optionCount; + _optionSelected %= _optionCount; + + InvalidateMenu(); + } + } + + public bool IsDebugMenuVisible + { + get => _isDebugMenuVisible; + set + { + if (_isDebugMenuVisible != value) + { + _isDebugMenuVisible = value; + InvalidateMenu(); + } + } + } + + public MainMenu(IMenuManager menuManager) : base(menuManager) + { + InitializeMenu(); + } + + private void InvalidateMenu() + { + var frame = _menuSeq.FrameIndex; + _menuSeq = InitializeMenuOptions(true); + _menuSeq.Begin(); + _menuSeq.FrameIndex = frame; + } + + private void InitializeMenu() + { + _backgroundSeq = SequenceFactory.Create(new AnimatedSequenceDesc + { + SequenceIndexStart = 46, + SequenceIndexLoop = 47, + SequenceIndexEnd = 48, + }); + _menuSeq = InitializeMenuOptions(); + + _characterSeq = SequenceFactory.Create(Enumerable.Range(0, 5) + .Select(i => new AnimatedSequenceDesc + { + SequenceIndexStart = 101, + SequenceIndexLoop = 102, + SequenceIndexEnd = 103, + StackIndex = i + 1, + StackWidth = AnimatedSequenceDesc.DefaultStacking, + Children = new List() + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = 93, + Children = new List() + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = 124, + MessageText = "Donald", + Flags = AnimationFlags.TextIgnoreColor, + TextAnchor = TextAnchor.BottomCenter, + }, + new AnimatedSequenceDesc() + { + SequenceIndexLoop = 90, + Children = new List() + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = 124, + MessageId = MsgLv, + TextAnchor = TextAnchor.BottomLeft, + }, + new AnimatedSequenceDesc + { + SequenceIndexLoop = 124, + MessageText = "99", + TextAnchor = TextAnchor.BottomRight, + }, + new AnimatedSequenceDesc() + { + StackIndex = 1, + SequenceIndexLoop = 121, + MessageId = MsgHp, + TextAnchor = TextAnchor.BottomLeft, + }, + new AnimatedSequenceDesc() + { + StackIndex = 1, + SequenceIndexLoop = 121, + MessageText = "60/60", + TextAnchor = TextAnchor.BottomRight, + }, + new AnimatedSequenceDesc() + { + StackIndex = 1, + SequenceIndexLoop = CharacterHpBar, + TextAnchor = TextAnchor.BottomLeft, + }, + new AnimatedSequenceDesc() + { + StackIndex = 2, + SequenceIndexLoop = 118, + MessageId = MsgMp, + TextAnchor = TextAnchor.BottomLeft, + }, + new AnimatedSequenceDesc() + { + StackIndex = 2, + SequenceIndexLoop = 118, + MessageText = "120/120", + TextAnchor = TextAnchor.BottomRight, + }, + new AnimatedSequenceDesc() + { + StackIndex = 2, + SequenceIndexLoop = CharacterMpBar, + TextAnchor = TextAnchor.BottomLeft, + }, + } + }, + } + } + } + }) + ); + } + + protected override void ProcessInput(IInput input) + { + if (input.Repeated.Up) + SelectedOption--; + if (input.Repeated.Down) + SelectedOption++; + if (input.Triggered.Confirm) + { + switch (SelectedOption) + { + case 4: + Push(new MenuStatus(MenuManager)); + break; + case 6: + if (_isDebugMenuVisible) + Push(new MenuDebug(MenuManager)); + else + Push(new MenuConfig(MenuManager)); + break; + default: + Push(new MenuTemplate(MenuManager, 0)); + break; + } + } + else if (input.Triggered.Cancel) + MenuManager.CloseAllMenu(); + + IsDebugMenuVisible = input.Pressed.R2; + } + + private IAnimatedSequence InitializeMenuOptions(bool skipIntro = false) + { + const int MenuOptionsBitfields = 0xbf; + var menuDesc = new List(); + var menuOptions = MenuOptionsBitfields; + + _optionCount = 0; + for (int bitIndex = 0; menuOptions > 0; bitIndex++) + { + var bitMask = 1 << bitIndex; + if ((menuOptions & bitMask) == 0) + continue; + menuOptions -= bitMask; + if (_optionCount >= MenuOptions.Length) + break; + + string overrideTextField = null; + if (bitIndex == 7 && _isDebugMenuVisible) + overrideTextField = MenuDebug.Name; + + AnimatedSequenceDesc desc = _optionCount != _optionSelected + ? new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 133, + SequenceIndexLoop = 134, + SequenceIndexEnd = 135, + StackIndex = _optionCount, + StackWidth = 0, + StackHeight = AnimatedSequenceDesc.DefaultStacking, + MessageId = MenuOptions[bitIndex], + MessageText = overrideTextField, + Flags = AnimationFlags.TextTranslateX, + } + : new AnimatedSequenceDesc + { + SequenceIndexLoop = 132, + SequenceIndexEnd = 135, + StackIndex = _optionCount, + StackWidth = 0, + StackHeight = AnimatedSequenceDesc.DefaultStacking, + MessageId = MenuOptions[bitIndex], + MessageText = overrideTextField, + Flags = AnimationFlags.TextTranslateX | + AnimationFlags.ChildStackHorizontally, + Children = new List + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = 25, + TextAnchor = TextAnchor.BottomLeft, + Flags = AnimationFlags.NoChildTranslationX, + }, + new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 27, + SequenceIndexLoop = 28, + SequenceIndexEnd = 29, + } + } + }; + menuDesc.Add(desc); + + _optionCount++; + } + + return SequenceFactory.Create(menuDesc); + } + + public override void Open() + { + _backgroundSeq.Begin(); + _menuSeq.Begin(); + _characterSeq.Begin(); + base.Open(); + } + + public override void Close() + { + _backgroundSeq.End(); + _menuSeq.End(); + _characterSeq.End(); + base.Close(); + } + + protected override void MyUpdate(double deltaTime) + { + _backgroundSeq.Update(deltaTime); + _menuSeq.Update(deltaTime); + _characterSeq.Update(deltaTime); + } + + protected override void MyDraw() + { + _backgroundSeq.Draw(0, 0); + _menuSeq.Draw(0, 0); + _characterSeq.Draw(0, 0); + } + } +} diff --git a/OpenKh.Game/Menu/MenuBase.cs b/OpenKh.Game/Menu/MenuBase.cs index dd833c4f0..696a3faf5 100644 --- a/OpenKh.Game/Menu/MenuBase.cs +++ b/OpenKh.Game/Menu/MenuBase.cs @@ -1,87 +1,87 @@ -using OpenKh.Engine.Input; -using OpenKh.Game.Infrastructure; - -namespace OpenKh.Game.Menu -{ - public abstract class MenuBase : IMenu - { - private bool _isClosing; - private IMenu _subMenu; - - protected IMenuManager MenuManager { get; } - protected AnimatedSequenceFactory SequenceFactory => MenuManager.SequenceFactory; - protected IInput Input => MenuManager.Input; - abstract protected bool IsEnd { get; } - abstract public ushort MenuNameId { get; } - public bool IsClosed { get; private set; } - - public MenuBase(IMenuManager menuManager) - { - MenuManager = menuManager; - } - - virtual protected void ProcessInput(IInput input) - { - if (input.Triggered.Cancel) - Close(); - } - - virtual public void Open() - { - _isClosing = false; - } - - virtual public void Close() - { - _isClosing = true; - _subMenu?.Close(); - } - - virtual public void Push(IMenu subMenu) - { - Close(); - _subMenu = subMenu; - _subMenu.Open(); - - if (subMenu.MenuNameId == 0) - MenuManager.PushSubMenuDescription(subMenu.ToString()); - else - MenuManager.PushSubMenuDescription(subMenu.MenuNameId); - } - - public void Update(double deltaTime) - { - if (!IsEnd) - MyUpdate(deltaTime); - - if (_subMenu == null) - { - if (!_isClosing) - ProcessInput(Input); - - IsClosed = IsEnd; - } - else - { - _subMenu.Update(deltaTime); - if (_subMenu.IsClosed) - { - _subMenu = null; - MenuManager.PopSubMenuDescription(); - Open(); - } - } - } - - public void Draw() - { - if (_subMenu == null || !IsEnd) - MyDraw(); - else - _subMenu.Draw(); - } - - abstract protected void MyUpdate(double deltaTime); - abstract protected void MyDraw(); - } -} +using OpenKh.Engine.Input; +using OpenKh.Game.Infrastructure; + +namespace OpenKh.Game.Menu +{ + public abstract class MenuBase : IMenu + { + private bool _isClosing; + private IMenu _subMenu; + + protected IMenuManager MenuManager { get; } + protected AnimatedSequenceFactory SequenceFactory => MenuManager.SequenceFactory; + protected IInput Input => MenuManager.Input; + abstract protected bool IsEnd { get; } + abstract public ushort MenuNameId { get; } + public bool IsClosed { get; private set; } + + public MenuBase(IMenuManager menuManager) + { + MenuManager = menuManager; + } + + virtual protected void ProcessInput(IInput input) + { + if (input.Triggered.Cancel) + Close(); + } + + virtual public void Open() + { + _isClosing = false; + } + + virtual public void Close() + { + _isClosing = true; + _subMenu?.Close(); + } + + virtual public void Push(IMenu subMenu) + { + Close(); + _subMenu = subMenu; + _subMenu.Open(); + + if (subMenu.MenuNameId == 0) + MenuManager.PushSubMenuDescription(subMenu.ToString()); + else + MenuManager.PushSubMenuDescription(subMenu.MenuNameId); + } + + public void Update(double deltaTime) + { + if (!IsEnd) + MyUpdate(deltaTime); + + if (_subMenu == null) + { + if (!_isClosing) + ProcessInput(Input); + + IsClosed = IsEnd; + } + else + { + _subMenu.Update(deltaTime); + if (_subMenu.IsClosed) + { + _subMenu = null; + MenuManager.PopSubMenuDescription(); + Open(); + } + } + } + + public void Draw() + { + if (_subMenu == null || !IsEnd) + MyDraw(); + else + _subMenu.Draw(); + } + + abstract protected void MyUpdate(double deltaTime); + abstract protected void MyDraw(); + } +} diff --git a/OpenKh.Game/Menu/MenuConfig.cs b/OpenKh.Game/Menu/MenuConfig.cs index a2ed02da4..8923caacc 100644 --- a/OpenKh.Game/Menu/MenuConfig.cs +++ b/OpenKh.Game/Menu/MenuConfig.cs @@ -1,377 +1,377 @@ -using OpenKh.Engine.Input; -using OpenKh.Engine.Renderers; -using OpenKh.Game.Infrastructure; -using System; -using System.Collections.Generic; - -namespace OpenKh.Game.Menu -{ - public class MenuConfig : MenuBase - { - private enum Options : int - { - FieldCamera, - RightStick, - CameraUpDown, - CameraLeftRight, - SummonEffects, - NavigationalMap, - Vibration, - Sound, - CommandMenu, - GameMode, - - END - } - - private const int MaimumOptionPerLine = 3; - private const int MaimumSettingsPerScreen = 9; - private const int SettingCount = (int)Options.END; - - private struct OptionAnimation - { - public int UnselectedOption; - public int SelectedOption; - public int Cursor; - } - - private struct OptionRow - { - public ushort Title; - public OptionEntry[] Options; - } - - private struct OptionEntry - { - public ushort Name; - public ushort Desc; - - public OptionEntry(ushort name, ushort desc) - { - Name = name; - Desc = desc; - } - } - - private static readonly int[] Names = new int[] - { - 0x3717, - 0x3718, - 0x42f5, - 0x42f6, - 0x42f7, - 0x3719, - 0x371a, - 0x371b, - 0x371c, - 0x371d, - }; - - private static readonly OptionAnimation[] OptionAnimations = new OptionAnimation[MaimumOptionPerLine] - { - new OptionAnimation { UnselectedOption = 261, SelectedOption = 260, Cursor = 259 }, - new OptionAnimation { UnselectedOption = 254, SelectedOption = 255, Cursor = 253 }, - new OptionAnimation { UnselectedOption = 257, SelectedOption = 258, Cursor = 256 }, - }; - - private static readonly OptionRow[] Rows = new OptionRow[SettingCount] - { - new OptionRow - { - Title = 0x3717, - Options = new OptionEntry[] - { - new OptionEntry(0x371e, 0x3720), - new OptionEntry(0x371f, 0x3721), - } - }, - new OptionRow - { - Title = 0x3718, - Options = new OptionEntry[] - { - new OptionEntry(0x3722, 0x3724), - new OptionEntry(0x3723, 0x3725), - } - }, - new OptionRow - { - Title = 0x42f5, - Options = new OptionEntry[] - { - new OptionEntry(0x42f8, 0x42fa), - new OptionEntry(0x42f9, 0x42fb), - } - }, - new OptionRow - { - Title = 0x42f6, - Options = new OptionEntry[] - { - new OptionEntry(0x42fc, 0x42fe), - new OptionEntry(0x42fd, 0x42ff), - } - }, - new OptionRow - { - Title = 0x42f7, - Options = new OptionEntry[] - { - new OptionEntry(0x4302, 0x4305), - new OptionEntry(0x4300, 0x4303), - new OptionEntry(0x4301, 0x4304), - } - }, - new OptionRow - { - Title = 0x3719, - Options = new OptionEntry[] - { - new OptionEntry(0x3726, 0x3728), - new OptionEntry(0x3727, 0x3729), - } - }, - new OptionRow - { - Title = 0x371a, - Options = new OptionEntry[] - { - new OptionEntry(0x372a, 0x372c), - new OptionEntry(0x3752, 0x372d), - } - }, - new OptionRow - { - Title = 0x371b, - Options = new OptionEntry[] - { - new OptionEntry(0x372e, 0x3731), - new OptionEntry(0x372f, 0x3732), - new OptionEntry(0x3730, 0x3733), - } - }, - new OptionRow - { - Title = 0x371c, - Options = new OptionEntry[] - { - new OptionEntry(0x3734, 0x3736), - new OptionEntry(0x3735, 0x3737), - } - }, - new OptionRow - { - Title = 0x371d, - Options = new OptionEntry[] - { - new OptionEntry(0x3738, 0x373b), - new OptionEntry(0x3739, 0x373c), - new OptionEntry(0x373a, 0x373d), - new OptionEntry(0x4e30, 0x4e31), - } - }, - }; - - private readonly int[] _optionValues = new int[SettingCount]; - private IAnimatedSequence _menuSeq; - private int _selectedOption; - - public override ushort MenuNameId => 0xb617; - protected override bool IsEnd => _menuSeq.IsEnd; - - public int SelectedSettingIndex - { - get => _selectedOption; - private set - { - value = value < 0 ? SettingCount - 1 : value % SettingCount; - if (_selectedOption != value) - { - _selectedOption = value; - InvalidateMenu(); - } - } - } - - public MenuConfig(IMenuManager menuManager) : base(menuManager) - { - _menuSeq = InitializeMenu(false); - _menuSeq.Begin(); - - SetSelectedOption((int)Options.FieldCamera, menuManager.GameContext.Kernel.SaveData.FieldCameraManual ? 1 : 0); - SetSelectedOption((int)Options.RightStick, menuManager.GameContext.Kernel.SaveData.RightAnalogStickCommand ? 1 : 0); - SetSelectedOption((int)Options.CameraUpDown, menuManager.GameContext.Kernel.SaveData.CameraUpDownReversed ? 1 : 0); - SetSelectedOption((int)Options.CameraLeftRight, menuManager.GameContext.Kernel.SaveData.CameraLeftRightReversed ? 1 : 0); - SetSelectedOption((int)Options.SummonEffects, 0); // TODO not implemented - SetSelectedOption((int)Options.NavigationalMap, menuManager.GameContext.Kernel.SaveData.NavigationalMap ? 0 : 1); - SetSelectedOption((int)Options.Vibration, menuManager.GameContext.Kernel.SaveData.Vibration ? 0 : 1); - SetSelectedOption((int)Options.Sound, 0); // TODO not implemented - SetSelectedOption((int)Options.CommandMenu, menuManager.GameContext.Kernel.SaveData.CommandMenuClassic ? 1 : 0); - SetSelectedOption((int)Options.GameMode, menuManager.GameContext.Kernel.SaveData.Difficulty); - } - - public int GetOptionCount(int settingIndex) => Rows[settingIndex].Options.Length; - public int GetSelectedOption(int settingIndex) => _optionValues[settingIndex]; - public void SetSelectedOption(int settingIndex, int value) - { - var optionCount = GetOptionCount(settingIndex); - if (value < 0) - value = optionCount - 1; - else - value %= optionCount; - - if (_optionValues[settingIndex] != value) - { - _optionValues[settingIndex] = value; - InvalidateMenu(); - } - } - - private void InvalidateMenu() - { - _menuSeq = InitializeMenu(true); - _menuSeq.Begin(); - } - - private IAnimatedSequence InitializeMenu(bool skipIntro = false) - { - var settingList = new List(); - var displaySettingStart = Math.Max(SelectedSettingIndex - MaimumSettingsPerScreen + 1, 0); - var displaySettingCount = Math.Min(SettingCount, MaimumSettingsPerScreen); - - for (var i = displaySettingStart; i < displaySettingStart + displaySettingCount; i++) - { - var setting = Rows[i]; - var optionAnimations = OptionAnimations[setting.Options.Length switch - { - 2 => 1, - 3 => 2, - _ => 0, - }]; - var displayOptionCount = setting.Options.Length <= MaimumOptionPerLine ? - setting.Options.Length : 1; - - var optionList = new List(); - for (var j = 0; j < displayOptionCount; j++) - { - if (j == GetSelectedOption(i)) - { - if (i == SelectedSettingIndex) - { - optionList.Add(new AnimatedSequenceDesc - { - SequenceIndexLoop = optionAnimations.SelectedOption, - TextAnchor = TextAnchor.BottomCenter, - MessageId = setting.Options[j].Name, - Children = new List - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = optionAnimations.Cursor, - Flags = AnimationFlags.TextTranslateX | - AnimationFlags.ChildStackHorizontally, - Children = new List - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = 25, - TextAnchor = TextAnchor.BottomLeft, - Flags = AnimationFlags.NoChildTranslationX, - }, - new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 27, - SequenceIndexLoop = 28, - SequenceIndexEnd = 29, - } - } - } - } - }); - } - else - { - optionList.Add(new AnimatedSequenceDesc - { - SequenceIndexLoop = optionAnimations.SelectedOption, - TextAnchor = TextAnchor.BottomCenter, - MessageId = setting.Options[j].Name, - }); - } - } - else - { - optionList.Add(new AnimatedSequenceDesc - { - SequenceIndexLoop = optionAnimations.UnselectedOption, - TextAnchor = TextAnchor.BottomCenter, - MessageId = setting.Options[j].Name, - }); - } - } - - settingList.Add(new AnimatedSequenceDesc - { - SequenceIndexLoop = 279, - MessageId = setting.Title, - TextAnchor = TextAnchor.BottomCenter, - StackIndex = i, - Flags = AnimationFlags.NoChildTranslationX | - AnimationFlags.TextTranslateX | - AnimationFlags.TextIgnoreColor | - AnimationFlags.TextIgnoreScaling | - AnimationFlags.StackNextChildHorizontally, - Children = optionList - }); - } - - var anim = SequenceFactory.Create(new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 233, - SequenceIndexLoop = 234, - SequenceIndexEnd = 235, - Flags = AnimationFlags.StackNextChildVertically, - Children = settingList - }); - anim.Begin(); - - return anim; - } - - protected override void ProcessInput(IInput input) - { - if (input.Repeated.Up) - SelectedSettingIndex--; - else if (input.Repeated.Down) - SelectedSettingIndex++; - else if (input.Repeated.Left) - SetSelectedOption(SelectedSettingIndex, GetSelectedOption(SelectedSettingIndex) - 1); - else if (input.Repeated.Right) - SetSelectedOption(SelectedSettingIndex, GetSelectedOption(SelectedSettingIndex) + 1); - else if (input.Triggered.Confirm) - { - // ignore - } - else - base.ProcessInput(input); - } - - public override void Open() - { - _menuSeq.Begin(); - base.Open(); - } - - public override void Close() - { - _menuSeq.End(); - base.Close(); - } - - protected override void MyUpdate(double deltaTime) => - _menuSeq.Update(deltaTime); - - protected override void MyDraw() => - _menuSeq.Draw(0, 0); - } -} +using OpenKh.Engine.Input; +using OpenKh.Engine.Renderers; +using OpenKh.Game.Infrastructure; +using System; +using System.Collections.Generic; + +namespace OpenKh.Game.Menu +{ + public class MenuConfig : MenuBase + { + private enum Options : int + { + FieldCamera, + RightStick, + CameraUpDown, + CameraLeftRight, + SummonEffects, + NavigationalMap, + Vibration, + Sound, + CommandMenu, + GameMode, + + END + } + + private const int MaimumOptionPerLine = 3; + private const int MaimumSettingsPerScreen = 9; + private const int SettingCount = (int)Options.END; + + private struct OptionAnimation + { + public int UnselectedOption; + public int SelectedOption; + public int Cursor; + } + + private struct OptionRow + { + public ushort Title; + public OptionEntry[] Options; + } + + private struct OptionEntry + { + public ushort Name; + public ushort Desc; + + public OptionEntry(ushort name, ushort desc) + { + Name = name; + Desc = desc; + } + } + + private static readonly int[] Names = new int[] + { + 0x3717, + 0x3718, + 0x42f5, + 0x42f6, + 0x42f7, + 0x3719, + 0x371a, + 0x371b, + 0x371c, + 0x371d, + }; + + private static readonly OptionAnimation[] OptionAnimations = new OptionAnimation[MaimumOptionPerLine] + { + new OptionAnimation { UnselectedOption = 261, SelectedOption = 260, Cursor = 259 }, + new OptionAnimation { UnselectedOption = 254, SelectedOption = 255, Cursor = 253 }, + new OptionAnimation { UnselectedOption = 257, SelectedOption = 258, Cursor = 256 }, + }; + + private static readonly OptionRow[] Rows = new OptionRow[SettingCount] + { + new OptionRow + { + Title = 0x3717, + Options = new OptionEntry[] + { + new OptionEntry(0x371e, 0x3720), + new OptionEntry(0x371f, 0x3721), + } + }, + new OptionRow + { + Title = 0x3718, + Options = new OptionEntry[] + { + new OptionEntry(0x3722, 0x3724), + new OptionEntry(0x3723, 0x3725), + } + }, + new OptionRow + { + Title = 0x42f5, + Options = new OptionEntry[] + { + new OptionEntry(0x42f8, 0x42fa), + new OptionEntry(0x42f9, 0x42fb), + } + }, + new OptionRow + { + Title = 0x42f6, + Options = new OptionEntry[] + { + new OptionEntry(0x42fc, 0x42fe), + new OptionEntry(0x42fd, 0x42ff), + } + }, + new OptionRow + { + Title = 0x42f7, + Options = new OptionEntry[] + { + new OptionEntry(0x4302, 0x4305), + new OptionEntry(0x4300, 0x4303), + new OptionEntry(0x4301, 0x4304), + } + }, + new OptionRow + { + Title = 0x3719, + Options = new OptionEntry[] + { + new OptionEntry(0x3726, 0x3728), + new OptionEntry(0x3727, 0x3729), + } + }, + new OptionRow + { + Title = 0x371a, + Options = new OptionEntry[] + { + new OptionEntry(0x372a, 0x372c), + new OptionEntry(0x3752, 0x372d), + } + }, + new OptionRow + { + Title = 0x371b, + Options = new OptionEntry[] + { + new OptionEntry(0x372e, 0x3731), + new OptionEntry(0x372f, 0x3732), + new OptionEntry(0x3730, 0x3733), + } + }, + new OptionRow + { + Title = 0x371c, + Options = new OptionEntry[] + { + new OptionEntry(0x3734, 0x3736), + new OptionEntry(0x3735, 0x3737), + } + }, + new OptionRow + { + Title = 0x371d, + Options = new OptionEntry[] + { + new OptionEntry(0x3738, 0x373b), + new OptionEntry(0x3739, 0x373c), + new OptionEntry(0x373a, 0x373d), + new OptionEntry(0x4e30, 0x4e31), + } + }, + }; + + private readonly int[] _optionValues = new int[SettingCount]; + private IAnimatedSequence _menuSeq; + private int _selectedOption; + + public override ushort MenuNameId => 0xb617; + protected override bool IsEnd => _menuSeq.IsEnd; + + public int SelectedSettingIndex + { + get => _selectedOption; + private set + { + value = value < 0 ? SettingCount - 1 : value % SettingCount; + if (_selectedOption != value) + { + _selectedOption = value; + InvalidateMenu(); + } + } + } + + public MenuConfig(IMenuManager menuManager) : base(menuManager) + { + _menuSeq = InitializeMenu(false); + _menuSeq.Begin(); + + SetSelectedOption((int)Options.FieldCamera, menuManager.GameContext.Kernel.SaveData.FieldCameraManual ? 1 : 0); + SetSelectedOption((int)Options.RightStick, menuManager.GameContext.Kernel.SaveData.RightAnalogStickCommand ? 1 : 0); + SetSelectedOption((int)Options.CameraUpDown, menuManager.GameContext.Kernel.SaveData.CameraUpDownReversed ? 1 : 0); + SetSelectedOption((int)Options.CameraLeftRight, menuManager.GameContext.Kernel.SaveData.CameraLeftRightReversed ? 1 : 0); + SetSelectedOption((int)Options.SummonEffects, 0); // TODO not implemented + SetSelectedOption((int)Options.NavigationalMap, menuManager.GameContext.Kernel.SaveData.NavigationalMap ? 0 : 1); + SetSelectedOption((int)Options.Vibration, menuManager.GameContext.Kernel.SaveData.Vibration ? 0 : 1); + SetSelectedOption((int)Options.Sound, 0); // TODO not implemented + SetSelectedOption((int)Options.CommandMenu, menuManager.GameContext.Kernel.SaveData.CommandMenuClassic ? 1 : 0); + SetSelectedOption((int)Options.GameMode, menuManager.GameContext.Kernel.SaveData.Difficulty); + } + + public int GetOptionCount(int settingIndex) => Rows[settingIndex].Options.Length; + public int GetSelectedOption(int settingIndex) => _optionValues[settingIndex]; + public void SetSelectedOption(int settingIndex, int value) + { + var optionCount = GetOptionCount(settingIndex); + if (value < 0) + value = optionCount - 1; + else + value %= optionCount; + + if (_optionValues[settingIndex] != value) + { + _optionValues[settingIndex] = value; + InvalidateMenu(); + } + } + + private void InvalidateMenu() + { + _menuSeq = InitializeMenu(true); + _menuSeq.Begin(); + } + + private IAnimatedSequence InitializeMenu(bool skipIntro = false) + { + var settingList = new List(); + var displaySettingStart = Math.Max(SelectedSettingIndex - MaimumSettingsPerScreen + 1, 0); + var displaySettingCount = Math.Min(SettingCount, MaimumSettingsPerScreen); + + for (var i = displaySettingStart; i < displaySettingStart + displaySettingCount; i++) + { + var setting = Rows[i]; + var optionAnimations = OptionAnimations[setting.Options.Length switch + { + 2 => 1, + 3 => 2, + _ => 0, + }]; + var displayOptionCount = setting.Options.Length <= MaimumOptionPerLine ? + setting.Options.Length : 1; + + var optionList = new List(); + for (var j = 0; j < displayOptionCount; j++) + { + if (j == GetSelectedOption(i)) + { + if (i == SelectedSettingIndex) + { + optionList.Add(new AnimatedSequenceDesc + { + SequenceIndexLoop = optionAnimations.SelectedOption, + TextAnchor = TextAnchor.BottomCenter, + MessageId = setting.Options[j].Name, + Children = new List + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = optionAnimations.Cursor, + Flags = AnimationFlags.TextTranslateX | + AnimationFlags.ChildStackHorizontally, + Children = new List + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = 25, + TextAnchor = TextAnchor.BottomLeft, + Flags = AnimationFlags.NoChildTranslationX, + }, + new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 27, + SequenceIndexLoop = 28, + SequenceIndexEnd = 29, + } + } + } + } + }); + } + else + { + optionList.Add(new AnimatedSequenceDesc + { + SequenceIndexLoop = optionAnimations.SelectedOption, + TextAnchor = TextAnchor.BottomCenter, + MessageId = setting.Options[j].Name, + }); + } + } + else + { + optionList.Add(new AnimatedSequenceDesc + { + SequenceIndexLoop = optionAnimations.UnselectedOption, + TextAnchor = TextAnchor.BottomCenter, + MessageId = setting.Options[j].Name, + }); + } + } + + settingList.Add(new AnimatedSequenceDesc + { + SequenceIndexLoop = 279, + MessageId = setting.Title, + TextAnchor = TextAnchor.BottomCenter, + StackIndex = i, + Flags = AnimationFlags.NoChildTranslationX | + AnimationFlags.TextTranslateX | + AnimationFlags.TextIgnoreColor | + AnimationFlags.TextIgnoreScaling | + AnimationFlags.StackNextChildHorizontally, + Children = optionList + }); + } + + var anim = SequenceFactory.Create(new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 233, + SequenceIndexLoop = 234, + SequenceIndexEnd = 235, + Flags = AnimationFlags.StackNextChildVertically, + Children = settingList + }); + anim.Begin(); + + return anim; + } + + protected override void ProcessInput(IInput input) + { + if (input.Repeated.Up) + SelectedSettingIndex--; + else if (input.Repeated.Down) + SelectedSettingIndex++; + else if (input.Repeated.Left) + SetSelectedOption(SelectedSettingIndex, GetSelectedOption(SelectedSettingIndex) - 1); + else if (input.Repeated.Right) + SetSelectedOption(SelectedSettingIndex, GetSelectedOption(SelectedSettingIndex) + 1); + else if (input.Triggered.Confirm) + { + // ignore + } + else + base.ProcessInput(input); + } + + public override void Open() + { + _menuSeq.Begin(); + base.Open(); + } + + public override void Close() + { + _menuSeq.End(); + base.Close(); + } + + protected override void MyUpdate(double deltaTime) => + _menuSeq.Update(deltaTime); + + protected override void MyDraw() => + _menuSeq.Draw(0, 0); + } +} diff --git a/OpenKh.Game/Menu/MenuDebug.cs b/OpenKh.Game/Menu/MenuDebug.cs index 4a03ff838..7497feaca 100644 --- a/OpenKh.Game/Menu/MenuDebug.cs +++ b/OpenKh.Game/Menu/MenuDebug.cs @@ -1,138 +1,138 @@ -using OpenKh.Engine.Input; -using OpenKh.Engine.Renderers; -using OpenKh.Game.Infrastructure; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Game.Menu -{ - public class DebugMenuEntry - { - public string Name { get; } - public Action Action { get; } - - public DebugMenuEntry(string name, Action action) - { - Name = name; - Action = action; - } - } - - public class MenuDebug : MenuBase - { - public static string Name = "DEBUG"; - private readonly DebugMenuEntry[] Entries; - private IAnimatedSequence _menuSeq; - private int _selectedOption; - - public int SelectedOption - { - get => _selectedOption; - set - { - value = value < 0 ? Entries.Length - 1 : value % Entries.Length; - if (_selectedOption != value) - { - _selectedOption = value; - _menuSeq = InitializeMenu(true); - _menuSeq.Begin(); - } - } - } - - public override ushort MenuNameId => 0; - protected override bool IsEnd => _menuSeq.IsEnd; - - public MenuDebug(IMenuManager menuManager) : base(menuManager) - { - Entries = new DebugMenuEntry[] - { - new DebugMenuEntry("PLAY EVENT", OpenPlayEventMenu), - new DebugMenuEntry(MenuDebugChangePlace.Name, OpenChangePlaceMenu), - new DebugMenuEntry("TITLE SCREEN", ReturnToTitleScreen), - }; - _menuSeq = InitializeMenu(false); - } - - private void ReturnToTitleScreen() - { - MenuManager.GameContext.LoadTitleScreen(); - MenuManager.CloseAllMenu(); - } - - private void OpenChangePlaceMenu() => - Push(new MenuDebugChangePlace(MenuManager)); - - private void OpenPlayEventMenu() => - Push(new MenuDebugPlayEvent(MenuManager)); - - private void OpenResolutionMenu() - { - } - - private IAnimatedSequence InitializeMenu(bool skipIntro) - { - return SequenceFactory.Create(Enumerable.Range(0, Entries.Length) - .Select(i => new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 133, - SequenceIndexLoop = SelectedOption == i ? 132 : 134, - SequenceIndexEnd = 135, - StackIndex = i, - StackWidth = 0, - StackHeight = AnimatedSequenceDesc.DefaultStacking, - Flags = AnimationFlags.TextTranslateX | - AnimationFlags.ChildStackHorizontally, - MessageText = Entries[i].Name, - Children = SelectedOption == i ? new List - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = 25, - TextAnchor = TextAnchor.BottomLeft, - Flags = AnimationFlags.NoChildTranslationX, - }, - new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 27, - SequenceIndexLoop = 28, - SequenceIndexEnd = 29, - } - } : new List() - })); - } - - protected override void ProcessInput(IInput input) - { - if (input.Repeated.Up) - SelectedOption--; - else if (input.Repeated.Down) - SelectedOption++; - else if (input.Triggered.Confirm) - Entries[SelectedOption].Action(); - else - base.ProcessInput(input); - } - - public override void Open() - { - _menuSeq.Begin(); - base.Open(); - } - - public override void Close() - { - _menuSeq.End(); - base.Close(); - } - - protected override void MyUpdate(double deltaTime) => - _menuSeq.Update(deltaTime); - - protected override void MyDraw() => - _menuSeq.Draw(0, 0); - - public override string ToString() => Name; - } -} +using OpenKh.Engine.Input; +using OpenKh.Engine.Renderers; +using OpenKh.Game.Infrastructure; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Game.Menu +{ + public class DebugMenuEntry + { + public string Name { get; } + public Action Action { get; } + + public DebugMenuEntry(string name, Action action) + { + Name = name; + Action = action; + } + } + + public class MenuDebug : MenuBase + { + public static string Name = "DEBUG"; + private readonly DebugMenuEntry[] Entries; + private IAnimatedSequence _menuSeq; + private int _selectedOption; + + public int SelectedOption + { + get => _selectedOption; + set + { + value = value < 0 ? Entries.Length - 1 : value % Entries.Length; + if (_selectedOption != value) + { + _selectedOption = value; + _menuSeq = InitializeMenu(true); + _menuSeq.Begin(); + } + } + } + + public override ushort MenuNameId => 0; + protected override bool IsEnd => _menuSeq.IsEnd; + + public MenuDebug(IMenuManager menuManager) : base(menuManager) + { + Entries = new DebugMenuEntry[] + { + new DebugMenuEntry("PLAY EVENT", OpenPlayEventMenu), + new DebugMenuEntry(MenuDebugChangePlace.Name, OpenChangePlaceMenu), + new DebugMenuEntry("TITLE SCREEN", ReturnToTitleScreen), + }; + _menuSeq = InitializeMenu(false); + } + + private void ReturnToTitleScreen() + { + MenuManager.GameContext.LoadTitleScreen(); + MenuManager.CloseAllMenu(); + } + + private void OpenChangePlaceMenu() => + Push(new MenuDebugChangePlace(MenuManager)); + + private void OpenPlayEventMenu() => + Push(new MenuDebugPlayEvent(MenuManager)); + + private void OpenResolutionMenu() + { + } + + private IAnimatedSequence InitializeMenu(bool skipIntro) + { + return SequenceFactory.Create(Enumerable.Range(0, Entries.Length) + .Select(i => new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 133, + SequenceIndexLoop = SelectedOption == i ? 132 : 134, + SequenceIndexEnd = 135, + StackIndex = i, + StackWidth = 0, + StackHeight = AnimatedSequenceDesc.DefaultStacking, + Flags = AnimationFlags.TextTranslateX | + AnimationFlags.ChildStackHorizontally, + MessageText = Entries[i].Name, + Children = SelectedOption == i ? new List + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = 25, + TextAnchor = TextAnchor.BottomLeft, + Flags = AnimationFlags.NoChildTranslationX, + }, + new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 27, + SequenceIndexLoop = 28, + SequenceIndexEnd = 29, + } + } : new List() + })); + } + + protected override void ProcessInput(IInput input) + { + if (input.Repeated.Up) + SelectedOption--; + else if (input.Repeated.Down) + SelectedOption++; + else if (input.Triggered.Confirm) + Entries[SelectedOption].Action(); + else + base.ProcessInput(input); + } + + public override void Open() + { + _menuSeq.Begin(); + base.Open(); + } + + public override void Close() + { + _menuSeq.End(); + base.Close(); + } + + protected override void MyUpdate(double deltaTime) => + _menuSeq.Update(deltaTime); + + protected override void MyDraw() => + _menuSeq.Draw(0, 0); + + public override string ToString() => Name; + } +} diff --git a/OpenKh.Game/Menu/MenuDebugChangePlace.cs b/OpenKh.Game/Menu/MenuDebugChangePlace.cs index 7ae79ea9b..a17593a1e 100644 --- a/OpenKh.Game/Menu/MenuDebugChangePlace.cs +++ b/OpenKh.Game/Menu/MenuDebugChangePlace.cs @@ -1,116 +1,116 @@ -using OpenKh.Engine.Input; -using OpenKh.Engine.Renderers; -using OpenKh.Game.Infrastructure; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Game.Menu -{ - public class MenuDebugChangePlace : MenuBase - { - const int MaxOptionPerColumn = 10; - private const int WorldCount = Kh2.Constants.WorldCount; - private static readonly ushort[] WorldMsgIds = Enumerable - .Range(0, WorldCount) - .Select(i => (ushort)(0x8211 + i)) - .ToArray(); - - public static string Name = "CHANGE PLACE"; - private IAnimatedSequence _menuSeq; - private int _selectedOption; - - public int SelectedOption - { - get => _selectedOption; - set - { - value = value < 0 ? WorldCount - 1 : value % WorldCount; - if (_selectedOption != value) - { - _selectedOption = value; - _menuSeq = InitializeMenu(true); - _menuSeq.Begin(); - } - } - } - - public override ushort MenuNameId => 0; - protected override bool IsEnd => _menuSeq.IsEnd; - - public MenuDebugChangePlace(IMenuManager menuManager) : base(menuManager) - { - _menuSeq = InitializeMenu(false); - } - - private IAnimatedSequence InitializeMenu(bool skipIntro) - { - return SequenceFactory.Create(Enumerable.Range(0, WorldMsgIds.Length) - .Select(i => new AnimatedSequenceDesc - { - X = i / MaxOptionPerColumn * 140, - SequenceIndexStart = skipIntro ? -1 : 133, - SequenceIndexLoop = SelectedOption == i ? 132 : 134, - SequenceIndexEnd = 135, - StackIndex = i % MaxOptionPerColumn, - StackWidth = 0, - StackHeight = AnimatedSequenceDesc.DefaultStacking, - Flags = AnimationFlags.TextTranslateX | - AnimationFlags.ChildStackHorizontally, - MessageId = WorldMsgIds[i], - Children = SelectedOption == i ? new List - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = 25, - TextAnchor = TextAnchor.BottomLeft, - Flags = AnimationFlags.NoChildTranslationX, - }, - new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 27, - SequenceIndexLoop = 28, - SequenceIndexEnd = 29, - } - } : new List() - })); - } - - protected override void ProcessInput(IInput input) - { - if (input.Repeated.Up) - SelectedOption--; - else if (input.Repeated.Down) - SelectedOption++; - if (input.Repeated.Left) - SelectedOption -= MaxOptionPerColumn; - if (input.Repeated.Right) - SelectedOption += MaxOptionPerColumn; - else if (input.Triggered.Confirm) - Push(new MenuDebugSelectPlace( - MenuManager, SelectedOption, WorldMsgIds[SelectedOption])); - else - base.ProcessInput(input); - } - - public override void Open() - { - _menuSeq.Begin(); - base.Open(); - } - - public override void Close() - { - _menuSeq.End(); - base.Close(); - } - - protected override void MyUpdate(double deltaTime) => - _menuSeq.Update(deltaTime); - - protected override void MyDraw() => - _menuSeq.Draw(0, 0); - - public override string ToString() => Name; - } -} +using OpenKh.Engine.Input; +using OpenKh.Engine.Renderers; +using OpenKh.Game.Infrastructure; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Game.Menu +{ + public class MenuDebugChangePlace : MenuBase + { + const int MaxOptionPerColumn = 10; + private const int WorldCount = Kh2.Constants.WorldCount; + private static readonly ushort[] WorldMsgIds = Enumerable + .Range(0, WorldCount) + .Select(i => (ushort)(0x8211 + i)) + .ToArray(); + + public static string Name = "CHANGE PLACE"; + private IAnimatedSequence _menuSeq; + private int _selectedOption; + + public int SelectedOption + { + get => _selectedOption; + set + { + value = value < 0 ? WorldCount - 1 : value % WorldCount; + if (_selectedOption != value) + { + _selectedOption = value; + _menuSeq = InitializeMenu(true); + _menuSeq.Begin(); + } + } + } + + public override ushort MenuNameId => 0; + protected override bool IsEnd => _menuSeq.IsEnd; + + public MenuDebugChangePlace(IMenuManager menuManager) : base(menuManager) + { + _menuSeq = InitializeMenu(false); + } + + private IAnimatedSequence InitializeMenu(bool skipIntro) + { + return SequenceFactory.Create(Enumerable.Range(0, WorldMsgIds.Length) + .Select(i => new AnimatedSequenceDesc + { + X = i / MaxOptionPerColumn * 140, + SequenceIndexStart = skipIntro ? -1 : 133, + SequenceIndexLoop = SelectedOption == i ? 132 : 134, + SequenceIndexEnd = 135, + StackIndex = i % MaxOptionPerColumn, + StackWidth = 0, + StackHeight = AnimatedSequenceDesc.DefaultStacking, + Flags = AnimationFlags.TextTranslateX | + AnimationFlags.ChildStackHorizontally, + MessageId = WorldMsgIds[i], + Children = SelectedOption == i ? new List + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = 25, + TextAnchor = TextAnchor.BottomLeft, + Flags = AnimationFlags.NoChildTranslationX, + }, + new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 27, + SequenceIndexLoop = 28, + SequenceIndexEnd = 29, + } + } : new List() + })); + } + + protected override void ProcessInput(IInput input) + { + if (input.Repeated.Up) + SelectedOption--; + else if (input.Repeated.Down) + SelectedOption++; + if (input.Repeated.Left) + SelectedOption -= MaxOptionPerColumn; + if (input.Repeated.Right) + SelectedOption += MaxOptionPerColumn; + else if (input.Triggered.Confirm) + Push(new MenuDebugSelectPlace( + MenuManager, SelectedOption, WorldMsgIds[SelectedOption])); + else + base.ProcessInput(input); + } + + public override void Open() + { + _menuSeq.Begin(); + base.Open(); + } + + public override void Close() + { + _menuSeq.End(); + base.Close(); + } + + protected override void MyUpdate(double deltaTime) => + _menuSeq.Update(deltaTime); + + protected override void MyDraw() => + _menuSeq.Draw(0, 0); + + public override string ToString() => Name; + } +} diff --git a/OpenKh.Game/Menu/MenuDebugPlayEvent.cs b/OpenKh.Game/Menu/MenuDebugPlayEvent.cs index eefe20a87..029ae0421 100644 --- a/OpenKh.Game/Menu/MenuDebugPlayEvent.cs +++ b/OpenKh.Game/Menu/MenuDebugPlayEvent.cs @@ -1,112 +1,112 @@ -using OpenKh.Engine.Input; -using OpenKh.Engine.Renderers; -using OpenKh.Game.Infrastructure; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Game.Menu -{ - public class MenuDebugPlayEvent : MenuBase - { - const int MaxOptionPerColumn = 10; - public static string Name = "PLAY EVENT"; - private IAnimatedSequence _menuSeq; - private int _selectedOption; - - private IList Events => MenuManager.GameContext.Field.Events; - private int OptionCount => Events.Count; - - public int SelectedOption - { - get => _selectedOption; - set - { - value = value < 0 ? OptionCount - 1 : value % OptionCount; - if (_selectedOption != value) - { - _selectedOption = value; - _menuSeq = InitializeMenu(true); - _menuSeq.Begin(); - } - } - } - - public override ushort MenuNameId => 0; - protected override bool IsEnd => _menuSeq.IsEnd; - - public MenuDebugPlayEvent(IMenuManager menuManager) : - base(menuManager) - { - _menuSeq = InitializeMenu(false); - } - - private IAnimatedSequence InitializeMenu(bool skipIntro) - { - return SequenceFactory.Create(Events - .Select((name, i) => new AnimatedSequenceDesc - { - X = i / MaxOptionPerColumn * 140, - SequenceIndexStart = skipIntro ? -1 : 133, - SequenceIndexLoop = SelectedOption == i ? 132 : 134, - SequenceIndexEnd = 135, - StackIndex = i % MaxOptionPerColumn, - StackWidth = 0, - StackHeight = AnimatedSequenceDesc.DefaultStacking, - Flags = AnimationFlags.TextTranslateX | - AnimationFlags.ChildStackHorizontally, - MessageText = name.ToUpper(), - Children = SelectedOption == i ? new List - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = 25, - TextAnchor = TextAnchor.BottomLeft, - Flags = AnimationFlags.NoChildTranslationX, - }, - new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 27, - SequenceIndexLoop = 28, - SequenceIndexEnd = 29, - } - } : new List() - })); - } - - protected override void ProcessInput(IInput input) - { - if (input.Repeated.Up) - SelectedOption--; - else if (input.Repeated.Down) - SelectedOption++; - if (input.Repeated.Left) - SelectedOption -= MaxOptionPerColumn; - if (input.Repeated.Right) - SelectedOption += MaxOptionPerColumn; - else if (input.Triggered.Confirm) - MenuManager.GameContext.Field.PlayEvent(Events[SelectedOption]); - else - base.ProcessInput(input); - } - - public override void Open() - { - _menuSeq.Begin(); - base.Open(); - } - - public override void Close() - { - _menuSeq.End(); - base.Close(); - } - - protected override void MyUpdate(double deltaTime) => - _menuSeq.Update(deltaTime); - - protected override void MyDraw() => - _menuSeq.Draw(0, 0); - - public override string ToString() => Name; - } -} +using OpenKh.Engine.Input; +using OpenKh.Engine.Renderers; +using OpenKh.Game.Infrastructure; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Game.Menu +{ + public class MenuDebugPlayEvent : MenuBase + { + const int MaxOptionPerColumn = 10; + public static string Name = "PLAY EVENT"; + private IAnimatedSequence _menuSeq; + private int _selectedOption; + + private IList Events => MenuManager.GameContext.Field.Events; + private int OptionCount => Events.Count; + + public int SelectedOption + { + get => _selectedOption; + set + { + value = value < 0 ? OptionCount - 1 : value % OptionCount; + if (_selectedOption != value) + { + _selectedOption = value; + _menuSeq = InitializeMenu(true); + _menuSeq.Begin(); + } + } + } + + public override ushort MenuNameId => 0; + protected override bool IsEnd => _menuSeq.IsEnd; + + public MenuDebugPlayEvent(IMenuManager menuManager) : + base(menuManager) + { + _menuSeq = InitializeMenu(false); + } + + private IAnimatedSequence InitializeMenu(bool skipIntro) + { + return SequenceFactory.Create(Events + .Select((name, i) => new AnimatedSequenceDesc + { + X = i / MaxOptionPerColumn * 140, + SequenceIndexStart = skipIntro ? -1 : 133, + SequenceIndexLoop = SelectedOption == i ? 132 : 134, + SequenceIndexEnd = 135, + StackIndex = i % MaxOptionPerColumn, + StackWidth = 0, + StackHeight = AnimatedSequenceDesc.DefaultStacking, + Flags = AnimationFlags.TextTranslateX | + AnimationFlags.ChildStackHorizontally, + MessageText = name.ToUpper(), + Children = SelectedOption == i ? new List + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = 25, + TextAnchor = TextAnchor.BottomLeft, + Flags = AnimationFlags.NoChildTranslationX, + }, + new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 27, + SequenceIndexLoop = 28, + SequenceIndexEnd = 29, + } + } : new List() + })); + } + + protected override void ProcessInput(IInput input) + { + if (input.Repeated.Up) + SelectedOption--; + else if (input.Repeated.Down) + SelectedOption++; + if (input.Repeated.Left) + SelectedOption -= MaxOptionPerColumn; + if (input.Repeated.Right) + SelectedOption += MaxOptionPerColumn; + else if (input.Triggered.Confirm) + MenuManager.GameContext.Field.PlayEvent(Events[SelectedOption]); + else + base.ProcessInput(input); + } + + public override void Open() + { + _menuSeq.Begin(); + base.Open(); + } + + public override void Close() + { + _menuSeq.End(); + base.Close(); + } + + protected override void MyUpdate(double deltaTime) => + _menuSeq.Update(deltaTime); + + protected override void MyDraw() => + _menuSeq.Draw(0, 0); + + public override string ToString() => Name; + } +} diff --git a/OpenKh.Game/Menu/MenuDebugSelectPlace.cs b/OpenKh.Game/Menu/MenuDebugSelectPlace.cs index a6a1f0328..3dfae2b62 100644 --- a/OpenKh.Game/Menu/MenuDebugSelectPlace.cs +++ b/OpenKh.Game/Menu/MenuDebugSelectPlace.cs @@ -1,142 +1,142 @@ -using OpenKh.Engine.Input; -using OpenKh.Engine.Renderers; -using OpenKh.Game.Infrastructure; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Game.Menu -{ - public class MenuDebugSelectPlace : MenuBase - { - private class PlaceDescriptor - { - public int WorldIndex { get; set; } - public int PlaceIndex { get; set; } - public ushort MessageId { get; set; } - } - - const int MaxOptionPerColumn = 10; - public static string Name = "SELECT PLACE"; - private readonly PlaceDescriptor[] _places; - private IAnimatedSequence _menuSeq; - private int _selectedOption; - - public int SelectedOption - { - get => _selectedOption; - set - { - value = value < 0 ? _places.Length - 1 : value % _places.Length; - if (_selectedOption != value) - { - _selectedOption = value; - _menuSeq = InitializeMenu(true); - _menuSeq.Begin(); - } - } - } - - public override ushort MenuNameId { get; } - protected override bool IsEnd => _menuSeq.IsEnd; - - public MenuDebugSelectPlace( - IMenuManager menuManager, - int worldId, - ushort worldMessageId) : base(menuManager) - { - MenuNameId = worldMessageId; - - var worldKey = Kh2.Constants.WorldIds[worldId]; - _places = menuManager.GameContext.Kernel.Places[worldKey] - .Select((x, Index) => new { x.MessageId, Index }) - .Where(x => menuManager.GameContext.Kernel.DataContent - .FileExists(menuManager.GameContext.Kernel.GetMapFileName(worldId, x.Index))) - .Select(x => new PlaceDescriptor - { - WorldIndex = worldId, - PlaceIndex = x.Index, - MessageId = x.MessageId, - }) - .ToArray(); - - _menuSeq = InitializeMenu(false); - } - - private IAnimatedSequence InitializeMenu(bool skipIntro) - { - return SequenceFactory.Create(Enumerable.Range(0, _places.Length) - .Select(i => new AnimatedSequenceDesc - { - X = i / MaxOptionPerColumn * 140, - SequenceIndexStart = skipIntro ? -1 : 133, - SequenceIndexLoop = SelectedOption == i ? 132 : 134, - SequenceIndexEnd = 135, - StackIndex = i % MaxOptionPerColumn, - StackWidth = 0, - StackHeight = AnimatedSequenceDesc.DefaultStacking, - Flags = AnimationFlags.TextTranslateX | - AnimationFlags.ChildStackHorizontally, - MessageId = _places[i].MessageId, - Children = SelectedOption == i ? new List - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = 25, - TextAnchor = TextAnchor.BottomLeft, - Flags = AnimationFlags.NoChildTranslationX, - }, - new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 27, - SequenceIndexLoop = 28, - SequenceIndexEnd = 29, - } - } : new List() - })); - } - - protected override void ProcessInput(IInput input) - { - if (input.Repeated.Up) - SelectedOption--; - else if (input.Repeated.Down) - SelectedOption++; - if (input.Repeated.Left) - SelectedOption -= MaxOptionPerColumn; - if (input.Repeated.Right) - SelectedOption += MaxOptionPerColumn; - else if (input.Triggered.Confirm) - { - var place = _places[SelectedOption]; - MenuManager.GameContext.LoadPlace( - place.WorldIndex, - place.PlaceIndex, - 0); - - MenuManager.CloseAllMenu(); - } - else - base.ProcessInput(input); - } - - public override void Open() - { - _menuSeq.Begin(); - base.Open(); - } - - public override void Close() - { - _menuSeq.End(); - base.Close(); - } - - protected override void MyUpdate(double deltaTime) => - _menuSeq.Update(deltaTime); - - protected override void MyDraw() => - _menuSeq.Draw(0, 0); - - public override string ToString() => Name; - } -} +using OpenKh.Engine.Input; +using OpenKh.Engine.Renderers; +using OpenKh.Game.Infrastructure; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Game.Menu +{ + public class MenuDebugSelectPlace : MenuBase + { + private class PlaceDescriptor + { + public int WorldIndex { get; set; } + public int PlaceIndex { get; set; } + public ushort MessageId { get; set; } + } + + const int MaxOptionPerColumn = 10; + public static string Name = "SELECT PLACE"; + private readonly PlaceDescriptor[] _places; + private IAnimatedSequence _menuSeq; + private int _selectedOption; + + public int SelectedOption + { + get => _selectedOption; + set + { + value = value < 0 ? _places.Length - 1 : value % _places.Length; + if (_selectedOption != value) + { + _selectedOption = value; + _menuSeq = InitializeMenu(true); + _menuSeq.Begin(); + } + } + } + + public override ushort MenuNameId { get; } + protected override bool IsEnd => _menuSeq.IsEnd; + + public MenuDebugSelectPlace( + IMenuManager menuManager, + int worldId, + ushort worldMessageId) : base(menuManager) + { + MenuNameId = worldMessageId; + + var worldKey = Kh2.Constants.WorldIds[worldId]; + _places = menuManager.GameContext.Kernel.Places[worldKey] + .Select((x, Index) => new { x.MessageId, Index }) + .Where(x => menuManager.GameContext.Kernel.DataContent + .FileExists(menuManager.GameContext.Kernel.GetMapFileName(worldId, x.Index))) + .Select(x => new PlaceDescriptor + { + WorldIndex = worldId, + PlaceIndex = x.Index, + MessageId = x.MessageId, + }) + .ToArray(); + + _menuSeq = InitializeMenu(false); + } + + private IAnimatedSequence InitializeMenu(bool skipIntro) + { + return SequenceFactory.Create(Enumerable.Range(0, _places.Length) + .Select(i => new AnimatedSequenceDesc + { + X = i / MaxOptionPerColumn * 140, + SequenceIndexStart = skipIntro ? -1 : 133, + SequenceIndexLoop = SelectedOption == i ? 132 : 134, + SequenceIndexEnd = 135, + StackIndex = i % MaxOptionPerColumn, + StackWidth = 0, + StackHeight = AnimatedSequenceDesc.DefaultStacking, + Flags = AnimationFlags.TextTranslateX | + AnimationFlags.ChildStackHorizontally, + MessageId = _places[i].MessageId, + Children = SelectedOption == i ? new List + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = 25, + TextAnchor = TextAnchor.BottomLeft, + Flags = AnimationFlags.NoChildTranslationX, + }, + new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 27, + SequenceIndexLoop = 28, + SequenceIndexEnd = 29, + } + } : new List() + })); + } + + protected override void ProcessInput(IInput input) + { + if (input.Repeated.Up) + SelectedOption--; + else if (input.Repeated.Down) + SelectedOption++; + if (input.Repeated.Left) + SelectedOption -= MaxOptionPerColumn; + if (input.Repeated.Right) + SelectedOption += MaxOptionPerColumn; + else if (input.Triggered.Confirm) + { + var place = _places[SelectedOption]; + MenuManager.GameContext.LoadPlace( + place.WorldIndex, + place.PlaceIndex, + 0); + + MenuManager.CloseAllMenu(); + } + else + base.ProcessInput(input); + } + + public override void Open() + { + _menuSeq.Begin(); + base.Open(); + } + + public override void Close() + { + _menuSeq.End(); + base.Close(); + } + + protected override void MyUpdate(double deltaTime) => + _menuSeq.Update(deltaTime); + + protected override void MyDraw() => + _menuSeq.Draw(0, 0); + + public override string ToString() => Name; + } +} diff --git a/OpenKh.Game/Menu/MenuStatus.cs b/OpenKh.Game/Menu/MenuStatus.cs index 6092a551a..f7e005199 100644 --- a/OpenKh.Game/Menu/MenuStatus.cs +++ b/OpenKh.Game/Menu/MenuStatus.cs @@ -1,455 +1,455 @@ -using OpenKh.Engine.Renderers; -using OpenKh.Common; -using OpenKh.Game.Infrastructure; -using System.Collections.Generic; -using System.Linq; -using OpenKh.Engine.Input; - -namespace OpenKh.Game.Menu -{ - public class MenuStatus : MenuBase - { - const int OptionHover = 0; - const int OptionStart = 1; - const int OptionSel = 2; - const int OptionEnd = 3; - private readonly int[] OptionNormal = new int[] - { - 132, - 133, - 134, - 135 - }; - private readonly int[] OptionSub = new int[] - { - 128, - 129, - 130, - 131 - }; - - private const int CharacterSora = 0; - private const int CharacterRoxas = 14; - private const int CharacterDonald = 1; - private const int CharacterGoofy = 2; - private const int CharacterMickey = 3; - private const int CharacterAuron = 4; - private const int CharacterMulan = 5; - private const int CharacterAladdin = 6; - private const int CharacterJack = 7; - private const int CharacterBeast = 8; - private const int CharacterSparrow = 9; - private const int CharacterSimba = 10; - private const int CharacterTron = 11; - private const int CharacterRiku = 12; - - private const int FormVanillaValor = 0; - private const int FormVanillaWisdom = 1; - private const int FormVanillaMaster = 2; - private const int FormVanillaFinal = 3; - private const int FormVanillaSummon = 4; - private const int FormFinalMixValor = 0; - private const int FormFinalMixWisdom = 1; - private const int FormFinalMixLimit = 2; - private const int FormFinalMixMaster = 3; - private const int FormFinalMixFinal = 4; - private const int FormFinalMixSummon = 5; - - private const int SeqResistance = 139; - private const int SeqLevel = 137; - private const int SeqBonus = 144; - private const int SeqBattle = 150; - private const int SeqStats = 143; - private const int WindowStart = 140; - private const int WindowLoop = 141; - private const int WindowEnd = 142; - private const int SeqValueText = 124; - - private static readonly int[] CharacterMsgIds = new int[] - { - 0x851F, - 0x8520, - 0x8521, - 0x8522, - 0x8523, - 0x8525, // 0x8524 for Ping - 0x8526, - 0x8527, - 0x8528, - 0x8529, - 0x852A, - 0x852B, - 0x852C, - 0x852D, - }; - - private static readonly int[] FormVanillaMsgIds = new int[] - { - 0xC32A, - 0xC32B, - 0xC32C, - 0xC32D, - //0xC5B1, // no summon here - 0x864A, // antiform - }; - - private static readonly int[] FormFinalMixMsgIds = new int[] - { - 0xC32A, - 0xC32B, - 0xCF0B, - 0xC32C, - 0xC32D, - //0xC5B1, // no summon here - 0x864A, // antiform - }; - - private static readonly int[] CharacterSoraVanilla = new int[] - { - CharacterSora, - FormVanillaValor, - FormVanillaWisdom, - FormVanillaMaster, - FormVanillaFinal, - FormVanillaSummon - }; - private static readonly int[] CharacterSoraFinalMix = new int[] - { - CharacterSora, - FormFinalMixValor, - FormFinalMixWisdom, - FormFinalMixLimit, - FormFinalMixMaster, - FormFinalMixFinal, - FormFinalMixSummon - }; - - private readonly int[][] Characters; - private readonly int[] FormMsgIds; - private readonly int[] CurrentCharacters; - private IAnimatedSequence _menuSeq; - private IAnimatedSequence _subMenuSeq; - private List<(int charaterIndex, int formIndex)> _partyList; - private int OptionCount => _partyList.Count; - private int _selectedOption; - - public int SelectedOption - { - get => _selectedOption; - set - { - value = value < 0 ? OptionCount - 1 : value % OptionCount; - if (_selectedOption != value) - { - _selectedOption = value; - _menuSeq = InitializeMenu(true); - _menuSeq.Begin(); - - _subMenuSeq = InitializeSubMenu(true); - _subMenuSeq.Begin(); - } - } - } - - public override ushort MenuNameId => 0xBEB7; - - protected override bool IsEnd => _menuSeq.IsEnd; - - public MenuStatus(IMenuManager menuManager) : base(menuManager) - { - var isFinalMix = menuManager.GameContext.Kernel.IsFinalMix; - Characters = new int[][] - { - isFinalMix ? CharacterSoraFinalMix : CharacterSoraVanilla, - new int[] { CharacterDonald }, - new int[] { CharacterGoofy }, - new int[] { CharacterMickey }, - new int[] { CharacterAuron }, - new int[] { CharacterMulan }, - new int[] { CharacterAladdin }, - new int[] { CharacterJack }, - new int[] { CharacterBeast }, - new int[] { CharacterSparrow }, - new int[] { CharacterSimba }, - new int[] { CharacterTron }, - new int[] { CharacterRiku }, - new int[] { CharacterRoxas }, - }; - FormMsgIds = isFinalMix ? FormFinalMixMsgIds : FormVanillaMsgIds; - - CurrentCharacters = new int[] // TODO: inhert this from the save data - { - CharacterSora, - CharacterRiku, - CharacterGoofy, - CharacterDonald - }; - - // Generates the menu option list - _partyList = new List<(int charaterIndex, int formIndex)>(); - for (var i = 0; i < CurrentCharacters.Length; i++) - { - var characterId = CurrentCharacters[i]; - var characterDesc = Characters[characterId]; - _partyList.Add((characterDesc[0], -1)); - for (var j = 1; j < characterDesc.Length; j++) - _partyList.Add((characterId, characterDesc[j])); - } - - _menuSeq = InitializeMenu(false); - _menuSeq.Begin(); - - _subMenuSeq = InitializeSubMenu(false); - _subMenuSeq.Begin(); - } - - private IAnimatedSequence InitializeMenu(bool skipIntro) - { - AnimatedSequenceDesc createSequenceDesc(int index, int msgId, int[] optionSeq) => new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : optionSeq[OptionStart], - SequenceIndexLoop = SelectedOption == index ? optionSeq[OptionHover] : optionSeq[OptionSel], - SequenceIndexEnd = optionSeq[OptionEnd], - StackIndex = index, - StackWidth = 0, - StackHeight = AnimatedSequenceDesc.DefaultStacking, - Flags = AnimationFlags.TextTranslateX | - AnimationFlags.ChildStackHorizontally, - MessageId = (ushort)msgId, - Children = SelectedOption == index ? new List - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = 25, - TextAnchor = TextAnchor.BottomLeft, - Flags = AnimationFlags.NoChildTranslationX, - }, - new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 27, - SequenceIndexLoop = 28, - SequenceIndexEnd = 29, - } - } : new List() - }; - - var animDescs = new List(); - animDescs = _partyList.Select((x, i) => - { - var characterDesc = Characters[x.charaterIndex]; - if (x.formIndex >= 0) - return createSequenceDesc(i, FormMsgIds[x.formIndex], OptionSub); - else - return createSequenceDesc(i, CharacterMsgIds[characterDesc[0]], OptionNormal); - }).ToList(); - - return SequenceFactory.Create(animDescs); - } - private IAnimatedSequence InitializeSubMenu(bool skipIntro) - { - AnimatedSequenceDesc createSequenceDesc(int x, int y, int msgId, int seqId, object value) => new AnimatedSequenceDesc - { - X = x * 170, - Y = y * 24, - SequenceIndexStart = -1, - SequenceIndexLoop = seqId, - SequenceIndexEnd = -1, - StackIndex = 0, - StackWidth = 0, - StackHeight = 0, - Flags = AnimationFlags.TextIgnoreScaling | - AnimationFlags.TextTranslateX | - AnimationFlags.ChildStackHorizontally, - MessageId = (ushort)msgId, - TextAnchor = TextAnchor.BottomLeft, - Children = new List() - { - new AnimatedSequenceDesc - { - SequenceIndexStart = -1, - SequenceIndexLoop = SeqValueText, - SequenceIndexEnd = -1, - StackIndex = 0, - StackWidth = AnimatedSequenceDesc.DefaultStacking, - StackHeight = AnimatedSequenceDesc.DefaultStacking, - Flags = AnimationFlags.TextTranslateX, - TextAnchor = TextAnchor.BottomRight, - MessageText = value.ToString(), - Children = new List(), - } - } - }; - - IEnumerable createMenuForMainPlayer(int characterIndex) - { - var saveData = MenuManager.GameContext.Kernel.SaveData; - if (characterIndex < 0 || characterIndex >= (saveData.Characters?.Length ?? 0)) - { - Log.Err("Stats for character '{0}' is out of range", characterIndex); - yield break; - } - - var formIndex = 0; - var character = saveData.Characters[characterIndex]; - if (character == null) - { - Log.Err("Stats for character '{0}' is null", characterIndex); - yield break; - } - - yield return createSequenceDesc(0, 0, 0xC559, SeqLevel, character.Level); - yield return createSequenceDesc(0, 1, 0xC55A, SeqLevel, saveData.Experience); - yield return createSequenceDesc(0, 2, 0xC55B, SeqLevel, -1); - yield return createSequenceDesc(0, 3, 0xC55C, SeqStats, $"{character.HpCur}/{character.HpMax}"); - yield return createSequenceDesc(0, 4, 0xC55D, SeqStats, $"{character.MpCur}/{character.MpMax}"); - yield return createSequenceDesc(0, 5, 0xC55E, SeqStats, $"-1/{character.ApBoost}"); - yield return createSequenceDesc(0, 6, 0xC55F, SeqStats, -1); - yield return createSequenceDesc(1, 0, 0xC560, SeqBattle, character.StrengthBoost); - yield return createSequenceDesc(1, 1, 0xC561, SeqBattle, character.MagicBoost); - yield return createSequenceDesc(1, 2, 0xC562, SeqBattle, character.DefenseBoost); - yield return createSequenceDesc(1, 3, 0xC563, SeqResistance, "-1%"); - yield return createSequenceDesc(1, 4, 0xC564, SeqResistance, "-1%"); - yield return createSequenceDesc(1, 5, 0xC565, SeqResistance, "-1%"); - yield return createSequenceDesc(1, 6, 0xC566, SeqResistance, "-1%"); - yield return createSequenceDesc(0, 7, 0xC567, SeqBonus, saveData.BonusLevel); - yield return createSequenceDesc(1, 7, 0xC5AA, SeqBonus, saveData.DriveForms[formIndex++].Level); - yield return createSequenceDesc(0, 8, 0xC5AB, SeqBonus, saveData.DriveForms[formIndex++].Level); - if (MenuManager.GameContext.Kernel.IsFinalMix) - yield return createSequenceDesc(1, 8, 0xCE9B, SeqBonus, saveData.DriveForms[formIndex++].Level); - yield return createSequenceDesc(0, 9, 0xC5AC, SeqBonus, saveData.DriveForms[formIndex++].Level); - yield return createSequenceDesc(1, 9, 0xC5AD, SeqBonus, saveData.DriveForms[formIndex++].Level); - } - - IEnumerable createMenuForPartyMember(int characterIndex) - { - var saveData = MenuManager.GameContext.Kernel.SaveData; - if (characterIndex < 0 || characterIndex >= (saveData.Characters?.Length ?? 0)) - { - Log.Err("Stats for character '{0}' is out of range", characterIndex); - yield break; - } - - var character = saveData.Characters[characterIndex]; - if (character == null) - { - Log.Err("Stats for character '{0}' is null", characterIndex); - yield break; - } - - yield return createSequenceDesc(0, 0, 0xC559, SeqLevel, character.Level); - yield return createSequenceDesc(0, 1, 0xC55A, SeqLevel, saveData.Experience); - yield return createSequenceDesc(0, 2, 0xC55B, SeqLevel, -1); - yield return createSequenceDesc(0, 3, 0xC55C, SeqStats, $"{character.HpCur}/{character.HpMax}"); - yield return createSequenceDesc(0, 4, 0xC55D, SeqStats, $"{character.MpCur}/{character.MpMax}"); - yield return createSequenceDesc(0, 5, 0xC55E, SeqStats, $"-1/{character.ApBoost}"); - yield return createSequenceDesc(1, 0, 0xC560, SeqBattle, character.StrengthBoost); - yield return createSequenceDesc(1, 1, 0xC561, SeqBattle, character.MagicBoost); - yield return createSequenceDesc(1, 2, 0xC562, SeqBattle, character.DefenseBoost); - yield return createSequenceDesc(1, 3, 0xC563, SeqResistance, "-1%"); - yield return createSequenceDesc(1, 4, 0xC564, SeqResistance, "-1%"); - yield return createSequenceDesc(1, 5, 0xC565, SeqResistance, "-1%"); - yield return createSequenceDesc(1, 6, 0xC566, SeqResistance, "-1%"); - } - - IEnumerable createMenuForDriveForm(int driveFormIndex) - { - var saveData = MenuManager.GameContext.Kernel.SaveData; - if (driveFormIndex < 0 || driveFormIndex >= (saveData.DriveForms?.Length ?? 0)) - { - Log.Err("Stats for drive form '{0}' is out of range", driveFormIndex); - yield break; - } - var driveForm = saveData.DriveForms[driveFormIndex]; - if (driveForm == null) - { - Log.Err("Stats for drive form '{0}' is null", driveFormIndex); - yield break; - } - - yield return createSequenceDesc(0, 0, 0xC569, SeqLevel, driveForm.Level); - yield return createSequenceDesc(0, 1, 0xC55A, SeqLevel, driveForm.Experience); - yield return createSequenceDesc(0, 2, 0xC55B, SeqLevel, -1); - yield return createSequenceDesc(0, 3, 0xC583, SeqStats, -1); - yield return createSequenceDesc(1, 0, 0xC560, SeqBattle, -1); - yield return createSequenceDesc(1, 1, 0xC561, SeqBattle, -1); - yield return createSequenceDesc(1, 2, 0xC562, SeqBattle, -1); - yield return createSequenceDesc(1, 3, 0xC563, SeqResistance, -1); - yield return createSequenceDesc(1, 4, 0xC564, SeqResistance, -1); - yield return createSequenceDesc(1, 5, 0xC565, SeqResistance, -1); - yield return createSequenceDesc(1, 6, 0xC566, SeqResistance, -1); - } - - var animDesc = new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : WindowStart, - SequenceIndexLoop = WindowLoop, - SequenceIndexEnd = WindowEnd, - StackHeight = AnimatedSequenceDesc.DefaultStacking, - Flags = AnimationFlags.TextTranslateX, - Children = null - }; - - var partyMemberDesc = _partyList[SelectedOption]; - if (partyMemberDesc.formIndex < 0) - { - switch (partyMemberDesc.charaterIndex) - { - case CharacterSora: - case CharacterRoxas: - animDesc.Children = createMenuForMainPlayer(partyMemberDesc.charaterIndex).ToList(); - break; - default: - animDesc.Children = createMenuForPartyMember(partyMemberDesc.charaterIndex).ToList(); - break; - } - } - else - { - animDesc.Children = createMenuForDriveForm(partyMemberDesc.formIndex).ToList(); - } - - - return SequenceFactory.Create(animDesc); - } - - protected override void ProcessInput(IInput input) - { - if (input.Repeated.Up) - SelectedOption--; - else if (input.Repeated.Down) - SelectedOption++; - else if (input.Triggered.Confirm) - { - // No selection - } - else - base.ProcessInput(input); - } - - public override void Open() - { - _menuSeq.Begin(); - base.Open(); - } - - public override void Close() - { - _menuSeq.End(); - base.Close(); - } - - protected override void MyUpdate(double deltaTime) - { - _menuSeq.Update(deltaTime); - _subMenuSeq.Update(deltaTime); - } - - protected override void MyDraw() - { - _menuSeq.Draw(0, 0); - _subMenuSeq.Draw(0, 0); - } - - public override string ToString() => "STATUS"; - } -} +using OpenKh.Engine.Renderers; +using OpenKh.Common; +using OpenKh.Game.Infrastructure; +using System.Collections.Generic; +using System.Linq; +using OpenKh.Engine.Input; + +namespace OpenKh.Game.Menu +{ + public class MenuStatus : MenuBase + { + const int OptionHover = 0; + const int OptionStart = 1; + const int OptionSel = 2; + const int OptionEnd = 3; + private readonly int[] OptionNormal = new int[] + { + 132, + 133, + 134, + 135 + }; + private readonly int[] OptionSub = new int[] + { + 128, + 129, + 130, + 131 + }; + + private const int CharacterSora = 0; + private const int CharacterRoxas = 14; + private const int CharacterDonald = 1; + private const int CharacterGoofy = 2; + private const int CharacterMickey = 3; + private const int CharacterAuron = 4; + private const int CharacterMulan = 5; + private const int CharacterAladdin = 6; + private const int CharacterJack = 7; + private const int CharacterBeast = 8; + private const int CharacterSparrow = 9; + private const int CharacterSimba = 10; + private const int CharacterTron = 11; + private const int CharacterRiku = 12; + + private const int FormVanillaValor = 0; + private const int FormVanillaWisdom = 1; + private const int FormVanillaMaster = 2; + private const int FormVanillaFinal = 3; + private const int FormVanillaSummon = 4; + private const int FormFinalMixValor = 0; + private const int FormFinalMixWisdom = 1; + private const int FormFinalMixLimit = 2; + private const int FormFinalMixMaster = 3; + private const int FormFinalMixFinal = 4; + private const int FormFinalMixSummon = 5; + + private const int SeqResistance = 139; + private const int SeqLevel = 137; + private const int SeqBonus = 144; + private const int SeqBattle = 150; + private const int SeqStats = 143; + private const int WindowStart = 140; + private const int WindowLoop = 141; + private const int WindowEnd = 142; + private const int SeqValueText = 124; + + private static readonly int[] CharacterMsgIds = new int[] + { + 0x851F, + 0x8520, + 0x8521, + 0x8522, + 0x8523, + 0x8525, // 0x8524 for Ping + 0x8526, + 0x8527, + 0x8528, + 0x8529, + 0x852A, + 0x852B, + 0x852C, + 0x852D, + }; + + private static readonly int[] FormVanillaMsgIds = new int[] + { + 0xC32A, + 0xC32B, + 0xC32C, + 0xC32D, + //0xC5B1, // no summon here + 0x864A, // antiform + }; + + private static readonly int[] FormFinalMixMsgIds = new int[] + { + 0xC32A, + 0xC32B, + 0xCF0B, + 0xC32C, + 0xC32D, + //0xC5B1, // no summon here + 0x864A, // antiform + }; + + private static readonly int[] CharacterSoraVanilla = new int[] + { + CharacterSora, + FormVanillaValor, + FormVanillaWisdom, + FormVanillaMaster, + FormVanillaFinal, + FormVanillaSummon + }; + private static readonly int[] CharacterSoraFinalMix = new int[] + { + CharacterSora, + FormFinalMixValor, + FormFinalMixWisdom, + FormFinalMixLimit, + FormFinalMixMaster, + FormFinalMixFinal, + FormFinalMixSummon + }; + + private readonly int[][] Characters; + private readonly int[] FormMsgIds; + private readonly int[] CurrentCharacters; + private IAnimatedSequence _menuSeq; + private IAnimatedSequence _subMenuSeq; + private List<(int charaterIndex, int formIndex)> _partyList; + private int OptionCount => _partyList.Count; + private int _selectedOption; + + public int SelectedOption + { + get => _selectedOption; + set + { + value = value < 0 ? OptionCount - 1 : value % OptionCount; + if (_selectedOption != value) + { + _selectedOption = value; + _menuSeq = InitializeMenu(true); + _menuSeq.Begin(); + + _subMenuSeq = InitializeSubMenu(true); + _subMenuSeq.Begin(); + } + } + } + + public override ushort MenuNameId => 0xBEB7; + + protected override bool IsEnd => _menuSeq.IsEnd; + + public MenuStatus(IMenuManager menuManager) : base(menuManager) + { + var isFinalMix = menuManager.GameContext.Kernel.IsFinalMix; + Characters = new int[][] + { + isFinalMix ? CharacterSoraFinalMix : CharacterSoraVanilla, + new int[] { CharacterDonald }, + new int[] { CharacterGoofy }, + new int[] { CharacterMickey }, + new int[] { CharacterAuron }, + new int[] { CharacterMulan }, + new int[] { CharacterAladdin }, + new int[] { CharacterJack }, + new int[] { CharacterBeast }, + new int[] { CharacterSparrow }, + new int[] { CharacterSimba }, + new int[] { CharacterTron }, + new int[] { CharacterRiku }, + new int[] { CharacterRoxas }, + }; + FormMsgIds = isFinalMix ? FormFinalMixMsgIds : FormVanillaMsgIds; + + CurrentCharacters = new int[] // TODO: inhert this from the save data + { + CharacterSora, + CharacterRiku, + CharacterGoofy, + CharacterDonald + }; + + // Generates the menu option list + _partyList = new List<(int charaterIndex, int formIndex)>(); + for (var i = 0; i < CurrentCharacters.Length; i++) + { + var characterId = CurrentCharacters[i]; + var characterDesc = Characters[characterId]; + _partyList.Add((characterDesc[0], -1)); + for (var j = 1; j < characterDesc.Length; j++) + _partyList.Add((characterId, characterDesc[j])); + } + + _menuSeq = InitializeMenu(false); + _menuSeq.Begin(); + + _subMenuSeq = InitializeSubMenu(false); + _subMenuSeq.Begin(); + } + + private IAnimatedSequence InitializeMenu(bool skipIntro) + { + AnimatedSequenceDesc createSequenceDesc(int index, int msgId, int[] optionSeq) => new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : optionSeq[OptionStart], + SequenceIndexLoop = SelectedOption == index ? optionSeq[OptionHover] : optionSeq[OptionSel], + SequenceIndexEnd = optionSeq[OptionEnd], + StackIndex = index, + StackWidth = 0, + StackHeight = AnimatedSequenceDesc.DefaultStacking, + Flags = AnimationFlags.TextTranslateX | + AnimationFlags.ChildStackHorizontally, + MessageId = (ushort)msgId, + Children = SelectedOption == index ? new List + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = 25, + TextAnchor = TextAnchor.BottomLeft, + Flags = AnimationFlags.NoChildTranslationX, + }, + new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 27, + SequenceIndexLoop = 28, + SequenceIndexEnd = 29, + } + } : new List() + }; + + var animDescs = new List(); + animDescs = _partyList.Select((x, i) => + { + var characterDesc = Characters[x.charaterIndex]; + if (x.formIndex >= 0) + return createSequenceDesc(i, FormMsgIds[x.formIndex], OptionSub); + else + return createSequenceDesc(i, CharacterMsgIds[characterDesc[0]], OptionNormal); + }).ToList(); + + return SequenceFactory.Create(animDescs); + } + private IAnimatedSequence InitializeSubMenu(bool skipIntro) + { + AnimatedSequenceDesc createSequenceDesc(int x, int y, int msgId, int seqId, object value) => new AnimatedSequenceDesc + { + X = x * 170, + Y = y * 24, + SequenceIndexStart = -1, + SequenceIndexLoop = seqId, + SequenceIndexEnd = -1, + StackIndex = 0, + StackWidth = 0, + StackHeight = 0, + Flags = AnimationFlags.TextIgnoreScaling | + AnimationFlags.TextTranslateX | + AnimationFlags.ChildStackHorizontally, + MessageId = (ushort)msgId, + TextAnchor = TextAnchor.BottomLeft, + Children = new List() + { + new AnimatedSequenceDesc + { + SequenceIndexStart = -1, + SequenceIndexLoop = SeqValueText, + SequenceIndexEnd = -1, + StackIndex = 0, + StackWidth = AnimatedSequenceDesc.DefaultStacking, + StackHeight = AnimatedSequenceDesc.DefaultStacking, + Flags = AnimationFlags.TextTranslateX, + TextAnchor = TextAnchor.BottomRight, + MessageText = value.ToString(), + Children = new List(), + } + } + }; + + IEnumerable createMenuForMainPlayer(int characterIndex) + { + var saveData = MenuManager.GameContext.Kernel.SaveData; + if (characterIndex < 0 || characterIndex >= (saveData.Characters?.Length ?? 0)) + { + Log.Err("Stats for character '{0}' is out of range", characterIndex); + yield break; + } + + var formIndex = 0; + var character = saveData.Characters[characterIndex]; + if (character == null) + { + Log.Err("Stats for character '{0}' is null", characterIndex); + yield break; + } + + yield return createSequenceDesc(0, 0, 0xC559, SeqLevel, character.Level); + yield return createSequenceDesc(0, 1, 0xC55A, SeqLevel, saveData.Experience); + yield return createSequenceDesc(0, 2, 0xC55B, SeqLevel, -1); + yield return createSequenceDesc(0, 3, 0xC55C, SeqStats, $"{character.HpCur}/{character.HpMax}"); + yield return createSequenceDesc(0, 4, 0xC55D, SeqStats, $"{character.MpCur}/{character.MpMax}"); + yield return createSequenceDesc(0, 5, 0xC55E, SeqStats, $"-1/{character.ApBoost}"); + yield return createSequenceDesc(0, 6, 0xC55F, SeqStats, -1); + yield return createSequenceDesc(1, 0, 0xC560, SeqBattle, character.StrengthBoost); + yield return createSequenceDesc(1, 1, 0xC561, SeqBattle, character.MagicBoost); + yield return createSequenceDesc(1, 2, 0xC562, SeqBattle, character.DefenseBoost); + yield return createSequenceDesc(1, 3, 0xC563, SeqResistance, "-1%"); + yield return createSequenceDesc(1, 4, 0xC564, SeqResistance, "-1%"); + yield return createSequenceDesc(1, 5, 0xC565, SeqResistance, "-1%"); + yield return createSequenceDesc(1, 6, 0xC566, SeqResistance, "-1%"); + yield return createSequenceDesc(0, 7, 0xC567, SeqBonus, saveData.BonusLevel); + yield return createSequenceDesc(1, 7, 0xC5AA, SeqBonus, saveData.DriveForms[formIndex++].Level); + yield return createSequenceDesc(0, 8, 0xC5AB, SeqBonus, saveData.DriveForms[formIndex++].Level); + if (MenuManager.GameContext.Kernel.IsFinalMix) + yield return createSequenceDesc(1, 8, 0xCE9B, SeqBonus, saveData.DriveForms[formIndex++].Level); + yield return createSequenceDesc(0, 9, 0xC5AC, SeqBonus, saveData.DriveForms[formIndex++].Level); + yield return createSequenceDesc(1, 9, 0xC5AD, SeqBonus, saveData.DriveForms[formIndex++].Level); + } + + IEnumerable createMenuForPartyMember(int characterIndex) + { + var saveData = MenuManager.GameContext.Kernel.SaveData; + if (characterIndex < 0 || characterIndex >= (saveData.Characters?.Length ?? 0)) + { + Log.Err("Stats for character '{0}' is out of range", characterIndex); + yield break; + } + + var character = saveData.Characters[characterIndex]; + if (character == null) + { + Log.Err("Stats for character '{0}' is null", characterIndex); + yield break; + } + + yield return createSequenceDesc(0, 0, 0xC559, SeqLevel, character.Level); + yield return createSequenceDesc(0, 1, 0xC55A, SeqLevel, saveData.Experience); + yield return createSequenceDesc(0, 2, 0xC55B, SeqLevel, -1); + yield return createSequenceDesc(0, 3, 0xC55C, SeqStats, $"{character.HpCur}/{character.HpMax}"); + yield return createSequenceDesc(0, 4, 0xC55D, SeqStats, $"{character.MpCur}/{character.MpMax}"); + yield return createSequenceDesc(0, 5, 0xC55E, SeqStats, $"-1/{character.ApBoost}"); + yield return createSequenceDesc(1, 0, 0xC560, SeqBattle, character.StrengthBoost); + yield return createSequenceDesc(1, 1, 0xC561, SeqBattle, character.MagicBoost); + yield return createSequenceDesc(1, 2, 0xC562, SeqBattle, character.DefenseBoost); + yield return createSequenceDesc(1, 3, 0xC563, SeqResistance, "-1%"); + yield return createSequenceDesc(1, 4, 0xC564, SeqResistance, "-1%"); + yield return createSequenceDesc(1, 5, 0xC565, SeqResistance, "-1%"); + yield return createSequenceDesc(1, 6, 0xC566, SeqResistance, "-1%"); + } + + IEnumerable createMenuForDriveForm(int driveFormIndex) + { + var saveData = MenuManager.GameContext.Kernel.SaveData; + if (driveFormIndex < 0 || driveFormIndex >= (saveData.DriveForms?.Length ?? 0)) + { + Log.Err("Stats for drive form '{0}' is out of range", driveFormIndex); + yield break; + } + var driveForm = saveData.DriveForms[driveFormIndex]; + if (driveForm == null) + { + Log.Err("Stats for drive form '{0}' is null", driveFormIndex); + yield break; + } + + yield return createSequenceDesc(0, 0, 0xC569, SeqLevel, driveForm.Level); + yield return createSequenceDesc(0, 1, 0xC55A, SeqLevel, driveForm.Experience); + yield return createSequenceDesc(0, 2, 0xC55B, SeqLevel, -1); + yield return createSequenceDesc(0, 3, 0xC583, SeqStats, -1); + yield return createSequenceDesc(1, 0, 0xC560, SeqBattle, -1); + yield return createSequenceDesc(1, 1, 0xC561, SeqBattle, -1); + yield return createSequenceDesc(1, 2, 0xC562, SeqBattle, -1); + yield return createSequenceDesc(1, 3, 0xC563, SeqResistance, -1); + yield return createSequenceDesc(1, 4, 0xC564, SeqResistance, -1); + yield return createSequenceDesc(1, 5, 0xC565, SeqResistance, -1); + yield return createSequenceDesc(1, 6, 0xC566, SeqResistance, -1); + } + + var animDesc = new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : WindowStart, + SequenceIndexLoop = WindowLoop, + SequenceIndexEnd = WindowEnd, + StackHeight = AnimatedSequenceDesc.DefaultStacking, + Flags = AnimationFlags.TextTranslateX, + Children = null + }; + + var partyMemberDesc = _partyList[SelectedOption]; + if (partyMemberDesc.formIndex < 0) + { + switch (partyMemberDesc.charaterIndex) + { + case CharacterSora: + case CharacterRoxas: + animDesc.Children = createMenuForMainPlayer(partyMemberDesc.charaterIndex).ToList(); + break; + default: + animDesc.Children = createMenuForPartyMember(partyMemberDesc.charaterIndex).ToList(); + break; + } + } + else + { + animDesc.Children = createMenuForDriveForm(partyMemberDesc.formIndex).ToList(); + } + + + return SequenceFactory.Create(animDesc); + } + + protected override void ProcessInput(IInput input) + { + if (input.Repeated.Up) + SelectedOption--; + else if (input.Repeated.Down) + SelectedOption++; + else if (input.Triggered.Confirm) + { + // No selection + } + else + base.ProcessInput(input); + } + + public override void Open() + { + _menuSeq.Begin(); + base.Open(); + } + + public override void Close() + { + _menuSeq.End(); + base.Close(); + } + + protected override void MyUpdate(double deltaTime) + { + _menuSeq.Update(deltaTime); + _subMenuSeq.Update(deltaTime); + } + + protected override void MyDraw() + { + _menuSeq.Draw(0, 0); + _subMenuSeq.Draw(0, 0); + } + + public override string ToString() => "STATUS"; + } +} diff --git a/OpenKh.Game/Menu/MenuTemplate.cs b/OpenKh.Game/Menu/MenuTemplate.cs index ccde4cd37..60ca27af5 100644 --- a/OpenKh.Game/Menu/MenuTemplate.cs +++ b/OpenKh.Game/Menu/MenuTemplate.cs @@ -1,108 +1,108 @@ -using OpenKh.Engine.Input; -using OpenKh.Engine.Renderers; -using OpenKh.Game.Infrastructure; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Game.Menu -{ - public class MenuTemplate : MenuBase - { - private const int OptionCount = 3; - private readonly IMenuManager _menuManager; - private readonly int _stackIndex; - private IAnimatedSequence _menuSeq; - private int _selectedOption; - - public int SelectedOption - { - get => _selectedOption; - set - { - value = value < 0 ? OptionCount - 1 : value % OptionCount; - if (_selectedOption != value) - { - _selectedOption = value; - _menuSeq = InitializeMenu(true); - _menuSeq.Begin(); - } - } - } - - public override ushort MenuNameId => 0; - protected override bool IsEnd => _menuSeq.IsEnd; - - public MenuTemplate(IMenuManager menuManager, int stackIndex) : base(menuManager) - { - _menuManager = menuManager; - _stackIndex = stackIndex; - _menuSeq = InitializeMenu(false); - } - - private IAnimatedSequence InitializeMenu(bool skipIntro) - { - return SequenceFactory.Create(Enumerable.Range(0, OptionCount) - .Select(i => new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 133, - SequenceIndexLoop = SelectedOption == i ? 132 : 134, - SequenceIndexEnd = 135, - StackIndex = i, - StackWidth = 0, - StackHeight = AnimatedSequenceDesc.DefaultStacking, - Flags = AnimationFlags.TextTranslateX | - AnimationFlags.ChildStackHorizontally, - MessageText = $"TEMPLATE {_stackIndex}-{i}", - Children = SelectedOption == i ? new List - { - new AnimatedSequenceDesc - { - SequenceIndexLoop = 25, - TextAnchor = TextAnchor.BottomLeft, - Flags = AnimationFlags.NoChildTranslationX, - }, - new AnimatedSequenceDesc - { - SequenceIndexStart = skipIntro ? -1 : 27, - SequenceIndexLoop = 28, - SequenceIndexEnd = 29, - } - } : new List() - })); - } - - protected override void ProcessInput(IInput input) - { - if (input.Repeated.Up) - SelectedOption--; - else if (input.Repeated.Down) - SelectedOption++; - else if (input.Triggered.Confirm) - { - Push(new MenuTemplate(_menuManager, _stackIndex + 1)); - } - else - base.ProcessInput(input); - } - - public override void Open() - { - _menuSeq.Begin(); - base.Open(); - } - - public override void Close() - { - _menuSeq.End(); - base.Close(); - } - - protected override void MyUpdate(double deltaTime) => - _menuSeq.Update(deltaTime); - - protected override void MyDraw() => - _menuSeq.Draw(0, 0); - - public override string ToString() => "TEMPLATE"; - } -} +using OpenKh.Engine.Input; +using OpenKh.Engine.Renderers; +using OpenKh.Game.Infrastructure; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Game.Menu +{ + public class MenuTemplate : MenuBase + { + private const int OptionCount = 3; + private readonly IMenuManager _menuManager; + private readonly int _stackIndex; + private IAnimatedSequence _menuSeq; + private int _selectedOption; + + public int SelectedOption + { + get => _selectedOption; + set + { + value = value < 0 ? OptionCount - 1 : value % OptionCount; + if (_selectedOption != value) + { + _selectedOption = value; + _menuSeq = InitializeMenu(true); + _menuSeq.Begin(); + } + } + } + + public override ushort MenuNameId => 0; + protected override bool IsEnd => _menuSeq.IsEnd; + + public MenuTemplate(IMenuManager menuManager, int stackIndex) : base(menuManager) + { + _menuManager = menuManager; + _stackIndex = stackIndex; + _menuSeq = InitializeMenu(false); + } + + private IAnimatedSequence InitializeMenu(bool skipIntro) + { + return SequenceFactory.Create(Enumerable.Range(0, OptionCount) + .Select(i => new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 133, + SequenceIndexLoop = SelectedOption == i ? 132 : 134, + SequenceIndexEnd = 135, + StackIndex = i, + StackWidth = 0, + StackHeight = AnimatedSequenceDesc.DefaultStacking, + Flags = AnimationFlags.TextTranslateX | + AnimationFlags.ChildStackHorizontally, + MessageText = $"TEMPLATE {_stackIndex}-{i}", + Children = SelectedOption == i ? new List + { + new AnimatedSequenceDesc + { + SequenceIndexLoop = 25, + TextAnchor = TextAnchor.BottomLeft, + Flags = AnimationFlags.NoChildTranslationX, + }, + new AnimatedSequenceDesc + { + SequenceIndexStart = skipIntro ? -1 : 27, + SequenceIndexLoop = 28, + SequenceIndexEnd = 29, + } + } : new List() + })); + } + + protected override void ProcessInput(IInput input) + { + if (input.Repeated.Up) + SelectedOption--; + else if (input.Repeated.Down) + SelectedOption++; + else if (input.Triggered.Confirm) + { + Push(new MenuTemplate(_menuManager, _stackIndex + 1)); + } + else + base.ProcessInput(input); + } + + public override void Open() + { + _menuSeq.Begin(); + base.Open(); + } + + public override void Close() + { + _menuSeq.End(); + base.Close(); + } + + protected override void MyUpdate(double deltaTime) => + _menuSeq.Update(deltaTime); + + protected override void MyDraw() => + _menuSeq.Draw(0, 0); + + public override string ToString() => "TEMPLATE"; + } +} diff --git a/OpenKh.Game/OpenKhGame.cs b/OpenKh.Game/OpenKhGame.cs index 8e3fa482a..aaa9b6fca 100644 --- a/OpenKh.Game/OpenKhGame.cs +++ b/OpenKh.Game/OpenKhGame.cs @@ -1,277 +1,277 @@ -using Microsoft.Xna.Framework; -using OpenKh.Common; -using OpenKh.Engine.Input; -using OpenKh.Game.DataContent; -using OpenKh.Game.Debugging; -using OpenKh.Game.Infrastructure; -using OpenKh.Game.States; -using OpenKh.Game.States.Title; -using System; -using System.Collections.Generic; -using System.IO; - -namespace OpenKh.Game -{ - public class OpenKhGameStartup - { - public string ContentPath { get; internal set; } - public string ModPath { get; internal set; } - public int InitialState { get; internal set; } - public int InitialMap { get; internal set; } - public int? InitialPlace { get; internal set; } - public int? InitialSpawnScriptMap { get; internal set; } - public int? InitialSpawnScriptBtl { get; internal set; } - public int? InitialSpawnScriptEvt { get; internal set; } - } - - public class OpenKhGame : Microsoft.Xna.Framework.Game, IStateChange - { - private GraphicsDeviceManager graphics; - - private readonly Dictionary GlobalSettings; - private readonly IDataContent _dataContent; - private readonly Kernel _kernel; - private readonly ArchiveManager archiveManager; - private readonly IInput _input; - private readonly DebugOverlay _debugOverlay; - private readonly OpenKhGameStartup _startup; - private IState state; - private bool _isResolutionChanged; - - public int State - { - set - { - Log.Info("State={0}", value); - switch (value) - { - case 0: - state = new TitleState(); - state.Initialize(GetStateInitDesc()); - break; - case 1: - state = new MapState(); - state.Initialize(GetStateInitDesc()); - break; - case 2: - // WARNING: this is quite buggy since no game context will be passed to - // the menu, but it useful for quick menu testing. - var myState = new MenuState(null); - myState.Initialize(GetStateInitDesc()); - myState.OpenMenu(); - state = myState; - break; - default: - Log.Err("Invalid state {0}", value); - return; - } - - if (state is IDebugConsumer debugConsumer) - { - _debugOverlay.OnUpdate = debugConsumer.DebugUpdate; - _debugOverlay.OnDraw = debugConsumer.DebugDraw; - } - } - } - - public OpenKhGame(OpenKhGameStartup startup) - { - _startup = startup; - GlobalSettings = new Dictionary(); - TryAddSetting("WorldId", startup.InitialMap); - TryAddSetting("PlaceId", startup.InitialPlace); - //TryAddSetting("SpawnId", ); - TryAddSetting("SpawnScriptMap", startup.InitialSpawnScriptMap); - TryAddSetting("SpawnScriptBtl", startup.InitialSpawnScriptBtl); - TryAddSetting("SpawnScriptEvt", startup.InitialSpawnScriptEvt); - - var contentPath = startup.ContentPath ?? Config.DataPath; - var modPathPath = startup.ModPath ?? Config.ModPath; - - _dataContent = CreateDataContent(contentPath, Config.IdxFilePath, Config.ImgFilePath); - _dataContent = new MultipleDataContent(new ModDataContent(modPathPath), _dataContent); - if (Kernel.IsReMixFileHasHdAssetHeader(_dataContent, "fm")) - { - Log.Info("ReMIX files with HD asset header detected"); - _dataContent = new HdAssetContent(_dataContent); - } - - _dataContent = new SafeDataContent(_dataContent); - - _kernel = new Kernel(_dataContent); - if (startup.InitialState != 0) - _kernel.LoadSaveData(Config.LastSave); - - var resolutionWidth = GetResolutionWidth(); - var resolutionHeight = GetResolutionHeight(); - - Log.Info("Internal game resolution set to {0}x{1}", resolutionWidth, resolutionHeight); - - graphics = new GraphicsDeviceManager(this) - { - PreferredBackBufferWidth = (int)Math.Round(resolutionWidth * Config.ResolutionBoost), - PreferredBackBufferHeight = (int)Math.Round(resolutionHeight * Config.ResolutionBoost), - IsFullScreen = Config.IsFullScreen, - }; - - Content.RootDirectory = "Content"; - IsMouseVisible = true; - - archiveManager = new ArchiveManager(_dataContent); - _input = new InputManager(true, new InputKeyboard(), new InputGamepad()); - _debugOverlay = new DebugOverlay(this); - - Config.OnConfigurationChange += () => - { - var resolutionWidth = GetResolutionWidth(); - var resolutionHeight = GetResolutionHeight(); - - var backBufferWidth = (int)Math.Round(resolutionWidth * Config.ResolutionBoost); - var backBufferHeight = (int)Math.Round(resolutionHeight * Config.ResolutionBoost); - - if (graphics.PreferredBackBufferWidth != backBufferWidth || - graphics.PreferredBackBufferHeight != backBufferHeight || - graphics.IsFullScreen != Config.IsFullScreen) - { - graphics.PreferredBackBufferWidth = backBufferWidth; - graphics.PreferredBackBufferHeight = backBufferHeight; - graphics.IsFullScreen = Config.IsFullScreen; - _isResolutionChanged = true; - Log.Info($"Internal game resolution set to {resolutionWidth}x{resolutionHeight}"); - } - }; - } - - protected override void Initialize() - { - Window.AllowUserResizing = true; - Window.Title = "OpenKH Game Engine"; - - _debugOverlay.Initialize(GetStateInitDesc()); - State = _startup.InitialState; - - base.Initialize(); - } - - protected override void LoadContent() - { - // Create a new SpriteBatch, which can be used to draw textures. - - // TODO: use this.Content to load your game content here - } - - protected override void Update(GameTime gameTime) - { - var deltaTimes = GetDeltaTimes(gameTime); - _input.Update(deltaTimes.DeltaTime); - if (false) - Exit(); - - if (Config.DebugMode) - _debugOverlay.Update(deltaTimes); - state?.Update(deltaTimes); - base.Update(gameTime); - } - - protected override void Draw(GameTime gameTime) - { - if (_isResolutionChanged) - { - graphics.ApplyChanges(); - _isResolutionChanged = false; - } - - graphics.GraphicsDevice.Clear(Color.CornflowerBlue); - - var deltaTimes = GetDeltaTimes(gameTime); - - state?.Draw(deltaTimes); - if (Config.DebugMode) - _debugOverlay.Draw(deltaTimes); - base.Draw(gameTime); - } - - private void TryAddSetting(string key, string value) - { - if (!string.IsNullOrEmpty(value)) - GlobalSettings.Add(key, value); - } - - private void TryAddSetting(string key, int value) - { - if (value >= 0) - GlobalSettings.Add(key, value.ToString()); - } - - private void TryAddSetting(string key, int? value) - { - if (value.HasValue) - TryAddSetting(key, value.Value); - } - - private StateInitDesc GetStateInitDesc() - { - return new StateInitDesc - { - DataContent = _dataContent, - ArchiveManager = archiveManager, - Kernel = _kernel, - Input = _input, - ContentManager = Content, - GraphicsDevice = graphics, - StateChange = this, - StateSettings = GlobalSettings, - }; - } - - private DeltaTimes GetDeltaTimes(GameTime gameTime) - { - return new DeltaTimes - { - DeltaTime = 1.0 / 60.0 * Config.GameSpeed - }; - } - - private static IDataContent CreateDataContent(string basePath, string idxFileName, string imgFileName) - { - Log.Info("Base directory is {0}", basePath); - - var idxFullPath = Path.Combine(basePath, idxFileName); - var imgFullPath = Path.Combine(basePath, imgFileName); - if (File.Exists(idxFullPath) && File.Exists(imgFullPath)) - { - Log.Info("{0} and {1} has been found", idxFullPath, imgFullPath); - - var imgStream = File.OpenRead(imgFullPath); - var idxDataContent = File.OpenRead(idxFullPath) - .Using(stream => new IdxDataContent(stream, imgStream)); - return new MultipleDataContent( - new StandardDataContent(basePath), - idxDataContent, - new IdxMultipleDataContent(idxDataContent, imgStream) - ); - } - else - { - Log.Info("No {0} or {1}, loading extracted files", idxFullPath, imgFullPath); - return new StandardDataContent(basePath); - } - } - - private static int GetResolutionHeight() - { - var resolutionHeight = Config.ResolutionHeight; - if (resolutionHeight == 0) - resolutionHeight = Global.ResolutionHeight; - return resolutionHeight; - } - - private int GetResolutionWidth() - { - var resolutionWidth = Config.ResolutionWidth; - if (resolutionWidth == 0) - resolutionWidth = _kernel.IsReMix ? Global.ResolutionRemixWidth : Global.ResolutionWidth; - return resolutionWidth; - } - } -} +using Microsoft.Xna.Framework; +using OpenKh.Common; +using OpenKh.Engine.Input; +using OpenKh.Game.DataContent; +using OpenKh.Game.Debugging; +using OpenKh.Game.Infrastructure; +using OpenKh.Game.States; +using OpenKh.Game.States.Title; +using System; +using System.Collections.Generic; +using System.IO; + +namespace OpenKh.Game +{ + public class OpenKhGameStartup + { + public string ContentPath { get; internal set; } + public string ModPath { get; internal set; } + public int InitialState { get; internal set; } + public int InitialMap { get; internal set; } + public int? InitialPlace { get; internal set; } + public int? InitialSpawnScriptMap { get; internal set; } + public int? InitialSpawnScriptBtl { get; internal set; } + public int? InitialSpawnScriptEvt { get; internal set; } + } + + public class OpenKhGame : Microsoft.Xna.Framework.Game, IStateChange + { + private GraphicsDeviceManager graphics; + + private readonly Dictionary GlobalSettings; + private readonly IDataContent _dataContent; + private readonly Kernel _kernel; + private readonly ArchiveManager archiveManager; + private readonly IInput _input; + private readonly DebugOverlay _debugOverlay; + private readonly OpenKhGameStartup _startup; + private IState state; + private bool _isResolutionChanged; + + public int State + { + set + { + Log.Info("State={0}", value); + switch (value) + { + case 0: + state = new TitleState(); + state.Initialize(GetStateInitDesc()); + break; + case 1: + state = new MapState(); + state.Initialize(GetStateInitDesc()); + break; + case 2: + // WARNING: this is quite buggy since no game context will be passed to + // the menu, but it useful for quick menu testing. + var myState = new MenuState(null); + myState.Initialize(GetStateInitDesc()); + myState.OpenMenu(); + state = myState; + break; + default: + Log.Err("Invalid state {0}", value); + return; + } + + if (state is IDebugConsumer debugConsumer) + { + _debugOverlay.OnUpdate = debugConsumer.DebugUpdate; + _debugOverlay.OnDraw = debugConsumer.DebugDraw; + } + } + } + + public OpenKhGame(OpenKhGameStartup startup) + { + _startup = startup; + GlobalSettings = new Dictionary(); + TryAddSetting("WorldId", startup.InitialMap); + TryAddSetting("PlaceId", startup.InitialPlace); + //TryAddSetting("SpawnId", ); + TryAddSetting("SpawnScriptMap", startup.InitialSpawnScriptMap); + TryAddSetting("SpawnScriptBtl", startup.InitialSpawnScriptBtl); + TryAddSetting("SpawnScriptEvt", startup.InitialSpawnScriptEvt); + + var contentPath = startup.ContentPath ?? Config.DataPath; + var modPathPath = startup.ModPath ?? Config.ModPath; + + _dataContent = CreateDataContent(contentPath, Config.IdxFilePath, Config.ImgFilePath); + _dataContent = new MultipleDataContent(new ModDataContent(modPathPath), _dataContent); + if (Kernel.IsReMixFileHasHdAssetHeader(_dataContent, "fm")) + { + Log.Info("ReMIX files with HD asset header detected"); + _dataContent = new HdAssetContent(_dataContent); + } + + _dataContent = new SafeDataContent(_dataContent); + + _kernel = new Kernel(_dataContent); + if (startup.InitialState != 0) + _kernel.LoadSaveData(Config.LastSave); + + var resolutionWidth = GetResolutionWidth(); + var resolutionHeight = GetResolutionHeight(); + + Log.Info("Internal game resolution set to {0}x{1}", resolutionWidth, resolutionHeight); + + graphics = new GraphicsDeviceManager(this) + { + PreferredBackBufferWidth = (int)Math.Round(resolutionWidth * Config.ResolutionBoost), + PreferredBackBufferHeight = (int)Math.Round(resolutionHeight * Config.ResolutionBoost), + IsFullScreen = Config.IsFullScreen, + }; + + Content.RootDirectory = "Content"; + IsMouseVisible = true; + + archiveManager = new ArchiveManager(_dataContent); + _input = new InputManager(true, new InputKeyboard(), new InputGamepad()); + _debugOverlay = new DebugOverlay(this); + + Config.OnConfigurationChange += () => + { + var resolutionWidth = GetResolutionWidth(); + var resolutionHeight = GetResolutionHeight(); + + var backBufferWidth = (int)Math.Round(resolutionWidth * Config.ResolutionBoost); + var backBufferHeight = (int)Math.Round(resolutionHeight * Config.ResolutionBoost); + + if (graphics.PreferredBackBufferWidth != backBufferWidth || + graphics.PreferredBackBufferHeight != backBufferHeight || + graphics.IsFullScreen != Config.IsFullScreen) + { + graphics.PreferredBackBufferWidth = backBufferWidth; + graphics.PreferredBackBufferHeight = backBufferHeight; + graphics.IsFullScreen = Config.IsFullScreen; + _isResolutionChanged = true; + Log.Info($"Internal game resolution set to {resolutionWidth}x{resolutionHeight}"); + } + }; + } + + protected override void Initialize() + { + Window.AllowUserResizing = true; + Window.Title = "OpenKH Game Engine"; + + _debugOverlay.Initialize(GetStateInitDesc()); + State = _startup.InitialState; + + base.Initialize(); + } + + protected override void LoadContent() + { + // Create a new SpriteBatch, which can be used to draw textures. + + // TODO: use this.Content to load your game content here + } + + protected override void Update(GameTime gameTime) + { + var deltaTimes = GetDeltaTimes(gameTime); + _input.Update(deltaTimes.DeltaTime); + if (false) + Exit(); + + if (Config.DebugMode) + _debugOverlay.Update(deltaTimes); + state?.Update(deltaTimes); + base.Update(gameTime); + } + + protected override void Draw(GameTime gameTime) + { + if (_isResolutionChanged) + { + graphics.ApplyChanges(); + _isResolutionChanged = false; + } + + graphics.GraphicsDevice.Clear(Color.CornflowerBlue); + + var deltaTimes = GetDeltaTimes(gameTime); + + state?.Draw(deltaTimes); + if (Config.DebugMode) + _debugOverlay.Draw(deltaTimes); + base.Draw(gameTime); + } + + private void TryAddSetting(string key, string value) + { + if (!string.IsNullOrEmpty(value)) + GlobalSettings.Add(key, value); + } + + private void TryAddSetting(string key, int value) + { + if (value >= 0) + GlobalSettings.Add(key, value.ToString()); + } + + private void TryAddSetting(string key, int? value) + { + if (value.HasValue) + TryAddSetting(key, value.Value); + } + + private StateInitDesc GetStateInitDesc() + { + return new StateInitDesc + { + DataContent = _dataContent, + ArchiveManager = archiveManager, + Kernel = _kernel, + Input = _input, + ContentManager = Content, + GraphicsDevice = graphics, + StateChange = this, + StateSettings = GlobalSettings, + }; + } + + private DeltaTimes GetDeltaTimes(GameTime gameTime) + { + return new DeltaTimes + { + DeltaTime = 1.0 / 60.0 * Config.GameSpeed + }; + } + + private static IDataContent CreateDataContent(string basePath, string idxFileName, string imgFileName) + { + Log.Info("Base directory is {0}", basePath); + + var idxFullPath = Path.Combine(basePath, idxFileName); + var imgFullPath = Path.Combine(basePath, imgFileName); + if (File.Exists(idxFullPath) && File.Exists(imgFullPath)) + { + Log.Info("{0} and {1} has been found", idxFullPath, imgFullPath); + + var imgStream = File.OpenRead(imgFullPath); + var idxDataContent = File.OpenRead(idxFullPath) + .Using(stream => new IdxDataContent(stream, imgStream)); + return new MultipleDataContent( + new StandardDataContent(basePath), + idxDataContent, + new IdxMultipleDataContent(idxDataContent, imgStream) + ); + } + else + { + Log.Info("No {0} or {1}, loading extracted files", idxFullPath, imgFullPath); + return new StandardDataContent(basePath); + } + } + + private static int GetResolutionHeight() + { + var resolutionHeight = Config.ResolutionHeight; + if (resolutionHeight == 0) + resolutionHeight = Global.ResolutionHeight; + return resolutionHeight; + } + + private int GetResolutionWidth() + { + var resolutionWidth = Config.ResolutionWidth; + if (resolutionWidth == 0) + resolutionWidth = _kernel.IsReMix ? Global.ResolutionRemixWidth : Global.ResolutionWidth; + return resolutionWidth; + } + } +} diff --git a/OpenKh.Game/Program.cs b/OpenKh.Game/Program.cs index 01dd5df26..86f95fbdc 100644 --- a/OpenKh.Game/Program.cs +++ b/OpenKh.Game/Program.cs @@ -1,139 +1,139 @@ -using McMaster.Extensions.CommandLineUtils; -using Microsoft.Win32.SafeHandles; -using OpenKh.Common; -using System; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Text; - -namespace OpenKh.Game -{ - [Command("OpenKh.Game")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - public class Program - { - [DllImport("kernel32.dll", SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool AllocConsole(); - - [DllImport("kernel32.dll", SetLastError = true)] - private static extern IntPtr GetStdHandle(int nStdHandle); - - public static readonly string ProductVersion = typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - [STAThread] - static void Main(string[] args) - { - Log.Info("Boot"); - Log.Info("Version {0}", ProductVersion); - void run() - { - Config.Open(); - Config.Listen(); - - CommandLineApplication.Execute(args); - - Config.Close(); - Log.Info("End"); - } - -#if DEBUG - run(); -#else - try - { - run(); - } - catch (Exception ex) - { - Log.Err("A fatal error has occurred. Please attach this log to https://github.com/xeeynamo/openkh/issues"); - Catch(ex); - Log.Close(); - - throw ex; - } -#endif - Log.Close(); - } - - private static string GetVersion() => ProductVersion; - - - [Option("--data ", "Location of game's data", CommandOptionType.SingleValue)] - public string ContentPath { get; } - - - [Option("--modpath ", "Location of game's modified assets", CommandOptionType.SingleValue)] - public string ModPath { get; } - - [Option(CommandOptionType.NoValue, ShortName = "v", LongName = "console", Description = "Show the console output (Windows only)")] - public bool ShowConsole { get; set; } - - [Option("--state ", "Boot the game into a specific state (0 = Title, 1 = Map, 2 = Menu)", CommandOptionType.SingleValue)] - public int InitialState { get; set; } - - [Option("--world ", "Boot the game into a specific world ID (eg. 'dc')", CommandOptionType.SingleValue)] - public string InitialWorld { get; set; } - - [Option("--place ", "Boot the game into a specific place ID (eg. for dc06 specify '6')", CommandOptionType.SingleValue)] - public int InitialPlace { get; set; } = -1; - - [Option("--spawn-map ", "Force the boot map to use a specific spawn script program ID for MAP", CommandOptionType.SingleValue)] - public int InitialSpawnScriptMap { get; set; } = -1; - - [Option("--spawn-btl ", "Force the boot map to use a specific spawn script program ID for BTL", CommandOptionType.SingleValue)] - public int InitialSpawnScriptBtl { get; set; } = -1; - - [Option("--spawn-evt ", "Force the boot map to use a specific spawn script program ID for EVT", CommandOptionType.SingleValue)] - public int InitialSpawnScriptEvt { get; set; } = -1; - - private void OnExecute() - { - if (ShowConsole && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - const int STD_OUTPUT_HANDLE = -11; - AllocConsole(); - - var stdHandle = GetStdHandle(STD_OUTPUT_HANDLE); - var safeFileHandle = new SafeFileHandle(stdHandle, true); - var fileStream = new FileStream(safeFileHandle, FileAccess.Write); - var standardOutput = new StreamWriter(fileStream, Encoding.UTF8); - standardOutput.AutoFlush = true; - - Console.SetOut(standardOutput); - } - - using var game = new OpenKhGame(new OpenKhGameStartup - { - ContentPath = ContentPath, - ModPath = ModPath, - InitialState = InitialState, - InitialMap = Kh2.Constants.WorldIds - .Select((world, index) => (world, index)) - .Concat(new (string world, int index)[] - { - (InitialWorld, -1) - }) - .Where(x => x.world == InitialWorld) - .Select(x => x.index) - .FirstOrDefault(), - InitialPlace = InitialPlace >= 0 ? (int?)InitialPlace : null, - InitialSpawnScriptMap = InitialSpawnScriptMap >= 0 ? (int?)InitialSpawnScriptMap : null, - InitialSpawnScriptBtl = InitialSpawnScriptBtl >= 0 ? (int?)InitialSpawnScriptBtl : null, - InitialSpawnScriptEvt = InitialSpawnScriptEvt >= 0 ? (int?)InitialSpawnScriptEvt : null, - }); - - game.Run(); - } - - private static void Catch(Exception ex) - { - Log.Err("{0}: {1}:\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace); - if (ex.InnerException != null) - Catch(ex.InnerException); - } - } -} +using McMaster.Extensions.CommandLineUtils; +using Microsoft.Win32.SafeHandles; +using OpenKh.Common; +using System; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Text; + +namespace OpenKh.Game +{ + [Command("OpenKh.Game")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + public class Program + { + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool AllocConsole(); + + [DllImport("kernel32.dll", SetLastError = true)] + private static extern IntPtr GetStdHandle(int nStdHandle); + + public static readonly string ProductVersion = typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + [STAThread] + static void Main(string[] args) + { + Log.Info("Boot"); + Log.Info("Version {0}", ProductVersion); + void run() + { + Config.Open(); + Config.Listen(); + + CommandLineApplication.Execute(args); + + Config.Close(); + Log.Info("End"); + } + +#if DEBUG + run(); +#else + try + { + run(); + } + catch (Exception ex) + { + Log.Err("A fatal error has occurred. Please attach this log to https://github.com/xeeynamo/openkh/issues"); + Catch(ex); + Log.Close(); + + throw ex; + } +#endif + Log.Close(); + } + + private static string GetVersion() => ProductVersion; + + + [Option("--data ", "Location of game's data", CommandOptionType.SingleValue)] + public string ContentPath { get; } + + + [Option("--modpath ", "Location of game's modified assets", CommandOptionType.SingleValue)] + public string ModPath { get; } + + [Option(CommandOptionType.NoValue, ShortName = "v", LongName = "console", Description = "Show the console output (Windows only)")] + public bool ShowConsole { get; set; } + + [Option("--state ", "Boot the game into a specific state (0 = Title, 1 = Map, 2 = Menu)", CommandOptionType.SingleValue)] + public int InitialState { get; set; } + + [Option("--world ", "Boot the game into a specific world ID (eg. 'dc')", CommandOptionType.SingleValue)] + public string InitialWorld { get; set; } + + [Option("--place ", "Boot the game into a specific place ID (eg. for dc06 specify '6')", CommandOptionType.SingleValue)] + public int InitialPlace { get; set; } = -1; + + [Option("--spawn-map ", "Force the boot map to use a specific spawn script program ID for MAP", CommandOptionType.SingleValue)] + public int InitialSpawnScriptMap { get; set; } = -1; + + [Option("--spawn-btl ", "Force the boot map to use a specific spawn script program ID for BTL", CommandOptionType.SingleValue)] + public int InitialSpawnScriptBtl { get; set; } = -1; + + [Option("--spawn-evt ", "Force the boot map to use a specific spawn script program ID for EVT", CommandOptionType.SingleValue)] + public int InitialSpawnScriptEvt { get; set; } = -1; + + private void OnExecute() + { + if (ShowConsole && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + const int STD_OUTPUT_HANDLE = -11; + AllocConsole(); + + var stdHandle = GetStdHandle(STD_OUTPUT_HANDLE); + var safeFileHandle = new SafeFileHandle(stdHandle, true); + var fileStream = new FileStream(safeFileHandle, FileAccess.Write); + var standardOutput = new StreamWriter(fileStream, Encoding.UTF8); + standardOutput.AutoFlush = true; + + Console.SetOut(standardOutput); + } + + using var game = new OpenKhGame(new OpenKhGameStartup + { + ContentPath = ContentPath, + ModPath = ModPath, + InitialState = InitialState, + InitialMap = Kh2.Constants.WorldIds + .Select((world, index) => (world, index)) + .Concat(new (string world, int index)[] + { + (InitialWorld, -1) + }) + .Where(x => x.world == InitialWorld) + .Select(x => x.index) + .FirstOrDefault(), + InitialPlace = InitialPlace >= 0 ? (int?)InitialPlace : null, + InitialSpawnScriptMap = InitialSpawnScriptMap >= 0 ? (int?)InitialSpawnScriptMap : null, + InitialSpawnScriptBtl = InitialSpawnScriptBtl >= 0 ? (int?)InitialSpawnScriptBtl : null, + InitialSpawnScriptEvt = InitialSpawnScriptEvt >= 0 ? (int?)InitialSpawnScriptEvt : null, + }); + + game.Run(); + } + + private static void Catch(Exception ex) + { + Log.Err("{0}: {1}:\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace); + if (ex.InnerException != null) + Catch(ex.InnerException); + } + } +} diff --git a/OpenKh.Game/States/IState.cs b/OpenKh.Game/States/IState.cs index 3a6900554..863a20ecf 100644 --- a/OpenKh.Game/States/IState.cs +++ b/OpenKh.Game/States/IState.cs @@ -1,13 +1,13 @@ -using OpenKh.Game.Infrastructure; - -namespace OpenKh.Game.States -{ - public interface IState - { - void Initialize(StateInitDesc initDesc); - void Destroy(); - - void Update(DeltaTimes deltaTimes); - void Draw(DeltaTimes deltaTimes); - } -} +using OpenKh.Game.Infrastructure; + +namespace OpenKh.Game.States +{ + public interface IState + { + void Initialize(StateInitDesc initDesc); + void Destroy(); + + void Update(DeltaTimes deltaTimes); + void Draw(DeltaTimes deltaTimes); + } +} diff --git a/OpenKh.Game/States/IStateChange.cs b/OpenKh.Game/States/IStateChange.cs index eaa0866b0..08e42effe 100644 --- a/OpenKh.Game/States/IStateChange.cs +++ b/OpenKh.Game/States/IStateChange.cs @@ -1,7 +1,7 @@ -namespace OpenKh.Game.States -{ - public interface IStateChange - { - public int State { set; } - } -} +namespace OpenKh.Game.States +{ + public interface IStateChange + { + public int State { set; } + } +} diff --git a/OpenKh.Game/States/MapState.cs b/OpenKh.Game/States/MapState.cs index 7ac2ec27b..82e49ea49 100644 --- a/OpenKh.Game/States/MapState.cs +++ b/OpenKh.Game/States/MapState.cs @@ -1,183 +1,183 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Common; -using OpenKh.Engine; -using OpenKh.Engine.Input; -using OpenKh.Engine.MonoGame; -using OpenKh.Game.Debugging; -using OpenKh.Game.Field; -using OpenKh.Game.Infrastructure; -using System; -using System.Numerics; -using xna = Microsoft.Xna.Framework; - -namespace OpenKh.Game.States -{ - public class MapState : IState, IGameContext, IDebugConsumer - { - private readonly static BlendState AlphaBlendState = new BlendState() - { - ColorSourceBlend = Blend.SourceAlpha, - AlphaSourceBlend = Blend.SourceAlpha, - ColorDestinationBlend = Blend.InverseSourceAlpha, - AlphaDestinationBlend = Blend.InverseSourceAlpha, - ColorBlendFunction = BlendFunction.Add, - AlphaBlendFunction = BlendFunction.Add, - BlendFactor = xna.Color.White, - MultiSampleMask = int.MaxValue, - IndependentBlendEnable = false - }; - - public Kernel Kernel { get; private set; } - private IDataContent _dataContent; - private ArchiveManager _archiveManager; - private xna.GraphicsDeviceManager _graphics; - private IInput _input; - private IStateChange _stateChange; - private KingdomShader _shader; - private Camera _camera; - - public IField Field { get; private set; } - - private MenuState _menuState; - - public void Initialize(StateInitDesc initDesc) - { - Kernel = initDesc.Kernel; - _dataContent = initDesc.DataContent; - _archiveManager = initDesc.ArchiveManager; - _graphics = initDesc.GraphicsDevice; - _input = initDesc.Input; - _stateChange = initDesc.StateChange; - _shader = new KingdomShader(initDesc.ContentManager); - _camera = new Camera() - { - CameraPosition = new Vector3(0, 251, -920), - CameraRotationYawPitchRoll = new Vector3(-90, 0, -10), - }; - _menuState = new MenuState(this); - - Kernel.World = initDesc.StateSettings.GetInt("WorldId", Kernel.World); - Kernel.Area = initDesc.StateSettings.GetInt("PlaceId", Kernel.Area); - Kernel.Entrance = initDesc.StateSettings.GetInt("SpawnId", Kernel.Entrance); - Field = new Kh2Field( - Kernel, - _camera, - initDesc.StateSettings, - _graphics.GraphicsDevice, - _shader, - _input); - - BasicallyForceToReloadEverything(); - _menuState.Initialize(initDesc); - } - - public void Destroy() - { - _menuState.Destroy(); - } - - public void Update(DeltaTimes deltaTimes) - { - if (_menuState.IsMenuOpen) - { - _menuState.Update(deltaTimes); - return; - } - - if (_input.Triggered.SpecialRight) - { - _menuState.OpenMenu(); - } - else - { - const double Speed = 100.0; - var speed = (float)(deltaTimes.DeltaTime * Speed); - _camera.CameraPosition += Vector3.Multiply(_camera.CameraLookAtX, _input.AxisLeft.Y * speed * 5); - _camera.CameraPosition += Vector3.Multiply(_camera.CameraLookAtY, -_input.AxisLeft.X * speed * 5); - _camera.CameraRotationYawPitchRoll -= new Vector3(0, 0, -_input.AxisRight.Y * speed); - _camera.CameraRotationYawPitchRoll += new Vector3(_input.AxisRight.X * speed, 0, 0); - - Field.Update(deltaTimes.DeltaTime); - } - } - - public void Draw(DeltaTimes deltaTimes) - { - var viewport = _graphics.GraphicsDevice.Viewport; - _camera.AspectRatio = (float)viewport.Width / viewport.Height; - - _graphics.GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; - - _shader.Pass(pass => - { - _graphics.GraphicsDevice.BlendState = BlendState.Opaque; - _shader.UseAlphaMask = true; - - DrawAllMeshes(pass, /*passRenderOpaque=*/true); - - _graphics.GraphicsDevice.BlendState = AlphaBlendState; - _shader.UseAlphaMask = false; - - DrawAllMeshes(pass, /*passRenderOpaque=*/false); - }); - Field.Draw(); - - if (_menuState.IsMenuOpen) - { - _menuState.Draw(deltaTimes); - } - } - - private void DrawAllMeshes(EffectPass pass, bool passRenderOpaque) - { - _graphics.GraphicsDevice.DepthStencilState = passRenderOpaque ? DepthStencilState.Default : DepthStencilState.DepthRead; - - _shader.SetProjectionView(_camera.Projection); - _shader.SetWorldView(_camera.World); - _shader.SetModelViewIdentity(); - pass.Apply(); - - Field.Render(_camera, _shader, pass, passRenderOpaque); - } - - private void BasicallyForceToReloadEverything() - { - switch (Field) - { - case Kh2Field kh2Field: - kh2Field.LoadArea(Kernel.World, Kernel.Area); - break; - } - } - - public void LoadTitleScreen() => _stateChange.State = 0; - - public void LoadPlace(int world, int area, int entrance) - { - Kernel.World = world; - Kernel.Area = area; - Kernel.Entrance = entrance; - - BasicallyForceToReloadEverything(); - } - - public void DebugUpdate(IDebug debug) - { - if (_input.Triggered.SpecialLeft) - Kernel.DebugMode = !Kernel.DebugMode; - } - - public void DebugDraw(IDebug debug) - { - if (_menuState.IsMenuOpen) - return; - - if (Kernel.DebugMode) - { - debug.Println($"MAP: {Kh2.Constants.WorldIds[Kernel.World]}{Kernel.Area:D02}"); - debug.Println($"POS ({_camera.CameraPosition.X:F0}, {_camera.CameraPosition.Y:F0}, {_camera.CameraPosition.Z:F0})"); - debug.Println($"LKT ({_camera.CameraLookAt.X:F0}, {_camera.CameraLookAt.Y:F0}, {_camera.CameraLookAt.Z:F0})"); - } - } - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Common; +using OpenKh.Engine; +using OpenKh.Engine.Input; +using OpenKh.Engine.MonoGame; +using OpenKh.Game.Debugging; +using OpenKh.Game.Field; +using OpenKh.Game.Infrastructure; +using System; +using System.Numerics; +using xna = Microsoft.Xna.Framework; + +namespace OpenKh.Game.States +{ + public class MapState : IState, IGameContext, IDebugConsumer + { + private readonly static BlendState AlphaBlendState = new BlendState() + { + ColorSourceBlend = Blend.SourceAlpha, + AlphaSourceBlend = Blend.SourceAlpha, + ColorDestinationBlend = Blend.InverseSourceAlpha, + AlphaDestinationBlend = Blend.InverseSourceAlpha, + ColorBlendFunction = BlendFunction.Add, + AlphaBlendFunction = BlendFunction.Add, + BlendFactor = xna.Color.White, + MultiSampleMask = int.MaxValue, + IndependentBlendEnable = false + }; + + public Kernel Kernel { get; private set; } + private IDataContent _dataContent; + private ArchiveManager _archiveManager; + private xna.GraphicsDeviceManager _graphics; + private IInput _input; + private IStateChange _stateChange; + private KingdomShader _shader; + private Camera _camera; + + public IField Field { get; private set; } + + private MenuState _menuState; + + public void Initialize(StateInitDesc initDesc) + { + Kernel = initDesc.Kernel; + _dataContent = initDesc.DataContent; + _archiveManager = initDesc.ArchiveManager; + _graphics = initDesc.GraphicsDevice; + _input = initDesc.Input; + _stateChange = initDesc.StateChange; + _shader = new KingdomShader(initDesc.ContentManager); + _camera = new Camera() + { + CameraPosition = new Vector3(0, 251, -920), + CameraRotationYawPitchRoll = new Vector3(-90, 0, -10), + }; + _menuState = new MenuState(this); + + Kernel.World = initDesc.StateSettings.GetInt("WorldId", Kernel.World); + Kernel.Area = initDesc.StateSettings.GetInt("PlaceId", Kernel.Area); + Kernel.Entrance = initDesc.StateSettings.GetInt("SpawnId", Kernel.Entrance); + Field = new Kh2Field( + Kernel, + _camera, + initDesc.StateSettings, + _graphics.GraphicsDevice, + _shader, + _input); + + BasicallyForceToReloadEverything(); + _menuState.Initialize(initDesc); + } + + public void Destroy() + { + _menuState.Destroy(); + } + + public void Update(DeltaTimes deltaTimes) + { + if (_menuState.IsMenuOpen) + { + _menuState.Update(deltaTimes); + return; + } + + if (_input.Triggered.SpecialRight) + { + _menuState.OpenMenu(); + } + else + { + const double Speed = 100.0; + var speed = (float)(deltaTimes.DeltaTime * Speed); + _camera.CameraPosition += Vector3.Multiply(_camera.CameraLookAtX, _input.AxisLeft.Y * speed * 5); + _camera.CameraPosition += Vector3.Multiply(_camera.CameraLookAtY, -_input.AxisLeft.X * speed * 5); + _camera.CameraRotationYawPitchRoll -= new Vector3(0, 0, -_input.AxisRight.Y * speed); + _camera.CameraRotationYawPitchRoll += new Vector3(_input.AxisRight.X * speed, 0, 0); + + Field.Update(deltaTimes.DeltaTime); + } + } + + public void Draw(DeltaTimes deltaTimes) + { + var viewport = _graphics.GraphicsDevice.Viewport; + _camera.AspectRatio = (float)viewport.Width / viewport.Height; + + _graphics.GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; + + _shader.Pass(pass => + { + _graphics.GraphicsDevice.BlendState = BlendState.Opaque; + _shader.UseAlphaMask = true; + + DrawAllMeshes(pass, /*passRenderOpaque=*/true); + + _graphics.GraphicsDevice.BlendState = AlphaBlendState; + _shader.UseAlphaMask = false; + + DrawAllMeshes(pass, /*passRenderOpaque=*/false); + }); + Field.Draw(); + + if (_menuState.IsMenuOpen) + { + _menuState.Draw(deltaTimes); + } + } + + private void DrawAllMeshes(EffectPass pass, bool passRenderOpaque) + { + _graphics.GraphicsDevice.DepthStencilState = passRenderOpaque ? DepthStencilState.Default : DepthStencilState.DepthRead; + + _shader.SetProjectionView(_camera.Projection); + _shader.SetWorldView(_camera.World); + _shader.SetModelViewIdentity(); + pass.Apply(); + + Field.Render(_camera, _shader, pass, passRenderOpaque); + } + + private void BasicallyForceToReloadEverything() + { + switch (Field) + { + case Kh2Field kh2Field: + kh2Field.LoadArea(Kernel.World, Kernel.Area); + break; + } + } + + public void LoadTitleScreen() => _stateChange.State = 0; + + public void LoadPlace(int world, int area, int entrance) + { + Kernel.World = world; + Kernel.Area = area; + Kernel.Entrance = entrance; + + BasicallyForceToReloadEverything(); + } + + public void DebugUpdate(IDebug debug) + { + if (_input.Triggered.SpecialLeft) + Kernel.DebugMode = !Kernel.DebugMode; + } + + public void DebugDraw(IDebug debug) + { + if (_menuState.IsMenuOpen) + return; + + if (Kernel.DebugMode) + { + debug.Println($"MAP: {Kh2.Constants.WorldIds[Kernel.World]}{Kernel.Area:D02}"); + debug.Println($"POS ({_camera.CameraPosition.X:F0}, {_camera.CameraPosition.Y:F0}, {_camera.CameraPosition.Z:F0})"); + debug.Println($"LKT ({_camera.CameraLookAt.X:F0}, {_camera.CameraLookAt.Y:F0}, {_camera.CameraLookAt.Z:F0})"); + } + } + } +} diff --git a/OpenKh.Game/States/MenuState.cs b/OpenKh.Game/States/MenuState.cs index 6f3ef85f3..36937112d 100644 --- a/OpenKh.Game/States/MenuState.cs +++ b/OpenKh.Game/States/MenuState.cs @@ -1,285 +1,285 @@ -using OpenKh.Engine.Extensions; -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Renderers; -using OpenKh.Engine.Renders; -using OpenKh.Game.Infrastructure; -using OpenKh.Game.Menu; -using OpenKh.Kh2; -using System.Collections.Generic; -using System.Linq; -using OpenKh.Game.Debugging; -using OpenKh.Engine.Input; - -namespace OpenKh.Game.States -{ - public class MenuState : IMenuManager, IState - { - private Kernel _kernel; - private IDataContent _content; - private ArchiveManager _archiveManager; - private KingdomShader _shader; - private MonoSpriteDrawing _drawing; - private Layout _campLayout; - private LayoutRenderer _layoutRenderer; - private List _textures = new List(); - private Dictionary _cachedText = new Dictionary(); - - private IAnimatedSequence _backgroundSeq; - private IAnimatedSequence _subMenuDescriptionSeq; - private List _subMenuDescriptionInfo = new List(); - - private Kh2MessageRenderer _messageRenderer; - private IMenu _subMenu; - - public IGameContext GameContext { get; } - public AnimatedSequenceFactory SequenceFactory { get; private set; } - public IInput Input { get; private set; } - public bool IsMenuOpen { get; private set; } - - public MenuState(IGameContext gameContext) - { - GameContext = gameContext; - } - - public void Initialize(StateInitDesc initDesc) - { - _kernel = initDesc.Kernel; - _content = initDesc.DataContent; - _archiveManager = initDesc.ArchiveManager; - Input = initDesc.Input; - - var viewport = initDesc.GraphicsDevice.GraphicsDevice.Viewport; - _shader = new KingdomShader(initDesc.ContentManager); - _drawing = new MonoSpriteDrawing(initDesc.GraphicsDevice.GraphicsDevice, _shader); - _drawing.SetProjection( - viewport.Width, - viewport.Height, - Global.ResolutionWidth, - Global.ResolutionHeight, - 1.0f); - initDesc.GraphicsDevice.GraphicsDevice.DepthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState - { - DepthBufferEnable = false, - StencilEnable = false, - }; - - var messageContext = _kernel.SystemMessageContext; - _messageRenderer = new Kh2MessageRenderer(_drawing, messageContext); - - _archiveManager.LoadArchive($"menu/{_kernel.Region}/camp.2ld"); - (_campLayout, _textures) = GetLayoutResources("camp", "camp"); - _layoutRenderer = new LayoutRenderer(_campLayout, _drawing, _textures) - { - SelectedSequenceGroupIndex = 0 - }; - - SequenceFactory = new AnimatedSequenceFactory( - _drawing, - initDesc.Kernel.MessageProvider, - _messageRenderer, - _kernel.SystemMessageContext.Encoder, - _campLayout.SequenceItems[1], - _textures.First()); - - _backgroundSeq = SequenceFactory.Create(new List - { - new AnimatedSequenceDesc - { - SequenceIndexStart = 107, - SequenceIndexLoop = 108, - SequenceIndexEnd = 109, - }, - new AnimatedSequenceDesc - { - SequenceIndexStart = 110, - SequenceIndexLoop = 111, - SequenceIndexEnd = 112, - }, - new AnimatedSequenceDesc - { - SequenceIndexStart = 113, - SequenceIndexLoop = 114, - SequenceIndexEnd = 115, - } - }); - _subMenuDescriptionSeq = SequenceFactory.Create(new List()); - } - - public void Destroy() - { - foreach (var texture in _textures) - texture.Dispose(); - _shader.Dispose(); - _drawing.Dispose(); - } - - public void OpenMenu() - { - _layoutRenderer.FrameIndex = 0; - _layoutRenderer.SelectedSequenceGroupIndex = 0; - - _backgroundSeq.Begin(); - _subMenu = new MainMenu(this); - _subMenu.Open(); - - _subMenuDescriptionInfo.Clear(); - _subMenuDescriptionSeq = SequenceFactory.Create(new List()); - _subMenuDescriptionSeq.Begin(); - - IsMenuOpen = true; - } - - public void CloseAllMenu() - { - _layoutRenderer.FrameIndex = 0; - _layoutRenderer.SelectedSequenceGroupIndex = 2; - - _backgroundSeq.End(); - _subMenuDescriptionSeq.End(); - _subMenu.Close(); - } - - public void PushSubMenuDescription(ushort messageId) - { - _subMenuDescriptionInfo.Add(messageId); - SubMenuDescriptionInvalidateByPush(); - } - - public void PushSubMenuDescription(string message) - { - _subMenuDescriptionInfo.Add(message); - SubMenuDescriptionInvalidateByPush(); - } - - private void SubMenuDescriptionInvalidateByPush() - { - var count = _subMenuDescriptionInfo.Count; - _subMenuDescriptionSeq = SequenceFactory.Create(Enumerable.Range(0, count) - .Select(i => new AnimatedSequenceDesc - { - SequenceIndexStart = i + 1 < count ? -1 : 75, - SequenceIndexLoop = 76, - SequenceIndexEnd = 77, - StackIndex = i, - StackWidth = AnimatedSequenceDesc.DefaultStacking, - StackHeight = 0, - MessageId = _subMenuDescriptionInfo[i] is ushort id ? id : (ushort)0, - MessageText = _subMenuDescriptionInfo[i] as string, - Flags = AnimationFlags.TextIgnoreColor | - AnimationFlags.TextTranslateX | - AnimationFlags.ChildStackHorizontally, - TextAnchor = TextAnchor.BottomLeft, - Children = new List - { - new AnimatedSequenceDesc { }, - new AnimatedSequenceDesc - { - SequenceIndexStart = i + 1 < count ? -1 : 27, - SequenceIndexLoop = 28, - SequenceIndexEnd = 29, - } - } - }) - .ToList()); - _subMenuDescriptionSeq.Begin(); - } - - public void PopSubMenuDescription() - { - var count = _subMenuDescriptionInfo.Count; - if (count == 0) - return; - - _subMenuDescriptionSeq = SequenceFactory.Create(Enumerable.Range(0, count) - .Select(i => new AnimatedSequenceDesc - { - SequenceIndexLoop = i + 1 < count ? 76 : -1, - SequenceIndexEnd = 77, - StackIndex = i, - StackWidth = AnimatedSequenceDesc.DefaultStacking, - StackHeight = 0, - MessageId = _subMenuDescriptionInfo[i] is ushort id ? id : (ushort)0, - MessageText = _subMenuDescriptionInfo[i] as string, - Flags = AnimationFlags.TextIgnoreColor | - AnimationFlags.TextTranslateX | - AnimationFlags.ChildStackHorizontally, - TextAnchor = TextAnchor.BottomLeft, - Children = new List - { - new AnimatedSequenceDesc { }, - new AnimatedSequenceDesc - { - SequenceIndexLoop = i + 1 < count ? 28 : -1, - SequenceIndexEnd = 29, - }, - } - }) - .ToList()); - _subMenuDescriptionSeq.Begin(); - - _subMenuDescriptionInfo.RemoveAt(_subMenuDescriptionInfo.Count - 1); - } - - public void SetElementDescription(ushort messageId) - { - } - - public void Update(DeltaTimes deltaTimes) - { - var deltaTime = deltaTimes.DeltaTime; - - ProcessInput(Input); - - _layoutRenderer.FrameIndex++; - _backgroundSeq.Update(deltaTime); - _subMenuDescriptionSeq.Update(deltaTime); - _subMenu.Update(deltaTime); - } - - public void Draw(DeltaTimes deltaTimes) - { - switch (_layoutRenderer.SelectedSequenceGroupIndex) - { - case 0: - if (_layoutRenderer.IsLastFrame) - { - _layoutRenderer.FrameIndex = 0; - _layoutRenderer.SelectedSequenceGroupIndex = 1; - } - break; - case 1: - break; - case 2: - if (_layoutRenderer.IsLastFrame) - { - IsMenuOpen = false; - } - break; - } - if (_layoutRenderer.SelectedSequenceGroupIndex == 0 && _layoutRenderer.IsLastFrame) - _layoutRenderer.SelectedSequenceGroupIndex = 1; - - _layoutRenderer.Draw(); - _backgroundSeq.Draw(0, 0); - _subMenuDescriptionSeq.Draw(0, 0); - _subMenu.Draw(); - - _drawing.Flush(); - } - - private void ProcessInput(IInput input) - { - if (input.Triggered.SpecialRight) - CloseAllMenu(); - } - - private (Layout layout, List textures) GetLayoutResources(string layoutResourceName, string imagesResourceName) - { - var layout = _archiveManager.Get(layoutResourceName); - _textures = _archiveManager.Get(imagesResourceName) - ?.Images?.Select(x => _drawing.CreateSpriteTexture(x)).ToList(); - - return (layout, _textures); - } - } -} +using OpenKh.Engine.Extensions; +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Renderers; +using OpenKh.Engine.Renders; +using OpenKh.Game.Infrastructure; +using OpenKh.Game.Menu; +using OpenKh.Kh2; +using System.Collections.Generic; +using System.Linq; +using OpenKh.Game.Debugging; +using OpenKh.Engine.Input; + +namespace OpenKh.Game.States +{ + public class MenuState : IMenuManager, IState + { + private Kernel _kernel; + private IDataContent _content; + private ArchiveManager _archiveManager; + private KingdomShader _shader; + private MonoSpriteDrawing _drawing; + private Layout _campLayout; + private LayoutRenderer _layoutRenderer; + private List _textures = new List(); + private Dictionary _cachedText = new Dictionary(); + + private IAnimatedSequence _backgroundSeq; + private IAnimatedSequence _subMenuDescriptionSeq; + private List _subMenuDescriptionInfo = new List(); + + private Kh2MessageRenderer _messageRenderer; + private IMenu _subMenu; + + public IGameContext GameContext { get; } + public AnimatedSequenceFactory SequenceFactory { get; private set; } + public IInput Input { get; private set; } + public bool IsMenuOpen { get; private set; } + + public MenuState(IGameContext gameContext) + { + GameContext = gameContext; + } + + public void Initialize(StateInitDesc initDesc) + { + _kernel = initDesc.Kernel; + _content = initDesc.DataContent; + _archiveManager = initDesc.ArchiveManager; + Input = initDesc.Input; + + var viewport = initDesc.GraphicsDevice.GraphicsDevice.Viewport; + _shader = new KingdomShader(initDesc.ContentManager); + _drawing = new MonoSpriteDrawing(initDesc.GraphicsDevice.GraphicsDevice, _shader); + _drawing.SetProjection( + viewport.Width, + viewport.Height, + Global.ResolutionWidth, + Global.ResolutionHeight, + 1.0f); + initDesc.GraphicsDevice.GraphicsDevice.DepthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState + { + DepthBufferEnable = false, + StencilEnable = false, + }; + + var messageContext = _kernel.SystemMessageContext; + _messageRenderer = new Kh2MessageRenderer(_drawing, messageContext); + + _archiveManager.LoadArchive($"menu/{_kernel.Region}/camp.2ld"); + (_campLayout, _textures) = GetLayoutResources("camp", "camp"); + _layoutRenderer = new LayoutRenderer(_campLayout, _drawing, _textures) + { + SelectedSequenceGroupIndex = 0 + }; + + SequenceFactory = new AnimatedSequenceFactory( + _drawing, + initDesc.Kernel.MessageProvider, + _messageRenderer, + _kernel.SystemMessageContext.Encoder, + _campLayout.SequenceItems[1], + _textures.First()); + + _backgroundSeq = SequenceFactory.Create(new List + { + new AnimatedSequenceDesc + { + SequenceIndexStart = 107, + SequenceIndexLoop = 108, + SequenceIndexEnd = 109, + }, + new AnimatedSequenceDesc + { + SequenceIndexStart = 110, + SequenceIndexLoop = 111, + SequenceIndexEnd = 112, + }, + new AnimatedSequenceDesc + { + SequenceIndexStart = 113, + SequenceIndexLoop = 114, + SequenceIndexEnd = 115, + } + }); + _subMenuDescriptionSeq = SequenceFactory.Create(new List()); + } + + public void Destroy() + { + foreach (var texture in _textures) + texture.Dispose(); + _shader.Dispose(); + _drawing.Dispose(); + } + + public void OpenMenu() + { + _layoutRenderer.FrameIndex = 0; + _layoutRenderer.SelectedSequenceGroupIndex = 0; + + _backgroundSeq.Begin(); + _subMenu = new MainMenu(this); + _subMenu.Open(); + + _subMenuDescriptionInfo.Clear(); + _subMenuDescriptionSeq = SequenceFactory.Create(new List()); + _subMenuDescriptionSeq.Begin(); + + IsMenuOpen = true; + } + + public void CloseAllMenu() + { + _layoutRenderer.FrameIndex = 0; + _layoutRenderer.SelectedSequenceGroupIndex = 2; + + _backgroundSeq.End(); + _subMenuDescriptionSeq.End(); + _subMenu.Close(); + } + + public void PushSubMenuDescription(ushort messageId) + { + _subMenuDescriptionInfo.Add(messageId); + SubMenuDescriptionInvalidateByPush(); + } + + public void PushSubMenuDescription(string message) + { + _subMenuDescriptionInfo.Add(message); + SubMenuDescriptionInvalidateByPush(); + } + + private void SubMenuDescriptionInvalidateByPush() + { + var count = _subMenuDescriptionInfo.Count; + _subMenuDescriptionSeq = SequenceFactory.Create(Enumerable.Range(0, count) + .Select(i => new AnimatedSequenceDesc + { + SequenceIndexStart = i + 1 < count ? -1 : 75, + SequenceIndexLoop = 76, + SequenceIndexEnd = 77, + StackIndex = i, + StackWidth = AnimatedSequenceDesc.DefaultStacking, + StackHeight = 0, + MessageId = _subMenuDescriptionInfo[i] is ushort id ? id : (ushort)0, + MessageText = _subMenuDescriptionInfo[i] as string, + Flags = AnimationFlags.TextIgnoreColor | + AnimationFlags.TextTranslateX | + AnimationFlags.ChildStackHorizontally, + TextAnchor = TextAnchor.BottomLeft, + Children = new List + { + new AnimatedSequenceDesc { }, + new AnimatedSequenceDesc + { + SequenceIndexStart = i + 1 < count ? -1 : 27, + SequenceIndexLoop = 28, + SequenceIndexEnd = 29, + } + } + }) + .ToList()); + _subMenuDescriptionSeq.Begin(); + } + + public void PopSubMenuDescription() + { + var count = _subMenuDescriptionInfo.Count; + if (count == 0) + return; + + _subMenuDescriptionSeq = SequenceFactory.Create(Enumerable.Range(0, count) + .Select(i => new AnimatedSequenceDesc + { + SequenceIndexLoop = i + 1 < count ? 76 : -1, + SequenceIndexEnd = 77, + StackIndex = i, + StackWidth = AnimatedSequenceDesc.DefaultStacking, + StackHeight = 0, + MessageId = _subMenuDescriptionInfo[i] is ushort id ? id : (ushort)0, + MessageText = _subMenuDescriptionInfo[i] as string, + Flags = AnimationFlags.TextIgnoreColor | + AnimationFlags.TextTranslateX | + AnimationFlags.ChildStackHorizontally, + TextAnchor = TextAnchor.BottomLeft, + Children = new List + { + new AnimatedSequenceDesc { }, + new AnimatedSequenceDesc + { + SequenceIndexLoop = i + 1 < count ? 28 : -1, + SequenceIndexEnd = 29, + }, + } + }) + .ToList()); + _subMenuDescriptionSeq.Begin(); + + _subMenuDescriptionInfo.RemoveAt(_subMenuDescriptionInfo.Count - 1); + } + + public void SetElementDescription(ushort messageId) + { + } + + public void Update(DeltaTimes deltaTimes) + { + var deltaTime = deltaTimes.DeltaTime; + + ProcessInput(Input); + + _layoutRenderer.FrameIndex++; + _backgroundSeq.Update(deltaTime); + _subMenuDescriptionSeq.Update(deltaTime); + _subMenu.Update(deltaTime); + } + + public void Draw(DeltaTimes deltaTimes) + { + switch (_layoutRenderer.SelectedSequenceGroupIndex) + { + case 0: + if (_layoutRenderer.IsLastFrame) + { + _layoutRenderer.FrameIndex = 0; + _layoutRenderer.SelectedSequenceGroupIndex = 1; + } + break; + case 1: + break; + case 2: + if (_layoutRenderer.IsLastFrame) + { + IsMenuOpen = false; + } + break; + } + if (_layoutRenderer.SelectedSequenceGroupIndex == 0 && _layoutRenderer.IsLastFrame) + _layoutRenderer.SelectedSequenceGroupIndex = 1; + + _layoutRenderer.Draw(); + _backgroundSeq.Draw(0, 0); + _subMenuDescriptionSeq.Draw(0, 0); + _subMenu.Draw(); + + _drawing.Flush(); + } + + private void ProcessInput(IInput input) + { + if (input.Triggered.SpecialRight) + CloseAllMenu(); + } + + private (Layout layout, List textures) GetLayoutResources(string layoutResourceName, string imagesResourceName) + { + var layout = _archiveManager.Get(layoutResourceName); + _textures = _archiveManager.Get(imagesResourceName) + ?.Images?.Select(x => _drawing.CreateSpriteTexture(x)).ToList(); + + return (layout, _textures); + } + } +} diff --git a/OpenKh.Game/States/Title/Constants.cs b/OpenKh.Game/States/Title/Constants.cs index 7b1c31824..1de581b1e 100644 --- a/OpenKh.Game/States/Title/Constants.cs +++ b/OpenKh.Game/States/Title/Constants.cs @@ -1,77 +1,77 @@ -namespace OpenKh.Game.States.Title -{ - internal class Constants - { - public static readonly TitleLayout VanillaTitleLayout = new TitleLayout - { - Copyright = 8, - Intro = 11, - IntroSkip = 12, - NewGame = 13, - MenuOptionNewGame = 0, - MenuOptionLoad = 1, - MenuOptionTheater = 2, - MenuOptionBack = 3, - HasTheater = false, - HasBack = false, - }; - - public static readonly TitleLayout FinalMixTitleLayout = new TitleLayout - { - FadeIn = 17, - Copyright = 8, - Intro = 12, - IntroSkip = 14, - NewGame = 10, // but also 15? - MenuOptionNewGame = 0, - MenuOptionLoad = 1, - MenuOptionTheater = 4, - HasTheater = false, - HasBack = false, - }; - - public static readonly TitleLayout FinalMixTheaterTitleLayout = new TitleLayout - { - FadeIn = 17, - Copyright = 8, - Intro = 13, - IntroSkip = 14, - NewGame = 11, // but also 16? - MenuOptionNewGame = 2, - MenuOptionLoad = 3, - MenuOptionTheater = 4, - HasTheater = true, - HasBack = false, - }; - - public static readonly TitleLayout ReMixTitleLayout = new TitleLayout - { - FadeIn = 17, - Copyright = 8, - Intro = 12, - IntroSkip = 14, - NewGame = 10, // but also 15? - MenuOptionNewGame = 0, - MenuOptionLoad = 1, - MenuOptionTheater = 4, - MenuOptionBack = 18, - HasTheater = false, - HasBack = true, - }; - - public static readonly TitleLayout ReMixTheaterTitleLayout = new TitleLayout - { - FadeIn = 17, - Copyright = 8, - Intro = 13, - IntroSkip = 14, - NewGame = 11, // but also 16? - MenuOptionNewGame = 2, - MenuOptionLoad = 3, - MenuOptionTheater = 4, - MenuOptionBack = 19, - HasTheater = true, - HasBack = true, - }; - } -} +namespace OpenKh.Game.States.Title +{ + internal class Constants + { + public static readonly TitleLayout VanillaTitleLayout = new TitleLayout + { + Copyright = 8, + Intro = 11, + IntroSkip = 12, + NewGame = 13, + MenuOptionNewGame = 0, + MenuOptionLoad = 1, + MenuOptionTheater = 2, + MenuOptionBack = 3, + HasTheater = false, + HasBack = false, + }; + + public static readonly TitleLayout FinalMixTitleLayout = new TitleLayout + { + FadeIn = 17, + Copyright = 8, + Intro = 12, + IntroSkip = 14, + NewGame = 10, // but also 15? + MenuOptionNewGame = 0, + MenuOptionLoad = 1, + MenuOptionTheater = 4, + HasTheater = false, + HasBack = false, + }; + + public static readonly TitleLayout FinalMixTheaterTitleLayout = new TitleLayout + { + FadeIn = 17, + Copyright = 8, + Intro = 13, + IntroSkip = 14, + NewGame = 11, // but also 16? + MenuOptionNewGame = 2, + MenuOptionLoad = 3, + MenuOptionTheater = 4, + HasTheater = true, + HasBack = false, + }; + + public static readonly TitleLayout ReMixTitleLayout = new TitleLayout + { + FadeIn = 17, + Copyright = 8, + Intro = 12, + IntroSkip = 14, + NewGame = 10, // but also 15? + MenuOptionNewGame = 0, + MenuOptionLoad = 1, + MenuOptionTheater = 4, + MenuOptionBack = 18, + HasTheater = false, + HasBack = true, + }; + + public static readonly TitleLayout ReMixTheaterTitleLayout = new TitleLayout + { + FadeIn = 17, + Copyright = 8, + Intro = 13, + IntroSkip = 14, + NewGame = 11, // but also 16? + MenuOptionNewGame = 2, + MenuOptionLoad = 3, + MenuOptionTheater = 4, + MenuOptionBack = 19, + HasTheater = true, + HasBack = true, + }; + } +} diff --git a/OpenKh.Game/States/Title/ITitleMainMenu.cs b/OpenKh.Game/States/Title/ITitleMainMenu.cs index 96d3ba197..238cf28c5 100644 --- a/OpenKh.Game/States/Title/ITitleMainMenu.cs +++ b/OpenKh.Game/States/Title/ITitleMainMenu.cs @@ -1,32 +1,32 @@ -using OpenKh.Engine.Input; -using OpenKh.Engine.Renders; -using OpenKh.Game.Infrastructure; - -namespace OpenKh.Game.States.Title -{ - public enum MainMenuState - { - Running, - StartNewGame - } - - public enum TextAlignment - { - Left, - Center, - Right - } - - interface ITitleMainMenu - { - Kernel Kernel { get; } - IInput Input { get; } - IMessageRenderer MessageRenderer { get; } - MainMenuState State { set; } - - byte[] GetMessage(ushort messageId); - - void Print(ushort messageId, float left, float top, - uint color = 0xffffffff, TextAlignment alignment = TextAlignment.Left); - } -} +using OpenKh.Engine.Input; +using OpenKh.Engine.Renders; +using OpenKh.Game.Infrastructure; + +namespace OpenKh.Game.States.Title +{ + public enum MainMenuState + { + Running, + StartNewGame + } + + public enum TextAlignment + { + Left, + Center, + Right + } + + interface ITitleMainMenu + { + Kernel Kernel { get; } + IInput Input { get; } + IMessageRenderer MessageRenderer { get; } + MainMenuState State { set; } + + byte[] GetMessage(ushort messageId); + + void Print(ushort messageId, float left, float top, + uint color = 0xffffffff, TextAlignment alignment = TextAlignment.Left); + } +} diff --git a/OpenKh.Game/States/Title/ITitleSubMenu.cs b/OpenKh.Game/States/Title/ITitleSubMenu.cs index d64dfc8d2..34d9247de 100644 --- a/OpenKh.Game/States/Title/ITitleSubMenu.cs +++ b/OpenKh.Game/States/Title/ITitleSubMenu.cs @@ -1,11 +1,11 @@ -namespace OpenKh.Game.States.Title -{ - internal interface ITitleSubMenu - { - bool IsOpen { get; } - - void Invoke(); - void Update(double deltaTime); - void Draw(); - } -} +namespace OpenKh.Game.States.Title +{ + internal interface ITitleSubMenu + { + bool IsOpen { get; } + + void Invoke(); + void Update(double deltaTime); + void Draw(); + } +} diff --git a/OpenKh.Game/States/Title/NewGameMenu.cs b/OpenKh.Game/States/Title/NewGameMenu.cs index a62c1d2db..169647776 100644 --- a/OpenKh.Game/States/Title/NewGameMenu.cs +++ b/OpenKh.Game/States/Title/NewGameMenu.cs @@ -1,196 +1,196 @@ -using OpenKh.Engine.Input; -using OpenKh.Engine.Renderers; -using OpenKh.Game.Infrastructure; - -namespace OpenKh.Game.States.Title -{ - internal class NewGameMenu : ITitleSubMenu - { - private const int NewGameTitle = 22; - private const int NewGameWindow = 28; - private const int NewGameOption = 15; - - private static readonly ushort[] DifficultyTitle = new ushort[] - { - 0x4331, 0x4332, 0x4333, 0x4e33 - }; - private static readonly ushort[] DifficultyDescription = new ushort[] - { - 0x4334, 0x4335, 0x4336, 0x4e34 - }; - - private readonly ITitleMainMenu _mainMenu; - private readonly AnimatedSequenceFactory _animSeqFactory; - private readonly IAnimatedSequence _animMenuBg; - private readonly IAnimatedSequence _animMenuWindow; - private readonly IAnimatedSequence _animMenuTitle; - private readonly IAnimatedSequence _animMenuOption1; - private readonly IAnimatedSequence _animMenuOption2; - private readonly IAnimatedSequence _animMenuOption3; - private readonly IAnimatedSequence _animMenuOption4; - private readonly IAnimatedSequence _animMenuOptionSelected; - - private int _difficultyCount; - private int _difficultyOption; - private MainMenuState _stateToSet; - - public bool IsOpen { get; private set; } - - public NewGameMenu(AnimatedSequenceFactory sequenceFactory, ITitleMainMenu mainMenu) - { - _difficultyCount = mainMenu.Kernel.IsFinalMix ? 4 : 3; - - _mainMenu = mainMenu; - _animSeqFactory = sequenceFactory; - - _animMenuBg = sequenceFactory.FromAnimatedIndex(NewGameTitle); - _animMenuWindow = sequenceFactory.FromAnimatedIndex(NewGameWindow); - _animMenuTitle = sequenceFactory.FromStaticIndex(25); - _animMenuOption1 = sequenceFactory.FromAnimatedIndex(NewGameOption); - _animMenuOption2 = sequenceFactory.FromAnimatedIndex(NewGameOption); - _animMenuOption3 = sequenceFactory.FromAnimatedIndex(NewGameOption); - _animMenuOption4 = sequenceFactory.FromAnimatedIndex(NewGameOption); - - _animMenuOptionSelected = sequenceFactory.FromAnimatedIndex(15, 14, 14); - //_animMenuOptionSelected.AddChild(new AnimatedSequenceRenderer(_seqRenderer, 7)); - //_animMenuOptionSelected.AddChild(new AnimatedSequenceRenderer(_seqRenderer, 10), true); - //_animMenuOptionSelected.ChildPositionX = -110; - } - - public void Invoke() - { - IsOpen = true; - _difficultyOption = 1; - - _animMenuBg.Begin(); - _animMenuBg.TextAnchor = TextAnchor.Center; - _animMenuBg.SetMessage(0x432e); - - _animMenuWindow.Begin(); - - _animMenuTitle.Begin(); - _animMenuTitle.TextAnchor = TextAnchor.BottomCenter; - _animMenuTitle.SetMessage(0x4330); - - _animMenuOption1.Begin(); - _animMenuOption1.TextAnchor = TextAnchor.BottomCenter; - _animMenuOption1.SetMessage(DifficultyTitle[0]); - - _animMenuOption2.Begin(); - _animMenuOption2.TextAnchor = TextAnchor.BottomCenter; - _animMenuOption2.SetMessage(DifficultyTitle[1]); - - _animMenuOption3.Begin(); - _animMenuOption3.TextAnchor = TextAnchor.BottomCenter; - _animMenuOption3.SetMessage(DifficultyTitle[2]); - - _animMenuOption4.Begin(); - _animMenuOption4.TextAnchor = TextAnchor.BottomCenter; - _animMenuOption4.SetMessage(DifficultyTitle[3]); - - _animMenuOptionSelected.Begin(); - } - - public void Update(double deltaTime) - { - _animMenuBg.Update(deltaTime); - _animMenuWindow.Update(deltaTime); - _animMenuTitle.Update(deltaTime); - _animMenuOption1.Update(deltaTime); - _animMenuOption2.Update(deltaTime); - _animMenuOption3.Update(deltaTime); - _animMenuOption4.Update(deltaTime); - _animMenuOptionSelected.Update(deltaTime); - - var input = _mainMenu.Input; - InputNewGameMenu(input); - - if (_animMenuBg.IsEnd) - { - _mainMenu.State = _stateToSet; - IsOpen = false; - } - } - - public void Draw() - { - DrawNewGameMenu(); - } - - private void InputNewGameMenu(IInput input) - { - bool isOptionChanged = false; - if (input.Triggered.Cancel) - { - _animMenuBg.End(); - _animMenuWindow.End(); - _animMenuTitle.End(); - _animMenuOption1.End(); - _animMenuOption2.End(); - _animMenuOption3.End(); - _animMenuOption4.End(); - _animMenuOptionSelected.End(); - _stateToSet = MainMenuState.Running; - } - else if (input.Triggered.Confirm) - { - _animMenuBg.End(); - _animMenuWindow.End(); - _animMenuTitle.End(); - _animMenuOption1.End(); - _animMenuOption2.End(); - _animMenuOption3.End(); - _animMenuOption4.End(); - _animMenuOptionSelected.End(); - _stateToSet = MainMenuState.StartNewGame; - } - else if (input.Repeated.Up) - { - _difficultyOption--; - if (_difficultyOption < 0) - _difficultyOption = _difficultyCount - 1; - isOptionChanged = true; - } - else if (input.Repeated.Down) - { - _difficultyOption = (_difficultyOption + 1) % _difficultyCount; - isOptionChanged = true; - } - - if (isOptionChanged) - { - _animMenuWindow.Skip(); - _animMenuOption1.Skip(); - _animMenuOption2.Skip(); - _animMenuOption3.Skip(); - _animMenuOption4.Skip(); - _animMenuOptionSelected.Skip(); - } - } - - private void DrawNewGameMenu() - { - const int OptionHDistance = 30; - var subTitleBgY = _mainMenu.Kernel.IsFinalMix ? 180 : 188; - var optionY = _mainMenu.Kernel.IsFinalMix ? 120 : 144; - - _animMenuBg.Draw(0, 0); - - _animMenuWindow.TextAnchor = TextAnchor.BottomCenter; - _animMenuWindow.SetMessage(DifficultyDescription[_difficultyOption]); - _animMenuWindow.Draw(0, 0); - - _animMenuTitle.Draw(256, subTitleBgY); - - _animMenuOption1.Draw(256, optionY + OptionHDistance * 0); - _animMenuOption2.Draw(256, optionY + OptionHDistance * 1); - _animMenuOption3.Draw(256, optionY + OptionHDistance * 2); - if (_difficultyCount >= 4) - _animMenuOption4.Draw(256, optionY + OptionHDistance * 3); - - _animMenuOptionSelected.TextAnchor = TextAnchor.BottomCenter; - _animMenuOptionSelected.SetMessage(DifficultyTitle[_difficultyOption]); - _animMenuOptionSelected.Draw(256, optionY + OptionHDistance * _difficultyOption); - } - } -} +using OpenKh.Engine.Input; +using OpenKh.Engine.Renderers; +using OpenKh.Game.Infrastructure; + +namespace OpenKh.Game.States.Title +{ + internal class NewGameMenu : ITitleSubMenu + { + private const int NewGameTitle = 22; + private const int NewGameWindow = 28; + private const int NewGameOption = 15; + + private static readonly ushort[] DifficultyTitle = new ushort[] + { + 0x4331, 0x4332, 0x4333, 0x4e33 + }; + private static readonly ushort[] DifficultyDescription = new ushort[] + { + 0x4334, 0x4335, 0x4336, 0x4e34 + }; + + private readonly ITitleMainMenu _mainMenu; + private readonly AnimatedSequenceFactory _animSeqFactory; + private readonly IAnimatedSequence _animMenuBg; + private readonly IAnimatedSequence _animMenuWindow; + private readonly IAnimatedSequence _animMenuTitle; + private readonly IAnimatedSequence _animMenuOption1; + private readonly IAnimatedSequence _animMenuOption2; + private readonly IAnimatedSequence _animMenuOption3; + private readonly IAnimatedSequence _animMenuOption4; + private readonly IAnimatedSequence _animMenuOptionSelected; + + private int _difficultyCount; + private int _difficultyOption; + private MainMenuState _stateToSet; + + public bool IsOpen { get; private set; } + + public NewGameMenu(AnimatedSequenceFactory sequenceFactory, ITitleMainMenu mainMenu) + { + _difficultyCount = mainMenu.Kernel.IsFinalMix ? 4 : 3; + + _mainMenu = mainMenu; + _animSeqFactory = sequenceFactory; + + _animMenuBg = sequenceFactory.FromAnimatedIndex(NewGameTitle); + _animMenuWindow = sequenceFactory.FromAnimatedIndex(NewGameWindow); + _animMenuTitle = sequenceFactory.FromStaticIndex(25); + _animMenuOption1 = sequenceFactory.FromAnimatedIndex(NewGameOption); + _animMenuOption2 = sequenceFactory.FromAnimatedIndex(NewGameOption); + _animMenuOption3 = sequenceFactory.FromAnimatedIndex(NewGameOption); + _animMenuOption4 = sequenceFactory.FromAnimatedIndex(NewGameOption); + + _animMenuOptionSelected = sequenceFactory.FromAnimatedIndex(15, 14, 14); + //_animMenuOptionSelected.AddChild(new AnimatedSequenceRenderer(_seqRenderer, 7)); + //_animMenuOptionSelected.AddChild(new AnimatedSequenceRenderer(_seqRenderer, 10), true); + //_animMenuOptionSelected.ChildPositionX = -110; + } + + public void Invoke() + { + IsOpen = true; + _difficultyOption = 1; + + _animMenuBg.Begin(); + _animMenuBg.TextAnchor = TextAnchor.Center; + _animMenuBg.SetMessage(0x432e); + + _animMenuWindow.Begin(); + + _animMenuTitle.Begin(); + _animMenuTitle.TextAnchor = TextAnchor.BottomCenter; + _animMenuTitle.SetMessage(0x4330); + + _animMenuOption1.Begin(); + _animMenuOption1.TextAnchor = TextAnchor.BottomCenter; + _animMenuOption1.SetMessage(DifficultyTitle[0]); + + _animMenuOption2.Begin(); + _animMenuOption2.TextAnchor = TextAnchor.BottomCenter; + _animMenuOption2.SetMessage(DifficultyTitle[1]); + + _animMenuOption3.Begin(); + _animMenuOption3.TextAnchor = TextAnchor.BottomCenter; + _animMenuOption3.SetMessage(DifficultyTitle[2]); + + _animMenuOption4.Begin(); + _animMenuOption4.TextAnchor = TextAnchor.BottomCenter; + _animMenuOption4.SetMessage(DifficultyTitle[3]); + + _animMenuOptionSelected.Begin(); + } + + public void Update(double deltaTime) + { + _animMenuBg.Update(deltaTime); + _animMenuWindow.Update(deltaTime); + _animMenuTitle.Update(deltaTime); + _animMenuOption1.Update(deltaTime); + _animMenuOption2.Update(deltaTime); + _animMenuOption3.Update(deltaTime); + _animMenuOption4.Update(deltaTime); + _animMenuOptionSelected.Update(deltaTime); + + var input = _mainMenu.Input; + InputNewGameMenu(input); + + if (_animMenuBg.IsEnd) + { + _mainMenu.State = _stateToSet; + IsOpen = false; + } + } + + public void Draw() + { + DrawNewGameMenu(); + } + + private void InputNewGameMenu(IInput input) + { + bool isOptionChanged = false; + if (input.Triggered.Cancel) + { + _animMenuBg.End(); + _animMenuWindow.End(); + _animMenuTitle.End(); + _animMenuOption1.End(); + _animMenuOption2.End(); + _animMenuOption3.End(); + _animMenuOption4.End(); + _animMenuOptionSelected.End(); + _stateToSet = MainMenuState.Running; + } + else if (input.Triggered.Confirm) + { + _animMenuBg.End(); + _animMenuWindow.End(); + _animMenuTitle.End(); + _animMenuOption1.End(); + _animMenuOption2.End(); + _animMenuOption3.End(); + _animMenuOption4.End(); + _animMenuOptionSelected.End(); + _stateToSet = MainMenuState.StartNewGame; + } + else if (input.Repeated.Up) + { + _difficultyOption--; + if (_difficultyOption < 0) + _difficultyOption = _difficultyCount - 1; + isOptionChanged = true; + } + else if (input.Repeated.Down) + { + _difficultyOption = (_difficultyOption + 1) % _difficultyCount; + isOptionChanged = true; + } + + if (isOptionChanged) + { + _animMenuWindow.Skip(); + _animMenuOption1.Skip(); + _animMenuOption2.Skip(); + _animMenuOption3.Skip(); + _animMenuOption4.Skip(); + _animMenuOptionSelected.Skip(); + } + } + + private void DrawNewGameMenu() + { + const int OptionHDistance = 30; + var subTitleBgY = _mainMenu.Kernel.IsFinalMix ? 180 : 188; + var optionY = _mainMenu.Kernel.IsFinalMix ? 120 : 144; + + _animMenuBg.Draw(0, 0); + + _animMenuWindow.TextAnchor = TextAnchor.BottomCenter; + _animMenuWindow.SetMessage(DifficultyDescription[_difficultyOption]); + _animMenuWindow.Draw(0, 0); + + _animMenuTitle.Draw(256, subTitleBgY); + + _animMenuOption1.Draw(256, optionY + OptionHDistance * 0); + _animMenuOption2.Draw(256, optionY + OptionHDistance * 1); + _animMenuOption3.Draw(256, optionY + OptionHDistance * 2); + if (_difficultyCount >= 4) + _animMenuOption4.Draw(256, optionY + OptionHDistance * 3); + + _animMenuOptionSelected.TextAnchor = TextAnchor.BottomCenter; + _animMenuOptionSelected.SetMessage(DifficultyTitle[_difficultyOption]); + _animMenuOptionSelected.Draw(256, optionY + OptionHDistance * _difficultyOption); + } + } +} diff --git a/OpenKh.Game/States/Title/TitleLayout.cs b/OpenKh.Game/States/Title/TitleLayout.cs index bde1c3879..71e6697ec 100644 --- a/OpenKh.Game/States/Title/TitleLayout.cs +++ b/OpenKh.Game/States/Title/TitleLayout.cs @@ -1,17 +1,17 @@ -namespace OpenKh.Game.States.Title -{ - internal class TitleLayout - { - public int FadeIn { get; set; } - public int Copyright { get; set; } - public int Intro { get; set; } - public int IntroSkip { get; set; } - public int NewGame { get; set; } - public int MenuOptionNewGame { get; set; } - public int MenuOptionLoad { get; set; } - public int MenuOptionTheater { get; set; } - public int MenuOptionBack { get; set; } - public bool HasTheater { get; set; } - public bool HasBack { get; set; } - } -} +namespace OpenKh.Game.States.Title +{ + internal class TitleLayout + { + public int FadeIn { get; set; } + public int Copyright { get; set; } + public int Intro { get; set; } + public int IntroSkip { get; set; } + public int NewGame { get; set; } + public int MenuOptionNewGame { get; set; } + public int MenuOptionLoad { get; set; } + public int MenuOptionTheater { get; set; } + public int MenuOptionBack { get; set; } + public bool HasTheater { get; set; } + public bool HasBack { get; set; } + } +} diff --git a/OpenKh.Game/States/Title/TitleState.cs b/OpenKh.Game/States/Title/TitleState.cs index 69c61a13c..0ef3ba2b0 100644 --- a/OpenKh.Game/States/Title/TitleState.cs +++ b/OpenKh.Game/States/Title/TitleState.cs @@ -1,418 +1,418 @@ -using OpenKh.Engine.Extensions; -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Renderers; -using OpenKh.Engine.Renders; -using OpenKh.Common; -using OpenKh.Game.Infrastructure; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.Linq; -using static OpenKh.Game.States.Title.Constants; -using OpenKh.Engine.Input; - -namespace OpenKh.Game.States.Title -{ - public class TitleState : IState, ITitleMainMenu - { - private enum TitleSubMenu - { - NewGame, - } - - private const int MainMenuNewGameOption = 0; - private const int MainMenuLoadOption = 1; - private const int MainMenuTheaterOption = 2; - private const int MainMenuBackOption = 3; - private const int MainMenuMaxOptionCount = 4; - - private ArchiveManager _archiveManager; - private IStateChange _stateChange; - private KingdomShader _shader; - private MonoSpriteDrawing drawing; - private LayoutRenderer layoutRendererFg; - private LayoutRenderer layoutRendererBg; - private LayoutRenderer layoutRendererTheater; - private AnimatedSequenceFactory _animatedSequenceFactory; - private Kh2MessageRenderer _messageRenderer; - private Layout _titleLayout; - private Layout _theaterLayout; - private Dictionary> cachedSurfaces = new Dictionary>(); - private Dictionary _cachedText = new Dictionary(); - - private TitleLayout _titleLayoutDesc; - private int _optionSelected; - - private ITitleSubMenu _subMenu; - - private bool _isTheaterModeUnlocked; - private bool _isInTheaterMenu; - - public Kernel Kernel { get; private set; } - public IInput Input { get; private set; } - public IMessageRenderer MessageRenderer => _messageRenderer; - - public MainMenuState State - { - set - { - switch (value) - { - case MainMenuState.StartNewGame: - StartNewGame(); - break; - } - } - } - - private TitleSubMenu SubMenu - { - set - { - switch (value) - { - case TitleSubMenu.NewGame: - _subMenu = new NewGameMenu(_animatedSequenceFactory, this); - break; - default: - Log.Warn("Submenu {0} not implemented.", value); - break; - } - - _subMenu?.Invoke(); - } - } - - private bool IsIntro - { - get - { - var currentSequence = layoutRendererBg.SelectedSequenceGroupIndex; - return currentSequence == _titleLayoutDesc.Copyright || - currentSequence == _titleLayoutDesc.Intro; - } - } - - private bool IsNewGameStarting => - layoutRendererBg.SelectedSequenceGroupIndex == _titleLayoutDesc.NewGame; - - public void Initialize(StateInitDesc initDesc) - { - Kernel = initDesc.Kernel; - _archiveManager = initDesc.ArchiveManager; - Input = initDesc.Input; - _stateChange = initDesc.StateChange; - - var viewport = initDesc.GraphicsDevice.GraphicsDevice.Viewport; - _shader = new KingdomShader(initDesc.ContentManager); - drawing = new MonoSpriteDrawing(initDesc.GraphicsDevice.GraphicsDevice, _shader); - drawing.SetProjection( - viewport.Width, - viewport.Height, - Global.ResolutionWidth, - Global.ResolutionHeight, - 1.0f); - - if (Kernel.IsReMix) - _archiveManager.LoadArchive($"menu/{Kernel.Region}/titlejf.2ld"); - _archiveManager.LoadArchive($"menu/{Kernel.Region}/title.2ld"); - _archiveManager.LoadArchive($"menu/{Kernel.Region}/save.2ld"); - - _isTheaterModeUnlocked = false; - if (Kernel.IsReMix) - { - if (_isTheaterModeUnlocked) - _titleLayoutDesc = ReMixTheaterTitleLayout; - else - _titleLayoutDesc = ReMixTitleLayout; - } - else if (Kernel.RegionId == (int)Kh2.Constants.RegionId.FinalMix) - { - if (_isTheaterModeUnlocked) - _titleLayoutDesc = FinalMixTheaterTitleLayout; - else - _titleLayoutDesc = FinalMixTitleLayout; - } - else - _titleLayoutDesc = VanillaTitleLayout; - - var messageContext = Kernel.SystemMessageContext; - _messageRenderer = new Kh2MessageRenderer(drawing, messageContext); - - IEnumerable images; - (_titleLayout, images) = GetLayoutResources("titl", "titl"); - - layoutRendererBg = new LayoutRenderer(_titleLayout, drawing, images); - layoutRendererFg = new LayoutRenderer(_titleLayout, drawing, images); - layoutRendererBg.SelectedSequenceGroupIndex = _titleLayoutDesc.Copyright; - - _animatedSequenceFactory = new AnimatedSequenceFactory( - drawing, - initDesc.Kernel.MessageProvider, - _messageRenderer, - initDesc.Kernel.SystemMessageContext.Encoder, - _titleLayout.SequenceItems[0], - images.First()); - - Log.Info("Theater={0}", _titleLayoutDesc.HasTheater); - if (_titleLayoutDesc.HasTheater) - { - (_theaterLayout, images) = GetLayoutResources("even", "even"); - layoutRendererTheater = new LayoutRenderer(_theaterLayout, drawing, images); - } - - SetOption(0); - } - - public void Destroy() - { - throw new NotImplementedException(); - } - - public void Update(DeltaTimes deltaTimes) - { - CheckTitlLoop(layoutRendererBg); - CheckTitlLoop(layoutRendererFg); - - if (_isInTheaterMenu) - { - switch (layoutRendererTheater.SelectedSequenceGroupIndex) - { - case 0: - layoutRendererTheater.FrameIndex++; - if (layoutRendererTheater.FrameIndex > 32) - { - layoutRendererTheater.FrameIndex = 0; - layoutRendererTheater.SelectedSequenceGroupIndex = 1; - } - break; - case 1: - break; - case 2: - layoutRendererTheater.FrameIndex++; - if (layoutRendererTheater.FrameIndex > 32) - _isInTheaterMenu = false; - break; - } - } - - if (_subMenu?.IsOpen == true) - _subMenu.Update(deltaTimes.DeltaTime); - else - { - if (IsIntro) - { - if (Input.Triggered.Confirm || Input.Triggered.Cancel || Input.Triggered.SpecialRight) - SkipIntro(); - } - else if (IsNewGameStarting) - { - // block any input - } - else if (_isInTheaterMenu) - ProcessInputTheaterMenu(); - else - ProcessInputMainMenu(); - } - } - - public void Draw(DeltaTimes deltaTimes) - { - layoutRendererBg.Draw(); - - if (!(IsIntro || IsNewGameStarting)) - layoutRendererFg.Draw(); - - if (_isInTheaterMenu) - layoutRendererTheater.Draw(); - - else if (_subMenu?.IsOpen == true) - _subMenu.Draw(); - - drawing.Flush(); - } - - private void ProcessInputMainMenu() - { - var currentOption = _optionSelected; - if (Input.Repeated.Up) - { - currentOption--; - if (currentOption < 0) - currentOption = MainMenuBackOption; - - if (currentOption == MainMenuBackOption && !_titleLayoutDesc.HasBack) - currentOption = MainMenuTheaterOption; - if (currentOption == MainMenuTheaterOption && !_titleLayoutDesc.HasTheater) - currentOption = MainMenuLoadOption; - } - else if (Input.Repeated.Down) - { - currentOption++; - if (currentOption == MainMenuTheaterOption && !_titleLayoutDesc.HasTheater) - currentOption++; - if (currentOption == MainMenuBackOption && !_titleLayoutDesc.HasBack) - currentOption++; - if (currentOption >= MainMenuMaxOptionCount) - currentOption = 0; - } - else if (Input.Triggered.Confirm) - { - switch (currentOption) - { - case MainMenuNewGameOption: - SubMenu = TitleSubMenu.NewGame; - break; - case MainMenuLoadOption: - Kernel.LoadSaveData(Config.LastSave); - SetStateToGameplay(); - break; - case MainMenuTheaterOption: - _isInTheaterMenu = true; - layoutRendererTheater.FrameIndex = 0; - layoutRendererTheater.SelectedSequenceGroupIndex = 0; - break; - } - } - - - if (currentOption != _optionSelected) - SetOption(currentOption); - } - - private void ProcessInputTheaterMenu() - { - if (Input.Repeated.Cancel) - { - layoutRendererTheater.FrameIndex = 0; - layoutRendererTheater.SelectedSequenceGroupIndex = 2; - } - } - - private void SkipIntro() - { - layoutRendererBg.SelectedSequenceGroupIndex = _titleLayoutDesc.IntroSkip; - layoutRendererBg.FrameIndex = 0; - } - - private void SetStateToGameplay() - { - _stateChange.State = 1; - } - - private void StartNewGame() - { - layoutRendererBg.SelectedSequenceGroupIndex = _titleLayoutDesc.NewGame; - layoutRendererBg.FrameIndex = 0; - } - - private void SetOption(int option) - { - Log.Info("TitleOption={0} prev={1}", option, _optionSelected); - _optionSelected = option; - - switch (_optionSelected) - { - case MainMenuNewGameOption: - layoutRendererFg.SelectedSequenceGroupIndex = _titleLayoutDesc.MenuOptionNewGame; - break; - case MainMenuLoadOption: - layoutRendererFg.SelectedSequenceGroupIndex = _titleLayoutDesc.MenuOptionLoad; - break; - case MainMenuTheaterOption: - layoutRendererFg.SelectedSequenceGroupIndex = _titleLayoutDesc.MenuOptionTheater; - break; - case MainMenuBackOption: - layoutRendererFg.SelectedSequenceGroupIndex = _titleLayoutDesc.MenuOptionBack; - break; - } - - layoutRendererFg.FrameIndex = 0; - } - - private void CheckTitlLoop(LayoutRenderer layout) - { - layout.FrameIndex++; - var currentSequenceGroupIndex = layout.SelectedSequenceGroupIndex; - if (currentSequenceGroupIndex == _titleLayoutDesc.Copyright) - { - if (layout.IsLastFrame) - { - layout.SelectedSequenceGroupIndex = _titleLayoutDesc.Intro; - layout.FrameIndex = 0; - } - } - else if (currentSequenceGroupIndex == _titleLayoutDesc.Intro) - { - if (layout.FrameIndex >= 480) - { - layout.SelectedSequenceGroupIndex = _titleLayoutDesc.IntroSkip; - layout.FrameIndex = 0; - } - } - else if (currentSequenceGroupIndex == _titleLayoutDesc.NewGame) - { - if (layout.IsLastFrame) - SetStateToGameplay(); - } - else - layout.FrameIndex++; - } - - private (Layout layout, IEnumerable textures) GetLayoutResources(string layoutResourceName, string imagesResourceName) - { - var layout = _archiveManager.Get(layoutResourceName); - if (!cachedSurfaces.TryGetValue(imagesResourceName, out var images)) - images = cachedSurfaces[imagesResourceName] = _archiveManager.Get(imagesResourceName) - ?.Images?.Select(x => drawing.CreateSpriteTexture(x)).ToList(); - - return (layout, images); - } - - public byte[] GetMessage(ushort messageId) - { - if (!_cachedText.TryGetValue(messageId, out var data)) - _cachedText[messageId] = data = Kernel.MessageProvider.GetMessage(messageId); - - return data; - } - - public void Print(ushort messageId, float left, float top, - uint color, TextAlignment alignment) - { - var data = GetMessage(messageId); - - var x = alignment switch - { - TextAlignment.Left => 0, - TextAlignment.Center => -(GetTextWidth(data) / 2), - TextAlignment.Right => -GetTextWidth(data), - _ => 0, - }; - _messageRenderer.Draw(new DrawContext - { - xStart = left + x, - x = left + x, - y = top, - Scale = 0.8f, - Color = new ColorF( - ((color >> 16) & 0xff) / 255.0f, - ((color >> 8) & 0xff) / 255.0f, - ((color >> 0) & 0xff) / 255.0f, - ((color >> 24) & 0xff) / 255.0f) - }, data); - } - - private float GetTextWidth(byte[] text) - { - var ctx = new DrawContext - { - IgnoreDraw = true, - Scale = 0.8f - }; - _messageRenderer.Draw(ctx, text); - - return (float)ctx.Width; - } - } -} +using OpenKh.Engine.Extensions; +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Renderers; +using OpenKh.Engine.Renders; +using OpenKh.Common; +using OpenKh.Game.Infrastructure; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.Linq; +using static OpenKh.Game.States.Title.Constants; +using OpenKh.Engine.Input; + +namespace OpenKh.Game.States.Title +{ + public class TitleState : IState, ITitleMainMenu + { + private enum TitleSubMenu + { + NewGame, + } + + private const int MainMenuNewGameOption = 0; + private const int MainMenuLoadOption = 1; + private const int MainMenuTheaterOption = 2; + private const int MainMenuBackOption = 3; + private const int MainMenuMaxOptionCount = 4; + + private ArchiveManager _archiveManager; + private IStateChange _stateChange; + private KingdomShader _shader; + private MonoSpriteDrawing drawing; + private LayoutRenderer layoutRendererFg; + private LayoutRenderer layoutRendererBg; + private LayoutRenderer layoutRendererTheater; + private AnimatedSequenceFactory _animatedSequenceFactory; + private Kh2MessageRenderer _messageRenderer; + private Layout _titleLayout; + private Layout _theaterLayout; + private Dictionary> cachedSurfaces = new Dictionary>(); + private Dictionary _cachedText = new Dictionary(); + + private TitleLayout _titleLayoutDesc; + private int _optionSelected; + + private ITitleSubMenu _subMenu; + + private bool _isTheaterModeUnlocked; + private bool _isInTheaterMenu; + + public Kernel Kernel { get; private set; } + public IInput Input { get; private set; } + public IMessageRenderer MessageRenderer => _messageRenderer; + + public MainMenuState State + { + set + { + switch (value) + { + case MainMenuState.StartNewGame: + StartNewGame(); + break; + } + } + } + + private TitleSubMenu SubMenu + { + set + { + switch (value) + { + case TitleSubMenu.NewGame: + _subMenu = new NewGameMenu(_animatedSequenceFactory, this); + break; + default: + Log.Warn("Submenu {0} not implemented.", value); + break; + } + + _subMenu?.Invoke(); + } + } + + private bool IsIntro + { + get + { + var currentSequence = layoutRendererBg.SelectedSequenceGroupIndex; + return currentSequence == _titleLayoutDesc.Copyright || + currentSequence == _titleLayoutDesc.Intro; + } + } + + private bool IsNewGameStarting => + layoutRendererBg.SelectedSequenceGroupIndex == _titleLayoutDesc.NewGame; + + public void Initialize(StateInitDesc initDesc) + { + Kernel = initDesc.Kernel; + _archiveManager = initDesc.ArchiveManager; + Input = initDesc.Input; + _stateChange = initDesc.StateChange; + + var viewport = initDesc.GraphicsDevice.GraphicsDevice.Viewport; + _shader = new KingdomShader(initDesc.ContentManager); + drawing = new MonoSpriteDrawing(initDesc.GraphicsDevice.GraphicsDevice, _shader); + drawing.SetProjection( + viewport.Width, + viewport.Height, + Global.ResolutionWidth, + Global.ResolutionHeight, + 1.0f); + + if (Kernel.IsReMix) + _archiveManager.LoadArchive($"menu/{Kernel.Region}/titlejf.2ld"); + _archiveManager.LoadArchive($"menu/{Kernel.Region}/title.2ld"); + _archiveManager.LoadArchive($"menu/{Kernel.Region}/save.2ld"); + + _isTheaterModeUnlocked = false; + if (Kernel.IsReMix) + { + if (_isTheaterModeUnlocked) + _titleLayoutDesc = ReMixTheaterTitleLayout; + else + _titleLayoutDesc = ReMixTitleLayout; + } + else if (Kernel.RegionId == (int)Kh2.Constants.RegionId.FinalMix) + { + if (_isTheaterModeUnlocked) + _titleLayoutDesc = FinalMixTheaterTitleLayout; + else + _titleLayoutDesc = FinalMixTitleLayout; + } + else + _titleLayoutDesc = VanillaTitleLayout; + + var messageContext = Kernel.SystemMessageContext; + _messageRenderer = new Kh2MessageRenderer(drawing, messageContext); + + IEnumerable images; + (_titleLayout, images) = GetLayoutResources("titl", "titl"); + + layoutRendererBg = new LayoutRenderer(_titleLayout, drawing, images); + layoutRendererFg = new LayoutRenderer(_titleLayout, drawing, images); + layoutRendererBg.SelectedSequenceGroupIndex = _titleLayoutDesc.Copyright; + + _animatedSequenceFactory = new AnimatedSequenceFactory( + drawing, + initDesc.Kernel.MessageProvider, + _messageRenderer, + initDesc.Kernel.SystemMessageContext.Encoder, + _titleLayout.SequenceItems[0], + images.First()); + + Log.Info("Theater={0}", _titleLayoutDesc.HasTheater); + if (_titleLayoutDesc.HasTheater) + { + (_theaterLayout, images) = GetLayoutResources("even", "even"); + layoutRendererTheater = new LayoutRenderer(_theaterLayout, drawing, images); + } + + SetOption(0); + } + + public void Destroy() + { + throw new NotImplementedException(); + } + + public void Update(DeltaTimes deltaTimes) + { + CheckTitlLoop(layoutRendererBg); + CheckTitlLoop(layoutRendererFg); + + if (_isInTheaterMenu) + { + switch (layoutRendererTheater.SelectedSequenceGroupIndex) + { + case 0: + layoutRendererTheater.FrameIndex++; + if (layoutRendererTheater.FrameIndex > 32) + { + layoutRendererTheater.FrameIndex = 0; + layoutRendererTheater.SelectedSequenceGroupIndex = 1; + } + break; + case 1: + break; + case 2: + layoutRendererTheater.FrameIndex++; + if (layoutRendererTheater.FrameIndex > 32) + _isInTheaterMenu = false; + break; + } + } + + if (_subMenu?.IsOpen == true) + _subMenu.Update(deltaTimes.DeltaTime); + else + { + if (IsIntro) + { + if (Input.Triggered.Confirm || Input.Triggered.Cancel || Input.Triggered.SpecialRight) + SkipIntro(); + } + else if (IsNewGameStarting) + { + // block any input + } + else if (_isInTheaterMenu) + ProcessInputTheaterMenu(); + else + ProcessInputMainMenu(); + } + } + + public void Draw(DeltaTimes deltaTimes) + { + layoutRendererBg.Draw(); + + if (!(IsIntro || IsNewGameStarting)) + layoutRendererFg.Draw(); + + if (_isInTheaterMenu) + layoutRendererTheater.Draw(); + + else if (_subMenu?.IsOpen == true) + _subMenu.Draw(); + + drawing.Flush(); + } + + private void ProcessInputMainMenu() + { + var currentOption = _optionSelected; + if (Input.Repeated.Up) + { + currentOption--; + if (currentOption < 0) + currentOption = MainMenuBackOption; + + if (currentOption == MainMenuBackOption && !_titleLayoutDesc.HasBack) + currentOption = MainMenuTheaterOption; + if (currentOption == MainMenuTheaterOption && !_titleLayoutDesc.HasTheater) + currentOption = MainMenuLoadOption; + } + else if (Input.Repeated.Down) + { + currentOption++; + if (currentOption == MainMenuTheaterOption && !_titleLayoutDesc.HasTheater) + currentOption++; + if (currentOption == MainMenuBackOption && !_titleLayoutDesc.HasBack) + currentOption++; + if (currentOption >= MainMenuMaxOptionCount) + currentOption = 0; + } + else if (Input.Triggered.Confirm) + { + switch (currentOption) + { + case MainMenuNewGameOption: + SubMenu = TitleSubMenu.NewGame; + break; + case MainMenuLoadOption: + Kernel.LoadSaveData(Config.LastSave); + SetStateToGameplay(); + break; + case MainMenuTheaterOption: + _isInTheaterMenu = true; + layoutRendererTheater.FrameIndex = 0; + layoutRendererTheater.SelectedSequenceGroupIndex = 0; + break; + } + } + + + if (currentOption != _optionSelected) + SetOption(currentOption); + } + + private void ProcessInputTheaterMenu() + { + if (Input.Repeated.Cancel) + { + layoutRendererTheater.FrameIndex = 0; + layoutRendererTheater.SelectedSequenceGroupIndex = 2; + } + } + + private void SkipIntro() + { + layoutRendererBg.SelectedSequenceGroupIndex = _titleLayoutDesc.IntroSkip; + layoutRendererBg.FrameIndex = 0; + } + + private void SetStateToGameplay() + { + _stateChange.State = 1; + } + + private void StartNewGame() + { + layoutRendererBg.SelectedSequenceGroupIndex = _titleLayoutDesc.NewGame; + layoutRendererBg.FrameIndex = 0; + } + + private void SetOption(int option) + { + Log.Info("TitleOption={0} prev={1}", option, _optionSelected); + _optionSelected = option; + + switch (_optionSelected) + { + case MainMenuNewGameOption: + layoutRendererFg.SelectedSequenceGroupIndex = _titleLayoutDesc.MenuOptionNewGame; + break; + case MainMenuLoadOption: + layoutRendererFg.SelectedSequenceGroupIndex = _titleLayoutDesc.MenuOptionLoad; + break; + case MainMenuTheaterOption: + layoutRendererFg.SelectedSequenceGroupIndex = _titleLayoutDesc.MenuOptionTheater; + break; + case MainMenuBackOption: + layoutRendererFg.SelectedSequenceGroupIndex = _titleLayoutDesc.MenuOptionBack; + break; + } + + layoutRendererFg.FrameIndex = 0; + } + + private void CheckTitlLoop(LayoutRenderer layout) + { + layout.FrameIndex++; + var currentSequenceGroupIndex = layout.SelectedSequenceGroupIndex; + if (currentSequenceGroupIndex == _titleLayoutDesc.Copyright) + { + if (layout.IsLastFrame) + { + layout.SelectedSequenceGroupIndex = _titleLayoutDesc.Intro; + layout.FrameIndex = 0; + } + } + else if (currentSequenceGroupIndex == _titleLayoutDesc.Intro) + { + if (layout.FrameIndex >= 480) + { + layout.SelectedSequenceGroupIndex = _titleLayoutDesc.IntroSkip; + layout.FrameIndex = 0; + } + } + else if (currentSequenceGroupIndex == _titleLayoutDesc.NewGame) + { + if (layout.IsLastFrame) + SetStateToGameplay(); + } + else + layout.FrameIndex++; + } + + private (Layout layout, IEnumerable textures) GetLayoutResources(string layoutResourceName, string imagesResourceName) + { + var layout = _archiveManager.Get(layoutResourceName); + if (!cachedSurfaces.TryGetValue(imagesResourceName, out var images)) + images = cachedSurfaces[imagesResourceName] = _archiveManager.Get(imagesResourceName) + ?.Images?.Select(x => drawing.CreateSpriteTexture(x)).ToList(); + + return (layout, images); + } + + public byte[] GetMessage(ushort messageId) + { + if (!_cachedText.TryGetValue(messageId, out var data)) + _cachedText[messageId] = data = Kernel.MessageProvider.GetMessage(messageId); + + return data; + } + + public void Print(ushort messageId, float left, float top, + uint color, TextAlignment alignment) + { + var data = GetMessage(messageId); + + var x = alignment switch + { + TextAlignment.Left => 0, + TextAlignment.Center => -(GetTextWidth(data) / 2), + TextAlignment.Right => -GetTextWidth(data), + _ => 0, + }; + _messageRenderer.Draw(new DrawContext + { + xStart = left + x, + x = left + x, + y = top, + Scale = 0.8f, + Color = new ColorF( + ((color >> 16) & 0xff) / 255.0f, + ((color >> 8) & 0xff) / 255.0f, + ((color >> 0) & 0xff) / 255.0f, + ((color >> 24) & 0xff) / 255.0f) + }, data); + } + + private float GetTextWidth(byte[] text) + { + var ctx = new DrawContext + { + IgnoreDraw = true, + Scale = 0.8f + }; + _messageRenderer.Draw(ctx, text); + + return (float)ctx.Width; + } + } +} diff --git a/OpenKh.Imaging/IImage.cs b/OpenKh.Imaging/IImage.cs index 1d20f2d45..244647ea1 100644 --- a/OpenKh.Imaging/IImage.cs +++ b/OpenKh.Imaging/IImage.cs @@ -1,11 +1,11 @@ -using System.Drawing; - -namespace OpenKh.Imaging -{ - public interface IImage - { - Size Size { get; } - - PixelFormat PixelFormat { get; } - } -} +using System.Drawing; + +namespace OpenKh.Imaging +{ + public interface IImage + { + Size Size { get; } + + PixelFormat PixelFormat { get; } + } +} diff --git a/OpenKh.Imaging/IImageRead.cs b/OpenKh.Imaging/IImageRead.cs index 73db5ce20..f714ed2a3 100644 --- a/OpenKh.Imaging/IImageRead.cs +++ b/OpenKh.Imaging/IImageRead.cs @@ -1,16 +1,16 @@ -namespace OpenKh.Imaging -{ - public interface IImageRead : IImage - { - /// - /// Get pixel data - /// - /// - /// PixelFormat == Rgba8888 - /// - 4 bytes [B, G, R, A] per pixel. - /// - byte[] GetData(); - - byte[] GetClut(); - } -} +namespace OpenKh.Imaging +{ + public interface IImageRead : IImage + { + /// + /// Get pixel data + /// + /// + /// PixelFormat == Rgba8888 + /// - 4 bytes [B, G, R, A] per pixel. + /// + byte[] GetData(); + + byte[] GetClut(); + } +} diff --git a/OpenKh.Imaging/ImageDataHelpers.cs b/OpenKh.Imaging/ImageDataHelpers.cs index bd2a28356..71a30b625 100644 --- a/OpenKh.Imaging/ImageDataHelpers.cs +++ b/OpenKh.Imaging/ImageDataHelpers.cs @@ -1,138 +1,138 @@ -using System; -using System.Drawing; -using System.Linq; - -namespace OpenKh.Imaging -{ - public static class ImageDataHelpers - { - public const int RedChannel = 0; - public const int GreenChannel = 1; - public const int BlueChannel = 2; - public const int AlphaChannel = 3; - public static readonly byte[] BGRA = new byte[] { BlueChannel, GreenChannel, RedChannel, AlphaChannel }; - public static readonly byte[] RGBA = new byte[] { RedChannel, GreenChannel, BlueChannel, AlphaChannel }; - - public static byte[] FromIndexed8ToBitmap32(byte[] data, byte[] clut, byte[] channelOrder) - { - var bitmap = new byte[data.Length * 4]; - for (int i = 0; i < data.Length; i++) - { - var clutIndex = data[i]; - bitmap[i * 4 + 0] = clut[clutIndex * 4 + channelOrder[2]]; - bitmap[i * 4 + 1] = clut[clutIndex * 4 + channelOrder[1]]; - bitmap[i * 4 + 2] = clut[clutIndex * 4 + channelOrder[0]]; - bitmap[i * 4 + 3] = clut[clutIndex * 4 + channelOrder[3]]; - } - return bitmap; - } - - public static byte[] FromIndexed4ToBitmap32(byte[] data, byte[] clut, byte[] channelOrder) - { - var bitmap = new byte[data.Length * 8]; - for (int i = 0; i < data.Length; i++) - { - var subData = data[i]; - var clutIndex1 = subData >> 4; - var clutIndex2 = subData & 0x0F; - bitmap[i * 8 + 0] = clut[clutIndex1 * 4 + channelOrder[2]]; - bitmap[i * 8 + 1] = clut[clutIndex1 * 4 + channelOrder[1]]; - bitmap[i * 8 + 2] = clut[clutIndex1 * 4 + channelOrder[0]]; - bitmap[i * 8 + 3] = clut[clutIndex1 * 4 + channelOrder[3]]; - bitmap[i * 8 + 4] = clut[clutIndex2 * 4 + channelOrder[2]]; - bitmap[i * 8 + 5] = clut[clutIndex2 * 4 + channelOrder[1]]; - bitmap[i * 8 + 6] = clut[clutIndex2 * 4 + channelOrder[0]]; - bitmap[i * 8 + 7] = clut[clutIndex2 * 4 + channelOrder[3]]; - } - return bitmap; - } - - public static byte[] FromBitmap32(byte[] data, byte[] channelOrder) - { - var dstData = new byte[data.Length]; - - for (var i = 0; i < data.Length; i += 4) - { - dstData[i + 0] = data[i + channelOrder[0]]; - dstData[i + 1] = data[i + channelOrder[1]]; - dstData[i + 2] = data[i + channelOrder[2]]; - dstData[i + 3] = data[i + channelOrder[3]]; - } - - return dstData; - } - - public static void InvertRedBlueChannels(byte[] data, Size size, PixelFormat pixelFormat) - { - var length = size.Width * size.Height; - switch (pixelFormat) - { - case PixelFormat.Rgb888: - for (var i = 0; i < length; i++) - { - byte tmp = data[i * 3 + 0]; - data[i * 3 + 0] = data[i * 3 + 2]; - data[i * 3 + 2] = tmp; - } - break; - case PixelFormat.Rgba8888: - for (int i = 0; i < length; i++) - { - byte tmp = data[i * 4 + 0]; - data[i * 4 + 0] = data[i * 4 + 2]; - data[i * 4 + 2] = tmp; - } - break; - case PixelFormat.Indexed8: - break; - case PixelFormat.Indexed4: - // no pixel swapping is required - break; - default: - throw new ArgumentOutOfRangeException($"The format {pixelFormat} is invalid or not supported."); - } - } - - public static byte[] GetInvertedRedBlueChannels(byte[] data, Size size, PixelFormat pixelFormat) - { - var length = size.Width * size.Height; - var dst = new byte[data.Length]; - - switch (pixelFormat) - { - case PixelFormat.Rgb888: - for (var i = 0; i < length; i++) - { - dst[i * 3 + 0] = data[i * 3 + 2]; - dst[i * 3 + 1] = data[i * 3 + 1]; - dst[i * 3 + 2] = data[i * 3 + 0]; - } - break; - case PixelFormat.Rgba8888: - for (var i = 0; i < length; i++) - { - dst[i * 4 + 0] = data[i * 4 + 2]; - dst[i * 4 + 1] = data[i * 4 + 1]; - dst[i * 4 + 2] = data[i * 4 + 0]; - dst[i * 4 + 3] = data[i * 4 + 3]; - } - break; - case PixelFormat.Indexed8: - return data; - case PixelFormat.Indexed4: - // no pixel swapping is required - return data; - default: - throw new ArgumentOutOfRangeException($"The format {pixelFormat} is invalid or not supported."); - } - - return dst; - } - - public static void SwapEndianIndexed4(byte[] data) - { - for (var i = 0; i < data.Length; i++) - data[i] = (byte)(((data[i] & 0x0F) << 4) | (data[i] >> 4)); - } - } -} +using System; +using System.Drawing; +using System.Linq; + +namespace OpenKh.Imaging +{ + public static class ImageDataHelpers + { + public const int RedChannel = 0; + public const int GreenChannel = 1; + public const int BlueChannel = 2; + public const int AlphaChannel = 3; + public static readonly byte[] BGRA = new byte[] { BlueChannel, GreenChannel, RedChannel, AlphaChannel }; + public static readonly byte[] RGBA = new byte[] { RedChannel, GreenChannel, BlueChannel, AlphaChannel }; + + public static byte[] FromIndexed8ToBitmap32(byte[] data, byte[] clut, byte[] channelOrder) + { + var bitmap = new byte[data.Length * 4]; + for (int i = 0; i < data.Length; i++) + { + var clutIndex = data[i]; + bitmap[i * 4 + 0] = clut[clutIndex * 4 + channelOrder[2]]; + bitmap[i * 4 + 1] = clut[clutIndex * 4 + channelOrder[1]]; + bitmap[i * 4 + 2] = clut[clutIndex * 4 + channelOrder[0]]; + bitmap[i * 4 + 3] = clut[clutIndex * 4 + channelOrder[3]]; + } + return bitmap; + } + + public static byte[] FromIndexed4ToBitmap32(byte[] data, byte[] clut, byte[] channelOrder) + { + var bitmap = new byte[data.Length * 8]; + for (int i = 0; i < data.Length; i++) + { + var subData = data[i]; + var clutIndex1 = subData >> 4; + var clutIndex2 = subData & 0x0F; + bitmap[i * 8 + 0] = clut[clutIndex1 * 4 + channelOrder[2]]; + bitmap[i * 8 + 1] = clut[clutIndex1 * 4 + channelOrder[1]]; + bitmap[i * 8 + 2] = clut[clutIndex1 * 4 + channelOrder[0]]; + bitmap[i * 8 + 3] = clut[clutIndex1 * 4 + channelOrder[3]]; + bitmap[i * 8 + 4] = clut[clutIndex2 * 4 + channelOrder[2]]; + bitmap[i * 8 + 5] = clut[clutIndex2 * 4 + channelOrder[1]]; + bitmap[i * 8 + 6] = clut[clutIndex2 * 4 + channelOrder[0]]; + bitmap[i * 8 + 7] = clut[clutIndex2 * 4 + channelOrder[3]]; + } + return bitmap; + } + + public static byte[] FromBitmap32(byte[] data, byte[] channelOrder) + { + var dstData = new byte[data.Length]; + + for (var i = 0; i < data.Length; i += 4) + { + dstData[i + 0] = data[i + channelOrder[0]]; + dstData[i + 1] = data[i + channelOrder[1]]; + dstData[i + 2] = data[i + channelOrder[2]]; + dstData[i + 3] = data[i + channelOrder[3]]; + } + + return dstData; + } + + public static void InvertRedBlueChannels(byte[] data, Size size, PixelFormat pixelFormat) + { + var length = size.Width * size.Height; + switch (pixelFormat) + { + case PixelFormat.Rgb888: + for (var i = 0; i < length; i++) + { + byte tmp = data[i * 3 + 0]; + data[i * 3 + 0] = data[i * 3 + 2]; + data[i * 3 + 2] = tmp; + } + break; + case PixelFormat.Rgba8888: + for (int i = 0; i < length; i++) + { + byte tmp = data[i * 4 + 0]; + data[i * 4 + 0] = data[i * 4 + 2]; + data[i * 4 + 2] = tmp; + } + break; + case PixelFormat.Indexed8: + break; + case PixelFormat.Indexed4: + // no pixel swapping is required + break; + default: + throw new ArgumentOutOfRangeException($"The format {pixelFormat} is invalid or not supported."); + } + } + + public static byte[] GetInvertedRedBlueChannels(byte[] data, Size size, PixelFormat pixelFormat) + { + var length = size.Width * size.Height; + var dst = new byte[data.Length]; + + switch (pixelFormat) + { + case PixelFormat.Rgb888: + for (var i = 0; i < length; i++) + { + dst[i * 3 + 0] = data[i * 3 + 2]; + dst[i * 3 + 1] = data[i * 3 + 1]; + dst[i * 3 + 2] = data[i * 3 + 0]; + } + break; + case PixelFormat.Rgba8888: + for (var i = 0; i < length; i++) + { + dst[i * 4 + 0] = data[i * 4 + 2]; + dst[i * 4 + 1] = data[i * 4 + 1]; + dst[i * 4 + 2] = data[i * 4 + 0]; + dst[i * 4 + 3] = data[i * 4 + 3]; + } + break; + case PixelFormat.Indexed8: + return data; + case PixelFormat.Indexed4: + // no pixel swapping is required + return data; + default: + throw new ArgumentOutOfRangeException($"The format {pixelFormat} is invalid or not supported."); + } + + return dst; + } + + public static void SwapEndianIndexed4(byte[] data) + { + for (var i = 0; i < data.Length; i++) + data[i] = (byte)(((data[i] & 0x0F) << 4) | (data[i] >> 4)); + } + } +} diff --git a/OpenKh.Imaging/ImageExtensions.cs b/OpenKh.Imaging/ImageExtensions.cs index e12c0bd31..c7c661a79 100644 --- a/OpenKh.Imaging/ImageExtensions.cs +++ b/OpenKh.Imaging/ImageExtensions.cs @@ -1,24 +1,24 @@ -using System; - -namespace OpenKh.Imaging -{ - public static class ImageExtensions - { - public static byte[] ToBgra32(this IImageRead imageRead) - { - switch (imageRead.PixelFormat) - { - case PixelFormat.Indexed4: - return ImageDataHelpers.FromIndexed4ToBitmap32(imageRead.GetData(), imageRead.GetClut(), - ImageDataHelpers.RGBA); - case PixelFormat.Indexed8: - return ImageDataHelpers.FromIndexed8ToBitmap32(imageRead.GetData(), imageRead.GetClut(), - ImageDataHelpers.RGBA); - case PixelFormat.Rgba8888: - return imageRead.GetData(); - default: - throw new NotImplementedException($"The PixelFormat {imageRead.PixelFormat} cannot be converted to a Bgra32."); - } - } - } -} +using System; + +namespace OpenKh.Imaging +{ + public static class ImageExtensions + { + public static byte[] ToBgra32(this IImageRead imageRead) + { + switch (imageRead.PixelFormat) + { + case PixelFormat.Indexed4: + return ImageDataHelpers.FromIndexed4ToBitmap32(imageRead.GetData(), imageRead.GetClut(), + ImageDataHelpers.RGBA); + case PixelFormat.Indexed8: + return ImageDataHelpers.FromIndexed8ToBitmap32(imageRead.GetData(), imageRead.GetClut(), + ImageDataHelpers.RGBA); + case PixelFormat.Rgba8888: + return imageRead.GetData(); + default: + throw new NotImplementedException($"The PixelFormat {imageRead.PixelFormat} cannot be converted to a Bgra32."); + } + } + } +} diff --git a/OpenKh.Imaging/PixelFormat.cs b/OpenKh.Imaging/PixelFormat.cs index ab519bfe0..cf4773ec6 100644 --- a/OpenKh.Imaging/PixelFormat.cs +++ b/OpenKh.Imaging/PixelFormat.cs @@ -1,13 +1,13 @@ -namespace OpenKh.Imaging -{ - public enum PixelFormat - { - Undefined, - Indexed4, - Indexed8, - Rgba1555, - Rgb888, - Rgbx8888, - Rgba8888 - } -} +namespace OpenKh.Imaging +{ + public enum PixelFormat + { + Undefined, + Indexed4, + Indexed8, + Rgba1555, + Rgb888, + Rgbx8888, + Rgba8888 + } +} diff --git a/OpenKh.Imaging/PixelFormatExtensions.cs b/OpenKh.Imaging/PixelFormatExtensions.cs index 97b37c71b..ef42f6d7f 100644 --- a/OpenKh.Imaging/PixelFormatExtensions.cs +++ b/OpenKh.Imaging/PixelFormatExtensions.cs @@ -1,19 +1,19 @@ -using System; - -namespace OpenKh.Imaging -{ - public static class PixelFormatExtensions - { - public static bool IsIndexed(this PixelFormat pixelFormat) - { - switch (pixelFormat) - { - case PixelFormat.Indexed4: - case PixelFormat.Indexed8: - return true; - default: - return false; - } - } - } -} +using System; + +namespace OpenKh.Imaging +{ + public static class PixelFormatExtensions + { + public static bool IsIndexed(this PixelFormat pixelFormat) + { + switch (pixelFormat) + { + case PixelFormat.Indexed4: + case PixelFormat.Indexed8: + return true; + default: + return false; + } + } + } +} diff --git a/OpenKh.Imaging/PngImage.cs b/OpenKh.Imaging/PngImage.cs index 91afa2ab8..9dd00b48f 100644 --- a/OpenKh.Imaging/PngImage.cs +++ b/OpenKh.Imaging/PngImage.cs @@ -2,358 +2,358 @@ using OpenKh.Imaging; using System; using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.IO.Compression; +using System.Drawing; +using System.IO; +using System.IO.Compression; using System.Text; -using Xe.BinaryMapper; - +using Xe.BinaryMapper; + namespace OpenKh.Imaging { public class PngImage : IImageRead - { - private byte[] _data; - private byte[] _clut; - - internal enum ColorType - { - TrueColor = 2, - Indexed = 3, - AlphaTrueColor = 6, - } - - internal enum ComprMethod - { - Deflate = 0, - } - - internal enum InterlaceMethod - { - None = 0, - Adam7 = 1, - } - - internal class Signature - { - [Data] public ulong Magic { get; set; } - - public const ulong Valid = 727905341920923785; - } - - internal class Chunk - { - [Data] public int Length { get; set; } - [Data] public int CType { get; set; } - public byte[] RawData { get; set; } - public int Crc { get; set; } - - public const int IHDR = 0x49484452; - public const int IDAT = 0x49444154; - public const int IEND = 0x49454E44; - public const int PLTE = 0x504C5445; - public const int tRNS = 0x74524E53; - } - - internal class IHdr - { - [Data] public int Width { get; set; } - [Data] public int Height { get; set; } - [Data] public byte Bits { get; set; } - [Data] public byte ColorType { get; set; } - [Data] public byte ComprMethod { get; set; } - [Data] public byte FilterMethod { get; set; } - [Data] public byte InterlaceMethod { get; set; } - } - - public PngImage(Stream stream) - { - stream.SetPosition(0); - var header = BinaryMapping.ReadObject(stream); - if (header.Magic != Signature.Valid) - { - throw new InvalidDataException("Bad signature code!"); - } - - var fullData = new MemoryStream(); - IHdr ihdr = null; - byte[] PLTE = null; - byte[] tRNS = null; - - while (stream.Position < stream.Length) - { - var chunk = BinaryMapping.ReadObject(stream); - chunk.CType = Turn(chunk.CType); - chunk.Length = Turn(chunk.Length); - chunk.RawData = stream.ReadBytes(chunk.Length); - chunk.Crc = Turn(stream.ReadInt32()); - - if (chunk.CType == Chunk.IEND) - { - break; - } - switch (chunk.CType) - { - case Chunk.IHDR: - ihdr = BinaryMapping.ReadObject(new MemoryStream(chunk.RawData)); - ihdr.Width = Turn(ihdr.Width); - ihdr.Height = Turn(ihdr.Height); - break; - - case Chunk.PLTE: - PLTE = chunk.RawData; - break; - - case Chunk.tRNS: - tRNS = chunk.RawData; - break; - - case Chunk.IDAT: - fullData.Write(chunk.RawData); - break; - } - } - - if (ihdr == null) - { - throw new InvalidDataException("No IHDR!"); - } - - var interlaceMethod = (InterlaceMethod)ihdr.InterlaceMethod; - - if (interlaceMethod != InterlaceMethod.None) - { - throw new NotSupportedException($"interlaceMethod {interlaceMethod} not supported!"); - } - - var comprMethod = (ComprMethod)ihdr.ComprMethod; - - if (comprMethod != ComprMethod.Deflate) - { - throw new NotSupportedException($"comprMethod {comprMethod} not supported!"); - } - - fullData.Position = 2; - - var deflater = new DeflateStream(fullData, CompressionMode.Decompress); - - Size = new Size(ihdr.Width, ihdr.Height); - - var bits = ihdr.Bits; - var colorType = (ColorType)ihdr.ColorType; - - if (bits == 4 && colorType == ColorType.Indexed) - { - PixelFormat = PixelFormat.Indexed4; - var stride = (1 + Size.Width) / 2; - _data = new byte[stride * Size.Height]; - for (int y = 0; y < Size.Height; y++) - { - var filter = deflater.ReadByte(); - deflater.Read(_data, y * stride, stride); - ApplyFilter(_data, y * stride, 1, stride, filter); - } - _clut = PrepareClut(PLTE, tRNS, 16); - } - else if (bits == 8 && colorType == ColorType.Indexed) - { - PixelFormat = PixelFormat.Indexed8; - var stride = Size.Width; - _data = new byte[stride * Size.Height]; - for (int y = 0; y < Size.Height; y++) - { - var filter = deflater.ReadByte(); - deflater.Read(_data, y * stride, stride); - ApplyFilter(_data, y * stride, 1, stride, filter); - } - _clut = PrepareClut(PLTE, tRNS, 256); - } - else if (bits == 8 && colorType == ColorType.TrueColor) - { - PixelFormat = PixelFormat.Rgb888; - var stride = 3 * Size.Width; - _data = new byte[stride * Size.Height]; - for (int y = 0; y < Size.Height; y++) - { - var filter = deflater.ReadByte(); - deflater.Read(_data, y * stride, stride); - ApplyFilter(_data, y * stride, 3, stride, filter); - } - } - else if (bits == 8 && colorType == ColorType.AlphaTrueColor) - { - PixelFormat = PixelFormat.Rgba8888; - var stride = 4 * Size.Width; - _data = new byte[stride * Size.Height]; - for (int y = 0; y < Size.Height; y++) - { - var filter = deflater.ReadByte(); - deflater.Read(_data, y * stride, stride); - ApplyFilter(_data, y * stride, 4, stride, filter); - } - - int localOfs = 0; - - for (int y = 0; y < Size.Height; y++) - { - for (int x = 0; x < Size.Width; x++, localOfs += 4) - { - var r = _data[localOfs + 0]; - var g = _data[localOfs + 1]; - var b = _data[localOfs + 2]; - var a = _data[localOfs + 3]; - - _data[localOfs + 0] = b; - _data[localOfs + 1] = g; - _data[localOfs + 2] = r; - _data[localOfs + 3] = a; - } - } - } - else - { - throw new NotSupportedException($"Not supported combination: bits = {bits} and colorType = {colorType}"); - } - } - - private void ApplyFilter(byte[] data, int ptr, int pixelSize, int stride, int filter) - { - // See: https://www.w3.org/TR/PNG-Filters.html - // See: https://www.w3.org/TR/2003/REC-PNG-20031110/#9FtIntro - - if (filter == 0) - { - // nop - } - else if (filter == 1) - { - var endPtr = ptr + stride; - ptr += pixelSize; - for (; ptr < endPtr; ptr++) - { - data[ptr] += data[ptr - pixelSize]; - } - } - else if (filter == 2) - { - var endPtr = ptr + stride; - for (; ptr < endPtr; ptr++) - { - data[ptr] += data[ptr - stride]; - } - } - else if (filter == 3) - { - var endPtr = ptr + stride; - var atNextPixel = ptr + pixelSize; - for (; ptr < atNextPixel; ptr++) - { - data[ptr] += (byte)((0 + data[ptr - stride]) / 2); - } - for (; ptr < endPtr; ptr++) - { - data[ptr] += (byte)((data[ptr - pixelSize] + data[ptr - stride]) / 2); - } - } - else if (filter == 4) - { - var endPtr = ptr + stride; - var atNextPixel = ptr + pixelSize; - for (; ptr < atNextPixel; ptr++) - { - data[ptr] += data[ptr - stride]; - } - for (; ptr < endPtr; ptr++) - { - data[ptr] += PaethPredictor( - data[ptr - pixelSize], - data[ptr - stride], - data[ptr - pixelSize - stride] - ); - } - } - else - { - throw new NotSupportedException(); - } - } - - private byte PaethPredictor(byte a, byte b, byte c) - { - var p = a + b - c; - var pa = Math.Abs(p - a); - var pb = Math.Abs(p - b); - var pc = Math.Abs(p - c); - if (pa <= pb && pa <= pc) - { - return (byte)a; - } - else if (pb <= pc) - { - return (byte)b; - } - else - { - return (byte)c; - } - } - - private byte[] PrepareClut(byte[] PLTE, byte[] tRNS, int count) - { - var clut = new byte[4 * count]; - for (int y = 0; y < count; y++) - { - if (3 * (y + 1) <= PLTE.Length) - { - clut[4 * y + 0] = PLTE[3 * y + 0]; - clut[4 * y + 1] = PLTE[3 * y + 1]; - clut[4 * y + 2] = PLTE[3 * y + 2]; - } - if (y + 1 <= tRNS.Length) - { - clut[4 * y + 3] = tRNS[y]; - } - } - return clut; - } - - private static int Turn(int val) - { - return (int)Turn((uint)val); - } - - private static uint Turn(uint val) - { - return 0 - | ((val << 24)) - | ((val << 8) & 0x00FF0000) - | ((val >> 8) & 0x0000FF00) - | ((val >> 24) & 0x000000FF) - ; - } - - public static bool IsValid(Stream stream) - { - stream.SetPosition(0); - return stream.ReadByte() == 0x89 && - stream.ReadByte() == 0x50 && - stream.ReadByte() == 0x4e && - stream.ReadByte() == 0x47 && - stream.ReadByte() == 0x0d && - stream.ReadByte() == 0x0a && - stream.ReadByte() == 0x1a && - stream.ReadByte() == 0x0a; - } - - public static PngImage Read(Stream stream) => new PngImage(stream); - - #region IImageRead - public Size Size { get; internal set; } - - public PixelFormat PixelFormat { get; internal set; } - - public byte[] GetData() => _data; - - public byte[] GetClut() => _clut; - #endregion + { + private byte[] _data; + private byte[] _clut; + + internal enum ColorType + { + TrueColor = 2, + Indexed = 3, + AlphaTrueColor = 6, + } + + internal enum ComprMethod + { + Deflate = 0, + } + + internal enum InterlaceMethod + { + None = 0, + Adam7 = 1, + } + + internal class Signature + { + [Data] public ulong Magic { get; set; } + + public const ulong Valid = 727905341920923785; + } + + internal class Chunk + { + [Data] public int Length { get; set; } + [Data] public int CType { get; set; } + public byte[] RawData { get; set; } + public int Crc { get; set; } + + public const int IHDR = 0x49484452; + public const int IDAT = 0x49444154; + public const int IEND = 0x49454E44; + public const int PLTE = 0x504C5445; + public const int tRNS = 0x74524E53; + } + + internal class IHdr + { + [Data] public int Width { get; set; } + [Data] public int Height { get; set; } + [Data] public byte Bits { get; set; } + [Data] public byte ColorType { get; set; } + [Data] public byte ComprMethod { get; set; } + [Data] public byte FilterMethod { get; set; } + [Data] public byte InterlaceMethod { get; set; } + } + + public PngImage(Stream stream) + { + stream.SetPosition(0); + var header = BinaryMapping.ReadObject(stream); + if (header.Magic != Signature.Valid) + { + throw new InvalidDataException("Bad signature code!"); + } + + var fullData = new MemoryStream(); + IHdr ihdr = null; + byte[] PLTE = null; + byte[] tRNS = null; + + while (stream.Position < stream.Length) + { + var chunk = BinaryMapping.ReadObject(stream); + chunk.CType = Turn(chunk.CType); + chunk.Length = Turn(chunk.Length); + chunk.RawData = stream.ReadBytes(chunk.Length); + chunk.Crc = Turn(stream.ReadInt32()); + + if (chunk.CType == Chunk.IEND) + { + break; + } + switch (chunk.CType) + { + case Chunk.IHDR: + ihdr = BinaryMapping.ReadObject(new MemoryStream(chunk.RawData)); + ihdr.Width = Turn(ihdr.Width); + ihdr.Height = Turn(ihdr.Height); + break; + + case Chunk.PLTE: + PLTE = chunk.RawData; + break; + + case Chunk.tRNS: + tRNS = chunk.RawData; + break; + + case Chunk.IDAT: + fullData.Write(chunk.RawData); + break; + } + } + + if (ihdr == null) + { + throw new InvalidDataException("No IHDR!"); + } + + var interlaceMethod = (InterlaceMethod)ihdr.InterlaceMethod; + + if (interlaceMethod != InterlaceMethod.None) + { + throw new NotSupportedException($"interlaceMethod {interlaceMethod} not supported!"); + } + + var comprMethod = (ComprMethod)ihdr.ComprMethod; + + if (comprMethod != ComprMethod.Deflate) + { + throw new NotSupportedException($"comprMethod {comprMethod} not supported!"); + } + + fullData.Position = 2; + + var deflater = new DeflateStream(fullData, CompressionMode.Decompress); + + Size = new Size(ihdr.Width, ihdr.Height); + + var bits = ihdr.Bits; + var colorType = (ColorType)ihdr.ColorType; + + if (bits == 4 && colorType == ColorType.Indexed) + { + PixelFormat = PixelFormat.Indexed4; + var stride = (1 + Size.Width) / 2; + _data = new byte[stride * Size.Height]; + for (int y = 0; y < Size.Height; y++) + { + var filter = deflater.ReadByte(); + deflater.Read(_data, y * stride, stride); + ApplyFilter(_data, y * stride, 1, stride, filter); + } + _clut = PrepareClut(PLTE, tRNS, 16); + } + else if (bits == 8 && colorType == ColorType.Indexed) + { + PixelFormat = PixelFormat.Indexed8; + var stride = Size.Width; + _data = new byte[stride * Size.Height]; + for (int y = 0; y < Size.Height; y++) + { + var filter = deflater.ReadByte(); + deflater.Read(_data, y * stride, stride); + ApplyFilter(_data, y * stride, 1, stride, filter); + } + _clut = PrepareClut(PLTE, tRNS, 256); + } + else if (bits == 8 && colorType == ColorType.TrueColor) + { + PixelFormat = PixelFormat.Rgb888; + var stride = 3 * Size.Width; + _data = new byte[stride * Size.Height]; + for (int y = 0; y < Size.Height; y++) + { + var filter = deflater.ReadByte(); + deflater.Read(_data, y * stride, stride); + ApplyFilter(_data, y * stride, 3, stride, filter); + } + } + else if (bits == 8 && colorType == ColorType.AlphaTrueColor) + { + PixelFormat = PixelFormat.Rgba8888; + var stride = 4 * Size.Width; + _data = new byte[stride * Size.Height]; + for (int y = 0; y < Size.Height; y++) + { + var filter = deflater.ReadByte(); + deflater.Read(_data, y * stride, stride); + ApplyFilter(_data, y * stride, 4, stride, filter); + } + + int localOfs = 0; + + for (int y = 0; y < Size.Height; y++) + { + for (int x = 0; x < Size.Width; x++, localOfs += 4) + { + var r = _data[localOfs + 0]; + var g = _data[localOfs + 1]; + var b = _data[localOfs + 2]; + var a = _data[localOfs + 3]; + + _data[localOfs + 0] = b; + _data[localOfs + 1] = g; + _data[localOfs + 2] = r; + _data[localOfs + 3] = a; + } + } + } + else + { + throw new NotSupportedException($"Not supported combination: bits = {bits} and colorType = {colorType}"); + } + } + + private void ApplyFilter(byte[] data, int ptr, int pixelSize, int stride, int filter) + { + // See: https://www.w3.org/TR/PNG-Filters.html + // See: https://www.w3.org/TR/2003/REC-PNG-20031110/#9FtIntro + + if (filter == 0) + { + // nop + } + else if (filter == 1) + { + var endPtr = ptr + stride; + ptr += pixelSize; + for (; ptr < endPtr; ptr++) + { + data[ptr] += data[ptr - pixelSize]; + } + } + else if (filter == 2) + { + var endPtr = ptr + stride; + for (; ptr < endPtr; ptr++) + { + data[ptr] += data[ptr - stride]; + } + } + else if (filter == 3) + { + var endPtr = ptr + stride; + var atNextPixel = ptr + pixelSize; + for (; ptr < atNextPixel; ptr++) + { + data[ptr] += (byte)((0 + data[ptr - stride]) / 2); + } + for (; ptr < endPtr; ptr++) + { + data[ptr] += (byte)((data[ptr - pixelSize] + data[ptr - stride]) / 2); + } + } + else if (filter == 4) + { + var endPtr = ptr + stride; + var atNextPixel = ptr + pixelSize; + for (; ptr < atNextPixel; ptr++) + { + data[ptr] += data[ptr - stride]; + } + for (; ptr < endPtr; ptr++) + { + data[ptr] += PaethPredictor( + data[ptr - pixelSize], + data[ptr - stride], + data[ptr - pixelSize - stride] + ); + } + } + else + { + throw new NotSupportedException(); + } + } + + private byte PaethPredictor(byte a, byte b, byte c) + { + var p = a + b - c; + var pa = Math.Abs(p - a); + var pb = Math.Abs(p - b); + var pc = Math.Abs(p - c); + if (pa <= pb && pa <= pc) + { + return (byte)a; + } + else if (pb <= pc) + { + return (byte)b; + } + else + { + return (byte)c; + } + } + + private byte[] PrepareClut(byte[] PLTE, byte[] tRNS, int count) + { + var clut = new byte[4 * count]; + for (int y = 0; y < count; y++) + { + if (3 * (y + 1) <= PLTE.Length) + { + clut[4 * y + 0] = PLTE[3 * y + 0]; + clut[4 * y + 1] = PLTE[3 * y + 1]; + clut[4 * y + 2] = PLTE[3 * y + 2]; + } + if (y + 1 <= tRNS.Length) + { + clut[4 * y + 3] = tRNS[y]; + } + } + return clut; + } + + private static int Turn(int val) + { + return (int)Turn((uint)val); + } + + private static uint Turn(uint val) + { + return 0 + | ((val << 24)) + | ((val << 8) & 0x00FF0000) + | ((val >> 8) & 0x0000FF00) + | ((val >> 24) & 0x000000FF) + ; + } + + public static bool IsValid(Stream stream) + { + stream.SetPosition(0); + return stream.ReadByte() == 0x89 && + stream.ReadByte() == 0x50 && + stream.ReadByte() == 0x4e && + stream.ReadByte() == 0x47 && + stream.ReadByte() == 0x0d && + stream.ReadByte() == 0x0a && + stream.ReadByte() == 0x1a && + stream.ReadByte() == 0x0a; + } + + public static PngImage Read(Stream stream) => new PngImage(stream); + + #region IImageRead + public Size Size { get; internal set; } + + public PixelFormat PixelFormat { get; internal set; } + + public byte[] GetData() => _data; + + public byte[] GetClut() => _clut; + #endregion } } diff --git a/OpenKh.Imaging/Tm2.cs b/OpenKh.Imaging/Tm2.cs index badd564dc..5417aecc4 100644 --- a/OpenKh.Imaging/Tm2.cs +++ b/OpenKh.Imaging/Tm2.cs @@ -1,597 +1,609 @@ -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Imaging -{ - public class Tm2 : IImageRead - { - private const uint MagicCode = 0x324D4954U; - private const int Version = 4; - private const int Format = 0; - private const int HeaderLength = 16; - - /// - /// Pixel Storage Mode, or PSM - /// Defines how pixel are arranged in each 32-bit word of local memory. - /// - public enum GsPSM - { - /// - /// RGBA32, uses 32-bit per pixel. - /// - GS_PSMCT32 = 0, - - /// - /// RGB24, uses 24-bit per pixel with the upper 8 bit unused. - /// - GS_PSMCT24 = 1, - - /// - /// RGBA16, pack two pixels in 32-bit in little endian order. - /// - GS_PSMCT16 = 2, - - /// - /// RGBA16, pack two pixels in 32-bit in little endian order. - /// - GS_PSMCT16S = 10, - - /// - /// 8-bit indexed, packing 4 pixels per 32-bit. - /// - GS_PSMT8 = 19, - - /// - /// 4-bit indexed, packing 8 pixels per 32-bit. - /// - GS_PSMT4 = 20, - - /// - /// 8-bit indexed, but the upper 24-bit are unused. - /// - GS_PSMT8H = 27, - - /// - /// 4-bit indexed, but the upper 24-bit are unused. - /// - GS_PSMT4HL = 36, - - /// - /// 4-bit indexed, where the bits 4-7 are evaluated and the rest discarded. - /// - GS_PSMT4HH = 44, - - /// - /// 32-bit Z buffer - /// - GS_PSMZ32 = 48, - - /// - /// 24-bit Z buffer with the upper 8-bit unused - /// - GS_PSMZ24 = 49, - - /// - /// 16-bit Z buffer, pack two pixels in 32-bit in little endian order. - /// - GS_PSMZ16 = 50, - - /// - /// 16-bit Z buffer, pack two pixels in 32-bit in little endian order. - /// - GS_PSMZ16S = 58, - }; - - public enum GsCPSM - { - GS_PSMCT32 = 0, // 32bit RGBA - GS_PSMCT24 = 1, - GS_PSMCT16 = 2, - GS_PSMCT16S = 10, - } - - private enum IMG_TYPE - { - IT_RGBA = 3, - IT_CLUT4 = 4, - IT_CLUT8 = 5, - }; - - private enum CLT_TYPE - { - CT_A1BGR5 = 1, - CT_XBGR8 = 2, - CT_ABGR8 = 3, - }; - - /// - /// register for image - /// 14 bit, texture buffer base pointer (address / 256) - /// 6 bit, texture buffer width (texels / 64) - /// 6 bit, pixel storage format (0 = 32bit RGBA) - /// 4 bit, width 2^n - /// 4 bit, height 2^n - /// 1 bit, 0 = RGB, 1 = RGBA - /// 2 bit, texture function (0=modulate, 1=decal, 2=hilight, 3=hilight2) - /// 14 bit, CLUT buffer base pointer (address / 256) - /// 4 bit, CLUT storage format - /// 1 bit, storage mode - /// 5 bit, offset - /// 3 bit, load control - /// - /// http://forum.xentax.com/viewtopic.php?f=16&t=4501&start=75 - /// - public class GsTex - { - public GsTex() - { - - } - - public GsTex(GsTex gsTex) - { - Data = gsTex.Data; - } - - public GsTex(GsTex gsTex, int width, int height) - { - Data = gsTex.Data; - TW = GetSizeRegister(width); - TH = GetSizeRegister(height); - } - - [Data] public long Data { get; set; } - - /// - /// Texture Base Pointer. - /// - public int TBP0 - { - get => GetBits(Data, 0, 14); - set => Data = SetBits(Data, 0, 14, value); - } - - /// - /// Texture Buffer Width. - /// - public int TBW - { - get => GetBits(Data, 14, 6); - set => Data = SetBits(Data, 14, 6, value); - } - - /// - /// Pixel Storage Mode. - /// Tells what is the format used to store the individual pixels. - /// - public GsPSM PSM - { - get => (GsPSM)GetBits(Data, 20, 6); - set => Data = SetBits(Data, 20, 6, (int)value); - } - - /// - /// Texture Width; power of 2. - /// - public int TW - { - get => GetBits(Data, 26, 4); - set => Data = SetBits(Data, 26, 4, value); - } - - /// - /// Texture Height; power of 2 - /// - public int TH - { - get => GetBits(Data, 30, 4); - set => Data = SetBits(Data, 30, 4, value); - } - - public bool TCC - { - get => GetBit(Data, 34); - set => Data = SetBit(Data, 34, value); - - } - - /// - /// Texture Function - /// - public int TFX - { - get => GetBits(Data, 35, 2); - set => Data = SetBits(Data, 35, 2, value); - } - - /// - /// Clut Base Pointer - /// - public int CBP - { - get => GetBits(Data, 37, 14); - set => Data = SetBits(Data, 37, 14, value); - } - - /// - /// Clut Pixel Storage mode - /// - public GsCPSM CPSM - { - get => (GsCPSM)GetBits(Data, 51, 4); - set => Data = SetBits(Data, 51, 4, (int)value); - } - - - /// - /// Clut storage mode field - /// false: store CLUT using CSM1, which swizzled the data every 8 colours. - /// true: store CLUT using CSM2, which is linear but slower. - /// - public bool CSM - { - get => GetBit(Data, 55); - set => Data = SetBit(Data, 55, value); - } - - /// - /// Clut Entry Offset - /// - public int CSA - { - get => GetBits(Data, 56, 5); - set => Data = SetBits(Data, 56, 5, value); - } - - /// - /// Clut Buffer Load Control - /// - public int CLD - { - get => GetBits(Data, 61, 3); - set => Data = SetBits(Data, 61, 3, value); - } - } - - private class Header - { - [Data] public uint MagicCode { get; set; } - [Data] public byte Version { get; set; } - [Data] public byte Format { get; set; } - [Data] public short ImageCount { get; set; } - [Data] public long Zero { get; set; } - } - - private class Picture - { - [Data] public int TotalSize { get; set; } - [Data] public int ClutSize { get; set; } - [Data] public int ImageSize { get; set; } - [Data] public short HeaderSize { get; set; } - [Data] public short ClutColorCount { get; set; } - [Data] public byte PictureFormat { get; set; } - [Data] public byte MipMapCount { get; set; } - [Data] public byte ClutType { get; set; } - [Data] public byte ImageType { get; set; } - [Data] public short Width { get; set; } - [Data] public short Height { get; set; } - [Data] public GsTex GsTex0 { get; set; } - [Data] public GsTex GsTex1 { get; set; } - [Data] public int GsRegs { get; set; } - [Data] public int GsClut { get; set; } - }; - - private class MipMap - { - [Data] public int GsMiptbp1_1 { get; set; } - [Data] public int GsMiptbp1_2 { get; set; } - [Data] public int GsMiptbp2_1 { get; set; } - [Data] public int GsMiptbp2_2 { get; set; } - [Data(Count = 8)] public int[] Sizes { get; set; } - } - - private readonly byte _imageFormat; - private readonly byte _mipMapCount; - private readonly byte _imageType; - private readonly byte _clutType; - private readonly GsTex _gsTex0; - private readonly GsTex _gsTex1; - private readonly int _gsReg; - private readonly int _gsPal; - private readonly byte[] _imageData; - private readonly byte[] _clutData; - private readonly MipMap _mipmap; - private bool IsClutSwizzled => (_clutType & 0x80) == 0; - - public Size Size { get; } - public PixelFormat PixelFormat => GetPixelFormat(_imageType); - public PixelFormat ClutFormat => GetPixelFormat(_clutType & 7); - - private Tm2(Stream stream, Picture picture) - { - _imageFormat = picture.PictureFormat; - _mipMapCount = picture.MipMapCount; - _imageType = picture.ImageType; - _clutType = picture.ClutType; - _gsTex0 = picture.GsTex0; - _gsTex1 = picture.GsTex1; - _gsReg = picture.GsRegs; - _gsPal = picture.GsClut; - Size = new Size(picture.Width, picture.Height); - - if (picture.MipMapCount > 1) - { - _mipmap = BinaryMapping.ReadObject(stream); - throw new NotImplementedException("Mipmaps are not currently supported."); - } - - // picture.ClutSize is not valid for KH2 map radar. +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Imaging +{ + public class Tm2 : IImageRead + { + private const uint MagicCode = 0x324D4954U; + private const int Version = 4; + private const int Format = 0; + private const int HeaderLength = 16; + + /// + /// Pixel Storage Mode, or PSM + /// Defines how pixel are arranged in each 32-bit word of local memory. + /// + public enum GsPSM + { + /// + /// RGBA32, uses 32-bit per pixel. + /// + GS_PSMCT32 = 0, + + /// + /// RGB24, uses 24-bit per pixel with the upper 8 bit unused. + /// + GS_PSMCT24 = 1, + + /// + /// RGBA16, pack two pixels in 32-bit in little endian order. + /// + GS_PSMCT16 = 2, + + /// + /// RGBA16, pack two pixels in 32-bit in little endian order. + /// + GS_PSMCT16S = 10, + + /// + /// 8-bit indexed, packing 4 pixels per 32-bit. + /// + GS_PSMT8 = 19, + + /// + /// 4-bit indexed, packing 8 pixels per 32-bit. + /// + GS_PSMT4 = 20, + + /// + /// 8-bit indexed, but the upper 24-bit are unused. + /// + GS_PSMT8H = 27, + + /// + /// 4-bit indexed, but the upper 24-bit are unused. + /// + GS_PSMT4HL = 36, + + /// + /// 4-bit indexed, where the bits 4-7 are evaluated and the rest discarded. + /// + GS_PSMT4HH = 44, + + /// + /// 32-bit Z buffer + /// + GS_PSMZ32 = 48, + + /// + /// 24-bit Z buffer with the upper 8-bit unused + /// + GS_PSMZ24 = 49, + + /// + /// 16-bit Z buffer, pack two pixels in 32-bit in little endian order. + /// + GS_PSMZ16 = 50, + + /// + /// 16-bit Z buffer, pack two pixels in 32-bit in little endian order. + /// + GS_PSMZ16S = 58, + }; + + public enum GsCPSM + { + GS_PSMCT32 = 0, // 32bit RGBA + GS_PSMCT24 = 1, + GS_PSMCT16 = 2, + GS_PSMCT16S = 10, + } + + private enum IMG_TYPE + { + IT_RGBA = 3, + IT_CLUT4 = 4, + IT_CLUT8 = 5, + }; + + private enum CLT_TYPE + { + CT_A1BGR5 = 1, + CT_XBGR8 = 2, + CT_ABGR8 = 3, + }; + + /// + /// register for image + /// 14 bit, texture buffer base pointer (address / 256) + /// 6 bit, texture buffer width (texels / 64) + /// 6 bit, pixel storage format (0 = 32bit RGBA) + /// 4 bit, width 2^n + /// 4 bit, height 2^n + /// 1 bit, 0 = RGB, 1 = RGBA + /// 2 bit, texture function (0=modulate, 1=decal, 2=hilight, 3=hilight2) + /// 14 bit, CLUT buffer base pointer (address / 256) + /// 4 bit, CLUT storage format + /// 1 bit, storage mode + /// 5 bit, offset + /// 3 bit, load control + /// + /// http://forum.xentax.com/viewtopic.php?f=16&t=4501&start=75 + /// + public class GsTex + { + public GsTex() + { + + } + + public GsTex(GsTex gsTex) + { + Data = gsTex.Data; + } + + public GsTex(GsTex gsTex, int width, int height) + { + Data = gsTex.Data; + TW = GetSizeRegister(width); + TH = GetSizeRegister(height); + } + + [Data] public long Data { get; set; } + + /// + /// Texture Base Pointer. + /// + public int TBP0 + { + get => GetBits(Data, 0, 14); + set => Data = SetBits(Data, 0, 14, value); + } + + /// + /// Texture Buffer Width. + /// + public int TBW + { + get => GetBits(Data, 14, 6); + set => Data = SetBits(Data, 14, 6, value); + } + + /// + /// Pixel Storage Mode. + /// Tells what is the format used to store the individual pixels. + /// + public GsPSM PSM + { + get => (GsPSM)GetBits(Data, 20, 6); + set => Data = SetBits(Data, 20, 6, (int)value); + } + + /// + /// Texture Width; power of 2. + /// + public int TW + { + get => GetBits(Data, 26, 4); + set => Data = SetBits(Data, 26, 4, value); + } + + /// + /// Texture Height; power of 2 + /// + public int TH + { + get => GetBits(Data, 30, 4); + set => Data = SetBits(Data, 30, 4, value); + } + + public bool TCC + { + get => GetBit(Data, 34); + set => Data = SetBit(Data, 34, value); + + } + + /// + /// Texture Function + /// + public int TFX + { + get => GetBits(Data, 35, 2); + set => Data = SetBits(Data, 35, 2, value); + } + + /// + /// Clut Base Pointer + /// + public int CBP + { + get => GetBits(Data, 37, 14); + set => Data = SetBits(Data, 37, 14, value); + } + + /// + /// Clut Pixel Storage mode + /// + public GsCPSM CPSM + { + get => (GsCPSM)GetBits(Data, 51, 4); + set => Data = SetBits(Data, 51, 4, (int)value); + } + + + /// + /// Clut storage mode field + /// false: store CLUT using CSM1, which swizzled the data every 8 colours. + /// true: store CLUT using CSM2, which is linear but slower. + /// + public bool CSM + { + get => GetBit(Data, 55); + set => Data = SetBit(Data, 55, value); + } + + /// + /// Clut Entry Offset + /// + public int CSA + { + get => GetBits(Data, 56, 5); + set => Data = SetBits(Data, 56, 5, value); + } + + /// + /// Clut Buffer Load Control + /// + public int CLD + { + get => GetBits(Data, 61, 3); + set => Data = SetBits(Data, 61, 3, value); + } + } + + private class Header + { + [Data] public uint MagicCode { get; set; } + [Data] public byte Version { get; set; } + [Data] public byte Format { get; set; } + [Data] public short ImageCount { get; set; } + [Data] public long Zero { get; set; } + } + + private class Picture + { + [Data] public int TotalSize { get; set; } + [Data] public int ClutSize { get; set; } + [Data] public int ImageSize { get; set; } + [Data] public short HeaderSize { get; set; } + [Data] public short ClutColorCount { get; set; } + [Data] public byte PictureFormat { get; set; } + [Data] public byte MipMapCount { get; set; } + [Data] public byte ClutType { get; set; } + [Data] public byte ImageType { get; set; } + [Data] public short Width { get; set; } + [Data] public short Height { get; set; } + [Data] public GsTex GsTex0 { get; set; } + [Data] public GsTex GsTex1 { get; set; } + [Data] public int GsRegs { get; set; } + [Data] public int GsClut { get; set; } + }; + + private class MipMap + { + [Data] public int GsMiptbp1_1 { get; set; } + [Data] public int GsMiptbp1_2 { get; set; } + [Data] public int GsMiptbp2_1 { get; set; } + [Data] public int GsMiptbp2_2 { get; set; } + [Data(Count = 8)] public int[] Sizes { get; set; } + } + + private readonly byte _imageFormat; + private readonly byte _mipMapCount; + private readonly byte _imageType; + private readonly byte _clutType; + private readonly GsTex _gsTex0; + private readonly GsTex _gsTex1; + private readonly int _gsReg; + private readonly int _gsPal; + private readonly byte[] _imageData; + private readonly byte[] _clutData; + private readonly MipMap _mipmap; + private bool IsClutSwizzled => (_clutType & 0x80) == 0; + + public Size Size { get; } + public PixelFormat PixelFormat => GetPixelFormat(_imageType); + public PixelFormat ClutFormat => GetPixelFormat(_clutType & 7); + + private Tm2(Stream stream, Picture picture) + { + _imageFormat = picture.PictureFormat; + _mipMapCount = picture.MipMapCount; + _imageType = picture.ImageType; + _clutType = picture.ClutType; + _gsTex0 = picture.GsTex0; + _gsTex1 = picture.GsTex1; + _gsReg = picture.GsRegs; + _gsPal = picture.GsClut; + Size = new Size(picture.Width, picture.Height); + + if (picture.MipMapCount > 1) + { + _mipmap = BinaryMapping.ReadObject(stream); + throw new NotImplementedException("Mipmaps are not currently supported."); + } + + // picture.ClutSize is not valid for KH2 map radar. var clutDataSize = 4 * picture.ClutColorCount; - _imageData = stream.ReadBytes(picture.ImageSize); - _clutData = stream.ReadBytes(clutDataSize); - if (IsClutSwizzled) - _clutData = SortClut(_clutData, ClutFormat, picture.ClutColorCount); - - ImageDataHelpers.InvertRedBlueChannels(_imageData, Size, PixelFormat); - } - - private Tm2(byte[] buffer, byte[] clut, Picture picture, PixelFormat pixFormat) - { - _imageFormat = picture.PictureFormat; - _mipMapCount = picture.MipMapCount; - _imageType = 5; - _clutType = picture.ClutType; - _gsTex0 = picture.GsTex0; - _gsTex1 = picture.GsTex1; - _gsReg = picture.GsRegs; - _gsPal = picture.GsClut; - Size = new Size(picture.Width, picture.Height); - - if (picture.MipMapCount > 1) - { - _mipmap = new MipMap(); - throw new NotImplementedException("Mipmaps are not currently supported."); - } - - // picture.ClutSize is not valid for KH2 map radar. + _imageData = stream.ReadBytes(picture.ImageSize); + _clutData = stream.ReadBytes(clutDataSize); + if (IsClutSwizzled) + _clutData = SortClut(_clutData, ClutFormat, picture.ClutColorCount); + + ImageDataHelpers.InvertRedBlueChannels(_imageData, Size, PixelFormat); + } + + private Tm2(byte[] buffer, byte[] clut, Picture picture, PixelFormat pixFormat) + { + _imageFormat = picture.PictureFormat; + _mipMapCount = picture.MipMapCount; + _imageType = 5; + _clutType = picture.ClutType; + _gsTex0 = picture.GsTex0; + _gsTex1 = picture.GsTex1; + _gsReg = picture.GsRegs; + _gsPal = picture.GsClut; + Size = new Size(picture.Width, picture.Height); + + if (picture.MipMapCount > 1) + { + _mipmap = new MipMap(); + throw new NotImplementedException("Mipmaps are not currently supported."); + } + + // picture.ClutSize is not valid for KH2 map radar. var clutDataSize = 4 * picture.ClutColorCount; - _imageData = buffer; - _clutData = clut; - if (IsClutSwizzled) - _clutData = SortClut(_clutData, ClutFormat, picture.ClutColorCount); - - ImageDataHelpers.InvertRedBlueChannels(_imageData, Size, pixFormat); - } - - public static bool IsValid(Stream stream) => - stream.SetPosition(0).ReadInt32() == MagicCode && - stream.Length >= HeaderLength; - - public static Tm2 Create(byte[] buffer, short width, short height) - { - byte[] buff = buffer; - byte[] clut = new byte[1024]; - Array.Resize(ref buff, buff.Length - 1024); - Array.Copy(buffer, buffer.Length - 1024, clut, 0, 1024); - Picture pic = new Picture(); - pic.Width = width; - pic.Height = height; - pic.MipMapCount = 0; - return new Tm2(buff, clut, pic, PixelFormat.Indexed8); - } - - public static Tm2 Create(IImageRead image) - { - byte[] buff = image.GetData(); - byte[] clut = image.GetClut(); - Picture pic = new Picture(); - pic.Width = (short)image.Size.Width; - pic.Height = (short)image.Size.Height; - pic.GsTex0 = new GsTex(); - pic.GsTex1 = new GsTex(); - pic.ClutType = 3; - return new Tm2(buff, clut, pic, PixelFormat.Indexed8); - } - - // bRelative controls whether the TM2 file is read from the beginning of the file or the current stream position. - public static IEnumerable Read(Stream stream, bool bRelative = false) - { - if (!stream.CanRead || !stream.CanSeek) - throw new InvalidDataException($"Read or seek must be supported."); - - if (!bRelative) - stream.Seek(0, SeekOrigin.Begin); - - var header = BinaryMapping.ReadObject
(stream); - if (header.Format != 0) - { - if (bRelative) - { - stream.Position += 128; - } - else - { - stream.Position = 128; - } - } - - if (stream.Length < HeaderLength || header.MagicCode != MagicCode) - throw new InvalidDataException("Invalid header"); - - return Enumerable.Range(0, header.ImageCount) - .Select(x => new Tm2(stream, BinaryMapping.ReadObject(stream))) - .ToArray(); - } - - public static void Write(Stream stream, IEnumerable images) - { - if (!stream.CanWrite || !stream.CanSeek) - throw new InvalidDataException($"Write or seek must be supported."); - - var myImages = images.ToArray(); - BinaryMapping.WriteObject(stream, new Header - { - MagicCode = MagicCode, - Version = Version, - Format = Format, - ImageCount = (short)myImages.Length, - Zero = 0, - }); - - foreach (var image in myImages) - { - var colorCount = - image._clutData.Length > 0 ? - image._clutData.Length * 8 / GetBitsPerPixel(image._clutType) : 0; - - BinaryMapping.WriteObject(stream, new Picture - { - TotalSize = 0x30 + image._imageData.Length + image._clutData.Length, - ClutSize = image._clutData.Length, - ImageSize = image._imageData.Length, - HeaderSize = 0x30, - ClutColorCount = (short)colorCount, - PictureFormat = image._imageFormat, - MipMapCount = image._mipMapCount, - ClutType = image._clutType, - ImageType = image._imageType, - Width = (short)image.Size.Width, - Height = (short)image.Size.Height, - GsTex0 = new GsTex(image._gsTex0, image.Size.Width, image.Size.Height), - GsTex1 = new GsTex(image._gsTex1), - GsRegs = image._gsReg, - GsClut = image._gsPal, - }); - - var data = ImageDataHelpers.GetInvertedRedBlueChannels(image._imageData, image.Size, image.PixelFormat); - stream.Write(data, 0, image._imageData.Length); - - var clut = image.IsClutSwizzled ? SortClut(image._clutData, image.ClutFormat, colorCount) : image._clutData; - stream.Write(clut, 0, image._clutData.Length); - } - } - - public byte[] GetData() => _imageData; - public byte[] GetClut() => _clutData; - - private static int GetBitsPerPixel(int format) - { - switch (format) - { - case 0: return 0; - case 1: return 16; - case 2: return 24; - case 3: return 32; - case 4: return 4; - case 5: return 8; - default: - throw new ArgumentOutOfRangeException($"The format ID {format} is invalid or not supported."); - } - } - - private static int GetSizeRegister(int realSize) => (int)Math.Ceiling(Math.Log(realSize, 2)); - - private static int GetBits(long Data, int position, int size) - { - var mask = (1 << size) - 1; - return (int)((Data >> position) & mask); - } - - private static long SetBits(long Data, int position, int size, int value) - { - var mask = (1 << size) - 1U; - return Data & ~(mask << position) | ((value & mask) << position); - } - - private static bool GetBit(long Data, int position) => GetBits(Data, position, 1) != 0; - private static long SetBit(long Data, int position, bool value) => SetBits(Data, position, 1, value ? 1 : 0); - - private static PixelFormat GetPixelFormat(int format) - { - switch (format) - { - case 0: return PixelFormat.Undefined; - case 1: return PixelFormat.Rgba1555; - case 2: return PixelFormat.Rgb888; - case 3: return PixelFormat.Rgba8888; - case 4: return PixelFormat.Indexed4; - case 5: return PixelFormat.Indexed8; - default: - throw new ArgumentOutOfRangeException($"The format ID {format} is invalid or not supported."); - } - } - - private static byte[] SortClut(byte[] clut, PixelFormat format, int colorCount) - { - if (colorCount != 256) - return clut; - - var index = 0; - var dst = ToIntArray(clut); - switch (format) - { - case PixelFormat.Rgba1555: - for (int i = 0; i < 8; i++) - { - for (int j = 0; j < 4; j++) - { - int tmp = dst[index + 4 + j]; - dst[index + 4 + j] = dst[index + 8 + j]; - dst[index + 8 + j] = tmp; - } - index += 16; - } - break; - case PixelFormat.Rgba8888: - for (int i = 0; i < 8; i++) - { - for (int j = 0; j < 8; j++) - { - int tmp = dst[index + 8 + j]; - dst[index + 8 + j] = dst[index + 16 + j]; - dst[index + 16 + j] = tmp; - } - index += 32; - } - break; - } - - return ToByteArray(dst); - } - - private static int[] ToIntArray(byte[] a) - { - var b = new int[a.Length / 4]; - for (var i = 0; i < b.Length; i++) - { - b[i] = a[i * 4 + 0] | - (a[i * 4 + 1] << 8) | - (a[i * 4 + 2] << 16) | - (a[i * 4 + 3] << 24); - } - - return b; - } - - private static byte[] ToByteArray(int[] src) - { - var dst = new byte[src.Length * 4]; - for (var i = 0; i < src.Length; i++) - { - dst[i * 4 + 0] = (byte)(src[i] >> 0); - dst[i * 4 + 1] = (byte)(src[i] >> 8); - dst[i * 4 + 2] = (byte)(src[i] >> 16); - dst[i * 4 + 3] = (byte)(src[i] >> 24); - } - - return dst; - } - } -} + _imageData = buffer; + _clutData = clut; + if (IsClutSwizzled) + _clutData = SortClut(_clutData, ClutFormat, picture.ClutColorCount); + + ImageDataHelpers.InvertRedBlueChannels(_imageData, Size, pixFormat); + } + + public static bool IsValid(Stream stream) => + stream.SetPosition(0).ReadInt32() == MagicCode && + stream.Length >= HeaderLength; + + public static Tm2 Create(byte[] buffer, short width, short height) + { + byte[] buff = buffer; + byte[] clut = new byte[1024]; + Array.Resize(ref buff, buff.Length - 1024); + Array.Copy(buffer, buffer.Length - 1024, clut, 0, 1024); + Picture pic = new Picture(); + pic.Width = width; + pic.Height = height; + pic.MipMapCount = 0; + return new Tm2(buff, clut, pic, PixelFormat.Indexed8); + } + + public static Tm2 Create(IImageRead image) + { + byte[] buff = image.GetData(); + byte[] clut = image.GetClut(); + Picture pic = new Picture(); + pic.Width = (short)image.Size.Width; + pic.Height = (short)image.Size.Height; + pic.GsTex0 = new GsTex(); + pic.GsTex1 = new GsTex(); + pic.ClutType = 3; + return new Tm2(buff, clut, pic, PixelFormat.Indexed8); + } + + // bRelative controls whether the TM2 file is read from the beginning of the file or the current stream position. + public static IEnumerable Read(Stream stream, bool bRelative = false) + { + if (!stream.CanRead || !stream.CanSeek) + throw new InvalidDataException($"Read or seek must be supported."); + + if (!bRelative) + stream.Seek(0, SeekOrigin.Begin); + + var header = BinaryMapping.ReadObject
(stream); + if (header.Format != 0) + { + if (bRelative) + { + stream.Position += 128; + } + else + { + stream.Position = 128; + } + } + + if (stream.Length < HeaderLength || header.MagicCode != MagicCode) + throw new InvalidDataException("Invalid header"); + + return Enumerable.Range(0, header.ImageCount) + .Select(x => new Tm2(stream, BinaryMapping.ReadObject(stream))) + .ToArray(); + } + + public static void Write(Stream stream, IEnumerable images) + { + if (!stream.CanWrite || !stream.CanSeek) + throw new InvalidDataException($"Write or seek must be supported."); + + var myImages = images.ToArray(); + BinaryMapping.WriteObject(stream, new Header + { + MagicCode = MagicCode, + Version = Version, + Format = Format, + ImageCount = (short)myImages.Length, + Zero = 0, + }); + + foreach (var image in myImages) + { + var colorCount = + image._clutData.Length > 0 ? + image._clutData.Length * 8 / GetBitsPerPixel(image._clutType) : 0; + + BinaryMapping.WriteObject(stream, new Picture + { + TotalSize = 0x30 + image._imageData.Length + image._clutData.Length, + ClutSize = image._clutData.Length, + ImageSize = image._imageData.Length, + HeaderSize = 0x30, + ClutColorCount = (short)colorCount, + PictureFormat = image._imageFormat, + MipMapCount = image._mipMapCount, + ClutType = image._clutType, + ImageType = image._imageType, + Width = (short)image.Size.Width, + Height = (short)image.Size.Height, + GsTex0 = new GsTex(image._gsTex0, image.Size.Width, image.Size.Height), + GsTex1 = new GsTex(image._gsTex1), + GsRegs = image._gsReg, + GsClut = image._gsPal, + }); + + var data = ImageDataHelpers.GetInvertedRedBlueChannels(image._imageData, image.Size, image.PixelFormat); + stream.Write(data, 0, image._imageData.Length); + + var clut = image.IsClutSwizzled ? SortClut(image._clutData, image.ClutFormat, colorCount) : image._clutData; + stream.Write(clut, 0, image._clutData.Length); + } + } + + public byte[] GetData() => _imageData; + public byte[] GetClut() => _clutData; + + private static int GetBitsPerPixel(int format) + { + switch (format) + { + case 0: + return 0; + case 1: + return 16; + case 2: + return 24; + case 3: + return 32; + case 4: + return 4; + case 5: + return 8; + default: + throw new ArgumentOutOfRangeException($"The format ID {format} is invalid or not supported."); + } + } + + private static int GetSizeRegister(int realSize) => (int)Math.Ceiling(Math.Log(realSize, 2)); + + private static int GetBits(long Data, int position, int size) + { + var mask = (1 << size) - 1; + return (int)((Data >> position) & mask); + } + + private static long SetBits(long Data, int position, int size, int value) + { + var mask = (1 << size) - 1U; + return Data & ~(mask << position) | ((value & mask) << position); + } + + private static bool GetBit(long Data, int position) => GetBits(Data, position, 1) != 0; + private static long SetBit(long Data, int position, bool value) => SetBits(Data, position, 1, value ? 1 : 0); + + private static PixelFormat GetPixelFormat(int format) + { + switch (format) + { + case 0: + return PixelFormat.Undefined; + case 1: + return PixelFormat.Rgba1555; + case 2: + return PixelFormat.Rgb888; + case 3: + return PixelFormat.Rgba8888; + case 4: + return PixelFormat.Indexed4; + case 5: + return PixelFormat.Indexed8; + default: + throw new ArgumentOutOfRangeException($"The format ID {format} is invalid or not supported."); + } + } + + private static byte[] SortClut(byte[] clut, PixelFormat format, int colorCount) + { + if (colorCount != 256) + return clut; + + var index = 0; + var dst = ToIntArray(clut); + switch (format) + { + case PixelFormat.Rgba1555: + for (int i = 0; i < 8; i++) + { + for (int j = 0; j < 4; j++) + { + int tmp = dst[index + 4 + j]; + dst[index + 4 + j] = dst[index + 8 + j]; + dst[index + 8 + j] = tmp; + } + index += 16; + } + break; + case PixelFormat.Rgba8888: + for (int i = 0; i < 8; i++) + { + for (int j = 0; j < 8; j++) + { + int tmp = dst[index + 8 + j]; + dst[index + 8 + j] = dst[index + 16 + j]; + dst[index + 16 + j] = tmp; + } + index += 32; + } + break; + } + + return ToByteArray(dst); + } + + private static int[] ToIntArray(byte[] a) + { + var b = new int[a.Length / 4]; + for (var i = 0; i < b.Length; i++) + { + b[i] = a[i * 4 + 0] | + (a[i * 4 + 1] << 8) | + (a[i * 4 + 2] << 16) | + (a[i * 4 + 3] << 24); + } + + return b; + } + + private static byte[] ToByteArray(int[] src) + { + var dst = new byte[src.Length * 4]; + for (var i = 0; i < src.Length; i++) + { + dst[i * 4 + 0] = (byte)(src[i] >> 0); + dst[i * 4 + 1] = (byte)(src[i] >> 8); + dst[i * 4 + 2] = (byte)(src[i] >> 16); + dst[i * 4 + 3] = (byte)(src[i] >> 24); + } + + return dst; + } + } +} diff --git a/OpenKh.Kh1/Idx1.cs b/OpenKh.Kh1/Idx1.cs index c90cc2806..ebdf72e75 100644 --- a/OpenKh.Kh1/Idx1.cs +++ b/OpenKh.Kh1/Idx1.cs @@ -1,55 +1,55 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using OpenKh.Common; -using Xe.BinaryMapper; - -namespace OpenKh.Kh1 -{ - public record Idx1 - { - public const int EntryLength = 0x10; - public const int MaxItemCount = 0xE00; - public const int kingdomimg = 0x4d7000 / 0x800; - - [Data] public uint Hash { get; set; } - [Data] public uint CompressionFlag { get; set; } - [Data] public uint IsoBlock { get; set; } - [Data] public uint Length { get; set; } - - public static List Read(Stream stream) => Enumerable - .Range(0, MaxItemCount) - .Select(_ => BinaryMapping.ReadObject(stream)) - .Where(x => x.Hash != 0) - .ToList(); - - public static void Write(Stream stream, ICollection entries) - { - stream.MustWriteAndSeek(); - - if (entries.Count > MaxItemCount) - throw new ArgumentOutOfRangeException($"Can not insert more than {MaxItemCount} IDX1 items."); - - foreach (var entry in entries) - BinaryMapping.WriteObject(stream, entry); - - var remainingEntries = MaxItemCount - entries.Count; - stream.Position += remainingEntries * EntryLength; - if (stream.Length < stream.Position) - stream.SetLength(stream.Position); - } - - public static uint GetHash(string text) => - GetHash(Encoding.UTF8.GetBytes(text)); - public static uint GetHash(byte[] data) - { - var hash = 0U; - foreach (var ch in data) - hash = (2 * hash) ^ (uint)((ch << 16) % 69665); - - return hash; - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using OpenKh.Common; +using Xe.BinaryMapper; + +namespace OpenKh.Kh1 +{ + public record Idx1 + { + public const int EntryLength = 0x10; + public const int MaxItemCount = 0xE00; + public const int kingdomimg = 0x4d7000 / 0x800; + + [Data] public uint Hash { get; set; } + [Data] public uint CompressionFlag { get; set; } + [Data] public uint IsoBlock { get; set; } + [Data] public uint Length { get; set; } + + public static List Read(Stream stream) => Enumerable + .Range(0, MaxItemCount) + .Select(_ => BinaryMapping.ReadObject(stream)) + .Where(x => x.Hash != 0) + .ToList(); + + public static void Write(Stream stream, ICollection entries) + { + stream.MustWriteAndSeek(); + + if (entries.Count > MaxItemCount) + throw new ArgumentOutOfRangeException($"Can not insert more than {MaxItemCount} IDX1 items."); + + foreach (var entry in entries) + BinaryMapping.WriteObject(stream, entry); + + var remainingEntries = MaxItemCount - entries.Count; + stream.Position += remainingEntries * EntryLength; + if (stream.Length < stream.Position) + stream.SetLength(stream.Position); + } + + public static uint GetHash(string text) => + GetHash(Encoding.UTF8.GetBytes(text)); + public static uint GetHash(byte[] data) + { + var hash = 0U; + foreach (var ch in data) + hash = (2 * hash) ^ (uint)((ch << 16) % 69665); + + return hash; + } + } +} diff --git a/OpenKh.Kh1/Idx1Name.cs b/OpenKh.Kh1/Idx1Name.cs index d1f5b85a0..56b6e8a73 100644 --- a/OpenKh.Kh1/Idx1Name.cs +++ b/OpenKh.Kh1/Idx1Name.cs @@ -1,27 +1,27 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Kh1 -{ - public record Idx1Name - { - private static Dictionary _nameDictionary = File - .ReadAllLines(Path.Combine(AppContext.BaseDirectory, "resources/kh1idx.txt")) - .ToDictionary(name => Idx1.GetHash(name), name => name); - - public Idx1 Entry { get; set; } - public string Name { get; set; } - - public static IEnumerable Lookup(IEnumerable entries) => entries - .Select(entry => new Idx1Name - { - Entry = entry, - Name = Lookup(entry) - }); - - public static string Lookup(Idx1 entry) => - _nameDictionary.TryGetValue(entry.Hash, out var name) ? name : null; - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Kh1 +{ + public record Idx1Name + { + private static Dictionary _nameDictionary = File + .ReadAllLines(Path.Combine(AppContext.BaseDirectory, "resources/kh1idx.txt")) + .ToDictionary(name => Idx1.GetHash(name), name => name); + + public Idx1 Entry { get; set; } + public string Name { get; set; } + + public static IEnumerable Lookup(IEnumerable entries) => entries + .Select(entry => new Idx1Name + { + Entry = entry, + Name = Lookup(entry) + }); + + public static string Lookup(Idx1 entry) => + _nameDictionary.TryGetValue(entry.Hash, out var name) ? name : null; + } +} diff --git a/OpenKh.Kh1/Img1.cs b/OpenKh.Kh1/Img1.cs index 5ea857083..ad4406bd3 100644 --- a/OpenKh.Kh1/Img1.cs +++ b/OpenKh.Kh1/Img1.cs @@ -1,214 +1,214 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.IO; - -namespace OpenKh.Kh1 -{ - public class Img1 : IDisposable - { - public const int IsoBlockAlign = 0x800; - - private readonly Stream _stream; - private readonly int _firstBlock; - - public Dictionary Entries { get; } - - public Img1(Stream stream, IEnumerable idxEntries, int firstBlock) - { - _stream = stream; - _firstBlock = firstBlock; - Entries = Idx1Name.Lookup(idxEntries).ToDictionary(x => x.Name ?? $"@noname/{x.Entry.Hash:X08}", x => x.Entry); - } - - public void Dispose() => _stream.Dispose(); - - public bool FileExists(string fileName) => Entries.ContainsKey(fileName); - - public bool TryFileOpen(string fileName, out Stream stream) - { - if (Entries.TryGetValue(fileName, out var entry)) - { - stream = FileOpen(entry); - return true; - } - - stream = null; - return false; - } - - public bool FileOpen(string fileName, Action callback) - { - bool result; - if (result = Entries.TryGetValue(fileName, out var entry)) - callback(FileOpen(entry)); - - return result; - } - - public Stream FileOpen(string fileName) - { - if (Entries.TryGetValue(fileName, out var entry)) - return FileOpen(entry); - - throw new FileNotFoundException("File not found", fileName); - } - - public Stream FileOpen(Idx1 entry) - { - if (entry.CompressionFlag != 0) - { - var fileStream = new SubStream(_stream, (_firstBlock + entry.IsoBlock) * IsoBlockAlign, entry.Length); - return new MemoryStream(Decompress(fileStream)); - } - - return new SubStream(_stream, (_firstBlock + entry.IsoBlock) * IsoBlockAlign, entry.Length); - } - - public static byte[] Decompress(Stream src) - { - return Decompress(new BinaryReader(src).ReadBytes((int)src.Length)); - } - - public static byte[] Decompress(byte[] srcData) - { - var srcIndex = srcData.Length - 1; - - if (srcIndex == 0) - return Array.Empty(); - - var key = srcData[srcIndex--]; - var decSize = srcData[srcIndex--] | - (srcData[srcIndex--] << 8) | - (srcData[srcIndex--] << 16); - - int dstIndex = decSize - 1; - var dstData = new byte[decSize]; - while (dstIndex >= 0 && srcIndex >= 0) - { - var data = srcData[srcIndex--]; - if (data == key && srcIndex >= 0) - { - var copyIndex = srcData[srcIndex--]; - if (copyIndex > 0 && srcIndex >= 0) - { - var copyLength = srcData[srcIndex--]; - for (int i = 0; i < copyLength + 3 && dstIndex >= 0; i++) - { - if (dstIndex + copyIndex + 1 < dstData.Length) - dstData[dstIndex--] = dstData[dstIndex + copyIndex + 1]; - else - dstData[dstIndex--] = 0; - } - } - else - { - dstData[dstIndex--] = data; - } - - } - else - { - dstData[dstIndex--] = data; - } - } - - return dstData; - } - - public static byte[] Compress(byte[] srcData) - { - const int MaxWindowSize = 0x102; - const int MaxSlidingIndex = 0xff; - - var decompressedLength = srcData.Length; - var key = GetLeastUsedByte(srcData); - var buffer = new List(decompressedLength); - - buffer.Add(key); - buffer.Add((byte)(decompressedLength >> 0)); - buffer.Add((byte)(decompressedLength >> 8)); - buffer.Add((byte)(decompressedLength >> 16)); - - int sourceIndex = decompressedLength - 1; - - while (sourceIndex >= 0) - { - var ch = srcData[sourceIndex]; - if (ch == key) - { - buffer.Add(key); - buffer.Add(0); - sourceIndex--; - continue; - } - - var windowSizeCandidate = 0; - var slidingIndexCandidate = -1; - var maxWindowSize = Math.Min(sourceIndex, MaxWindowSize); - for (var slidingIndex = MaxSlidingIndex; slidingIndex > 0; slidingIndex--) - { - if (slidingIndex + sourceIndex >= decompressedLength) - continue; - - int windowSize; - for (windowSize = 0; windowSize < maxWindowSize; windowSize++) - { - var startWindow = sourceIndex + slidingIndex - windowSize; - if (srcData[startWindow] != srcData[sourceIndex - windowSize]) - break; - } - - if (windowSize > windowSizeCandidate) - { - windowSizeCandidate = windowSize; - slidingIndexCandidate = slidingIndex; - } - } - - if (windowSizeCandidate > 3) - { - buffer.Add(key); - buffer.Add((byte)slidingIndexCandidate); - buffer.Add((byte)(windowSizeCandidate - 3)); - sourceIndex -= windowSizeCandidate; - } - else - { - buffer.Add(ch); - sourceIndex--; - } - } - - var compressedLength = buffer.Count; - var cmp = new byte[compressedLength]; - for (var i = 0; i < compressedLength; i++) - { - cmp[i] = buffer[compressedLength - i - 1]; - } - - return cmp; - } - - private static byte GetLeastUsedByte(byte[] data) - { - var dictionary = new int[0x100]; - foreach (var ch in data) - dictionary[ch]++; - - var elementFound = int.MaxValue; - var indexFound = 1; // the least used byte is never zero - for (var i = 0; i < 0x100; i++) - { - if (dictionary[i] < elementFound) - { - elementFound = dictionary[i]; - indexFound = i; - } - } - - return (byte)indexFound; - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.IO; + +namespace OpenKh.Kh1 +{ + public class Img1 : IDisposable + { + public const int IsoBlockAlign = 0x800; + + private readonly Stream _stream; + private readonly int _firstBlock; + + public Dictionary Entries { get; } + + public Img1(Stream stream, IEnumerable idxEntries, int firstBlock) + { + _stream = stream; + _firstBlock = firstBlock; + Entries = Idx1Name.Lookup(idxEntries).ToDictionary(x => x.Name ?? $"@noname/{x.Entry.Hash:X08}", x => x.Entry); + } + + public void Dispose() => _stream.Dispose(); + + public bool FileExists(string fileName) => Entries.ContainsKey(fileName); + + public bool TryFileOpen(string fileName, out Stream stream) + { + if (Entries.TryGetValue(fileName, out var entry)) + { + stream = FileOpen(entry); + return true; + } + + stream = null; + return false; + } + + public bool FileOpen(string fileName, Action callback) + { + bool result; + if (result = Entries.TryGetValue(fileName, out var entry)) + callback(FileOpen(entry)); + + return result; + } + + public Stream FileOpen(string fileName) + { + if (Entries.TryGetValue(fileName, out var entry)) + return FileOpen(entry); + + throw new FileNotFoundException("File not found", fileName); + } + + public Stream FileOpen(Idx1 entry) + { + if (entry.CompressionFlag != 0) + { + var fileStream = new SubStream(_stream, (_firstBlock + entry.IsoBlock) * IsoBlockAlign, entry.Length); + return new MemoryStream(Decompress(fileStream)); + } + + return new SubStream(_stream, (_firstBlock + entry.IsoBlock) * IsoBlockAlign, entry.Length); + } + + public static byte[] Decompress(Stream src) + { + return Decompress(new BinaryReader(src).ReadBytes((int)src.Length)); + } + + public static byte[] Decompress(byte[] srcData) + { + var srcIndex = srcData.Length - 1; + + if (srcIndex == 0) + return Array.Empty(); + + var key = srcData[srcIndex--]; + var decSize = srcData[srcIndex--] | + (srcData[srcIndex--] << 8) | + (srcData[srcIndex--] << 16); + + int dstIndex = decSize - 1; + var dstData = new byte[decSize]; + while (dstIndex >= 0 && srcIndex >= 0) + { + var data = srcData[srcIndex--]; + if (data == key && srcIndex >= 0) + { + var copyIndex = srcData[srcIndex--]; + if (copyIndex > 0 && srcIndex >= 0) + { + var copyLength = srcData[srcIndex--]; + for (int i = 0; i < copyLength + 3 && dstIndex >= 0; i++) + { + if (dstIndex + copyIndex + 1 < dstData.Length) + dstData[dstIndex--] = dstData[dstIndex + copyIndex + 1]; + else + dstData[dstIndex--] = 0; + } + } + else + { + dstData[dstIndex--] = data; + } + + } + else + { + dstData[dstIndex--] = data; + } + } + + return dstData; + } + + public static byte[] Compress(byte[] srcData) + { + const int MaxWindowSize = 0x102; + const int MaxSlidingIndex = 0xff; + + var decompressedLength = srcData.Length; + var key = GetLeastUsedByte(srcData); + var buffer = new List(decompressedLength); + + buffer.Add(key); + buffer.Add((byte)(decompressedLength >> 0)); + buffer.Add((byte)(decompressedLength >> 8)); + buffer.Add((byte)(decompressedLength >> 16)); + + int sourceIndex = decompressedLength - 1; + + while (sourceIndex >= 0) + { + var ch = srcData[sourceIndex]; + if (ch == key) + { + buffer.Add(key); + buffer.Add(0); + sourceIndex--; + continue; + } + + var windowSizeCandidate = 0; + var slidingIndexCandidate = -1; + var maxWindowSize = Math.Min(sourceIndex, MaxWindowSize); + for (var slidingIndex = MaxSlidingIndex; slidingIndex > 0; slidingIndex--) + { + if (slidingIndex + sourceIndex >= decompressedLength) + continue; + + int windowSize; + for (windowSize = 0; windowSize < maxWindowSize; windowSize++) + { + var startWindow = sourceIndex + slidingIndex - windowSize; + if (srcData[startWindow] != srcData[sourceIndex - windowSize]) + break; + } + + if (windowSize > windowSizeCandidate) + { + windowSizeCandidate = windowSize; + slidingIndexCandidate = slidingIndex; + } + } + + if (windowSizeCandidate > 3) + { + buffer.Add(key); + buffer.Add((byte)slidingIndexCandidate); + buffer.Add((byte)(windowSizeCandidate - 3)); + sourceIndex -= windowSizeCandidate; + } + else + { + buffer.Add(ch); + sourceIndex--; + } + } + + var compressedLength = buffer.Count; + var cmp = new byte[compressedLength]; + for (var i = 0; i < compressedLength; i++) + { + cmp[i] = buffer[compressedLength - i - 1]; + } + + return cmp; + } + + private static byte GetLeastUsedByte(byte[] data) + { + var dictionary = new int[0x100]; + foreach (var ch in data) + dictionary[ch]++; + + var elementFound = int.MaxValue; + var indexFound = 1; // the least used byte is never zero + for (var i = 0; i < 0x100; i++) + { + if (dictionary[i] < elementFound) + { + elementFound = dictionary[i]; + indexFound = i; + } + } + + return (byte)indexFound; + } + } +} diff --git a/OpenKh.Kh1/KingdomArchive.cs b/OpenKh.Kh1/KingdomArchive.cs index add3a672f..ec3baef01 100644 --- a/OpenKh.Kh1/KingdomArchive.cs +++ b/OpenKh.Kh1/KingdomArchive.cs @@ -1,71 +1,71 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; - -namespace OpenKh.Kh1 -{ - public class KingdomArchive - { - private const int Alignment = 0x80; - - public static List Read(Stream stream) - { - var itemCount = stream.ReadInt32(); - var offsets = new int[itemCount + 1]; - for (var i = 0; i < offsets.Length; i++) - offsets[i] = stream.ReadInt32(); - - var items = new List(itemCount); - for (var i = 0; i < itemCount; i++) - { - stream.SetPosition(offsets[i]); - items.Add(stream.ReadBytes(offsets[i + 1] - offsets[i])); - } - - return items; - } - - public static void Write(Stream stream, ICollection entries) - { - stream.MustWriteAndSeek(); - stream.Write(entries.Count); - - var accumulator = (entries.Count + 2) * 4; - foreach (var entry in entries) - { - accumulator = Helpers.Align(accumulator, Alignment); - stream.Write(accumulator); - accumulator += entry.Length; - } - stream.Write(Helpers.Align(accumulator, Alignment)); - - foreach (var entry in entries) - { - stream.AlignPosition(Alignment); - stream.Write(entry); - } - } - - public static void Write(Stream stream, ICollection entries) - where TStream : Stream - { - stream.MustWriteAndSeek(); - stream.Write(entries.Count); - - var accumulator = (entries.Count + 2) * 4; - foreach (var entry in entries) - { - accumulator = Helpers.Align(accumulator, Alignment); - stream.Write(accumulator); - accumulator += (int)stream.Length; - } - stream.Write(Helpers.Align(accumulator, Alignment)); - - foreach (var entry in entries) - { - stream.AlignPosition(Alignment); - entry.FromBegin().CopyTo(stream); - } - } - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; + +namespace OpenKh.Kh1 +{ + public class KingdomArchive + { + private const int Alignment = 0x80; + + public static List Read(Stream stream) + { + var itemCount = stream.ReadInt32(); + var offsets = new int[itemCount + 1]; + for (var i = 0; i < offsets.Length; i++) + offsets[i] = stream.ReadInt32(); + + var items = new List(itemCount); + for (var i = 0; i < itemCount; i++) + { + stream.SetPosition(offsets[i]); + items.Add(stream.ReadBytes(offsets[i + 1] - offsets[i])); + } + + return items; + } + + public static void Write(Stream stream, ICollection entries) + { + stream.MustWriteAndSeek(); + stream.Write(entries.Count); + + var accumulator = (entries.Count + 2) * 4; + foreach (var entry in entries) + { + accumulator = Helpers.Align(accumulator, Alignment); + stream.Write(accumulator); + accumulator += entry.Length; + } + stream.Write(Helpers.Align(accumulator, Alignment)); + + foreach (var entry in entries) + { + stream.AlignPosition(Alignment); + stream.Write(entry); + } + } + + public static void Write(Stream stream, ICollection entries) + where TStream : Stream + { + stream.MustWriteAndSeek(); + stream.Write(entries.Count); + + var accumulator = (entries.Count + 2) * 4; + foreach (var entry in entries) + { + accumulator = Helpers.Align(accumulator, Alignment); + stream.Write(accumulator); + accumulator += (int)stream.Length; + } + stream.Write(Helpers.Align(accumulator, Alignment)); + + foreach (var entry in entries) + { + stream.AlignPosition(Alignment); + entry.FromBegin().CopyTo(stream); + } + } + } +} diff --git a/OpenKh.Kh2/Ard/AreaDataScript.cs b/OpenKh.Kh2/Ard/AreaDataScript.cs index b6db7a97d..f7aa98422 100644 --- a/OpenKh.Kh2/Ard/AreaDataScript.cs +++ b/OpenKh.Kh2/Ard/AreaDataScript.cs @@ -1,1185 +1,1185 @@ -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Text; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Ard -{ - public interface IAreaDataCommand - { - void Parse(int nRow, List tokens); - } - - public interface IAreaDataSetting - { - void Parse(int nRow, List tokens); - } - - public enum Party : int - { - NO_FRIEND, - DEFAULT, - W_FRIEND, - W_FRIEND_IN, - W_FRIEND_FIX, - W_FRIEND_ONLY, - DONALD_ONLY, - }; - - public class SpawnScriptParserException : Exception - { - public SpawnScriptParserException(int line, string message) : - base($"Line {line}: {message}") - { } - } - - public class SpawnScriptMissingProgramException : SpawnScriptParserException - { - public SpawnScriptMissingProgramException(int line) : - base(line, "Expected \"Program\" statement.") - { } - } - - public class SpawnScriptCommandNotRecognizedException : SpawnScriptParserException - { - public SpawnScriptCommandNotRecognizedException(int line, string command) : - base(line, $"The command \"{command}\" was not recognized.") - { } - } - - public class SpawnScriptNotANumberException : SpawnScriptParserException - { - public SpawnScriptNotANumberException(int line, string token) : - base(line, $"Expected an integer value, but got '{token}'.") - { } - } - - public class SpawnScriptShortException : SpawnScriptParserException - { - public SpawnScriptShortException(int line, int value) : - base(line, $"The value {value} is too big. Please chose a value between {0} and {short.MaxValue}.") - { } - } - - public class SpawnScriptStringTooLongException : SpawnScriptParserException - { - public SpawnScriptStringTooLongException(int line, string value, int maxLength) : - base(line, $"The value \"{value}\" is {value.Length} characters long, but the maximum allowed is {maxLength}.") - { } - } - - public class SpawnScriptInvalidEnumException : SpawnScriptParserException - { - public SpawnScriptInvalidEnumException(int line, string token, IEnumerable allowed) : - base(line, $"The token '{token}' is not recognized as only {string.Join(",", allowed.Select(x => $"'{x}'"))} are allowed.") - { } - } - - public class AreaDataScript - { - private static readonly string[] PartyValues = new string[] - { - "NO_FRIEND", - "DEFAULT", - "W_FRIEND", - "W_FRIEND_IN", - "W_FRIEND_FIX", - "W_FRIEND_ONLY", - "DONALD_ONLY", - }; - - private enum LexState - { - Init, - Code, - } - - private const short Terminator = -1; - private static readonly IBinaryMapping Mapping = - MappingConfiguration.DefaultConfiguration() - .ForType(ScriptStringReader, ScriptStringWriter) - .ForType>(ScriptMultipleStringReader, ScriptMultipleStringWriter) - .ForType(AreaSettingsReader, AreaSettingsWriter) - .ForType(SetInventoryReader, SetInventoryWriter) - .ForType(IfReader, IfWriter) - .Build(); - - private static readonly Dictionary _idType = new Dictionary() - { - [0x00] = typeof(Spawn), - [0x01] = typeof(MapVisibility), - [0x02] = typeof(RandomSpawn), - [0x03] = typeof(CasualSpawn), - [0x04] = typeof(Capacity), - [0x05] = typeof(AllocEnemy), - [0x06] = typeof(Unk06), - [0x07] = typeof(Unk07), - [0x09] = typeof(SpawnAlt), - [0x0A] = typeof(MapScript), - [0x0B] = typeof(BarrierFlag), - [0x0C] = typeof(AreaSettings), - [0x0E] = typeof(Unk0e), - [0x0F] = typeof(Party), - [0x10] = typeof(Bgm), - [0x11] = typeof(MsgWall), - [0x13] = typeof(Camera), - [0x14] = typeof(StatusFlag3), - [0x15] = typeof(Mission), - [0x16] = typeof(Layout), - [0x17] = typeof(StatusFlag5), - [0x18] = typeof(AllocEffect), - [0x19] = typeof(Progress), - [0x1A] = typeof(VisibilityOn), - [0x1B] = typeof(VisibilityOff), - [0x1C] = typeof(If), - [0x1D] = typeof(Unk1d), - [0x1E] = typeof(BattleLevel), - [0x1F] = typeof(Unk1f), - }; - - private static readonly Dictionary _idSetType = new Dictionary() - { - [0x00] = typeof(SetEvent), - [0x01] = typeof(SetJump), - [0x02] = typeof(SetProgressFlag), - [0x03] = typeof(SetMenuFlag), - [0x04] = typeof(SetMember), - [0x05] = typeof(SetUnk05), - [0x06] = typeof(SetInventory), - [0x07] = typeof(SetPartyMenu), - [0x08] = typeof(SetUnkFlag), - }; - - private static readonly Dictionary _typeId = - _idType.ToDictionary(x => x.Value, x => x.Key); - - private static readonly Dictionary _typeStr = - _idType.ToDictionary(x => x.Value.Name, x => x.Value); - - private static readonly Dictionary _typeSetId = - _idSetType.ToDictionary(x => x.Value, x => x.Key); - - private static readonly Dictionary _typeSetStr = - _idSetType.ToDictionary(x => x.Value.Name, x => x.Value); - - private class Header - { - [Data] public short Id { get; set; } - [Data] public short Length { get; set; } - } - - public class Spawn : IAreaDataCommand - { - [Data(Count = 4)] public string SpawnSet { get; set; } - - public void Parse(int nRow, List tokens) - { - SpawnSet = ParseAsString(nRow, GetToken(nRow, tokens, 1), 4); - } - - public override string ToString() => - $"{nameof(Spawn)} \"{SpawnSet}\""; - } - - public class MapVisibility : IAreaDataCommand - { - [Data] public int Flags1 { get; set; } - [Data] public int Flags2 { get; set; } - - public void Parse(int nRow, List tokens) - { - Flags1 = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - Flags2 = ParseAsInt(nRow, GetToken(nRow, tokens, 2)); - } - - public override string ToString() => - $"{nameof(MapVisibility)} 0x{Flags1:x08} 0x{Flags2:x08}"; - } - - public class RandomSpawn : IAreaDataCommand - { - [Data] public List SpawnSet { get; set; } - - public void Parse(int nRow, List tokens) - { - SpawnSet = Enumerable - .Range(1, tokens.Count - 1) - .Select(i => ParseAsString(nRow, GetToken(nRow, tokens, i), 4)) - .ToList(); - } - - public override string ToString() => - $"{nameof(RandomSpawn)} {string.Join(" ", SpawnSet.Select(x => $"\"{x}\""))}"; - } - - public class CasualSpawn : IAreaDataCommand - { - [Data] public int Unk00 { get; set; } - [Data(Count = 4)] public string SpawnSet { get; set; } - - public void Parse(int nRow, List tokens) - { - Unk00 = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - SpawnSet = ParseAsString(nRow, GetToken(nRow, tokens, 2), 4); - } - - public override string ToString() => - $"{nameof(CasualSpawn)} {Unk00} \"{SpawnSet}\""; - } - - public class Capacity : IAreaDataCommand - { - [Data] public float Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsFloat(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(Capacity)} {Value}"; - } - - public class AllocEnemy : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public override string ToString() => - $"{nameof(AllocEnemy)} {Value}"; - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - } - - public class Unk06 : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(Unk06)} {Value}"; - } - - public class Unk07 : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(Unk07)} {Value}"; - } - - public class SpawnAlt : IAreaDataCommand - { - [Data(Count = 4)] public string Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsString(nRow, GetToken(nRow, tokens, 1), 4); - } - - public override string ToString() => - $"{nameof(SpawnAlt)} \"{Value}\""; - } - - public class MapScript : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(MapScript)} {Value}"; - } - - public class BarrierFlag : IAreaDataCommand - { - [Data] public int Value1 { get; set; } - [Data] public int Value2 { get; set; } - - public void Parse(int nRow, List tokens) - { - Value1 = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - Value2 = ParseAsInt(nRow, GetToken(nRow, tokens, 2)); - } - - public override string ToString() => - $"{nameof(BarrierFlag)} 0x{Value1:x} 0x{Value2:x}"; - } - - public class AreaSettings : IAreaDataCommand - { - public short Unk00 { get; set; } - public short Unk02 { get; set; } - public List Settings { get; set; } - - public void Parse(int nRow, List tokens) - { - Unk00 = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); - Unk02 = (short)ParseAsInt(nRow, GetToken(nRow, tokens, 2)); - } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.AppendLine($"{nameof(AreaSettings)} {Unk00} {Unk02}"); - foreach (var item in Settings) - sb.AppendLine($"\t{item}"); - - return sb.ToString().Replace("\r", string.Empty); - } - } - - public class Unk0e : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(Unk0e)} {Value}"; - } - - public class Party : IAreaDataCommand - { - [Data] public Ard.Party Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = (Ard.Party)ParseAsEnum(nRow, GetToken(nRow, tokens, 1), PartyValues); - } - - public override string ToString() => - $"{nameof(Party)} {Value}"; - } - - public class Bgm : IAreaDataCommand - { - [Data] public short BgmField { get; set; } - [Data] public short BgmBattle { get; set; } - - public void Parse(int nRow, List tokens) - { - var token1 = GetToken(nRow, tokens, 1); - var token2 = GetToken(nRow, tokens, 2); - BgmField = token1 == "Default" ? (short)0 : ParseAsShort(nRow, token1); - BgmBattle = token2 == "Default" ? (short)0 : ParseAsShort(nRow, token2); - } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append($"{nameof(Bgm)} "); - sb.Append(BgmField == 0 ? "Default" : BgmField.ToString()); - sb.Append(" "); - sb.Append(BgmBattle == 0 ? "Default" : BgmBattle.ToString()); - - return sb.ToString(); - } - } - - public class MsgWall : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(MsgWall)} 0x{Value:x}"; - } - - public class Camera : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(Camera)} {Value}"; - } - - public class StatusFlag3 : IAreaDataCommand - { - public void Parse(int nRow, List tokens) { } - - public override string ToString() => nameof(StatusFlag3); - } - - public class Mission : IAreaDataCommand - { - [Data] public int Unk00 { get; set; } - [Data(Count = 32)] public string Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Unk00 = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - Value = ParseAsString(nRow, GetToken(nRow, tokens, 2), 32); - } - - public override string ToString() => - $"{nameof(Mission)} 0x{Unk00:X} \"{Value}\""; - } - - public class Layout : IAreaDataCommand - { - [Data(Count = 32)] public string Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsString(nRow, GetToken(nRow, tokens, 1), 32); - } - - public override string ToString() => - $"{nameof(Layout)} \"{Value}\""; - } - - public class StatusFlag5 : IAreaDataCommand - { - public void Parse(int nRow, List tokens) { } - - public override string ToString() => nameof(StatusFlag5); - } - - public class AllocEffect : IAreaDataCommand - { - [Data] public int Value1 { get; set; } - [Data] public int Value2 { get; set; } - - public void Parse(int nRow, List tokens) - { - Value1 = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - Value2 = ParseAsInt(nRow, GetToken(nRow, tokens, 2)); - } - - public override string ToString() => - $"{nameof(AllocEffect)} 0x{Value1:x} 0x{Value2:x}"; - } - - public class Progress : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(Progress)} 0x{Value:x}"; - } - - public class VisibilityOn : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(VisibilityOn)} {Value}"; - } - - public class VisibilityOff : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(VisibilityOff)} {Value}"; - } - - public class If : IAreaDataCommand - { - [Data] public int Value { get; set; } - public List Commands { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - throw new Exception($"Parsing an '{nameof(If)}' is not yet supported"); - } - - public override string ToString() => - $"{nameof(If)} Entrance {Value}{string.Join("\n\t", Commands)}\n"; - } - - public class Unk1d : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(Unk1d)} {Value}"; - } - - public class BattleLevel : IAreaDataCommand - { - [Data] public int Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(BattleLevel)} {Value}"; - } - - public class Unk1f : IAreaDataCommand - { - [Data(Count = 4)] public string Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsString(nRow, GetToken(nRow, tokens, 1), 4); - } - - public override string ToString() => - $"{nameof(Unk1f)} \"{Value}\""; - } - - public class SetEvent : IAreaDataSetting - { - [Data] public short Type { get; set; } - [Data(Count = 4)] public string Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Type = ParseAsShort(nRow, GetToken(nRow, tokens, 3)); - Value = ParseAsString(nRow, GetToken(nRow, tokens, 1), 4); - } - - public override string ToString() => - $"{nameof(SetEvent)} \"{Value}\" Type {Type}"; - } - - public class SetJump : IAreaDataSetting - { - [Data] public short Padding { get; set; } - [Data] public short Type { get; set; } - [Data] public short World { get; set; } - [Data] public short Area { get; set; } - [Data] public short Entrance { get; set; } - [Data] public short LocalSet { get; set; } - [Data] public short FadeType { get; set; } - - public void Parse(int nRow, List tokens) - { - for (var i = 1; i < tokens.Count; i++) - { - switch (tokens[i++]) - { - case nameof(Type): - Type = ParseAsShort(nRow, GetToken(nRow, tokens, i)); - break; - case nameof(World): - var worldId = GetToken(nRow, tokens, i); - for (var j = 0; j < Constants.WorldIds.Length; j++) - { - if (worldId.ToLower() == Constants.WorldIds[j]) - { - World = (short)j; - break; - } - } - break; - case nameof(Area): - Area = ParseAsShort(nRow, GetToken(nRow, tokens, i)); - break; - case nameof(Entrance): - Entrance = ParseAsShort(nRow, GetToken(nRow, tokens, i)); - break; - case nameof(LocalSet): - LocalSet = ParseAsShort(nRow, GetToken(nRow, tokens, i)); - break; - case nameof(FadeType): - FadeType = ParseAsShort(nRow, GetToken(nRow, tokens, i)); - break; - } - } - } - - public override string ToString() - { - var items = new List(); - items.Add(nameof(SetJump)); - items.Add(nameof(Type)); - items.Add(Type.ToString()); - items.Add(nameof(World)); - items.Add(Constants.WorldIds[World].ToUpper()); - items.Add(nameof(Area)); - items.Add(Area.ToString()); - items.Add(nameof(Entrance)); - items.Add(Entrance.ToString()); - items.Add(nameof(LocalSet)); - items.Add(LocalSet.ToString()); - items.Add(nameof(FadeType)); - items.Add(FadeType.ToString()); - - return string.Join(" ", items); - } - } - - public class SetProgressFlag : IAreaDataSetting - { - [Data] public short Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(SetProgressFlag)} 0x{Value:X}"; - } - - public class SetMenuFlag : IAreaDataSetting - { - [Data] public short Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(SetMenuFlag)} 0x{Value:X}"; - } - - public class SetMember : IAreaDataSetting - { - [Data] public short Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(SetMember)} {Value}"; - } - - public class SetUnk05 : IAreaDataSetting - { - [Data] public short Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(SetUnk05)} 0x{Value:X}"; - } - - public class SetInventory : IAreaDataSetting - { - public List Items { get; set; } - - public void Parse(int nRow, List tokens) - { - Items = new List(); - for (var i = 1; i < tokens.Count; i++) - Items.Add(ParseAsInt(nRow, GetToken(nRow, tokens, i))); - } - - public override string ToString() => - $"{nameof(SetInventory)} {string.Join(" ", Items)}"; - } - - public class SetPartyMenu : IAreaDataSetting - { - [Data] public short Value { get; set; } - - public void Parse(int nRow, List tokens) - { - Value = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); - } - - public override string ToString() => - $"{nameof(SetPartyMenu)} {Value}"; - } - - public class SetUnkFlag : IAreaDataSetting - { - public void Parse(int nRow, List tokens) { } - - public override string ToString() => - $"{nameof(SetUnkFlag)}"; - } - - public short ProgramId { get; set; } - public List Functions { get; set; } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.AppendLine($"Program 0x{ProgramId:X02}"); - sb.Append(string.Join("\n", Functions)); - - return sb.ToString().Replace("\r", string.Empty); - } - - public static bool IsValid(Stream stream) - { - if (stream.Length == 0) - return false; - - var isValid = stream.SetPosition(stream.Length - 4).ReadInt32() == 0x0000FFFF; - stream.SetPosition(0); - return isValid; - } - - public static List Read(Stream stream) => - ReadAll(stream).ToList(); - - public static IEnumerable Read(Stream stream, int programId) - { - while (true) - { - var header = BinaryMapping.ReadObject
(stream); - if (header.Id == Terminator && header.Length == 0) - return null; - - if (header.Id == programId) - return ParseScript(stream.ReadBytes(header.Length - 4)); - else - stream.Position += header.Length - 4; - } - } - - public static void Write(Stream stream, IEnumerable scripts) - { - foreach (var script in scripts) - { - using var dataStream = new MemoryStream(); - Write(dataStream, script.Functions); - - stream.Write(script.ProgramId); - stream.Write((short)(dataStream.Length + 4)); - dataStream.SetPosition(0).CopyTo(stream); - } - stream.Write(0x0000FFFF); - } - - public static string Decompile(IEnumerable scripts) => - string.Join("\n\n", scripts.Select(x => x.ToString())); - - public static IEnumerable Compile(string text) - { - const char Comment = '#'; - AreaDataScript newScript() => new AreaDataScript - { - Functions = new List() - }; - - var script = newScript(); - var state = LexState.Init; - var lines = text - .Replace("\n\r", "\n") - .Replace("\r\n", "\n") - .Replace("\r", "\n") - .Split('\n'); - - var row = 0; - while (row < lines.Length) - { - var line = lines[row++]; - var cleanLine = line.Split(Comment); - var tokens = Tokenize(row, cleanLine[0]).ToList(); - if (tokens.Count == 0) - continue; - - if (state == LexState.Init && tokens[0] != "Program") - throw new SpawnScriptMissingProgramException(row); - - switch (tokens[0]) - { - case "Program": - var programId = ParseAsShort(row, GetToken(row, tokens, 1)); - if (state == LexState.Code) - { - yield return script; - script = newScript(); - } - - state = LexState.Code; - script.ProgramId = programId; - break; - case "AreaSettings": - var function = new AreaSettings - { - Settings = new List() - }; - function.Parse(row, tokens); - script.Functions.Add(function); - - while (row < lines.Length && (lines[row].Length == 0 || lines[row][0] == '\t')) - { - line = lines[row++]; - cleanLine = line.Split(Comment); - tokens = Tokenize(row, cleanLine[0]).ToList(); - if (tokens.Count == 0) - continue; - - function.Settings.Add(ParseAreaSetting(row, tokens)); - } - break; - default: - script.Functions.Add(ParseCommand(row, tokens)); - break; - } - } - - yield return script; - } - - private static IEnumerable ReadAll(Stream stream) - { - while (true) - { - var header = BinaryMapping.ReadObject
(stream); - if (header.Id == Terminator && header.Length == 0) - yield break; - - var bytecode = stream.ReadBytes(header.Length - 4); - yield return new AreaDataScript() - { - ProgramId = header.Id, - Functions = ParseScript(bytecode).ToList() - }; - } - } - - private static IEnumerable ParseScript(byte[] bytecode) - { - for (int pc = 0; pc < bytecode.Length;) - { - var opcode = BitConverter.ToUInt16(bytecode, pc); - var parameterCount = BitConverter.ToUInt16(bytecode, pc + 2); - using var stream = new MemoryStream(bytecode, pc + 4, parameterCount * 4); - var instance = Activator.CreateInstance(_idType[opcode]); - yield return Mapping.ReadObject(stream, instance) as IAreaDataCommand; - - pc += 4 + parameterCount * 4; - } - } - - private static void Write(Stream stream, IEnumerable commands) - { - foreach (var command in commands) - { - using var commandStream = new MemoryStream(); - Mapping.WriteObject(commandStream, command); - var opcode = (short)_typeId[command.GetType()]; - var parameterCount = (short)(commandStream.Length / 4); - - stream.Write(opcode); - stream.Write(parameterCount); - commandStream.SetPosition(0).CopyTo(stream); - } - } - - private static object ScriptStringReader(MappingReadArgs args) - { - if (args.Count > 1) - { - var data = args.Reader.ReadBytes(args.Count); - int byteCount; - for (byteCount = 0; byteCount < data.Length; byteCount++) - if (data[byteCount] == 0) - break; - - return Encoding.UTF8.GetString(data, 0, byteCount); - } - else - { - var sb = new StringBuilder(); - while (true) - { - var ch = args.Reader.ReadByte(); - if (ch == 0 || ch < 0) - break; - - sb.Append((char)ch); - } - - return sb.ToString(); - } - } - - private static void ScriptStringWriter(MappingWriteArgs args) - { - byte[] data; - var value = (string)args.Item; - - if (args.Count == 4) - { - data = new byte[4]; - if (value.Length > 2) - { - data[0] = (byte)value[0]; - data[1] = (byte)value[1]; - data[2] = (byte)value[2]; - if (value.Length >= 4) - data[3] = (byte)value[3]; - } - else if (value.Length > 0) - { - data[0] = (byte)value[0]; - if (value.Length == 2) - data[1] = (byte)value[1]; - } - } - else - { - var strData = Encoding.ASCII.GetBytes(value); - var length = args.Count == 1 ? Helpers.Align(strData.Length + 1, 4) : args.Count; - data = new byte[length]; - Array.Copy(strData, data, strData.Length); - args.Writer.BaseStream.AlignPosition(4); - - } - - args.Writer.BaseStream.Write(data); - } - - private static object ScriptMultipleStringReader(MappingReadArgs args) - { - var list = new List(); - args.Count = 4; - while (args.Reader.BaseStream.Position + 3 < args.Reader.BaseStream.Length) - list.Add(ScriptStringReader(args) as string); - - return list; - } - - private static void ScriptMultipleStringWriter(MappingWriteArgs args) - { - var items = (List)args.Item; - foreach (var item in items) - { - args.Item = item; - args.Count = 4; - ScriptStringWriter(args); - } - } - - private static object AreaSettingsReader(MappingReadArgs args) - { - var reader = args.Reader; - var settings = new AreaSettings - { - Unk00 = reader.ReadInt16(), - Unk02 = reader.ReadInt16(), - Settings = new List() - }; - - while (reader.BaseStream.Position < args.Reader.BaseStream.Length) - { - var opcode = reader.ReadInt16(); - var instance = Activator.CreateInstance(_idSetType[opcode]); - instance = Mapping.ReadObject(reader.BaseStream, instance); - settings.Settings.Add(instance as IAreaDataSetting); - } - - return settings; - } - - private static void AreaSettingsWriter(MappingWriteArgs args) - { - var settings = args.Item as AreaSettings; - args.Writer.Write(settings.Unk00); - args.Writer.Write(settings.Unk02); - foreach (var setting in settings.Settings) - { - var opcode = (short)_typeSetId[setting.GetType()]; - args.Writer.Write(opcode); - Mapping.WriteObject(args.Writer.BaseStream, setting); - } - } - - private static object SetInventoryReader(MappingReadArgs args) - { - var count = args.Reader.ReadInt16(); - return new SetInventory - { - Items = Enumerable - .Range(0, count) - .Select(_ => args.Reader.ReadInt32()) - .ToList() - }; - } - - private static void SetInventoryWriter(MappingWriteArgs args) - { - var items = args.Item as SetInventory; - args.Writer.Write((short)items.Items.Count); - foreach (var item in items.Items) - args.Writer.Write(item); - } - - private static object IfReader(MappingReadArgs args) - { - var item = new If - { - Value = args.Reader.ReadInt32(), - Commands = ParseScript(args.Reader.BaseStream.ReadBytes()).ToList() - }; - - return item; - } - - private static void IfWriter(MappingWriteArgs args) - { - var item = args.Item as If; - args.Writer.Write(item.Value); - Write(args.Writer.BaseStream, item.Commands); - } - - private static IAreaDataCommand ParseCommand(int nRow, List tokens) - { - var commandName = tokens[0]; - if (!_typeStr.TryGetValue(commandName, out var type)) - throw new SpawnScriptCommandNotRecognizedException(nRow, commandName); - - var command = Activator.CreateInstance(type) as IAreaDataCommand; - command.Parse(nRow, tokens); - return command; - } - - private static IAreaDataSetting ParseAreaSetting(int nRow, List tokens) - { - var commandName = tokens[0]; - if (!_typeSetStr.TryGetValue(commandName, out var type)) - throw new SpawnScriptCommandNotRecognizedException(nRow, commandName); - - var setting = Activator.CreateInstance(type) as IAreaDataSetting; - setting.Parse(nRow, tokens); - return setting; - } - - private static IEnumerable Tokenize(int row, string line) - { - var sb = new StringBuilder(); - for (var i = 0; i < line.Length; i++) - { - var ch = line[i]; - if (char.IsWhiteSpace(ch)) - { - if (sb.Length > 0) - yield return sb.ToString(); - sb.Clear(); - continue; - } - else if (ch == '"') - { - sb.Append(ch); - do - { - i++; - if (i >= line.Length) - throw new SpawnScriptParserException(row, $"Missing '\"'."); - sb.Append(ch = line[i]); - } while (ch != '"'); - } - else - sb.Append(ch); - } - - if (sb.Length > 0) - yield return sb.ToString(); - } - - private static string GetToken(int row, List tokens, int tokenIndex) => - tokens[tokenIndex]; - - public static string ParseAsString(int row, string text, int maxLength) - { - if (text.Length < 2) - throw new SpawnScriptParserException(row, $"Expected a string but got '{text}'"); - if (text[0] != '"' || text[text.Length - 1] != '"') - throw new SpawnScriptParserException(row, $"Expected a string but got '{text}' with probably wrong double-quotes."); - - text = text.Substring(1, text.Length - 2); - if (text.Length > maxLength) - throw new SpawnScriptStringTooLongException(row, text, maxLength); - - return text; - } - - private static short ParseAsShort(int row, string text) - { - var value = ParseAsInt(row, text); - if (value < short.MinValue || value > short.MaxValue) - throw new SpawnScriptShortException(row, value); - return (short)value; - } - - private static int ParseAsInt(int row, string token) - { - var isHexadecimal = token.Length > 2 && - token[0] == '0' && token[1] == 'x'; - var nStyle = isHexadecimal ? NumberStyles.HexNumber : NumberStyles.Integer; - var strValue = isHexadecimal ? token.Substring(2) : token; - - if (!int.TryParse(strValue, nStyle, null, out var value)) - throw new SpawnScriptNotANumberException(row, token); - return value; - } - - private static float ParseAsFloat(int row, string token) - { - if (!float.TryParse(token, out var value)) - throw new SpawnScriptNotANumberException(row, token); - return value; - } - - private static int ParseAsEnum(int row, string token, string[] allowValues) - { - for (var i = 0; i < allowValues.Length; i++) - { - if (token == allowValues[i]) - return i; - } - - throw new SpawnScriptInvalidEnumException(row, token, allowValues); - } - } -} +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Ard +{ + public interface IAreaDataCommand + { + void Parse(int nRow, List tokens); + } + + public interface IAreaDataSetting + { + void Parse(int nRow, List tokens); + } + + public enum Party : int + { + NO_FRIEND, + DEFAULT, + W_FRIEND, + W_FRIEND_IN, + W_FRIEND_FIX, + W_FRIEND_ONLY, + DONALD_ONLY, + }; + + public class SpawnScriptParserException : Exception + { + public SpawnScriptParserException(int line, string message) : + base($"Line {line}: {message}") + { } + } + + public class SpawnScriptMissingProgramException : SpawnScriptParserException + { + public SpawnScriptMissingProgramException(int line) : + base(line, "Expected \"Program\" statement.") + { } + } + + public class SpawnScriptCommandNotRecognizedException : SpawnScriptParserException + { + public SpawnScriptCommandNotRecognizedException(int line, string command) : + base(line, $"The command \"{command}\" was not recognized.") + { } + } + + public class SpawnScriptNotANumberException : SpawnScriptParserException + { + public SpawnScriptNotANumberException(int line, string token) : + base(line, $"Expected an integer value, but got '{token}'.") + { } + } + + public class SpawnScriptShortException : SpawnScriptParserException + { + public SpawnScriptShortException(int line, int value) : + base(line, $"The value {value} is too big. Please chose a value between {0} and {short.MaxValue}.") + { } + } + + public class SpawnScriptStringTooLongException : SpawnScriptParserException + { + public SpawnScriptStringTooLongException(int line, string value, int maxLength) : + base(line, $"The value \"{value}\" is {value.Length} characters long, but the maximum allowed is {maxLength}.") + { } + } + + public class SpawnScriptInvalidEnumException : SpawnScriptParserException + { + public SpawnScriptInvalidEnumException(int line, string token, IEnumerable allowed) : + base(line, $"The token '{token}' is not recognized as only {string.Join(",", allowed.Select(x => $"'{x}'"))} are allowed.") + { } + } + + public class AreaDataScript + { + private static readonly string[] PartyValues = new string[] + { + "NO_FRIEND", + "DEFAULT", + "W_FRIEND", + "W_FRIEND_IN", + "W_FRIEND_FIX", + "W_FRIEND_ONLY", + "DONALD_ONLY", + }; + + private enum LexState + { + Init, + Code, + } + + private const short Terminator = -1; + private static readonly IBinaryMapping Mapping = + MappingConfiguration.DefaultConfiguration() + .ForType(ScriptStringReader, ScriptStringWriter) + .ForType>(ScriptMultipleStringReader, ScriptMultipleStringWriter) + .ForType(AreaSettingsReader, AreaSettingsWriter) + .ForType(SetInventoryReader, SetInventoryWriter) + .ForType(IfReader, IfWriter) + .Build(); + + private static readonly Dictionary _idType = new Dictionary() + { + [0x00] = typeof(Spawn), + [0x01] = typeof(MapVisibility), + [0x02] = typeof(RandomSpawn), + [0x03] = typeof(CasualSpawn), + [0x04] = typeof(Capacity), + [0x05] = typeof(AllocEnemy), + [0x06] = typeof(Unk06), + [0x07] = typeof(Unk07), + [0x09] = typeof(SpawnAlt), + [0x0A] = typeof(MapScript), + [0x0B] = typeof(BarrierFlag), + [0x0C] = typeof(AreaSettings), + [0x0E] = typeof(Unk0e), + [0x0F] = typeof(Party), + [0x10] = typeof(Bgm), + [0x11] = typeof(MsgWall), + [0x13] = typeof(Camera), + [0x14] = typeof(StatusFlag3), + [0x15] = typeof(Mission), + [0x16] = typeof(Layout), + [0x17] = typeof(StatusFlag5), + [0x18] = typeof(AllocEffect), + [0x19] = typeof(Progress), + [0x1A] = typeof(VisibilityOn), + [0x1B] = typeof(VisibilityOff), + [0x1C] = typeof(If), + [0x1D] = typeof(Unk1d), + [0x1E] = typeof(BattleLevel), + [0x1F] = typeof(Unk1f), + }; + + private static readonly Dictionary _idSetType = new Dictionary() + { + [0x00] = typeof(SetEvent), + [0x01] = typeof(SetJump), + [0x02] = typeof(SetProgressFlag), + [0x03] = typeof(SetMenuFlag), + [0x04] = typeof(SetMember), + [0x05] = typeof(SetUnk05), + [0x06] = typeof(SetInventory), + [0x07] = typeof(SetPartyMenu), + [0x08] = typeof(SetUnkFlag), + }; + + private static readonly Dictionary _typeId = + _idType.ToDictionary(x => x.Value, x => x.Key); + + private static readonly Dictionary _typeStr = + _idType.ToDictionary(x => x.Value.Name, x => x.Value); + + private static readonly Dictionary _typeSetId = + _idSetType.ToDictionary(x => x.Value, x => x.Key); + + private static readonly Dictionary _typeSetStr = + _idSetType.ToDictionary(x => x.Value.Name, x => x.Value); + + private class Header + { + [Data] public short Id { get; set; } + [Data] public short Length { get; set; } + } + + public class Spawn : IAreaDataCommand + { + [Data(Count = 4)] public string SpawnSet { get; set; } + + public void Parse(int nRow, List tokens) + { + SpawnSet = ParseAsString(nRow, GetToken(nRow, tokens, 1), 4); + } + + public override string ToString() => + $"{nameof(Spawn)} \"{SpawnSet}\""; + } + + public class MapVisibility : IAreaDataCommand + { + [Data] public int Flags1 { get; set; } + [Data] public int Flags2 { get; set; } + + public void Parse(int nRow, List tokens) + { + Flags1 = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + Flags2 = ParseAsInt(nRow, GetToken(nRow, tokens, 2)); + } + + public override string ToString() => + $"{nameof(MapVisibility)} 0x{Flags1:x08} 0x{Flags2:x08}"; + } + + public class RandomSpawn : IAreaDataCommand + { + [Data] public List SpawnSet { get; set; } + + public void Parse(int nRow, List tokens) + { + SpawnSet = Enumerable + .Range(1, tokens.Count - 1) + .Select(i => ParseAsString(nRow, GetToken(nRow, tokens, i), 4)) + .ToList(); + } + + public override string ToString() => + $"{nameof(RandomSpawn)} {string.Join(" ", SpawnSet.Select(x => $"\"{x}\""))}"; + } + + public class CasualSpawn : IAreaDataCommand + { + [Data] public int Unk00 { get; set; } + [Data(Count = 4)] public string SpawnSet { get; set; } + + public void Parse(int nRow, List tokens) + { + Unk00 = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + SpawnSet = ParseAsString(nRow, GetToken(nRow, tokens, 2), 4); + } + + public override string ToString() => + $"{nameof(CasualSpawn)} {Unk00} \"{SpawnSet}\""; + } + + public class Capacity : IAreaDataCommand + { + [Data] public float Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsFloat(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(Capacity)} {Value}"; + } + + public class AllocEnemy : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public override string ToString() => + $"{nameof(AllocEnemy)} {Value}"; + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + } + + public class Unk06 : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(Unk06)} {Value}"; + } + + public class Unk07 : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(Unk07)} {Value}"; + } + + public class SpawnAlt : IAreaDataCommand + { + [Data(Count = 4)] public string Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsString(nRow, GetToken(nRow, tokens, 1), 4); + } + + public override string ToString() => + $"{nameof(SpawnAlt)} \"{Value}\""; + } + + public class MapScript : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(MapScript)} {Value}"; + } + + public class BarrierFlag : IAreaDataCommand + { + [Data] public int Value1 { get; set; } + [Data] public int Value2 { get; set; } + + public void Parse(int nRow, List tokens) + { + Value1 = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + Value2 = ParseAsInt(nRow, GetToken(nRow, tokens, 2)); + } + + public override string ToString() => + $"{nameof(BarrierFlag)} 0x{Value1:x} 0x{Value2:x}"; + } + + public class AreaSettings : IAreaDataCommand + { + public short Unk00 { get; set; } + public short Unk02 { get; set; } + public List Settings { get; set; } + + public void Parse(int nRow, List tokens) + { + Unk00 = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); + Unk02 = (short)ParseAsInt(nRow, GetToken(nRow, tokens, 2)); + } + + public override string ToString() + { + var sb = new StringBuilder(); + sb.AppendLine($"{nameof(AreaSettings)} {Unk00} {Unk02}"); + foreach (var item in Settings) + sb.AppendLine($"\t{item}"); + + return sb.ToString().Replace("\r", string.Empty); + } + } + + public class Unk0e : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(Unk0e)} {Value}"; + } + + public class Party : IAreaDataCommand + { + [Data] public Ard.Party Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = (Ard.Party)ParseAsEnum(nRow, GetToken(nRow, tokens, 1), PartyValues); + } + + public override string ToString() => + $"{nameof(Party)} {Value}"; + } + + public class Bgm : IAreaDataCommand + { + [Data] public short BgmField { get; set; } + [Data] public short BgmBattle { get; set; } + + public void Parse(int nRow, List tokens) + { + var token1 = GetToken(nRow, tokens, 1); + var token2 = GetToken(nRow, tokens, 2); + BgmField = token1 == "Default" ? (short)0 : ParseAsShort(nRow, token1); + BgmBattle = token2 == "Default" ? (short)0 : ParseAsShort(nRow, token2); + } + + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append($"{nameof(Bgm)} "); + sb.Append(BgmField == 0 ? "Default" : BgmField.ToString()); + sb.Append(" "); + sb.Append(BgmBattle == 0 ? "Default" : BgmBattle.ToString()); + + return sb.ToString(); + } + } + + public class MsgWall : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(MsgWall)} 0x{Value:x}"; + } + + public class Camera : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(Camera)} {Value}"; + } + + public class StatusFlag3 : IAreaDataCommand + { + public void Parse(int nRow, List tokens) { } + + public override string ToString() => nameof(StatusFlag3); + } + + public class Mission : IAreaDataCommand + { + [Data] public int Unk00 { get; set; } + [Data(Count = 32)] public string Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Unk00 = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + Value = ParseAsString(nRow, GetToken(nRow, tokens, 2), 32); + } + + public override string ToString() => + $"{nameof(Mission)} 0x{Unk00:X} \"{Value}\""; + } + + public class Layout : IAreaDataCommand + { + [Data(Count = 32)] public string Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsString(nRow, GetToken(nRow, tokens, 1), 32); + } + + public override string ToString() => + $"{nameof(Layout)} \"{Value}\""; + } + + public class StatusFlag5 : IAreaDataCommand + { + public void Parse(int nRow, List tokens) { } + + public override string ToString() => nameof(StatusFlag5); + } + + public class AllocEffect : IAreaDataCommand + { + [Data] public int Value1 { get; set; } + [Data] public int Value2 { get; set; } + + public void Parse(int nRow, List tokens) + { + Value1 = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + Value2 = ParseAsInt(nRow, GetToken(nRow, tokens, 2)); + } + + public override string ToString() => + $"{nameof(AllocEffect)} 0x{Value1:x} 0x{Value2:x}"; + } + + public class Progress : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(Progress)} 0x{Value:x}"; + } + + public class VisibilityOn : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(VisibilityOn)} {Value}"; + } + + public class VisibilityOff : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(VisibilityOff)} {Value}"; + } + + public class If : IAreaDataCommand + { + [Data] public int Value { get; set; } + public List Commands { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + throw new Exception($"Parsing an '{nameof(If)}' is not yet supported"); + } + + public override string ToString() => + $"{nameof(If)} Entrance {Value}{string.Join("\n\t", Commands)}\n"; + } + + public class Unk1d : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(Unk1d)} {Value}"; + } + + public class BattleLevel : IAreaDataCommand + { + [Data] public int Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsInt(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(BattleLevel)} {Value}"; + } + + public class Unk1f : IAreaDataCommand + { + [Data(Count = 4)] public string Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsString(nRow, GetToken(nRow, tokens, 1), 4); + } + + public override string ToString() => + $"{nameof(Unk1f)} \"{Value}\""; + } + + public class SetEvent : IAreaDataSetting + { + [Data] public short Type { get; set; } + [Data(Count = 4)] public string Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Type = ParseAsShort(nRow, GetToken(nRow, tokens, 3)); + Value = ParseAsString(nRow, GetToken(nRow, tokens, 1), 4); + } + + public override string ToString() => + $"{nameof(SetEvent)} \"{Value}\" Type {Type}"; + } + + public class SetJump : IAreaDataSetting + { + [Data] public short Padding { get; set; } + [Data] public short Type { get; set; } + [Data] public short World { get; set; } + [Data] public short Area { get; set; } + [Data] public short Entrance { get; set; } + [Data] public short LocalSet { get; set; } + [Data] public short FadeType { get; set; } + + public void Parse(int nRow, List tokens) + { + for (var i = 1; i < tokens.Count; i++) + { + switch (tokens[i++]) + { + case nameof(Type): + Type = ParseAsShort(nRow, GetToken(nRow, tokens, i)); + break; + case nameof(World): + var worldId = GetToken(nRow, tokens, i); + for (var j = 0; j < Constants.WorldIds.Length; j++) + { + if (worldId.ToLower() == Constants.WorldIds[j]) + { + World = (short)j; + break; + } + } + break; + case nameof(Area): + Area = ParseAsShort(nRow, GetToken(nRow, tokens, i)); + break; + case nameof(Entrance): + Entrance = ParseAsShort(nRow, GetToken(nRow, tokens, i)); + break; + case nameof(LocalSet): + LocalSet = ParseAsShort(nRow, GetToken(nRow, tokens, i)); + break; + case nameof(FadeType): + FadeType = ParseAsShort(nRow, GetToken(nRow, tokens, i)); + break; + } + } + } + + public override string ToString() + { + var items = new List(); + items.Add(nameof(SetJump)); + items.Add(nameof(Type)); + items.Add(Type.ToString()); + items.Add(nameof(World)); + items.Add(Constants.WorldIds[World].ToUpper()); + items.Add(nameof(Area)); + items.Add(Area.ToString()); + items.Add(nameof(Entrance)); + items.Add(Entrance.ToString()); + items.Add(nameof(LocalSet)); + items.Add(LocalSet.ToString()); + items.Add(nameof(FadeType)); + items.Add(FadeType.ToString()); + + return string.Join(" ", items); + } + } + + public class SetProgressFlag : IAreaDataSetting + { + [Data] public short Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(SetProgressFlag)} 0x{Value:X}"; + } + + public class SetMenuFlag : IAreaDataSetting + { + [Data] public short Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(SetMenuFlag)} 0x{Value:X}"; + } + + public class SetMember : IAreaDataSetting + { + [Data] public short Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(SetMember)} {Value}"; + } + + public class SetUnk05 : IAreaDataSetting + { + [Data] public short Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(SetUnk05)} 0x{Value:X}"; + } + + public class SetInventory : IAreaDataSetting + { + public List Items { get; set; } + + public void Parse(int nRow, List tokens) + { + Items = new List(); + for (var i = 1; i < tokens.Count; i++) + Items.Add(ParseAsInt(nRow, GetToken(nRow, tokens, i))); + } + + public override string ToString() => + $"{nameof(SetInventory)} {string.Join(" ", Items)}"; + } + + public class SetPartyMenu : IAreaDataSetting + { + [Data] public short Value { get; set; } + + public void Parse(int nRow, List tokens) + { + Value = ParseAsShort(nRow, GetToken(nRow, tokens, 1)); + } + + public override string ToString() => + $"{nameof(SetPartyMenu)} {Value}"; + } + + public class SetUnkFlag : IAreaDataSetting + { + public void Parse(int nRow, List tokens) { } + + public override string ToString() => + $"{nameof(SetUnkFlag)}"; + } + + public short ProgramId { get; set; } + public List Functions { get; set; } + + public override string ToString() + { + var sb = new StringBuilder(); + sb.AppendLine($"Program 0x{ProgramId:X02}"); + sb.Append(string.Join("\n", Functions)); + + return sb.ToString().Replace("\r", string.Empty); + } + + public static bool IsValid(Stream stream) + { + if (stream.Length == 0) + return false; + + var isValid = stream.SetPosition(stream.Length - 4).ReadInt32() == 0x0000FFFF; + stream.SetPosition(0); + return isValid; + } + + public static List Read(Stream stream) => + ReadAll(stream).ToList(); + + public static IEnumerable Read(Stream stream, int programId) + { + while (true) + { + var header = BinaryMapping.ReadObject
(stream); + if (header.Id == Terminator && header.Length == 0) + return null; + + if (header.Id == programId) + return ParseScript(stream.ReadBytes(header.Length - 4)); + else + stream.Position += header.Length - 4; + } + } + + public static void Write(Stream stream, IEnumerable scripts) + { + foreach (var script in scripts) + { + using var dataStream = new MemoryStream(); + Write(dataStream, script.Functions); + + stream.Write(script.ProgramId); + stream.Write((short)(dataStream.Length + 4)); + dataStream.SetPosition(0).CopyTo(stream); + } + stream.Write(0x0000FFFF); + } + + public static string Decompile(IEnumerable scripts) => + string.Join("\n\n", scripts.Select(x => x.ToString())); + + public static IEnumerable Compile(string text) + { + const char Comment = '#'; + AreaDataScript newScript() => new AreaDataScript + { + Functions = new List() + }; + + var script = newScript(); + var state = LexState.Init; + var lines = text + .Replace("\n\r", "\n") + .Replace("\r\n", "\n") + .Replace("\r", "\n") + .Split('\n'); + + var row = 0; + while (row < lines.Length) + { + var line = lines[row++]; + var cleanLine = line.Split(Comment); + var tokens = Tokenize(row, cleanLine[0]).ToList(); + if (tokens.Count == 0) + continue; + + if (state == LexState.Init && tokens[0] != "Program") + throw new SpawnScriptMissingProgramException(row); + + switch (tokens[0]) + { + case "Program": + var programId = ParseAsShort(row, GetToken(row, tokens, 1)); + if (state == LexState.Code) + { + yield return script; + script = newScript(); + } + + state = LexState.Code; + script.ProgramId = programId; + break; + case "AreaSettings": + var function = new AreaSettings + { + Settings = new List() + }; + function.Parse(row, tokens); + script.Functions.Add(function); + + while (row < lines.Length && (lines[row].Length == 0 || lines[row][0] == '\t')) + { + line = lines[row++]; + cleanLine = line.Split(Comment); + tokens = Tokenize(row, cleanLine[0]).ToList(); + if (tokens.Count == 0) + continue; + + function.Settings.Add(ParseAreaSetting(row, tokens)); + } + break; + default: + script.Functions.Add(ParseCommand(row, tokens)); + break; + } + } + + yield return script; + } + + private static IEnumerable ReadAll(Stream stream) + { + while (true) + { + var header = BinaryMapping.ReadObject
(stream); + if (header.Id == Terminator && header.Length == 0) + yield break; + + var bytecode = stream.ReadBytes(header.Length - 4); + yield return new AreaDataScript() + { + ProgramId = header.Id, + Functions = ParseScript(bytecode).ToList() + }; + } + } + + private static IEnumerable ParseScript(byte[] bytecode) + { + for (int pc = 0; pc < bytecode.Length;) + { + var opcode = BitConverter.ToUInt16(bytecode, pc); + var parameterCount = BitConverter.ToUInt16(bytecode, pc + 2); + using var stream = new MemoryStream(bytecode, pc + 4, parameterCount * 4); + var instance = Activator.CreateInstance(_idType[opcode]); + yield return Mapping.ReadObject(stream, instance) as IAreaDataCommand; + + pc += 4 + parameterCount * 4; + } + } + + private static void Write(Stream stream, IEnumerable commands) + { + foreach (var command in commands) + { + using var commandStream = new MemoryStream(); + Mapping.WriteObject(commandStream, command); + var opcode = (short)_typeId[command.GetType()]; + var parameterCount = (short)(commandStream.Length / 4); + + stream.Write(opcode); + stream.Write(parameterCount); + commandStream.SetPosition(0).CopyTo(stream); + } + } + + private static object ScriptStringReader(MappingReadArgs args) + { + if (args.Count > 1) + { + var data = args.Reader.ReadBytes(args.Count); + int byteCount; + for (byteCount = 0; byteCount < data.Length; byteCount++) + if (data[byteCount] == 0) + break; + + return Encoding.UTF8.GetString(data, 0, byteCount); + } + else + { + var sb = new StringBuilder(); + while (true) + { + var ch = args.Reader.ReadByte(); + if (ch == 0 || ch < 0) + break; + + sb.Append((char)ch); + } + + return sb.ToString(); + } + } + + private static void ScriptStringWriter(MappingWriteArgs args) + { + byte[] data; + var value = (string)args.Item; + + if (args.Count == 4) + { + data = new byte[4]; + if (value.Length > 2) + { + data[0] = (byte)value[0]; + data[1] = (byte)value[1]; + data[2] = (byte)value[2]; + if (value.Length >= 4) + data[3] = (byte)value[3]; + } + else if (value.Length > 0) + { + data[0] = (byte)value[0]; + if (value.Length == 2) + data[1] = (byte)value[1]; + } + } + else + { + var strData = Encoding.ASCII.GetBytes(value); + var length = args.Count == 1 ? Helpers.Align(strData.Length + 1, 4) : args.Count; + data = new byte[length]; + Array.Copy(strData, data, strData.Length); + args.Writer.BaseStream.AlignPosition(4); + + } + + args.Writer.BaseStream.Write(data); + } + + private static object ScriptMultipleStringReader(MappingReadArgs args) + { + var list = new List(); + args.Count = 4; + while (args.Reader.BaseStream.Position + 3 < args.Reader.BaseStream.Length) + list.Add(ScriptStringReader(args) as string); + + return list; + } + + private static void ScriptMultipleStringWriter(MappingWriteArgs args) + { + var items = (List)args.Item; + foreach (var item in items) + { + args.Item = item; + args.Count = 4; + ScriptStringWriter(args); + } + } + + private static object AreaSettingsReader(MappingReadArgs args) + { + var reader = args.Reader; + var settings = new AreaSettings + { + Unk00 = reader.ReadInt16(), + Unk02 = reader.ReadInt16(), + Settings = new List() + }; + + while (reader.BaseStream.Position < args.Reader.BaseStream.Length) + { + var opcode = reader.ReadInt16(); + var instance = Activator.CreateInstance(_idSetType[opcode]); + instance = Mapping.ReadObject(reader.BaseStream, instance); + settings.Settings.Add(instance as IAreaDataSetting); + } + + return settings; + } + + private static void AreaSettingsWriter(MappingWriteArgs args) + { + var settings = args.Item as AreaSettings; + args.Writer.Write(settings.Unk00); + args.Writer.Write(settings.Unk02); + foreach (var setting in settings.Settings) + { + var opcode = (short)_typeSetId[setting.GetType()]; + args.Writer.Write(opcode); + Mapping.WriteObject(args.Writer.BaseStream, setting); + } + } + + private static object SetInventoryReader(MappingReadArgs args) + { + var count = args.Reader.ReadInt16(); + return new SetInventory + { + Items = Enumerable + .Range(0, count) + .Select(_ => args.Reader.ReadInt32()) + .ToList() + }; + } + + private static void SetInventoryWriter(MappingWriteArgs args) + { + var items = args.Item as SetInventory; + args.Writer.Write((short)items.Items.Count); + foreach (var item in items.Items) + args.Writer.Write(item); + } + + private static object IfReader(MappingReadArgs args) + { + var item = new If + { + Value = args.Reader.ReadInt32(), + Commands = ParseScript(args.Reader.BaseStream.ReadBytes()).ToList() + }; + + return item; + } + + private static void IfWriter(MappingWriteArgs args) + { + var item = args.Item as If; + args.Writer.Write(item.Value); + Write(args.Writer.BaseStream, item.Commands); + } + + private static IAreaDataCommand ParseCommand(int nRow, List tokens) + { + var commandName = tokens[0]; + if (!_typeStr.TryGetValue(commandName, out var type)) + throw new SpawnScriptCommandNotRecognizedException(nRow, commandName); + + var command = Activator.CreateInstance(type) as IAreaDataCommand; + command.Parse(nRow, tokens); + return command; + } + + private static IAreaDataSetting ParseAreaSetting(int nRow, List tokens) + { + var commandName = tokens[0]; + if (!_typeSetStr.TryGetValue(commandName, out var type)) + throw new SpawnScriptCommandNotRecognizedException(nRow, commandName); + + var setting = Activator.CreateInstance(type) as IAreaDataSetting; + setting.Parse(nRow, tokens); + return setting; + } + + private static IEnumerable Tokenize(int row, string line) + { + var sb = new StringBuilder(); + for (var i = 0; i < line.Length; i++) + { + var ch = line[i]; + if (char.IsWhiteSpace(ch)) + { + if (sb.Length > 0) + yield return sb.ToString(); + sb.Clear(); + continue; + } + else if (ch == '"') + { + sb.Append(ch); + do + { + i++; + if (i >= line.Length) + throw new SpawnScriptParserException(row, $"Missing '\"'."); + sb.Append(ch = line[i]); + } while (ch != '"'); + } + else + sb.Append(ch); + } + + if (sb.Length > 0) + yield return sb.ToString(); + } + + private static string GetToken(int row, List tokens, int tokenIndex) => + tokens[tokenIndex]; + + public static string ParseAsString(int row, string text, int maxLength) + { + if (text.Length < 2) + throw new SpawnScriptParserException(row, $"Expected a string but got '{text}'"); + if (text[0] != '"' || text[text.Length - 1] != '"') + throw new SpawnScriptParserException(row, $"Expected a string but got '{text}' with probably wrong double-quotes."); + + text = text.Substring(1, text.Length - 2); + if (text.Length > maxLength) + throw new SpawnScriptStringTooLongException(row, text, maxLength); + + return text; + } + + private static short ParseAsShort(int row, string text) + { + var value = ParseAsInt(row, text); + if (value < short.MinValue || value > short.MaxValue) + throw new SpawnScriptShortException(row, value); + return (short)value; + } + + private static int ParseAsInt(int row, string token) + { + var isHexadecimal = token.Length > 2 && + token[0] == '0' && token[1] == 'x'; + var nStyle = isHexadecimal ? NumberStyles.HexNumber : NumberStyles.Integer; + var strValue = isHexadecimal ? token.Substring(2) : token; + + if (!int.TryParse(strValue, nStyle, null, out var value)) + throw new SpawnScriptNotANumberException(row, token); + return value; + } + + private static float ParseAsFloat(int row, string token) + { + if (!float.TryParse(token, out var value)) + throw new SpawnScriptNotANumberException(row, token); + return value; + } + + private static int ParseAsEnum(int row, string token, string[] allowValues) + { + for (var i = 0; i < allowValues.Length; i++) + { + if (token == allowValues[i]) + return i; + } + + throw new SpawnScriptInvalidEnumException(row, token, allowValues); + } + } +} diff --git a/OpenKh.Kh2/Ard/Event.cs b/OpenKh.Kh2/Ard/Event.cs index 46429a320..27593f8a9 100644 --- a/OpenKh.Kh2/Ard/Event.cs +++ b/OpenKh.Kh2/Ard/Event.cs @@ -1,1052 +1,1052 @@ -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Ard -{ - public static class Event - { - private const short Terminator = 0; - private static readonly IBinaryMapping Mapping = - MappingConfiguration.DefaultConfiguration() - .ForType(CStringReader, CStringWriter) - .ForType(ReadVoices, WriteVoices) - .ForType(ReadSetCameraData, WriteSetCameraData) - .ForType(ReadLoadAssets, WriteLoadAssets) - .ForType(ReadUnk1E, WriteUnk1E) - .Build(); - - private static readonly Dictionary _idType = new Dictionary() - { - [0x00] = typeof(SetProject), - [0x01] = typeof(SetActor), - [0x02] = typeof(SeqActorPosition), - [0x03] = typeof(SetMap), - [0x06] = typeof(SeqCamera), - [0x08] = typeof(SetEndFrame), - [0x09] = typeof(SeqEffect), - [0x0A] = typeof(AttachEffect), - [0x0C] = typeof(Unk0C), - [0x0D] = typeof(Unk0D), - [0x0E] = typeof(Unk0E), - [0x0F] = typeof(SetupEvent), - [0x10] = typeof(EventStart), - [0x12] = typeof(SeqFade), - [0x13] = typeof(SetCameraData), - [0x14] = typeof(EntryUnk14), - [0x15] = typeof(SeqSubtitle), - [0x16] = typeof(EntryUnk16), - [0x17] = typeof(EntryUnk17), - [0x18] = typeof(EntryUnk18), - [0x19] = typeof(SeqTextureAnim), - [0x1A] = typeof(SeqActorLeave), - [0x1B] = typeof(SeqCrossFade), - [0x1D] = typeof(EntryUnk1D), - [0x1E] = typeof(Unk1E), - [0x1F] = typeof(Unk1F), - [0x20] = typeof(SeqGameSpeed), - [0x22] = typeof(EntryUnk22), - [0x23] = typeof(SeqVoices), - [0x24] = typeof(ReadAssets), - [0x25] = typeof(ReadMotion), - [0x26] = typeof(ReadAudio), - [0x27] = typeof(SetShake), - [0x29] = typeof(EntryUnk29), - [0x2A] = typeof(EntryUnk2A), - [0x2B] = typeof(SeqPlayAudio), - [0x2C] = typeof(SeqPlayAnimation), - [0x2D] = typeof(SeqDialog), - [0x2E] = typeof(SeqPlayBgm), - [0x2F] = typeof(ReadBgm), - [0x30] = typeof(SetBgm), - [0x36] = typeof(EntryUnk36), - [0x38] = typeof(ReadActor), - [0x39] = typeof(ReadEffect), - [0x3D] = typeof(SeqLayout), - [0x3E] = typeof(ReadLayout), - [0x3F] = typeof(StopEffect), - [0x42] = typeof(Unk42), - [0x44] = typeof(RunMovie), - [0x47] = typeof(EntryUnk47), - [0x4D] = typeof(SeqHideObject), - }; - - private static readonly Dictionary _typeId = - _idType.ToDictionary(x => x.Value, x => x.Key); - - private class SetCameraDataHeader - { - [Data] public short Index { get; set; } - [Data] public short Count { get; set; } - } - - public class CameraValueInternal - { - [Data] public uint FlagData { get; set; } - [Data] public float Value { get; set; } - [Data] public float TangentEaseIn { get; set; } - [Data] public float TangentEaseOut { get; set; } - } - - public interface IEventEntry - { - } - - public class SetProject : IEventEntry // unused - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - - // Always PS2_BIN_VER (2) - [Data] public byte Version { get; set; } - [Data] public byte ObjCameraType { get; set; } - - // Can't be greater than 32 bytes - [Data] public string Name { get; set; } - - public override string ToString() => - $"{nameof(SetProject)}: {Name}, Version {Version}, Camera type {ObjCameraType}, ({Unk00:X}, {Unk02:X})"; - } - - public class SetActor : IEventEntry // sub_22F528 - { - [Data] public short ObjectEntry { get; set; } - [Data] public short ActorId { get; set; } - [Data] public string Name { get; set; } - - public override string ToString() => - $"{nameof(SetActor)}: ObjEntry {ObjectEntry:X}, Name {Name}, ActorID {ActorId}"; - } - - public class SeqActorPosition : IEventEntry - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public float PositionX { get; set; } - [Data] public float PositionY { get; set; } - [Data] public float PositionZ { get; set; } - [Data] public float RotationX { get; set; } - [Data] public float RotationY { get; set; } - [Data] public float RotationZ { get; set; } - [Data] public float Unk1C { get; set; } - [Data] public short ActorId { get; set; } - [Data] public short Frame { get; set; } - - public override string ToString() => - $"{nameof(SeqActorPosition)}: Frame {Frame}, ActorID {ActorId}, Pos({PositionX}, {PositionY}, {PositionZ}) Rot({RotationX}, {RotationY}, {RotationZ}) Unk({Unk00}, {Unk02}, {Unk1C})"; - } - - public class SetMap : IEventEntry // unused - { - [Data] public short Place { get; set; } - [Data] public string World { get; set; } - - public override string ToString() => - $"{nameof(SetMap)}: {World}{Place:D02}"; - } - - public class SeqCamera : IEventEntry // ignored - { - [Data] public short CameraId { get; set; } - [Data] public short FrameStart { get; set; } - [Data] public short FrameEnd { get; set; } - [Data] public short Unk06 { get; set; } - - public override string ToString() => - $"{nameof(SeqCamera)}: CameraID {CameraId}, Frame start {FrameStart}, Frame end {FrameEnd}, {Unk06}"; - } - - public class SetEndFrame : IEventEntry // sub_22D3B8 - { - [Data] public short EndFrame { get; set; } // dword_35DE28 - [Data] public short Unused { get; set; } - - public override string ToString() => - $"{nameof(SetEndFrame)}: {EndFrame}"; - } - - public class SeqEffect : IEventEntry - { - [Data] public short FrameStart { get; set; } - [Data] public short FrameLoop { get; set; } - [Data] public short EffectId { get; set; } - [Data] public short PaxId { get; set; } - [Data] public short PaxEntryIndex { get; set; } - [Data] public short EndType { get; set; } - [Data] public short FadeFrame { get; set; } - - public override string ToString() => - $"{nameof(SeqEffect)}: Frame start {FrameStart}, Frame loop {FrameLoop}, Effect ID {EffectId}, PAX ID {PaxId}, PAX entry index {PaxEntryIndex}, End type {EndType}, Frame fade {FadeFrame}"; - } - - public class AttachEffect : IEventEntry - { - [Data] public short FrameStart { get; set; } - [Data] public short FrameEnd { get; set; } // maybe unused? - [Data] public short AttachEffectId { get; set; } - [Data] public short ActorId { get; set; } - [Data] public short BoneIndex { get; set; } - [Data] public short PaxEntryIndex { get; set; } - [Data] public short Type { get; set; } - - public override string ToString() => - $"{nameof(AttachEffect)}: Frame start {FrameStart}, Frame end {FrameEnd}, Attach effect ID {AttachEffectId}, ActorID {ActorId}, Bone index {BoneIndex}, PAX entry {PaxEntryIndex}, Type {Type}"; - } - - public class EventStart : IEventEntry // sub_22D3A8 - { - [Data] public short FadeIn { get; set; } // dword_35DE40 - [Data] public short Unused { get; set; } - - public override string ToString() => - $"{nameof(EventStart)}: Fade in for {FadeIn} frames"; - } - - public class SeqFade: IEventEntry - { - public enum FadeType : short - { - FromBlack, - ToBlack, - ToWhite, - FromBlackVariant, - ToBlackVariant, - FromWhite, - ToWhiteVariant, - FromWhiteVariant, - } - - [Data] public short FrameIndex { get; set; } - [Data] public short Duration { get; set; } - [Data] public FadeType Type { get; set; } - - public override string ToString() => - $"{nameof(SeqFade)}: Frame {FrameIndex}, Duration {Duration}, {Type}"; - } - - public class SetCameraData : IEventEntry - { - public class CameraKeys - { - public Motion.Interpolation Interpolation { get; set; } - public int KeyFrame { get; set; } - public float Value { get; set; } - public float TangentEaseIn { get; set; } - public float TangentEaseOut { get; set; } - - public override string ToString() => - $"Key frame {KeyFrame}, Value {Value}, {TangentEaseIn}, {TangentEaseOut}, Interpolation {Interpolation}"; - } - - public short CameraId { get; set; } - public List PositionY { get; set; } - public List PositionZ { get; set; } - public List LookAtX { get; set; } - public List LookAtY { get; set; } - public List LookAtZ { get; set; } - public List Roll { get; set; } - public List FieldOfView { get; set; } - public List PositionX { get; set; } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.AppendLine($"{nameof(SetCameraData)}: ID {CameraId}"); - sb.AppendLine($"\tPositionX: {ToString(PositionX)}"); - sb.AppendLine($"\tPositionY: {ToString(PositionY)}"); - sb.AppendLine($"\tPositionZ: {ToString(PositionZ)}"); - sb.AppendLine($"\tLookAtX: {ToString(LookAtX)}"); - sb.AppendLine($"\tLookAtY: {ToString(LookAtY)}"); - sb.AppendLine($"\tLookAtZ: {ToString(LookAtZ)}"); - sb.AppendLine($"\tRoll: {ToString(Roll)}"); - sb.AppendLine($"\tFOV: {ToString(FieldOfView)}"); - return sb.ToString(); - } - - private string ToString(IList values) - { - if (values.Count == 1) - return values[0].ToString(); - return string.Join("\n\t\t", values); - } - - } - - public class EntryUnk14 : IEventEntry - { - [Data] public short Unk00 { get; set; } - - public override string ToString() => - $"{nameof(EntryUnk14)}: {Unk00}"; - } - - public class SeqSubtitle : IEventEntry - { - [Data] public short FrameStart { get; set; } - [Data] public short Index { get; set; } - [Data] public short MessageId { get; set; } - [Data] public short HideFlag { get; set; } - - public override string ToString() => - $"{nameof(SeqSubtitle)}: Frame {FrameStart}, MsgId {MessageId}, Index {Index}, Hide {HideFlag != 0}"; - } - - public class EntryUnk16 : IEventEntry - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - - public override string ToString() => - $"{nameof(EntryUnk16)}: {Unk00} {Unk02}"; - } - - public class EntryUnk17 : IEventEntry - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public short Unk04 { get; set; } - [Data] public short Unk06 { get; set; } - [Data] public short Unk08 { get; set; } - [Data] public short Unk0A { get; set; } - [Data] public short Unk0C { get; set; } - [Data] public short Unk0E { get; set; } - - public override string ToString() => - $"{nameof(EntryUnk17)}: {Unk00}, {Unk02} {Unk04} {Unk06} {Unk08} {Unk0A} {Unk0C} {Unk0E}"; - } - - public class EntryUnk18 : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public short Unk04 { get; set; } - [Data] public short Unk06 { get; set; } - - public override string ToString() => - $"{nameof(EntryUnk18)}: Frame {Frame}, {Unk02} {Unk04} {Unk06}"; - } - - public class SeqTextureAnim : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public short Unk04 { get; set; } - [Data] public short Unk06 { get; set; } - - public override string ToString() => - $"{nameof(SeqTextureAnim)}: Frame {Frame}, {Unk02}, {Unk04}, {Unk06}"; - } - - public class SeqActorLeave : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short ActorId { get; set; } - - public override string ToString() => - $"{nameof(SeqActorLeave)}: {Frame} {ActorId}"; - } - - public class SeqCrossFade : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short Duration { get; set; } - - public override string ToString() => - $"{nameof(SeqCrossFade)}: {Frame}, {Duration}"; - } - - public class EntryUnk1D : IEventEntry - { - [Data] public short Channel { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public short Unk04 { get; set; } - [Data] public short Unk06 { get; set; } - [Data] public short Unk08 { get; set; } - [Data] public short Unk0a { get; set; } - [Data] public short Unk0c { get; set; } - [Data] public short Unk0e { get; set; } - [Data] public short Unk10 { get; set; } - [Data] public short Unk12 { get; set; } - [Data] public short Unk14 { get; set; } - [Data] public short Unk16 { get; set; } - [Data] public short Unk18 { get; set; } - [Data] public short Unk1a { get; set; } - [Data] public float Unk1c { get; set; } - [Data] public float Unk20 { get; set; } - [Data] public float Unk24 { get; set; } - - public override string ToString() => - $"{nameof(EntryUnk1D)}: Channel {Channel}, {Unk02} {Unk04} {Unk06} {Unk08} {Unk0a} {Unk0c} {Unk0e} {Unk10} {Unk12} {Unk14} {Unk16} {Unk18} {Unk1a} {Unk1c} {Unk20} {Unk24}"; - } - - public class Unk1E : IEventEntry - { - public class Entry - { - [Data] public float Unk00 { get; set; } - [Data] public float Unk04 { get; set; } - [Data] public float Unk08 { get; set; } - [Data] public float Unk0C { get; set; } - [Data] public float Unk10 { get; set; } - [Data] public float Unk14 { get; set; } - [Data] public float Unk18 { get; set; } - [Data] public float Unk1C { get; set; } - [Data] public float Unk20 { get; set; } - [Data] public float Unk24 { get; set; } - } - - public short Id { get; set; } - public List Entries { get; set; } - public short UnkG { get; set; } - public short UnkH { get; set; } - - public override string ToString() => - $"{nameof(Unk1E)}: Id {Id}"; - } - - public class Unk1F : IEventEntry - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public short Unk04 { get; set; } - [Data] public short Unk06 { get; set; } - - public override string ToString() => - $"{nameof(Unk1F)}: {Unk00}, {Unk02} {Unk04} {Unk06}"; - } - - public class SeqGameSpeed : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short Unused { get; set; } - [Data] public float Speed { get; set; } - - public override string ToString() => - $"{nameof(SeqGameSpeed)}: {Frame} {Speed}"; - } - - public class EntryUnk22 : IEventEntry - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - - public override string ToString() => - $"{nameof(EntryUnk22)}: {Unk00} {Unk02}"; - } - - public class SeqVoices : IEventEntry - { - public class Voice - { - public short FrameStart { get; set; } - public string Name { get; set; } - - public override string ToString() => - $"Frame {FrameStart}, {Name}"; - } - - public List Voices { get; set; } - - public override string ToString() => - $"{nameof(SeqVoices)}:\n\t{string.Join("\n\t", Voices)}"; - } - - public class Unk0C : IEventEntry - { - [Data] public short StartFrame { get; set; } - [Data] public short EndFrame { get; set; } - [Data] public short Unk04 { get; set; } - [Data] public short Unk08 { get; set; } - - public override string ToString() => - $"{nameof(Unk0C)}: Frame {StartFrame}, {Unk04}, {Unk08}"; - } - - public class Unk0D : IEventEntry - { - [Data] public short StartFrame { get; set; } - [Data] public short EndFrame { get; set; } - [Data(Count = 34)] public short[] Unk { get; set; } - - public override string ToString() => - $"{nameof(Unk0D)}: Frame {StartFrame}, ({string.Join(", ", Unk)})"; - } - - public class Unk0E : IEventEntry - { - [Data] public short StartFrame { get; set; } - [Data] public short EndFrame { get; set; } - [Data] public short Unk04 { get; set; } - [Data] public short Unk06 { get; set; } - [Data] public short Unk08 { get; set; } - - public override string ToString() => - $"{nameof(Unk0E)}: Frame {StartFrame}, {Unk04}, {Unk06}, {Unk08}"; - } - - public class SetupEvent : IEventEntry // sub_22d358 - { - public override string ToString() => - $"{nameof(SetupEvent)}"; - } - - public class ReadAssets : IEventEntry - { - public short FrameStart { get; set; } - public short FrameEnd { get; set; } - public short Unk06 { get; set; } - public List Set { get; set; } - - public override string ToString() => - $"{nameof(ReadAssets)}: {FrameStart} {FrameEnd} {Unk06}\n\t{string.Join("\n\t", Set)}"; - } - - public class EntryUnk29 : IEventEntry - { - [Data] public short StartFrame { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public short Unk04 { get; set; } - [Data] public short Unk06 { get; set; } - [Data] public float Unk08 { get; set; } - - public override string ToString() => - $"{nameof(EntryUnk29)}: {StartFrame} {Unk02} {Unk04} {Unk06} {Unk08}"; - } - - public class EntryUnk2A : IEventEntry // sub_232A48 - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public short Unk04 { get; set; } - - public override string ToString() => - $"{nameof(EntryUnk2A)}: {Unk00} {Unk02} {Unk04}"; - } - - public class SeqPlayAudio : IEventEntry - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public short Unk04 { get; set; } - [Data] public short Unk06 { get; set; } - [Data] public short FrameStart { get; set; } - [Data] public short Unk0A { get; set; } - - public override string ToString() => - $"{nameof(SeqPlayAudio)}: {Unk00}, {Unk02}, {Unk04}, {Unk06}, Frame {FrameStart}, {Unk0A}"; - } - - public class SeqPlayAnimation : IEventEntry - { - [Data] public short FrameStart { get; set; } - [Data] public short FrameEnd { get; set; } - [Data] public short Unk04 { get; set; } - [Data] public short Unk06 { get; set; } - [Data] public short Unk08 { get; set; } - [Data] public short ActorId { get; set; } - [Data] public short Unk0C { get; set; } - [Data] public string Path { get; set; } - - public override string ToString() => - $"{nameof(SeqPlayAnimation)}: Frame start {FrameStart}, Frame end {FrameEnd}, {Unk04}, {Unk06}, {Unk08}, ActorID {ActorId}, {Unk0C}, {Path}"; - } - - public class SeqDialog : IEventEntry - { - [Data] public short FrameIndex { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public short MessageId { get; set; } - [Data] public short Unk06 { get; set; } - [Data] public short Unk08 { get; set; } - - public override string ToString() => - $"{nameof(SeqDialog)}: Frame index {FrameIndex}, {Unk02}, MsgID {MessageId}, {Unk06}, {Unk08}"; - } - - public class SeqPlayBgm : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short BankIndex { get; set; } - [Data] public byte VolumeStartIndex { get; set; } - [Data] public byte VolumeEndIndex { get; set; } - [Data] public byte FadeType { get; set; } - [Data] public byte Unused { get; set; } - - public override string ToString() => - $"{nameof(SeqPlayBgm)}: Frame {Frame}, Bank {BankIndex}, Volume start {VolumeStartIndex}, Volume end {VolumeEndIndex}, Fade type {FadeType}"; - } - - public class ReadBgm : IEventEntry - { - [Data] public short Unk00 { get; set; } - [Data] public short BgmId { get; set; } - - public override string ToString() => - $"{nameof(ReadBgm)}: BGM ID {BgmId}, {Unk00}"; - } - - public class SetBgm : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short BankIndex { get; set; } - [Data] public short BgmId { get; set; } - - public override string ToString() => - $"{nameof(SetBgm)}: BGM ID {BgmId}, {Frame} {BankIndex}"; - } - - public class EntryUnk36 : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public float Unk04 { get; set; } - [Data] public float Unk08 { get; set; } - [Data] public float Unk0c { get; set; } - - public override string ToString() => - $"{nameof(EntryUnk36)}: Frame {Frame}, {Unk02}, {Unk04}, {Unk08}, {Unk0c}"; - } - - public class ReadActor : IEventEntry - { - [Data] public short ObjectId { get; set; } - [Data] public short ActorId { get; set; } - [Data] public string Name { get; set; } - - public override string ToString() => - $"{nameof(ReadActor)}: ObjectEntry {ObjectId:X04}, Name {Name}, ActorID {ActorId}"; - } - - public class ReadEffect : IEventEntry - { - [Data] public short Id { get; set; } - [Data] public string Name { get; set; } - - public override string ToString() => - $"{nameof(ReadEffect)}: Id {Id}, Name {Name}"; - } - - public class SeqLayout : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short LayoutIndex { get; set; } - [Data] public string LayoutName { get; set; } - - public override string ToString() => - $"{nameof(ReadEffect)}: Start frame {Frame}, Layout {LayoutName} Index {LayoutIndex}"; - } - - public class ReadLayout : IEventEntry - { - [Data] public string Name { get; set; } - - public override string ToString() => - $"{nameof(ReadLayout)}: {Name}"; - } - - public class ReadMotion : IEventEntry - { - [Data] public short ObjectId { get; set; } - [Data] public short ActorId { get; set; } - [Data] public short UnknownIndex { get; set; } - [Data] public string Name { get; set; } - - public override string ToString() => - $"{nameof(ReadMotion)}: ObjectEntry {ObjectId:X04}, ActorID {ActorId}, Unk? {UnknownIndex}, Path {Name}"; - } - - public class ReadAudio : IEventEntry - { - [Data] public string Name { get; set; } - - public override string ToString() => $"{nameof(ReadAudio)} {Name}"; - } - - public class SetShake : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short Type { get; set; } - [Data] public short Width { get; set; } - [Data] public short Height { get; set; } - [Data] public short Depth { get; set; } - [Data] public short Duration { get; set; } - - public override string ToString() => - $"{nameof(SetShake)}: Frame {Frame}, Type {Type}, Width {Width}, Height {Height}, Depth {Depth}, Duration {Duration}"; - } - - public class StopEffect : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short Unused { get; set; } - - public override string ToString() => - $"{nameof(StopEffect)}: Frame {Frame}"; - } - - public class Unk42 : IEventEntry - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - - public override string ToString() => - $"{nameof(Unk42)}: {Unk00}, {Unk02}"; - } - - public class RunMovie : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public string Name { get; set; } - - public override string ToString() => - $"{nameof(RunMovie)}: Frame {Frame}, Name {Name}"; - } - - public class EntryUnk47 : IEventEntry - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public float StartPositionX { get; set; } - [Data] public float StartPositionY { get; set; } - [Data] public float StartPositionZ { get; set; } - [Data] public float EndPositionX { get; set; } - [Data] public float EndPositionY { get; set; } - [Data] public float EndPositionZ { get; set; } - [Data] public float RotationX { get; set; } - [Data] public float RotationY { get; set; } - [Data] public float RotationZ { get; set; } - [Data] public short Unk28 { get; set; } - [Data] public short Unk2A { get; set; } - - public override string ToString() => - $"{nameof(EntryUnk47)}: {Unk00}, {Unk02}, {Unk28}, {Unk2A}, StartPos({StartPositionX}, {StartPositionY}, {StartPositionZ}), EndPos({EndPositionX}, {EndPositionY}, {EndPositionZ}), Rot({RotationX}, {RotationY}, {RotationZ})"; - } - - public class SeqHideObject : IEventEntry - { - [Data] public short Frame { get; set; } - [Data] public short Type { get; set; } - - public override string ToString() => - $"{nameof(SeqHideObject)}: Frame {Frame}, Type {Type}"; - } - - public static List Read(Stream stream) - { - var entries = new List(); - - int blockLength; - while (stream.Position + 3 < stream.Length) - { - blockLength = stream.ReadInt16(); - if (blockLength == Terminator) - break; - - var startPosition = stream.Position - 2; - var type = stream.ReadInt16(); - if (_idType.TryGetValue(type, out var entryType)) - entries.Add(Mapping.ReadObject(stream, (IEventEntry)Activator.CreateInstance(entryType))); - else - Console.Error.WriteLine($"No Event implementation for {type:X02}"); - - if (stream.Position != startPosition + blockLength) - stream.Position = stream.Position; - stream.Position = startPosition + blockLength; - } - - return entries; - } - - public static void Write(Stream stream, - IEnumerable eventSet) - { - foreach (var item in eventSet) - { - var startPosition = stream.Position; - stream.Position += 4; - Mapping.WriteObject(stream, item); - var nextPosition = stream.AlignPosition(2).Position; - - var id = _typeId[item.GetType()]; - var length = stream.Position - startPosition; - stream.Position = startPosition; - stream.Write((short)(length)); - stream.Write((short)id); - stream.Position = nextPosition; - } - - stream.Write(Terminator); - } - - public static string ToString(IEnumerable eventSet) => - string.Join("\n", eventSet); - - private static string ReadCStyleString(Stream stream) - { - var sb = new StringBuilder(); - while (stream.Position < stream.Length) - { - var ch = stream.ReadByte(); - if (ch == 0) - break; - - sb.Append((char)ch); - } - - return sb.ToString(); - } - - private static void WriteCStyleString(Stream stream, string str) - { - foreach (var ch in str) - stream.WriteByte((byte)ch); - stream.WriteByte(0); - } - - private static void CStringWriter(MappingWriteArgs args) => - WriteCStyleString(args.Writer.BaseStream, (string)args.Item); - - private static object CStringReader(MappingReadArgs args) => - ReadCStyleString(args.Reader.BaseStream); - - private static object ReadVoices(MappingReadArgs args) - { - var voiceCount = args.Reader.ReadInt32(); - var voices = new List(voiceCount); - for (var i = 0; i < voiceCount; i++) - { - var voice = new SeqVoices.Voice(); - var startPos = args.Reader.BaseStream.Position; - args.Reader.ReadInt32(); // It always supposed to be 0 - voice.FrameStart = args.Reader.ReadInt16(); - args.Reader.ReadByte(); - voice.Name = ReadCStyleString(args.Reader.BaseStream); - voices.Add(voice); - args.Reader.BaseStream.Position = startPos + 0x20; - } - - return new SeqVoices - { - Voices = voices - }; - } - - private static void WriteVoices(MappingWriteArgs args) - { - var item = (SeqVoices)args.Item; - args.Writer.Write(item.Voices.Count); - foreach (var voice in item.Voices) - { - var startPos = args.Writer.BaseStream.Position; - args.Writer.Write(0); - args.Writer.Write(voice.FrameStart); - args.Writer.Write((byte)0); - WriteCStyleString(args.Writer.BaseStream, voice.Name); - args.Writer.BaseStream.Position = startPos + 0x20; - } - - var endPosition = args.Writer.BaseStream.Position; - if (endPosition > args.Writer.BaseStream.Length) - args.Writer.BaseStream.SetLength(endPosition); - } - - private static object ReadSetCameraData(MappingReadArgs args) - { - List AssignValues(SetCameraDataHeader header, IList val) => - Enumerable.Range(0, header.Count).Select(i => val[header.Index + i]).ToList(); - - var cameraId = args.Reader.ReadInt16(); - var headers = Enumerable - .Range(0, 8) - .Select(x => BinaryMapping.ReadObject(args.Reader.BaseStream)) - .ToList(); - args.Reader.BaseStream.AlignPosition(4); - var valueCount = headers.Max(x => x.Index + x.Count); - var values = Enumerable - .Range(0, valueCount) - .Select(x => BinaryMapping.ReadObject(args.Reader.BaseStream)) - .Select(x => new SetCameraData.CameraKeys - { - Interpolation = (Motion.Interpolation)(x.FlagData >> 29), - KeyFrame = (int)((x.FlagData & 0x1FFFFFFF ^ 0x10000000) - 0x10000000), - Value = x.Value, - TangentEaseIn = x.TangentEaseIn, - TangentEaseOut = x.TangentEaseOut - }) - .ToList(); - - return new SetCameraData - { - CameraId = cameraId, - PositionX = AssignValues(headers[0], values), - PositionY = AssignValues(headers[1], values), - PositionZ = AssignValues(headers[2], values), - LookAtX = AssignValues(headers[3], values), - LookAtY = AssignValues(headers[4], values), - LookAtZ = AssignValues(headers[5], values), - Roll = AssignValues(headers[6], values), - FieldOfView = AssignValues(headers[7], values), - }; - } - - private static void WriteSetCameraData(MappingWriteArgs args) - { - void WriteHeader(Stream stream, - List values, - int sIndex) => - Mapping.WriteObject(stream, new SetCameraDataHeader - { - Index = (short)sIndex, - Count = (short)values.Count - }); - - void WriteData(Stream stream, List values) - { - foreach (var value in values.Select(x => new CameraValueInternal - { - FlagData = (uint)((((x.KeyFrame + 0x10000000) ^ 0x10000000) & 0x1FFFFFFF) | - ((int)x.Interpolation << 29)), - Value = x.Value, - TangentEaseIn = x.TangentEaseIn, - TangentEaseOut = x.TangentEaseOut - })) - Mapping.WriteObject(stream, value); - } - - - var item = args.Item as SetCameraData; - args.Writer.Write(item.CameraId); - - var channelCountList = new List(8) - { - item.PositionX.Count, - item.PositionY.Count, - item.PositionZ.Count, - item.LookAtX.Count, - item.LookAtY.Count, - item.LookAtZ.Count, - item.Roll.Count, - item.FieldOfView.Count, - }; - var indexList = new List(8); - var startIndex = 0; - foreach (var channelCount in channelCountList) - { - indexList.Add(startIndex); - startIndex += channelCount; - } - - WriteHeader(args.Writer.BaseStream, item.PositionX, indexList[0]); - WriteHeader(args.Writer.BaseStream, item.PositionY, indexList[1]); - WriteHeader(args.Writer.BaseStream, item.PositionZ, indexList[2]); - WriteHeader(args.Writer.BaseStream, item.LookAtX, indexList[3]); - WriteHeader(args.Writer.BaseStream, item.LookAtY, indexList[4]); - WriteHeader(args.Writer.BaseStream, item.LookAtZ, indexList[5]); - WriteHeader(args.Writer.BaseStream, item.Roll, indexList[6]); - WriteHeader(args.Writer.BaseStream, item.FieldOfView, indexList[7]); - - args.Writer.BaseStream.AlignPosition(4); - WriteData(args.Writer.BaseStream, item.PositionX); - WriteData(args.Writer.BaseStream, item.PositionY); - WriteData(args.Writer.BaseStream, item.PositionZ); - WriteData(args.Writer.BaseStream, item.LookAtX); - WriteData(args.Writer.BaseStream, item.LookAtY); - WriteData(args.Writer.BaseStream, item.LookAtZ); - WriteData(args.Writer.BaseStream, item.Roll); - WriteData(args.Writer.BaseStream, item.FieldOfView); - } - - private static object ReadLoadAssets(MappingReadArgs args) - { - var reader = args.Reader; - var itemCount = reader.ReadInt16(); - var unk02 = reader.ReadInt16(); - var unk04 = reader.ReadInt16(); - var unk06 = reader.ReadInt16(); - - var loadSet = new List(); - for (var i = 0; i < itemCount; i++) - { - var startPosition = reader.BaseStream.Position; - var typeId = reader.ReadInt16(); - var length = reader.ReadInt16(); - var entryType = _idType[typeId]; - loadSet.Add(Mapping.ReadObject(reader.BaseStream, - (IEventEntry)Activator.CreateInstance(entryType))); - reader.BaseStream.Position = startPosition + length; - } - - return new ReadAssets - { - FrameStart = unk02, - FrameEnd = unk04, - Unk06 = unk06, - Set = loadSet - }; - } - - private static void WriteLoadAssets(MappingWriteArgs args) - { - var item = args.Item as ReadAssets; - args.Writer.Write((short)item.Set.Count); - args.Writer.Write(item.FrameStart); - args.Writer.Write(item.FrameEnd); - args.Writer.Write(item.Unk06); - - var stream = args.Writer.BaseStream; - foreach (var loadItem in item.Set) - { - var startPosition = stream.Position; - stream.Position += 4; - Mapping.WriteObject(stream, loadItem); - var nextPosition = stream.AlignPosition(2).Position; - - var id = _typeId[loadItem.GetType()]; - var length = stream.Position - startPosition; - stream.Position = startPosition; - stream.Write((short)id); - stream.Write((short)length); - stream.Position = nextPosition; - } - } - - private static object ReadUnk1E(MappingReadArgs args) - { - var id = args.Reader.ReadInt16(); - var count = args.Reader.ReadInt16(); - var unk04 = args.Reader.ReadInt16(); - var unk06 = args.Reader.ReadInt16(); - var entries = Enumerable - .Range(0, count) - .Select(x => Mapping.ReadObject(args.Reader.BaseStream)) - .ToList(); - var unkG = args.Reader.ReadInt16(); - var unkH = args.Reader.ReadInt16(); - - return new Unk1E - { - Id = id, - UnkG = unkG, - UnkH = unkH, - Entries = entries - }; - } - - private static void WriteUnk1E(MappingWriteArgs args) - { - var item = args.Item as Unk1E; - args.Writer.Write(item.Id); - args.Writer.Write((short)item.Entries.Count); - args.Writer.Write((short)3); - args.Writer.Write((short)0); - foreach (var entry in item.Entries) - Mapping.WriteObject(args.Writer.BaseStream, entry); - args.Writer.Write(item.UnkG); - args.Writer.Write(item.UnkH); - } - } -} +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Ard +{ + public static class Event + { + private const short Terminator = 0; + private static readonly IBinaryMapping Mapping = + MappingConfiguration.DefaultConfiguration() + .ForType(CStringReader, CStringWriter) + .ForType(ReadVoices, WriteVoices) + .ForType(ReadSetCameraData, WriteSetCameraData) + .ForType(ReadLoadAssets, WriteLoadAssets) + .ForType(ReadUnk1E, WriteUnk1E) + .Build(); + + private static readonly Dictionary _idType = new Dictionary() + { + [0x00] = typeof(SetProject), + [0x01] = typeof(SetActor), + [0x02] = typeof(SeqActorPosition), + [0x03] = typeof(SetMap), + [0x06] = typeof(SeqCamera), + [0x08] = typeof(SetEndFrame), + [0x09] = typeof(SeqEffect), + [0x0A] = typeof(AttachEffect), + [0x0C] = typeof(Unk0C), + [0x0D] = typeof(Unk0D), + [0x0E] = typeof(Unk0E), + [0x0F] = typeof(SetupEvent), + [0x10] = typeof(EventStart), + [0x12] = typeof(SeqFade), + [0x13] = typeof(SetCameraData), + [0x14] = typeof(EntryUnk14), + [0x15] = typeof(SeqSubtitle), + [0x16] = typeof(EntryUnk16), + [0x17] = typeof(EntryUnk17), + [0x18] = typeof(EntryUnk18), + [0x19] = typeof(SeqTextureAnim), + [0x1A] = typeof(SeqActorLeave), + [0x1B] = typeof(SeqCrossFade), + [0x1D] = typeof(EntryUnk1D), + [0x1E] = typeof(Unk1E), + [0x1F] = typeof(Unk1F), + [0x20] = typeof(SeqGameSpeed), + [0x22] = typeof(EntryUnk22), + [0x23] = typeof(SeqVoices), + [0x24] = typeof(ReadAssets), + [0x25] = typeof(ReadMotion), + [0x26] = typeof(ReadAudio), + [0x27] = typeof(SetShake), + [0x29] = typeof(EntryUnk29), + [0x2A] = typeof(EntryUnk2A), + [0x2B] = typeof(SeqPlayAudio), + [0x2C] = typeof(SeqPlayAnimation), + [0x2D] = typeof(SeqDialog), + [0x2E] = typeof(SeqPlayBgm), + [0x2F] = typeof(ReadBgm), + [0x30] = typeof(SetBgm), + [0x36] = typeof(EntryUnk36), + [0x38] = typeof(ReadActor), + [0x39] = typeof(ReadEffect), + [0x3D] = typeof(SeqLayout), + [0x3E] = typeof(ReadLayout), + [0x3F] = typeof(StopEffect), + [0x42] = typeof(Unk42), + [0x44] = typeof(RunMovie), + [0x47] = typeof(EntryUnk47), + [0x4D] = typeof(SeqHideObject), + }; + + private static readonly Dictionary _typeId = + _idType.ToDictionary(x => x.Value, x => x.Key); + + private class SetCameraDataHeader + { + [Data] public short Index { get; set; } + [Data] public short Count { get; set; } + } + + public class CameraValueInternal + { + [Data] public uint FlagData { get; set; } + [Data] public float Value { get; set; } + [Data] public float TangentEaseIn { get; set; } + [Data] public float TangentEaseOut { get; set; } + } + + public interface IEventEntry + { + } + + public class SetProject : IEventEntry // unused + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + + // Always PS2_BIN_VER (2) + [Data] public byte Version { get; set; } + [Data] public byte ObjCameraType { get; set; } + + // Can't be greater than 32 bytes + [Data] public string Name { get; set; } + + public override string ToString() => + $"{nameof(SetProject)}: {Name}, Version {Version}, Camera type {ObjCameraType}, ({Unk00:X}, {Unk02:X})"; + } + + public class SetActor : IEventEntry // sub_22F528 + { + [Data] public short ObjectEntry { get; set; } + [Data] public short ActorId { get; set; } + [Data] public string Name { get; set; } + + public override string ToString() => + $"{nameof(SetActor)}: ObjEntry {ObjectEntry:X}, Name {Name}, ActorID {ActorId}"; + } + + public class SeqActorPosition : IEventEntry + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public float PositionX { get; set; } + [Data] public float PositionY { get; set; } + [Data] public float PositionZ { get; set; } + [Data] public float RotationX { get; set; } + [Data] public float RotationY { get; set; } + [Data] public float RotationZ { get; set; } + [Data] public float Unk1C { get; set; } + [Data] public short ActorId { get; set; } + [Data] public short Frame { get; set; } + + public override string ToString() => + $"{nameof(SeqActorPosition)}: Frame {Frame}, ActorID {ActorId}, Pos({PositionX}, {PositionY}, {PositionZ}) Rot({RotationX}, {RotationY}, {RotationZ}) Unk({Unk00}, {Unk02}, {Unk1C})"; + } + + public class SetMap : IEventEntry // unused + { + [Data] public short Place { get; set; } + [Data] public string World { get; set; } + + public override string ToString() => + $"{nameof(SetMap)}: {World}{Place:D02}"; + } + + public class SeqCamera : IEventEntry // ignored + { + [Data] public short CameraId { get; set; } + [Data] public short FrameStart { get; set; } + [Data] public short FrameEnd { get; set; } + [Data] public short Unk06 { get; set; } + + public override string ToString() => + $"{nameof(SeqCamera)}: CameraID {CameraId}, Frame start {FrameStart}, Frame end {FrameEnd}, {Unk06}"; + } + + public class SetEndFrame : IEventEntry // sub_22D3B8 + { + [Data] public short EndFrame { get; set; } // dword_35DE28 + [Data] public short Unused { get; set; } + + public override string ToString() => + $"{nameof(SetEndFrame)}: {EndFrame}"; + } + + public class SeqEffect : IEventEntry + { + [Data] public short FrameStart { get; set; } + [Data] public short FrameLoop { get; set; } + [Data] public short EffectId { get; set; } + [Data] public short PaxId { get; set; } + [Data] public short PaxEntryIndex { get; set; } + [Data] public short EndType { get; set; } + [Data] public short FadeFrame { get; set; } + + public override string ToString() => + $"{nameof(SeqEffect)}: Frame start {FrameStart}, Frame loop {FrameLoop}, Effect ID {EffectId}, PAX ID {PaxId}, PAX entry index {PaxEntryIndex}, End type {EndType}, Frame fade {FadeFrame}"; + } + + public class AttachEffect : IEventEntry + { + [Data] public short FrameStart { get; set; } + [Data] public short FrameEnd { get; set; } // maybe unused? + [Data] public short AttachEffectId { get; set; } + [Data] public short ActorId { get; set; } + [Data] public short BoneIndex { get; set; } + [Data] public short PaxEntryIndex { get; set; } + [Data] public short Type { get; set; } + + public override string ToString() => + $"{nameof(AttachEffect)}: Frame start {FrameStart}, Frame end {FrameEnd}, Attach effect ID {AttachEffectId}, ActorID {ActorId}, Bone index {BoneIndex}, PAX entry {PaxEntryIndex}, Type {Type}"; + } + + public class EventStart : IEventEntry // sub_22D3A8 + { + [Data] public short FadeIn { get; set; } // dword_35DE40 + [Data] public short Unused { get; set; } + + public override string ToString() => + $"{nameof(EventStart)}: Fade in for {FadeIn} frames"; + } + + public class SeqFade : IEventEntry + { + public enum FadeType : short + { + FromBlack, + ToBlack, + ToWhite, + FromBlackVariant, + ToBlackVariant, + FromWhite, + ToWhiteVariant, + FromWhiteVariant, + } + + [Data] public short FrameIndex { get; set; } + [Data] public short Duration { get; set; } + [Data] public FadeType Type { get; set; } + + public override string ToString() => + $"{nameof(SeqFade)}: Frame {FrameIndex}, Duration {Duration}, {Type}"; + } + + public class SetCameraData : IEventEntry + { + public class CameraKeys + { + public Motion.Interpolation Interpolation { get; set; } + public int KeyFrame { get; set; } + public float Value { get; set; } + public float TangentEaseIn { get; set; } + public float TangentEaseOut { get; set; } + + public override string ToString() => + $"Key frame {KeyFrame}, Value {Value}, {TangentEaseIn}, {TangentEaseOut}, Interpolation {Interpolation}"; + } + + public short CameraId { get; set; } + public List PositionY { get; set; } + public List PositionZ { get; set; } + public List LookAtX { get; set; } + public List LookAtY { get; set; } + public List LookAtZ { get; set; } + public List Roll { get; set; } + public List FieldOfView { get; set; } + public List PositionX { get; set; } + + public override string ToString() + { + var sb = new StringBuilder(); + sb.AppendLine($"{nameof(SetCameraData)}: ID {CameraId}"); + sb.AppendLine($"\tPositionX: {ToString(PositionX)}"); + sb.AppendLine($"\tPositionY: {ToString(PositionY)}"); + sb.AppendLine($"\tPositionZ: {ToString(PositionZ)}"); + sb.AppendLine($"\tLookAtX: {ToString(LookAtX)}"); + sb.AppendLine($"\tLookAtY: {ToString(LookAtY)}"); + sb.AppendLine($"\tLookAtZ: {ToString(LookAtZ)}"); + sb.AppendLine($"\tRoll: {ToString(Roll)}"); + sb.AppendLine($"\tFOV: {ToString(FieldOfView)}"); + return sb.ToString(); + } + + private string ToString(IList values) + { + if (values.Count == 1) + return values[0].ToString(); + return string.Join("\n\t\t", values); + } + + } + + public class EntryUnk14 : IEventEntry + { + [Data] public short Unk00 { get; set; } + + public override string ToString() => + $"{nameof(EntryUnk14)}: {Unk00}"; + } + + public class SeqSubtitle : IEventEntry + { + [Data] public short FrameStart { get; set; } + [Data] public short Index { get; set; } + [Data] public short MessageId { get; set; } + [Data] public short HideFlag { get; set; } + + public override string ToString() => + $"{nameof(SeqSubtitle)}: Frame {FrameStart}, MsgId {MessageId}, Index {Index}, Hide {HideFlag != 0}"; + } + + public class EntryUnk16 : IEventEntry + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + + public override string ToString() => + $"{nameof(EntryUnk16)}: {Unk00} {Unk02}"; + } + + public class EntryUnk17 : IEventEntry + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public short Unk04 { get; set; } + [Data] public short Unk06 { get; set; } + [Data] public short Unk08 { get; set; } + [Data] public short Unk0A { get; set; } + [Data] public short Unk0C { get; set; } + [Data] public short Unk0E { get; set; } + + public override string ToString() => + $"{nameof(EntryUnk17)}: {Unk00}, {Unk02} {Unk04} {Unk06} {Unk08} {Unk0A} {Unk0C} {Unk0E}"; + } + + public class EntryUnk18 : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public short Unk04 { get; set; } + [Data] public short Unk06 { get; set; } + + public override string ToString() => + $"{nameof(EntryUnk18)}: Frame {Frame}, {Unk02} {Unk04} {Unk06}"; + } + + public class SeqTextureAnim : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public short Unk04 { get; set; } + [Data] public short Unk06 { get; set; } + + public override string ToString() => + $"{nameof(SeqTextureAnim)}: Frame {Frame}, {Unk02}, {Unk04}, {Unk06}"; + } + + public class SeqActorLeave : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short ActorId { get; set; } + + public override string ToString() => + $"{nameof(SeqActorLeave)}: {Frame} {ActorId}"; + } + + public class SeqCrossFade : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short Duration { get; set; } + + public override string ToString() => + $"{nameof(SeqCrossFade)}: {Frame}, {Duration}"; + } + + public class EntryUnk1D : IEventEntry + { + [Data] public short Channel { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public short Unk04 { get; set; } + [Data] public short Unk06 { get; set; } + [Data] public short Unk08 { get; set; } + [Data] public short Unk0a { get; set; } + [Data] public short Unk0c { get; set; } + [Data] public short Unk0e { get; set; } + [Data] public short Unk10 { get; set; } + [Data] public short Unk12 { get; set; } + [Data] public short Unk14 { get; set; } + [Data] public short Unk16 { get; set; } + [Data] public short Unk18 { get; set; } + [Data] public short Unk1a { get; set; } + [Data] public float Unk1c { get; set; } + [Data] public float Unk20 { get; set; } + [Data] public float Unk24 { get; set; } + + public override string ToString() => + $"{nameof(EntryUnk1D)}: Channel {Channel}, {Unk02} {Unk04} {Unk06} {Unk08} {Unk0a} {Unk0c} {Unk0e} {Unk10} {Unk12} {Unk14} {Unk16} {Unk18} {Unk1a} {Unk1c} {Unk20} {Unk24}"; + } + + public class Unk1E : IEventEntry + { + public class Entry + { + [Data] public float Unk00 { get; set; } + [Data] public float Unk04 { get; set; } + [Data] public float Unk08 { get; set; } + [Data] public float Unk0C { get; set; } + [Data] public float Unk10 { get; set; } + [Data] public float Unk14 { get; set; } + [Data] public float Unk18 { get; set; } + [Data] public float Unk1C { get; set; } + [Data] public float Unk20 { get; set; } + [Data] public float Unk24 { get; set; } + } + + public short Id { get; set; } + public List Entries { get; set; } + public short UnkG { get; set; } + public short UnkH { get; set; } + + public override string ToString() => + $"{nameof(Unk1E)}: Id {Id}"; + } + + public class Unk1F : IEventEntry + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public short Unk04 { get; set; } + [Data] public short Unk06 { get; set; } + + public override string ToString() => + $"{nameof(Unk1F)}: {Unk00}, {Unk02} {Unk04} {Unk06}"; + } + + public class SeqGameSpeed : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short Unused { get; set; } + [Data] public float Speed { get; set; } + + public override string ToString() => + $"{nameof(SeqGameSpeed)}: {Frame} {Speed}"; + } + + public class EntryUnk22 : IEventEntry + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + + public override string ToString() => + $"{nameof(EntryUnk22)}: {Unk00} {Unk02}"; + } + + public class SeqVoices : IEventEntry + { + public class Voice + { + public short FrameStart { get; set; } + public string Name { get; set; } + + public override string ToString() => + $"Frame {FrameStart}, {Name}"; + } + + public List Voices { get; set; } + + public override string ToString() => + $"{nameof(SeqVoices)}:\n\t{string.Join("\n\t", Voices)}"; + } + + public class Unk0C : IEventEntry + { + [Data] public short StartFrame { get; set; } + [Data] public short EndFrame { get; set; } + [Data] public short Unk04 { get; set; } + [Data] public short Unk08 { get; set; } + + public override string ToString() => + $"{nameof(Unk0C)}: Frame {StartFrame}, {Unk04}, {Unk08}"; + } + + public class Unk0D : IEventEntry + { + [Data] public short StartFrame { get; set; } + [Data] public short EndFrame { get; set; } + [Data(Count = 34)] public short[] Unk { get; set; } + + public override string ToString() => + $"{nameof(Unk0D)}: Frame {StartFrame}, ({string.Join(", ", Unk)})"; + } + + public class Unk0E : IEventEntry + { + [Data] public short StartFrame { get; set; } + [Data] public short EndFrame { get; set; } + [Data] public short Unk04 { get; set; } + [Data] public short Unk06 { get; set; } + [Data] public short Unk08 { get; set; } + + public override string ToString() => + $"{nameof(Unk0E)}: Frame {StartFrame}, {Unk04}, {Unk06}, {Unk08}"; + } + + public class SetupEvent : IEventEntry // sub_22d358 + { + public override string ToString() => + $"{nameof(SetupEvent)}"; + } + + public class ReadAssets : IEventEntry + { + public short FrameStart { get; set; } + public short FrameEnd { get; set; } + public short Unk06 { get; set; } + public List Set { get; set; } + + public override string ToString() => + $"{nameof(ReadAssets)}: {FrameStart} {FrameEnd} {Unk06}\n\t{string.Join("\n\t", Set)}"; + } + + public class EntryUnk29 : IEventEntry + { + [Data] public short StartFrame { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public short Unk04 { get; set; } + [Data] public short Unk06 { get; set; } + [Data] public float Unk08 { get; set; } + + public override string ToString() => + $"{nameof(EntryUnk29)}: {StartFrame} {Unk02} {Unk04} {Unk06} {Unk08}"; + } + + public class EntryUnk2A : IEventEntry // sub_232A48 + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public short Unk04 { get; set; } + + public override string ToString() => + $"{nameof(EntryUnk2A)}: {Unk00} {Unk02} {Unk04}"; + } + + public class SeqPlayAudio : IEventEntry + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public short Unk04 { get; set; } + [Data] public short Unk06 { get; set; } + [Data] public short FrameStart { get; set; } + [Data] public short Unk0A { get; set; } + + public override string ToString() => + $"{nameof(SeqPlayAudio)}: {Unk00}, {Unk02}, {Unk04}, {Unk06}, Frame {FrameStart}, {Unk0A}"; + } + + public class SeqPlayAnimation : IEventEntry + { + [Data] public short FrameStart { get; set; } + [Data] public short FrameEnd { get; set; } + [Data] public short Unk04 { get; set; } + [Data] public short Unk06 { get; set; } + [Data] public short Unk08 { get; set; } + [Data] public short ActorId { get; set; } + [Data] public short Unk0C { get; set; } + [Data] public string Path { get; set; } + + public override string ToString() => + $"{nameof(SeqPlayAnimation)}: Frame start {FrameStart}, Frame end {FrameEnd}, {Unk04}, {Unk06}, {Unk08}, ActorID {ActorId}, {Unk0C}, {Path}"; + } + + public class SeqDialog : IEventEntry + { + [Data] public short FrameIndex { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public short MessageId { get; set; } + [Data] public short Unk06 { get; set; } + [Data] public short Unk08 { get; set; } + + public override string ToString() => + $"{nameof(SeqDialog)}: Frame index {FrameIndex}, {Unk02}, MsgID {MessageId}, {Unk06}, {Unk08}"; + } + + public class SeqPlayBgm : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short BankIndex { get; set; } + [Data] public byte VolumeStartIndex { get; set; } + [Data] public byte VolumeEndIndex { get; set; } + [Data] public byte FadeType { get; set; } + [Data] public byte Unused { get; set; } + + public override string ToString() => + $"{nameof(SeqPlayBgm)}: Frame {Frame}, Bank {BankIndex}, Volume start {VolumeStartIndex}, Volume end {VolumeEndIndex}, Fade type {FadeType}"; + } + + public class ReadBgm : IEventEntry + { + [Data] public short Unk00 { get; set; } + [Data] public short BgmId { get; set; } + + public override string ToString() => + $"{nameof(ReadBgm)}: BGM ID {BgmId}, {Unk00}"; + } + + public class SetBgm : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short BankIndex { get; set; } + [Data] public short BgmId { get; set; } + + public override string ToString() => + $"{nameof(SetBgm)}: BGM ID {BgmId}, {Frame} {BankIndex}"; + } + + public class EntryUnk36 : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public float Unk04 { get; set; } + [Data] public float Unk08 { get; set; } + [Data] public float Unk0c { get; set; } + + public override string ToString() => + $"{nameof(EntryUnk36)}: Frame {Frame}, {Unk02}, {Unk04}, {Unk08}, {Unk0c}"; + } + + public class ReadActor : IEventEntry + { + [Data] public short ObjectId { get; set; } + [Data] public short ActorId { get; set; } + [Data] public string Name { get; set; } + + public override string ToString() => + $"{nameof(ReadActor)}: ObjectEntry {ObjectId:X04}, Name {Name}, ActorID {ActorId}"; + } + + public class ReadEffect : IEventEntry + { + [Data] public short Id { get; set; } + [Data] public string Name { get; set; } + + public override string ToString() => + $"{nameof(ReadEffect)}: Id {Id}, Name {Name}"; + } + + public class SeqLayout : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short LayoutIndex { get; set; } + [Data] public string LayoutName { get; set; } + + public override string ToString() => + $"{nameof(ReadEffect)}: Start frame {Frame}, Layout {LayoutName} Index {LayoutIndex}"; + } + + public class ReadLayout : IEventEntry + { + [Data] public string Name { get; set; } + + public override string ToString() => + $"{nameof(ReadLayout)}: {Name}"; + } + + public class ReadMotion : IEventEntry + { + [Data] public short ObjectId { get; set; } + [Data] public short ActorId { get; set; } + [Data] public short UnknownIndex { get; set; } + [Data] public string Name { get; set; } + + public override string ToString() => + $"{nameof(ReadMotion)}: ObjectEntry {ObjectId:X04}, ActorID {ActorId}, Unk? {UnknownIndex}, Path {Name}"; + } + + public class ReadAudio : IEventEntry + { + [Data] public string Name { get; set; } + + public override string ToString() => $"{nameof(ReadAudio)} {Name}"; + } + + public class SetShake : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short Type { get; set; } + [Data] public short Width { get; set; } + [Data] public short Height { get; set; } + [Data] public short Depth { get; set; } + [Data] public short Duration { get; set; } + + public override string ToString() => + $"{nameof(SetShake)}: Frame {Frame}, Type {Type}, Width {Width}, Height {Height}, Depth {Depth}, Duration {Duration}"; + } + + public class StopEffect : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short Unused { get; set; } + + public override string ToString() => + $"{nameof(StopEffect)}: Frame {Frame}"; + } + + public class Unk42 : IEventEntry + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + + public override string ToString() => + $"{nameof(Unk42)}: {Unk00}, {Unk02}"; + } + + public class RunMovie : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public string Name { get; set; } + + public override string ToString() => + $"{nameof(RunMovie)}: Frame {Frame}, Name {Name}"; + } + + public class EntryUnk47 : IEventEntry + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public float StartPositionX { get; set; } + [Data] public float StartPositionY { get; set; } + [Data] public float StartPositionZ { get; set; } + [Data] public float EndPositionX { get; set; } + [Data] public float EndPositionY { get; set; } + [Data] public float EndPositionZ { get; set; } + [Data] public float RotationX { get; set; } + [Data] public float RotationY { get; set; } + [Data] public float RotationZ { get; set; } + [Data] public short Unk28 { get; set; } + [Data] public short Unk2A { get; set; } + + public override string ToString() => + $"{nameof(EntryUnk47)}: {Unk00}, {Unk02}, {Unk28}, {Unk2A}, StartPos({StartPositionX}, {StartPositionY}, {StartPositionZ}), EndPos({EndPositionX}, {EndPositionY}, {EndPositionZ}), Rot({RotationX}, {RotationY}, {RotationZ})"; + } + + public class SeqHideObject : IEventEntry + { + [Data] public short Frame { get; set; } + [Data] public short Type { get; set; } + + public override string ToString() => + $"{nameof(SeqHideObject)}: Frame {Frame}, Type {Type}"; + } + + public static List Read(Stream stream) + { + var entries = new List(); + + int blockLength; + while (stream.Position + 3 < stream.Length) + { + blockLength = stream.ReadInt16(); + if (blockLength == Terminator) + break; + + var startPosition = stream.Position - 2; + var type = stream.ReadInt16(); + if (_idType.TryGetValue(type, out var entryType)) + entries.Add(Mapping.ReadObject(stream, (IEventEntry)Activator.CreateInstance(entryType))); + else + Console.Error.WriteLine($"No Event implementation for {type:X02}"); + + if (stream.Position != startPosition + blockLength) + stream.Position = stream.Position; + stream.Position = startPosition + blockLength; + } + + return entries; + } + + public static void Write(Stream stream, + IEnumerable eventSet) + { + foreach (var item in eventSet) + { + var startPosition = stream.Position; + stream.Position += 4; + Mapping.WriteObject(stream, item); + var nextPosition = stream.AlignPosition(2).Position; + + var id = _typeId[item.GetType()]; + var length = stream.Position - startPosition; + stream.Position = startPosition; + stream.Write((short)(length)); + stream.Write((short)id); + stream.Position = nextPosition; + } + + stream.Write(Terminator); + } + + public static string ToString(IEnumerable eventSet) => + string.Join("\n", eventSet); + + private static string ReadCStyleString(Stream stream) + { + var sb = new StringBuilder(); + while (stream.Position < stream.Length) + { + var ch = stream.ReadByte(); + if (ch == 0) + break; + + sb.Append((char)ch); + } + + return sb.ToString(); + } + + private static void WriteCStyleString(Stream stream, string str) + { + foreach (var ch in str) + stream.WriteByte((byte)ch); + stream.WriteByte(0); + } + + private static void CStringWriter(MappingWriteArgs args) => + WriteCStyleString(args.Writer.BaseStream, (string)args.Item); + + private static object CStringReader(MappingReadArgs args) => + ReadCStyleString(args.Reader.BaseStream); + + private static object ReadVoices(MappingReadArgs args) + { + var voiceCount = args.Reader.ReadInt32(); + var voices = new List(voiceCount); + for (var i = 0; i < voiceCount; i++) + { + var voice = new SeqVoices.Voice(); + var startPos = args.Reader.BaseStream.Position; + args.Reader.ReadInt32(); // It always supposed to be 0 + voice.FrameStart = args.Reader.ReadInt16(); + args.Reader.ReadByte(); + voice.Name = ReadCStyleString(args.Reader.BaseStream); + voices.Add(voice); + args.Reader.BaseStream.Position = startPos + 0x20; + } + + return new SeqVoices + { + Voices = voices + }; + } + + private static void WriteVoices(MappingWriteArgs args) + { + var item = (SeqVoices)args.Item; + args.Writer.Write(item.Voices.Count); + foreach (var voice in item.Voices) + { + var startPos = args.Writer.BaseStream.Position; + args.Writer.Write(0); + args.Writer.Write(voice.FrameStart); + args.Writer.Write((byte)0); + WriteCStyleString(args.Writer.BaseStream, voice.Name); + args.Writer.BaseStream.Position = startPos + 0x20; + } + + var endPosition = args.Writer.BaseStream.Position; + if (endPosition > args.Writer.BaseStream.Length) + args.Writer.BaseStream.SetLength(endPosition); + } + + private static object ReadSetCameraData(MappingReadArgs args) + { + List AssignValues(SetCameraDataHeader header, IList val) => + Enumerable.Range(0, header.Count).Select(i => val[header.Index + i]).ToList(); + + var cameraId = args.Reader.ReadInt16(); + var headers = Enumerable + .Range(0, 8) + .Select(x => BinaryMapping.ReadObject(args.Reader.BaseStream)) + .ToList(); + args.Reader.BaseStream.AlignPosition(4); + var valueCount = headers.Max(x => x.Index + x.Count); + var values = Enumerable + .Range(0, valueCount) + .Select(x => BinaryMapping.ReadObject(args.Reader.BaseStream)) + .Select(x => new SetCameraData.CameraKeys + { + Interpolation = (Motion.Interpolation)(x.FlagData >> 29), + KeyFrame = (int)((x.FlagData & 0x1FFFFFFF ^ 0x10000000) - 0x10000000), + Value = x.Value, + TangentEaseIn = x.TangentEaseIn, + TangentEaseOut = x.TangentEaseOut + }) + .ToList(); + + return new SetCameraData + { + CameraId = cameraId, + PositionX = AssignValues(headers[0], values), + PositionY = AssignValues(headers[1], values), + PositionZ = AssignValues(headers[2], values), + LookAtX = AssignValues(headers[3], values), + LookAtY = AssignValues(headers[4], values), + LookAtZ = AssignValues(headers[5], values), + Roll = AssignValues(headers[6], values), + FieldOfView = AssignValues(headers[7], values), + }; + } + + private static void WriteSetCameraData(MappingWriteArgs args) + { + void WriteHeader(Stream stream, + List values, + int sIndex) => + Mapping.WriteObject(stream, new SetCameraDataHeader + { + Index = (short)sIndex, + Count = (short)values.Count + }); + + void WriteData(Stream stream, List values) + { + foreach (var value in values.Select(x => new CameraValueInternal + { + FlagData = (uint)((((x.KeyFrame + 0x10000000) ^ 0x10000000) & 0x1FFFFFFF) | + ((int)x.Interpolation << 29)), + Value = x.Value, + TangentEaseIn = x.TangentEaseIn, + TangentEaseOut = x.TangentEaseOut + })) + Mapping.WriteObject(stream, value); + } + + + var item = args.Item as SetCameraData; + args.Writer.Write(item.CameraId); + + var channelCountList = new List(8) + { + item.PositionX.Count, + item.PositionY.Count, + item.PositionZ.Count, + item.LookAtX.Count, + item.LookAtY.Count, + item.LookAtZ.Count, + item.Roll.Count, + item.FieldOfView.Count, + }; + var indexList = new List(8); + var startIndex = 0; + foreach (var channelCount in channelCountList) + { + indexList.Add(startIndex); + startIndex += channelCount; + } + + WriteHeader(args.Writer.BaseStream, item.PositionX, indexList[0]); + WriteHeader(args.Writer.BaseStream, item.PositionY, indexList[1]); + WriteHeader(args.Writer.BaseStream, item.PositionZ, indexList[2]); + WriteHeader(args.Writer.BaseStream, item.LookAtX, indexList[3]); + WriteHeader(args.Writer.BaseStream, item.LookAtY, indexList[4]); + WriteHeader(args.Writer.BaseStream, item.LookAtZ, indexList[5]); + WriteHeader(args.Writer.BaseStream, item.Roll, indexList[6]); + WriteHeader(args.Writer.BaseStream, item.FieldOfView, indexList[7]); + + args.Writer.BaseStream.AlignPosition(4); + WriteData(args.Writer.BaseStream, item.PositionX); + WriteData(args.Writer.BaseStream, item.PositionY); + WriteData(args.Writer.BaseStream, item.PositionZ); + WriteData(args.Writer.BaseStream, item.LookAtX); + WriteData(args.Writer.BaseStream, item.LookAtY); + WriteData(args.Writer.BaseStream, item.LookAtZ); + WriteData(args.Writer.BaseStream, item.Roll); + WriteData(args.Writer.BaseStream, item.FieldOfView); + } + + private static object ReadLoadAssets(MappingReadArgs args) + { + var reader = args.Reader; + var itemCount = reader.ReadInt16(); + var unk02 = reader.ReadInt16(); + var unk04 = reader.ReadInt16(); + var unk06 = reader.ReadInt16(); + + var loadSet = new List(); + for (var i = 0; i < itemCount; i++) + { + var startPosition = reader.BaseStream.Position; + var typeId = reader.ReadInt16(); + var length = reader.ReadInt16(); + var entryType = _idType[typeId]; + loadSet.Add(Mapping.ReadObject(reader.BaseStream, + (IEventEntry)Activator.CreateInstance(entryType))); + reader.BaseStream.Position = startPosition + length; + } + + return new ReadAssets + { + FrameStart = unk02, + FrameEnd = unk04, + Unk06 = unk06, + Set = loadSet + }; + } + + private static void WriteLoadAssets(MappingWriteArgs args) + { + var item = args.Item as ReadAssets; + args.Writer.Write((short)item.Set.Count); + args.Writer.Write(item.FrameStart); + args.Writer.Write(item.FrameEnd); + args.Writer.Write(item.Unk06); + + var stream = args.Writer.BaseStream; + foreach (var loadItem in item.Set) + { + var startPosition = stream.Position; + stream.Position += 4; + Mapping.WriteObject(stream, loadItem); + var nextPosition = stream.AlignPosition(2).Position; + + var id = _typeId[loadItem.GetType()]; + var length = stream.Position - startPosition; + stream.Position = startPosition; + stream.Write((short)id); + stream.Write((short)length); + stream.Position = nextPosition; + } + } + + private static object ReadUnk1E(MappingReadArgs args) + { + var id = args.Reader.ReadInt16(); + var count = args.Reader.ReadInt16(); + var unk04 = args.Reader.ReadInt16(); + var unk06 = args.Reader.ReadInt16(); + var entries = Enumerable + .Range(0, count) + .Select(x => Mapping.ReadObject(args.Reader.BaseStream)) + .ToList(); + var unkG = args.Reader.ReadInt16(); + var unkH = args.Reader.ReadInt16(); + + return new Unk1E + { + Id = id, + UnkG = unkG, + UnkH = unkH, + Entries = entries + }; + } + + private static void WriteUnk1E(MappingWriteArgs args) + { + var item = args.Item as Unk1E; + args.Writer.Write(item.Id); + args.Writer.Write((short)item.Entries.Count); + args.Writer.Write((short)3); + args.Writer.Write((short)0); + foreach (var entry in item.Entries) + Mapping.WriteObject(args.Writer.BaseStream, entry); + args.Writer.Write(item.UnkG); + args.Writer.Write(item.UnkH); + } + } +} diff --git a/OpenKh.Kh2/Ard/SpawnPoint.cs b/OpenKh.Kh2/Ard/SpawnPoint.cs index 90d632eec..775659b78 100644 --- a/OpenKh.Kh2/Ard/SpawnPoint.cs +++ b/OpenKh.Kh2/Ard/SpawnPoint.cs @@ -1,420 +1,420 @@ -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Ard -{ - public class SpawnPoint - { - public class Entity - { - private class Raw - { - [Data] public int ObjectId { get; set; } - [Data] public float PositionX { get; set; } - [Data] public float PositionY { get; set; } - [Data] public float PositionZ { get; set; } - [Data] public float RotationX { get; set; } - [Data] public float RotationY { get; set; } - [Data] public float RotationZ { get; set; } - [Data] public byte SpawnType { get; set; } - [Data] public byte SpawnArgument { get; set; } - [Data] public short Serial { get; set; } - [Data] public int Argument1 { get; set; } - [Data] public int Argument2 { get; set; } - [Data] public short ReactionCommand { get; set; } - [Data] public short SpawnDelay { get; set; } - [Data] public short Command { get; set; } - [Data] public short SpawnRange { get; set; } - [Data] public byte Level { get; set; } - [Data] public byte Medal { get; set; } - [Data] public short Reserved32 { get; set; } - [Data] public int Reserved34 { get; set; } - [Data] public int Reserved38 { get; set; } - [Data] public int Reserved3c { get; set; } - } - - public int ObjectId { get; set; } - public float PositionX { get; set; } - public float PositionY { get; set; } - public float PositionZ { get; set; } - public float RotationX { get; set; } - public float RotationY { get; set; } - public float RotationZ { get; set; } - public byte SpawnType { get; set; } - public byte SpawnArgument { get; set; } - public short Serial { get; set; } - public int Argument1 { get; set; } - public int Argument2 { get; set; } - public short ReactionCommand { get; set; } - public short SpawnDelay { get; set; } - public short Command { get; set; } - public short SpawnRange { get; set; } - public byte Level { get; set; } - public byte Medal { get; set; } - - public static Entity Read(Stream stream) - { - var raw = BinaryMapping.ReadObject(stream); - return new Entity - { - ObjectId = raw.ObjectId, - PositionX = raw.PositionX, - PositionY = raw.PositionY, - PositionZ = raw.PositionZ, - RotationX = raw.RotationX, - RotationY = raw.RotationY, - RotationZ = raw.RotationZ, - SpawnType = raw.SpawnType, - SpawnArgument = raw.SpawnArgument, - Serial = raw.Serial, - Argument1 = raw.Argument1, - Argument2 = raw.Argument2, - ReactionCommand = raw.ReactionCommand, - SpawnDelay = raw.SpawnDelay, - Command = raw.Command, - SpawnRange = raw.SpawnRange, - Level = raw.Level, - Medal = raw.Medal, - }; - } - - public static void Write(Stream stream, Entity entity) => - BinaryMapping.WriteObject(stream, new Raw - { - ObjectId = entity.ObjectId, - PositionX = entity.PositionX, - PositionY = entity.PositionY, - PositionZ = entity.PositionZ, - RotationX = entity.RotationX, - RotationY = entity.RotationY, - RotationZ = entity.RotationZ, - SpawnType = entity.SpawnType, - SpawnArgument = entity.SpawnArgument, - Serial = entity.Serial, - Argument1 = entity.Argument1, - Argument2 = entity.Argument2, - ReactionCommand = entity.ReactionCommand, - SpawnDelay = entity.SpawnDelay, - Command = entity.Command, - SpawnRange = entity.SpawnRange, - Level = entity.Level, - Medal = entity.Medal, - }); - - public override string ToString() => - $"ID {ObjectId} POS({PositionX:F0}, {PositionY:F0}, {PositionZ:F0}) ROT({RotationX:F0}, {RotationY:F0}, {RotationZ:F0})"; - } - - public class EventActivator - { - private class Raw - { - [Data] public short Shape { get; set; } - [Data] public short Option { get; set; } - [Data] public float PositionX { get; set; } - [Data] public float PositionY { get; set; } - [Data] public float PositionZ { get; set; } - [Data] public float ScaleX { get; set; } - [Data] public float ScaleY { get; set; } - [Data] public float ScaleZ { get; set; } - [Data] public float RotationX { get; set; } - [Data] public float RotationY { get; set; } - [Data] public float RotationZ { get; set; } - [Data] public int Flags { get; set; } - [Data] public short Type { get; set; } - [Data] public byte OnBgGroup { get; set; } - [Data] public byte OffBgGroup { get; set; } - [Data] public int Padding30 { get; set; } - [Data] public int Padding34 { get; set; } - [Data] public int Padding38 { get; set; } - [Data] public int Padding3c { get; set; } - } - - public short Shape { get; set; } - public short Option { get; set; } - public float PositionX { get; set; } - public float PositionY { get; set; } - public float PositionZ { get; set; } - public float ScaleX { get; set; } - public float ScaleY { get; set; } - public float ScaleZ { get; set; } - public float RotationX { get; set; } - public float RotationY { get; set; } - public float RotationZ { get; set; } - public int Flags { get; set; } - public short Type { get; set; } - public byte OnBgGroup { get; set; } - public byte OffBgGroup { get; set; } - - public static EventActivator Read(Stream stream) - { - var raw = BinaryMapping.ReadObject(stream); - return new EventActivator - { - Shape = raw.Shape, - Option = raw.Option, - PositionX = raw.PositionX, - PositionY = raw.PositionY, - PositionZ = raw.PositionZ, - ScaleX = raw.ScaleX, - ScaleY = raw.ScaleY, - ScaleZ = raw.ScaleZ, - RotationX = raw.RotationX, - RotationY = raw.RotationY, - RotationZ = raw.RotationZ, - Flags = raw.Flags, - Type = raw.Type, - OnBgGroup = raw.OnBgGroup, - OffBgGroup = raw.OffBgGroup, - }; - } - - public static void Write(Stream stream, EventActivator activator) => - BinaryMapping.WriteObject(stream, new Raw - { - Shape = activator.Shape, - Option = activator.Option, - PositionX = activator.PositionX, - PositionY = activator.PositionY, - PositionZ = activator.PositionZ, - ScaleX = activator.ScaleX, - ScaleY = activator.ScaleY, - ScaleZ = activator.ScaleZ, - RotationX = activator.RotationX, - RotationY = activator.RotationY, - RotationZ = activator.RotationZ, - Flags = activator.Flags, - Type = activator.Type, - OnBgGroup = activator.OnBgGroup, - OffBgGroup = activator.OffBgGroup, - }); - - public override string ToString() => - $"Shape {Shape} Option {Option} POS({PositionX:F0}, {PositionY:F0}, {PositionZ:F0}) SCL({ScaleX:F0}, {ScaleY:F0}, {ScaleZ:F0}) ROT({RotationX:F0}, {RotationY:F0}, {RotationZ:F0}) " + - $"Flags {Flags:X}, Type {Type}, OnBg {OnBgGroup:X}, OffBg {OffBgGroup:X}"; - } - - public class WalkPathDesc - { - private class Raw - { - [Data] public short Serial { get; set; } - [Data] public short Count { get; set; } - [Data] public byte Flag { get; set; } - [Data] public byte Id { get; set; } - [Data] public short Reserved { get; set; } - } - - public short Serial { get; set; } - public byte Flag { get; set; } - public byte Id { get; set; } - public List Positions { get; set; } - - public static WalkPathDesc Read(Stream stream) - { - var header = BinaryMapping.ReadObject(stream); - return new WalkPathDesc - { - Serial = header.Serial, - Flag = header.Flag, - Id = header.Id, - Positions = Enumerable.Range(0, header.Count) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList() - }; - } - - public static void Write(Stream stream, WalkPathDesc entity) - { - BinaryMapping.WriteObject(stream, new Raw - { - Serial = entity.Serial, - Flag = entity.Flag, - Count = (short)entity.Positions.Count, - Id = entity.Id, - }); - - foreach (var position in entity.Positions) - BinaryMapping.WriteObject(stream, position); - } - - public override string ToString() => $"Serial {Serial:X} Flag {Flag:X} Id {Id:X}"; - } - - public class Position - { - [Data] public float X { get; set; } - [Data] public float Y { get; set; } - [Data] public float Z { get; set; } - - public override string ToString() => $"{X:F0} {Y:F0} {Z:F0}"; - } - - public class ReturnParameter - { - [Data] public byte Id { get; set; } - [Data] public byte Type { get; set; } - [Data] public byte Rate { get; set; } - [Data] public byte EntryType { get; set; } - [Data] public int Argument04 { get; set; } - [Data] public int Argument08 { get; set; } - [Data] public int Argument0c { get; set; } - - public static ReturnParameter Read(Stream stream) => - BinaryMapping.ReadObject(stream); - - public static void Write(Stream stream, ReturnParameter entity) => - BinaryMapping.WriteObject(stream, entity); - } - - public class Signal - { - [Data] public ushort SignalId { get; set; } - [Data] public ushort Argument { get; set; } - [Data] public byte Action { get; set; } - [Data] public byte Padding05 { get; set; } - [Data] public byte Padding06 { get; set; } - [Data] public byte Padding07 { get; set; } - - public static Signal Read(Stream stream) => - BinaryMapping.ReadObject(stream); - - public static void Write(Stream stream, Signal entity) => - BinaryMapping.WriteObject(stream, entity); - } - - private class Raw - { - [Data] public byte Type { get; set; } - [Data] public byte Flag { get; set; } - [Data] public short Id { get; set; } - [Data] public short EntityCount { get; set; } - [Data] public short EventActivatorCount { get; set; } - [Data] public short WalkPathCount { get; set; } - [Data] public short ReturnParameterCount { get; set; } - [Data] public short SignalCount { get; set; } - [Data] public short Reserved0e { get; set; } - [Data] public int Reserved10 { get; set; } - [Data] public int Reserved14 { get; set; } - [Data] public int Reserved18 { get; set; } - [Data] public byte Place { get; set; } - [Data] public byte Door { get; set; } - [Data] public byte World { get; set; } - [Data] public byte Unk1f { get; set; } - [Data] public int Unk20 { get; set; } - [Data] public int Unk24 { get; set; } - [Data] public int Unk28 { get; set; } - } - - public class TeleportDesc - { - public byte Place { get; set; } - public byte Door { get; set; } - public byte World { get; set; } - public byte Unknown { get; set; } - } - - public byte Type { get; set; } - public byte Flag { get; set; } - public short Id { get; set; } - public TeleportDesc Teleport { get; set; } - public int Unk20 { get; set; } - public int Unk24 { get; set; } - - public List Entities { get; set; } - public List EventActivators { get; set; } - public List WalkPath { get; set; } - public List ReturnParameters { get; set; } - public List Signals { get; set; } - - public override string ToString() => - $"Type {Type:X} Flag {Flag:X} {Id:X}\n{string.Join("\n", Entities.Select(x => x.ToString()))}"; - - public static List Read(Stream stream) - { - var typeId = stream.ReadInt32(); - var itemCount = stream.ReadInt32(); - if (itemCount <= 0) - return new List(); - return Enumerable.Range(0, itemCount) - .Select(x => ReadSingle(stream)) - .ToList(); - } - - public static void Write(Stream stream, List items) - { - stream.Write(2); - stream.Write(items.Count); - foreach (var item in items) - { - BinaryMapping.WriteObject(stream, new Raw - { - Type = item.Type, - Flag = item.Flag, - Id = item.Id, - EntityCount = (short)item.Entities.Count, - EventActivatorCount = (short)item.EventActivators.Count, - WalkPathCount = (short)item.WalkPath.Count, - ReturnParameterCount = (short)item.ReturnParameters.Count, - SignalCount = (short)item.Signals.Count, - Reserved10 = 0, - Reserved14 = 0, - Reserved18 = 0, - Place = item.Teleport.Place, - Door = item.Teleport.Door, - World = item.Teleport.World, - Unk1f = item.Teleport.Unknown, - Unk20 = item.Unk20, - Unk24 = item.Unk24, - Unk28 = 0, - }); - - foreach (var spawnPoint in item.Entities) - Entity.Write(stream, spawnPoint); - foreach (var unk in item.EventActivators) - EventActivator.Write(stream, unk); - foreach (var unk in item.WalkPath) - WalkPathDesc.Write(stream, unk); - foreach (var unk in item.ReturnParameters) - ReturnParameter.Write(stream, unk); - foreach (var unk in item.Signals) - Signal.Write(stream, unk); - } - } - - private static SpawnPoint ReadSingle(Stream stream) - { - var raw = BinaryMapping.ReadObject(stream); - var spawn = new SpawnPoint - { - Type = raw.Type, - Flag = raw.Flag, - Id = raw.Id, - Teleport = new TeleportDesc - { - Place = raw.Place, - Door = raw.Door, - World = raw.World, - Unknown = raw.Unk1f - }, - Unk20 = raw.Unk20, - Unk24 = raw.Unk24, - }; - - spawn.Entities = ReadList(stream, raw.EntityCount, Entity.Read); - spawn.EventActivators = ReadList(stream, raw.EventActivatorCount, EventActivator.Read); - spawn.WalkPath = ReadList(stream, raw.WalkPathCount, WalkPathDesc.Read); - spawn.ReturnParameters = ReadList(stream, raw.ReturnParameterCount, ReturnParameter.Read); - spawn.Signals = ReadList(stream, raw.SignalCount, Signal.Read); - - return spawn; - } - - private static List ReadList(Stream stream, int count, Func reader) => - Enumerable.Range(0, count).Select(x => reader(stream)).ToList(); - } -} +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Ard +{ + public class SpawnPoint + { + public class Entity + { + private class Raw + { + [Data] public int ObjectId { get; set; } + [Data] public float PositionX { get; set; } + [Data] public float PositionY { get; set; } + [Data] public float PositionZ { get; set; } + [Data] public float RotationX { get; set; } + [Data] public float RotationY { get; set; } + [Data] public float RotationZ { get; set; } + [Data] public byte SpawnType { get; set; } + [Data] public byte SpawnArgument { get; set; } + [Data] public short Serial { get; set; } + [Data] public int Argument1 { get; set; } + [Data] public int Argument2 { get; set; } + [Data] public short ReactionCommand { get; set; } + [Data] public short SpawnDelay { get; set; } + [Data] public short Command { get; set; } + [Data] public short SpawnRange { get; set; } + [Data] public byte Level { get; set; } + [Data] public byte Medal { get; set; } + [Data] public short Reserved32 { get; set; } + [Data] public int Reserved34 { get; set; } + [Data] public int Reserved38 { get; set; } + [Data] public int Reserved3c { get; set; } + } + + public int ObjectId { get; set; } + public float PositionX { get; set; } + public float PositionY { get; set; } + public float PositionZ { get; set; } + public float RotationX { get; set; } + public float RotationY { get; set; } + public float RotationZ { get; set; } + public byte SpawnType { get; set; } + public byte SpawnArgument { get; set; } + public short Serial { get; set; } + public int Argument1 { get; set; } + public int Argument2 { get; set; } + public short ReactionCommand { get; set; } + public short SpawnDelay { get; set; } + public short Command { get; set; } + public short SpawnRange { get; set; } + public byte Level { get; set; } + public byte Medal { get; set; } + + public static Entity Read(Stream stream) + { + var raw = BinaryMapping.ReadObject(stream); + return new Entity + { + ObjectId = raw.ObjectId, + PositionX = raw.PositionX, + PositionY = raw.PositionY, + PositionZ = raw.PositionZ, + RotationX = raw.RotationX, + RotationY = raw.RotationY, + RotationZ = raw.RotationZ, + SpawnType = raw.SpawnType, + SpawnArgument = raw.SpawnArgument, + Serial = raw.Serial, + Argument1 = raw.Argument1, + Argument2 = raw.Argument2, + ReactionCommand = raw.ReactionCommand, + SpawnDelay = raw.SpawnDelay, + Command = raw.Command, + SpawnRange = raw.SpawnRange, + Level = raw.Level, + Medal = raw.Medal, + }; + } + + public static void Write(Stream stream, Entity entity) => + BinaryMapping.WriteObject(stream, new Raw + { + ObjectId = entity.ObjectId, + PositionX = entity.PositionX, + PositionY = entity.PositionY, + PositionZ = entity.PositionZ, + RotationX = entity.RotationX, + RotationY = entity.RotationY, + RotationZ = entity.RotationZ, + SpawnType = entity.SpawnType, + SpawnArgument = entity.SpawnArgument, + Serial = entity.Serial, + Argument1 = entity.Argument1, + Argument2 = entity.Argument2, + ReactionCommand = entity.ReactionCommand, + SpawnDelay = entity.SpawnDelay, + Command = entity.Command, + SpawnRange = entity.SpawnRange, + Level = entity.Level, + Medal = entity.Medal, + }); + + public override string ToString() => + $"ID {ObjectId} POS({PositionX:F0}, {PositionY:F0}, {PositionZ:F0}) ROT({RotationX:F0}, {RotationY:F0}, {RotationZ:F0})"; + } + + public class EventActivator + { + private class Raw + { + [Data] public short Shape { get; set; } + [Data] public short Option { get; set; } + [Data] public float PositionX { get; set; } + [Data] public float PositionY { get; set; } + [Data] public float PositionZ { get; set; } + [Data] public float ScaleX { get; set; } + [Data] public float ScaleY { get; set; } + [Data] public float ScaleZ { get; set; } + [Data] public float RotationX { get; set; } + [Data] public float RotationY { get; set; } + [Data] public float RotationZ { get; set; } + [Data] public int Flags { get; set; } + [Data] public short Type { get; set; } + [Data] public byte OnBgGroup { get; set; } + [Data] public byte OffBgGroup { get; set; } + [Data] public int Padding30 { get; set; } + [Data] public int Padding34 { get; set; } + [Data] public int Padding38 { get; set; } + [Data] public int Padding3c { get; set; } + } + + public short Shape { get; set; } + public short Option { get; set; } + public float PositionX { get; set; } + public float PositionY { get; set; } + public float PositionZ { get; set; } + public float ScaleX { get; set; } + public float ScaleY { get; set; } + public float ScaleZ { get; set; } + public float RotationX { get; set; } + public float RotationY { get; set; } + public float RotationZ { get; set; } + public int Flags { get; set; } + public short Type { get; set; } + public byte OnBgGroup { get; set; } + public byte OffBgGroup { get; set; } + + public static EventActivator Read(Stream stream) + { + var raw = BinaryMapping.ReadObject(stream); + return new EventActivator + { + Shape = raw.Shape, + Option = raw.Option, + PositionX = raw.PositionX, + PositionY = raw.PositionY, + PositionZ = raw.PositionZ, + ScaleX = raw.ScaleX, + ScaleY = raw.ScaleY, + ScaleZ = raw.ScaleZ, + RotationX = raw.RotationX, + RotationY = raw.RotationY, + RotationZ = raw.RotationZ, + Flags = raw.Flags, + Type = raw.Type, + OnBgGroup = raw.OnBgGroup, + OffBgGroup = raw.OffBgGroup, + }; + } + + public static void Write(Stream stream, EventActivator activator) => + BinaryMapping.WriteObject(stream, new Raw + { + Shape = activator.Shape, + Option = activator.Option, + PositionX = activator.PositionX, + PositionY = activator.PositionY, + PositionZ = activator.PositionZ, + ScaleX = activator.ScaleX, + ScaleY = activator.ScaleY, + ScaleZ = activator.ScaleZ, + RotationX = activator.RotationX, + RotationY = activator.RotationY, + RotationZ = activator.RotationZ, + Flags = activator.Flags, + Type = activator.Type, + OnBgGroup = activator.OnBgGroup, + OffBgGroup = activator.OffBgGroup, + }); + + public override string ToString() => + $"Shape {Shape} Option {Option} POS({PositionX:F0}, {PositionY:F0}, {PositionZ:F0}) SCL({ScaleX:F0}, {ScaleY:F0}, {ScaleZ:F0}) ROT({RotationX:F0}, {RotationY:F0}, {RotationZ:F0}) " + + $"Flags {Flags:X}, Type {Type}, OnBg {OnBgGroup:X}, OffBg {OffBgGroup:X}"; + } + + public class WalkPathDesc + { + private class Raw + { + [Data] public short Serial { get; set; } + [Data] public short Count { get; set; } + [Data] public byte Flag { get; set; } + [Data] public byte Id { get; set; } + [Data] public short Reserved { get; set; } + } + + public short Serial { get; set; } + public byte Flag { get; set; } + public byte Id { get; set; } + public List Positions { get; set; } + + public static WalkPathDesc Read(Stream stream) + { + var header = BinaryMapping.ReadObject(stream); + return new WalkPathDesc + { + Serial = header.Serial, + Flag = header.Flag, + Id = header.Id, + Positions = Enumerable.Range(0, header.Count) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList() + }; + } + + public static void Write(Stream stream, WalkPathDesc entity) + { + BinaryMapping.WriteObject(stream, new Raw + { + Serial = entity.Serial, + Flag = entity.Flag, + Count = (short)entity.Positions.Count, + Id = entity.Id, + }); + + foreach (var position in entity.Positions) + BinaryMapping.WriteObject(stream, position); + } + + public override string ToString() => $"Serial {Serial:X} Flag {Flag:X} Id {Id:X}"; + } + + public class Position + { + [Data] public float X { get; set; } + [Data] public float Y { get; set; } + [Data] public float Z { get; set; } + + public override string ToString() => $"{X:F0} {Y:F0} {Z:F0}"; + } + + public class ReturnParameter + { + [Data] public byte Id { get; set; } + [Data] public byte Type { get; set; } + [Data] public byte Rate { get; set; } + [Data] public byte EntryType { get; set; } + [Data] public int Argument04 { get; set; } + [Data] public int Argument08 { get; set; } + [Data] public int Argument0c { get; set; } + + public static ReturnParameter Read(Stream stream) => + BinaryMapping.ReadObject(stream); + + public static void Write(Stream stream, ReturnParameter entity) => + BinaryMapping.WriteObject(stream, entity); + } + + public class Signal + { + [Data] public ushort SignalId { get; set; } + [Data] public ushort Argument { get; set; } + [Data] public byte Action { get; set; } + [Data] public byte Padding05 { get; set; } + [Data] public byte Padding06 { get; set; } + [Data] public byte Padding07 { get; set; } + + public static Signal Read(Stream stream) => + BinaryMapping.ReadObject(stream); + + public static void Write(Stream stream, Signal entity) => + BinaryMapping.WriteObject(stream, entity); + } + + private class Raw + { + [Data] public byte Type { get; set; } + [Data] public byte Flag { get; set; } + [Data] public short Id { get; set; } + [Data] public short EntityCount { get; set; } + [Data] public short EventActivatorCount { get; set; } + [Data] public short WalkPathCount { get; set; } + [Data] public short ReturnParameterCount { get; set; } + [Data] public short SignalCount { get; set; } + [Data] public short Reserved0e { get; set; } + [Data] public int Reserved10 { get; set; } + [Data] public int Reserved14 { get; set; } + [Data] public int Reserved18 { get; set; } + [Data] public byte Place { get; set; } + [Data] public byte Door { get; set; } + [Data] public byte World { get; set; } + [Data] public byte Unk1f { get; set; } + [Data] public int Unk20 { get; set; } + [Data] public int Unk24 { get; set; } + [Data] public int Unk28 { get; set; } + } + + public class TeleportDesc + { + public byte Place { get; set; } + public byte Door { get; set; } + public byte World { get; set; } + public byte Unknown { get; set; } + } + + public byte Type { get; set; } + public byte Flag { get; set; } + public short Id { get; set; } + public TeleportDesc Teleport { get; set; } + public int Unk20 { get; set; } + public int Unk24 { get; set; } + + public List Entities { get; set; } + public List EventActivators { get; set; } + public List WalkPath { get; set; } + public List ReturnParameters { get; set; } + public List Signals { get; set; } + + public override string ToString() => + $"Type {Type:X} Flag {Flag:X} {Id:X}\n{string.Join("\n", Entities.Select(x => x.ToString()))}"; + + public static List Read(Stream stream) + { + var typeId = stream.ReadInt32(); + var itemCount = stream.ReadInt32(); + if (itemCount <= 0) + return new List(); + return Enumerable.Range(0, itemCount) + .Select(x => ReadSingle(stream)) + .ToList(); + } + + public static void Write(Stream stream, List items) + { + stream.Write(2); + stream.Write(items.Count); + foreach (var item in items) + { + BinaryMapping.WriteObject(stream, new Raw + { + Type = item.Type, + Flag = item.Flag, + Id = item.Id, + EntityCount = (short)item.Entities.Count, + EventActivatorCount = (short)item.EventActivators.Count, + WalkPathCount = (short)item.WalkPath.Count, + ReturnParameterCount = (short)item.ReturnParameters.Count, + SignalCount = (short)item.Signals.Count, + Reserved10 = 0, + Reserved14 = 0, + Reserved18 = 0, + Place = item.Teleport.Place, + Door = item.Teleport.Door, + World = item.Teleport.World, + Unk1f = item.Teleport.Unknown, + Unk20 = item.Unk20, + Unk24 = item.Unk24, + Unk28 = 0, + }); + + foreach (var spawnPoint in item.Entities) + Entity.Write(stream, spawnPoint); + foreach (var unk in item.EventActivators) + EventActivator.Write(stream, unk); + foreach (var unk in item.WalkPath) + WalkPathDesc.Write(stream, unk); + foreach (var unk in item.ReturnParameters) + ReturnParameter.Write(stream, unk); + foreach (var unk in item.Signals) + Signal.Write(stream, unk); + } + } + + private static SpawnPoint ReadSingle(Stream stream) + { + var raw = BinaryMapping.ReadObject(stream); + var spawn = new SpawnPoint + { + Type = raw.Type, + Flag = raw.Flag, + Id = raw.Id, + Teleport = new TeleportDesc + { + Place = raw.Place, + Door = raw.Door, + World = raw.World, + Unknown = raw.Unk1f + }, + Unk20 = raw.Unk20, + Unk24 = raw.Unk24, + }; + + spawn.Entities = ReadList(stream, raw.EntityCount, Entity.Read); + spawn.EventActivators = ReadList(stream, raw.EventActivatorCount, EventActivator.Read); + spawn.WalkPath = ReadList(stream, raw.WalkPathCount, WalkPathDesc.Read); + spawn.ReturnParameters = ReadList(stream, raw.ReturnParameterCount, ReturnParameter.Read); + spawn.Signals = ReadList(stream, raw.SignalCount, Signal.Read); + + return spawn; + } + + private static List ReadList(Stream stream, int count, Func reader) => + Enumerable.Range(0, count).Select(x => reader(stream)).ToList(); + } +} diff --git a/OpenKh.Kh2/Bar.cs b/OpenKh.Kh2/Bar.cs index f3cdb9b34..fd12bf26b 100644 --- a/OpenKh.Kh2/Bar.cs +++ b/OpenKh.Kh2/Bar.cs @@ -1,268 +1,268 @@ -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace OpenKh.Kh2 -{ - public class Bar : List - { - private const uint MagicCode = 0x01524142U; - private const int HeaderSize = 0x10; - private const int EntrySize = 0x10; - - private static Dictionary _alignments = new Dictionary - { - [EntryType.Model] = 0x10, - [EntryType.ModelTexture] = 0x80, - [EntryType.Motion] = 0x10, - [EntryType.Tim2] = 0x40, - [EntryType.CameraOctalTree] = 0x10, - [EntryType.CollisionOctalTree] = 0x10, - [EntryType.ColorOctalTree] = 0x10, - [EntryType.Anb] = 0x10, - [EntryType.Pax] = 0x10, - [EntryType.MapCollision2] = 0x10, - [EntryType.Motionset] = 0x10, - [EntryType.Imgd] = 0x10, - [EntryType.Seqd] = 0x10, - [EntryType.Layout] = 0x10, - [EntryType.Imgz] = 0x10, - [EntryType.AnimationMap] = 0x10, - [EntryType.Seb] = 0x40, - [EntryType.Wd] = 0x40, - [EntryType.IopVoice] = 0x40, - [EntryType.RawBitmap] = 0x80, - [EntryType.MemoryCard] = 0x40, - [EntryType.WrappedCollisionData] = 0x10, - [EntryType.Unknown39] = 0x10, - [EntryType.Minigame] = 0x10, - [EntryType.Progress] = 0x10, - [EntryType.BarUnknown] = 0x10, - [EntryType.Vag] = 0x10, - }; - - public enum EntryType - { - Dummy = 0, - Binary = 1, - List = 2, - Bdx = 3, - Model = 4, - DrawOctalTree = 5, - CollisionOctalTree = 6, - ModelTexture = 7, - Dpx = 8, - Motion = 9, - Tim2 = 10, - CameraOctalTree = 11, - AreaDataSpawn = 12, - AreaDataScript = 13, - FogColor = 14, - ColorOctalTree = 15, - MotionTriggers = 16, - Anb = 17, - Pax = 18, - MapCollision2 = 19, - Motionset = 20, - BgObjPlacement = 21, - Event = 22, - ModelCollision = 23, - Imgd = 24, - Seqd = 25, - Layout = 28, - Imgz = 29, - AnimationMap = 30, - Seb = 31, - Wd = 32, - Unknown33, - IopVoice = 34, - RawBitmap = 36, - MemoryCard = 37, - WrappedCollisionData = 38, - Unknown39, - Unknown40, - Unknown41, - Minigame = 42, - JimiData, - Progress = 44, - Synthesis, - BarUnknown = 46, - Vibration = 47, - Vag = 48, - } - - public enum MotionsetType - { - Default, - Player, - Raw - } - - public class Entry - { - public EntryType Type { get; set; } - - public int Index { get; set; } - - public string Name { get; set; } - - public int Offset { get; set; } - - public Stream Stream { get; set; } - } - - public MotionsetType Motionset { get; set; } - - public class BarContainer - { - /// - /// Used by p_ex msets. - /// - public int Flags = 0; - - public List Entries { get; set; } = new List(); - } - - public static Bar Read(Stream stream, Func predicate) - { - if (!stream.CanRead || !stream.CanSeek) - throw new InvalidDataException($"Read or seek must be supported."); - - var reader = new BinaryReader(stream); - if (stream.Length < 16L || reader.ReadUInt32() != MagicCode) - throw new InvalidDataException("Invalid header"); - - int entryCount = reader.ReadInt32(); - reader.ReadInt32(); // always zero - - var motionsetType = (MotionsetType)reader.ReadInt32(); - var binarc = new Bar() - { - Motionset = motionsetType - }; - - binarc.AddRange(Enumerable.Range(0, entryCount) - .Select(x => new - { - Type = (EntryType)reader.ReadUInt16(), - Index = reader.ReadInt16(), - Name = Encoding.UTF8.GetString(reader.ReadBytes(4)), - Offset = reader.ReadInt32(), - Size = reader.ReadInt32() - }) - .ToList() // Needs to be consumed - .Where(x => predicate(x.Name, x.Type)) - .Select(x => - { - reader.BaseStream.Position = x.Offset; - var data = reader.ReadBytes(x.Size); - - var fileStream = new MemoryStream(); - fileStream.Write(data, 0, data.Length); - fileStream.Position = 0; - - var name = x.Name.Split('\0').FirstOrDefault(); - - return new Entry - { - Type = x.Type, - Index = x.Index, - Name = name, - Offset = x.Offset, - Stream = fileStream - }; - })); - - return binarc; - } - - public static Bar Read(Stream stream) => Read(stream, (name, type) => true); - - public static void Write(Stream stream, Bar binarc) => - Write(stream, binarc, binarc.Motionset); - - public static void Write(Stream stream, IEnumerable entries, MotionsetType motionset = MotionsetType.Default) - { - if (!stream.CanWrite || !stream.CanSeek) - throw new InvalidDataException($"Write or seek must be supported."); - - var writer = new BinaryWriter(stream); - var entriesCount = entries.Count(); - - writer.Write(MagicCode); - writer.Write(entriesCount); - writer.Write(0); - writer.Write((int)motionset); - - var offset = HeaderSize + entriesCount * EntrySize; - var dicLink = new Dictionary<(string name, EntryType type), (int offset, int length)>(); - var myEntries = entries.ToList(); - - foreach (var entry in myEntries) - { - var normalizedName = entry.Name ?? "xxxx"; - if (normalizedName.Length < 4) - normalizedName = $"{entry.Name}\0\0\0\0"; - else if (normalizedName.Length > 4) - normalizedName = entry.Name.Substring(0, 4); - - offset = Align(offset, entry); - - writer.Write((ushort)entry.Type); - writer.Write((ushort)entry.Index); - writer.Write(Encoding.UTF8.GetBytes(normalizedName), 0, 4); - - if (entry.Index != 0) - { - var linkInfo = dicLink[(entry.Name, entry.Type)]; - entry.Offset = linkInfo.offset; - - writer.Write(linkInfo.offset); - writer.Write(linkInfo.length); - } - else - { - dicLink[(entry.Name, entry.Type)] = (offset, (int)entry.Stream.Length); - entry.Offset = offset; - - writer.Write(offset); - writer.Write((int)entry.Stream.Length); - - offset += (int)entry.Stream.Length; - } - - } - - foreach (var entry in myEntries) - { - writer.BaseStream.Position = entry.Offset; - if (entry.Index == 0) - { - entry.Stream.Position = 0; - entry.Stream.CopyTo(writer.BaseStream); - } - } - } - - private static int Align(int offset, Entry entry) - { - if (!_alignments.TryGetValue(entry.Type, out var alignment)) - { - var stream = entry.Stream; - var magicCode = stream.Length >= 4 ? - stream.SetPosition(0).ReadUInt32() : 0; - - alignment = magicCode == MagicCode ? 0x80 : 4; - } - - return Helpers.Align(offset, alignment); - } - - public static bool IsValid(Stream stream) => - stream.Length >= 4 && stream.PeekInt32() == MagicCode; - - } -} +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace OpenKh.Kh2 +{ + public class Bar : List + { + private const uint MagicCode = 0x01524142U; + private const int HeaderSize = 0x10; + private const int EntrySize = 0x10; + + private static Dictionary _alignments = new Dictionary + { + [EntryType.Model] = 0x10, + [EntryType.ModelTexture] = 0x80, + [EntryType.Motion] = 0x10, + [EntryType.Tim2] = 0x40, + [EntryType.CameraOctalTree] = 0x10, + [EntryType.CollisionOctalTree] = 0x10, + [EntryType.ColorOctalTree] = 0x10, + [EntryType.Anb] = 0x10, + [EntryType.Pax] = 0x10, + [EntryType.MapCollision2] = 0x10, + [EntryType.Motionset] = 0x10, + [EntryType.Imgd] = 0x10, + [EntryType.Seqd] = 0x10, + [EntryType.Layout] = 0x10, + [EntryType.Imgz] = 0x10, + [EntryType.AnimationMap] = 0x10, + [EntryType.Seb] = 0x40, + [EntryType.Wd] = 0x40, + [EntryType.IopVoice] = 0x40, + [EntryType.RawBitmap] = 0x80, + [EntryType.MemoryCard] = 0x40, + [EntryType.WrappedCollisionData] = 0x10, + [EntryType.Unknown39] = 0x10, + [EntryType.Minigame] = 0x10, + [EntryType.Progress] = 0x10, + [EntryType.BarUnknown] = 0x10, + [EntryType.Vag] = 0x10, + }; + + public enum EntryType + { + Dummy = 0, + Binary = 1, + List = 2, + Bdx = 3, + Model = 4, + DrawOctalTree = 5, + CollisionOctalTree = 6, + ModelTexture = 7, + Dpx = 8, + Motion = 9, + Tim2 = 10, + CameraOctalTree = 11, + AreaDataSpawn = 12, + AreaDataScript = 13, + FogColor = 14, + ColorOctalTree = 15, + MotionTriggers = 16, + Anb = 17, + Pax = 18, + MapCollision2 = 19, + Motionset = 20, + BgObjPlacement = 21, + Event = 22, + ModelCollision = 23, + Imgd = 24, + Seqd = 25, + Layout = 28, + Imgz = 29, + AnimationMap = 30, + Seb = 31, + Wd = 32, + Unknown33, + IopVoice = 34, + RawBitmap = 36, + MemoryCard = 37, + WrappedCollisionData = 38, + Unknown39, + Unknown40, + Unknown41, + Minigame = 42, + JimiData, + Progress = 44, + Synthesis, + BarUnknown = 46, + Vibration = 47, + Vag = 48, + } + + public enum MotionsetType + { + Default, + Player, + Raw + } + + public class Entry + { + public EntryType Type { get; set; } + + public int Index { get; set; } + + public string Name { get; set; } + + public int Offset { get; set; } + + public Stream Stream { get; set; } + } + + public MotionsetType Motionset { get; set; } + + public class BarContainer + { + /// + /// Used by p_ex msets. + /// + public int Flags = 0; + + public List Entries { get; set; } = new List(); + } + + public static Bar Read(Stream stream, Func predicate) + { + if (!stream.CanRead || !stream.CanSeek) + throw new InvalidDataException($"Read or seek must be supported."); + + var reader = new BinaryReader(stream); + if (stream.Length < 16L || reader.ReadUInt32() != MagicCode) + throw new InvalidDataException("Invalid header"); + + int entryCount = reader.ReadInt32(); + reader.ReadInt32(); // always zero + + var motionsetType = (MotionsetType)reader.ReadInt32(); + var binarc = new Bar() + { + Motionset = motionsetType + }; + + binarc.AddRange(Enumerable.Range(0, entryCount) + .Select(x => new + { + Type = (EntryType)reader.ReadUInt16(), + Index = reader.ReadInt16(), + Name = Encoding.UTF8.GetString(reader.ReadBytes(4)), + Offset = reader.ReadInt32(), + Size = reader.ReadInt32() + }) + .ToList() // Needs to be consumed + .Where(x => predicate(x.Name, x.Type)) + .Select(x => + { + reader.BaseStream.Position = x.Offset; + var data = reader.ReadBytes(x.Size); + + var fileStream = new MemoryStream(); + fileStream.Write(data, 0, data.Length); + fileStream.Position = 0; + + var name = x.Name.Split('\0').FirstOrDefault(); + + return new Entry + { + Type = x.Type, + Index = x.Index, + Name = name, + Offset = x.Offset, + Stream = fileStream + }; + })); + + return binarc; + } + + public static Bar Read(Stream stream) => Read(stream, (name, type) => true); + + public static void Write(Stream stream, Bar binarc) => + Write(stream, binarc, binarc.Motionset); + + public static void Write(Stream stream, IEnumerable entries, MotionsetType motionset = MotionsetType.Default) + { + if (!stream.CanWrite || !stream.CanSeek) + throw new InvalidDataException($"Write or seek must be supported."); + + var writer = new BinaryWriter(stream); + var entriesCount = entries.Count(); + + writer.Write(MagicCode); + writer.Write(entriesCount); + writer.Write(0); + writer.Write((int)motionset); + + var offset = HeaderSize + entriesCount * EntrySize; + var dicLink = new Dictionary<(string name, EntryType type), (int offset, int length)>(); + var myEntries = entries.ToList(); + + foreach (var entry in myEntries) + { + var normalizedName = entry.Name ?? "xxxx"; + if (normalizedName.Length < 4) + normalizedName = $"{entry.Name}\0\0\0\0"; + else if (normalizedName.Length > 4) + normalizedName = entry.Name.Substring(0, 4); + + offset = Align(offset, entry); + + writer.Write((ushort)entry.Type); + writer.Write((ushort)entry.Index); + writer.Write(Encoding.UTF8.GetBytes(normalizedName), 0, 4); + + if (entry.Index != 0) + { + var linkInfo = dicLink[(entry.Name, entry.Type)]; + entry.Offset = linkInfo.offset; + + writer.Write(linkInfo.offset); + writer.Write(linkInfo.length); + } + else + { + dicLink[(entry.Name, entry.Type)] = (offset, (int)entry.Stream.Length); + entry.Offset = offset; + + writer.Write(offset); + writer.Write((int)entry.Stream.Length); + + offset += (int)entry.Stream.Length; + } + + } + + foreach (var entry in myEntries) + { + writer.BaseStream.Position = entry.Offset; + if (entry.Index == 0) + { + entry.Stream.Position = 0; + entry.Stream.CopyTo(writer.BaseStream); + } + } + } + + private static int Align(int offset, Entry entry) + { + if (!_alignments.TryGetValue(entry.Type, out var alignment)) + { + var stream = entry.Stream; + var magicCode = stream.Length >= 4 ? + stream.SetPosition(0).ReadUInt32() : 0; + + alignment = magicCode == MagicCode ? 0x80 : 4; + } + + return Helpers.Align(offset, alignment); + } + + public static bool IsValid(Stream stream) => + stream.Length >= 4 && stream.PeekInt32() == MagicCode; + + } +} diff --git a/OpenKh.Kh2/BaseTable.cs b/OpenKh.Kh2/BaseTable.cs index 77d8db9d5..a01ddc0d5 100644 --- a/OpenKh.Kh2/BaseTable.cs +++ b/OpenKh.Kh2/BaseTable.cs @@ -1,63 +1,63 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2 -{ - internal class BaseTable - where T : class - { - [Data] public int Version { get; set; } - [Data] public int Count { get; set; } - - public static List Read(Stream stream) - { - var header = BinaryMapping.ReadObject>(stream); - return Enumerable.Range(0, header.Count) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList(); - } - - public static void Write(Stream stream, int version, IEnumerable items) - { - var itemList = items as IList ?? items.ToList(); - BinaryMapping.WriteObject(stream, new BaseTable - { - Version = version, - Count = itemList.Count, - }); - - foreach (var item in itemList) - BinaryMapping.WriteObject(stream, item); - } - } - - public class BaseShortTable - where T : class - { - [Data] public short Id { get; set; } - [Data] public short Count { get; set; } - - public static List Read(Stream stream) - { - var header = BinaryMapping.ReadObject>(stream); - return Enumerable.Range(0, header.Count) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList(); - } - - public static void Write(Stream stream, int id, IEnumerable items) - { - var itemList = items as IList ?? items.ToList(); - BinaryMapping.WriteObject(stream, new BaseShortTable - { - Id = (short)id, - Count = (short)itemList.Count, - }); - - foreach (var item in itemList) - BinaryMapping.WriteObject(stream, item); - } - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2 +{ + internal class BaseTable + where T : class + { + [Data] public int Version { get; set; } + [Data] public int Count { get; set; } + + public static List Read(Stream stream) + { + var header = BinaryMapping.ReadObject>(stream); + return Enumerable.Range(0, header.Count) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList(); + } + + public static void Write(Stream stream, int version, IEnumerable items) + { + var itemList = items as IList ?? items.ToList(); + BinaryMapping.WriteObject(stream, new BaseTable + { + Version = version, + Count = itemList.Count, + }); + + foreach (var item in itemList) + BinaryMapping.WriteObject(stream, item); + } + } + + public class BaseShortTable + where T : class + { + [Data] public short Id { get; set; } + [Data] public short Count { get; set; } + + public static List Read(Stream stream) + { + var header = BinaryMapping.ReadObject>(stream); + return Enumerable.Range(0, header.Count) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList(); + } + + public static void Write(Stream stream, int id, IEnumerable items) + { + var itemList = items as IList ?? items.ToList(); + BinaryMapping.WriteObject(stream, new BaseShortTable + { + Id = (short)id, + Count = (short)itemList.Count, + }); + + foreach (var item in itemList) + BinaryMapping.WriteObject(stream, item); + } + } +} diff --git a/OpenKh.Kh2/Battle/Atkp.cs b/OpenKh.Kh2/Battle/Atkp.cs index 0076f8c14..3d51a7c7f 100644 --- a/OpenKh.Kh2/Battle/Atkp.cs +++ b/OpenKh.Kh2/Battle/Atkp.cs @@ -1,36 +1,36 @@ -using System.Collections.Generic; -using System.IO; - -namespace OpenKh.Kh2.Battle -{ - /// - /// Unfinished - /// - public class Atkp - { - public int Id { get; set; } - public short Unknown04 { get; set; } - public short Unknown06 { get; set; } - public short Unknown08 { get; set; } - public short Unknown0a { get; set; } - public short Unknown0c { get; set; } - public short Unknown0e { get; set; } - public short Unknown10 { get; set; } - public short Unknown12 { get; set; } - public short Unknown14 { get; set; } - public short Unknown16 { get; set; } - public short Unknown18 { get; set; } - public short Unknown1a { get; set; } - public int Unknown1c { get; set; } - public short Unknown20 { get; set; } - public short Unknown22 { get; set; } - public short Unknown24 { get; set; } - public short Unknown26 { get; set; } - public short Unknown28 { get; set; } - public short Unknown2a { get; set; } - public short Unknown2c { get; set; } - public short Unknown2e { get; set; } - - public static List Read(Stream stream) => BaseTable.Read(stream); - } -} +using System.Collections.Generic; +using System.IO; + +namespace OpenKh.Kh2.Battle +{ + /// + /// Unfinished + /// + public class Atkp + { + public int Id { get; set; } + public short Unknown04 { get; set; } + public short Unknown06 { get; set; } + public short Unknown08 { get; set; } + public short Unknown0a { get; set; } + public short Unknown0c { get; set; } + public short Unknown0e { get; set; } + public short Unknown10 { get; set; } + public short Unknown12 { get; set; } + public short Unknown14 { get; set; } + public short Unknown16 { get; set; } + public short Unknown18 { get; set; } + public short Unknown1a { get; set; } + public int Unknown1c { get; set; } + public short Unknown20 { get; set; } + public short Unknown22 { get; set; } + public short Unknown24 { get; set; } + public short Unknown26 { get; set; } + public short Unknown28 { get; set; } + public short Unknown2a { get; set; } + public short Unknown2c { get; set; } + public short Unknown2e { get; set; } + + public static List Read(Stream stream) => BaseTable.Read(stream); + } +} diff --git a/OpenKh.Kh2/Battle/Bons.cs b/OpenKh.Kh2/Battle/Bons.cs index 921fefbb4..8755cdfae 100644 --- a/OpenKh.Kh2/Battle/Bons.cs +++ b/OpenKh.Kh2/Battle/Bons.cs @@ -1,30 +1,30 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Battle -{ - public class Bons - { - [Data] public byte RewardId { get; set; } - [Data] public byte CharacterId { get; set; } - [Data] public byte HpIncrease { get; set; } - [Data] public byte MpIncrease { get; set; } - [Data] public byte DriveGaugeUpgrade { get; set; } - [Data] public byte ItemSlotUpgrade { get; set; } - [Data] public byte AccessorySlotUpgrade { get; set; } - [Data] public byte ArmorSlotUpgrade { get; set; } - [Data] public short BonusItem1 { get; set; } - [Data] public short BonusItem2 { get; set; } - [Data] public int Unknown0c { get; set; } - - public override string ToString() => - $"HP: {HpIncrease}, MP: {MpIncrease}, ItemSlot: {ItemSlotUpgrade}, " + - $"Acc.Slot: {AccessorySlotUpgrade}, Bonus 1: {BonusItem1}, Bonus 2: {BonusItem2}"; - - public static List Read(Stream stream) => BaseTable.Read(stream); - - public static void Write(Stream stream, IEnumerable items) => - BaseTable.Write(stream, 2, items); - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Battle +{ + public class Bons + { + [Data] public byte RewardId { get; set; } + [Data] public byte CharacterId { get; set; } + [Data] public byte HpIncrease { get; set; } + [Data] public byte MpIncrease { get; set; } + [Data] public byte DriveGaugeUpgrade { get; set; } + [Data] public byte ItemSlotUpgrade { get; set; } + [Data] public byte AccessorySlotUpgrade { get; set; } + [Data] public byte ArmorSlotUpgrade { get; set; } + [Data] public short BonusItem1 { get; set; } + [Data] public short BonusItem2 { get; set; } + [Data] public int Unknown0c { get; set; } + + public override string ToString() => + $"HP: {HpIncrease}, MP: {MpIncrease}, ItemSlot: {ItemSlotUpgrade}, " + + $"Acc.Slot: {AccessorySlotUpgrade}, Bonus 1: {BonusItem1}, Bonus 2: {BonusItem2}"; + + public static List Read(Stream stream) => BaseTable.Read(stream); + + public static void Write(Stream stream, IEnumerable items) => + BaseTable.Write(stream, 2, items); + } +} diff --git a/OpenKh.Kh2/Battle/Enmp.cs b/OpenKh.Kh2/Battle/Enmp.cs index 1b6dc5599..c0c317686 100644 --- a/OpenKh.Kh2/Battle/Enmp.cs +++ b/OpenKh.Kh2/Battle/Enmp.cs @@ -1,30 +1,30 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Battle -{ - public class Enmp - { - [Data] public short Id { get; set; } - [Data] public short Level { get; set; } - [Data(Count = 32)] public short[] Health { get; set; } - [Data] public short Unknown44 { get; set; } - [Data] public short Unknown46 { get; set; } - [Data] public short PhysicalWeakness { get; set; } - [Data] public short FireWeakness { get; set; } - [Data] public short IceWeakness { get; set; } - [Data] public short ThunderWeakness { get; set; } - [Data] public short DarkWeakness { get; set; } - [Data] public short Unknown52 { get; set; } - [Data] public short ReflectWeakness { get; set; } - [Data] public short Unknown56 { get; set; } - [Data] public short Unknown58 { get; set; } - [Data] public short Unknown5a { get; set; } - - public static List Read(Stream stream) => BaseTable.Read(stream); - - public static void Write(Stream stream, IEnumerable items) => - BaseTable.Write(stream, 2, items); - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Battle +{ + public class Enmp + { + [Data] public short Id { get; set; } + [Data] public short Level { get; set; } + [Data(Count = 32)] public short[] Health { get; set; } + [Data] public short Unknown44 { get; set; } + [Data] public short Unknown46 { get; set; } + [Data] public short PhysicalWeakness { get; set; } + [Data] public short FireWeakness { get; set; } + [Data] public short IceWeakness { get; set; } + [Data] public short ThunderWeakness { get; set; } + [Data] public short DarkWeakness { get; set; } + [Data] public short Unknown52 { get; set; } + [Data] public short ReflectWeakness { get; set; } + [Data] public short Unknown56 { get; set; } + [Data] public short Unknown58 { get; set; } + [Data] public short Unknown5a { get; set; } + + public static List Read(Stream stream) => BaseTable.Read(stream); + + public static void Write(Stream stream, IEnumerable items) => + BaseTable.Write(stream, 2, items); + } +} diff --git a/OpenKh.Kh2/Battle/Fmlv.cs b/OpenKh.Kh2/Battle/Fmlv.cs index 5c267770b..e761ed719 100644 --- a/OpenKh.Kh2/Battle/Fmlv.cs +++ b/OpenKh.Kh2/Battle/Fmlv.cs @@ -1,69 +1,69 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Battle -{ - public class Fmlv - { - public enum FormVanilla - { - Summon, - Valor, - Wisdom, - Master, - Final, - AntiForm - } - public enum FormFm - { - Summon, - Valor, - Wisdom, - Limit, - Master, - Final, - AntiForm - } - - public class Level - { - [Data] public byte Unk0 { get; set; } - [Data] public byte LevelGrowthAbility { get; set; } - [Data] public short Ability { get; set; } - [Data] public int Exp { get; set; } - - public int FormId - { - get => Unk0 >> 4; - set => Unk0 = (byte)((Unk0 & 0x0F) | (value << 4)); - } - - public int FormLevel - { - get => Unk0 & 0xF; - set => Unk0 = (byte)((Unk0 & 0xF0) | (value & 0xF)); - } - - public FormVanilla FormVanilla - { - get => (FormVanilla)FormId; - set => FormId = (int)value; - } - - public FormFm FormFm - { - get => (FormFm)FormId; - set => FormId = (int)value; - } - - public override string ToString() => - $"{FormFm} {FormLevel}: EXP {Exp}, Ability {Ability:X04} Lv. {LevelGrowthAbility}"; - } - - public static List Read(Stream stream) => BaseTable.Read(stream); - - public static void Write(Stream stream, IEnumerable items) => - BaseTable.Write(stream, 2, items); - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Battle +{ + public class Fmlv + { + public enum FormVanilla + { + Summon, + Valor, + Wisdom, + Master, + Final, + AntiForm + } + public enum FormFm + { + Summon, + Valor, + Wisdom, + Limit, + Master, + Final, + AntiForm + } + + public class Level + { + [Data] public byte Unk0 { get; set; } + [Data] public byte LevelGrowthAbility { get; set; } + [Data] public short Ability { get; set; } + [Data] public int Exp { get; set; } + + public int FormId + { + get => Unk0 >> 4; + set => Unk0 = (byte)((Unk0 & 0x0F) | (value << 4)); + } + + public int FormLevel + { + get => Unk0 & 0xF; + set => Unk0 = (byte)((Unk0 & 0xF0) | (value & 0xF)); + } + + public FormVanilla FormVanilla + { + get => (FormVanilla)FormId; + set => FormId = (int)value; + } + + public FormFm FormFm + { + get => (FormFm)FormId; + set => FormId = (int)value; + } + + public override string ToString() => + $"{FormFm} {FormLevel}: EXP {Exp}, Ability {Ability:X04} Lv. {LevelGrowthAbility}"; + } + + public static List Read(Stream stream) => BaseTable.Read(stream); + + public static void Write(Stream stream, IEnumerable items) => + BaseTable.Write(stream, 2, items); + } +} diff --git a/OpenKh.Kh2/Battle/Lvpm.cs b/OpenKh.Kh2/Battle/Lvpm.cs index 1d2392548..8ca9cbfa6 100644 --- a/OpenKh.Kh2/Battle/Lvpm.cs +++ b/OpenKh.Kh2/Battle/Lvpm.cs @@ -1,20 +1,20 @@ -using System.Collections.Generic; -using System.IO; - -namespace OpenKh.Kh2.Battle -{ - public class Lvpm - { - public short HpMultiplier { get; set; } // (Hp * HpMultiplier + 99) / 100 - public short Unknown02 { get; set; } - public short Unknown04 { get; set; } - public short Unknown06 { get; set; } - public short Attack { get; set; } - public short Unknown0a { get; set; } - - public static List Read(Stream stream) => BaseTable.Read(stream); - - public static void Write(Stream stream, IEnumerable items) => - BaseTable.Write(stream, 2, items); - } -} +using System.Collections.Generic; +using System.IO; + +namespace OpenKh.Kh2.Battle +{ + public class Lvpm + { + public short HpMultiplier { get; set; } // (Hp * HpMultiplier + 99) / 100 + public short Unknown02 { get; set; } + public short Unknown04 { get; set; } + public short Unknown06 { get; set; } + public short Attack { get; set; } + public short Unknown0a { get; set; } + + public static List Read(Stream stream) => BaseTable.Read(stream); + + public static void Write(Stream stream, IEnumerable items) => + BaseTable.Write(stream, 2, items); + } +} diff --git a/OpenKh.Kh2/Battle/Lvup.cs b/OpenKh.Kh2/Battle/Lvup.cs index b1d38b6b6..1d300fccb 100644 --- a/OpenKh.Kh2/Battle/Lvup.cs +++ b/OpenKh.Kh2/Battle/Lvup.cs @@ -1,54 +1,54 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Battle -{ - public class Lvup - { - [Data] public int MagicCode { get; set; } - [Data] public int Count { get; set; } - [Data(Count = 0x38)] public byte[] Unknown08 { get; set; } - [Data(Count = 13)] public List Characters { get; set; } - - public class PlayableCharacter - { - [Data] public int NumLevels { get; set; } - [Data(Count = 99)] public List Levels { get; set; } - - public class Level - { - [Data] public int Exp { get; set; } - [Data] public byte Strength { get; set; } - [Data] public byte Magic { get; set; } - [Data] public byte Defense { get; set; } - [Data] public byte Ap { get; set; } - [Data] public short SwordAbility { get; set; } - [Data] public short ShieldAbility { get; set; } - [Data] public short StaffAbility { get; set; } - [Data] public short Padding { get; set; } - } - } - - public enum PlayableCharacterType - { - Sora, - Donald, - Goofy, - Mickey, - Auron, - PingMulan, - Aladdin, - Sparrow, - Beast, - Jack, - Simba, - Tron, - Riku - } - - public static Lvup Read(Stream stream) => BinaryMapping.ReadObject(stream); - - public void Write(Stream stream) => BinaryMapping.WriteObject(stream, this); - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Battle +{ + public class Lvup + { + [Data] public int MagicCode { get; set; } + [Data] public int Count { get; set; } + [Data(Count = 0x38)] public byte[] Unknown08 { get; set; } + [Data(Count = 13)] public List Characters { get; set; } + + public class PlayableCharacter + { + [Data] public int NumLevels { get; set; } + [Data(Count = 99)] public List Levels { get; set; } + + public class Level + { + [Data] public int Exp { get; set; } + [Data] public byte Strength { get; set; } + [Data] public byte Magic { get; set; } + [Data] public byte Defense { get; set; } + [Data] public byte Ap { get; set; } + [Data] public short SwordAbility { get; set; } + [Data] public short ShieldAbility { get; set; } + [Data] public short StaffAbility { get; set; } + [Data] public short Padding { get; set; } + } + } + + public enum PlayableCharacterType + { + Sora, + Donald, + Goofy, + Mickey, + Auron, + PingMulan, + Aladdin, + Sparrow, + Beast, + Jack, + Simba, + Tron, + Riku + } + + public static Lvup Read(Stream stream) => BinaryMapping.ReadObject(stream); + + public void Write(Stream stream) => BinaryMapping.WriteObject(stream, this); + } +} diff --git a/OpenKh.Kh2/Battle/Plrp.cs b/OpenKh.Kh2/Battle/Plrp.cs index 59cf541ca..9c56c3587 100644 --- a/OpenKh.Kh2/Battle/Plrp.cs +++ b/OpenKh.Kh2/Battle/Plrp.cs @@ -1,27 +1,27 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Battle -{ - /// - /// Unfinished - /// - public class Plrp - { - [Data] public short Difficulty { get; set; } //??? - [Data] public byte Character { get; set; } //??? - [Data] public byte Hp { get; set; } - [Data] public byte Mp { get; set; } - [Data] public byte Ap { get; set; } - [Data] public short Unknown06 { get; set; } //Padding? - [Data] public short Unknown08 { get; set; } - [Data] public short Unknown0a { get; set; } - [Data(Count = 58)] public List Objects { get; set; } - - public static List Read(Stream stream) => BaseTable.Read(stream); - - public static void Write(Stream stream, IEnumerable items) => - BaseTable.Write(stream, 2, items); - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Battle +{ + /// + /// Unfinished + /// + public class Plrp + { + [Data] public short Difficulty { get; set; } //??? + [Data] public byte Character { get; set; } //??? + [Data] public byte Hp { get; set; } + [Data] public byte Mp { get; set; } + [Data] public byte Ap { get; set; } + [Data] public short Unknown06 { get; set; } //Padding? + [Data] public short Unknown08 { get; set; } + [Data] public short Unknown0a { get; set; } + [Data(Count = 58)] public List Objects { get; set; } + + public static List Read(Stream stream) => BaseTable.Read(stream); + + public static void Write(Stream stream, IEnumerable items) => + BaseTable.Write(stream, 2, items); + } +} diff --git a/OpenKh.Kh2/Battle/Przt.cs b/OpenKh.Kh2/Battle/Przt.cs index c85d3c070..39989f6d2 100644 --- a/OpenKh.Kh2/Battle/Przt.cs +++ b/OpenKh.Kh2/Battle/Przt.cs @@ -1,32 +1,32 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Battle -{ - public class Przt - { - [Data] public ushort Id { get; set; } - [Data] public byte SmallHpOrbs { get; set; } - [Data] public byte BigHpOrbs { get; set; } - [Data] public byte BigMoneyOrbs { get; set; } - [Data] public byte MediumMoneyOrbs { get; set; } - [Data] public byte SmallMoneyOrbs { get; set; } - [Data] public byte SmallMpOrbs { get; set; } - [Data] public byte BigMpOrbs { get; set; } - [Data] public byte SmallDriveOrbs { get; set; } - [Data] public byte BigDriveOrbs { get; set; } - [Data] public byte Unknown0a { get; set; } // Padding? - [Data] public ushort Item1 { get; set; } - [Data] public short Item1Percentage { get; set; } - [Data] public ushort Item2 { get; set; } - [Data] public short Item2Percentage { get; set; } - [Data] public ushort Item3 { get; set; } - [Data] public short Item3Percentage { get; set; } - - public static List Read(Stream stream) => BaseTable.Read(stream); - - public static void Write(Stream stream, IEnumerable items) => - BaseTable.Write(stream, 2, items); - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Battle +{ + public class Przt + { + [Data] public ushort Id { get; set; } + [Data] public byte SmallHpOrbs { get; set; } + [Data] public byte BigHpOrbs { get; set; } + [Data] public byte BigMoneyOrbs { get; set; } + [Data] public byte MediumMoneyOrbs { get; set; } + [Data] public byte SmallMoneyOrbs { get; set; } + [Data] public byte SmallMpOrbs { get; set; } + [Data] public byte BigMpOrbs { get; set; } + [Data] public byte SmallDriveOrbs { get; set; } + [Data] public byte BigDriveOrbs { get; set; } + [Data] public byte Unknown0a { get; set; } // Padding? + [Data] public ushort Item1 { get; set; } + [Data] public short Item1Percentage { get; set; } + [Data] public ushort Item2 { get; set; } + [Data] public short Item2Percentage { get; set; } + [Data] public ushort Item3 { get; set; } + [Data] public short Item3Percentage { get; set; } + + public static List Read(Stream stream) => BaseTable.Read(stream); + + public static void Write(Stream stream, IEnumerable items) => + BaseTable.Write(stream, 2, items); + } +} diff --git a/OpenKh.Kh2/Battle/Vtbl.cs b/OpenKh.Kh2/Battle/Vtbl.cs index 4385578f0..d16a19c94 100644 --- a/OpenKh.Kh2/Battle/Vtbl.cs +++ b/OpenKh.Kh2/Battle/Vtbl.cs @@ -1,26 +1,26 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Battle -{ - public class Vtbl - { - [Data] public byte CharacterId { get; set; } - [Data] public byte ActionId { get; set; } - [Data] public byte Priority { get; set; } - [Data] public byte Unknown03 { get; set; } //Padding? - [Data(Count = 5)] public List Voices { get; set; } - - public class Voice - { - [Data] public sbyte VsbIndex { get; set; } - [Data] public sbyte Weight { get; set; } //(0 = normal random; 100 = guaranteed run) - } - - public static List Read(Stream stream) => BaseTable.Read(stream); - - public static void Write(Stream stream, IEnumerable items) => - BaseTable.Write(stream, 1, items); - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Battle +{ + public class Vtbl + { + [Data] public byte CharacterId { get; set; } + [Data] public byte ActionId { get; set; } + [Data] public byte Priority { get; set; } + [Data] public byte Unknown03 { get; set; } //Padding? + [Data(Count = 5)] public List Voices { get; set; } + + public class Voice + { + [Data] public sbyte VsbIndex { get; set; } + [Data] public sbyte Weight { get; set; } //(0 = normal random; 100 = guaranteed run) + } + + public static List Read(Stream stream) => BaseTable.Read(stream); + + public static void Write(Stream stream, IEnumerable items) => + BaseTable.Write(stream, 1, items); + } +} diff --git a/OpenKh.Kh2/Coct.cs b/OpenKh.Kh2/Coct.cs index 3f7f5bfbf..696dcf3eb 100644 --- a/OpenKh.Kh2/Coct.cs +++ b/OpenKh.Kh2/Coct.cs @@ -1,23 +1,23 @@ -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; -using System.Numerics; +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; +using System.Numerics; using OpenKh.Kh2.Extensions; using OpenKh.Kh2.Utils; using System.Collections; -namespace OpenKh.Kh2 -{ +namespace OpenKh.Kh2 +{ /// /// Low level reader/writer of COCT - /// - public class Coct + /// + public class Coct { private class WriteCache : IEnumerable - { + { private readonly List _list = new List(); private readonly Dictionary _dictionary = new Dictionary(); private readonly Func _getKey; @@ -48,53 +48,53 @@ public void Add(TValue item) public IEnumerator GetEnumerator() => _list.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator(); - } - - private interface IData { } - - private const uint MagicCode = 0x54434F43; - private const int HeaderSize = 0x50; - private const int NodeSize = 0x20; - private const int MeshSize = 0x14; - private const int PolygonSize = 0x10; - private const int Col4Size = 0x10; - private const int Col5Size = 0x10; - private const int BoundingBoxSize = 0xC; + } + + private interface IData { } + + private const uint MagicCode = 0x54434F43; + private const int HeaderSize = 0x50; + private const int NodeSize = 0x20; + private const int MeshSize = 0x14; + private const int PolygonSize = 0x10; + private const int Col4Size = 0x10; + private const int Col5Size = 0x10; + private const int BoundingBoxSize = 0xC; private const int AttributesSize = 0x4; - private class Header - { - [Data] public uint MagicCode { get; set; } - [Data] public int Version { get; set; } - [Data] public int Depth { get; set; } - [Data] public int Type { get; set; } - [Data(Count = 8)] public Entry[] Entries { get; set; } - } - - private class Entry - { - [Data] public int Offset { get; set; } - [Data] public int Length { get; set; } - } - - public class RawNode : IData - { - [Data] public short Child1 { get; set; } = -1; - [Data] public short Child2 { get; set; } = -1; - [Data] public short Child3 { get; set; } = -1; - [Data] public short Child4 { get; set; } = -1; - [Data] public short Child5 { get; set; } = -1; - [Data] public short Child6 { get; set; } = -1; - [Data] public short Child7 { get; set; } = -1; - [Data] public short Child8 { get; set; } = -1; - [Data] public BoundingBoxInt16 BoundingBox { get; set; } - [Data] public ushort CollisionMeshStart { get; set; } - [Data] public ushort CollisionMeshEnd { get; set; } + private class Header + { + [Data] public uint MagicCode { get; set; } + [Data] public int Version { get; set; } + [Data] public int Depth { get; set; } + [Data] public int Type { get; set; } + [Data(Count = 8)] public Entry[] Entries { get; set; } + } + + private class Entry + { + [Data] public int Offset { get; set; } + [Data] public int Length { get; set; } + } + + public class RawNode : IData + { + [Data] public short Child1 { get; set; } = -1; + [Data] public short Child2 { get; set; } = -1; + [Data] public short Child3 { get; set; } = -1; + [Data] public short Child4 { get; set; } = -1; + [Data] public short Child5 { get; set; } = -1; + [Data] public short Child6 { get; set; } = -1; + [Data] public short Child7 { get; set; } = -1; + [Data] public short Child8 { get; set; } = -1; + [Data] public BoundingBoxInt16 BoundingBox { get; set; } + [Data] public ushort CollisionMeshStart { get; set; } + [Data] public ushort CollisionMeshEnd { get; set; } } private class RawCollision : IData { - [Data] public byte Ground { get; set; } + [Data] public byte Ground { get; set; } [Data] public byte FloorLevel { get; set; } [Data] public short Vertex1 { get; set; } [Data] public short Vertex2 { get; set; } @@ -103,92 +103,92 @@ private class RawCollision : IData [Data] public short PlaneIndex { get; set; } [Data] public short BoundingBoxIndex { get; set; } [Data] public short AttributeIndex { get; set; } - } - - private class RawCollisionMesh : IData - { - [Data] public BoundingBoxInt16 BoundingBox { get; set; } - [Data] public ushort CollisionStart { get; set; } - [Data] public ushort CollisionEnd { get; set; } - [Data] public byte Visibility { get; set; } - [Data] public byte Group { get; set; } - [Data] public short padding { get; set; } - } - - public class CollisionNode : IData - { - public short Child1 { get; set; } = -1; - public short Child2 { get; set; } = -1; - public short Child3 { get; set; } = -1; - public short Child4 { get; set; } = -1; - public short Child5 { get; set; } = -1; - public short Child6 { get; set; } = -1; - public short Child7 { get; set; } = -1; - public short Child8 { get; set; } = -1; - public BoundingBoxInt16 BoundingBox { get; set; } - public List Meshes { get; set; } - } - - public class CollisionMesh - { - public BoundingBoxInt16 BoundingBox { get; set; } - public List Collisions { get; set; } - public byte Visibility { get; set; } - public byte Group { get; set; } - } - - public class Collision : IData - { - public byte Ground { get; set; } - public byte FloorLevel { get; set; } - public short Vertex1 { get; set; } = -1; - public short Vertex2 { get; set; } = -1; - public short Vertex3 { get; set; } = -1; - public short Vertex4 { get; set; } = -1; - public Plane Plane { get; set; } - public BoundingBoxInt16 BoundingBox { get; set; } - public Attributes Attributes { get; set; } } - public class Attributes : IData - { - [Data] public int Flags { get; set; } - } - - public int Depth { get; set; } - public int Type { get; set; } - public List Nodes { get; } = new List(); - public List VertexList { get; } = new List(); - + private class RawCollisionMesh : IData + { + [Data] public BoundingBoxInt16 BoundingBox { get; set; } + [Data] public ushort CollisionStart { get; set; } + [Data] public ushort CollisionEnd { get; set; } + [Data] public byte Visibility { get; set; } + [Data] public byte Group { get; set; } + [Data] public short padding { get; set; } + } + + public class CollisionNode : IData + { + public short Child1 { get; set; } = -1; + public short Child2 { get; set; } = -1; + public short Child3 { get; set; } = -1; + public short Child4 { get; set; } = -1; + public short Child5 { get; set; } = -1; + public short Child6 { get; set; } = -1; + public short Child7 { get; set; } = -1; + public short Child8 { get; set; } = -1; + public BoundingBoxInt16 BoundingBox { get; set; } + public List Meshes { get; set; } + } + + public class CollisionMesh + { + public BoundingBoxInt16 BoundingBox { get; set; } + public List Collisions { get; set; } + public byte Visibility { get; set; } + public byte Group { get; set; } + } + + public class Collision : IData + { + public byte Ground { get; set; } + public byte FloorLevel { get; set; } + public short Vertex1 { get; set; } = -1; + public short Vertex2 { get; set; } = -1; + public short Vertex3 { get; set; } = -1; + public short Vertex4 { get; set; } = -1; + public Plane Plane { get; set; } + public BoundingBoxInt16 BoundingBox { get; set; } + public Attributes Attributes { get; set; } + } + + public class Attributes : IData + { + [Data] public int Flags { get; set; } + } + + public int Depth { get; set; } + public int Type { get; set; } + public List Nodes { get; } = new List(); + public List VertexList { get; } = new List(); + private readonly BuildHelper buildHelper; - + public Coct() { buildHelper = new BuildHelper(this); - } - - private Coct(Stream stream) - : this() - { - if (!IsValid(stream)) - throw new InvalidDataException("Invalid header"); - - var header = BinaryMapping.ReadObject
(stream.SetPosition(0)); - Depth = header.Depth; - Type = header.Type; - - var rawNodeList = ReactCoctEntry(stream, header.Entries[1], NodeSize); - var rawCollisionMeshList = ReactCoctEntry(stream, header.Entries[2], MeshSize); - var rawCollisionList = ReactCoctEntry(stream, header.Entries[3], PolygonSize); - VertexList = ReadValueEntry(stream, header.Entries[4], Col4Size, ReadVector4); - var planeList = ReadValueEntry(stream, header.Entries[5], Col5Size, ReadPlane); - var boundingBoxes = ReadValueEntry(stream, header.Entries[6], BoundingBoxSize, ReadBoundingBoxInt16); - var attributesList = ReactCoctEntry(stream, header.Entries[7], AttributesSize); - - var collisionList = rawCollisionList - .Select(x => new Collision + } + + private Coct(Stream stream) + : this() + { + if (!IsValid(stream)) + throw new InvalidDataException("Invalid header"); + + var header = BinaryMapping.ReadObject
(stream.SetPosition(0)); + Depth = header.Depth; + Type = header.Type; + + var rawNodeList = ReactCoctEntry(stream, header.Entries[1], NodeSize); + var rawCollisionMeshList = ReactCoctEntry(stream, header.Entries[2], MeshSize); + var rawCollisionList = ReactCoctEntry(stream, header.Entries[3], PolygonSize); + VertexList = ReadValueEntry(stream, header.Entries[4], Col4Size, ReadVector4); + var planeList = ReadValueEntry(stream, header.Entries[5], Col5Size, ReadPlane); + var boundingBoxes = ReadValueEntry(stream, header.Entries[6], BoundingBoxSize, ReadBoundingBoxInt16); + var attributesList = ReactCoctEntry(stream, header.Entries[7], AttributesSize); + + var collisionList = rawCollisionList + .Select(x => new Collision { - Ground = x.Ground, + Ground = x.Ground, FloorLevel = x.FloorLevel, Vertex1 = x.Vertex1, Vertex2 = x.Vertex2, @@ -197,11 +197,11 @@ private Coct(Stream stream) Plane = planeList[x.PlaneIndex], BoundingBox = x.BoundingBoxIndex >= 0 ? boundingBoxes[x.BoundingBoxIndex] : BoundingBoxInt16.Invalid, Attributes = attributesList[x.AttributeIndex], - }) - .ToList(); - - var collisionMeshList = rawCollisionMeshList - .Select(x => new CollisionMesh + }) + .ToList(); + + var collisionMeshList = rawCollisionMeshList + .Select(x => new CollisionMesh { BoundingBox = x.BoundingBox, Collisions = Enumerable.Range(x.CollisionStart, x.CollisionEnd - x.CollisionStart) @@ -209,11 +209,11 @@ private Coct(Stream stream) .ToList(), Visibility = x.Visibility, Group = x.Group - }) - .ToList(); - - Nodes = rawNodeList - .Select(x => new CollisionNode + }) + .ToList(); + + Nodes = rawNodeList + .Select(x => new CollisionNode { Child1 = x.Child1, Child2 = x.Child2, @@ -227,8 +227,8 @@ private Coct(Stream stream) Meshes = Enumerable.Range(x.CollisionMeshStart, x.CollisionMeshEnd - x.CollisionMeshStart) .Select(i => collisionMeshList[i]) .ToList(), - }) - .ToList(); + }) + .ToList(); } private BoundingBoxInt16 ReadBoundingBoxInt16(Stream arg) @@ -267,7 +267,7 @@ private Vector4 ReadVector4(Stream arg) ); } - public void Write(Stream stream) + public void Write(Stream stream) { var collisionList = new List(); var collisionMeshList = new List(); @@ -316,34 +316,34 @@ public void Write(Stream stream) var planeCache = new WriteCache(x => x.ToString()); foreach (var item in collisionList) - planeCache.Add(item.Plane); - - var entries = new List(8); - AddEntry(entries, HeaderSize, 1); - AddEntry(entries, Nodes.Count * NodeSize, 0x10); - AddEntry(entries, collisionMeshList.Count * MeshSize, 0x10); - AddEntry(entries, collisionList.Count * PolygonSize, 4); - AddEntry(entries, VertexList.Count * Col4Size, 0x10); - AddEntry(entries, planeCache.Count * Col5Size, 0x10); - AddEntry(entries, bbCache.Count * BoundingBoxSize, 0x10); - AddEntry(entries, surfaceCache.Count * AttributesSize, 4); - - stream.Position = 0; - BinaryMapping.WriteObject(stream, new Header - { - MagicCode = MagicCode, - Version = 1, - Depth = Depth, - Type = Type, - Entries = entries.ToArray() - }); - - WriteCoctEntry(stream, collisionMeshGroupList); - WriteCoctEntry(stream, collisionMeshList); - WriteCoctEntry(stream, collisionList - .Select(x => new RawCollision + planeCache.Add(item.Plane); + + var entries = new List(8); + AddEntry(entries, HeaderSize, 1); + AddEntry(entries, Nodes.Count * NodeSize, 0x10); + AddEntry(entries, collisionMeshList.Count * MeshSize, 0x10); + AddEntry(entries, collisionList.Count * PolygonSize, 4); + AddEntry(entries, VertexList.Count * Col4Size, 0x10); + AddEntry(entries, planeCache.Count * Col5Size, 0x10); + AddEntry(entries, bbCache.Count * BoundingBoxSize, 0x10); + AddEntry(entries, surfaceCache.Count * AttributesSize, 4); + + stream.Position = 0; + BinaryMapping.WriteObject(stream, new Header + { + MagicCode = MagicCode, + Version = 1, + Depth = Depth, + Type = Type, + Entries = entries.ToArray() + }); + + WriteCoctEntry(stream, collisionMeshGroupList); + WriteCoctEntry(stream, collisionMeshList); + WriteCoctEntry(stream, collisionList + .Select(x => new RawCollision { - Ground = x.Ground, + Ground = x.Ground, FloorLevel = x.FloorLevel, Vertex1 = x.Vertex1, Vertex2 = x.Vertex2, @@ -352,12 +352,12 @@ public void Write(Stream stream) PlaneIndex = planeCache[x.Plane], BoundingBoxIndex = bbCache[x.BoundingBox], AttributeIndex = surfaceCache[x.Attributes], - })); - stream.AlignPosition(0x10); - WriteValueEntry(stream, VertexList, WriteVector4); - WriteValueEntry(stream, planeCache, WritePlane); - WriteValueEntry(stream, bbCache, WriteBoundingBoxInt16); - WriteCoctEntry(stream, surfaceCache); + })); + stream.AlignPosition(0x10); + WriteValueEntry(stream, VertexList, WriteVector4); + WriteValueEntry(stream, planeCache, WritePlane); + WriteValueEntry(stream, bbCache, WriteBoundingBoxInt16); + WriteCoctEntry(stream, surfaceCache); } private void WriteBoundingBoxInt16(Stream arg1, BoundingBoxInt16 arg2) @@ -389,62 +389,62 @@ private void WriteVector4(Stream arg1, Vector4 arg2) writer.Write(arg2.W); } - private List ReactCoctEntry(Stream stream, Entry entry, int sizePerElement) - where T : class, IData => ReactCoctEntry(stream, entry.Offset, entry.Length / sizePerElement); - - private List ReactCoctEntry(Stream stream, int offset, int length) - where T : class, IData - { - stream.Position = offset; - return Enumerable.Range(0, length) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList(); - } - - private List ReadValueEntry(Stream stream, Entry entry, int sizePerElement, Func readFunc) - => ReadValueEntry(stream, entry.Offset, entry.Length / sizePerElement, readFunc); - - private List ReadValueEntry(Stream stream, int offset, int length, Func readFunc) - { - stream.Position = offset; - return Enumerable.Range(0, length) - .Select(_ => readFunc(stream)) - .ToList(); - } - - private void WriteCoctEntry(Stream stream, IEnumerable entries) - where T : class, IData - { - foreach (var entry in entries) - BinaryMapping.WriteObject(stream, entry); + private List ReactCoctEntry(Stream stream, Entry entry, int sizePerElement) + where T : class, IData => ReactCoctEntry(stream, entry.Offset, entry.Length / sizePerElement); + + private List ReactCoctEntry(Stream stream, int offset, int length) + where T : class, IData + { + stream.Position = offset; + return Enumerable.Range(0, length) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList(); + } + + private List ReadValueEntry(Stream stream, Entry entry, int sizePerElement, Func readFunc) + => ReadValueEntry(stream, entry.Offset, entry.Length / sizePerElement, readFunc); + + private List ReadValueEntry(Stream stream, int offset, int length, Func readFunc) + { + stream.Position = offset; + return Enumerable.Range(0, length) + .Select(_ => readFunc(stream)) + .ToList(); + } + + private void WriteCoctEntry(Stream stream, IEnumerable entries) + where T : class, IData + { + foreach (var entry in entries) + BinaryMapping.WriteObject(stream, entry); + } + + private void WriteValueEntry(Stream stream, IEnumerable entries, Action writeFunc) + { + foreach (var entry in entries) + writeFunc(stream, entry); + } + + private static void AddEntry(List entries, int newEntryLength, int alignment) + { + var lastEntry = entries.LastOrDefault(); + entries.Add(new Entry + { + Offset = Helpers.Align((lastEntry?.Offset + lastEntry?.Length) ?? 0, alignment), + Length = newEntryLength + }); + } + + public static bool IsValid(Stream stream) + { + if (stream.SetPosition(0).ReadInt32() != MagicCode || + stream.ReadInt32() != 1 || + stream.Length < 0x50) + return false; + + return true; } - private void WriteValueEntry(Stream stream, IEnumerable entries, Action writeFunc) - { - foreach (var entry in entries) - writeFunc(stream, entry); - } - - private static void AddEntry(List entries, int newEntryLength, int alignment) - { - var lastEntry = entries.LastOrDefault(); - entries.Add(new Entry - { - Offset = Helpers.Align((lastEntry?.Offset + lastEntry?.Length) ?? 0, alignment), - Length = newEntryLength - }); - } - - public static bool IsValid(Stream stream) - { - if (stream.SetPosition(0).ReadInt32() != MagicCode || - stream.ReadInt32() != 1 || - stream.Length < 0x50) - return false; - - return true; - } - public class BuildHelper { private readonly Coct coct; @@ -592,29 +592,29 @@ short ReverseChildIndex(short child) } } - public static Coct Read(Stream stream) => - new Coct(stream.SetPosition(0)); - + public static Coct Read(Stream stream) => + new Coct(stream.SetPosition(0)); + public Collision Complete(Collision it, int inflate = 0) { buildHelper.CompleteBBox(it, inflate); buildHelper.CompletePlane(it); return it; - } - + } + public CollisionMesh Complete(CollisionMesh it) { buildHelper.CompleteBBox(it); return it; - } - + } + public CollisionNode CompleteAndAdd(CollisionNode it) { buildHelper.CompleteBBox(it); Nodes.Add(it); return it; - } - - public void FlushCache() => buildHelper.FlushCache(); - } -} + } + + public void FlushCache() => buildHelper.FlushCache(); + } +} diff --git a/OpenKh.Kh2/Constants.cs b/OpenKh.Kh2/Constants.cs index 02e8f4569..2a5b7bffe 100644 --- a/OpenKh.Kh2/Constants.cs +++ b/OpenKh.Kh2/Constants.cs @@ -1,125 +1,125 @@ -namespace OpenKh.Kh2 -{ - public enum World - { - WorldZz, - EndOfSea, - TwilightTown, - DestinyIsland, - HollowBastion, - BeastCastle, - TheUnderworld, - Agrabah, - LandOfDragons, - HundredAcreWood, - PrideLands, - Atlantica, - DisneyCastle, - TimelessRiver, - HalloweenTown, - WorldMap, - PortRoyal, - SpaceParanoids, - WorldThatNeverWas - } - - public enum JiminyWorld - { - TwilightTown, - HollowBastion, - BeastCastle, - OlympusColiseum, - Agrabah, - LandOfDragons, - HundredAcreWood, - PrideLands, - Atlantica, - DisneyCastle, - TimelessRiver, - HalloweenTown, - PortRoyal, - SpaceParanoids, - WorldThatNeverWas, - Collection, - - //used in the character section - Other = 0x10, - Heartless = 0x11, - Nobody = 0x12, - } - - public static class Constants - { - public const int FontEuropeanSystemWidth = 18; - public const int FontEuropeanSystemHeight = 24; - public const int FontEuropeanEventWidth = 24; - public const int FontEuropeanEventHeight = 32; - public const int FontJapaneseSystemWidth = 18; - public const int FontJapaneseSystemHeight = 18; - public const int FontJapaneseEventWidth = 24; - public const int FontJapaneseEventHeight = 24; - public const int FontTableSystemHeight = 256; - public const int FontTableEventHeight = 512; - public const int FontIconWidth = 24; - public const int FontIconHeight = 24; - - public const int PaletteCount = 9; - public const int WorldCount = (int)World.WorldThatNeverWas + 1; - public const int MaxAreaPerWorldCount = 64; - public const int JiminyWorldCount = (int)JiminyWorld.Nobody + 1; - - public enum RegionId - { - Undefined, - Japanese, - UnitedStates, - UnitedKingdom, - Italian, - Spanish, - German, - French, - FinalMix, - MAX - } - - public static readonly string[] WorldIds = new string[WorldCount] - { - "zz", "es", "tt", "di", "hb", "bb", "he", "al", - "mu", "po", "lk", "lm", "dc", "wi", "nm", "wm", - "ca", "tr", "eh" - }; - - public static readonly string[] Regions = new string[(int)RegionId.MAX] - { - "", "jp", "us", "uk", "it", "sp", "gr", "fr", "fm" - }; - - public static readonly string[] Languages = new string[(int)RegionId.MAX] - { - "", "jp", "us", "us", "it", "sp", "gr", "fr", "jp" - }; - - public static readonly string[] WorldNames = new string[WorldCount] - { - "World ZZ", - "End of Sea", - "Twilight Town", - "Destiny Islands", - "Hollow Bastion", - "Beast's Castle", - "Olympus Coliseum", - "Agrabah", - "The Land of Dragons", - "100 Acre Wood", - "Pride Lands", - "Atlantica", - "Disney Castle", - "Timeless River", - "Halloween Town", - "World Map", - "Port Royal", - "Space Paranoids", - "World That Never Was" - }; - } -} +namespace OpenKh.Kh2 +{ + public enum World + { + WorldZz, + EndOfSea, + TwilightTown, + DestinyIsland, + HollowBastion, + BeastCastle, + TheUnderworld, + Agrabah, + LandOfDragons, + HundredAcreWood, + PrideLands, + Atlantica, + DisneyCastle, + TimelessRiver, + HalloweenTown, + WorldMap, + PortRoyal, + SpaceParanoids, + WorldThatNeverWas + } + + public enum JiminyWorld + { + TwilightTown, + HollowBastion, + BeastCastle, + OlympusColiseum, + Agrabah, + LandOfDragons, + HundredAcreWood, + PrideLands, + Atlantica, + DisneyCastle, + TimelessRiver, + HalloweenTown, + PortRoyal, + SpaceParanoids, + WorldThatNeverWas, + Collection, + + //used in the character section + Other = 0x10, + Heartless = 0x11, + Nobody = 0x12, + } + + public static class Constants + { + public const int FontEuropeanSystemWidth = 18; + public const int FontEuropeanSystemHeight = 24; + public const int FontEuropeanEventWidth = 24; + public const int FontEuropeanEventHeight = 32; + public const int FontJapaneseSystemWidth = 18; + public const int FontJapaneseSystemHeight = 18; + public const int FontJapaneseEventWidth = 24; + public const int FontJapaneseEventHeight = 24; + public const int FontTableSystemHeight = 256; + public const int FontTableEventHeight = 512; + public const int FontIconWidth = 24; + public const int FontIconHeight = 24; + + public const int PaletteCount = 9; + public const int WorldCount = (int)World.WorldThatNeverWas + 1; + public const int MaxAreaPerWorldCount = 64; + public const int JiminyWorldCount = (int)JiminyWorld.Nobody + 1; + + public enum RegionId + { + Undefined, + Japanese, + UnitedStates, + UnitedKingdom, + Italian, + Spanish, + German, + French, + FinalMix, + MAX + } + + public static readonly string[] WorldIds = new string[WorldCount] + { + "zz", "es", "tt", "di", "hb", "bb", "he", "al", + "mu", "po", "lk", "lm", "dc", "wi", "nm", "wm", + "ca", "tr", "eh" + }; + + public static readonly string[] Regions = new string[(int)RegionId.MAX] + { + "", "jp", "us", "uk", "it", "sp", "gr", "fr", "fm" + }; + + public static readonly string[] Languages = new string[(int)RegionId.MAX] + { + "", "jp", "us", "us", "it", "sp", "gr", "fr", "jp" + }; + + public static readonly string[] WorldNames = new string[WorldCount] + { + "World ZZ", + "End of Sea", + "Twilight Town", + "Destiny Islands", + "Hollow Bastion", + "Beast's Castle", + "Olympus Coliseum", + "Agrabah", + "The Land of Dragons", + "100 Acre Wood", + "Pride Lands", + "Atlantica", + "Disney Castle", + "Timeless River", + "Halloween Town", + "World Map", + "Port Royal", + "Space Paranoids", + "World That Never Was" + }; + } +} diff --git a/OpenKh.Kh2/Contextes/FontContext.cs b/OpenKh.Kh2/Contextes/FontContext.cs index f360b8e94..0105dd1b3 100644 --- a/OpenKh.Kh2/Contextes/FontContext.cs +++ b/OpenKh.Kh2/Contextes/FontContext.cs @@ -1,134 +1,134 @@ -using OpenKh.Imaging; -using OpenKh.Kh2.SystemData; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Kh2.Contextes -{ - public class FontContext - { - private IImageRead imageSystem; - private IImageRead imageSystem2; - private IImageRead imageEvent; - private IImageRead imageEvent2; - private IImageRead imageIcon; - private byte[] spacingSystem; - private byte[] spacingEvent; - private byte[] spacingIcon; - - public IImageRead ImageSystem { get => imageSystem; set => imageSystem = value; } - public IImageRead ImageSystem2 { get => imageSystem2; set => imageSystem2 = value; } - public IImageRead ImageEvent { get => imageEvent; set => imageEvent = value; } - public IImageRead ImageEvent2 { get => imageEvent2; set => imageEvent2 = value; } - public IImageRead ImageIcon { get => imageIcon; set => imageIcon = value; } - - public byte[] SpacingSystem { get => spacingSystem; set => spacingSystem = value; } - public byte[] SpacingEvent { get => spacingEvent; set => spacingEvent = value; } - public byte[] SpacingIcon { get => spacingIcon; set => spacingIcon = value; } - - public Dictionary palette; - - public void Read(IEnumerable entries) - { - foreach (var entry in entries) - { - switch (entry.Name) - { - case "sys": - ReadFont(entry, ref imageSystem, ref imageSystem2, ref spacingSystem); - break; - case "evt": - ReadFont(entry, ref imageEvent, ref imageEvent2, ref spacingEvent); - break; - case "icon": - ReadIcon(entry, ref imageIcon, ref spacingIcon, 256, 160); - break; - case "ftst": - if (entry.Type == Bar.EntryType.List) - palette = Ftst.Read(entry.Stream).ToDictionary(x => x.Id, x => x); - break; - } - } - } - - private void ReadFont(Bar.Entry entry, ref IImageRead image1, ref IImageRead image2, ref byte[] spacing) - { - switch (entry.Type) - { - case Bar.EntryType.List: - spacing = ReadSpacing(entry); - break; - case Bar.EntryType.RawBitmap: - entry.Stream.Position = 0; - image1 = ReadImagePalette1(entry); - entry.Stream.Position = 0; - image2 = ReadImagePalette2(entry); - break; - } - } - - private void ReadIcon(Bar.Entry entry, ref IImageRead image, ref byte[] spacing, int width, int height) - { - switch (entry.Type) - { - case Bar.EntryType.List: - spacing = ReadSpacing(entry); - break; - case Bar.EntryType.RawBitmap: - entry.Stream.Position = 0; - image = ReadImage8bit(entry, width, height); - break; - } - } - - private static byte[] ReadSpacing(Bar.Entry entry) - { - return new BinaryReader(entry.Stream).ReadBytes((int)entry.Stream.Length); - } - - private static IImageRead ReadImage8bit(Bar.Entry entry, int width, int height) - { - return RawBitmap.Read8bit(entry.Stream, width, height); - } - - private static IImageRead ReadImagePalette1(Bar.Entry entry) - { - DeductImageSize((int)entry.Stream.Length, out var width, out var height); - return RawBitmap.Read4bitPalette1(entry.Stream, width, height); - } - - private static IImageRead ReadImagePalette2(Bar.Entry entry) - { - DeductImageSize((int)entry.Stream.Length, out var width, out var height); - return RawBitmap.Read4bitPalette2(entry.Stream, width, height); - } - - private static bool DeductImageSize(int rawLength, out int width, out int height) - { - if (rawLength < 128 * 1024) - { - width = 512; - height = 256; - } - else if (rawLength < 256 * 1024) - { - width = 512; - height = 512; - } - else if (rawLength < 512 * 1024) - { - width = 512; - height = 1024; - } - else - { - width = 0; - height = 0; - return false; - } - - return true; - } - } -} +using OpenKh.Imaging; +using OpenKh.Kh2.SystemData; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Kh2.Contextes +{ + public class FontContext + { + private IImageRead imageSystem; + private IImageRead imageSystem2; + private IImageRead imageEvent; + private IImageRead imageEvent2; + private IImageRead imageIcon; + private byte[] spacingSystem; + private byte[] spacingEvent; + private byte[] spacingIcon; + + public IImageRead ImageSystem { get => imageSystem; set => imageSystem = value; } + public IImageRead ImageSystem2 { get => imageSystem2; set => imageSystem2 = value; } + public IImageRead ImageEvent { get => imageEvent; set => imageEvent = value; } + public IImageRead ImageEvent2 { get => imageEvent2; set => imageEvent2 = value; } + public IImageRead ImageIcon { get => imageIcon; set => imageIcon = value; } + + public byte[] SpacingSystem { get => spacingSystem; set => spacingSystem = value; } + public byte[] SpacingEvent { get => spacingEvent; set => spacingEvent = value; } + public byte[] SpacingIcon { get => spacingIcon; set => spacingIcon = value; } + + public Dictionary palette; + + public void Read(IEnumerable entries) + { + foreach (var entry in entries) + { + switch (entry.Name) + { + case "sys": + ReadFont(entry, ref imageSystem, ref imageSystem2, ref spacingSystem); + break; + case "evt": + ReadFont(entry, ref imageEvent, ref imageEvent2, ref spacingEvent); + break; + case "icon": + ReadIcon(entry, ref imageIcon, ref spacingIcon, 256, 160); + break; + case "ftst": + if (entry.Type == Bar.EntryType.List) + palette = Ftst.Read(entry.Stream).ToDictionary(x => x.Id, x => x); + break; + } + } + } + + private void ReadFont(Bar.Entry entry, ref IImageRead image1, ref IImageRead image2, ref byte[] spacing) + { + switch (entry.Type) + { + case Bar.EntryType.List: + spacing = ReadSpacing(entry); + break; + case Bar.EntryType.RawBitmap: + entry.Stream.Position = 0; + image1 = ReadImagePalette1(entry); + entry.Stream.Position = 0; + image2 = ReadImagePalette2(entry); + break; + } + } + + private void ReadIcon(Bar.Entry entry, ref IImageRead image, ref byte[] spacing, int width, int height) + { + switch (entry.Type) + { + case Bar.EntryType.List: + spacing = ReadSpacing(entry); + break; + case Bar.EntryType.RawBitmap: + entry.Stream.Position = 0; + image = ReadImage8bit(entry, width, height); + break; + } + } + + private static byte[] ReadSpacing(Bar.Entry entry) + { + return new BinaryReader(entry.Stream).ReadBytes((int)entry.Stream.Length); + } + + private static IImageRead ReadImage8bit(Bar.Entry entry, int width, int height) + { + return RawBitmap.Read8bit(entry.Stream, width, height); + } + + private static IImageRead ReadImagePalette1(Bar.Entry entry) + { + DeductImageSize((int)entry.Stream.Length, out var width, out var height); + return RawBitmap.Read4bitPalette1(entry.Stream, width, height); + } + + private static IImageRead ReadImagePalette2(Bar.Entry entry) + { + DeductImageSize((int)entry.Stream.Length, out var width, out var height); + return RawBitmap.Read4bitPalette2(entry.Stream, width, height); + } + + private static bool DeductImageSize(int rawLength, out int width, out int height) + { + if (rawLength < 128 * 1024) + { + width = 512; + height = 256; + } + else if (rawLength < 256 * 1024) + { + width = 512; + height = 512; + } + else if (rawLength < 512 * 1024) + { + width = 512; + height = 1024; + } + else + { + width = 0; + height = 0; + return false; + } + + return true; + } + } +} diff --git a/OpenKh.Kh2/Doct.cs b/OpenKh.Kh2/Doct.cs index 4c0f20aef..64bf890da 100644 --- a/OpenKh.Kh2/Doct.cs +++ b/OpenKh.Kh2/Doct.cs @@ -1,4 +1,4 @@ -using OpenKh.Common; +using OpenKh.Common; using OpenKh.Kh2.Extensions; using OpenKh.Kh2.Utils; using System; diff --git a/OpenKh.Kh2/Dpd.Texture.cs b/OpenKh.Kh2/Dpd.Texture.cs index 781cfae63..2f78848fc 100644 --- a/OpenKh.Kh2/Dpd.Texture.cs +++ b/OpenKh.Kh2/Dpd.Texture.cs @@ -1,136 +1,136 @@ -using System; -using System.Drawing; -using System.IO; - -namespace OpenKh.Kh2 -{ - public partial class Dpd - { - public class Texture - { - private short unk00; - private short unk02; - private short unk04; - private short format; - private short unk08; - private short unk0a; - private short width; - private short height; - private short unk10; - private short unk12; - private short unk14; - private short unk16; - private int unk18; - private int unk1c; - - public Texture() - { - - } - - internal Texture(BinaryReader reader) - { - var basePosition = reader.BaseStream.Position; - unk00 = reader.ReadInt16(); - unk02 = reader.ReadInt16(); - unk04 = reader.ReadInt16(); - format = reader.ReadInt16(); - unk08 = reader.ReadInt16(); - unk0a = reader.ReadInt16(); - width = reader.ReadInt16(); - height = reader.ReadInt16(); - unk10 = reader.ReadInt16(); - unk12 = reader.ReadInt16(); - unk14 = reader.ReadInt16(); - unk16 = reader.ReadInt16(); - unk18 = reader.ReadInt32(); - unk1c = reader.ReadInt32(); - - Data = reader.ReadBytes(width * height); - Palette = reader.ReadBytes(0x100 * sizeof(int)); - } - - internal void Write(BinaryWriter writer) - { - writer.Write(unk00); - writer.Write(unk02); - writer.Write(unk04); - writer.Write(format); - writer.Write(unk08); - writer.Write(unk0a); - writer.Write(width); - writer.Write(height); - writer.Write(unk10); - writer.Write(unk12); - writer.Write(unk14); - writer.Write(unk16); - writer.Write(unk18); - writer.Write(unk1c); - - writer.Write(Data); - writer.Write(Palette); - } - - public Size Size => new Size(width, height); - - public byte[] Data { get; } - - public byte[] Palette { get; } - - public byte[] GetBitmap() - { - var swizzled = 0; - - switch (format) - { - case 0x13: - return GetBitmapFrom8bpp( - swizzled == 7 ? Ps2.Decode8(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 64), Size.Width / 128, Size.Height / 64) : Data - , Palette, Size.Width, Size.Height); - case 0x14: - return GetBitmapFrom4bpp( - swizzled == 7 ? Ps2.Decode4(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 128), Size.Width / 128, Size.Height / 128) : Data - , Palette, Size.Width, Size.Height); - default: - throw new NotSupportedException($"The format {format} is not supported."); - } - } - - private static byte[] GetBitmapFrom8bpp(byte[] src, byte[] palette, int width, int height) - { - var dst = new byte[width * height * 4]; - for (int i = 0; i < dst.Length; i += 4) - { - var index = Ps2.Repl(src[i / 4]); - dst[i + 0] = (byte)Math.Max(0, palette[index * 4 + 2] * 2 - 1); - dst[i + 1] = (byte)Math.Max(0, palette[index * 4 + 1] * 2 - 1); - dst[i + 2] = (byte)Math.Max(0, palette[index * 4 + 0] * 2 - 1); - dst[i + 3] = (byte)Math.Max(0, palette[index * 4 + 3] * 2 - 1); - } - - return dst; - } - - private static byte[] GetBitmapFrom4bpp(byte[] src, byte[] palette, int width, int height) - { - var dst = new byte[width * height * 4]; - for (int i = 0; i < dst.Length; i += 8) - { - var index = src[i / 8] & 0x0F; - dst[i + 0] = palette[index * 4 + 0]; - dst[i + 1] = palette[index * 4 + 1]; - dst[i + 2] = palette[index * 4 + 2]; - dst[i + 3] = palette[index * 4 + 3]; - - index = src[i / 8] >> 4; - dst[i + 4] = palette[index * 4 + 0]; - dst[i + 5] = palette[index * 4 + 1]; - dst[i + 6] = palette[index * 4 + 2]; - dst[i + 7] = palette[index * 4 + 3]; - } - - return dst; - } - } - } -} +using System; +using System.Drawing; +using System.IO; + +namespace OpenKh.Kh2 +{ + public partial class Dpd + { + public class Texture + { + private short unk00; + private short unk02; + private short unk04; + private short format; + private short unk08; + private short unk0a; + private short width; + private short height; + private short unk10; + private short unk12; + private short unk14; + private short unk16; + private int unk18; + private int unk1c; + + public Texture() + { + + } + + internal Texture(BinaryReader reader) + { + var basePosition = reader.BaseStream.Position; + unk00 = reader.ReadInt16(); + unk02 = reader.ReadInt16(); + unk04 = reader.ReadInt16(); + format = reader.ReadInt16(); + unk08 = reader.ReadInt16(); + unk0a = reader.ReadInt16(); + width = reader.ReadInt16(); + height = reader.ReadInt16(); + unk10 = reader.ReadInt16(); + unk12 = reader.ReadInt16(); + unk14 = reader.ReadInt16(); + unk16 = reader.ReadInt16(); + unk18 = reader.ReadInt32(); + unk1c = reader.ReadInt32(); + + Data = reader.ReadBytes(width * height); + Palette = reader.ReadBytes(0x100 * sizeof(int)); + } + + internal void Write(BinaryWriter writer) + { + writer.Write(unk00); + writer.Write(unk02); + writer.Write(unk04); + writer.Write(format); + writer.Write(unk08); + writer.Write(unk0a); + writer.Write(width); + writer.Write(height); + writer.Write(unk10); + writer.Write(unk12); + writer.Write(unk14); + writer.Write(unk16); + writer.Write(unk18); + writer.Write(unk1c); + + writer.Write(Data); + writer.Write(Palette); + } + + public Size Size => new Size(width, height); + + public byte[] Data { get; } + + public byte[] Palette { get; } + + public byte[] GetBitmap() + { + var swizzled = 0; + + switch (format) + { + case 0x13: + return GetBitmapFrom8bpp( + swizzled == 7 ? Ps2.Decode8(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 64), Size.Width / 128, Size.Height / 64) : Data + , Palette, Size.Width, Size.Height); + case 0x14: + return GetBitmapFrom4bpp( + swizzled == 7 ? Ps2.Decode4(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 128), Size.Width / 128, Size.Height / 128) : Data + , Palette, Size.Width, Size.Height); + default: + throw new NotSupportedException($"The format {format} is not supported."); + } + } + + private static byte[] GetBitmapFrom8bpp(byte[] src, byte[] palette, int width, int height) + { + var dst = new byte[width * height * 4]; + for (int i = 0; i < dst.Length; i += 4) + { + var index = Ps2.Repl(src[i / 4]); + dst[i + 0] = (byte)Math.Max(0, palette[index * 4 + 2] * 2 - 1); + dst[i + 1] = (byte)Math.Max(0, palette[index * 4 + 1] * 2 - 1); + dst[i + 2] = (byte)Math.Max(0, palette[index * 4 + 0] * 2 - 1); + dst[i + 3] = (byte)Math.Max(0, palette[index * 4 + 3] * 2 - 1); + } + + return dst; + } + + private static byte[] GetBitmapFrom4bpp(byte[] src, byte[] palette, int width, int height) + { + var dst = new byte[width * height * 4]; + for (int i = 0; i < dst.Length; i += 8) + { + var index = src[i / 8] & 0x0F; + dst[i + 0] = palette[index * 4 + 0]; + dst[i + 1] = palette[index * 4 + 1]; + dst[i + 2] = palette[index * 4 + 2]; + dst[i + 3] = palette[index * 4 + 3]; + + index = src[i / 8] >> 4; + dst[i + 4] = palette[index * 4 + 0]; + dst[i + 5] = palette[index * 4 + 1]; + dst[i + 6] = palette[index * 4 + 2]; + dst[i + 7] = palette[index * 4 + 3]; + } + + return dst; + } + } + } +} diff --git a/OpenKh.Kh2/Dpd.cs b/OpenKh.Kh2/Dpd.cs index 9bcbf3522..5d06b81ed 100644 --- a/OpenKh.Kh2/Dpd.cs +++ b/OpenKh.Kh2/Dpd.cs @@ -1,154 +1,154 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.IO; - -namespace OpenKh.Kh2 -{ - public partial class Dpd - { - private const uint Version = 0x00000096U; - - public List OffsetPdt { get; set; } - public List OffsetTextures { get; set; } - public List Offset3 { get; set; } - public List Offset4 { get; set; } - public List Offset5 { get; set; } - - public Dpd(Stream stream) - { - if (!stream.CanRead || !stream.CanSeek) - throw new InvalidDataException($"Read or seek must be supported."); - - var reader = new BinaryReader(stream); - if (stream.Length < 16L || reader.ReadUInt32() != Version) - throw new InvalidDataException("Invalid header"); - - // dpd_h_init_datainfo - OffsetPdt = ReadOffsetsList(reader); - OffsetTextures = ReadOffsetsList(reader); - Offset3 = ReadOffsetsList(reader); - Offset4 = ReadOffsetsList(reader); - Offset5 = ReadOffsetsList(reader); - - // pppInitPdt - // OffsetPdt, Table 1 - foreach (var offset in OffsetPdt) - { - // 9648E0 - pppInitPdt(reader, offset, 0x354BF0); - } - - Textures = OffsetTextures - .Select(x => new Texture(new BinaryReader(new SubStream(reader.BaseStream, x, 0)))); - } - - public IEnumerable Textures { get; } - - private void pppInitPdt(BinaryReader reader, int offset, int unk) - { - int a0, a1, a2, a3, a4, a5, a6, a7; - int t0, t1, t2, t3, t4, t5, t6, t7; - int v0, v1, v2, v3; - // a0 = offset - // a1 = unk - - a1 = unk; - a0 = offset + 0x110; - t7 = ReadInt32(reader, a0 + 0x08); - t4 = a0 + 0x10; - t6 = ReadInt32(reader, a0 + 0x0C); - t0 = a0 + t7; - - a3 = a0 + t6; - t5 = ReadInt32(reader, t4); - a2 = ReadInt32(reader, t0); - v1 = ReadInt32(reader, a3); - t0 += 4; - - if (t5 != 0) - { - do - { - t7 = a0 + ReadInt32(reader, t4); - var count = ReadInt16(reader, t4 + 0x26); - // sw $t7, 0($t4) - - for (var i = 0; i < count; i++) - { - t5 = a1 + ReadInt32(reader, t4 + i * 0x10 + 0x28) * 0x48; - t6 = a0 + ReadInt32(reader, t4 + i * 0x10 + 0x30); - t7 = a0 + ReadInt32(reader, t4 + i * 0x10 + 0x34); - // sw $t5, 0x28($t4) - // sw $t6, 0x30($t4) - // sw $t7, 0x34($t4) - } - - t6 = a0 + ReadInt32(reader, t4); - t7 = ReadInt32(reader, t6); - t4 = t6; - } while (t7 != 0); - - // sw $zero, 0($t4) - for (var i = 0; i < a2; i++) - { - t7 = a1 + ReadInt32(reader, t0 + i * 4) * 0x48; - // sw $t7, 0($t5) - } - - t5 = a3; - t4 = v1; - - do - { - t7 = ReadInt32(reader, t5); - t4--; - t7 += a0; - // sw $t7, 0($t5) - t5 += 4; - } while (t4 != 0); - } - } - - - private List ReadOffsetsList(BinaryReader reader) - { - int count = reader.ReadInt32(); - var list = new List(count); - - for (int i = 0; i < count; i++) - { - list.Add(reader.ReadInt32()); - } - - return list; - } - - private void WriteOffsetsList(BinaryWriter writer, List list) - { - writer.Write(list.Count); - for (int i = 0; i < list.Count; i++) - { - writer.Write(list[i]); - } - } - - public int ReadInt16(BinaryReader reader, int offset) - { - var old = reader.BaseStream.Position; - reader.BaseStream.Position = offset; - var data = reader.ReadInt16(); - reader.BaseStream.Position = old; - return data; - } - - public int ReadInt32(BinaryReader reader, int offset) - { - var old = reader.BaseStream.Position; - reader.BaseStream.Position = offset; - var data = reader.ReadInt32(); - reader.BaseStream.Position = old; - return data; - } - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.IO; + +namespace OpenKh.Kh2 +{ + public partial class Dpd + { + private const uint Version = 0x00000096U; + + public List OffsetPdt { get; set; } + public List OffsetTextures { get; set; } + public List Offset3 { get; set; } + public List Offset4 { get; set; } + public List Offset5 { get; set; } + + public Dpd(Stream stream) + { + if (!stream.CanRead || !stream.CanSeek) + throw new InvalidDataException($"Read or seek must be supported."); + + var reader = new BinaryReader(stream); + if (stream.Length < 16L || reader.ReadUInt32() != Version) + throw new InvalidDataException("Invalid header"); + + // dpd_h_init_datainfo + OffsetPdt = ReadOffsetsList(reader); + OffsetTextures = ReadOffsetsList(reader); + Offset3 = ReadOffsetsList(reader); + Offset4 = ReadOffsetsList(reader); + Offset5 = ReadOffsetsList(reader); + + // pppInitPdt + // OffsetPdt, Table 1 + foreach (var offset in OffsetPdt) + { + // 9648E0 + pppInitPdt(reader, offset, 0x354BF0); + } + + Textures = OffsetTextures + .Select(x => new Texture(new BinaryReader(new SubStream(reader.BaseStream, x, 0)))); + } + + public IEnumerable Textures { get; } + + private void pppInitPdt(BinaryReader reader, int offset, int unk) + { + int a0, a1, a2, a3, a4, a5, a6, a7; + int t0, t1, t2, t3, t4, t5, t6, t7; + int v0, v1, v2, v3; + // a0 = offset + // a1 = unk + + a1 = unk; + a0 = offset + 0x110; + t7 = ReadInt32(reader, a0 + 0x08); + t4 = a0 + 0x10; + t6 = ReadInt32(reader, a0 + 0x0C); + t0 = a0 + t7; + + a3 = a0 + t6; + t5 = ReadInt32(reader, t4); + a2 = ReadInt32(reader, t0); + v1 = ReadInt32(reader, a3); + t0 += 4; + + if (t5 != 0) + { + do + { + t7 = a0 + ReadInt32(reader, t4); + var count = ReadInt16(reader, t4 + 0x26); + // sw $t7, 0($t4) + + for (var i = 0; i < count; i++) + { + t5 = a1 + ReadInt32(reader, t4 + i * 0x10 + 0x28) * 0x48; + t6 = a0 + ReadInt32(reader, t4 + i * 0x10 + 0x30); + t7 = a0 + ReadInt32(reader, t4 + i * 0x10 + 0x34); + // sw $t5, 0x28($t4) + // sw $t6, 0x30($t4) + // sw $t7, 0x34($t4) + } + + t6 = a0 + ReadInt32(reader, t4); + t7 = ReadInt32(reader, t6); + t4 = t6; + } while (t7 != 0); + + // sw $zero, 0($t4) + for (var i = 0; i < a2; i++) + { + t7 = a1 + ReadInt32(reader, t0 + i * 4) * 0x48; + // sw $t7, 0($t5) + } + + t5 = a3; + t4 = v1; + + do + { + t7 = ReadInt32(reader, t5); + t4--; + t7 += a0; + // sw $t7, 0($t5) + t5 += 4; + } while (t4 != 0); + } + } + + + private List ReadOffsetsList(BinaryReader reader) + { + int count = reader.ReadInt32(); + var list = new List(count); + + for (int i = 0; i < count; i++) + { + list.Add(reader.ReadInt32()); + } + + return list; + } + + private void WriteOffsetsList(BinaryWriter writer, List list) + { + writer.Write(list.Count); + for (int i = 0; i < list.Count; i++) + { + writer.Write(list[i]); + } + } + + public int ReadInt16(BinaryReader reader, int offset) + { + var old = reader.BaseStream.Position; + reader.BaseStream.Position = offset; + var data = reader.ReadInt16(); + reader.BaseStream.Position = old; + return data; + } + + public int ReadInt32(BinaryReader reader, int offset) + { + var old = reader.BaseStream.Position; + reader.BaseStream.Position = offset; + var data = reader.ReadInt32(); + reader.BaseStream.Position = old; + return data; + } + } +} diff --git a/OpenKh.Kh2/Dpx.Models.cs b/OpenKh.Kh2/Dpx.Models.cs index 720b39c0b..54a387ead 100644 --- a/OpenKh.Kh2/Dpx.Models.cs +++ b/OpenKh.Kh2/Dpx.Models.cs @@ -1,6 +1,6 @@ -namespace OpenKh.Kh2 -{ - public partial class Dpx - { - } -} +namespace OpenKh.Kh2 +{ + public partial class Dpx + { + } +} diff --git a/OpenKh.Kh2/Dpx.cs b/OpenKh.Kh2/Dpx.cs index 720b39c0b..54a387ead 100644 --- a/OpenKh.Kh2/Dpx.cs +++ b/OpenKh.Kh2/Dpx.cs @@ -1,6 +1,6 @@ -namespace OpenKh.Kh2 -{ - public partial class Dpx - { - } -} +namespace OpenKh.Kh2 +{ + public partial class Dpx + { + } +} diff --git a/OpenKh.Kh2/Extensions/BarExtensions.cs b/OpenKh.Kh2/Extensions/BarExtensions.cs index 60569cf2f..b772823c9 100644 --- a/OpenKh.Kh2/Extensions/BarExtensions.cs +++ b/OpenKh.Kh2/Extensions/BarExtensions.cs @@ -1,97 +1,97 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Kh2.Extensions -{ - public static class BarExtensions - { - public static IEnumerable ForEntry(this IEnumerable entries, Bar.EntryType type, string name, int index, Action funcEntry) - { - var entry = entries.FirstOrDefault(x => x.Type == type && x.Name == name && x.Index == index); - if (entry == null) - { - entry = new Bar.Entry - { - Type = type, - Name = name, - Index = index, - Stream = new MemoryStream() - }; - - entries = entries.Concat(new Bar.Entry[] { entry }); - } - - funcEntry(entry); - return entries; - } - - public static IEnumerable AddOrReplace( - this IEnumerable entries, Bar.Entry entry) - { - var existingEntry = entries - .FirstOrDefault(x => x.Type == entry.Type && x.Name == entry.Name && x.Index == 0); - if (existingEntry == null) - { - entries = entries.Concat(new Bar.Entry[] { - new Bar.Entry - { - Type = entry.Type, - Name = entry.Name, - Index = 0, - Stream = entry.Stream - } - }); - } - else - existingEntry.Stream = entry.Stream; - - return entries; - } - - public static bool ForEntry(this IEnumerable entries, string name, Bar.EntryType type, Action action) - { - var entry = entries.FirstOrDefault(x => x.Type == type && x.Name == name); - if (entry == null) - return false; - - entry.Stream.Seek(0, SeekOrigin.Begin); - action(entry.Stream); - return true; - } - - public static T ForEntry(this IEnumerable entries, string name, Bar.EntryType type, Func action) => - entries.ForEntry(x => x.Type == type && x.Name == name, action); - - public static T ForEntry(this IEnumerable entries, Func predicate, Func action) - { - var entry = entries.FirstOrDefault(predicate); - if (entry == null) - return default; - - entry.Stream.Seek(0, SeekOrigin.Begin); - return action(entry.Stream); - } - - public static int ForEntries(this IEnumerable entries, string name, Bar.EntryType type, Action action) - { - var itemFound = 0; - foreach (var entry in entries.Where(x => x.Type == type && x.Name == name)) - { - entry.Stream.Seek(0, SeekOrigin.Begin); - action(entry.Stream); - itemFound++; - } - - return itemFound; - } - - public static IEnumerable ForEntries(this IEnumerable entries, string name, Bar.EntryType type, Func action) => - entries.Where(x => x.Type == type && x.Name == name).Select(x => - { - x.Stream.Seek(0, SeekOrigin.Begin); - return action(x.Stream); - }); - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Kh2.Extensions +{ + public static class BarExtensions + { + public static IEnumerable ForEntry(this IEnumerable entries, Bar.EntryType type, string name, int index, Action funcEntry) + { + var entry = entries.FirstOrDefault(x => x.Type == type && x.Name == name && x.Index == index); + if (entry == null) + { + entry = new Bar.Entry + { + Type = type, + Name = name, + Index = index, + Stream = new MemoryStream() + }; + + entries = entries.Concat(new Bar.Entry[] { entry }); + } + + funcEntry(entry); + return entries; + } + + public static IEnumerable AddOrReplace( + this IEnumerable entries, Bar.Entry entry) + { + var existingEntry = entries + .FirstOrDefault(x => x.Type == entry.Type && x.Name == entry.Name && x.Index == 0); + if (existingEntry == null) + { + entries = entries.Concat(new Bar.Entry[] { + new Bar.Entry + { + Type = entry.Type, + Name = entry.Name, + Index = 0, + Stream = entry.Stream + } + }); + } + else + existingEntry.Stream = entry.Stream; + + return entries; + } + + public static bool ForEntry(this IEnumerable entries, string name, Bar.EntryType type, Action action) + { + var entry = entries.FirstOrDefault(x => x.Type == type && x.Name == name); + if (entry == null) + return false; + + entry.Stream.Seek(0, SeekOrigin.Begin); + action(entry.Stream); + return true; + } + + public static T ForEntry(this IEnumerable entries, string name, Bar.EntryType type, Func action) => + entries.ForEntry(x => x.Type == type && x.Name == name, action); + + public static T ForEntry(this IEnumerable entries, Func predicate, Func action) + { + var entry = entries.FirstOrDefault(predicate); + if (entry == null) + return default; + + entry.Stream.Seek(0, SeekOrigin.Begin); + return action(entry.Stream); + } + + public static int ForEntries(this IEnumerable entries, string name, Bar.EntryType type, Action action) + { + var itemFound = 0; + foreach (var entry in entries.Where(x => x.Type == type && x.Name == name)) + { + entry.Stream.Seek(0, SeekOrigin.Begin); + action(entry.Stream); + itemFound++; + } + + return itemFound; + } + + public static IEnumerable ForEntries(this IEnumerable entries, string name, Bar.EntryType type, Func action) => + entries.Where(x => x.Type == type && x.Name == name).Select(x => + { + x.Stream.Seek(0, SeekOrigin.Begin); + return action(x.Stream); + }); + } +} diff --git a/OpenKh.Kh2/Extensions/BoundingBoxExtensions.cs b/OpenKh.Kh2/Extensions/BoundingBoxExtensions.cs index 08b2071d6..3567ff028 100644 --- a/OpenKh.Kh2/Extensions/BoundingBoxExtensions.cs +++ b/OpenKh.Kh2/Extensions/BoundingBoxExtensions.cs @@ -1,4 +1,4 @@ -using OpenKh.Kh2.Utils; +using OpenKh.Kh2.Utils; using System; using System.Collections.Generic; using System.Linq; diff --git a/OpenKh.Kh2/Extensions/BoundingBoxInt16Extensions.cs b/OpenKh.Kh2/Extensions/BoundingBoxInt16Extensions.cs index 0753dc7ec..6d221f756 100644 --- a/OpenKh.Kh2/Extensions/BoundingBoxInt16Extensions.cs +++ b/OpenKh.Kh2/Extensions/BoundingBoxInt16Extensions.cs @@ -1,4 +1,4 @@ -using OpenKh.Kh2.Utils; +using OpenKh.Kh2.Utils; using System; using System.Collections.Generic; using System.Linq; diff --git a/OpenKh.Kh2/Extensions/ImageReadExtensions.cs b/OpenKh.Kh2/Extensions/ImageReadExtensions.cs index f4b6d0e89..73c5eda22 100644 --- a/OpenKh.Kh2/Extensions/ImageReadExtensions.cs +++ b/OpenKh.Kh2/Extensions/ImageReadExtensions.cs @@ -1,10 +1,10 @@ -using OpenKh.Imaging; +using OpenKh.Imaging; using System; -namespace OpenKh.Kh2.Extensions -{ - public static class ImageReadExtensions - { +namespace OpenKh.Kh2.Extensions +{ + public static class ImageReadExtensions + { public static Imgd AsImgd(this IImageRead image, bool isSwizzled = false) { if (image is Imgd imgd) @@ -36,5 +36,5 @@ private static byte[] GetAsRGBA(byte[] inData) } return outData; } - } -} + } +} diff --git a/OpenKh.Kh2/Extensions/LayoutExtensions.cs b/OpenKh.Kh2/Extensions/LayoutExtensions.cs index b03328c6f..f44f321b8 100644 --- a/OpenKh.Kh2/Extensions/LayoutExtensions.cs +++ b/OpenKh.Kh2/Extensions/LayoutExtensions.cs @@ -1,45 +1,45 @@ -using OpenKh.Common; -using System; -using System.Drawing; -using System.Linq; - -namespace OpenKh.Kh2.Extensions -{ - public static class LayoutExtensions - { - public static Rectangle GetVisibilityRectangleFromSequenceGroup( - this Layout layout, int sequenceGroupIndex) - { - var sgi = layout.SequenceGroups[sequenceGroupIndex]; - return sgi.Sequences.Aggregate(new Rectangle(), - (rect, x) => rect.Union(layout.GetVisibilityRectangleFromSequenceProperty(x))); - } - - public static int GetFrameLengthFromSequenceGroup( - this Layout layout, int sequenceGroupIndex) - { - var sgi = layout.SequenceGroups[sequenceGroupIndex]; - return sgi.Sequences.Aggregate(0, - (len, x) => Math.Max(len, layout.GetFrameLengthFromSequenceProperty(x))); - } - - public static Rectangle GetVisibilityRectangleFromSequenceProperty( - this Layout layout, Layout.SequenceProperty sequenceProperty) - { - var sequence = layout.SequenceItems[sequenceProperty.SequenceIndex]; - var animGroup = sequence.AnimationGroups[sequenceProperty.AnimationGroup]; - - return sequence.GetVisibilityRectangleFromAnimationGroup(animGroup) - .Traslate(sequenceProperty.PositionX, sequenceProperty.PositionY); - } - - public static int GetFrameLengthFromSequenceProperty( - this Layout layout, Layout.SequenceProperty sequenceProperty) - { - var sequence = layout.SequenceItems[sequenceProperty.SequenceIndex]; - var animGroup = sequence.AnimationGroups[sequenceProperty.AnimationGroup]; - - return animGroup.GetFrameLength() + sequenceProperty.ShowAtFrame; - } - } -} +using OpenKh.Common; +using System; +using System.Drawing; +using System.Linq; + +namespace OpenKh.Kh2.Extensions +{ + public static class LayoutExtensions + { + public static Rectangle GetVisibilityRectangleFromSequenceGroup( + this Layout layout, int sequenceGroupIndex) + { + var sgi = layout.SequenceGroups[sequenceGroupIndex]; + return sgi.Sequences.Aggregate(new Rectangle(), + (rect, x) => rect.Union(layout.GetVisibilityRectangleFromSequenceProperty(x))); + } + + public static int GetFrameLengthFromSequenceGroup( + this Layout layout, int sequenceGroupIndex) + { + var sgi = layout.SequenceGroups[sequenceGroupIndex]; + return sgi.Sequences.Aggregate(0, + (len, x) => Math.Max(len, layout.GetFrameLengthFromSequenceProperty(x))); + } + + public static Rectangle GetVisibilityRectangleFromSequenceProperty( + this Layout layout, Layout.SequenceProperty sequenceProperty) + { + var sequence = layout.SequenceItems[sequenceProperty.SequenceIndex]; + var animGroup = sequence.AnimationGroups[sequenceProperty.AnimationGroup]; + + return sequence.GetVisibilityRectangleFromAnimationGroup(animGroup) + .Traslate(sequenceProperty.PositionX, sequenceProperty.PositionY); + } + + public static int GetFrameLengthFromSequenceProperty( + this Layout layout, Layout.SequenceProperty sequenceProperty) + { + var sequence = layout.SequenceItems[sequenceProperty.SequenceIndex]; + var animGroup = sequence.AnimationGroups[sequenceProperty.AnimationGroup]; + + return animGroup.GetFrameLength() + sequenceProperty.ShowAtFrame; + } + } +} diff --git a/OpenKh.Kh2/Extensions/SequenceExtensions.cs b/OpenKh.Kh2/Extensions/SequenceExtensions.cs index 049b81397..c22b9c1a7 100644 --- a/OpenKh.Kh2/Extensions/SequenceExtensions.cs +++ b/OpenKh.Kh2/Extensions/SequenceExtensions.cs @@ -1,97 +1,97 @@ -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; - -namespace OpenKh.Kh2.Extensions -{ - public static class SequenceExtensions - { - public static Rectangle GetVisibilityRectangleFromAnimationGroup( - this Sequence sequence, Sequence.AnimationGroup animGroup) => - animGroup.Animations.Aggregate(new Rectangle(), (rect, x) => rect.Union(sequence.GetVisibilityRectangleFromAnimation(x))); - - public static int GetFrameLength(this Sequence.AnimationGroup animGroup) => - animGroup.Animations.Aggregate(0, (length, anim) => Math.Max(length, anim.FrameEnd)); - - public static Rectangle GetVisibilityRectangleFromAnimation( - this Sequence sequence, Sequence.Animation animation) - { - var rect = sequence.GetVisibilityRectangleForFrameGroup(animation.SpriteGroupIndex); - - var minXPos = animation.TranslateXStart; - int maxXPos = animation.TranslateXEnd; - var minYPos = animation.TranslateYStart; - int maxYPos = animation.TranslateYEnd; - var minXScale = animation.ScaleStart * animation.ScaleXStart; - var maxXScale = animation.ScaleEnd * animation.ScaleXEnd; - var minYScale = animation.ScaleStart * animation.ScaleYStart; - var maxYScale = animation.ScaleEnd * animation.ScaleYEnd; - - var minRect = rect - .Multiply(minXScale, minYScale) - .Traslate(minXPos, minYPos); - - var maxRect = rect - .Multiply(maxXScale, maxYScale) - .Traslate(maxXPos, maxYPos); - - return minRect.Union(maxRect); - } - - public static Rectangle GetVisibilityRectangleForFrameGroup(this Sequence sequence, int frameGroupIndex) => - sequence.SpriteGroups[frameGroupIndex].GetVisibilityRectangleForFrameGroup(); - - public static Rectangle GetVisibilityRectangleForFrameGroup(this List spriteGroup) => - spriteGroup.Aggregate(new Rectangle(), (rect, x) => rect.Union(x.GetVisibilityRectangle())); - - public static Rectangle GetVisibilityRectangle( - this Sequence.SpritePart frameEx) => Rectangle.FromLTRB( - frameEx.Left, - frameEx.Top, - frameEx.Right, - frameEx.Bottom); - - public static Sequence.Animation Clone(this Sequence.Animation anim) => new Sequence.Animation - { - Flags = anim.Flags, - SpriteGroupIndex = anim.SpriteGroupIndex, - FrameStart = anim.FrameStart, - FrameEnd = anim.FrameEnd, - TranslateXStart = anim.TranslateXStart, - TranslateXEnd = anim.TranslateXEnd, - TranslateYStart = anim.TranslateYStart, - TranslateYEnd = anim.TranslateYEnd, - PivotXStart = anim.PivotXStart, - PivotXEnd = anim.PivotXEnd, - PivotYStart = anim.PivotYStart, - PivotYEnd = anim.PivotYEnd, - RotationXStart = anim.RotationXStart, - RotationXEnd = anim.RotationXEnd, - RotationYStart = anim.RotationYStart, - RotationYEnd = anim.RotationYEnd, - RotationZStart = anim.RotationZStart, - RotationZEnd = anim.RotationZEnd, - ScaleStart = anim.ScaleStart, - ScaleEnd = anim.ScaleEnd, - ScaleXStart = anim.ScaleXStart, - ScaleXEnd = anim.ScaleXEnd, - ScaleYStart = anim.ScaleYStart, - ScaleYEnd = anim.ScaleYEnd, - CurveXStart = anim.CurveXStart, - CurveYStart = anim.CurveYStart, - CurveXEnd = anim.CurveXEnd, - CurveYEnd = anim.CurveYEnd, - BounceXStart = anim.BounceXStart, - BounceXEnd = anim.BounceXEnd, - BounceYStart = anim.BounceYStart, - BounceYEnd = anim.BounceYEnd, - BounceXCount = anim.BounceXCount, - BounceYCount = anim.BounceYCount, - ColorBlend = anim.ColorBlend, - ColorStart = anim.ColorStart, - ColorEnd = anim.ColorEnd, - }; - } -} +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; + +namespace OpenKh.Kh2.Extensions +{ + public static class SequenceExtensions + { + public static Rectangle GetVisibilityRectangleFromAnimationGroup( + this Sequence sequence, Sequence.AnimationGroup animGroup) => + animGroup.Animations.Aggregate(new Rectangle(), (rect, x) => rect.Union(sequence.GetVisibilityRectangleFromAnimation(x))); + + public static int GetFrameLength(this Sequence.AnimationGroup animGroup) => + animGroup.Animations.Aggregate(0, (length, anim) => Math.Max(length, anim.FrameEnd)); + + public static Rectangle GetVisibilityRectangleFromAnimation( + this Sequence sequence, Sequence.Animation animation) + { + var rect = sequence.GetVisibilityRectangleForFrameGroup(animation.SpriteGroupIndex); + + var minXPos = animation.TranslateXStart; + int maxXPos = animation.TranslateXEnd; + var minYPos = animation.TranslateYStart; + int maxYPos = animation.TranslateYEnd; + var minXScale = animation.ScaleStart * animation.ScaleXStart; + var maxXScale = animation.ScaleEnd * animation.ScaleXEnd; + var minYScale = animation.ScaleStart * animation.ScaleYStart; + var maxYScale = animation.ScaleEnd * animation.ScaleYEnd; + + var minRect = rect + .Multiply(minXScale, minYScale) + .Traslate(minXPos, minYPos); + + var maxRect = rect + .Multiply(maxXScale, maxYScale) + .Traslate(maxXPos, maxYPos); + + return minRect.Union(maxRect); + } + + public static Rectangle GetVisibilityRectangleForFrameGroup(this Sequence sequence, int frameGroupIndex) => + sequence.SpriteGroups[frameGroupIndex].GetVisibilityRectangleForFrameGroup(); + + public static Rectangle GetVisibilityRectangleForFrameGroup(this List spriteGroup) => + spriteGroup.Aggregate(new Rectangle(), (rect, x) => rect.Union(x.GetVisibilityRectangle())); + + public static Rectangle GetVisibilityRectangle( + this Sequence.SpritePart frameEx) => Rectangle.FromLTRB( + frameEx.Left, + frameEx.Top, + frameEx.Right, + frameEx.Bottom); + + public static Sequence.Animation Clone(this Sequence.Animation anim) => new Sequence.Animation + { + Flags = anim.Flags, + SpriteGroupIndex = anim.SpriteGroupIndex, + FrameStart = anim.FrameStart, + FrameEnd = anim.FrameEnd, + TranslateXStart = anim.TranslateXStart, + TranslateXEnd = anim.TranslateXEnd, + TranslateYStart = anim.TranslateYStart, + TranslateYEnd = anim.TranslateYEnd, + PivotXStart = anim.PivotXStart, + PivotXEnd = anim.PivotXEnd, + PivotYStart = anim.PivotYStart, + PivotYEnd = anim.PivotYEnd, + RotationXStart = anim.RotationXStart, + RotationXEnd = anim.RotationXEnd, + RotationYStart = anim.RotationYStart, + RotationYEnd = anim.RotationYEnd, + RotationZStart = anim.RotationZStart, + RotationZEnd = anim.RotationZEnd, + ScaleStart = anim.ScaleStart, + ScaleEnd = anim.ScaleEnd, + ScaleXStart = anim.ScaleXStart, + ScaleXEnd = anim.ScaleXEnd, + ScaleYStart = anim.ScaleYStart, + ScaleYEnd = anim.ScaleYEnd, + CurveXStart = anim.CurveXStart, + CurveYStart = anim.CurveYStart, + CurveXEnd = anim.CurveXEnd, + CurveYEnd = anim.CurveYEnd, + BounceXStart = anim.BounceXStart, + BounceXEnd = anim.BounceXEnd, + BounceYStart = anim.BounceYStart, + BounceYEnd = anim.BounceYEnd, + BounceXCount = anim.BounceXCount, + BounceYCount = anim.BounceYCount, + ColorBlend = anim.ColorBlend, + ColorStart = anim.ColorStart, + ColorEnd = anim.ColorEnd, + }; + } +} diff --git a/OpenKh.Kh2/Extensions/Vector3Extensions.cs b/OpenKh.Kh2/Extensions/Vector3Extensions.cs index a59976139..3476189b1 100644 --- a/OpenKh.Kh2/Extensions/Vector3Extensions.cs +++ b/OpenKh.Kh2/Extensions/Vector3Extensions.cs @@ -1,4 +1,4 @@ -using OpenKh.Kh2.Utils; +using OpenKh.Kh2.Utils; using System; using System.Collections.Generic; using System.Numerics; diff --git a/OpenKh.Kh2/Extensions/Vector4Extensions.cs b/OpenKh.Kh2/Extensions/Vector4Extensions.cs index 7dbb66ac4..97f81b979 100644 --- a/OpenKh.Kh2/Extensions/Vector4Extensions.cs +++ b/OpenKh.Kh2/Extensions/Vector4Extensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Numerics; using System.Text; diff --git a/OpenKh.Kh2/Idx.cs b/OpenKh.Kh2/Idx.cs index 382d2e902..a71166b13 100644 --- a/OpenKh.Kh2/Idx.cs +++ b/OpenKh.Kh2/Idx.cs @@ -1,184 +1,184 @@ -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2 -{ - public static class Idx - { - public class Entry - { - public const int MaxBlockLength = 0x3FFF; - private const int IsCompressedFlag = 0x4000; - private const int IsStreamedFlag = 0x8000; - - /// - /// 32-bit hash of the file name. - /// Paired with Hash2 to reduce the hash collisions. - /// - [Data] public uint Hash32 { get; set; } - - /// - /// 16-bit hash of the file name. - /// Paired with Hash1 to reduce the hash collisions. - /// - [Data] public ushort Hash16 { get; set; } - - /// - /// Additional info and files - /// - [Data] public ushort BlockDescription { get; set; } - - /// - /// Offset of the file in the archive, divided by the ISO block size - /// - [Data] public uint Offset { get; set; } - - /// - /// Length of the file in bytes - /// - [Data] public int Length { get; set; } - - /// - /// ISO blocks used in the ISO. - /// - public int BlockLength - { - get - { - var blockLength = BlockDescription & MaxBlockLength; - if (Length >= 0x1000000 && IsCompressed) // HACK: please refer to IdxBlockSizeBugTest - blockLength |= 0x1000; - - return blockLength; - } - - set - { - if (value > MaxBlockLength) - throw new ArgumentOutOfRangeException(nameof(BlockLength), $"Cannot exceeds {MaxBlockLength}"); - - BlockDescription = (ushort)((ushort)value | (BlockDescription & 0xC000U)); - } - } - - /// - /// If the file is compressed. - /// - public bool IsCompressed - { - get => (BlockDescription & IsCompressedFlag) != 0; - set - { - if (value) - BlockDescription |= IsCompressedFlag; - else - BlockDescription = (ushort)(BlockDescription & ~IsCompressedFlag); - } - } - - /// - /// If the file is not loaded in RAM, but streamed. - /// - public bool IsStreamed - { - get => (BlockDescription & IsStreamedFlag) != 0; - set - { - if (value) - BlockDescription |= IsStreamedFlag; - else - BlockDescription = (ushort)(BlockDescription & ~IsStreamedFlag); - } - } - } - - public static bool IsValid(Stream stream) => - stream.Length == new BinaryReader(stream.SetPosition(0)).ReadInt32() * 0x10 + 4; - - /// - /// Deserialize an IDX from a stream - /// - /// Readable stream where the IDX has been serialized. - /// - public static List Read(Stream stream) => Enumerable - .Range(0, stream.SetPosition(0).ReadInt32()) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList(); - - /// - /// Serialize an IDX to a stream - /// - /// Writable stream that will contain the IDX data - public static void Write(Stream stream, List entries) - { - stream.Write(entries.Count); - foreach (var entry in entries) - BinaryMapping.WriteObject(stream, entry); - } - - /// - /// Calculate an hash32 from a name - /// - /// - /// - public static uint GetHash32(string text) => GetHash32(Encoding.UTF8.GetBytes(text)); - - /// - /// Calculate an hash32 from data - /// - /// - /// - public static uint GetHash32(byte[] data) - { - int c = -1; - for (int i = 0; i < data.Length; i++) - { - c ^= data[i] << 24; - for (int j = 8; j > 0; j--) - { - if (c < 0) - c = (c << 1) ^ 0x4C11DB7; - else - c <<= 1; - } - } - - return (uint)~c; - } - - /// - /// Calculate an hash16 from a name - /// - /// - /// - public static ushort GetHash16(string text) => - GetHash16(Encoding.UTF8.GetBytes(text)); - - /// - /// Calculate an hash16 from data - /// - /// - /// - public static ushort GetHash16(byte[] data) - { - int s1 = -1; - for (int i = data.Length - 1; i >= 0; i--) - { - s1 = (s1 ^ (data[i] << 8)) & 0xFFFF; - for (int j = 8; j > 0; j--) - { - if ((s1 & 0x8000) != 0) - s1 = ((s1 << 1) ^ 0x1021) & 0xFFFF; - else - s1 <<= 1; - } - } - return (ushort)~s1; - } - } -} +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2 +{ + public static class Idx + { + public class Entry + { + public const int MaxBlockLength = 0x3FFF; + private const int IsCompressedFlag = 0x4000; + private const int IsStreamedFlag = 0x8000; + + /// + /// 32-bit hash of the file name. + /// Paired with Hash2 to reduce the hash collisions. + /// + [Data] public uint Hash32 { get; set; } + + /// + /// 16-bit hash of the file name. + /// Paired with Hash1 to reduce the hash collisions. + /// + [Data] public ushort Hash16 { get; set; } + + /// + /// Additional info and files + /// + [Data] public ushort BlockDescription { get; set; } + + /// + /// Offset of the file in the archive, divided by the ISO block size + /// + [Data] public uint Offset { get; set; } + + /// + /// Length of the file in bytes + /// + [Data] public int Length { get; set; } + + /// + /// ISO blocks used in the ISO. + /// + public int BlockLength + { + get + { + var blockLength = BlockDescription & MaxBlockLength; + if (Length >= 0x1000000 && IsCompressed) // HACK: please refer to IdxBlockSizeBugTest + blockLength |= 0x1000; + + return blockLength; + } + + set + { + if (value > MaxBlockLength) + throw new ArgumentOutOfRangeException(nameof(BlockLength), $"Cannot exceeds {MaxBlockLength}"); + + BlockDescription = (ushort)((ushort)value | (BlockDescription & 0xC000U)); + } + } + + /// + /// If the file is compressed. + /// + public bool IsCompressed + { + get => (BlockDescription & IsCompressedFlag) != 0; + set + { + if (value) + BlockDescription |= IsCompressedFlag; + else + BlockDescription = (ushort)(BlockDescription & ~IsCompressedFlag); + } + } + + /// + /// If the file is not loaded in RAM, but streamed. + /// + public bool IsStreamed + { + get => (BlockDescription & IsStreamedFlag) != 0; + set + { + if (value) + BlockDescription |= IsStreamedFlag; + else + BlockDescription = (ushort)(BlockDescription & ~IsStreamedFlag); + } + } + } + + public static bool IsValid(Stream stream) => + stream.Length == new BinaryReader(stream.SetPosition(0)).ReadInt32() * 0x10 + 4; + + /// + /// Deserialize an IDX from a stream + /// + /// Readable stream where the IDX has been serialized. + /// + public static List Read(Stream stream) => Enumerable + .Range(0, stream.SetPosition(0).ReadInt32()) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList(); + + /// + /// Serialize an IDX to a stream + /// + /// Writable stream that will contain the IDX data + public static void Write(Stream stream, List entries) + { + stream.Write(entries.Count); + foreach (var entry in entries) + BinaryMapping.WriteObject(stream, entry); + } + + /// + /// Calculate an hash32 from a name + /// + /// + /// + public static uint GetHash32(string text) => GetHash32(Encoding.UTF8.GetBytes(text)); + + /// + /// Calculate an hash32 from data + /// + /// + /// + public static uint GetHash32(byte[] data) + { + int c = -1; + for (int i = 0; i < data.Length; i++) + { + c ^= data[i] << 24; + for (int j = 8; j > 0; j--) + { + if (c < 0) + c = (c << 1) ^ 0x4C11DB7; + else + c <<= 1; + } + } + + return (uint)~c; + } + + /// + /// Calculate an hash16 from a name + /// + /// + /// + public static ushort GetHash16(string text) => + GetHash16(Encoding.UTF8.GetBytes(text)); + + /// + /// Calculate an hash16 from data + /// + /// + /// + public static ushort GetHash16(byte[] data) + { + int s1 = -1; + for (int i = data.Length - 1; i >= 0; i--) + { + s1 = (s1 ^ (data[i] << 8)) & 0xFFFF; + for (int j = 8; j > 0; j--) + { + if ((s1 & 0x8000) != 0) + s1 = ((s1 << 1) ^ 0x1021) & 0xFFFF; + else + s1 <<= 1; + } + } + return (ushort)~s1; + } + } +} diff --git a/OpenKh.Kh2/IdxDictionary.cs b/OpenKh.Kh2/IdxDictionary.cs index 520ed738d..06bed8261 100644 --- a/OpenKh.Kh2/IdxDictionary.cs +++ b/OpenKh.Kh2/IdxDictionary.cs @@ -1,74 +1,74 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace OpenKh.Kh2 -{ - public class IdxDictionary : ICollection - { - private readonly Dictionary _entries = new Dictionary(); - - public int Count => _entries.Count; - - public bool IsReadOnly => false; - - public IEnumerator GetEnumerator() => - _entries.Values.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => - _entries.Values.GetEnumerator(); - - public void Add(Idx.Entry entry) => - _entries[GetHash(entry)] = entry; - - public void Add(IEnumerable entries) - { - foreach (var entry in entries) - _entries[GetHash(entry)] = entry; - } - - public bool Exists(string name) => _entries.ContainsKey(GetHash(name)); - - public bool TryGetEntry(string name, out Idx.Entry entry) => - _entries.TryGetValue(GetHash(name), out entry); - - public bool TryGetEntry(uint hash32, ushort hash16, out Idx.Entry entry) => - _entries.TryGetValue(GetHash(hash32, hash16), out entry); - - internal static long GetHash(string name) => - Idx.GetHash32(name) | ((long)Idx.GetHash16(name) << 32); - - internal static long GetHash(Idx.Entry e) => - e.Hash32 | ((long)e.Hash16 << 32); - - internal static long GetHash(uint hash32, ushort hash16) => - hash32 | ((long)hash16 << 32); - - public void Clear() => _entries.Clear(); - - public bool Contains(Idx.Entry item) => _entries.ContainsValue(item); - - public void CopyTo(Idx.Entry[] array, int arrayIndex) - { - if (array.Length - arrayIndex > _entries.Count) - throw new ArgumentOutOfRangeException("The destination array is too small"); - - foreach (var entry in _entries) - array[arrayIndex++] = entry.Value; - } - - public bool Remove(Idx.Entry item) - { - foreach (var entry in _entries) - { - if (entry.Value == item) - { - _entries.Remove(entry.Key); - return true; - } - } - - return false; - } - } -} +using System; +using System.Collections; +using System.Collections.Generic; + +namespace OpenKh.Kh2 +{ + public class IdxDictionary : ICollection + { + private readonly Dictionary _entries = new Dictionary(); + + public int Count => _entries.Count; + + public bool IsReadOnly => false; + + public IEnumerator GetEnumerator() => + _entries.Values.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => + _entries.Values.GetEnumerator(); + + public void Add(Idx.Entry entry) => + _entries[GetHash(entry)] = entry; + + public void Add(IEnumerable entries) + { + foreach (var entry in entries) + _entries[GetHash(entry)] = entry; + } + + public bool Exists(string name) => _entries.ContainsKey(GetHash(name)); + + public bool TryGetEntry(string name, out Idx.Entry entry) => + _entries.TryGetValue(GetHash(name), out entry); + + public bool TryGetEntry(uint hash32, ushort hash16, out Idx.Entry entry) => + _entries.TryGetValue(GetHash(hash32, hash16), out entry); + + internal static long GetHash(string name) => + Idx.GetHash32(name) | ((long)Idx.GetHash16(name) << 32); + + internal static long GetHash(Idx.Entry e) => + e.Hash32 | ((long)e.Hash16 << 32); + + internal static long GetHash(uint hash32, ushort hash16) => + hash32 | ((long)hash16 << 32); + + public void Clear() => _entries.Clear(); + + public bool Contains(Idx.Entry item) => _entries.ContainsValue(item); + + public void CopyTo(Idx.Entry[] array, int arrayIndex) + { + if (array.Length - arrayIndex > _entries.Count) + throw new ArgumentOutOfRangeException("The destination array is too small"); + + foreach (var entry in _entries) + array[arrayIndex++] = entry.Value; + } + + public bool Remove(Idx.Entry item) + { + foreach (var entry in _entries) + { + if (entry.Value == item) + { + _entries.Remove(entry.Key); + return true; + } + } + + return false; + } + } +} diff --git a/OpenKh.Kh2/IdxName.cs b/OpenKh.Kh2/IdxName.cs index b3bb438b2..32c3fc50c 100644 --- a/OpenKh.Kh2/IdxName.cs +++ b/OpenKh.Kh2/IdxName.cs @@ -1,32 +1,32 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Kh2 -{ - public class IdxName - { - public static string Names = Path.Combine(Path.GetDirectoryName(AppContext.BaseDirectory), "resources/kh2idx.txt"); - - private static Dictionary _nameDictionary = File - .ReadAllLines(Names) - .ToDictionary(name => IdxDictionary.GetHash(name), name => name); - - public Idx.Entry Entry { get; set; } - public string Name { get; set; } - - public static IEnumerable GetNameEntries(IEnumerable entries) => entries - .Select(entry => new IdxName - { - Entry = entry, - Name = Lookup(entry) - }); - - public static string Lookup(uint hash32, ushort hash16) => - _nameDictionary.TryGetValue(IdxDictionary.GetHash(hash32, hash16), out var name) ? name : null; - - public static string Lookup(Idx.Entry entry) => - _nameDictionary.TryGetValue(IdxDictionary.GetHash(entry), out var name) ? name : null; - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Kh2 +{ + public class IdxName + { + public static string Names = Path.Combine(Path.GetDirectoryName(AppContext.BaseDirectory), "resources/kh2idx.txt"); + + private static Dictionary _nameDictionary = File + .ReadAllLines(Names) + .ToDictionary(name => IdxDictionary.GetHash(name), name => name); + + public Idx.Entry Entry { get; set; } + public string Name { get; set; } + + public static IEnumerable GetNameEntries(IEnumerable entries) => entries + .Select(entry => new IdxName + { + Entry = entry, + Name = Lookup(entry) + }); + + public static string Lookup(uint hash32, ushort hash16) => + _nameDictionary.TryGetValue(IdxDictionary.GetHash(hash32, hash16), out var name) ? name : null; + + public static string Lookup(Idx.Entry entry) => + _nameDictionary.TryGetValue(IdxDictionary.GetHash(entry), out var name) ? name : null; + } +} diff --git a/OpenKh.Kh2/Img.cs b/OpenKh.Kh2/Img.cs index c31153020..ecb7b2195 100644 --- a/OpenKh.Kh2/Img.cs +++ b/OpenKh.Kh2/Img.cs @@ -1,249 +1,250 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Xe.IO; - -namespace OpenKh.Kh2 -{ - public class Img - { - public const int IsoBlockAlign = 0x800; - - public static string[] InternalIdxs = - { - "000al.idx", - "000bb.idx", - "000ca.idx", - "000dc.idx", - "000di.idx", - "000eh.idx", - "000es.idx", - "000gumi.idx", - "000hb.idx", - "000he.idx", - "000lk.idx", - "000lm.idx", - "000mu.idx", - "000nm.idx", - "000po.idx", - "000tr.idx", - "000tt.idx", - "000wi.idx", - "000wm.idx", - "000zz.idx", - }; - - private readonly Stream stream; - - public Img(Stream stream, IEnumerable idxEntries, bool loadAllIdx) - { - this.stream = stream; - Entries = new IdxDictionary - { - idxEntries - }; - - if (loadAllIdx) - { - foreach (var fileName in InternalIdxs) - { - FileOpen(fileName, entryStream => - { - Entries.Add(Idx.Read(entryStream)); - }); - } - } - } - - public IdxDictionary Entries { get; } - - public bool FileExists(string fileName) => Entries.Exists(fileName); - - public bool TryFileOpen(string fileName, out Stream stream) - { - bool result; - if (result = Entries.TryGetEntry(fileName, out var entry)) - { - stream = FileOpen(entry); - return true; - } - - stream = null; - return false; - } - - public bool FileOpen(string fileName, Action callback) - { - bool result; - if (result = Entries.TryGetEntry(fileName, out var entry)) - callback(FileOpen(entry)); - - return result; - } - - public Stream FileOpen(string fileName) - { - if (Entries.TryGetEntry(fileName, out var entry)) - return FileOpen(entry); - - throw new FileNotFoundException("File not found", fileName); - } - - public Stream FileOpen(Idx.Entry entry) - { - if (entry.IsCompressed) - { - var fileStream = new SubStream(stream, entry.Offset * IsoBlockAlign, entry.BlockLength * IsoBlockAlign + IsoBlockAlign); - return new MemoryStream(Decompress(fileStream)); - } - - return new SubStream(stream, entry.Offset * IsoBlockAlign, entry.Length); - } - - public static byte[] Decompress(Stream src) - { - return Decompress(new BinaryReader(src).ReadBytes((int)src.Length)); - } - - public static byte[] Decompress(byte[] srcData) - { - var srcIndex = srcData.Length - 1; - - byte key = 0; - while (srcIndex > 0 && (key = srcData[srcIndex--]) == 0) ; - if (srcIndex == 0) - return new byte[0]; - - int decSize = srcData[srcIndex--] | - (srcData[srcIndex--] << 8) | - (srcData[srcIndex--] << 16) | - (srcData[srcIndex--] << 24); - - int dstIndex = decSize - 1; - var dstData = new byte[decSize]; - - while (dstIndex >= 0 && srcIndex >= 0) - { - var data = srcData[srcIndex--]; - if (data == key && srcIndex >= 0) - { - var copyIndex = srcData[srcIndex--]; - if (copyIndex > 0 && srcIndex >= 0) - { - var copyLength = srcData[srcIndex--]; - for (int i = 0; i < copyLength + 3 && dstIndex >= 0; i++) - { - dstData[dstIndex--] = dstData[dstIndex + copyIndex + 1]; - } - } - else - { - dstData[dstIndex--] = data; - } - - } - else - { - dstData[dstIndex--] = data; - } - } - - return dstData; - } - - public static byte[] Compress(byte[] srcData) - { - const int MaxWindowSize = 0x102; - const int MaxSlidingIndex = 0xff; - - var decompressedLength = srcData.Length; - var key = GetLeastUsedByte(srcData); - var buffer = new List(decompressedLength); - - buffer.Add(key); - buffer.Add((byte)(decompressedLength >> 0)); - buffer.Add((byte)(decompressedLength >> 8)); - buffer.Add((byte)(decompressedLength >> 16)); - buffer.Add((byte)(decompressedLength >> 24)); - - int sourceIndex = decompressedLength - 1; - - while (sourceIndex >= 0) - { - var ch = srcData[sourceIndex]; - if (ch == key) - { - buffer.Add(key); - buffer.Add(0); - sourceIndex--; - continue; - } - - var windowSizeCandidate = 0; - var slidingIndexCandidate = -1; - var maxWindowSize = Math.Min(sourceIndex, MaxWindowSize); - for (var slidingIndex = MaxSlidingIndex; slidingIndex > 0; slidingIndex--) - { - if (slidingIndex + sourceIndex >= decompressedLength) - continue; - - int windowSize; - for (windowSize = 0; windowSize < maxWindowSize; windowSize++) - { - var startWindow = sourceIndex + slidingIndex - windowSize; - if (srcData[startWindow] != srcData[sourceIndex - windowSize]) - break; - } - - if (windowSize > windowSizeCandidate) - { - windowSizeCandidate = windowSize; - slidingIndexCandidate = slidingIndex; - } - } - - if (windowSizeCandidate > 3) - { - buffer.Add(key); - buffer.Add((byte)slidingIndexCandidate); - buffer.Add((byte)(windowSizeCandidate - 3)); - sourceIndex -= windowSizeCandidate; - } - else - { - buffer.Add(ch); - sourceIndex--; - } - } - - var compressedLength = buffer.Count; - var cmp = new byte[compressedLength]; - for (var i = 0; i < compressedLength; i++) - { - cmp[i] = buffer[compressedLength - i - 1]; - } - - return cmp; - } - - private static byte GetLeastUsedByte(byte[] data) - { - var dictionary = new int[0x100]; - foreach (var ch in data) - dictionary[ch]++; - - var elementFound = int.MaxValue; - var indexFound = 1; // the least used byte is never zero - for (var i = 1; i < 0x100; i++) - { - if (dictionary[i] < elementFound) - { - elementFound = dictionary[i]; - indexFound = i; - } - } - - return (byte)indexFound; - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using Xe.IO; + +namespace OpenKh.Kh2 +{ + public class Img + { + public const int IsoBlockAlign = 0x800; + + public static string[] InternalIdxs = + { + "000al.idx", + "000bb.idx", + "000ca.idx", + "000dc.idx", + "000di.idx", + "000eh.idx", + "000es.idx", + "000gumi.idx", + "000hb.idx", + "000he.idx", + "000lk.idx", + "000lm.idx", + "000mu.idx", + "000nm.idx", + "000po.idx", + "000tr.idx", + "000tt.idx", + "000wi.idx", + "000wm.idx", + "000zz.idx", + }; + + private readonly Stream stream; + + public Img(Stream stream, IEnumerable idxEntries, bool loadAllIdx) + { + this.stream = stream; + Entries = new IdxDictionary + { + idxEntries + }; + + if (loadAllIdx) + { + foreach (var fileName in InternalIdxs) + { + FileOpen(fileName, entryStream => + { + Entries.Add(Idx.Read(entryStream)); + }); + } + } + } + + public IdxDictionary Entries { get; } + + public bool FileExists(string fileName) => Entries.Exists(fileName); + + public bool TryFileOpen(string fileName, out Stream stream) + { + bool result; + if (result = Entries.TryGetEntry(fileName, out var entry)) + { + stream = FileOpen(entry); + return true; + } + + stream = null; + return false; + } + + public bool FileOpen(string fileName, Action callback) + { + bool result; + if (result = Entries.TryGetEntry(fileName, out var entry)) + callback(FileOpen(entry)); + + return result; + } + + public Stream FileOpen(string fileName) + { + if (Entries.TryGetEntry(fileName, out var entry)) + return FileOpen(entry); + + throw new FileNotFoundException("File not found", fileName); + } + + public Stream FileOpen(Idx.Entry entry) + { + if (entry.IsCompressed) + { + var fileStream = new SubStream(stream, entry.Offset * IsoBlockAlign, entry.BlockLength * IsoBlockAlign + IsoBlockAlign); + return new MemoryStream(Decompress(fileStream)); + } + + return new SubStream(stream, entry.Offset * IsoBlockAlign, entry.Length); + } + + public static byte[] Decompress(Stream src) + { + return Decompress(new BinaryReader(src).ReadBytes((int)src.Length)); + } + + public static byte[] Decompress(byte[] srcData) + { + var srcIndex = srcData.Length - 1; + + byte key = 0; + while (srcIndex > 0 && (key = srcData[srcIndex--]) == 0) + ; + if (srcIndex == 0) + return new byte[0]; + + int decSize = srcData[srcIndex--] | + (srcData[srcIndex--] << 8) | + (srcData[srcIndex--] << 16) | + (srcData[srcIndex--] << 24); + + int dstIndex = decSize - 1; + var dstData = new byte[decSize]; + + while (dstIndex >= 0 && srcIndex >= 0) + { + var data = srcData[srcIndex--]; + if (data == key && srcIndex >= 0) + { + var copyIndex = srcData[srcIndex--]; + if (copyIndex > 0 && srcIndex >= 0) + { + var copyLength = srcData[srcIndex--]; + for (int i = 0; i < copyLength + 3 && dstIndex >= 0; i++) + { + dstData[dstIndex--] = dstData[dstIndex + copyIndex + 1]; + } + } + else + { + dstData[dstIndex--] = data; + } + + } + else + { + dstData[dstIndex--] = data; + } + } + + return dstData; + } + + public static byte[] Compress(byte[] srcData) + { + const int MaxWindowSize = 0x102; + const int MaxSlidingIndex = 0xff; + + var decompressedLength = srcData.Length; + var key = GetLeastUsedByte(srcData); + var buffer = new List(decompressedLength); + + buffer.Add(key); + buffer.Add((byte)(decompressedLength >> 0)); + buffer.Add((byte)(decompressedLength >> 8)); + buffer.Add((byte)(decompressedLength >> 16)); + buffer.Add((byte)(decompressedLength >> 24)); + + int sourceIndex = decompressedLength - 1; + + while (sourceIndex >= 0) + { + var ch = srcData[sourceIndex]; + if (ch == key) + { + buffer.Add(key); + buffer.Add(0); + sourceIndex--; + continue; + } + + var windowSizeCandidate = 0; + var slidingIndexCandidate = -1; + var maxWindowSize = Math.Min(sourceIndex, MaxWindowSize); + for (var slidingIndex = MaxSlidingIndex; slidingIndex > 0; slidingIndex--) + { + if (slidingIndex + sourceIndex >= decompressedLength) + continue; + + int windowSize; + for (windowSize = 0; windowSize < maxWindowSize; windowSize++) + { + var startWindow = sourceIndex + slidingIndex - windowSize; + if (srcData[startWindow] != srcData[sourceIndex - windowSize]) + break; + } + + if (windowSize > windowSizeCandidate) + { + windowSizeCandidate = windowSize; + slidingIndexCandidate = slidingIndex; + } + } + + if (windowSizeCandidate > 3) + { + buffer.Add(key); + buffer.Add((byte)slidingIndexCandidate); + buffer.Add((byte)(windowSizeCandidate - 3)); + sourceIndex -= windowSizeCandidate; + } + else + { + buffer.Add(ch); + sourceIndex--; + } + } + + var compressedLength = buffer.Count; + var cmp = new byte[compressedLength]; + for (var i = 0; i < compressedLength; i++) + { + cmp[i] = buffer[compressedLength - i - 1]; + } + + return cmp; + } + + private static byte GetLeastUsedByte(byte[] data) + { + var dictionary = new int[0x100]; + foreach (var ch in data) + dictionary[ch]++; + + var elementFound = int.MaxValue; + var indexFound = 1; // the least used byte is never zero + for (var i = 1; i < 0x100; i++) + { + if (dictionary[i] < elementFound) + { + elementFound = dictionary[i]; + indexFound = i; + } + } + + return (byte)indexFound; + } + } +} diff --git a/OpenKh.Kh2/Imgd.Create.cs b/OpenKh.Kh2/Imgd.Create.cs index 112cb4f57..8445e8254 100644 --- a/OpenKh.Kh2/Imgd.Create.cs +++ b/OpenKh.Kh2/Imgd.Create.cs @@ -1,105 +1,105 @@ -using OpenKh.Imaging; -using System; -using System.Drawing; - -namespace OpenKh.Kh2 -{ - public partial class Imgd - { - public Imgd( - Size size, - PixelFormat pixelFormat, - byte[] data, - byte[] clut, - bool isSwizzled) - { - Size = size; - format = GetFormat(pixelFormat); - swizzled = isSwizzled ? 7 : 3; - - if (isSwizzled) - { - switch (format) - { - case Format4bpp: - Data = Swizzle4bpp(size, data); - break; - case Format8bpp: - Data = Swizzle8bpp(size, data); - break; - default: - Data = data; - break; - } - } - else - { - Data = data; - } - - switch (format) - { - case Format4bpp: - Clut = GetKh2Clut4(clut); - break; - case Format8bpp: - Clut = GetKh2Clut8(clut); - break; - } +using OpenKh.Imaging; +using System; +using System.Drawing; + +namespace OpenKh.Kh2 +{ + public partial class Imgd + { + public Imgd( + Size size, + PixelFormat pixelFormat, + byte[] data, + byte[] clut, + bool isSwizzled) + { + Size = size; + format = GetFormat(pixelFormat); + swizzled = isSwizzled ? 7 : 3; + + if (isSwizzled) + { + switch (format) + { + case Format4bpp: + Data = Swizzle4bpp(size, data); + break; + case Format8bpp: + Data = Swizzle8bpp(size, data); + break; + default: + Data = data; + break; + } + } + else + { + Data = data; + } + + switch (format) + { + case Format4bpp: + Clut = GetKh2Clut4(clut); + break; + case Format8bpp: + Clut = GetKh2Clut8(clut); + break; + } + } + + public static Imgd Create( + Size size, + PixelFormat pixelFormat, + byte[] data, + byte[] clut, + bool isSwizzled) => + new Imgd(size, pixelFormat, ImageDataHelpers.GetInvertedRedBlueChannels(data, size, pixelFormat), clut, isSwizzled); + + private static byte[] Swizzle4bpp(Size size, byte[] data) + { + data = Ps2.Encode4(data, size.Width / 128, size.Height / 128); + return Ps2.Decode32(data, size.Width / 128, size.Height / 128); + } + + private static byte[] Swizzle8bpp(Size size, byte[] data) + { + data = Ps2.Encode8(data, size.Width / 128, size.Height / 64); + return Ps2.Decode32(data, size.Width / 128, size.Height / 64); + } + + private static byte[] GetKh2Clut4(byte[] rawClut) + { + var inputColorCount = rawClut.Length / 4; + var newClut = new byte[16 * 4]; + for (var i = 0; i < inputColorCount; i++) + { + newClut[i * 4 + 0] = rawClut[i * 4 + 0]; + newClut[i * 4 + 1] = rawClut[i * 4 + 1]; + newClut[i * 4 + 2] = rawClut[i * 4 + 2]; + newClut[i * 4 + 3] = ToPs2Alpha(rawClut[i * 4 + 3]); + } + + return newClut; + } + + private static byte[] GetKh2Clut8(byte[] rawClut) + { + var inputColorCount = rawClut.Length / 4; + var newClut = new byte[256 * 4]; + + for (var i = 0; i < inputColorCount; i++) + { + var dstIndex = Ps2.Repl(i); + newClut[dstIndex * 4 + 0] = rawClut[i * 4 + 0]; + newClut[dstIndex * 4 + 1] = rawClut[i * 4 + 1]; + newClut[dstIndex * 4 + 2] = rawClut[i * 4 + 2]; + newClut[dstIndex * 4 + 3] = ToPs2Alpha(rawClut[i * 4 + 3]); + } + + return newClut; } - public static Imgd Create( - Size size, - PixelFormat pixelFormat, - byte[] data, - byte[] clut, - bool isSwizzled) => - new Imgd(size, pixelFormat, ImageDataHelpers.GetInvertedRedBlueChannels(data, size, pixelFormat), clut, isSwizzled); - - private static byte[] Swizzle4bpp(Size size, byte[] data) - { - data = Ps2.Encode4(data, size.Width / 128, size.Height / 128); - return Ps2.Decode32(data, size.Width / 128, size.Height / 128); - } - - private static byte[] Swizzle8bpp(Size size, byte[] data) - { - data = Ps2.Encode8(data, size.Width / 128, size.Height / 64); - return Ps2.Decode32(data, size.Width / 128, size.Height / 64); - } - - private static byte[] GetKh2Clut4(byte[] rawClut) - { - var inputColorCount = rawClut.Length / 4; - var newClut = new byte[16 * 4]; - for (var i = 0; i < inputColorCount; i++) - { - newClut[i * 4 + 0] = rawClut[i * 4 + 0]; - newClut[i * 4 + 1] = rawClut[i * 4 + 1]; - newClut[i * 4 + 2] = rawClut[i * 4 + 2]; - newClut[i * 4 + 3] = ToPs2Alpha(rawClut[i * 4 + 3]); - } - - return newClut; - } - - private static byte[] GetKh2Clut8(byte[] rawClut) - { - var inputColorCount = rawClut.Length / 4; - var newClut = new byte[256 * 4]; - - for (var i = 0; i < inputColorCount; i++) - { - var dstIndex = Ps2.Repl(i); - newClut[dstIndex * 4 + 0] = rawClut[i * 4 + 0]; - newClut[dstIndex * 4 + 1] = rawClut[i * 4 + 1]; - newClut[dstIndex * 4 + 2] = rawClut[i * 4 + 2]; - newClut[dstIndex * 4 + 3] = ToPs2Alpha(rawClut[i * 4 + 3]); - } - - return newClut; - } - private byte[] GetSwappedPixelData(byte[] data) { var newData = new byte[data.Length]; @@ -111,6 +111,6 @@ private byte[] GetSwappedPixelData(byte[] data) return newData; } - private static byte ToPs2Alpha(byte data) => (byte)((data + 1) / 2); - } -} + private static byte ToPs2Alpha(byte data) => (byte)((data + 1) / 2); + } +} diff --git a/OpenKh.Kh2/Imgd.cs b/OpenKh.Kh2/Imgd.cs index 42569ef0f..ed8e06f15 100644 --- a/OpenKh.Kh2/Imgd.cs +++ b/OpenKh.Kh2/Imgd.cs @@ -1,314 +1,326 @@ -using OpenKh.Common; -using OpenKh.Imaging; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using Xe.BinaryMapper; -using Xe.IO; - -namespace OpenKh.Kh2 -{ +using OpenKh.Common; +using OpenKh.Imaging; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using Xe.BinaryMapper; +using Xe.IO; + +namespace OpenKh.Kh2 +{ public partial class Imgd : IImageRead - { - private class Header - { - [Data] public uint MagicCode { get; set; } - [Data] public int Unk04 { get; set; } - [Data] public int BitmapOffset { get; set; } - [Data] public int BitmapLength { get; set; } - [Data] public int ClutOffset { get; set; } - [Data] public int ClutLength { get; set; } - [Data] public int Unk18 { get; set; } - [Data] public short Width { get; set; } - [Data] public short Height { get; set; } - [Data] public short PowWidth { get; set; } - [Data] public short PowHeight { get; set; } - [Data] public short WidthDiv64 { get; set; } - [Data] public short Format { get; set; } - [Data] public int Unk28 { get; set; } - [Data] public short Unk2c { get; set; } - [Data] public short Unk2e { get; set; } - [Data] public short Unk30 { get; set; } - [Data] public short Unk32 { get; set; } - [Data] public short Unk34 { get; set; } - [Data] public short Unk36 { get; set; } - [Data] public int Unk38 { get; set; } - [Data] public int Swizzled { get; set; } + { + private class Header + { + [Data] public uint MagicCode { get; set; } + [Data] public int Unk04 { get; set; } + [Data] public int BitmapOffset { get; set; } + [Data] public int BitmapLength { get; set; } + [Data] public int ClutOffset { get; set; } + [Data] public int ClutLength { get; set; } + [Data] public int Unk18 { get; set; } + [Data] public short Width { get; set; } + [Data] public short Height { get; set; } + [Data] public short PowWidth { get; set; } + [Data] public short PowHeight { get; set; } + [Data] public short WidthDiv64 { get; set; } + [Data] public short Format { get; set; } + [Data] public int Unk28 { get; set; } + [Data] public short Unk2c { get; set; } + [Data] public short Unk2e { get; set; } + [Data] public short Unk30 { get; set; } + [Data] public short Unk32 { get; set; } + [Data] public short Unk34 { get; set; } + [Data] public short Unk36 { get; set; } + [Data] public int Unk38 { get; set; } + [Data] public int Swizzled { get; set; } + } + + private const uint MagicCode = 0x44474D49U; + private const int HeaderLength = 0x40; + private const short Format32bpp = 0x00; + private const short Format8bpp = 0x13; + private const short Format4bpp = 0x14; + private const short SubFormat32bpp = 3; + private const short SubFormat8bpp = 5; + private const short SubFormat4bpp = 4; + private const int FacAlignment = 0x800; + private static readonly InvalidDataException InvalidHeaderException = new InvalidDataException("Invalid header"); + + public static bool IsValid(Stream stream) => + stream.Length >= HeaderLength && stream.SetPosition(0).ReadInt32() == MagicCode; + + private readonly short format; + private readonly int swizzled; + + private Imgd(Stream stream) + { + stream + .MustReadAndSeek() + .MustHaveHeaderLengthOf(HeaderLength); + + var reader = new BinaryReader(stream); + var header = BinaryMapping.ReadObject
(stream); + if (header.MagicCode != MagicCode) + throw InvalidHeaderException; + + Size = new Size(header.Width, header.Height); + format = header.Format; + swizzled = header.Swizzled; + + stream.SetPosition(header.BitmapOffset); + var data = reader.ReadBytes(header.BitmapLength); + + // Swap pixel order for only unswizzled 4-bpp IMGD. + Data = (format == Format4bpp && (swizzled & 4) == 0) + ? GetSwappedPixelData(data) + : data; + + stream.SetPosition(header.ClutOffset); + Clut = reader.ReadBytes(header.ClutLength); + } + + public static Imgd Read(Stream stream) => new Imgd(stream.SetPosition(0)); + + public void Write(Stream stream) + { + stream.MustWriteAndSeek(); + + BinaryMapping.WriteObject(stream, new Header + { + MagicCode = MagicCode, + Unk04 = 0x100, + BitmapOffset = HeaderLength, + BitmapLength = Data.Length, + ClutOffset = HeaderLength + Data.Length, + ClutLength = Clut?.Length ?? 0, + Unk18 = -1, + Width = (short)Size.Width, + Height = (short)Size.Height, + PowWidth = GetPow(Size.Width), + PowHeight = GetPow(Size.Height), + WidthDiv64 = (short)(Size.Width / 64), + Format = format, + Unk28 = -1, + Unk2c = (short)(format == Format4bpp ? 8 : 16), + Unk2e = (short)(format == Format4bpp ? 2 : 16), + Unk30 = 1, + Unk32 = (short)(format == Format32bpp ? 19 : 0), + Unk34 = GetSubFormat(format), + Unk36 = (short)(format == Format32bpp ? 0 : 3), + Unk38 = 0, + Swizzled = swizzled, + }); + + // Swap pixel order for only unswizzled 4-bpp IMGD. + var data = (format == Format4bpp && (swizzled & 4) == 0) + ? GetSwappedPixelData(Data) + : Data; + + stream.Write(data, 0, data.Length); + + if (Clut != null) + stream.Write(Clut, 0, Clut.Length); + } + + public static bool IsFac(Stream stream) + { + if (stream.Length < HeaderLength) + return false; + + stream.MustReadAndSeek().SetPosition(0); + var header = BinaryMapping.ReadObject
(stream); + if (header.MagicCode != MagicCode) + return false; + + stream + .SetPosition(header.ClutOffset + header.ClutLength) + .AlignPosition(FacAlignment); + + if (stream.Position + HeaderLength >= stream.Length) + return false; + + header = BinaryMapping.ReadObject
(stream); + if (header.MagicCode != MagicCode) + return false; + + return true; + } + + public static IEnumerable ReadAsFac(Stream stream) + { + stream.SetPosition(0); + while (true) + { + stream.AlignPosition(FacAlignment); + var subStreamLength = stream.Length - stream.Position; + if (subStreamLength < HeaderLength) + yield break; + + yield return Imgd.Read(new SubStream(stream, stream.Position, subStreamLength)); + } } - private const uint MagicCode = 0x44474D49U; - private const int HeaderLength = 0x40; - private const short Format32bpp = 0x00; - private const short Format8bpp = 0x13; - private const short Format4bpp = 0x14; - private const short SubFormat32bpp = 3; - private const short SubFormat8bpp = 5; - private const short SubFormat4bpp = 4; - private const int FacAlignment = 0x800; - private static readonly InvalidDataException InvalidHeaderException = new InvalidDataException("Invalid header"); - - public static bool IsValid(Stream stream) => - stream.Length >= HeaderLength && stream.SetPosition(0).ReadInt32() == MagicCode; - - private readonly short format; - private readonly int swizzled; - - private Imgd(Stream stream) - { - stream - .MustReadAndSeek() - .MustHaveHeaderLengthOf(HeaderLength); - - var reader = new BinaryReader(stream); - var header = BinaryMapping.ReadObject
(stream); - if (header.MagicCode != MagicCode) - throw InvalidHeaderException; - - Size = new Size(header.Width, header.Height); - format = header.Format; - swizzled = header.Swizzled; - - stream.SetPosition(header.BitmapOffset); - var data = reader.ReadBytes(header.BitmapLength); - - // Swap pixel order for only unswizzled 4-bpp IMGD. - Data = (format == Format4bpp && (swizzled & 4) == 0) - ? GetSwappedPixelData(data) - : data; - - stream.SetPosition(header.ClutOffset); - Clut = reader.ReadBytes(header.ClutLength); - } - - public static Imgd Read(Stream stream) => new Imgd(stream.SetPosition(0)); - - public void Write(Stream stream) - { - stream.MustWriteAndSeek(); - - BinaryMapping.WriteObject(stream, new Header - { - MagicCode = MagicCode, - Unk04 = 0x100, - BitmapOffset = HeaderLength, - BitmapLength = Data.Length, - ClutOffset = HeaderLength + Data.Length, - ClutLength = Clut?.Length ?? 0, - Unk18 = -1, - Width = (short)Size.Width, - Height = (short)Size.Height, - PowWidth = GetPow(Size.Width), - PowHeight = GetPow(Size.Height), - WidthDiv64 = (short)(Size.Width / 64), - Format = format, - Unk28 = -1, - Unk2c = (short)(format == Format4bpp ? 8 : 16), - Unk2e = (short)(format == Format4bpp ? 2 : 16), - Unk30 = 1, - Unk32 = (short)(format == Format32bpp ? 19 : 0), - Unk34 = GetSubFormat(format), - Unk36 = (short)(format == Format32bpp ? 0 : 3), - Unk38 = 0, - Swizzled = swizzled, - }); - - // Swap pixel order for only unswizzled 4-bpp IMGD. - var data = (format == Format4bpp && (swizzled & 4) == 0) - ? GetSwappedPixelData(Data) - : Data; - - stream.Write(data, 0, data.Length); - - if (Clut != null) - stream.Write(Clut, 0, Clut.Length); - } - - public static bool IsFac(Stream stream) - { - if (stream.Length < HeaderLength) - return false; - - stream.MustReadAndSeek().SetPosition(0); - var header = BinaryMapping.ReadObject
(stream); - if (header.MagicCode != MagicCode) - return false; - - stream - .SetPosition(header.ClutOffset + header.ClutLength) - .AlignPosition(FacAlignment); - - if (stream.Position + HeaderLength >= stream.Length) - return false; - - header = BinaryMapping.ReadObject
(stream); - if (header.MagicCode != MagicCode) - return false; - - return true; - } - - public static IEnumerable ReadAsFac(Stream stream) - { - stream.SetPosition(0); - while (true) - { - stream.AlignPosition(FacAlignment); - var subStreamLength = stream.Length - stream.Position; - if (subStreamLength < HeaderLength) - yield break; - - yield return Imgd.Read(new SubStream(stream, stream.Position, subStreamLength)); - } - } - - public static void WriteAsFac(Stream stream, IEnumerable images) - { - foreach (var image in images) - { - image.Write(stream); - stream.SetLength(stream.AlignPosition(FacAlignment).Position); - } - } - - public Size Size { get; } - + public static void WriteAsFac(Stream stream, IEnumerable images) + { + foreach (var image in images) + { + image.Write(stream); + stream.SetLength(stream.AlignPosition(FacAlignment).Position); + } + } + + public Size Size { get; } + /// /// Bitmap data - /// - /// - /// In the following case, this `Data` is not same bitmap data stored in imgd file. - /// - /// In OpenKh: - /// - NOT IsSwizzled && Format4bpp = storing Windows pixel order ([1, 2] to 0x12) - /// - /// In IMGD file: - /// - NOT IsSwizzled && Format4bpp = storing reversed pixel order ([1, 2] to 0x21) - /// - public byte[] Data { get; } - - public byte[] Clut { get; } - - public bool IsSwizzled => (swizzled & 4) != 0; - - public PixelFormat PixelFormat => GetPixelFormat(format); - - public byte[] GetData() - { - switch (format) - { - case Format32bpp: - return GetData32bpp(); - case Format8bpp: - return IsSwizzled ? Ps2.Decode8(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 64), Size.Width / 128, Size.Height / 64) : Data; - case Format4bpp: - return IsSwizzled ? Ps2.Decode4(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 128), Size.Width / 128, Size.Height / 128) : Data; - default: - throw new NotSupportedException($"The format {format} is not supported."); - } - } - - public byte[] GetClut() - { - switch (format) - { - case Format8bpp: return GetClut8(); - case Format4bpp: return GetClut4(); - default: - throw new NotSupportedException($"The format {format} is not supported or does not contain any palette."); - } - } - - private byte[] GetClut4() - { - var data = new byte[16 * 4]; - for (var i = 0; i < 16; i++) - { - data[i * 4 + 0] = Clut[i * 4 + 0]; - data[i * 4 + 1] = Clut[i * 4 + 1]; - data[i * 4 + 2] = Clut[i * 4 + 2]; - data[i * 4 + 3] = Ps2.FromPs2Alpha(Clut[i * 4 + 3]); - } - - return data; - } - - private byte[] GetClut8() - { - var data = new byte[256 * 4]; - for (var i = 0; i < 256; i++) - { - var srcIndex = Ps2.Repl(i); - if (srcIndex * 4 < Clut.Length) - { - data[i * 4 + 0] = Clut[srcIndex * 4 + 0]; - data[i * 4 + 1] = Clut[srcIndex * 4 + 1]; - data[i * 4 + 2] = Clut[srcIndex * 4 + 2]; - data[i * 4 + 3] = Ps2.FromPs2Alpha(Clut[srcIndex * 4 + 3]); - } - } - - return data; - } - - private byte[] GetData32bpp() - { - var newData = new byte[Data.Length]; - for (var i = 0; i < newData.Length - 3; i += 4) - { - newData[i + 0] = Data[i + 2]; - newData[i + 1] = Data[i + 1]; - newData[i + 2] = Data[i + 0]; - newData[i + 3] = Ps2.FromPs2Alpha(Data[i + 3]); - } - - return newData; - } - - private static short GetPow(int value) - { - short pow = 1; - while (value > (1 << pow)) - pow++; - - return pow; - } - - private static PixelFormat GetPixelFormat(int format) - { - switch (format) - { - case Format32bpp: return PixelFormat.Rgba8888; - case Format8bpp: return PixelFormat.Indexed8; - case Format4bpp: return PixelFormat.Indexed4; - default: return PixelFormat.Undefined; - } - } - - private static short GetFormat(PixelFormat pixelFormat) - { - switch (pixelFormat) - { - case PixelFormat.Rgba8888: return Format32bpp; - case PixelFormat.Indexed4: return Format4bpp; - case PixelFormat.Indexed8: return Format8bpp; - default: - throw new ArgumentOutOfRangeException( - $"Pixel format {pixelFormat} is not supported."); - } - } - - private static short GetSubFormat(short format) - { - switch (format) - { - case Format32bpp: return SubFormat32bpp; - case Format4bpp: return SubFormat4bpp; - case Format8bpp: return SubFormat8bpp; - default: - throw new ArgumentOutOfRangeException( - $"Format {format} is not supported."); - } - } - } -} + /// + /// + /// In the following case, this `Data` is not same bitmap data stored in imgd file. + /// + /// In OpenKh: + /// - NOT IsSwizzled && Format4bpp = storing Windows pixel order ([1, 2] to 0x12) + /// + /// In IMGD file: + /// - NOT IsSwizzled && Format4bpp = storing reversed pixel order ([1, 2] to 0x21) + /// + public byte[] Data { get; } + + public byte[] Clut { get; } + + public bool IsSwizzled => (swizzled & 4) != 0; + + public PixelFormat PixelFormat => GetPixelFormat(format); + + public byte[] GetData() + { + switch (format) + { + case Format32bpp: + return GetData32bpp(); + case Format8bpp: + return IsSwizzled ? Ps2.Decode8(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 64), Size.Width / 128, Size.Height / 64) : Data; + case Format4bpp: + return IsSwizzled ? Ps2.Decode4(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 128), Size.Width / 128, Size.Height / 128) : Data; + default: + throw new NotSupportedException($"The format {format} is not supported."); + } + } + + public byte[] GetClut() + { + switch (format) + { + case Format8bpp: + return GetClut8(); + case Format4bpp: + return GetClut4(); + default: + throw new NotSupportedException($"The format {format} is not supported or does not contain any palette."); + } + } + + private byte[] GetClut4() + { + var data = new byte[16 * 4]; + for (var i = 0; i < 16; i++) + { + data[i * 4 + 0] = Clut[i * 4 + 0]; + data[i * 4 + 1] = Clut[i * 4 + 1]; + data[i * 4 + 2] = Clut[i * 4 + 2]; + data[i * 4 + 3] = Ps2.FromPs2Alpha(Clut[i * 4 + 3]); + } + + return data; + } + + private byte[] GetClut8() + { + var data = new byte[256 * 4]; + for (var i = 0; i < 256; i++) + { + var srcIndex = Ps2.Repl(i); + if (srcIndex * 4 < Clut.Length) + { + data[i * 4 + 0] = Clut[srcIndex * 4 + 0]; + data[i * 4 + 1] = Clut[srcIndex * 4 + 1]; + data[i * 4 + 2] = Clut[srcIndex * 4 + 2]; + data[i * 4 + 3] = Ps2.FromPs2Alpha(Clut[srcIndex * 4 + 3]); + } + } + + return data; + } + + private byte[] GetData32bpp() + { + var newData = new byte[Data.Length]; + for (var i = 0; i < newData.Length - 3; i += 4) + { + newData[i + 0] = Data[i + 2]; + newData[i + 1] = Data[i + 1]; + newData[i + 2] = Data[i + 0]; + newData[i + 3] = Ps2.FromPs2Alpha(Data[i + 3]); + } + + return newData; + } + + private static short GetPow(int value) + { + short pow = 1; + while (value > (1 << pow)) + pow++; + + return pow; + } + + private static PixelFormat GetPixelFormat(int format) + { + switch (format) + { + case Format32bpp: + return PixelFormat.Rgba8888; + case Format8bpp: + return PixelFormat.Indexed8; + case Format4bpp: + return PixelFormat.Indexed4; + default: + return PixelFormat.Undefined; + } + } + + private static short GetFormat(PixelFormat pixelFormat) + { + switch (pixelFormat) + { + case PixelFormat.Rgba8888: + return Format32bpp; + case PixelFormat.Indexed4: + return Format4bpp; + case PixelFormat.Indexed8: + return Format8bpp; + default: + throw new ArgumentOutOfRangeException( + $"Pixel format {pixelFormat} is not supported."); + } + } + + private static short GetSubFormat(short format) + { + switch (format) + { + case Format32bpp: + return SubFormat32bpp; + case Format4bpp: + return SubFormat4bpp; + case Format8bpp: + return SubFormat8bpp; + default: + throw new ArgumentOutOfRangeException( + $"Format {format} is not supported."); + } + } + } +} diff --git a/OpenKh.Kh2/Imgz.cs b/OpenKh.Kh2/Imgz.cs index 400bbf5ba..e1f019bec 100644 --- a/OpenKh.Kh2/Imgz.cs +++ b/OpenKh.Kh2/Imgz.cs @@ -1,106 +1,106 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.IO; - -namespace OpenKh.Kh2 -{ - public class Imgz - { - private struct Entry - { - public int Offset, Length; - } - - private const uint MagicCode = 0x5A474D49U; - - public IEnumerable Images { get; } - - public Imgz(Stream stream) - { - Images = Read(stream); - } - - public static IEnumerable OpenAsStream(Stream stream) - { - if (!stream.CanRead || !stream.CanSeek) - throw new InvalidDataException($"Read or seek must be supported."); - - var reader = new BinaryReader(stream); - var offsetBase = reader.BaseStream.Position; - - if (stream.Length < 16L || reader.ReadUInt32() != MagicCode) - throw new InvalidDataException("Invalid header"); - - var unknown = reader.ReadInt32(); - var entriesOffset = reader.ReadInt32(); - var count = reader.ReadInt32(); - - stream.Position = entriesOffset; - var entries = new List(count); - for (int i = 0; i < count; i++) - { - entries.Add(new Entry() - { - Offset = reader.ReadInt32(), - Length = reader.ReadInt32(), - }); - } - - return entries - .Select(x => new SubStream(stream, x.Offset, x.Length)) - .ToList(); - } - - public static bool IsValid(Stream stream) => - stream.Length >= 4 && stream.SetPosition(0).ReadInt32() == MagicCode; - - public static IEnumerable Read(Stream stream) => - OpenAsStream(stream.SetPosition(0)).Select(x => Imgd.Read(x)).ToArray(); - - public static void Write(Stream stream, IEnumerable images) - { - if (!stream.CanWrite) - throw new InvalidDataException($"Read or seek must be supported."); - - var writer = new BinaryWriter(stream); - var count = images.Count(); - - writer.Write(MagicCode); - writer.Write(0x100); - writer.Write(0x10); // Header size; - writer.Write(count); - - int baseOffset = (int)(stream.Position + count * 8); - - // Align by 0x10 - if ((baseOffset & 0xF) != 0) - { - baseOffset += 0x10 - (baseOffset & 0xF); - } - - int currentOffset = baseOffset; - - var imgStreams = new List(count); - foreach (var image in images) - { - var memStream = new MemoryStream(); - image.Write(memStream); - imgStreams.Add(memStream); - - writer.Write(currentOffset); - writer.Write((int)memStream.Length); - - currentOffset += (int)memStream.Length; - } - - stream.Position = baseOffset; - foreach (var imgStream in imgStreams) - { - imgStream.Position = 0; - imgStream.WriteTo(stream); - } - } - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.IO; + +namespace OpenKh.Kh2 +{ + public class Imgz + { + private struct Entry + { + public int Offset, Length; + } + + private const uint MagicCode = 0x5A474D49U; + + public IEnumerable Images { get; } + + public Imgz(Stream stream) + { + Images = Read(stream); + } + + public static IEnumerable OpenAsStream(Stream stream) + { + if (!stream.CanRead || !stream.CanSeek) + throw new InvalidDataException($"Read or seek must be supported."); + + var reader = new BinaryReader(stream); + var offsetBase = reader.BaseStream.Position; + + if (stream.Length < 16L || reader.ReadUInt32() != MagicCode) + throw new InvalidDataException("Invalid header"); + + var unknown = reader.ReadInt32(); + var entriesOffset = reader.ReadInt32(); + var count = reader.ReadInt32(); + + stream.Position = entriesOffset; + var entries = new List(count); + for (int i = 0; i < count; i++) + { + entries.Add(new Entry() + { + Offset = reader.ReadInt32(), + Length = reader.ReadInt32(), + }); + } + + return entries + .Select(x => new SubStream(stream, x.Offset, x.Length)) + .ToList(); + } + + public static bool IsValid(Stream stream) => + stream.Length >= 4 && stream.SetPosition(0).ReadInt32() == MagicCode; + + public static IEnumerable Read(Stream stream) => + OpenAsStream(stream.SetPosition(0)).Select(x => Imgd.Read(x)).ToArray(); + + public static void Write(Stream stream, IEnumerable images) + { + if (!stream.CanWrite) + throw new InvalidDataException($"Read or seek must be supported."); + + var writer = new BinaryWriter(stream); + var count = images.Count(); + + writer.Write(MagicCode); + writer.Write(0x100); + writer.Write(0x10); // Header size; + writer.Write(count); + + int baseOffset = (int)(stream.Position + count * 8); + + // Align by 0x10 + if ((baseOffset & 0xF) != 0) + { + baseOffset += 0x10 - (baseOffset & 0xF); + } + + int currentOffset = baseOffset; + + var imgStreams = new List(count); + foreach (var image in images) + { + var memStream = new MemoryStream(); + image.Write(memStream); + imgStreams.Add(memStream); + + writer.Write(currentOffset); + writer.Write((int)memStream.Length); + + currentOffset += (int)memStream.Length; + } + + stream.Position = baseOffset; + foreach (var imgStream in imgStreams) + { + imgStream.Position = 0; + imgStream.WriteTo(stream); + } + } + } +} diff --git a/OpenKh.Kh2/Jigsaw.cs b/OpenKh.Kh2/Jigsaw.cs index ffc68a57e..a8eec1928 100644 --- a/OpenKh.Kh2/Jigsaw.cs +++ b/OpenKh.Kh2/Jigsaw.cs @@ -1,22 +1,22 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2 -{ - public class Jigsaw - { - [Data] public byte Picture { get; set; } - [Data] public byte Part { get; set; } - [Data] public ushort Text { get; set; } //z_un_002a2de8, binary addition 0x8000 - [Data] public byte World { get; set; } - [Data] public byte Room { get; set; } - [Data] public byte JigsawIdWorld { get; set; } - [Data] public byte Unk07 { get; set; } //has also something to do with pos and orientation - [Data] public ushort Unk08 { get; set; } //z_un_001d9d88, starting pos and orientation - - public static List Read(Stream stream) => BaseTable.Read(stream); - public static void Write(Stream stream, IEnumerable items) => - BaseTable.Write(stream, 2, items); - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2 +{ + public class Jigsaw + { + [Data] public byte Picture { get; set; } + [Data] public byte Part { get; set; } + [Data] public ushort Text { get; set; } //z_un_002a2de8, binary addition 0x8000 + [Data] public byte World { get; set; } + [Data] public byte Room { get; set; } + [Data] public byte JigsawIdWorld { get; set; } + [Data] public byte Unk07 { get; set; } //has also something to do with pos and orientation + [Data] public ushort Unk08 { get; set; } //z_un_001d9d88, starting pos and orientation + + public static List Read(Stream stream) => BaseTable.Read(stream); + public static void Write(Stream stream, IEnumerable items) => + BaseTable.Write(stream, 2, items); + } +} diff --git a/OpenKh.Kh2/Jiminy/Albu.cs b/OpenKh.Kh2/Jiminy/Albu.cs index b235dbed6..9bce78d7f 100644 --- a/OpenKh.Kh2/Jiminy/Albu.cs +++ b/OpenKh.Kh2/Jiminy/Albu.cs @@ -1,23 +1,23 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Jiminy -{ - public class Albu - { - public const int MagicCode = 0x4C414D4A; - - [Data] public byte World { get; set; } //Worl -> Id - [Data(Count = 2)] public string Number { get; set; } //menu//jm_photo/.bin - [Data] public byte Padding { get; set; } - [Data] public ushort Unk04 { get; set; } // Padding?, always 00 - [Data] public ushort StoryFlag { get; set; } - [Data] public ushort Title { get; set; } - [Data] public ushort Text { get; set; } - - public List Read(Stream stream) => BaseJiminy.Read(stream).Items; - public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Jiminy +{ + public class Albu + { + public const int MagicCode = 0x4C414D4A; + + [Data] public byte World { get; set; } //Worl -> Id + [Data(Count = 2)] public string Number { get; set; } //menu//jm_photo/.bin + [Data] public byte Padding { get; set; } + [Data] public ushort Unk04 { get; set; } // Padding?, always 00 + [Data] public ushort StoryFlag { get; set; } + [Data] public ushort Title { get; set; } + [Data] public ushort Text { get; set; } + + public List Read(Stream stream) => BaseJiminy.Read(stream).Items; + public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/Jiminy/Anse.cs b/OpenKh.Kh2/Jiminy/Anse.cs index ce223e092..6690629ca 100644 --- a/OpenKh.Kh2/Jiminy/Anse.cs +++ b/OpenKh.Kh2/Jiminy/Anse.cs @@ -1,20 +1,20 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Jiminy -{ - public class Anse - { - public const int MagicCode = 0x4E414D4A; - - [Data] public ushort Id { get; set; } //03system -> item - [Data] public ushort Title { get; set; } - [Data] public ushort Text { get; set; } - [Data] public ushort Padding { get; set; } - - public List Read(Stream stream) => BaseJiminy.Read(stream).Items; - public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Jiminy +{ + public class Anse + { + public const int MagicCode = 0x4E414D4A; + + [Data] public ushort Id { get; set; } //03system -> item + [Data] public ushort Title { get; set; } + [Data] public ushort Text { get; set; } + [Data] public ushort Padding { get; set; } + + public List Read(Stream stream) => BaseJiminy.Read(stream).Items; + public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/Jiminy/BaseJiminy.cs b/OpenKh.Kh2/Jiminy/BaseJiminy.cs index 5bd6603d9..57fae67fa 100644 --- a/OpenKh.Kh2/Jiminy/BaseJiminy.cs +++ b/OpenKh.Kh2/Jiminy/BaseJiminy.cs @@ -1,47 +1,47 @@ -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Jiminy -{ - public class BaseJiminy : IEnumerable - where T : class - { - [Data] public int MagicCode { get; set; } - [Data] public int Version { get; set; } - [Data] public int Count { get; set; } - [Data] public int Padding { get; set; } - public List Items { get; set; } - - public static BaseJiminy Read(Stream stream) - { - var baseTable = BinaryMapping.ReadObject>(stream); - baseTable.Items = Enumerable.Range(0, baseTable.Count) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList(); - return baseTable; - } - - public static void Write(Stream stream, int magic, int version, List items) => - new BaseJiminy() - { - MagicCode = magic, - Version = version, - Padding = 0, - Items = items - }.Write(stream); - public void Write(Stream stream) - { - Count = Items.Count; - BinaryMapping.WriteObject(stream, this); - foreach (var item in Items) - BinaryMapping.WriteObject(stream, item); - } - - public IEnumerator GetEnumerator() => Items.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => Items.GetEnumerator(); - } -} +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Jiminy +{ + public class BaseJiminy : IEnumerable + where T : class + { + [Data] public int MagicCode { get; set; } + [Data] public int Version { get; set; } + [Data] public int Count { get; set; } + [Data] public int Padding { get; set; } + public List Items { get; set; } + + public static BaseJiminy Read(Stream stream) + { + var baseTable = BinaryMapping.ReadObject>(stream); + baseTable.Items = Enumerable.Range(0, baseTable.Count) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList(); + return baseTable; + } + + public static void Write(Stream stream, int magic, int version, List items) => + new BaseJiminy() + { + MagicCode = magic, + Version = version, + Padding = 0, + Items = items + }.Write(stream); + public void Write(Stream stream) + { + Count = Items.Count; + BinaryMapping.WriteObject(stream, this); + foreach (var item in Items) + BinaryMapping.WriteObject(stream, item); + } + + public IEnumerator GetEnumerator() => Items.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => Items.GetEnumerator(); + } +} diff --git a/OpenKh.Kh2/Jiminy/Char.cs b/OpenKh.Kh2/Jiminy/Char.cs index f4ce4cc11..cad0b0caa 100644 --- a/OpenKh.Kh2/Jiminy/Char.cs +++ b/OpenKh.Kh2/Jiminy/Char.cs @@ -1,35 +1,35 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Jiminy -{ - public class Char - { - public const int MagicCode = 0x48434D4A; - - [Data] public byte World { get; set; } - [Data] public byte Picture { get; set; } //index jmface - [Data] public byte PictureBgColor { get; set; } - [Data] public byte Padding { get; set; } - [Data] public ushort Id { get; set; } - [Data] public ushort Title { get; set; } - [Data] public ushort Description { get; set; } - [Data] public ushort SecondTitle { get; set; } //used for disney and ff characters, describes where they come from - [Data] public ushort ObjectId { get; set; } //00objentry - [Data] public ushort Unk0E { get; set; } - [Data] public ushort Unk10 { get; set; } - [Data] public short ObjectPositionX { get; set; } //z_un_0029e4c8 - [Data] public short ObjectPositionY { get; set; } - [Data] public short ObjectRotationX { get; set; } - [Data] public short Unk18 { get; set; } - [Data] public short Unk1A { get; set; } - [Data] public float Unk1C { get; set; } //this is read like a float, but the it behaves different?! third byte controls the size - [Data] public float Unk20 { get; set; } - - public static List Read(Stream stream) => BaseJiminy.Read(stream).Items; - public static void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); - - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Jiminy +{ + public class Char + { + public const int MagicCode = 0x48434D4A; + + [Data] public byte World { get; set; } + [Data] public byte Picture { get; set; } //index jmface + [Data] public byte PictureBgColor { get; set; } + [Data] public byte Padding { get; set; } + [Data] public ushort Id { get; set; } + [Data] public ushort Title { get; set; } + [Data] public ushort Description { get; set; } + [Data] public ushort SecondTitle { get; set; } //used for disney and ff characters, describes where they come from + [Data] public ushort ObjectId { get; set; } //00objentry + [Data] public ushort Unk0E { get; set; } + [Data] public ushort Unk10 { get; set; } + [Data] public short ObjectPositionX { get; set; } //z_un_0029e4c8 + [Data] public short ObjectPositionY { get; set; } + [Data] public short ObjectRotationX { get; set; } + [Data] public short Unk18 { get; set; } + [Data] public short Unk1A { get; set; } + [Data] public float Unk1C { get; set; } //this is read like a float, but the it behaves different?! third byte controls the size + [Data] public float Unk20 { get; set; } + + public static List Read(Stream stream) => BaseJiminy.Read(stream).Items; + public static void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); + + } +} diff --git a/OpenKh.Kh2/Jiminy/Diag.cs b/OpenKh.Kh2/Jiminy/Diag.cs index 8871aa82d..dc82f4da2 100644 --- a/OpenKh.Kh2/Jiminy/Diag.cs +++ b/OpenKh.Kh2/Jiminy/Diag.cs @@ -1,22 +1,22 @@ -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Jiminy -{ - public class Diag - { - public const int MagicCode = 0x49444D4A; - - public class Flag - { - [Data] public ushort Id { get; set; } - [Data] public ushort Unk02 { get; set; } - [Data] public byte World { get; set; } - [Data] public byte Room { get; set; } - [Data] public byte Unk06 { get; set; } - [Data] public byte Padding { get; set; } - [Data] public int Unk08 { get; set; } - } - - //z_un_002a18d0 - } -} +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Jiminy +{ + public class Diag + { + public const int MagicCode = 0x49444D4A; + + public class Flag + { + [Data] public ushort Id { get; set; } + [Data] public ushort Unk02 { get; set; } + [Data] public byte World { get; set; } + [Data] public byte Room { get; set; } + [Data] public byte Unk06 { get; set; } + [Data] public byte Padding { get; set; } + [Data] public int Unk08 { get; set; } + } + + //z_un_002a18d0 + } +} diff --git a/OpenKh.Kh2/Jiminy/Limi.cs b/OpenKh.Kh2/Jiminy/Limi.cs index 4a9fb4ad4..f4d9c451e 100644 --- a/OpenKh.Kh2/Jiminy/Limi.cs +++ b/OpenKh.Kh2/Jiminy/Limi.cs @@ -1,20 +1,20 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Jiminy -{ - public class Limi - { - public const int MagicCode = 0x494C4D4A; - - [Data] public ushort Unk00 { get; set; } - [Data] public ushort Title { get; set; } - [Data] public ushort Description { get; set; } - [Data] public ushort Padding { get; set; } - - public List Read(Stream stream) => BaseJiminy.Read(stream).Items; - public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Jiminy +{ + public class Limi + { + public const int MagicCode = 0x494C4D4A; + + [Data] public ushort Unk00 { get; set; } + [Data] public ushort Title { get; set; } + [Data] public ushort Description { get; set; } + [Data] public ushort Padding { get; set; } + + public List Read(Stream stream) => BaseJiminy.Read(stream).Items; + public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/Jiminy/Mini.cs b/OpenKh.Kh2/Jiminy/Mini.cs index 7a840daf9..825bfc2c5 100644 --- a/OpenKh.Kh2/Jiminy/Mini.cs +++ b/OpenKh.Kh2/Jiminy/Mini.cs @@ -1,20 +1,20 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Jiminy -{ - public class Mini - { - public const int MagicCode = 0x474D4D4A; - - [Data] public ushort World { get; set; } - [Data] public ushort Title { get; set; } - [Data] public ushort HighscoreText { get; set; } - [Data] public ushort Unk06 { get; set; } - - public List Read(Stream stream) => BaseJiminy.Read(stream).Items; - public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Jiminy +{ + public class Mini + { + public const int MagicCode = 0x474D4D4A; + + [Data] public ushort World { get; set; } + [Data] public ushort Title { get; set; } + [Data] public ushort HighscoreText { get; set; } + [Data] public ushort Unk06 { get; set; } + + public List Read(Stream stream) => BaseJiminy.Read(stream).Items; + public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/Jiminy/Puzz.cs b/OpenKh.Kh2/Jiminy/Puzz.cs index 8857147de..bb918a854 100644 --- a/OpenKh.Kh2/Jiminy/Puzz.cs +++ b/OpenKh.Kh2/Jiminy/Puzz.cs @@ -1,45 +1,45 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Jiminy -{ - public class Puzz - { - public const int MagicCode = 0x5A504D4A; - - public enum Rotation : byte - { - Fixed = 0x0, - Rotatable = 0x1, - } - - public enum PuzzleSize : byte - { - Twelve = 0x0, - FourtyEight = 0x1, - } - - [Data] public byte Id { get; set; } - [Data] public byte Unk1 { get; set; } - [Data] public ushort Name { get; set; } - [Data] public ushort RewardItem { get; set; } - [Data(Count = 0xA)] public string FileName { get; set; } - - public int PieceRotation - { - get => Unk1 >> 4; - set => Unk1 = (byte)((Unk1 & 0x0F) | (value << 4)); - } - - public int Size - { - get => Unk1 & 0xF; - set => Unk1 = (byte)((Unk1 & 0xF0) | (value & 0xF)); - } - - public static List Read(Stream stream) => BaseJiminy.Read(stream).Items; - public static void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Jiminy +{ + public class Puzz + { + public const int MagicCode = 0x5A504D4A; + + public enum Rotation : byte + { + Fixed = 0x0, + Rotatable = 0x1, + } + + public enum PuzzleSize : byte + { + Twelve = 0x0, + FourtyEight = 0x1, + } + + [Data] public byte Id { get; set; } + [Data] public byte Unk1 { get; set; } + [Data] public ushort Name { get; set; } + [Data] public ushort RewardItem { get; set; } + [Data(Count = 0xA)] public string FileName { get; set; } + + public int PieceRotation + { + get => Unk1 >> 4; + set => Unk1 = (byte)((Unk1 & 0x0F) | (value << 4)); + } + + public int Size + { + get => Unk1 & 0xF; + set => Unk1 = (byte)((Unk1 & 0xF0) | (value & 0xF)); + } + + public static List Read(Stream stream) => BaseJiminy.Read(stream).Items; + public static void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/Jiminy/Ques.cs b/OpenKh.Kh2/Jiminy/Ques.cs index ebbe23955..832748be1 100644 --- a/OpenKh.Kh2/Jiminy/Ques.cs +++ b/OpenKh.Kh2/Jiminy/Ques.cs @@ -1,24 +1,24 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Jiminy -{ - public class Ques - { - public const int MagicCode = 0x55514D4A; - - [Data] public ushort World { get; set; } - [Data] public ushort CategoryText { get; set; } - [Data] public ushort Title { get; set; } - [Data] public ushort Unk06 { get; set; } //z_un_002a99c8 - [Data] public ushort StoryFlag { get; set; } - [Data] public ushort Unk0A { get; set; } - [Data] public ushort Unk0C { get; set; } - [Data] public ushort Unk0E { get; set; } - - public List Read(Stream stream) => BaseJiminy.Read(stream).Items; - public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Jiminy +{ + public class Ques + { + public const int MagicCode = 0x55514D4A; + + [Data] public ushort World { get; set; } + [Data] public ushort CategoryText { get; set; } + [Data] public ushort Title { get; set; } + [Data] public ushort Unk06 { get; set; } //z_un_002a99c8 + [Data] public ushort StoryFlag { get; set; } + [Data] public ushort Unk0A { get; set; } + [Data] public ushort Unk0C { get; set; } + [Data] public ushort Unk0E { get; set; } + + public List Read(Stream stream) => BaseJiminy.Read(stream).Items; + public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/Jiminy/Stor.cs b/OpenKh.Kh2/Jiminy/Stor.cs index 722b67fb4..f147bf74f 100644 --- a/OpenKh.Kh2/Jiminy/Stor.cs +++ b/OpenKh.Kh2/Jiminy/Stor.cs @@ -1,23 +1,23 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Jiminy -{ - public class Stor - { - public const int MagicCode = 0x54534D4A; - - [Data] public byte World { get; set; } - [Data] public byte Unk1 { get; set; } //always 00 - [Data] public ushort Unk2 { get; set; } //always 0000 - [Data] public ushort SummaryText { get; set; } - [Data] public ushort ObjectiveText { get; set; } - [Data] public ushort StoryText { get; set; } - [Data] public ushort StoryFlag { get; set; } - - public List Read(Stream stream) => BaseJiminy.Read(stream).Items; - public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Jiminy +{ + public class Stor + { + public const int MagicCode = 0x54534D4A; + + [Data] public byte World { get; set; } + [Data] public byte Unk1 { get; set; } //always 00 + [Data] public ushort Unk2 { get; set; } //always 0000 + [Data] public ushort SummaryText { get; set; } + [Data] public ushort ObjectiveText { get; set; } + [Data] public ushort StoryText { get; set; } + [Data] public ushort StoryFlag { get; set; } + + public List Read(Stream stream) => BaseJiminy.Read(stream).Items; + public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/Jiminy/Worl.cs b/OpenKh.Kh2/Jiminy/Worl.cs index 3be778184..e03596ea5 100644 --- a/OpenKh.Kh2/Jiminy/Worl.cs +++ b/OpenKh.Kh2/Jiminy/Worl.cs @@ -1,25 +1,25 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Jiminy -{ - public class Worl - { - public const int MagicCode = 0x4F574D4A; - - [Data] public byte Id { get; set; } //also responsible for world icon in journal, menu//jm_world.2ld - [Data(Count = 2)] public string Name { get; set; } - [Data] public byte Padding { get; set; } - [Data] public ushort TextTitle { get; set; } - [Data] public ushort TextSubmenu { get; set; } - [Data] public ushort StoryFlag { get; set; } //this same flag is used in multiple subfiles, probably to determine a world name switch?? - [Data] public ushort TextTitle2 { get; set; } //these 3 fields are only used by hollow bastion, to switch to radiant garden later - [Data] public ushort TextSubmenu2 { get; set; } - [Data] public ushort Unk0E { get; set; } - - public List Read(Stream stream) => BaseJiminy.Read(stream).Items; - public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Jiminy +{ + public class Worl + { + public const int MagicCode = 0x4F574D4A; + + [Data] public byte Id { get; set; } //also responsible for world icon in journal, menu//jm_world.2ld + [Data(Count = 2)] public string Name { get; set; } + [Data] public byte Padding { get; set; } + [Data] public ushort TextTitle { get; set; } + [Data] public ushort TextSubmenu { get; set; } + [Data] public ushort StoryFlag { get; set; } //this same flag is used in multiple subfiles, probably to determine a world name switch?? + [Data] public ushort TextTitle2 { get; set; } //these 3 fields are only used by hollow bastion, to switch to radiant garden later + [Data] public ushort TextSubmenu2 { get; set; } + [Data] public ushort Unk0E { get; set; } + + public List Read(Stream stream) => BaseJiminy.Read(stream).Items; + public void Write(Stream stream, int version, IEnumerable items) => BaseJiminy.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/Layout.cs b/OpenKh.Kh2/Layout.cs index 7e606bcb3..e3ca02650 100644 --- a/OpenKh.Kh2/Layout.cs +++ b/OpenKh.Kh2/Layout.cs @@ -1,170 +1,170 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; -using Xe.IO; - -namespace OpenKh.Kh2 -{ - public class Layout - { - public const uint MagicCodeValidator = 0x4459414CU; - private const int SupportedVersion = 0x100; - private static readonly long MinimumLength = 32L; - - private class Header - { - [Data] public uint MagicCode { get; set; } - [Data] public int Version { get; set; } - [Data] public int L1Count { get; set; } - [Data] public int L1Offset { get; set; } - [Data] public int L2Count { get; set; } - [Data] public int L2Offset { get; set; } - [Data] public int SequenceCount { get; set; } - [Data] public int SequenceOffset { get; set; } - } - - private class RawSequenceGroup - { - [Data] public short L1Index { get; set; } - [Data] public short L1Count { get; set; } - [Data] public int Unknown04 { get; set; } - [Data] public int Unknown08 { get; set; } - [Data] public int Unknown0c { get; set; } - [Data] public int Unknown10 { get; set; } - } - - public class SequenceProperty - { - [Data] public int TextureIndex { get; set; } - [Data] public int SequenceIndex { get; set; } - [Data] public int AnimationGroup { get; set; } - [Data] public int ShowAtFrame { get; set; } - [Data] public int PositionX { get; set; } - [Data] public int PositionY { get; set; } - } - - public class SequenceGroup - { - public List Sequences { get; set; } - public int Unknown04 { get; set; } - public int Unknown08 { get; set; } - public int Unknown0c { get; set; } - public int Unknown10 { get; set; } - } - - public List SequenceGroups { get; set; } - public List SequenceItems { get; set; } - - public Layout() - { } - - internal Layout(Stream stream) - { - if (!stream.CanRead || !stream.CanSeek) - throw new InvalidDataException($"Read or seek must be supported."); - - if (stream.Length < MinimumLength) - throw new InvalidDataException("Invalid header length"); - - var header = BinaryMapping.ReadObject
(stream); - if (header.MagicCode != MagicCodeValidator) - throw new InvalidDataException("Invalid header"); - if (header.Version != SupportedVersion) - throw new InvalidDataException($"Unsupported version {header.Version}"); - - var sequenceProperties = stream.ReadList(header.L1Offset, header.L1Count); - SequenceGroups = stream - .ReadList(header.L2Offset, header.L2Count) - .Select(x => new SequenceGroup - { - Sequences = sequenceProperties.Skip(x.L1Index).Take(x.L1Count).ToList(), - Unknown04 = x.Unknown04, - Unknown08 = x.Unknown08, - Unknown0c = x.Unknown0c, - Unknown10 = x.Unknown10 - }) - .ToList(); - - SequenceItems = new List(); - - var sequenceOffsets = stream.ReadInt32List(header.SequenceOffset, header.SequenceCount); - sequenceOffsets.Add((int)stream.Length); - for (var i = 0; i < sequenceOffsets.Count - 1; i++) - { - // TODO Assuming that the sequence files are stored in order... - int offset = sequenceOffsets[i]; - var length = sequenceOffsets[i + 1] - offset; - var sequenceStream = new SubStream(stream, offset, length); - SequenceItems.Add(Sequence.Read(sequenceStream)); - } - } - - public void Write(Stream stream) - { - if (!stream.CanWrite || !stream.CanSeek) - throw new InvalidDataException($"Write and seek must be supported."); - - var sequenceProperties = SequenceGroups - .SelectMany(x => x.Sequences) - .ToList(); - var header = new Header - { - MagicCode = MagicCodeValidator, - Version = SupportedVersion, - L1Count = sequenceProperties.Count, - L2Count = SequenceGroups.Count, - SequenceCount = SequenceItems.Count, - }; - - stream.Position = MinimumLength; - header.L1Offset = (int)stream.Position; - header.L2Offset = stream.WriteList(sequenceProperties) + header.L1Offset; - - var oldPosition = stream.Position; - var index = 0; - foreach (var item in SequenceGroups) - { - BinaryMapping.WriteObject(stream, new RawSequenceGroup - { - L1Index = (short)index, - L1Count = (short)item.Sequences.Count, - Unknown04 = item.Unknown04, - Unknown08 = item.Unknown08, - Unknown0c = item.Unknown0c, - Unknown10 = item.Unknown10, - }); - - index += item.Sequences.Count; - } - header.SequenceOffset = (int)(stream.Position - oldPosition + header.L2Offset); - WriteSequences(stream); - - stream.Position = 0; - BinaryMapping.WriteObject(stream, header); - } - - private void WriteSequences(Stream stream) - { - var currentPosition = stream.Position; - var offsets = new int[SequenceItems.Count]; - - stream.Position += SequenceItems.Count * 4; - for (var i = 0; i < SequenceItems.Count; i++) - { - offsets[i] = (int)stream.Position; - SequenceItems[i].Write(stream); - } - - stream.Position = currentPosition; - stream.Write(offsets); - } - - public static bool IsValid(Stream stream) => - stream.Length >= MinimumLength && stream.PeekInt32() == MagicCodeValidator; - - public static Layout Read(Stream stream) => new Layout(stream); - - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; +using Xe.IO; + +namespace OpenKh.Kh2 +{ + public class Layout + { + public const uint MagicCodeValidator = 0x4459414CU; + private const int SupportedVersion = 0x100; + private static readonly long MinimumLength = 32L; + + private class Header + { + [Data] public uint MagicCode { get; set; } + [Data] public int Version { get; set; } + [Data] public int L1Count { get; set; } + [Data] public int L1Offset { get; set; } + [Data] public int L2Count { get; set; } + [Data] public int L2Offset { get; set; } + [Data] public int SequenceCount { get; set; } + [Data] public int SequenceOffset { get; set; } + } + + private class RawSequenceGroup + { + [Data] public short L1Index { get; set; } + [Data] public short L1Count { get; set; } + [Data] public int Unknown04 { get; set; } + [Data] public int Unknown08 { get; set; } + [Data] public int Unknown0c { get; set; } + [Data] public int Unknown10 { get; set; } + } + + public class SequenceProperty + { + [Data] public int TextureIndex { get; set; } + [Data] public int SequenceIndex { get; set; } + [Data] public int AnimationGroup { get; set; } + [Data] public int ShowAtFrame { get; set; } + [Data] public int PositionX { get; set; } + [Data] public int PositionY { get; set; } + } + + public class SequenceGroup + { + public List Sequences { get; set; } + public int Unknown04 { get; set; } + public int Unknown08 { get; set; } + public int Unknown0c { get; set; } + public int Unknown10 { get; set; } + } + + public List SequenceGroups { get; set; } + public List SequenceItems { get; set; } + + public Layout() + { } + + internal Layout(Stream stream) + { + if (!stream.CanRead || !stream.CanSeek) + throw new InvalidDataException($"Read or seek must be supported."); + + if (stream.Length < MinimumLength) + throw new InvalidDataException("Invalid header length"); + + var header = BinaryMapping.ReadObject
(stream); + if (header.MagicCode != MagicCodeValidator) + throw new InvalidDataException("Invalid header"); + if (header.Version != SupportedVersion) + throw new InvalidDataException($"Unsupported version {header.Version}"); + + var sequenceProperties = stream.ReadList(header.L1Offset, header.L1Count); + SequenceGroups = stream + .ReadList(header.L2Offset, header.L2Count) + .Select(x => new SequenceGroup + { + Sequences = sequenceProperties.Skip(x.L1Index).Take(x.L1Count).ToList(), + Unknown04 = x.Unknown04, + Unknown08 = x.Unknown08, + Unknown0c = x.Unknown0c, + Unknown10 = x.Unknown10 + }) + .ToList(); + + SequenceItems = new List(); + + var sequenceOffsets = stream.ReadInt32List(header.SequenceOffset, header.SequenceCount); + sequenceOffsets.Add((int)stream.Length); + for (var i = 0; i < sequenceOffsets.Count - 1; i++) + { + // TODO Assuming that the sequence files are stored in order... + int offset = sequenceOffsets[i]; + var length = sequenceOffsets[i + 1] - offset; + var sequenceStream = new SubStream(stream, offset, length); + SequenceItems.Add(Sequence.Read(sequenceStream)); + } + } + + public void Write(Stream stream) + { + if (!stream.CanWrite || !stream.CanSeek) + throw new InvalidDataException($"Write and seek must be supported."); + + var sequenceProperties = SequenceGroups + .SelectMany(x => x.Sequences) + .ToList(); + var header = new Header + { + MagicCode = MagicCodeValidator, + Version = SupportedVersion, + L1Count = sequenceProperties.Count, + L2Count = SequenceGroups.Count, + SequenceCount = SequenceItems.Count, + }; + + stream.Position = MinimumLength; + header.L1Offset = (int)stream.Position; + header.L2Offset = stream.WriteList(sequenceProperties) + header.L1Offset; + + var oldPosition = stream.Position; + var index = 0; + foreach (var item in SequenceGroups) + { + BinaryMapping.WriteObject(stream, new RawSequenceGroup + { + L1Index = (short)index, + L1Count = (short)item.Sequences.Count, + Unknown04 = item.Unknown04, + Unknown08 = item.Unknown08, + Unknown0c = item.Unknown0c, + Unknown10 = item.Unknown10, + }); + + index += item.Sequences.Count; + } + header.SequenceOffset = (int)(stream.Position - oldPosition + header.L2Offset); + WriteSequences(stream); + + stream.Position = 0; + BinaryMapping.WriteObject(stream, header); + } + + private void WriteSequences(Stream stream) + { + var currentPosition = stream.Position; + var offsets = new int[SequenceItems.Count]; + + stream.Position += SequenceItems.Count * 4; + for (var i = 0; i < SequenceItems.Count; i++) + { + offsets[i] = (int)stream.Position; + SequenceItems[i].Write(stream); + } + + stream.Position = currentPosition; + stream.Write(offsets); + } + + public static bool IsValid(Stream stream) => + stream.Length >= MinimumLength && stream.PeekInt32() == MagicCodeValidator; + + public static Layout Read(Stream stream) => new Layout(stream); + + } +} diff --git a/OpenKh.Kh2/Mdlx.Map.cs b/OpenKh.Kh2/Mdlx.Map.cs index b1afca45b..f3cacc125 100644 --- a/OpenKh.Kh2/Mdlx.Map.cs +++ b/OpenKh.Kh2/Mdlx.Map.cs @@ -1,259 +1,261 @@ -// Original source code: https://gitlab.com/kenjiuno/khkh_xldM/blob/master/khkh_xldMii/Mdlxfst.cs - -using OpenKh.Common; -using OpenKh.Common.Ps2; -using OpenKh.Common.Utils; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2 -{ - public partial class Mdlx - { - public class SubModelMapHeader - { - [Data] public int Type { get; set; } - [Data] public int Unk04 { get; set; } - [Data] public int Unk08 { get; set; } - [Data] public int NextOffset { get; set; } - [Data] public int DmaChainMapCount { get; set; } - [Data] public short va4 { get; set; } - [Data] public short CountVifPacketRenderingGroup { get; set; } - [Data] public int OffsetVifPacketRenderingGroup { get; set; } - [Data] public int OffsetToOffsetDmaChainIndexRemapTable { get; set; } - } - - private class DmaChainMap - { - [Data] public int VifOffset { get; set; } - [Data] public int TextureIndex { get; set; } - [Data] public short Unk08 { get; set; } - [Data] public short IsTransparentFlag { get; set; } - [Data] public int Unk0c { get; set; } - - public bool EnableUvsc - { - get => BitsUtil.Int.GetBit(Unk0c, 1); - set => Unk0c = BitsUtil.Int.SetBit(Unk0c, 1, value); - } - - public int UvscIndex - { - get => BitsUtil.Int.GetBits(Unk0c, 2, 4); - set => Unk0c = BitsUtil.Int.SetBits(Unk0c, 2, 4, value); - } - } - - public class M4 - { - public int unk04; - public int unk08; - public int nextOffset; - public short va4; - public List DmaChainIndexRemapTable; - public List vifPacketRenderingGroup; - public List VifPackets; - } - - public class VifPacketDescriptor - { - public byte[] VifPacket { get; set; } - public int TextureId { get; set; } - public short Unk08 { get; set; } - public short IsTransparentFlag { get; set; } - public int Unk0c { get; set; } - public ushort[] DmaPerVif { get; set; } - - public bool EnableUvsc - { - get => BitsUtil.Int.GetBit(Unk0c, 1); - set => Unk0c = BitsUtil.Int.SetBit(Unk0c, 1, value); - } - - public int UvscIndex - { - get => BitsUtil.Int.GetBits(Unk0c, 2, 4); - set => Unk0c = BitsUtil.Int.SetBits(Unk0c, 2, 4, value); - } - } - - private static M4 ReadAsMap(Stream stream) - { - var header = BinaryMapping.ReadObject(stream); - if (header.Type != Map) throw new NotSupportedException("Type must be 2 for maps"); - - var dmaChainMaps = For(header.DmaChainMapCount, () => BinaryMapping.ReadObject(stream)); - - stream.Position = header.OffsetVifPacketRenderingGroup; - - // The original game engine ignores header.Count1 for some reason - var count1 = (short)((stream.ReadInt32() - header.OffsetVifPacketRenderingGroup) / 4); - stream.Position -= 4; - - var vifPacketRenderingGroup = For(count1, () => stream.ReadInt32()) - .Select(offset => ReadUInt16List(stream.SetPosition(offset)).ToArray()) - .ToList(); - - stream.Position = header.OffsetToOffsetDmaChainIndexRemapTable; - var offsetDmaChainIndexRemapTable = stream.ReadInt32(); +// Original source code: https://gitlab.com/kenjiuno/khkh_xldM/blob/master/khkh_xldMii/Mdlxfst.cs + +using OpenKh.Common; +using OpenKh.Common.Ps2; +using OpenKh.Common.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2 +{ + public partial class Mdlx + { + public class SubModelMapHeader + { + [Data] public int Type { get; set; } + [Data] public int Unk04 { get; set; } + [Data] public int Unk08 { get; set; } + [Data] public int NextOffset { get; set; } + [Data] public int DmaChainMapCount { get; set; } + [Data] public short va4 { get; set; } + [Data] public short CountVifPacketRenderingGroup { get; set; } + [Data] public int OffsetVifPacketRenderingGroup { get; set; } + [Data] public int OffsetToOffsetDmaChainIndexRemapTable { get; set; } + } + + private class DmaChainMap + { + [Data] public int VifOffset { get; set; } + [Data] public int TextureIndex { get; set; } + [Data] public short Unk08 { get; set; } + [Data] public short IsTransparentFlag { get; set; } + [Data] public int Unk0c { get; set; } + + public bool EnableUvsc + { + get => BitsUtil.Int.GetBit(Unk0c, 1); + set => Unk0c = BitsUtil.Int.SetBit(Unk0c, 1, value); + } + + public int UvscIndex + { + get => BitsUtil.Int.GetBits(Unk0c, 2, 4); + set => Unk0c = BitsUtil.Int.SetBits(Unk0c, 2, 4, value); + } + } + + public class M4 + { + public int unk04; + public int unk08; + public int nextOffset; + public short va4; + public List DmaChainIndexRemapTable; + public List vifPacketRenderingGroup; + public List VifPackets; + } + + public class VifPacketDescriptor + { + public byte[] VifPacket { get; set; } + public int TextureId { get; set; } + public short Unk08 { get; set; } + public short IsTransparentFlag { get; set; } + public int Unk0c { get; set; } + public ushort[] DmaPerVif { get; set; } + + public bool EnableUvsc + { + get => BitsUtil.Int.GetBit(Unk0c, 1); + set => Unk0c = BitsUtil.Int.SetBit(Unk0c, 1, value); + } + + public int UvscIndex + { + get => BitsUtil.Int.GetBits(Unk0c, 2, 4); + set => Unk0c = BitsUtil.Int.SetBits(Unk0c, 2, 4, value); + } + } + + private static M4 ReadAsMap(Stream stream) + { + var header = BinaryMapping.ReadObject(stream); + if (header.Type != Map) + throw new NotSupportedException("Type must be 2 for maps"); + + var dmaChainMaps = For(header.DmaChainMapCount, () => BinaryMapping.ReadObject(stream)); + + stream.Position = header.OffsetVifPacketRenderingGroup; + + // The original game engine ignores header.Count1 for some reason + var count1 = (short)((stream.ReadInt32() - header.OffsetVifPacketRenderingGroup) / 4); + stream.Position -= 4; + + var vifPacketRenderingGroup = For(count1, () => stream.ReadInt32()) + .Select(offset => ReadUInt16List(stream.SetPosition(offset)).ToArray()) + .ToList(); + + stream.Position = header.OffsetToOffsetDmaChainIndexRemapTable; + var offsetDmaChainIndexRemapTable = stream.ReadInt32(); stream.Position = offsetDmaChainIndexRemapTable; - var dmaChainIndexRemapTable = ReadUInt16List(stream) - .ToList(); - - var vifPackets = dmaChainMaps - .Select(dmaChain => - { - var currentVifOffset = dmaChain.VifOffset; - - DmaTag dmaTag; - var packet = new List(); - var sizePerDma = new List(); - do - { - stream.Position = currentVifOffset; - dmaTag = BinaryMapping.ReadObject(stream); - var packets = stream.ReadBytes(8 + 16 * dmaTag.Qwc); - - packet.AddRange(packets); - - sizePerDma.Add(dmaTag.Qwc); - currentVifOffset += 16 + 16 * dmaTag.Qwc; - } while (dmaTag.TagId < 2); - - return new VifPacketDescriptor - { - VifPacket = packet.ToArray(), - TextureId = dmaChain.TextureIndex, - Unk08 = dmaChain.Unk08, - IsTransparentFlag = dmaChain.IsTransparentFlag, - Unk0c = dmaChain.Unk0c, - DmaPerVif = sizePerDma.ToArray(), - }; - }) - .ToList(); - - return new M4 - { - unk04 = header.Unk04, - unk08 = header.Unk08, - nextOffset = header.NextOffset, - va4 = header.va4, - - vifPacketRenderingGroup = vifPacketRenderingGroup, - DmaChainIndexRemapTable = dmaChainIndexRemapTable, - VifPackets = vifPackets - }; - } - - private static void WriteAsMap(Stream stream, M4 mapModel) - { - var mapHeader = new SubModelMapHeader - { - Type = Map, - DmaChainMapCount = mapModel.VifPackets.Count, - - Unk04 = mapModel.unk04, - Unk08 = mapModel.unk08, - NextOffset = mapModel.nextOffset, - va4 = mapModel.va4, - CountVifPacketRenderingGroup = Convert.ToInt16(mapModel.vifPacketRenderingGroup.Count), - }; - - BinaryMapping.WriteObject(stream, mapHeader); - - var dmaChainMapDescriptorOffset = (int)stream.Position; - stream.Position += mapModel.VifPackets.Count * 0x10; - - mapHeader.OffsetVifPacketRenderingGroup = (int)stream.Position; - stream.Position += mapModel.vifPacketRenderingGroup.Count * 4; - var groupOffsets = new List(); - foreach (var group in mapModel.vifPacketRenderingGroup) - { - groupOffsets.Add((int)stream.Position); - WriteUInt16List(stream, group); - } - - // capture remapTable offset here - var remapTableOffsetToOffset = Helpers.Align((int)stream.Position, 4); - - // seek back and fill offsets - stream.Position = mapHeader.OffsetVifPacketRenderingGroup; - foreach (var offset in groupOffsets) - stream.Write(offset); - - // write remapTable here - stream.Position = remapTableOffsetToOffset; - mapHeader.OffsetToOffsetDmaChainIndexRemapTable = remapTableOffsetToOffset; - var remapTableOffset = remapTableOffsetToOffset + 4; - stream.Write(remapTableOffset); - WriteUInt16List(stream, mapModel.DmaChainIndexRemapTable); - - stream.AlignPosition(0x10); - - var dmaChainVifOffsets = new List(); - foreach (var dmaChainMap in mapModel.VifPackets) - { - var vifPacketIndex = 0; - dmaChainVifOffsets.Add((int)stream.Position); - - foreach (var packetCount in dmaChainMap.DmaPerVif) - { - BinaryMapping.WriteObject(stream, new DmaTag - { - Qwc = packetCount, - Address = 0, - TagId = packetCount > 0 ? 1 : 6, - Irq = false, - }); - - var packetLength = packetCount * 0x10 + 8; - stream.Write(dmaChainMap.VifPacket, vifPacketIndex, packetLength); - - vifPacketIndex += packetLength; - } - } - - stream.AlignPosition(0x80); - stream.SetLength(stream.Position); - - stream.Position = dmaChainMapDescriptorOffset; - for (var i = 0; i < mapModel.VifPackets.Count; i++) - { - var dmaChainMap = mapModel.VifPackets[i]; - BinaryMapping.WriteObject(stream, new DmaChainMap - { - VifOffset = dmaChainVifOffsets[i], - TextureIndex = dmaChainMap.TextureId, - Unk08 = dmaChainMap.Unk08, - IsTransparentFlag = dmaChainMap.IsTransparentFlag, - Unk0c = dmaChainMap.Unk0c, - EnableUvsc = dmaChainMap.EnableUvsc, - UvscIndex = dmaChainMap.UvscIndex, - }); - } - - stream.Position = 0; - BinaryMapping.WriteObject(stream, mapHeader); - } - - private static IEnumerable ReadUInt16List(Stream stream) - { - while (true) - { - var data = stream.ReadUInt16(); - if (data == 0xFFFF) break; - yield return data; - } - } - - private static void WriteUInt16List(Stream stream, IEnumerable alb2t2) - { - foreach (var data in alb2t2) - stream.Write(data); - stream.Write((ushort)0xFFFF); - } - } -} + var dmaChainIndexRemapTable = ReadUInt16List(stream) + .ToList(); + + var vifPackets = dmaChainMaps + .Select(dmaChain => + { + var currentVifOffset = dmaChain.VifOffset; + + DmaTag dmaTag; + var packet = new List(); + var sizePerDma = new List(); + do + { + stream.Position = currentVifOffset; + dmaTag = BinaryMapping.ReadObject(stream); + var packets = stream.ReadBytes(8 + 16 * dmaTag.Qwc); + + packet.AddRange(packets); + + sizePerDma.Add(dmaTag.Qwc); + currentVifOffset += 16 + 16 * dmaTag.Qwc; + } while (dmaTag.TagId < 2); + + return new VifPacketDescriptor + { + VifPacket = packet.ToArray(), + TextureId = dmaChain.TextureIndex, + Unk08 = dmaChain.Unk08, + IsTransparentFlag = dmaChain.IsTransparentFlag, + Unk0c = dmaChain.Unk0c, + DmaPerVif = sizePerDma.ToArray(), + }; + }) + .ToList(); + + return new M4 + { + unk04 = header.Unk04, + unk08 = header.Unk08, + nextOffset = header.NextOffset, + va4 = header.va4, + + vifPacketRenderingGroup = vifPacketRenderingGroup, + DmaChainIndexRemapTable = dmaChainIndexRemapTable, + VifPackets = vifPackets + }; + } + + private static void WriteAsMap(Stream stream, M4 mapModel) + { + var mapHeader = new SubModelMapHeader + { + Type = Map, + DmaChainMapCount = mapModel.VifPackets.Count, + + Unk04 = mapModel.unk04, + Unk08 = mapModel.unk08, + NextOffset = mapModel.nextOffset, + va4 = mapModel.va4, + CountVifPacketRenderingGroup = Convert.ToInt16(mapModel.vifPacketRenderingGroup.Count), + }; + + BinaryMapping.WriteObject(stream, mapHeader); + + var dmaChainMapDescriptorOffset = (int)stream.Position; + stream.Position += mapModel.VifPackets.Count * 0x10; + + mapHeader.OffsetVifPacketRenderingGroup = (int)stream.Position; + stream.Position += mapModel.vifPacketRenderingGroup.Count * 4; + var groupOffsets = new List(); + foreach (var group in mapModel.vifPacketRenderingGroup) + { + groupOffsets.Add((int)stream.Position); + WriteUInt16List(stream, group); + } + + // capture remapTable offset here + var remapTableOffsetToOffset = Helpers.Align((int)stream.Position, 4); + + // seek back and fill offsets + stream.Position = mapHeader.OffsetVifPacketRenderingGroup; + foreach (var offset in groupOffsets) + stream.Write(offset); + + // write remapTable here + stream.Position = remapTableOffsetToOffset; + mapHeader.OffsetToOffsetDmaChainIndexRemapTable = remapTableOffsetToOffset; + var remapTableOffset = remapTableOffsetToOffset + 4; + stream.Write(remapTableOffset); + WriteUInt16List(stream, mapModel.DmaChainIndexRemapTable); + + stream.AlignPosition(0x10); + + var dmaChainVifOffsets = new List(); + foreach (var dmaChainMap in mapModel.VifPackets) + { + var vifPacketIndex = 0; + dmaChainVifOffsets.Add((int)stream.Position); + + foreach (var packetCount in dmaChainMap.DmaPerVif) + { + BinaryMapping.WriteObject(stream, new DmaTag + { + Qwc = packetCount, + Address = 0, + TagId = packetCount > 0 ? 1 : 6, + Irq = false, + }); + + var packetLength = packetCount * 0x10 + 8; + stream.Write(dmaChainMap.VifPacket, vifPacketIndex, packetLength); + + vifPacketIndex += packetLength; + } + } + + stream.AlignPosition(0x80); + stream.SetLength(stream.Position); + + stream.Position = dmaChainMapDescriptorOffset; + for (var i = 0; i < mapModel.VifPackets.Count; i++) + { + var dmaChainMap = mapModel.VifPackets[i]; + BinaryMapping.WriteObject(stream, new DmaChainMap + { + VifOffset = dmaChainVifOffsets[i], + TextureIndex = dmaChainMap.TextureId, + Unk08 = dmaChainMap.Unk08, + IsTransparentFlag = dmaChainMap.IsTransparentFlag, + Unk0c = dmaChainMap.Unk0c, + EnableUvsc = dmaChainMap.EnableUvsc, + UvscIndex = dmaChainMap.UvscIndex, + }); + } + + stream.Position = 0; + BinaryMapping.WriteObject(stream, mapHeader); + } + + private static IEnumerable ReadUInt16List(Stream stream) + { + while (true) + { + var data = stream.ReadUInt16(); + if (data == 0xFFFF) + break; + yield return data; + } + } + + private static void WriteUInt16List(Stream stream, IEnumerable alb2t2) + { + foreach (var data in alb2t2) + stream.Write(data); + stream.Write((ushort)0xFFFF); + } + } +} diff --git a/OpenKh.Kh2/Mdlx.Model.cs b/OpenKh.Kh2/Mdlx.Model.cs index 48d661c0e..c555195b2 100644 --- a/OpenKh.Kh2/Mdlx.Model.cs +++ b/OpenKh.Kh2/Mdlx.Model.cs @@ -1,372 +1,372 @@ -// Inspired by Kddf2's khkh_xldM. -// Original source code: https://gitlab.com/kenjiuno/khkh_xldM/blob/master/khkh_xldMii/Mdlxfst.cs - -using OpenKh.Common; -using OpenKh.Common.Ps2; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; -using Xe.IO; - -namespace OpenKh.Kh2 -{ - public partial class Mdlx - { - private static readonly VifCode DefaultVifCode = new VifCode - { - Opcode = VifOpcode.STCYCL, - Interrupt = false, - Num = 1, - Immediate = 0x0100, - }; - private static readonly DmaPacket CloseDmaPacket = new DmaPacket - { - DmaTag = new DmaTag - { - Qwc = 0, - TagId = 1, - Irq = false, - Address = 0 - }, - VifCode = new VifCode - { - Opcode = VifOpcode.NOP, - Interrupt = false, - Num = 0, - Immediate = 0x1700, - }, - Parameter = 0 - }; - - public class Bone - { - [Data] public int Index { get; set; } - [Data] public int Parent { get; set; } - [Data] public int Unk08 { get; set; } - [Data] public int Unk0c { get; set; } - [Data] public float ScaleX { get; set; } - [Data] public float ScaleY { get; set; } - [Data] public float ScaleZ { get; set; } - [Data] public float ScaleW { get; set; } - [Data] public float RotationX { get; set; } - [Data] public float RotationY { get; set; } - [Data] public float RotationZ { get; set; } - [Data] public float RotationW { get; set; } - [Data] public float TranslationX { get; set; } - [Data] public float TranslationY { get; set; } - [Data] public float TranslationZ { get; set; } - [Data] public float TranslationW { get; set; } - } - - public class DmaPacket - { - [Data] public DmaTag DmaTag { get; set; } - [Data] public VifCode VifCode { get; set; } - [Data] public int Parameter { get; set; } - } - - private class SubModelHeader - { - [Data] public int Type { get; set; } - [Data] public int Unk04 { get; set; } - [Data] public int Unk08 { get; set; } - [Data] public int NextOffset { get; set; } - [Data] public short BoneCount { get; set; } - [Data] public short Unk { get; set; } - [Data] public int BoneOffset { get; set; } - [Data] public int UnkDataOffset { get; set; } - [Data] public int DmaChainCount { get; set; } - } - - private class DmaChainHeader - { - [Data] public int Unk00 { get; set; } - [Data] public int TextureIndex { get; set; } - [Data] public int Unk08 { get; set; } - [Data] public int Unused1 { get; set; } - [Data] public int DmaOffset { get; set; } - [Data] public int Count1aOffset { get; set; } - [Data] public int DmaLength { get; set; } - [Data] public int Unused2 { get; set; } - } - - public class SubModel - { - public int Type { get; set; } - public int Unk04 { get; set; } - public int Unk08 { get; set; } - public short BoneCount { get; set; } - public short Unk { get; set; } - public int DmaChainCount { get; set; } - - public List Bones { get; internal set; } - public byte[] UnknownData { get; internal set; } - public List DmaChains { get; internal set; } - } - - public class DmaChain - { - public int RenderFlags { get; set; } - public int TextureIndex { get; set; } - public int Unk08 { get; set; } - public int DmaLength { get; set; } - public List DmaVifs { get; set; } - } - - public class DmaVif - { - public int TextureIndex { get; } - public int[] Alaxi { get; } - public byte[] VifPacket { get; } - public int BaseAddress { get; } - - public DmaVif(int texi, int[] alaxi, byte[] bin, int baseAddress) - { - TextureIndex = texi; - Alaxi = alaxi; - VifPacket = bin; - BaseAddress = baseAddress; - } - } - - private static IEnumerable ReadAsModel(Stream stream) - { - var currentOffset = 0; - var nextOffset = ReservedArea; - while (nextOffset != 0) - { - currentOffset += nextOffset; - var subStream = new SubStream(stream, currentOffset, stream.Length - currentOffset); - if (subStream.Length == 0) - yield break; - - nextOffset = ReadSubModel(subStream, out var subModel); - - yield return subModel; - } - } - - private static int ReadSubModel(Stream stream, out SubModel subModel) - { - var header = BinaryMapping.ReadObject(stream); - subModel = new SubModel - { - Type = header.Type, - Unk04 = header.Unk04, - Unk08 = header.Unk08, - BoneCount = header.BoneCount, - Unk = header.Unk, - DmaChainCount = header.DmaChainCount, - }; - - var dmaChainHeaders = For(subModel.DmaChainCount, () => BinaryMapping.ReadObject(stream)); - - stream.Position = header.UnkDataOffset; - subModel.UnknownData = stream.ReadBytes(0x120); - - if (header.BoneOffset != 0) - { - stream.Position = header.BoneOffset; - subModel.Bones = For(subModel.BoneCount, () => ReadBone(stream)).ToList(); - } - - subModel.DmaChains = dmaChainHeaders.Select(x => ReadDmaChain(stream, x)).ToList(); - - return header.NextOffset; - } - - private static DmaChain ReadDmaChain(Stream stream, DmaChainHeader dmaChainHeader) - { - var dmaVifs = new List(); - var count1a = stream.SetPosition(dmaChainHeader.Count1aOffset).ReadInt32(); - var alv1 = For(count1a, () => stream.ReadInt32()).ToList(); - - var offsetDmaPackets = new List(); - var alaxi = new List(); - var alaxref = new List(); - - offsetDmaPackets.Add(dmaChainHeader.DmaOffset); - - var offsetDmaBase = dmaChainHeader.DmaOffset + 0x10; - - for (var i = 0; i < count1a; i++) - { - if (alv1[i] == -1) - { - offsetDmaPackets.Add(offsetDmaBase + 0x10); - offsetDmaBase += 0x20; - - alaxi.Add(alaxref.ToArray()); - alaxref.Clear(); - } - else - { - offsetDmaBase += 0x10; - alaxref.Add(alv1[i]); - } - } - - alaxi.Add(alaxref.ToArray()); - alaxref.Clear(); - - var dmaPackets = offsetDmaPackets - .Select(offset => ReadTags(stream.SetPosition(offset)).ToArray()) - .ToArray(); - - for (var i = 0; i < offsetDmaPackets.Count; i++) - { - var dmaTag = dmaPackets[i][0].DmaTag; - var baseAddress = dmaTag.Qwc != 0 ? dmaPackets[i][1].Parameter : 0; - stream.Position = dmaTag.Address & 0x7FFFFFFF; - var vifPacket = stream.ReadBytes(dmaTag.Qwc * 0x10); - dmaVifs.Add(new DmaVif(dmaChainHeader.TextureIndex, alaxi[i], vifPacket, baseAddress)); - } - - return new DmaChain - { - RenderFlags = dmaChainHeader.Unk00, - TextureIndex = dmaChainHeader.TextureIndex, - Unk08 = dmaChainHeader.Unk08, - DmaLength = dmaChainHeader.DmaLength, - DmaVifs = dmaVifs, - }; - } - - private static IEnumerable ReadTags(Stream stream) - { - while (true) - { - var dmaPacket = BinaryMapping.ReadObject(stream); - yield return dmaPacket; - - if (dmaPacket.DmaTag.Qwc == 0) - yield break; - } - } - - private static void WriteSubModel(Stream stream, SubModel subModel, int baseAddress) - { - var header = new SubModelHeader - { - Type = subModel.Type, - Unk04 = subModel.Unk04, - Unk08 = subModel.Unk08, - Unk = subModel.Unk, - DmaChainCount = subModel.DmaChains.Count, - }; - - stream.Position += 0x20; // skip header - stream.Position += subModel.DmaChainCount * 0x20; - - if (subModel.Type == Entity) - { - header.UnkDataOffset = (int)stream.Position; - stream.Write(subModel.UnknownData); - - header.BoneOffset = (int)stream.Position; - header.BoneCount = (short)subModel.Bones.Count; - foreach (var bone in subModel.Bones) - WriteBone(stream, bone); - } - else if (subModel.Type == Shadow) - { - header.UnkDataOffset = 0; - header.BoneOffset = 0; - header.BoneCount = subModel.BoneCount; - } - else - throw new NotImplementedException($"Submodel type {subModel.Type} not supported."); - - var dmaChainHeaders = subModel.DmaChains.Select(x => WriteDmaChain(stream, x)).ToList(); - - stream.SetLength(stream.AlignPosition(0x80).Position); - header.NextOffset = baseAddress >= 0 ? (int)(baseAddress + stream.Position) : 0; - - stream.Position = 0; - BinaryMapping.WriteObject(stream, header); - foreach (var dmaChainHeader in dmaChainHeaders) - BinaryMapping.WriteObject(stream, dmaChainHeader); - } - - private static DmaChainHeader WriteDmaChain(Stream stream, DmaChain dmaChain) - { - var dmaChainHeader = new DmaChainHeader - { - Unk00 = dmaChain.RenderFlags, - TextureIndex = dmaChain.TextureIndex, - Unk08 = dmaChain.Unk08, - DmaLength = dmaChain.DmaLength, - }; - - var dmaVifs = dmaChain.DmaVifs; - - var vifPacketOffsets = new List(); - foreach (var dmaVif in dmaVifs) - { - vifPacketOffsets.Add((int)stream.Position); - stream.Write(dmaVif.VifPacket); - } - - dmaChainHeader.DmaOffset = (int)stream.Position; - - for (var i = 0; i < dmaVifs.Count; i++) - { - if (dmaVifs[i].BaseAddress > 0) - { - BinaryMapping.WriteObject(stream, new DmaPacket - { - DmaTag = new DmaTag - { - Qwc = (ushort)(dmaVifs[i].VifPacket.Length / 0x10), - TagId = 3, - Irq = false, - Address = vifPacketOffsets[i] - }, - VifCode = new VifCode { }, - Parameter = 0 - }); - - for (var j = 0; j < dmaVifs[i].Alaxi.Length; j++) - { - BinaryMapping.WriteObject(stream, new DmaPacket - { - DmaTag = new DmaTag - { - Qwc = 4, - TagId = 3, - Irq = false, - Address = dmaVifs[i].Alaxi[j] - }, - VifCode = DefaultVifCode, - Parameter = dmaVifs[i].BaseAddress + j * 4 - }); - } - } - - BinaryMapping.WriteObject(stream, CloseDmaPacket); - } - - var alv1 = new List(); - foreach (var vif in dmaVifs) - { - alv1.AddRange(vif.Alaxi); - alv1.Add(-1); - } - alv1.RemoveAt(alv1.Count - 1); - - dmaChainHeader.Count1aOffset = (int)stream.Position; - stream.Write(alv1.Count); - foreach (var alvItem in alv1) - stream.Write(alvItem); - - stream.AlignPosition(0x10); - - return dmaChainHeader; - } - - private static Bone ReadBone(Stream stream) => BinaryMapping.ReadObject(stream); - private static void WriteBone(Stream stream, Bone bone) => BinaryMapping.WriteObject(stream, bone); - } -} +// Inspired by Kddf2's khkh_xldM. +// Original source code: https://gitlab.com/kenjiuno/khkh_xldM/blob/master/khkh_xldMii/Mdlxfst.cs + +using OpenKh.Common; +using OpenKh.Common.Ps2; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; +using Xe.IO; + +namespace OpenKh.Kh2 +{ + public partial class Mdlx + { + private static readonly VifCode DefaultVifCode = new VifCode + { + Opcode = VifOpcode.STCYCL, + Interrupt = false, + Num = 1, + Immediate = 0x0100, + }; + private static readonly DmaPacket CloseDmaPacket = new DmaPacket + { + DmaTag = new DmaTag + { + Qwc = 0, + TagId = 1, + Irq = false, + Address = 0 + }, + VifCode = new VifCode + { + Opcode = VifOpcode.NOP, + Interrupt = false, + Num = 0, + Immediate = 0x1700, + }, + Parameter = 0 + }; + + public class Bone + { + [Data] public int Index { get; set; } + [Data] public int Parent { get; set; } + [Data] public int Unk08 { get; set; } + [Data] public int Unk0c { get; set; } + [Data] public float ScaleX { get; set; } + [Data] public float ScaleY { get; set; } + [Data] public float ScaleZ { get; set; } + [Data] public float ScaleW { get; set; } + [Data] public float RotationX { get; set; } + [Data] public float RotationY { get; set; } + [Data] public float RotationZ { get; set; } + [Data] public float RotationW { get; set; } + [Data] public float TranslationX { get; set; } + [Data] public float TranslationY { get; set; } + [Data] public float TranslationZ { get; set; } + [Data] public float TranslationW { get; set; } + } + + public class DmaPacket + { + [Data] public DmaTag DmaTag { get; set; } + [Data] public VifCode VifCode { get; set; } + [Data] public int Parameter { get; set; } + } + + private class SubModelHeader + { + [Data] public int Type { get; set; } + [Data] public int Unk04 { get; set; } + [Data] public int Unk08 { get; set; } + [Data] public int NextOffset { get; set; } + [Data] public short BoneCount { get; set; } + [Data] public short Unk { get; set; } + [Data] public int BoneOffset { get; set; } + [Data] public int UnkDataOffset { get; set; } + [Data] public int DmaChainCount { get; set; } + } + + private class DmaChainHeader + { + [Data] public int Unk00 { get; set; } + [Data] public int TextureIndex { get; set; } + [Data] public int Unk08 { get; set; } + [Data] public int Unused1 { get; set; } + [Data] public int DmaOffset { get; set; } + [Data] public int Count1aOffset { get; set; } + [Data] public int DmaLength { get; set; } + [Data] public int Unused2 { get; set; } + } + + public class SubModel + { + public int Type { get; set; } + public int Unk04 { get; set; } + public int Unk08 { get; set; } + public short BoneCount { get; set; } + public short Unk { get; set; } + public int DmaChainCount { get; set; } + + public List Bones { get; internal set; } + public byte[] UnknownData { get; internal set; } + public List DmaChains { get; internal set; } + } + + public class DmaChain + { + public int RenderFlags { get; set; } + public int TextureIndex { get; set; } + public int Unk08 { get; set; } + public int DmaLength { get; set; } + public List DmaVifs { get; set; } + } + + public class DmaVif + { + public int TextureIndex { get; } + public int[] Alaxi { get; } + public byte[] VifPacket { get; } + public int BaseAddress { get; } + + public DmaVif(int texi, int[] alaxi, byte[] bin, int baseAddress) + { + TextureIndex = texi; + Alaxi = alaxi; + VifPacket = bin; + BaseAddress = baseAddress; + } + } + + private static IEnumerable ReadAsModel(Stream stream) + { + var currentOffset = 0; + var nextOffset = ReservedArea; + while (nextOffset != 0) + { + currentOffset += nextOffset; + var subStream = new SubStream(stream, currentOffset, stream.Length - currentOffset); + if (subStream.Length == 0) + yield break; + + nextOffset = ReadSubModel(subStream, out var subModel); + + yield return subModel; + } + } + + private static int ReadSubModel(Stream stream, out SubModel subModel) + { + var header = BinaryMapping.ReadObject(stream); + subModel = new SubModel + { + Type = header.Type, + Unk04 = header.Unk04, + Unk08 = header.Unk08, + BoneCount = header.BoneCount, + Unk = header.Unk, + DmaChainCount = header.DmaChainCount, + }; + + var dmaChainHeaders = For(subModel.DmaChainCount, () => BinaryMapping.ReadObject(stream)); + + stream.Position = header.UnkDataOffset; + subModel.UnknownData = stream.ReadBytes(0x120); + + if (header.BoneOffset != 0) + { + stream.Position = header.BoneOffset; + subModel.Bones = For(subModel.BoneCount, () => ReadBone(stream)).ToList(); + } + + subModel.DmaChains = dmaChainHeaders.Select(x => ReadDmaChain(stream, x)).ToList(); + + return header.NextOffset; + } + + private static DmaChain ReadDmaChain(Stream stream, DmaChainHeader dmaChainHeader) + { + var dmaVifs = new List(); + var count1a = stream.SetPosition(dmaChainHeader.Count1aOffset).ReadInt32(); + var alv1 = For(count1a, () => stream.ReadInt32()).ToList(); + + var offsetDmaPackets = new List(); + var alaxi = new List(); + var alaxref = new List(); + + offsetDmaPackets.Add(dmaChainHeader.DmaOffset); + + var offsetDmaBase = dmaChainHeader.DmaOffset + 0x10; + + for (var i = 0; i < count1a; i++) + { + if (alv1[i] == -1) + { + offsetDmaPackets.Add(offsetDmaBase + 0x10); + offsetDmaBase += 0x20; + + alaxi.Add(alaxref.ToArray()); + alaxref.Clear(); + } + else + { + offsetDmaBase += 0x10; + alaxref.Add(alv1[i]); + } + } + + alaxi.Add(alaxref.ToArray()); + alaxref.Clear(); + + var dmaPackets = offsetDmaPackets + .Select(offset => ReadTags(stream.SetPosition(offset)).ToArray()) + .ToArray(); + + for (var i = 0; i < offsetDmaPackets.Count; i++) + { + var dmaTag = dmaPackets[i][0].DmaTag; + var baseAddress = dmaTag.Qwc != 0 ? dmaPackets[i][1].Parameter : 0; + stream.Position = dmaTag.Address & 0x7FFFFFFF; + var vifPacket = stream.ReadBytes(dmaTag.Qwc * 0x10); + dmaVifs.Add(new DmaVif(dmaChainHeader.TextureIndex, alaxi[i], vifPacket, baseAddress)); + } + + return new DmaChain + { + RenderFlags = dmaChainHeader.Unk00, + TextureIndex = dmaChainHeader.TextureIndex, + Unk08 = dmaChainHeader.Unk08, + DmaLength = dmaChainHeader.DmaLength, + DmaVifs = dmaVifs, + }; + } + + private static IEnumerable ReadTags(Stream stream) + { + while (true) + { + var dmaPacket = BinaryMapping.ReadObject(stream); + yield return dmaPacket; + + if (dmaPacket.DmaTag.Qwc == 0) + yield break; + } + } + + private static void WriteSubModel(Stream stream, SubModel subModel, int baseAddress) + { + var header = new SubModelHeader + { + Type = subModel.Type, + Unk04 = subModel.Unk04, + Unk08 = subModel.Unk08, + Unk = subModel.Unk, + DmaChainCount = subModel.DmaChains.Count, + }; + + stream.Position += 0x20; // skip header + stream.Position += subModel.DmaChainCount * 0x20; + + if (subModel.Type == Entity) + { + header.UnkDataOffset = (int)stream.Position; + stream.Write(subModel.UnknownData); + + header.BoneOffset = (int)stream.Position; + header.BoneCount = (short)subModel.Bones.Count; + foreach (var bone in subModel.Bones) + WriteBone(stream, bone); + } + else if (subModel.Type == Shadow) + { + header.UnkDataOffset = 0; + header.BoneOffset = 0; + header.BoneCount = subModel.BoneCount; + } + else + throw new NotImplementedException($"Submodel type {subModel.Type} not supported."); + + var dmaChainHeaders = subModel.DmaChains.Select(x => WriteDmaChain(stream, x)).ToList(); + + stream.SetLength(stream.AlignPosition(0x80).Position); + header.NextOffset = baseAddress >= 0 ? (int)(baseAddress + stream.Position) : 0; + + stream.Position = 0; + BinaryMapping.WriteObject(stream, header); + foreach (var dmaChainHeader in dmaChainHeaders) + BinaryMapping.WriteObject(stream, dmaChainHeader); + } + + private static DmaChainHeader WriteDmaChain(Stream stream, DmaChain dmaChain) + { + var dmaChainHeader = new DmaChainHeader + { + Unk00 = dmaChain.RenderFlags, + TextureIndex = dmaChain.TextureIndex, + Unk08 = dmaChain.Unk08, + DmaLength = dmaChain.DmaLength, + }; + + var dmaVifs = dmaChain.DmaVifs; + + var vifPacketOffsets = new List(); + foreach (var dmaVif in dmaVifs) + { + vifPacketOffsets.Add((int)stream.Position); + stream.Write(dmaVif.VifPacket); + } + + dmaChainHeader.DmaOffset = (int)stream.Position; + + for (var i = 0; i < dmaVifs.Count; i++) + { + if (dmaVifs[i].BaseAddress > 0) + { + BinaryMapping.WriteObject(stream, new DmaPacket + { + DmaTag = new DmaTag + { + Qwc = (ushort)(dmaVifs[i].VifPacket.Length / 0x10), + TagId = 3, + Irq = false, + Address = vifPacketOffsets[i] + }, + VifCode = new VifCode { }, + Parameter = 0 + }); + + for (var j = 0; j < dmaVifs[i].Alaxi.Length; j++) + { + BinaryMapping.WriteObject(stream, new DmaPacket + { + DmaTag = new DmaTag + { + Qwc = 4, + TagId = 3, + Irq = false, + Address = dmaVifs[i].Alaxi[j] + }, + VifCode = DefaultVifCode, + Parameter = dmaVifs[i].BaseAddress + j * 4 + }); + } + } + + BinaryMapping.WriteObject(stream, CloseDmaPacket); + } + + var alv1 = new List(); + foreach (var vif in dmaVifs) + { + alv1.AddRange(vif.Alaxi); + alv1.Add(-1); + } + alv1.RemoveAt(alv1.Count - 1); + + dmaChainHeader.Count1aOffset = (int)stream.Position; + stream.Write(alv1.Count); + foreach (var alvItem in alv1) + stream.Write(alvItem); + + stream.AlignPosition(0x10); + + return dmaChainHeader; + } + + private static Bone ReadBone(Stream stream) => BinaryMapping.ReadObject(stream); + private static void WriteBone(Stream stream, Bone bone) => BinaryMapping.WriteObject(stream, bone); + } +} diff --git a/OpenKh.Kh2/Mdlx.cs b/OpenKh.Kh2/Mdlx.cs index dde1167a6..ef5ca1db2 100644 --- a/OpenKh.Kh2/Mdlx.cs +++ b/OpenKh.Kh2/Mdlx.cs @@ -1,99 +1,99 @@ -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.IO; - -namespace OpenKh.Kh2 -{ - public partial class Mdlx - { - private const int Map = 2; - private const int Entity = 3; - private const int Shadow = 4; - private const int ReservedArea = 0x90; - - public List SubModels { get; } - public M4 MapModel { get; } - - private Mdlx(Stream stream) - { - var type = ReadMdlxType(stream); - stream.Position = 0; - - switch (type) - { - case Map: - MapModel = ReadAsMap(new SubStream(stream, ReservedArea, stream.Length - ReservedArea)); - break; - case Entity: - SubModels = ReadAsModel(stream).ToList(); - break; - } - } - - public bool IsMap => MapModel != null; - - public void Write(Stream realStream) - { - var stream = new MemoryStream(); - if (IsMap) - WriteAsMap(stream, MapModel); - else - WriteAsModel(stream, SubModels); - - realStream.Position = ReservedArea; - realStream.Write(stream.GetBuffer(), 0, (int)stream.Length); - } - - private static void WriteAsModel(Stream stream, List subModels) - { - var baseAddress = 0; - for (var i = 0; i < subModels.Count; i++) - { - if (i + 1 >= subModels.Count) - baseAddress = -1; - - var subModelStream = new MemoryStream(); - WriteSubModel(subModelStream, subModels[i], baseAddress); - subModelStream.SetPosition(0).Copy(stream, (int)subModelStream.Length); - } - } - - public static Mdlx Read(Stream stream) => - new Mdlx(stream.SetPosition(0)); - - private static int ReadMdlxType(Stream stream) => - stream.SetPosition(ReservedArea).ReadInt32(); - - private static T[] For(int count, Func func) => - Enumerable.Range(0, count).Select(_ => func()).ToArray(); - +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.IO; + +namespace OpenKh.Kh2 +{ + public partial class Mdlx + { + private const int Map = 2; + private const int Entity = 3; + private const int Shadow = 4; + private const int ReservedArea = 0x90; + + public List SubModels { get; } + public M4 MapModel { get; } + + private Mdlx(Stream stream) + { + var type = ReadMdlxType(stream); + stream.Position = 0; + + switch (type) + { + case Map: + MapModel = ReadAsMap(new SubStream(stream, ReservedArea, stream.Length - ReservedArea)); + break; + case Entity: + SubModels = ReadAsModel(stream).ToList(); + break; + } + } + + public bool IsMap => MapModel != null; + + public void Write(Stream realStream) + { + var stream = new MemoryStream(); + if (IsMap) + WriteAsMap(stream, MapModel); + else + WriteAsModel(stream, SubModels); + + realStream.Position = ReservedArea; + realStream.Write(stream.GetBuffer(), 0, (int)stream.Length); + } + + private static void WriteAsModel(Stream stream, List subModels) + { + var baseAddress = 0; + for (var i = 0; i < subModels.Count; i++) + { + if (i + 1 >= subModels.Count) + baseAddress = -1; + + var subModelStream = new MemoryStream(); + WriteSubModel(subModelStream, subModels[i], baseAddress); + subModelStream.SetPosition(0).Copy(stream, (int)subModelStream.Length); + } + } + + public static Mdlx Read(Stream stream) => + new Mdlx(stream.SetPosition(0)); + + private static int ReadMdlxType(Stream stream) => + stream.SetPosition(ReservedArea).ReadInt32(); + + private static T[] For(int count, Func func) => + Enumerable.Range(0, count).Select(_ => func()).ToArray(); + private Mdlx(M4 mapModel) { this.MapModel = mapModel; - } - - public static Mdlx CreateFromMapModel(M4 mapModel) => new Mdlx(mapModel); - - private Mdlx() - { - SubModels = new List(); - SubModels.Add(new SubModel - { - Type = Entity, - Bones = new List(), - DmaChains = new List(), - }); - SubModels.Add(new SubModel - { - Type = Shadow, - Bones = new List(), - DmaChains = new List(), - }); - } - - public static Mdlx CreateModelFromScratch() => new Mdlx(); - } -} + } + + public static Mdlx CreateFromMapModel(M4 mapModel) => new Mdlx(mapModel); + + private Mdlx() + { + SubModels = new List(); + SubModels.Add(new SubModel + { + Type = Entity, + Bones = new List(), + DmaChains = new List(), + }); + SubModels.Add(new SubModel + { + Type = Shadow, + Bones = new List(), + DmaChains = new List(), + }); + } + + public static Mdlx CreateModelFromScratch() => new Mdlx(); + } +} diff --git a/OpenKh.Kh2/Messages/Encoders.cs b/OpenKh.Kh2/Messages/Encoders.cs index a94a8995d..845711903 100644 --- a/OpenKh.Kh2/Messages/Encoders.cs +++ b/OpenKh.Kh2/Messages/Encoders.cs @@ -1,53 +1,53 @@ -using OpenKh.Kh2.Messages.Internals; -using System.Collections.Generic; - -namespace OpenKh.Kh2.Messages -{ - public static class Encoders - { - internal class InternationalSystemEncoder : IMessageEncoder - { - private readonly IMessageDecode _decode = new InternationalSystemDecode(); - private readonly IMessageEncode _encode = new InternationalSystemEncode(); - - public List Decode(byte[] data) => _decode.Decode(data); - public byte[] Encode(List messageCommands) => _encode.Encode(messageCommands); - } - - internal class TurkishSystemEncoder : IMessageEncoder - { - private readonly IMessageDecode _decode = new TurkishSystemDecode(); - private readonly IMessageEncode _encode = new TurkishSystemEncode(); - - public List Decode(byte[] data) => _decode.Decode(data); - public byte[] Encode(List messageCommands) => _encode.Encode(messageCommands); - } - - internal class JapaneseSystemEncoder : IMessageEncoder - { - private readonly IMessageDecode _decode = new JapaneseSystemDecode(); - private readonly IMessageEncode _encode = new JapaneseSystemEncode(); - - public List Decode(byte[] data) => _decode.Decode(data); - public byte[] Encode(List messageCommands) => _encode.Encode(messageCommands); - } - - internal class JapaneseEventEncoder : IMessageEncoder - { - private readonly IMessageDecode _decode = new JapaneseEventDecode(); - private readonly IMessageEncode _encode = new JapaneseEventEncode(); - - public List Decode(byte[] data) => _decode.Decode(data); - public byte[] Encode(List messageCommands) => _encode.Encode(messageCommands); - } - - public static IMessageEncoder InternationalSystem { get; } = - new InternationalSystemEncoder(); - public static IMessageEncoder TurkishSystem { get; } = - new TurkishSystemEncoder(); - public static IMessageEncoder JapaneseSystem { get; } = - new JapaneseSystemEncoder(); - public static IMessageEncoder JapaneseEvent { get; } = - new JapaneseEventEncoder(); - } -} +using OpenKh.Kh2.Messages.Internals; +using System.Collections.Generic; + +namespace OpenKh.Kh2.Messages +{ + public static class Encoders + { + internal class InternationalSystemEncoder : IMessageEncoder + { + private readonly IMessageDecode _decode = new InternationalSystemDecode(); + private readonly IMessageEncode _encode = new InternationalSystemEncode(); + + public List Decode(byte[] data) => _decode.Decode(data); + public byte[] Encode(List messageCommands) => _encode.Encode(messageCommands); + } + + internal class TurkishSystemEncoder : IMessageEncoder + { + private readonly IMessageDecode _decode = new TurkishSystemDecode(); + private readonly IMessageEncode _encode = new TurkishSystemEncode(); + + public List Decode(byte[] data) => _decode.Decode(data); + public byte[] Encode(List messageCommands) => _encode.Encode(messageCommands); + } + + internal class JapaneseSystemEncoder : IMessageEncoder + { + private readonly IMessageDecode _decode = new JapaneseSystemDecode(); + private readonly IMessageEncode _encode = new JapaneseSystemEncode(); + + public List Decode(byte[] data) => _decode.Decode(data); + public byte[] Encode(List messageCommands) => _encode.Encode(messageCommands); + } + + internal class JapaneseEventEncoder : IMessageEncoder + { + private readonly IMessageDecode _decode = new JapaneseEventDecode(); + private readonly IMessageEncode _encode = new JapaneseEventEncode(); + + public List Decode(byte[] data) => _decode.Decode(data); + public byte[] Encode(List messageCommands) => _encode.Encode(messageCommands); + } + + public static IMessageEncoder InternationalSystem { get; } = + new InternationalSystemEncoder(); + public static IMessageEncoder TurkishSystem { get; } = + new TurkishSystemEncoder(); + public static IMessageEncoder JapaneseSystem { get; } = + new JapaneseSystemEncoder(); + public static IMessageEncoder JapaneseEvent { get; } = + new JapaneseEventEncoder(); + } +} diff --git a/OpenKh.Kh2/Messages/IMessageDecode.cs b/OpenKh.Kh2/Messages/IMessageDecode.cs index 9d7255bb0..1b348dc0a 100644 --- a/OpenKh.Kh2/Messages/IMessageDecode.cs +++ b/OpenKh.Kh2/Messages/IMessageDecode.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; - -namespace OpenKh.Kh2.Messages -{ - public interface IMessageDecode - { - List Decode(byte[] data); - } -} +using System.Collections.Generic; + +namespace OpenKh.Kh2.Messages +{ + public interface IMessageDecode + { + List Decode(byte[] data); + } +} diff --git a/OpenKh.Kh2/Messages/IMessageEncode.cs b/OpenKh.Kh2/Messages/IMessageEncode.cs index 0f4bd8f3f..4cd5d579d 100644 --- a/OpenKh.Kh2/Messages/IMessageEncode.cs +++ b/OpenKh.Kh2/Messages/IMessageEncode.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; - -namespace OpenKh.Kh2.Messages -{ - public interface IMessageEncode - { - byte[] Encode(List messageCommands); - } -} +using System.Collections.Generic; + +namespace OpenKh.Kh2.Messages +{ + public interface IMessageEncode + { + byte[] Encode(List messageCommands); + } +} diff --git a/OpenKh.Kh2/Messages/IMessageEncoder.cs b/OpenKh.Kh2/Messages/IMessageEncoder.cs index 2c1695331..a772096b1 100644 --- a/OpenKh.Kh2/Messages/IMessageEncoder.cs +++ b/OpenKh.Kh2/Messages/IMessageEncoder.cs @@ -1,6 +1,6 @@ -namespace OpenKh.Kh2.Messages -{ - public interface IMessageEncoder : IMessageDecode, IMessageEncode - { - } -} +namespace OpenKh.Kh2.Messages +{ + public interface IMessageEncoder : IMessageDecode, IMessageEncode + { + } +} diff --git a/OpenKh.Kh2/Messages/Internals/BaseCmdModel.cs b/OpenKh.Kh2/Messages/Internals/BaseCmdModel.cs index 2cdeb4d3c..62d0aba80 100644 --- a/OpenKh.Kh2/Messages/Internals/BaseCmdModel.cs +++ b/OpenKh.Kh2/Messages/Internals/BaseCmdModel.cs @@ -1,13 +1,13 @@ -namespace OpenKh.Kh2.Messages.Internals -{ - internal class BaseCmdModel - { - public MessageCommand Command { get; set; } - - public int Length { get; set; } - - public string Text { get; set; } - - public byte RawData { get; set; } - } -} +namespace OpenKh.Kh2.Messages.Internals +{ + internal class BaseCmdModel + { + public MessageCommand Command { get; set; } + + public int Length { get; set; } + + public string Text { get; set; } + + public byte RawData { get; set; } + } +} diff --git a/OpenKh.Kh2/Messages/Internals/BaseMessageDecoder.cs b/OpenKh.Kh2/Messages/Internals/BaseMessageDecoder.cs index 4c71fd4cf..7a2569d71 100644 --- a/OpenKh.Kh2/Messages/Internals/BaseMessageDecoder.cs +++ b/OpenKh.Kh2/Messages/Internals/BaseMessageDecoder.cs @@ -1,159 +1,159 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace OpenKh.Kh2.Messages.Internals -{ - internal interface IDecoder - { - bool IsEof(int offset = 0); - byte Peek(int offset); - byte Next(); - bool WrapTable(ref byte ch, ref byte parameter); - void AppendComplex(string str); - } - - internal partial class BaseMessageDecoder : IDecoder - { - private readonly Dictionary _table; - private readonly List _entries; - private StringBuilder _stringBuilder; - private byte[] _data; - private int _index; - - internal BaseMessageDecoder( - Dictionary table, - byte[] data) - { - _table = table; - _entries = new List(); - _data = data; - } - - internal List Decode(Func handler = null) - { - while (!IsEof()) - { - if (handler?.Invoke(this) ?? false) - continue; - - byte ch = Next(); - var cmdModel = GetCommandModel(ch); - - - switch (cmdModel.Command) - { - case MessageCommand.PrintText: - Append(cmdModel.Text[0]); - break; - case MessageCommand.PrintComplex: - AppendComplex(cmdModel.Text); - break; - case MessageCommand.Table2: - case MessageCommand.Table3: - case MessageCommand.Table4: - case MessageCommand.Table5: - case MessageCommand.Table6: - case MessageCommand.Table7: - case MessageCommand.Table8: - AppendFromTable(cmdModel, ch, Next()); - break; - case MessageCommand.Unsupported: - AppendEntry(cmdModel.Command, new byte[] { cmdModel.RawData }); - break; - default: - AppendEntry(cmdModel); - break; - } - } - - FlushTextBuilder(); - return _entries; - } - - private void AppendFromTable(BaseCmdModel cmdModel, byte ch, byte parameter) - { - if (WrapTable(ref ch, ref parameter)) - AppendFromTable(GetCommandModel(ch), ch, parameter); - else - Append((cmdModel as TableCmdModel).GetText(parameter)); - } - - private BaseCmdModel GetCommandModel(byte ch) - { - if (!_table.TryGetValue(ch, out var commandModel) || commandModel == null) - throw new NotImplementedException($"Command {ch:X02} not implemented yet"); - - return commandModel; - } - - public bool IsEof(int offset = 0) => _index + offset >= _data.Length; - public byte Peek(int offset) => _data[_index + offset]; - public byte Next() => _data[_index++]; - public bool WrapTable(ref byte ch, ref byte parameter) - { - if (ch >= 0x20) - return false; - - var data = (ushort)((ch << 8) | parameter); - if (data >= 0x1e40) - { - data -= 0x310; - - ch = (byte)(data >> 8); - parameter = (byte)(data & 0xff); - return true; - } - - return false; - } - - private StringBuilder RequestTextBuilder() - { - if (_stringBuilder == null) - _stringBuilder = new StringBuilder(); - - return _stringBuilder; - } - - private void FlushTextBuilder(MessageCommand command = MessageCommand.PrintText) - { - if (_stringBuilder != null) - { - _entries.Add(new MessageCommandModel - { - Command = command, - Text = _stringBuilder.ToString() - }); - _stringBuilder = null; - } - } - - private void AppendEntry(BaseCmdModel cmdModel) => AppendEntry(cmdModel.Command, ReadBytes(cmdModel.Length)); - - private void AppendEntry(MessageCommand command, byte[] data) - { - FlushTextBuilder(); - _entries.Add(new MessageCommandModel - { - Command = command, - Data = data - }); - } - - private void Append(char ch) => RequestTextBuilder().Append(ch); - private void Append(string str) => RequestTextBuilder().Append(str); - public void AppendComplex(string str) - { - FlushTextBuilder(); - RequestTextBuilder().Append(str); - FlushTextBuilder(MessageCommand.PrintComplex); - } - - private byte[] ReadBytes(int length) => - Enumerable.Range(0, length) - .Select(x => Next()) - .ToArray(); - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenKh.Kh2.Messages.Internals +{ + internal interface IDecoder + { + bool IsEof(int offset = 0); + byte Peek(int offset); + byte Next(); + bool WrapTable(ref byte ch, ref byte parameter); + void AppendComplex(string str); + } + + internal partial class BaseMessageDecoder : IDecoder + { + private readonly Dictionary _table; + private readonly List _entries; + private StringBuilder _stringBuilder; + private byte[] _data; + private int _index; + + internal BaseMessageDecoder( + Dictionary table, + byte[] data) + { + _table = table; + _entries = new List(); + _data = data; + } + + internal List Decode(Func handler = null) + { + while (!IsEof()) + { + if (handler?.Invoke(this) ?? false) + continue; + + byte ch = Next(); + var cmdModel = GetCommandModel(ch); + + + switch (cmdModel.Command) + { + case MessageCommand.PrintText: + Append(cmdModel.Text[0]); + break; + case MessageCommand.PrintComplex: + AppendComplex(cmdModel.Text); + break; + case MessageCommand.Table2: + case MessageCommand.Table3: + case MessageCommand.Table4: + case MessageCommand.Table5: + case MessageCommand.Table6: + case MessageCommand.Table7: + case MessageCommand.Table8: + AppendFromTable(cmdModel, ch, Next()); + break; + case MessageCommand.Unsupported: + AppendEntry(cmdModel.Command, new byte[] { cmdModel.RawData }); + break; + default: + AppendEntry(cmdModel); + break; + } + } + + FlushTextBuilder(); + return _entries; + } + + private void AppendFromTable(BaseCmdModel cmdModel, byte ch, byte parameter) + { + if (WrapTable(ref ch, ref parameter)) + AppendFromTable(GetCommandModel(ch), ch, parameter); + else + Append((cmdModel as TableCmdModel).GetText(parameter)); + } + + private BaseCmdModel GetCommandModel(byte ch) + { + if (!_table.TryGetValue(ch, out var commandModel) || commandModel == null) + throw new NotImplementedException($"Command {ch:X02} not implemented yet"); + + return commandModel; + } + + public bool IsEof(int offset = 0) => _index + offset >= _data.Length; + public byte Peek(int offset) => _data[_index + offset]; + public byte Next() => _data[_index++]; + public bool WrapTable(ref byte ch, ref byte parameter) + { + if (ch >= 0x20) + return false; + + var data = (ushort)((ch << 8) | parameter); + if (data >= 0x1e40) + { + data -= 0x310; + + ch = (byte)(data >> 8); + parameter = (byte)(data & 0xff); + return true; + } + + return false; + } + + private StringBuilder RequestTextBuilder() + { + if (_stringBuilder == null) + _stringBuilder = new StringBuilder(); + + return _stringBuilder; + } + + private void FlushTextBuilder(MessageCommand command = MessageCommand.PrintText) + { + if (_stringBuilder != null) + { + _entries.Add(new MessageCommandModel + { + Command = command, + Text = _stringBuilder.ToString() + }); + _stringBuilder = null; + } + } + + private void AppendEntry(BaseCmdModel cmdModel) => AppendEntry(cmdModel.Command, ReadBytes(cmdModel.Length)); + + private void AppendEntry(MessageCommand command, byte[] data) + { + FlushTextBuilder(); + _entries.Add(new MessageCommandModel + { + Command = command, + Data = data + }); + } + + private void Append(char ch) => RequestTextBuilder().Append(ch); + private void Append(string str) => RequestTextBuilder().Append(str); + public void AppendComplex(string str) + { + FlushTextBuilder(); + RequestTextBuilder().Append(str); + FlushTextBuilder(MessageCommand.PrintComplex); + } + + private byte[] ReadBytes(int length) => + Enumerable.Range(0, length) + .Select(x => Next()) + .ToArray(); + } +} diff --git a/OpenKh.Kh2/Messages/Internals/DataCmdModel.cs b/OpenKh.Kh2/Messages/Internals/DataCmdModel.cs index 1a9f832b4..aee6f7130 100644 --- a/OpenKh.Kh2/Messages/Internals/DataCmdModel.cs +++ b/OpenKh.Kh2/Messages/Internals/DataCmdModel.cs @@ -1,11 +1,11 @@ -namespace OpenKh.Kh2.Messages.Internals -{ - internal class DataCmdModel : BaseCmdModel - { - public DataCmdModel(MessageCommand command, int lenght) - { - Command = command; - Length = lenght; - } - } -} +namespace OpenKh.Kh2.Messages.Internals +{ + internal class DataCmdModel : BaseCmdModel + { + public DataCmdModel(MessageCommand command, int lenght) + { + Command = command; + Length = lenght; + } + } +} diff --git a/OpenKh.Kh2/Messages/Internals/InternationalSystemDecode.cs b/OpenKh.Kh2/Messages/Internals/InternationalSystemDecode.cs index 89d575f59..0f825066b 100644 --- a/OpenKh.Kh2/Messages/Internals/InternationalSystemDecode.cs +++ b/OpenKh.Kh2/Messages/Internals/InternationalSystemDecode.cs @@ -1,273 +1,273 @@ -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Kh2.Messages.Internals -{ - internal class InternationalSystemDecode : IMessageDecode - { - private static readonly char[] _tableGeneric = Enumerable.Range(0, 0x100).Select(x => '?').ToArray(); - - public static readonly Dictionary _table = new Dictionary - { - [0x00] = new SimpleCmdModel(MessageCommand.End), - [0x01] = new TextCmdModel(' '), - [0x02] = new TextCmdModel('\n'), - [0x03] = new SimpleCmdModel(MessageCommand.Reset), - [0x04] = new SingleDataCmdModel(MessageCommand.Theme), - [0x05] = new DataCmdModel(MessageCommand.Unknown05, 6), - [0x06] = new SingleDataCmdModel(MessageCommand.Unknown06), - [0x07] = new DataCmdModel(MessageCommand.Color, 4), - [0x08] = new DataCmdModel(MessageCommand.Unknown08, 3), - [0x09] = new SingleDataCmdModel(MessageCommand.PrintIcon), - [0x0a] = new SingleDataCmdModel(MessageCommand.TextScale), - [0x0b] = new SingleDataCmdModel(MessageCommand.TextWidth), - [0x0c] = new SingleDataCmdModel(MessageCommand.LineSpacing), - [0x0d] = new SimpleCmdModel(MessageCommand.Unknown0d), - [0x0e] = new SingleDataCmdModel(MessageCommand.Unknown0e), - [0x0f] = new DataCmdModel(MessageCommand.Unknown0f, 5), - [0x10] = new SimpleCmdModel(MessageCommand.Clear), - [0x11] = new DataCmdModel(MessageCommand.Position, 4), - [0x12] = new DataCmdModel(MessageCommand.Unknown12, 2), - [0x13] = new DataCmdModel(MessageCommand.Unknown13, 4), - [0x14] = new DataCmdModel(MessageCommand.Delay, 2), - [0x15] = new DataCmdModel(MessageCommand.CharDelay, 2), - [0x16] = new SingleDataCmdModel(MessageCommand.Unknown16), - [0x17] = new DataCmdModel(MessageCommand.DelayAndFade, 2), - [0x18] = new DataCmdModel(MessageCommand.Unknown18, 2), - [0x19] = new TableCmdModel(MessageCommand.Table2, _tableGeneric), - [0x1a] = new TableCmdModel(MessageCommand.Table3, _tableGeneric), - [0x1b] = new TableCmdModel(MessageCommand.Table4, _tableGeneric), - [0x1c] = new TableCmdModel(MessageCommand.Table5, _tableGeneric), - [0x1d] = new TableCmdModel(MessageCommand.Table6, _tableGeneric), - [0x1e] = new TableCmdModel(MessageCommand.Table7, _tableGeneric), - [0x1f] = new TableCmdModel(MessageCommand.Table8, _tableGeneric), - [0x20] = new TextCmdModel('⬛'), - [0x21] = new TextCmdModel('0'), - [0x22] = new TextCmdModel('1'), - [0x23] = new TextCmdModel('2'), - [0x24] = new TextCmdModel('3'), - [0x25] = new TextCmdModel('4'), - [0x26] = new TextCmdModel('5'), - [0x27] = new TextCmdModel('6'), - [0x28] = new TextCmdModel('7'), - [0x29] = new TextCmdModel('8'), - [0x2a] = new TextCmdModel('9'), - [0x2b] = new TextCmdModel('+'), - [0x2c] = new TextCmdModel('−'), - [0x2d] = new TextCmdModel('ₓ'), - [0x2e] = new TextCmdModel('A'), - [0x2f] = new TextCmdModel('B'), - [0x30] = new TextCmdModel('C'), - [0x31] = new TextCmdModel('D'), - [0x32] = new TextCmdModel('E'), - [0x33] = new TextCmdModel('F'), - [0x34] = new TextCmdModel('G'), - [0x35] = new TextCmdModel('H'), - [0x36] = new TextCmdModel('I'), - [0x37] = new TextCmdModel('J'), - [0x38] = new TextCmdModel('K'), - [0x39] = new TextCmdModel('L'), - [0x3a] = new TextCmdModel('M'), - [0x3b] = new TextCmdModel('N'), - [0x3c] = new TextCmdModel('O'), - [0x3d] = new TextCmdModel('P'), - [0x3e] = new TextCmdModel('Q'), - [0x3f] = new TextCmdModel('R'), - [0x40] = new TextCmdModel('S'), - [0x41] = new TextCmdModel('T'), - [0x42] = new TextCmdModel('U'), - [0x43] = new TextCmdModel('V'), - [0x44] = new TextCmdModel('W'), - [0x45] = new TextCmdModel('X'), - [0x46] = new TextCmdModel('Y'), - [0x47] = new TextCmdModel('Z'), - [0x48] = new TextCmdModel('!'), - [0x49] = new TextCmdModel('?'), - [0x4a] = new TextCmdModel('%'), - [0x4b] = new TextCmdModel('/'), - [0x4c] = new TextCmdModel('※'), - [0x4d] = new TextCmdModel('、'), - [0x4e] = new TextCmdModel('。'), - [0x4f] = new TextCmdModel('.'), - [0x50] = new TextCmdModel(','), - [0x51] = new TextCmdModel(';'), - [0x52] = new TextCmdModel(':'), - [0x53] = new TextCmdModel('…'), - [0x54] = new TextCmdModel("-"), - [0x55] = new TextCmdModel('–'), - [0x56] = new TextCmdModel('〜'), - [0x57] = new TextCmdModel("'"), - [0x58] = new UnsupportedCmdModel(0x58), // Unused - [0x59] = new UnsupportedCmdModel(0x59), // Unused - [0x5a] = new TextCmdModel('('), - [0x5b] = new TextCmdModel(')'), - [0x5c] = new TextCmdModel('「'), - [0x5d] = new TextCmdModel('」'), - [0x5e] = new TextCmdModel('『'), - [0x5f] = new TextCmdModel('』'), - [0x60] = new TextCmdModel('“'), - [0x61] = new TextCmdModel('”'), - [0x62] = new TextCmdModel('['), - [0x63] = new TextCmdModel(']'), - [0x64] = new TextCmdModel('<'), - [0x65] = new TextCmdModel('>'), - [0x66] = new TextCmdModel('-'), - [0x67] = new TextCmdModel("–"), - [0x68] = new TextCmdModel('⤷'), // Used only in EVT - [0x69] = new TextCmdModel('♩'), - [0x6a] = new TextCmdModel('⇾'), // Used only in EVT - [0x6b] = new TextCmdModel('⇽'), // Used only in EVT - [0x6c] = new TextCmdModel('◯'), - [0x6d] = new TextCmdModel('✕'), - [0x6e] = new UnsupportedCmdModel(0x6e), // Unused - [0x6f] = new UnsupportedCmdModel(0x6e), // Unused - [0x70] = new UnsupportedCmdModel(0x70), // Unused - [0x71] = new UnsupportedCmdModel(0x71), // Unused - [0x72] = new UnsupportedCmdModel(0x72), // Unused - [0x73] = new SimpleCmdModel(MessageCommand.Tabulation), - [0x74] = new TextCmdModel("I"), - [0x75] = new TextCmdModel("II"), - [0x76] = new TextCmdModel("III"), - [0x77] = new TextCmdModel("IV"), - [0x78] = new TextCmdModel("V"), - [0x79] = new TextCmdModel("VI"), - [0x7a] = new TextCmdModel("VII"), - [0x7b] = new TextCmdModel("VIII"), - [0x7c] = new TextCmdModel("IX"), - [0x7d] = new TextCmdModel("X"), - [0x7e] = new TextCmdModel("XIII"), - [0x7f] = new TextCmdModel('α'), - [0x80] = new TextCmdModel('β'), - [0x81] = new TextCmdModel('γ'), - [0x82] = new TextCmdModel('⭑'), - [0x83] = new TextCmdModel('⭒'), - [0x84] = new TextCmdModel("XI"), - [0x85] = new TextCmdModel("XII"), - [0x86] = new TextCmdModel('&'), - [0x87] = new TextCmdModel('#'), - [0x88] = new TextCmdModel('®'), - [0x89] = new TextCmdModel('▴'), - [0x8a] = new TextCmdModel('▾'), - [0x8b] = new TextCmdModel('▸'), - [0x8c] = new TextCmdModel('◂'), - [0x8d] = new TextCmdModel('°'), - [0x8e] = new TextCmdModel("♪"), - [0x8f] = new UnsupportedCmdModel(0x8f), // Unused - [0x90] = new TextCmdModel('0'), - [0x91] = new TextCmdModel('1'), - [0x92] = new TextCmdModel('2'), - [0x93] = new TextCmdModel('3'), - [0x94] = new TextCmdModel('4'), - [0x95] = new TextCmdModel('5'), - [0x96] = new TextCmdModel('6'), - [0x97] = new TextCmdModel('7'), - [0x98] = new TextCmdModel('8'), - [0x99] = new TextCmdModel('9'), - [0x9a] = new TextCmdModel('a'), - [0x9b] = new TextCmdModel('b'), - [0x9c] = new TextCmdModel('c'), - [0x9d] = new TextCmdModel('d'), - [0x9e] = new TextCmdModel('e'), - [0x9f] = new TextCmdModel('f'), - [0xa0] = new TextCmdModel('g'), - [0xa1] = new TextCmdModel('h'), - [0xa2] = new TextCmdModel('i'), - [0xa3] = new TextCmdModel('j'), - [0xa4] = new TextCmdModel('k'), - [0xa5] = new TextCmdModel('l'), - [0xa6] = new TextCmdModel('m'), - [0xa7] = new TextCmdModel('n'), - [0xa8] = new TextCmdModel('o'), - [0xa9] = new TextCmdModel('p'), - [0xaa] = new TextCmdModel('q'), - [0xab] = new TextCmdModel('r'), - [0xac] = new TextCmdModel('s'), - [0xad] = new TextCmdModel('t'), - [0xae] = new TextCmdModel('u'), - [0xaf] = new TextCmdModel('v'), - [0xb0] = new TextCmdModel('w'), - [0xb1] = new TextCmdModel('x'), - [0xb2] = new TextCmdModel('y'), - [0xb3] = new TextCmdModel('z'), - [0xb4] = new TextCmdModel('Æ'), - [0xb5] = new TextCmdModel('æ'), - [0xb6] = new TextCmdModel('ß'), - [0xb7] = new TextCmdModel('à'), - [0xb8] = new TextCmdModel('á'), - [0xb9] = new TextCmdModel('â'), - [0xba] = new TextCmdModel('ä'), - [0xbb] = new TextCmdModel('è'), - [0xbc] = new TextCmdModel('é'), - [0xbd] = new TextCmdModel('ê'), - [0xbe] = new TextCmdModel('ë'), - [0xbf] = new TextCmdModel('ì'), - [0xc0] = new TextCmdModel('í'), - [0xc1] = new TextCmdModel('î'), - [0xc2] = new TextCmdModel('ï'), - [0xc3] = new TextCmdModel('ñ'), - [0xc4] = new TextCmdModel('ò'), - [0xc5] = new TextCmdModel('ó'), - [0xc6] = new TextCmdModel('ô'), - [0xc7] = new TextCmdModel('ö'), - [0xc8] = new TextCmdModel('ù'), - [0xc9] = new TextCmdModel('ú'), - [0xca] = new TextCmdModel('û'), - [0xcb] = new TextCmdModel('ü'), - [0xcc] = new TextCmdModel('º'), - [0xcd] = new TextCmdModel('—'), - [0xce] = new TextCmdModel('»'), - [0xcf] = new TextCmdModel('«'), - [0xd0] = new TextCmdModel('À'), - [0xd1] = new TextCmdModel('Á'), - [0xd2] = new TextCmdModel('Â'), - [0xd3] = new TextCmdModel('Ä'), - [0xd4] = new TextCmdModel('È'), - [0xd5] = new TextCmdModel('É'), - [0xd6] = new TextCmdModel('Ê'), - [0xd7] = new TextCmdModel('Ë'), - [0xd8] = new TextCmdModel('Ì'), - [0xd9] = new TextCmdModel('Í'), - [0xda] = new TextCmdModel('Î'), - [0xdb] = new TextCmdModel('Ï'), - [0xdc] = new TextCmdModel('Ñ'), - [0xdd] = new TextCmdModel('Ò'), - [0xde] = new TextCmdModel('Ó'), - [0xdf] = new TextCmdModel('Ô'), - [0xe0] = new TextCmdModel('Ö'), - [0xe1] = new TextCmdModel('Ù'), - [0xe2] = new TextCmdModel('Ú'), - [0xe3] = new TextCmdModel('Û'), - [0xe4] = new TextCmdModel('Ü'), - [0xe5] = new TextCmdModel('¡'), - [0xe6] = new TextCmdModel('¿'), - [0xe7] = new TextCmdModel('Ç'), - [0xe8] = new TextCmdModel('ç'), - [0xe9] = new TextCmdModel('‛'), - [0xea] = new TextCmdModel('’'), - [0xeb] = new TextCmdModel('`'), - [0xec] = new TextCmdModel('´'), - [0xed] = new TextCmdModel('"'), - [0xee] = new TextCmdModel('\''), - [0xef] = new TextCmdModel('★'), - [0xf0] = new TextCmdModel('☆'), - [0xf1] = new TextCmdModel('■'), - [0xf2] = new TextCmdModel('□'), - [0xf3] = new TextCmdModel('▲'), - [0xf4] = new TextCmdModel('△'), - [0xf5] = new TextCmdModel('●'), - [0xf6] = new TextCmdModel('○'), - [0xf7] = new TextCmdModel('♪'), - [0xf8] = new TextCmdModel('♫'), - [0xf9] = new TextCmdModel('→'), - [0xfa] = new TextCmdModel('←'), - [0xfb] = new TextCmdModel('↑'), - [0xfc] = new TextCmdModel('↓'), - [0xfd] = new TextCmdModel('・'), - [0xfe] = new TextCmdModel('❤'), - [0xff] = new UnsupportedCmdModel(0xff), // Unused - }; - - public List Decode(byte[] data) => - new BaseMessageDecoder(_table, data).Decode(); - } -} +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Kh2.Messages.Internals +{ + internal class InternationalSystemDecode : IMessageDecode + { + private static readonly char[] _tableGeneric = Enumerable.Range(0, 0x100).Select(x => '?').ToArray(); + + public static readonly Dictionary _table = new Dictionary + { + [0x00] = new SimpleCmdModel(MessageCommand.End), + [0x01] = new TextCmdModel(' '), + [0x02] = new TextCmdModel('\n'), + [0x03] = new SimpleCmdModel(MessageCommand.Reset), + [0x04] = new SingleDataCmdModel(MessageCommand.Theme), + [0x05] = new DataCmdModel(MessageCommand.Unknown05, 6), + [0x06] = new SingleDataCmdModel(MessageCommand.Unknown06), + [0x07] = new DataCmdModel(MessageCommand.Color, 4), + [0x08] = new DataCmdModel(MessageCommand.Unknown08, 3), + [0x09] = new SingleDataCmdModel(MessageCommand.PrintIcon), + [0x0a] = new SingleDataCmdModel(MessageCommand.TextScale), + [0x0b] = new SingleDataCmdModel(MessageCommand.TextWidth), + [0x0c] = new SingleDataCmdModel(MessageCommand.LineSpacing), + [0x0d] = new SimpleCmdModel(MessageCommand.Unknown0d), + [0x0e] = new SingleDataCmdModel(MessageCommand.Unknown0e), + [0x0f] = new DataCmdModel(MessageCommand.Unknown0f, 5), + [0x10] = new SimpleCmdModel(MessageCommand.Clear), + [0x11] = new DataCmdModel(MessageCommand.Position, 4), + [0x12] = new DataCmdModel(MessageCommand.Unknown12, 2), + [0x13] = new DataCmdModel(MessageCommand.Unknown13, 4), + [0x14] = new DataCmdModel(MessageCommand.Delay, 2), + [0x15] = new DataCmdModel(MessageCommand.CharDelay, 2), + [0x16] = new SingleDataCmdModel(MessageCommand.Unknown16), + [0x17] = new DataCmdModel(MessageCommand.DelayAndFade, 2), + [0x18] = new DataCmdModel(MessageCommand.Unknown18, 2), + [0x19] = new TableCmdModel(MessageCommand.Table2, _tableGeneric), + [0x1a] = new TableCmdModel(MessageCommand.Table3, _tableGeneric), + [0x1b] = new TableCmdModel(MessageCommand.Table4, _tableGeneric), + [0x1c] = new TableCmdModel(MessageCommand.Table5, _tableGeneric), + [0x1d] = new TableCmdModel(MessageCommand.Table6, _tableGeneric), + [0x1e] = new TableCmdModel(MessageCommand.Table7, _tableGeneric), + [0x1f] = new TableCmdModel(MessageCommand.Table8, _tableGeneric), + [0x20] = new TextCmdModel('⬛'), + [0x21] = new TextCmdModel('0'), + [0x22] = new TextCmdModel('1'), + [0x23] = new TextCmdModel('2'), + [0x24] = new TextCmdModel('3'), + [0x25] = new TextCmdModel('4'), + [0x26] = new TextCmdModel('5'), + [0x27] = new TextCmdModel('6'), + [0x28] = new TextCmdModel('7'), + [0x29] = new TextCmdModel('8'), + [0x2a] = new TextCmdModel('9'), + [0x2b] = new TextCmdModel('+'), + [0x2c] = new TextCmdModel('−'), + [0x2d] = new TextCmdModel('ₓ'), + [0x2e] = new TextCmdModel('A'), + [0x2f] = new TextCmdModel('B'), + [0x30] = new TextCmdModel('C'), + [0x31] = new TextCmdModel('D'), + [0x32] = new TextCmdModel('E'), + [0x33] = new TextCmdModel('F'), + [0x34] = new TextCmdModel('G'), + [0x35] = new TextCmdModel('H'), + [0x36] = new TextCmdModel('I'), + [0x37] = new TextCmdModel('J'), + [0x38] = new TextCmdModel('K'), + [0x39] = new TextCmdModel('L'), + [0x3a] = new TextCmdModel('M'), + [0x3b] = new TextCmdModel('N'), + [0x3c] = new TextCmdModel('O'), + [0x3d] = new TextCmdModel('P'), + [0x3e] = new TextCmdModel('Q'), + [0x3f] = new TextCmdModel('R'), + [0x40] = new TextCmdModel('S'), + [0x41] = new TextCmdModel('T'), + [0x42] = new TextCmdModel('U'), + [0x43] = new TextCmdModel('V'), + [0x44] = new TextCmdModel('W'), + [0x45] = new TextCmdModel('X'), + [0x46] = new TextCmdModel('Y'), + [0x47] = new TextCmdModel('Z'), + [0x48] = new TextCmdModel('!'), + [0x49] = new TextCmdModel('?'), + [0x4a] = new TextCmdModel('%'), + [0x4b] = new TextCmdModel('/'), + [0x4c] = new TextCmdModel('※'), + [0x4d] = new TextCmdModel('、'), + [0x4e] = new TextCmdModel('。'), + [0x4f] = new TextCmdModel('.'), + [0x50] = new TextCmdModel(','), + [0x51] = new TextCmdModel(';'), + [0x52] = new TextCmdModel(':'), + [0x53] = new TextCmdModel('…'), + [0x54] = new TextCmdModel("-"), + [0x55] = new TextCmdModel('–'), + [0x56] = new TextCmdModel('〜'), + [0x57] = new TextCmdModel("'"), + [0x58] = new UnsupportedCmdModel(0x58), // Unused + [0x59] = new UnsupportedCmdModel(0x59), // Unused + [0x5a] = new TextCmdModel('('), + [0x5b] = new TextCmdModel(')'), + [0x5c] = new TextCmdModel('「'), + [0x5d] = new TextCmdModel('」'), + [0x5e] = new TextCmdModel('『'), + [0x5f] = new TextCmdModel('』'), + [0x60] = new TextCmdModel('“'), + [0x61] = new TextCmdModel('”'), + [0x62] = new TextCmdModel('['), + [0x63] = new TextCmdModel(']'), + [0x64] = new TextCmdModel('<'), + [0x65] = new TextCmdModel('>'), + [0x66] = new TextCmdModel('-'), + [0x67] = new TextCmdModel("–"), + [0x68] = new TextCmdModel('⤷'), // Used only in EVT + [0x69] = new TextCmdModel('♩'), + [0x6a] = new TextCmdModel('⇾'), // Used only in EVT + [0x6b] = new TextCmdModel('⇽'), // Used only in EVT + [0x6c] = new TextCmdModel('◯'), + [0x6d] = new TextCmdModel('✕'), + [0x6e] = new UnsupportedCmdModel(0x6e), // Unused + [0x6f] = new UnsupportedCmdModel(0x6e), // Unused + [0x70] = new UnsupportedCmdModel(0x70), // Unused + [0x71] = new UnsupportedCmdModel(0x71), // Unused + [0x72] = new UnsupportedCmdModel(0x72), // Unused + [0x73] = new SimpleCmdModel(MessageCommand.Tabulation), + [0x74] = new TextCmdModel("I"), + [0x75] = new TextCmdModel("II"), + [0x76] = new TextCmdModel("III"), + [0x77] = new TextCmdModel("IV"), + [0x78] = new TextCmdModel("V"), + [0x79] = new TextCmdModel("VI"), + [0x7a] = new TextCmdModel("VII"), + [0x7b] = new TextCmdModel("VIII"), + [0x7c] = new TextCmdModel("IX"), + [0x7d] = new TextCmdModel("X"), + [0x7e] = new TextCmdModel("XIII"), + [0x7f] = new TextCmdModel('α'), + [0x80] = new TextCmdModel('β'), + [0x81] = new TextCmdModel('γ'), + [0x82] = new TextCmdModel('⭑'), + [0x83] = new TextCmdModel('⭒'), + [0x84] = new TextCmdModel("XI"), + [0x85] = new TextCmdModel("XII"), + [0x86] = new TextCmdModel('&'), + [0x87] = new TextCmdModel('#'), + [0x88] = new TextCmdModel('®'), + [0x89] = new TextCmdModel('▴'), + [0x8a] = new TextCmdModel('▾'), + [0x8b] = new TextCmdModel('▸'), + [0x8c] = new TextCmdModel('◂'), + [0x8d] = new TextCmdModel('°'), + [0x8e] = new TextCmdModel("♪"), + [0x8f] = new UnsupportedCmdModel(0x8f), // Unused + [0x90] = new TextCmdModel('0'), + [0x91] = new TextCmdModel('1'), + [0x92] = new TextCmdModel('2'), + [0x93] = new TextCmdModel('3'), + [0x94] = new TextCmdModel('4'), + [0x95] = new TextCmdModel('5'), + [0x96] = new TextCmdModel('6'), + [0x97] = new TextCmdModel('7'), + [0x98] = new TextCmdModel('8'), + [0x99] = new TextCmdModel('9'), + [0x9a] = new TextCmdModel('a'), + [0x9b] = new TextCmdModel('b'), + [0x9c] = new TextCmdModel('c'), + [0x9d] = new TextCmdModel('d'), + [0x9e] = new TextCmdModel('e'), + [0x9f] = new TextCmdModel('f'), + [0xa0] = new TextCmdModel('g'), + [0xa1] = new TextCmdModel('h'), + [0xa2] = new TextCmdModel('i'), + [0xa3] = new TextCmdModel('j'), + [0xa4] = new TextCmdModel('k'), + [0xa5] = new TextCmdModel('l'), + [0xa6] = new TextCmdModel('m'), + [0xa7] = new TextCmdModel('n'), + [0xa8] = new TextCmdModel('o'), + [0xa9] = new TextCmdModel('p'), + [0xaa] = new TextCmdModel('q'), + [0xab] = new TextCmdModel('r'), + [0xac] = new TextCmdModel('s'), + [0xad] = new TextCmdModel('t'), + [0xae] = new TextCmdModel('u'), + [0xaf] = new TextCmdModel('v'), + [0xb0] = new TextCmdModel('w'), + [0xb1] = new TextCmdModel('x'), + [0xb2] = new TextCmdModel('y'), + [0xb3] = new TextCmdModel('z'), + [0xb4] = new TextCmdModel('Æ'), + [0xb5] = new TextCmdModel('æ'), + [0xb6] = new TextCmdModel('ß'), + [0xb7] = new TextCmdModel('à'), + [0xb8] = new TextCmdModel('á'), + [0xb9] = new TextCmdModel('â'), + [0xba] = new TextCmdModel('ä'), + [0xbb] = new TextCmdModel('è'), + [0xbc] = new TextCmdModel('é'), + [0xbd] = new TextCmdModel('ê'), + [0xbe] = new TextCmdModel('ë'), + [0xbf] = new TextCmdModel('ì'), + [0xc0] = new TextCmdModel('í'), + [0xc1] = new TextCmdModel('î'), + [0xc2] = new TextCmdModel('ï'), + [0xc3] = new TextCmdModel('ñ'), + [0xc4] = new TextCmdModel('ò'), + [0xc5] = new TextCmdModel('ó'), + [0xc6] = new TextCmdModel('ô'), + [0xc7] = new TextCmdModel('ö'), + [0xc8] = new TextCmdModel('ù'), + [0xc9] = new TextCmdModel('ú'), + [0xca] = new TextCmdModel('û'), + [0xcb] = new TextCmdModel('ü'), + [0xcc] = new TextCmdModel('º'), + [0xcd] = new TextCmdModel('—'), + [0xce] = new TextCmdModel('»'), + [0xcf] = new TextCmdModel('«'), + [0xd0] = new TextCmdModel('À'), + [0xd1] = new TextCmdModel('Á'), + [0xd2] = new TextCmdModel('Â'), + [0xd3] = new TextCmdModel('Ä'), + [0xd4] = new TextCmdModel('È'), + [0xd5] = new TextCmdModel('É'), + [0xd6] = new TextCmdModel('Ê'), + [0xd7] = new TextCmdModel('Ë'), + [0xd8] = new TextCmdModel('Ì'), + [0xd9] = new TextCmdModel('Í'), + [0xda] = new TextCmdModel('Î'), + [0xdb] = new TextCmdModel('Ï'), + [0xdc] = new TextCmdModel('Ñ'), + [0xdd] = new TextCmdModel('Ò'), + [0xde] = new TextCmdModel('Ó'), + [0xdf] = new TextCmdModel('Ô'), + [0xe0] = new TextCmdModel('Ö'), + [0xe1] = new TextCmdModel('Ù'), + [0xe2] = new TextCmdModel('Ú'), + [0xe3] = new TextCmdModel('Û'), + [0xe4] = new TextCmdModel('Ü'), + [0xe5] = new TextCmdModel('¡'), + [0xe6] = new TextCmdModel('¿'), + [0xe7] = new TextCmdModel('Ç'), + [0xe8] = new TextCmdModel('ç'), + [0xe9] = new TextCmdModel('‛'), + [0xea] = new TextCmdModel('’'), + [0xeb] = new TextCmdModel('`'), + [0xec] = new TextCmdModel('´'), + [0xed] = new TextCmdModel('"'), + [0xee] = new TextCmdModel('\''), + [0xef] = new TextCmdModel('★'), + [0xf0] = new TextCmdModel('☆'), + [0xf1] = new TextCmdModel('■'), + [0xf2] = new TextCmdModel('□'), + [0xf3] = new TextCmdModel('▲'), + [0xf4] = new TextCmdModel('△'), + [0xf5] = new TextCmdModel('●'), + [0xf6] = new TextCmdModel('○'), + [0xf7] = new TextCmdModel('♪'), + [0xf8] = new TextCmdModel('♫'), + [0xf9] = new TextCmdModel('→'), + [0xfa] = new TextCmdModel('←'), + [0xfb] = new TextCmdModel('↑'), + [0xfc] = new TextCmdModel('↓'), + [0xfd] = new TextCmdModel('・'), + [0xfe] = new TextCmdModel('❤'), + [0xff] = new UnsupportedCmdModel(0xff), // Unused + }; + + public List Decode(byte[] data) => + new BaseMessageDecoder(_table, data).Decode(); + } +} diff --git a/OpenKh.Kh2/Messages/Internals/InternationalSystemEncode.cs b/OpenKh.Kh2/Messages/Internals/InternationalSystemEncode.cs index 32e555bfb..dc88506a6 100644 --- a/OpenKh.Kh2/Messages/Internals/InternationalSystemEncode.cs +++ b/OpenKh.Kh2/Messages/Internals/InternationalSystemEncode.cs @@ -1,79 +1,79 @@ -using OpenKh.Common.Exceptions; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Kh2.Messages.Internals -{ - internal class InternationalSystemEncode : IMessageEncode - { - private static readonly Dictionary> _tableCommands = - InternationalSystemDecode._table - .Where(x => x.Value != null && x.Value.Command != MessageCommand.PrintText) - .GroupBy(x => x.Value.Command) - .ToDictionary(x => x.Key, x => x.First()); - - private static readonly Dictionary _tableCharacters = - InternationalSystemDecode._table - .Where(x => x.Value?.Command == MessageCommand.PrintText) - .ToDictionary(x => x.Value.Text[0], x => x.Key); - - private static readonly Dictionary _tableComplex = - InternationalSystemDecode._table - .Where(x => x.Value?.Command == MessageCommand.PrintComplex) - .ToDictionary(x => x.Value.Text, x => x.Key); - - private void AppendEncodedMessageCommand(List list, MessageCommandModel messageCommand) - { - if (messageCommand.Command == MessageCommand.PrintText) - AppendEncodedText(list, messageCommand.Text); - else if (messageCommand.Command == MessageCommand.PrintComplex) - AppendEncodedComplex(list, messageCommand.Text); - else if (messageCommand.Command == MessageCommand.Unsupported) - list.AddRange(messageCommand.Data); - else - AppendEncodedCommand(list, messageCommand.Command, messageCommand.Data); - } - - private void AppendEncodedCommand(List list, MessageCommand command, byte[] data) - { - if (!_tableCommands.TryGetValue(command, out var pair)) - throw new ArgumentException($"The command {command} it is not supported by the specified encoding."); - - list.Add(pair.Key); - for (var i = 0; i < pair.Value.Length; i++) - list.Add(data[i]); - } - - private void AppendEncodedText(List list, string text) - { - foreach (var ch in text) - AppendEncodedChar(list, ch); - } - - private void AppendEncodedComplex(List list, string text) - { - if (!_tableComplex.TryGetValue(text, out var data)) - throw new ParseException(text, 0, "Complex text does not exists"); - - list.Add(data); - } - - private void AppendEncodedChar(List list, char ch) - { - if (!_tableCharacters.TryGetValue(ch, out var data)) - throw new ArgumentException($"The character {ch} it is not supported by the specified encoding."); - - list.Add(data); - } - - public byte[] Encode(List messageCommands) - { - var list = new List(100); - foreach (var model in messageCommands) - AppendEncodedMessageCommand(list, model); - - return list.ToArray(); - } - } -} +using OpenKh.Common.Exceptions; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Kh2.Messages.Internals +{ + internal class InternationalSystemEncode : IMessageEncode + { + private static readonly Dictionary> _tableCommands = + InternationalSystemDecode._table + .Where(x => x.Value != null && x.Value.Command != MessageCommand.PrintText) + .GroupBy(x => x.Value.Command) + .ToDictionary(x => x.Key, x => x.First()); + + private static readonly Dictionary _tableCharacters = + InternationalSystemDecode._table + .Where(x => x.Value?.Command == MessageCommand.PrintText) + .ToDictionary(x => x.Value.Text[0], x => x.Key); + + private static readonly Dictionary _tableComplex = + InternationalSystemDecode._table + .Where(x => x.Value?.Command == MessageCommand.PrintComplex) + .ToDictionary(x => x.Value.Text, x => x.Key); + + private void AppendEncodedMessageCommand(List list, MessageCommandModel messageCommand) + { + if (messageCommand.Command == MessageCommand.PrintText) + AppendEncodedText(list, messageCommand.Text); + else if (messageCommand.Command == MessageCommand.PrintComplex) + AppendEncodedComplex(list, messageCommand.Text); + else if (messageCommand.Command == MessageCommand.Unsupported) + list.AddRange(messageCommand.Data); + else + AppendEncodedCommand(list, messageCommand.Command, messageCommand.Data); + } + + private void AppendEncodedCommand(List list, MessageCommand command, byte[] data) + { + if (!_tableCommands.TryGetValue(command, out var pair)) + throw new ArgumentException($"The command {command} it is not supported by the specified encoding."); + + list.Add(pair.Key); + for (var i = 0; i < pair.Value.Length; i++) + list.Add(data[i]); + } + + private void AppendEncodedText(List list, string text) + { + foreach (var ch in text) + AppendEncodedChar(list, ch); + } + + private void AppendEncodedComplex(List list, string text) + { + if (!_tableComplex.TryGetValue(text, out var data)) + throw new ParseException(text, 0, "Complex text does not exists"); + + list.Add(data); + } + + private void AppendEncodedChar(List list, char ch) + { + if (!_tableCharacters.TryGetValue(ch, out var data)) + throw new ArgumentException($"The character {ch} it is not supported by the specified encoding."); + + list.Add(data); + } + + public byte[] Encode(List messageCommands) + { + var list = new List(100); + foreach (var model in messageCommands) + AppendEncodedMessageCommand(list, model); + + return list.ToArray(); + } + } +} diff --git a/OpenKh.Kh2/Messages/Internals/JapaneseEventDecode.cs b/OpenKh.Kh2/Messages/Internals/JapaneseEventDecode.cs index 4e6bfba5e..c9cd14f99 100644 --- a/OpenKh.Kh2/Messages/Internals/JapaneseEventDecode.cs +++ b/OpenKh.Kh2/Messages/Internals/JapaneseEventDecode.cs @@ -1,436 +1,443 @@ -using System.Collections.Generic; - -namespace OpenKh.Kh2.Messages.Internals -{ - internal class JapaneseEventDecode : IMessageDecode - { - public static readonly Dictionary _table = new Dictionary - { - [0x00] = new SimpleCmdModel(MessageCommand.End), - [0x01] = new TextCmdModel(' '), - [0x02] = new TextCmdModel('\n'), - [0x03] = new SimpleCmdModel(MessageCommand.Reset), - [0x04] = new SingleDataCmdModel(MessageCommand.Theme), - [0x05] = new DataCmdModel(MessageCommand.Unknown05, 6), - [0x06] = new SingleDataCmdModel(MessageCommand.Unknown06), - [0x07] = new DataCmdModel(MessageCommand.Color, 4), - [0x08] = new DataCmdModel(MessageCommand.Unknown08, 3), - [0x09] = new SingleDataCmdModel(MessageCommand.PrintIcon), - [0x0a] = new SingleDataCmdModel(MessageCommand.TextScale), - [0x0b] = new SingleDataCmdModel(MessageCommand.TextWidth), - [0x0c] = new SingleDataCmdModel(MessageCommand.LineSpacing), - [0x0d] = new SimpleCmdModel(MessageCommand.Unknown0d), - [0x0e] = new SingleDataCmdModel(MessageCommand.Unknown0e), - [0x0f] = new DataCmdModel(MessageCommand.Unknown0f, 5), - [0x10] = new SimpleCmdModel(MessageCommand.Clear), - [0x11] = new DataCmdModel(MessageCommand.Position, 4), - [0x12] = new DataCmdModel(MessageCommand.Unknown12, 2), - [0x13] = new DataCmdModel(MessageCommand.Unknown13, 4), - [0x14] = new DataCmdModel(MessageCommand.Delay, 2), - [0x15] = new DataCmdModel(MessageCommand.CharDelay, 2), - [0x16] = new SingleDataCmdModel(MessageCommand.Unknown16), - [0x17] = null, - [0x18] = new DataCmdModel(MessageCommand.Unknown18, 2), - [0x19] = new TableCmdModel(MessageCommand.Table2, JapaneseEventTable._table2), - [0x1a] = new TableCmdModel(MessageCommand.Table3, JapaneseEventTable._table3), - [0x1b] = new TableCmdModel(MessageCommand.Table4, JapaneseEventTable._table4), - [0x1c] = new TableCmdModel(MessageCommand.Table5, JapaneseEventTable._table5), - [0x1d] = new TableCmdModel(MessageCommand.Table6, JapaneseEventTable._table6), - [0x1e] = new TableCmdModel(MessageCommand.Table7, JapaneseEventTable._table7), - [0x1f] = new TableCmdModel(MessageCommand.Table8, JapaneseEventTable._table8), - [0x20] = new TextCmdModel(' '), - [0x21] = new TextCmdModel('0'), - [0x22] = new TextCmdModel('1'), - [0x23] = new TextCmdModel('2'), - [0x24] = new TextCmdModel('3'), - [0x25] = new TextCmdModel('4'), - [0x26] = new TextCmdModel('5'), - [0x27] = new TextCmdModel('6'), - [0x28] = new TextCmdModel('7'), - [0x29] = new TextCmdModel('8'), - [0x2a] = new TextCmdModel('9'), - [0x2b] = new TextCmdModel('+'), - [0x2c] = new TextCmdModel('−'), - [0x2d] = new TextCmdModel('ₓ'), - [0x2e] = new TextCmdModel('A'), - [0x2f] = new TextCmdModel('B'), - [0x30] = new TextCmdModel('C'), - [0x31] = new TextCmdModel('D'), - [0x32] = new TextCmdModel('E'), - [0x33] = new TextCmdModel('F'), - [0x34] = new TextCmdModel('G'), - [0x35] = new TextCmdModel('H'), - [0x36] = new TextCmdModel('I'), - [0x37] = new TextCmdModel('J'), - [0x38] = new TextCmdModel('K'), - [0x39] = new TextCmdModel('L'), - [0x3a] = new TextCmdModel('M'), - [0x3b] = new TextCmdModel('N'), - [0x3c] = new TextCmdModel('O'), - [0x3d] = new TextCmdModel('P'), - [0x3e] = new TextCmdModel('Q'), - [0x3f] = new TextCmdModel('R'), - [0x40] = new TextCmdModel('S'), - [0x41] = new TextCmdModel('T'), - [0x42] = new TextCmdModel('U'), - [0x43] = new TextCmdModel('V'), - [0x44] = new TextCmdModel('W'), - [0x45] = new TextCmdModel('X'), - [0x46] = new TextCmdModel('Y'), - [0x47] = new TextCmdModel('Z'), - [0x48] = new TextCmdModel('!'), - [0x49] = new TextCmdModel('?'), - [0x4a] = new TextCmdModel('%'), - [0x4b] = new TextCmdModel('/'), - [0x4c] = new TextCmdModel('※'), - [0x4d] = new TextCmdModel('、'), - [0x4e] = new TextCmdModel('。'), - [0x4f] = new TextCmdModel('.'), - [0x50] = new TextCmdModel(','), - [0x51] = new TextCmdModel('·'), - [0x52] = new TextCmdModel(':'), - [0x53] = new TextCmdModel('…'), - [0x54] = new TextCmdModel("-"), - [0x55] = new TextCmdModel('ー'), - [0x56] = new TextCmdModel('〜'), - [0x57] = new TextCmdModel("'"), - [0x58] = new TextCmdModel("‟"), - [0x59] = new TextCmdModel("„"), - [0x5a] = new TextCmdModel('('), - [0x5b] = new TextCmdModel(')'), - [0x5c] = new TextCmdModel('「'), - [0x5d] = new TextCmdModel('」'), - [0x5e] = new TextCmdModel('『'), - [0x5f] = new TextCmdModel('』'), - [0x60] = new TextCmdModel('“'), - [0x61] = new TextCmdModel('”'), - [0x62] = new TextCmdModel('['), - [0x63] = new TextCmdModel(']'), - [0x64] = new TextCmdModel('<'), - [0x65] = new TextCmdModel('>'), - [0x66] = new TextCmdModel('-'), - [0x67] = new TextCmdModel("–"), - [0x68] = new TextCmdModel('⤷'), // Used only in EVT - [0x69] = new TextCmdModel('♪'), - [0x6a] = new TextCmdModel('⇾'), // Used only in EVT - [0x6b] = new TextCmdModel('⇽'), // Used only in EVT - [0x6c] = new TextCmdModel("全"), - [0x6d] = new TextCmdModel("合"), - [0x6e] = new TextCmdModel("成"), - [0x6f] = new TextCmdModel("半"), - [0x70] = new TextCmdModel('◯'), - [0x71] = new TextCmdModel('✕'), - [0x72] = new TextCmdModel('△'), - [0x73] = new TextCmdModel('☐'), - [0x74] = new TextCmdModel('▴'), - [0x75] = new TextCmdModel('▾'), - [0x76] = new TextCmdModel('▸'), - [0x77] = new TextCmdModel('◂'), - [0x78] = null, - [0x79] = null, - [0x7a] = null, - [0x7b] = null, - [0x7c] = null, - [0x7d] = null, - [0x7e] = null, - [0x7f] = null, - [0x80] = null, - [0x81] = null, - [0x82] = new TextCmdModel('⭑'), - [0x83] = new TextCmdModel('⭒'), - [0x84] = new TextCmdModel('l'), - [0x85] = new TextCmdModel('a'), - [0x86] = new TextCmdModel('y'), - [0x87] = new TextCmdModel('t'), - [0x88] = new TextCmdModel('i'), - [0x89] = new TextCmdModel('o'), - [0x8a] = new TextCmdModel('n'), - [0x8b] = new TextCmdModel('r'), - [0x8c] = new TextCmdModel('⬛'), - [0x8d] = new TextCmdModel('前'), - [0x8e] = new TextCmdModel('選'), - [0x8f] = new TextCmdModel('一'), - [0x90] = new TextCmdModel('あ'), - [0x91] = new TextCmdModel('い'), - [0x92] = new TextCmdModel('う'), - [0x93] = new TextCmdModel('え'), - [0x94] = new TextCmdModel('お'), - [0x95] = new TextCmdModel('か'), - [0x96] = new TextCmdModel('き'), - [0x97] = new TextCmdModel('く'), - [0x98] = new TextCmdModel('け'), - [0x99] = new TextCmdModel('こ'), - [0x9a] = new TextCmdModel('さ'), - [0x9b] = new TextCmdModel('し'), - [0x9c] = new TextCmdModel('す'), - [0x9d] = new TextCmdModel('せ'), - [0x9e] = new TextCmdModel('そ'), - [0x9f] = new TextCmdModel('た'), - [0xa0] = new TextCmdModel('ち'), - [0xa1] = new TextCmdModel('つ'), - [0xa2] = new TextCmdModel('て'), - [0xa3] = new TextCmdModel('と'), - [0xa4] = new TextCmdModel('な'), - [0xa5] = new TextCmdModel('に'), - [0xa6] = new TextCmdModel('ぬ'), - [0xa7] = new TextCmdModel('ね'), - [0xa8] = new TextCmdModel('の'), - [0xa9] = new TextCmdModel('は'), - [0xaa] = new TextCmdModel('ひ'), - [0xab] = new TextCmdModel('ふ'), - [0xac] = new TextCmdModel('へ'), - [0xad] = new TextCmdModel('ほ'), - [0xae] = new TextCmdModel('ま'), - [0xaf] = new TextCmdModel('み'), - [0xb0] = new TextCmdModel('む'), - [0xb1] = new TextCmdModel('め'), - [0xb2] = new TextCmdModel('も'), - [0xb3] = new TextCmdModel('や'), - [0xb4] = new TextCmdModel('ゆ'), - [0xb5] = new TextCmdModel('よ'), - [0xb6] = new TextCmdModel('ら'), - [0xb7] = new TextCmdModel('り'), - [0xb8] = new TextCmdModel('る'), - [0xb9] = new TextCmdModel('れ'), - [0xba] = new TextCmdModel('ろ'), - [0xbb] = new TextCmdModel('わ'), - [0xbc] = new TextCmdModel('を'), - [0xbd] = new TextCmdModel('ん'), - [0xbe] = new TextCmdModel('が'), - [0xbf] = new TextCmdModel('ぎ'), - [0xc0] = new TextCmdModel('ぐ'), - [0xc1] = new TextCmdModel('げ'), - [0xc2] = new TextCmdModel('ご'), - [0xc3] = new TextCmdModel('ざ'), - [0xc4] = new TextCmdModel('じ'), - [0xc5] = new TextCmdModel('ず'), - [0xc6] = new TextCmdModel('ぜ'), - [0xc7] = new TextCmdModel('ぞ'), - [0xc8] = new TextCmdModel('だ'), - [0xc9] = new TextCmdModel('ぢ'), - [0xca] = new TextCmdModel('づ'), - [0xcb] = new TextCmdModel('で'), - [0xcc] = new TextCmdModel('ど'), - [0xcd] = new TextCmdModel('ば'), - [0xce] = new TextCmdModel('び'), - [0xcf] = new TextCmdModel('ぶ'), - [0xd0] = new TextCmdModel('べ'), - [0xd1] = new TextCmdModel('ぼ'), - [0xd2] = new TextCmdModel('ぱ'), - [0xd3] = new TextCmdModel('ぴ'), - [0xd4] = new TextCmdModel('ぷ'), - [0xd5] = new TextCmdModel('ぺ'), - [0xd6] = new TextCmdModel('ぽ'), - [0xd7] = new TextCmdModel('ぁ'), - [0xd8] = new TextCmdModel('ぃ'), - [0xd9] = new TextCmdModel('ぅ'), - [0xda] = new TextCmdModel('ぇ'), - [0xdb] = new TextCmdModel('ぉ'), - [0xdc] = new TextCmdModel('ゃ'), - [0xdd] = new TextCmdModel('ゅ'), - [0xde] = new TextCmdModel('ょ'), - [0xdf] = new TextCmdModel('っ'), - [0xe0] = new TextCmdModel('ア'), - [0xe1] = new TextCmdModel('イ'), - [0xe2] = new TextCmdModel('ウ'), - [0xe3] = new TextCmdModel('エ'), - [0xe4] = new TextCmdModel('オ'), - [0xe5] = new TextCmdModel('カ'), - [0xe6] = new TextCmdModel('キ'), - [0xe7] = new TextCmdModel('ク'), - [0xe8] = new TextCmdModel('ケ'), - [0xe9] = new TextCmdModel('コ'), - [0xea] = new TextCmdModel('サ'), - [0xeb] = new TextCmdModel('シ'), - [0xec] = new TextCmdModel('ス'), - [0xed] = new TextCmdModel('セ'), - [0xee] = new TextCmdModel('ソ'), - [0xef] = new TextCmdModel('タ'), - [0xf0] = new TextCmdModel('チ'), - [0xf1] = new TextCmdModel('ツ'), - [0xf2] = new TextCmdModel('テ'), - [0xf3] = new TextCmdModel('ト'), - [0xf4] = new TextCmdModel('ナ'), - [0xf5] = new TextCmdModel('ニ'), - [0xf6] = new TextCmdModel('ヌ'), - [0xf7] = new TextCmdModel('ネ'), - [0xf8] = new TextCmdModel('ノ'), - [0xf9] = new TextCmdModel('ハ'), - [0xfa] = new TextCmdModel('ヒ'), - [0xfb] = new TextCmdModel('フ'), - [0xfc] = new TextCmdModel('ヘ'), - [0xfd] = new TextCmdModel('ホ'), - [0xfe] = new TextCmdModel('マ'), - [0xff] = new TextCmdModel('ミ'), - }; - - public List Decode(byte[] data) => - new BaseMessageDecoder(_table, data).Decode(decoder => - { - if (decoder.IsEof(1)) - return false; - - var ch = decoder.Peek(0); - var parameter = decoder.Peek(1); - decoder.WrapTable(ref ch, ref parameter); - - switch (ch) - { - case 0x1d: - switch (parameter) - { - case 0x1a: return AppendComplex(decoder, "III"); - case 0x1b: return AppendComplex(decoder, "VII"); - case 0x1c: return AppendComplex(decoder, "VIII"); - case 0x1d: return AppendComplex(decoder, "X"); - } - break; - case 0x1e: - switch (parameter) - { - case 0x50: return AppendComplex(decoder, "XIII"); - case 0xb6: return AppendComplex(decoder, "VI"); - case 0xb7: return AppendComplex(decoder, "IX"); - } - break; - } - - return false; - }); - - private bool AppendComplex(IDecoder decoder, string value) - { - decoder.Next(); - decoder.Next(); - decoder.AppendComplex(value); - return true; - } - } - - internal static class JapaneseEventTable - { - public static readonly char[] _table2 = new char[0x100] - { - 'ム', 'メ', 'モ', 'ヤ', 'ユ', 'ヨ', 'ラ', - 'リ', 'ル', 'レ', 'ロ', 'ワ', 'ヲ', 'ン', 'ガ', 'ギ', 'グ', 'ゲ', 'ゴ', 'ザ', 'ジ', 'ズ', 'ゼ', 'ゾ', 'ダ', 'ヂ', 'ヅ', 'デ', - 'ド', 'バ', 'ビ', 'ブ', 'ベ', 'ボ', 'ヴ', 'パ', 'ピ', 'プ', 'ペ', 'ポ', 'ァ', 'ィ', 'ゥ', 'ェ', 'ォ', 'ャ', 'ュ', 'ョ', 'ッ', - '端', '子', '接', '続', '正', '常', '発', '生', '使', '用', '専', '付', '属', '取', '扱', '説', '明', '書', '指', '示', '従', - '修', '復', '下', '空', '容', '量', '不', '足', '以', '上', '必', '要', '開', '始', '本', '魔', '石', '晶', '結', '大', '紋', - '盾', '凍', '透', '燃', '水', '気', '炎', '士', '守', '証', '吹', '闘', '力', '木', '人', '飲', '過', '丸', '騎', '去', '魚', - '剣', '荒', '氏', '杖', '束', '太', '鳥', '導', '布', '風', '満', '約', '源', '出', '実', '海', '思', '王', '自', '名', '喚', - '召', '地', '家', '火', '森', '皆', '許', '恐', '古', '轟', '魂', '臭', '章', '雲', '雪', '然', '達', '嘆', '潰', '瓜', '伝', - '怒', '悲', '怖', '鳴', '免', '雷', '林', '様', '巻', '片', '翼', '天', '則', '四', '掲', '板', '登', '孫', '⬛', '⬛', '⬛', - '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', - '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', - - //evt1-2 - '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', - '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', - }; - - public static readonly char[] _table3 = new char[0x100] - { - '⬛', '誠', '納', - '泡', '程', '析', '遮', '戒', '井', '及', '模', '算', '霧', '熟', '#', '鈍', '賭', '欺', '鹿', '式', '炸', '裂', '索', '詮', - '眩', '罠', '千', '塗', '羽', '柵', '緊', '粗', '何', '俺', '行', '世', '界', '紀', '事', '前', '符', '来', '見', '一', '絡', - '分', '寂', '心', '賃', '言', '物', '知', '外', '君', '私', '宛', '今', '男', '島', '老', '緒', '幕', '処', '菓', '場', '鎖', - '食', '夢', '女', '賞', '所', '者', '時', '消', '探', '当', '無', '儀', '話', '鍵', '捜', '中', '目', '公', '声', '謎', '間', - '為', '鍵', '密', '闇', '掌', '僕', '留', '句', '般', '誰', '聞', '連', '夫', '扉', '統', '顔', '丈', '少', '我', '他', '立', - '合', '助', '対', '刀', '侮', '辱', '秘', '通', '頼', '冒', '帰', '刑', '夜', '絶', '船', '即', '方', '込', '全', '良', '忘', - '凱', '追', '旅', '起', '険', '供', '抜', '遠', '最', '感', '役', '各', '入', '旋', '遂', '日', '欠', '堅', '主', '会', '向', - '年', '早', '別', '褒', '宝', '変', '度', '後', '星', '授', '矢', '配', '現', '覚', '選', '急', '二', '居', '座', '願', '勝', - '怪', '漁', '鼻', '影', '違', '離', '遅', '訣', '繋', '視', '勇', '笑', '奪', '馳', '々', '切', '厄', '父', '犬', '白', '跳', - '祝', '仮', '強', '押', '仲', '面', '毛', '回', '倒', '拒', '持', '画', '近', '戻', '望', '負', '傷', '刀', '拐', '優', '内', - '赦', '秒', '数', '敵', '槍', '珍', '姿', '歩', '左', '英', '雄', '破', '求', '鷹', '周', '蹴', '費', '衝', '狙', '経', '験', - '値', '便', '表', '歳', '元', '災', '先', '宙', '残', '閉', '移', '動', '走', '眠', '与', '敢', '壊', '臆', '病', '犠', '牲', - '滅', - - }; - - public static readonly char[] _table4 = new char[0x100] - { - '竜', '床', '落', '思', '踏', '特', '加', '停', '応', '化', '右', '死', '襲', '由', '進', '滑', '陽', '頭', '済', '限', - '昼', '五', '楽', '道', '昇', '朝', '照', '確', '甲', '更', '辿', '着', '断', '途', '光', '身', '番', '武', '器', '考', '傑', - '性', '意', '味', '同', '景', '色', '長', '待', '彼', '悪', '穴', '飛', '友', '集', '植', '逃', '雅', '料', '街', '幸', '危', - '決', '房', '記', '判', '掃', '部', '備', '完', '隠', '試', '遊', '姫', '形', '撫', '規', '材', '成', '置', '尾', '計', '作', - '準', '卵', '仕', '命', '真', '音', '宮', '裁', '娘', '聴', '嘘', '殿', '憶', '信', '城', '奴', '福', '返', '己', '拠', '戦', - '冗', '談', '康', '答', '弱', '黙', '呑', '欲', '理', '調', '犯', '予', '止', '博', '件', '解', '削', '舎', '渡', '深', '策', - '屈', '装', '努', '挽', '捕', '失', '刻', '例', '息', '航', '敗', '得', '訳', '放', '矛', '告', '罪', '次', '参', '機', '巣', - - //evt2-1 - '金', '情', '令', '貸', '突', '円', '妙', '録', '笛', '境', '田', '秀', '根', '相', '終', '広', '乗', '駄', '的', '宇', '邪', - '冷', '投', '呼', '葉', '暴', '百', '黄', '新', '町', '喰', '捨', '避', '妃', '安', '頃', '枚', '尻', '没', '嵐', '季', '節', - '困', '悔', '汽', '暗', '排', '体', '状', '況', '流', '条', '希', '店', '被', '再', '第', '僧', '練', '習', '末', '契', '果', - '可', '族', '滝', '反', '組', '多', '協', '支', '念', '了', '誘', '卒', '業', '泳', '嬢', '灯', '賊', '張', '嫌', '員', '隊', - '争', '服', '黒', '→', '←', '口', '忙', '映', '写', '砂', '漠', '妖', '精', '粉', '存', '在', '♪', '野', '郎', '降', '想', - '像', '数', '激', '国', '務', - }; - - public static readonly char[] _table5 = new char[0x100] - { - '操', '縦', '洞', '整', '鼓', '室', '屋', '貝', '騒', '問', '題', '簡', '単', '関', '係', '祈', - '辺', '昔', '匹', '母', '礼', '任', '腹', '輩', '侵', '非', '距', '学', '愚', '点', '活', '躍', '臣', '喜', '板', '岩', '茶', - '異', '線', '沈', '迷', '働', '秩', '序', '規', '#', '貴', '送', '静', '初', '六', '払', '客', '薬', '暮', '青', '諸', '舵', - '旗', '廃', '墟', '陰', '奇', '懐', '染', '横', '響', '逆', '苦', '威', '廷', '育', '群', '悟', '奥', '査', '慎', '好', '利', - '有', '住', '平', '和', '壁', '瞬', '難', '干', '渉', '乱', '窟', '窓', '研', '究', '香', '台', 'ヶ', '救', '態', '村', '驚', - '伸', '咲', '繁', '価', '甘', '獲', '案', '誤', '賛', '舞', '迎', '保', '識', '庫', '慣', '冠', '魅', '増', '狐', '握', '班', - '散', '転', '弁', '至', '律', '亡', '万', '油', '等', '席', '興', '局', '位', '図', '宿', '申', '憎', '焼', '惑', '凶', '北', - '謝', '議', '紹', '介', '複', '雑', '才', '虜', '恩', '順', '格', '皮', '質', '雨', '直', '胸', '近', '媒', '路', '未', '吸', - '志', '封', '土', '牢', '獄', '溶', '哀', '届', '徒', '択', '勢', '踊', '祭', '叩', '叱', '厳', '報', '寸', '似', '引', '受', - '囲', '振', '#', '嬉', '背', '曲', '芽', '偶', '借', '休', '伏', '陛', '除', '緑', '換', '舟', '覆', '叶', 'a', '詳', '焦', - '惜', '久', '企', '互', '招', '汚', '差', '塔', '吐', '渦', 'e', '狭', '尽', '構', '固', '紙', '読', 'i', '競', '姉', '検', - '審', '担', '売', '買', '率', 'k', '美', '獣', '兵', 'n', 'o', '冥', '短', '忠', '盗', '赤', '耳', '故', '郷', '刺', '勉', - '印', '功', '鬼', 'r', '蒸', '愛', '婚', '恋', '賢', - }; - - public static readonly char[] _table6 = new char[0x100] - { - '猫', '責', '熱', '若', '市', '歌', '袋', '虫', '裏', '義', '畑', '西', - '囚', '弟', '妻', 's', '善', '禁', '占', '芸', '幽', '霊', '清', '個', 'l', 'p', 'Ⅲ', 'Ⅶ', 'Ⅷ', 'Ⅹ', '高', '工', '敷', - '科', '恵', '痛', '毎', '注', '軽', '橋', '殖', '球', '陣', '打', '崩', '品', '退', '催', '永', '遺', '脱', '疑', '民', '尊', - '敬', '純', '純', '治', '潜', '種', '類', '抑', '制', '幅', '領', '域', '療', '施', '具', '称', '収', '象', '跡', '察', '糧', - - //evt2-2 - '統', '観', '触', '揺', '標', '到', '拐', '超', '測', '弾', '富', '留', '易', '文', '献', '採', '漂', '語', '造', '稼', '改', - '能', '比', '較', '区', '訪', '往', '混', '沌', '底', '原', '墓', '普', '絵', '額', '又', '暇', '縮', '呪', '掛', '慮', '#', - '癒', '階', '鐘', '描', '秋', '冬', '夏', '泊', '東', '展', '戸', '舷', '浮', '毒', '氷', '幻', '胃', '腸', '誕', '椅', '館', - '廊', '堂', '斎', '玉', '械', '砲', '聖', '針', '春', '冬', '南', '山', '川', '谷', '渓', '崖', '岸', 't', '棺', '門', '月', - '丘', '吊', '拷', '倉', '蔵', '浜', '江', '淵', '溝', '庭', '園', '峡', '潮', '段', '柱', '基', 'h', '汝', '楼', '拝', '草', - '竹', '沼', '層', '虚', '噴', '交', '花', '輝', '護', '巧', '師', '首', '術', '飾', '神', '箱', '輪', '腕', '手', '防', '御', - '撃', '攻', '小', '定', '認', '法', '技', '巨', '樹', '効', '系', '運', '半', '字', '鉱', '三', '型', '耐', '速', '設', '低', - '共', 'g', '側', '阻', '両', '級', '殻', '圧', '亜', '劣', '胴', '脚', '独', '射', '偉', '勘', '頂', '戴', '忍', '素', 'b', - '&', '則', '四', '掲', '板', '登', '孫', '締', '憐', '鮮', '歪', '叫', '推', - }; - - public static readonly char[] _table7 = new char[0x100] - { - '旧', '臨', '奈', '摩', 'y', '細', '肉', '因', - '財', '疲', '婆', '省', '寒', '沢', '商', '却', '派', '盛', '泥', '棄', '棒', '代', '晩', '枯', '期', '譲', '晴', '卑', '越', - '縁', '権', '極', '磨', '替', '宣', '歓', '績', '繰', '栄', '淑', '幾', '杯', '紳', '候', '壁', '杭', '補', '懲', '酬', '勤', - '怯', '余', '労', '匂', '罰', '糸', '辛', '棟', '課', '荷', '頑', '恥', '酷', '随', '醜', '詞', '償', '棒', '隣', '励', '倍', - '充', '#', '雰', '涙', '脅', '泣', '泥', '党', '洪', '_', '討', '伐', '皇', '帝', '殺', '編', '窮', '恨', '腰', '飯', '貨', - '港', '軍', '号', '血', '掟', '浴', '範', '謹', '寄', '豪', '詰', '慢', '損', '史', '略', '抱', '遭', '慈', '際', '誉', '縄', - '銘', '肝', '並', '殴', '利', '誇', '謁', '憩', '祖', '官', '都', '司', '駆', '柄', '挑', '偽', '吉', '堤', '建', '銅', '車', - '贈', '唯', '資', '預', '委', '埋', '督', '謀', '穏', '筋', '適', '迫', '殊', '絆', '狼', '割', '砦', '徐', '煙', '肖', '慌', - '訓', '芝', '桟', '灰', '障', '砕', '幼', '製', '鋭', '骨', '馬', '拾', '掘', '温', '微', '歯', '将', '兄', '駅', '忌', '坊', - '慕', '執', '寝', '酒', '管', '華', 'Ⅵ', 'Ⅸ', '狂', '網', '雲', '征', '総', '衆', '冶', '雇', '髪', '燭', '鉄', '監', '団', - '継', '肩', '電', '給', '評', '営', '依', '職', '憧', '麗', '症', '衣', '眼', '揮', '鋼', '瞳', '匠', '貫', '克', '歴', '養', - '織', '礎', '讐', '演', '衛', '狩', '減', '波', '丁', '積', '環', '銃', '警', '龍', '峠', '脈', '宅', '創', '社', '論', '枢', - '否', '列', '包', '奮', '七', '噂', '坂', '貼', '逮', '幕', '帯', '銀', '援', '悩', '凄', '昨', '妬', - }; - - public static readonly char[] _table8 = new char[0x100] - { - '捧', '怠', '裕', '十', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', - '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', - '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', - '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', - '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', - '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', - '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', - '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', - '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', - '*', '*', '*', '*', - }; - } -} +using System.Collections.Generic; + +namespace OpenKh.Kh2.Messages.Internals +{ + internal class JapaneseEventDecode : IMessageDecode + { + public static readonly Dictionary _table = new Dictionary + { + [0x00] = new SimpleCmdModel(MessageCommand.End), + [0x01] = new TextCmdModel(' '), + [0x02] = new TextCmdModel('\n'), + [0x03] = new SimpleCmdModel(MessageCommand.Reset), + [0x04] = new SingleDataCmdModel(MessageCommand.Theme), + [0x05] = new DataCmdModel(MessageCommand.Unknown05, 6), + [0x06] = new SingleDataCmdModel(MessageCommand.Unknown06), + [0x07] = new DataCmdModel(MessageCommand.Color, 4), + [0x08] = new DataCmdModel(MessageCommand.Unknown08, 3), + [0x09] = new SingleDataCmdModel(MessageCommand.PrintIcon), + [0x0a] = new SingleDataCmdModel(MessageCommand.TextScale), + [0x0b] = new SingleDataCmdModel(MessageCommand.TextWidth), + [0x0c] = new SingleDataCmdModel(MessageCommand.LineSpacing), + [0x0d] = new SimpleCmdModel(MessageCommand.Unknown0d), + [0x0e] = new SingleDataCmdModel(MessageCommand.Unknown0e), + [0x0f] = new DataCmdModel(MessageCommand.Unknown0f, 5), + [0x10] = new SimpleCmdModel(MessageCommand.Clear), + [0x11] = new DataCmdModel(MessageCommand.Position, 4), + [0x12] = new DataCmdModel(MessageCommand.Unknown12, 2), + [0x13] = new DataCmdModel(MessageCommand.Unknown13, 4), + [0x14] = new DataCmdModel(MessageCommand.Delay, 2), + [0x15] = new DataCmdModel(MessageCommand.CharDelay, 2), + [0x16] = new SingleDataCmdModel(MessageCommand.Unknown16), + [0x17] = null, + [0x18] = new DataCmdModel(MessageCommand.Unknown18, 2), + [0x19] = new TableCmdModel(MessageCommand.Table2, JapaneseEventTable._table2), + [0x1a] = new TableCmdModel(MessageCommand.Table3, JapaneseEventTable._table3), + [0x1b] = new TableCmdModel(MessageCommand.Table4, JapaneseEventTable._table4), + [0x1c] = new TableCmdModel(MessageCommand.Table5, JapaneseEventTable._table5), + [0x1d] = new TableCmdModel(MessageCommand.Table6, JapaneseEventTable._table6), + [0x1e] = new TableCmdModel(MessageCommand.Table7, JapaneseEventTable._table7), + [0x1f] = new TableCmdModel(MessageCommand.Table8, JapaneseEventTable._table8), + [0x20] = new TextCmdModel(' '), + [0x21] = new TextCmdModel('0'), + [0x22] = new TextCmdModel('1'), + [0x23] = new TextCmdModel('2'), + [0x24] = new TextCmdModel('3'), + [0x25] = new TextCmdModel('4'), + [0x26] = new TextCmdModel('5'), + [0x27] = new TextCmdModel('6'), + [0x28] = new TextCmdModel('7'), + [0x29] = new TextCmdModel('8'), + [0x2a] = new TextCmdModel('9'), + [0x2b] = new TextCmdModel('+'), + [0x2c] = new TextCmdModel('−'), + [0x2d] = new TextCmdModel('ₓ'), + [0x2e] = new TextCmdModel('A'), + [0x2f] = new TextCmdModel('B'), + [0x30] = new TextCmdModel('C'), + [0x31] = new TextCmdModel('D'), + [0x32] = new TextCmdModel('E'), + [0x33] = new TextCmdModel('F'), + [0x34] = new TextCmdModel('G'), + [0x35] = new TextCmdModel('H'), + [0x36] = new TextCmdModel('I'), + [0x37] = new TextCmdModel('J'), + [0x38] = new TextCmdModel('K'), + [0x39] = new TextCmdModel('L'), + [0x3a] = new TextCmdModel('M'), + [0x3b] = new TextCmdModel('N'), + [0x3c] = new TextCmdModel('O'), + [0x3d] = new TextCmdModel('P'), + [0x3e] = new TextCmdModel('Q'), + [0x3f] = new TextCmdModel('R'), + [0x40] = new TextCmdModel('S'), + [0x41] = new TextCmdModel('T'), + [0x42] = new TextCmdModel('U'), + [0x43] = new TextCmdModel('V'), + [0x44] = new TextCmdModel('W'), + [0x45] = new TextCmdModel('X'), + [0x46] = new TextCmdModel('Y'), + [0x47] = new TextCmdModel('Z'), + [0x48] = new TextCmdModel('!'), + [0x49] = new TextCmdModel('?'), + [0x4a] = new TextCmdModel('%'), + [0x4b] = new TextCmdModel('/'), + [0x4c] = new TextCmdModel('※'), + [0x4d] = new TextCmdModel('、'), + [0x4e] = new TextCmdModel('。'), + [0x4f] = new TextCmdModel('.'), + [0x50] = new TextCmdModel(','), + [0x51] = new TextCmdModel('·'), + [0x52] = new TextCmdModel(':'), + [0x53] = new TextCmdModel('…'), + [0x54] = new TextCmdModel("-"), + [0x55] = new TextCmdModel('ー'), + [0x56] = new TextCmdModel('〜'), + [0x57] = new TextCmdModel("'"), + [0x58] = new TextCmdModel("‟"), + [0x59] = new TextCmdModel("„"), + [0x5a] = new TextCmdModel('('), + [0x5b] = new TextCmdModel(')'), + [0x5c] = new TextCmdModel('「'), + [0x5d] = new TextCmdModel('」'), + [0x5e] = new TextCmdModel('『'), + [0x5f] = new TextCmdModel('』'), + [0x60] = new TextCmdModel('“'), + [0x61] = new TextCmdModel('”'), + [0x62] = new TextCmdModel('['), + [0x63] = new TextCmdModel(']'), + [0x64] = new TextCmdModel('<'), + [0x65] = new TextCmdModel('>'), + [0x66] = new TextCmdModel('-'), + [0x67] = new TextCmdModel("–"), + [0x68] = new TextCmdModel('⤷'), // Used only in EVT + [0x69] = new TextCmdModel('♪'), + [0x6a] = new TextCmdModel('⇾'), // Used only in EVT + [0x6b] = new TextCmdModel('⇽'), // Used only in EVT + [0x6c] = new TextCmdModel("全"), + [0x6d] = new TextCmdModel("合"), + [0x6e] = new TextCmdModel("成"), + [0x6f] = new TextCmdModel("半"), + [0x70] = new TextCmdModel('◯'), + [0x71] = new TextCmdModel('✕'), + [0x72] = new TextCmdModel('△'), + [0x73] = new TextCmdModel('☐'), + [0x74] = new TextCmdModel('▴'), + [0x75] = new TextCmdModel('▾'), + [0x76] = new TextCmdModel('▸'), + [0x77] = new TextCmdModel('◂'), + [0x78] = null, + [0x79] = null, + [0x7a] = null, + [0x7b] = null, + [0x7c] = null, + [0x7d] = null, + [0x7e] = null, + [0x7f] = null, + [0x80] = null, + [0x81] = null, + [0x82] = new TextCmdModel('⭑'), + [0x83] = new TextCmdModel('⭒'), + [0x84] = new TextCmdModel('l'), + [0x85] = new TextCmdModel('a'), + [0x86] = new TextCmdModel('y'), + [0x87] = new TextCmdModel('t'), + [0x88] = new TextCmdModel('i'), + [0x89] = new TextCmdModel('o'), + [0x8a] = new TextCmdModel('n'), + [0x8b] = new TextCmdModel('r'), + [0x8c] = new TextCmdModel('⬛'), + [0x8d] = new TextCmdModel('前'), + [0x8e] = new TextCmdModel('選'), + [0x8f] = new TextCmdModel('一'), + [0x90] = new TextCmdModel('あ'), + [0x91] = new TextCmdModel('い'), + [0x92] = new TextCmdModel('う'), + [0x93] = new TextCmdModel('え'), + [0x94] = new TextCmdModel('お'), + [0x95] = new TextCmdModel('か'), + [0x96] = new TextCmdModel('き'), + [0x97] = new TextCmdModel('く'), + [0x98] = new TextCmdModel('け'), + [0x99] = new TextCmdModel('こ'), + [0x9a] = new TextCmdModel('さ'), + [0x9b] = new TextCmdModel('し'), + [0x9c] = new TextCmdModel('す'), + [0x9d] = new TextCmdModel('せ'), + [0x9e] = new TextCmdModel('そ'), + [0x9f] = new TextCmdModel('た'), + [0xa0] = new TextCmdModel('ち'), + [0xa1] = new TextCmdModel('つ'), + [0xa2] = new TextCmdModel('て'), + [0xa3] = new TextCmdModel('と'), + [0xa4] = new TextCmdModel('な'), + [0xa5] = new TextCmdModel('に'), + [0xa6] = new TextCmdModel('ぬ'), + [0xa7] = new TextCmdModel('ね'), + [0xa8] = new TextCmdModel('の'), + [0xa9] = new TextCmdModel('は'), + [0xaa] = new TextCmdModel('ひ'), + [0xab] = new TextCmdModel('ふ'), + [0xac] = new TextCmdModel('へ'), + [0xad] = new TextCmdModel('ほ'), + [0xae] = new TextCmdModel('ま'), + [0xaf] = new TextCmdModel('み'), + [0xb0] = new TextCmdModel('む'), + [0xb1] = new TextCmdModel('め'), + [0xb2] = new TextCmdModel('も'), + [0xb3] = new TextCmdModel('や'), + [0xb4] = new TextCmdModel('ゆ'), + [0xb5] = new TextCmdModel('よ'), + [0xb6] = new TextCmdModel('ら'), + [0xb7] = new TextCmdModel('り'), + [0xb8] = new TextCmdModel('る'), + [0xb9] = new TextCmdModel('れ'), + [0xba] = new TextCmdModel('ろ'), + [0xbb] = new TextCmdModel('わ'), + [0xbc] = new TextCmdModel('を'), + [0xbd] = new TextCmdModel('ん'), + [0xbe] = new TextCmdModel('が'), + [0xbf] = new TextCmdModel('ぎ'), + [0xc0] = new TextCmdModel('ぐ'), + [0xc1] = new TextCmdModel('げ'), + [0xc2] = new TextCmdModel('ご'), + [0xc3] = new TextCmdModel('ざ'), + [0xc4] = new TextCmdModel('じ'), + [0xc5] = new TextCmdModel('ず'), + [0xc6] = new TextCmdModel('ぜ'), + [0xc7] = new TextCmdModel('ぞ'), + [0xc8] = new TextCmdModel('だ'), + [0xc9] = new TextCmdModel('ぢ'), + [0xca] = new TextCmdModel('づ'), + [0xcb] = new TextCmdModel('で'), + [0xcc] = new TextCmdModel('ど'), + [0xcd] = new TextCmdModel('ば'), + [0xce] = new TextCmdModel('び'), + [0xcf] = new TextCmdModel('ぶ'), + [0xd0] = new TextCmdModel('べ'), + [0xd1] = new TextCmdModel('ぼ'), + [0xd2] = new TextCmdModel('ぱ'), + [0xd3] = new TextCmdModel('ぴ'), + [0xd4] = new TextCmdModel('ぷ'), + [0xd5] = new TextCmdModel('ぺ'), + [0xd6] = new TextCmdModel('ぽ'), + [0xd7] = new TextCmdModel('ぁ'), + [0xd8] = new TextCmdModel('ぃ'), + [0xd9] = new TextCmdModel('ぅ'), + [0xda] = new TextCmdModel('ぇ'), + [0xdb] = new TextCmdModel('ぉ'), + [0xdc] = new TextCmdModel('ゃ'), + [0xdd] = new TextCmdModel('ゅ'), + [0xde] = new TextCmdModel('ょ'), + [0xdf] = new TextCmdModel('っ'), + [0xe0] = new TextCmdModel('ア'), + [0xe1] = new TextCmdModel('イ'), + [0xe2] = new TextCmdModel('ウ'), + [0xe3] = new TextCmdModel('エ'), + [0xe4] = new TextCmdModel('オ'), + [0xe5] = new TextCmdModel('カ'), + [0xe6] = new TextCmdModel('キ'), + [0xe7] = new TextCmdModel('ク'), + [0xe8] = new TextCmdModel('ケ'), + [0xe9] = new TextCmdModel('コ'), + [0xea] = new TextCmdModel('サ'), + [0xeb] = new TextCmdModel('シ'), + [0xec] = new TextCmdModel('ス'), + [0xed] = new TextCmdModel('セ'), + [0xee] = new TextCmdModel('ソ'), + [0xef] = new TextCmdModel('タ'), + [0xf0] = new TextCmdModel('チ'), + [0xf1] = new TextCmdModel('ツ'), + [0xf2] = new TextCmdModel('テ'), + [0xf3] = new TextCmdModel('ト'), + [0xf4] = new TextCmdModel('ナ'), + [0xf5] = new TextCmdModel('ニ'), + [0xf6] = new TextCmdModel('ヌ'), + [0xf7] = new TextCmdModel('ネ'), + [0xf8] = new TextCmdModel('ノ'), + [0xf9] = new TextCmdModel('ハ'), + [0xfa] = new TextCmdModel('ヒ'), + [0xfb] = new TextCmdModel('フ'), + [0xfc] = new TextCmdModel('ヘ'), + [0xfd] = new TextCmdModel('ホ'), + [0xfe] = new TextCmdModel('マ'), + [0xff] = new TextCmdModel('ミ'), + }; + + public List Decode(byte[] data) => + new BaseMessageDecoder(_table, data).Decode(decoder => + { + if (decoder.IsEof(1)) + return false; + + var ch = decoder.Peek(0); + var parameter = decoder.Peek(1); + decoder.WrapTable(ref ch, ref parameter); + + switch (ch) + { + case 0x1d: + switch (parameter) + { + case 0x1a: + return AppendComplex(decoder, "III"); + case 0x1b: + return AppendComplex(decoder, "VII"); + case 0x1c: + return AppendComplex(decoder, "VIII"); + case 0x1d: + return AppendComplex(decoder, "X"); + } + break; + case 0x1e: + switch (parameter) + { + case 0x50: + return AppendComplex(decoder, "XIII"); + case 0xb6: + return AppendComplex(decoder, "VI"); + case 0xb7: + return AppendComplex(decoder, "IX"); + } + break; + } + + return false; + }); + + private bool AppendComplex(IDecoder decoder, string value) + { + decoder.Next(); + decoder.Next(); + decoder.AppendComplex(value); + return true; + } + } + + internal static class JapaneseEventTable + { + public static readonly char[] _table2 = new char[0x100] + { + 'ム', 'メ', 'モ', 'ヤ', 'ユ', 'ヨ', 'ラ', + 'リ', 'ル', 'レ', 'ロ', 'ワ', 'ヲ', 'ン', 'ガ', 'ギ', 'グ', 'ゲ', 'ゴ', 'ザ', 'ジ', 'ズ', 'ゼ', 'ゾ', 'ダ', 'ヂ', 'ヅ', 'デ', + 'ド', 'バ', 'ビ', 'ブ', 'ベ', 'ボ', 'ヴ', 'パ', 'ピ', 'プ', 'ペ', 'ポ', 'ァ', 'ィ', 'ゥ', 'ェ', 'ォ', 'ャ', 'ュ', 'ョ', 'ッ', + '端', '子', '接', '続', '正', '常', '発', '生', '使', '用', '専', '付', '属', '取', '扱', '説', '明', '書', '指', '示', '従', + '修', '復', '下', '空', '容', '量', '不', '足', '以', '上', '必', '要', '開', '始', '本', '魔', '石', '晶', '結', '大', '紋', + '盾', '凍', '透', '燃', '水', '気', '炎', '士', '守', '証', '吹', '闘', '力', '木', '人', '飲', '過', '丸', '騎', '去', '魚', + '剣', '荒', '氏', '杖', '束', '太', '鳥', '導', '布', '風', '満', '約', '源', '出', '実', '海', '思', '王', '自', '名', '喚', + '召', '地', '家', '火', '森', '皆', '許', '恐', '古', '轟', '魂', '臭', '章', '雲', '雪', '然', '達', '嘆', '潰', '瓜', '伝', + '怒', '悲', '怖', '鳴', '免', '雷', '林', '様', '巻', '片', '翼', '天', '則', '四', '掲', '板', '登', '孫', '⬛', '⬛', '⬛', + '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', + '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', + + //evt1-2 + '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', + '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', '⬛', + }; + + public static readonly char[] _table3 = new char[0x100] + { + '⬛', '誠', '納', + '泡', '程', '析', '遮', '戒', '井', '及', '模', '算', '霧', '熟', '#', '鈍', '賭', '欺', '鹿', '式', '炸', '裂', '索', '詮', + '眩', '罠', '千', '塗', '羽', '柵', '緊', '粗', '何', '俺', '行', '世', '界', '紀', '事', '前', '符', '来', '見', '一', '絡', + '分', '寂', '心', '賃', '言', '物', '知', '外', '君', '私', '宛', '今', '男', '島', '老', '緒', '幕', '処', '菓', '場', '鎖', + '食', '夢', '女', '賞', '所', '者', '時', '消', '探', '当', '無', '儀', '話', '鍵', '捜', '中', '目', '公', '声', '謎', '間', + '為', '鍵', '密', '闇', '掌', '僕', '留', '句', '般', '誰', '聞', '連', '夫', '扉', '統', '顔', '丈', '少', '我', '他', '立', + '合', '助', '対', '刀', '侮', '辱', '秘', '通', '頼', '冒', '帰', '刑', '夜', '絶', '船', '即', '方', '込', '全', '良', '忘', + '凱', '追', '旅', '起', '険', '供', '抜', '遠', '最', '感', '役', '各', '入', '旋', '遂', '日', '欠', '堅', '主', '会', '向', + '年', '早', '別', '褒', '宝', '変', '度', '後', '星', '授', '矢', '配', '現', '覚', '選', '急', '二', '居', '座', '願', '勝', + '怪', '漁', '鼻', '影', '違', '離', '遅', '訣', '繋', '視', '勇', '笑', '奪', '馳', '々', '切', '厄', '父', '犬', '白', '跳', + '祝', '仮', '強', '押', '仲', '面', '毛', '回', '倒', '拒', '持', '画', '近', '戻', '望', '負', '傷', '刀', '拐', '優', '内', + '赦', '秒', '数', '敵', '槍', '珍', '姿', '歩', '左', '英', '雄', '破', '求', '鷹', '周', '蹴', '費', '衝', '狙', '経', '験', + '値', '便', '表', '歳', '元', '災', '先', '宙', '残', '閉', '移', '動', '走', '眠', '与', '敢', '壊', '臆', '病', '犠', '牲', + '滅', + + }; + + public static readonly char[] _table4 = new char[0x100] + { + '竜', '床', '落', '思', '踏', '特', '加', '停', '応', '化', '右', '死', '襲', '由', '進', '滑', '陽', '頭', '済', '限', + '昼', '五', '楽', '道', '昇', '朝', '照', '確', '甲', '更', '辿', '着', '断', '途', '光', '身', '番', '武', '器', '考', '傑', + '性', '意', '味', '同', '景', '色', '長', '待', '彼', '悪', '穴', '飛', '友', '集', '植', '逃', '雅', '料', '街', '幸', '危', + '決', '房', '記', '判', '掃', '部', '備', '完', '隠', '試', '遊', '姫', '形', '撫', '規', '材', '成', '置', '尾', '計', '作', + '準', '卵', '仕', '命', '真', '音', '宮', '裁', '娘', '聴', '嘘', '殿', '憶', '信', '城', '奴', '福', '返', '己', '拠', '戦', + '冗', '談', '康', '答', '弱', '黙', '呑', '欲', '理', '調', '犯', '予', '止', '博', '件', '解', '削', '舎', '渡', '深', '策', + '屈', '装', '努', '挽', '捕', '失', '刻', '例', '息', '航', '敗', '得', '訳', '放', '矛', '告', '罪', '次', '参', '機', '巣', + + //evt2-1 + '金', '情', '令', '貸', '突', '円', '妙', '録', '笛', '境', '田', '秀', '根', '相', '終', '広', '乗', '駄', '的', '宇', '邪', + '冷', '投', '呼', '葉', '暴', '百', '黄', '新', '町', '喰', '捨', '避', '妃', '安', '頃', '枚', '尻', '没', '嵐', '季', '節', + '困', '悔', '汽', '暗', '排', '体', '状', '況', '流', '条', '希', '店', '被', '再', '第', '僧', '練', '習', '末', '契', '果', + '可', '族', '滝', '反', '組', '多', '協', '支', '念', '了', '誘', '卒', '業', '泳', '嬢', '灯', '賊', '張', '嫌', '員', '隊', + '争', '服', '黒', '→', '←', '口', '忙', '映', '写', '砂', '漠', '妖', '精', '粉', '存', '在', '♪', '野', '郎', '降', '想', + '像', '数', '激', '国', '務', + }; + + public static readonly char[] _table5 = new char[0x100] + { + '操', '縦', '洞', '整', '鼓', '室', '屋', '貝', '騒', '問', '題', '簡', '単', '関', '係', '祈', + '辺', '昔', '匹', '母', '礼', '任', '腹', '輩', '侵', '非', '距', '学', '愚', '点', '活', '躍', '臣', '喜', '板', '岩', '茶', + '異', '線', '沈', '迷', '働', '秩', '序', '規', '#', '貴', '送', '静', '初', '六', '払', '客', '薬', '暮', '青', '諸', '舵', + '旗', '廃', '墟', '陰', '奇', '懐', '染', '横', '響', '逆', '苦', '威', '廷', '育', '群', '悟', '奥', '査', '慎', '好', '利', + '有', '住', '平', '和', '壁', '瞬', '難', '干', '渉', '乱', '窟', '窓', '研', '究', '香', '台', 'ヶ', '救', '態', '村', '驚', + '伸', '咲', '繁', '価', '甘', '獲', '案', '誤', '賛', '舞', '迎', '保', '識', '庫', '慣', '冠', '魅', '増', '狐', '握', '班', + '散', '転', '弁', '至', '律', '亡', '万', '油', '等', '席', '興', '局', '位', '図', '宿', '申', '憎', '焼', '惑', '凶', '北', + '謝', '議', '紹', '介', '複', '雑', '才', '虜', '恩', '順', '格', '皮', '質', '雨', '直', '胸', '近', '媒', '路', '未', '吸', + '志', '封', '土', '牢', '獄', '溶', '哀', '届', '徒', '択', '勢', '踊', '祭', '叩', '叱', '厳', '報', '寸', '似', '引', '受', + '囲', '振', '#', '嬉', '背', '曲', '芽', '偶', '借', '休', '伏', '陛', '除', '緑', '換', '舟', '覆', '叶', 'a', '詳', '焦', + '惜', '久', '企', '互', '招', '汚', '差', '塔', '吐', '渦', 'e', '狭', '尽', '構', '固', '紙', '読', 'i', '競', '姉', '検', + '審', '担', '売', '買', '率', 'k', '美', '獣', '兵', 'n', 'o', '冥', '短', '忠', '盗', '赤', '耳', '故', '郷', '刺', '勉', + '印', '功', '鬼', 'r', '蒸', '愛', '婚', '恋', '賢', + }; + + public static readonly char[] _table6 = new char[0x100] + { + '猫', '責', '熱', '若', '市', '歌', '袋', '虫', '裏', '義', '畑', '西', + '囚', '弟', '妻', 's', '善', '禁', '占', '芸', '幽', '霊', '清', '個', 'l', 'p', 'Ⅲ', 'Ⅶ', 'Ⅷ', 'Ⅹ', '高', '工', '敷', + '科', '恵', '痛', '毎', '注', '軽', '橋', '殖', '球', '陣', '打', '崩', '品', '退', '催', '永', '遺', '脱', '疑', '民', '尊', + '敬', '純', '純', '治', '潜', '種', '類', '抑', '制', '幅', '領', '域', '療', '施', '具', '称', '収', '象', '跡', '察', '糧', + + //evt2-2 + '統', '観', '触', '揺', '標', '到', '拐', '超', '測', '弾', '富', '留', '易', '文', '献', '採', '漂', '語', '造', '稼', '改', + '能', '比', '較', '区', '訪', '往', '混', '沌', '底', '原', '墓', '普', '絵', '額', '又', '暇', '縮', '呪', '掛', '慮', '#', + '癒', '階', '鐘', '描', '秋', '冬', '夏', '泊', '東', '展', '戸', '舷', '浮', '毒', '氷', '幻', '胃', '腸', '誕', '椅', '館', + '廊', '堂', '斎', '玉', '械', '砲', '聖', '針', '春', '冬', '南', '山', '川', '谷', '渓', '崖', '岸', 't', '棺', '門', '月', + '丘', '吊', '拷', '倉', '蔵', '浜', '江', '淵', '溝', '庭', '園', '峡', '潮', '段', '柱', '基', 'h', '汝', '楼', '拝', '草', + '竹', '沼', '層', '虚', '噴', '交', '花', '輝', '護', '巧', '師', '首', '術', '飾', '神', '箱', '輪', '腕', '手', '防', '御', + '撃', '攻', '小', '定', '認', '法', '技', '巨', '樹', '効', '系', '運', '半', '字', '鉱', '三', '型', '耐', '速', '設', '低', + '共', 'g', '側', '阻', '両', '級', '殻', '圧', '亜', '劣', '胴', '脚', '独', '射', '偉', '勘', '頂', '戴', '忍', '素', 'b', + '&', '則', '四', '掲', '板', '登', '孫', '締', '憐', '鮮', '歪', '叫', '推', + }; + + public static readonly char[] _table7 = new char[0x100] + { + '旧', '臨', '奈', '摩', 'y', '細', '肉', '因', + '財', '疲', '婆', '省', '寒', '沢', '商', '却', '派', '盛', '泥', '棄', '棒', '代', '晩', '枯', '期', '譲', '晴', '卑', '越', + '縁', '権', '極', '磨', '替', '宣', '歓', '績', '繰', '栄', '淑', '幾', '杯', '紳', '候', '壁', '杭', '補', '懲', '酬', '勤', + '怯', '余', '労', '匂', '罰', '糸', '辛', '棟', '課', '荷', '頑', '恥', '酷', '随', '醜', '詞', '償', '棒', '隣', '励', '倍', + '充', '#', '雰', '涙', '脅', '泣', '泥', '党', '洪', '_', '討', '伐', '皇', '帝', '殺', '編', '窮', '恨', '腰', '飯', '貨', + '港', '軍', '号', '血', '掟', '浴', '範', '謹', '寄', '豪', '詰', '慢', '損', '史', '略', '抱', '遭', '慈', '際', '誉', '縄', + '銘', '肝', '並', '殴', '利', '誇', '謁', '憩', '祖', '官', '都', '司', '駆', '柄', '挑', '偽', '吉', '堤', '建', '銅', '車', + '贈', '唯', '資', '預', '委', '埋', '督', '謀', '穏', '筋', '適', '迫', '殊', '絆', '狼', '割', '砦', '徐', '煙', '肖', '慌', + '訓', '芝', '桟', '灰', '障', '砕', '幼', '製', '鋭', '骨', '馬', '拾', '掘', '温', '微', '歯', '将', '兄', '駅', '忌', '坊', + '慕', '執', '寝', '酒', '管', '華', 'Ⅵ', 'Ⅸ', '狂', '網', '雲', '征', '総', '衆', '冶', '雇', '髪', '燭', '鉄', '監', '団', + '継', '肩', '電', '給', '評', '営', '依', '職', '憧', '麗', '症', '衣', '眼', '揮', '鋼', '瞳', '匠', '貫', '克', '歴', '養', + '織', '礎', '讐', '演', '衛', '狩', '減', '波', '丁', '積', '環', '銃', '警', '龍', '峠', '脈', '宅', '創', '社', '論', '枢', + '否', '列', '包', '奮', '七', '噂', '坂', '貼', '逮', '幕', '帯', '銀', '援', '悩', '凄', '昨', '妬', + }; + + public static readonly char[] _table8 = new char[0x100] + { + '捧', '怠', '裕', '十', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', + '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', + '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', + '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', + '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', + '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', + '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', + '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', + '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', + '*', '*', '*', '*', + }; + } +} diff --git a/OpenKh.Kh2/Messages/Internals/JapaneseEventEncode.cs b/OpenKh.Kh2/Messages/Internals/JapaneseEventEncode.cs index 474b9f0fd..24a507c76 100644 --- a/OpenKh.Kh2/Messages/Internals/JapaneseEventEncode.cs +++ b/OpenKh.Kh2/Messages/Internals/JapaneseEventEncode.cs @@ -1,148 +1,148 @@ -using OpenKh.Common.Exceptions; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; - -namespace OpenKh.Kh2.Messages.Internals -{ - internal class JapaneseEventEncode : IMessageEncode - { - private static readonly Dictionary> _tableCommands = - JapaneseEventDecode._table - .Where(x => x.Value != null && x.Value.Command != MessageCommand.PrintText) - .GroupBy(x => x.Value.Command) - .ToDictionary(x => x.Key, x => x.First()); - - private static readonly Dictionary _tableCharacters = - GenerateCharacterDictionary(); - - private static readonly Dictionary _tableComplex = - JapaneseEventDecode._table - .Where(x => x.Value?.Command == MessageCommand.PrintComplex) - .Select(x => new - { - Key = x.Value.Text, - Value = new byte[] { x.Key } - }) - .Concat(new[] - { - new { Key = "III", Value = new byte[] { 0x1d, 0x1a} }, - new { Key = "VII", Value = new byte[] { 0x1d, 0x1b} }, - new { Key = "VIII", Value = new byte[] { 0x1d, 0x1c } }, - new { Key = "X", Value = new byte[] { 0x1d, 0x1d } }, - new { Key = "XIII", Value = new byte[] { 0x1e, 0x50 } }, - new { Key = "VI", Value = new byte[] { 0x1e, 0xB6 } }, - new { Key = "IX", Value = new byte[] { 0x1e, 0xB7 } }, - }) - .ToDictionary(x => x.Key, x => x.Value); - - private void AppendEncodedMessageCommand(List list, MessageCommandModel messageCommand) - { - if (messageCommand.Command == MessageCommand.PrintText) - AppendEncodedText(list, messageCommand.Text); - else if (messageCommand.Command == MessageCommand.PrintComplex) - AppendEncodedComplex(list, messageCommand.Text); - else if (messageCommand.Command == MessageCommand.Unsupported) - list.AddRange(messageCommand.Data); - else - AppendEncodedCommand(list, messageCommand.Command, messageCommand.Data); - } - - private void AppendEncodedCommand(List list, MessageCommand command, byte[] data) - { - if (!_tableCommands.TryGetValue(command, out var pair)) - throw new ArgumentException($"The command {command} it is not supported by the specified encoding."); - - list.Add(pair.Key); - for (var i = 0; i < pair.Value.Length; i++) - list.Add(data[i]); - } - - private void AppendEncodedText(List list, string text) - { - foreach (var ch in text) - AppendEncodedChar(list, ch); - } - - private void AppendEncodedComplex(List list, string text) - { - if (!_tableComplex.TryGetValue(text, out var data)) - throw new ParseException(text, 0, "Complex text does not exists"); - - list.AddRange(data); - } - - private void AppendEncodedChar(List list, char ch) - { - if (!_tableCharacters.TryGetValue(ch, out var data)) - throw new CharacterNotSupportedException(ch); - - if (data.Item1 != 0) - list.Add(data.Item1); - list.Add(data.Item2); - } - - public byte[] Encode(List messageCommands) - { - var list = new List(100); - foreach (var model in messageCommands) - AppendEncodedMessageCommand(list, model); - - return list.ToArray(); - } - - private static Dictionary GenerateCharacterDictionary() - { - var pairs = GenerateCharacterKeyValuePair(MessageCommand.PrintText) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table2, JapaneseEventTable._table2)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table3, JapaneseEventTable._table3)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table4, JapaneseEventTable._table4)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table5, JapaneseEventTable._table5)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table6, JapaneseEventTable._table6)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table7, JapaneseEventTable._table7)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table8, JapaneseEventTable._table8)); - -#if DEBUG - var stringBuilder = new StringBuilder(); - foreach (var item in pairs - .GroupBy(x => x.Key) - .Where(x => x.Count() > 1)) - { - var ch = item.Key; - var data1 = item.First().Value; - var data2 = item.Skip(1).First().Value; - - stringBuilder.AppendLine($"Character '{ch}' ({data1.Item1:X02} {data1.Item2:X02}) is duplicate (with {data2.Item1:X02} {data2.Item2:X02})."); - } - - Debug.WriteLine(stringBuilder); -#endif - - return pairs - .GroupBy(x => x.Key) - .ToDictionary(x => x.Key, x => x.First().Value); - } - - private static IEnumerable> GenerateCharacterKeyValuePair( - MessageCommand messageCommand) => - JapaneseEventDecode._table - .Where(x => x.Value?.Command == messageCommand) - .Select(x => new KeyValuePair(x.Value.Text[0], (0, x.Key))); - - private static IEnumerable> GenerateCharacterKeyValuePairFromTable( - MessageCommand messageCommand, char[] table) => - JapaneseEventDecode._table - .Where(x => x.Value?.Command == messageCommand) - .Select(x => table.Select((ch, i) => new - { - TableId = x.Key, - Character = ch, - Data = (byte)i - })) - .SelectMany(x => x) - .Where(x => x.Character != '_' && x.Character != '?') - .Select(x => new KeyValuePair(x.Character, (x.TableId, x.Data))); - } -} +using OpenKh.Common.Exceptions; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; + +namespace OpenKh.Kh2.Messages.Internals +{ + internal class JapaneseEventEncode : IMessageEncode + { + private static readonly Dictionary> _tableCommands = + JapaneseEventDecode._table + .Where(x => x.Value != null && x.Value.Command != MessageCommand.PrintText) + .GroupBy(x => x.Value.Command) + .ToDictionary(x => x.Key, x => x.First()); + + private static readonly Dictionary _tableCharacters = + GenerateCharacterDictionary(); + + private static readonly Dictionary _tableComplex = + JapaneseEventDecode._table + .Where(x => x.Value?.Command == MessageCommand.PrintComplex) + .Select(x => new + { + Key = x.Value.Text, + Value = new byte[] { x.Key } + }) + .Concat(new[] + { + new { Key = "III", Value = new byte[] { 0x1d, 0x1a} }, + new { Key = "VII", Value = new byte[] { 0x1d, 0x1b} }, + new { Key = "VIII", Value = new byte[] { 0x1d, 0x1c } }, + new { Key = "X", Value = new byte[] { 0x1d, 0x1d } }, + new { Key = "XIII", Value = new byte[] { 0x1e, 0x50 } }, + new { Key = "VI", Value = new byte[] { 0x1e, 0xB6 } }, + new { Key = "IX", Value = new byte[] { 0x1e, 0xB7 } }, + }) + .ToDictionary(x => x.Key, x => x.Value); + + private void AppendEncodedMessageCommand(List list, MessageCommandModel messageCommand) + { + if (messageCommand.Command == MessageCommand.PrintText) + AppendEncodedText(list, messageCommand.Text); + else if (messageCommand.Command == MessageCommand.PrintComplex) + AppendEncodedComplex(list, messageCommand.Text); + else if (messageCommand.Command == MessageCommand.Unsupported) + list.AddRange(messageCommand.Data); + else + AppendEncodedCommand(list, messageCommand.Command, messageCommand.Data); + } + + private void AppendEncodedCommand(List list, MessageCommand command, byte[] data) + { + if (!_tableCommands.TryGetValue(command, out var pair)) + throw new ArgumentException($"The command {command} it is not supported by the specified encoding."); + + list.Add(pair.Key); + for (var i = 0; i < pair.Value.Length; i++) + list.Add(data[i]); + } + + private void AppendEncodedText(List list, string text) + { + foreach (var ch in text) + AppendEncodedChar(list, ch); + } + + private void AppendEncodedComplex(List list, string text) + { + if (!_tableComplex.TryGetValue(text, out var data)) + throw new ParseException(text, 0, "Complex text does not exists"); + + list.AddRange(data); + } + + private void AppendEncodedChar(List list, char ch) + { + if (!_tableCharacters.TryGetValue(ch, out var data)) + throw new CharacterNotSupportedException(ch); + + if (data.Item1 != 0) + list.Add(data.Item1); + list.Add(data.Item2); + } + + public byte[] Encode(List messageCommands) + { + var list = new List(100); + foreach (var model in messageCommands) + AppendEncodedMessageCommand(list, model); + + return list.ToArray(); + } + + private static Dictionary GenerateCharacterDictionary() + { + var pairs = GenerateCharacterKeyValuePair(MessageCommand.PrintText) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table2, JapaneseEventTable._table2)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table3, JapaneseEventTable._table3)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table4, JapaneseEventTable._table4)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table5, JapaneseEventTable._table5)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table6, JapaneseEventTable._table6)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table7, JapaneseEventTable._table7)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table8, JapaneseEventTable._table8)); + +#if DEBUG + var stringBuilder = new StringBuilder(); + foreach (var item in pairs + .GroupBy(x => x.Key) + .Where(x => x.Count() > 1)) + { + var ch = item.Key; + var data1 = item.First().Value; + var data2 = item.Skip(1).First().Value; + + stringBuilder.AppendLine($"Character '{ch}' ({data1.Item1:X02} {data1.Item2:X02}) is duplicate (with {data2.Item1:X02} {data2.Item2:X02})."); + } + + Debug.WriteLine(stringBuilder); +#endif + + return pairs + .GroupBy(x => x.Key) + .ToDictionary(x => x.Key, x => x.First().Value); + } + + private static IEnumerable> GenerateCharacterKeyValuePair( + MessageCommand messageCommand) => + JapaneseEventDecode._table + .Where(x => x.Value?.Command == messageCommand) + .Select(x => new KeyValuePair(x.Value.Text[0], (0, x.Key))); + + private static IEnumerable> GenerateCharacterKeyValuePairFromTable( + MessageCommand messageCommand, char[] table) => + JapaneseEventDecode._table + .Where(x => x.Value?.Command == messageCommand) + .Select(x => table.Select((ch, i) => new + { + TableId = x.Key, + Character = ch, + Data = (byte)i + })) + .SelectMany(x => x) + .Where(x => x.Character != '_' && x.Character != '?') + .Select(x => new KeyValuePair(x.Character, (x.TableId, x.Data))); + } +} diff --git a/OpenKh.Kh2/Messages/Internals/JapaneseSystemDecode.cs b/OpenKh.Kh2/Messages/Internals/JapaneseSystemDecode.cs index 9c8342fe4..2ba453b61 100644 --- a/OpenKh.Kh2/Messages/Internals/JapaneseSystemDecode.cs +++ b/OpenKh.Kh2/Messages/Internals/JapaneseSystemDecode.cs @@ -1,405 +1,411 @@ -using System.Collections.Generic; - -namespace OpenKh.Kh2.Messages.Internals -{ - internal class JapaneseSystemDecode : IMessageDecode - { - public static readonly Dictionary _table = new Dictionary - { - [0x00] = new SimpleCmdModel(MessageCommand.End), - [0x01] = new TextCmdModel(' '), - [0x02] = new TextCmdModel('\n'), - [0x03] = new SimpleCmdModel(MessageCommand.Reset), - [0x04] = new SingleDataCmdModel(MessageCommand.Theme), - [0x05] = new DataCmdModel(MessageCommand.Unknown05, 6), - [0x06] = new SingleDataCmdModel(MessageCommand.Unknown06), - [0x07] = new DataCmdModel(MessageCommand.Color, 4), - [0x08] = new DataCmdModel(MessageCommand.Unknown08, 3), - [0x09] = new SingleDataCmdModel(MessageCommand.PrintIcon), - [0x0a] = new SingleDataCmdModel(MessageCommand.TextScale), - [0x0b] = new SingleDataCmdModel(MessageCommand.TextWidth), - [0x0c] = new SingleDataCmdModel(MessageCommand.LineSpacing), - [0x0d] = new SimpleCmdModel(MessageCommand.Unknown0d), - [0x0e] = new SingleDataCmdModel(MessageCommand.Unknown0e), - [0x0f] = new DataCmdModel(MessageCommand.Unknown0f, 5), - [0x10] = new SimpleCmdModel(MessageCommand.Clear), - [0x11] = new DataCmdModel(MessageCommand.Position, 4), - [0x12] = new DataCmdModel(MessageCommand.Unknown12, 2), - [0x13] = new DataCmdModel(MessageCommand.Unknown13, 4), - [0x14] = new DataCmdModel(MessageCommand.Delay, 2), - [0x15] = new DataCmdModel(MessageCommand.CharDelay, 2), - [0x16] = new SingleDataCmdModel(MessageCommand.Unknown16), - [0x17] = null, - [0x18] = new DataCmdModel(MessageCommand.Unknown18, 2), - [0x19] = new TableCmdModel(MessageCommand.Table2, JapaneseSystemTable._table2), - [0x1a] = new TableCmdModel(MessageCommand.Table3, JapaneseSystemTable._table3), - [0x1b] = new TableCmdModel(MessageCommand.Table4, JapaneseSystemTable._table4), - [0x1c] = new TableCmdModel(MessageCommand.Table5, JapaneseSystemTable._table5), - [0x1d] = new TableCmdModel(MessageCommand.Table6, JapaneseSystemTable._table6), - [0x1e] = new TableCmdModel(MessageCommand.Table7, JapaneseSystemTable._table7), - [0x1f] = new TableCmdModel(MessageCommand.Table8, JapaneseSystemTable._table8), - [0x20] = new TextCmdModel('⬛'), - [0x21] = new TextCmdModel('0'), - [0x22] = new TextCmdModel('1'), - [0x23] = new TextCmdModel('2'), - [0x24] = new TextCmdModel('3'), - [0x25] = new TextCmdModel('4'), - [0x26] = new TextCmdModel('5'), - [0x27] = new TextCmdModel('6'), - [0x28] = new TextCmdModel('7'), - [0x29] = new TextCmdModel('8'), - [0x2a] = new TextCmdModel('9'), - [0x2b] = new TextCmdModel('+'), - [0x2c] = new TextCmdModel('−'), - [0x2d] = new TextCmdModel('ₓ'), - [0x2e] = new TextCmdModel('A'), - [0x2f] = new TextCmdModel('B'), - [0x30] = new TextCmdModel('C'), - [0x31] = new TextCmdModel('D'), - [0x32] = new TextCmdModel('E'), - [0x33] = new TextCmdModel('F'), - [0x34] = new TextCmdModel('G'), - [0x35] = new TextCmdModel('H'), - [0x36] = new TextCmdModel('I'), - [0x37] = new TextCmdModel('J'), - [0x38] = new TextCmdModel('K'), - [0x39] = new TextCmdModel('L'), - [0x3a] = new TextCmdModel('M'), - [0x3b] = new TextCmdModel('N'), - [0x3c] = new TextCmdModel('O'), - [0x3d] = new TextCmdModel('P'), - [0x3e] = new TextCmdModel('Q'), - [0x3f] = new TextCmdModel('R'), - [0x40] = new TextCmdModel('S'), - [0x41] = new TextCmdModel('T'), - [0x42] = new TextCmdModel('U'), - [0x43] = new TextCmdModel('V'), - [0x44] = new TextCmdModel('W'), - [0x45] = new TextCmdModel('X'), - [0x46] = new TextCmdModel('Y'), - [0x47] = new TextCmdModel('Z'), - [0x48] = new TextCmdModel('!'), - [0x49] = new TextCmdModel('?'), - [0x4a] = new TextCmdModel('%'), - [0x4b] = new TextCmdModel('/'), - [0x4c] = new TextCmdModel('※'), - [0x4d] = new TextCmdModel('、'), - [0x4e] = new TextCmdModel('。'), - [0x4f] = new TextCmdModel('.'), - [0x50] = new TextCmdModel(','), - [0x51] = new TextCmdModel('·'), - [0x52] = new TextCmdModel(':'), - [0x53] = new TextCmdModel('…'), - [0x54] = new TextCmdModel("-"), - [0x55] = new TextCmdModel('ー'), - [0x56] = new TextCmdModel('〜'), - [0x57] = new TextCmdModel("'"), - [0x58] = new TextCmdModel("‟"), - [0x59] = new TextCmdModel("„"), - [0x5a] = new TextCmdModel('('), - [0x5b] = new TextCmdModel(')'), - [0x5c] = new TextCmdModel('「'), - [0x5d] = new TextCmdModel('」'), - [0x5e] = new TextCmdModel('『'), - [0x5f] = new TextCmdModel('』'), - [0x60] = new TextCmdModel('“'), - [0x61] = new TextCmdModel('”'), - [0x62] = new TextCmdModel('['), - [0x63] = new TextCmdModel(']'), - [0x64] = new TextCmdModel('<'), - [0x65] = new TextCmdModel('>'), - [0x66] = new TextCmdModel('-'), - [0x67] = new TextCmdModel("–"), - [0x68] = new TextCmdModel('⤷'), // Used only in EVT - [0x69] = new TextCmdModel('⇾'), // Used only in EVT - [0x6a] = new TextCmdModel('⇽'), // Used only in EVT - [0x6b] = new TextCmdModel('♩'), - [0x6c] = new TextCmdModel("全"), - [0x6d] = new TextCmdModel("合"), - [0x6e] = new TextCmdModel("成"), - [0x6f] = new TextCmdModel("半"), - [0x70] = new TextCmdModel('◯'), - [0x71] = new TextCmdModel('✕'), - [0x72] = new TextCmdModel('△'), - [0x73] = new TextCmdModel('☐'), - [0x74] = new TextCmdModel('▴'), - [0x75] = new TextCmdModel('▾'), - [0x76] = new TextCmdModel('▸'), - [0x77] = new TextCmdModel('◂'), - [0x78] = null, - [0x79] = null, - [0x7a] = null, - [0x7b] = null, - [0x7c] = null, - [0x7d] = null, - [0x7e] = null, - [0x7f] = null, - [0x80] = null, - [0x81] = null, - [0x82] = new TextCmdModel('⭑'), - [0x83] = new TextCmdModel('⭒'), - [0x84] = new TextCmdModel("III"), - [0x85] = new TextCmdModel("VII"), - [0x86] = new TextCmdModel("VIII"), - [0x87] = new TextCmdModel("X"), - [0x88] = new TextCmdModel("(R)"), - [0x89] = new TextCmdModel("o"), - [0x8a] = new TextCmdModel("n"), - [0x8b] = new TextCmdModel("r"), - [0x8c] = new UnsupportedCmdModel(0x8c), - [0x8d] = new TextCmdModel('前'), - [0x8e] = new TextCmdModel('選'), - [0x8f] = new TextCmdModel('一'), - [0x90] = new TextCmdModel('あ'), - [0x91] = new TextCmdModel('い'), - [0x92] = new TextCmdModel('う'), - [0x93] = new TextCmdModel('え'), - [0x94] = new TextCmdModel('お'), - [0x95] = new TextCmdModel('か'), - [0x96] = new TextCmdModel('き'), - [0x97] = new TextCmdModel('く'), - [0x98] = new TextCmdModel('け'), - [0x99] = new TextCmdModel('こ'), - [0x9a] = new TextCmdModel('さ'), - [0x9b] = new TextCmdModel('し'), - [0x9c] = new TextCmdModel('す'), - [0x9d] = new TextCmdModel('せ'), - [0x9e] = new TextCmdModel('そ'), - [0x9f] = new TextCmdModel('た'), - [0xa0] = new TextCmdModel('ち'), - [0xa1] = new TextCmdModel('つ'), - [0xa2] = new TextCmdModel('て'), - [0xa3] = new TextCmdModel('と'), - [0xa4] = new TextCmdModel('な'), - [0xa5] = new TextCmdModel('に'), - [0xa6] = new TextCmdModel('ぬ'), - [0xa7] = new TextCmdModel('ね'), - [0xa8] = new TextCmdModel('の'), - [0xa9] = new TextCmdModel('は'), - [0xaa] = new TextCmdModel('ひ'), - [0xab] = new TextCmdModel('ふ'), - [0xac] = new TextCmdModel('へ'), - [0xad] = new TextCmdModel('ほ'), - [0xae] = new TextCmdModel('ま'), - [0xaf] = new TextCmdModel('み'), - [0xb0] = new TextCmdModel('む'), - [0xb1] = new TextCmdModel('め'), - [0xb2] = new TextCmdModel('も'), - [0xb3] = new TextCmdModel('や'), - [0xb4] = new TextCmdModel('ゆ'), - [0xb5] = new TextCmdModel('よ'), - [0xb6] = new TextCmdModel('ら'), - [0xb7] = new TextCmdModel('り'), - [0xb8] = new TextCmdModel('る'), - [0xb9] = new TextCmdModel('れ'), - [0xba] = new TextCmdModel('ろ'), - [0xbb] = new TextCmdModel('わ'), - [0xbc] = new TextCmdModel('を'), - [0xbd] = new TextCmdModel('ん'), - [0xbe] = new TextCmdModel('が'), - [0xbf] = new TextCmdModel('ぎ'), - [0xc0] = new TextCmdModel('ぐ'), - [0xc1] = new TextCmdModel('げ'), - [0xc2] = new TextCmdModel('ご'), - [0xc3] = new TextCmdModel('ざ'), - [0xc4] = new TextCmdModel('じ'), - [0xc5] = new TextCmdModel('ず'), - [0xc6] = new TextCmdModel('ぜ'), - [0xc7] = new TextCmdModel('ぞ'), - [0xc8] = new TextCmdModel('だ'), - [0xc9] = new TextCmdModel('ぢ'), - [0xca] = new TextCmdModel('づ'), - [0xcb] = new TextCmdModel('で'), - [0xcc] = new TextCmdModel('ど'), - [0xcd] = new TextCmdModel('ば'), - [0xce] = new TextCmdModel('び'), - [0xcf] = new TextCmdModel('ぶ'), - [0xd0] = new TextCmdModel('べ'), - [0xd1] = new TextCmdModel('ぼ'), - [0xd2] = new TextCmdModel('ぱ'), - [0xd3] = new TextCmdModel('ぴ'), - [0xd4] = new TextCmdModel('ぷ'), - [0xd5] = new TextCmdModel('ぺ'), - [0xd6] = new TextCmdModel('ぽ'), - [0xd7] = new TextCmdModel('ぁ'), - [0xd8] = new TextCmdModel('ぃ'), - [0xd9] = new TextCmdModel('ぅ'), - [0xda] = new TextCmdModel('ぇ'), - [0xdb] = new TextCmdModel('ぉ'), - [0xdc] = new TextCmdModel('ゃ'), - [0xdd] = new TextCmdModel('ゅ'), - [0xde] = new TextCmdModel('ょ'), - [0xdf] = new TextCmdModel('っ'), - [0xe0] = new TextCmdModel('ア'), - [0xe1] = new TextCmdModel('イ'), - [0xe2] = new TextCmdModel('ウ'), - [0xe3] = new TextCmdModel('エ'), - [0xe4] = new TextCmdModel('オ'), - [0xe5] = new TextCmdModel('カ'), - [0xe6] = new TextCmdModel('キ'), - [0xe7] = new TextCmdModel('ク'), - [0xe8] = new TextCmdModel('ケ'), - [0xe9] = new TextCmdModel('コ'), - [0xea] = new TextCmdModel('サ'), - [0xeb] = new TextCmdModel('シ'), - [0xec] = new TextCmdModel('ス'), - [0xed] = new TextCmdModel('セ'), - [0xee] = new TextCmdModel('ソ'), - [0xef] = new TextCmdModel('タ'), - [0xf0] = new TextCmdModel('チ'), - [0xf1] = new TextCmdModel('ツ'), - [0xf2] = new TextCmdModel('テ'), - [0xf3] = new TextCmdModel('ト'), - [0xf4] = new TextCmdModel('ナ'), - [0xf5] = new TextCmdModel('ニ'), - [0xf6] = new TextCmdModel('ヌ'), - [0xf7] = new TextCmdModel('ネ'), - [0xf8] = new TextCmdModel('ノ'), - [0xf9] = new TextCmdModel('ハ'), - [0xfa] = new TextCmdModel('ヒ'), - [0xfb] = new TextCmdModel('フ'), - [0xfc] = new TextCmdModel('ヘ'), - [0xfd] = new TextCmdModel('ホ'), - [0xfe] = new TextCmdModel('マ'), - [0xff] = new TextCmdModel('ミ'), - }; - - public List Decode(byte[] data) => - new BaseMessageDecoder(_table, data).Decode(decoder => - { - if (decoder.IsEof(1)) - return false; - - var ch = decoder.Peek(0); - var parameter = decoder.Peek(1); - decoder.WrapTable(ref ch, ref parameter); - - switch (ch) - { - case 0x19: - if (parameter == 0xb2) - return AppendComplex(decoder, "XIII"); - break; - case 0x1b: - switch (parameter) - { - case 0x54: return AppendComplex(decoder, "I"); - case 0x55: return AppendComplex(decoder, "II"); - case 0x56: return AppendComplex(decoder, "IV"); - case 0x57: return AppendComplex(decoder, "V"); - case 0x58: return AppendComplex(decoder, "VI"); - case 0x59: return AppendComplex(decoder, "IX"); - } - break; - } - - return false; - }); - - private bool AppendComplex(IDecoder decoder, string value) - { - decoder.Next(); - decoder.Next(); - decoder.AppendComplex(value); - return true; - } - } - - internal static class JapaneseSystemTable - { - public static readonly char[] _table2 = new char[0x100] - { - 'ム', 'メ', 'モ', 'ヤ', 'ユ', 'ヨ', 'ラ', 'リ', 'ル', 'レ', 'ロ', 'ワ', 'ヲ', 'ン', 'ガ', 'ギ', 'グ', 'ゲ', 'ゴ', 'ザ', 'ジ', 'ズ', 'ゼ', 'ゾ', 'ダ', 'ヂ', 'ヅ', 'デ', - 'ド', 'バ', 'ビ', 'ブ', 'ベ', 'ボ', 'ヴ', 'パ', 'ピ', 'プ', 'ペ', 'ポ', 'ァ', 'ィ', 'ゥ', 'ェ', 'ォ', 'ャ', 'ュ', 'ョ', 'ッ', '端', '子', '接', '続', '正', '常', '発', - '生', '使', '用', '専', '付', '属', '取', '扱', '説', '明', '書', '指', '示', '従', '修', '復', '下', '空', '容', '量', '不', '足', '以', '上', '必', '要', '開', '始', - '本', '魔', '石', '晶', '結', '大', '紋', '盾', '凍', '透', '燃', '水', '気', '炎', '士', '守', '証', '吹', '闘', '力', '木', '人', '飲', '過', '丸', '騎', '去', '魚', - '剣', '荒', '氏', '杖', '束', '太', '鳥', '導', '布', '風', '満', '約', '源', '出', '実', '海', '思', '王', '自', '名', '喚', '召', '地', '家', '火', '森', '皆', '許', - '恐', '古', '轟', '魂', '臭', '章', '雲', '雪', '然', '達', '嘆', '潰', '瓜', '伝', '怒', '悲', '怖', '鳴', '免', '雷', '林', '様', '巻', '片', '翼', '天', '?', '?', - - /*sys1-2 _*/ - '亡', '者', '囚', '封', '印', '迷', '東', '棟', '西', '冥', '_', '?', '?', '?', '事', '典', '匹', '貓', '姬', '規', '失', '敗', '神', '箱', '兵', '教', '跡', '率', - '組', '造', '図', '情', '多', '報', '分', '由', '立', '具', '星', '質', '流', '替', '役', '優', '雄', '連', '判', '斷', '共', '有', '工', '改', '考', '強', '好', '消', - '求', '捨', '收', '順', '助', '身', '轉', '同', '渡', '錄', '的', '直', '運', '英', '距', '驚', '惠', '系', '効', '鉱', '三', '止', '字', '狀', '心', '振', '絕', '線', - '像', '打', '態', '彈', - }; - - public static readonly char[] _table3 = new char[0x100] - { - '珍', '投', '当', '內', '配', '白', '半', '費', '文', '枚', '在', '通', '特', '択', '動', '備', '武', '類', '覽', '技', '陸', '押', '換', '起', '经', '裝', '種', '殊', - '作', '初', '主', '視', '員', '引', '泳', '活', '寄', '材', '全', '增', '速', '短', '倒', '落', '料', '形', '中', '表', '間', '敵', '來', '丘', '見', '橋', '黑', '原', - '船', '長', '道', '秘', '闇', '数', '变', '化', '時', '高', '型', '段', '食', '登', '場', '賊', '入', '飛', '少', '最', '行', '回', '持', '成', '合', '手', '防', '御', - '擊', '攻', '法', '耐', '久', '一', '度', '低', '超', '操', '縦', '性', '調', '整', '遠', '複', '機', '能', '追', '加','前', '方', '向', '部', '小', '定', '屋', '居', - '隱', '奧', '遺', '暗', '安', '淵', '園', '胃', '江', '館', '犬', '客', '験', '穴', '会', '口', '窟', '広', '宮', '庫', '峽', '研', '究', '棺', '鬼', '計', '巻', '虛', - '基', '果', '球', '界', '交', '休', '街', '議', '群', '岩', '月', '拷', '逆', '獄', '後', '所', '宿', '赤', '私', '室', '斎', '層', '草', '砂', '深', '倉', '集', '敷', - '世', '息', '想', '女', '城', '蔵', '乗', '島', '竹', '滝', '通', '置', '底', '沈', '庭', '潮', '吊', '袋', '腸', '扉', '堂', '洞', '殿', '台', '沼', '難', '浜', '辺', - '壁', '宝', '破', '腹', '氷', '拝', '噴', '崩', '番', '漠', '物', '墓', '密', '門', '默', '問', '遊', '谷', '離', '路', '裏', '綠', '廊', '楼', '牢', '礼', '巨', '樹', - '意', '俺', '降', '壊', '今', '急', '光', '怪', '凶', '舵', '近', '確', '旗', '減', '画', '昇', '青', '左', '色', '捜', '先', '勝', '選', '受', '次', '丈', '点', '注', - '他', '知', '体', '駄', - }; - - public static readonly char[] _table4 = new char[0x100] - { - '何', '吞', '返', '夫', '僕', '暴', '面', '目', '無', '待', '戾', '認', '電', '切', '完', '了', '保', '既', '可', '込', - '決', '新', '差', '商', '設', '削', '除', '獣', '值', '抜', '仲', '品', '未', '読', '野', '右', '素', '個', '移', '位', '憶', '器', '更', '記', '期', '観', '級', '現', - - /*sys2-1*/ - '外', '送', '梱', '包', '謁', '礎', '格', '納', '盤', '信', '枢', '港', '号', '死', '山', '薬', '砦', '市', '店', '護', '住', '処', '廃', '墟', '試', '練', '埋', '営', - '関', '村', '尾', '根', '頂', '場', '玉', '座', '_', '_', '_', '_', '_', '_', 'α', 'β', 'γ', '二', '四', '五', '六', '七', '几', '九', '零', '壱', '弐', '參', - '百', '式', '號', '駅', '宅', '町', '車', '塔', '階', '絡', '狭', '象', '存', '渓', '建', '製', '施', '忘', '却', '桟', '停', '泊', '摩', '災', '床', '滅', '危', '波', - '岸', '話', '再', '彼', '姿', '聞', '言', '戦', '隊', '着', '国', '進', '訪', '服', '救', '残', '帰', '元', '呪', '幻', '得', '逃', '解', '貸', '金', '囲', '探', '脱', - '協', '男', '到', '帝', '都', '相', '頼', '盗', '影', '代', '宰', '緒', '皇', '血', '妃', '任', '放', '誰', '財', '務', '捕', '声', '終', '越', '閉', '聾', '平', '杯', - '窓', '騒', '音', '償', 'ヶ', '準', '葉', '告', '父', '喜', '習', '々', '犯', '勢', '吉', '違', '真', '胸', '険', '催', '途', '日', '届', '友', '狙', '和', '突', '奪', - '軍', '棒', '娘', '抱', '景', '異', '恋', '応', '映', '略', '支', '顔', '命', '別', '呼', '散', '叩', '感', '提', '揺', '荷', '挑', '駆', '談', '銅', '味', '慣', '謎', - '笑', '博', '輝', '畑', '宣', '況', '泥', '早', '演', '悩', '川', '弱', - }; - - public static readonly char[] _table5 = new char[0x100] - { - '係', '資', '張', '希', '非', '如', '迎', '軽', '暮', '派', '旅', '責', '督', '退', '縮', '頭', - '謝', '貸', '曲', '偉', '並', '借', '継', '絵', '伏', '治', '功', '与', '楽', '望', '殺', '親', '美', '勇', '染', '眠', '走', '契', '隙', '拠', '討', '拒', '族', '歌', - '良', '夢', '預', '覚', '価', '予', '争', '惑', '儀', '贈', '為', '崖', '周', '板', '穏', '割', '術', '誕', '伐', '疲', '渉', '狼', '互', '煙', '夜', '因', '爆', '嵐', - '漂', '固', '砲', '側', '看', '抑', '絆', '末', '紡', '誘', '歪', '貫', '柱', '黄', '昏', '旋', '律', '辿', '混', '沌', '創', '祭', '壇', '精', '妖', '買', '吸', '克', - '歴', '歩', '北', '対', '司', '夏', '静', '帯', '師', '反', '総', '限', '売', '利', '秒', '写', '響', '委', '両', '角', '列', '菓', '補', '販', '各', '桜', '虹', '紫', - '年', '禁', '灰', '超', '矢', '触', '重', '十', - '充', '仮', '霊', '幽', '拾', '符', '冒', '第', '件', '背', '綱', '負', '花', '匠', '標', '頑', '射', '紙', '柄', '制', - '峠', '困', '範', '陣', '君', '倍', '奏', '躍', '昨', '簡', '網', '願', '奇', '便', '浮', '郊', '単', '侵', '域', '叫', '詳', '索', '検', '渦', '幕', '官', '項', '念', - - /*sys2-2*/ - '還', '題', '没', '描', '令', '→', '←', '♪', '艦', '聖', '竜', '龍', '忍', '苦', '評', '仕', '賢', '距', '&', '採', '鉱', '坑', '積', '夕', '錬', '斬', '霸', '一', - '編', '語', '条', '理', '拡', '央', '冠', '極', '烈', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', - 't', 'u', 'v', 'w', 'x', 'y', 'z', '欲', '兜', '限', '臨', '威', '乱', '故', '郷', '悪' - }; - - public static readonly char[] _table6 = new char[0x100] - { - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - }; - - public static readonly char[] _table7 = new char[0x40] - { - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', - }; - - public static readonly char[] _table8 = new char[0] - { - }; - } -} +using System.Collections.Generic; + +namespace OpenKh.Kh2.Messages.Internals +{ + internal class JapaneseSystemDecode : IMessageDecode + { + public static readonly Dictionary _table = new Dictionary + { + [0x00] = new SimpleCmdModel(MessageCommand.End), + [0x01] = new TextCmdModel(' '), + [0x02] = new TextCmdModel('\n'), + [0x03] = new SimpleCmdModel(MessageCommand.Reset), + [0x04] = new SingleDataCmdModel(MessageCommand.Theme), + [0x05] = new DataCmdModel(MessageCommand.Unknown05, 6), + [0x06] = new SingleDataCmdModel(MessageCommand.Unknown06), + [0x07] = new DataCmdModel(MessageCommand.Color, 4), + [0x08] = new DataCmdModel(MessageCommand.Unknown08, 3), + [0x09] = new SingleDataCmdModel(MessageCommand.PrintIcon), + [0x0a] = new SingleDataCmdModel(MessageCommand.TextScale), + [0x0b] = new SingleDataCmdModel(MessageCommand.TextWidth), + [0x0c] = new SingleDataCmdModel(MessageCommand.LineSpacing), + [0x0d] = new SimpleCmdModel(MessageCommand.Unknown0d), + [0x0e] = new SingleDataCmdModel(MessageCommand.Unknown0e), + [0x0f] = new DataCmdModel(MessageCommand.Unknown0f, 5), + [0x10] = new SimpleCmdModel(MessageCommand.Clear), + [0x11] = new DataCmdModel(MessageCommand.Position, 4), + [0x12] = new DataCmdModel(MessageCommand.Unknown12, 2), + [0x13] = new DataCmdModel(MessageCommand.Unknown13, 4), + [0x14] = new DataCmdModel(MessageCommand.Delay, 2), + [0x15] = new DataCmdModel(MessageCommand.CharDelay, 2), + [0x16] = new SingleDataCmdModel(MessageCommand.Unknown16), + [0x17] = null, + [0x18] = new DataCmdModel(MessageCommand.Unknown18, 2), + [0x19] = new TableCmdModel(MessageCommand.Table2, JapaneseSystemTable._table2), + [0x1a] = new TableCmdModel(MessageCommand.Table3, JapaneseSystemTable._table3), + [0x1b] = new TableCmdModel(MessageCommand.Table4, JapaneseSystemTable._table4), + [0x1c] = new TableCmdModel(MessageCommand.Table5, JapaneseSystemTable._table5), + [0x1d] = new TableCmdModel(MessageCommand.Table6, JapaneseSystemTable._table6), + [0x1e] = new TableCmdModel(MessageCommand.Table7, JapaneseSystemTable._table7), + [0x1f] = new TableCmdModel(MessageCommand.Table8, JapaneseSystemTable._table8), + [0x20] = new TextCmdModel('⬛'), + [0x21] = new TextCmdModel('0'), + [0x22] = new TextCmdModel('1'), + [0x23] = new TextCmdModel('2'), + [0x24] = new TextCmdModel('3'), + [0x25] = new TextCmdModel('4'), + [0x26] = new TextCmdModel('5'), + [0x27] = new TextCmdModel('6'), + [0x28] = new TextCmdModel('7'), + [0x29] = new TextCmdModel('8'), + [0x2a] = new TextCmdModel('9'), + [0x2b] = new TextCmdModel('+'), + [0x2c] = new TextCmdModel('−'), + [0x2d] = new TextCmdModel('ₓ'), + [0x2e] = new TextCmdModel('A'), + [0x2f] = new TextCmdModel('B'), + [0x30] = new TextCmdModel('C'), + [0x31] = new TextCmdModel('D'), + [0x32] = new TextCmdModel('E'), + [0x33] = new TextCmdModel('F'), + [0x34] = new TextCmdModel('G'), + [0x35] = new TextCmdModel('H'), + [0x36] = new TextCmdModel('I'), + [0x37] = new TextCmdModel('J'), + [0x38] = new TextCmdModel('K'), + [0x39] = new TextCmdModel('L'), + [0x3a] = new TextCmdModel('M'), + [0x3b] = new TextCmdModel('N'), + [0x3c] = new TextCmdModel('O'), + [0x3d] = new TextCmdModel('P'), + [0x3e] = new TextCmdModel('Q'), + [0x3f] = new TextCmdModel('R'), + [0x40] = new TextCmdModel('S'), + [0x41] = new TextCmdModel('T'), + [0x42] = new TextCmdModel('U'), + [0x43] = new TextCmdModel('V'), + [0x44] = new TextCmdModel('W'), + [0x45] = new TextCmdModel('X'), + [0x46] = new TextCmdModel('Y'), + [0x47] = new TextCmdModel('Z'), + [0x48] = new TextCmdModel('!'), + [0x49] = new TextCmdModel('?'), + [0x4a] = new TextCmdModel('%'), + [0x4b] = new TextCmdModel('/'), + [0x4c] = new TextCmdModel('※'), + [0x4d] = new TextCmdModel('、'), + [0x4e] = new TextCmdModel('。'), + [0x4f] = new TextCmdModel('.'), + [0x50] = new TextCmdModel(','), + [0x51] = new TextCmdModel('·'), + [0x52] = new TextCmdModel(':'), + [0x53] = new TextCmdModel('…'), + [0x54] = new TextCmdModel("-"), + [0x55] = new TextCmdModel('ー'), + [0x56] = new TextCmdModel('〜'), + [0x57] = new TextCmdModel("'"), + [0x58] = new TextCmdModel("‟"), + [0x59] = new TextCmdModel("„"), + [0x5a] = new TextCmdModel('('), + [0x5b] = new TextCmdModel(')'), + [0x5c] = new TextCmdModel('「'), + [0x5d] = new TextCmdModel('」'), + [0x5e] = new TextCmdModel('『'), + [0x5f] = new TextCmdModel('』'), + [0x60] = new TextCmdModel('“'), + [0x61] = new TextCmdModel('”'), + [0x62] = new TextCmdModel('['), + [0x63] = new TextCmdModel(']'), + [0x64] = new TextCmdModel('<'), + [0x65] = new TextCmdModel('>'), + [0x66] = new TextCmdModel('-'), + [0x67] = new TextCmdModel("–"), + [0x68] = new TextCmdModel('⤷'), // Used only in EVT + [0x69] = new TextCmdModel('⇾'), // Used only in EVT + [0x6a] = new TextCmdModel('⇽'), // Used only in EVT + [0x6b] = new TextCmdModel('♩'), + [0x6c] = new TextCmdModel("全"), + [0x6d] = new TextCmdModel("合"), + [0x6e] = new TextCmdModel("成"), + [0x6f] = new TextCmdModel("半"), + [0x70] = new TextCmdModel('◯'), + [0x71] = new TextCmdModel('✕'), + [0x72] = new TextCmdModel('△'), + [0x73] = new TextCmdModel('☐'), + [0x74] = new TextCmdModel('▴'), + [0x75] = new TextCmdModel('▾'), + [0x76] = new TextCmdModel('▸'), + [0x77] = new TextCmdModel('◂'), + [0x78] = null, + [0x79] = null, + [0x7a] = null, + [0x7b] = null, + [0x7c] = null, + [0x7d] = null, + [0x7e] = null, + [0x7f] = null, + [0x80] = null, + [0x81] = null, + [0x82] = new TextCmdModel('⭑'), + [0x83] = new TextCmdModel('⭒'), + [0x84] = new TextCmdModel("III"), + [0x85] = new TextCmdModel("VII"), + [0x86] = new TextCmdModel("VIII"), + [0x87] = new TextCmdModel("X"), + [0x88] = new TextCmdModel("(R)"), + [0x89] = new TextCmdModel("o"), + [0x8a] = new TextCmdModel("n"), + [0x8b] = new TextCmdModel("r"), + [0x8c] = new UnsupportedCmdModel(0x8c), + [0x8d] = new TextCmdModel('前'), + [0x8e] = new TextCmdModel('選'), + [0x8f] = new TextCmdModel('一'), + [0x90] = new TextCmdModel('あ'), + [0x91] = new TextCmdModel('い'), + [0x92] = new TextCmdModel('う'), + [0x93] = new TextCmdModel('え'), + [0x94] = new TextCmdModel('お'), + [0x95] = new TextCmdModel('か'), + [0x96] = new TextCmdModel('き'), + [0x97] = new TextCmdModel('く'), + [0x98] = new TextCmdModel('け'), + [0x99] = new TextCmdModel('こ'), + [0x9a] = new TextCmdModel('さ'), + [0x9b] = new TextCmdModel('し'), + [0x9c] = new TextCmdModel('す'), + [0x9d] = new TextCmdModel('せ'), + [0x9e] = new TextCmdModel('そ'), + [0x9f] = new TextCmdModel('た'), + [0xa0] = new TextCmdModel('ち'), + [0xa1] = new TextCmdModel('つ'), + [0xa2] = new TextCmdModel('て'), + [0xa3] = new TextCmdModel('と'), + [0xa4] = new TextCmdModel('な'), + [0xa5] = new TextCmdModel('に'), + [0xa6] = new TextCmdModel('ぬ'), + [0xa7] = new TextCmdModel('ね'), + [0xa8] = new TextCmdModel('の'), + [0xa9] = new TextCmdModel('は'), + [0xaa] = new TextCmdModel('ひ'), + [0xab] = new TextCmdModel('ふ'), + [0xac] = new TextCmdModel('へ'), + [0xad] = new TextCmdModel('ほ'), + [0xae] = new TextCmdModel('ま'), + [0xaf] = new TextCmdModel('み'), + [0xb0] = new TextCmdModel('む'), + [0xb1] = new TextCmdModel('め'), + [0xb2] = new TextCmdModel('も'), + [0xb3] = new TextCmdModel('や'), + [0xb4] = new TextCmdModel('ゆ'), + [0xb5] = new TextCmdModel('よ'), + [0xb6] = new TextCmdModel('ら'), + [0xb7] = new TextCmdModel('り'), + [0xb8] = new TextCmdModel('る'), + [0xb9] = new TextCmdModel('れ'), + [0xba] = new TextCmdModel('ろ'), + [0xbb] = new TextCmdModel('わ'), + [0xbc] = new TextCmdModel('を'), + [0xbd] = new TextCmdModel('ん'), + [0xbe] = new TextCmdModel('が'), + [0xbf] = new TextCmdModel('ぎ'), + [0xc0] = new TextCmdModel('ぐ'), + [0xc1] = new TextCmdModel('げ'), + [0xc2] = new TextCmdModel('ご'), + [0xc3] = new TextCmdModel('ざ'), + [0xc4] = new TextCmdModel('じ'), + [0xc5] = new TextCmdModel('ず'), + [0xc6] = new TextCmdModel('ぜ'), + [0xc7] = new TextCmdModel('ぞ'), + [0xc8] = new TextCmdModel('だ'), + [0xc9] = new TextCmdModel('ぢ'), + [0xca] = new TextCmdModel('づ'), + [0xcb] = new TextCmdModel('で'), + [0xcc] = new TextCmdModel('ど'), + [0xcd] = new TextCmdModel('ば'), + [0xce] = new TextCmdModel('び'), + [0xcf] = new TextCmdModel('ぶ'), + [0xd0] = new TextCmdModel('べ'), + [0xd1] = new TextCmdModel('ぼ'), + [0xd2] = new TextCmdModel('ぱ'), + [0xd3] = new TextCmdModel('ぴ'), + [0xd4] = new TextCmdModel('ぷ'), + [0xd5] = new TextCmdModel('ぺ'), + [0xd6] = new TextCmdModel('ぽ'), + [0xd7] = new TextCmdModel('ぁ'), + [0xd8] = new TextCmdModel('ぃ'), + [0xd9] = new TextCmdModel('ぅ'), + [0xda] = new TextCmdModel('ぇ'), + [0xdb] = new TextCmdModel('ぉ'), + [0xdc] = new TextCmdModel('ゃ'), + [0xdd] = new TextCmdModel('ゅ'), + [0xde] = new TextCmdModel('ょ'), + [0xdf] = new TextCmdModel('っ'), + [0xe0] = new TextCmdModel('ア'), + [0xe1] = new TextCmdModel('イ'), + [0xe2] = new TextCmdModel('ウ'), + [0xe3] = new TextCmdModel('エ'), + [0xe4] = new TextCmdModel('オ'), + [0xe5] = new TextCmdModel('カ'), + [0xe6] = new TextCmdModel('キ'), + [0xe7] = new TextCmdModel('ク'), + [0xe8] = new TextCmdModel('ケ'), + [0xe9] = new TextCmdModel('コ'), + [0xea] = new TextCmdModel('サ'), + [0xeb] = new TextCmdModel('シ'), + [0xec] = new TextCmdModel('ス'), + [0xed] = new TextCmdModel('セ'), + [0xee] = new TextCmdModel('ソ'), + [0xef] = new TextCmdModel('タ'), + [0xf0] = new TextCmdModel('チ'), + [0xf1] = new TextCmdModel('ツ'), + [0xf2] = new TextCmdModel('テ'), + [0xf3] = new TextCmdModel('ト'), + [0xf4] = new TextCmdModel('ナ'), + [0xf5] = new TextCmdModel('ニ'), + [0xf6] = new TextCmdModel('ヌ'), + [0xf7] = new TextCmdModel('ネ'), + [0xf8] = new TextCmdModel('ノ'), + [0xf9] = new TextCmdModel('ハ'), + [0xfa] = new TextCmdModel('ヒ'), + [0xfb] = new TextCmdModel('フ'), + [0xfc] = new TextCmdModel('ヘ'), + [0xfd] = new TextCmdModel('ホ'), + [0xfe] = new TextCmdModel('マ'), + [0xff] = new TextCmdModel('ミ'), + }; + + public List Decode(byte[] data) => + new BaseMessageDecoder(_table, data).Decode(decoder => + { + if (decoder.IsEof(1)) + return false; + + var ch = decoder.Peek(0); + var parameter = decoder.Peek(1); + decoder.WrapTable(ref ch, ref parameter); + + switch (ch) + { + case 0x19: + if (parameter == 0xb2) + return AppendComplex(decoder, "XIII"); + break; + case 0x1b: + switch (parameter) + { + case 0x54: + return AppendComplex(decoder, "I"); + case 0x55: + return AppendComplex(decoder, "II"); + case 0x56: + return AppendComplex(decoder, "IV"); + case 0x57: + return AppendComplex(decoder, "V"); + case 0x58: + return AppendComplex(decoder, "VI"); + case 0x59: + return AppendComplex(decoder, "IX"); + } + break; + } + + return false; + }); + + private bool AppendComplex(IDecoder decoder, string value) + { + decoder.Next(); + decoder.Next(); + decoder.AppendComplex(value); + return true; + } + } + + internal static class JapaneseSystemTable + { + public static readonly char[] _table2 = new char[0x100] + { + 'ム', 'メ', 'モ', 'ヤ', 'ユ', 'ヨ', 'ラ', 'リ', 'ル', 'レ', 'ロ', 'ワ', 'ヲ', 'ン', 'ガ', 'ギ', 'グ', 'ゲ', 'ゴ', 'ザ', 'ジ', 'ズ', 'ゼ', 'ゾ', 'ダ', 'ヂ', 'ヅ', 'デ', + 'ド', 'バ', 'ビ', 'ブ', 'ベ', 'ボ', 'ヴ', 'パ', 'ピ', 'プ', 'ペ', 'ポ', 'ァ', 'ィ', 'ゥ', 'ェ', 'ォ', 'ャ', 'ュ', 'ョ', 'ッ', '端', '子', '接', '続', '正', '常', '発', + '生', '使', '用', '専', '付', '属', '取', '扱', '説', '明', '書', '指', '示', '従', '修', '復', '下', '空', '容', '量', '不', '足', '以', '上', '必', '要', '開', '始', + '本', '魔', '石', '晶', '結', '大', '紋', '盾', '凍', '透', '燃', '水', '気', '炎', '士', '守', '証', '吹', '闘', '力', '木', '人', '飲', '過', '丸', '騎', '去', '魚', + '剣', '荒', '氏', '杖', '束', '太', '鳥', '導', '布', '風', '満', '約', '源', '出', '実', '海', '思', '王', '自', '名', '喚', '召', '地', '家', '火', '森', '皆', '許', + '恐', '古', '轟', '魂', '臭', '章', '雲', '雪', '然', '達', '嘆', '潰', '瓜', '伝', '怒', '悲', '怖', '鳴', '免', '雷', '林', '様', '巻', '片', '翼', '天', '?', '?', + + /*sys1-2 _*/ + '亡', '者', '囚', '封', '印', '迷', '東', '棟', '西', '冥', '_', '?', '?', '?', '事', '典', '匹', '貓', '姬', '規', '失', '敗', '神', '箱', '兵', '教', '跡', '率', + '組', '造', '図', '情', '多', '報', '分', '由', '立', '具', '星', '質', '流', '替', '役', '優', '雄', '連', '判', '斷', '共', '有', '工', '改', '考', '強', '好', '消', + '求', '捨', '收', '順', '助', '身', '轉', '同', '渡', '錄', '的', '直', '運', '英', '距', '驚', '惠', '系', '効', '鉱', '三', '止', '字', '狀', '心', '振', '絕', '線', + '像', '打', '態', '彈', + }; + + public static readonly char[] _table3 = new char[0x100] + { + '珍', '投', '当', '內', '配', '白', '半', '費', '文', '枚', '在', '通', '特', '択', '動', '備', '武', '類', '覽', '技', '陸', '押', '換', '起', '经', '裝', '種', '殊', + '作', '初', '主', '視', '員', '引', '泳', '活', '寄', '材', '全', '增', '速', '短', '倒', '落', '料', '形', '中', '表', '間', '敵', '來', '丘', '見', '橋', '黑', '原', + '船', '長', '道', '秘', '闇', '数', '变', '化', '時', '高', '型', '段', '食', '登', '場', '賊', '入', '飛', '少', '最', '行', '回', '持', '成', '合', '手', '防', '御', + '擊', '攻', '法', '耐', '久', '一', '度', '低', '超', '操', '縦', '性', '調', '整', '遠', '複', '機', '能', '追', '加','前', '方', '向', '部', '小', '定', '屋', '居', + '隱', '奧', '遺', '暗', '安', '淵', '園', '胃', '江', '館', '犬', '客', '験', '穴', '会', '口', '窟', '広', '宮', '庫', '峽', '研', '究', '棺', '鬼', '計', '巻', '虛', + '基', '果', '球', '界', '交', '休', '街', '議', '群', '岩', '月', '拷', '逆', '獄', '後', '所', '宿', '赤', '私', '室', '斎', '層', '草', '砂', '深', '倉', '集', '敷', + '世', '息', '想', '女', '城', '蔵', '乗', '島', '竹', '滝', '通', '置', '底', '沈', '庭', '潮', '吊', '袋', '腸', '扉', '堂', '洞', '殿', '台', '沼', '難', '浜', '辺', + '壁', '宝', '破', '腹', '氷', '拝', '噴', '崩', '番', '漠', '物', '墓', '密', '門', '默', '問', '遊', '谷', '離', '路', '裏', '綠', '廊', '楼', '牢', '礼', '巨', '樹', + '意', '俺', '降', '壊', '今', '急', '光', '怪', '凶', '舵', '近', '確', '旗', '減', '画', '昇', '青', '左', '色', '捜', '先', '勝', '選', '受', '次', '丈', '点', '注', + '他', '知', '体', '駄', + }; + + public static readonly char[] _table4 = new char[0x100] + { + '何', '吞', '返', '夫', '僕', '暴', '面', '目', '無', '待', '戾', '認', '電', '切', '完', '了', '保', '既', '可', '込', + '決', '新', '差', '商', '設', '削', '除', '獣', '值', '抜', '仲', '品', '未', '読', '野', '右', '素', '個', '移', '位', '憶', '器', '更', '記', '期', '観', '級', '現', + + /*sys2-1*/ + '外', '送', '梱', '包', '謁', '礎', '格', '納', '盤', '信', '枢', '港', '号', '死', '山', '薬', '砦', '市', '店', '護', '住', '処', '廃', '墟', '試', '練', '埋', '営', + '関', '村', '尾', '根', '頂', '場', '玉', '座', '_', '_', '_', '_', '_', '_', 'α', 'β', 'γ', '二', '四', '五', '六', '七', '几', '九', '零', '壱', '弐', '參', + '百', '式', '號', '駅', '宅', '町', '車', '塔', '階', '絡', '狭', '象', '存', '渓', '建', '製', '施', '忘', '却', '桟', '停', '泊', '摩', '災', '床', '滅', '危', '波', + '岸', '話', '再', '彼', '姿', '聞', '言', '戦', '隊', '着', '国', '進', '訪', '服', '救', '残', '帰', '元', '呪', '幻', '得', '逃', '解', '貸', '金', '囲', '探', '脱', + '協', '男', '到', '帝', '都', '相', '頼', '盗', '影', '代', '宰', '緒', '皇', '血', '妃', '任', '放', '誰', '財', '務', '捕', '声', '終', '越', '閉', '聾', '平', '杯', + '窓', '騒', '音', '償', 'ヶ', '準', '葉', '告', '父', '喜', '習', '々', '犯', '勢', '吉', '違', '真', '胸', '険', '催', '途', '日', '届', '友', '狙', '和', '突', '奪', + '軍', '棒', '娘', '抱', '景', '異', '恋', '応', '映', '略', '支', '顔', '命', '別', '呼', '散', '叩', '感', '提', '揺', '荷', '挑', '駆', '談', '銅', '味', '慣', '謎', + '笑', '博', '輝', '畑', '宣', '況', '泥', '早', '演', '悩', '川', '弱', + }; + + public static readonly char[] _table5 = new char[0x100] + { + '係', '資', '張', '希', '非', '如', '迎', '軽', '暮', '派', '旅', '責', '督', '退', '縮', '頭', + '謝', '貸', '曲', '偉', '並', '借', '継', '絵', '伏', '治', '功', '与', '楽', '望', '殺', '親', '美', '勇', '染', '眠', '走', '契', '隙', '拠', '討', '拒', '族', '歌', + '良', '夢', '預', '覚', '価', '予', '争', '惑', '儀', '贈', '為', '崖', '周', '板', '穏', '割', '術', '誕', '伐', '疲', '渉', '狼', '互', '煙', '夜', '因', '爆', '嵐', + '漂', '固', '砲', '側', '看', '抑', '絆', '末', '紡', '誘', '歪', '貫', '柱', '黄', '昏', '旋', '律', '辿', '混', '沌', '創', '祭', '壇', '精', '妖', '買', '吸', '克', + '歴', '歩', '北', '対', '司', '夏', '静', '帯', '師', '反', '総', '限', '売', '利', '秒', '写', '響', '委', '両', '角', '列', '菓', '補', '販', '各', '桜', '虹', '紫', + '年', '禁', '灰', '超', '矢', '触', '重', '十', + '充', '仮', '霊', '幽', '拾', '符', '冒', '第', '件', '背', '綱', '負', '花', '匠', '標', '頑', '射', '紙', '柄', '制', + '峠', '困', '範', '陣', '君', '倍', '奏', '躍', '昨', '簡', '網', '願', '奇', '便', '浮', '郊', '単', '侵', '域', '叫', '詳', '索', '検', '渦', '幕', '官', '項', '念', + + /*sys2-2*/ + '還', '題', '没', '描', '令', '→', '←', '♪', '艦', '聖', '竜', '龍', '忍', '苦', '評', '仕', '賢', '距', '&', '採', '鉱', '坑', '積', '夕', '錬', '斬', '霸', '一', + '編', '語', '条', '理', '拡', '央', '冠', '極', '烈', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '欲', '兜', '限', '臨', '威', '乱', '故', '郷', '悪' + }; + + public static readonly char[] _table6 = new char[0x100] + { + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + }; + + public static readonly char[] _table7 = new char[0x40] + { + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', + }; + + public static readonly char[] _table8 = new char[0] + { + }; + } +} diff --git a/OpenKh.Kh2/Messages/Internals/JapaneseSystemEncode.cs b/OpenKh.Kh2/Messages/Internals/JapaneseSystemEncode.cs index f39299a0d..f84dc56e0 100644 --- a/OpenKh.Kh2/Messages/Internals/JapaneseSystemEncode.cs +++ b/OpenKh.Kh2/Messages/Internals/JapaneseSystemEncode.cs @@ -1,148 +1,148 @@ -using OpenKh.Common.Exceptions; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; - -namespace OpenKh.Kh2.Messages.Internals -{ - internal class JapaneseSystemEncode : IMessageEncode - { - private static readonly Dictionary> _tableCommands = - JapaneseSystemDecode._table - .Where(x => x.Value != null && x.Value.Command != MessageCommand.PrintText) - .GroupBy(x => x.Value.Command) - .ToDictionary(x => x.Key, x => x.First()); - - private static readonly Dictionary _tableCharacters = - GenerateCharacterDictionary(); - - private static readonly Dictionary _tableComplex = - JapaneseSystemDecode._table - .Where(x => x.Value?.Command == MessageCommand.PrintComplex) - .Select(x => new - { - Key = x.Value.Text, - Value = new byte[] { x.Key } - }) - .Concat(new[] - { - new { Key = "XIII", Value = new byte[] { 0x19, 0xb2 } }, - new { Key = "I", Value = new byte[] { 0x1b, 0x54 } }, - new { Key = "II", Value = new byte[] { 0x1b, 0x55 } }, - new { Key = "IV", Value = new byte[] { 0x1b, 0x56 } }, - new { Key = "V", Value = new byte[] { 0x1b, 0x57 } }, - new { Key = "VI", Value = new byte[] { 0x1b, 0x58 } }, - new { Key = "IX", Value = new byte[] { 0x1b, 0x59 } }, - }) - .ToDictionary(x => x.Key, x => x.Value); - - private void AppendEncodedMessageCommand(List list, MessageCommandModel messageCommand) - { - if (messageCommand.Command == MessageCommand.PrintText) - AppendEncodedText(list, messageCommand.Text); - else if (messageCommand.Command == MessageCommand.PrintComplex) - AppendEncodedComplex(list, messageCommand.Text); - else if (messageCommand.Command == MessageCommand.Unsupported) - list.AddRange(messageCommand.Data); - else - AppendEncodedCommand(list, messageCommand.Command, messageCommand.Data); - } - - private void AppendEncodedCommand(List list, MessageCommand command, byte[] data) - { - if (!_tableCommands.TryGetValue(command, out var pair)) - throw new ArgumentException($"The command {command} it is not supported by the specified encoding."); - - list.Add(pair.Key); - for (var i = 0; i < pair.Value.Length; i++) - list.Add(data[i]); - } - - private void AppendEncodedText(List list, string text) - { - foreach (var ch in text) - AppendEncodedChar(list, ch); - } - - private void AppendEncodedComplex(List list, string text) - { - if (!_tableComplex.TryGetValue(text, out var data)) - throw new ParseException(text, 0, "Complex text does not exists"); - - list.AddRange(data); - } - - private void AppendEncodedChar(List list, char ch) - { - if (!_tableCharacters.TryGetValue(ch, out var data)) - throw new CharacterNotSupportedException(ch); - - if (data.Item1 != 0) - list.Add(data.Item1); - list.Add(data.Item2); - } - - public byte[] Encode(List messageCommands) - { - var list = new List(100); - foreach (var model in messageCommands) - AppendEncodedMessageCommand(list, model); - - return list.ToArray(); - } - - private static Dictionary GenerateCharacterDictionary() - { - var pairs = GenerateCharacterKeyValuePair(MessageCommand.PrintText) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table2, JapaneseSystemTable._table2)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table3, JapaneseSystemTable._table3)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table4, JapaneseSystemTable._table4)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table5, JapaneseSystemTable._table5)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table6, JapaneseSystemTable._table6)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table7, JapaneseSystemTable._table7)) - .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table8, JapaneseSystemTable._table8)); - -#if DEBUG - var stringBuilder = new StringBuilder(); - foreach (var item in pairs - .GroupBy(x => x.Key) - .Where(x => x.Count() > 1)) - { - var ch = item.Key; - var data1 = item.First().Value; - var data2 = item.Skip(1).First().Value; - - stringBuilder.AppendLine($"Character '{ch}' ({data1.Item1:X02} {data1.Item2:X02}) is duplicate (with {data2.Item1:X02} {data2.Item2:X02})."); - } - - Debug.WriteLine(stringBuilder); -#endif - - return pairs - .GroupBy(x => x.Key) - .ToDictionary(x => x.Key, x => x.First().Value); - } - - private static IEnumerable> GenerateCharacterKeyValuePair( - MessageCommand messageCommand) => - JapaneseSystemDecode._table - .Where(x => x.Value?.Command == messageCommand) - .Select(x => new KeyValuePair(x.Value.Text[0], (0, x.Key))); - - private static IEnumerable> GenerateCharacterKeyValuePairFromTable( - MessageCommand messageCommand, char[] table) => - JapaneseSystemDecode._table - .Where(x => x.Value?.Command == messageCommand) - .Select(x => table.Select((ch, i) => new - { - TableId = x.Key, - Character = ch, - Data = (byte)i - })) - .SelectMany(x => x) - .Where(x => x.Character != '_' && x.Character != '?') - .Select(x => new KeyValuePair(x.Character, (x.TableId, x.Data))); - } -} +using OpenKh.Common.Exceptions; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; + +namespace OpenKh.Kh2.Messages.Internals +{ + internal class JapaneseSystemEncode : IMessageEncode + { + private static readonly Dictionary> _tableCommands = + JapaneseSystemDecode._table + .Where(x => x.Value != null && x.Value.Command != MessageCommand.PrintText) + .GroupBy(x => x.Value.Command) + .ToDictionary(x => x.Key, x => x.First()); + + private static readonly Dictionary _tableCharacters = + GenerateCharacterDictionary(); + + private static readonly Dictionary _tableComplex = + JapaneseSystemDecode._table + .Where(x => x.Value?.Command == MessageCommand.PrintComplex) + .Select(x => new + { + Key = x.Value.Text, + Value = new byte[] { x.Key } + }) + .Concat(new[] + { + new { Key = "XIII", Value = new byte[] { 0x19, 0xb2 } }, + new { Key = "I", Value = new byte[] { 0x1b, 0x54 } }, + new { Key = "II", Value = new byte[] { 0x1b, 0x55 } }, + new { Key = "IV", Value = new byte[] { 0x1b, 0x56 } }, + new { Key = "V", Value = new byte[] { 0x1b, 0x57 } }, + new { Key = "VI", Value = new byte[] { 0x1b, 0x58 } }, + new { Key = "IX", Value = new byte[] { 0x1b, 0x59 } }, + }) + .ToDictionary(x => x.Key, x => x.Value); + + private void AppendEncodedMessageCommand(List list, MessageCommandModel messageCommand) + { + if (messageCommand.Command == MessageCommand.PrintText) + AppendEncodedText(list, messageCommand.Text); + else if (messageCommand.Command == MessageCommand.PrintComplex) + AppendEncodedComplex(list, messageCommand.Text); + else if (messageCommand.Command == MessageCommand.Unsupported) + list.AddRange(messageCommand.Data); + else + AppendEncodedCommand(list, messageCommand.Command, messageCommand.Data); + } + + private void AppendEncodedCommand(List list, MessageCommand command, byte[] data) + { + if (!_tableCommands.TryGetValue(command, out var pair)) + throw new ArgumentException($"The command {command} it is not supported by the specified encoding."); + + list.Add(pair.Key); + for (var i = 0; i < pair.Value.Length; i++) + list.Add(data[i]); + } + + private void AppendEncodedText(List list, string text) + { + foreach (var ch in text) + AppendEncodedChar(list, ch); + } + + private void AppendEncodedComplex(List list, string text) + { + if (!_tableComplex.TryGetValue(text, out var data)) + throw new ParseException(text, 0, "Complex text does not exists"); + + list.AddRange(data); + } + + private void AppendEncodedChar(List list, char ch) + { + if (!_tableCharacters.TryGetValue(ch, out var data)) + throw new CharacterNotSupportedException(ch); + + if (data.Item1 != 0) + list.Add(data.Item1); + list.Add(data.Item2); + } + + public byte[] Encode(List messageCommands) + { + var list = new List(100); + foreach (var model in messageCommands) + AppendEncodedMessageCommand(list, model); + + return list.ToArray(); + } + + private static Dictionary GenerateCharacterDictionary() + { + var pairs = GenerateCharacterKeyValuePair(MessageCommand.PrintText) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table2, JapaneseSystemTable._table2)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table3, JapaneseSystemTable._table3)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table4, JapaneseSystemTable._table4)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table5, JapaneseSystemTable._table5)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table6, JapaneseSystemTable._table6)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table7, JapaneseSystemTable._table7)) + .Concat(GenerateCharacterKeyValuePairFromTable(MessageCommand.Table8, JapaneseSystemTable._table8)); + +#if DEBUG + var stringBuilder = new StringBuilder(); + foreach (var item in pairs + .GroupBy(x => x.Key) + .Where(x => x.Count() > 1)) + { + var ch = item.Key; + var data1 = item.First().Value; + var data2 = item.Skip(1).First().Value; + + stringBuilder.AppendLine($"Character '{ch}' ({data1.Item1:X02} {data1.Item2:X02}) is duplicate (with {data2.Item1:X02} {data2.Item2:X02})."); + } + + Debug.WriteLine(stringBuilder); +#endif + + return pairs + .GroupBy(x => x.Key) + .ToDictionary(x => x.Key, x => x.First().Value); + } + + private static IEnumerable> GenerateCharacterKeyValuePair( + MessageCommand messageCommand) => + JapaneseSystemDecode._table + .Where(x => x.Value?.Command == messageCommand) + .Select(x => new KeyValuePair(x.Value.Text[0], (0, x.Key))); + + private static IEnumerable> GenerateCharacterKeyValuePairFromTable( + MessageCommand messageCommand, char[] table) => + JapaneseSystemDecode._table + .Where(x => x.Value?.Command == messageCommand) + .Select(x => table.Select((ch, i) => new + { + TableId = x.Key, + Character = ch, + Data = (byte)i + })) + .SelectMany(x => x) + .Where(x => x.Character != '_' && x.Character != '?') + .Select(x => new KeyValuePair(x.Character, (x.TableId, x.Data))); + } +} diff --git a/OpenKh.Kh2/Messages/Internals/SimpleCmdModel.cs b/OpenKh.Kh2/Messages/Internals/SimpleCmdModel.cs index 1fee68ca1..47b2bbec6 100644 --- a/OpenKh.Kh2/Messages/Internals/SimpleCmdModel.cs +++ b/OpenKh.Kh2/Messages/Internals/SimpleCmdModel.cs @@ -1,10 +1,10 @@ -namespace OpenKh.Kh2.Messages.Internals -{ - internal class SimpleCmdModel : BaseCmdModel - { - public SimpleCmdModel(MessageCommand command) - { - Command = command; - } - } -} +namespace OpenKh.Kh2.Messages.Internals +{ + internal class SimpleCmdModel : BaseCmdModel + { + public SimpleCmdModel(MessageCommand command) + { + Command = command; + } + } +} diff --git a/OpenKh.Kh2/Messages/Internals/SingleDataCmdModel.cs b/OpenKh.Kh2/Messages/Internals/SingleDataCmdModel.cs index 904e83150..f54428a06 100644 --- a/OpenKh.Kh2/Messages/Internals/SingleDataCmdModel.cs +++ b/OpenKh.Kh2/Messages/Internals/SingleDataCmdModel.cs @@ -1,9 +1,9 @@ -namespace OpenKh.Kh2.Messages.Internals -{ - internal class SingleDataCmdModel : DataCmdModel - { - public SingleDataCmdModel(MessageCommand command) : - base(command, 1) - { } - } -} +namespace OpenKh.Kh2.Messages.Internals +{ + internal class SingleDataCmdModel : DataCmdModel + { + public SingleDataCmdModel(MessageCommand command) : + base(command, 1) + { } + } +} diff --git a/OpenKh.Kh2/Messages/Internals/TableCmdModel.cs b/OpenKh.Kh2/Messages/Internals/TableCmdModel.cs index 399a15d09..66b488273 100644 --- a/OpenKh.Kh2/Messages/Internals/TableCmdModel.cs +++ b/OpenKh.Kh2/Messages/Internals/TableCmdModel.cs @@ -1,15 +1,15 @@ -namespace OpenKh.Kh2.Messages.Internals -{ - internal class TableCmdModel : BaseCmdModel - { - private readonly char[] _table; - - public TableCmdModel(MessageCommand messageCommand, char[] table) - { - Command = messageCommand; - _table = table; - } - - public string GetText(byte data) => $"{_table[data]}"; - } -} +namespace OpenKh.Kh2.Messages.Internals +{ + internal class TableCmdModel : BaseCmdModel + { + private readonly char[] _table; + + public TableCmdModel(MessageCommand messageCommand, char[] table) + { + Command = messageCommand; + _table = table; + } + + public string GetText(byte data) => $"{_table[data]}"; + } +} diff --git a/OpenKh.Kh2/Messages/Internals/TextCmdModel.cs b/OpenKh.Kh2/Messages/Internals/TextCmdModel.cs index 1bdf9d097..7adaf1277 100644 --- a/OpenKh.Kh2/Messages/Internals/TextCmdModel.cs +++ b/OpenKh.Kh2/Messages/Internals/TextCmdModel.cs @@ -1,22 +1,22 @@ -namespace OpenKh.Kh2.Messages.Internals -{ - internal class TextCmdModel : BaseCmdModel - { - public TextCmdModel(byte chData) : - this((char)chData) - { } - - public TextCmdModel(char ch) : - this($"{ch}") - { - Command = MessageCommand.PrintText; - Text = $"{ch}"; - } - - public TextCmdModel(string str) - { - Command = MessageCommand.PrintComplex; - Text = str; - } - } -} +namespace OpenKh.Kh2.Messages.Internals +{ + internal class TextCmdModel : BaseCmdModel + { + public TextCmdModel(byte chData) : + this((char)chData) + { } + + public TextCmdModel(char ch) : + this($"{ch}") + { + Command = MessageCommand.PrintText; + Text = $"{ch}"; + } + + public TextCmdModel(string str) + { + Command = MessageCommand.PrintComplex; + Text = str; + } + } +} diff --git a/OpenKh.Kh2/Messages/Internals/TurkishSystemDecode.cs b/OpenKh.Kh2/Messages/Internals/TurkishSystemDecode.cs index af413573d..04e01ff16 100644 --- a/OpenKh.Kh2/Messages/Internals/TurkishSystemDecode.cs +++ b/OpenKh.Kh2/Messages/Internals/TurkishSystemDecode.cs @@ -1,273 +1,273 @@ -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Kh2.Messages.Internals -{ - internal class TurkishSystemDecode : IMessageDecode - { - private static readonly char[] _tableGeneric = Enumerable.Range(0, 0x100).Select(x => '?').ToArray(); - - public static readonly Dictionary _table = new Dictionary - { - [0x00] = new SimpleCmdModel(MessageCommand.End), - [0x01] = new TextCmdModel(' '), - [0x02] = new TextCmdModel('\n'), - [0x03] = new SimpleCmdModel(MessageCommand.Reset), - [0x04] = new SingleDataCmdModel(MessageCommand.Theme), - [0x05] = new DataCmdModel(MessageCommand.Unknown05, 6), - [0x06] = new SingleDataCmdModel(MessageCommand.Unknown06), - [0x07] = new DataCmdModel(MessageCommand.Color, 4), - [0x08] = new DataCmdModel(MessageCommand.Unknown08, 3), - [0x09] = new SingleDataCmdModel(MessageCommand.PrintIcon), - [0x0a] = new SingleDataCmdModel(MessageCommand.TextScale), - [0x0b] = new SingleDataCmdModel(MessageCommand.TextWidth), - [0x0c] = new SingleDataCmdModel(MessageCommand.LineSpacing), - [0x0d] = new SimpleCmdModel(MessageCommand.Unknown0d), - [0x0e] = new SingleDataCmdModel(MessageCommand.Unknown0e), - [0x0f] = new DataCmdModel(MessageCommand.Unknown0f, 5), - [0x10] = new SimpleCmdModel(MessageCommand.Clear), - [0x11] = new DataCmdModel(MessageCommand.Position, 4), - [0x12] = new DataCmdModel(MessageCommand.Unknown12, 2), - [0x13] = new DataCmdModel(MessageCommand.Unknown13, 4), - [0x14] = new DataCmdModel(MessageCommand.Delay, 2), - [0x15] = new DataCmdModel(MessageCommand.CharDelay, 2), - [0x16] = new SingleDataCmdModel(MessageCommand.Unknown16), - [0x17] = new DataCmdModel(MessageCommand.DelayAndFade, 2), - [0x18] = new DataCmdModel(MessageCommand.Unknown18, 2), - [0x19] = new TableCmdModel(MessageCommand.Table2, _tableGeneric), - [0x1a] = new TableCmdModel(MessageCommand.Table3, _tableGeneric), - [0x1b] = new TableCmdModel(MessageCommand.Table4, _tableGeneric), - [0x1c] = new TableCmdModel(MessageCommand.Table5, _tableGeneric), - [0x1d] = new TableCmdModel(MessageCommand.Table6, _tableGeneric), - [0x1e] = new TableCmdModel(MessageCommand.Table7, _tableGeneric), - [0x1f] = new TableCmdModel(MessageCommand.Table8, _tableGeneric), - [0x20] = new TextCmdModel('⬛'), - [0x21] = new TextCmdModel('0'), - [0x22] = new TextCmdModel('1'), - [0x23] = new TextCmdModel('2'), - [0x24] = new TextCmdModel('3'), - [0x25] = new TextCmdModel('4'), - [0x26] = new TextCmdModel('5'), - [0x27] = new TextCmdModel('6'), - [0x28] = new TextCmdModel('7'), - [0x29] = new TextCmdModel('8'), - [0x2a] = new TextCmdModel('9'), - [0x2b] = new TextCmdModel('+'), - [0x2c] = new TextCmdModel('−'), - [0x2d] = new TextCmdModel('ₓ'), - [0x2e] = new TextCmdModel('A'), - [0x2f] = new TextCmdModel('B'), - [0x30] = new TextCmdModel('C'), - [0x31] = new TextCmdModel('D'), - [0x32] = new TextCmdModel('E'), - [0x33] = new TextCmdModel('F'), - [0x34] = new TextCmdModel('G'), - [0x35] = new TextCmdModel('H'), - [0x36] = new TextCmdModel('I'), - [0x37] = new TextCmdModel('J'), - [0x38] = new TextCmdModel('K'), - [0x39] = new TextCmdModel('L'), - [0x3a] = new TextCmdModel('M'), - [0x3b] = new TextCmdModel('N'), - [0x3c] = new TextCmdModel('O'), - [0x3d] = new TextCmdModel('P'), - [0x3e] = new TextCmdModel('Q'), - [0x3f] = new TextCmdModel('R'), - [0x40] = new TextCmdModel('S'), - [0x41] = new TextCmdModel('T'), - [0x42] = new TextCmdModel('U'), - [0x43] = new TextCmdModel('V'), - [0x44] = new TextCmdModel('W'), - [0x45] = new TextCmdModel('X'), - [0x46] = new TextCmdModel('Y'), - [0x47] = new TextCmdModel('Z'), - [0x48] = new TextCmdModel('!'), - [0x49] = new TextCmdModel('?'), - [0x4a] = new TextCmdModel('%'), - [0x4b] = new TextCmdModel('/'), - [0x4c] = new TextCmdModel('※'), - [0x4d] = new TextCmdModel('、'), - [0x4e] = new TextCmdModel('。'), - [0x4f] = new TextCmdModel('.'), - [0x50] = new TextCmdModel(','), - [0x51] = new TextCmdModel(';'), - [0x52] = new TextCmdModel(':'), - [0x53] = new TextCmdModel('…'), - [0x54] = new TextCmdModel("-"), - [0x55] = new TextCmdModel('–'), - [0x56] = new TextCmdModel('〜'), - [0x57] = new TextCmdModel("'"), - [0x58] = new UnsupportedCmdModel(0x58), // Unused - [0x59] = new UnsupportedCmdModel(0x59), // Unused - [0x5a] = new TextCmdModel('('), - [0x5b] = new TextCmdModel(')'), - [0x5c] = new TextCmdModel('「'), - [0x5d] = new TextCmdModel('」'), - [0x5e] = new TextCmdModel('『'), - [0x5f] = new TextCmdModel('』'), - [0x60] = new TextCmdModel('“'), - [0x61] = new TextCmdModel('”'), - [0x62] = new TextCmdModel('['), - [0x63] = new TextCmdModel(']'), - [0x64] = new TextCmdModel('<'), - [0x65] = new TextCmdModel('>'), - [0x66] = new TextCmdModel('-'), - [0x67] = new TextCmdModel("–"), - [0x68] = new TextCmdModel('⤷'), // Used only in EVT - [0x69] = new TextCmdModel('♩'), - [0x6a] = new TextCmdModel('⇾'), // Used only in EVT - [0x6b] = new TextCmdModel('⇽'), // Used only in EVT - [0x6c] = new TextCmdModel('◯'), - [0x6d] = new TextCmdModel('✕'), - [0x6e] = new UnsupportedCmdModel(0x6e), // Unused - [0x6f] = new UnsupportedCmdModel(0x6e), // Unused - [0x70] = new UnsupportedCmdModel(0x70), // Unused - [0x71] = new UnsupportedCmdModel(0x71), // Unused - [0x72] = new UnsupportedCmdModel(0x72), // Unused - [0x73] = new SimpleCmdModel(MessageCommand.Tabulation), - [0x74] = new TextCmdModel("I"), - [0x75] = new TextCmdModel("II"), - [0x76] = new TextCmdModel("III"), - [0x77] = new TextCmdModel("IV"), - [0x78] = new TextCmdModel("V"), - [0x79] = new TextCmdModel("VI"), - [0x7a] = new TextCmdModel("VII"), - [0x7b] = new TextCmdModel("VIII"), - [0x7c] = new TextCmdModel("IX"), - [0x7d] = new TextCmdModel("X"), - [0x7e] = new TextCmdModel("XIII"), - [0x7f] = new TextCmdModel('α'), - [0x80] = new TextCmdModel('β'), - [0x81] = new TextCmdModel('γ'), - [0x82] = new TextCmdModel('⭑'), - [0x83] = new TextCmdModel('⭒'), - [0x84] = new TextCmdModel("XI"), - [0x85] = new TextCmdModel("XII"), - [0x86] = new TextCmdModel('&'), - [0x87] = new TextCmdModel('#'), - [0x88] = new TextCmdModel('®'), - [0x89] = new TextCmdModel('▴'), - [0x8a] = new TextCmdModel('▾'), - [0x8b] = new TextCmdModel('▸'), - [0x8c] = new TextCmdModel('◂'), - [0x8d] = new TextCmdModel('°'), - [0x8e] = new TextCmdModel("♪"), - [0x8f] = new UnsupportedCmdModel(0x8f), // Unused - [0x90] = new TextCmdModel('0'), - [0x91] = new TextCmdModel('1'), - [0x92] = new TextCmdModel('2'), - [0x93] = new TextCmdModel('3'), - [0x94] = new TextCmdModel('4'), - [0x95] = new TextCmdModel('5'), - [0x96] = new TextCmdModel('6'), - [0x97] = new TextCmdModel('7'), - [0x98] = new TextCmdModel('8'), - [0x99] = new TextCmdModel('9'), - [0x9a] = new TextCmdModel('a'), - [0x9b] = new TextCmdModel('b'), - [0x9c] = new TextCmdModel('c'), - [0x9d] = new TextCmdModel('d'), - [0x9e] = new TextCmdModel('e'), - [0x9f] = new TextCmdModel('f'), - [0xa0] = new TextCmdModel('g'), - [0xa1] = new TextCmdModel('h'), - [0xa2] = new TextCmdModel('i'), - [0xa3] = new TextCmdModel('j'), - [0xa4] = new TextCmdModel('k'), - [0xa5] = new TextCmdModel('l'), - [0xa6] = new TextCmdModel('m'), - [0xa7] = new TextCmdModel('n'), - [0xa8] = new TextCmdModel('o'), - [0xa9] = new TextCmdModel('p'), - [0xaa] = new TextCmdModel('q'), - [0xab] = new TextCmdModel('r'), - [0xac] = new TextCmdModel('s'), - [0xad] = new TextCmdModel('t'), - [0xae] = new TextCmdModel('u'), - [0xaf] = new TextCmdModel('v'), - [0xb0] = new TextCmdModel('w'), - [0xb1] = new TextCmdModel('x'), - [0xb2] = new TextCmdModel('y'), - [0xb3] = new TextCmdModel('z'), - [0xb4] = new TextCmdModel('Æ'), - [0xb5] = new TextCmdModel('æ'), - [0xb6] = new TextCmdModel('ß'), - [0xb7] = new TextCmdModel('ş'), - [0xb8] = new TextCmdModel('ğ'), - [0xb9] = new TextCmdModel('â'), - [0xba] = new TextCmdModel('ä'), - [0xbb] = new TextCmdModel('è'), - [0xbc] = new TextCmdModel('é'), - [0xbd] = new TextCmdModel('ê'), - [0xbe] = new TextCmdModel('ë'), - [0xbf] = new TextCmdModel('ì'), - [0xc0] = new TextCmdModel('í'), - [0xc1] = new TextCmdModel('î'), - [0xc2] = new TextCmdModel('ï'), - [0xc3] = new TextCmdModel('ñ'), - [0xc4] = new TextCmdModel('ò'), - [0xc5] = new TextCmdModel('ó'), - [0xc6] = new TextCmdModel('ô'), - [0xc7] = new TextCmdModel('ö'), - [0xc8] = new TextCmdModel('ù'), - [0xc9] = new TextCmdModel('ú'), - [0xca] = new TextCmdModel('û'), - [0xcb] = new TextCmdModel('ü'), - [0xcc] = new TextCmdModel('º'), - [0xcd] = new TextCmdModel('—'), - [0xce] = new TextCmdModel('»'), - [0xcf] = new TextCmdModel('«'), - [0xd0] = new TextCmdModel('Ş'), - [0xd1] = new TextCmdModel('Ğ'), - [0xd2] = new TextCmdModel('Â'), - [0xd3] = new TextCmdModel('Ä'), - [0xd4] = new TextCmdModel('È'), - [0xd5] = new TextCmdModel('É'), - [0xd6] = new TextCmdModel('Ê'), - [0xd7] = new TextCmdModel('Ë'), - [0xd8] = new TextCmdModel('Ì'), - [0xd9] = new TextCmdModel('Í'), - [0xda] = new TextCmdModel('Î'), - [0xdb] = new TextCmdModel('İ'), - [0xdc] = new TextCmdModel('Ñ'), - [0xdd] = new TextCmdModel('Ò'), - [0xde] = new TextCmdModel('Ó'), - [0xdf] = new TextCmdModel('Ô'), - [0xe0] = new TextCmdModel('Ö'), - [0xe1] = new TextCmdModel('Ù'), - [0xe2] = new TextCmdModel('Ú'), - [0xe3] = new TextCmdModel('Û'), - [0xe4] = new TextCmdModel('Ü'), - [0xe5] = new TextCmdModel('ı'), - [0xe6] = new TextCmdModel('¿'), - [0xe7] = new TextCmdModel('Ç'), - [0xe8] = new TextCmdModel('ç'), - [0xe9] = new TextCmdModel('‛'), - [0xea] = new TextCmdModel('’'), - [0xeb] = new TextCmdModel('`'), - [0xec] = new TextCmdModel('´'), - [0xed] = new TextCmdModel('"'), - [0xee] = new TextCmdModel('\''), - [0xef] = new TextCmdModel('★'), - [0xf0] = new TextCmdModel('☆'), - [0xf1] = new TextCmdModel('■'), - [0xf2] = new TextCmdModel('□'), - [0xf3] = new TextCmdModel('▲'), - [0xf4] = new TextCmdModel('△'), - [0xf5] = new TextCmdModel('●'), - [0xf6] = new TextCmdModel('○'), - [0xf7] = new TextCmdModel('♪'), - [0xf8] = new TextCmdModel('♫'), - [0xf9] = new TextCmdModel('→'), - [0xfa] = new TextCmdModel('←'), - [0xfb] = new TextCmdModel('↑'), - [0xfc] = new TextCmdModel('↓'), - [0xfd] = new TextCmdModel('・'), - [0xfe] = new TextCmdModel('❤'), - [0xff] = new UnsupportedCmdModel(0xff), // Unused - }; - - public List Decode(byte[] data) => - new BaseMessageDecoder(_table, data).Decode(); - } -} +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Kh2.Messages.Internals +{ + internal class TurkishSystemDecode : IMessageDecode + { + private static readonly char[] _tableGeneric = Enumerable.Range(0, 0x100).Select(x => '?').ToArray(); + + public static readonly Dictionary _table = new Dictionary + { + [0x00] = new SimpleCmdModel(MessageCommand.End), + [0x01] = new TextCmdModel(' '), + [0x02] = new TextCmdModel('\n'), + [0x03] = new SimpleCmdModel(MessageCommand.Reset), + [0x04] = new SingleDataCmdModel(MessageCommand.Theme), + [0x05] = new DataCmdModel(MessageCommand.Unknown05, 6), + [0x06] = new SingleDataCmdModel(MessageCommand.Unknown06), + [0x07] = new DataCmdModel(MessageCommand.Color, 4), + [0x08] = new DataCmdModel(MessageCommand.Unknown08, 3), + [0x09] = new SingleDataCmdModel(MessageCommand.PrintIcon), + [0x0a] = new SingleDataCmdModel(MessageCommand.TextScale), + [0x0b] = new SingleDataCmdModel(MessageCommand.TextWidth), + [0x0c] = new SingleDataCmdModel(MessageCommand.LineSpacing), + [0x0d] = new SimpleCmdModel(MessageCommand.Unknown0d), + [0x0e] = new SingleDataCmdModel(MessageCommand.Unknown0e), + [0x0f] = new DataCmdModel(MessageCommand.Unknown0f, 5), + [0x10] = new SimpleCmdModel(MessageCommand.Clear), + [0x11] = new DataCmdModel(MessageCommand.Position, 4), + [0x12] = new DataCmdModel(MessageCommand.Unknown12, 2), + [0x13] = new DataCmdModel(MessageCommand.Unknown13, 4), + [0x14] = new DataCmdModel(MessageCommand.Delay, 2), + [0x15] = new DataCmdModel(MessageCommand.CharDelay, 2), + [0x16] = new SingleDataCmdModel(MessageCommand.Unknown16), + [0x17] = new DataCmdModel(MessageCommand.DelayAndFade, 2), + [0x18] = new DataCmdModel(MessageCommand.Unknown18, 2), + [0x19] = new TableCmdModel(MessageCommand.Table2, _tableGeneric), + [0x1a] = new TableCmdModel(MessageCommand.Table3, _tableGeneric), + [0x1b] = new TableCmdModel(MessageCommand.Table4, _tableGeneric), + [0x1c] = new TableCmdModel(MessageCommand.Table5, _tableGeneric), + [0x1d] = new TableCmdModel(MessageCommand.Table6, _tableGeneric), + [0x1e] = new TableCmdModel(MessageCommand.Table7, _tableGeneric), + [0x1f] = new TableCmdModel(MessageCommand.Table8, _tableGeneric), + [0x20] = new TextCmdModel('⬛'), + [0x21] = new TextCmdModel('0'), + [0x22] = new TextCmdModel('1'), + [0x23] = new TextCmdModel('2'), + [0x24] = new TextCmdModel('3'), + [0x25] = new TextCmdModel('4'), + [0x26] = new TextCmdModel('5'), + [0x27] = new TextCmdModel('6'), + [0x28] = new TextCmdModel('7'), + [0x29] = new TextCmdModel('8'), + [0x2a] = new TextCmdModel('9'), + [0x2b] = new TextCmdModel('+'), + [0x2c] = new TextCmdModel('−'), + [0x2d] = new TextCmdModel('ₓ'), + [0x2e] = new TextCmdModel('A'), + [0x2f] = new TextCmdModel('B'), + [0x30] = new TextCmdModel('C'), + [0x31] = new TextCmdModel('D'), + [0x32] = new TextCmdModel('E'), + [0x33] = new TextCmdModel('F'), + [0x34] = new TextCmdModel('G'), + [0x35] = new TextCmdModel('H'), + [0x36] = new TextCmdModel('I'), + [0x37] = new TextCmdModel('J'), + [0x38] = new TextCmdModel('K'), + [0x39] = new TextCmdModel('L'), + [0x3a] = new TextCmdModel('M'), + [0x3b] = new TextCmdModel('N'), + [0x3c] = new TextCmdModel('O'), + [0x3d] = new TextCmdModel('P'), + [0x3e] = new TextCmdModel('Q'), + [0x3f] = new TextCmdModel('R'), + [0x40] = new TextCmdModel('S'), + [0x41] = new TextCmdModel('T'), + [0x42] = new TextCmdModel('U'), + [0x43] = new TextCmdModel('V'), + [0x44] = new TextCmdModel('W'), + [0x45] = new TextCmdModel('X'), + [0x46] = new TextCmdModel('Y'), + [0x47] = new TextCmdModel('Z'), + [0x48] = new TextCmdModel('!'), + [0x49] = new TextCmdModel('?'), + [0x4a] = new TextCmdModel('%'), + [0x4b] = new TextCmdModel('/'), + [0x4c] = new TextCmdModel('※'), + [0x4d] = new TextCmdModel('、'), + [0x4e] = new TextCmdModel('。'), + [0x4f] = new TextCmdModel('.'), + [0x50] = new TextCmdModel(','), + [0x51] = new TextCmdModel(';'), + [0x52] = new TextCmdModel(':'), + [0x53] = new TextCmdModel('…'), + [0x54] = new TextCmdModel("-"), + [0x55] = new TextCmdModel('–'), + [0x56] = new TextCmdModel('〜'), + [0x57] = new TextCmdModel("'"), + [0x58] = new UnsupportedCmdModel(0x58), // Unused + [0x59] = new UnsupportedCmdModel(0x59), // Unused + [0x5a] = new TextCmdModel('('), + [0x5b] = new TextCmdModel(')'), + [0x5c] = new TextCmdModel('「'), + [0x5d] = new TextCmdModel('」'), + [0x5e] = new TextCmdModel('『'), + [0x5f] = new TextCmdModel('』'), + [0x60] = new TextCmdModel('“'), + [0x61] = new TextCmdModel('”'), + [0x62] = new TextCmdModel('['), + [0x63] = new TextCmdModel(']'), + [0x64] = new TextCmdModel('<'), + [0x65] = new TextCmdModel('>'), + [0x66] = new TextCmdModel('-'), + [0x67] = new TextCmdModel("–"), + [0x68] = new TextCmdModel('⤷'), // Used only in EVT + [0x69] = new TextCmdModel('♩'), + [0x6a] = new TextCmdModel('⇾'), // Used only in EVT + [0x6b] = new TextCmdModel('⇽'), // Used only in EVT + [0x6c] = new TextCmdModel('◯'), + [0x6d] = new TextCmdModel('✕'), + [0x6e] = new UnsupportedCmdModel(0x6e), // Unused + [0x6f] = new UnsupportedCmdModel(0x6e), // Unused + [0x70] = new UnsupportedCmdModel(0x70), // Unused + [0x71] = new UnsupportedCmdModel(0x71), // Unused + [0x72] = new UnsupportedCmdModel(0x72), // Unused + [0x73] = new SimpleCmdModel(MessageCommand.Tabulation), + [0x74] = new TextCmdModel("I"), + [0x75] = new TextCmdModel("II"), + [0x76] = new TextCmdModel("III"), + [0x77] = new TextCmdModel("IV"), + [0x78] = new TextCmdModel("V"), + [0x79] = new TextCmdModel("VI"), + [0x7a] = new TextCmdModel("VII"), + [0x7b] = new TextCmdModel("VIII"), + [0x7c] = new TextCmdModel("IX"), + [0x7d] = new TextCmdModel("X"), + [0x7e] = new TextCmdModel("XIII"), + [0x7f] = new TextCmdModel('α'), + [0x80] = new TextCmdModel('β'), + [0x81] = new TextCmdModel('γ'), + [0x82] = new TextCmdModel('⭑'), + [0x83] = new TextCmdModel('⭒'), + [0x84] = new TextCmdModel("XI"), + [0x85] = new TextCmdModel("XII"), + [0x86] = new TextCmdModel('&'), + [0x87] = new TextCmdModel('#'), + [0x88] = new TextCmdModel('®'), + [0x89] = new TextCmdModel('▴'), + [0x8a] = new TextCmdModel('▾'), + [0x8b] = new TextCmdModel('▸'), + [0x8c] = new TextCmdModel('◂'), + [0x8d] = new TextCmdModel('°'), + [0x8e] = new TextCmdModel("♪"), + [0x8f] = new UnsupportedCmdModel(0x8f), // Unused + [0x90] = new TextCmdModel('0'), + [0x91] = new TextCmdModel('1'), + [0x92] = new TextCmdModel('2'), + [0x93] = new TextCmdModel('3'), + [0x94] = new TextCmdModel('4'), + [0x95] = new TextCmdModel('5'), + [0x96] = new TextCmdModel('6'), + [0x97] = new TextCmdModel('7'), + [0x98] = new TextCmdModel('8'), + [0x99] = new TextCmdModel('9'), + [0x9a] = new TextCmdModel('a'), + [0x9b] = new TextCmdModel('b'), + [0x9c] = new TextCmdModel('c'), + [0x9d] = new TextCmdModel('d'), + [0x9e] = new TextCmdModel('e'), + [0x9f] = new TextCmdModel('f'), + [0xa0] = new TextCmdModel('g'), + [0xa1] = new TextCmdModel('h'), + [0xa2] = new TextCmdModel('i'), + [0xa3] = new TextCmdModel('j'), + [0xa4] = new TextCmdModel('k'), + [0xa5] = new TextCmdModel('l'), + [0xa6] = new TextCmdModel('m'), + [0xa7] = new TextCmdModel('n'), + [0xa8] = new TextCmdModel('o'), + [0xa9] = new TextCmdModel('p'), + [0xaa] = new TextCmdModel('q'), + [0xab] = new TextCmdModel('r'), + [0xac] = new TextCmdModel('s'), + [0xad] = new TextCmdModel('t'), + [0xae] = new TextCmdModel('u'), + [0xaf] = new TextCmdModel('v'), + [0xb0] = new TextCmdModel('w'), + [0xb1] = new TextCmdModel('x'), + [0xb2] = new TextCmdModel('y'), + [0xb3] = new TextCmdModel('z'), + [0xb4] = new TextCmdModel('Æ'), + [0xb5] = new TextCmdModel('æ'), + [0xb6] = new TextCmdModel('ß'), + [0xb7] = new TextCmdModel('ş'), + [0xb8] = new TextCmdModel('ğ'), + [0xb9] = new TextCmdModel('â'), + [0xba] = new TextCmdModel('ä'), + [0xbb] = new TextCmdModel('è'), + [0xbc] = new TextCmdModel('é'), + [0xbd] = new TextCmdModel('ê'), + [0xbe] = new TextCmdModel('ë'), + [0xbf] = new TextCmdModel('ì'), + [0xc0] = new TextCmdModel('í'), + [0xc1] = new TextCmdModel('î'), + [0xc2] = new TextCmdModel('ï'), + [0xc3] = new TextCmdModel('ñ'), + [0xc4] = new TextCmdModel('ò'), + [0xc5] = new TextCmdModel('ó'), + [0xc6] = new TextCmdModel('ô'), + [0xc7] = new TextCmdModel('ö'), + [0xc8] = new TextCmdModel('ù'), + [0xc9] = new TextCmdModel('ú'), + [0xca] = new TextCmdModel('û'), + [0xcb] = new TextCmdModel('ü'), + [0xcc] = new TextCmdModel('º'), + [0xcd] = new TextCmdModel('—'), + [0xce] = new TextCmdModel('»'), + [0xcf] = new TextCmdModel('«'), + [0xd0] = new TextCmdModel('Ş'), + [0xd1] = new TextCmdModel('Ğ'), + [0xd2] = new TextCmdModel('Â'), + [0xd3] = new TextCmdModel('Ä'), + [0xd4] = new TextCmdModel('È'), + [0xd5] = new TextCmdModel('É'), + [0xd6] = new TextCmdModel('Ê'), + [0xd7] = new TextCmdModel('Ë'), + [0xd8] = new TextCmdModel('Ì'), + [0xd9] = new TextCmdModel('Í'), + [0xda] = new TextCmdModel('Î'), + [0xdb] = new TextCmdModel('İ'), + [0xdc] = new TextCmdModel('Ñ'), + [0xdd] = new TextCmdModel('Ò'), + [0xde] = new TextCmdModel('Ó'), + [0xdf] = new TextCmdModel('Ô'), + [0xe0] = new TextCmdModel('Ö'), + [0xe1] = new TextCmdModel('Ù'), + [0xe2] = new TextCmdModel('Ú'), + [0xe3] = new TextCmdModel('Û'), + [0xe4] = new TextCmdModel('Ü'), + [0xe5] = new TextCmdModel('ı'), + [0xe6] = new TextCmdModel('¿'), + [0xe7] = new TextCmdModel('Ç'), + [0xe8] = new TextCmdModel('ç'), + [0xe9] = new TextCmdModel('‛'), + [0xea] = new TextCmdModel('’'), + [0xeb] = new TextCmdModel('`'), + [0xec] = new TextCmdModel('´'), + [0xed] = new TextCmdModel('"'), + [0xee] = new TextCmdModel('\''), + [0xef] = new TextCmdModel('★'), + [0xf0] = new TextCmdModel('☆'), + [0xf1] = new TextCmdModel('■'), + [0xf2] = new TextCmdModel('□'), + [0xf3] = new TextCmdModel('▲'), + [0xf4] = new TextCmdModel('△'), + [0xf5] = new TextCmdModel('●'), + [0xf6] = new TextCmdModel('○'), + [0xf7] = new TextCmdModel('♪'), + [0xf8] = new TextCmdModel('♫'), + [0xf9] = new TextCmdModel('→'), + [0xfa] = new TextCmdModel('←'), + [0xfb] = new TextCmdModel('↑'), + [0xfc] = new TextCmdModel('↓'), + [0xfd] = new TextCmdModel('・'), + [0xfe] = new TextCmdModel('❤'), + [0xff] = new UnsupportedCmdModel(0xff), // Unused + }; + + public List Decode(byte[] data) => + new BaseMessageDecoder(_table, data).Decode(); + } +} diff --git a/OpenKh.Kh2/Messages/Internals/TurkishSystemEncode.cs b/OpenKh.Kh2/Messages/Internals/TurkishSystemEncode.cs index 191fe85d3..259cac038 100644 --- a/OpenKh.Kh2/Messages/Internals/TurkishSystemEncode.cs +++ b/OpenKh.Kh2/Messages/Internals/TurkishSystemEncode.cs @@ -1,79 +1,79 @@ -using OpenKh.Common.Exceptions; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Kh2.Messages.Internals -{ - internal class TurkishSystemEncode : IMessageEncode - { - private static readonly Dictionary> _tableCommands = - TurkishSystemDecode._table - .Where(x => x.Value != null && x.Value.Command != MessageCommand.PrintText) - .GroupBy(x => x.Value.Command) - .ToDictionary(x => x.Key, x => x.First()); - - private static readonly Dictionary _tableCharacters = - TurkishSystemDecode._table - .Where(x => x.Value?.Command == MessageCommand.PrintText) - .ToDictionary(x => x.Value.Text[0], x => x.Key); - - private static readonly Dictionary _tableComplex = - TurkishSystemDecode._table - .Where(x => x.Value?.Command == MessageCommand.PrintComplex) - .ToDictionary(x => x.Value.Text, x => x.Key); - - private void AppendEncodedMessageCommand(List list, MessageCommandModel messageCommand) - { - if (messageCommand.Command == MessageCommand.PrintText) - AppendEncodedText(list, messageCommand.Text); - else if (messageCommand.Command == MessageCommand.PrintComplex) - AppendEncodedComplex(list, messageCommand.Text); - else if (messageCommand.Command == MessageCommand.Unsupported) - list.AddRange(messageCommand.Data); - else - AppendEncodedCommand(list, messageCommand.Command, messageCommand.Data); - } - - private void AppendEncodedCommand(List list, MessageCommand command, byte[] data) - { - if (!_tableCommands.TryGetValue(command, out var pair)) - throw new ArgumentException($"The command {command} it is not supported by the specified encoding."); - - list.Add(pair.Key); - for (var i = 0; i < pair.Value.Length; i++) - list.Add(data[i]); - } - - private void AppendEncodedText(List list, string text) - { - foreach (var ch in text) - AppendEncodedChar(list, ch); - } - - private void AppendEncodedComplex(List list, string text) - { - if (!_tableComplex.TryGetValue(text, out var data)) - throw new ParseException(text, 0, "Complex text does not exists"); - - list.Add(data); - } - - private void AppendEncodedChar(List list, char ch) - { - if (!_tableCharacters.TryGetValue(ch, out var data)) - throw new ArgumentException($"The character {ch} it is not supported by the specified encoding."); - - list.Add(data); - } - - public byte[] Encode(List messageCommands) - { - var list = new List(100); - foreach (var model in messageCommands) - AppendEncodedMessageCommand(list, model); - - return list.ToArray(); - } - } -} +using OpenKh.Common.Exceptions; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Kh2.Messages.Internals +{ + internal class TurkishSystemEncode : IMessageEncode + { + private static readonly Dictionary> _tableCommands = + TurkishSystemDecode._table + .Where(x => x.Value != null && x.Value.Command != MessageCommand.PrintText) + .GroupBy(x => x.Value.Command) + .ToDictionary(x => x.Key, x => x.First()); + + private static readonly Dictionary _tableCharacters = + TurkishSystemDecode._table + .Where(x => x.Value?.Command == MessageCommand.PrintText) + .ToDictionary(x => x.Value.Text[0], x => x.Key); + + private static readonly Dictionary _tableComplex = + TurkishSystemDecode._table + .Where(x => x.Value?.Command == MessageCommand.PrintComplex) + .ToDictionary(x => x.Value.Text, x => x.Key); + + private void AppendEncodedMessageCommand(List list, MessageCommandModel messageCommand) + { + if (messageCommand.Command == MessageCommand.PrintText) + AppendEncodedText(list, messageCommand.Text); + else if (messageCommand.Command == MessageCommand.PrintComplex) + AppendEncodedComplex(list, messageCommand.Text); + else if (messageCommand.Command == MessageCommand.Unsupported) + list.AddRange(messageCommand.Data); + else + AppendEncodedCommand(list, messageCommand.Command, messageCommand.Data); + } + + private void AppendEncodedCommand(List list, MessageCommand command, byte[] data) + { + if (!_tableCommands.TryGetValue(command, out var pair)) + throw new ArgumentException($"The command {command} it is not supported by the specified encoding."); + + list.Add(pair.Key); + for (var i = 0; i < pair.Value.Length; i++) + list.Add(data[i]); + } + + private void AppendEncodedText(List list, string text) + { + foreach (var ch in text) + AppendEncodedChar(list, ch); + } + + private void AppendEncodedComplex(List list, string text) + { + if (!_tableComplex.TryGetValue(text, out var data)) + throw new ParseException(text, 0, "Complex text does not exists"); + + list.Add(data); + } + + private void AppendEncodedChar(List list, char ch) + { + if (!_tableCharacters.TryGetValue(ch, out var data)) + throw new ArgumentException($"The character {ch} it is not supported by the specified encoding."); + + list.Add(data); + } + + public byte[] Encode(List messageCommands) + { + var list = new List(100); + foreach (var model in messageCommands) + AppendEncodedMessageCommand(list, model); + + return list.ToArray(); + } + } +} diff --git a/OpenKh.Kh2/Messages/Internals/UnsupportedCmdModel.cs b/OpenKh.Kh2/Messages/Internals/UnsupportedCmdModel.cs index f93fd5c04..6b1a6f81a 100644 --- a/OpenKh.Kh2/Messages/Internals/UnsupportedCmdModel.cs +++ b/OpenKh.Kh2/Messages/Internals/UnsupportedCmdModel.cs @@ -1,11 +1,11 @@ -namespace OpenKh.Kh2.Messages.Internals -{ - internal class UnsupportedCmdModel : BaseCmdModel - { - public UnsupportedCmdModel(byte data) - { - Command = MessageCommand.Unsupported; - RawData = data; - } - } -} +namespace OpenKh.Kh2.Messages.Internals +{ + internal class UnsupportedCmdModel : BaseCmdModel + { + public UnsupportedCmdModel(byte data) + { + Command = MessageCommand.Unsupported; + RawData = data; + } + } +} diff --git a/OpenKh.Kh2/Messages/MessageCommand.cs b/OpenKh.Kh2/Messages/MessageCommand.cs index 530e61776..cacf1a3d0 100644 --- a/OpenKh.Kh2/Messages/MessageCommand.cs +++ b/OpenKh.Kh2/Messages/MessageCommand.cs @@ -1,40 +1,40 @@ -namespace OpenKh.Kh2.Messages -{ - public enum MessageCommand - { - End, - PrintText, - PrintComplex, - Tabulation, - Reset, - Theme, - Unknown05, - Unknown06, - Color, - Unknown08, - PrintIcon, - TextScale, // Default: 0x10 - TextWidth, // Default: 0x48 - LineSpacing, - Unknown0d, - Unknown0e, - Unknown0f, - Clear, - Position, - Unknown12, - Unknown13, - Delay, - CharDelay, - Unknown16, - DelayAndFade, - Unknown18, - Table2, - Table3, - Table4, - Table5, - Table6, - Table7, - Table8, - Unsupported, - } -} +namespace OpenKh.Kh2.Messages +{ + public enum MessageCommand + { + End, + PrintText, + PrintComplex, + Tabulation, + Reset, + Theme, + Unknown05, + Unknown06, + Color, + Unknown08, + PrintIcon, + TextScale, // Default: 0x10 + TextWidth, // Default: 0x48 + LineSpacing, + Unknown0d, + Unknown0e, + Unknown0f, + Clear, + Position, + Unknown12, + Unknown13, + Delay, + CharDelay, + Unknown16, + DelayAndFade, + Unknown18, + Table2, + Table3, + Table4, + Table5, + Table6, + Table7, + Table8, + Unsupported, + } +} diff --git a/OpenKh.Kh2/Messages/MessageCommandModel.cs b/OpenKh.Kh2/Messages/MessageCommandModel.cs index 8f1db9658..ff3747bf9 100644 --- a/OpenKh.Kh2/Messages/MessageCommandModel.cs +++ b/OpenKh.Kh2/Messages/MessageCommandModel.cs @@ -1,45 +1,45 @@ -using System; - -namespace OpenKh.Kh2.Messages -{ - public class MessageCommandModel - { - public MessageCommand Command { get; set; } - public byte[] Data { get; set; } - public string Text { get; set; } - - public short PositionX - { - get => (short)(Data[0] | (Data[1] << 8)); - set - { - var rawValue = (ushort)value; - Data[0] = (byte)(rawValue & 0xFF); - Data[1] = (byte)((rawValue >> 8) & 0xFF); - } - } - - public short PositionY - { - get => (short)(Data[2] | (Data[3] << 8)); - set - { - var rawValue = (ushort)value; - Data[2] = (byte)(rawValue & 0xFF); - Data[3] = (byte)((rawValue >> 8) & 0xFF); - } - } - - public double TextScale - { - get => Data[0] / 16.0; - set => Data[0] = (byte)Math.Min(byte.MaxValue, Math.Max(byte.MinValue, value * 16.0)); - } - - public double TextWidth - { - get => Data[0] / 72.0; - set => Data[0] = (byte)Math.Min(byte.MaxValue, Math.Max(byte.MinValue, value * 72.0)); - } - } -} +using System; + +namespace OpenKh.Kh2.Messages +{ + public class MessageCommandModel + { + public MessageCommand Command { get; set; } + public byte[] Data { get; set; } + public string Text { get; set; } + + public short PositionX + { + get => (short)(Data[0] | (Data[1] << 8)); + set + { + var rawValue = (ushort)value; + Data[0] = (byte)(rawValue & 0xFF); + Data[1] = (byte)((rawValue >> 8) & 0xFF); + } + } + + public short PositionY + { + get => (short)(Data[2] | (Data[3] << 8)); + set + { + var rawValue = (ushort)value; + Data[2] = (byte)(rawValue & 0xFF); + Data[3] = (byte)((rawValue >> 8) & 0xFF); + } + } + + public double TextScale + { + get => Data[0] / 16.0; + set => Data[0] = (byte)Math.Min(byte.MaxValue, Math.Max(byte.MinValue, value * 16.0)); + } + + public double TextWidth + { + get => Data[0] / 72.0; + set => Data[0] = (byte)Math.Min(byte.MaxValue, Math.Max(byte.MinValue, value * 72.0)); + } + } +} diff --git a/OpenKh.Kh2/Messages/MsgSerializer.Text.cs b/OpenKh.Kh2/Messages/MsgSerializer.Text.cs index 9caff3952..df0e62142 100644 --- a/OpenKh.Kh2/Messages/MsgSerializer.Text.cs +++ b/OpenKh.Kh2/Messages/MsgSerializer.Text.cs @@ -1,139 +1,139 @@ -using OpenKh.Common.Exceptions; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Text; - -namespace OpenKh.Kh2.Messages -{ - public partial class MsgSerializer - { - public static string SerializeText(IEnumerable entries) - { - var sb = new StringBuilder(); - foreach (var entry in entries) - sb.Append(SerializeToText(entry)); - return sb.ToString(); - } - - public static string SerializeToText(MessageCommandModel entry) - { - if (entry.Command == MessageCommand.End) - return string.Empty; - if (entry.Command == MessageCommand.PrintText) - return entry.Text; - if (entry.Command == MessageCommand.PrintComplex) - return $"{{{entry.Text}}}"; - if (entry.Command == MessageCommand.Tabulation) - return "\t"; - - if (!_serializer.TryGetValue(entry.Command, out var serializeModel)) - throw new NotImplementedException($"The command {entry.Command} serialization is not implemented yet."); - - Debug.Assert(serializeModel != null, $"BUG: {nameof(serializeModel)} should never be null"); - - if (serializeModel.Serializer != null) - return $"{{:{serializeModel.Name} {serializeModel.Serializer(entry)}}}"; - return $"{{:{serializeModel.Name}}}"; - } - - - public static IEnumerable DeserializeText(string value) - { - var entries = new List(); - var strBuilder = new StringBuilder(); - - var i = 0; - while (i < value.Length) - { - MessageCommandModel messageCommand; - - var ch = value[i++]; - if (ch == '\t') - { - messageCommand = new MessageCommandModel - { - Command = MessageCommand.Tabulation, - }; - } - else if (ch == '\r') - { - // ignore - messageCommand = null; - } - else if (ch == '{') - { - var closeBracketIndex = value.Substring(i).IndexOf('}') + i; - if (closeBracketIndex < i) - throw new ParseException(value, i, "Expected '}'"); - - if (value[i] == ':') - messageCommand = GetCommandModel(value.Substring(i + 1, closeBracketIndex - i - 1)); - else - messageCommand = GetPrintComplexCommandModel(value.Substring(i, closeBracketIndex - i)); - - i = closeBracketIndex + 1; - } - else - { - messageCommand = null; - strBuilder.Append(ch); - } - - if (messageCommand != null) - { - if (strBuilder.Length > 0) - { - entries.Add(new MessageCommandModel - { - Command = MessageCommand.PrintText, - Text = strBuilder.ToString() - }); - strBuilder.Clear(); - } - - entries.Add(messageCommand); - } - } - - if (strBuilder.Length > 0) - { - entries.Add(new MessageCommandModel - { - Command = MessageCommand.PrintText, - Text = strBuilder.ToString() - }); - } - - entries.Add(new MessageCommandModel - { - Command = MessageCommand.End, - }); - - return entries; - } - - private static MessageCommandModel GetCommandModel(string value) - { - var splitIndex = value.IndexOf(' '); - var command = splitIndex >= 0 ? value.Substring(0, splitIndex) : value; - - if (!_deserializer.TryGetValue(command, out var deserializerModel)) - throw new ParseException(command, 0, $"Command not existing or un-supported"); - - var parameter = splitIndex >= 0 ? value.Substring(splitIndex).Trim() : null; - return new MessageCommandModel - { - Command = deserializerModel.Command, - Data = deserializerModel.Deserializer?.Invoke(parameter) - }; - } - - private static MessageCommandModel GetPrintComplexCommandModel(string value) - => new MessageCommandModel - { - Command = MessageCommand.PrintComplex, - Text = value - }; - } -} +using OpenKh.Common.Exceptions; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; + +namespace OpenKh.Kh2.Messages +{ + public partial class MsgSerializer + { + public static string SerializeText(IEnumerable entries) + { + var sb = new StringBuilder(); + foreach (var entry in entries) + sb.Append(SerializeToText(entry)); + return sb.ToString(); + } + + public static string SerializeToText(MessageCommandModel entry) + { + if (entry.Command == MessageCommand.End) + return string.Empty; + if (entry.Command == MessageCommand.PrintText) + return entry.Text; + if (entry.Command == MessageCommand.PrintComplex) + return $"{{{entry.Text}}}"; + if (entry.Command == MessageCommand.Tabulation) + return "\t"; + + if (!_serializer.TryGetValue(entry.Command, out var serializeModel)) + throw new NotImplementedException($"The command {entry.Command} serialization is not implemented yet."); + + Debug.Assert(serializeModel != null, $"BUG: {nameof(serializeModel)} should never be null"); + + if (serializeModel.Serializer != null) + return $"{{:{serializeModel.Name} {serializeModel.Serializer(entry)}}}"; + return $"{{:{serializeModel.Name}}}"; + } + + + public static IEnumerable DeserializeText(string value) + { + var entries = new List(); + var strBuilder = new StringBuilder(); + + var i = 0; + while (i < value.Length) + { + MessageCommandModel messageCommand; + + var ch = value[i++]; + if (ch == '\t') + { + messageCommand = new MessageCommandModel + { + Command = MessageCommand.Tabulation, + }; + } + else if (ch == '\r') + { + // ignore + messageCommand = null; + } + else if (ch == '{') + { + var closeBracketIndex = value.Substring(i).IndexOf('}') + i; + if (closeBracketIndex < i) + throw new ParseException(value, i, "Expected '}'"); + + if (value[i] == ':') + messageCommand = GetCommandModel(value.Substring(i + 1, closeBracketIndex - i - 1)); + else + messageCommand = GetPrintComplexCommandModel(value.Substring(i, closeBracketIndex - i)); + + i = closeBracketIndex + 1; + } + else + { + messageCommand = null; + strBuilder.Append(ch); + } + + if (messageCommand != null) + { + if (strBuilder.Length > 0) + { + entries.Add(new MessageCommandModel + { + Command = MessageCommand.PrintText, + Text = strBuilder.ToString() + }); + strBuilder.Clear(); + } + + entries.Add(messageCommand); + } + } + + if (strBuilder.Length > 0) + { + entries.Add(new MessageCommandModel + { + Command = MessageCommand.PrintText, + Text = strBuilder.ToString() + }); + } + + entries.Add(new MessageCommandModel + { + Command = MessageCommand.End, + }); + + return entries; + } + + private static MessageCommandModel GetCommandModel(string value) + { + var splitIndex = value.IndexOf(' '); + var command = splitIndex >= 0 ? value.Substring(0, splitIndex) : value; + + if (!_deserializer.TryGetValue(command, out var deserializerModel)) + throw new ParseException(command, 0, $"Command not existing or un-supported"); + + var parameter = splitIndex >= 0 ? value.Substring(splitIndex).Trim() : null; + return new MessageCommandModel + { + Command = deserializerModel.Command, + Data = deserializerModel.Deserializer?.Invoke(parameter) + }; + } + + private static MessageCommandModel GetPrintComplexCommandModel(string value) + => new MessageCommandModel + { + Command = MessageCommand.PrintComplex, + Text = value + }; + } +} diff --git a/OpenKh.Kh2/Messages/MsgSerializer.Xml.cs b/OpenKh.Kh2/Messages/MsgSerializer.Xml.cs index f688f2c25..73b3b3932 100644 --- a/OpenKh.Kh2/Messages/MsgSerializer.Xml.cs +++ b/OpenKh.Kh2/Messages/MsgSerializer.Xml.cs @@ -1,82 +1,83 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Xml.Linq; - -namespace OpenKh.Kh2.Messages -{ - public partial class MsgSerializer - { - private static Dictionary> _xmlCustomSerializer = - new Dictionary>() - { - [MessageCommand.PrintText] = (msgCmd, model) => new XElement("text", model.Serializer(msgCmd)), - }; - - public static XElement SerializeXEntries(IEnumerable entries, IMessageDecode decode, bool ignoreExceptions = false) - { - return new XElement("messages", entries.Select(x => - { - List messageDecoded; - - try - { - messageDecoded = decode.Decode(x.Data); - } - catch (NotImplementedException ex) - { - if (ignoreExceptions) - return new XElement("msgerror", - new XAttribute("id", x.Id), - ex.Message); - else - throw ex; - } - - return SerializeXEntries(x.Id, messageDecoded, ignoreExceptions); ; - })); - } - - public static XElement SerializeXEntries(int id, IEnumerable entries, bool ignoreExceptions = false) - { - var root = new XElement("message", new XAttribute("id", id)); - foreach (var entry in entries) - { - XNode node; - - try - { - if (!_serializer.TryGetValue(entry.Command, out var serializeModel)) - throw new NotImplementedException($"The command {entry.Command} serialization is not implemented yet."); - - if (serializeModel == null) - break; - - if (_xmlCustomSerializer.TryGetValue(entry.Command, out var xmlCustomSerializer)) - node = xmlCustomSerializer(entry, serializeModel); - else - node = GetDefaultSerializer(entry, serializeModel); - } - catch (NotImplementedException ex) - { - if (ignoreExceptions) - node = new XElement("error", ex.Message); - else - throw ex; - } - - root.Add(node); - } - return root; - } - - private static XNode GetDefaultSerializer(MessageCommandModel msgCmd, SerializerModel model) - { - if (model.Serializer == null) - return null; - - var attribute = new XAttribute("value", model.Serializer(msgCmd)); - return attribute != null ? new XElement(model.Name, attribute) : new XElement(model.Name); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Linq; + +namespace OpenKh.Kh2.Messages +{ + public partial class MsgSerializer + { + private static Dictionary> _xmlCustomSerializer = + new Dictionary>() + { + [MessageCommand.PrintText] = (msgCmd, model) => new XElement("text", model.Serializer(msgCmd)), + }; + + public static XElement SerializeXEntries(IEnumerable entries, IMessageDecode decode, bool ignoreExceptions = false) + { + return new XElement("messages", entries.Select(x => + { + List messageDecoded; + + try + { + messageDecoded = decode.Decode(x.Data); + } + catch (NotImplementedException ex) + { + if (ignoreExceptions) + return new XElement("msgerror", + new XAttribute("id", x.Id), + ex.Message); + else + throw ex; + } + + return SerializeXEntries(x.Id, messageDecoded, ignoreExceptions); + ; + })); + } + + public static XElement SerializeXEntries(int id, IEnumerable entries, bool ignoreExceptions = false) + { + var root = new XElement("message", new XAttribute("id", id)); + foreach (var entry in entries) + { + XNode node; + + try + { + if (!_serializer.TryGetValue(entry.Command, out var serializeModel)) + throw new NotImplementedException($"The command {entry.Command} serialization is not implemented yet."); + + if (serializeModel == null) + break; + + if (_xmlCustomSerializer.TryGetValue(entry.Command, out var xmlCustomSerializer)) + node = xmlCustomSerializer(entry, serializeModel); + else + node = GetDefaultSerializer(entry, serializeModel); + } + catch (NotImplementedException ex) + { + if (ignoreExceptions) + node = new XElement("error", ex.Message); + else + throw ex; + } + + root.Add(node); + } + return root; + } + + private static XNode GetDefaultSerializer(MessageCommandModel msgCmd, SerializerModel model) + { + if (model.Serializer == null) + return null; + + var attribute = new XAttribute("value", model.Serializer(msgCmd)); + return attribute != null ? new XElement(model.Name, attribute) : new XElement(model.Name); + } + } +} diff --git a/OpenKh.Kh2/Messages/MsgSerializer.cs b/OpenKh.Kh2/Messages/MsgSerializer.cs index 28e54fec3..2cae4cadd 100644 --- a/OpenKh.Kh2/Messages/MsgSerializer.cs +++ b/OpenKh.Kh2/Messages/MsgSerializer.cs @@ -1,386 +1,386 @@ -using OpenKh.Common.Exceptions; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; - -namespace OpenKh.Kh2.Messages -{ - public partial class MsgSerializer - { - private class SerializerModel - { - public string Name { get; set; } - public MessageCommand Command { get; set; } - public Func Serializer { get; set; } - public Func Deserializer { get; set; } - } - - private static List _serializeModel = new List - { - new SerializerModel - { - Name = "end", - Command = MessageCommand.End - }, - new SerializerModel - { - Name = "text", - Command = MessageCommand.PrintText, - Serializer = x => x.Text, - Deserializer = null - }, - new SerializerModel - { - Name = "complex", - Command = MessageCommand.PrintComplex, - Serializer = x => x.Text, - Deserializer = null - }, - new SerializerModel - { - Name = "tabulation", - Command = MessageCommand.Tabulation, - }, - new SerializerModel - { - Name = "reset", - Command = MessageCommand.Reset, - }, - new SerializerModel - { - Name = "theme", - Command = MessageCommand.Theme, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "unk05", - Command = MessageCommand.Unknown05, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "unk06", - Command = MessageCommand.Unknown06, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "color", - Command = MessageCommand.Color, - Serializer = x => $"#{x.Data[0]:X02}{x.Data[1]:X02}{x.Data[2]:X02}{x.Data[3]:X02}", - Deserializer = x => DeserializeColor(x) - }, - new SerializerModel - { - Name = "unk08", - Command = MessageCommand.Unknown08, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "icon", - Command = MessageCommand.PrintIcon, - Serializer = x => _icons[x.Data[0]], - Deserializer = x => DeserializeIcon(x) - }, - new SerializerModel - { - Name = "scale", - Command = MessageCommand.TextScale, - Serializer = x => x.Data[0].ToString(), - Deserializer = x => DeserializeScale(x) - }, - new SerializerModel - { - Name = "width", - Command = MessageCommand.TextWidth, - Serializer = x => x.Data[0].ToString(), - Deserializer = x => DeserializeWidth(x) - }, - new SerializerModel - { - Name = "linespacing", - Command = MessageCommand.LineSpacing, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "unk0d", - Command = MessageCommand.Unknown0d, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => new byte[0] - }, - new SerializerModel - { - Name = "unk0e", - Command = MessageCommand.Unknown0e, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "unk0f", - Command = MessageCommand.Unknown0f, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "clear", - Command = MessageCommand.Clear, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => new byte[0] - }, - new SerializerModel - { - Name = "position", - Command = MessageCommand.Position, - Serializer = x => ToPosition(x), - Deserializer = x => FromPosition(x) - }, - new SerializerModel - { - Name = "unk12", - Command = MessageCommand.Unknown12, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "unk13", - Command = MessageCommand.Unknown13, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "delay", - Command = MessageCommand.Delay, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "chardelay", - Command = MessageCommand.CharDelay, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "unk16", - Command = MessageCommand.Unknown16, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "delayandfade", - Command = MessageCommand.DelayAndFade, - Serializer = x => ToDelayAndFade(x.Data), - Deserializer = x => FromDelayAndFade(x) - }, - new SerializerModel - { - Name = "unk18", - Command = MessageCommand.Unknown18, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "t2", - Command = MessageCommand.Table2, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "t3", - Command = MessageCommand.Table3, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "t4", - Command = MessageCommand.Table4, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "t5", - Command = MessageCommand.Table5, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "t6", - Command = MessageCommand.Table6, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "t7", - Command = MessageCommand.Table7, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "t8", - Command = MessageCommand.Table8, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - new SerializerModel - { - Name = "unk", - Command = MessageCommand.Unsupported, - Serializer = x => ToStringRawData(x.Data), - Deserializer = x => FromStringToByte(x) - }, - }; - - private static Dictionary _serializer = - _serializeModel.ToDictionary(x => x.Command, x => x); - - private static Dictionary _deserializer = - _serializeModel.ToDictionary(x => x.Name, x => x); - - private static Dictionary _icons = - new Dictionary() - { - [0] = "item-consumable", - [1] = "item-tent", - [2] = "item-key", - [3] = "ability-unequip", - [4] = "weapon-keyblade", - [5] = "weapon-staff", - [6] = "weapon-shield", - [7] = "armor", - [8] = "magic", - [9] = "material", - [10] = "exclamation-mark", - [11] = "question-mark", - [12] = "auto-equip", - [13] = "ability-equip", - [14] = "weapon-keyblade-equip", - [15] = "weapon-staff-equip", - [16] = "weapon-shield-equip", - [17] = "accessory", - [18] = "magic-nocharge", - [19] = "party", - [20] = "button-select", - [21] = "button-start", - [22] = "button-dpad", - [23] = "tranquil", - [24] = "remembrance", - [25] = "form", - [26] = "ai-mode-frequent", - [27] = "ai-mode-moderate", - [28] = "ai-mode-rare", - [29] = "ai-settings", - [30] = "button-r1", - [31] = "button-r2", - [32] = "button-l1", - [33] = "button-l2", - [34] = "button-triangle", - [35] = "button-cross", - [36] = "button-square", - [37] = "button-circle", - [38] = "gem-dark", - [39] = "gem-blaze", - [40] = "gem-frost", - [41] = "gem-lightning", - [42] = "gem-power", - [43] = "gem-lucid", - [44] = "gem-dense", - [45] = "gem-twilight", - [46] = "gem-mythril", - [47] = "gem-bright", - [48] = "gem-energy", - [49] = "gem-serenity", - [50] = "gem-orichalcum", - [51] = "rank-s", - [52] = "rank-a", - [53] = "rank-b", - [54] = "rank-c", - [55] = "gumi-brush", - [56] = "gumi-blueprint", - [57] = "gumi-ship", - [58] = "gumi-block", - [59] = "gumi-gear", - }; - - private static Dictionary _iconsDeserialize = - _icons.ToDictionary(x => x.Value, x => x.Key); - - private static byte[] DeserializeScale(string parameter) => new byte[] { byte.Parse(parameter) }; - private static byte[] DeserializeWidth(string parameter) => new byte[] { byte.Parse(parameter) }; - - private static byte[] FromStringToByte(string parameter) => - parameter.Split(' ').Select(x => byte.Parse(x, NumberStyles.HexNumber)).ToArray(); - - private static byte[] DeserializeColor(string value) - { - if (value[0] == '#') - value = value.Substring(1); - - // horrible piece of crap, but works - return new byte[] - { - byte.Parse(value.Substring(0, 2), NumberStyles.HexNumber), - byte.Parse(value.Substring(2, 2), NumberStyles.HexNumber), - byte.Parse(value.Substring(4, 2), NumberStyles.HexNumber), - byte.Parse(value.Substring(6, 2), NumberStyles.HexNumber), - }; - } - - private static byte[] DeserializeIcon(string value) - { - if (!_iconsDeserialize.TryGetValue(value, out var data)) - throw new ParseException(value, 0, "Icon not supported"); - - return new byte[] { data }; - } - - private static string ToPosition(MessageCommandModel command) => - $"{command.PositionX},{command.PositionY}"; - - private static byte[] FromPosition(string text) - { - var parameters = text.Split(',') - .Select(x => short.TryParse(x.Trim(), out var result) ? result : 0) - .ToArray(); - - var xCoord = parameters.Length > 0 ? parameters[0] : 0; - var yCoord = parameters.Length > 1 ? parameters[1] : 0; - - return new byte[4] - { - (byte)((ushort)xCoord & 0xFF), - (byte)(((ushort)xCoord >> 8) & 0xFF), - (byte)((ushort)yCoord & 0xFF), - (byte)(((ushort)yCoord >> 8) & 0xFF), - }; - } - - private static string ToDelayAndFade(byte[] data) => ToStringRawData(data); - - private static byte[] FromDelayAndFade(string text) => FromStringToByte(text); - - private static string ToStringRawData(byte[] data) => - string.Join(" ", data.Select(x => $"{x:X02}")); - } -} +using OpenKh.Common.Exceptions; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; + +namespace OpenKh.Kh2.Messages +{ + public partial class MsgSerializer + { + private class SerializerModel + { + public string Name { get; set; } + public MessageCommand Command { get; set; } + public Func Serializer { get; set; } + public Func Deserializer { get; set; } + } + + private static List _serializeModel = new List + { + new SerializerModel + { + Name = "end", + Command = MessageCommand.End + }, + new SerializerModel + { + Name = "text", + Command = MessageCommand.PrintText, + Serializer = x => x.Text, + Deserializer = null + }, + new SerializerModel + { + Name = "complex", + Command = MessageCommand.PrintComplex, + Serializer = x => x.Text, + Deserializer = null + }, + new SerializerModel + { + Name = "tabulation", + Command = MessageCommand.Tabulation, + }, + new SerializerModel + { + Name = "reset", + Command = MessageCommand.Reset, + }, + new SerializerModel + { + Name = "theme", + Command = MessageCommand.Theme, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "unk05", + Command = MessageCommand.Unknown05, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "unk06", + Command = MessageCommand.Unknown06, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "color", + Command = MessageCommand.Color, + Serializer = x => $"#{x.Data[0]:X02}{x.Data[1]:X02}{x.Data[2]:X02}{x.Data[3]:X02}", + Deserializer = x => DeserializeColor(x) + }, + new SerializerModel + { + Name = "unk08", + Command = MessageCommand.Unknown08, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "icon", + Command = MessageCommand.PrintIcon, + Serializer = x => _icons[x.Data[0]], + Deserializer = x => DeserializeIcon(x) + }, + new SerializerModel + { + Name = "scale", + Command = MessageCommand.TextScale, + Serializer = x => x.Data[0].ToString(), + Deserializer = x => DeserializeScale(x) + }, + new SerializerModel + { + Name = "width", + Command = MessageCommand.TextWidth, + Serializer = x => x.Data[0].ToString(), + Deserializer = x => DeserializeWidth(x) + }, + new SerializerModel + { + Name = "linespacing", + Command = MessageCommand.LineSpacing, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "unk0d", + Command = MessageCommand.Unknown0d, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => new byte[0] + }, + new SerializerModel + { + Name = "unk0e", + Command = MessageCommand.Unknown0e, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "unk0f", + Command = MessageCommand.Unknown0f, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "clear", + Command = MessageCommand.Clear, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => new byte[0] + }, + new SerializerModel + { + Name = "position", + Command = MessageCommand.Position, + Serializer = x => ToPosition(x), + Deserializer = x => FromPosition(x) + }, + new SerializerModel + { + Name = "unk12", + Command = MessageCommand.Unknown12, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "unk13", + Command = MessageCommand.Unknown13, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "delay", + Command = MessageCommand.Delay, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "chardelay", + Command = MessageCommand.CharDelay, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "unk16", + Command = MessageCommand.Unknown16, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "delayandfade", + Command = MessageCommand.DelayAndFade, + Serializer = x => ToDelayAndFade(x.Data), + Deserializer = x => FromDelayAndFade(x) + }, + new SerializerModel + { + Name = "unk18", + Command = MessageCommand.Unknown18, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "t2", + Command = MessageCommand.Table2, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "t3", + Command = MessageCommand.Table3, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "t4", + Command = MessageCommand.Table4, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "t5", + Command = MessageCommand.Table5, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "t6", + Command = MessageCommand.Table6, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "t7", + Command = MessageCommand.Table7, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "t8", + Command = MessageCommand.Table8, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + new SerializerModel + { + Name = "unk", + Command = MessageCommand.Unsupported, + Serializer = x => ToStringRawData(x.Data), + Deserializer = x => FromStringToByte(x) + }, + }; + + private static Dictionary _serializer = + _serializeModel.ToDictionary(x => x.Command, x => x); + + private static Dictionary _deserializer = + _serializeModel.ToDictionary(x => x.Name, x => x); + + private static Dictionary _icons = + new Dictionary() + { + [0] = "item-consumable", + [1] = "item-tent", + [2] = "item-key", + [3] = "ability-unequip", + [4] = "weapon-keyblade", + [5] = "weapon-staff", + [6] = "weapon-shield", + [7] = "armor", + [8] = "magic", + [9] = "material", + [10] = "exclamation-mark", + [11] = "question-mark", + [12] = "auto-equip", + [13] = "ability-equip", + [14] = "weapon-keyblade-equip", + [15] = "weapon-staff-equip", + [16] = "weapon-shield-equip", + [17] = "accessory", + [18] = "magic-nocharge", + [19] = "party", + [20] = "button-select", + [21] = "button-start", + [22] = "button-dpad", + [23] = "tranquil", + [24] = "remembrance", + [25] = "form", + [26] = "ai-mode-frequent", + [27] = "ai-mode-moderate", + [28] = "ai-mode-rare", + [29] = "ai-settings", + [30] = "button-r1", + [31] = "button-r2", + [32] = "button-l1", + [33] = "button-l2", + [34] = "button-triangle", + [35] = "button-cross", + [36] = "button-square", + [37] = "button-circle", + [38] = "gem-dark", + [39] = "gem-blaze", + [40] = "gem-frost", + [41] = "gem-lightning", + [42] = "gem-power", + [43] = "gem-lucid", + [44] = "gem-dense", + [45] = "gem-twilight", + [46] = "gem-mythril", + [47] = "gem-bright", + [48] = "gem-energy", + [49] = "gem-serenity", + [50] = "gem-orichalcum", + [51] = "rank-s", + [52] = "rank-a", + [53] = "rank-b", + [54] = "rank-c", + [55] = "gumi-brush", + [56] = "gumi-blueprint", + [57] = "gumi-ship", + [58] = "gumi-block", + [59] = "gumi-gear", + }; + + private static Dictionary _iconsDeserialize = + _icons.ToDictionary(x => x.Value, x => x.Key); + + private static byte[] DeserializeScale(string parameter) => new byte[] { byte.Parse(parameter) }; + private static byte[] DeserializeWidth(string parameter) => new byte[] { byte.Parse(parameter) }; + + private static byte[] FromStringToByte(string parameter) => + parameter.Split(' ').Select(x => byte.Parse(x, NumberStyles.HexNumber)).ToArray(); + + private static byte[] DeserializeColor(string value) + { + if (value[0] == '#') + value = value.Substring(1); + + // horrible piece of crap, but works + return new byte[] + { + byte.Parse(value.Substring(0, 2), NumberStyles.HexNumber), + byte.Parse(value.Substring(2, 2), NumberStyles.HexNumber), + byte.Parse(value.Substring(4, 2), NumberStyles.HexNumber), + byte.Parse(value.Substring(6, 2), NumberStyles.HexNumber), + }; + } + + private static byte[] DeserializeIcon(string value) + { + if (!_iconsDeserialize.TryGetValue(value, out var data)) + throw new ParseException(value, 0, "Icon not supported"); + + return new byte[] { data }; + } + + private static string ToPosition(MessageCommandModel command) => + $"{command.PositionX},{command.PositionY}"; + + private static byte[] FromPosition(string text) + { + var parameters = text.Split(',') + .Select(x => short.TryParse(x.Trim(), out var result) ? result : 0) + .ToArray(); + + var xCoord = parameters.Length > 0 ? parameters[0] : 0; + var yCoord = parameters.Length > 1 ? parameters[1] : 0; + + return new byte[4] + { + (byte)((ushort)xCoord & 0xFF), + (byte)(((ushort)xCoord >> 8) & 0xFF), + (byte)((ushort)yCoord & 0xFF), + (byte)(((ushort)yCoord >> 8) & 0xFF), + }; + } + + private static string ToDelayAndFade(byte[] data) => ToStringRawData(data); + + private static byte[] FromDelayAndFade(string text) => FromStringToByte(text); + + private static string ToStringRawData(byte[] data) => + string.Join(" ", data.Select(x => $"{x:X02}")); + } +} diff --git a/OpenKh.Kh2/Mixdata/BaseMixdata.cs b/OpenKh.Kh2/Mixdata/BaseMixdata.cs index 905b53154..baeb30a2a 100644 --- a/OpenKh.Kh2/Mixdata/BaseMixdata.cs +++ b/OpenKh.Kh2/Mixdata/BaseMixdata.cs @@ -1,48 +1,48 @@ -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Mixdata -{ - public class BaseMixdata : IEnumerable - where T : class - { - [Data] public int MagicCode { get; set; } - [Data] public int Version { get; set; } - [Data] public int Count { get; set; } - [Data] public int Padding { get; set; } - [Data] public List Items { get; set; } - - public static BaseMixdata Read(Stream stream) - { - var baseTable = BinaryMapping.ReadObject>(stream); - baseTable.Items = Enumerable.Range(0, baseTable.Count) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList(); - return baseTable; - } - - public static void Write(Stream stream, int magic, int version, List items) => - new BaseMixdata() - { - MagicCode = magic, - Version = version, - Padding = 0, - Items = items - }.Write(stream); - - public void Write(Stream stream) - { - Count = Items.Count; - BinaryMapping.WriteObject(stream, this); - foreach (var item in Items) - BinaryMapping.WriteObject(stream, item); - } - - public IEnumerator GetEnumerator() => Items.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => Items.GetEnumerator(); - } -} +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Mixdata +{ + public class BaseMixdata : IEnumerable + where T : class + { + [Data] public int MagicCode { get; set; } + [Data] public int Version { get; set; } + [Data] public int Count { get; set; } + [Data] public int Padding { get; set; } + [Data] public List Items { get; set; } + + public static BaseMixdata Read(Stream stream) + { + var baseTable = BinaryMapping.ReadObject>(stream); + baseTable.Items = Enumerable.Range(0, baseTable.Count) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList(); + return baseTable; + } + + public static void Write(Stream stream, int magic, int version, List items) => + new BaseMixdata() + { + MagicCode = magic, + Version = version, + Padding = 0, + Items = items + }.Write(stream); + + public void Write(Stream stream) + { + Count = Items.Count; + BinaryMapping.WriteObject(stream, this); + foreach (var item in Items) + BinaryMapping.WriteObject(stream, item); + } + + public IEnumerator GetEnumerator() => Items.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => Items.GetEnumerator(); + } +} diff --git a/OpenKh.Kh2/Mixdata/Cond.cs b/OpenKh.Kh2/Mixdata/Cond.cs index 8985788e2..c4d30da48 100644 --- a/OpenKh.Kh2/Mixdata/Cond.cs +++ b/OpenKh.Kh2/Mixdata/Cond.cs @@ -1,24 +1,24 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Mixdata -{ - public class Cond - { - private const int MagicCode = 0x4F43494D; - - [Data] public ushort Id { get; set; } - [Data] public short Reward { get; set; } //either item from 03system or shop upgrades - [Data] public byte Unk4 { get; set; } - [Data] public byte Unk5 { get; set; } - [Data] public byte Unk6 { get; set; } - [Data] public byte Unk7 { get; set; } - [Data] public short Count { get; set; } - [Data] public short UnkA { get; set; } - - public List Read(Stream stream) => BaseMixdata.Read(stream).Items; - public void Write(Stream stream, int version, IEnumerable items) => BaseMixdata.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Mixdata +{ + public class Cond + { + private const int MagicCode = 0x4F43494D; + + [Data] public ushort Id { get; set; } + [Data] public short Reward { get; set; } //either item from 03system or shop upgrades + [Data] public byte Unk4 { get; set; } + [Data] public byte Unk5 { get; set; } + [Data] public byte Unk6 { get; set; } + [Data] public byte Unk7 { get; set; } + [Data] public short Count { get; set; } + [Data] public short UnkA { get; set; } + + public List Read(Stream stream) => BaseMixdata.Read(stream).Items; + public void Write(Stream stream, int version, IEnumerable items) => BaseMixdata.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/Mixdata/Exp.cs b/OpenKh.Kh2/Mixdata/Exp.cs index 3f97defbe..ce4451c75 100644 --- a/OpenKh.Kh2/Mixdata/Exp.cs +++ b/OpenKh.Kh2/Mixdata/Exp.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Kh2.Mixdata -{ - public class Exp - { - private const int MagicCode = 0x5845494D; - - public List Read(Stream stream) => BaseMixdata.Read(stream).Items; - public void Write(Stream stream, int version, IEnumerable items) => BaseMixdata.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Kh2.Mixdata +{ + public class Exp + { + private const int MagicCode = 0x5845494D; + + public List Read(Stream stream) => BaseMixdata.Read(stream).Items; + public void Write(Stream stream, int version, IEnumerable items) => BaseMixdata.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/Mixdata/Leve.cs b/OpenKh.Kh2/Mixdata/Leve.cs index a63acbf03..b90db66c9 100644 --- a/OpenKh.Kh2/Mixdata/Leve.cs +++ b/OpenKh.Kh2/Mixdata/Leve.cs @@ -1,21 +1,21 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Mixdata -{ - public class Leve - { - private const int MagicCode = 0x564C494D; - - [Data] public ushort Id { get; set; } - [Data] public ushort Unk2 { get; set; } - [Data] public ushort Unk4 { get; set; } - [Data] public ushort Unk6 { get; set; } - [Data] public int Exp { get; set; } - - public List Read(Stream stream) => BaseMixdata.Read(stream).Items; - public void Write(Stream stream, int version, IEnumerable items) => BaseMixdata.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Mixdata +{ + public class Leve + { + private const int MagicCode = 0x564C494D; + + [Data] public ushort Id { get; set; } + [Data] public ushort Unk2 { get; set; } + [Data] public ushort Unk4 { get; set; } + [Data] public ushort Unk6 { get; set; } + [Data] public int Exp { get; set; } + + public List Read(Stream stream) => BaseMixdata.Read(stream).Items; + public void Write(Stream stream, int version, IEnumerable items) => BaseMixdata.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/Mixdata/Reci.cs b/OpenKh.Kh2/Mixdata/Reci.cs index acf4cc139..114fbfb2f 100644 --- a/OpenKh.Kh2/Mixdata/Reci.cs +++ b/OpenKh.Kh2/Mixdata/Reci.cs @@ -1,33 +1,33 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Mixdata -{ - public class Reci - { - private const int MagicCode = 0x4552494D; - - [Data] public ushort Id { get; set; } //03system -> item - [Data] public byte Unk2 { get; set; } - [Data] public byte Unk3 { get; set; } - [Data] public ushort Item { get; set; } - [Data] public ushort UpgradedItem { get; set; } - [Data] public ushort Ingredient1 { get; set; } - [Data] public ushort Ingredient1Amount { get; set; } - [Data] public ushort Ingredient2 { get; set; } - [Data] public ushort Ingredient2Amount { get; set; } - [Data] public ushort Ingredient3 { get; set; } - [Data] public ushort Ingredient3Amount { get; set; } - [Data] public ushort Ingredient4 { get; set; } - [Data] public ushort Ingredient4Amount { get; set; } - [Data] public ushort Ingredient5 { get; set; } - [Data] public ushort Ingredient5Amount { get; set; } - [Data] public ushort Ingredient6 { get; set; } - [Data] public ushort Ingredient6Amount { get; set; } - - public List Read(Stream stream) => BaseMixdata.Read(stream).Items; - public void Write(Stream stream, int version, IEnumerable items) => BaseMixdata.Write(stream, MagicCode, version, items.ToList()); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Mixdata +{ + public class Reci + { + private const int MagicCode = 0x4552494D; + + [Data] public ushort Id { get; set; } //03system -> item + [Data] public byte Unk2 { get; set; } + [Data] public byte Unk3 { get; set; } + [Data] public ushort Item { get; set; } + [Data] public ushort UpgradedItem { get; set; } + [Data] public ushort Ingredient1 { get; set; } + [Data] public ushort Ingredient1Amount { get; set; } + [Data] public ushort Ingredient2 { get; set; } + [Data] public ushort Ingredient2Amount { get; set; } + [Data] public ushort Ingredient3 { get; set; } + [Data] public ushort Ingredient3Amount { get; set; } + [Data] public ushort Ingredient4 { get; set; } + [Data] public ushort Ingredient4Amount { get; set; } + [Data] public ushort Ingredient5 { get; set; } + [Data] public ushort Ingredient5Amount { get; set; } + [Data] public ushort Ingredient6 { get; set; } + [Data] public ushort Ingredient6Amount { get; set; } + + public List Read(Stream stream) => BaseMixdata.Read(stream).Items; + public void Write(Stream stream, int version, IEnumerable items) => BaseMixdata.Write(stream, MagicCode, version, items.ToList()); + } +} diff --git a/OpenKh.Kh2/ModelTexture.cs b/OpenKh.Kh2/ModelTexture.cs index bfd6b72da..eb879a160 100644 --- a/OpenKh.Kh2/ModelTexture.cs +++ b/OpenKh.Kh2/ModelTexture.cs @@ -1,141 +1,141 @@ -using OpenKh.Common; -using OpenKh.Imaging; -using OpenKh.Kh2.TextureFooter; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.Linq; +using OpenKh.Common; +using OpenKh.Imaging; +using OpenKh.Kh2.TextureFooter; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; using System.Text; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2 -{ - public class ModelTexture - { - private class Header - { - [Data] public int MagicCode { get; set; } - [Data] public int ColorCount { get; set; } - [Data] public int TextureInfoCount { get; set; } - [Data] public int GsInfoCount { get; set; } - [Data] public int Offset1 { get; set; } - [Data] public int Texinf1off { get; set; } - [Data] public int Texinf2off { get; set; } - [Data] public int PictureOffset { get; set; } - [Data] public int PaletteOffset { get; set; } - } - - public class Texture : IImageRead - { - private readonly byte[] _data; - private readonly byte[] _palette; - private readonly int _cbp; - private readonly int _csa; - private readonly Tm2.GsPSM _uploadPixelFormat; - - internal Texture( - int width, int height, PixelFormat pixelFormat, Tm2.GsPSM uploadPixelFormat, - byte[] data, byte[] palette, - TextureAddressMode textureAddressMode, int cbp, int csa) - { - Size = new Size(width, height); - PixelFormat = pixelFormat; - _uploadPixelFormat = uploadPixelFormat; - _data = data; - _palette = palette; - TextureAddressMode = textureAddressMode; - _cbp = cbp; - _csa = csa; - } - - public Size Size { get; } - - public PixelFormat PixelFormat { get; } - - public TextureAddressMode TextureAddressMode { get; } - - public byte[] GetClut() - { - switch (PixelFormat) - { - case PixelFormat.Indexed8: - return GetClut8(_palette, _cbp, _csa); - case PixelFormat.Indexed4: - return GetClut4(_palette, _cbp, _csa); - default: - throw new NotSupportedException($"The format {PixelFormat} is not supported or does not contain any palette."); - } - } - - public byte[] GetData() - { - switch (PixelFormat) - { - case PixelFormat.Rgba8888: - case PixelFormat.Rgbx8888: - return GetData32bpp(_data); - case PixelFormat.Indexed8: - if (_uploadPixelFormat == Tm2.GsPSM.GS_PSMCT32) - return Ps2.Decode8(Ps2.Encode32(_data, Size.Width / 128, Size.Height / 64), Size.Width / 128, Size.Height / 64); - return _data; - case PixelFormat.Indexed4: - if (_uploadPixelFormat == Tm2.GsPSM.GS_PSMCT32) - return Ps2.Decode4(Ps2.Encode32(_data, Size.Width / 128, Size.Height / 128), Size.Width / 128, Size.Height / 128); - return _data; - default: - throw new NotSupportedException($"The format {PixelFormat} is not supported."); - } - } - } - - private class DataTransferInfo +using Xe.BinaryMapper; + +namespace OpenKh.Kh2 +{ + public class ModelTexture + { + private class Header + { + [Data] public int MagicCode { get; set; } + [Data] public int ColorCount { get; set; } + [Data] public int TextureInfoCount { get; set; } + [Data] public int GsInfoCount { get; set; } + [Data] public int Offset1 { get; set; } + [Data] public int Texinf1off { get; set; } + [Data] public int Texinf2off { get; set; } + [Data] public int PictureOffset { get; set; } + [Data] public int PaletteOffset { get; set; } + } + + public class Texture : IImageRead + { + private readonly byte[] _data; + private readonly byte[] _palette; + private readonly int _cbp; + private readonly int _csa; + private readonly Tm2.GsPSM _uploadPixelFormat; + + internal Texture( + int width, int height, PixelFormat pixelFormat, Tm2.GsPSM uploadPixelFormat, + byte[] data, byte[] palette, + TextureAddressMode textureAddressMode, int cbp, int csa) + { + Size = new Size(width, height); + PixelFormat = pixelFormat; + _uploadPixelFormat = uploadPixelFormat; + _data = data; + _palette = palette; + TextureAddressMode = textureAddressMode; + _cbp = cbp; + _csa = csa; + } + + public Size Size { get; } + + public PixelFormat PixelFormat { get; } + + public TextureAddressMode TextureAddressMode { get; } + + public byte[] GetClut() + { + switch (PixelFormat) + { + case PixelFormat.Indexed8: + return GetClut8(_palette, _cbp, _csa); + case PixelFormat.Indexed4: + return GetClut4(_palette, _cbp, _csa); + default: + throw new NotSupportedException($"The format {PixelFormat} is not supported or does not contain any palette."); + } + } + + public byte[] GetData() + { + switch (PixelFormat) + { + case PixelFormat.Rgba8888: + case PixelFormat.Rgbx8888: + return GetData32bpp(_data); + case PixelFormat.Indexed8: + if (_uploadPixelFormat == Tm2.GsPSM.GS_PSMCT32) + return Ps2.Decode8(Ps2.Encode32(_data, Size.Width / 128, Size.Height / 64), Size.Width / 128, Size.Height / 64); + return _data; + case PixelFormat.Indexed4: + if (_uploadPixelFormat == Tm2.GsPSM.GS_PSMCT32) + return Ps2.Decode4(Ps2.Encode32(_data, Size.Width / 128, Size.Height / 128), Size.Width / 128, Size.Height / 128); + return _data; + default: + throw new NotSupportedException($"The format {PixelFormat} is not supported."); + } + } + } + + private class DataTransferInfo { public DataTransferInfo() { } - public BITBLTBUF BitBltBuf { get; set; } + public BITBLTBUF BitBltBuf { get; set; } public TRXPOS TrxPos { get; set; } - public TRXREG TrxReg { get; set; } - public TRXDIR TrxDir { get; set; } - public int DataOffset { get; set; } - - public int QuadWordCount { get; set; } - } - - private class _DataTransfer - { - [Data] public int Data00 { get; set; } - [Data] public int Data04 { get; set; } - [Data] public int Data08 { get; set; } - [Data] public int Data0c { get; set; } - [Data] public int Data10 { get; set; } - [Data] public int Data14 { get; set; } - [Data] public int Data18 { get; set; } - [Data] public int Data1c { get; set; } - [Data] public BITBLTBUF BitBltBuf { get; set; } - [Data] public long GSReg50 { get; set; } - [Data] public TRXPOS TrxPos { get; set; } - [Data] public long GSReg51 { get; set; } - [Data] public TRXREG TrxReg { get; set; } - [Data] public long GSReg52 { get; set; } - [Data] public TRXDIR TrxDir { get; set; } - [Data] public long GSReg53 { get; set; } - [Data] public int Data60 { get; set; } - [Data] public int Data64 { get; set; } - [Data] public int Data68 { get; set; } - [Data] public int Data6c { get; set; } - [Data] public int Data70 { get; set; } - [Data] public int DataOffset { get; set; } - [Data] public int Data78 { get; set; } - [Data] public int Data7c { get; set; } - [Data] public int Data80 { get; set; } - [Data] public int Data84 { get; set; } - [Data] public int Data88 { get; set; } - [Data] public int Data8c { get; set; } - + public TRXREG TrxReg { get; set; } + public TRXDIR TrxDir { get; set; } + public int DataOffset { get; set; } + + public int QuadWordCount { get; set; } + } + + private class _DataTransfer + { + [Data] public int Data00 { get; set; } + [Data] public int Data04 { get; set; } + [Data] public int Data08 { get; set; } + [Data] public int Data0c { get; set; } + [Data] public int Data10 { get; set; } + [Data] public int Data14 { get; set; } + [Data] public int Data18 { get; set; } + [Data] public int Data1c { get; set; } + [Data] public BITBLTBUF BitBltBuf { get; set; } + [Data] public long GSReg50 { get; set; } + [Data] public TRXPOS TrxPos { get; set; } + [Data] public long GSReg51 { get; set; } + [Data] public TRXREG TrxReg { get; set; } + [Data] public long GSReg52 { get; set; } + [Data] public TRXDIR TrxDir { get; set; } + [Data] public long GSReg53 { get; set; } + [Data] public int Data60 { get; set; } + [Data] public int Data64 { get; set; } + [Data] public int Data68 { get; set; } + [Data] public int Data6c { get; set; } + [Data] public int Data70 { get; set; } + [Data] public int DataOffset { get; set; } + [Data] public int Data78 { get; set; } + [Data] public int Data7c { get; set; } + [Data] public int Data80 { get; set; } + [Data] public int Data84 { get; set; } + [Data] public int Data88 { get; set; } + [Data] public int Data8c { get; set; } + public int QuadWordCount => Data60 & 0x7FFF; public DataTransferInfo ToInfo() => new DataTransferInfo @@ -145,58 +145,58 @@ private class _DataTransfer TrxReg = TrxReg, TrxDir = TrxDir, DataOffset = DataOffset, - QuadWordCount = QuadWordCount, + QuadWordCount = QuadWordCount, }; - } - - public class GsInfo - { - public MIPTBP1 MipTbp1 { get; set; } - public MIPTBP2 MipTbp2 { get; set; } - public Tm2.GsTex Tex2 { get; set; } - public TEX1 Tex1 { get; set; } - public Tm2.GsTex Tex0 { get; set; } - public TextureAddressMode AddressMode { get; set; } - } - - private class _GsInfo - { - [Data] public long Data00 { get; set; } - [Data] public long Data08 { get; set; } - [Data] public long Data10 { get; set; } - [Data] public long Data18 { get; set; } - [Data] public long TexFlush { get; set; } - [Data] public long GSReg3F { get; set; } - [Data] public MIPTBP1 MipTbp1 { get; set; } - [Data] public long GSReg34 { get; set; } - [Data] public MIPTBP2 MipTbp2 { get; set; } - [Data] public long GSReg36 { get; set; } - [Data] public Tm2.GsTex Tex2 { get; set; } - [Data] public long GSReg16 { get; set; } - [Data] public TEX1 Tex1 { get; set; } - [Data] public long GSReg14 { get; set; } - [Data] public Tm2.GsTex Tex0 { get; set; } - [Data] public long GSReg06 { get; set; } - [Data] public CLAMP Clamp { get; set; } - [Data] public long Data88 { get; set; } - [Data] public long Data90 { get; set; } - [Data] public long Data98 { get; set; } - } - - public enum TextureWrapMode - { - Repeat, Clamp, RegionClamp, RegionRepeat - } - - public class TextureAddressMode - { - public TextureWrapMode AddressU { get; set; } - public TextureWrapMode AddressV { get; set; } - public int Left { get; set; } - public int Top { get; set; } - public int Right { get; set; } - public int Bottom { get; set; } + } + + public class GsInfo + { + public MIPTBP1 MipTbp1 { get; set; } + public MIPTBP2 MipTbp2 { get; set; } + public Tm2.GsTex Tex2 { get; set; } + public TEX1 Tex1 { get; set; } + public Tm2.GsTex Tex0 { get; set; } + public TextureAddressMode AddressMode { get; set; } + } + + private class _GsInfo + { + [Data] public long Data00 { get; set; } + [Data] public long Data08 { get; set; } + [Data] public long Data10 { get; set; } + [Data] public long Data18 { get; set; } + [Data] public long TexFlush { get; set; } + [Data] public long GSReg3F { get; set; } + [Data] public MIPTBP1 MipTbp1 { get; set; } + [Data] public long GSReg34 { get; set; } + [Data] public MIPTBP2 MipTbp2 { get; set; } + [Data] public long GSReg36 { get; set; } + [Data] public Tm2.GsTex Tex2 { get; set; } + [Data] public long GSReg16 { get; set; } + [Data] public TEX1 Tex1 { get; set; } + [Data] public long GSReg14 { get; set; } + [Data] public Tm2.GsTex Tex0 { get; set; } + [Data] public long GSReg06 { get; set; } + [Data] public CLAMP Clamp { get; set; } + [Data] public long Data88 { get; set; } + [Data] public long Data90 { get; set; } + [Data] public long Data98 { get; set; } + } + + public enum TextureWrapMode + { + Repeat, Clamp, RegionClamp, RegionRepeat + } + + public class TextureAddressMode + { + public TextureWrapMode AddressU { get; set; } + public TextureWrapMode AddressV { get; set; } + public int Left { get; set; } + public int Top { get; set; } + public int Right { get; set; } + public int Bottom { get; set; } } public class BITBLTBUF @@ -294,7 +294,7 @@ public TEX1() { } public int L { get => GetBits(Data, 19, 2); set => Data = SetBits(Data, 19, 2, value); } public int K { get => GetBits(Data, 32, 12); set => Data = SetBits(Data, 32, 12, value); } } - + public class CLAMP { [Data] public long Data { get; set; } @@ -389,93 +389,93 @@ public ClutAlloc Allocate(bool isIndexed4) return entry; } } - - private const int MagicCode = 0; - private const int HeaderLength = 0x24; - - private DataTransferInfo _clutTransfer; - private List _textureTransfer; - private List _gsInfo; - + + private const int MagicCode = 0; + private const int HeaderLength = 0x24; + + private DataTransferInfo _clutTransfer; + private List _textureTransfer; + private List _gsInfo; + /// /// 0x74 of DataTransfer will be relative to offset from zero position. /// private bool _useRelativeOffset; - - public List Images { get; } - - private byte[] OffsetData { get; } - private byte[] PictureData { get; } - private byte[] PaletteData { get; } - - public TextureFooterData TextureFooterData { get; } + + public List Images { get; } + + private byte[] OffsetData { get; } + private byte[] PictureData { get; } + private byte[] PaletteData { get; } + + public TextureFooterData TextureFooterData { get; } private const int ClutBasePtr = 0x2C00; private const int TexBasePtr = 0x3000; - private ModelTexture(Stream stream) - { - var header = BinaryMapping.ReadObject
(stream.SetPosition(0)); - if (header.MagicCode == -1) - return; - - var offset1Size = header.Texinf1off - header.Offset1; - var Texinf2offSize = header.PictureOffset - header.Texinf2off; - var pictureSize = header.PaletteOffset - header.PictureOffset; - var paletteSize = header.ColorCount * 4; - var footerSize = (int)stream.Length - (header.PaletteOffset + paletteSize); - if (footerSize < 0) - throw new NotFiniteNumberException("Invalid texture"); - - stream.Position = header.Offset1; - OffsetData = stream.ReadBytes(header.GsInfoCount); - - stream.Position = header.Texinf1off; - _clutTransfer = BinaryMapping.ReadObject<_DataTransfer>(stream).ToInfo(); - _textureTransfer = Enumerable.Range(0, header.TextureInfoCount) - .Select(_ => BinaryMapping.ReadObject<_DataTransfer>(stream).ToInfo()) - .ToList(); - - stream.Position = header.Texinf2off; - _gsInfo = Enumerable.Range(0, header.GsInfoCount) - .Select(_ => BinaryMapping.ReadObject<_GsInfo>(stream)) - .Select(x => new GsInfo - { - MipTbp1 = x.MipTbp1, - MipTbp2 = x.MipTbp2, - Tex2 = x.Tex2, - Tex1 = x.Tex1, - Tex0 = x.Tex0, - AddressMode = ClampFromGs(x.Clamp.Data), - }) - .ToList(); - - stream.Position = header.PictureOffset; - PictureData = stream.ReadBytes(pictureSize); - - stream.Position = header.PaletteOffset; - PaletteData = stream.ReadBytes(paletteSize); - - TextureFooterData = TextureFooterData.Read(stream); - - var paletteBaseOffset = _clutTransfer.BitBltBuf.DBP; - - Images = new List(); - for (var i = 0; i < header.GsInfoCount; i++) - { - var texInfo = _textureTransfer[OffsetData[i]]; - var gsInfo = _gsInfo[i]; - var gsTex = gsInfo.Tex0; - - var width = 1 << gsTex.TW; - var height = 1 << gsTex.TH; - var pixelFormat = GetPixelFormat(gsTex.PSM); - var uploadPixelFormat = (Tm2.GsPSM)texInfo.BitBltBuf.DPSM; - var dataLength = width * height / (pixelFormat == PixelFormat.Indexed4 ? 2 : 1); - var data = stream.SetPosition(texInfo.DataOffset).ReadBytes(dataLength); - - Images.Add(new Texture(width, height, pixelFormat, uploadPixelFormat, data, PaletteData, gsInfo.AddressMode, gsTex.CBP - paletteBaseOffset, gsTex.CSA)); - } + private ModelTexture(Stream stream) + { + var header = BinaryMapping.ReadObject
(stream.SetPosition(0)); + if (header.MagicCode == -1) + return; + + var offset1Size = header.Texinf1off - header.Offset1; + var Texinf2offSize = header.PictureOffset - header.Texinf2off; + var pictureSize = header.PaletteOffset - header.PictureOffset; + var paletteSize = header.ColorCount * 4; + var footerSize = (int)stream.Length - (header.PaletteOffset + paletteSize); + if (footerSize < 0) + throw new NotFiniteNumberException("Invalid texture"); + + stream.Position = header.Offset1; + OffsetData = stream.ReadBytes(header.GsInfoCount); + + stream.Position = header.Texinf1off; + _clutTransfer = BinaryMapping.ReadObject<_DataTransfer>(stream).ToInfo(); + _textureTransfer = Enumerable.Range(0, header.TextureInfoCount) + .Select(_ => BinaryMapping.ReadObject<_DataTransfer>(stream).ToInfo()) + .ToList(); + + stream.Position = header.Texinf2off; + _gsInfo = Enumerable.Range(0, header.GsInfoCount) + .Select(_ => BinaryMapping.ReadObject<_GsInfo>(stream)) + .Select(x => new GsInfo + { + MipTbp1 = x.MipTbp1, + MipTbp2 = x.MipTbp2, + Tex2 = x.Tex2, + Tex1 = x.Tex1, + Tex0 = x.Tex0, + AddressMode = ClampFromGs(x.Clamp.Data), + }) + .ToList(); + + stream.Position = header.PictureOffset; + PictureData = stream.ReadBytes(pictureSize); + + stream.Position = header.PaletteOffset; + PaletteData = stream.ReadBytes(paletteSize); + + TextureFooterData = TextureFooterData.Read(stream); + + var paletteBaseOffset = _clutTransfer.BitBltBuf.DBP; + + Images = new List(); + for (var i = 0; i < header.GsInfoCount; i++) + { + var texInfo = _textureTransfer[OffsetData[i]]; + var gsInfo = _gsInfo[i]; + var gsTex = gsInfo.Tex0; + + var width = 1 << gsTex.TW; + var height = 1 << gsTex.TH; + var pixelFormat = GetPixelFormat(gsTex.PSM); + var uploadPixelFormat = (Tm2.GsPSM)texInfo.BitBltBuf.DPSM; + var dataLength = width * height / (pixelFormat == PixelFormat.Indexed4 ? 2 : 1); + var data = stream.SetPosition(texInfo.DataOffset).ReadBytes(dataLength); + + Images.Add(new Texture(width, height, pixelFormat, uploadPixelFormat, data, PaletteData, gsInfo.AddressMode, gsTex.CBP - paletteBaseOffset, gsTex.CSA)); + } } public class Build @@ -483,16 +483,16 @@ public class Build public IList images; public byte[] offsetData; public IList textureTransfer; - public IList gsInfo; - public byte[] footerData; + public IList gsInfo; + public byte[] footerData; } public class UserDataTransferInfo { - public BITBLTBUF BitBltBuf { get; set; } = new BITBLTBUF(); + public BITBLTBUF BitBltBuf { get; set; } = new BITBLTBUF(); public TRXPOS TrxPos { get; set; } = new TRXPOS(); - public TRXREG TrxReg { get; set; } = new TRXREG(); - public TRXDIR TrxDir { get; set; } = new TRXDIR(); + public TRXREG TrxReg { get; set; } = new TRXREG(); + public TRXDIR TrxDir { get; set; } = new TRXDIR(); public UserDataTransferInfo() { @@ -694,9 +694,9 @@ private static Tm2.GsPSM ToPSM(PixelFormat pixelFormat) { switch (pixelFormat) { - case PixelFormat.Indexed4: + case PixelFormat.Indexed4: return Tm2.GsPSM.GS_PSMT4; - case PixelFormat.Indexed8: + case PixelFormat.Indexed8: return Tm2.GsPSM.GS_PSMT8; } throw new NotSupportedException(); @@ -782,14 +782,14 @@ public void Write(Stream stream) var paletteOffset = (int)stream.Position; stream.Write(PaletteData); - - if (TextureFooterData != null) - { - TextureFooterData.Write(stream); - } - else - { - stream.Write(Encoding.ASCII.GetBytes("_KN5")); + + if (TextureFooterData != null) + { + TextureFooterData.Write(stream); + } + else + { + stream.Write(Encoding.ASCII.GetBytes("_KN5")); } var writer = new BinaryWriter(stream.SetPosition(0)); @@ -869,9 +869,9 @@ private static PixelFormat GetPixelFormat(Tm2.GsPSM psm) { switch (psm) { - case Tm2.GsPSM.GS_PSMT8: + case Tm2.GsPSM.GS_PSMT8: return PixelFormat.Indexed8; - case Tm2.GsPSM.GS_PSMT4: + case Tm2.GsPSM.GS_PSMT4: return PixelFormat.Indexed4; default: throw new NotSupportedException($"GsPSM format {psm} not supported"); @@ -966,6 +966,6 @@ private static long SetBits(long Data, int position, int size, int value) { var mask = (1 << size) - 1U; return Data & ~(mask << position) | ((value & mask) << position); - } - } -} + } + } +} diff --git a/OpenKh.Kh2/Models/BobDescriptor.cs b/OpenKh.Kh2/Models/BobDescriptor.cs index 320aeda5a..ed0aad115 100644 --- a/OpenKh.Kh2/Models/BobDescriptor.cs +++ b/OpenKh.Kh2/Models/BobDescriptor.cs @@ -1,71 +1,71 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.Models -{ - public class BobDescriptor - { - private const int Identifier = 8; - - [Data] public float PositionX { get; set; } - [Data] public float PositionY { get; set; } - [Data] public float PositionZ { get; set; } - [Data] public float RotationX { get; set; } - [Data] public float RotationY { get; set; } - [Data] public float RotationZ { get; set; } - [Data] public float ScalingX { get; set; } - [Data] public float ScalingY { get; set; } - [Data] public float ScalingZ { get; set; } - [Data] public int BobIndex { get; set; } - [Data] public int Unknown28 { get; set; } - [Data] public int Unknown2c { get; set; } - [Data] public int Unknown30 { get; set; } - [Data] public int Unknown34 { get; set; } - [Data] public float Unknown38 { get; set; } - [Data] public float Unknown3c { get; set; } - [Data] public float Unknown40 { get; set; } - [Data] public float Unknown44 { get; set; } - [Data] public float Unknown48 { get; set; } - [Data] public float Unknown4c { get; set; } - [Data] public float Unknown50 { get; set; } - [Data] public float Unknown54 { get; set; } - [Data] public float Unknown58 { get; set; } - [Data] public float Unknown5c { get; set; } - [Data] public float Unknown60 { get; set; } - [Data] public float Unknown64 { get; set; } - - public override string ToString() => - $"POS({PositionX:F0}, {PositionY:F0},{PositionZ:F0}) " + - $"ROT({RotationX:F0}, {RotationY:F0},{RotationZ:F0}) " + - $"SCA({ScalingX:F0}, {ScalingY:F0},{ScalingZ:F0}) " + - $"IDX({BobIndex}"; - - public static bool IsValid(Stream stream) => - stream.ReadInt32() == Identifier; - - public static List Read(Stream stream) - { - var id = stream.ReadInt32(); - if (id != Identifier) - throw new InvalidDataException($"Expected {Identifier} as identifier but found {id}"); - - var entryCount = stream.ReadInt32() / 0x68; - return Enumerable.Range(0, entryCount) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList(); - } - - public static void Write(Stream stream, IEnumerable bobDescriptors) - { - var items = bobDescriptors.ToList(); - - stream.Write(8); - stream.Write(items.Count * 0x68); - foreach (var item in bobDescriptors) - BinaryMapping.WriteObject(stream, item); - } - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.Models +{ + public class BobDescriptor + { + private const int Identifier = 8; + + [Data] public float PositionX { get; set; } + [Data] public float PositionY { get; set; } + [Data] public float PositionZ { get; set; } + [Data] public float RotationX { get; set; } + [Data] public float RotationY { get; set; } + [Data] public float RotationZ { get; set; } + [Data] public float ScalingX { get; set; } + [Data] public float ScalingY { get; set; } + [Data] public float ScalingZ { get; set; } + [Data] public int BobIndex { get; set; } + [Data] public int Unknown28 { get; set; } + [Data] public int Unknown2c { get; set; } + [Data] public int Unknown30 { get; set; } + [Data] public int Unknown34 { get; set; } + [Data] public float Unknown38 { get; set; } + [Data] public float Unknown3c { get; set; } + [Data] public float Unknown40 { get; set; } + [Data] public float Unknown44 { get; set; } + [Data] public float Unknown48 { get; set; } + [Data] public float Unknown4c { get; set; } + [Data] public float Unknown50 { get; set; } + [Data] public float Unknown54 { get; set; } + [Data] public float Unknown58 { get; set; } + [Data] public float Unknown5c { get; set; } + [Data] public float Unknown60 { get; set; } + [Data] public float Unknown64 { get; set; } + + public override string ToString() => + $"POS({PositionX:F0}, {PositionY:F0},{PositionZ:F0}) " + + $"ROT({RotationX:F0}, {RotationY:F0},{RotationZ:F0}) " + + $"SCA({ScalingX:F0}, {ScalingY:F0},{ScalingZ:F0}) " + + $"IDX({BobIndex}"; + + public static bool IsValid(Stream stream) => + stream.ReadInt32() == Identifier; + + public static List Read(Stream stream) + { + var id = stream.ReadInt32(); + if (id != Identifier) + throw new InvalidDataException($"Expected {Identifier} as identifier but found {id}"); + + var entryCount = stream.ReadInt32() / 0x68; + return Enumerable.Range(0, entryCount) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList(); + } + + public static void Write(Stream stream, IEnumerable bobDescriptors) + { + var items = bobDescriptors.ToList(); + + stream.Write(8); + stream.Write(items.Count * 0x68); + foreach (var item in bobDescriptors) + BinaryMapping.WriteObject(stream, item); + } + } +} diff --git a/OpenKh.Kh2/Motion.cs b/OpenKh.Kh2/Motion.cs index 896aa5793..7d913c646 100644 --- a/OpenKh.Kh2/Motion.cs +++ b/OpenKh.Kh2/Motion.cs @@ -1,762 +1,762 @@ -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Numerics; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2 -{ - public class Motion - { - private class PoolValues - { - private readonly Dictionary _valuePool = new Dictionary(); - private readonly List _valueList = new List(); - - public List Values => _valueList; - - public PoolValues() - { - - } - - public PoolValues(IEnumerable values) - { - var index = 0; - foreach (var value in values) - { - _valuePool.Add(value, index++); - _valueList.Add(value); - } - } - - public int GetIndex(T value) - { - if (_valuePool.TryGetValue(value, out var index)) - return index; - - index = _valueList.Count; - _valuePool.Add(value, index); - _valueList.Add(value); - - return index; - } - } - - private const int ReservedSize = 0x90; - private const int Matrix4x4Size = 0x40; - private static readonly string[] Transforms = new[] - { - "Scale.X", "Scale.Y", "Scale.Z", - "Rotation.X", "Rotation.Y", "Rotation.Z", - "Translation.X", "Translation.Y", "Translation.Z", - }; - - public enum Interpolation - { - Zero = -1, // default - Nearest, - Linear, - Hermite, - Hermite3, // unused? - Hermite4, // unused? - } - - private class Header - { - [Data] public int Version { get; set; } - [Data] public int Unk04 { get; set; } - [Data] public int ByteCount { get; set; } - [Data] public int Unk0c { get; set; } - } - - private class RawMotionInternal - { - [Data] public int BoneCount { get; set; } - [Data] public int Unk14 { get; set; } - [Data] public int Unk18 { get; set; } - [Data] public int Unk1c { get; set; } - [Data] public int FrameCountPerLoop { get; set; } - [Data] public int TotalFrameCount { get; set; } - [Data] public int Unk28 { get; set; } - [Data] public int Unk2c { get; set; } - [Data] public float BoundingBoxMinX { get; set; } - [Data] public float BoundingBoxMinY { get; set; } - [Data] public float BoundingBoxMinZ { get; set; } - [Data] public float BoundingBoxMinW { get; set; } - [Data] public float BoundingBoxMaxX { get; set; } - [Data] public float BoundingBoxMaxY { get; set; } - [Data] public float BoundingBoxMaxZ { get; set; } - [Data] public float BoundingBoxMaxW { get; set; } - [Data] public float FrameLoop { get; set; } - [Data] public float FrameEnd { get; set; } - [Data] public float FramePerSecond { get; set; } - [Data] public float FrameCount { get; set; } - - public List Matrices { get; set; } - } - - public class RawMotion - { - public int BoneCount { get; set; } - public int Unk28 { get; set; } - public int Unk2c { get; set; } - public float BoundingBoxMinX { get; set; } - public float BoundingBoxMinY { get; set; } - public float BoundingBoxMinZ { get; set; } - public float BoundingBoxMinW { get; set; } - public float BoundingBoxMaxX { get; set; } - public float BoundingBoxMaxY { get; set; } - public float BoundingBoxMaxZ { get; set; } - public float BoundingBoxMaxW { get; set; } - public float FrameLoop { get; set; } - public float FrameEnd { get; set; } - public float FramePerSecond { get; set; } - public float FrameCount { get; set; } - - public List Matrices { get; set; } - public Matrix4x4[] Matrices2 { get; set; } - } - - private class InterpolatedMotionInternal - { - [Data] public short BoneCount { get; set; } - [Data] public short TotalBoneCount { get; set; } - [Data] public int TotalFrameCount { get; set; } - [Data] public int IKHelperOffset { get; set; } - [Data] public int JointIndexOffset { get; set; } - [Data] public int KeyFrameCount { get; set; } - [Data] public int StaticPoseOffset { get; set; } - [Data] public int StaticPoseCount { get; set; } - [Data] public int FooterOffset { get; set; } - [Data] public int ModelBoneAnimationOffset { get; set; } - [Data] public int ModelBoneAnimationCount { get; set; } - [Data] public int IKHelperAnimationOffset { get; set; } - [Data] public int IKHelperAnimationCount { get; set; } - [Data] public int TimelineOffset { get; set; } - [Data] public int KeyFrameOffset { get; set; } - [Data] public int TransformationValueOffset { get; set; } - [Data] public int TangentOffset { get; set; } - [Data] public int IKChainOffset { get; set; } - [Data] public int IKChainCount { get; set; } - [Data] public int Unk48 { get; set; } - [Data] public int Table8Offset { get; set; } - [Data] public int Table7Offset { get; set; } - [Data] public int Table7Count { get; set; } - [Data] public int Table6Offset { get; set; } - [Data] public int Table6Count { get; set; } - [Data] public float BoundingBoxMinX { get; set; } - [Data] public float BoundingBoxMinY { get; set; } - [Data] public float BoundingBoxMinZ { get; set; } - [Data] public float BoundingBoxMinW { get; set; } - [Data] public float BoundingBoxMaxX { get; set; } - [Data] public float BoundingBoxMaxY { get; set; } - [Data] public float BoundingBoxMaxZ { get; set; } - [Data] public float BoundingBoxMaxW { get; set; } - [Data] public float FrameLoop { get; set; } - [Data] public float FrameEnd { get; set; } - [Data] public float FramePerSecond { get; set; } - [Data] public float FrameCount { get; set; } - [Data] public int UnknownTable1Offset { get; set; } - [Data] public int UnknownTable1Count { get; set; } - [Data] public int Unk98 { get; set; } - [Data] public int Unk9c { get; set; } - } - - public class InterpolatedMotion - { - public short BoneCount { get; set; } - public int TotalFrameCount { get; set; } - public int Unk48 { get; set; } - public float BoundingBoxMinX { get; set; } - public float BoundingBoxMinY { get; set; } - public float BoundingBoxMinZ { get; set; } - public float BoundingBoxMinW { get; set; } - public float BoundingBoxMaxX { get; set; } - public float BoundingBoxMaxY { get; set; } - public float BoundingBoxMaxZ { get; set; } - public float BoundingBoxMaxW { get; set; } - public float FrameLoop { get; set; } - public float FrameEnd { get; set; } - public float FramePerSecond { get; set; } - public float FrameCount { get; set; } - public int Unk98 { get; set; } - public int Unk9c { get; set; } - - public List StaticPose { get; set; } - public List ModelBoneAnimation { get; set; } - public List IKHelperAnimation { get; set; } - public List Timeline { get; set; } - public List IKChains { get; set; } - public List Table8 { get; set; } - public List Table7 { get; set; } - public List Table6 { get; set; } - public List IKHelpers { get; set; } - public List Joints { get; set; } - public FooterTable Footer { get; set; } - } - - public class StaticPoseTable - { - [Data] public short BoneIndex { get; set; } - [Data] public short Channel { get; set; } - [Data] public float Value { get; set; } - - public override string ToString() => - $"{BoneIndex} {Transforms[Channel]} {Value}"; - } - - public class BoneAnimationTableInternal - { - [Data] public short JointIndex { get; set; } - [Data] public byte Channel { get; set; } - [Data] public byte TimelineCount { get; set; } - [Data] public short TimelineStartIndex { get; set; } - - public override string ToString() => - $"{JointIndex} {Transforms[Channel]} ({TimelineStartIndex},{TimelineCount})"; - } - - public class BoneAnimationTable - { - public short JointIndex { get; set; } - public byte Channel { get; set; } - public byte Pre { get; set; } - public byte Post { get; set; } - public byte TimelineCount { get; set; } - public short TimelineStartIndex { get; set; } - - public override string ToString() => - $"{JointIndex} {Transforms[Channel]} ({Pre},{Post}) ({TimelineStartIndex},{TimelineCount})"; - } - - private class TimelineTableInternal - { - [Data] public short Time { get; set; } - [Data] public short ValueIndex { get; set; } - [Data] public short TangentIndexEaseIn { get; set; } - [Data] public short TangentIndexEaseOut { get; set; } - } - - public class TimelineTable - { - public Interpolation Interpolation { get; set; } - public float KeyFrame { get; set; } - public float Value { get; set; } - public float TangentEaseIn { get; set; } - public float TangentEaseOut { get; set; } - - public override string ToString() => - $"{KeyFrame} {Value} {Interpolation}:({TangentEaseIn},{TangentEaseOut})"; - } - - public class IKChainTable - { - [Data] public byte Unk00 { get; set; } - [Data] public byte Unk01 { get; set; } - [Data] public short ModelBoneIndex { get; set; } - [Data] public short IKHelperIndex { get; set; } - [Data] public short Table8Index { get; set; } - [Data] public int Unk08 { get; set; } - } - - public class UnknownTable8 - { - [Data] public int Unk00 { get; set; } - [Data] public float Unk04 { get; set; } - [Data] public float Unk08 { get; set; } - [Data] public float Unk0c { get; set; } - [Data] public float Unk10 { get; set; } - [Data] public float Unk14 { get; set; } - [Data] public float Unk18 { get; set; } - [Data] public float Unk1c { get; set; } - [Data] public float Unk20 { get; set; } - [Data] public float Unk24 { get; set; } - [Data] public float Unk28 { get; set; } - [Data] public float Unk2c { get; set; } - } - - public class UnknownTable7 - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public float Unk04 { get; set; } - } - - public class UnknownTable6 - { - [Data] public short Unk00 { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public float Unk04 { get; set; } - [Data] public short Unk08 { get; set; } - [Data] public short Unk0a { get; set; } - } - - public class JointTable - { - [Data] public short JointIndex { get; set; } - [Data] public short Flag { get; set; } - } - - public class IKHelperTable - { - [Data] public int Index { get; set; } - [Data] public int ParentIndex { get; set; } - [Data] public int Unk08 { get; set; } - [Data] public int Unk0c { get; set; } - [Data] public float ScaleX { get; set; } - [Data] public float ScaleY { get; set; } - [Data] public float ScaleZ { get; set; } - [Data] public float ScaleW { get; set; } - [Data] public float RotateX { get; set; } - [Data] public float RotateY { get; set; } - [Data] public float RotateZ { get; set; } - [Data] public float RotateW { get; set; } - [Data] public float TranslateX { get; set; } - [Data] public float TranslateY { get; set; } - [Data] public float TranslateZ { get; set; } - [Data] public float TranslateW { get; set; } - } - - public class FooterTable - { - [Data] public float ScaleX { get; set; } - [Data] public float ScaleY { get; set; } - [Data] public float ScaleZ { get; set; } - [Data] public float ScaleW { get; set; } - [Data] public float RotateX { get; set; } - [Data] public float RotateY { get; set; } - [Data] public float RotateZ { get; set; } - [Data] public float RotateW { get; set; } - [Data] public float TranslateX { get; set; } - [Data] public float TranslateY { get; set; } - [Data] public float TranslateZ { get; set; } - [Data] public float TranslateW { get; set; } - [Data(Count = 9)] public int[] Unknown { get; set; } - } - - - public bool UnkFlag { get; set; } - public bool IsRaw { get; } - - public RawMotion Raw { get; } - public InterpolatedMotion Interpolated { get; } - - private Motion(Stream stream) - { - stream.Position += ReservedSize; - - var header = BinaryMapping.ReadObject
(stream); - IsRaw = header.Version == 1; - UnkFlag = header.Unk04 != 0; - - if (IsRaw) - { - var raw = BinaryMapping.ReadObject(stream); - Raw = new RawMotion - { - BoneCount = raw.BoneCount, - Unk28 = raw.Unk28, - Unk2c = raw.Unk2c, - BoundingBoxMinX = raw.BoundingBoxMinX, - BoundingBoxMinY = raw.BoundingBoxMinY, - BoundingBoxMinZ = raw.BoundingBoxMinZ, - BoundingBoxMinW = raw.BoundingBoxMinW, - BoundingBoxMaxX = raw.BoundingBoxMaxX, - BoundingBoxMaxY = raw.BoundingBoxMaxY, - BoundingBoxMaxZ = raw.BoundingBoxMaxZ, - BoundingBoxMaxW = raw.BoundingBoxMaxW, - FrameLoop = raw.FrameLoop, - FrameEnd = raw.FrameEnd, - FramePerSecond = raw.FramePerSecond, - FrameCount = raw.FrameCount - }; - - Raw.Matrices = new List(raw.TotalFrameCount); - for (var i = 0; i < raw.TotalFrameCount; i++) - { - var matrices = new Matrix4x4[Raw.BoneCount]; - for (var j = 0; j < Raw.BoneCount; j++) - matrices[j] = stream.ReadMatrix4x4(); - - Raw.Matrices.Add(matrices); - } - - if (raw.Unk2c > 0) - { - stream.Position = ReservedSize + raw.Unk2c; - Raw.Matrices2 = new Matrix4x4[raw.TotalFrameCount]; - for (var j = 0; j < Raw.Matrices2.Length; j++) - Raw.Matrices2[j] = stream.ReadMatrix4x4(); - } - else - Raw.Matrices2 = new Matrix4x4[0]; - } - else - { - var reader = new BinaryReader(stream); - var motion = BinaryMapping.ReadObject(stream); - Interpolated = new InterpolatedMotion - { - BoneCount = motion.BoneCount, - TotalFrameCount = motion.TotalFrameCount, - Unk48 = motion.Unk48, - BoundingBoxMinX = motion.BoundingBoxMinX, - BoundingBoxMinY = motion.BoundingBoxMinY, - BoundingBoxMinZ = motion.BoundingBoxMinZ, - BoundingBoxMinW = motion.BoundingBoxMinW, - BoundingBoxMaxX = motion.BoundingBoxMaxX, - BoundingBoxMaxY = motion.BoundingBoxMaxY, - BoundingBoxMaxZ = motion.BoundingBoxMaxZ, - BoundingBoxMaxW = motion.BoundingBoxMaxW, - FrameLoop = motion.FrameLoop, - FrameEnd = motion.FrameEnd, - FramePerSecond = motion.FramePerSecond, - FrameCount = motion.FrameCount, - Unk98 = motion.Unk98, - Unk9c = motion.Unk9c, - }; - - stream.Position = ReservedSize + motion.StaticPoseOffset; - Interpolated.StaticPose = Enumerable - .Range(0, motion.StaticPoseCount) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToList(); - - stream.Position = ReservedSize + motion.ModelBoneAnimationOffset; - Interpolated.ModelBoneAnimation = Enumerable - .Range(0, motion.ModelBoneAnimationCount) - .Select(x => BinaryMapping.ReadObject(stream)) - .Select(Map) - .ToList(); - - stream.Position = ReservedSize + motion.IKHelperAnimationOffset; - Interpolated.IKHelperAnimation = Enumerable - .Range(0, motion.IKHelperAnimationCount) - .Select(x => BinaryMapping.ReadObject(stream)) - .Select(Map) - .ToList(); - - stream.Position = ReservedSize + motion.TimelineOffset; - var estimatedTimelineCount = (motion.KeyFrameOffset - motion.TimelineOffset) / 8; - var rawTimeline = Enumerable - .Range(0, estimatedTimelineCount) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToList(); - - stream.Position = ReservedSize + motion.KeyFrameOffset; - var keyFrames = Enumerable - .Range(0, motion.KeyFrameCount) - .Select(x => reader.ReadSingle()) - .ToList(); - - stream.Position = ReservedSize + motion.TransformationValueOffset; - var estimatedKeyFrameCount = (motion.TangentOffset - motion.TransformationValueOffset) / 4; - var transformationValues = Enumerable - .Range(0, estimatedKeyFrameCount) - .Select(x => reader.ReadSingle()) - .ToList(); - - stream.Position = ReservedSize + motion.TangentOffset; - var estimatedTangentCount = (motion.IKChainOffset - motion.TangentOffset) / 4; - var tangentValues = Enumerable - .Range(0, estimatedTangentCount) - .Select(x => reader.ReadSingle()) - .ToList(); - - stream.Position = ReservedSize + motion.IKChainOffset; - Interpolated.IKChains = Enumerable - .Range(0, motion.IKChainCount) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToList(); - - stream.Position = ReservedSize + motion.Table8Offset; - var estimatedTable8Count = (motion.Table7Offset - motion.Table8Offset) / 0x30; - Interpolated.Table8 = Enumerable - .Range(0, estimatedTable8Count) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToList(); - - stream.Position = ReservedSize + motion.Table7Offset; - Interpolated.Table7 = Enumerable - .Range(0, motion.Table7Count) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToList(); - - stream.Position = ReservedSize + motion.Table6Offset; - Interpolated.Table6 = Enumerable - .Range(0, motion.Table6Count) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToList(); - - stream.Position = ReservedSize + motion.IKHelperOffset; - Interpolated.IKHelpers = Enumerable - .Range(0, motion.TotalBoneCount - motion.BoneCount) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToList(); - - stream.Position = ReservedSize + motion.JointIndexOffset; - Interpolated.Joints = Enumerable - .Range(0, motion.TotalBoneCount + 1) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToList(); - - Interpolated.Timeline = rawTimeline - .Select(x => new TimelineTable - { - Interpolation = (Interpolation)(x.Time & 3), - KeyFrame = keyFrames[Math.Min(keyFrames.Count - 1, x.Time >> 2)], - Value = transformationValues[Math.Min(transformationValues.Count - 1, x.ValueIndex)], - TangentEaseIn = tangentValues[x.TangentIndexEaseIn], - TangentEaseOut = tangentValues[x.TangentIndexEaseOut], - }) - .ToList(); - - stream.Position = ReservedSize + motion.FooterOffset; - Interpolated.Footer = BinaryMapping.ReadObject(stream); - - stream.Position = ReservedSize + motion.UnknownTable1Offset; - } - } - - public static Motion Read(Stream stream) => - new Motion(stream); - - public static void Write(Stream stream, Motion motion) - { - if (motion.IsRaw) - Write(stream, motion.Raw, motion.UnkFlag); - else - Write(stream, motion.Interpolated, motion.UnkFlag); - } - - private static void Write(Stream stream, RawMotion rawMotion, bool unkFlag) - { - const int HeaderSize = 0x60; - - stream.Write(new byte[ReservedSize], 0, ReservedSize); - BinaryMapping.WriteObject(stream, new Header - { - Version = 1, - Unk04 = unkFlag ? 1 : 0, - ByteCount = HeaderSize + - rawMotion.BoneCount * rawMotion.Matrices.Count * Matrix4x4Size + - rawMotion.Matrices2.Length * Matrix4x4Size, - Unk0c = 0, - }); - - BinaryMapping.WriteObject(stream, new RawMotionInternal - { - BoneCount = rawMotion.BoneCount, - Unk14 = 0, - Unk18 = 0, - Unk1c = 0, - FrameCountPerLoop = (int)(rawMotion.FrameEnd - rawMotion.FrameLoop) * 2, - TotalFrameCount = rawMotion.Matrices.Count, - Unk28 = rawMotion.Unk28, - Unk2c = rawMotion.Matrices2.Length > 0 ? HeaderSize + - rawMotion.BoneCount * rawMotion.Matrices.Count * Matrix4x4Size : 0, - BoundingBoxMinX = rawMotion.BoundingBoxMinX, - BoundingBoxMinY = rawMotion.BoundingBoxMinY, - BoundingBoxMinZ = rawMotion.BoundingBoxMinZ, - BoundingBoxMinW = rawMotion.BoundingBoxMinW, - BoundingBoxMaxX = rawMotion.BoundingBoxMaxX, - BoundingBoxMaxY = rawMotion.BoundingBoxMaxY, - BoundingBoxMaxZ = rawMotion.BoundingBoxMaxZ, - BoundingBoxMaxW = rawMotion.BoundingBoxMaxW, - FrameLoop = rawMotion.FrameLoop, - FrameEnd = rawMotion.FrameEnd, - FramePerSecond = rawMotion.FramePerSecond, - FrameCount = rawMotion.FrameCount - }); - - foreach (var block in rawMotion.Matrices) - for (int i = 0; i < block.Length; i++) - stream.Write(block[i]); - - for (int i = 0; i < rawMotion.Matrices2.Length; i++) - stream.Write(rawMotion.Matrices2[i]); - } - - private static void Write(Stream stream, InterpolatedMotion motion, bool unkFlag) - { - var valuePool = new PoolValues(); - var keyFramePool = new PoolValues(motion.Timeline.Select(x => x.KeyFrame).Distinct().OrderBy(x => x)); - var tangentPool = new PoolValues(); - var rawTimeline = new List(motion.Timeline.Count); - foreach (var item in motion.Timeline) - { - rawTimeline.Add(new TimelineTableInternal - { - Time = (short)(((int)item.Interpolation & 3) | (keyFramePool.GetIndex(item.KeyFrame) << 2)), - ValueIndex = (short)valuePool.GetIndex(item.Value), - TangentIndexEaseIn = (short)tangentPool.GetIndex(item.TangentEaseIn), - TangentIndexEaseOut = (short)tangentPool.GetIndex(item.TangentEaseOut), - }); - } - - var writer = new BinaryWriter(stream); - var header = new InterpolatedMotionInternal - { - BoneCount = motion.BoneCount, - TotalFrameCount = motion.TotalFrameCount, - Unk48 = motion.Unk48, - BoundingBoxMinX = motion.BoundingBoxMinX, - BoundingBoxMinY = motion.BoundingBoxMinY, - BoundingBoxMinZ = motion.BoundingBoxMinZ, - BoundingBoxMinW = motion.BoundingBoxMinW, - BoundingBoxMaxX = motion.BoundingBoxMaxX, - BoundingBoxMaxY = motion.BoundingBoxMaxY, - BoundingBoxMaxZ = motion.BoundingBoxMaxZ, - BoundingBoxMaxW = motion.BoundingBoxMaxW, - FrameLoop = motion.FrameLoop, - FrameEnd = motion.FrameEnd, - FramePerSecond = motion.FramePerSecond, - FrameCount = motion.FrameCount, - Unk98 = motion.Unk98, - Unk9c = motion.Unk9c, - }; - - stream.Write(new byte[ReservedSize], 0, ReservedSize); - BinaryMapping.WriteObject(stream, new Header { }); - BinaryMapping.WriteObject(stream, new InterpolatedMotionInternal { }); - - header.StaticPoseCount = motion.StaticPose.Count; - header.StaticPoseOffset = (int)(stream.Position - ReservedSize); - foreach (var item in motion.StaticPose) - BinaryMapping.WriteObject(stream, item); - - header.ModelBoneAnimationCount = motion.ModelBoneAnimation.Count; - header.ModelBoneAnimationOffset = (int)(stream.Position - ReservedSize); - foreach (var item in motion.ModelBoneAnimation.Select(Map)) - BinaryMapping.WriteObject(stream, item); - - header.IKHelperAnimationCount = motion.IKHelperAnimation.Count; - header.IKHelperAnimationOffset = (int)(stream.Position - ReservedSize); - foreach (var item in motion.IKHelperAnimation.Select(Map)) - BinaryMapping.WriteObject(stream, item); - - header.TimelineOffset = (int)(stream.Position - ReservedSize); - foreach (var item in rawTimeline) - BinaryMapping.WriteObject(stream, item); - - stream.AlignPosition(4); - header.KeyFrameCount = keyFramePool.Values.Count; - header.KeyFrameOffset = (int)(stream.Position - ReservedSize); - foreach (var item in keyFramePool.Values) - writer.Write(item); - - header.TransformationValueOffset = (int)(stream.Position - ReservedSize); - foreach (var item in valuePool.Values) - writer.Write(item); - - header.TangentOffset = (int)(stream.Position - ReservedSize); - foreach (var item in tangentPool.Values) - writer.Write(item); - - header.IKChainCount = motion.IKChains.Count; - header.IKChainOffset = (int)(stream.Position - ReservedSize); - foreach (var item in motion.IKChains) - BinaryMapping.WriteObject(stream, item); - - header.Unk48 = (int)(stream.Position - ReservedSize); - - stream.AlignPosition(0x10); - header.Table8Offset = (int)(stream.Position - ReservedSize); - foreach (var item in motion.Table8) - BinaryMapping.WriteObject(stream, item); - - stream.AlignPosition(0x10); - header.Table7Count = motion.Table7.Count; - header.Table7Offset = (int)(stream.Position - ReservedSize); - foreach (var item in motion.Table7) - BinaryMapping.WriteObject(stream, item); - - header.Table6Count = motion.Table6.Count; - header.Table6Offset = (int)(stream.Position - ReservedSize); - foreach (var item in motion.Table6) - BinaryMapping.WriteObject(stream, item); - - stream.AlignPosition(0x10); - header.TotalBoneCount = (short)(motion.BoneCount + motion.IKHelpers.Count); - header.IKHelperOffset = (int)(stream.Position - ReservedSize); - foreach (var item in motion.IKHelpers) - BinaryMapping.WriteObject(stream, item); - - header.JointIndexOffset = (int)(stream.Position - ReservedSize); - foreach (var item in motion.Joints) - BinaryMapping.WriteObject(stream, item); - - stream.AlignPosition(0x10); - header.FooterOffset = (int)(stream.Position - ReservedSize); - BinaryMapping.WriteObject(stream, motion.Footer); - - header.UnknownTable1Offset = (int)(stream.Position - ReservedSize); - header.UnknownTable1Count = 0; - - stream.AlignPosition(0x10); - stream.SetLength(stream.Position); - - stream.SetPosition(ReservedSize); - BinaryMapping.WriteObject(stream, new Header - { - Version = 0, - Unk04 = unkFlag ? 1 : 0, - ByteCount = (int)(stream.Length - ReservedSize), - Unk0c = 0, - }); - BinaryMapping.WriteObject(stream, header); - } - - private static BoneAnimationTable Map(BoneAnimationTableInternal obj) => new BoneAnimationTable - { - JointIndex = obj.JointIndex, - Channel = (byte)(obj.Channel & 0xF), - Pre = (byte)((obj.Channel >> 4) & 3), - Post = (byte)((obj.Channel >> 6) & 3), - TimelineStartIndex = obj.TimelineStartIndex, - TimelineCount = obj.TimelineCount, - }; - - private static BoneAnimationTableInternal Map(BoneAnimationTable obj) => new BoneAnimationTableInternal - { - JointIndex = obj.JointIndex, - Channel = (byte)((obj.Channel & 0xF) | ((obj.Pre & 3) << 4) | ((obj.Post & 3) << 6)), - TimelineStartIndex = obj.TimelineStartIndex, - TimelineCount = obj.TimelineCount, - }; - - private Motion(bool isRaw) - { - IsRaw = isRaw; - if (isRaw) - { - Raw = new RawMotion - { - Matrices = new List(), - }; - } - else - { - Interpolated = new InterpolatedMotion - { - Footer = new FooterTable(), - IKChains = new List(), - IKHelperAnimation = new List(), - IKHelpers = new List(), - Joints = new List(), - ModelBoneAnimation = new List(), - StaticPose = new List(), - Table6 = new List(), - Table7 = new List(), - Table8 = new List(), - Timeline = new List(), - }; - } - } - - public static Motion CreateInterpolatedFromScratch() => new Motion(false); - } -} +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Numerics; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2 +{ + public class Motion + { + private class PoolValues + { + private readonly Dictionary _valuePool = new Dictionary(); + private readonly List _valueList = new List(); + + public List Values => _valueList; + + public PoolValues() + { + + } + + public PoolValues(IEnumerable values) + { + var index = 0; + foreach (var value in values) + { + _valuePool.Add(value, index++); + _valueList.Add(value); + } + } + + public int GetIndex(T value) + { + if (_valuePool.TryGetValue(value, out var index)) + return index; + + index = _valueList.Count; + _valuePool.Add(value, index); + _valueList.Add(value); + + return index; + } + } + + private const int ReservedSize = 0x90; + private const int Matrix4x4Size = 0x40; + private static readonly string[] Transforms = new[] + { + "Scale.X", "Scale.Y", "Scale.Z", + "Rotation.X", "Rotation.Y", "Rotation.Z", + "Translation.X", "Translation.Y", "Translation.Z", + }; + + public enum Interpolation + { + Zero = -1, // default + Nearest, + Linear, + Hermite, + Hermite3, // unused? + Hermite4, // unused? + } + + private class Header + { + [Data] public int Version { get; set; } + [Data] public int Unk04 { get; set; } + [Data] public int ByteCount { get; set; } + [Data] public int Unk0c { get; set; } + } + + private class RawMotionInternal + { + [Data] public int BoneCount { get; set; } + [Data] public int Unk14 { get; set; } + [Data] public int Unk18 { get; set; } + [Data] public int Unk1c { get; set; } + [Data] public int FrameCountPerLoop { get; set; } + [Data] public int TotalFrameCount { get; set; } + [Data] public int Unk28 { get; set; } + [Data] public int Unk2c { get; set; } + [Data] public float BoundingBoxMinX { get; set; } + [Data] public float BoundingBoxMinY { get; set; } + [Data] public float BoundingBoxMinZ { get; set; } + [Data] public float BoundingBoxMinW { get; set; } + [Data] public float BoundingBoxMaxX { get; set; } + [Data] public float BoundingBoxMaxY { get; set; } + [Data] public float BoundingBoxMaxZ { get; set; } + [Data] public float BoundingBoxMaxW { get; set; } + [Data] public float FrameLoop { get; set; } + [Data] public float FrameEnd { get; set; } + [Data] public float FramePerSecond { get; set; } + [Data] public float FrameCount { get; set; } + + public List Matrices { get; set; } + } + + public class RawMotion + { + public int BoneCount { get; set; } + public int Unk28 { get; set; } + public int Unk2c { get; set; } + public float BoundingBoxMinX { get; set; } + public float BoundingBoxMinY { get; set; } + public float BoundingBoxMinZ { get; set; } + public float BoundingBoxMinW { get; set; } + public float BoundingBoxMaxX { get; set; } + public float BoundingBoxMaxY { get; set; } + public float BoundingBoxMaxZ { get; set; } + public float BoundingBoxMaxW { get; set; } + public float FrameLoop { get; set; } + public float FrameEnd { get; set; } + public float FramePerSecond { get; set; } + public float FrameCount { get; set; } + + public List Matrices { get; set; } + public Matrix4x4[] Matrices2 { get; set; } + } + + private class InterpolatedMotionInternal + { + [Data] public short BoneCount { get; set; } + [Data] public short TotalBoneCount { get; set; } + [Data] public int TotalFrameCount { get; set; } + [Data] public int IKHelperOffset { get; set; } + [Data] public int JointIndexOffset { get; set; } + [Data] public int KeyFrameCount { get; set; } + [Data] public int StaticPoseOffset { get; set; } + [Data] public int StaticPoseCount { get; set; } + [Data] public int FooterOffset { get; set; } + [Data] public int ModelBoneAnimationOffset { get; set; } + [Data] public int ModelBoneAnimationCount { get; set; } + [Data] public int IKHelperAnimationOffset { get; set; } + [Data] public int IKHelperAnimationCount { get; set; } + [Data] public int TimelineOffset { get; set; } + [Data] public int KeyFrameOffset { get; set; } + [Data] public int TransformationValueOffset { get; set; } + [Data] public int TangentOffset { get; set; } + [Data] public int IKChainOffset { get; set; } + [Data] public int IKChainCount { get; set; } + [Data] public int Unk48 { get; set; } + [Data] public int Table8Offset { get; set; } + [Data] public int Table7Offset { get; set; } + [Data] public int Table7Count { get; set; } + [Data] public int Table6Offset { get; set; } + [Data] public int Table6Count { get; set; } + [Data] public float BoundingBoxMinX { get; set; } + [Data] public float BoundingBoxMinY { get; set; } + [Data] public float BoundingBoxMinZ { get; set; } + [Data] public float BoundingBoxMinW { get; set; } + [Data] public float BoundingBoxMaxX { get; set; } + [Data] public float BoundingBoxMaxY { get; set; } + [Data] public float BoundingBoxMaxZ { get; set; } + [Data] public float BoundingBoxMaxW { get; set; } + [Data] public float FrameLoop { get; set; } + [Data] public float FrameEnd { get; set; } + [Data] public float FramePerSecond { get; set; } + [Data] public float FrameCount { get; set; } + [Data] public int UnknownTable1Offset { get; set; } + [Data] public int UnknownTable1Count { get; set; } + [Data] public int Unk98 { get; set; } + [Data] public int Unk9c { get; set; } + } + + public class InterpolatedMotion + { + public short BoneCount { get; set; } + public int TotalFrameCount { get; set; } + public int Unk48 { get; set; } + public float BoundingBoxMinX { get; set; } + public float BoundingBoxMinY { get; set; } + public float BoundingBoxMinZ { get; set; } + public float BoundingBoxMinW { get; set; } + public float BoundingBoxMaxX { get; set; } + public float BoundingBoxMaxY { get; set; } + public float BoundingBoxMaxZ { get; set; } + public float BoundingBoxMaxW { get; set; } + public float FrameLoop { get; set; } + public float FrameEnd { get; set; } + public float FramePerSecond { get; set; } + public float FrameCount { get; set; } + public int Unk98 { get; set; } + public int Unk9c { get; set; } + + public List StaticPose { get; set; } + public List ModelBoneAnimation { get; set; } + public List IKHelperAnimation { get; set; } + public List Timeline { get; set; } + public List IKChains { get; set; } + public List Table8 { get; set; } + public List Table7 { get; set; } + public List Table6 { get; set; } + public List IKHelpers { get; set; } + public List Joints { get; set; } + public FooterTable Footer { get; set; } + } + + public class StaticPoseTable + { + [Data] public short BoneIndex { get; set; } + [Data] public short Channel { get; set; } + [Data] public float Value { get; set; } + + public override string ToString() => + $"{BoneIndex} {Transforms[Channel]} {Value}"; + } + + public class BoneAnimationTableInternal + { + [Data] public short JointIndex { get; set; } + [Data] public byte Channel { get; set; } + [Data] public byte TimelineCount { get; set; } + [Data] public short TimelineStartIndex { get; set; } + + public override string ToString() => + $"{JointIndex} {Transforms[Channel]} ({TimelineStartIndex},{TimelineCount})"; + } + + public class BoneAnimationTable + { + public short JointIndex { get; set; } + public byte Channel { get; set; } + public byte Pre { get; set; } + public byte Post { get; set; } + public byte TimelineCount { get; set; } + public short TimelineStartIndex { get; set; } + + public override string ToString() => + $"{JointIndex} {Transforms[Channel]} ({Pre},{Post}) ({TimelineStartIndex},{TimelineCount})"; + } + + private class TimelineTableInternal + { + [Data] public short Time { get; set; } + [Data] public short ValueIndex { get; set; } + [Data] public short TangentIndexEaseIn { get; set; } + [Data] public short TangentIndexEaseOut { get; set; } + } + + public class TimelineTable + { + public Interpolation Interpolation { get; set; } + public float KeyFrame { get; set; } + public float Value { get; set; } + public float TangentEaseIn { get; set; } + public float TangentEaseOut { get; set; } + + public override string ToString() => + $"{KeyFrame} {Value} {Interpolation}:({TangentEaseIn},{TangentEaseOut})"; + } + + public class IKChainTable + { + [Data] public byte Unk00 { get; set; } + [Data] public byte Unk01 { get; set; } + [Data] public short ModelBoneIndex { get; set; } + [Data] public short IKHelperIndex { get; set; } + [Data] public short Table8Index { get; set; } + [Data] public int Unk08 { get; set; } + } + + public class UnknownTable8 + { + [Data] public int Unk00 { get; set; } + [Data] public float Unk04 { get; set; } + [Data] public float Unk08 { get; set; } + [Data] public float Unk0c { get; set; } + [Data] public float Unk10 { get; set; } + [Data] public float Unk14 { get; set; } + [Data] public float Unk18 { get; set; } + [Data] public float Unk1c { get; set; } + [Data] public float Unk20 { get; set; } + [Data] public float Unk24 { get; set; } + [Data] public float Unk28 { get; set; } + [Data] public float Unk2c { get; set; } + } + + public class UnknownTable7 + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public float Unk04 { get; set; } + } + + public class UnknownTable6 + { + [Data] public short Unk00 { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public float Unk04 { get; set; } + [Data] public short Unk08 { get; set; } + [Data] public short Unk0a { get; set; } + } + + public class JointTable + { + [Data] public short JointIndex { get; set; } + [Data] public short Flag { get; set; } + } + + public class IKHelperTable + { + [Data] public int Index { get; set; } + [Data] public int ParentIndex { get; set; } + [Data] public int Unk08 { get; set; } + [Data] public int Unk0c { get; set; } + [Data] public float ScaleX { get; set; } + [Data] public float ScaleY { get; set; } + [Data] public float ScaleZ { get; set; } + [Data] public float ScaleW { get; set; } + [Data] public float RotateX { get; set; } + [Data] public float RotateY { get; set; } + [Data] public float RotateZ { get; set; } + [Data] public float RotateW { get; set; } + [Data] public float TranslateX { get; set; } + [Data] public float TranslateY { get; set; } + [Data] public float TranslateZ { get; set; } + [Data] public float TranslateW { get; set; } + } + + public class FooterTable + { + [Data] public float ScaleX { get; set; } + [Data] public float ScaleY { get; set; } + [Data] public float ScaleZ { get; set; } + [Data] public float ScaleW { get; set; } + [Data] public float RotateX { get; set; } + [Data] public float RotateY { get; set; } + [Data] public float RotateZ { get; set; } + [Data] public float RotateW { get; set; } + [Data] public float TranslateX { get; set; } + [Data] public float TranslateY { get; set; } + [Data] public float TranslateZ { get; set; } + [Data] public float TranslateW { get; set; } + [Data(Count = 9)] public int[] Unknown { get; set; } + } + + + public bool UnkFlag { get; set; } + public bool IsRaw { get; } + + public RawMotion Raw { get; } + public InterpolatedMotion Interpolated { get; } + + private Motion(Stream stream) + { + stream.Position += ReservedSize; + + var header = BinaryMapping.ReadObject
(stream); + IsRaw = header.Version == 1; + UnkFlag = header.Unk04 != 0; + + if (IsRaw) + { + var raw = BinaryMapping.ReadObject(stream); + Raw = new RawMotion + { + BoneCount = raw.BoneCount, + Unk28 = raw.Unk28, + Unk2c = raw.Unk2c, + BoundingBoxMinX = raw.BoundingBoxMinX, + BoundingBoxMinY = raw.BoundingBoxMinY, + BoundingBoxMinZ = raw.BoundingBoxMinZ, + BoundingBoxMinW = raw.BoundingBoxMinW, + BoundingBoxMaxX = raw.BoundingBoxMaxX, + BoundingBoxMaxY = raw.BoundingBoxMaxY, + BoundingBoxMaxZ = raw.BoundingBoxMaxZ, + BoundingBoxMaxW = raw.BoundingBoxMaxW, + FrameLoop = raw.FrameLoop, + FrameEnd = raw.FrameEnd, + FramePerSecond = raw.FramePerSecond, + FrameCount = raw.FrameCount + }; + + Raw.Matrices = new List(raw.TotalFrameCount); + for (var i = 0; i < raw.TotalFrameCount; i++) + { + var matrices = new Matrix4x4[Raw.BoneCount]; + for (var j = 0; j < Raw.BoneCount; j++) + matrices[j] = stream.ReadMatrix4x4(); + + Raw.Matrices.Add(matrices); + } + + if (raw.Unk2c > 0) + { + stream.Position = ReservedSize + raw.Unk2c; + Raw.Matrices2 = new Matrix4x4[raw.TotalFrameCount]; + for (var j = 0; j < Raw.Matrices2.Length; j++) + Raw.Matrices2[j] = stream.ReadMatrix4x4(); + } + else + Raw.Matrices2 = new Matrix4x4[0]; + } + else + { + var reader = new BinaryReader(stream); + var motion = BinaryMapping.ReadObject(stream); + Interpolated = new InterpolatedMotion + { + BoneCount = motion.BoneCount, + TotalFrameCount = motion.TotalFrameCount, + Unk48 = motion.Unk48, + BoundingBoxMinX = motion.BoundingBoxMinX, + BoundingBoxMinY = motion.BoundingBoxMinY, + BoundingBoxMinZ = motion.BoundingBoxMinZ, + BoundingBoxMinW = motion.BoundingBoxMinW, + BoundingBoxMaxX = motion.BoundingBoxMaxX, + BoundingBoxMaxY = motion.BoundingBoxMaxY, + BoundingBoxMaxZ = motion.BoundingBoxMaxZ, + BoundingBoxMaxW = motion.BoundingBoxMaxW, + FrameLoop = motion.FrameLoop, + FrameEnd = motion.FrameEnd, + FramePerSecond = motion.FramePerSecond, + FrameCount = motion.FrameCount, + Unk98 = motion.Unk98, + Unk9c = motion.Unk9c, + }; + + stream.Position = ReservedSize + motion.StaticPoseOffset; + Interpolated.StaticPose = Enumerable + .Range(0, motion.StaticPoseCount) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToList(); + + stream.Position = ReservedSize + motion.ModelBoneAnimationOffset; + Interpolated.ModelBoneAnimation = Enumerable + .Range(0, motion.ModelBoneAnimationCount) + .Select(x => BinaryMapping.ReadObject(stream)) + .Select(Map) + .ToList(); + + stream.Position = ReservedSize + motion.IKHelperAnimationOffset; + Interpolated.IKHelperAnimation = Enumerable + .Range(0, motion.IKHelperAnimationCount) + .Select(x => BinaryMapping.ReadObject(stream)) + .Select(Map) + .ToList(); + + stream.Position = ReservedSize + motion.TimelineOffset; + var estimatedTimelineCount = (motion.KeyFrameOffset - motion.TimelineOffset) / 8; + var rawTimeline = Enumerable + .Range(0, estimatedTimelineCount) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToList(); + + stream.Position = ReservedSize + motion.KeyFrameOffset; + var keyFrames = Enumerable + .Range(0, motion.KeyFrameCount) + .Select(x => reader.ReadSingle()) + .ToList(); + + stream.Position = ReservedSize + motion.TransformationValueOffset; + var estimatedKeyFrameCount = (motion.TangentOffset - motion.TransformationValueOffset) / 4; + var transformationValues = Enumerable + .Range(0, estimatedKeyFrameCount) + .Select(x => reader.ReadSingle()) + .ToList(); + + stream.Position = ReservedSize + motion.TangentOffset; + var estimatedTangentCount = (motion.IKChainOffset - motion.TangentOffset) / 4; + var tangentValues = Enumerable + .Range(0, estimatedTangentCount) + .Select(x => reader.ReadSingle()) + .ToList(); + + stream.Position = ReservedSize + motion.IKChainOffset; + Interpolated.IKChains = Enumerable + .Range(0, motion.IKChainCount) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToList(); + + stream.Position = ReservedSize + motion.Table8Offset; + var estimatedTable8Count = (motion.Table7Offset - motion.Table8Offset) / 0x30; + Interpolated.Table8 = Enumerable + .Range(0, estimatedTable8Count) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToList(); + + stream.Position = ReservedSize + motion.Table7Offset; + Interpolated.Table7 = Enumerable + .Range(0, motion.Table7Count) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToList(); + + stream.Position = ReservedSize + motion.Table6Offset; + Interpolated.Table6 = Enumerable + .Range(0, motion.Table6Count) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToList(); + + stream.Position = ReservedSize + motion.IKHelperOffset; + Interpolated.IKHelpers = Enumerable + .Range(0, motion.TotalBoneCount - motion.BoneCount) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToList(); + + stream.Position = ReservedSize + motion.JointIndexOffset; + Interpolated.Joints = Enumerable + .Range(0, motion.TotalBoneCount + 1) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToList(); + + Interpolated.Timeline = rawTimeline + .Select(x => new TimelineTable + { + Interpolation = (Interpolation)(x.Time & 3), + KeyFrame = keyFrames[Math.Min(keyFrames.Count - 1, x.Time >> 2)], + Value = transformationValues[Math.Min(transformationValues.Count - 1, x.ValueIndex)], + TangentEaseIn = tangentValues[x.TangentIndexEaseIn], + TangentEaseOut = tangentValues[x.TangentIndexEaseOut], + }) + .ToList(); + + stream.Position = ReservedSize + motion.FooterOffset; + Interpolated.Footer = BinaryMapping.ReadObject(stream); + + stream.Position = ReservedSize + motion.UnknownTable1Offset; + } + } + + public static Motion Read(Stream stream) => + new Motion(stream); + + public static void Write(Stream stream, Motion motion) + { + if (motion.IsRaw) + Write(stream, motion.Raw, motion.UnkFlag); + else + Write(stream, motion.Interpolated, motion.UnkFlag); + } + + private static void Write(Stream stream, RawMotion rawMotion, bool unkFlag) + { + const int HeaderSize = 0x60; + + stream.Write(new byte[ReservedSize], 0, ReservedSize); + BinaryMapping.WriteObject(stream, new Header + { + Version = 1, + Unk04 = unkFlag ? 1 : 0, + ByteCount = HeaderSize + + rawMotion.BoneCount * rawMotion.Matrices.Count * Matrix4x4Size + + rawMotion.Matrices2.Length * Matrix4x4Size, + Unk0c = 0, + }); + + BinaryMapping.WriteObject(stream, new RawMotionInternal + { + BoneCount = rawMotion.BoneCount, + Unk14 = 0, + Unk18 = 0, + Unk1c = 0, + FrameCountPerLoop = (int)(rawMotion.FrameEnd - rawMotion.FrameLoop) * 2, + TotalFrameCount = rawMotion.Matrices.Count, + Unk28 = rawMotion.Unk28, + Unk2c = rawMotion.Matrices2.Length > 0 ? HeaderSize + + rawMotion.BoneCount * rawMotion.Matrices.Count * Matrix4x4Size : 0, + BoundingBoxMinX = rawMotion.BoundingBoxMinX, + BoundingBoxMinY = rawMotion.BoundingBoxMinY, + BoundingBoxMinZ = rawMotion.BoundingBoxMinZ, + BoundingBoxMinW = rawMotion.BoundingBoxMinW, + BoundingBoxMaxX = rawMotion.BoundingBoxMaxX, + BoundingBoxMaxY = rawMotion.BoundingBoxMaxY, + BoundingBoxMaxZ = rawMotion.BoundingBoxMaxZ, + BoundingBoxMaxW = rawMotion.BoundingBoxMaxW, + FrameLoop = rawMotion.FrameLoop, + FrameEnd = rawMotion.FrameEnd, + FramePerSecond = rawMotion.FramePerSecond, + FrameCount = rawMotion.FrameCount + }); + + foreach (var block in rawMotion.Matrices) + for (int i = 0; i < block.Length; i++) + stream.Write(block[i]); + + for (int i = 0; i < rawMotion.Matrices2.Length; i++) + stream.Write(rawMotion.Matrices2[i]); + } + + private static void Write(Stream stream, InterpolatedMotion motion, bool unkFlag) + { + var valuePool = new PoolValues(); + var keyFramePool = new PoolValues(motion.Timeline.Select(x => x.KeyFrame).Distinct().OrderBy(x => x)); + var tangentPool = new PoolValues(); + var rawTimeline = new List(motion.Timeline.Count); + foreach (var item in motion.Timeline) + { + rawTimeline.Add(new TimelineTableInternal + { + Time = (short)(((int)item.Interpolation & 3) | (keyFramePool.GetIndex(item.KeyFrame) << 2)), + ValueIndex = (short)valuePool.GetIndex(item.Value), + TangentIndexEaseIn = (short)tangentPool.GetIndex(item.TangentEaseIn), + TangentIndexEaseOut = (short)tangentPool.GetIndex(item.TangentEaseOut), + }); + } + + var writer = new BinaryWriter(stream); + var header = new InterpolatedMotionInternal + { + BoneCount = motion.BoneCount, + TotalFrameCount = motion.TotalFrameCount, + Unk48 = motion.Unk48, + BoundingBoxMinX = motion.BoundingBoxMinX, + BoundingBoxMinY = motion.BoundingBoxMinY, + BoundingBoxMinZ = motion.BoundingBoxMinZ, + BoundingBoxMinW = motion.BoundingBoxMinW, + BoundingBoxMaxX = motion.BoundingBoxMaxX, + BoundingBoxMaxY = motion.BoundingBoxMaxY, + BoundingBoxMaxZ = motion.BoundingBoxMaxZ, + BoundingBoxMaxW = motion.BoundingBoxMaxW, + FrameLoop = motion.FrameLoop, + FrameEnd = motion.FrameEnd, + FramePerSecond = motion.FramePerSecond, + FrameCount = motion.FrameCount, + Unk98 = motion.Unk98, + Unk9c = motion.Unk9c, + }; + + stream.Write(new byte[ReservedSize], 0, ReservedSize); + BinaryMapping.WriteObject(stream, new Header { }); + BinaryMapping.WriteObject(stream, new InterpolatedMotionInternal { }); + + header.StaticPoseCount = motion.StaticPose.Count; + header.StaticPoseOffset = (int)(stream.Position - ReservedSize); + foreach (var item in motion.StaticPose) + BinaryMapping.WriteObject(stream, item); + + header.ModelBoneAnimationCount = motion.ModelBoneAnimation.Count; + header.ModelBoneAnimationOffset = (int)(stream.Position - ReservedSize); + foreach (var item in motion.ModelBoneAnimation.Select(Map)) + BinaryMapping.WriteObject(stream, item); + + header.IKHelperAnimationCount = motion.IKHelperAnimation.Count; + header.IKHelperAnimationOffset = (int)(stream.Position - ReservedSize); + foreach (var item in motion.IKHelperAnimation.Select(Map)) + BinaryMapping.WriteObject(stream, item); + + header.TimelineOffset = (int)(stream.Position - ReservedSize); + foreach (var item in rawTimeline) + BinaryMapping.WriteObject(stream, item); + + stream.AlignPosition(4); + header.KeyFrameCount = keyFramePool.Values.Count; + header.KeyFrameOffset = (int)(stream.Position - ReservedSize); + foreach (var item in keyFramePool.Values) + writer.Write(item); + + header.TransformationValueOffset = (int)(stream.Position - ReservedSize); + foreach (var item in valuePool.Values) + writer.Write(item); + + header.TangentOffset = (int)(stream.Position - ReservedSize); + foreach (var item in tangentPool.Values) + writer.Write(item); + + header.IKChainCount = motion.IKChains.Count; + header.IKChainOffset = (int)(stream.Position - ReservedSize); + foreach (var item in motion.IKChains) + BinaryMapping.WriteObject(stream, item); + + header.Unk48 = (int)(stream.Position - ReservedSize); + + stream.AlignPosition(0x10); + header.Table8Offset = (int)(stream.Position - ReservedSize); + foreach (var item in motion.Table8) + BinaryMapping.WriteObject(stream, item); + + stream.AlignPosition(0x10); + header.Table7Count = motion.Table7.Count; + header.Table7Offset = (int)(stream.Position - ReservedSize); + foreach (var item in motion.Table7) + BinaryMapping.WriteObject(stream, item); + + header.Table6Count = motion.Table6.Count; + header.Table6Offset = (int)(stream.Position - ReservedSize); + foreach (var item in motion.Table6) + BinaryMapping.WriteObject(stream, item); + + stream.AlignPosition(0x10); + header.TotalBoneCount = (short)(motion.BoneCount + motion.IKHelpers.Count); + header.IKHelperOffset = (int)(stream.Position - ReservedSize); + foreach (var item in motion.IKHelpers) + BinaryMapping.WriteObject(stream, item); + + header.JointIndexOffset = (int)(stream.Position - ReservedSize); + foreach (var item in motion.Joints) + BinaryMapping.WriteObject(stream, item); + + stream.AlignPosition(0x10); + header.FooterOffset = (int)(stream.Position - ReservedSize); + BinaryMapping.WriteObject(stream, motion.Footer); + + header.UnknownTable1Offset = (int)(stream.Position - ReservedSize); + header.UnknownTable1Count = 0; + + stream.AlignPosition(0x10); + stream.SetLength(stream.Position); + + stream.SetPosition(ReservedSize); + BinaryMapping.WriteObject(stream, new Header + { + Version = 0, + Unk04 = unkFlag ? 1 : 0, + ByteCount = (int)(stream.Length - ReservedSize), + Unk0c = 0, + }); + BinaryMapping.WriteObject(stream, header); + } + + private static BoneAnimationTable Map(BoneAnimationTableInternal obj) => new BoneAnimationTable + { + JointIndex = obj.JointIndex, + Channel = (byte)(obj.Channel & 0xF), + Pre = (byte)((obj.Channel >> 4) & 3), + Post = (byte)((obj.Channel >> 6) & 3), + TimelineStartIndex = obj.TimelineStartIndex, + TimelineCount = obj.TimelineCount, + }; + + private static BoneAnimationTableInternal Map(BoneAnimationTable obj) => new BoneAnimationTableInternal + { + JointIndex = obj.JointIndex, + Channel = (byte)((obj.Channel & 0xF) | ((obj.Pre & 3) << 4) | ((obj.Post & 3) << 6)), + TimelineStartIndex = obj.TimelineStartIndex, + TimelineCount = obj.TimelineCount, + }; + + private Motion(bool isRaw) + { + IsRaw = isRaw; + if (isRaw) + { + Raw = new RawMotion + { + Matrices = new List(), + }; + } + else + { + Interpolated = new InterpolatedMotion + { + Footer = new FooterTable(), + IKChains = new List(), + IKHelperAnimation = new List(), + IKHelpers = new List(), + Joints = new List(), + ModelBoneAnimation = new List(), + StaticPose = new List(), + Table6 = new List(), + Table7 = new List(), + Table8 = new List(), + Timeline = new List(), + }; + } + } + + public static Motion CreateInterpolatedFromScratch() => new Motion(false); + } +} diff --git a/OpenKh.Kh2/MotionSet.cs b/OpenKh.Kh2/MotionSet.cs index 609f0e383..b3fed8705 100644 --- a/OpenKh.Kh2/MotionSet.cs +++ b/OpenKh.Kh2/MotionSet.cs @@ -1,247 +1,247 @@ -using System.Collections.Generic; - -namespace OpenKh.Kh2 -{ - public class MotionSet - { - public enum MotionName - { - IDLE, - WALK, - RUN, - JUMP, - FALL, - LAND, - LINK_IDLE, - HANG, - HANG_UP, - ITEM, - DAMAGE_S_FRONT_HIGH, - DAMAGE_S_FRONT_LOW, - DAMAGE_S_BACK_HIGH, - DAMAGE_S_BACK_LOW, - DAMAGE_AIR_FRONT, - DAMAGE_AIR_BACK, - DAMAGE_BLOW_FRONT, - DAMAGE_BLOW_FRONT_LAND, - DAMAGE_BLOW_BACK, - DAMAGE_BLOW_BACK_LAND, - DAMAGE_TORNADO_FRONT, - DAMAGE_TORNADO_BACK, - DAMAGE_TORNADO, - DAMAGE_LARGE_FRONT, - DAMAGE_LARGE_BACK, - DAMAGE_RESERVE_3, - DAMAGE_RESERVE_4, - DAMAGE_RESERVE_5, - DAMAGE_RESERVE_6, - DAMAGE_RESERVE_7, - DAMAGE_01, - DAMAGE_02, - DAMAGE_03, - DAMAGE_04, - DAMAGE_05, - DAMAGE_06, - DAMAGE_07, - DAMAGE_08, - DAMAGE_09, - DAMAGE_10, - DAMAGE_BLOW_RECOV, - REFLECT, - AUTOGUARD, - REFLECT_AIR, - APPEAR, - LEAVE, - LEAVE_AIR, - FOOTWORK, - TURN_L, - TURN_R, - TALK, - TALK_END, - CHANGEFORM, - CHANGEEND, - STUN_LOOP, - STUN_END, - MAGIC_FIRE, - MAGIC_FIRE_FINISH, - MAGIC_FIRE_AIR, - MAGIC_BLIZZARD, - MAGIC_BLIZZARD_FINISH, - MAGIC_BLIZZARD_AIR, - MAGIC_THUNDER, - MAGIC_THUNDER_FINISH, - MAGIC_THUNDER_AIR, - MAGIC_CURE, - MAGIC_CURE_FINISH, - MAGIC_CURE_AIR, - MAGIC_MAGNET, - MAGIC_MAGNET_FINISH, - MAGIC_MAGNET_AIR, - MAGIC_REFLECT, - MAGIC_REFLECT_FINISH, - MAGIC_REFLECT_AIR, - RTN_TURN, - CALL_SUMMON_END, - DEAD_LAND, - DEAD_AIR, - MEMO_IDLE, - SUBMENU_IDLE, - SUBMENU_ACTION1, - SUBMENU_ACTION2, - CALL_FRIEND, - CALL_SUMMON, - MENU_IDLE, - REFLECT00, - REFLECT01, - REFLECT02, - REFLECT03, - REFLECT04, - REFLECT05, - REFLECT06, - REFLECT07, - REFLECT08, - REFLECT09, - REFLECT10, - EX000, - EX001, - EX002, - EX003, - EX004, - EX005, - EX006, - EX007, - EX008, - EX009, - EX010, - EX011, - EX012, - EX013, - EX014, - EX015, - EX016, - EX017, - EX018, - EX019, - EX020, - EX021, - EX022, - EX023, - EX024, - EX025, - EX026, - EX027, - EX028, - EX029, - EX030, - EX031, - EX032, - EX033, - EX034, - EX035, - EX036, - EX037, - EX038, - EX039, - EX040, - EX041, - EX042, - EX043, - EX044, - EX045, - EX046, - EX047, - EX048, - EX049, - EX050, - EX051, - EX052, - EX053, - EX054, - EX055, - EX056, - EX057, - EX058, - EX059, - EX060, - EX061, - EX062, - EX063, - EX064, - EX065, - EX066, - EX067, - EX068, - EX069, - EX070, - EX071, - EX072, - EX073, - EX074, - EX075, - EX076, - EX077, - EX078, - EX079, - EX080, - EX081, - EX082, - EX083, - EX084, - EX085, - EX086, - EX087, - EX088, - EX089, - EX090, - EX091, - EX092, - EX093, - EX094, - EX095, - EX096, - EX097, - EX098, - EX099, - EX100, - RTN_00, - RTN_01, - RTN_02, - RTN_03, - RTN_04, - RTN_05, - RTN_06, - RTN_07, - RTN_08, - RTN_09, - } - - public static int GetMotionSetIndex( - IList barEntries, MotionName motionId, bool isBattle, bool hasWeapon) - { - const int MaxMotionCountPerAnim = 4; - var ModeTable = new byte[] - { - 0x00, 0x01, 0x03, 0x02, 0x01, 0x00, 0x02, 0x03, - 0x02, 0x03, 0x01, 0x00, 0x03, 0x02, 0x00, 0x01 - }; - - var modeIndex = isBattle == false ? 2 : 1; - if (hasWeapon) - modeIndex ^= 1; - - for (var i = 0; i < MaxMotionCountPerAnim; i++) - { - var msetId = ModeTable[modeIndex * 4 + i] + (int)motionId * 4; - //if (msetId == 0) - // continue; - if (ContainsAnimation(barEntries[msetId])) - return msetId; - } - - return -1; - } - - private static bool ContainsAnimation(Bar.Entry entry) => - entry.Stream.Length > 0; - } -} +using System.Collections.Generic; + +namespace OpenKh.Kh2 +{ + public class MotionSet + { + public enum MotionName + { + IDLE, + WALK, + RUN, + JUMP, + FALL, + LAND, + LINK_IDLE, + HANG, + HANG_UP, + ITEM, + DAMAGE_S_FRONT_HIGH, + DAMAGE_S_FRONT_LOW, + DAMAGE_S_BACK_HIGH, + DAMAGE_S_BACK_LOW, + DAMAGE_AIR_FRONT, + DAMAGE_AIR_BACK, + DAMAGE_BLOW_FRONT, + DAMAGE_BLOW_FRONT_LAND, + DAMAGE_BLOW_BACK, + DAMAGE_BLOW_BACK_LAND, + DAMAGE_TORNADO_FRONT, + DAMAGE_TORNADO_BACK, + DAMAGE_TORNADO, + DAMAGE_LARGE_FRONT, + DAMAGE_LARGE_BACK, + DAMAGE_RESERVE_3, + DAMAGE_RESERVE_4, + DAMAGE_RESERVE_5, + DAMAGE_RESERVE_6, + DAMAGE_RESERVE_7, + DAMAGE_01, + DAMAGE_02, + DAMAGE_03, + DAMAGE_04, + DAMAGE_05, + DAMAGE_06, + DAMAGE_07, + DAMAGE_08, + DAMAGE_09, + DAMAGE_10, + DAMAGE_BLOW_RECOV, + REFLECT, + AUTOGUARD, + REFLECT_AIR, + APPEAR, + LEAVE, + LEAVE_AIR, + FOOTWORK, + TURN_L, + TURN_R, + TALK, + TALK_END, + CHANGEFORM, + CHANGEEND, + STUN_LOOP, + STUN_END, + MAGIC_FIRE, + MAGIC_FIRE_FINISH, + MAGIC_FIRE_AIR, + MAGIC_BLIZZARD, + MAGIC_BLIZZARD_FINISH, + MAGIC_BLIZZARD_AIR, + MAGIC_THUNDER, + MAGIC_THUNDER_FINISH, + MAGIC_THUNDER_AIR, + MAGIC_CURE, + MAGIC_CURE_FINISH, + MAGIC_CURE_AIR, + MAGIC_MAGNET, + MAGIC_MAGNET_FINISH, + MAGIC_MAGNET_AIR, + MAGIC_REFLECT, + MAGIC_REFLECT_FINISH, + MAGIC_REFLECT_AIR, + RTN_TURN, + CALL_SUMMON_END, + DEAD_LAND, + DEAD_AIR, + MEMO_IDLE, + SUBMENU_IDLE, + SUBMENU_ACTION1, + SUBMENU_ACTION2, + CALL_FRIEND, + CALL_SUMMON, + MENU_IDLE, + REFLECT00, + REFLECT01, + REFLECT02, + REFLECT03, + REFLECT04, + REFLECT05, + REFLECT06, + REFLECT07, + REFLECT08, + REFLECT09, + REFLECT10, + EX000, + EX001, + EX002, + EX003, + EX004, + EX005, + EX006, + EX007, + EX008, + EX009, + EX010, + EX011, + EX012, + EX013, + EX014, + EX015, + EX016, + EX017, + EX018, + EX019, + EX020, + EX021, + EX022, + EX023, + EX024, + EX025, + EX026, + EX027, + EX028, + EX029, + EX030, + EX031, + EX032, + EX033, + EX034, + EX035, + EX036, + EX037, + EX038, + EX039, + EX040, + EX041, + EX042, + EX043, + EX044, + EX045, + EX046, + EX047, + EX048, + EX049, + EX050, + EX051, + EX052, + EX053, + EX054, + EX055, + EX056, + EX057, + EX058, + EX059, + EX060, + EX061, + EX062, + EX063, + EX064, + EX065, + EX066, + EX067, + EX068, + EX069, + EX070, + EX071, + EX072, + EX073, + EX074, + EX075, + EX076, + EX077, + EX078, + EX079, + EX080, + EX081, + EX082, + EX083, + EX084, + EX085, + EX086, + EX087, + EX088, + EX089, + EX090, + EX091, + EX092, + EX093, + EX094, + EX095, + EX096, + EX097, + EX098, + EX099, + EX100, + RTN_00, + RTN_01, + RTN_02, + RTN_03, + RTN_04, + RTN_05, + RTN_06, + RTN_07, + RTN_08, + RTN_09, + } + + public static int GetMotionSetIndex( + IList barEntries, MotionName motionId, bool isBattle, bool hasWeapon) + { + const int MaxMotionCountPerAnim = 4; + var ModeTable = new byte[] + { + 0x00, 0x01, 0x03, 0x02, 0x01, 0x00, 0x02, 0x03, + 0x02, 0x03, 0x01, 0x00, 0x03, 0x02, 0x00, 0x01 + }; + + var modeIndex = isBattle == false ? 2 : 1; + if (hasWeapon) + modeIndex ^= 1; + + for (var i = 0; i < MaxMotionCountPerAnim; i++) + { + var msetId = ModeTable[modeIndex * 4 + i] + (int)motionId * 4; + //if (msetId == 0) + // continue; + if (ContainsAnimation(barEntries[msetId])) + return msetId; + } + + return -1; + } + + private static bool ContainsAnimation(Bar.Entry entry) => + entry.Stream.Length > 0; + } +} diff --git a/OpenKh.Kh2/Msg.cs b/OpenKh.Kh2/Msg.cs index 79c87c55a..f2bbe9950 100644 --- a/OpenKh.Kh2/Msg.cs +++ b/OpenKh.Kh2/Msg.cs @@ -1,249 +1,251 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Kh2 -{ - public class Msg - { - private static uint MagicCode = 1; - private static byte Terminator = 0; - public static ushort FallbackMessage = 2780; - - public class Entry - { - public int Id { get; set; } - public byte[] Data { get; set; } - } - - internal class OptimizedEntry - { - public int Id { get; } - public byte[] Data { get; } - public int Offset { get; set; } - public int LinkId { get; private set; } - public int LinkOffset { get; private set; } - - public bool HasbeenLinked { get; private set; } - public bool IsLinked => LinkId >= 0; - - public OptimizedEntry(Entry entry) - { - Id = entry.Id; - Data = entry.Data; - Offset = -1; - LinkId = -1; - LinkOffset = -1; - HasbeenLinked = false; - } - - public void LinkTo(OptimizedEntry entry, int offset) - { - LinkId = entry.Id; - LinkOffset = offset; - entry.HasbeenLinked = true; - } - } - - public static List Read(Stream stream) - { - if (!stream.CanRead || !stream.CanSeek) - throw new InvalidDataException($"Read or seek must be supported."); - - var reader = new BinaryReader(stream); - if (stream.Length < 8L || reader.ReadUInt32() != MagicCode) - throw new InvalidDataException("Invalid header"); - - int entriesCount = reader.ReadInt32(); - return Enumerable.Range(0, entriesCount) - .Select(x => new - { - Id = reader.ReadInt32(), - Offset = reader.ReadInt32(), - }) - .ToList() - .Select(x => - { - reader.BaseStream.Position = x.Offset; - - return new Entry - { - Id = x.Id, - Data = GetMsgData(reader) - }; - }) - .ToList(); - } - - public static void Write(Stream stream, List entries) - { - if (!stream.CanWrite || !stream.CanSeek) - throw new InvalidDataException($"Write or seek must be supported."); - - var writer = new BinaryWriter(stream); - writer.Write(MagicCode); - writer.Write(entries.Count); - - var offset = 8 + entries.Count * 8; - var orderedEntries = entries.OrderBy(x => x.Id).ToList(); - foreach (var entry in orderedEntries) - { - writer.Write(entry.Id); - writer.Write(offset); - offset += entry.Data.Length; - } - foreach (var entry in orderedEntries) - { - writer.Write(entry.Data); - } - } - - public static void WriteOptimized(Stream stream, List entries) - { - if (!stream.CanWrite || !stream.CanSeek) - throw new InvalidDataException($"Write or seek must be supported."); - - var writer = new BinaryWriter(stream); - writer.Write(MagicCode); - writer.Write(entries.Count); - - var optimizedEntries = entries.OrderBy(x => x.Id).Select(x => new OptimizedEntry(x)).ToList(); - foreach (var entry in optimizedEntries) - { - if (entry.HasbeenLinked) - continue; - - foreach (var x in optimizedEntries) - { - if (entry == x || x.IsLinked) - continue; - - var indexFound = IndexOf(x.Data, entry.Data); - if (indexFound >= 0) - { - entry.LinkTo(x, indexFound); - break; - } - } - } - - var offset = 8 + entries.Count * 8; - foreach (var entry in optimizedEntries) - { - if (entry.LinkId < 0) - { - entry.Offset = offset; - offset += entry.Data.Length; - } - } - - foreach (var entry in optimizedEntries) - { - writer.Write(entry.Id); - if (entry.IsLinked) - { - var msgLink = optimizedEntries.Find(x => x.Id == entry.LinkId); - writer.Write(msgLink.Offset + entry.LinkOffset); - } - else - writer.Write(entry.Offset); - } - - foreach (var entry in optimizedEntries) - { - if (!entry.IsLinked) - writer.Write(entry.Data); - } - } - - private static int IndexOf(byte[] data, byte[] pattern) - { - var c = data.Length - pattern.Length + 1; - for (var i = 0; i < c; i++) - { - if (data[i] != pattern[0]) - continue; - - int j; - for (j = pattern.Length - 1; j >= 1 && data[i + j] == pattern[j]; j--) ; - if (j == 0) return i; - } - - return -1; - } - - private static byte[] GetMsgData(BinaryReader stream) - { - byte r; - var data = new List(); - do - { - r = stream.ReadByte(); - data.Add(r); - - switch (r) - { - case 0x04: - case 0x06: - case 0x09: - case 0x0a: - case 0x0b: - case 0x0c: - case 0x0e: - case 0x16: - case 0x19: - case 0x1a: - case 0x1b: - case 0x1c: - case 0x1d: - case 0x1e: - case 0x1f: - data.Add(stream.ReadByte()); - break; - case 0x12: - case 0x14: - case 0x15: - case 0x18: - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - break; - case 0x08: - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - break; - case 0x07: - case 0x11: - case 0x13: - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - break; - case 0x0f: - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - break; - case 0x05: - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - data.Add(stream.ReadByte()); - break; - } - } while (r != Terminator); - - return data.ToArray(); - } - - public static bool IsValid(Stream stream) => - stream.Length >= 4 && stream.PeekUInt32() == MagicCode; - - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Kh2 +{ + public class Msg + { + private static uint MagicCode = 1; + private static byte Terminator = 0; + public static ushort FallbackMessage = 2780; + + public class Entry + { + public int Id { get; set; } + public byte[] Data { get; set; } + } + + internal class OptimizedEntry + { + public int Id { get; } + public byte[] Data { get; } + public int Offset { get; set; } + public int LinkId { get; private set; } + public int LinkOffset { get; private set; } + + public bool HasbeenLinked { get; private set; } + public bool IsLinked => LinkId >= 0; + + public OptimizedEntry(Entry entry) + { + Id = entry.Id; + Data = entry.Data; + Offset = -1; + LinkId = -1; + LinkOffset = -1; + HasbeenLinked = false; + } + + public void LinkTo(OptimizedEntry entry, int offset) + { + LinkId = entry.Id; + LinkOffset = offset; + entry.HasbeenLinked = true; + } + } + + public static List Read(Stream stream) + { + if (!stream.CanRead || !stream.CanSeek) + throw new InvalidDataException($"Read or seek must be supported."); + + var reader = new BinaryReader(stream); + if (stream.Length < 8L || reader.ReadUInt32() != MagicCode) + throw new InvalidDataException("Invalid header"); + + int entriesCount = reader.ReadInt32(); + return Enumerable.Range(0, entriesCount) + .Select(x => new + { + Id = reader.ReadInt32(), + Offset = reader.ReadInt32(), + }) + .ToList() + .Select(x => + { + reader.BaseStream.Position = x.Offset; + + return new Entry + { + Id = x.Id, + Data = GetMsgData(reader) + }; + }) + .ToList(); + } + + public static void Write(Stream stream, List entries) + { + if (!stream.CanWrite || !stream.CanSeek) + throw new InvalidDataException($"Write or seek must be supported."); + + var writer = new BinaryWriter(stream); + writer.Write(MagicCode); + writer.Write(entries.Count); + + var offset = 8 + entries.Count * 8; + var orderedEntries = entries.OrderBy(x => x.Id).ToList(); + foreach (var entry in orderedEntries) + { + writer.Write(entry.Id); + writer.Write(offset); + offset += entry.Data.Length; + } + foreach (var entry in orderedEntries) + { + writer.Write(entry.Data); + } + } + + public static void WriteOptimized(Stream stream, List entries) + { + if (!stream.CanWrite || !stream.CanSeek) + throw new InvalidDataException($"Write or seek must be supported."); + + var writer = new BinaryWriter(stream); + writer.Write(MagicCode); + writer.Write(entries.Count); + + var optimizedEntries = entries.OrderBy(x => x.Id).Select(x => new OptimizedEntry(x)).ToList(); + foreach (var entry in optimizedEntries) + { + if (entry.HasbeenLinked) + continue; + + foreach (var x in optimizedEntries) + { + if (entry == x || x.IsLinked) + continue; + + var indexFound = IndexOf(x.Data, entry.Data); + if (indexFound >= 0) + { + entry.LinkTo(x, indexFound); + break; + } + } + } + + var offset = 8 + entries.Count * 8; + foreach (var entry in optimizedEntries) + { + if (entry.LinkId < 0) + { + entry.Offset = offset; + offset += entry.Data.Length; + } + } + + foreach (var entry in optimizedEntries) + { + writer.Write(entry.Id); + if (entry.IsLinked) + { + var msgLink = optimizedEntries.Find(x => x.Id == entry.LinkId); + writer.Write(msgLink.Offset + entry.LinkOffset); + } + else + writer.Write(entry.Offset); + } + + foreach (var entry in optimizedEntries) + { + if (!entry.IsLinked) + writer.Write(entry.Data); + } + } + + private static int IndexOf(byte[] data, byte[] pattern) + { + var c = data.Length - pattern.Length + 1; + for (var i = 0; i < c; i++) + { + if (data[i] != pattern[0]) + continue; + + int j; + for (j = pattern.Length - 1; j >= 1 && data[i + j] == pattern[j]; j--) + ; + if (j == 0) + return i; + } + + return -1; + } + + private static byte[] GetMsgData(BinaryReader stream) + { + byte r; + var data = new List(); + do + { + r = stream.ReadByte(); + data.Add(r); + + switch (r) + { + case 0x04: + case 0x06: + case 0x09: + case 0x0a: + case 0x0b: + case 0x0c: + case 0x0e: + case 0x16: + case 0x19: + case 0x1a: + case 0x1b: + case 0x1c: + case 0x1d: + case 0x1e: + case 0x1f: + data.Add(stream.ReadByte()); + break; + case 0x12: + case 0x14: + case 0x15: + case 0x18: + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + break; + case 0x08: + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + break; + case 0x07: + case 0x11: + case 0x13: + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + break; + case 0x0f: + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + break; + case 0x05: + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + data.Add(stream.ReadByte()); + break; + } + } while (r != Terminator); + + return data.ToArray(); + } + + public static bool IsValid(Stream stream) => + stream.Length >= 4 && stream.PeekUInt32() == MagicCode; + + } +} diff --git a/OpenKh.Kh2/ObjectCollision.cs b/OpenKh.Kh2/ObjectCollision.cs index 49f47ce76..8658454e8 100644 --- a/OpenKh.Kh2/ObjectCollision.cs +++ b/OpenKh.Kh2/ObjectCollision.cs @@ -1,44 +1,44 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2 -{ - public class ObjectCollision - { - [Data] public byte Group { get; set; } - [Data] public byte Parts { get; set; } - [Data] public short Argument { get; set; } - [Data] public byte Type { get; set; } - [Data] public byte Shape { get; set; } - [Data] public short Bone { get; set; } - [Data] public short PositionX { get; set; } - [Data] public short PositionY { get; set; } - [Data] public short PositionZ { get; set; } - [Data] public short PositionHeight { get; set; } - [Data] public short Radius { get; set; } - [Data] public short Height { get; set; } - - public static List Read(Stream stream) - { - var count = stream.ReadInt32(); - stream.Position += 0x40 - 4; - return Enumerable - .Range(0, count) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToList(); - } - - public static void Write(Stream stream, ICollection collisions) - { - stream.Write(collisions.Count); - stream.Write(1); - stream.Position += 0x40 - 8; - - foreach (var item in collisions) - BinaryMapping.WriteObject(stream, item); - } - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2 +{ + public class ObjectCollision + { + [Data] public byte Group { get; set; } + [Data] public byte Parts { get; set; } + [Data] public short Argument { get; set; } + [Data] public byte Type { get; set; } + [Data] public byte Shape { get; set; } + [Data] public short Bone { get; set; } + [Data] public short PositionX { get; set; } + [Data] public short PositionY { get; set; } + [Data] public short PositionZ { get; set; } + [Data] public short PositionHeight { get; set; } + [Data] public short Radius { get; set; } + [Data] public short Height { get; set; } + + public static List Read(Stream stream) + { + var count = stream.ReadInt32(); + stream.Position += 0x40 - 4; + return Enumerable + .Range(0, count) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToList(); + } + + public static void Write(Stream stream, ICollection collisions) + { + stream.Write(collisions.Count); + stream.Write(1); + stream.Position += 0x40 - 8; + + foreach (var item in collisions) + BinaryMapping.WriteObject(stream, item); + } + } +} diff --git a/OpenKh.Kh2/Objentry.cs b/OpenKh.Kh2/Objentry.cs index 5dab89e47..afb1a0d69 100644 --- a/OpenKh.Kh2/Objentry.cs +++ b/OpenKh.Kh2/Objentry.cs @@ -1,121 +1,121 @@ -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2 -{ - public class Objentry - { - public enum Type : byte - { - [Description("Player")] - PLAYER = 0x0, - [Description("Party Member")] - FRIEND = 0x1, - [Description("NPC")] - NPC = 0x2, - [Description("Boss")] - BOSS = 0x3, - [Description("Normal Enemy")] - ZAKO = 0x4, - [Description("Weapon")] - WEAPON = 0x5, - [Description("Placeholder (?)")] - E_WEAPON = 0x6, - [Description("Save Point")] - SP = 0x7, - [Description("Neutral")] - F_OBJ = 0x8, - [Description("Out of Party Member")] - BTLNPC = 0x9, - [Description("Chest")] - TREASURE = 0xA, - [Description("Moogle (?)")] - SUBMENU = 0xB, - [Description("Large Boss")] - L_BOSS = 0xC, - [Description] - G_OBJ = 0xD, - [Description] - MEMO = 0xE, - [Description] - RTN = 0xF, - [Description] - MINIGAME = 0x10, - [Description("World Map Object")] - WORLDMAP = 0x11, - [Description("Drop Item Container")] - PRIZEBOX = 0x12, - [Description("Summon")] - SUMMON = 0x13, - [Description("Shop")] - SHOP = 0x14, - [Description("Normal Enemy 2")] - L_ZAKO = 0x15, - [Description("Crowd Spawner")] - MASSEFFECT = 0x16, - [Description] - E_OBJ = 0x17, - [Description("Puzzle Piece")] - JIGSAW = 0x18, - } - - public enum CommandMenuOptions : byte - { - [Description("Sora / Roxas")] - SoraRoxasDefault = 0x0, - [Description("Valor Form")] - ValorForm = 0x1, - [Description("Wisdom Form")] - WisdomForm = 0x2, - [Description("Limit Form")] - LimitForm = 0x3, - [Description("Master Form")] - MasterForm = 0x4, - [Description("Final Form")] - FinalForm = 0x5, - [Description("Anti Form")] - AntiForm = 0x6, - [Description("Lion King Sora")] - LionKingSora = 0x7, - [Description("Magic, Drive, Party and Limit commands are greyed out")] - Unk08 = 0x8, - [Description("Drive, Party and Limit commands are greyed out (not used ingame)")] - Unk09 = 0x9, - [Description("Roxas Dual-Wield")] - RoxasDualWield = 0xA, - [Description("Only Attack and Summon commands are available")] - Default = 0xB, - [Description("Sora in Cube / Card Form (Luxord battle, not used ingame)")] - CubeCardForm = 0xC, - } - - [Data] public uint ObjectId { get; set; } - [Data] public Type ObjectType { get; set; } - [Data] public byte SubType { get; set; } - [Data] public byte DrawPriority { get; set; } - [Data] public byte WeaponJoint { get; set; } - [Data(Count = 32)] public string ModelName { get; set; } - [Data(Count = 32)] public string AnimationName { get; set; } - [Data] public ushort Flag { get; set; } - [Data] public byte TargetType { get; set; } - [Data] public byte Padding { get; set; } - [Data] public ushort NeoStatus { get; set; } - [Data] public ushort NeoMoveset { get; set; } - [Data] public float Weight { get; set; } - [Data] public byte SpawnLimiter { get; set; } - [Data] public byte Page { get; set; } - [Data] public byte ShadowSize { get; set; } - [Data] public CommandMenuOptions CommandMenuOption { get; set; } - [Data] public ushort SpawnObject1 { get; set; } - [Data] public ushort SpawnObject2 { get; set; } - [Data] public ushort SpawnObject3 { get; set; } - [Data] public ushort SpawnObject4 { get; set; } - - public static List Read(Stream stream) => BaseTable.Read(stream); - public static void Write(Stream stream, IEnumerable entries) => - BaseTable.Write(stream, 3, entries); - } -} +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2 +{ + public class Objentry + { + public enum Type : byte + { + [Description("Player")] + PLAYER = 0x0, + [Description("Party Member")] + FRIEND = 0x1, + [Description("NPC")] + NPC = 0x2, + [Description("Boss")] + BOSS = 0x3, + [Description("Normal Enemy")] + ZAKO = 0x4, + [Description("Weapon")] + WEAPON = 0x5, + [Description("Placeholder (?)")] + E_WEAPON = 0x6, + [Description("Save Point")] + SP = 0x7, + [Description("Neutral")] + F_OBJ = 0x8, + [Description("Out of Party Member")] + BTLNPC = 0x9, + [Description("Chest")] + TREASURE = 0xA, + [Description("Moogle (?)")] + SUBMENU = 0xB, + [Description("Large Boss")] + L_BOSS = 0xC, + [Description] + G_OBJ = 0xD, + [Description] + MEMO = 0xE, + [Description] + RTN = 0xF, + [Description] + MINIGAME = 0x10, + [Description("World Map Object")] + WORLDMAP = 0x11, + [Description("Drop Item Container")] + PRIZEBOX = 0x12, + [Description("Summon")] + SUMMON = 0x13, + [Description("Shop")] + SHOP = 0x14, + [Description("Normal Enemy 2")] + L_ZAKO = 0x15, + [Description("Crowd Spawner")] + MASSEFFECT = 0x16, + [Description] + E_OBJ = 0x17, + [Description("Puzzle Piece")] + JIGSAW = 0x18, + } + + public enum CommandMenuOptions : byte + { + [Description("Sora / Roxas")] + SoraRoxasDefault = 0x0, + [Description("Valor Form")] + ValorForm = 0x1, + [Description("Wisdom Form")] + WisdomForm = 0x2, + [Description("Limit Form")] + LimitForm = 0x3, + [Description("Master Form")] + MasterForm = 0x4, + [Description("Final Form")] + FinalForm = 0x5, + [Description("Anti Form")] + AntiForm = 0x6, + [Description("Lion King Sora")] + LionKingSora = 0x7, + [Description("Magic, Drive, Party and Limit commands are greyed out")] + Unk08 = 0x8, + [Description("Drive, Party and Limit commands are greyed out (not used ingame)")] + Unk09 = 0x9, + [Description("Roxas Dual-Wield")] + RoxasDualWield = 0xA, + [Description("Only Attack and Summon commands are available")] + Default = 0xB, + [Description("Sora in Cube / Card Form (Luxord battle, not used ingame)")] + CubeCardForm = 0xC, + } + + [Data] public uint ObjectId { get; set; } + [Data] public Type ObjectType { get; set; } + [Data] public byte SubType { get; set; } + [Data] public byte DrawPriority { get; set; } + [Data] public byte WeaponJoint { get; set; } + [Data(Count = 32)] public string ModelName { get; set; } + [Data(Count = 32)] public string AnimationName { get; set; } + [Data] public ushort Flag { get; set; } + [Data] public byte TargetType { get; set; } + [Data] public byte Padding { get; set; } + [Data] public ushort NeoStatus { get; set; } + [Data] public ushort NeoMoveset { get; set; } + [Data] public float Weight { get; set; } + [Data] public byte SpawnLimiter { get; set; } + [Data] public byte Page { get; set; } + [Data] public byte ShadowSize { get; set; } + [Data] public CommandMenuOptions CommandMenuOption { get; set; } + [Data] public ushort SpawnObject1 { get; set; } + [Data] public ushort SpawnObject2 { get; set; } + [Data] public ushort SpawnObject3 { get; set; } + [Data] public ushort SpawnObject4 { get; set; } + + public static List Read(Stream stream) => BaseTable.Read(stream); + public static void Write(Stream stream, IEnumerable entries) => + BaseTable.Write(stream, 3, entries); + } +} diff --git a/OpenKh.Kh2/Pax.cs b/OpenKh.Kh2/Pax.cs index 9572c619d..85a5fc848 100644 --- a/OpenKh.Kh2/Pax.cs +++ b/OpenKh.Kh2/Pax.cs @@ -1,180 +1,180 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace OpenKh.Kh2 -{ - public partial class Pax - { - public class Entry - { - public int Effect { get; set; } - public int Caster { get; set; } - public int Unk04 { get; set; } - public int Unk06 { get; set; } - public int Unk08 { get; set; } - public int Unk0C { get; set; } - public int Unk10 { get; set; } - public int Unk14 { get; set; } - public int SoundEffect { get; set; } - public float PosX { get; set; } - public float PosZ { get; set; } - public float PosY { get; set; } - public float RotX { get; set; } - public float RotZ { get; set; } - public float RotY { get; set; } - public float ScaleX { get; set; } - public float ScaleZ { get; set; } - public float ScaleY { get; set; } - public int Unk40 { get; set; } - public int Unk44 { get; set; } - public int Unk48 { get; set; } - public int Unk4C { get; set; } - - internal static Entry Read(BinaryReader reader) - { - return new Entry() - { - Effect = reader.ReadInt16(), - Caster = reader.ReadInt16(), - Unk04 = reader.ReadInt16(), - Unk06 = reader.ReadInt16(), - Unk08 = reader.ReadInt32(), - Unk0C = reader.ReadInt32(), - Unk10 = reader.ReadInt32(), - Unk14 = reader.ReadInt32(), - SoundEffect = reader.ReadInt32(), - PosX = reader.ReadSingle(), - PosZ = reader.ReadSingle(), - PosY = reader.ReadSingle(), - RotX = reader.ReadSingle(), - RotZ = reader.ReadSingle(), - RotY = reader.ReadSingle(), - ScaleX = reader.ReadSingle(), - ScaleZ = reader.ReadSingle(), - ScaleY = reader.ReadSingle(), - Unk40 = reader.ReadInt32(), - Unk44 = reader.ReadInt32(), - Unk48 = reader.ReadInt32(), - Unk4C = reader.ReadInt32(), - }; - } - - internal void Save(BinaryWriter writer) - { - writer.Write((short)Effect); - writer.Write((short)Caster); - writer.Write((short)Unk04); - writer.Write((short)Unk06); - writer.Write(Unk08); - writer.Write(Unk0C); - writer.Write(Unk10); - writer.Write(Unk14); - writer.Write(SoundEffect); - writer.Write(PosX); - writer.Write(PosZ); - writer.Write(PosY); - writer.Write(RotX); - writer.Write(RotZ); - writer.Write(RotY); - writer.Write(ScaleX); - writer.Write(ScaleZ); - writer.Write(ScaleY); - writer.Write(Unk40); - writer.Write(Unk44); - writer.Write(Unk48); - writer.Write(Unk4C); - } - } - - private const uint MagicCode = 0x5F584150U; - - public Pax(Stream stream) - { - if (!stream.CanRead || !stream.CanSeek) - throw new InvalidDataException($"Read or seek must be supported."); - - var reader = new BinaryReader(stream); - var offsetBase = reader.BaseStream.Position; - - if (stream.Length < 16L || reader.ReadUInt32() != MagicCode) - throw new InvalidDataException("Invalid header"); - - var offsetName = reader.ReadInt32(); - var entriesCount = reader.ReadInt32(); - var offsetDpx = reader.ReadInt32(); - - Entries = new List(entriesCount); - for (int i = 0; i < entriesCount; i++) - { - Entries.Add(Entry.Read(reader)); - } - - reader.BaseStream.Position = offsetBase + offsetName; - ReadName(reader); - - reader.BaseStream.Position = offsetBase + offsetDpx; - //Dpx = new Dpx(reader); - } - - public string Name { get; set; } - - public List Entries { get; set; } - - public Dpx Dpx { get; set; } - - - private void ReadName(BinaryReader reader) - { - byte[] data = new byte[0x80]; - reader.Read(data, 0, data.Length); - Name = Encoding.UTF8.GetString(data).TrimEnd('\0'); - } - - private void ReadDpx(BinaryReader reader) - { - } - - public void SaveChanges(Stream stream) - { - SaveChanges(new BinaryWriter(stream)); - } - - public void SaveChanges(BinaryWriter writer) - { - var offsetBase = writer.BaseStream.Position; - - writer.BaseStream.Position += 0x10; - SaveEntries(writer); - - int offsetName = (int)(writer.BaseStream.Position - offsetBase); - SaveName(writer); - - int offsetDpx = (int)(writer.BaseStream.Position - offsetBase); - //Dpx.SaveChanges(writer); - - writer.BaseStream.Position = offsetBase; - writer.Write(MagicCode); - writer.Write(offsetName); - writer.Write(Entries.Count); - writer.Write(offsetDpx); - } - - public void SaveEntries(BinaryWriter writer) - { - foreach (var entry in Entries) - { - entry.Save(writer); - } - } - - public void SaveName(BinaryWriter writer) - { - var data = new byte[0x80]; - var strData = Encoding.UTF8.GetBytes(Name); - Array.Copy(strData, data, Math.Min(data.Length, strData.Length)); - writer.Write(data); - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace OpenKh.Kh2 +{ + public partial class Pax + { + public class Entry + { + public int Effect { get; set; } + public int Caster { get; set; } + public int Unk04 { get; set; } + public int Unk06 { get; set; } + public int Unk08 { get; set; } + public int Unk0C { get; set; } + public int Unk10 { get; set; } + public int Unk14 { get; set; } + public int SoundEffect { get; set; } + public float PosX { get; set; } + public float PosZ { get; set; } + public float PosY { get; set; } + public float RotX { get; set; } + public float RotZ { get; set; } + public float RotY { get; set; } + public float ScaleX { get; set; } + public float ScaleZ { get; set; } + public float ScaleY { get; set; } + public int Unk40 { get; set; } + public int Unk44 { get; set; } + public int Unk48 { get; set; } + public int Unk4C { get; set; } + + internal static Entry Read(BinaryReader reader) + { + return new Entry() + { + Effect = reader.ReadInt16(), + Caster = reader.ReadInt16(), + Unk04 = reader.ReadInt16(), + Unk06 = reader.ReadInt16(), + Unk08 = reader.ReadInt32(), + Unk0C = reader.ReadInt32(), + Unk10 = reader.ReadInt32(), + Unk14 = reader.ReadInt32(), + SoundEffect = reader.ReadInt32(), + PosX = reader.ReadSingle(), + PosZ = reader.ReadSingle(), + PosY = reader.ReadSingle(), + RotX = reader.ReadSingle(), + RotZ = reader.ReadSingle(), + RotY = reader.ReadSingle(), + ScaleX = reader.ReadSingle(), + ScaleZ = reader.ReadSingle(), + ScaleY = reader.ReadSingle(), + Unk40 = reader.ReadInt32(), + Unk44 = reader.ReadInt32(), + Unk48 = reader.ReadInt32(), + Unk4C = reader.ReadInt32(), + }; + } + + internal void Save(BinaryWriter writer) + { + writer.Write((short)Effect); + writer.Write((short)Caster); + writer.Write((short)Unk04); + writer.Write((short)Unk06); + writer.Write(Unk08); + writer.Write(Unk0C); + writer.Write(Unk10); + writer.Write(Unk14); + writer.Write(SoundEffect); + writer.Write(PosX); + writer.Write(PosZ); + writer.Write(PosY); + writer.Write(RotX); + writer.Write(RotZ); + writer.Write(RotY); + writer.Write(ScaleX); + writer.Write(ScaleZ); + writer.Write(ScaleY); + writer.Write(Unk40); + writer.Write(Unk44); + writer.Write(Unk48); + writer.Write(Unk4C); + } + } + + private const uint MagicCode = 0x5F584150U; + + public Pax(Stream stream) + { + if (!stream.CanRead || !stream.CanSeek) + throw new InvalidDataException($"Read or seek must be supported."); + + var reader = new BinaryReader(stream); + var offsetBase = reader.BaseStream.Position; + + if (stream.Length < 16L || reader.ReadUInt32() != MagicCode) + throw new InvalidDataException("Invalid header"); + + var offsetName = reader.ReadInt32(); + var entriesCount = reader.ReadInt32(); + var offsetDpx = reader.ReadInt32(); + + Entries = new List(entriesCount); + for (int i = 0; i < entriesCount; i++) + { + Entries.Add(Entry.Read(reader)); + } + + reader.BaseStream.Position = offsetBase + offsetName; + ReadName(reader); + + reader.BaseStream.Position = offsetBase + offsetDpx; + //Dpx = new Dpx(reader); + } + + public string Name { get; set; } + + public List Entries { get; set; } + + public Dpx Dpx { get; set; } + + + private void ReadName(BinaryReader reader) + { + byte[] data = new byte[0x80]; + reader.Read(data, 0, data.Length); + Name = Encoding.UTF8.GetString(data).TrimEnd('\0'); + } + + private void ReadDpx(BinaryReader reader) + { + } + + public void SaveChanges(Stream stream) + { + SaveChanges(new BinaryWriter(stream)); + } + + public void SaveChanges(BinaryWriter writer) + { + var offsetBase = writer.BaseStream.Position; + + writer.BaseStream.Position += 0x10; + SaveEntries(writer); + + int offsetName = (int)(writer.BaseStream.Position - offsetBase); + SaveName(writer); + + int offsetDpx = (int)(writer.BaseStream.Position - offsetBase); + //Dpx.SaveChanges(writer); + + writer.BaseStream.Position = offsetBase; + writer.Write(MagicCode); + writer.Write(offsetName); + writer.Write(Entries.Count); + writer.Write(offsetDpx); + } + + public void SaveEntries(BinaryWriter writer) + { + foreach (var entry in Entries) + { + entry.Save(writer); + } + } + + public void SaveName(BinaryWriter writer) + { + var data = new byte[0x80]; + var strData = Encoding.UTF8.GetBytes(Name); + Array.Copy(strData, data, Math.Min(data.Length, strData.Length)); + writer.Write(data); + } + } +} diff --git a/OpenKh.Kh2/Places.cs b/OpenKh.Kh2/Places.cs index ae817ffa2..0b9884c95 100644 --- a/OpenKh.Kh2/Places.cs +++ b/OpenKh.Kh2/Places.cs @@ -1,127 +1,127 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Kh2 -{ - public class Place - { - /// - /// Refers to sys.bar - /// - public ushort MessageId { get; set; } - - /// - /// Place name to be decoded as Shift-JIS. - /// - public byte[] Name { get; set; } - - private static IEnumerable ReadPlaceSubEntries(Stream stream) - { - while (true) - { - var ch = stream.ReadByte(); - if (ch <= 0) - yield break; - - yield return (byte)ch; - } - } - - private static IEnumerable ReadPlaceEntry(Stream stream) - { - if (stream.Length < 4) - yield break; - - var placeCount = stream.SetPosition(2).ReadUInt16() / 4; - stream.SetPosition(0); - - var placeIds = new List(placeCount); - var offsetIds = new List(placeCount); - for (var i = 0; i < placeCount; i++) - { - placeIds.Add(stream.ReadUInt16()); - offsetIds.Add(stream.ReadUInt16() + i * 4); - } - - for (var i = 0; i < placeCount - 1; i++) - { - var hasName = offsetIds[i] != offsetIds[i + 1]; - var name = hasName ? - ReadPlaceSubEntries(stream.SetPosition(offsetIds[i])).ToArray() : - new byte[0]; - - yield return new Place - { - MessageId = placeIds[i], - Name = name - }; - } - - yield return new Place - { - MessageId = placeIds[placeCount - 1], - Name = ReadPlaceSubEntries(stream.SetPosition(offsetIds[placeCount - 1])).ToArray() - }; - } - - private static void Write(Stream stream, List places) - { - var endOfFile = places.Count * 4; - foreach (var place in places) - { - stream.Write(place.MessageId); - stream.Write((ushort)endOfFile); - - endOfFile -= 4; - if (place.Name.Length > 0) - endOfFile += place.Name.Length + 1; - } - - foreach (var place in places) - { - if (place.Name.Length > 0) - { - stream.Write(place.Name); - stream.Write((byte)0); - } - } - } - - public static Dictionary> Read(Stream stream) => - Bar.Read(stream) - .Where(x => x.Type == Bar.EntryType.List) - .ToDictionary(x => x.Name, x => ReadPlaceEntry(x.Stream).ToList()); - - public static void Write(Stream stream, Dictionary> entries) - { - var barEntries = new List - { - new Bar.Entry - { - Name = "tmp", - Stream = new MemoryStream() - } - }; - - foreach (var placeGroup in entries) - { - var memoryStream = new MemoryStream(); - Write(memoryStream, placeGroup.Value); - - barEntries.Add(new Bar.Entry - { - Name = placeGroup.Key, - Stream = memoryStream, - Type = Bar.EntryType.List - }); - }; - - Bar.Write(stream, barEntries); - - foreach (var barEntry in barEntries) - barEntry.Stream.Dispose(); - } - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Kh2 +{ + public class Place + { + /// + /// Refers to sys.bar + /// + public ushort MessageId { get; set; } + + /// + /// Place name to be decoded as Shift-JIS. + /// + public byte[] Name { get; set; } + + private static IEnumerable ReadPlaceSubEntries(Stream stream) + { + while (true) + { + var ch = stream.ReadByte(); + if (ch <= 0) + yield break; + + yield return (byte)ch; + } + } + + private static IEnumerable ReadPlaceEntry(Stream stream) + { + if (stream.Length < 4) + yield break; + + var placeCount = stream.SetPosition(2).ReadUInt16() / 4; + stream.SetPosition(0); + + var placeIds = new List(placeCount); + var offsetIds = new List(placeCount); + for (var i = 0; i < placeCount; i++) + { + placeIds.Add(stream.ReadUInt16()); + offsetIds.Add(stream.ReadUInt16() + i * 4); + } + + for (var i = 0; i < placeCount - 1; i++) + { + var hasName = offsetIds[i] != offsetIds[i + 1]; + var name = hasName ? + ReadPlaceSubEntries(stream.SetPosition(offsetIds[i])).ToArray() : + new byte[0]; + + yield return new Place + { + MessageId = placeIds[i], + Name = name + }; + } + + yield return new Place + { + MessageId = placeIds[placeCount - 1], + Name = ReadPlaceSubEntries(stream.SetPosition(offsetIds[placeCount - 1])).ToArray() + }; + } + + private static void Write(Stream stream, List places) + { + var endOfFile = places.Count * 4; + foreach (var place in places) + { + stream.Write(place.MessageId); + stream.Write((ushort)endOfFile); + + endOfFile -= 4; + if (place.Name.Length > 0) + endOfFile += place.Name.Length + 1; + } + + foreach (var place in places) + { + if (place.Name.Length > 0) + { + stream.Write(place.Name); + stream.Write((byte)0); + } + } + } + + public static Dictionary> Read(Stream stream) => + Bar.Read(stream) + .Where(x => x.Type == Bar.EntryType.List) + .ToDictionary(x => x.Name, x => ReadPlaceEntry(x.Stream).ToList()); + + public static void Write(Stream stream, Dictionary> entries) + { + var barEntries = new List + { + new Bar.Entry + { + Name = "tmp", + Stream = new MemoryStream() + } + }; + + foreach (var placeGroup in entries) + { + var memoryStream = new MemoryStream(); + Write(memoryStream, placeGroup.Value); + + barEntries.Add(new Bar.Entry + { + Name = placeGroup.Key, + Stream = memoryStream, + Type = Bar.EntryType.List + }); + }; + + Bar.Write(stream, barEntries); + + foreach (var barEntry in barEntries) + barEntry.Stream.Dispose(); + } + } +} diff --git a/OpenKh.Kh2/Ps2.Reform32.cs b/OpenKh.Kh2/Ps2.Reform32.cs index bb5bd17c0..e0d6ccb3f 100644 --- a/OpenKh.Kh2/Ps2.Reform32.cs +++ b/OpenKh.Kh2/Ps2.Reform32.cs @@ -1,83 +1,83 @@ -namespace OpenKh.Kh2 -{ - public partial class Ps2 - { - private static readonly byte[] tbl32bc = - { - 0, 1, 4, 5, 16, 17, 20, 21, 2, 3, 6, 7, 18, 19, 22, 23, - 8, 9, 12, 13, 24, 25, 28, 29, 10, 11, 14, 15, 26, 27, 30, 31 - }; - - private static readonly byte[] tbl32pao = { 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15 }; - - public static byte[] Decode32(byte[] bin, int bw, int bh) - { - var buffer = new byte[bin.Length]; - for (int i = 0; i < (0x20 * bh); i += 0x20) - { - for (int j = 0; j < (0x40 * bw); j += 0x40) - { - int num3 = 0x2000 * ((j / 0x40) + (bw * (i / 0x20))); - for (int k = 0; k < 0x20; k += 8) - { - for (int m = 0; m < 0x40; m += 8) - { - int num6 = 0x100 * tbl32bc[(m / 8) + ((k / 8) * 8)]; - for (int n = 0; n < 4; n++) - { - int num8 = 0x40 * n; - for (int num9 = 0; num9 < 0x10; num9++) - { - int num10 = (j + m) + (num9 % 8); - int num11 = ((i + k) + (2 * n)) + (num9 / 8); - int index = 4 * (num10 + ((0x40 * bw) * num11)); - int num13 = (((4 * tbl32pao[num9]) + num8) + num6) + num3; - buffer[index] = bin[num13]; - buffer[index + 1] = bin[num13 + 1]; - buffer[index + 2] = bin[num13 + 2]; - buffer[index + 3] = bin[num13 + 3]; - } - } - } - } - } - } - return buffer; - } - - public static byte[] Encode32(byte[] bin, int bw, int bh) - { - var buffer = new byte[bin.Length]; - for (int i = 0; i < (0x20 * bh); i += 0x20) - { - for (int j = 0; j < (0x40 * bw); j += 0x40) - { - int num3 = 0x2000 * ((j / 0x40) + (bw * (i / 0x20))); - for (int k = 0; k < 0x20; k += 8) - { - for (int m = 0; m < 0x40; m += 8) - { - int num6 = 0x100 * tbl32bc[(m / 8) + ((k / 8) * 8)]; - for (int n = 0; n < 4; n++) - { - int num8 = 0x40 * n; - for (int num9 = 0; num9 < 0x10; num9++) - { - int num10 = (j + m) + (num9 % 8); - int num11 = ((i + k) + (2 * n)) + (num9 / 8); - int index = 4 * (num10 + ((0x40 * bw) * num11)); - int num13 = (((4 * tbl32pao[num9]) + num8) + num6) + num3; - buffer[num13] = bin[index]; - buffer[num13 + 1] = bin[index + 1]; - buffer[num13 + 2] = bin[index + 2]; - buffer[num13 + 3] = bin[index + 3]; - } - } - } - } - } - } - return buffer; - } - } -} +namespace OpenKh.Kh2 +{ + public partial class Ps2 + { + private static readonly byte[] tbl32bc = + { + 0, 1, 4, 5, 16, 17, 20, 21, 2, 3, 6, 7, 18, 19, 22, 23, + 8, 9, 12, 13, 24, 25, 28, 29, 10, 11, 14, 15, 26, 27, 30, 31 + }; + + private static readonly byte[] tbl32pao = { 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15 }; + + public static byte[] Decode32(byte[] bin, int bw, int bh) + { + var buffer = new byte[bin.Length]; + for (int i = 0; i < (0x20 * bh); i += 0x20) + { + for (int j = 0; j < (0x40 * bw); j += 0x40) + { + int num3 = 0x2000 * ((j / 0x40) + (bw * (i / 0x20))); + for (int k = 0; k < 0x20; k += 8) + { + for (int m = 0; m < 0x40; m += 8) + { + int num6 = 0x100 * tbl32bc[(m / 8) + ((k / 8) * 8)]; + for (int n = 0; n < 4; n++) + { + int num8 = 0x40 * n; + for (int num9 = 0; num9 < 0x10; num9++) + { + int num10 = (j + m) + (num9 % 8); + int num11 = ((i + k) + (2 * n)) + (num9 / 8); + int index = 4 * (num10 + ((0x40 * bw) * num11)); + int num13 = (((4 * tbl32pao[num9]) + num8) + num6) + num3; + buffer[index] = bin[num13]; + buffer[index + 1] = bin[num13 + 1]; + buffer[index + 2] = bin[num13 + 2]; + buffer[index + 3] = bin[num13 + 3]; + } + } + } + } + } + } + return buffer; + } + + public static byte[] Encode32(byte[] bin, int bw, int bh) + { + var buffer = new byte[bin.Length]; + for (int i = 0; i < (0x20 * bh); i += 0x20) + { + for (int j = 0; j < (0x40 * bw); j += 0x40) + { + int num3 = 0x2000 * ((j / 0x40) + (bw * (i / 0x20))); + for (int k = 0; k < 0x20; k += 8) + { + for (int m = 0; m < 0x40; m += 8) + { + int num6 = 0x100 * tbl32bc[(m / 8) + ((k / 8) * 8)]; + for (int n = 0; n < 4; n++) + { + int num8 = 0x40 * n; + for (int num9 = 0; num9 < 0x10; num9++) + { + int num10 = (j + m) + (num9 % 8); + int num11 = ((i + k) + (2 * n)) + (num9 / 8); + int index = 4 * (num10 + ((0x40 * bw) * num11)); + int num13 = (((4 * tbl32pao[num9]) + num8) + num6) + num3; + buffer[num13] = bin[index]; + buffer[num13 + 1] = bin[index + 1]; + buffer[num13 + 2] = bin[index + 2]; + buffer[num13 + 3] = bin[index + 3]; + } + } + } + } + } + } + return buffer; + } + } +} diff --git a/OpenKh.Kh2/Ps2.Reform4.cs b/OpenKh.Kh2/Ps2.Reform4.cs index 113dca4f1..537bdca11 100644 --- a/OpenKh.Kh2/Ps2.Reform4.cs +++ b/OpenKh.Kh2/Ps2.Reform4.cs @@ -1,138 +1,138 @@ -namespace OpenKh.Kh2 -{ - public partial class Ps2 - { - private static readonly byte[] tbl4bc = - { - 0, 2, 8, 10, 1, 3, 9, 11, 4, 6, 12, 14, 5, 7, 13, 15, - 16, 18, 24, 26, 17, 19, 25, 27, 20, 22, 28, 30, 21, 23, 29, 31 - }; - - private static readonly int[] tbl4col0 = - { - 0x00, 0x20, 0x80, 0xa0, 0x100, 0x120, 0x180, 0x1a0, 0x08, 0x28, 0x88, 0xa8, 0x108, 0x128, 0x188, 0x1a8, - 0x10, 0x30, 0x90, 0xb0, 0x110, 0x130, 0x190, 0x1b0, 0x18, 0x38, 0x98, 0xb8, 0x118, 0x138, 0x198, 0x1b8, - 0x40, 0x60, 0xc0, 0xe0, 0x140, 0x160, 0x1c0, 0x1e0, 0x48, 0x68, 0xc8, 0xe8, 0x148, 0x168, 0x1c8, 0x1e8, - 0x50, 0x70, 0xd0, 0xf0, 0x150, 0x170, 0x1d0, 0x1f0, 0x58, 0x78, 0xd8, 0xf8, 0x158, 0x178, 0x1d8, 0x1f8, - 0x104, 0x124, 0x184, 0x1a4, 0x04, 0x24, 0x84, 0xa4, 0x10c, 0x12c, 0x18c, 0x1ac, 0x0c, 0x2c, 0x8c, 0xac, - 0x114, 0x134, 0x194, 0x1b4, 0x14, 0x34, 0x94, 0xb4, 0x11c, 0x13c, 0x19c, 0x1bc, 0x1c, 0x3c, 0x9c, 0xbc, - 0x144, 0x164, 0x1c4, 0x1e4, 0x44, 0x64, 0xc4, 0xe4, 0x14c, 0x16c, 0x1cc, 0x1ec, 0x4c, 0x6c, 0xcc, 0xec, - 0x154, 0x174, 0x1d4, 0x1f4, 0x54, 0x74, 0xd4, 0xf4, 0x15c, 0x17c, 0x1dc, 0x1fc, 0x5c, 0x7c, 0xdc, 0xfc - }; - - private static readonly int[] tbl4col1 = - { - 0x100, 0x120, 0x180, 0x1a0, 0x00, 0x20, 0x80, 0xa0, 0x108, 0x128, 0x188, 0x1a8, 0x08, 0x28, 0x88, 0xa8, - 0x110, 0x130, 0x190, 0x1b0, 0x10, 0x30, 0x90, 0xb0, 0x118, 0x138, 0x198, 0x1b8, 0x18, 0x38, 0x98, 0xb8, - 0x140, 0x160, 0x1c0, 0x1e0, 0x40, 0x60, 0xc0, 0xe0, 0x148, 0x168, 0x1c8, 0x1e8, 0x48, 0x68, 0xc8, 0xe8, - 0x150, 0x170, 0x1d0, 0x1f0, 0x50, 0x70, 0xd0, 0xf0, 0x158, 0x178, 0x1d8, 0x1f8, 0x58, 0x78, 0xd8, 0xf8, - 0x04, 0x24, 0x84, 0xa4, 0x104, 0x124, 0x184, 0x1a4, 0x0c, 0x2c, 0x8c, 0xac, 0x10c, 0x12c, 0x18c, 0x1ac, - 0x14, 0x34, 0x94, 0xb4, 0x114, 0x134, 0x194, 0x1b4, 0x1c, 0x3c, 0x9c, 0xbc, 0x11c, 0x13c, 0x19c, 0x1bc, - 0x44, 0x64, 0xc4, 0xe4, 0x144, 0x164, 0x1c4, 0x1e4, 0x4c, 0x6c, 0xcc, 0xec, 0x14c, 0x16c, 0x1cc, 0x1ec, - 0x54, 0x74, 0xd4, 0xf4, 0x154, 0x174, 0x1d4, 0x1f4, 0x5c, 0x7c, 0xdc, 0xfc, 0x15c, 0x17c, 0x1dc, 0x1fc - }; - - public static byte[] Decode4(byte[] bin, int bw, int bh) - { - var buffer = new byte[bin.Length]; - for (int i = 0; i < (0x80 * bh); i += 0x80) - { - for (int j = 0; j < (0x80 * bw); j += 0x80) - { - int num3 = 0x2000 * ((j / 0x80) + (bw * (i / 0x80))); - for (int k = 0; k < 0x80; k += 0x10) - { - for (int m = 0; m < 0x80; m += 0x20) - { - int num6 = 0x100 * tbl4bc[(m / 0x20) + (4 * (k / 0x10))]; - for (int n = 0; n < 4; n++) - { - int num8 = 0x40 * n; - int[] numArray = ((n & 1) == 0) ? tbl4col0 : tbl4col1; - for (int num9 = 0; num9 < 0x80; num9++) - { - int num10 = numArray[num9] / 8; - int num11 = numArray[num9] % 8; - var num12 = (byte)((bin[((num3 + num6) + num8) + num10] >> num11) & 15); - int num13 = (j + m) + (num9 % 0x20); - int num14 = ((i + k) + (4 * n)) + (num9 / 0x20); - int num15 = num13 + ((0x80 * bw) * num14); - byte num16 = buffer[num15 / 2]; - if ((num15 & 1) == 1) - { - num16 = (byte)(num16 & 240); - num16 = (byte)(num16 | num12); - } - else - { - num16 = (byte)(num16 & 15); - num16 = (byte)(num16 | ((byte)(num12 << 4))); - } - buffer[num15 / 2] = num16; - } - } - } - } - } - } - return buffer; - } - - public static byte[] Encode4(byte[] bin, int bw, int bh) - { - var buffer = new byte[bin.Length]; - for (int i = 0; i < (0x80 * bh); i += 0x80) - { - for (int j = 0; j < (0x80 * bw); j += 0x80) - { - int num3 = 0x2000 * ((j / 0x80) + (bw * (i / 0x80))); - for (int k = 0; k < 0x80; k += 0x10) - { - for (int m = 0; m < 0x80; m += 0x20) - { - int num6 = 0x100 * tbl4bc[(m / 0x20) + (4 * (k / 0x10))]; - for (int n = 0; n < 4; n++) - { - int num8 = 0x40 * n; - int[] numArray = ((n & 1) == 0) ? tbl4col0 : tbl4col1; - for (int num9 = 0; num9 < 0x80; num9++) - { - int num10 = (j + m) + (num9 % 0x20); - int num11 = ((i + k) + (4 * n)) + (num9 / 0x20); - int num12 = num10 + ((0x80 * bw) * num11); - byte num13 = bin[num12 / 2]; - if ((num12 & 1) == 0) - { - num13 = (byte)(num13 >> 4); - } - else - { - num13 = (byte)(num13 & 15); - } - int num14 = numArray[num9] / 8; - int num15 = numArray[num9] % 8; - int index = ((num3 + num6) + num8) + num14; - byte num17 = buffer[index]; - switch (num15) - { - case 0: - num17 = (byte)(num17 & 240); - num17 = (byte)(num17 | num13); - break; - - case 4: - num17 = (byte)(num17 & 15); - num17 = (byte)(num17 | ((byte)(num13 << 4))); - break; - } - buffer[index] = num17; - } - } - } - } - } - } - return buffer; - } - } -} +namespace OpenKh.Kh2 +{ + public partial class Ps2 + { + private static readonly byte[] tbl4bc = + { + 0, 2, 8, 10, 1, 3, 9, 11, 4, 6, 12, 14, 5, 7, 13, 15, + 16, 18, 24, 26, 17, 19, 25, 27, 20, 22, 28, 30, 21, 23, 29, 31 + }; + + private static readonly int[] tbl4col0 = + { + 0x00, 0x20, 0x80, 0xa0, 0x100, 0x120, 0x180, 0x1a0, 0x08, 0x28, 0x88, 0xa8, 0x108, 0x128, 0x188, 0x1a8, + 0x10, 0x30, 0x90, 0xb0, 0x110, 0x130, 0x190, 0x1b0, 0x18, 0x38, 0x98, 0xb8, 0x118, 0x138, 0x198, 0x1b8, + 0x40, 0x60, 0xc0, 0xe0, 0x140, 0x160, 0x1c0, 0x1e0, 0x48, 0x68, 0xc8, 0xe8, 0x148, 0x168, 0x1c8, 0x1e8, + 0x50, 0x70, 0xd0, 0xf0, 0x150, 0x170, 0x1d0, 0x1f0, 0x58, 0x78, 0xd8, 0xf8, 0x158, 0x178, 0x1d8, 0x1f8, + 0x104, 0x124, 0x184, 0x1a4, 0x04, 0x24, 0x84, 0xa4, 0x10c, 0x12c, 0x18c, 0x1ac, 0x0c, 0x2c, 0x8c, 0xac, + 0x114, 0x134, 0x194, 0x1b4, 0x14, 0x34, 0x94, 0xb4, 0x11c, 0x13c, 0x19c, 0x1bc, 0x1c, 0x3c, 0x9c, 0xbc, + 0x144, 0x164, 0x1c4, 0x1e4, 0x44, 0x64, 0xc4, 0xe4, 0x14c, 0x16c, 0x1cc, 0x1ec, 0x4c, 0x6c, 0xcc, 0xec, + 0x154, 0x174, 0x1d4, 0x1f4, 0x54, 0x74, 0xd4, 0xf4, 0x15c, 0x17c, 0x1dc, 0x1fc, 0x5c, 0x7c, 0xdc, 0xfc + }; + + private static readonly int[] tbl4col1 = + { + 0x100, 0x120, 0x180, 0x1a0, 0x00, 0x20, 0x80, 0xa0, 0x108, 0x128, 0x188, 0x1a8, 0x08, 0x28, 0x88, 0xa8, + 0x110, 0x130, 0x190, 0x1b0, 0x10, 0x30, 0x90, 0xb0, 0x118, 0x138, 0x198, 0x1b8, 0x18, 0x38, 0x98, 0xb8, + 0x140, 0x160, 0x1c0, 0x1e0, 0x40, 0x60, 0xc0, 0xe0, 0x148, 0x168, 0x1c8, 0x1e8, 0x48, 0x68, 0xc8, 0xe8, + 0x150, 0x170, 0x1d0, 0x1f0, 0x50, 0x70, 0xd0, 0xf0, 0x158, 0x178, 0x1d8, 0x1f8, 0x58, 0x78, 0xd8, 0xf8, + 0x04, 0x24, 0x84, 0xa4, 0x104, 0x124, 0x184, 0x1a4, 0x0c, 0x2c, 0x8c, 0xac, 0x10c, 0x12c, 0x18c, 0x1ac, + 0x14, 0x34, 0x94, 0xb4, 0x114, 0x134, 0x194, 0x1b4, 0x1c, 0x3c, 0x9c, 0xbc, 0x11c, 0x13c, 0x19c, 0x1bc, + 0x44, 0x64, 0xc4, 0xe4, 0x144, 0x164, 0x1c4, 0x1e4, 0x4c, 0x6c, 0xcc, 0xec, 0x14c, 0x16c, 0x1cc, 0x1ec, + 0x54, 0x74, 0xd4, 0xf4, 0x154, 0x174, 0x1d4, 0x1f4, 0x5c, 0x7c, 0xdc, 0xfc, 0x15c, 0x17c, 0x1dc, 0x1fc + }; + + public static byte[] Decode4(byte[] bin, int bw, int bh) + { + var buffer = new byte[bin.Length]; + for (int i = 0; i < (0x80 * bh); i += 0x80) + { + for (int j = 0; j < (0x80 * bw); j += 0x80) + { + int num3 = 0x2000 * ((j / 0x80) + (bw * (i / 0x80))); + for (int k = 0; k < 0x80; k += 0x10) + { + for (int m = 0; m < 0x80; m += 0x20) + { + int num6 = 0x100 * tbl4bc[(m / 0x20) + (4 * (k / 0x10))]; + for (int n = 0; n < 4; n++) + { + int num8 = 0x40 * n; + int[] numArray = ((n & 1) == 0) ? tbl4col0 : tbl4col1; + for (int num9 = 0; num9 < 0x80; num9++) + { + int num10 = numArray[num9] / 8; + int num11 = numArray[num9] % 8; + var num12 = (byte)((bin[((num3 + num6) + num8) + num10] >> num11) & 15); + int num13 = (j + m) + (num9 % 0x20); + int num14 = ((i + k) + (4 * n)) + (num9 / 0x20); + int num15 = num13 + ((0x80 * bw) * num14); + byte num16 = buffer[num15 / 2]; + if ((num15 & 1) == 1) + { + num16 = (byte)(num16 & 240); + num16 = (byte)(num16 | num12); + } + else + { + num16 = (byte)(num16 & 15); + num16 = (byte)(num16 | ((byte)(num12 << 4))); + } + buffer[num15 / 2] = num16; + } + } + } + } + } + } + return buffer; + } + + public static byte[] Encode4(byte[] bin, int bw, int bh) + { + var buffer = new byte[bin.Length]; + for (int i = 0; i < (0x80 * bh); i += 0x80) + { + for (int j = 0; j < (0x80 * bw); j += 0x80) + { + int num3 = 0x2000 * ((j / 0x80) + (bw * (i / 0x80))); + for (int k = 0; k < 0x80; k += 0x10) + { + for (int m = 0; m < 0x80; m += 0x20) + { + int num6 = 0x100 * tbl4bc[(m / 0x20) + (4 * (k / 0x10))]; + for (int n = 0; n < 4; n++) + { + int num8 = 0x40 * n; + int[] numArray = ((n & 1) == 0) ? tbl4col0 : tbl4col1; + for (int num9 = 0; num9 < 0x80; num9++) + { + int num10 = (j + m) + (num9 % 0x20); + int num11 = ((i + k) + (4 * n)) + (num9 / 0x20); + int num12 = num10 + ((0x80 * bw) * num11); + byte num13 = bin[num12 / 2]; + if ((num12 & 1) == 0) + { + num13 = (byte)(num13 >> 4); + } + else + { + num13 = (byte)(num13 & 15); + } + int num14 = numArray[num9] / 8; + int num15 = numArray[num9] % 8; + int index = ((num3 + num6) + num8) + num14; + byte num17 = buffer[index]; + switch (num15) + { + case 0: + num17 = (byte)(num17 & 240); + num17 = (byte)(num17 | num13); + break; + + case 4: + num17 = (byte)(num17 & 15); + num17 = (byte)(num17 | ((byte)(num13 << 4))); + break; + } + buffer[index] = num17; + } + } + } + } + } + } + return buffer; + } + } +} diff --git a/OpenKh.Kh2/Ps2.Reform8.cs b/OpenKh.Kh2/Ps2.Reform8.cs index b9b0c62f2..24d9d4610 100644 --- a/OpenKh.Kh2/Ps2.Reform8.cs +++ b/OpenKh.Kh2/Ps2.Reform8.cs @@ -1,93 +1,93 @@ -namespace OpenKh.Kh2 -{ - public partial class Ps2 - { - private static readonly byte[] tbl8bc = - { - 0, 1, 4, 5, 16, 17, 20, 21, 2, 3, 6, 7, 18, 19, 22, 23, - 8, 9, 12, 13, 24, 25, 28, 29, 10, 11, 14, 15, 26, 27, 30, 31 - }; - - private static readonly byte[] tbl8c0 = - { - 0x00, 0x04, 0x10, 0x14, 0x20, 0x24, 0x30, 0x34, 0x02, 0x06, 0x12, 0x16, 0x22, 0x26, 0x32, 0x36, - 0x08, 0x0c, 0x18, 0x1c, 0x28, 0x2c, 0x38, 0x3c, 0x0a, 0x0e, 0x1a, 0x1e, 0x2a, 0x2e, 0x3a, 0x3e, - 0x21, 0x25, 0x31, 0x35, 0x01, 0x05, 0x11, 0x15, 0x23, 0x27, 0x33, 0x37, 0x03, 0x07, 0x13, 0x17, - 0x29, 0x2d, 0x39, 0x3d, 0x09, 0x0d, 0x19, 0x1d, 0x2b, 0x2f, 0x3b, 0x3f, 0x0b, 0x0f, 0x1b, 0x1f - }; - - private static readonly byte[] tbl8c1 = - { - 0x20, 0x24, 0x30, 0x34, 0x00, 0x04, 0x10, 0x14, 0x22, 0x26, 0x32, 0x36, 0x02, 0x06, 0x12, 0x16, - 0x28, 0x2c, 0x38, 0x3c, 0x08, 0x0c, 0x18, 0x1c, 0x2a, 0x2e, 0x3a, 0x3e, 0x0a, 0x0e, 0x1a, 0x1e, - 0x01, 0x05, 0x11, 0x15, 0x21, 0x25, 0x31, 0x35, 0x03, 0x07, 0x13, 0x17, 0x23, 0x27, 0x33, 0x37, - 0x09, 0x0d, 0x19, 0x1d, 0x29, 0x2d, 0x39, 0x3d, 0x0b, 0x0f, 0x1b, 0x1f, 0x2b, 0x2f, 0x3b, 0x3f - }; - - public static byte[] Decode8(byte[] bin, int bw, int bh) - { - var buffer = new byte[bin.Length]; - for (int i = 0; i < (0x40 * bh); i += 0x40) - { - for (int j = 0; j < (0x80 * bw); j += 0x80) - { - int num3 = 0x2000 * ((j / 0x80) + (bw * (i / 0x40))); - for (int k = 0; k < 0x40; k += 0x10) - { - for (int m = 0; m < 0x80; m += 0x10) - { - int num6 = 0x100 * tbl8bc[(m / 0x10) + (8 * (k / 0x10))]; - for (int n = 0; n < 4; n++) - { - int num8 = 0x40 * n; - byte[] buffer2 = ((n & 1) == 0) ? tbl8c0 : tbl8c1; - for (int num9 = 0; num9 < 0x40; num9++) - { - int index = ((num3 + num6) + num8) + buffer2[num9]; - int num11 = (j + m) + (num9 % 0x10); - int num12 = ((i + k) + (4 * n)) + (num9 / 0x10); - int num13 = num11 + ((0x80 * bw) * num12); - buffer[num13] = bin[index]; - } - } - } - } - } - } - return buffer; - } - - public static byte[] Encode8(byte[] bin, int bw, int bh) - { - var buffer = new byte[bin.Length]; - for (int i = 0; i < (0x40 * bh); i += 0x40) - { - for (int j = 0; j < (0x80 * bw); j += 0x80) - { - int num3 = 0x2000 * ((j / 0x80) + (bw * (i / 0x40))); - for (int k = 0; k < 0x40; k += 0x10) - { - for (int m = 0; m < 0x80; m += 0x10) - { - int num6 = 0x100 * tbl8bc[(m / 0x10) + (8 * (k / 0x10))]; - for (int n = 0; n < 4; n++) - { - int num8 = 0x40 * n; - byte[] buffer2 = ((n & 1) == 0) ? tbl8c0 : tbl8c1; - for (int num9 = 0; num9 < 0x40; num9++) - { - int index = ((num3 + num6) + num8) + buffer2[num9]; - int num11 = (j + m) + (num9 % 0x10); - int num12 = ((i + k) + (4 * n)) + (num9 / 0x10); - int num13 = num11 + ((0x80 * bw) * num12); - buffer[index] = bin[num13]; - } - } - } - } - } - } - return buffer; - } - } -} +namespace OpenKh.Kh2 +{ + public partial class Ps2 + { + private static readonly byte[] tbl8bc = + { + 0, 1, 4, 5, 16, 17, 20, 21, 2, 3, 6, 7, 18, 19, 22, 23, + 8, 9, 12, 13, 24, 25, 28, 29, 10, 11, 14, 15, 26, 27, 30, 31 + }; + + private static readonly byte[] tbl8c0 = + { + 0x00, 0x04, 0x10, 0x14, 0x20, 0x24, 0x30, 0x34, 0x02, 0x06, 0x12, 0x16, 0x22, 0x26, 0x32, 0x36, + 0x08, 0x0c, 0x18, 0x1c, 0x28, 0x2c, 0x38, 0x3c, 0x0a, 0x0e, 0x1a, 0x1e, 0x2a, 0x2e, 0x3a, 0x3e, + 0x21, 0x25, 0x31, 0x35, 0x01, 0x05, 0x11, 0x15, 0x23, 0x27, 0x33, 0x37, 0x03, 0x07, 0x13, 0x17, + 0x29, 0x2d, 0x39, 0x3d, 0x09, 0x0d, 0x19, 0x1d, 0x2b, 0x2f, 0x3b, 0x3f, 0x0b, 0x0f, 0x1b, 0x1f + }; + + private static readonly byte[] tbl8c1 = + { + 0x20, 0x24, 0x30, 0x34, 0x00, 0x04, 0x10, 0x14, 0x22, 0x26, 0x32, 0x36, 0x02, 0x06, 0x12, 0x16, + 0x28, 0x2c, 0x38, 0x3c, 0x08, 0x0c, 0x18, 0x1c, 0x2a, 0x2e, 0x3a, 0x3e, 0x0a, 0x0e, 0x1a, 0x1e, + 0x01, 0x05, 0x11, 0x15, 0x21, 0x25, 0x31, 0x35, 0x03, 0x07, 0x13, 0x17, 0x23, 0x27, 0x33, 0x37, + 0x09, 0x0d, 0x19, 0x1d, 0x29, 0x2d, 0x39, 0x3d, 0x0b, 0x0f, 0x1b, 0x1f, 0x2b, 0x2f, 0x3b, 0x3f + }; + + public static byte[] Decode8(byte[] bin, int bw, int bh) + { + var buffer = new byte[bin.Length]; + for (int i = 0; i < (0x40 * bh); i += 0x40) + { + for (int j = 0; j < (0x80 * bw); j += 0x80) + { + int num3 = 0x2000 * ((j / 0x80) + (bw * (i / 0x40))); + for (int k = 0; k < 0x40; k += 0x10) + { + for (int m = 0; m < 0x80; m += 0x10) + { + int num6 = 0x100 * tbl8bc[(m / 0x10) + (8 * (k / 0x10))]; + for (int n = 0; n < 4; n++) + { + int num8 = 0x40 * n; + byte[] buffer2 = ((n & 1) == 0) ? tbl8c0 : tbl8c1; + for (int num9 = 0; num9 < 0x40; num9++) + { + int index = ((num3 + num6) + num8) + buffer2[num9]; + int num11 = (j + m) + (num9 % 0x10); + int num12 = ((i + k) + (4 * n)) + (num9 / 0x10); + int num13 = num11 + ((0x80 * bw) * num12); + buffer[num13] = bin[index]; + } + } + } + } + } + } + return buffer; + } + + public static byte[] Encode8(byte[] bin, int bw, int bh) + { + var buffer = new byte[bin.Length]; + for (int i = 0; i < (0x40 * bh); i += 0x40) + { + for (int j = 0; j < (0x80 * bw); j += 0x80) + { + int num3 = 0x2000 * ((j / 0x80) + (bw * (i / 0x40))); + for (int k = 0; k < 0x40; k += 0x10) + { + for (int m = 0; m < 0x80; m += 0x10) + { + int num6 = 0x100 * tbl8bc[(m / 0x10) + (8 * (k / 0x10))]; + for (int n = 0; n < 4; n++) + { + int num8 = 0x40 * n; + byte[] buffer2 = ((n & 1) == 0) ? tbl8c0 : tbl8c1; + for (int num9 = 0; num9 < 0x40; num9++) + { + int index = ((num3 + num6) + num8) + buffer2[num9]; + int num11 = (j + m) + (num9 % 0x10); + int num12 = ((i + k) + (4 * n)) + (num9 / 0x10); + int num13 = num11 + ((0x80 * bw) * num12); + buffer[index] = bin[num13]; + } + } + } + } + } + } + return buffer; + } + } +} diff --git a/OpenKh.Kh2/Ps2.Repl.cs b/OpenKh.Kh2/Ps2.Repl.cs index 923b4ac70..10b08ee62 100644 --- a/OpenKh.Kh2/Ps2.Repl.cs +++ b/OpenKh.Kh2/Ps2.Repl.cs @@ -1,10 +1,10 @@ -namespace OpenKh.Kh2 -{ - public partial class Ps2 - { - public static int Repl(int x) - { - return (x & 231) | (((x & 16) != 0) ? 8 : 0) | (((x & 8) != 0) ? 16 : 0); - } - } -} +namespace OpenKh.Kh2 +{ + public partial class Ps2 + { + public static int Repl(int x) + { + return (x & 231) | (((x & 16) != 0) ? 8 : 0) | (((x & 8) != 0) ? 16 : 0); + } + } +} diff --git a/OpenKh.Kh2/Ps2.Utility.cs b/OpenKh.Kh2/Ps2.Utility.cs index 3e0273f26..e912bfbb6 100644 --- a/OpenKh.Kh2/Ps2.Utility.cs +++ b/OpenKh.Kh2/Ps2.Utility.cs @@ -1,10 +1,10 @@ -using System; - -namespace OpenKh.Kh2 -{ - public partial class Ps2 - { - public static byte FromPs2Alpha(byte alpha) => - (byte)Math.Min(alpha * 2, byte.MaxValue); - } -} +using System; + +namespace OpenKh.Kh2 +{ + public partial class Ps2 + { + public static byte FromPs2Alpha(byte alpha) => + (byte)Math.Min(alpha * 2, byte.MaxValue); + } +} diff --git a/OpenKh.Kh2/RawBitmap.cs b/OpenKh.Kh2/RawBitmap.cs index fdb7571ea..70f0a4b8b 100644 --- a/OpenKh.Kh2/RawBitmap.cs +++ b/OpenKh.Kh2/RawBitmap.cs @@ -1,132 +1,134 @@ -using System; -using System.Drawing; -using System.IO; -using OpenKh.Imaging; - -namespace OpenKh.Kh2 -{ - public class RawBitmap : IImageRead - { - private const int PaletteCount = 256; - private const int BitsPerColor = 32; - private static readonly uint[] FontColors = new uint[] - { - 0x00000000, - 0x80a0a0a0, - 0xe4cccccc, - 0xfff0f0f0 - }; - private static readonly byte[] FontPalette1 = GeneratePalette1(FontColors); - private static readonly byte[] FontPalette2 = GeneratePalette2(FontColors); - - private readonly byte[] _data; - private readonly byte[] _clut; - - private RawBitmap(Stream stream, int width, int height, bool is8bit, bool defaultPaletteSwitch = false) - { - Size = new Size(width, height); - PixelFormat = is8bit ? PixelFormat.Indexed8 : PixelFormat.Indexed4; - - var reader = new BinaryReader(stream); - var bpp = is8bit ? 8 : 4; - _data = reader.ReadBytes(width * height * bpp / 8); - - if (bpp == 4) - ImageDataHelpers.SwapEndianIndexed4(_data); - - // If we did not reached the end of the stream, then it does mean that there is a palette - if (stream.Position < stream.Length) - { - _clut = reader.ReadBytes(PaletteCount * BitsPerColor / 8); - } - else - { - // Just assign a default palette - _clut = defaultPaletteSwitch ? FontPalette2 : FontPalette1; - } - } - - public Size Size { get; } - - public PixelFormat PixelFormat { get; } - - public byte[] GetClut() - { - switch (PixelFormat) - { - case PixelFormat.Indexed8: return GetClut8(); - case PixelFormat.Indexed4: return GetClut4(); - default: - throw new NotSupportedException($"The format {PixelFormat} is not supported."); - } - } - - private byte[] GetClut4() - { - var data = new byte[16 * 4]; - for (var i = 0; i < 16; i++) - { - data[i * 4 + 0] = _clut[(i & 15) * 4 + 0]; - data[i * 4 + 1] = _clut[(i & 15) * 4 + 1]; - data[i * 4 + 2] = _clut[(i & 15) * 4 + 2]; - data[i * 4 + 3] = Ps2.FromPs2Alpha(_clut[(i & 15) * 4 + 3]); - } - - return data; - } - - private byte[] GetClut8() - { - var data = new byte[256 * 4]; - for (var i = 0; i < 256; i++) - { - var srcIndex = Ps2.Repl(i); - data[i * 4 + 0] = _clut[srcIndex * 4 + 0]; - data[i * 4 + 1] = _clut[srcIndex * 4 + 1]; - data[i * 4 + 2] = _clut[srcIndex * 4 + 2]; - data[i * 4 + 3] = Ps2.FromPs2Alpha(_clut[srcIndex * 4 + 3]); - } - - return data; - } - - public byte[] GetData() => _data; - - public static RawBitmap Read8bit(Stream stream, int width, int height) => - new RawBitmap(stream, width, height, true); - - public static RawBitmap Read4bitPalette1(Stream stream, int width, int height) => - new RawBitmap(stream, width, height, false, false); - - public static RawBitmap Read4bitPalette2(Stream stream, int width, int height) => - new RawBitmap(stream, width, height, false, true); - - private static byte[] GeneratePalette1(uint[] fontColors) - { - var palette = new byte[16 * 4]; - for (int i = 0, index = 0; i < 16; i++) - { - palette[index++] = (byte)((fontColors[i & 3] >> 0) & 0xFF); - palette[index++] = (byte)((fontColors[i & 3] >> 8) & 0xFF); - palette[index++] = (byte)((fontColors[i & 3] >> 16) & 0xFF); - palette[index++] = (byte)((((fontColors[i & 3] >> 24) & 0xFF) + 1) / 2); - } - - return palette; - } - - private static byte[] GeneratePalette2(uint[] fontColors) - { - var palette = new byte[16 * 4]; - for (int i = 0, index = 0; i < 16; i++) - { - palette[index++] = (byte)((fontColors[i / 4] >> 0) & 0xFF); - palette[index++] = (byte)((fontColors[i / 4] >> 8) & 0xFF); - palette[index++] = (byte)((fontColors[i / 4] >> 16) & 0xFF); - palette[index++] = (byte)((((fontColors[i / 4] >> 24) & 0xFF) + 1) / 2); - } - - return palette; - } - } -} +using System; +using System.Drawing; +using System.IO; +using OpenKh.Imaging; + +namespace OpenKh.Kh2 +{ + public class RawBitmap : IImageRead + { + private const int PaletteCount = 256; + private const int BitsPerColor = 32; + private static readonly uint[] FontColors = new uint[] + { + 0x00000000, + 0x80a0a0a0, + 0xe4cccccc, + 0xfff0f0f0 + }; + private static readonly byte[] FontPalette1 = GeneratePalette1(FontColors); + private static readonly byte[] FontPalette2 = GeneratePalette2(FontColors); + + private readonly byte[] _data; + private readonly byte[] _clut; + + private RawBitmap(Stream stream, int width, int height, bool is8bit, bool defaultPaletteSwitch = false) + { + Size = new Size(width, height); + PixelFormat = is8bit ? PixelFormat.Indexed8 : PixelFormat.Indexed4; + + var reader = new BinaryReader(stream); + var bpp = is8bit ? 8 : 4; + _data = reader.ReadBytes(width * height * bpp / 8); + + if (bpp == 4) + ImageDataHelpers.SwapEndianIndexed4(_data); + + // If we did not reached the end of the stream, then it does mean that there is a palette + if (stream.Position < stream.Length) + { + _clut = reader.ReadBytes(PaletteCount * BitsPerColor / 8); + } + else + { + // Just assign a default palette + _clut = defaultPaletteSwitch ? FontPalette2 : FontPalette1; + } + } + + public Size Size { get; } + + public PixelFormat PixelFormat { get; } + + public byte[] GetClut() + { + switch (PixelFormat) + { + case PixelFormat.Indexed8: + return GetClut8(); + case PixelFormat.Indexed4: + return GetClut4(); + default: + throw new NotSupportedException($"The format {PixelFormat} is not supported."); + } + } + + private byte[] GetClut4() + { + var data = new byte[16 * 4]; + for (var i = 0; i < 16; i++) + { + data[i * 4 + 0] = _clut[(i & 15) * 4 + 0]; + data[i * 4 + 1] = _clut[(i & 15) * 4 + 1]; + data[i * 4 + 2] = _clut[(i & 15) * 4 + 2]; + data[i * 4 + 3] = Ps2.FromPs2Alpha(_clut[(i & 15) * 4 + 3]); + } + + return data; + } + + private byte[] GetClut8() + { + var data = new byte[256 * 4]; + for (var i = 0; i < 256; i++) + { + var srcIndex = Ps2.Repl(i); + data[i * 4 + 0] = _clut[srcIndex * 4 + 0]; + data[i * 4 + 1] = _clut[srcIndex * 4 + 1]; + data[i * 4 + 2] = _clut[srcIndex * 4 + 2]; + data[i * 4 + 3] = Ps2.FromPs2Alpha(_clut[srcIndex * 4 + 3]); + } + + return data; + } + + public byte[] GetData() => _data; + + public static RawBitmap Read8bit(Stream stream, int width, int height) => + new RawBitmap(stream, width, height, true); + + public static RawBitmap Read4bitPalette1(Stream stream, int width, int height) => + new RawBitmap(stream, width, height, false, false); + + public static RawBitmap Read4bitPalette2(Stream stream, int width, int height) => + new RawBitmap(stream, width, height, false, true); + + private static byte[] GeneratePalette1(uint[] fontColors) + { + var palette = new byte[16 * 4]; + for (int i = 0, index = 0; i < 16; i++) + { + palette[index++] = (byte)((fontColors[i & 3] >> 0) & 0xFF); + palette[index++] = (byte)((fontColors[i & 3] >> 8) & 0xFF); + palette[index++] = (byte)((fontColors[i & 3] >> 16) & 0xFF); + palette[index++] = (byte)((((fontColors[i & 3] >> 24) & 0xFF) + 1) / 2); + } + + return palette; + } + + private static byte[] GeneratePalette2(uint[] fontColors) + { + var palette = new byte[16 * 4]; + for (int i = 0, index = 0; i < 16; i++) + { + palette[index++] = (byte)((fontColors[i / 4] >> 0) & 0xFF); + palette[index++] = (byte)((fontColors[i / 4] >> 8) & 0xFF); + palette[index++] = (byte)((fontColors[i / 4] >> 16) & 0xFF); + palette[index++] = (byte)((((fontColors[i / 4] >> 24) & 0xFF) + 1) / 2); + } + + return palette; + } + } +} diff --git a/OpenKh.Kh2/SaveData/DriveForm.cs b/OpenKh.Kh2/SaveData/DriveForm.cs index d7d2ab482..6bbf41f35 100644 --- a/OpenKh.Kh2/SaveData/DriveForm.cs +++ b/OpenKh.Kh2/SaveData/DriveForm.cs @@ -1,46 +1,46 @@ -/* - Kingdom Save Editor - Copyright (C) 2021 Luciano Ciccariello - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SaveData -{ - public interface IDriveForm - { - short Weapon { get; set; } - byte Level { get; set; } - byte AbilityLevel { get; set; } - int Experience { get; set; } - ushort[] Abilities { get; set; } - } - - public class DriveFormVanilla : IDriveForm - { - [Data(0)] public short Weapon { get; set; } - [Data] public byte Level { get; set; } - [Data] public byte AbilityLevel { get; set; } - [Data] public int Experience { get; set; } - [Data(Count = 0x10)] public ushort[] Abilities { get; set; } - } - - public class DriveFormFinalMix : IDriveForm - { - [Data(0)] public short Weapon { get; set; } - [Data] public byte Level { get; set; } - [Data] public byte AbilityLevel { get; set; } - [Data] public int Experience { get; set; } - [Data(Count = 0x18)] public ushort[] Abilities { get; set; } - } -} +/* + Kingdom Save Editor + Copyright (C) 2021 Luciano Ciccariello + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SaveData +{ + public interface IDriveForm + { + short Weapon { get; set; } + byte Level { get; set; } + byte AbilityLevel { get; set; } + int Experience { get; set; } + ushort[] Abilities { get; set; } + } + + public class DriveFormVanilla : IDriveForm + { + [Data(0)] public short Weapon { get; set; } + [Data] public byte Level { get; set; } + [Data] public byte AbilityLevel { get; set; } + [Data] public int Experience { get; set; } + [Data(Count = 0x10)] public ushort[] Abilities { get; set; } + } + + public class DriveFormFinalMix : IDriveForm + { + [Data(0)] public short Weapon { get; set; } + [Data] public byte Level { get; set; } + [Data] public byte AbilityLevel { get; set; } + [Data] public int Experience { get; set; } + [Data(Count = 0x18)] public ushort[] Abilities { get; set; } + } +} diff --git a/OpenKh.Kh2/SaveData/ISaveData.cs b/OpenKh.Kh2/SaveData/ISaveData.cs index ac4ef16f0..79bf00fe5 100644 --- a/OpenKh.Kh2/SaveData/ISaveData.cs +++ b/OpenKh.Kh2/SaveData/ISaveData.cs @@ -1,77 +1,77 @@ -/* - Kingdom Save Editor - Copyright (C) 2021 Luciano Ciccariello - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -using System.IO; - -namespace OpenKh.Kh2.SaveData -{ - public interface ISaveData - { - bool IsFinalMix { get; } - - uint MagicCode { get; set; } - int Version { get; set; } - uint Checksum { get; set; } - byte WorldId { get; set; } - byte RoomId { get; set; } - byte SpawnId { get; set; } - byte Unused0f { get; set; } - IPlaceScript[] PlaceScripts { get; } - SaveProgress[] StoryProgress { get; set; } - - byte[] RoomVisitedFlag { get; set; } // There might be a chance that it starts from 0x2300 - int MunnyAmount { get; set; } - int Timer { get; set; } - byte Difficulty { get; set; } - byte[] PuzzlePieceFlags { get; set; } - ICharacter[] Characters { get; } - IDriveForm[] DriveForms { get; } - - PartyMembers[] WorldPartyMembers { get; set; } - byte[] InventoryCount { get; set; } - - int Experience { get; set; } - short ShortcutCircle { get; set; } - short ShortcutTriangle { get; set; } - short ShortcutSquare { get; set; } - short ShortcutCross { get; set; } - int BonusLevel { get; set; } - - bool Vibration { get; set; } - bool Unknown41a4_1 { get; set; } - bool Unknown41a4_2 { get; set; } - bool NavigationalMap { get; set; } - bool FieldCameraManual { get; set; } - bool RightAnalogStickCommand { get; set; } - bool CommandMenuClassic { get; set; } - bool CameraLeftRightReversed { get; set; } - bool CameraUpDownReversed { get; set; } - bool Unknown41a5_1 { get; set; } - bool Unknown41a5_2 { get; set; } - - short ProgressTutorialMenu { get; set; } - bool NewStatusValor { get; set; } - bool NewStatusWisdom { get; set; } - bool NewStatusLimit { get; set; } - bool NewStatusMaster { get; set; } - bool NewStatusFinal { get; set; } - bool NewStatusSummonStitch { get; set; } - bool NewStatusSummonGenie { get; set; } - bool NewStatusSummonPeterPan { get; set; } - bool NewStatusSummonChickenLittle { get; set; } - - void Write(Stream stream); - } -} +/* + Kingdom Save Editor + Copyright (C) 2021 Luciano Ciccariello + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using System.IO; + +namespace OpenKh.Kh2.SaveData +{ + public interface ISaveData + { + bool IsFinalMix { get; } + + uint MagicCode { get; set; } + int Version { get; set; } + uint Checksum { get; set; } + byte WorldId { get; set; } + byte RoomId { get; set; } + byte SpawnId { get; set; } + byte Unused0f { get; set; } + IPlaceScript[] PlaceScripts { get; } + SaveProgress[] StoryProgress { get; set; } + + byte[] RoomVisitedFlag { get; set; } // There might be a chance that it starts from 0x2300 + int MunnyAmount { get; set; } + int Timer { get; set; } + byte Difficulty { get; set; } + byte[] PuzzlePieceFlags { get; set; } + ICharacter[] Characters { get; } + IDriveForm[] DriveForms { get; } + + PartyMembers[] WorldPartyMembers { get; set; } + byte[] InventoryCount { get; set; } + + int Experience { get; set; } + short ShortcutCircle { get; set; } + short ShortcutTriangle { get; set; } + short ShortcutSquare { get; set; } + short ShortcutCross { get; set; } + int BonusLevel { get; set; } + + bool Vibration { get; set; } + bool Unknown41a4_1 { get; set; } + bool Unknown41a4_2 { get; set; } + bool NavigationalMap { get; set; } + bool FieldCameraManual { get; set; } + bool RightAnalogStickCommand { get; set; } + bool CommandMenuClassic { get; set; } + bool CameraLeftRightReversed { get; set; } + bool CameraUpDownReversed { get; set; } + bool Unknown41a5_1 { get; set; } + bool Unknown41a5_2 { get; set; } + + short ProgressTutorialMenu { get; set; } + bool NewStatusValor { get; set; } + bool NewStatusWisdom { get; set; } + bool NewStatusLimit { get; set; } + bool NewStatusMaster { get; set; } + bool NewStatusFinal { get; set; } + bool NewStatusSummonStitch { get; set; } + bool NewStatusSummonGenie { get; set; } + bool NewStatusSummonPeterPan { get; set; } + bool NewStatusSummonChickenLittle { get; set; } + + void Write(Stream stream); + } +} diff --git a/OpenKh.Kh2/SaveData/PartyMembers.cs b/OpenKh.Kh2/SaveData/PartyMembers.cs index 3704b05af..7c152be84 100644 --- a/OpenKh.Kh2/SaveData/PartyMembers.cs +++ b/OpenKh.Kh2/SaveData/PartyMembers.cs @@ -1,27 +1,27 @@ -/* - Kingdom Save Editor - Copyright (C) 2021 Luciano Ciccariello - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SaveData -{ - public class PartyMembers - { - [Data] public byte PlayableCharacter { get; set; } - [Data] public byte CompanionCharacter1 { get; set; } - [Data] public byte CompanionCharacter2 { get; set; } - [Data] public byte CompanionCharacter3 { get; set; } - } -} +/* + Kingdom Save Editor + Copyright (C) 2021 Luciano Ciccariello + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SaveData +{ + public class PartyMembers + { + [Data] public byte PlayableCharacter { get; set; } + [Data] public byte CompanionCharacter1 { get; set; } + [Data] public byte CompanionCharacter2 { get; set; } + [Data] public byte CompanionCharacter3 { get; set; } + } +} diff --git a/OpenKh.Kh2/SaveData/PlaceScript.cs b/OpenKh.Kh2/SaveData/PlaceScript.cs index f0c71d174..3b8db29c3 100644 --- a/OpenKh.Kh2/SaveData/PlaceScript.cs +++ b/OpenKh.Kh2/SaveData/PlaceScript.cs @@ -1,42 +1,42 @@ -/* - Kingdom Save Editor - Copyright (C) 2021 Luciano Ciccariello - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SaveData -{ - public interface IPlaceScript - { - byte Map { get; set; } - byte Battle { get; set; } - byte Event { get; set; } - } - public class PlaceScriptVanilla : IPlaceScript - { - [Data] public byte Map { get; set; } - [Data] public byte Battle { get; set; } - [Data] public byte Event { get; set; } - } - - public class PlaceScriptFinalMix : IPlaceScript - { - [Data] public byte Map { get; set; } - [Data] public byte MapSecondary { get; set; } - [Data] public byte Battle { get; set; } - [Data] public byte BattleSecondary { get; set; } - [Data] public byte Event { get; set; } - [Data] public byte EventSecondary { get; set; } - } -} +/* + Kingdom Save Editor + Copyright (C) 2021 Luciano Ciccariello + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SaveData +{ + public interface IPlaceScript + { + byte Map { get; set; } + byte Battle { get; set; } + byte Event { get; set; } + } + public class PlaceScriptVanilla : IPlaceScript + { + [Data] public byte Map { get; set; } + [Data] public byte Battle { get; set; } + [Data] public byte Event { get; set; } + } + + public class PlaceScriptFinalMix : IPlaceScript + { + [Data] public byte Map { get; set; } + [Data] public byte MapSecondary { get; set; } + [Data] public byte Battle { get; set; } + [Data] public byte BattleSecondary { get; set; } + [Data] public byte Event { get; set; } + [Data] public byte EventSecondary { get; set; } + } +} diff --git a/OpenKh.Kh2/SaveData/SaveCharacter.cs b/OpenKh.Kh2/SaveData/SaveCharacter.cs index 8dbc0b425..5c02b8587 100644 --- a/OpenKh.Kh2/SaveData/SaveCharacter.cs +++ b/OpenKh.Kh2/SaveData/SaveCharacter.cs @@ -1,121 +1,121 @@ -/* - Kingdom Save Editor - Copyright (C) 2021 Luciano Ciccariello - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SaveData -{ - public interface ICharacter - { - short Weapon { get; set; } - short Unk02 { get; set; } - byte HpCur { get; set; } - byte HpMax { get; set; } - byte MpCur { get; set; } - byte MpMax { get; set; } - byte ApBoost { get; set; } - byte StrengthBoost { get; set; } - byte MagicBoost { get; set; } - byte DefenseBoost { get; set; } - byte Unk0c { get; set; } - byte Unk0d { get; set; } - byte Unk0e { get; set; } - byte Level { get; set; } - byte ArmorCount { get; set; } - byte AccessoryCount { get; set; } - byte ItemCount { get; set; } - byte UnknownCount { get; set; } - short[] Armors { get; set; } - short[] Accessories { get; set; } - short[] Items { get; set; } - short[] ItemAutoReload { get; set; } - - ushort[] Abilities { get; set; } - - byte BattleStyle { get; set; } - byte AbilityStyle1 { get; set; } - byte AbilityStyle2 { get; set; } - byte AbilityStyle3 { get; set; } - byte AbilityStyle4 { get; set; } - } - - public class CharacterVanilla : ICharacter - { - [Data(Count = 0xf4)] public byte[] Data { get; set; } - - [Data(0)] public short Weapon { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public byte HpCur { get; set; } - [Data] public byte HpMax { get; set; } - [Data] public byte MpCur { get; set; } - [Data] public byte MpMax { get; set; } - [Data] public byte ApBoost { get; set; } - [Data] public byte StrengthBoost { get; set; } - [Data] public byte MagicBoost { get; set; } - [Data] public byte DefenseBoost { get; set; } - [Data] public byte Unk0c { get; set; } - [Data] public byte Unk0d { get; set; } - [Data] public byte Unk0e { get; set; } - [Data] public byte Level { get; set; } - [Data] public byte ArmorCount { get; set; } - [Data] public byte AccessoryCount { get; set; } - [Data] public byte ItemCount { get; set; } - [Data] public byte UnknownCount { get; set; } - [Data(Count = 8)] public short[] Armors { get; set; } - [Data(Count = 8)] public short[] Accessories { get; set; } - [Data(Count = 8)] public short[] Items { get; set; } - [Data(Count = 8)] public short[] ItemAutoReload { get; set; } - [Data(0x54, Count = 0x30)] public ushort[] Abilities { get; set; } - [Data] public byte BattleStyle { get; set; } - [Data] public byte AbilityStyle1 { get; set; } - [Data] public byte AbilityStyle2 { get; set; } - [Data] public byte AbilityStyle3 { get; set; } - [Data] public byte AbilityStyle4 { get; set; } - } - - public class CharacterFinalMix : ICharacter - { - [Data(Count = 0x114)] public byte[] Data { get; set; } - - [Data(0)] public short Weapon { get; set; } - [Data] public short Unk02 { get; set; } - [Data] public byte HpCur { get; set; } - [Data] public byte HpMax { get; set; } - [Data] public byte MpCur { get; set; } - [Data] public byte MpMax { get; set; } - [Data] public byte ApBoost { get; set; } - [Data] public byte StrengthBoost { get; set; } - [Data] public byte MagicBoost { get; set; } - [Data] public byte DefenseBoost { get; set; } - [Data] public byte Unk0c { get; set; } - [Data] public byte Unk0d { get; set; } - [Data] public byte Unk0e { get; set; } - [Data] public byte Level { get; set; } - [Data] public byte ArmorCount { get; set; } - [Data] public byte AccessoryCount { get; set; } - [Data] public byte ItemCount { get; set; } - [Data] public byte UnknownCount { get; set; } - [Data(Count = 8)] public short[] Armors { get; set; } - [Data(Count = 8)] public short[] Accessories { get; set; } - [Data(Count = 8)] public short[] Items { get; set; } - [Data(Count = 8)] public short[] ItemAutoReload { get; set; } - [Data(0x54, Count = 0x50)] public ushort[] Abilities { get; set; } - [Data] public byte BattleStyle { get; set; } - [Data] public byte AbilityStyle1 { get; set; } - [Data] public byte AbilityStyle2 { get; set; } - [Data] public byte AbilityStyle3 { get; set; } - [Data] public byte AbilityStyle4 { get; set; } - } -} +/* + Kingdom Save Editor + Copyright (C) 2021 Luciano Ciccariello + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SaveData +{ + public interface ICharacter + { + short Weapon { get; set; } + short Unk02 { get; set; } + byte HpCur { get; set; } + byte HpMax { get; set; } + byte MpCur { get; set; } + byte MpMax { get; set; } + byte ApBoost { get; set; } + byte StrengthBoost { get; set; } + byte MagicBoost { get; set; } + byte DefenseBoost { get; set; } + byte Unk0c { get; set; } + byte Unk0d { get; set; } + byte Unk0e { get; set; } + byte Level { get; set; } + byte ArmorCount { get; set; } + byte AccessoryCount { get; set; } + byte ItemCount { get; set; } + byte UnknownCount { get; set; } + short[] Armors { get; set; } + short[] Accessories { get; set; } + short[] Items { get; set; } + short[] ItemAutoReload { get; set; } + + ushort[] Abilities { get; set; } + + byte BattleStyle { get; set; } + byte AbilityStyle1 { get; set; } + byte AbilityStyle2 { get; set; } + byte AbilityStyle3 { get; set; } + byte AbilityStyle4 { get; set; } + } + + public class CharacterVanilla : ICharacter + { + [Data(Count = 0xf4)] public byte[] Data { get; set; } + + [Data(0)] public short Weapon { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public byte HpCur { get; set; } + [Data] public byte HpMax { get; set; } + [Data] public byte MpCur { get; set; } + [Data] public byte MpMax { get; set; } + [Data] public byte ApBoost { get; set; } + [Data] public byte StrengthBoost { get; set; } + [Data] public byte MagicBoost { get; set; } + [Data] public byte DefenseBoost { get; set; } + [Data] public byte Unk0c { get; set; } + [Data] public byte Unk0d { get; set; } + [Data] public byte Unk0e { get; set; } + [Data] public byte Level { get; set; } + [Data] public byte ArmorCount { get; set; } + [Data] public byte AccessoryCount { get; set; } + [Data] public byte ItemCount { get; set; } + [Data] public byte UnknownCount { get; set; } + [Data(Count = 8)] public short[] Armors { get; set; } + [Data(Count = 8)] public short[] Accessories { get; set; } + [Data(Count = 8)] public short[] Items { get; set; } + [Data(Count = 8)] public short[] ItemAutoReload { get; set; } + [Data(0x54, Count = 0x30)] public ushort[] Abilities { get; set; } + [Data] public byte BattleStyle { get; set; } + [Data] public byte AbilityStyle1 { get; set; } + [Data] public byte AbilityStyle2 { get; set; } + [Data] public byte AbilityStyle3 { get; set; } + [Data] public byte AbilityStyle4 { get; set; } + } + + public class CharacterFinalMix : ICharacter + { + [Data(Count = 0x114)] public byte[] Data { get; set; } + + [Data(0)] public short Weapon { get; set; } + [Data] public short Unk02 { get; set; } + [Data] public byte HpCur { get; set; } + [Data] public byte HpMax { get; set; } + [Data] public byte MpCur { get; set; } + [Data] public byte MpMax { get; set; } + [Data] public byte ApBoost { get; set; } + [Data] public byte StrengthBoost { get; set; } + [Data] public byte MagicBoost { get; set; } + [Data] public byte DefenseBoost { get; set; } + [Data] public byte Unk0c { get; set; } + [Data] public byte Unk0d { get; set; } + [Data] public byte Unk0e { get; set; } + [Data] public byte Level { get; set; } + [Data] public byte ArmorCount { get; set; } + [Data] public byte AccessoryCount { get; set; } + [Data] public byte ItemCount { get; set; } + [Data] public byte UnknownCount { get; set; } + [Data(Count = 8)] public short[] Armors { get; set; } + [Data(Count = 8)] public short[] Accessories { get; set; } + [Data(Count = 8)] public short[] Items { get; set; } + [Data(Count = 8)] public short[] ItemAutoReload { get; set; } + [Data(0x54, Count = 0x50)] public ushort[] Abilities { get; set; } + [Data] public byte BattleStyle { get; set; } + [Data] public byte AbilityStyle1 { get; set; } + [Data] public byte AbilityStyle2 { get; set; } + [Data] public byte AbilityStyle3 { get; set; } + [Data] public byte AbilityStyle4 { get; set; } + } +} diff --git a/OpenKh.Kh2/SaveData/SaveDataEuropean.cs b/OpenKh.Kh2/SaveData/SaveDataEuropean.cs index 72061bc1a..c397afa9a 100644 --- a/OpenKh.Kh2/SaveData/SaveDataEuropean.cs +++ b/OpenKh.Kh2/SaveData/SaveDataEuropean.cs @@ -1,86 +1,86 @@ -/* - Kingdom Save Editor - Copyright (C) 2021 Luciano Ciccariello - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -using OpenKh.Common; -using System; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SaveData -{ - public class SaveEuropean : ISaveData - { - public bool IsFinalMix => false; - - [Data(0, 0xb4e0)] public byte[] Data { get; set; } - - [Data(0)] public uint MagicCode { get; set; } - [Data] public int Version { get; set; } - [Data] public uint Checksum { get; set; } - [Data] public byte WorldId { get; set; } - [Data] public byte RoomId { get; set; } - [Data] public byte SpawnId { get; set; } - [Data] public byte Unused0f { get; set; } - [Data(0x13, Count = 64 * 19, Stride = 3)] public PlaceScriptVanilla[] PlaceScripts { get; set; } - [Data(0xe50, Count = 20, Stride = 0x20)] public SaveProgress[] StoryProgress { get; set; } - [Data(0x14b8, Count = 8 * Constants.WorldCount)] public byte[] RoomVisitedFlag { get; set; } - [Data(0x1600)] public int MunnyAmount { get; set; } - [Data(0x1604, Count = Constants.WorldCount + 2)] public int Timer { get; set; } - [Data(0x1658)] public byte Difficulty { get; set; } - [Data(Count = 0)] public byte[] PuzzlePieceFlags { get; set; } - [Data(0x1660, Count = 13, Stride = 0xf4)] public CharacterVanilla[] Characters { get; set; } - [Data(0x22c4, Count = 9, Stride = 0x28)] public DriveFormVanilla[] DriveForms { get; set; } - - [Data(0x3534, Count = Constants.WorldCount)] public PartyMembers[] WorldPartyMembers { get; set; } - [Data(0x2488, Count = 280)] public byte[] InventoryCount { get; set; } - [Data(0x25E8)] public int Experience { get; set; } - [Data(0x2600)] public short ShortcutCircle { get; set; } - [Data] public short ShortcutTriangle { get; set; } - [Data] public short ShortcutSquare { get; set; } - [Data] public short ShortcutCross { get; set; } - [Data] public int BonusLevel { get; set; } - - public bool Vibration { get; set; } - public bool Unknown41a4_1 { get; set; } - public bool Unknown41a4_2 { get; set; } - public bool NavigationalMap { get; set; } - public bool FieldCameraManual { get; set; } - public bool RightAnalogStickCommand { get; set; } - public bool CommandMenuClassic { get; set; } - public bool CameraLeftRightReversed { get; set; } - public bool CameraUpDownReversed { get; set; } - public bool Unknown41a5_1 { get; set; } - public bool Unknown41a5_2 { get; set; } - public short ProgressTutorialMenu { get; set; } - public bool NewStatusValor { get; set; } - public bool NewStatusWisdom { get; set; } - public bool NewStatusLimit { get; set; } - public bool NewStatusMaster { get; set; } - public bool NewStatusFinal { get; set; } - public bool NewStatusSummonStitch { get; set; } - public bool NewStatusSummonGenie { get; set; } - public bool NewStatusSummonPeterPan { get; set; } - public bool NewStatusSummonChickenLittle { get; set; } - - IPlaceScript[] ISaveData.PlaceScripts => PlaceScripts?.Cast().ToArray() ?? new IPlaceScript[0]; - ICharacter[] ISaveData.Characters => Characters?.Cast().ToArray() ?? new ICharacter[0]; - IDriveForm[] ISaveData.DriveForms => DriveForms?.Cast().ToArray() ?? new IDriveForm[0]; - - public void Write(Stream stream) => - BinaryMapping.WriteObject(stream.FromBegin(), this); - } - -} +/* + Kingdom Save Editor + Copyright (C) 2021 Luciano Ciccariello + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using OpenKh.Common; +using System; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SaveData +{ + public class SaveEuropean : ISaveData + { + public bool IsFinalMix => false; + + [Data(0, 0xb4e0)] public byte[] Data { get; set; } + + [Data(0)] public uint MagicCode { get; set; } + [Data] public int Version { get; set; } + [Data] public uint Checksum { get; set; } + [Data] public byte WorldId { get; set; } + [Data] public byte RoomId { get; set; } + [Data] public byte SpawnId { get; set; } + [Data] public byte Unused0f { get; set; } + [Data(0x13, Count = 64 * 19, Stride = 3)] public PlaceScriptVanilla[] PlaceScripts { get; set; } + [Data(0xe50, Count = 20, Stride = 0x20)] public SaveProgress[] StoryProgress { get; set; } + [Data(0x14b8, Count = 8 * Constants.WorldCount)] public byte[] RoomVisitedFlag { get; set; } + [Data(0x1600)] public int MunnyAmount { get; set; } + [Data(0x1604, Count = Constants.WorldCount + 2)] public int Timer { get; set; } + [Data(0x1658)] public byte Difficulty { get; set; } + [Data(Count = 0)] public byte[] PuzzlePieceFlags { get; set; } + [Data(0x1660, Count = 13, Stride = 0xf4)] public CharacterVanilla[] Characters { get; set; } + [Data(0x22c4, Count = 9, Stride = 0x28)] public DriveFormVanilla[] DriveForms { get; set; } + + [Data(0x3534, Count = Constants.WorldCount)] public PartyMembers[] WorldPartyMembers { get; set; } + [Data(0x2488, Count = 280)] public byte[] InventoryCount { get; set; } + [Data(0x25E8)] public int Experience { get; set; } + [Data(0x2600)] public short ShortcutCircle { get; set; } + [Data] public short ShortcutTriangle { get; set; } + [Data] public short ShortcutSquare { get; set; } + [Data] public short ShortcutCross { get; set; } + [Data] public int BonusLevel { get; set; } + + public bool Vibration { get; set; } + public bool Unknown41a4_1 { get; set; } + public bool Unknown41a4_2 { get; set; } + public bool NavigationalMap { get; set; } + public bool FieldCameraManual { get; set; } + public bool RightAnalogStickCommand { get; set; } + public bool CommandMenuClassic { get; set; } + public bool CameraLeftRightReversed { get; set; } + public bool CameraUpDownReversed { get; set; } + public bool Unknown41a5_1 { get; set; } + public bool Unknown41a5_2 { get; set; } + public short ProgressTutorialMenu { get; set; } + public bool NewStatusValor { get; set; } + public bool NewStatusWisdom { get; set; } + public bool NewStatusLimit { get; set; } + public bool NewStatusMaster { get; set; } + public bool NewStatusFinal { get; set; } + public bool NewStatusSummonStitch { get; set; } + public bool NewStatusSummonGenie { get; set; } + public bool NewStatusSummonPeterPan { get; set; } + public bool NewStatusSummonChickenLittle { get; set; } + + IPlaceScript[] ISaveData.PlaceScripts => PlaceScripts?.Cast().ToArray() ?? new IPlaceScript[0]; + ICharacter[] ISaveData.Characters => Characters?.Cast().ToArray() ?? new ICharacter[0]; + IDriveForm[] ISaveData.DriveForms => DriveForms?.Cast().ToArray() ?? new IDriveForm[0]; + + public void Write(Stream stream) => + BinaryMapping.WriteObject(stream.FromBegin(), this); + } + +} diff --git a/OpenKh.Kh2/SaveData/SaveDataFactory.cs b/OpenKh.Kh2/SaveData/SaveDataFactory.cs index 56412ecc5..74de09809 100644 --- a/OpenKh.Kh2/SaveData/SaveDataFactory.cs +++ b/OpenKh.Kh2/SaveData/SaveDataFactory.cs @@ -1,137 +1,137 @@ -/* - Kingdom Save Editor - Copyright (C) 2021 Luciano Ciccariello - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -using OpenKh.Common; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SaveData -{ - public static class SaveDataFactory - { - public const uint MagicCodeJp = 0x4a32484b; - public const uint MagicCodeUs = 0x5532484b; - public const uint MagicCodeEu = 0x4532484b; - - public enum GameVersion - { - Japanese = 0x2a, - American = 0x2d, - FinalMix = 0x3a - } - - public static bool IsValid(Stream stream) - { - var prevPosition = stream.Position; - var magicCode = new BinaryReader(stream).ReadUInt32(); - stream.Position = prevPosition; - - switch (magicCode) - { - case MagicCodeJp: - case MagicCodeUs: - case MagicCodeEu: - return true; - default: - return false; - } - } - - public static GameVersion? GetGameVersion(Stream stream) - { - if (!IsValid(stream)) - return null; - - var prevPosition = stream.Position; - stream.Position = 4; - var version = new BinaryReader(stream).ReadUInt32(); - stream.Position = prevPosition; - - switch ((GameVersion)version) - { - case GameVersion.Japanese: - case GameVersion.American: - case GameVersion.FinalMix: - return (GameVersion)version; - default: - return null; - } - } - - private static TSaveData Read(Stream stream) - where TSaveData : class, ISaveData => - BinaryMapping.ReadObject(stream.FromBegin()); - - public static ISaveData Read(Stream stream) - { - switch (GetGameVersion(stream)) - { - case GameVersion.Japanese: - throw new NotImplementedException("Japanese save file is not yet supported."); - case GameVersion.American: - return Read(stream); - case GameVersion.FinalMix: - return Read(stream); - case null: - throw new NotImplementedException("An invalid version has been specified."); - default: - throw new NotImplementedException("The version has been recognized but it is not supported."); - } - } - - public static void Write(Stream stream, TSaveData save) - where TSaveData : class, ISaveData - { - uint checksum; - using (var tempStream = new MemoryStream()) - { - save.Write(tempStream); - var rawData = tempStream.SetPosition(0xc).ReadBytes(); - checksum = CalculateChecksum(tempStream.FromBegin().ReadBytes(8), 8, uint.MaxValue); - checksum = CalculateChecksum(rawData, rawData.Length, checksum ^ uint.MaxValue); - } - - save.Checksum = checksum; - save.Write(stream.FromBegin()); - } - - private const int CrcPolynomial = 0x04c11db7; - private static uint[] crc_table = GetCrcTable(CrcPolynomial) - .Take(0x100) - .ToArray(); - - public static uint CalculateChecksum(byte[] data, int offset, uint checksum) - { - for (var i = 0; i < offset; i++) - checksum = crc_table[(checksum >> 24) ^ data[i]] ^ (checksum << 8); - - return checksum ^ uint.MaxValue; - } - - private static IEnumerable GetCrcTable(int polynomial) - { - for (var x = 0; ; x++) - { - var r = x << 24; - for (var j = 0; j < 0xff; j++) - r = r << 1 ^ (r < 0 ? polynomial : 0); - yield return (uint)r; - } - } - } -} +/* + Kingdom Save Editor + Copyright (C) 2021 Luciano Ciccariello + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using OpenKh.Common; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SaveData +{ + public static class SaveDataFactory + { + public const uint MagicCodeJp = 0x4a32484b; + public const uint MagicCodeUs = 0x5532484b; + public const uint MagicCodeEu = 0x4532484b; + + public enum GameVersion + { + Japanese = 0x2a, + American = 0x2d, + FinalMix = 0x3a + } + + public static bool IsValid(Stream stream) + { + var prevPosition = stream.Position; + var magicCode = new BinaryReader(stream).ReadUInt32(); + stream.Position = prevPosition; + + switch (magicCode) + { + case MagicCodeJp: + case MagicCodeUs: + case MagicCodeEu: + return true; + default: + return false; + } + } + + public static GameVersion? GetGameVersion(Stream stream) + { + if (!IsValid(stream)) + return null; + + var prevPosition = stream.Position; + stream.Position = 4; + var version = new BinaryReader(stream).ReadUInt32(); + stream.Position = prevPosition; + + switch ((GameVersion)version) + { + case GameVersion.Japanese: + case GameVersion.American: + case GameVersion.FinalMix: + return (GameVersion)version; + default: + return null; + } + } + + private static TSaveData Read(Stream stream) + where TSaveData : class, ISaveData => + BinaryMapping.ReadObject(stream.FromBegin()); + + public static ISaveData Read(Stream stream) + { + switch (GetGameVersion(stream)) + { + case GameVersion.Japanese: + throw new NotImplementedException("Japanese save file is not yet supported."); + case GameVersion.American: + return Read(stream); + case GameVersion.FinalMix: + return Read(stream); + case null: + throw new NotImplementedException("An invalid version has been specified."); + default: + throw new NotImplementedException("The version has been recognized but it is not supported."); + } + } + + public static void Write(Stream stream, TSaveData save) + where TSaveData : class, ISaveData + { + uint checksum; + using (var tempStream = new MemoryStream()) + { + save.Write(tempStream); + var rawData = tempStream.SetPosition(0xc).ReadBytes(); + checksum = CalculateChecksum(tempStream.FromBegin().ReadBytes(8), 8, uint.MaxValue); + checksum = CalculateChecksum(rawData, rawData.Length, checksum ^ uint.MaxValue); + } + + save.Checksum = checksum; + save.Write(stream.FromBegin()); + } + + private const int CrcPolynomial = 0x04c11db7; + private static uint[] crc_table = GetCrcTable(CrcPolynomial) + .Take(0x100) + .ToArray(); + + public static uint CalculateChecksum(byte[] data, int offset, uint checksum) + { + for (var i = 0; i < offset; i++) + checksum = crc_table[(checksum >> 24) ^ data[i]] ^ (checksum << 8); + + return checksum ^ uint.MaxValue; + } + + private static IEnumerable GetCrcTable(int polynomial) + { + for (var x = 0; ; x++) + { + var r = x << 24; + for (var j = 0; j < 0xff; j++) + r = r << 1 ^ (r < 0 ? polynomial : 0); + yield return (uint)r; + } + } + } +} diff --git a/OpenKh.Kh2/SaveData/SaveDataFinalMix.cs b/OpenKh.Kh2/SaveData/SaveDataFinalMix.cs index 54ba770f6..0a4c8c97c 100644 --- a/OpenKh.Kh2/SaveData/SaveDataFinalMix.cs +++ b/OpenKh.Kh2/SaveData/SaveDataFinalMix.cs @@ -1,113 +1,113 @@ -/* - Kingdom Save Editor - Copyright (C) 2021 Luciano Ciccariello - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -using OpenKh.Common; -using System; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SaveData -{ - public class SaveFinalMix : ISaveData - { - public bool IsFinalMix => true; - - [Data(0, 0x10FC0)] public byte[] Data { get; set; } - - [Data(0)] public uint MagicCode { get; set; } - [Data] public int Version { get; set; } - [Data] public uint Checksum { get; set; } - [Data] public byte WorldId { get; set; } - [Data] public byte RoomId { get; set; } - [Data] public byte SpawnId { get; set; } - [Data] public byte Unused0f { get; set; } - [Data(0x10, Count = 64 * 19, Stride = 6)] public PlaceScriptFinalMix[] PlaceScripts { get; set; } - [Data(0x1c90, Count = 20, Stride = 0x20)] public SaveProgress[] StoryProgress { get; set; } - // 3e8 of what? - [Data(0x22f8, Count = 8 * Constants.WorldCount)] public byte[] RoomVisitedFlag { get; set; } // There might be a chance that it starts from 0x2300 - [Data(0x2440)] public int MunnyAmount { get; set; } - [Data(0x2444, Count = Constants.WorldCount + 2)] public int Timer { get; set; } - [Data(0x2498)] public byte Difficulty { get; set; } - [Data(0x24a0, Count = 0x30)] public byte[] PuzzlePieceFlags { get; set; } - [Data(0x24f0, Count = 13, Stride = 0x114)] public CharacterFinalMix[] Characters { get; set; } - [Data(0x32f4, Count = 10, Stride = 0x38)] public DriveFormFinalMix[] DriveForms { get; set; } - - [Data(0x3526)] public byte SummonLevel { get; set; } - [Data(0x3529)] public byte DriveBarCurrent { get; set; } - [Data(0x352a)] public byte DriveBarMax { get; set; } - - [Data(0x3534, Count = Constants.WorldCount)] public PartyMembers[] WorldPartyMembers { get; set; } - [Data(0x3580, Count = 320)] public byte[] InventoryCount { get; set; } - - [Data(0x36E0)] public int Experience { get; set; } - [Data(0x36f8)] public short ShortcutCircle { get; set; } - [Data(0x36fa)] public short ShortcutTriangle { get; set; } - [Data(0x36fc)] public short ShortcutSquare { get; set; } - [Data(0x36fe)] public short ShortcutCross { get; set; } - [Data(0x3700)] public int BonusLevel { get; set; } - - [Data(0x41a4, BitIndex = 0)] public bool Vibration { get; set; } - [Data(0x41a4, BitIndex = 1)] public bool Unknown41a4_1 { get; set; } - [Data(0x41a4, BitIndex = 2)] public bool Unknown41a4_2 { get; set; } - [Data(0x41a4, BitIndex = 3)] public bool NavigationalMap { get; set; } - [Data(0x41a4, BitIndex = 4)] public bool FieldCameraManual { get; set; } - [Data(0x41a4, BitIndex = 5)] public bool RightAnalogStickCommand { get; set; } - [Data(0x41a4, BitIndex = 6)] public bool CommandMenuClassic { get; set; } - [Data(0x41a4, BitIndex = 7)] public bool CameraLeftRightReversed { get; set; } - [Data(0x41a5, BitIndex = 0)] public bool CameraUpDownReversed { get; set; } - [Data(0x41a5, BitIndex = 1)] public bool Unknown41a5_1 { get; set; } - [Data(0x41a5, BitIndex = 2)] public bool Unknown41a5_2 { get; set; } - - // WRONG. - // [Data(0x41aa, BitIndex = 0)] public bool NewMagicUnk1_0 { get; set; } - // [Data(0x41aa, BitIndex = 1)] public bool NewMagicUnk1_1 { get; set; } - // [Data(0x41aa, BitIndex = 2)] public bool NewMagicUnk1_2 { get; set; } - // [Data(0x41aa, BitIndex = 3)] public bool NewMagicUnk1_4 { get; set; } - // [Data(0x41aa, BitIndex = 4)] public bool NewMagicUnk1_8 { get; set; } - // [Data(0x41aa, BitIndex = 5)] public bool NewMagicFiraga { get; set; } - // [Data(0x41aa, BitIndex = 6)] public bool NewMagicBlizzaga { get; set; } - // [Data(0x41aa, BitIndex = 7)] public bool NewMagicThundaga { get; set; } - // [Data(0x41ab, BitIndex = 0)] public bool NewMagicCuraga { get; set; } - // [Data(0x41ab, BitIndex = 1)] public bool NewMagicUnkUnk { get; set; } - // [Data(0x41b2, BitIndex = 0)] public bool NewMagicUnk2_0 { get; set; } - // [Data(0x41b2, BitIndex = 1)] public bool NewMagicUnk2_1 { get; set; } - // [Data(0x41b2, BitIndex = 2)] public bool NewMagicUnk2_2 { get; set; } - // [Data(0x41b2, BitIndex = 3)] public bool NewMagicUnk2_4 { get; set; } - // [Data(0x41b2, BitIndex = 4)] public bool NewMagicUnk2_8 { get; set; } - // [Data(0x41b2, BitIndex = 5)] public bool NewMagicUnk2_10 { get; set; } - // [Data(0x41b2, BitIndex = 6)] public bool NewMagicUnk2_20 { get; set; } - // [Data(0x41b2, BitIndex = 7)] public bool NewMagicMagnega { get; set; } - // [Data(0x41b3)] public bool NewMagicReflega { get; set; } - - [Data(0x4270)] public short ProgressTutorialMenu { get; set; } - [Data(0x4274)] public bool NewStatusValor { get; set; } - [Data(0x4274)] public bool NewStatusWisdom { get; set; } - [Data(0x4274)] public bool NewStatusLimit { get; set; } - [Data(0x4274)] public bool NewStatusMaster { get; set; } - [Data(0x4274)] public bool NewStatusFinal { get; set; } - [Data(0x4274)] public bool NewStatusSummonStitch { get; set; } - [Data(0x4274)] public bool NewStatusSummonGenie { get; set; } - [Data(0x4274)] public bool NewStatusSummonPeterPan { get; set; } - [Data(0x4275)] public bool NewStatusSummonChickenLittle { get; set; } - - IPlaceScript[] ISaveData.PlaceScripts => PlaceScripts?.Cast().ToArray() ?? new IPlaceScript[0]; - ICharacter[] ISaveData.Characters => Characters?.Cast().ToArray() ?? new ICharacter[0]; - IDriveForm[] ISaveData.DriveForms => DriveForms?.Cast().ToArray() ?? new IDriveForm[0]; - - public void Write(Stream stream) => - BinaryMapping.WriteObject(stream.FromBegin(), this); - } -} +/* + Kingdom Save Editor + Copyright (C) 2021 Luciano Ciccariello + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using OpenKh.Common; +using System; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SaveData +{ + public class SaveFinalMix : ISaveData + { + public bool IsFinalMix => true; + + [Data(0, 0x10FC0)] public byte[] Data { get; set; } + + [Data(0)] public uint MagicCode { get; set; } + [Data] public int Version { get; set; } + [Data] public uint Checksum { get; set; } + [Data] public byte WorldId { get; set; } + [Data] public byte RoomId { get; set; } + [Data] public byte SpawnId { get; set; } + [Data] public byte Unused0f { get; set; } + [Data(0x10, Count = 64 * 19, Stride = 6)] public PlaceScriptFinalMix[] PlaceScripts { get; set; } + [Data(0x1c90, Count = 20, Stride = 0x20)] public SaveProgress[] StoryProgress { get; set; } + // 3e8 of what? + [Data(0x22f8, Count = 8 * Constants.WorldCount)] public byte[] RoomVisitedFlag { get; set; } // There might be a chance that it starts from 0x2300 + [Data(0x2440)] public int MunnyAmount { get; set; } + [Data(0x2444, Count = Constants.WorldCount + 2)] public int Timer { get; set; } + [Data(0x2498)] public byte Difficulty { get; set; } + [Data(0x24a0, Count = 0x30)] public byte[] PuzzlePieceFlags { get; set; } + [Data(0x24f0, Count = 13, Stride = 0x114)] public CharacterFinalMix[] Characters { get; set; } + [Data(0x32f4, Count = 10, Stride = 0x38)] public DriveFormFinalMix[] DriveForms { get; set; } + + [Data(0x3526)] public byte SummonLevel { get; set; } + [Data(0x3529)] public byte DriveBarCurrent { get; set; } + [Data(0x352a)] public byte DriveBarMax { get; set; } + + [Data(0x3534, Count = Constants.WorldCount)] public PartyMembers[] WorldPartyMembers { get; set; } + [Data(0x3580, Count = 320)] public byte[] InventoryCount { get; set; } + + [Data(0x36E0)] public int Experience { get; set; } + [Data(0x36f8)] public short ShortcutCircle { get; set; } + [Data(0x36fa)] public short ShortcutTriangle { get; set; } + [Data(0x36fc)] public short ShortcutSquare { get; set; } + [Data(0x36fe)] public short ShortcutCross { get; set; } + [Data(0x3700)] public int BonusLevel { get; set; } + + [Data(0x41a4, BitIndex = 0)] public bool Vibration { get; set; } + [Data(0x41a4, BitIndex = 1)] public bool Unknown41a4_1 { get; set; } + [Data(0x41a4, BitIndex = 2)] public bool Unknown41a4_2 { get; set; } + [Data(0x41a4, BitIndex = 3)] public bool NavigationalMap { get; set; } + [Data(0x41a4, BitIndex = 4)] public bool FieldCameraManual { get; set; } + [Data(0x41a4, BitIndex = 5)] public bool RightAnalogStickCommand { get; set; } + [Data(0x41a4, BitIndex = 6)] public bool CommandMenuClassic { get; set; } + [Data(0x41a4, BitIndex = 7)] public bool CameraLeftRightReversed { get; set; } + [Data(0x41a5, BitIndex = 0)] public bool CameraUpDownReversed { get; set; } + [Data(0x41a5, BitIndex = 1)] public bool Unknown41a5_1 { get; set; } + [Data(0x41a5, BitIndex = 2)] public bool Unknown41a5_2 { get; set; } + + // WRONG. + // [Data(0x41aa, BitIndex = 0)] public bool NewMagicUnk1_0 { get; set; } + // [Data(0x41aa, BitIndex = 1)] public bool NewMagicUnk1_1 { get; set; } + // [Data(0x41aa, BitIndex = 2)] public bool NewMagicUnk1_2 { get; set; } + // [Data(0x41aa, BitIndex = 3)] public bool NewMagicUnk1_4 { get; set; } + // [Data(0x41aa, BitIndex = 4)] public bool NewMagicUnk1_8 { get; set; } + // [Data(0x41aa, BitIndex = 5)] public bool NewMagicFiraga { get; set; } + // [Data(0x41aa, BitIndex = 6)] public bool NewMagicBlizzaga { get; set; } + // [Data(0x41aa, BitIndex = 7)] public bool NewMagicThundaga { get; set; } + // [Data(0x41ab, BitIndex = 0)] public bool NewMagicCuraga { get; set; } + // [Data(0x41ab, BitIndex = 1)] public bool NewMagicUnkUnk { get; set; } + // [Data(0x41b2, BitIndex = 0)] public bool NewMagicUnk2_0 { get; set; } + // [Data(0x41b2, BitIndex = 1)] public bool NewMagicUnk2_1 { get; set; } + // [Data(0x41b2, BitIndex = 2)] public bool NewMagicUnk2_2 { get; set; } + // [Data(0x41b2, BitIndex = 3)] public bool NewMagicUnk2_4 { get; set; } + // [Data(0x41b2, BitIndex = 4)] public bool NewMagicUnk2_8 { get; set; } + // [Data(0x41b2, BitIndex = 5)] public bool NewMagicUnk2_10 { get; set; } + // [Data(0x41b2, BitIndex = 6)] public bool NewMagicUnk2_20 { get; set; } + // [Data(0x41b2, BitIndex = 7)] public bool NewMagicMagnega { get; set; } + // [Data(0x41b3)] public bool NewMagicReflega { get; set; } + + [Data(0x4270)] public short ProgressTutorialMenu { get; set; } + [Data(0x4274)] public bool NewStatusValor { get; set; } + [Data(0x4274)] public bool NewStatusWisdom { get; set; } + [Data(0x4274)] public bool NewStatusLimit { get; set; } + [Data(0x4274)] public bool NewStatusMaster { get; set; } + [Data(0x4274)] public bool NewStatusFinal { get; set; } + [Data(0x4274)] public bool NewStatusSummonStitch { get; set; } + [Data(0x4274)] public bool NewStatusSummonGenie { get; set; } + [Data(0x4274)] public bool NewStatusSummonPeterPan { get; set; } + [Data(0x4275)] public bool NewStatusSummonChickenLittle { get; set; } + + IPlaceScript[] ISaveData.PlaceScripts => PlaceScripts?.Cast().ToArray() ?? new IPlaceScript[0]; + ICharacter[] ISaveData.Characters => Characters?.Cast().ToArray() ?? new ICharacter[0]; + IDriveForm[] ISaveData.DriveForms => DriveForms?.Cast().ToArray() ?? new IDriveForm[0]; + + public void Write(Stream stream) => + BinaryMapping.WriteObject(stream.FromBegin(), this); + } +} diff --git a/OpenKh.Kh2/SaveData/SaveProgress.cs b/OpenKh.Kh2/SaveData/SaveProgress.cs index 8714c4311..0831c0c27 100644 --- a/OpenKh.Kh2/SaveData/SaveProgress.cs +++ b/OpenKh.Kh2/SaveData/SaveProgress.cs @@ -1,34 +1,34 @@ -/* - Kingdom Save Editor - Copyright (C) 2021 Luciano Ciccariello - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SaveData -{ - public class SaveProgress - { - [Data(Count = 0x20)] public byte[] Flags { get; set; } - - public bool GetFlag(int index) => (Flags[index / 8] & (1 << (index % 8))) != 0; - public void SetFlag(int index, bool value) - { - var mask = (byte)(1 << (index % 8)); - if (value) - Flags[index / 8] |= mask; - else - Flags[index / 8] &= (byte)~mask; - } - } -} +/* + Kingdom Save Editor + Copyright (C) 2021 Luciano Ciccariello + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SaveData +{ + public class SaveProgress + { + [Data(Count = 0x20)] public byte[] Flags { get; set; } + + public bool GetFlag(int index) => (Flags[index / 8] & (1 << (index % 8))) != 0; + public void SetFlag(int index, bool value) + { + var mask = (byte)(1 << (index % 8)); + if (value) + Flags[index / 8] |= mask; + else + Flags[index / 8] &= (byte)~mask; + } + } +} diff --git a/OpenKh.Kh2/Sequence.cs b/OpenKh.Kh2/Sequence.cs index 6c4deccba..e5141be87 100644 --- a/OpenKh.Kh2/Sequence.cs +++ b/OpenKh.Kh2/Sequence.cs @@ -1,307 +1,307 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; -using Xe.IO; - -namespace OpenKh.Kh2 -{ - public class Sequence - { - public static readonly uint MagicCodeValidator = 0x44514553U; - private static readonly long MinimumLength = 48L; - - public const int DisableCurveFlag = 0x00000001; - public const int IsActiveFlag = 0x00000002; - public const int DisableBilinearFlag = 0x00000004; - public const int BounceDelayFlag = 0x00000008; - public const int BounceDisableFlag = 0x00000010; - public const int RotationDisableFlag = 0x00000020; - public const int ScalingDisableFlag = 0x00000040; - public const int ColorInterpolationFlag = 0x00000080; - public const int RotationInterpolationFlag = 0x00000100; - public const int ScalingInterpolationFlag = 0x00000200; - public const int ColorMaskFlag = 0x00000400; - public const int BounceInterpolationFlag = 0x00000800; - public const int TranslationInterpolationFlag = 0x00001000; - public const int PivotInterpolationFlag = 0x00002000; - public const int PivotDisableFlag = 0x00004000; - public const int LastCutFlag = 0x00008000; - public const int TranslationDisableFlag = 0x00010000; - public const int TranslationOffsetDisableFlag = 0x00020000; - public const int PositionDisableFlag = 0x00040000; - public const int TagFlag = 0x00080000; - - private class Section - { - [Data] public int Count { get; set; } - [Data] public int Offset { get; set; } - } - - private class Header - { - [Data] public uint MagicCode { get; set; } - [Data] public int Unknown04 { get; set; } - [Data] public Section SpriteDesc { get; set; } - [Data] public Section SpritePartDesc { get; set; } - [Data] public Section SpriteGroupDesc { get; set; } - [Data] public Section AnimationDesc { get; set; } - [Data] public Section AnimationGroupDesc { get; set; } - } - - public class RawSprite - { - [Data] public int Palette { get; set; } - [Data] public int U0 { get; set; } - [Data] public int V0 { get; set; } - [Data] public int U1 { get; set; } - [Data] public int V1 { get; set; } - [Data] public float UScroll { get; set; } - [Data] public float VScroll { get; set; } - [Data] public uint ColorLeft { get; set; } - [Data] public uint ColorTop { get; set; } - [Data] public uint ColorRight { get; set; } - [Data] public uint ColorBottom { get; set; } - } - - public class RawSpriteGroup - { - [Data] public short Start { get; set; } - [Data] public short Count { get; set; } - } - - public class RawAnimationGroup - { - [Data] public short AnimationIndex { get; set; } - [Data] public short Count { get; set; } - [Data] public short Loop { get; set; } - [Data] public short Flags { get; set; } - [Data] public int FrameStart { get; set; } - [Data] public int FrameEnd { get; set; } - [Data] public int X { get; set; } - [Data] public int Y { get; set; } - [Data] public int Size { get; set; } - [Data] public int Unknown1C { get; set; } - [Data] public int Unknown20 { get; set; } - } - - public class Sprite - { - public int Left { get; set; } - public int Top { get; set; } - public int Right { get; set; } - public int Bottom { get; set; } - public float UTranslation { get; set; } - public float VTranslation { get; set; } - public uint ColorLeft { get; set; } - public uint ColorTop { get; set; } - public uint ColorRight { get; set; } - public uint ColorBottom { get; set; } - } - - public class SpritePart - { - [Data] public int Left { get; set; } - [Data] public int Top { get; set; } - [Data] public int Right { get; set; } - [Data] public int Bottom { get; set; } - [Data] public int SpriteIndex { get; set; } - } - - public class Animation - { - [Data] public int Flags { get; set; } - [Data] public int SpriteGroupIndex { get; set; } - [Data] public int FrameStart { get; set; } - [Data] public int FrameEnd { get; set; } - [Data] public int TranslateXStart { get; set; } - [Data] public int TranslateXEnd { get; set; } - [Data] public int TranslateYStart { get; set; } - [Data] public int TranslateYEnd { get; set; } - [Data] public int PivotXStart { get; set; } - [Data] public int PivotXEnd { get; set; } - [Data] public int PivotYStart { get; set; } - [Data] public int PivotYEnd { get; set; } - [Data] public float RotationXStart { get; set; } - [Data] public float RotationXEnd { get; set; } - [Data] public float RotationYStart { get; set; } - [Data] public float RotationYEnd { get; set; } - [Data] public float RotationZStart { get; set; } - [Data] public float RotationZEnd { get; set; } - [Data] public float ScaleStart { get; set; } - [Data] public float ScaleEnd { get; set; } - [Data] public float ScaleXStart { get; set; } - [Data] public float ScaleXEnd { get; set; } - [Data] public float ScaleYStart { get; set; } - [Data] public float ScaleYEnd { get; set; } - [Data] public float CurveXStart { get; set; } - [Data] public float CurveYStart { get; set; } - [Data] public float CurveXEnd { get; set; } - [Data] public float CurveYEnd { get; set; } - [Data] public float BounceXStart { get; set; } - [Data] public float BounceXEnd { get; set; } - [Data] public float BounceYStart { get; set; } - [Data] public float BounceYEnd { get; set; } - [Data] public short BounceXCount { get; set; } - [Data] public short BounceYCount { get; set; } - [Data] public int ColorBlend { get; set; } - [Data] public uint ColorStart { get; set; } - [Data] public uint ColorEnd { get; set; } - } - - public class AnimationGroup - { - public List Animations { get; set; } - public short DoNotLoop { get; set; } - public short Unknown06 { get; set; } - public int LoopStart { get; set; } - public int LoopEnd { get; set; } - public int LightPositionX { get; set; } - public int TextPositionY { get; set; } - public int TextScale { get; set; } - public int UiPadding { get; set; } - public int TextPositionX { get; set; } - } - - public int Unknown04 { get; set; } - public List Sprites { get; set; } - public List> SpriteGroups { get; set; } - public List AnimationGroups { get; set; } - - public Sequence() - { - Unknown04 = 0x100; // assuming that this value is constant - } - - private Sequence(Stream inputStream) - { - inputStream.MustReadAndSeek(); - if (inputStream.Length < MinimumLength) - throw new InvalidDataException("Invalid header length"); - - var stream = new SubStream(inputStream, inputStream.Position, inputStream.Length - inputStream.Position); - var header = BinaryMapping.ReadObject
(stream); - if (header.MagicCode != MagicCodeValidator) - throw new InvalidDataException("Invalid header"); - - Unknown04 = header.Unknown04; - Sprites = stream.ReadList(header.SpriteDesc.Offset, header.SpriteDesc.Count) - .Select(x => new Sprite - { - Left = x.U0, - Top = x.V0, - Right = x.U1, - Bottom = x.V1, - UTranslation = x.UScroll, - VTranslation = x.VScroll, - ColorLeft = x.ColorLeft, - ColorTop = x.ColorTop, - ColorRight = x.ColorRight, - ColorBottom = x.ColorBottom, - }).ToList(); - - var spritePart = stream.ReadList(header.SpritePartDesc.Offset, header.SpritePartDesc.Count); - SpriteGroups = stream.ReadList(header.SpriteGroupDesc.Offset, header.SpriteGroupDesc.Count) - .Select(x => spritePart.Skip(x.Start).Take(x.Count).ToList()).ToList(); - - var animations = stream.ReadList(header.AnimationDesc.Offset, header.AnimationDesc.Count); - AnimationGroups = stream.ReadList(header.AnimationGroupDesc.Offset, header.AnimationGroupDesc.Count) - .Select(x => new AnimationGroup - { - Animations = animations.Skip(x.AnimationIndex).Take(x.Count).ToList(), - DoNotLoop = x.Loop, - Unknown06 = x.Flags, - LoopStart = x.FrameStart, - LoopEnd = x.FrameEnd, - LightPositionX = x.X, - TextPositionY = x.Y, - TextScale = x.Size, - UiPadding = x.Unknown1C, - TextPositionX = x.Unknown20, - }).ToList(); - } - - public void Write(Stream stream) - { - stream.MustWriteAndSeek(); - - var header = new Header - { - MagicCode = MagicCodeValidator, - Unknown04 = Unknown04, - SpriteDesc = new Section() { Count = Sprites.Count }, - SpritePartDesc = new Section() { Count = SpriteGroups.Sum(x => x.Count) }, - SpriteGroupDesc = new Section() { Count = SpriteGroups.Count }, - AnimationDesc = new Section() { Count = AnimationGroups.Sum(x => x.Animations.Count) }, - AnimationGroupDesc = new Section() { Count = AnimationGroups.Count }, - }; - - var index = 0; - var basePosition = stream.Position; - - stream.Position = basePosition + MinimumLength; - header.SpriteDesc.Offset = (int)(stream.Position - basePosition); - - header.SpritePartDesc.Offset = stream.WriteList(Sprites.Select(x => new RawSprite - { - U0 = x.Left, - V0 = x.Top, - U1 = x.Right, - V1 = x.Bottom, - UScroll = x.UTranslation, - VScroll = x.VTranslation, - ColorLeft = x.ColorLeft, - ColorTop = x.ColorTop, - ColorRight = x.ColorRight, - ColorBottom = x.ColorBottom, - })) + header.SpriteDesc.Offset; - header.SpriteGroupDesc.Offset = stream.WriteList(SpriteGroups.SelectMany(x => x)) + header.SpritePartDesc.Offset; - - index = 0; - foreach (var spriteGroup in SpriteGroups) - { - BinaryMapping.WriteObject(stream, new RawSpriteGroup - { - Start = (short)index, - Count = (short)spriteGroup.Count - }); - - index += spriteGroup.Count; - } - header.AnimationDesc.Offset = SpriteGroups.Count * 4 + header.SpriteGroupDesc.Offset; - header.AnimationGroupDesc.Offset = stream.WriteList(AnimationGroups.SelectMany(x => x.Animations)) + header.AnimationDesc.Offset; - index = 0; - foreach (var animGroup in AnimationGroups) - { - BinaryMapping.WriteObject(stream, new RawAnimationGroup - { - AnimationIndex = (short)index, - Count = (short)animGroup.Animations.Count, - Loop = animGroup.DoNotLoop, - Flags = animGroup.Unknown06, - FrameStart = animGroup.LoopStart, - FrameEnd = animGroup.LoopEnd, - X = animGroup.LightPositionX, - Y = animGroup.TextPositionY, - Size = animGroup.TextScale, - Unknown1C = animGroup.UiPadding, - Unknown20 = animGroup.TextPositionX, - }); - - index += animGroup.Animations.Count; - } - - var endPosition = stream.Position; - stream.Position = basePosition; - BinaryMapping.WriteObject(stream, header); - stream.Position = endPosition; - } - - public static Sequence Read(Stream stream) => - new Sequence(stream); - - public static bool IsValid(Stream stream) => - stream.Length >= MinimumLength && stream.PeekInt32() == MagicCodeValidator; - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; +using Xe.IO; + +namespace OpenKh.Kh2 +{ + public class Sequence + { + public static readonly uint MagicCodeValidator = 0x44514553U; + private static readonly long MinimumLength = 48L; + + public const int DisableCurveFlag = 0x00000001; + public const int IsActiveFlag = 0x00000002; + public const int DisableBilinearFlag = 0x00000004; + public const int BounceDelayFlag = 0x00000008; + public const int BounceDisableFlag = 0x00000010; + public const int RotationDisableFlag = 0x00000020; + public const int ScalingDisableFlag = 0x00000040; + public const int ColorInterpolationFlag = 0x00000080; + public const int RotationInterpolationFlag = 0x00000100; + public const int ScalingInterpolationFlag = 0x00000200; + public const int ColorMaskFlag = 0x00000400; + public const int BounceInterpolationFlag = 0x00000800; + public const int TranslationInterpolationFlag = 0x00001000; + public const int PivotInterpolationFlag = 0x00002000; + public const int PivotDisableFlag = 0x00004000; + public const int LastCutFlag = 0x00008000; + public const int TranslationDisableFlag = 0x00010000; + public const int TranslationOffsetDisableFlag = 0x00020000; + public const int PositionDisableFlag = 0x00040000; + public const int TagFlag = 0x00080000; + + private class Section + { + [Data] public int Count { get; set; } + [Data] public int Offset { get; set; } + } + + private class Header + { + [Data] public uint MagicCode { get; set; } + [Data] public int Unknown04 { get; set; } + [Data] public Section SpriteDesc { get; set; } + [Data] public Section SpritePartDesc { get; set; } + [Data] public Section SpriteGroupDesc { get; set; } + [Data] public Section AnimationDesc { get; set; } + [Data] public Section AnimationGroupDesc { get; set; } + } + + public class RawSprite + { + [Data] public int Palette { get; set; } + [Data] public int U0 { get; set; } + [Data] public int V0 { get; set; } + [Data] public int U1 { get; set; } + [Data] public int V1 { get; set; } + [Data] public float UScroll { get; set; } + [Data] public float VScroll { get; set; } + [Data] public uint ColorLeft { get; set; } + [Data] public uint ColorTop { get; set; } + [Data] public uint ColorRight { get; set; } + [Data] public uint ColorBottom { get; set; } + } + + public class RawSpriteGroup + { + [Data] public short Start { get; set; } + [Data] public short Count { get; set; } + } + + public class RawAnimationGroup + { + [Data] public short AnimationIndex { get; set; } + [Data] public short Count { get; set; } + [Data] public short Loop { get; set; } + [Data] public short Flags { get; set; } + [Data] public int FrameStart { get; set; } + [Data] public int FrameEnd { get; set; } + [Data] public int X { get; set; } + [Data] public int Y { get; set; } + [Data] public int Size { get; set; } + [Data] public int Unknown1C { get; set; } + [Data] public int Unknown20 { get; set; } + } + + public class Sprite + { + public int Left { get; set; } + public int Top { get; set; } + public int Right { get; set; } + public int Bottom { get; set; } + public float UTranslation { get; set; } + public float VTranslation { get; set; } + public uint ColorLeft { get; set; } + public uint ColorTop { get; set; } + public uint ColorRight { get; set; } + public uint ColorBottom { get; set; } + } + + public class SpritePart + { + [Data] public int Left { get; set; } + [Data] public int Top { get; set; } + [Data] public int Right { get; set; } + [Data] public int Bottom { get; set; } + [Data] public int SpriteIndex { get; set; } + } + + public class Animation + { + [Data] public int Flags { get; set; } + [Data] public int SpriteGroupIndex { get; set; } + [Data] public int FrameStart { get; set; } + [Data] public int FrameEnd { get; set; } + [Data] public int TranslateXStart { get; set; } + [Data] public int TranslateXEnd { get; set; } + [Data] public int TranslateYStart { get; set; } + [Data] public int TranslateYEnd { get; set; } + [Data] public int PivotXStart { get; set; } + [Data] public int PivotXEnd { get; set; } + [Data] public int PivotYStart { get; set; } + [Data] public int PivotYEnd { get; set; } + [Data] public float RotationXStart { get; set; } + [Data] public float RotationXEnd { get; set; } + [Data] public float RotationYStart { get; set; } + [Data] public float RotationYEnd { get; set; } + [Data] public float RotationZStart { get; set; } + [Data] public float RotationZEnd { get; set; } + [Data] public float ScaleStart { get; set; } + [Data] public float ScaleEnd { get; set; } + [Data] public float ScaleXStart { get; set; } + [Data] public float ScaleXEnd { get; set; } + [Data] public float ScaleYStart { get; set; } + [Data] public float ScaleYEnd { get; set; } + [Data] public float CurveXStart { get; set; } + [Data] public float CurveYStart { get; set; } + [Data] public float CurveXEnd { get; set; } + [Data] public float CurveYEnd { get; set; } + [Data] public float BounceXStart { get; set; } + [Data] public float BounceXEnd { get; set; } + [Data] public float BounceYStart { get; set; } + [Data] public float BounceYEnd { get; set; } + [Data] public short BounceXCount { get; set; } + [Data] public short BounceYCount { get; set; } + [Data] public int ColorBlend { get; set; } + [Data] public uint ColorStart { get; set; } + [Data] public uint ColorEnd { get; set; } + } + + public class AnimationGroup + { + public List Animations { get; set; } + public short DoNotLoop { get; set; } + public short Unknown06 { get; set; } + public int LoopStart { get; set; } + public int LoopEnd { get; set; } + public int LightPositionX { get; set; } + public int TextPositionY { get; set; } + public int TextScale { get; set; } + public int UiPadding { get; set; } + public int TextPositionX { get; set; } + } + + public int Unknown04 { get; set; } + public List Sprites { get; set; } + public List> SpriteGroups { get; set; } + public List AnimationGroups { get; set; } + + public Sequence() + { + Unknown04 = 0x100; // assuming that this value is constant + } + + private Sequence(Stream inputStream) + { + inputStream.MustReadAndSeek(); + if (inputStream.Length < MinimumLength) + throw new InvalidDataException("Invalid header length"); + + var stream = new SubStream(inputStream, inputStream.Position, inputStream.Length - inputStream.Position); + var header = BinaryMapping.ReadObject
(stream); + if (header.MagicCode != MagicCodeValidator) + throw new InvalidDataException("Invalid header"); + + Unknown04 = header.Unknown04; + Sprites = stream.ReadList(header.SpriteDesc.Offset, header.SpriteDesc.Count) + .Select(x => new Sprite + { + Left = x.U0, + Top = x.V0, + Right = x.U1, + Bottom = x.V1, + UTranslation = x.UScroll, + VTranslation = x.VScroll, + ColorLeft = x.ColorLeft, + ColorTop = x.ColorTop, + ColorRight = x.ColorRight, + ColorBottom = x.ColorBottom, + }).ToList(); + + var spritePart = stream.ReadList(header.SpritePartDesc.Offset, header.SpritePartDesc.Count); + SpriteGroups = stream.ReadList(header.SpriteGroupDesc.Offset, header.SpriteGroupDesc.Count) + .Select(x => spritePart.Skip(x.Start).Take(x.Count).ToList()).ToList(); + + var animations = stream.ReadList(header.AnimationDesc.Offset, header.AnimationDesc.Count); + AnimationGroups = stream.ReadList(header.AnimationGroupDesc.Offset, header.AnimationGroupDesc.Count) + .Select(x => new AnimationGroup + { + Animations = animations.Skip(x.AnimationIndex).Take(x.Count).ToList(), + DoNotLoop = x.Loop, + Unknown06 = x.Flags, + LoopStart = x.FrameStart, + LoopEnd = x.FrameEnd, + LightPositionX = x.X, + TextPositionY = x.Y, + TextScale = x.Size, + UiPadding = x.Unknown1C, + TextPositionX = x.Unknown20, + }).ToList(); + } + + public void Write(Stream stream) + { + stream.MustWriteAndSeek(); + + var header = new Header + { + MagicCode = MagicCodeValidator, + Unknown04 = Unknown04, + SpriteDesc = new Section() { Count = Sprites.Count }, + SpritePartDesc = new Section() { Count = SpriteGroups.Sum(x => x.Count) }, + SpriteGroupDesc = new Section() { Count = SpriteGroups.Count }, + AnimationDesc = new Section() { Count = AnimationGroups.Sum(x => x.Animations.Count) }, + AnimationGroupDesc = new Section() { Count = AnimationGroups.Count }, + }; + + var index = 0; + var basePosition = stream.Position; + + stream.Position = basePosition + MinimumLength; + header.SpriteDesc.Offset = (int)(stream.Position - basePosition); + + header.SpritePartDesc.Offset = stream.WriteList(Sprites.Select(x => new RawSprite + { + U0 = x.Left, + V0 = x.Top, + U1 = x.Right, + V1 = x.Bottom, + UScroll = x.UTranslation, + VScroll = x.VTranslation, + ColorLeft = x.ColorLeft, + ColorTop = x.ColorTop, + ColorRight = x.ColorRight, + ColorBottom = x.ColorBottom, + })) + header.SpriteDesc.Offset; + header.SpriteGroupDesc.Offset = stream.WriteList(SpriteGroups.SelectMany(x => x)) + header.SpritePartDesc.Offset; + + index = 0; + foreach (var spriteGroup in SpriteGroups) + { + BinaryMapping.WriteObject(stream, new RawSpriteGroup + { + Start = (short)index, + Count = (short)spriteGroup.Count + }); + + index += spriteGroup.Count; + } + header.AnimationDesc.Offset = SpriteGroups.Count * 4 + header.SpriteGroupDesc.Offset; + header.AnimationGroupDesc.Offset = stream.WriteList(AnimationGroups.SelectMany(x => x.Animations)) + header.AnimationDesc.Offset; + index = 0; + foreach (var animGroup in AnimationGroups) + { + BinaryMapping.WriteObject(stream, new RawAnimationGroup + { + AnimationIndex = (short)index, + Count = (short)animGroup.Animations.Count, + Loop = animGroup.DoNotLoop, + Flags = animGroup.Unknown06, + FrameStart = animGroup.LoopStart, + FrameEnd = animGroup.LoopEnd, + X = animGroup.LightPositionX, + Y = animGroup.TextPositionY, + Size = animGroup.TextScale, + Unknown1C = animGroup.UiPadding, + Unknown20 = animGroup.TextPositionX, + }); + + index += animGroup.Animations.Count; + } + + var endPosition = stream.Position; + stream.Position = basePosition; + BinaryMapping.WriteObject(stream, header); + stream.Position = endPosition; + } + + public static Sequence Read(Stream stream) => + new Sequence(stream); + + public static bool IsValid(Stream stream) => + stream.Length >= MinimumLength && stream.PeekInt32() == MagicCodeValidator; + } +} diff --git a/OpenKh.Kh2/SystemData/Arif.cs b/OpenKh.Kh2/SystemData/Arif.cs index 29e52264f..ea38c4dcd 100644 --- a/OpenKh.Kh2/SystemData/Arif.cs +++ b/OpenKh.Kh2/SystemData/Arif.cs @@ -1,73 +1,73 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SystemData -{ - public class BgmSet - { - [Data] public ushort BgmField { get; set; } - [Data] public ushort BgmBattle { get; set; } - } - - /// - /// AreaInfo - /// - public class Arif - { - [Data] public uint Flags { get; set; } - [Data] public int Reverb { get; set; } - [Data] public int SoundEffectBank1 { get; set; } - [Data] public int SoundEffectBank2 { get; set; } - [Data(Count = 8)] public BgmSet[] Bgms { get; set; } - [Data] public ushort Voice { get; set; } - [Data] public ushort NavigationMapItem { get; set; } - [Data] public byte Command { get; set; } - [Data(Count = 11)] public byte[] Reserved { get; set; } - - public static List> Read(Stream stream) - { - var basePosition = stream.Position; - var version = stream.ReadInt32(); - var worldCount = stream.ReadInt32(); - - List<(ushort areaCount, ushort offset)> worldsInfo = - Enumerable.Range(0, worldCount) - .Select(x => (stream.ReadUInt16(), stream.ReadUInt16())) - .ToList(); - - return Enumerable.Range(0, worldCount) - .Select(index => - { - var worldInfo = worldsInfo[index]; - stream.Position = basePosition + worldInfo.offset; - return Enumerable.Range(0, worldInfo.areaCount) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList(); - }) - .ToList(); - } - - public static void Write(Stream stream, ICollection> areainfos) - { - const int SupportedVersion = 1; - - stream.Write(SupportedVersion); - stream.Write(areainfos.Count); - - var offset = 8 + areainfos.Count * 4; - foreach (var worldInfo in areainfos) - { - stream.Write((ushort)worldInfo.Count); - stream.Write((ushort)offset); - offset += worldInfo.Count * 0x40; - } - - foreach (var worldInfo in areainfos) - foreach (var areaInfo in worldInfo) - BinaryMapping.WriteObject(stream, areaInfo); - } - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SystemData +{ + public class BgmSet + { + [Data] public ushort BgmField { get; set; } + [Data] public ushort BgmBattle { get; set; } + } + + /// + /// AreaInfo + /// + public class Arif + { + [Data] public uint Flags { get; set; } + [Data] public int Reverb { get; set; } + [Data] public int SoundEffectBank1 { get; set; } + [Data] public int SoundEffectBank2 { get; set; } + [Data(Count = 8)] public BgmSet[] Bgms { get; set; } + [Data] public ushort Voice { get; set; } + [Data] public ushort NavigationMapItem { get; set; } + [Data] public byte Command { get; set; } + [Data(Count = 11)] public byte[] Reserved { get; set; } + + public static List> Read(Stream stream) + { + var basePosition = stream.Position; + var version = stream.ReadInt32(); + var worldCount = stream.ReadInt32(); + + List<(ushort areaCount, ushort offset)> worldsInfo = + Enumerable.Range(0, worldCount) + .Select(x => (stream.ReadUInt16(), stream.ReadUInt16())) + .ToList(); + + return Enumerable.Range(0, worldCount) + .Select(index => + { + var worldInfo = worldsInfo[index]; + stream.Position = basePosition + worldInfo.offset; + return Enumerable.Range(0, worldInfo.areaCount) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList(); + }) + .ToList(); + } + + public static void Write(Stream stream, ICollection> areainfos) + { + const int SupportedVersion = 1; + + stream.Write(SupportedVersion); + stream.Write(areainfos.Count); + + var offset = 8 + areainfos.Count * 4; + foreach (var worldInfo in areainfos) + { + stream.Write((ushort)worldInfo.Count); + stream.Write((ushort)offset); + offset += worldInfo.Count * 0x40; + } + + foreach (var worldInfo in areainfos) + foreach (var areaInfo in worldInfo) + BinaryMapping.WriteObject(stream, areaInfo); + } + } +} diff --git a/OpenKh.Kh2/SystemData/Ftst.cs b/OpenKh.Kh2/SystemData/Ftst.cs index 3c952c7fb..16e6055c4 100644 --- a/OpenKh.Kh2/SystemData/Ftst.cs +++ b/OpenKh.Kh2/SystemData/Ftst.cs @@ -1,21 +1,21 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SystemData -{ - public class Ftst - { - public class Entry - { - [Data] public int Id { get; set; } - [Data(Count = Constants.WorldCount)] public int[] Colors { get; set; } - } - - public static List Read(Stream stream) => - BaseTable.Read(stream); - - public static void Write(Stream stream, List entries) => - BaseTable.Write(stream, 1, entries); - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SystemData +{ + public class Ftst + { + public class Entry + { + [Data] public int Id { get; set; } + [Data(Count = Constants.WorldCount)] public int[] Colors { get; set; } + } + + public static List Read(Stream stream) => + BaseTable.Read(stream); + + public static void Write(Stream stream, List entries) => + BaseTable.Write(stream, 1, entries); + } +} diff --git a/OpenKh.Kh2/SystemData/Item.cs b/OpenKh.Kh2/SystemData/Item.cs index 52c5fab36..436c66fa4 100644 --- a/OpenKh.Kh2/SystemData/Item.cs +++ b/OpenKh.Kh2/SystemData/Item.cs @@ -1,104 +1,104 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SystemData -{ - public class Item - { - public enum Type : byte - { - Consumable, - Boost, - Keyblade, - Staff, - Shield, - PingWeapon, - AuronWeapon, - BeastWeapon, - JackWeapon, - DummyWeapon, - RikuWeapon, - SimbaWeapon, - JackSparrowWeapon, - TronWeapon, - Armor, - Accessory, - Synthesis, - Recipe, - Magic, - Ability, - Summon, - Form, - Map, - Report, - } - - public enum Rank : byte - { - C, - B, - A, - S - } - - public class Entry - { - [Data] public ushort Id { get; set; } - [Data] public Type Type { get; set; } - [Data] public byte Flag0 { get; set; } - [Data] public byte Flag1 { get; set; } - [Data] public Rank Rank { get; set; } - [Data] public ushort StatEntry { get; set; } - [Data] public ushort Name { get; set; } - [Data] public ushort Description { get; set; } - [Data] public ushort ShopBuy { get; set; } - [Data] public ushort ShopSell { get; set; } - [Data] public ushort Command { get; set; } - [Data] public ushort Slot { get; set; } - [Data] public short Picture { get; set; } - [Data] public byte Icon1 { get; set; } - [Data] public byte Icon2 { get; set; } - } - - public class Stat - { - [Data] public ushort Id { get; set; } - [Data] public ushort Ability { get; set; } - [Data] public byte Attack { get; set; } - [Data] public byte Magic { get; set; } - [Data] public byte Defense { get; set; } - [Data] public byte AbilityPoints { get; set; } - [Data] public byte Unknown08 { get; set; } - [Data] public byte FireResistance { get; set; } - [Data] public byte IceResistance { get; set; } - [Data] public byte LightningResistance { get; set; } - [Data] public byte DarkResistance { get; set; } - [Data] public byte Unknown0d { get; set; } - [Data] public byte GeneralResistance { get; set; } - [Data] public byte Unknown { get; set; } - } - - [Data] public List Items1 { get; set; } - [Data] public List Items2 { get; set; } - - public static Item Read(Stream stream) - { - stream.Position = 0; - var one = BaseTable.Read(stream); - var two = BaseTable.Read(stream); - - return new Item - { - Items1 = one, - Items2 = two - }; - } - - public void Write(Stream stream) - { - BaseTable.Write(stream, 6, Items1); - BaseTable.Write(stream, 0, Items2); - } - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SystemData +{ + public class Item + { + public enum Type : byte + { + Consumable, + Boost, + Keyblade, + Staff, + Shield, + PingWeapon, + AuronWeapon, + BeastWeapon, + JackWeapon, + DummyWeapon, + RikuWeapon, + SimbaWeapon, + JackSparrowWeapon, + TronWeapon, + Armor, + Accessory, + Synthesis, + Recipe, + Magic, + Ability, + Summon, + Form, + Map, + Report, + } + + public enum Rank : byte + { + C, + B, + A, + S + } + + public class Entry + { + [Data] public ushort Id { get; set; } + [Data] public Type Type { get; set; } + [Data] public byte Flag0 { get; set; } + [Data] public byte Flag1 { get; set; } + [Data] public Rank Rank { get; set; } + [Data] public ushort StatEntry { get; set; } + [Data] public ushort Name { get; set; } + [Data] public ushort Description { get; set; } + [Data] public ushort ShopBuy { get; set; } + [Data] public ushort ShopSell { get; set; } + [Data] public ushort Command { get; set; } + [Data] public ushort Slot { get; set; } + [Data] public short Picture { get; set; } + [Data] public byte Icon1 { get; set; } + [Data] public byte Icon2 { get; set; } + } + + public class Stat + { + [Data] public ushort Id { get; set; } + [Data] public ushort Ability { get; set; } + [Data] public byte Attack { get; set; } + [Data] public byte Magic { get; set; } + [Data] public byte Defense { get; set; } + [Data] public byte AbilityPoints { get; set; } + [Data] public byte Unknown08 { get; set; } + [Data] public byte FireResistance { get; set; } + [Data] public byte IceResistance { get; set; } + [Data] public byte LightningResistance { get; set; } + [Data] public byte DarkResistance { get; set; } + [Data] public byte Unknown0d { get; set; } + [Data] public byte GeneralResistance { get; set; } + [Data] public byte Unknown { get; set; } + } + + [Data] public List Items1 { get; set; } + [Data] public List Items2 { get; set; } + + public static Item Read(Stream stream) + { + stream.Position = 0; + var one = BaseTable.Read(stream); + var two = BaseTable.Read(stream); + + return new Item + { + Items1 = one, + Items2 = two + }; + } + + public void Write(Stream stream) + { + BaseTable.Write(stream, 6, Items1); + BaseTable.Write(stream, 0, Items2); + } + } +} diff --git a/OpenKh.Kh2/SystemData/Memt.cs b/OpenKh.Kh2/SystemData/Memt.cs index 257a132ef..03e175992 100644 --- a/OpenKh.Kh2/SystemData/Memt.cs +++ b/OpenKh.Kh2/SystemData/Memt.cs @@ -1,158 +1,158 @@ -using OpenKh.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SystemData -{ - public enum MemberVanilla - { - Sora, - Donald, - Goofy, - WorldCharacter, - FormValor, - FormWisdom, - FormTrinity, - FormFinal, - Antiform, - Mickey, - SoraHighPoly, - FormValorHighPoly, - FormWisdomHighPoly, - FormTrinityHighPoly, - FormFinalHighPoly, - AntiformHighPoly, - } - - public enum MemberFinalMix - { - Sora, - Donald, - Goofy, - WorldCharacter, - FormValor, - FormWisdom, - FormLimit, - FormTrinity, - FormFinal, - Antiform, - Mickey, - SoraHighPoly, - FormValorHighPoly, - FormWisdomHighPoly, - FormLimitHighPoly, - FormTrinityHighPoly, - FormFinalHighPoly, - AntiformHighPoly, - } - - public class Memt - { - private const int Version = 5; - public const int MemberCountVanilla = 16; - public const int MemberCountFinalMix = 18; - - public interface IEntry - { - short CheckStoryFlag { get; set; } - short CheckStoryFlagNegation { get; set; } - short[] Members { get; set; } - short Unk06 { get; set; } - short Unk08 { get; set; } - short Unk0A { get; set; } - short Unk0C { get; set; } - short Unk0E { get; set; } - short WorldId { get; set; } - } - - public class EntryVanilla : IEntry - { - [Data] public short WorldId { get; set; } - [Data] public short CheckStoryFlag { get; set; } - [Data] public short CheckStoryFlagNegation { get; set; } - [Data] public short Unk06 { get; set; } - [Data] public short Unk08 { get; set; } - [Data] public short Unk0A { get; set; } - [Data] public short Unk0C { get; set; } - [Data] public short Unk0E { get; set; } - [Data(Count = MemberCountVanilla)] public short[] Members { get; set; } - } - - public class EntryFinalMix : IEntry - { - [Data] public short WorldId { get; set; } - [Data] public short CheckStoryFlag { get; set; } - [Data] public short CheckStoryFlagNegation { get; set; } - [Data] public short Unk06 { get; set; } - [Data] public short Unk08 { get; set; } - [Data] public short Unk0A { get; set; } - [Data] public short Unk0C { get; set; } - [Data] public short Unk0E { get; set; } - [Data(Count = MemberCountFinalMix)] public short[] Members { get; set; } - } - - public class MemberIndices - { - [Data] public byte Player { get; set; } - [Data] public byte Friend1 { get; set; } - [Data] public byte Friend2 { get; set; } - [Data] public byte FriendWorld { get; set; } - } - - public List Entries { get; } - public MemberIndices[] MemberIndexCollection { get; } - - public Memt() - { - Entries = new List().Cast().ToList(); - MemberIndexCollection = new MemberIndices[1] - { - new MemberIndices - { - Player = 0, - Friend1 = 1, - Friend2 = 2, - FriendWorld = 3 - } - }; - } - - internal Memt(Stream stream) - { - const int HeaderSize = 8; - const int StructLengthVanilla = 48; - const int MemberIndicesExpected = 7; - - var previousPosition = stream.Position; - var version = stream.ReadInt32(); - var count = stream.ReadInt32(); - stream.Position = previousPosition; - - if (stream.Length - previousPosition == HeaderSize + - count * StructLengthVanilla + MemberIndicesExpected * 4) - Entries = BaseTable.Read(stream).Cast().ToList(); - else - Entries = BaseTable.Read(stream).Cast().ToList(); - - MemberIndexCollection = Enumerable.Range(0, MemberIndicesExpected) - .Select(x => BinaryMapping.ReadObject(stream)) - .ToArray(); - } - - public static Memt Read(Stream stream) => new Memt(stream); - - public static void Write(Stream stream, Memt memt) - { - var firstElement = memt.Entries.FirstOrDefault(); - if (firstElement is EntryVanilla) - BaseTable.Write(stream, Version, memt.Entries.Cast()); - else if (firstElement is EntryFinalMix) - BaseTable.Write(stream, Version, memt.Entries.Cast()); - - foreach (var item in memt.MemberIndexCollection) - BinaryMapping.WriteObject(stream, item); - } - } -} +using OpenKh.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SystemData +{ + public enum MemberVanilla + { + Sora, + Donald, + Goofy, + WorldCharacter, + FormValor, + FormWisdom, + FormTrinity, + FormFinal, + Antiform, + Mickey, + SoraHighPoly, + FormValorHighPoly, + FormWisdomHighPoly, + FormTrinityHighPoly, + FormFinalHighPoly, + AntiformHighPoly, + } + + public enum MemberFinalMix + { + Sora, + Donald, + Goofy, + WorldCharacter, + FormValor, + FormWisdom, + FormLimit, + FormTrinity, + FormFinal, + Antiform, + Mickey, + SoraHighPoly, + FormValorHighPoly, + FormWisdomHighPoly, + FormLimitHighPoly, + FormTrinityHighPoly, + FormFinalHighPoly, + AntiformHighPoly, + } + + public class Memt + { + private const int Version = 5; + public const int MemberCountVanilla = 16; + public const int MemberCountFinalMix = 18; + + public interface IEntry + { + short CheckStoryFlag { get; set; } + short CheckStoryFlagNegation { get; set; } + short[] Members { get; set; } + short Unk06 { get; set; } + short Unk08 { get; set; } + short Unk0A { get; set; } + short Unk0C { get; set; } + short Unk0E { get; set; } + short WorldId { get; set; } + } + + public class EntryVanilla : IEntry + { + [Data] public short WorldId { get; set; } + [Data] public short CheckStoryFlag { get; set; } + [Data] public short CheckStoryFlagNegation { get; set; } + [Data] public short Unk06 { get; set; } + [Data] public short Unk08 { get; set; } + [Data] public short Unk0A { get; set; } + [Data] public short Unk0C { get; set; } + [Data] public short Unk0E { get; set; } + [Data(Count = MemberCountVanilla)] public short[] Members { get; set; } + } + + public class EntryFinalMix : IEntry + { + [Data] public short WorldId { get; set; } + [Data] public short CheckStoryFlag { get; set; } + [Data] public short CheckStoryFlagNegation { get; set; } + [Data] public short Unk06 { get; set; } + [Data] public short Unk08 { get; set; } + [Data] public short Unk0A { get; set; } + [Data] public short Unk0C { get; set; } + [Data] public short Unk0E { get; set; } + [Data(Count = MemberCountFinalMix)] public short[] Members { get; set; } + } + + public class MemberIndices + { + [Data] public byte Player { get; set; } + [Data] public byte Friend1 { get; set; } + [Data] public byte Friend2 { get; set; } + [Data] public byte FriendWorld { get; set; } + } + + public List Entries { get; } + public MemberIndices[] MemberIndexCollection { get; } + + public Memt() + { + Entries = new List().Cast().ToList(); + MemberIndexCollection = new MemberIndices[1] + { + new MemberIndices + { + Player = 0, + Friend1 = 1, + Friend2 = 2, + FriendWorld = 3 + } + }; + } + + internal Memt(Stream stream) + { + const int HeaderSize = 8; + const int StructLengthVanilla = 48; + const int MemberIndicesExpected = 7; + + var previousPosition = stream.Position; + var version = stream.ReadInt32(); + var count = stream.ReadInt32(); + stream.Position = previousPosition; + + if (stream.Length - previousPosition == HeaderSize + + count * StructLengthVanilla + MemberIndicesExpected * 4) + Entries = BaseTable.Read(stream).Cast().ToList(); + else + Entries = BaseTable.Read(stream).Cast().ToList(); + + MemberIndexCollection = Enumerable.Range(0, MemberIndicesExpected) + .Select(x => BinaryMapping.ReadObject(stream)) + .ToArray(); + } + + public static Memt Read(Stream stream) => new Memt(stream); + + public static void Write(Stream stream, Memt memt) + { + var firstElement = memt.Entries.FirstOrDefault(); + if (firstElement is EntryVanilla) + BaseTable.Write(stream, Version, memt.Entries.Cast()); + else if (firstElement is EntryFinalMix) + BaseTable.Write(stream, Version, memt.Entries.Cast()); + + foreach (var item in memt.MemberIndexCollection) + BinaryMapping.WriteObject(stream, item); + } + } +} diff --git a/OpenKh.Kh2/SystemData/Trsr.cs b/OpenKh.Kh2/SystemData/Trsr.cs index 0819026b5..ccffde33e 100644 --- a/OpenKh.Kh2/SystemData/Trsr.cs +++ b/OpenKh.Kh2/SystemData/Trsr.cs @@ -1,29 +1,29 @@ -using System.Collections.Generic; -using System.IO; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2.SystemData -{ - public class Trsr - { - public enum TrsrType : byte - { - Chest, - Event - } - - [Data] public ushort Id { get; set; } - [Data] public ushort ItemId { get; set; } - [Data] public TrsrType Type { get; set; } - [Data] public byte World { get; set; } - [Data] public byte Room { get; set; } - [Data] public byte RoomChestIndex { get; set; } - [Data] public short EventId { get; set; } - [Data] public short OverallChestIndex { get; set; } - - public static List Read(Stream stream) => BaseShortTable.Read(stream); - - public static void Write(Stream stream, IEnumerable items) => - BaseShortTable.Write(stream, 3, items); - } -} +using System.Collections.Generic; +using System.IO; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2.SystemData +{ + public class Trsr + { + public enum TrsrType : byte + { + Chest, + Event + } + + [Data] public ushort Id { get; set; } + [Data] public ushort ItemId { get; set; } + [Data] public TrsrType Type { get; set; } + [Data] public byte World { get; set; } + [Data] public byte Room { get; set; } + [Data] public byte RoomChestIndex { get; set; } + [Data] public short EventId { get; set; } + [Data] public short OverallChestIndex { get; set; } + + public static List Read(Stream stream) => BaseShortTable.Read(stream); + + public static void Write(Stream stream, IEnumerable items) => + BaseShortTable.Write(stream, 3, items); + } +} diff --git a/OpenKh.Kh2/TextureFooter/TextureAnimation.cs b/OpenKh.Kh2/TextureFooter/TextureAnimation.cs index 137dc998e..8bd509069 100644 --- a/OpenKh.Kh2/TextureFooter/TextureAnimation.cs +++ b/OpenKh.Kh2/TextureFooter/TextureAnimation.cs @@ -12,23 +12,23 @@ public class TextureAnimation [Data] public ushort FrameStride { get; set; } [Data] public ushort BitsPerPixel { get; set; } [Data] public ushort BaseSlotIndex { get; set; } - [Data] public ushort MaximumSlotIndex { get; set; } + [Data] public ushort MaximumSlotIndex { get; set; } - /// This field may be updated by serialization. + /// This field may be updated by serialization. [Data] public ushort NumAnimations { get; set; } [Data] public ushort NumSpritesInImageData { get; set; } [Data] public ushort UOffsetInBaseImage { get; set; } [Data] public ushort VOffsetInBaseImage { get; set; } [Data] public ushort SpriteWidth { get; set; } [Data] public ushort SpriteHeight { get; set; } - - /// This field may be updated by serialization. + + /// This field may be updated by serialization. [Data] public int OffsetSlotTable { get; set; } - - /// This field may be updated by serialization. + + /// This field may be updated by serialization. [Data] public int OffsetAnimationTable { get; set; } - - /// This field may be updated by serialization. + + /// This field may be updated by serialization. [Data] public int OffsetSpriteImage { get; set; } [Data] public int DefaultAnimationIndex { get; set; } diff --git a/OpenKh.Kh2/TextureFooter/TextureFooterData.cs b/OpenKh.Kh2/TextureFooter/TextureFooterData.cs index 06896d42f..36caa1412 100644 --- a/OpenKh.Kh2/TextureFooter/TextureFooterData.cs +++ b/OpenKh.Kh2/TextureFooter/TextureFooterData.cs @@ -11,34 +11,34 @@ namespace OpenKh.Kh2.TextureFooter public class TextureFooterData { public List UvscList { get; } = new List(); - public List TextureAnimationList { get; } = new List(); - public byte[] UnkFooter { get; set; } + public List TextureAnimationList { get; } = new List(); + public byte[] UnkFooter { get; set; } public bool ShouldEmitDMYAtFirst { get; set; } public bool ShouldEmitKN5 { get; set; } public override string ToString() => $"{UvscList.Count} UVSC, {TextureAnimationList.Count} TEXA"; - - public TextureFooterData() - { - - } + + public TextureFooterData() + { + + } public TextureFooterData(Stream stream) - { - var shouldEmitDMYAtFirst = false; - var index = -1; + { + var shouldEmitDMYAtFirst = false; + var index = -1; while (stream.Position < stream.Length) - { - ++index; + { + ++index; var tag = Encoding.ASCII.GetString(stream.ReadBytes(4)); if (tag == "_KN5") - { - ShouldEmitDMYAtFirst = (index == 1) && shouldEmitDMYAtFirst; - ShouldEmitKN5 = true; - - UnkFooter = stream.ReadBytes(); + { + ShouldEmitDMYAtFirst = (index == 1) && shouldEmitDMYAtFirst; + ShouldEmitKN5 = true; + + UnkFooter = stream.ReadBytes(); break; } @@ -104,131 +104,131 @@ public TextureFooterData(Stream stream) .ReadBytes(header.SpriteStride * header.SpriteHeight * header.NumSpritesInImageData); TextureAnimationList.Add(header); - } - else if (tag == "_DMY") - { - shouldEmitDMYAtFirst |= (index == 0) ? true : false; + } + else if (tag == "_DMY") + { + shouldEmitDMYAtFirst |= (index == 0) ? true : false; } stream.Position = nextTag; } - } - + } + public static TextureFooterData Read(Stream stream) => new TextureFooterData(stream); - - /// - /// Terminator mark - /// - private static byte[] _KN5 = Encoding.ASCII.GetBytes("_KN5"); - - /// - /// Dummy - /// - private static byte[] _DMY = Encoding.ASCII.GetBytes("_DMY"); - - private static byte[] UVSC = Encoding.ASCII.GetBytes("UVSC"); - - private static byte[] TEXA = Encoding.ASCII.GetBytes("TEXA"); - - public void Write(Stream stream) - { - if (ShouldEmitDMYAtFirst) - { - // Some map files has style "_DMY" "_KN5". This is for that consistency. - stream.Write(_DMY); - stream.Write(0); - } - - foreach (var item in TextureAnimationList) - { - var texaStream = new MemoryStream(); - - { - item.NumAnimations = Convert.ToUInt16(item.FrameGroupList.Length); - var animationTable = new int[item.NumAnimations]; - - for (var pass = 1; pass <= 2; pass++) - { - texaStream.Position = 0; - BinaryMapping.WriteObject(texaStream, item); - - item.OffsetSlotTable = Convert.ToInt32(texaStream.Position); - item.SlotTable.ToList().ForEach(texaStream.Write); - - texaStream.AlignPosition(4); - - item.OffsetAnimationTable = Convert.ToInt32(texaStream.Position); - texaStream.Write(animationTable); - - foreach (var (group, groupIndex) in item.FrameGroupList.Select((group, groupIndex) => (group, groupIndex))) - { - animationTable[groupIndex] = Convert.ToInt32(texaStream.Position); - - if (group.IndexedFrameList.Any()) - { - int minIdx = group.IndexedFrameList.Keys.Min(); - int maxIdx = group.IndexedFrameList.Keys.Max(); - - for (; minIdx <= maxIdx; minIdx++) - { - group.IndexedFrameList.TryGetValue(minIdx, out TextureFrame frame); - frame = frame ?? new TextureFrame(); - - BinaryMapping.WriteObject(texaStream, frame); - } - } - } - - texaStream.AlignPosition(16); - item.OffsetSpriteImage = Convert.ToInt32(texaStream.Position); - - texaStream.Write(item.SpriteImage); - texaStream.AlignPosition(16); - } - } - - stream.Write(_DMY); - stream.Write(0); - - stream.Write(TEXA); - stream.Write(Convert.ToUInt32(texaStream.Length)); - - texaStream.Position = 0; - texaStream.CopyTo(stream); - } - - if (UvscList.Any()) - { - // Before first "UVSC", "_DMY" has to be placed. This is for that consistency. - - stream.Write(_DMY); - stream.Write(0); - - foreach (var item in UvscList) - { - stream.Write(UVSC); - stream.Write(12); - BinaryMapping.WriteObject(stream, item); - } - } - else if (TextureAnimationList.Any()) - { - // Between "TEXA" and "_KN5", "_DMY" has to be placed. This is for that consistency. - - stream.Write(_DMY); - stream.Write(0); - } - - if (ShouldEmitKN5) - { - stream.Write(_KN5); - } - - if (UnkFooter != null) - { - stream.Write(UnkFooter); - } + + /// + /// Terminator mark + /// + private static byte[] _KN5 = Encoding.ASCII.GetBytes("_KN5"); + + /// + /// Dummy + /// + private static byte[] _DMY = Encoding.ASCII.GetBytes("_DMY"); + + private static byte[] UVSC = Encoding.ASCII.GetBytes("UVSC"); + + private static byte[] TEXA = Encoding.ASCII.GetBytes("TEXA"); + + public void Write(Stream stream) + { + if (ShouldEmitDMYAtFirst) + { + // Some map files has style "_DMY" "_KN5". This is for that consistency. + stream.Write(_DMY); + stream.Write(0); + } + + foreach (var item in TextureAnimationList) + { + var texaStream = new MemoryStream(); + + { + item.NumAnimations = Convert.ToUInt16(item.FrameGroupList.Length); + var animationTable = new int[item.NumAnimations]; + + for (var pass = 1; pass <= 2; pass++) + { + texaStream.Position = 0; + BinaryMapping.WriteObject(texaStream, item); + + item.OffsetSlotTable = Convert.ToInt32(texaStream.Position); + item.SlotTable.ToList().ForEach(texaStream.Write); + + texaStream.AlignPosition(4); + + item.OffsetAnimationTable = Convert.ToInt32(texaStream.Position); + texaStream.Write(animationTable); + + foreach (var (group, groupIndex) in item.FrameGroupList.Select((group, groupIndex) => (group, groupIndex))) + { + animationTable[groupIndex] = Convert.ToInt32(texaStream.Position); + + if (group.IndexedFrameList.Any()) + { + int minIdx = group.IndexedFrameList.Keys.Min(); + int maxIdx = group.IndexedFrameList.Keys.Max(); + + for (; minIdx <= maxIdx; minIdx++) + { + group.IndexedFrameList.TryGetValue(minIdx, out TextureFrame frame); + frame = frame ?? new TextureFrame(); + + BinaryMapping.WriteObject(texaStream, frame); + } + } + } + + texaStream.AlignPosition(16); + item.OffsetSpriteImage = Convert.ToInt32(texaStream.Position); + + texaStream.Write(item.SpriteImage); + texaStream.AlignPosition(16); + } + } + + stream.Write(_DMY); + stream.Write(0); + + stream.Write(TEXA); + stream.Write(Convert.ToUInt32(texaStream.Length)); + + texaStream.Position = 0; + texaStream.CopyTo(stream); + } + + if (UvscList.Any()) + { + // Before first "UVSC", "_DMY" has to be placed. This is for that consistency. + + stream.Write(_DMY); + stream.Write(0); + + foreach (var item in UvscList) + { + stream.Write(UVSC); + stream.Write(12); + BinaryMapping.WriteObject(stream, item); + } + } + else if (TextureAnimationList.Any()) + { + // Between "TEXA" and "_KN5", "_DMY" has to be placed. This is for that consistency. + + stream.Write(_DMY); + stream.Write(0); + } + + if (ShouldEmitKN5) + { + stream.Write(_KN5); + } + + if (UnkFooter != null) + { + stream.Write(UnkFooter); + } } } } diff --git a/OpenKh.Kh2/TextureFooter/TextureFrame.cs b/OpenKh.Kh2/TextureFooter/TextureFrame.cs index a93313d29..98b3ed513 100644 --- a/OpenKh.Kh2/TextureFooter/TextureFrame.cs +++ b/OpenKh.Kh2/TextureFooter/TextureFrame.cs @@ -13,10 +13,10 @@ public class TextureFrame [Data] public ushort MaximumLength { get; set; } [Data] public ushort SpriteImageIndex { get; set; } - public TextureFrameControl FrameControl - { - get => (TextureFrameControl)(Data & 15); - set => Data = (ushort)BitsUtil.Int.SetBits(Data, 0, 4, (int)value); + public TextureFrameControl FrameControl + { + get => (TextureFrameControl)(Data & 15); + set => Data = (ushort)BitsUtil.Int.SetBits(Data, 0, 4, (int)value); } public override string ToString() => $"{FrameControl}({FrameIndexDelta}), {MinimumLength}~{MaximumLength}, Sprite:{SpriteImageIndex}"; @@ -24,10 +24,10 @@ public TextureFrameControl FrameControl /// /// Available if JumpFrame is set. NextFrameIndex is CurrentFrameIndex + FrameIndexDelta. /// - public int FrameIndexDelta - { - get => BitsUtil.Int.SignExtend(Data, 4, 11); - set => Data = (ushort)BitsUtil.Int.SetBits(Data, 4, 12, value); + public int FrameIndexDelta + { + get => BitsUtil.Int.SignExtend(Data, 4, 11); + set => Data = (ushort)BitsUtil.Int.SetBits(Data, 4, 12, value); } public const int SizeInBytes = 8; diff --git a/OpenKh.Kh2/TextureFooter/TextureFrameControl.cs b/OpenKh.Kh2/TextureFooter/TextureFrameControl.cs index 16e4a6abb..d52ce0176 100644 --- a/OpenKh.Kh2/TextureFooter/TextureFrameControl.cs +++ b/OpenKh.Kh2/TextureFooter/TextureFrameControl.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; diff --git a/OpenKh.Kh2/TextureFooter/TextureFrameGroup.cs b/OpenKh.Kh2/TextureFooter/TextureFrameGroup.cs index 07f6be866..278910575 100644 --- a/OpenKh.Kh2/TextureFooter/TextureFrameGroup.cs +++ b/OpenKh.Kh2/TextureFooter/TextureFrameGroup.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; diff --git a/OpenKh.Kh2/TextureFooter/UvScroll.cs b/OpenKh.Kh2/TextureFooter/UvScroll.cs index b59b93c33..27cbec618 100644 --- a/OpenKh.Kh2/TextureFooter/UvScroll.cs +++ b/OpenKh.Kh2/TextureFooter/UvScroll.cs @@ -9,8 +9,8 @@ public class UvScroll { [Data] public int TextureIndex { get; set; } [Data] public float UScrollSpeed { get; set; } - [Data] public float VScrollSpeed { get; set; } - - public override string ToString() => $"Idx={TextureIndex}, USpd={UScrollSpeed}, VSpd={VScrollSpeed}"; + [Data] public float VScrollSpeed { get; set; } + + public override string ToString() => $"Idx={TextureIndex}, USpd={UScrollSpeed}, VSpd={VScrollSpeed}"; } } diff --git a/OpenKh.Kh2/Utils/BoundingBox.cs b/OpenKh.Kh2/Utils/BoundingBox.cs index 7faab82ce..4c9df7bec 100644 --- a/OpenKh.Kh2/Utils/BoundingBox.cs +++ b/OpenKh.Kh2/Utils/BoundingBox.cs @@ -1,4 +1,4 @@ -using OpenKh.Kh2.Extensions; +using OpenKh.Kh2.Extensions; using OpenKh.Kh2.Jiminy; using System; using System.Collections.Generic; diff --git a/OpenKh.Kh2/Utils/BoundingBoxInt16.cs b/OpenKh.Kh2/Utils/BoundingBoxInt16.cs index d0ccb0637..329d9251b 100644 --- a/OpenKh.Kh2/Utils/BoundingBoxInt16.cs +++ b/OpenKh.Kh2/Utils/BoundingBoxInt16.cs @@ -1,4 +1,4 @@ -using System.Numerics; +using System.Numerics; using Xe.BinaryMapper; namespace OpenKh.Kh2.Utils diff --git a/OpenKh.Kh2/Utils/Vector3Int16.cs b/OpenKh.Kh2/Utils/Vector3Int16.cs index 969ad84d6..99c5781da 100644 --- a/OpenKh.Kh2/Utils/Vector3Int16.cs +++ b/OpenKh.Kh2/Utils/Vector3Int16.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; using Xe.BinaryMapper; diff --git a/OpenKh.Kh2/WorldPoint.cs b/OpenKh.Kh2/WorldPoint.cs index d39bb4df9..417b3ab7a 100644 --- a/OpenKh.Kh2/WorldPoint.cs +++ b/OpenKh.Kh2/WorldPoint.cs @@ -1,29 +1,29 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Kh2 -{ - public class WorldPoint - { - [Data] public byte World { get; set; } - [Data] public byte Area { get; set; } - [Data] public byte Entrance { get; set; } - [Data] public byte Padding { get; set; } - - public static List Read(Stream stream) - { - var estimatedItemCount = (int)(stream.Length - stream.Position) / 4; - return Enumerable.Range(0, estimatedItemCount) - .Select(_ => BinaryMapping.ReadObject(stream)) - .ToList(); - } - - public static void Write(Stream stream, IEnumerable worldPoints) - { - foreach (var item in worldPoints) - BinaryMapping.WriteObject(stream, item); - } - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Kh2 +{ + public class WorldPoint + { + [Data] public byte World { get; set; } + [Data] public byte Area { get; set; } + [Data] public byte Entrance { get; set; } + [Data] public byte Padding { get; set; } + + public static List Read(Stream stream) + { + var estimatedItemCount = (int)(stream.Length - stream.Position) / 4; + return Enumerable.Range(0, estimatedItemCount) + .Select(_ => BinaryMapping.ReadObject(stream)) + .ToList(); + } + + public static void Write(Stream stream, IEnumerable worldPoints) + { + foreach (var item in worldPoints) + BinaryMapping.WriteObject(stream, item); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Legacy/AxBone.cs b/OpenKh.Kh2AnimEmu/Legacy/AxBone.cs index 8946dba35..76f35b694 100644 --- a/OpenKh.Kh2AnimEmu/Legacy/AxBone.cs +++ b/OpenKh.Kh2AnimEmu/Legacy/AxBone.cs @@ -1,19 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Kh2Anim.Legacy -{ - public class AxBone - { - public int cur, parent, v08, v0c; - public float x1, y1, z1, w1; // S - public float x2, y2, z2, w2; // R - public float x3, y3, z3, w3; // T - - public AxBone Clone() - { - return (AxBone)MemberwiseClone(); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Kh2Anim.Legacy +{ + public class AxBone + { + public int cur, parent, v08, v0c; + public float x1, y1, z1, w1; // S + public float x2, y2, z2, w2; // R + public float x3, y3, z3, w3; // T + + public AxBone Clone() + { + return (AxBone)MemberwiseClone(); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/AnbIndir.cs b/OpenKh.Kh2AnimEmu/Mset/AnbIndir.cs index af54bee19..bc4f79546 100644 --- a/OpenKh.Kh2AnimEmu/Mset/AnbIndir.cs +++ b/OpenKh.Kh2AnimEmu/Mset/AnbIndir.cs @@ -1,38 +1,38 @@ -using OpenKh.Kh2Anim.Mset.EmuRunner; -using OpenKh.Kh2Anim.Mset.Interfaces; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - /// - /// anb indirection - /// - public class AnbIndir - { - private readonly IEnumerable entries; - - public AnbIndir(IEnumerable entries) - { - this.entries = entries; - } - - public bool HasAnimationData => entries - .Any(it => it.Type == Bar.EntryType.Motion); - - public IAnimMatricesProvider GetAnimProvider(Stream mdlxStream) - { - var animEntry = entries - .First(it => it.Type == Bar.EntryType.Motion); // anb bar should have single 0x09 (AnimationData) - var animStream = animEntry.Stream; - - var animReader = new AnimReader(animStream); - - return new EmuBasedAnimMatricesProvider(animReader, mdlxStream, animStream); - } - } -} +using OpenKh.Kh2Anim.Mset.EmuRunner; +using OpenKh.Kh2Anim.Mset.Interfaces; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + /// + /// anb indirection + /// + public class AnbIndir + { + private readonly IEnumerable entries; + + public AnbIndir(IEnumerable entries) + { + this.entries = entries; + } + + public bool HasAnimationData => entries + .Any(it => it.Type == Bar.EntryType.Motion); + + public IAnimMatricesProvider GetAnimProvider(Stream mdlxStream) + { + var animEntry = entries + .First(it => it.Type == Bar.EntryType.Motion); // anb bar should have single 0x09 (AnimationData) + var animStream = animEntry.Stream; + + var animReader = new AnimReader(animStream); + + return new EmuBasedAnimMatricesProvider(animReader, mdlxStream, animStream); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/AnimModel.cs b/OpenKh.Kh2AnimEmu/Mset/AnimModel.cs index a6099742f..4e04ba996 100644 --- a/OpenKh.Kh2AnimEmu/Mset/AnimModel.cs +++ b/OpenKh.Kh2AnimEmu/Mset/AnimModel.cs @@ -1,23 +1,23 @@ -using OpenKh.Kh2Anim.Legacy; -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - public class AnimModel - { - public List t1List = new List(); - public List t2List = new List(); - public List t2xList = new List(); - public List t3List = new List(); - public List t4List = new List(); - public List t5List = new List(); - public List t9List = new List(); - public float[] t10List = null; - public float[] t11List = null; - public float[] t12List = null; - - public int off5 = 0, cnt5 = 0; - } -} +using OpenKh.Kh2Anim.Legacy; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + public class AnimModel + { + public List t1List = new List(); + public List t2List = new List(); + public List t2xList = new List(); + public List t3List = new List(); + public List t4List = new List(); + public List t5List = new List(); + public List t9List = new List(); + public float[] t10List = null; + public float[] t11List = null; + public float[] t12List = null; + + public int off5 = 0, cnt5 = 0; + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/AnimReader.cs b/OpenKh.Kh2AnimEmu/Mset/AnimReader.cs index d81ab1a1c..f5ffcdc4e 100644 --- a/OpenKh.Kh2AnimEmu/Mset/AnimReader.cs +++ b/OpenKh.Kh2AnimEmu/Mset/AnimReader.cs @@ -1,257 +1,257 @@ -using OpenKh.Kh2Anim.Legacy; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - public class AnimReader - { - public AnimModel model = new AnimModel(); - public int cntb1, cntb2; - - public AnimReader(Stream si) - { - var posTbl = new PosTbl(si); - int baseoff = 0; - int tbloff = posTbl.tbloff; - - cntb1 = posTbl.va0; - cntb2 = posTbl.va2; - - var br = new BinaryReader(si); - - // min - br.ReadSingle(); - br.ReadSingle(); - br.ReadSingle(); - br.ReadSingle(); - // max - br.ReadSingle(); - br.ReadSingle(); - br.ReadSingle(); - br.ReadSingle(); - - FrameLoop = br.ReadSingle(); - FrameEnd = br.ReadSingle(); - FramePerSecond = br.ReadSingle(); - FrameCount = br.ReadSingle(); - - int cnt9 = 0, cnt10 = 0, cnt12 = 0; - if (true) - { // cnt9 - si.Position = baseoff + tbloff + posTbl.vc0 - baseoff; // t2 - for (int i2 = 0; i2 < posTbl.vc4; i2++) - { - br.ReadByte(); - br.ReadByte(); - br.ReadByte(); - int tcx = br.ReadByte(); - int tx = br.ReadUInt16(); - cnt9 = Math.Max(cnt9, tx + tcx); - } - si.Position = baseoff + tbloff + posTbl.vc8 - baseoff; // t2x - for (int i2 = 0; i2 < posTbl.vcc; i2++) - { - br.ReadByte(); - br.ReadByte(); - br.ReadByte(); - int tcx = br.ReadByte(); - int tx = br.ReadUInt16(); - cnt9 = Math.Max(cnt9, tx + tcx); - } - - if (true) - { // cnt10, cnt12 - si.Position = baseoff + tbloff + posTbl.vd0 - baseoff; // t9 - for (int i9 = 0; i9 < cnt9; i9++) - { - br.ReadUInt16(); - int ti10 = br.ReadUInt16(); - cnt10 = Math.Max(cnt10, ti10 + 1); - int ti12a = br.ReadUInt16(); - cnt12 = Math.Max(cnt12, ti12a + 1); - int ti12b = br.ReadUInt16(); - cnt12 = Math.Max(cnt12, ti12b + 1); - } - } - } - int cntt8 = 0; - if (true) - { - si.Position = baseoff + tbloff + posTbl.ve0 - baseoff; // t3 - for (int i3 = 0; i3 < posTbl.ve4; i3++) - { - br.ReadUInt16(); - br.ReadUInt16(); - br.ReadUInt16(); - int ti8 = br.ReadInt16(); - cntt8 = Math.Max(cntt8, ti8 + 1); - br.ReadUInt16(); - br.ReadUInt16(); - } - } - - int off1 = tbloff + posTbl.vb4; - int cnt1 = posTbl.vb8; - si.Position = off1; - for (int a1 = 0; a1 < cnt1; a1++) - { - int c00 = br.ReadUInt16(); - int c02 = br.ReadUInt16(); - float c04 = br.ReadSingle(); - model.t1List.Add(new T1(c00, c02, c04)); - } - - int off10 = tbloff + posTbl.vd8; - si.Position = off10; - model.t10List = new float[cnt10]; - for (int a = 0; a < cnt10; a++) - { - model.t10List[a] = br.ReadSingle(); - } - - int off11 = tbloff + posTbl.vd4; - int cnt11 = posTbl.vb0; - si.Position = off11; - model.t11List = new float[cnt11]; - for (int a = 0; a < cnt11; a++) - { - model.t11List[a] = br.ReadSingle(); - } - - int off12 = tbloff + posTbl.vdc; - si.Position = off12; - model.t12List = new float[cnt12]; - for (int a = 0; a < cnt12; a++) - { - model.t12List[a] = br.ReadSingle(); - } - - int off9 = tbloff + posTbl.vd0; - si.Position = off9; - for (int a = 0; a < cnt9; a++) - { - int c00 = br.ReadUInt16(); - int c02 = br.ReadUInt16(); - int c04 = br.ReadUInt16(); - int c06 = br.ReadUInt16(); - model.t9List.Add(new T9(c00, c02, c04, c06)); - } - - int off2 = tbloff + posTbl.vc0; - int cnt2 = posTbl.vc4; - si.Position = off2; - for (int a = 0; a < cnt2; a++) - { - int c00 = br.ReadByte(); - int c01 = br.ReadByte(); - int c02 = br.ReadByte(); - int c03 = br.ReadByte(); - int c04 = br.ReadUInt16(); // t9_xxxx - T2 o2 = new T2(c00, c01, c02, c03, c04); - model.t2List.Add(o2); - } - for (int a = 0; a < cnt2; a++) - { - T2 o2 = model.t2List[a]; - for (int b = 0; b < o2.c03; b++) - { - T9 o9 = model.t9List[o2.c04 + b]; - - int t9c00 = o9.c00; // t11_xxxx - int t9c02 = o9.c02; // t10_xxxx - int t9c04 = o9.c04; // t12_xxxx - int t9c06 = o9.c06; // t12_xxxx - - o2.al9f.Add(new T9f(o2.c04 + b, model.t11List[t9c00 >> 2], model.t10List[t9c02], model.t12List[t9c04], model.t12List[t9c06])); - } - } - - int off2x = tbloff + posTbl.vc8; - int cnt2x = posTbl.vcc; - si.Position = off2x; - for (int a = 0; a < cnt2x; a++) - { - int c00 = br.ReadByte(); - int c01 = br.ReadByte(); - int c02 = br.ReadByte(); - int c03 = br.ReadByte(); - int c04 = br.ReadUInt16(); // t9_xxxx - T2 o2 = new T2(c00, c01, c02, c03, c04); - model.t2xList.Add(o2); - } - for (int a = 0; a < cnt2x; a++) - { - T2 o2 = model.t2xList[a]; - for (int b = 0; b < o2.c03; b++) - { - T9 o9 = model.t9List[o2.c04 + b]; - - int t9c00 = o9.c00; // t11_xxxx - int t9c02 = o9.c02; // t10_xxxx - int t9c04 = o9.c04; // t12_xxxx - int t9c06 = o9.c06; // t12_xxxx - - o2.al9f.Add(new T9f(o2.c04 + b, model.t11List[t9c00 >> 2], model.t10List[t9c02], model.t12List[t9c04], model.t12List[t9c06])); - } - } - - int off3 = tbloff + posTbl.ve0; - int cnt3 = posTbl.ve4; - si.Position = off3; - for (int a3 = 0; a3 < cnt3; a3++) - { - int c00 = br.ReadByte(); - int c01 = br.ReadByte(); - int c02 = br.ReadUInt16(); - int c04 = br.ReadUInt16(); - int c06 = br.ReadUInt16(); - uint c08 = br.ReadUInt32(); - model.t3List.Add(new T3(c00, c01, c02, c04, c06, c08)); - } - - int off4 = tbloff + posTbl.vac; - int cnt4 = posTbl.va2; - si.Position = off4; - for (int a4 = 0; a4 < cnt4; a4++) - { - int c00 = br.ReadUInt16(); - int c02 = br.ReadUInt16(); - model.t4List.Add(new T4(c00, c02)); - } - - model.off5 = tbloff + posTbl.va8; - model.cnt5 = (posTbl.va2 - posTbl.va0); - si.Position = model.off5; - for (int a5 = 0; a5 < model.cnt5; a5++) - { - AxBone o = new AxBone(); - o.cur = br.ReadUInt16(); - o.parent = br.ReadUInt16(); - o.v08 = br.ReadUInt16(); - o.v0c = br.ReadUInt16(); - br.ReadUInt64(); - o.x1 = br.ReadSingle(); - o.y1 = br.ReadSingle(); - o.z1 = br.ReadSingle(); - o.w1 = br.ReadSingle(); - o.x2 = br.ReadSingle(); - o.y2 = br.ReadSingle(); - o.z2 = br.ReadSingle(); - o.w2 = br.ReadSingle(); - o.x3 = br.ReadSingle(); - o.y3 = br.ReadSingle(); - o.z3 = br.ReadSingle(); - o.w3 = br.ReadSingle(); - model.t5List.Add(o); - } - } - - public float FrameLoop { get; } - public float FrameEnd { get; } - public float FramePerSecond { get; } - public float FrameCount { get; } - } -} +using OpenKh.Kh2Anim.Legacy; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + public class AnimReader + { + public AnimModel model = new AnimModel(); + public int cntb1, cntb2; + + public AnimReader(Stream si) + { + var posTbl = new PosTbl(si); + int baseoff = 0; + int tbloff = posTbl.tbloff; + + cntb1 = posTbl.va0; + cntb2 = posTbl.va2; + + var br = new BinaryReader(si); + + // min + br.ReadSingle(); + br.ReadSingle(); + br.ReadSingle(); + br.ReadSingle(); + // max + br.ReadSingle(); + br.ReadSingle(); + br.ReadSingle(); + br.ReadSingle(); + + FrameLoop = br.ReadSingle(); + FrameEnd = br.ReadSingle(); + FramePerSecond = br.ReadSingle(); + FrameCount = br.ReadSingle(); + + int cnt9 = 0, cnt10 = 0, cnt12 = 0; + if (true) + { // cnt9 + si.Position = baseoff + tbloff + posTbl.vc0 - baseoff; // t2 + for (int i2 = 0; i2 < posTbl.vc4; i2++) + { + br.ReadByte(); + br.ReadByte(); + br.ReadByte(); + int tcx = br.ReadByte(); + int tx = br.ReadUInt16(); + cnt9 = Math.Max(cnt9, tx + tcx); + } + si.Position = baseoff + tbloff + posTbl.vc8 - baseoff; // t2x + for (int i2 = 0; i2 < posTbl.vcc; i2++) + { + br.ReadByte(); + br.ReadByte(); + br.ReadByte(); + int tcx = br.ReadByte(); + int tx = br.ReadUInt16(); + cnt9 = Math.Max(cnt9, tx + tcx); + } + + if (true) + { // cnt10, cnt12 + si.Position = baseoff + tbloff + posTbl.vd0 - baseoff; // t9 + for (int i9 = 0; i9 < cnt9; i9++) + { + br.ReadUInt16(); + int ti10 = br.ReadUInt16(); + cnt10 = Math.Max(cnt10, ti10 + 1); + int ti12a = br.ReadUInt16(); + cnt12 = Math.Max(cnt12, ti12a + 1); + int ti12b = br.ReadUInt16(); + cnt12 = Math.Max(cnt12, ti12b + 1); + } + } + } + int cntt8 = 0; + if (true) + { + si.Position = baseoff + tbloff + posTbl.ve0 - baseoff; // t3 + for (int i3 = 0; i3 < posTbl.ve4; i3++) + { + br.ReadUInt16(); + br.ReadUInt16(); + br.ReadUInt16(); + int ti8 = br.ReadInt16(); + cntt8 = Math.Max(cntt8, ti8 + 1); + br.ReadUInt16(); + br.ReadUInt16(); + } + } + + int off1 = tbloff + posTbl.vb4; + int cnt1 = posTbl.vb8; + si.Position = off1; + for (int a1 = 0; a1 < cnt1; a1++) + { + int c00 = br.ReadUInt16(); + int c02 = br.ReadUInt16(); + float c04 = br.ReadSingle(); + model.t1List.Add(new T1(c00, c02, c04)); + } + + int off10 = tbloff + posTbl.vd8; + si.Position = off10; + model.t10List = new float[cnt10]; + for (int a = 0; a < cnt10; a++) + { + model.t10List[a] = br.ReadSingle(); + } + + int off11 = tbloff + posTbl.vd4; + int cnt11 = posTbl.vb0; + si.Position = off11; + model.t11List = new float[cnt11]; + for (int a = 0; a < cnt11; a++) + { + model.t11List[a] = br.ReadSingle(); + } + + int off12 = tbloff + posTbl.vdc; + si.Position = off12; + model.t12List = new float[cnt12]; + for (int a = 0; a < cnt12; a++) + { + model.t12List[a] = br.ReadSingle(); + } + + int off9 = tbloff + posTbl.vd0; + si.Position = off9; + for (int a = 0; a < cnt9; a++) + { + int c00 = br.ReadUInt16(); + int c02 = br.ReadUInt16(); + int c04 = br.ReadUInt16(); + int c06 = br.ReadUInt16(); + model.t9List.Add(new T9(c00, c02, c04, c06)); + } + + int off2 = tbloff + posTbl.vc0; + int cnt2 = posTbl.vc4; + si.Position = off2; + for (int a = 0; a < cnt2; a++) + { + int c00 = br.ReadByte(); + int c01 = br.ReadByte(); + int c02 = br.ReadByte(); + int c03 = br.ReadByte(); + int c04 = br.ReadUInt16(); // t9_xxxx + T2 o2 = new T2(c00, c01, c02, c03, c04); + model.t2List.Add(o2); + } + for (int a = 0; a < cnt2; a++) + { + T2 o2 = model.t2List[a]; + for (int b = 0; b < o2.c03; b++) + { + T9 o9 = model.t9List[o2.c04 + b]; + + int t9c00 = o9.c00; // t11_xxxx + int t9c02 = o9.c02; // t10_xxxx + int t9c04 = o9.c04; // t12_xxxx + int t9c06 = o9.c06; // t12_xxxx + + o2.al9f.Add(new T9f(o2.c04 + b, model.t11List[t9c00 >> 2], model.t10List[t9c02], model.t12List[t9c04], model.t12List[t9c06])); + } + } + + int off2x = tbloff + posTbl.vc8; + int cnt2x = posTbl.vcc; + si.Position = off2x; + for (int a = 0; a < cnt2x; a++) + { + int c00 = br.ReadByte(); + int c01 = br.ReadByte(); + int c02 = br.ReadByte(); + int c03 = br.ReadByte(); + int c04 = br.ReadUInt16(); // t9_xxxx + T2 o2 = new T2(c00, c01, c02, c03, c04); + model.t2xList.Add(o2); + } + for (int a = 0; a < cnt2x; a++) + { + T2 o2 = model.t2xList[a]; + for (int b = 0; b < o2.c03; b++) + { + T9 o9 = model.t9List[o2.c04 + b]; + + int t9c00 = o9.c00; // t11_xxxx + int t9c02 = o9.c02; // t10_xxxx + int t9c04 = o9.c04; // t12_xxxx + int t9c06 = o9.c06; // t12_xxxx + + o2.al9f.Add(new T9f(o2.c04 + b, model.t11List[t9c00 >> 2], model.t10List[t9c02], model.t12List[t9c04], model.t12List[t9c06])); + } + } + + int off3 = tbloff + posTbl.ve0; + int cnt3 = posTbl.ve4; + si.Position = off3; + for (int a3 = 0; a3 < cnt3; a3++) + { + int c00 = br.ReadByte(); + int c01 = br.ReadByte(); + int c02 = br.ReadUInt16(); + int c04 = br.ReadUInt16(); + int c06 = br.ReadUInt16(); + uint c08 = br.ReadUInt32(); + model.t3List.Add(new T3(c00, c01, c02, c04, c06, c08)); + } + + int off4 = tbloff + posTbl.vac; + int cnt4 = posTbl.va2; + si.Position = off4; + for (int a4 = 0; a4 < cnt4; a4++) + { + int c00 = br.ReadUInt16(); + int c02 = br.ReadUInt16(); + model.t4List.Add(new T4(c00, c02)); + } + + model.off5 = tbloff + posTbl.va8; + model.cnt5 = (posTbl.va2 - posTbl.va0); + si.Position = model.off5; + for (int a5 = 0; a5 < model.cnt5; a5++) + { + AxBone o = new AxBone(); + o.cur = br.ReadUInt16(); + o.parent = br.ReadUInt16(); + o.v08 = br.ReadUInt16(); + o.v0c = br.ReadUInt16(); + br.ReadUInt64(); + o.x1 = br.ReadSingle(); + o.y1 = br.ReadSingle(); + o.z1 = br.ReadSingle(); + o.w1 = br.ReadSingle(); + o.x2 = br.ReadSingle(); + o.y2 = br.ReadSingle(); + o.z2 = br.ReadSingle(); + o.w2 = br.ReadSingle(); + o.x3 = br.ReadSingle(); + o.y3 = br.ReadSingle(); + o.z3 = br.ReadSingle(); + o.w3 = br.ReadSingle(); + model.t5List.Add(o); + } + } + + public float FrameLoop { get; } + public float FrameEnd { get; } + public float FramePerSecond { get; } + public float FrameCount { get; } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/EmuBasedAnimMatricesProvider.cs b/OpenKh.Kh2AnimEmu/Mset/EmuBasedAnimMatricesProvider.cs index 7f76b70cb..1c1f4ee58 100644 --- a/OpenKh.Kh2AnimEmu/Mset/EmuBasedAnimMatricesProvider.cs +++ b/OpenKh.Kh2AnimEmu/Mset/EmuBasedAnimMatricesProvider.cs @@ -1,71 +1,71 @@ -using OpenKh.Common; -using OpenKh.Kh2Anim.Mset.EmuRunner; -using OpenKh.Kh2Anim.Mset.Interfaces; -using System; -using System.Collections.Generic; -using System.IO; -using System.Numerics; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - public class EmuBasedAnimMatricesProvider : IAnimMatricesProvider - { - private readonly Mlink emuRunner; - private readonly AnimReader animReader; - private double absTime = 0; - - public EmuBasedAnimMatricesProvider( - AnimReader animReader, - Stream mdlxStream, - Stream animStream - ) - { - emuRunner = new Mlink(); - this.animReader = animReader; - - var matrixOutStream = new MemoryStream(); - - mdlxStream.Position = 0; - animStream.Position = 0; - - // initialize emulator memory space - emuRunner.Permit( - mdlxStream, animReader.cntb1, - animStream, animReader.cntb2, - 0, (float)absTime, matrixOutStream - ); - } - - float IAnimMatricesProvider.FrameLoop => animReader.FrameLoop; - - float IAnimMatricesProvider.FrameEnd => animReader.FrameEnd; - - float IAnimMatricesProvider.FramePerSecond => animReader.FramePerSecond; - - float IAnimMatricesProvider.FrameCount => animReader.FrameCount; - - int IAnimMatricesProvider.MatrixCount => animReader.cntb2; - - Matrix4x4[] IAnimMatricesProvider.ProvideMatrices(double delta) - { - absTime += delta; - - var matrixOutStream = new MemoryStream(); - - emuRunner.Permit( - null, animReader.cntb1, - null, animReader.cntb2, - 0, (float)absTime, matrixOutStream - ); - - var br = new BinaryReader(matrixOutStream); - matrixOutStream.Position = 0; - var matrixOut = new Matrix4x4[animReader.cntb1]; - for (int t = 0; t < animReader.cntb1; t++) - matrixOut[t] = matrixOutStream.ReadMatrix4x4(); - - return matrixOut; - } - } -} +using OpenKh.Common; +using OpenKh.Kh2Anim.Mset.EmuRunner; +using OpenKh.Kh2Anim.Mset.Interfaces; +using System; +using System.Collections.Generic; +using System.IO; +using System.Numerics; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + public class EmuBasedAnimMatricesProvider : IAnimMatricesProvider + { + private readonly Mlink emuRunner; + private readonly AnimReader animReader; + private double absTime = 0; + + public EmuBasedAnimMatricesProvider( + AnimReader animReader, + Stream mdlxStream, + Stream animStream + ) + { + emuRunner = new Mlink(); + this.animReader = animReader; + + var matrixOutStream = new MemoryStream(); + + mdlxStream.Position = 0; + animStream.Position = 0; + + // initialize emulator memory space + emuRunner.Permit( + mdlxStream, animReader.cntb1, + animStream, animReader.cntb2, + 0, (float)absTime, matrixOutStream + ); + } + + float IAnimMatricesProvider.FrameLoop => animReader.FrameLoop; + + float IAnimMatricesProvider.FrameEnd => animReader.FrameEnd; + + float IAnimMatricesProvider.FramePerSecond => animReader.FramePerSecond; + + float IAnimMatricesProvider.FrameCount => animReader.FrameCount; + + int IAnimMatricesProvider.MatrixCount => animReader.cntb2; + + Matrix4x4[] IAnimMatricesProvider.ProvideMatrices(double delta) + { + absTime += delta; + + var matrixOutStream = new MemoryStream(); + + emuRunner.Permit( + null, animReader.cntb1, + null, animReader.cntb2, + 0, (float)absTime, matrixOutStream + ); + + var br = new BinaryReader(matrixOutStream); + matrixOutStream.Position = 0; + var matrixOut = new Matrix4x4[animReader.cntb1]; + for (int t = 0; t < animReader.cntb1; t++) + matrixOut[t] = matrixOutStream.ReadMatrix4x4(); + + return matrixOut; + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/EmuRunner/CustEE.cs b/OpenKh.Kh2AnimEmu/Mset/EmuRunner/CustEE.cs index 6f31c5e9d..fca730c8c 100644 --- a/OpenKh.Kh2AnimEmu/Mset/EmuRunner/CustEE.cs +++ b/OpenKh.Kh2AnimEmu/Mset/EmuRunner/CustEE.cs @@ -1,1799 +1,1799 @@ -//#define UseUnsafe -#define UseBitConverter - -using System; -using System.Collections.Generic; -using System.Text; -using System.Diagnostics; -using System.IO; -using System.Collections; -using System.Runtime.InteropServices; - -namespace OpenKh.Kh2Anim.Mset.EmuRunner -{ - public class UtUB - { - uint[] UL; - bool isR0; - - public UtUB(uint[] UL, bool isR0) - { - this.UL = UL; - this.isR0 = isR0; - } - - public byte this[int x] - { - get - { - switch (x & 3) - { - default: - return (byte)((UL[x >> 2])); - case 1: - return (byte)((UL[x >> 2] >> 8)); - case 2: - return (byte)((UL[x >> 2] >> 16)); - case 3: - return (byte)((UL[x >> 2] >> 24)); - } - } - set - { - if (isR0) - return;// throw new IsR0Exception(); - int v = x >> 2; - switch (x & 3) - { - default: - UL[v] = (UL[v] & 0xFFFFFF00U) | (value); - break; - case 1: - UL[v] = (UL[v] & 0xFFFF00FFU) | (uint)(value << 8); - break; - case 2: - UL[v] = (UL[v] & 0xFF00FFFFU) | (uint)(value << 16); - break; - case 3: - UL[v] = (UL[v] & 0x00FFFFFFU) | (uint)(value << 24); - break; - } - } - } - } - public class UtUS - { - uint[] UL; - bool isR0; - - public UtUS(uint[] UL, bool isR0) - { - this.UL = UL; - this.isR0 = isR0; - } - - public ushort this[int x] - { - get - { - return ((x & 1) == 0) ? ((ushort)(UL[x >> 1])) : ((ushort)(UL[x >> 1] >> 16)); - } - set - { - if (isR0) - return;// throw new IsR0Exception(); - if ((x & 1) == 0) - { - x >>= 1; - UL[x] = (UL[x] & 0xFFFF0000) | (uint)(value); - } - else - { - x >>= 1; - UL[x] = (UL[x] & 0x0000FFFF) | (uint)(value << 16); - } - } - } - } - public class UtUD - { - uint[] UL; - bool isR0; - - public UtUD(uint[] UL, bool isR0) - { - this.UL = UL; - this.isR0 = isR0; - } - - public ulong this[int x] - { - get - { - x <<= 1; - return UL[x] | ((ulong)UL[x + 1] << 32); - } - set - { - if (isR0) - return;// throw new IsR0Exception(); - x <<= 1; - UL[x] = (uint)(value); - UL[x + 1] = (uint)(value >> 32); - } - } - } - public class UtSD - { - uint[] UL; - bool isR0; - - public UtSD(uint[] UL, bool isR0) - { - this.UL = UL; - this.isR0 = isR0; - } - - public long this[int x] - { - get - { - x <<= 1; - return (long)(UL[x] | ((ulong)UL[x + 1] << 32)); - } - set - { - if (isR0) - return;// throw new IsR0Exception(); - x <<= 1; - UL[x] = (uint)(value); - UL[x + 1] = (uint)(value >> 32); - } - } - } - public class UtSL - { - uint[] UL; - bool isR0; - - public UtSL(uint[] UL, bool isR0) - { - this.UL = UL; - this.isR0 = isR0; - } - - public int this[int x] - { - get - { - return (int)UL[x]; - } - set - { - if (isR0) - return;// throw new IsR0Exception(); - UL[x] = (uint)value; - } - } - } - - public class GPR - { - public readonly uint[] UL = new uint[] { 0, 0, 0, 0 }; - public readonly UtUB UB; - public readonly UtUS US; - public readonly UtSL SL; - public readonly UtUD UD; - public readonly UtSD SD; - - // --> SByte - public byte UB0 { get { return UB[0]; } set { UB[0] = value; } } // --> Byte - public ushort US0 { get { return US[0]; } set { US[0] = value; } } // --> Int16 - // --> UInt16 - public int SL0 { get { return SL[0]; } set { SL[0] = value; } } // --> Int32 - public uint UL0 { get { return UL[0]; } set { UL[0] = value; } } // --> UInt32 - public long SD0 { get { return SD[0]; } set { SD[0] = value; } } // --> Int64 - public ulong UD0 { get { return UD[0]; } set { UD[0] = value; } } // --> UInt64 - - public ulong UD1 { get { return UD[1]; } set { UD[1] = value; } } - - public GPR(bool isR0) - { - UB = new UtUB(UL, isR0); - US = new UtUS(UL, isR0); - SL = new UtSL(UL, isR0); - UD = new UtUD(UL, isR0); - SD = new UtSD(UL, isR0); - } - - public override string ToString() - { - return string.Format("{0:x8}_{1:x8}_{2:x8}_{3:x8}", UL[3], UL[2], UL[1], UL[0]); - } - } - public class FPR - { - public float f = 0; - - public uint UL - { - get { return MobUt.F2UL(f); } - set { f = MobUt.UL2F(value); } - } - } - public class Vec : IComparable - { - public Vec(bool isVF0) - { - this.isVF0 = isVF0; - } - public bool isVF0; - public float[] F = new float[] { 0, 0, 0, 1 }; - public float x { get { return F[0]; } set { F[0] = value; } } - public float y { get { return F[1]; } set { F[1] = value; } } - public float z { get { return F[2]; } set { F[2] = value; } } - public float w { get { return F[3]; } set { F[3] = value; } } - - public override string ToString() - { - return string.Format("{0} | {1} | {2} | {3}", F[0], F[1], F[2], F[3]); - } - - #region IComparable メンバ - - public int CompareTo(Vec o) - { - int t; - if (0 != (t = x.CompareTo(o.x))) - return t; - if (0 != (t = y.CompareTo(o.y))) - return t; - if (0 != (t = z.CompareTo(o.z))) - return t; - if (0 != (t = w.CompareTo(o.w))) - return t; - return 0; - } - - #endregion - } - public class VIv - { - public UInt32 UL = 0; - - public float f - { - get { return MobUt.UL2F(UL); } - set { UL = MobUt.F2UL(value); } - } - } - public class CustEE - { - public GPR r0 = new GPR(true); - public GPR at = new GPR(false); - public GPR v0 = new GPR(false); - public GPR v1 = new GPR(false); - public GPR a0 = new GPR(false); - public GPR a1 = new GPR(false); - public GPR a2 = new GPR(false); - public GPR a3 = new GPR(false); - public GPR t0 = new GPR(false); - public GPR t1 = new GPR(false); - public GPR t2 = new GPR(false); - public GPR t3 = new GPR(false); - public GPR t4 = new GPR(false); - public GPR t5 = new GPR(false); - public GPR t6 = new GPR(false); - public GPR t7 = new GPR(false); - public GPR s0 = new GPR(false); - public GPR s1 = new GPR(false); - public GPR s2 = new GPR(false); - public GPR s3 = new GPR(false); - public GPR s4 = new GPR(false); - public GPR s5 = new GPR(false); - public GPR s6 = new GPR(false); - public GPR s7 = new GPR(false); - public GPR t8 = new GPR(false); - public GPR t9 = new GPR(false); - public GPR k0 = new GPR(false); - public GPR k1 = new GPR(false); - public GPR gp = new GPR(false); - public GPR sp = new GPR(false); - public GPR s8 = new GPR(false); - public GPR ra = new GPR(false); - - public GPR zero = new GPR(true); - - public GPR[] GPR - { - get - { - return new GPR[] { - r0, at, v0, v1, a0, a1, a2, a3, t0, t1, t2, t3, t4, t5, t6, t7, - s0, s1, s2, s3, s4, s5, s6, s7, t8, t9, k0, k1, gp, sp, s8, ra, - }; - } - } - - public Int64 LO = 0, HI = 0; - - // EE - public byte[] ram = new byte[1024 * 1024 * 32]; - public byte[] spr = new byte[16384]; - // COP1, FPU - public FPR[] fpr = new FPR[] { new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), }; - public uint[] fprc = new uint[32]; - public FPR fpracc = new FPR(); - // COP2, VU0 - public Vec[] VF = new Vec[] { new Vec(true), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), }; - public Vec Vacc = new Vec(false); - public VIv[] VI = new VIv[] { new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), }; - public VIv Vq; - public VIv Vp; - public VIv Vr; - public VIv Vi; - public VIv Vcf; - - uint fcr31 = 0; - - public bool fcr31_23 { get { return 0 != (fcr31 & 0x800000); } set { fcr31 = (fcr31 & (~0x800000U)) | (value ? 0x800000U : 0U); } } - - public uint pc = 0; - - public Func hwRead8 = delegate (uint mem) { throw new AccessUnpreparedMemoryException(mem); }; - public Func hwRead16 = delegate (uint mem) { throw new AccessUnpreparedMemoryException(mem); }; - public Func hwRead32 = delegate (uint mem) { throw new AccessUnpreparedMemoryException(mem); }; - public Func hwRead64 = delegate (uint mem) { throw new AccessUnpreparedMemoryException(mem); }; - - public Action hwWrite8 = delegate (uint mem, byte v) { throw new AccessUnpreparedMemoryException(mem); }; - public Action hwWrite16 = delegate (uint mem, ushort v) { throw new AccessUnpreparedMemoryException(mem); }; - public Action hwWrite32 = delegate (uint mem, uint v) { throw new AccessUnpreparedMemoryException(mem); }; - public Action hwWrite64 = delegate (uint mem, ulong v) { throw new AccessUnpreparedMemoryException(mem); }; - - public CustEE() - { - this.Vcf = VI[18]; - this.Vr = VI[20]; - this.Vi = VI[21]; - this.Vq = VI[22]; - this.Vp = VI[23]; - - ram2 = new BinaryWriter(ram1 = new MemoryStream(ram, true)); - spr2 = new BinaryWriter(spr1 = new MemoryStream(spr, true)); - } - - BinaryWriter ram2, spr2; - MemoryStream ram1, spr1; - - public void eeWrite64(uint off, ulong val) - { - if (false) - { } - else if ((off & 0xF0000000U) == 0x70000000U) - { - spr1.Position = off & 0x3FFF; - spr2.Write(val); - return; - } - else if ((off & 0xF0000000U) == 0x10000000U) - { - hwWrite64(off, val); - return; - } - else if ((off & 0xF0000000U) == 0x00000000U) - { - ram1.Position = off; - ram2.Write(val); - return; - } - - throw new AccessUnpreparedMemoryException(off); - } - public void eeWriteSingle(uint off, float val) - { - if (false) - { } - else if ((off & 0xF0000000U) == 0x70000000U) - { - spr1.Position = off & 0x3FFF; - spr2.Write(val); - return; - } - else if ((off & 0xF0000000U) == 0x10000000U) - { - ; - } - else if ((off & 0xF0000000U) == 0x00000000U) - { - ram1.Position = off; - ram2.Write(val); - return; - } - - throw new AccessUnpreparedMemoryException(off); - } - public void eeWrite32(uint off, uint val) - { - if (false) - { } - else if ((off & 0xF0000000U) == 0x70000000U) - { - spr1.Position = off & 0x3FFF; - spr2.Write(val); - return; - } - else if ((off & 0xF0000000U) == 0x10000000U) - { - hwWrite32(off, val); - return; - } - else if ((off & 0xF0000000U) == 0x00000000U) - { - ram1.Position = off; - ram2.Write(val); - return; - } - - throw new AccessUnpreparedMemoryException(off); - } - public void eeWrite16(uint off, ushort val) - { - if (false) - { } - else if ((off & 0xF0000000U) == 0x70000000U) - { - spr1.Position = off & 0x3FFF; - spr2.Write(val); - return; - } - else if ((off & 0xF0000000U) == 0x10000000U) - { - hwWrite16(off, val); - return; - } - else if ((off & 0xF0000000U) == 0x00000000U) - { - ram1.Position = off; - ram2.Write(val); - return; - } - - throw new AccessUnpreparedMemoryException(off); - } - public void eeWrite8(uint off, byte val) - { - if (false) - { } - else if ((off & 0xF0000000U) == 0x70000000U) - { - spr[off & 0x3FFF] = val; - return; - } - else if ((off & 0xF0000000U) == 0x10000000U) - { - hwWrite8(off, val); - return; - } - else if ((off & 0xF0000000U) == 0x00000000U) - { - ram[off] = val; - return; - } - - throw new AccessUnpreparedMemoryException(off); - } - - - public byte eeRead8(uint off) - { - if (false) - { } - else if ((off & 0xF0000000U) == 0x70000000U) - { - return spr[off & 0x3FFF]; - } - else if ((off & 0xF0000000U) == 0x10000000U) - { - return hwRead8(off); - } - else if ((off & 0xF0000000U) == 0x00000000U) - { - return ram[off]; - } - - throw new AccessUnpreparedMemoryException(off); - } - - public ushort eeRead16(uint off) - { - if (false) - { } - else if ((off & 0xF0000000U) == 0x70000000U) - { - return BitConverter.ToUInt16(spr, (int)off & 0x3FFF); - } - else if ((off & 0xF0000000U) == 0x10000000U) - { - return hwRead16(off); - } - else if ((off & 0xF0000000U) == 0x00000000U) - { - return BitConverter.ToUInt16(ram, (int)off); - } - - throw new AccessUnpreparedMemoryException(off); - } - - public uint eeRead32(uint off) - { - if (false) - { } - else if ((off & 0xF0000000U) == 0x70000000U) - { - return BitConverter.ToUInt32(spr, (int)off & 0x3FFF); - } - else if ((off & 0xF0000000U) == 0x10000000U) - { - return hwRead32(off); - } - else if ((off & 0xF0000000U) == 0x00000000U) - { - return BitConverter.ToUInt32(ram, (int)off); - } - - throw new AccessUnpreparedMemoryException(off); - } - - public ulong eeRead64(uint off) - { - if (false) - { } - else if ((off & 0xF0000000U) == 0x70000000U) - { - return BitConverter.ToUInt64(spr, (int)off & 0x3FFF); - } - else if ((off & 0xF0000000U) == 0x10000000U) - { - return hwRead64(off); - } - else if ((off & 0xF0000000U) == 0x00000000U) - { - return BitConverter.ToUInt64(ram, (int)off); - } - - throw new AccessUnpreparedMemoryException(off); - } - - public float eeReadSingle(uint off) - { - if (false) - { } - else if ((off & 0xF0000000U) == 0x70000000U) - { - return BitConverter.ToSingle(spr, (int)off & 0x3FFF); - } - else if ((off & 0xF0000000U) == 0x10000000U) - { - ; - } - else if ((off & 0xF0000000U) == 0x00000000U) - { - return BitConverter.ToSingle(ram, (int)off); - } - - throw new AccessUnpreparedMemoryException(off); - } - } - - public delegate TResult Func(); - public delegate TResult Func(T x); - - public delegate void Action(T1 x, T2 y); - - public class MobUt - { - public static BitArray bita = new BitArray(2097152, false); - public static BitArray bitr = new BitArray(2097152, false); - - public delegate void Tx8(); - - public static void LQ(CustEE ee, GPR rt, uint off) - { - //#Debug.Assert(off <= 32U * 1024 * 1024, "Avail only within 32MB ram"); - sysr((int)(off >> 4)); - rt.UL[0] = ee.eeRead32(off + 0); - rt.UL[1] = ee.eeRead32(off + 4); - rt.UL[2] = ee.eeRead32(off + 8); - rt.UL[3] = ee.eeRead32(off + 12); - } - public static void SQ(CustEE ee, GPR rt, uint off) - { - sysw((int)(off >> 4)); - ee.eeWrite32(off + 0, rt.UL[0]); - ee.eeWrite32(off + 4, rt.UL[1]); - ee.eeWrite32(off + 8, rt.UL[2]); - ee.eeWrite32(off + 12, rt.UL[3]); - } - public static void VCLIP(CustEE ee, Vec ft, Vec fs) - { - uint Vcf = 0; - float pw = +Math.Abs(MobUt.vuDouble(ft.w)); - float nw = -pw; - if (MobUt.vuDouble(fs.x) > pw) - Vcf |= 0x01; - if (MobUt.vuDouble(fs.x) < nw) - Vcf |= 0x02; - if (MobUt.vuDouble(fs.y) > pw) - Vcf |= 0x04; - if (MobUt.vuDouble(fs.y) < nw) - Vcf |= 0x08; - if (MobUt.vuDouble(fs.z) > pw) - Vcf |= 0x10; - if (MobUt.vuDouble(fs.z) < nw) - Vcf |= 0x20; - ee.Vcf.UL = ((ee.Vcf.UL << 6) | Vcf) & 0xFFFFFFu; - } - public static float UL2F(uint val) - { -#if UseBitConverter - return BitConverter.ToSingle(BitConverter.GetBytes(val), 0); -#elif UseUnsafe - unsafe - { - return *(float*)&val; - } -#else - MemoryStream os = new MemoryStream(new byte[] { 0, 0, 0, 0 }); - new BinaryWriter(os).Write(val); - os.Position = 0; - float r = new BinaryReader(os).ReadSingle(); - //Debug.Assert(!float.IsNaN(r)); - //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); - return r; -#endif - } - public static uint F2UL(float val) - { -#if UseBitConverter - return BitConverter.ToUInt32(BitConverter.GetBytes(val), 0); -#elif UseUnsafe - unsafe - { - return *(uint*)&val; - } -#else - MemoryStream os = new MemoryStream(new byte[] { 0, 0, 0, 0 }); - //Debug.Assert(!float.IsNaN(val)); - //Debug.Assert(!float.IsNegativeInfinity(val) && !float.IsPositiveInfinity(val)); - new BinaryWriter(os).Write(val); - os.Position = 0; - uint r = new BinaryReader(os).ReadUInt32(); - return r; -#endif - } - - public static void SD(CustEE ee, GPR rt, uint off) - { - sysw((int)(off >> 4)); - ee.eeWrite64(off, rt.UD0); - } - - public static void LD(CustEE ee, GPR rt, uint off) - { - sysr((int)(off >> 4)); - rt.UD0 = ee.eeRead64(off); - } - - public static void LWC1(CustEE ee, FPR ft, uint off) - { - //#Debug.Assert(off <= 32U * 1024 * 1024, "Avail only within 32MB ram"); - sysr((int)(off >> 4)); - float r = ee.eeReadSingle(off); - //Debug.Assert(!float.IsNaN(r)); - //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); - ft.f = r; - } - - public static void SWC1(CustEE ee, FPR ft, uint off) - { - //#Debug.Assert(off <= 32U * 1024 * 1024, "Avail only within 32MB ram"); - sysw((int)(off >> 4)); - ee.eeWriteSingle(off, ft.f); - } - - public static void LQC2(CustEE ee, Vec VF, uint off) - { - //#Debug.Assert(off <= 32U * 1024 * 1024 && off + 16U <= 32U * 1024 * 1024, "Avail only within 32MB ram"); - sysr((int)(off >> 4)); - if (true) - { - float r = ee.eeReadSingle(off + 0U); - //Debug.Assert(!float.IsNaN(r)); - //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); - if (VF != ee.VF[0]) - VF.x = r; - } - if (true) - { - float r = ee.eeReadSingle(off + 4U); - //Debug.Assert(!float.IsNaN(r)); - //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); - if (VF != ee.VF[0]) - VF.y = r; - } - if (true) - { - float r = ee.eeReadSingle(off + 8U); - //Debug.Assert(!float.IsNaN(r)); - //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); - if (VF != ee.VF[0]) - VF.z = r; - } - if (true) - { - float r = ee.eeReadSingle(off + 12U); - //Debug.Assert(!float.IsNaN(r)); - //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); - if (VF != ee.VF[0]) - VF.w = r; - } - } - - public static void QMFC2(GPR rt, Vec vf) - { -#if UseBitConverter - rt.UL[0] = BitConverter.ToUInt32(BitConverter.GetBytes(vf.x), 0); - rt.UL[1] = BitConverter.ToUInt32(BitConverter.GetBytes(vf.y), 0); - rt.UL[2] = BitConverter.ToUInt32(BitConverter.GetBytes(vf.z), 0); - rt.UL[3] = BitConverter.ToUInt32(BitConverter.GetBytes(vf.w), 0); -#elif UseUnsafe - unsafe - { - float f; - f = vf.x; rt.UL[0] = *(uint*)&f; - f = vf.y; rt.UL[1] = *(uint*)&f; - f = vf.z; rt.UL[2] = *(uint*)&f; - f = vf.w; rt.UL[3] = *(uint*)&f; - } -#else - if (rt.isR0) return; - MemoryStream os = new MemoryStream(16); - BinaryWriter wr = new BinaryWriter(os); - wr.Write(vf.x); - wr.Write(vf.y); - wr.Write(vf.z); - wr.Write(vf.w); - os.Position = 0; - BinaryReader br = new BinaryReader(os); - rt.UL[0] = br.ReadUInt32(); - rt.UL[1] = br.ReadUInt32(); - rt.UL[2] = br.ReadUInt32(); - rt.UL[3] = br.ReadUInt32(); -#endif - } - - public static void SQC2(CustEE ee, Vec VF, uint off) - { - sysw((int)(off >> 4)); - ee.eeWriteSingle(off + 0, VF.x); - ee.eeWriteSingle(off + 4, VF.y); - ee.eeWriteSingle(off + 8, VF.z); - ee.eeWriteSingle(off + 12, VF.w); - } - - public static void CFC2(GPR rt, VIv id) - { - rt.UD0 = id.UL; - } - - public static void Latency() { } - - public static void SW(CustEE ee, GPR rt, uint off) - { - sysw((int)(off >> 4)); - ee.eeWrite32(off, rt.UL0); - } - - public static void DSRL(GPR rd, GPR rt, int sa) - { - rd.UD0 = rt.UD0 >> sa; - } - - public static void DSRLV(GPR rd, GPR rt, GPR rs) - { - rd.UD0 = rt.UD0 >> rs.UB0; - } - - public static void SB(CustEE ee, GPR rt, uint off) - { - sysw((int)(off >> 4)); - ee.eeWrite8(off, rt.UB0); - } - - public static void SLL(GPR rd, GPR rt, int sa) - { - rd.SD0 = (int)(rt.UL0 << sa); - } - - public static void LW(CustEE ee, GPR rt, uint off) - { - sysr((int)(off >> 4)); - rt.SD0 = (int)ee.eeRead32(off); - } - - public static void LWU(CustEE ee, GPR rt, uint off) - { - sysr((int)(off >> 4)); - rt.UD0 = ee.eeRead32(off); - } - - public static void LHU(CustEE ee, GPR rt, uint off) - { - sysr((int)(off >> 4)); - rt.UD0 = ee.eeRead16(off); - } - - public static void LBU(CustEE ee, GPR rt, uint off) - { - sysr((int)(off >> 4)); - rt.UD0 = ee.eeRead8(off); - } - - public static void MFC1(GPR rt, FPR fs) - { - MemoryStream os = new MemoryStream(new byte[] { 0, 0, 0, 0 }); - new BinaryWriter(os).Write(fs.f); - os.Position = 0; - rt.SD0 = new BinaryReader(os).ReadInt32(); - } - - public static void SH(CustEE ee, GPR rt, uint off) - { - sysw((int)(off >> 4)); - ee.eeWrite16(off, rt.US0); - } - - private static void sysw(int mark) - { - if (mark >= bita.Count) - return; - bita[mark] = true; - } - private static void sysr(int mark) - { - if (mark >= bita.Count) - return; - if (bita[mark]) - return; - bita[mark] = true; - bitr[mark] = true; - } - - public static void QMTC2(GPR rt, Vec vf) - { -#if UseBitConverter - vf.x = BitConverter.ToSingle(BitConverter.GetBytes(rt.UL[0]), 0); - vf.y = BitConverter.ToSingle(BitConverter.GetBytes(rt.UL[1]), 0); - vf.z = BitConverter.ToSingle(BitConverter.GetBytes(rt.UL[2]), 0); - vf.w = BitConverter.ToSingle(BitConverter.GetBytes(rt.UL[3]), 0); -#elif UseUnsafe - unsafe - { - uint v; - v = rt.UL[0]; vf.x = *(float*)&v; - v = rt.UL[1]; vf.y = *(float*)&v; - v = rt.UL[2]; vf.z = *(float*)&v; - v = rt.UL[3]; vf.w = *(float*)&v; - } -#else - if (vf.isVF0) return; - MemoryStream os = new MemoryStream(16); - BinaryWriter wr = new BinaryWriter(os); - wr.Write(rt.UL[0]); - wr.Write(rt.UL[1]); - wr.Write(rt.UL[2]); - wr.Write(rt.UL[3]); - os.Position = 0; - BinaryReader br = new BinaryReader(os); - vf.x = br.ReadSingle(); - vf.y = br.ReadSingle(); - vf.z = br.ReadSingle(); - vf.w = br.ReadSingle(); -#endif - } - - public static void LH(CustEE ee, GPR rt, uint off) - { - sysr((int)(off >> 4)); - rt.SD0 = (short)ee.eeRead16(off); - } - - public static void XOR(GPR rd, GPR rs, GPR rt) - { - rd.UD0 = rs.UD0 ^ rt.UD0; - } - - public static void DSRL32(GPR rd, GPR rt, int sa) - { - rd.UD0 = rt.UD0 >> (32 + sa); - } - - public static void DSLL32(GPR rd, GPR rt, int sa) - { - rd.UD0 = rt.UD0 << (32 + sa); - } - - public static void CVT_W(FPR fd, FPR fs) - { - uint r = F2UL(fs.f); - if ((r & 0x7F800000U) <= 0x4E800000U) - { - fd.f = UL2F((uint)((int)fs.f)); - } - else if ((r & 0x80000000) != 0) - { - fd.f = UL2F(0x80000000); - } - else - { - fd.f = UL2F(0x7FFFFFFF); - } - } - - public static void SRL(GPR rd, GPR rt, int sa) - { - rd.UD0 = (ulong)((int)(rt.UL0 >> sa)); - } - - public static void SRA(GPR rd, GPR rt, int sa) - { - rd.SD0 = (int)(rt.SL0 >> sa); - } - - public static float MUL(float v0, float v1) - { - return vuDouble(vuDouble(v0) * vuDouble(v1)); - } - - public static float MADD(float f0, float f1, float f2) - { - return vuDouble(vuDouble(f0) + (float)(vuDouble(f1) * vuDouble(f2))); - } - - public static float OPMSUB(float f0, float f1, float f2) - { - return vuDouble(f0) - (float)(vuDouble(f1) * vuDouble(f2)); - } - - public static float vuDouble(float v) - { -#if UseUnsafe - unsafe - { - uint f = *(uint*)&v; - switch (f & 0x7F800000) - { - case 0x0: - f &= 0x80000000; - return *(float*)&f; - case 0x7F800000: - f = ((f & 0x80000000) | 0x7F7FFFFF); - return *(float*)&f; - default: - return v; - } - } -#else - uint f = F2UL(v); - switch (f & 0x7F800000) - { - case 0x0: - f &= 0x80000000; - return UL2F(f); - case 0x7F800000: - return UL2F((f & 0x80000000) | 0x7F7FFFFF); - default: - return UL2F(f); - } -#endif - } - - public static float MSUB(float f0, float f1, float f2) - { - return vuDouble(vuDouble(f0) - (float)(vuDouble(f1) * vuDouble(f2))); - } - - public static void SLLV(GPR rd, GPR rt, GPR rs) - { - rd.SD0 = (int)(rt.SD0 << (rs.UB0 & 15)); - } - - public static void CVT_S(FPR fd, FPR fs) - { - fd.f = (int)fs.UL; - } - - public static void LB(CustEE ee, GPR rt, uint off) - { - sysr((int)(off >> 4)); - rt.SD0 = (sbyte)ee.eeRead8(off); - } - - [DllImport("MySSE.dll", CallingConvention = CallingConvention.StdCall)] - static extern void MySSE_VMx16(float[] param); - - public static void VMx16(Vec vacc, - Vec vec1, float v1f, - Vec vec2, float v2f, - Vec vec3, float v3f, - Vec vec4, float v4f, - Vec veco - ) - { -#if UseUnsafe && false - unsafe { - float[] param = new float[] { - vec1.F[0], vec1.F[1], vec1.F[2], vec1.F[3], - vec2.F[0], vec2.F[1], vec2.F[2], vec2.F[3], - vec3.F[0], vec3.F[1], vec3.F[2], vec3.F[3], - vec4.F[0], vec4.F[1], vec4.F[2], vec4.F[3], - v1f, v1f, v1f, v1f, - v2f, v2f, v2f, v2f, - v3f, v3f, v3f, v3f, - v4f, v4f, v4f, v4f, - }; - - MySSE_VMx16(param); - - veco.x = param[0]; - veco.y = param[1]; - veco.z = param[2]; - veco.w = param[3]; - } -#else - veco.F[0] = vuDouble((vacc.F[0] = vuDouble((vec1.F[0] * v1f) + (vec2.F[0] * v2f) + (vec3.F[0] * v3f))) + (vec4.F[0] * v4f)); - veco.F[1] = vuDouble((vacc.F[1] = vuDouble((vec1.F[1] * v1f) + (vec2.F[1] * v2f) + (vec3.F[1] * v3f))) + (vec4.F[1] * v4f)); - veco.F[2] = vuDouble((vacc.F[2] = vuDouble((vec1.F[2] * v1f) + (vec2.F[2] * v2f) + (vec3.F[2] * v3f))) + (vec4.F[2] * v4f)); - veco.F[3] = vuDouble((vacc.F[3] = vuDouble((vec1.F[3] * v1f) + (vec2.F[3] * v2f) + (vec3.F[3] * v3f))) + (vec4.F[3] * v4f)); -#endif - } - - public static void DSLLV(GPR rd, GPR rt, GPR rs) - { - rd.UD0 = (ulong)(rt.UD0 << (rs.UB0 & 63)); - } - - public static void POR(GPR rd, GPR rt, GPR rs) - { - rd.UD0 = rs.UD0 | rt.UD0; - rd.UD1 = rs.UD1 | rt.UD1; - } - - public static void PAND(GPR rd, GPR rt, GPR rs) - { - rd.UD0 = rs.UD0 & rt.UD0; - rd.UD1 = rs.UD1 & rt.UD1; - } - - public static void ADD(GPR rd, GPR rt, GPR rs) - { - rd.SD0 = (rs.SL0 + rt.SL0); - } - - public static void DSLL(GPR rd, GPR rt, int sa) - { - rd.UD0 = (ulong)(rt.UD0 << (sa & 63)); - } - - public static void DSRA(GPR rd, GPR rt, int sa) - { - rd.SD0 = (long)(rt.SD0 >> sa); - } - - public static void DSRA32(GPR rd, GPR rt, int sa) - { - rd.SD0 = (long)(rt.SD0 >> (32 + sa)); - } - - public static void SYSCALL(int code) - { - // http://gamehacking.org/?s=faqs&id=90 - Debug.WriteLine(String.Format("#SYSCALL {0:x}", code)); - } - - public static void PEXTLW(GPR rd, GPR rs, GPR rt) - { - uint[] res = { - rt.UL[0], - rs.UL[0], - rt.UL[1], - rs.UL[1], - }; - for (int x = 0; x < 4; x++) - rd.UL[x] = res[x]; - } - - public static void PEXTLH(GPR rd, GPR rs, GPR rt) - { - ushort[] res = { - rt.US[0], - rs.US[0], - rt.US[1], - rs.US[1], - rt.US[2], - rs.US[2], - rt.US[3], - rs.US[3], - }; - for (int x = 0; x < 8; x++) - rd.US[x] = res[x]; - } - - public static void PEXTLB(GPR rd, GPR rs, GPR rt) - { - byte[] res ={ - rt.UB[0], - rs.UB[0], - rt.UB[1], - rs.UB[1], - rt.UB[2], - rs.UB[2], - rt.UB[3], - rs.UB[3], - rt.UB[4], - rs.UB[4], - rt.UB[5], - rs.UB[5], - rt.UB[6], - rs.UB[6], - rt.UB[7], - rs.UB[7], - }; - for (int x = 0; x < 16; x++) - rd.UB[x] = res[x]; - } - - public static void MULTU(CustEE ee, GPR rs, GPR rt) - { - Int64 r = (Int64)rs.UL0 * rt.UL0; - ee.LO = (int)(r); - ee.HI = (int)(r >> 32); - } - public static void MULT(CustEE ee, GPR rd, GPR rs, GPR rt) - { - Int64 r = (Int64)rs.SL0 * rt.SL0; - ee.LO = (int)(r); - ee.HI = (int)(r >> 32); - rd.SD0 = r; - } - - public static void MFC0(CustEE ee, GPR rt, int rd) - { - //fake - rt.UD0 = 0; - } - - public static void MOVZ(GPR rd, GPR rs, GPR rt) - { - if (rt.UD0 == 0) - rd.UD0 = rs.UD0; - } - - public static void PCPYH(GPR rd, GPR rt) - { - UInt64 v0 = rt.US[0]; - UInt64 v1 = rt.US[4]; - rd.UD0 = v0 | (v0 << 16) | (v0 << 32) | (v0 << 48); - rd.UD1 = v1 | (v1 << 16) | (v1 << 32) | (v1 << 48); - } - - public static void VRXOR(CustEE ee, float fs) - { - ee.Vr.UL = ee.Vr.UL ^ (F2UL(fs) & 0x7FFFFF); - } - - public static float VRNEXT(CustEE ee, bool next) - { - if (next) - { - ee.Vr.f = new Random((int)ee.Vr.UL).Next(1, 20000) / 10000.0f; - } - return ee.Vr.f; - } - - public static void PADDW(GPR rd, GPR rs, GPR rt) - { - for (int x = 0; x < 4; x++) - rd.UL[x] = rs.UL[x] + rt.UL[x]; - } - - public static float MINI(float x, float y) - { - return Math.Min(x, y); - } - - public static float MAX(float x, float y) - { - return Math.Max(x, y); - } - - public static void PROT3W(GPR rd, GPR rt) - { - uint[] res = { - rt.UL[1], - rt.UL[2], - rt.UL[0], - rt.UL[3], - }; - for (int x = 0; x < 4; x++) - rd.UL[x] = res[x]; - } - - public static void PPACW(GPR rd, GPR rs, GPR rt) - { - uint[] res = { - rt.UL[0], - rt.UL[2], - rs.UL[0], - rs.UL[2], - }; - for (int x = 0; x < 4; x++) - rd.UL[x] = res[x]; - } - - public static void PEXTUW(GPR rd, GPR rs, GPR rt) - { - uint[] res = { - rt.UL[2], - rs.UL[2], - rt.UL[3], - rs.UL[3], - }; - for (int x = 0; x < 4; x++) - rd.UL[x] = res[x]; - } - - public static void PPACB(GPR rd, GPR rs, GPR rt) - { - byte[] res = { - rt.UB[0], - rt.UB[2], - rt.UB[4], - rt.UB[6], - rt.UB[8], - rt.UB[10], - rt.UB[12], - rt.UB[14], - rs.UB[0], - rs.UB[2], - rs.UB[4], - rs.UB[6], - rs.UB[8], - rs.UB[10], - rs.UB[12], - rs.UB[14], - }; - for (int x = 0; x < 16; x++) - rd.UB[x] = res[x]; - } - public static void PPACH(GPR rd, GPR rs, GPR rt) - { - ushort[] res = { - rt.US[0], - rt.US[2], - rt.US[4], - rt.US[6], - rs.US[0], - rs.US[2], - rs.US[4], - rs.US[6], - }; - for (int x = 0; x < 8; x++) - rd.US[x] = res[x]; - } - - public static void PCPYLD(GPR rd, GPR rs, GPR rt) - { - UInt64 v0 = rt.UD0; - UInt64 v1 = rs.UD0; - rd.UD0 = v0; - rd.UD1 = v1; - } - public static void PCPYUD(GPR rd, GPR rs, GPR rt) - { - UInt64 v0 = rs.UD1; - UInt64 v1 = rt.UD1; - rd.UD0 = v0; - rd.UD1 = v1; - } - - public static void XORI(GPR rt, GPR rs, uint imm) - { - rt.UL0 = rs.UL0 ^ imm; - } - - public static void CTC2(GPR rt, VIv id) - { - id.UL = rt.UL0; - } - - public static void PSRLW(GPR rd, GPR rt, int sa) - { - rd.UL[0] = rt.UL[0] >> sa; - rd.UL[1] = rt.UL[1] >> sa; - rd.UL[2] = rt.UL[2] >> sa; - rd.UL[3] = rt.UL[3] >> sa; - } - - // MobUtHere --- - } - -#if false - public class Mobx { - CustEE ee = new CustEE(); - uint pc; - - delegate void Txxxxxxxx(); - SortedList dicti2a = new SortedList(); - - public void Exec() { - dicti2a[0x011B420] = new Txxxxxxxx(_011B420); - - pc = 0x011B420; - while (true) { - (dicti2a[pc])(); - } - } - - public void _011B420() { - ee.t7.US[1] = 0x0035; - ee.t7.SL[0] += (short)0x4260; - MobUt.LQ(ee, ee.t0, 0x0000 + ee.t7.UL[0]); - MobUt.LQ(ee, ee.t1, 0x0010 + ee.t7.UL[0]); - MobUt.LQ(ee, ee.t2, 0x0020 + ee.t7.UL[0]); - MobUt.LQ(ee, ee.t3, 0x0030 + ee.t7.UL[0]); - MobUt.SQ(ee, ee.t0, 0x0000 + ee.t7.UL[0]); - MobUt.SQ(ee, ee.t1, 0x0010 + ee.t7.UL[0]); - MobUt.SQ(ee, ee.t2, 0x0020 + ee.t7.UL[0]); - MobUt.SQ(ee, ee.t3, 0x0030 + ee.t7.UL[0]); - pc = ee.ra.UL[0]; - } - - public void DUMMY() { - // @0011B420 LUI t7, $0035 - this.ee.t7.UD0 = 53 << 16; - - this.ee.t7.SL[0] = (this.ee.t7.SL[0] + 16992); - MobUt.LQ(this.ee, this.ee.t0, (0 + this.ee.t7.UL[0])); - MobUt.LQ(this.ee, this.ee.t1, (16 + this.ee.t7.UL[0])); - MobUt.LQ(this.ee, this.ee.t2, (32 + this.ee.t7.UL[0])); - MobUt.LQ(this.ee, this.ee.t3, (48 + this.ee.t7.UL[0])); - MobUt.LQ(this.ee, this.ee.t0, (0 + this.ee.a0.UL[0])); - MobUt.LQ(this.ee, this.ee.t1, (16 + this.ee.a0.UL[0])); - MobUt.LQ(this.ee, this.ee.t2, (32 + this.ee.a0.UL[0])); - MobUt.LQ(this.ee, this.ee.t3, (48 + this.ee.a0.UL[0])); - this.pc = this.ee.ra.UL[0]; - // @0011B450 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - this.ee.sp.SL[0] = (this.ee.sp.SL[0] + -16); - - // @0011B458 SD s0, $0000(sp) - MobUt.SD(ee, ee.s0, 0x0000 + ee.sp.UL[0]); - // @0011B458 SD s0, $0000(sp) - MobUt.SD(this.ee, this.ee.s0, (0 + this.ee.sp.UL[0])); - // @0011B45C C.EQ.S $f12, $f0 - ee.fcr31_23 = ee.fpr[12].f == ee.fpr[0].f; - // @0011B45C C.EQ.S $f12, $f0 - this.ee.fcr31_23 = (this.ee.fpr[12].f == this.ee.fpr[0].f); - // @0011B464 BC1T $0011b484 - if (ee.fcr31_23) pc = 0x0011B484; - // @0011B464 BC1T $0011b484 - if (this.ee.fcr31_23) { - this.pc = 1160324u; - } - // @0011B468 DADDU s0, a0, zero - ee.s0.UD[0] = ee.a0.UD[0] + ee.r0.UD[0]; - // @0011B468 DADDU s0, a0, zero - this.ee.s0.UD[0] = (this.ee.a0.UD[0] + this.ee.r0.UD[0]); - - // @0011B46C JAL $0011bdc8 - ee.ra.UL[0] = pc + 8; pc = 0x0011B46C; - // @0011B46C JAL $0011bdc8 - this.ee.ra.UL[0] = 1160308u; - this.pc = 1162696u; - - // @0011B474 MOV.S $f12, $f0 - ee.fpr[12].f = ee.fpr[0].f; - // @0011B474 MOV.S $f12, $f0 - this.ee.fpr[12].f = this.ee.fpr[0].f; - - // @0011B488 LD ra, $0008(sp) - MobUt.LD(ee, ee.ra, 0x0008 + ee.sp.UL[0]); - // @0011B488 LD ra, $0008(sp) - MobUt.LD(this.ee, this.ee.ra, (8 + this.ee.sp.UL0)); - - // @0011B528 ADDIU sp, sp, $ffe0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); - - // @0011B570 LWC1 $f0, $0004(s1) - MobUt.LWC1(ee, ee.fpr[0], 4 + ee.s1.UL0); - // @0011B570 LWC1 $f0, $0004(s1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4 + this.ee.s1.UL0)); - - // @0011B85C SWC1 $f20, $0048(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (0x0048 + this.ee.s1.UL0)); - // @0011B534 SWC1 $f20, $0018(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (24 + this.ee.sp.UL0)); - - // @0011B868 C.LT.S $f20, $f0 - ee.fcr31_23 = ee.fpr[20].f < ee.fpr[0].f; - // @0011B868 C.LT.S $f20, $f0 - this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[0].f); - - // @0011B884 BC1FL $0011b894 - if (!ee.fcr31_23) { - pc = 0x0011b894; - //xxx - } - - // @0011B8A0 MULA.S $f13, $f13 - ee.fpracc.f = ee.fpr[13].f * ee.fpr[13].f; - // @0011B8A0 MULA.S $f13, $f13 - this.ee.fpracc.f = (this.ee.fpr[13].f * this.ee.fpr[13].f); - - // @0011B8A4 MADD.S $f0, $f12, $f12 - ee.fpr[0].f = ee.fpracc.f + ee.fpr[12].f * ee.fpr[12].f; - // @0011B8A4 MADD.S $f0, $f12, $f12 - this.ee.fpr[0].f = (this.ee.fpracc.f - + (this.ee.fpr[12].f * this.ee.fpr[12].f)); - - // @0011B8B4 SQRT.S $f0, $f0 - ee.fpr[0].f = (float)Math.Sqrt(ee.fpr[0].f); - // @0011B8B4 SQRT.S $f0, $f0 - this.ee.fpr[0].f = ((float)(System.Math.Sqrt(this.ee.fpr[0].f))); - - // @0011B8BC BC1F $0011ba50 - if (!ee.fcr31_23) pc = 0x0011ba50; - - // @0011B8CC NEG.S $f12, $f20 - ee.fpr[12].f = -ee.fpr[20].f; - // @0011B8CC NEG.S $f12, $f20 - this.ee.fpr[12].f = (0 - this.ee.fpr[20].f); - - // @0011B8FC SUB.S $f12, $f1, $f12 - ee.fpr[12].f = ee.fpr[1].f - ee.fpr[12].f; - // @0011B8FC SUB.S $f12, $f1, $f12 - this.ee.fpr[12].f = (this.ee.fpr[1].f - this.ee.fpr[12].f); - - // @0011B940 ADD.S $f2, $f2, $f3 - ee.fpr[2].f = ee.fpr[2].f + ee.fpr[3].f; - // @0011B940 ADD.S $f2, $f2, $f3 - this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[3].f); - - // @0011B998 LQC2 vf1, $0000(sp) - MobUt.LQC2(ee, ee.VF[1], 0x0000 + ee.sp.UL0); - // @0011B998 LQC2 vf1, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[1], (0 + this.ee.sp.UL0)); - - // @0011B9A0 VMUL.xyz vf1, vf1, vf2 - ee.VF[1].x = ee.VF[1].x * ee.VF[2].x; - ee.VF[1].y = ee.VF[1].y * ee.VF[2].y; - ee.VF[1].z = ee.VF[1].z * ee.VF[2].z; - - // @0011B9A4 VADDy.x vf1, vf1, vf1y - ee.VF[1].x = ee.VF[1].x + ee.VF[1].y; - // @0011B9A4 VADDy.x vf1, vf1, vf1y - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); - - // @0011B9C8 QMFC2 t0, vf1 - MobUt.QMFC2(ee.t0, ee.VF[1]); - // @0011B9AC QMFC2 t0, vf1 - MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); - - // @0011B9D0 C.LE.S $f1, $f0 - ee.fcr31_23 = (ee.fpr[1].f <= ee.fpr[0].f); - // @0011B9D0 C.LE.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f <= this.ee.fpr[0].f); - - // @00124D70 BEQ s3, t7, $00124d98 - if ((this.ee.s3.UD0 == this.ee.t7.UD0)) { - this.pc = 1199512u; - } - - // @00124CAC BEQL t7, t6, $00124cc0 - if ((this.ee.t7.UD0 == this.ee.t6.UD0)) { - this.pc = 1199296u; - // @00124CB0 ADDIU t7, sp, $0050 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 80))); - } - - // @00124B28 SQC2 vf1, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[1], (0 + this.ee.s2.UL0)); - - // @00124B24 VSUB.xyzw vf1, vf1, vf2 - ee.VF[1].x = ee.VF[1].x - ee.VF[2].x; - ee.VF[1].y = ee.VF[1].y - ee.VF[2].y; - ee.VF[1].z = ee.VF[1].z - ee.VF[2].z; - ee.VF[1].w = ee.VF[1].w - ee.VF[2].w; - - // @00124B4C VSQRT Q, vf2x - ee.Vq.f = (float)Math.Sqrt(ee.VF[2].x); - // @00124B4C VSQRT Q, vf2x - this.ee.Vq.f = ((float)(System.Math.Sqrt(this.ee.VF[2].x))); - - // @00124B54 CFC2 t0, $vi22 - MobUt.CFC2(ee.t0, ee.VI[22]); - // @00124B54 CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - - // @00124B58 VADDq.x vf2, vf0, Q - ee.VF[2].x = ee.VF[0].x + ee.Vq.f; - // @00124B58 VADDq.x vf2, vf0, Q - this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); - - // @00124B64 VDIV Q, vf0w, vf2x - ee.Vq.f = ee.VF[0].w / ee.VF[2].x; - // @00124B64 VDIV Q, vf0w, vf2x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); - - // @00124B6C VMULq.xyz vf1, vf1, Q - ee.VF[1].x = ee.VF[1].x * ee.Vq.f; - ee.VF[1].y = ee.VF[1].y * ee.Vq.f; - ee.VF[1].z = ee.VF[1].z * ee.Vq.f; - // @00124B6C VMULq.xyz vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - - // @00124D20 VMULAx.xyzw ACC, vf1, vf5x - ee.Vacc.x = ee.VF[1].x * ee.VF[5].x; - ee.Vacc.y = ee.VF[1].y * ee.VF[5].x; - ee.Vacc.z = ee.VF[1].z * ee.VF[5].x; - ee.Vacc.w = ee.VF[1].w * ee.VF[5].x; - // @00124D20 VMULAx.xyzw ACC, vf1, vf5x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); - this.ee.Vacc.w = (this.ee.VF[1].w * this.ee.VF[5].x); - - // @00124D24 VMADDAy.xyzw ACC, vf2, vf5y - ee.Vacc.x += ee.VF[2].x * ee.VF[5].y; - ee.Vacc.y += ee.VF[2].y * ee.VF[5].y; - ee.Vacc.z += ee.VF[2].z * ee.VF[5].y; - ee.Vacc.w += ee.VF[2].w * ee.VF[5].y; - // @00124D24 VMADDAy.xyzw ACC, vf2, vf5y - this.ee.Vacc.x = (this.ee.Vacc.x - + (this.ee.VF[2].x * this.ee.VF[5].y)); - this.ee.Vacc.y = (this.ee.Vacc.y - + (this.ee.VF[2].y * this.ee.VF[5].y)); - this.ee.Vacc.z = (this.ee.Vacc.z - + (this.ee.VF[2].z * this.ee.VF[5].y)); - this.ee.Vacc.w = (this.ee.Vacc.w - + (this.ee.VF[2].w * this.ee.VF[5].y)); - - // @00124D2C VMADDw.xyzw vf5, vf4, vf5w - ee.VF[5].x = ee.Vacc.x + ee.VF[4].x * ee.VF[5].w; - ee.VF[5].y = ee.Vacc.y + ee.VF[4].y * ee.VF[5].w; - ee.VF[5].z = ee.Vacc.z + ee.VF[4].z * ee.VF[5].w; - ee.VF[5].w = ee.Vacc.w + ee.VF[4].w * ee.VF[5].w; - // @00124D2C VMADDw.xyzw vf5, vf4, vf5w - this.ee.VF[5].x = (this.ee.Vacc.x - + (this.ee.VF[4].x * this.ee.VF[5].w)); - this.ee.VF[5].y = (this.ee.Vacc.y - + (this.ee.VF[4].y * this.ee.VF[5].w)); - this.ee.VF[5].z = (this.ee.Vacc.z - + (this.ee.VF[4].z * this.ee.VF[5].w)); - this.ee.VF[5].w = (this.ee.Vacc.w - + (this.ee.VF[4].w * this.ee.VF[5].w)); - - // @00124D98 BNEL s1, zero, $00124e04 - if ((this.ee.s1.UD0 != this.ee.r0.UD0)) { - this.pc = 1199620u; - // @00124D9C ADD.S $f0, $f23, $f23 - this.ee.fpr[0].f = (this.ee.fpr[23].f + this.ee.fpr[23].f); - } - - // @00124E10 MSUBA.S $f23, $f23 - ee.fpracc.f = ee.fpracc.f - ee.fpr[23].f * ee.fpr[23].f; - // @00124E10 MSUBA.S $f23, $f23 - this.ee.fpracc.f = (this.ee.fpracc.f - - (this.ee.fpr[23].f * this.ee.fpr[23].f)); - - // @00124E14 MSUB.S $f1, $f22, $f22 - ee.fpr[1].f = ee.fpracc.f - ee.fpr[22].f * ee.fpr[22].f; - // @00124E14 MSUB.S $f1, $f22, $f22 - this.ee.fpr[1].f = (this.ee.fpracc.f - - (this.ee.fpr[22].f * this.ee.fpr[22].f)); - - // @00124E18 MUL.S $f0, $f0, $f22 - this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[22].f); - - // @00124E28 DIV.S $f21, $f1, $f0 - this.ee.fpr[21].f = (this.ee.fpr[1].f / this.ee.fpr[0].f); - - // @00124E78 SW zero, $0008(s1) - MobUt.SW(ee, ee.r0, 0x0008 + ee.s1.UL0); - // @00124E78 SW zero, $0008(s1) - MobUt.SW(this.ee, this.ee.r0, (8 + this.ee.s1.UL0)); - - // @00125144 VOPMULA.xyz ACC, vf1, vf2 - ee.Vacc.x = ee.VF[1].y * ee.VF[2].z; - ee.Vacc.y = ee.VF[1].z * ee.VF[2].x; - ee.Vacc.z = ee.VF[1].x * ee.VF[2].y; - // @00125144 VOPMULA.xyz ACC, vf1, vf2 - this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); - this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); - this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); - - // @00125148 VOPMSUB.xyz vf3xyz, vf2, vf1 - ee.VF[3].x = ee.Vacc.x - ee.VF[2].y * ee.VF[1].z; - ee.VF[3].y = ee.Vacc.y - ee.VF[2].z * ee.VF[1].x; - ee.VF[3].z = ee.Vacc.z - ee.VF[2].x * ee.VF[1].y; - // @00125148 VOPMSUB.xyz vf3, vf2, vf1 - this.ee.VF[3].x = (this.ee.Vacc.x - - (this.ee.VF[2].y * this.ee.VF[1].z)); - this.ee.VF[3].y = (this.ee.Vacc.y - - (this.ee.VF[2].z * this.ee.VF[1].x)); - this.ee.VF[3].z = (this.ee.Vacc.z - - (this.ee.VF[2].x * this.ee.VF[1].y)); - - // @00127E68 ANDI t7, t6, $0007 - ee.t7.UD0 = ee.t6.US[0] & 0x0007u; - // @00127E68 ANDI t7, t6, $0007 - this.ee.t7.UD0 = ((ushort)((this.ee.t6.US0 & 7))); - - // @00127E78 BNE t7, zero, $00128254 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) { - this.pc = 1213012u; - } - - // @00128020 DSRL t2, t3, 9 - MobUt.DSRL(ee.t2, ee.t3, 9); - // @00128020 DSRL t2, t3, 9 - MobUt.DSRL(this.ee.t2, this.ee.t3, 9); - - // @00128068 SB t6, $0021(sp) - MobUt.SB(this.ee, this.ee.t6, (33 + this.ee.sp.UL0)); - - // @0012809C SLL t7, s0, 1 - MobUt.SLL(this.ee.t7, this.ee.s0, 1); - // @0011B424 ADDIU t7, t7, $4260 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16992))); - - // @0012065C ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - - // @00120670 LW t7, $0004(a0) - MobUt.LW(this.ee, this.ee.t7, (4 + this.ee.a0.UL0)); - - // @001206B4 JALR ra, v0 - ee.ra.UD0 = 0x001206B4 + 8; - pc = ee.v0.UL0; - // @001206B4 JALR ra, v0 - this.ee.ra.UD0 = 1181372u; - this.pc = this.ee.v0.UL0; - - // @00128DA0 LHU a2, $0010(t7) - MobUt.LHU(this.ee, this.ee.a2, (16 + this.ee.t7.UL0)); - - // @00128DA4 SLT t6, t5, a2 - ee.t6.UD0 = Convert.ToByte(ee.t5.SD0 < ee.a2.SD0); - // @00128DA4 SLT t6, t5, a2 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.a2.SD0)); - - // @001280A4 LBU t6, $0020(t5) - MobUt.LBU(this.ee, this.ee.t6, (32 + this.ee.t5.UL0)); - - // @00128104 SLTI t7, s0, $0003 - ee.t7.UD0 = Convert.ToByte(ee.s0.SD0 < 3); - - // @00128EA4 SLTIU t7, t6, $002c - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 44ul)); - - // @00129BA8 ORI t7, t7, $ffff - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 | 65535))); - - // @00129BB4 AND s4, s4, t7 - this.ee.s4.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - - // @00300400 MFC1 t3, $f12 - MobUt.MFC1(ee.t3, ee.fpr[12]); - - // @00145134 MFC1 t7, $f0 - MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); - - // @00142018 SH s2, $0000(t6) - MobUt.SH(this.ee, this.ee.s2, (0 + this.ee.t6.UL0)); - - // @00128154 LBU t7, $ffff(s6) - MobUt.LBU(this.ee, this.ee.t7, (4294967295u + this.ee.s6.UL0)); - - // @002FAA3C ADDI a3, a3, $ffff - this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); - - // @002FA950 VMULx.yzw vf4, vf4, vf0x - this.ee.VF[4].y = (this.ee.VF[4].y * this.ee.VF[0].x); - this.ee.VF[4].z = (this.ee.VF[4].z * this.ee.VF[0].x); - this.ee.VF[4].w = (this.ee.VF[4].w * this.ee.VF[0].x); - - // @0016274C VADD.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y + this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z + this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w + this.ee.VF[2].w); - - // @00145848 LH t7, $000a(a1) - MobUt.LH(this.ee, this.ee.t7, (10u + this.ee.a1.UL0)); - - // @00162770 SLTU v0, zero, v0 - this.ee.v0.UD0 = System.Convert.ToByte((this.ee.r0.UD0 < this.ee.v0.UD0)); - - // @001420CC XOR t7, t7, t6 - MobUt.XOR(this.ee.t7, this.ee.t7, this.ee.t6); - - // @0012D4F4 SUBU t7, s2, t4 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); - - // @00141FE8 MULT t7, t6, t5 - this.ee.t7.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.t5.SL0))); - - // @0012D2C8 BLTZ t7, $0012d33c - if ((this.ee.t7.SD0 < 0)) { - this.pc = 1233724u; - } - - // @0012C808 BGEZ t4, $0012c860 - if ((this.ee.t4.SD0 >= 0)) { - this.pc = 1230944u; - } - - // @0012C984 BGEZL t7, $0012c9dc - if ((this.ee.t7.SD0 >= 0)) { - this.pc = 1231324u; - // @0012C988 LW t6, $0004(s0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); - } - - // @0012BD40 PCPYLD t2, t7, t5 - ee.t2.UD1 = ee.t7.UD0; - ee.t2.UD0 = ee.t5.UD0; - - // @0012BD40 PCPYLD t2, t7, t5 - this.ee.t2.UD1 = this.ee.t7.UD0; - this.ee.t2.UD0 = this.ee.t5.UD0; - - // @0012BD3C PCPYUD t1, t4, t6 - this.ee.t1.UD0 = this.ee.t4.UD1; - this.ee.t1.UD1 = this.ee.t6.UD1; - - // @0012BD34 PEXTUW t7, t3, t2 - this.ee.t7.UL[0] = this.ee.t2.UL[2]; - this.ee.t7.UL[1] = this.ee.t3.UL[2]; - this.ee.t7.UL[2] = this.ee.t2.UL[3]; - this.ee.t7.UL[3] = this.ee.t3.UL[3]; - - // @0012AC74 DSRL32 t7, t5, 20 - MobUt.DSRL32(this.ee.t7, this.ee.t5, 20); - - // @0012AC60 DSLL32 t4, t4, 21 - MobUt.DSLL32(this.ee.t4, this.ee.t4, 21); - - // @00162328 BLEZ v0, $00162464 - if ((this.ee.v0.SD0 <= 0)) { - this.pc = 1451108u; - } - - // @00145300 CVT.W.S $f0, $f1 - MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); - - // @00143F44 OR s0, s0, v0 - this.ee.s0.UD0 = (this.ee.s0.UD0 | this.ee.v0.UD0); - - // @0012D3B0 MOVN t5, t6, t7 - if ((this.ee.t7.UD0 != 0)) { - this.ee.t5.UD0 = this.ee.t6.UD0; - } - } - } -#endif -} +//#define UseUnsafe +#define UseBitConverter + +using System; +using System.Collections.Generic; +using System.Text; +using System.Diagnostics; +using System.IO; +using System.Collections; +using System.Runtime.InteropServices; + +namespace OpenKh.Kh2Anim.Mset.EmuRunner +{ + public class UtUB + { + uint[] UL; + bool isR0; + + public UtUB(uint[] UL, bool isR0) + { + this.UL = UL; + this.isR0 = isR0; + } + + public byte this[int x] + { + get + { + switch (x & 3) + { + default: + return (byte)((UL[x >> 2])); + case 1: + return (byte)((UL[x >> 2] >> 8)); + case 2: + return (byte)((UL[x >> 2] >> 16)); + case 3: + return (byte)((UL[x >> 2] >> 24)); + } + } + set + { + if (isR0) + return;// throw new IsR0Exception(); + int v = x >> 2; + switch (x & 3) + { + default: + UL[v] = (UL[v] & 0xFFFFFF00U) | (value); + break; + case 1: + UL[v] = (UL[v] & 0xFFFF00FFU) | (uint)(value << 8); + break; + case 2: + UL[v] = (UL[v] & 0xFF00FFFFU) | (uint)(value << 16); + break; + case 3: + UL[v] = (UL[v] & 0x00FFFFFFU) | (uint)(value << 24); + break; + } + } + } + } + public class UtUS + { + uint[] UL; + bool isR0; + + public UtUS(uint[] UL, bool isR0) + { + this.UL = UL; + this.isR0 = isR0; + } + + public ushort this[int x] + { + get + { + return ((x & 1) == 0) ? ((ushort)(UL[x >> 1])) : ((ushort)(UL[x >> 1] >> 16)); + } + set + { + if (isR0) + return;// throw new IsR0Exception(); + if ((x & 1) == 0) + { + x >>= 1; + UL[x] = (UL[x] & 0xFFFF0000) | (uint)(value); + } + else + { + x >>= 1; + UL[x] = (UL[x] & 0x0000FFFF) | (uint)(value << 16); + } + } + } + } + public class UtUD + { + uint[] UL; + bool isR0; + + public UtUD(uint[] UL, bool isR0) + { + this.UL = UL; + this.isR0 = isR0; + } + + public ulong this[int x] + { + get + { + x <<= 1; + return UL[x] | ((ulong)UL[x + 1] << 32); + } + set + { + if (isR0) + return;// throw new IsR0Exception(); + x <<= 1; + UL[x] = (uint)(value); + UL[x + 1] = (uint)(value >> 32); + } + } + } + public class UtSD + { + uint[] UL; + bool isR0; + + public UtSD(uint[] UL, bool isR0) + { + this.UL = UL; + this.isR0 = isR0; + } + + public long this[int x] + { + get + { + x <<= 1; + return (long)(UL[x] | ((ulong)UL[x + 1] << 32)); + } + set + { + if (isR0) + return;// throw new IsR0Exception(); + x <<= 1; + UL[x] = (uint)(value); + UL[x + 1] = (uint)(value >> 32); + } + } + } + public class UtSL + { + uint[] UL; + bool isR0; + + public UtSL(uint[] UL, bool isR0) + { + this.UL = UL; + this.isR0 = isR0; + } + + public int this[int x] + { + get + { + return (int)UL[x]; + } + set + { + if (isR0) + return;// throw new IsR0Exception(); + UL[x] = (uint)value; + } + } + } + + public class GPR + { + public readonly uint[] UL = new uint[] { 0, 0, 0, 0 }; + public readonly UtUB UB; + public readonly UtUS US; + public readonly UtSL SL; + public readonly UtUD UD; + public readonly UtSD SD; + + // --> SByte + public byte UB0 { get { return UB[0]; } set { UB[0] = value; } } // --> Byte + public ushort US0 { get { return US[0]; } set { US[0] = value; } } // --> Int16 + // --> UInt16 + public int SL0 { get { return SL[0]; } set { SL[0] = value; } } // --> Int32 + public uint UL0 { get { return UL[0]; } set { UL[0] = value; } } // --> UInt32 + public long SD0 { get { return SD[0]; } set { SD[0] = value; } } // --> Int64 + public ulong UD0 { get { return UD[0]; } set { UD[0] = value; } } // --> UInt64 + + public ulong UD1 { get { return UD[1]; } set { UD[1] = value; } } + + public GPR(bool isR0) + { + UB = new UtUB(UL, isR0); + US = new UtUS(UL, isR0); + SL = new UtSL(UL, isR0); + UD = new UtUD(UL, isR0); + SD = new UtSD(UL, isR0); + } + + public override string ToString() + { + return string.Format("{0:x8}_{1:x8}_{2:x8}_{3:x8}", UL[3], UL[2], UL[1], UL[0]); + } + } + public class FPR + { + public float f = 0; + + public uint UL + { + get { return MobUt.F2UL(f); } + set { f = MobUt.UL2F(value); } + } + } + public class Vec : IComparable + { + public Vec(bool isVF0) + { + this.isVF0 = isVF0; + } + public bool isVF0; + public float[] F = new float[] { 0, 0, 0, 1 }; + public float x { get { return F[0]; } set { F[0] = value; } } + public float y { get { return F[1]; } set { F[1] = value; } } + public float z { get { return F[2]; } set { F[2] = value; } } + public float w { get { return F[3]; } set { F[3] = value; } } + + public override string ToString() + { + return string.Format("{0} | {1} | {2} | {3}", F[0], F[1], F[2], F[3]); + } + + #region IComparable メンバ + + public int CompareTo(Vec o) + { + int t; + if (0 != (t = x.CompareTo(o.x))) + return t; + if (0 != (t = y.CompareTo(o.y))) + return t; + if (0 != (t = z.CompareTo(o.z))) + return t; + if (0 != (t = w.CompareTo(o.w))) + return t; + return 0; + } + + #endregion + } + public class VIv + { + public UInt32 UL = 0; + + public float f + { + get { return MobUt.UL2F(UL); } + set { UL = MobUt.F2UL(value); } + } + } + public class CustEE + { + public GPR r0 = new GPR(true); + public GPR at = new GPR(false); + public GPR v0 = new GPR(false); + public GPR v1 = new GPR(false); + public GPR a0 = new GPR(false); + public GPR a1 = new GPR(false); + public GPR a2 = new GPR(false); + public GPR a3 = new GPR(false); + public GPR t0 = new GPR(false); + public GPR t1 = new GPR(false); + public GPR t2 = new GPR(false); + public GPR t3 = new GPR(false); + public GPR t4 = new GPR(false); + public GPR t5 = new GPR(false); + public GPR t6 = new GPR(false); + public GPR t7 = new GPR(false); + public GPR s0 = new GPR(false); + public GPR s1 = new GPR(false); + public GPR s2 = new GPR(false); + public GPR s3 = new GPR(false); + public GPR s4 = new GPR(false); + public GPR s5 = new GPR(false); + public GPR s6 = new GPR(false); + public GPR s7 = new GPR(false); + public GPR t8 = new GPR(false); + public GPR t9 = new GPR(false); + public GPR k0 = new GPR(false); + public GPR k1 = new GPR(false); + public GPR gp = new GPR(false); + public GPR sp = new GPR(false); + public GPR s8 = new GPR(false); + public GPR ra = new GPR(false); + + public GPR zero = new GPR(true); + + public GPR[] GPR + { + get + { + return new GPR[] { + r0, at, v0, v1, a0, a1, a2, a3, t0, t1, t2, t3, t4, t5, t6, t7, + s0, s1, s2, s3, s4, s5, s6, s7, t8, t9, k0, k1, gp, sp, s8, ra, + }; + } + } + + public Int64 LO = 0, HI = 0; + + // EE + public byte[] ram = new byte[1024 * 1024 * 32]; + public byte[] spr = new byte[16384]; + // COP1, FPU + public FPR[] fpr = new FPR[] { new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), new FPR(), }; + public uint[] fprc = new uint[32]; + public FPR fpracc = new FPR(); + // COP2, VU0 + public Vec[] VF = new Vec[] { new Vec(true), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), new Vec(false), }; + public Vec Vacc = new Vec(false); + public VIv[] VI = new VIv[] { new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), new VIv(), }; + public VIv Vq; + public VIv Vp; + public VIv Vr; + public VIv Vi; + public VIv Vcf; + + uint fcr31 = 0; + + public bool fcr31_23 { get { return 0 != (fcr31 & 0x800000); } set { fcr31 = (fcr31 & (~0x800000U)) | (value ? 0x800000U : 0U); } } + + public uint pc = 0; + + public Func hwRead8 = delegate (uint mem) { throw new AccessUnpreparedMemoryException(mem); }; + public Func hwRead16 = delegate (uint mem) { throw new AccessUnpreparedMemoryException(mem); }; + public Func hwRead32 = delegate (uint mem) { throw new AccessUnpreparedMemoryException(mem); }; + public Func hwRead64 = delegate (uint mem) { throw new AccessUnpreparedMemoryException(mem); }; + + public Action hwWrite8 = delegate (uint mem, byte v) { throw new AccessUnpreparedMemoryException(mem); }; + public Action hwWrite16 = delegate (uint mem, ushort v) { throw new AccessUnpreparedMemoryException(mem); }; + public Action hwWrite32 = delegate (uint mem, uint v) { throw new AccessUnpreparedMemoryException(mem); }; + public Action hwWrite64 = delegate (uint mem, ulong v) { throw new AccessUnpreparedMemoryException(mem); }; + + public CustEE() + { + this.Vcf = VI[18]; + this.Vr = VI[20]; + this.Vi = VI[21]; + this.Vq = VI[22]; + this.Vp = VI[23]; + + ram2 = new BinaryWriter(ram1 = new MemoryStream(ram, true)); + spr2 = new BinaryWriter(spr1 = new MemoryStream(spr, true)); + } + + BinaryWriter ram2, spr2; + MemoryStream ram1, spr1; + + public void eeWrite64(uint off, ulong val) + { + if (false) + { } + else if ((off & 0xF0000000U) == 0x70000000U) + { + spr1.Position = off & 0x3FFF; + spr2.Write(val); + return; + } + else if ((off & 0xF0000000U) == 0x10000000U) + { + hwWrite64(off, val); + return; + } + else if ((off & 0xF0000000U) == 0x00000000U) + { + ram1.Position = off; + ram2.Write(val); + return; + } + + throw new AccessUnpreparedMemoryException(off); + } + public void eeWriteSingle(uint off, float val) + { + if (false) + { } + else if ((off & 0xF0000000U) == 0x70000000U) + { + spr1.Position = off & 0x3FFF; + spr2.Write(val); + return; + } + else if ((off & 0xF0000000U) == 0x10000000U) + { + ; + } + else if ((off & 0xF0000000U) == 0x00000000U) + { + ram1.Position = off; + ram2.Write(val); + return; + } + + throw new AccessUnpreparedMemoryException(off); + } + public void eeWrite32(uint off, uint val) + { + if (false) + { } + else if ((off & 0xF0000000U) == 0x70000000U) + { + spr1.Position = off & 0x3FFF; + spr2.Write(val); + return; + } + else if ((off & 0xF0000000U) == 0x10000000U) + { + hwWrite32(off, val); + return; + } + else if ((off & 0xF0000000U) == 0x00000000U) + { + ram1.Position = off; + ram2.Write(val); + return; + } + + throw new AccessUnpreparedMemoryException(off); + } + public void eeWrite16(uint off, ushort val) + { + if (false) + { } + else if ((off & 0xF0000000U) == 0x70000000U) + { + spr1.Position = off & 0x3FFF; + spr2.Write(val); + return; + } + else if ((off & 0xF0000000U) == 0x10000000U) + { + hwWrite16(off, val); + return; + } + else if ((off & 0xF0000000U) == 0x00000000U) + { + ram1.Position = off; + ram2.Write(val); + return; + } + + throw new AccessUnpreparedMemoryException(off); + } + public void eeWrite8(uint off, byte val) + { + if (false) + { } + else if ((off & 0xF0000000U) == 0x70000000U) + { + spr[off & 0x3FFF] = val; + return; + } + else if ((off & 0xF0000000U) == 0x10000000U) + { + hwWrite8(off, val); + return; + } + else if ((off & 0xF0000000U) == 0x00000000U) + { + ram[off] = val; + return; + } + + throw new AccessUnpreparedMemoryException(off); + } + + + public byte eeRead8(uint off) + { + if (false) + { } + else if ((off & 0xF0000000U) == 0x70000000U) + { + return spr[off & 0x3FFF]; + } + else if ((off & 0xF0000000U) == 0x10000000U) + { + return hwRead8(off); + } + else if ((off & 0xF0000000U) == 0x00000000U) + { + return ram[off]; + } + + throw new AccessUnpreparedMemoryException(off); + } + + public ushort eeRead16(uint off) + { + if (false) + { } + else if ((off & 0xF0000000U) == 0x70000000U) + { + return BitConverter.ToUInt16(spr, (int)off & 0x3FFF); + } + else if ((off & 0xF0000000U) == 0x10000000U) + { + return hwRead16(off); + } + else if ((off & 0xF0000000U) == 0x00000000U) + { + return BitConverter.ToUInt16(ram, (int)off); + } + + throw new AccessUnpreparedMemoryException(off); + } + + public uint eeRead32(uint off) + { + if (false) + { } + else if ((off & 0xF0000000U) == 0x70000000U) + { + return BitConverter.ToUInt32(spr, (int)off & 0x3FFF); + } + else if ((off & 0xF0000000U) == 0x10000000U) + { + return hwRead32(off); + } + else if ((off & 0xF0000000U) == 0x00000000U) + { + return BitConverter.ToUInt32(ram, (int)off); + } + + throw new AccessUnpreparedMemoryException(off); + } + + public ulong eeRead64(uint off) + { + if (false) + { } + else if ((off & 0xF0000000U) == 0x70000000U) + { + return BitConverter.ToUInt64(spr, (int)off & 0x3FFF); + } + else if ((off & 0xF0000000U) == 0x10000000U) + { + return hwRead64(off); + } + else if ((off & 0xF0000000U) == 0x00000000U) + { + return BitConverter.ToUInt64(ram, (int)off); + } + + throw new AccessUnpreparedMemoryException(off); + } + + public float eeReadSingle(uint off) + { + if (false) + { } + else if ((off & 0xF0000000U) == 0x70000000U) + { + return BitConverter.ToSingle(spr, (int)off & 0x3FFF); + } + else if ((off & 0xF0000000U) == 0x10000000U) + { + ; + } + else if ((off & 0xF0000000U) == 0x00000000U) + { + return BitConverter.ToSingle(ram, (int)off); + } + + throw new AccessUnpreparedMemoryException(off); + } + } + + public delegate TResult Func(); + public delegate TResult Func(T x); + + public delegate void Action(T1 x, T2 y); + + public class MobUt + { + public static BitArray bita = new BitArray(2097152, false); + public static BitArray bitr = new BitArray(2097152, false); + + public delegate void Tx8(); + + public static void LQ(CustEE ee, GPR rt, uint off) + { + //#Debug.Assert(off <= 32U * 1024 * 1024, "Avail only within 32MB ram"); + sysr((int)(off >> 4)); + rt.UL[0] = ee.eeRead32(off + 0); + rt.UL[1] = ee.eeRead32(off + 4); + rt.UL[2] = ee.eeRead32(off + 8); + rt.UL[3] = ee.eeRead32(off + 12); + } + public static void SQ(CustEE ee, GPR rt, uint off) + { + sysw((int)(off >> 4)); + ee.eeWrite32(off + 0, rt.UL[0]); + ee.eeWrite32(off + 4, rt.UL[1]); + ee.eeWrite32(off + 8, rt.UL[2]); + ee.eeWrite32(off + 12, rt.UL[3]); + } + public static void VCLIP(CustEE ee, Vec ft, Vec fs) + { + uint Vcf = 0; + float pw = +Math.Abs(MobUt.vuDouble(ft.w)); + float nw = -pw; + if (MobUt.vuDouble(fs.x) > pw) + Vcf |= 0x01; + if (MobUt.vuDouble(fs.x) < nw) + Vcf |= 0x02; + if (MobUt.vuDouble(fs.y) > pw) + Vcf |= 0x04; + if (MobUt.vuDouble(fs.y) < nw) + Vcf |= 0x08; + if (MobUt.vuDouble(fs.z) > pw) + Vcf |= 0x10; + if (MobUt.vuDouble(fs.z) < nw) + Vcf |= 0x20; + ee.Vcf.UL = ((ee.Vcf.UL << 6) | Vcf) & 0xFFFFFFu; + } + public static float UL2F(uint val) + { +#if UseBitConverter + return BitConverter.ToSingle(BitConverter.GetBytes(val), 0); +#elif UseUnsafe + unsafe + { + return *(float*)&val; + } +#else + MemoryStream os = new MemoryStream(new byte[] { 0, 0, 0, 0 }); + new BinaryWriter(os).Write(val); + os.Position = 0; + float r = new BinaryReader(os).ReadSingle(); + //Debug.Assert(!float.IsNaN(r)); + //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); + return r; +#endif + } + public static uint F2UL(float val) + { +#if UseBitConverter + return BitConverter.ToUInt32(BitConverter.GetBytes(val), 0); +#elif UseUnsafe + unsafe + { + return *(uint*)&val; + } +#else + MemoryStream os = new MemoryStream(new byte[] { 0, 0, 0, 0 }); + //Debug.Assert(!float.IsNaN(val)); + //Debug.Assert(!float.IsNegativeInfinity(val) && !float.IsPositiveInfinity(val)); + new BinaryWriter(os).Write(val); + os.Position = 0; + uint r = new BinaryReader(os).ReadUInt32(); + return r; +#endif + } + + public static void SD(CustEE ee, GPR rt, uint off) + { + sysw((int)(off >> 4)); + ee.eeWrite64(off, rt.UD0); + } + + public static void LD(CustEE ee, GPR rt, uint off) + { + sysr((int)(off >> 4)); + rt.UD0 = ee.eeRead64(off); + } + + public static void LWC1(CustEE ee, FPR ft, uint off) + { + //#Debug.Assert(off <= 32U * 1024 * 1024, "Avail only within 32MB ram"); + sysr((int)(off >> 4)); + float r = ee.eeReadSingle(off); + //Debug.Assert(!float.IsNaN(r)); + //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); + ft.f = r; + } + + public static void SWC1(CustEE ee, FPR ft, uint off) + { + //#Debug.Assert(off <= 32U * 1024 * 1024, "Avail only within 32MB ram"); + sysw((int)(off >> 4)); + ee.eeWriteSingle(off, ft.f); + } + + public static void LQC2(CustEE ee, Vec VF, uint off) + { + //#Debug.Assert(off <= 32U * 1024 * 1024 && off + 16U <= 32U * 1024 * 1024, "Avail only within 32MB ram"); + sysr((int)(off >> 4)); + if (true) + { + float r = ee.eeReadSingle(off + 0U); + //Debug.Assert(!float.IsNaN(r)); + //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); + if (VF != ee.VF[0]) + VF.x = r; + } + if (true) + { + float r = ee.eeReadSingle(off + 4U); + //Debug.Assert(!float.IsNaN(r)); + //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); + if (VF != ee.VF[0]) + VF.y = r; + } + if (true) + { + float r = ee.eeReadSingle(off + 8U); + //Debug.Assert(!float.IsNaN(r)); + //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); + if (VF != ee.VF[0]) + VF.z = r; + } + if (true) + { + float r = ee.eeReadSingle(off + 12U); + //Debug.Assert(!float.IsNaN(r)); + //Debug.Assert(!float.IsNegativeInfinity(r) && !float.IsPositiveInfinity(r)); + if (VF != ee.VF[0]) + VF.w = r; + } + } + + public static void QMFC2(GPR rt, Vec vf) + { +#if UseBitConverter + rt.UL[0] = BitConverter.ToUInt32(BitConverter.GetBytes(vf.x), 0); + rt.UL[1] = BitConverter.ToUInt32(BitConverter.GetBytes(vf.y), 0); + rt.UL[2] = BitConverter.ToUInt32(BitConverter.GetBytes(vf.z), 0); + rt.UL[3] = BitConverter.ToUInt32(BitConverter.GetBytes(vf.w), 0); +#elif UseUnsafe + unsafe + { + float f; + f = vf.x; rt.UL[0] = *(uint*)&f; + f = vf.y; rt.UL[1] = *(uint*)&f; + f = vf.z; rt.UL[2] = *(uint*)&f; + f = vf.w; rt.UL[3] = *(uint*)&f; + } +#else + if (rt.isR0) return; + MemoryStream os = new MemoryStream(16); + BinaryWriter wr = new BinaryWriter(os); + wr.Write(vf.x); + wr.Write(vf.y); + wr.Write(vf.z); + wr.Write(vf.w); + os.Position = 0; + BinaryReader br = new BinaryReader(os); + rt.UL[0] = br.ReadUInt32(); + rt.UL[1] = br.ReadUInt32(); + rt.UL[2] = br.ReadUInt32(); + rt.UL[3] = br.ReadUInt32(); +#endif + } + + public static void SQC2(CustEE ee, Vec VF, uint off) + { + sysw((int)(off >> 4)); + ee.eeWriteSingle(off + 0, VF.x); + ee.eeWriteSingle(off + 4, VF.y); + ee.eeWriteSingle(off + 8, VF.z); + ee.eeWriteSingle(off + 12, VF.w); + } + + public static void CFC2(GPR rt, VIv id) + { + rt.UD0 = id.UL; + } + + public static void Latency() { } + + public static void SW(CustEE ee, GPR rt, uint off) + { + sysw((int)(off >> 4)); + ee.eeWrite32(off, rt.UL0); + } + + public static void DSRL(GPR rd, GPR rt, int sa) + { + rd.UD0 = rt.UD0 >> sa; + } + + public static void DSRLV(GPR rd, GPR rt, GPR rs) + { + rd.UD0 = rt.UD0 >> rs.UB0; + } + + public static void SB(CustEE ee, GPR rt, uint off) + { + sysw((int)(off >> 4)); + ee.eeWrite8(off, rt.UB0); + } + + public static void SLL(GPR rd, GPR rt, int sa) + { + rd.SD0 = (int)(rt.UL0 << sa); + } + + public static void LW(CustEE ee, GPR rt, uint off) + { + sysr((int)(off >> 4)); + rt.SD0 = (int)ee.eeRead32(off); + } + + public static void LWU(CustEE ee, GPR rt, uint off) + { + sysr((int)(off >> 4)); + rt.UD0 = ee.eeRead32(off); + } + + public static void LHU(CustEE ee, GPR rt, uint off) + { + sysr((int)(off >> 4)); + rt.UD0 = ee.eeRead16(off); + } + + public static void LBU(CustEE ee, GPR rt, uint off) + { + sysr((int)(off >> 4)); + rt.UD0 = ee.eeRead8(off); + } + + public static void MFC1(GPR rt, FPR fs) + { + MemoryStream os = new MemoryStream(new byte[] { 0, 0, 0, 0 }); + new BinaryWriter(os).Write(fs.f); + os.Position = 0; + rt.SD0 = new BinaryReader(os).ReadInt32(); + } + + public static void SH(CustEE ee, GPR rt, uint off) + { + sysw((int)(off >> 4)); + ee.eeWrite16(off, rt.US0); + } + + private static void sysw(int mark) + { + if (mark >= bita.Count) + return; + bita[mark] = true; + } + private static void sysr(int mark) + { + if (mark >= bita.Count) + return; + if (bita[mark]) + return; + bita[mark] = true; + bitr[mark] = true; + } + + public static void QMTC2(GPR rt, Vec vf) + { +#if UseBitConverter + vf.x = BitConverter.ToSingle(BitConverter.GetBytes(rt.UL[0]), 0); + vf.y = BitConverter.ToSingle(BitConverter.GetBytes(rt.UL[1]), 0); + vf.z = BitConverter.ToSingle(BitConverter.GetBytes(rt.UL[2]), 0); + vf.w = BitConverter.ToSingle(BitConverter.GetBytes(rt.UL[3]), 0); +#elif UseUnsafe + unsafe + { + uint v; + v = rt.UL[0]; vf.x = *(float*)&v; + v = rt.UL[1]; vf.y = *(float*)&v; + v = rt.UL[2]; vf.z = *(float*)&v; + v = rt.UL[3]; vf.w = *(float*)&v; + } +#else + if (vf.isVF0) return; + MemoryStream os = new MemoryStream(16); + BinaryWriter wr = new BinaryWriter(os); + wr.Write(rt.UL[0]); + wr.Write(rt.UL[1]); + wr.Write(rt.UL[2]); + wr.Write(rt.UL[3]); + os.Position = 0; + BinaryReader br = new BinaryReader(os); + vf.x = br.ReadSingle(); + vf.y = br.ReadSingle(); + vf.z = br.ReadSingle(); + vf.w = br.ReadSingle(); +#endif + } + + public static void LH(CustEE ee, GPR rt, uint off) + { + sysr((int)(off >> 4)); + rt.SD0 = (short)ee.eeRead16(off); + } + + public static void XOR(GPR rd, GPR rs, GPR rt) + { + rd.UD0 = rs.UD0 ^ rt.UD0; + } + + public static void DSRL32(GPR rd, GPR rt, int sa) + { + rd.UD0 = rt.UD0 >> (32 + sa); + } + + public static void DSLL32(GPR rd, GPR rt, int sa) + { + rd.UD0 = rt.UD0 << (32 + sa); + } + + public static void CVT_W(FPR fd, FPR fs) + { + uint r = F2UL(fs.f); + if ((r & 0x7F800000U) <= 0x4E800000U) + { + fd.f = UL2F((uint)((int)fs.f)); + } + else if ((r & 0x80000000) != 0) + { + fd.f = UL2F(0x80000000); + } + else + { + fd.f = UL2F(0x7FFFFFFF); + } + } + + public static void SRL(GPR rd, GPR rt, int sa) + { + rd.UD0 = (ulong)((int)(rt.UL0 >> sa)); + } + + public static void SRA(GPR rd, GPR rt, int sa) + { + rd.SD0 = (int)(rt.SL0 >> sa); + } + + public static float MUL(float v0, float v1) + { + return vuDouble(vuDouble(v0) * vuDouble(v1)); + } + + public static float MADD(float f0, float f1, float f2) + { + return vuDouble(vuDouble(f0) + (float)(vuDouble(f1) * vuDouble(f2))); + } + + public static float OPMSUB(float f0, float f1, float f2) + { + return vuDouble(f0) - (float)(vuDouble(f1) * vuDouble(f2)); + } + + public static float vuDouble(float v) + { +#if UseUnsafe + unsafe + { + uint f = *(uint*)&v; + switch (f & 0x7F800000) + { + case 0x0: + f &= 0x80000000; + return *(float*)&f; + case 0x7F800000: + f = ((f & 0x80000000) | 0x7F7FFFFF); + return *(float*)&f; + default: + return v; + } + } +#else + uint f = F2UL(v); + switch (f & 0x7F800000) + { + case 0x0: + f &= 0x80000000; + return UL2F(f); + case 0x7F800000: + return UL2F((f & 0x80000000) | 0x7F7FFFFF); + default: + return UL2F(f); + } +#endif + } + + public static float MSUB(float f0, float f1, float f2) + { + return vuDouble(vuDouble(f0) - (float)(vuDouble(f1) * vuDouble(f2))); + } + + public static void SLLV(GPR rd, GPR rt, GPR rs) + { + rd.SD0 = (int)(rt.SD0 << (rs.UB0 & 15)); + } + + public static void CVT_S(FPR fd, FPR fs) + { + fd.f = (int)fs.UL; + } + + public static void LB(CustEE ee, GPR rt, uint off) + { + sysr((int)(off >> 4)); + rt.SD0 = (sbyte)ee.eeRead8(off); + } + + [DllImport("MySSE.dll", CallingConvention = CallingConvention.StdCall)] + static extern void MySSE_VMx16(float[] param); + + public static void VMx16(Vec vacc, + Vec vec1, float v1f, + Vec vec2, float v2f, + Vec vec3, float v3f, + Vec vec4, float v4f, + Vec veco + ) + { +#if UseUnsafe && false + unsafe { + float[] param = new float[] { + vec1.F[0], vec1.F[1], vec1.F[2], vec1.F[3], + vec2.F[0], vec2.F[1], vec2.F[2], vec2.F[3], + vec3.F[0], vec3.F[1], vec3.F[2], vec3.F[3], + vec4.F[0], vec4.F[1], vec4.F[2], vec4.F[3], + v1f, v1f, v1f, v1f, + v2f, v2f, v2f, v2f, + v3f, v3f, v3f, v3f, + v4f, v4f, v4f, v4f, + }; + + MySSE_VMx16(param); + + veco.x = param[0]; + veco.y = param[1]; + veco.z = param[2]; + veco.w = param[3]; + } +#else + veco.F[0] = vuDouble((vacc.F[0] = vuDouble((vec1.F[0] * v1f) + (vec2.F[0] * v2f) + (vec3.F[0] * v3f))) + (vec4.F[0] * v4f)); + veco.F[1] = vuDouble((vacc.F[1] = vuDouble((vec1.F[1] * v1f) + (vec2.F[1] * v2f) + (vec3.F[1] * v3f))) + (vec4.F[1] * v4f)); + veco.F[2] = vuDouble((vacc.F[2] = vuDouble((vec1.F[2] * v1f) + (vec2.F[2] * v2f) + (vec3.F[2] * v3f))) + (vec4.F[2] * v4f)); + veco.F[3] = vuDouble((vacc.F[3] = vuDouble((vec1.F[3] * v1f) + (vec2.F[3] * v2f) + (vec3.F[3] * v3f))) + (vec4.F[3] * v4f)); +#endif + } + + public static void DSLLV(GPR rd, GPR rt, GPR rs) + { + rd.UD0 = (ulong)(rt.UD0 << (rs.UB0 & 63)); + } + + public static void POR(GPR rd, GPR rt, GPR rs) + { + rd.UD0 = rs.UD0 | rt.UD0; + rd.UD1 = rs.UD1 | rt.UD1; + } + + public static void PAND(GPR rd, GPR rt, GPR rs) + { + rd.UD0 = rs.UD0 & rt.UD0; + rd.UD1 = rs.UD1 & rt.UD1; + } + + public static void ADD(GPR rd, GPR rt, GPR rs) + { + rd.SD0 = (rs.SL0 + rt.SL0); + } + + public static void DSLL(GPR rd, GPR rt, int sa) + { + rd.UD0 = (ulong)(rt.UD0 << (sa & 63)); + } + + public static void DSRA(GPR rd, GPR rt, int sa) + { + rd.SD0 = (long)(rt.SD0 >> sa); + } + + public static void DSRA32(GPR rd, GPR rt, int sa) + { + rd.SD0 = (long)(rt.SD0 >> (32 + sa)); + } + + public static void SYSCALL(int code) + { + // http://gamehacking.org/?s=faqs&id=90 + Debug.WriteLine(String.Format("#SYSCALL {0:x}", code)); + } + + public static void PEXTLW(GPR rd, GPR rs, GPR rt) + { + uint[] res = { + rt.UL[0], + rs.UL[0], + rt.UL[1], + rs.UL[1], + }; + for (int x = 0; x < 4; x++) + rd.UL[x] = res[x]; + } + + public static void PEXTLH(GPR rd, GPR rs, GPR rt) + { + ushort[] res = { + rt.US[0], + rs.US[0], + rt.US[1], + rs.US[1], + rt.US[2], + rs.US[2], + rt.US[3], + rs.US[3], + }; + for (int x = 0; x < 8; x++) + rd.US[x] = res[x]; + } + + public static void PEXTLB(GPR rd, GPR rs, GPR rt) + { + byte[] res ={ + rt.UB[0], + rs.UB[0], + rt.UB[1], + rs.UB[1], + rt.UB[2], + rs.UB[2], + rt.UB[3], + rs.UB[3], + rt.UB[4], + rs.UB[4], + rt.UB[5], + rs.UB[5], + rt.UB[6], + rs.UB[6], + rt.UB[7], + rs.UB[7], + }; + for (int x = 0; x < 16; x++) + rd.UB[x] = res[x]; + } + + public static void MULTU(CustEE ee, GPR rs, GPR rt) + { + Int64 r = (Int64)rs.UL0 * rt.UL0; + ee.LO = (int)(r); + ee.HI = (int)(r >> 32); + } + public static void MULT(CustEE ee, GPR rd, GPR rs, GPR rt) + { + Int64 r = (Int64)rs.SL0 * rt.SL0; + ee.LO = (int)(r); + ee.HI = (int)(r >> 32); + rd.SD0 = r; + } + + public static void MFC0(CustEE ee, GPR rt, int rd) + { + //fake + rt.UD0 = 0; + } + + public static void MOVZ(GPR rd, GPR rs, GPR rt) + { + if (rt.UD0 == 0) + rd.UD0 = rs.UD0; + } + + public static void PCPYH(GPR rd, GPR rt) + { + UInt64 v0 = rt.US[0]; + UInt64 v1 = rt.US[4]; + rd.UD0 = v0 | (v0 << 16) | (v0 << 32) | (v0 << 48); + rd.UD1 = v1 | (v1 << 16) | (v1 << 32) | (v1 << 48); + } + + public static void VRXOR(CustEE ee, float fs) + { + ee.Vr.UL = ee.Vr.UL ^ (F2UL(fs) & 0x7FFFFF); + } + + public static float VRNEXT(CustEE ee, bool next) + { + if (next) + { + ee.Vr.f = new Random((int)ee.Vr.UL).Next(1, 20000) / 10000.0f; + } + return ee.Vr.f; + } + + public static void PADDW(GPR rd, GPR rs, GPR rt) + { + for (int x = 0; x < 4; x++) + rd.UL[x] = rs.UL[x] + rt.UL[x]; + } + + public static float MINI(float x, float y) + { + return Math.Min(x, y); + } + + public static float MAX(float x, float y) + { + return Math.Max(x, y); + } + + public static void PROT3W(GPR rd, GPR rt) + { + uint[] res = { + rt.UL[1], + rt.UL[2], + rt.UL[0], + rt.UL[3], + }; + for (int x = 0; x < 4; x++) + rd.UL[x] = res[x]; + } + + public static void PPACW(GPR rd, GPR rs, GPR rt) + { + uint[] res = { + rt.UL[0], + rt.UL[2], + rs.UL[0], + rs.UL[2], + }; + for (int x = 0; x < 4; x++) + rd.UL[x] = res[x]; + } + + public static void PEXTUW(GPR rd, GPR rs, GPR rt) + { + uint[] res = { + rt.UL[2], + rs.UL[2], + rt.UL[3], + rs.UL[3], + }; + for (int x = 0; x < 4; x++) + rd.UL[x] = res[x]; + } + + public static void PPACB(GPR rd, GPR rs, GPR rt) + { + byte[] res = { + rt.UB[0], + rt.UB[2], + rt.UB[4], + rt.UB[6], + rt.UB[8], + rt.UB[10], + rt.UB[12], + rt.UB[14], + rs.UB[0], + rs.UB[2], + rs.UB[4], + rs.UB[6], + rs.UB[8], + rs.UB[10], + rs.UB[12], + rs.UB[14], + }; + for (int x = 0; x < 16; x++) + rd.UB[x] = res[x]; + } + public static void PPACH(GPR rd, GPR rs, GPR rt) + { + ushort[] res = { + rt.US[0], + rt.US[2], + rt.US[4], + rt.US[6], + rs.US[0], + rs.US[2], + rs.US[4], + rs.US[6], + }; + for (int x = 0; x < 8; x++) + rd.US[x] = res[x]; + } + + public static void PCPYLD(GPR rd, GPR rs, GPR rt) + { + UInt64 v0 = rt.UD0; + UInt64 v1 = rs.UD0; + rd.UD0 = v0; + rd.UD1 = v1; + } + public static void PCPYUD(GPR rd, GPR rs, GPR rt) + { + UInt64 v0 = rs.UD1; + UInt64 v1 = rt.UD1; + rd.UD0 = v0; + rd.UD1 = v1; + } + + public static void XORI(GPR rt, GPR rs, uint imm) + { + rt.UL0 = rs.UL0 ^ imm; + } + + public static void CTC2(GPR rt, VIv id) + { + id.UL = rt.UL0; + } + + public static void PSRLW(GPR rd, GPR rt, int sa) + { + rd.UL[0] = rt.UL[0] >> sa; + rd.UL[1] = rt.UL[1] >> sa; + rd.UL[2] = rt.UL[2] >> sa; + rd.UL[3] = rt.UL[3] >> sa; + } + + // MobUtHere --- + } + +#if false + public class Mobx { + CustEE ee = new CustEE(); + uint pc; + + delegate void Txxxxxxxx(); + SortedList dicti2a = new SortedList(); + + public void Exec() { + dicti2a[0x011B420] = new Txxxxxxxx(_011B420); + + pc = 0x011B420; + while (true) { + (dicti2a[pc])(); + } + } + + public void _011B420() { + ee.t7.US[1] = 0x0035; + ee.t7.SL[0] += (short)0x4260; + MobUt.LQ(ee, ee.t0, 0x0000 + ee.t7.UL[0]); + MobUt.LQ(ee, ee.t1, 0x0010 + ee.t7.UL[0]); + MobUt.LQ(ee, ee.t2, 0x0020 + ee.t7.UL[0]); + MobUt.LQ(ee, ee.t3, 0x0030 + ee.t7.UL[0]); + MobUt.SQ(ee, ee.t0, 0x0000 + ee.t7.UL[0]); + MobUt.SQ(ee, ee.t1, 0x0010 + ee.t7.UL[0]); + MobUt.SQ(ee, ee.t2, 0x0020 + ee.t7.UL[0]); + MobUt.SQ(ee, ee.t3, 0x0030 + ee.t7.UL[0]); + pc = ee.ra.UL[0]; + } + + public void DUMMY() { + // @0011B420 LUI t7, $0035 + this.ee.t7.UD0 = 53 << 16; + + this.ee.t7.SL[0] = (this.ee.t7.SL[0] + 16992); + MobUt.LQ(this.ee, this.ee.t0, (0 + this.ee.t7.UL[0])); + MobUt.LQ(this.ee, this.ee.t1, (16 + this.ee.t7.UL[0])); + MobUt.LQ(this.ee, this.ee.t2, (32 + this.ee.t7.UL[0])); + MobUt.LQ(this.ee, this.ee.t3, (48 + this.ee.t7.UL[0])); + MobUt.LQ(this.ee, this.ee.t0, (0 + this.ee.a0.UL[0])); + MobUt.LQ(this.ee, this.ee.t1, (16 + this.ee.a0.UL[0])); + MobUt.LQ(this.ee, this.ee.t2, (32 + this.ee.a0.UL[0])); + MobUt.LQ(this.ee, this.ee.t3, (48 + this.ee.a0.UL[0])); + this.pc = this.ee.ra.UL[0]; + // @0011B450 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + this.ee.sp.SL[0] = (this.ee.sp.SL[0] + -16); + + // @0011B458 SD s0, $0000(sp) + MobUt.SD(ee, ee.s0, 0x0000 + ee.sp.UL[0]); + // @0011B458 SD s0, $0000(sp) + MobUt.SD(this.ee, this.ee.s0, (0 + this.ee.sp.UL[0])); + // @0011B45C C.EQ.S $f12, $f0 + ee.fcr31_23 = ee.fpr[12].f == ee.fpr[0].f; + // @0011B45C C.EQ.S $f12, $f0 + this.ee.fcr31_23 = (this.ee.fpr[12].f == this.ee.fpr[0].f); + // @0011B464 BC1T $0011b484 + if (ee.fcr31_23) pc = 0x0011B484; + // @0011B464 BC1T $0011b484 + if (this.ee.fcr31_23) { + this.pc = 1160324u; + } + // @0011B468 DADDU s0, a0, zero + ee.s0.UD[0] = ee.a0.UD[0] + ee.r0.UD[0]; + // @0011B468 DADDU s0, a0, zero + this.ee.s0.UD[0] = (this.ee.a0.UD[0] + this.ee.r0.UD[0]); + + // @0011B46C JAL $0011bdc8 + ee.ra.UL[0] = pc + 8; pc = 0x0011B46C; + // @0011B46C JAL $0011bdc8 + this.ee.ra.UL[0] = 1160308u; + this.pc = 1162696u; + + // @0011B474 MOV.S $f12, $f0 + ee.fpr[12].f = ee.fpr[0].f; + // @0011B474 MOV.S $f12, $f0 + this.ee.fpr[12].f = this.ee.fpr[0].f; + + // @0011B488 LD ra, $0008(sp) + MobUt.LD(ee, ee.ra, 0x0008 + ee.sp.UL[0]); + // @0011B488 LD ra, $0008(sp) + MobUt.LD(this.ee, this.ee.ra, (8 + this.ee.sp.UL0)); + + // @0011B528 ADDIU sp, sp, $ffe0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); + + // @0011B570 LWC1 $f0, $0004(s1) + MobUt.LWC1(ee, ee.fpr[0], 4 + ee.s1.UL0); + // @0011B570 LWC1 $f0, $0004(s1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4 + this.ee.s1.UL0)); + + // @0011B85C SWC1 $f20, $0048(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (0x0048 + this.ee.s1.UL0)); + // @0011B534 SWC1 $f20, $0018(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (24 + this.ee.sp.UL0)); + + // @0011B868 C.LT.S $f20, $f0 + ee.fcr31_23 = ee.fpr[20].f < ee.fpr[0].f; + // @0011B868 C.LT.S $f20, $f0 + this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[0].f); + + // @0011B884 BC1FL $0011b894 + if (!ee.fcr31_23) { + pc = 0x0011b894; + //xxx + } + + // @0011B8A0 MULA.S $f13, $f13 + ee.fpracc.f = ee.fpr[13].f * ee.fpr[13].f; + // @0011B8A0 MULA.S $f13, $f13 + this.ee.fpracc.f = (this.ee.fpr[13].f * this.ee.fpr[13].f); + + // @0011B8A4 MADD.S $f0, $f12, $f12 + ee.fpr[0].f = ee.fpracc.f + ee.fpr[12].f * ee.fpr[12].f; + // @0011B8A4 MADD.S $f0, $f12, $f12 + this.ee.fpr[0].f = (this.ee.fpracc.f + + (this.ee.fpr[12].f * this.ee.fpr[12].f)); + + // @0011B8B4 SQRT.S $f0, $f0 + ee.fpr[0].f = (float)Math.Sqrt(ee.fpr[0].f); + // @0011B8B4 SQRT.S $f0, $f0 + this.ee.fpr[0].f = ((float)(System.Math.Sqrt(this.ee.fpr[0].f))); + + // @0011B8BC BC1F $0011ba50 + if (!ee.fcr31_23) pc = 0x0011ba50; + + // @0011B8CC NEG.S $f12, $f20 + ee.fpr[12].f = -ee.fpr[20].f; + // @0011B8CC NEG.S $f12, $f20 + this.ee.fpr[12].f = (0 - this.ee.fpr[20].f); + + // @0011B8FC SUB.S $f12, $f1, $f12 + ee.fpr[12].f = ee.fpr[1].f - ee.fpr[12].f; + // @0011B8FC SUB.S $f12, $f1, $f12 + this.ee.fpr[12].f = (this.ee.fpr[1].f - this.ee.fpr[12].f); + + // @0011B940 ADD.S $f2, $f2, $f3 + ee.fpr[2].f = ee.fpr[2].f + ee.fpr[3].f; + // @0011B940 ADD.S $f2, $f2, $f3 + this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[3].f); + + // @0011B998 LQC2 vf1, $0000(sp) + MobUt.LQC2(ee, ee.VF[1], 0x0000 + ee.sp.UL0); + // @0011B998 LQC2 vf1, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[1], (0 + this.ee.sp.UL0)); + + // @0011B9A0 VMUL.xyz vf1, vf1, vf2 + ee.VF[1].x = ee.VF[1].x * ee.VF[2].x; + ee.VF[1].y = ee.VF[1].y * ee.VF[2].y; + ee.VF[1].z = ee.VF[1].z * ee.VF[2].z; + + // @0011B9A4 VADDy.x vf1, vf1, vf1y + ee.VF[1].x = ee.VF[1].x + ee.VF[1].y; + // @0011B9A4 VADDy.x vf1, vf1, vf1y + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); + + // @0011B9C8 QMFC2 t0, vf1 + MobUt.QMFC2(ee.t0, ee.VF[1]); + // @0011B9AC QMFC2 t0, vf1 + MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); + + // @0011B9D0 C.LE.S $f1, $f0 + ee.fcr31_23 = (ee.fpr[1].f <= ee.fpr[0].f); + // @0011B9D0 C.LE.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f <= this.ee.fpr[0].f); + + // @00124D70 BEQ s3, t7, $00124d98 + if ((this.ee.s3.UD0 == this.ee.t7.UD0)) { + this.pc = 1199512u; + } + + // @00124CAC BEQL t7, t6, $00124cc0 + if ((this.ee.t7.UD0 == this.ee.t6.UD0)) { + this.pc = 1199296u; + // @00124CB0 ADDIU t7, sp, $0050 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 80))); + } + + // @00124B28 SQC2 vf1, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[1], (0 + this.ee.s2.UL0)); + + // @00124B24 VSUB.xyzw vf1, vf1, vf2 + ee.VF[1].x = ee.VF[1].x - ee.VF[2].x; + ee.VF[1].y = ee.VF[1].y - ee.VF[2].y; + ee.VF[1].z = ee.VF[1].z - ee.VF[2].z; + ee.VF[1].w = ee.VF[1].w - ee.VF[2].w; + + // @00124B4C VSQRT Q, vf2x + ee.Vq.f = (float)Math.Sqrt(ee.VF[2].x); + // @00124B4C VSQRT Q, vf2x + this.ee.Vq.f = ((float)(System.Math.Sqrt(this.ee.VF[2].x))); + + // @00124B54 CFC2 t0, $vi22 + MobUt.CFC2(ee.t0, ee.VI[22]); + // @00124B54 CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + + // @00124B58 VADDq.x vf2, vf0, Q + ee.VF[2].x = ee.VF[0].x + ee.Vq.f; + // @00124B58 VADDq.x vf2, vf0, Q + this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); + + // @00124B64 VDIV Q, vf0w, vf2x + ee.Vq.f = ee.VF[0].w / ee.VF[2].x; + // @00124B64 VDIV Q, vf0w, vf2x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); + + // @00124B6C VMULq.xyz vf1, vf1, Q + ee.VF[1].x = ee.VF[1].x * ee.Vq.f; + ee.VF[1].y = ee.VF[1].y * ee.Vq.f; + ee.VF[1].z = ee.VF[1].z * ee.Vq.f; + // @00124B6C VMULq.xyz vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + + // @00124D20 VMULAx.xyzw ACC, vf1, vf5x + ee.Vacc.x = ee.VF[1].x * ee.VF[5].x; + ee.Vacc.y = ee.VF[1].y * ee.VF[5].x; + ee.Vacc.z = ee.VF[1].z * ee.VF[5].x; + ee.Vacc.w = ee.VF[1].w * ee.VF[5].x; + // @00124D20 VMULAx.xyzw ACC, vf1, vf5x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); + this.ee.Vacc.w = (this.ee.VF[1].w * this.ee.VF[5].x); + + // @00124D24 VMADDAy.xyzw ACC, vf2, vf5y + ee.Vacc.x += ee.VF[2].x * ee.VF[5].y; + ee.Vacc.y += ee.VF[2].y * ee.VF[5].y; + ee.Vacc.z += ee.VF[2].z * ee.VF[5].y; + ee.Vacc.w += ee.VF[2].w * ee.VF[5].y; + // @00124D24 VMADDAy.xyzw ACC, vf2, vf5y + this.ee.Vacc.x = (this.ee.Vacc.x + + (this.ee.VF[2].x * this.ee.VF[5].y)); + this.ee.Vacc.y = (this.ee.Vacc.y + + (this.ee.VF[2].y * this.ee.VF[5].y)); + this.ee.Vacc.z = (this.ee.Vacc.z + + (this.ee.VF[2].z * this.ee.VF[5].y)); + this.ee.Vacc.w = (this.ee.Vacc.w + + (this.ee.VF[2].w * this.ee.VF[5].y)); + + // @00124D2C VMADDw.xyzw vf5, vf4, vf5w + ee.VF[5].x = ee.Vacc.x + ee.VF[4].x * ee.VF[5].w; + ee.VF[5].y = ee.Vacc.y + ee.VF[4].y * ee.VF[5].w; + ee.VF[5].z = ee.Vacc.z + ee.VF[4].z * ee.VF[5].w; + ee.VF[5].w = ee.Vacc.w + ee.VF[4].w * ee.VF[5].w; + // @00124D2C VMADDw.xyzw vf5, vf4, vf5w + this.ee.VF[5].x = (this.ee.Vacc.x + + (this.ee.VF[4].x * this.ee.VF[5].w)); + this.ee.VF[5].y = (this.ee.Vacc.y + + (this.ee.VF[4].y * this.ee.VF[5].w)); + this.ee.VF[5].z = (this.ee.Vacc.z + + (this.ee.VF[4].z * this.ee.VF[5].w)); + this.ee.VF[5].w = (this.ee.Vacc.w + + (this.ee.VF[4].w * this.ee.VF[5].w)); + + // @00124D98 BNEL s1, zero, $00124e04 + if ((this.ee.s1.UD0 != this.ee.r0.UD0)) { + this.pc = 1199620u; + // @00124D9C ADD.S $f0, $f23, $f23 + this.ee.fpr[0].f = (this.ee.fpr[23].f + this.ee.fpr[23].f); + } + + // @00124E10 MSUBA.S $f23, $f23 + ee.fpracc.f = ee.fpracc.f - ee.fpr[23].f * ee.fpr[23].f; + // @00124E10 MSUBA.S $f23, $f23 + this.ee.fpracc.f = (this.ee.fpracc.f + - (this.ee.fpr[23].f * this.ee.fpr[23].f)); + + // @00124E14 MSUB.S $f1, $f22, $f22 + ee.fpr[1].f = ee.fpracc.f - ee.fpr[22].f * ee.fpr[22].f; + // @00124E14 MSUB.S $f1, $f22, $f22 + this.ee.fpr[1].f = (this.ee.fpracc.f + - (this.ee.fpr[22].f * this.ee.fpr[22].f)); + + // @00124E18 MUL.S $f0, $f0, $f22 + this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[22].f); + + // @00124E28 DIV.S $f21, $f1, $f0 + this.ee.fpr[21].f = (this.ee.fpr[1].f / this.ee.fpr[0].f); + + // @00124E78 SW zero, $0008(s1) + MobUt.SW(ee, ee.r0, 0x0008 + ee.s1.UL0); + // @00124E78 SW zero, $0008(s1) + MobUt.SW(this.ee, this.ee.r0, (8 + this.ee.s1.UL0)); + + // @00125144 VOPMULA.xyz ACC, vf1, vf2 + ee.Vacc.x = ee.VF[1].y * ee.VF[2].z; + ee.Vacc.y = ee.VF[1].z * ee.VF[2].x; + ee.Vacc.z = ee.VF[1].x * ee.VF[2].y; + // @00125144 VOPMULA.xyz ACC, vf1, vf2 + this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); + this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); + this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); + + // @00125148 VOPMSUB.xyz vf3xyz, vf2, vf1 + ee.VF[3].x = ee.Vacc.x - ee.VF[2].y * ee.VF[1].z; + ee.VF[3].y = ee.Vacc.y - ee.VF[2].z * ee.VF[1].x; + ee.VF[3].z = ee.Vacc.z - ee.VF[2].x * ee.VF[1].y; + // @00125148 VOPMSUB.xyz vf3, vf2, vf1 + this.ee.VF[3].x = (this.ee.Vacc.x + - (this.ee.VF[2].y * this.ee.VF[1].z)); + this.ee.VF[3].y = (this.ee.Vacc.y + - (this.ee.VF[2].z * this.ee.VF[1].x)); + this.ee.VF[3].z = (this.ee.Vacc.z + - (this.ee.VF[2].x * this.ee.VF[1].y)); + + // @00127E68 ANDI t7, t6, $0007 + ee.t7.UD0 = ee.t6.US[0] & 0x0007u; + // @00127E68 ANDI t7, t6, $0007 + this.ee.t7.UD0 = ((ushort)((this.ee.t6.US0 & 7))); + + // @00127E78 BNE t7, zero, $00128254 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) { + this.pc = 1213012u; + } + + // @00128020 DSRL t2, t3, 9 + MobUt.DSRL(ee.t2, ee.t3, 9); + // @00128020 DSRL t2, t3, 9 + MobUt.DSRL(this.ee.t2, this.ee.t3, 9); + + // @00128068 SB t6, $0021(sp) + MobUt.SB(this.ee, this.ee.t6, (33 + this.ee.sp.UL0)); + + // @0012809C SLL t7, s0, 1 + MobUt.SLL(this.ee.t7, this.ee.s0, 1); + // @0011B424 ADDIU t7, t7, $4260 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16992))); + + // @0012065C ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + + // @00120670 LW t7, $0004(a0) + MobUt.LW(this.ee, this.ee.t7, (4 + this.ee.a0.UL0)); + + // @001206B4 JALR ra, v0 + ee.ra.UD0 = 0x001206B4 + 8; + pc = ee.v0.UL0; + // @001206B4 JALR ra, v0 + this.ee.ra.UD0 = 1181372u; + this.pc = this.ee.v0.UL0; + + // @00128DA0 LHU a2, $0010(t7) + MobUt.LHU(this.ee, this.ee.a2, (16 + this.ee.t7.UL0)); + + // @00128DA4 SLT t6, t5, a2 + ee.t6.UD0 = Convert.ToByte(ee.t5.SD0 < ee.a2.SD0); + // @00128DA4 SLT t6, t5, a2 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.a2.SD0)); + + // @001280A4 LBU t6, $0020(t5) + MobUt.LBU(this.ee, this.ee.t6, (32 + this.ee.t5.UL0)); + + // @00128104 SLTI t7, s0, $0003 + ee.t7.UD0 = Convert.ToByte(ee.s0.SD0 < 3); + + // @00128EA4 SLTIU t7, t6, $002c + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 44ul)); + + // @00129BA8 ORI t7, t7, $ffff + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 | 65535))); + + // @00129BB4 AND s4, s4, t7 + this.ee.s4.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + + // @00300400 MFC1 t3, $f12 + MobUt.MFC1(ee.t3, ee.fpr[12]); + + // @00145134 MFC1 t7, $f0 + MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); + + // @00142018 SH s2, $0000(t6) + MobUt.SH(this.ee, this.ee.s2, (0 + this.ee.t6.UL0)); + + // @00128154 LBU t7, $ffff(s6) + MobUt.LBU(this.ee, this.ee.t7, (4294967295u + this.ee.s6.UL0)); + + // @002FAA3C ADDI a3, a3, $ffff + this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); + + // @002FA950 VMULx.yzw vf4, vf4, vf0x + this.ee.VF[4].y = (this.ee.VF[4].y * this.ee.VF[0].x); + this.ee.VF[4].z = (this.ee.VF[4].z * this.ee.VF[0].x); + this.ee.VF[4].w = (this.ee.VF[4].w * this.ee.VF[0].x); + + // @0016274C VADD.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y + this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z + this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w + this.ee.VF[2].w); + + // @00145848 LH t7, $000a(a1) + MobUt.LH(this.ee, this.ee.t7, (10u + this.ee.a1.UL0)); + + // @00162770 SLTU v0, zero, v0 + this.ee.v0.UD0 = System.Convert.ToByte((this.ee.r0.UD0 < this.ee.v0.UD0)); + + // @001420CC XOR t7, t7, t6 + MobUt.XOR(this.ee.t7, this.ee.t7, this.ee.t6); + + // @0012D4F4 SUBU t7, s2, t4 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); + + // @00141FE8 MULT t7, t6, t5 + this.ee.t7.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.t5.SL0))); + + // @0012D2C8 BLTZ t7, $0012d33c + if ((this.ee.t7.SD0 < 0)) { + this.pc = 1233724u; + } + + // @0012C808 BGEZ t4, $0012c860 + if ((this.ee.t4.SD0 >= 0)) { + this.pc = 1230944u; + } + + // @0012C984 BGEZL t7, $0012c9dc + if ((this.ee.t7.SD0 >= 0)) { + this.pc = 1231324u; + // @0012C988 LW t6, $0004(s0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); + } + + // @0012BD40 PCPYLD t2, t7, t5 + ee.t2.UD1 = ee.t7.UD0; + ee.t2.UD0 = ee.t5.UD0; + + // @0012BD40 PCPYLD t2, t7, t5 + this.ee.t2.UD1 = this.ee.t7.UD0; + this.ee.t2.UD0 = this.ee.t5.UD0; + + // @0012BD3C PCPYUD t1, t4, t6 + this.ee.t1.UD0 = this.ee.t4.UD1; + this.ee.t1.UD1 = this.ee.t6.UD1; + + // @0012BD34 PEXTUW t7, t3, t2 + this.ee.t7.UL[0] = this.ee.t2.UL[2]; + this.ee.t7.UL[1] = this.ee.t3.UL[2]; + this.ee.t7.UL[2] = this.ee.t2.UL[3]; + this.ee.t7.UL[3] = this.ee.t3.UL[3]; + + // @0012AC74 DSRL32 t7, t5, 20 + MobUt.DSRL32(this.ee.t7, this.ee.t5, 20); + + // @0012AC60 DSLL32 t4, t4, 21 + MobUt.DSLL32(this.ee.t4, this.ee.t4, 21); + + // @00162328 BLEZ v0, $00162464 + if ((this.ee.v0.SD0 <= 0)) { + this.pc = 1451108u; + } + + // @00145300 CVT.W.S $f0, $f1 + MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); + + // @00143F44 OR s0, s0, v0 + this.ee.s0.UD0 = (this.ee.s0.UD0 | this.ee.v0.UD0); + + // @0012D3B0 MOVN t5, t6, t7 + if ((this.ee.t7.UD0 != 0)) { + this.ee.t5.UD0 = this.ee.t6.UD0; + } + } + } +#endif +} diff --git a/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Execee.cs b/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Execee.cs index 61bec1bb6..46b030563 100644 --- a/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Execee.cs +++ b/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Execee.cs @@ -1,60 +1,60 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; - -namespace OpenKh.Kh2Anim.Mset.EmuRunner -{ - public class ExeceeException : Exception - { - public ExeceeException() : base() { } - public ExeceeException(string text) : base(text) { } - } - public class TraceDiffException : ExeceeException - { - public TraceDiffException(string what, GPR v1, GPR v2) : base("The trace diff hit: " + what + " --- " + HexFmtUt.Format(v1) + " ≠ " + HexFmtUt.Format(v2)) { } - public TraceDiffException(string what, uint v1, uint v2) : base("The trace diff hit: " + what + " --- " + v1.ToString("x8") + " ≠ " + v2.ToString("x8")) { } - public TraceDiffException(string what, Vec v1, Vec v2) : base("The trace diff hit: " + what + " --- " + HexFmtUt.Format(v1) + " ≠ " + HexFmtUt.Format(v2)) { } - } - public class RecfnnotFound : ExeceeException - { - public RecfnnotFound(uint addr) : base("Recfn not found: " + addr.ToString("X8")) { } - public RecfnnotFound(uint addr, string rc) : base("Recfn not found: " + rc + " " + addr.ToString("X8")) { } - } - public class AccessUnpreparedMemoryException : ExeceeException - { - public AccessUnpreparedMemoryException(uint addr) : base("Access to undefined memory space: " + addr.ToString("X8")) { } - } - public class RecProcIsTooLong : ExeceeException - { - public RecProcIsTooLong(int cnt) : base("Recompiler hits limit: " + cnt + " > max") { } - } - public class IsR0Exception : Exception - { - } - - class HexFmtUt - { - public static string Format(Vec v) - { - MemoryStream os = new MemoryStream(16); - BinaryWriter wr = new BinaryWriter(os); - wr.Write(v.x); - wr.Write(v.y); - wr.Write(v.z); - wr.Write(v.w); - os.Position = 0; - BinaryReader br = new BinaryReader(os); - uint x = br.ReadUInt32(); - uint y = br.ReadUInt32(); - uint z = br.ReadUInt32(); - uint w = br.ReadUInt32(); - return string.Format("{0:x8}_{1:x8}_{2:x8}_{3:x8}", w, z, y, x); - } - - public static string Format(GPR o) - { - return string.Format("{0:x8}_{1:x8}_{2:x8}_{3:x8}", o.UL[3], o.UL[2], o.UL[1], o.UL[0]); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace OpenKh.Kh2Anim.Mset.EmuRunner +{ + public class ExeceeException : Exception + { + public ExeceeException() : base() { } + public ExeceeException(string text) : base(text) { } + } + public class TraceDiffException : ExeceeException + { + public TraceDiffException(string what, GPR v1, GPR v2) : base("The trace diff hit: " + what + " --- " + HexFmtUt.Format(v1) + " ≠ " + HexFmtUt.Format(v2)) { } + public TraceDiffException(string what, uint v1, uint v2) : base("The trace diff hit: " + what + " --- " + v1.ToString("x8") + " ≠ " + v2.ToString("x8")) { } + public TraceDiffException(string what, Vec v1, Vec v2) : base("The trace diff hit: " + what + " --- " + HexFmtUt.Format(v1) + " ≠ " + HexFmtUt.Format(v2)) { } + } + public class RecfnnotFound : ExeceeException + { + public RecfnnotFound(uint addr) : base("Recfn not found: " + addr.ToString("X8")) { } + public RecfnnotFound(uint addr, string rc) : base("Recfn not found: " + rc + " " + addr.ToString("X8")) { } + } + public class AccessUnpreparedMemoryException : ExeceeException + { + public AccessUnpreparedMemoryException(uint addr) : base("Access to undefined memory space: " + addr.ToString("X8")) { } + } + public class RecProcIsTooLong : ExeceeException + { + public RecProcIsTooLong(int cnt) : base("Recompiler hits limit: " + cnt + " > max") { } + } + public class IsR0Exception : Exception + { + } + + class HexFmtUt + { + public static string Format(Vec v) + { + MemoryStream os = new MemoryStream(16); + BinaryWriter wr = new BinaryWriter(os); + wr.Write(v.x); + wr.Write(v.y); + wr.Write(v.z); + wr.Write(v.w); + os.Position = 0; + BinaryReader br = new BinaryReader(os); + uint x = br.ReadUInt32(); + uint y = br.ReadUInt32(); + uint z = br.ReadUInt32(); + uint w = br.ReadUInt32(); + return string.Format("{0:x8}_{1:x8}_{2:x8}_{3:x8}", w, z, y, x); + } + + public static string Format(GPR o) + { + return string.Format("{0:x8}_{1:x8}_{2:x8}_{3:x8}", o.UL[3], o.UL[2], o.UL[1], o.UL[0]); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Mlink.cs b/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Mlink.cs index 713ede4a4..0f7ad62ab 100644 --- a/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Mlink.cs +++ b/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Mlink.cs @@ -1,622 +1,622 @@ -//#define UsePressed_eeram -//#define AllowRec1 -//#define Allow_DEB_eeram01 - -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; -using System.Reflection; -using System.Runtime.Serialization.Formatters.Binary; -using System.Collections; -using System.Xml; -using System.IO.Compression; - -namespace OpenKh.Kh2Anim.Mset.EmuRunner -{ - public class Mlink - { - Mobrc1 o1 = new Mobrc1(); - CustEE ee = new CustEE(); - - 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) - { - o1.Init0(); - o1.Init1(ee); - } - if (cntPass == 0) - { -#if UsePressed_eeram - Szexp.Decode(Resources.eeramx, ee.ram, ee.ram.Length); -#else - using (FileStream fsi = File.OpenRead(CnfUt.findeeram)) - using (GZipStream gz = new GZipStream(fsi, CompressionMode.Decompress)) - { - gz.Read(ee.ram, 0, 32 * 1024 * 1024); - } -#endif - } - - uint tmp1 = (32 * 1024 * 1024) - (768) - (65536); - uint tmp2 = (32 * 1024 * 1024) - (768) - (65536) - (65536); - uint tmp3 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536); - uint tmp4 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536); - uint tmp5 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512); - uint tmp6 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512); - uint tmp7 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512); - uint tmp8 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536); - uint tmp9 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536); - uint tmpa = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536) - (65536); - uint tmpb = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536) - (65536) - (65536); - // tmp1 1abb0b0 64k [out] temp - // tmp2 1abb590 64k [in] st1 - // tmp3 1ac7410 64k [out] temp - // tmp4 1acad50 64k [out] (4x4 matrix for mdlx bone calc) - // tmp5 1abb6d0 8k [out] (Sxyz) - // tmp6 1abc520 8k [out] (Rxyz) - // tmp7 1abd370 8k [out] (Txyz) - // tmp8 3b1870 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) - // tmp9 3b5eb0 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) - // tmpa 3b6bb0 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) - // tmpb 3b78b0 64k [out] (s.r.t.?) - - uint Sxyz = tmp5; - uint Rxyz = tmp6; - uint Txyz = tmp7; - - uint offMdlxRoot = 10 * 1024 * 1024; - if (cntPass == 0) - { - fsMdlx.Read(ee.ram, (int)offMdlxRoot, 5 * 1024 * 1024); - - offMdlx04 = new RelocMdlx(ee.ram, (int)offMdlxRoot, (int)offMdlxRoot, 0x354398, 0, tmp2, 1).Run(); - } - - uint s4 = tmp1; // temp; - uint s2 = tmp2; // st1; - uint a1 = s2; - - for (int w = 0; w < 65536; w++) - ee.ram[w] = 0; - - if (true) - { - MemoryStream wri = new MemoryStream(ee.ram, true); - wri.Position = s2; - BinaryWriter wr = new BinaryWriter(wri); - uint[] st1al = new uint[] { - 0x0 ,0 ,0 ,0, - 0x0 ,offMdlx04 ,0x0 ,Sxyz, - Rxyz ,Txyz ,tmp3 ,tmp4, - 0x0 ,0x0 ,0x0 ,0, - }; - foreach (uint ui in st1al) - wr.Write(ui); - } - - uint offMsetRoot = 15 * 1024 * 1024; - if (cntPass == 0) - { - fsMset.Read(ee.ram, (int)offMsetRoot, 17 * 1024 * 1024); - - RelocMset RM = new RelocMset(ee.ram, offMsetRoot, offMsetRoot, new uint[] { 0, 0, tmp8, tmp9, tmpa, tmpb, }); - RM.Run(); - } - - //uint offMset = 0x009E0340 + 0x1D390; - //uint offMset = offMsetRoot + 0x3370; - uint offMset = offMsetRoot + offMsetRxxx; - - // s0, s1, s2, s4, a1 - uint s1 = offMset; - uint a0 = offMset; - uint s0 = offMset + 0x90; - - ee.VF[0].w = 1; - - // Opt3 - if (true) - { - //ee.r0.UD0 = 0U; - ee.at.UD0 = 0U; - ee.v0.UD0 = 0U; - ee.v1.UD0 = 0U; - ee.a0.UD0 = a0; // mset +0x00 - ee.a1.UD0 = a1; // info tbl - ee.a2.UD0 = 0U; - ee.a3.UD0 = 0U; - ee.t0.UD0 = 0U; - ee.t1.UD0 = 0U; - ee.t2.UD0 = 0U; - ee.t3.UD0 = 0U; - ee.t4.UD0 = 0U; - ee.t5.UD0 = 0U; - ee.t6.UD0 = 0U; - ee.t7.UD0 = 0U; - ee.s0.UD0 = 0U; // s0; // mset +0x90 - ee.s1.UD0 = 0U; - ee.s2.UD0 = 0U; - ee.s3.UD0 = 0U; - ee.s4.UD0 = s4; // temp? - ee.s5.UD0 = 0U; - ee.s6.UD0 = 0U; - ee.s7.UD0 = 0U; - ee.t8.UD0 = 0U; - ee.t9.UD0 = 0U; - ee.k0.UD0 = 0U; - ee.k1.UD0 = 0U; - ee.gp.UD0 = 0U; - ee.sp.UD0 = 0x2000000U; - ee.s8.UD0 = 0U; - ee.ra.UD0 = 0xFFFFFFFFU; - - ee.pc = 0x128260; - while (ee.pc != 0xFFFFFFFFU) - { - if (o1.pfns.ContainsKey(ee.pc) || MobRecUt.Rec1(ee.pc, o1.pfns, ee)) - { - o1.pfns[ee.pc](); - } - else - throw new RecfnnotFound(ee.pc, "rc3"); - } - } - // Opt2 - if (true) - { - //ee.r0.UD0 = 0U; - ee.at.UD0 = 0U; - ee.v0.UD0 = 0U; - ee.v1.UD0 = 0U; - ee.a0.UD0 = a0; // mset +0x00 - ee.a1.UD0 = a1; // info tbl - ee.a2.UD0 = 0U; - ee.a3.UD0 = 0U; - ee.t0.UD0 = 0U; - ee.t1.UD0 = 0U; - ee.t2.UD0 = 0U; - ee.t3.UD0 = 0U; - ee.t4.UD0 = 0U; - ee.t5.UD0 = 0U; - ee.t6.UD0 = 0U; - ee.t7.UD0 = 0U; - ee.s0.UD0 = s0; // mset +0x90 - ee.s1.UD0 = s1; - ee.s2.UD0 = s2; - ee.s3.UD0 = 0U; - ee.s4.UD0 = s4; // temp? - ee.s5.UD0 = 0U; - ee.s6.UD0 = 0U; - ee.s7.UD0 = 0U; - ee.t8.UD0 = 0U; - ee.t9.UD0 = 0U; - ee.k0.UD0 = 0U; - ee.k1.UD0 = 0U; - ee.gp.UD0 = 0U; - ee.sp.UD0 = 0x2000000U; - ee.s8.UD0 = 0U; - ee.ra.UD0 = 0xFFFFFFFFU; - - ee.fpr[12].f = tick; - - ee.pc = 0x128918; - while (ee.pc != 0xFFFFFFFFU) - { - if (o1.pfns.ContainsKey(ee.pc) || MobRecUt.Rec1(ee.pc, o1.pfns, ee)) - { - o1.pfns[ee.pc](); - } - else - throw new RecfnnotFound(ee.pc, "rc2"); - } - } - // Opt1 - if (true) - { - ee.at.UD0 = 0U; - ee.v0.UD0 = 0U; - ee.v1.UD0 = 0U; - ee.a0.UD0 = a0; // mset +0x00 - ee.a1.UD0 = a1; // info tbl - ee.a2.UD0 = 0U; - ee.a3.UD0 = 0U; - ee.t0.UD0 = 0U; - ee.t1.UD0 = 0U; - ee.t2.UD0 = 0U; - ee.t3.UD0 = 0U; - ee.t4.UD0 = 0U; - ee.t5.UD0 = 0U; - ee.t6.UD0 = 0U; - ee.t7.UD0 = 0U; - ee.s0.UD0 = s0; // mset +0x90 - ee.s1.UD0 = 0U; - ee.s2.UD0 = 0U; - ee.s3.UD0 = 0U; - ee.s4.UD0 = s4; // temp? - ee.s5.UD0 = 0U; - ee.s6.UD0 = 0U; - ee.s7.UD0 = 0U; - ee.t8.UD0 = 0U; - ee.t9.UD0 = 0U; - ee.k0.UD0 = 0U; - ee.k1.UD0 = 0U; - ee.gp.UD0 = 0U; - ee.sp.UD0 = 0x2000000U; - ee.s8.UD0 = 0U; - ee.ra.UD0 = 0xFFFFFFFFU; - - ee.pc = 0x129A18; - while (ee.pc != 0xFFFFFFFFU) - { - if (o1.pfns.ContainsKey(ee.pc) || MobRecUt.Rec1(ee.pc, o1.pfns, ee)) - { - o1.pfns[ee.pc](); - } - else - { - throw new RecfnnotFound(ee.pc, "rc1"); - } - } - } - - os.Write(ee.ram, (int)tmp4, 0x40 * cnt1); - - cntPass++; - - } - - public void Permit_DEB(Stream fsMdlx, int cnt1, Stream fsMset, int cnt2, uint offMsetRxxx, float tick, out float[] Svec, out float[] Rvec, out float[] Tvec) - { - if (cntPass == 0) - { - o1.Init0(); - o1.Init1(ee); - } - if (cntPass == 0) - { -#if UsePressed_eeram - Szexp.Decode(Resources.eeramx, ee.ram, ee.ram.Length); -#else - using (FileStream fsi = File.OpenRead(CnfUt.findeeram)) - using (GZipStream gz = new GZipStream(fsi, CompressionMode.Decompress)) - { - gz.Read(ee.ram, 0, 32 * 1024 * 1024); - } -#endif - } - - uint tmp1 = (32 * 1024 * 1024) - (768) - (65536); - uint tmp2 = (32 * 1024 * 1024) - (768) - (65536) - (65536); - uint tmp3 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536); - uint tmp4 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536); - uint tmp5 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512); - uint tmp6 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512); - uint tmp7 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512); - uint tmp8 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536); - uint tmp9 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536); - uint tmpa = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536) - (65536); - uint tmpb = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536) - (65536) - (65536); - // tmp1 1abb0b0 64k [out] temp - // tmp2 1abb590 64k [in] st1 - // tmp3 1ac7410 64k [out] temp - // tmp4 1acad50 64k [out] (4x4 matrix for mdlx bone calc) - // tmp5 1abb6d0 8k [out] (Sxyz) - // tmp6 1abc520 8k [out] (Rxyz) - // tmp7 1abd370 8k [out] (Txyz) - // tmp8 3b1870 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) - // tmp9 3b5eb0 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) - // tmpa 3b6bb0 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) - // tmpb 3b78b0 64k [out] (s.r.t.?) - - uint Sxyz = tmp5; - uint Rxyz = tmp6; - uint Txyz = tmp7; - - uint offMdlxRoot = 20 * 1024 * 1024; - if (cntPass == 0) - { - fsMdlx.Read(ee.ram, (int)offMdlxRoot, 5 * 1024 * 1024); - - offMdlx04 = new RelocMdlx(ee.ram, (int)offMdlxRoot, (int)offMdlxRoot, 0x354398, 0, tmp2, 1).Run(); - } - - uint s4 = tmp1; // temp; - uint s2 = tmp2; // st1; - uint a1 = s2; - - for (int w = 0; w < 65536; w++) - ee.ram[w] = 0; - - if (true) - { - MemoryStream wri = new MemoryStream(ee.ram, true); - wri.Position = s2; - BinaryWriter wr = new BinaryWriter(wri); - uint[] st1al = new uint[] { - 0x0 ,0 ,0 ,0, - 0x0 ,offMdlx04 ,0x0 ,Sxyz, - Rxyz ,Txyz ,tmp3 ,tmp4, - 0x0 ,0x0 ,0x0 ,0, - }; - foreach (uint ui in st1al) - wr.Write(ui); - } - - uint offMsetRoot = 25 * 1024 * 1024; - if (cntPass == 0) - { - fsMset.Read(ee.ram, (int)offMsetRoot, 5 * 1024 * 1024); - - RelocMset RM = new RelocMset(ee.ram, offMsetRoot, offMsetRoot, new uint[] { 0, 0, tmp8, tmp9, tmpa, tmpb, }); - RM.Run(); - } - - //uint offMset = 0x009E0340 + 0x1D390; - //uint offMset = offMsetRoot + 0x3370; - uint offMset = offMsetRoot + offMsetRxxx; - - // s0, s1, s2, s4, a1 - uint s1 = offMset; - uint a0 = offMset; - uint s0 = offMset + 0x90; - - ee.VF[0].w = 1; - - // Opt3 - if (true) - { - //ee.r0.UD0 = 0U; - ee.at.UD0 = 0U; - ee.v0.UD0 = 0U; - ee.v1.UD0 = 0U; - ee.a0.UD0 = a0; // mset +0x00 - ee.a1.UD0 = a1; // info tbl - ee.a2.UD0 = 0U; - ee.a3.UD0 = 0U; - ee.t0.UD0 = 0U; - ee.t1.UD0 = 0U; - ee.t2.UD0 = 0U; - ee.t3.UD0 = 0U; - ee.t4.UD0 = 0U; - ee.t5.UD0 = 0U; - ee.t6.UD0 = 0U; - ee.t7.UD0 = 0U; - ee.s0.UD0 = 0U; // s0; // mset +0x90 - ee.s1.UD0 = 0U; - ee.s2.UD0 = 0U; - ee.s3.UD0 = 0U; - ee.s4.UD0 = s4; // temp? - ee.s5.UD0 = 0U; - ee.s6.UD0 = 0U; - ee.s7.UD0 = 0U; - ee.t8.UD0 = 0U; - ee.t9.UD0 = 0U; - ee.k0.UD0 = 0U; - ee.k1.UD0 = 0U; - ee.gp.UD0 = 0U; - ee.sp.UD0 = 0x2000000U; - ee.s8.UD0 = 0U; - ee.ra.UD0 = 0xFFFFFFFFU; - - ee.pc = 0x128260; - while (ee.pc != 0xFFFFFFFFU) - { - if (o1.pfns.ContainsKey(ee.pc) || MobRecUt.Rec1(ee.pc, o1.pfns, ee)) - { - o1.pfns[ee.pc](); - } - else - throw new RecfnnotFound(ee.pc, "rc3"); - } - } - // Opt2 - if (true) - { - //ee.r0.UD0 = 0U; - ee.at.UD0 = 0U; - ee.v0.UD0 = 0U; - ee.v1.UD0 = 0U; - ee.a0.UD0 = a0; // mset +0x00 - ee.a1.UD0 = a1; // info tbl - ee.a2.UD0 = 0U; - ee.a3.UD0 = 0U; - ee.t0.UD0 = 0U; - ee.t1.UD0 = 0U; - ee.t2.UD0 = 0U; - ee.t3.UD0 = 0U; - ee.t4.UD0 = 0U; - ee.t5.UD0 = 0U; - ee.t6.UD0 = 0U; - ee.t7.UD0 = 0U; - ee.s0.UD0 = s0; // mset +0x90 - ee.s1.UD0 = s1; - ee.s2.UD0 = s2; - ee.s3.UD0 = 0U; - ee.s4.UD0 = s4; // temp? - ee.s5.UD0 = 0U; - ee.s6.UD0 = 0U; - ee.s7.UD0 = 0U; - ee.t8.UD0 = 0U; - ee.t9.UD0 = 0U; - ee.k0.UD0 = 0U; - ee.k1.UD0 = 0U; - ee.gp.UD0 = 0U; - ee.sp.UD0 = 0x2000000U; - ee.s8.UD0 = 0U; - ee.ra.UD0 = 0xFFFFFFFFU; - - ee.fpr[12].f = tick; - - ee.pc = 0x128918; - while (ee.pc != 0xFFFFFFFFU) - { - if (o1.pfns.ContainsKey(ee.pc) || MobRecUt.Rec1(ee.pc, o1.pfns, ee)) - { - o1.pfns[ee.pc](); - } - else - throw new RecfnnotFound(ee.pc, "rc2"); - } - } - - { - MemoryStream si = new MemoryStream(ee.ram, false); - BinaryReader br = new BinaryReader(si); - - si.Position = Sxyz; - Svec = new float[4 * cnt1]; - for (int a = 0; a < 4 * cnt1; a++) - Svec[a] = br.ReadSingle(); - - si.Position = Rxyz; - Rvec = new float[4 * cnt1]; - for (int a = 0; a < 4 * cnt1; a++) - Rvec[a] = br.ReadSingle(); - - si.Position = Txyz; - Tvec = new float[4 * cnt1]; - for (int a = 0; a < 4 * cnt1; a++) - Tvec[a] = br.ReadSingle(); - } - - cntPass++; - - } - - public void DEB() - { -#if Allow_DEB_eeram01 - MobUt.bitr[0x378368 >> 4] = true; - MobUt.bitr[0x378378 >> 4] = true; - MobUt.bitr[0x378378 >> 4] = true; - MobUt.bitr[0x378398 >> 4] = true; - MobUt.bitr[0x3783a8 >> 4] = true; - MobUt.bitr[0x3783b8 >> 4] = true; - - BitArray bita = MobUt.bita; - BitArray bitr = MobUt.bitr; - if (File.Exists(Path.Combine(Settings.Default.pressdir, "save_DEB.bin"))) { - using (FileStream fsx = File.OpenRead(Path.Combine(Settings.Default.pressdir, "save_DEB.bin"))) { - BinaryFormatter bf = new BinaryFormatter(); - BitArray b; - bita = bita.Or(b = (BitArray)bf.Deserialize(fsx)); - bitr = bitr.Or(b = (BitArray)bf.Deserialize(fsx)); - } - } - - using (FileStream fs = File.Create(Path.Combine(Settings.Default.pressdir, "eeram01.bin"))) { - byte[] noop16 = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; - for (int x = 0; x < 2097152; x++) { - if ((bitr[x] || bitr[Math.Max(0, x - 1)] || bitr[Math.Min(2097152 - 1, x + 1)]) && x < 20 * 1024 * 1024 / 16) { - fs.Write(ee.ram, 16 * x, 16); - } - else { - fs.Write(noop16, 0, 16); - } - } - } - - if (true) { - using (FileStream fsx = File.Create(Path.Combine(Settings.Default.pressdir, "save_DEB.bin"))) { - BinaryFormatter bf = new BinaryFormatter(); - bf.Serialize(fsx, bita); - bf.Serialize(fsx, bitr); - } - } -#endif - } - } - - public partial class Mobrc1 - { - void here(uint pc) { } - - internal SortedDictionary pfns { get { return dicti2a; } } - internal void Init0() { initfns(); } - 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(); - - public static bool Rec1(uint addr, SortedDictionary dicti2a, CustEE ee) - { -#if AllowRec1 - string dirlib = Settings.Default.dirlib; - string flib = Myrec.Getflib(addr, dirlib); - if (!File.Exists(flib)) { - Myrec.Privrec1(addr, new MemoryStream(Uteeram.eeram, false), dirlib); - if (!File.Exists(flib)) return false; - } - - Assembly lib = Assembly.LoadFile(flib); - Type cls1 = lib.GetType("ee1Dec.C.Class1"); - object o = Activator.CreateInstance(cls1, ee); - MethodInfo mi = cls1.GetMethod(LabUt.addr2Funct(addr)); - MobUt.Tx8 tx8 = (MobUt.Tx8)Delegate.CreateDelegate(typeof(MobUt.Tx8), o, mi); - dicti2a[addr] = tx8; - System.Diagnostics.Debug.WriteLine("## " + addr.ToString("X8")); - return true; -#else - return false; -#endif - } - } -} +//#define UsePressed_eeram +//#define AllowRec1 +//#define Allow_DEB_eeram01 + +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Reflection; +using System.Runtime.Serialization.Formatters.Binary; +using System.Collections; +using System.Xml; +using System.IO.Compression; + +namespace OpenKh.Kh2Anim.Mset.EmuRunner +{ + public class Mlink + { + Mobrc1 o1 = new Mobrc1(); + CustEE ee = new CustEE(); + + 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) + { + o1.Init0(); + o1.Init1(ee); + } + if (cntPass == 0) + { +#if UsePressed_eeram + Szexp.Decode(Resources.eeramx, ee.ram, ee.ram.Length); +#else + using (FileStream fsi = File.OpenRead(CnfUt.findeeram)) + using (GZipStream gz = new GZipStream(fsi, CompressionMode.Decompress)) + { + gz.Read(ee.ram, 0, 32 * 1024 * 1024); + } +#endif + } + + uint tmp1 = (32 * 1024 * 1024) - (768) - (65536); + uint tmp2 = (32 * 1024 * 1024) - (768) - (65536) - (65536); + uint tmp3 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536); + uint tmp4 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536); + uint tmp5 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512); + uint tmp6 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512); + uint tmp7 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512); + uint tmp8 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536); + uint tmp9 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536); + uint tmpa = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536) - (65536); + uint tmpb = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536) - (65536) - (65536); + // tmp1 1abb0b0 64k [out] temp + // tmp2 1abb590 64k [in] st1 + // tmp3 1ac7410 64k [out] temp + // tmp4 1acad50 64k [out] (4x4 matrix for mdlx bone calc) + // tmp5 1abb6d0 8k [out] (Sxyz) + // tmp6 1abc520 8k [out] (Rxyz) + // tmp7 1abd370 8k [out] (Txyz) + // tmp8 3b1870 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) + // tmp9 3b5eb0 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) + // tmpa 3b6bb0 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) + // tmpb 3b78b0 64k [out] (s.r.t.?) + + uint Sxyz = tmp5; + uint Rxyz = tmp6; + uint Txyz = tmp7; + + uint offMdlxRoot = 10 * 1024 * 1024; + if (cntPass == 0) + { + fsMdlx.Read(ee.ram, (int)offMdlxRoot, 5 * 1024 * 1024); + + offMdlx04 = new RelocMdlx(ee.ram, (int)offMdlxRoot, (int)offMdlxRoot, 0x354398, 0, tmp2, 1).Run(); + } + + uint s4 = tmp1; // temp; + uint s2 = tmp2; // st1; + uint a1 = s2; + + for (int w = 0; w < 65536; w++) + ee.ram[w] = 0; + + if (true) + { + MemoryStream wri = new MemoryStream(ee.ram, true); + wri.Position = s2; + BinaryWriter wr = new BinaryWriter(wri); + uint[] st1al = new uint[] { + 0x0 ,0 ,0 ,0, + 0x0 ,offMdlx04 ,0x0 ,Sxyz, + Rxyz ,Txyz ,tmp3 ,tmp4, + 0x0 ,0x0 ,0x0 ,0, + }; + foreach (uint ui in st1al) + wr.Write(ui); + } + + uint offMsetRoot = 15 * 1024 * 1024; + if (cntPass == 0) + { + fsMset.Read(ee.ram, (int)offMsetRoot, 17 * 1024 * 1024); + + RelocMset RM = new RelocMset(ee.ram, offMsetRoot, offMsetRoot, new uint[] { 0, 0, tmp8, tmp9, tmpa, tmpb, }); + RM.Run(); + } + + //uint offMset = 0x009E0340 + 0x1D390; + //uint offMset = offMsetRoot + 0x3370; + uint offMset = offMsetRoot + offMsetRxxx; + + // s0, s1, s2, s4, a1 + uint s1 = offMset; + uint a0 = offMset; + uint s0 = offMset + 0x90; + + ee.VF[0].w = 1; + + // Opt3 + if (true) + { + //ee.r0.UD0 = 0U; + ee.at.UD0 = 0U; + ee.v0.UD0 = 0U; + ee.v1.UD0 = 0U; + ee.a0.UD0 = a0; // mset +0x00 + ee.a1.UD0 = a1; // info tbl + ee.a2.UD0 = 0U; + ee.a3.UD0 = 0U; + ee.t0.UD0 = 0U; + ee.t1.UD0 = 0U; + ee.t2.UD0 = 0U; + ee.t3.UD0 = 0U; + ee.t4.UD0 = 0U; + ee.t5.UD0 = 0U; + ee.t6.UD0 = 0U; + ee.t7.UD0 = 0U; + ee.s0.UD0 = 0U; // s0; // mset +0x90 + ee.s1.UD0 = 0U; + ee.s2.UD0 = 0U; + ee.s3.UD0 = 0U; + ee.s4.UD0 = s4; // temp? + ee.s5.UD0 = 0U; + ee.s6.UD0 = 0U; + ee.s7.UD0 = 0U; + ee.t8.UD0 = 0U; + ee.t9.UD0 = 0U; + ee.k0.UD0 = 0U; + ee.k1.UD0 = 0U; + ee.gp.UD0 = 0U; + ee.sp.UD0 = 0x2000000U; + ee.s8.UD0 = 0U; + ee.ra.UD0 = 0xFFFFFFFFU; + + ee.pc = 0x128260; + while (ee.pc != 0xFFFFFFFFU) + { + if (o1.pfns.ContainsKey(ee.pc) || MobRecUt.Rec1(ee.pc, o1.pfns, ee)) + { + o1.pfns[ee.pc](); + } + else + throw new RecfnnotFound(ee.pc, "rc3"); + } + } + // Opt2 + if (true) + { + //ee.r0.UD0 = 0U; + ee.at.UD0 = 0U; + ee.v0.UD0 = 0U; + ee.v1.UD0 = 0U; + ee.a0.UD0 = a0; // mset +0x00 + ee.a1.UD0 = a1; // info tbl + ee.a2.UD0 = 0U; + ee.a3.UD0 = 0U; + ee.t0.UD0 = 0U; + ee.t1.UD0 = 0U; + ee.t2.UD0 = 0U; + ee.t3.UD0 = 0U; + ee.t4.UD0 = 0U; + ee.t5.UD0 = 0U; + ee.t6.UD0 = 0U; + ee.t7.UD0 = 0U; + ee.s0.UD0 = s0; // mset +0x90 + ee.s1.UD0 = s1; + ee.s2.UD0 = s2; + ee.s3.UD0 = 0U; + ee.s4.UD0 = s4; // temp? + ee.s5.UD0 = 0U; + ee.s6.UD0 = 0U; + ee.s7.UD0 = 0U; + ee.t8.UD0 = 0U; + ee.t9.UD0 = 0U; + ee.k0.UD0 = 0U; + ee.k1.UD0 = 0U; + ee.gp.UD0 = 0U; + ee.sp.UD0 = 0x2000000U; + ee.s8.UD0 = 0U; + ee.ra.UD0 = 0xFFFFFFFFU; + + ee.fpr[12].f = tick; + + ee.pc = 0x128918; + while (ee.pc != 0xFFFFFFFFU) + { + if (o1.pfns.ContainsKey(ee.pc) || MobRecUt.Rec1(ee.pc, o1.pfns, ee)) + { + o1.pfns[ee.pc](); + } + else + throw new RecfnnotFound(ee.pc, "rc2"); + } + } + // Opt1 + if (true) + { + ee.at.UD0 = 0U; + ee.v0.UD0 = 0U; + ee.v1.UD0 = 0U; + ee.a0.UD0 = a0; // mset +0x00 + ee.a1.UD0 = a1; // info tbl + ee.a2.UD0 = 0U; + ee.a3.UD0 = 0U; + ee.t0.UD0 = 0U; + ee.t1.UD0 = 0U; + ee.t2.UD0 = 0U; + ee.t3.UD0 = 0U; + ee.t4.UD0 = 0U; + ee.t5.UD0 = 0U; + ee.t6.UD0 = 0U; + ee.t7.UD0 = 0U; + ee.s0.UD0 = s0; // mset +0x90 + ee.s1.UD0 = 0U; + ee.s2.UD0 = 0U; + ee.s3.UD0 = 0U; + ee.s4.UD0 = s4; // temp? + ee.s5.UD0 = 0U; + ee.s6.UD0 = 0U; + ee.s7.UD0 = 0U; + ee.t8.UD0 = 0U; + ee.t9.UD0 = 0U; + ee.k0.UD0 = 0U; + ee.k1.UD0 = 0U; + ee.gp.UD0 = 0U; + ee.sp.UD0 = 0x2000000U; + ee.s8.UD0 = 0U; + ee.ra.UD0 = 0xFFFFFFFFU; + + ee.pc = 0x129A18; + while (ee.pc != 0xFFFFFFFFU) + { + if (o1.pfns.ContainsKey(ee.pc) || MobRecUt.Rec1(ee.pc, o1.pfns, ee)) + { + o1.pfns[ee.pc](); + } + else + { + throw new RecfnnotFound(ee.pc, "rc1"); + } + } + } + + os.Write(ee.ram, (int)tmp4, 0x40 * cnt1); + + cntPass++; + + } + + public void Permit_DEB(Stream fsMdlx, int cnt1, Stream fsMset, int cnt2, uint offMsetRxxx, float tick, out float[] Svec, out float[] Rvec, out float[] Tvec) + { + if (cntPass == 0) + { + o1.Init0(); + o1.Init1(ee); + } + if (cntPass == 0) + { +#if UsePressed_eeram + Szexp.Decode(Resources.eeramx, ee.ram, ee.ram.Length); +#else + using (FileStream fsi = File.OpenRead(CnfUt.findeeram)) + using (GZipStream gz = new GZipStream(fsi, CompressionMode.Decompress)) + { + gz.Read(ee.ram, 0, 32 * 1024 * 1024); + } +#endif + } + + uint tmp1 = (32 * 1024 * 1024) - (768) - (65536); + uint tmp2 = (32 * 1024 * 1024) - (768) - (65536) - (65536); + uint tmp3 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536); + uint tmp4 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536); + uint tmp5 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512); + uint tmp6 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512); + uint tmp7 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512); + uint tmp8 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536); + uint tmp9 = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536); + uint tmpa = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536) - (65536); + uint tmpb = (32 * 1024 * 1024) - (768) - (65536) - (65536) - (65536) - (65536) - (16 * 512) - (16 * 512) - (16 * 512) - (65536) - (65536) - (65536) - (65536); + // tmp1 1abb0b0 64k [out] temp + // tmp2 1abb590 64k [in] st1 + // tmp3 1ac7410 64k [out] temp + // tmp4 1acad50 64k [out] (4x4 matrix for mdlx bone calc) + // tmp5 1abb6d0 8k [out] (Sxyz) + // tmp6 1abc520 8k [out] (Rxyz) + // tmp7 1abd370 8k [out] (Txyz) + // tmp8 3b1870 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) + // tmp9 3b5eb0 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) + // tmpa 3b6bb0 64k [out] (4x4 matrix) size=64*(cnt2-cnt1) + // tmpb 3b78b0 64k [out] (s.r.t.?) + + uint Sxyz = tmp5; + uint Rxyz = tmp6; + uint Txyz = tmp7; + + uint offMdlxRoot = 20 * 1024 * 1024; + if (cntPass == 0) + { + fsMdlx.Read(ee.ram, (int)offMdlxRoot, 5 * 1024 * 1024); + + offMdlx04 = new RelocMdlx(ee.ram, (int)offMdlxRoot, (int)offMdlxRoot, 0x354398, 0, tmp2, 1).Run(); + } + + uint s4 = tmp1; // temp; + uint s2 = tmp2; // st1; + uint a1 = s2; + + for (int w = 0; w < 65536; w++) + ee.ram[w] = 0; + + if (true) + { + MemoryStream wri = new MemoryStream(ee.ram, true); + wri.Position = s2; + BinaryWriter wr = new BinaryWriter(wri); + uint[] st1al = new uint[] { + 0x0 ,0 ,0 ,0, + 0x0 ,offMdlx04 ,0x0 ,Sxyz, + Rxyz ,Txyz ,tmp3 ,tmp4, + 0x0 ,0x0 ,0x0 ,0, + }; + foreach (uint ui in st1al) + wr.Write(ui); + } + + uint offMsetRoot = 25 * 1024 * 1024; + if (cntPass == 0) + { + fsMset.Read(ee.ram, (int)offMsetRoot, 5 * 1024 * 1024); + + RelocMset RM = new RelocMset(ee.ram, offMsetRoot, offMsetRoot, new uint[] { 0, 0, tmp8, tmp9, tmpa, tmpb, }); + RM.Run(); + } + + //uint offMset = 0x009E0340 + 0x1D390; + //uint offMset = offMsetRoot + 0x3370; + uint offMset = offMsetRoot + offMsetRxxx; + + // s0, s1, s2, s4, a1 + uint s1 = offMset; + uint a0 = offMset; + uint s0 = offMset + 0x90; + + ee.VF[0].w = 1; + + // Opt3 + if (true) + { + //ee.r0.UD0 = 0U; + ee.at.UD0 = 0U; + ee.v0.UD0 = 0U; + ee.v1.UD0 = 0U; + ee.a0.UD0 = a0; // mset +0x00 + ee.a1.UD0 = a1; // info tbl + ee.a2.UD0 = 0U; + ee.a3.UD0 = 0U; + ee.t0.UD0 = 0U; + ee.t1.UD0 = 0U; + ee.t2.UD0 = 0U; + ee.t3.UD0 = 0U; + ee.t4.UD0 = 0U; + ee.t5.UD0 = 0U; + ee.t6.UD0 = 0U; + ee.t7.UD0 = 0U; + ee.s0.UD0 = 0U; // s0; // mset +0x90 + ee.s1.UD0 = 0U; + ee.s2.UD0 = 0U; + ee.s3.UD0 = 0U; + ee.s4.UD0 = s4; // temp? + ee.s5.UD0 = 0U; + ee.s6.UD0 = 0U; + ee.s7.UD0 = 0U; + ee.t8.UD0 = 0U; + ee.t9.UD0 = 0U; + ee.k0.UD0 = 0U; + ee.k1.UD0 = 0U; + ee.gp.UD0 = 0U; + ee.sp.UD0 = 0x2000000U; + ee.s8.UD0 = 0U; + ee.ra.UD0 = 0xFFFFFFFFU; + + ee.pc = 0x128260; + while (ee.pc != 0xFFFFFFFFU) + { + if (o1.pfns.ContainsKey(ee.pc) || MobRecUt.Rec1(ee.pc, o1.pfns, ee)) + { + o1.pfns[ee.pc](); + } + else + throw new RecfnnotFound(ee.pc, "rc3"); + } + } + // Opt2 + if (true) + { + //ee.r0.UD0 = 0U; + ee.at.UD0 = 0U; + ee.v0.UD0 = 0U; + ee.v1.UD0 = 0U; + ee.a0.UD0 = a0; // mset +0x00 + ee.a1.UD0 = a1; // info tbl + ee.a2.UD0 = 0U; + ee.a3.UD0 = 0U; + ee.t0.UD0 = 0U; + ee.t1.UD0 = 0U; + ee.t2.UD0 = 0U; + ee.t3.UD0 = 0U; + ee.t4.UD0 = 0U; + ee.t5.UD0 = 0U; + ee.t6.UD0 = 0U; + ee.t7.UD0 = 0U; + ee.s0.UD0 = s0; // mset +0x90 + ee.s1.UD0 = s1; + ee.s2.UD0 = s2; + ee.s3.UD0 = 0U; + ee.s4.UD0 = s4; // temp? + ee.s5.UD0 = 0U; + ee.s6.UD0 = 0U; + ee.s7.UD0 = 0U; + ee.t8.UD0 = 0U; + ee.t9.UD0 = 0U; + ee.k0.UD0 = 0U; + ee.k1.UD0 = 0U; + ee.gp.UD0 = 0U; + ee.sp.UD0 = 0x2000000U; + ee.s8.UD0 = 0U; + ee.ra.UD0 = 0xFFFFFFFFU; + + ee.fpr[12].f = tick; + + ee.pc = 0x128918; + while (ee.pc != 0xFFFFFFFFU) + { + if (o1.pfns.ContainsKey(ee.pc) || MobRecUt.Rec1(ee.pc, o1.pfns, ee)) + { + o1.pfns[ee.pc](); + } + else + throw new RecfnnotFound(ee.pc, "rc2"); + } + } + + { + MemoryStream si = new MemoryStream(ee.ram, false); + BinaryReader br = new BinaryReader(si); + + si.Position = Sxyz; + Svec = new float[4 * cnt1]; + for (int a = 0; a < 4 * cnt1; a++) + Svec[a] = br.ReadSingle(); + + si.Position = Rxyz; + Rvec = new float[4 * cnt1]; + for (int a = 0; a < 4 * cnt1; a++) + Rvec[a] = br.ReadSingle(); + + si.Position = Txyz; + Tvec = new float[4 * cnt1]; + for (int a = 0; a < 4 * cnt1; a++) + Tvec[a] = br.ReadSingle(); + } + + cntPass++; + + } + + public void DEB() + { +#if Allow_DEB_eeram01 + MobUt.bitr[0x378368 >> 4] = true; + MobUt.bitr[0x378378 >> 4] = true; + MobUt.bitr[0x378378 >> 4] = true; + MobUt.bitr[0x378398 >> 4] = true; + MobUt.bitr[0x3783a8 >> 4] = true; + MobUt.bitr[0x3783b8 >> 4] = true; + + BitArray bita = MobUt.bita; + BitArray bitr = MobUt.bitr; + if (File.Exists(Path.Combine(Settings.Default.pressdir, "save_DEB.bin"))) { + using (FileStream fsx = File.OpenRead(Path.Combine(Settings.Default.pressdir, "save_DEB.bin"))) { + BinaryFormatter bf = new BinaryFormatter(); + BitArray b; + bita = bita.Or(b = (BitArray)bf.Deserialize(fsx)); + bitr = bitr.Or(b = (BitArray)bf.Deserialize(fsx)); + } + } + + using (FileStream fs = File.Create(Path.Combine(Settings.Default.pressdir, "eeram01.bin"))) { + byte[] noop16 = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; + for (int x = 0; x < 2097152; x++) { + if ((bitr[x] || bitr[Math.Max(0, x - 1)] || bitr[Math.Min(2097152 - 1, x + 1)]) && x < 20 * 1024 * 1024 / 16) { + fs.Write(ee.ram, 16 * x, 16); + } + else { + fs.Write(noop16, 0, 16); + } + } + } + + if (true) { + using (FileStream fsx = File.Create(Path.Combine(Settings.Default.pressdir, "save_DEB.bin"))) { + BinaryFormatter bf = new BinaryFormatter(); + bf.Serialize(fsx, bita); + bf.Serialize(fsx, bitr); + } + } +#endif + } + } + + public partial class Mobrc1 + { + void here(uint pc) { } + + internal SortedDictionary pfns { get { return dicti2a; } } + internal void Init0() { initfns(); } + 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(); + + public static bool Rec1(uint addr, SortedDictionary dicti2a, CustEE ee) + { +#if AllowRec1 + string dirlib = Settings.Default.dirlib; + string flib = Myrec.Getflib(addr, dirlib); + if (!File.Exists(flib)) { + Myrec.Privrec1(addr, new MemoryStream(Uteeram.eeram, false), dirlib); + if (!File.Exists(flib)) return false; + } + + Assembly lib = Assembly.LoadFile(flib); + Type cls1 = lib.GetType("ee1Dec.C.Class1"); + object o = Activator.CreateInstance(cls1, ee); + MethodInfo mi = cls1.GetMethod(LabUt.addr2Funct(addr)); + MobUt.Tx8 tx8 = (MobUt.Tx8)Delegate.CreateDelegate(typeof(MobUt.Tx8), o, mi); + dicti2a[addr] = tx8; + System.Diagnostics.Debug.WriteLine("## " + addr.ToString("X8")); + return true; +#else + return false; +#endif + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Mobrc1.cs b/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Mobrc1.cs index cf1229aaa..0217707f6 100644 --- a/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Mobrc1.cs +++ b/OpenKh.Kh2AnimEmu/Mset/EmuRunner/Mobrc1.cs @@ -1,24821 +1,24821 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset.EmuRunner -{ - public partial class Mobrc1 - { - - private CustEE ee = new CustEE(); - - private SortedDictionary dicti2a = new SortedDictionary(); - - public virtual void funct0011b420() - { - this.ee.pc = 1160272u; - // @0011B420 LUI t7, $0035 - this.ee.t7.SD0 = 3473408; - // @0011B424 ADDIU t7, t7, $4260 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16992))); - // @0011B428 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0011B42C LQ t1, $0010(t7) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); - // @0011B430 LQ t2, $0020(t7) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); - // @0011B434 LQ t3, $0030(t7) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); - // @0011B438 SQ t0, $0000(a0) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a0.UL[0])); - // @0011B43C SQ t1, $0010(a0) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a0.UL[0])); - // @0011B440 SQ t2, $0020(a0) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a0.UL[0])); - // @0011B444 SQ t3, $0030(a0) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.a0.UL[0])); - // @0011B448 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0011B44C NOP - MobUt.Latency(); - } - - public virtual void funct0011b450() - { - this.ee.pc = 1160300u; - // @0011B450 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @0011B454 ADDIU sp, sp, $fff0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); - // @0011B458 SD s0, $0000(sp) - MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @0011B45C C.EQ.S $f12, $f0 - this.ee.fcr31_23 = (this.ee.fpr[12].f == this.ee.fpr[0].f); - // @0011B460 SD ra, $0008(sp) - MobUt.SD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); - // @0011B464 BC1T $0011b484 - if (this.ee.fcr31_23) - { - this.ee.pc = 1160324u; - } - // @0011B468 DADDU s0, a0, zero - this.ee.s0.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0011b46c() - { - this.ee.pc = 1160308u; - // @0011B46C JAL $0011bdc8 - this.ee.ra.UL0 = 1160308u; - this.ee.pc = 1162696u; - // @0011B470 NOP - MobUt.Latency(); - } - - public virtual void funct0011b474() - { - this.ee.pc = 1160324u; - // @0011B474 MOV.S $f12, $f0 - this.ee.fpr[12].f = this.ee.fpr[0].f; - // @0011B478 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0011B47C JAL $002faa58 - this.ee.ra.UL0 = 1160324u; - this.ee.pc = 3123800u; - // @0011B480 DADDU a1, s0, zero - this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0011b484() - { - this.ee.pc = 1160344u; - // @0011B484 DADDU v0, s0, zero - this.ee.v0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0011B488 LD ra, $0008(sp) - MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); - // @0011B48C LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @0011B490 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0011B494 ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct0011b528() - { - this.ee.pc = 1160536u; - // @0011B528 ADDIU sp, sp, $ffe0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); - // @0011B52C SD s0, $0000(sp) - MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @0011B530 SD s1, $0008(sp) - MobUt.SD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); - // @0011B534 SWC1 $f20, $0018(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); - // @0011B538 DADDU s0, a0, zero - this.ee.s0.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); - // @0011B53C SD ra, $0010(sp) - MobUt.SD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - // @0011B540 DADDU s1, a1, zero - this.ee.s1.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - // @0011B544 MTC1 zero, $f20 - this.ee.fpr[20].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @0011B548 LWC1 $f0, $0000(a1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.a1.UL0)); - // @0011B54C C.EQ.S $f0, $f20 - this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[20].f); - // @0011B550 BC1T $0011b570 - if (this.ee.fcr31_23) - { - this.ee.pc = 1160560u; - } - // @0011B554 MOV.S $f12, $f0 - this.ee.fpr[12].f = this.ee.fpr[0].f; - } - - public virtual void funct0011b558() - { - this.ee.pc = 1160544u; - // @0011B558 JAL $0011bdc8 - this.ee.ra.UL0 = 1160544u; - this.ee.pc = 1162696u; - // @0011B55C NOP - MobUt.Latency(); - } - - public virtual void funct0011b560() - { - this.ee.pc = 1160560u; - // @0011B560 MOV.S $f12, $f0 - this.ee.fpr[12].f = this.ee.fpr[0].f; - // @0011B564 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0011B568 JAL $002faa58 - this.ee.ra.UL0 = 1160560u; - this.ee.pc = 3123800u; - // @0011B56C DADDU a1, s0, zero - this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0011b570() - { - this.ee.pc = 1160576u; - // @0011B570 LWC1 $f0, $0004(s1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.s1.UL0)); - // @0011B574 C.EQ.S $f0, $f20 - this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[20].f); - // @0011B578 BC1T $0011b598 - if (this.ee.fcr31_23) - { - this.ee.pc = 1160600u; - } - // @0011B57C MOV.S $f12, $f0 - this.ee.fpr[12].f = this.ee.fpr[0].f; - } - - public virtual void funct0011b580() - { - this.ee.pc = 1160584u; - // @0011B580 JAL $0011bdc8 - this.ee.ra.UL0 = 1160584u; - this.ee.pc = 1162696u; - // @0011B584 NOP - MobUt.Latency(); - } - - public virtual void funct0011b588() - { - this.ee.pc = 1160600u; - // @0011B588 MOV.S $f12, $f0 - this.ee.fpr[12].f = this.ee.fpr[0].f; - // @0011B58C DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0011B590 JAL $002fab00 - this.ee.ra.UL0 = 1160600u; - this.ee.pc = 3123968u; - // @0011B594 DADDU a1, s0, zero - this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0011b598() - { - this.ee.pc = 1160616u; - // @0011B598 LWC1 $f0, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.s1.UL0)); - // @0011B59C C.EQ.S $f0, $f20 - this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[20].f); - // @0011B5A0 BC1T $0011b5c0 - if (this.ee.fcr31_23) - { - this.ee.pc = 1160640u; - } - // @0011B5A4 MOV.S $f12, $f0 - this.ee.fpr[12].f = this.ee.fpr[0].f; - } - - public virtual void funct0011b5a8() - { - this.ee.pc = 1160624u; - // @0011B5A8 JAL $0011bdc8 - this.ee.ra.UL0 = 1160624u; - this.ee.pc = 1162696u; - // @0011B5AC NOP - MobUt.Latency(); - } - - public virtual void funct0011b5b0() - { - this.ee.pc = 1160640u; - // @0011B5B0 MOV.S $f12, $f0 - this.ee.fpr[12].f = this.ee.fpr[0].f; - // @0011B5B4 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0011B5B8 JAL $002fa9b0 - this.ee.ra.UL0 = 1160640u; - this.ee.pc = 3123632u; - // @0011B5BC DADDU a1, s0, zero - this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0011b5c0() - { - this.ee.pc = 1160668u; - // @0011B5C0 DADDU v0, s0, zero - this.ee.v0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0011B5C4 LD s1, $0008(sp) - MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); - // @0011B5C8 LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @0011B5CC LD ra, $0010(sp) - MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - // @0011B5D0 LWC1 $f20, $0018(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); - // @0011B5D4 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0011B5D8 ADDIU sp, sp, $0020 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); - } - - public virtual void funct0011b840() - { - this.ee.pc = 1161332u; - // @0011B840 ADDIU sp, sp, $ffb0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -80))); - // @0011B844 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @0011B848 SD s0, $0030(sp) - MobUt.SD(this.ee, this.ee.s0, (48u + this.ee.sp.UL0)); - // @0011B84C ADDIU t7, t7, $8104 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32508))); - // @0011B850 SD s1, $0038(sp) - MobUt.SD(this.ee, this.ee.s1, (56u + this.ee.sp.UL0)); - // @0011B854 SD ra, $0040(sp) - MobUt.SD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); - // @0011B858 DADDU s0, a0, zero - this.ee.s0.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); - // @0011B85C SWC1 $f20, $0048(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (72u + this.ee.sp.UL0)); - // @0011B860 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @0011B864 LWC1 $f20, $0008(a0) - MobUt.LWC1(this.ee, this.ee.fpr[20], (8u + this.ee.a0.UL0)); - // @0011B868 C.LT.S $f20, $f0 - this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[0].f); - // @0011B86C BC1T $0011b88c - if (this.ee.fcr31_23) - { - this.ee.pc = 1161356u; - } - // @0011B870 DADDU s1, a1, zero - this.ee.s1.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0011b874() - { - this.ee.pc = 1161356u; - // @0011B874 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @0011B878 ADDIU t7, t7, $8108 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32504))); - // @0011B87C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @0011B880 C.LT.S $f0, $f20 - this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[20].f); - // @0011B884 BC1FL $0011b894 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1161364u; - // @0011B888 LWC1 $f13, $0000(s0) - MobUt.LWC1(this.ee, this.ee.fpr[13], (0u + this.ee.s0.UL0)); - } - } - - public virtual void funct0011b88c() - { - this.ee.pc = 1161412u; - // @0011B88C MOV.S $f20, $f0 - this.ee.fpr[20].f = this.ee.fpr[0].f; - // @0011B890 LWC1 $f13, $0000(s0) - MobUt.LWC1(this.ee, this.ee.fpr[13], (0u + this.ee.s0.UL0)); - // @0011B894 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @0011B898 LWC1 $f12, $0004(s0) - MobUt.LWC1(this.ee, this.ee.fpr[12], (4u + this.ee.s0.UL0)); - // @0011B89C ADDIU t7, t7, $810c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32500))); - // @0011B8A0 MULA.S $f13, $f13 - this.ee.fpracc.f = (this.ee.fpr[13].f * this.ee.fpr[13].f); - // @0011B8A4 MADD.S $f0, $f12, $f12 - this.ee.fpr[0].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[12].f, this.ee.fpr[12].f); - // @0011B8A8 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @0011B8AC NOP - MobUt.Latency(); - // @0011B8B0 NOP - MobUt.Latency(); - // @0011B8B4 SQRT.S $f0, $f0 - this.ee.fpr[0].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[0].f)))); - // @0011B8B8 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @0011B8BC BC1F $0011ba50 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1161808u; - } - // @0011B8C0 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - } - - public virtual void funct0011b894() - { - this.ee.pc = 1161412u; - // @0011B894 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @0011B898 LWC1 $f12, $0004(s0) - MobUt.LWC1(this.ee, this.ee.fpr[12], (4u + this.ee.s0.UL0)); - // @0011B89C ADDIU t7, t7, $810c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32500))); - // @0011B8A0 MULA.S $f13, $f13 - this.ee.fpracc.f = (this.ee.fpr[13].f * this.ee.fpr[13].f); - // @0011B8A4 MADD.S $f0, $f12, $f12 - this.ee.fpr[0].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[12].f, this.ee.fpr[12].f); - // @0011B8A8 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @0011B8AC NOP - MobUt.Latency(); - // @0011B8B0 NOP - MobUt.Latency(); - // @0011B8B4 SQRT.S $f0, $f0 - this.ee.fpr[0].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[0].f)))); - // @0011B8B8 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @0011B8BC BC1F $0011ba50 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1161808u; - } - // @0011B8C0 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - } - - public virtual void funct0011b8c4() - { - this.ee.pc = 1161420u; - // @0011B8C4 JAL $002ff8c0 - this.ee.ra.UL0 = 1161420u; - this.ee.pc = 3143872u; - // @0011B8C8 NOP - MobUt.Latency(); - } - - public virtual void funct0011b8cc() - { - this.ee.pc = 1161432u; - // @0011B8CC NEG.S $f12, $f20 - this.ee.fpr[12].f = (0 - this.ee.fpr[20].f); - // @0011B8D0 JAL $002ff8a8 - this.ee.ra.UL0 = 1161432u; - this.ee.pc = 3143848u; - // @0011B8D4 SWC1 $f0, $0028(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (40u + this.ee.sp.UL0)); - } - - public virtual void funct0011b8d8() - { - this.ee.pc = 1161448u; - // @0011B8D8 SWC1 $f0, $0024(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (36u + this.ee.sp.UL0)); - // @0011B8DC LWC1 $f13, $0028(s0) - MobUt.LWC1(this.ee, this.ee.fpr[13], (40u + this.ee.s0.UL0)); - // @0011B8E0 JAL $002ff8c0 - this.ee.ra.UL0 = 1161448u; - this.ee.pc = 3143872u; - // @0011B8E4 LWC1 $f12, $0018(s0) - MobUt.LWC1(this.ee, this.ee.fpr[12], (24u + this.ee.s0.UL0)); - } - - public virtual void funct0011b8e8() - { - this.ee.pc = 1161472u; - // @0011B8E8 MOV.S $f1, $f0 - this.ee.fpr[1].f = this.ee.fpr[0].f; - // @0011B8EC SWC1 $f0, $0020(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (32u + this.ee.sp.UL0)); - // @0011B8F0 LWC1 $f12, $0000(s1) - MobUt.LWC1(this.ee, this.ee.fpr[12], (0u + this.ee.s1.UL0)); - // @0011B8F4 ADDIU s0, sp, $0010 - this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 16))); - // @0011B8F8 JAL $0011bdc8 - this.ee.ra.UL0 = 1161472u; - this.ee.pc = 1162696u; - // @0011B8FC SUB.S $f12, $f1, $f12 - this.ee.fpr[12].f = (this.ee.fpr[1].f - this.ee.fpr[12].f); - } - - public virtual void funct0011b8f0() - { - this.ee.pc = 1161472u; - // @0011B8F0 LWC1 $f12, $0000(s1) - MobUt.LWC1(this.ee, this.ee.fpr[12], (0u + this.ee.s1.UL0)); - // @0011B8F4 ADDIU s0, sp, $0010 - this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 16))); - // @0011B8F8 JAL $0011bdc8 - this.ee.ra.UL0 = 1161472u; - this.ee.pc = 1162696u; - // @0011B8FC SUB.S $f12, $f1, $f12 - this.ee.fpr[12].f = (this.ee.fpr[1].f - this.ee.fpr[12].f); - } - - public virtual void funct0011b900() - { - this.ee.pc = 1161492u; - // @0011B900 LWC1 $f1, $0004(s1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.s1.UL0)); - // @0011B904 LWC1 $f12, $0024(sp) - MobUt.LWC1(this.ee, this.ee.fpr[12], (36u + this.ee.sp.UL0)); - // @0011B908 SWC1 $f0, $0000(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.sp.UL0)); - // @0011B90C JAL $0011bdc8 - this.ee.ra.UL0 = 1161492u; - this.ee.pc = 1162696u; - // @0011B910 SUB.S $f12, $f12, $f1 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[1].f); - } - - public virtual void funct0011b914() - { - this.ee.pc = 1161512u; - // @0011B914 LWC1 $f1, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.s1.UL0)); - // @0011B918 LWC1 $f12, $0028(sp) - MobUt.LWC1(this.ee, this.ee.fpr[12], (40u + this.ee.sp.UL0)); - // @0011B91C SWC1 $f0, $0004(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (4u + this.ee.sp.UL0)); - // @0011B920 JAL $0011bdc8 - this.ee.ra.UL0 = 1161512u; - this.ee.pc = 1162696u; - // @0011B924 SUB.S $f12, $f12, $f1 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[1].f); - } - - public virtual void funct0011b928() - { - this.ee.pc = 1161576u; - // @0011B928 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @0011B92C LWC1 $f1, $0020(sp) - MobUt.LWC1(this.ee, this.ee.fpr[1], (32u + this.ee.sp.UL0)); - // @0011B930 ADDIU t7, t7, $8114 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32492))); - // @0011B934 LWC1 $f2, $0028(sp) - MobUt.LWC1(this.ee, this.ee.fpr[2], (40u + this.ee.sp.UL0)); - // @0011B938 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @0011B93C SWC1 $f0, $0008(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (8u + this.ee.sp.UL0)); - // @0011B940 ADD.S $f2, $f2, $f3 - this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[3].f); - // @0011B944 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @0011B948 LWC1 $f0, $0024(sp) - MobUt.LWC1(this.ee, this.ee.fpr[0], (36u + this.ee.sp.UL0)); - // @0011B94C LWC1 $f12, $0000(s1) - MobUt.LWC1(this.ee, this.ee.fpr[12], (0u + this.ee.s1.UL0)); - // @0011B950 SWC1 $f2, $0028(sp) - MobUt.SWC1(this.ee, this.ee.fpr[2], (40u + this.ee.sp.UL0)); - // @0011B954 SUB.S $f3, $f3, $f0 - this.ee.fpr[3].f = (this.ee.fpr[3].f - this.ee.fpr[0].f); - // @0011B958 SUB.S $f12, $f1, $f12 - this.ee.fpr[12].f = (this.ee.fpr[1].f - this.ee.fpr[12].f); - // @0011B95C SWC1 $f1, $0020(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (32u + this.ee.sp.UL0)); - // @0011B960 JAL $0011bdc8 - this.ee.ra.UL0 = 1161576u; - this.ee.pc = 1162696u; - // @0011B964 SWC1 $f3, $0024(sp) - MobUt.SWC1(this.ee, this.ee.fpr[3], (36u + this.ee.sp.UL0)); - } - - public virtual void funct0011b968() - { - this.ee.pc = 1161596u; - // @0011B968 LWC1 $f1, $0004(s1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.s1.UL0)); - // @0011B96C LWC1 $f12, $0024(sp) - MobUt.LWC1(this.ee, this.ee.fpr[12], (36u + this.ee.sp.UL0)); - // @0011B970 SWC1 $f0, $0010(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.sp.UL0)); - // @0011B974 JAL $0011bdc8 - this.ee.ra.UL0 = 1161596u; - this.ee.pc = 1162696u; - // @0011B978 SUB.S $f12, $f12, $f1 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[1].f); - } - - public virtual void funct0011b97c() - { - this.ee.pc = 1161616u; - // @0011B97C LWC1 $f1, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.s1.UL0)); - // @0011B980 LWC1 $f12, $0028(sp) - MobUt.LWC1(this.ee, this.ee.fpr[12], (40u + this.ee.sp.UL0)); - // @0011B984 SWC1 $f0, $0014(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (20u + this.ee.sp.UL0)); - // @0011B988 JAL $0011bdc8 - this.ee.ra.UL0 = 1161616u; - this.ee.pc = 1162696u; - // @0011B98C SUB.S $f12, $f12, $f1 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[1].f); - } - - public virtual void funct0011b990() - { - this.ee.pc = 1161692u; - // @0011B990 SWC1 $f0, $0018(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (24u + this.ee.sp.UL0)); - // @0011B994 MOV.S $f5, $f0 - this.ee.fpr[5].f = this.ee.fpr[0].f; - // @0011B998 LQC2 vf1, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @0011B99C LQC2 vf2, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.sp.UL0)); - // @0011B9A0 VMUL.xyz vf1, vf1, vf2 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); - // @0011B9A4 VADDy.x vf1, vf1, vf1y - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); - // @0011B9A8 VADDz.x vf1, vf1, vf1z - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); - // @0011B9AC QMFC2 t0, vf1 - MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); - // @0011B9B0 MTC1 t0, $f1 - this.ee.fpr[1].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @0011B9B4 LQC2 vf1, $0000(s0) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s0.UL0)); - // @0011B9B8 LQC2 vf2, $0000(s0) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.s0.UL0)); - // @0011B9BC VMUL.xyz vf1, vf1, vf2 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); - // @0011B9C0 VADDy.x vf1, vf1, vf1y - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); - // @0011B9C4 VADDz.x vf1, vf1, vf1z - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); - // @0011B9C8 QMFC2 t0, vf1 - MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); - // @0011B9CC MTC1 t0, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @0011B9D0 C.LE.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f <= this.ee.fpr[0].f); - // @0011B9D4 BC1F $0011ba20 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1161760u; - } - // @0011B9D8 LWC1 $f2, $0000(sp) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.sp.UL0)); - } - - public virtual void funct0011b9dc() - { - this.ee.pc = 1161760u; - // @0011B9DC LWC1 $f0, $0000(s1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.s1.UL0)); - // @0011B9E0 LWC1 $f3, $0004(s1) - MobUt.LWC1(this.ee, this.ee.fpr[3], (4u + this.ee.s1.UL0)); - // @0011B9E4 ADD.S $f2, $f2, $f0 - this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[0].f); - // @0011B9E8 LWC1 $f4, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[4], (8u + this.ee.s1.UL0)); - // @0011B9EC LWC1 $f1, $0004(sp) - MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.sp.UL0)); - // @0011B9F0 LWC1 $f0, $0008(sp) - MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.sp.UL0)); - // @0011B9F4 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @0011B9F8 ADD.S $f0, $f0, $f4 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[4].f); - // @0011B9FC SWC1 $f2, $0000(s1) - MobUt.SWC1(this.ee, this.ee.fpr[2], (0u + this.ee.s1.UL0)); - // @0011BA00 SWC1 $f1, $0004(s1) - MobUt.SWC1(this.ee, this.ee.fpr[1], (4u + this.ee.s1.UL0)); - // @0011BA04 SWC1 $f0, $0008(s1) - MobUt.SWC1(this.ee, this.ee.fpr[0], (8u + this.ee.s1.UL0)); - // @0011BA08 LD s0, $0030(sp) - MobUt.LD(this.ee, this.ee.s0, (48u + this.ee.sp.UL0)); - // @0011BA0C LD s1, $0038(sp) - MobUt.LD(this.ee, this.ee.s1, (56u + this.ee.sp.UL0)); - // @0011BA10 LD ra, $0040(sp) - MobUt.LD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); - // @0011BA14 LWC1 $f20, $0048(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (72u + this.ee.sp.UL0)); - // @0011BA18 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0011BA1C ADDIU sp, sp, $0050 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 80))); - } - - public virtual void funct0011ba08() - { - this.ee.pc = 1161760u; - // @0011BA08 LD s0, $0030(sp) - MobUt.LD(this.ee, this.ee.s0, (48u + this.ee.sp.UL0)); - // @0011BA0C LD s1, $0038(sp) - MobUt.LD(this.ee, this.ee.s1, (56u + this.ee.sp.UL0)); - // @0011BA10 LD ra, $0040(sp) - MobUt.LD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); - // @0011BA14 LWC1 $f20, $0048(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (72u + this.ee.sp.UL0)); - // @0011BA18 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0011BA1C ADDIU sp, sp, $0050 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 80))); - } - - public virtual void funct0011ba20() - { - this.ee.pc = 1161808u; - // @0011BA20 LWC1 $f3, $0000(s1) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.s1.UL0)); - // @0011BA24 LWC1 $f4, $0004(s1) - MobUt.LWC1(this.ee, this.ee.fpr[4], (4u + this.ee.s1.UL0)); - // @0011BA28 LWC1 $f2, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[2], (8u + this.ee.s1.UL0)); - // @0011BA2C LWC1 $f1, $0010(sp) - MobUt.LWC1(this.ee, this.ee.fpr[1], (16u + this.ee.sp.UL0)); - // @0011BA30 LWC1 $f0, $0014(sp) - MobUt.LWC1(this.ee, this.ee.fpr[0], (20u + this.ee.sp.UL0)); - // @0011BA34 ADD.S $f2, $f5, $f2 - this.ee.fpr[2].f = (this.ee.fpr[5].f + this.ee.fpr[2].f); - // @0011BA38 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @0011BA3C ADD.S $f0, $f0, $f4 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[4].f); - // @0011BA40 SWC1 $f2, $0008(s1) - MobUt.SWC1(this.ee, this.ee.fpr[2], (8u + this.ee.s1.UL0)); - // @0011BA44 SWC1 $f1, $0000(s1) - MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s1.UL0)); - // @0011BA48 BEQ zero, zero, $0011ba08 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1161736u; - } - // @0011BA4C SWC1 $f0, $0004(s1) - MobUt.SWC1(this.ee, this.ee.fpr[0], (4u + this.ee.s1.UL0)); - } - - public virtual void funct0011ba50() - { - this.ee.pc = 1161820u; - // @0011BA50 C.LT.S $f0, $f20 - this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[20].f); - // @0011BA54 BC1F $0011bab0 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1161904u; - } - // @0011BA58 LWC1 $f13, $0014(s0) - MobUt.LWC1(this.ee, this.ee.fpr[13], (20u + this.ee.s0.UL0)); - } - - public virtual void funct0011ba5c() - { - this.ee.pc = 1161832u; - // @0011BA5C LWC1 $f12, $0010(s0) - MobUt.LWC1(this.ee, this.ee.fpr[12], (16u + this.ee.s0.UL0)); - // @0011BA60 JAL $002ff8c0 - this.ee.ra.UL0 = 1161832u; - this.ee.pc = 3143872u; - // @0011BA64 NEG.S $f12, $f12 - this.ee.fpr[12].f = (0 - this.ee.fpr[12].f); - } - - public virtual void funct0011ba68() - { - this.ee.pc = 1161860u; - // @0011BA68 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @0011BA6C NEG.S $f12, $f20 - this.ee.fpr[12].f = (0 - this.ee.fpr[20].f); - // @0011BA70 ADDIU t7, t7, $8110 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32496))); - // @0011BA74 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @0011BA78 MUL.S $f1, $f0, $f1 - this.ee.fpr[1].f = (this.ee.fpr[0].f * this.ee.fpr[1].f); - // @0011BA7C JAL $002ff8a8 - this.ee.ra.UL0 = 1161860u; - this.ee.pc = 3143848u; - // @0011BA80 SWC1 $f1, $0020(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (32u + this.ee.sp.UL0)); - } - - public virtual void funct0011ba84() - { - this.ee.pc = 1161888u; - // @0011BA84 LWC1 $f1, $0020(sp) - MobUt.LWC1(this.ee, this.ee.fpr[1], (32u + this.ee.sp.UL0)); - // @0011BA88 SWC1 $f0, $0024(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (36u + this.ee.sp.UL0)); - // @0011BA8C SWC1 $f1, $0028(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (40u + this.ee.sp.UL0)); - // @0011BA90 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @0011BA94 C.LE.S $f0, $f20 - this.ee.fcr31_23 = (this.ee.fpr[0].f <= this.ee.fpr[20].f); - // @0011BA98 BC1F $0011baa8 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1161896u; - } - // @0011BA9C NEG.S $f0, $f1 - this.ee.fpr[0].f = (0 - this.ee.fpr[1].f); - } - - public virtual void funct0011baa0() - { - this.ee.pc = 1161896u; - // @0011BAA0 BEQ zero, zero, $0011b8f0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1161456u; - } - // @0011BAA4 SWC1 $f1, $0028(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (40u + this.ee.sp.UL0)); - } - - public virtual void funct0011bdc8() - { - this.ee.pc = 1162712u; - // @0011BDC8 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @0011BDCC C.LT.S $f0, $f12 - this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[12].f); - // @0011BDD0 BC1F $0011be24 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1162788u; - } - // @0011BDD4 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct0011bdd8() - { - this.ee.pc = 1162732u; - // @0011BDD8 ADDIU t7, t7, $8120 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32480))); - // @0011BDDC LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @0011BDE0 C.LT.S $f0, $f12 - this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[12].f); - // @0011BDE4 BC1F $0011be1c - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1162780u; - } - // @0011BDE8 NOP - MobUt.Latency(); - } - - public virtual void funct0011bdec() - { - this.ee.pc = 1162780u; - // @0011BDEC MOV.S $f1, $f0 - this.ee.fpr[1].f = this.ee.fpr[0].f; - // @0011BDF0 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @0011BDF4 ADDIU t7, t7, $8124 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32476))); - // @0011BDF8 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @0011BDFC SUB.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - // @0011BE00 C.LT.S $f1, $f12 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[12].f); - // @0011BE04 NOP - MobUt.Latency(); - // @0011BE08 NOP - MobUt.Latency(); - // @0011BE0C NOP - MobUt.Latency(); - // @0011BE10 NOP - MobUt.Latency(); - // @0011BE14 BC1TL $0011be00 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1162752u; - // @0011BE18 SUB.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - } - } - - public virtual void funct0011be00() - { - this.ee.pc = 1162780u; - // @0011BE00 C.LT.S $f1, $f12 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[12].f); - // @0011BE04 NOP - MobUt.Latency(); - // @0011BE08 NOP - MobUt.Latency(); - // @0011BE0C NOP - MobUt.Latency(); - // @0011BE10 NOP - MobUt.Latency(); - // @0011BE14 BC1TL $0011be00 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1162752u; - // @0011BE18 SUB.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - } - } - - public virtual void funct0011be1c() - { - this.ee.pc = 1162788u; - // @0011BE1C JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0011BE20 MOV.S $f0, $f12 - this.ee.fpr[0].f = this.ee.fpr[12].f; - } - - public virtual void funct0011be24() - { - this.ee.pc = 1162812u; - // @0011BE24 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @0011BE28 ADDIU t7, t7, $8128 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32472))); - // @0011BE2C LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @0011BE30 C.LT.S $f12, $f1 - this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[1].f); - // @0011BE34 BC1F $0011be1c - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1162780u; - } - // @0011BE38 NOP - MobUt.Latency(); - } - - public virtual void funct0011be3c() - { - this.ee.pc = 1162840u; - // @0011BE3C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @0011BE40 ADDIU t7, t7, $8124 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32476))); - // @0011BE44 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @0011BE48 ADD.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); - // @0011BE4C C.LT.S $f12, $f1 - this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[1].f); - // @0011BE50 BC1TL $0011be4c - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1162828u; - // @0011BE54 ADD.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); - } - } - - public virtual void funct0011be4c() - { - this.ee.pc = 1162840u; - // @0011BE4C C.LT.S $f12, $f1 - this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[1].f); - // @0011BE50 BC1TL $0011be4c - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1162828u; - // @0011BE54 ADD.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); - } - } - - public virtual void funct0011be58() - { - this.ee.pc = 1162848u; - // @0011BE58 BEQ zero, zero, $0011be1c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1162780u; - } - // @0011BE5C NOP - MobUt.Latency(); - } - - public virtual void funct00120650() - { - this.ee.pc = 1181292u; - // @00120650 LW t7, $0004(a0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); - // @00120654 SLL a1, a1, 2 - MobUt.SLL(this.ee.a1, this.ee.a1, 2); - // @00120658 LW t6, $0018(t7) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t7.UL0)); - // @0012065C ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00120660 ADDU t7, t7, a1 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.a1.SD0))); - // @00120664 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00120668 LWC1 $f0, $0020(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (32u + this.ee.t7.UL0)); - } - - public virtual void funct00120670() - { - this.ee.pc = 1181324u; - // @00120670 LW t7, $0004(a0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); - // @00120674 SLL a1, a1, 2 - MobUt.SLL(this.ee.a1, this.ee.a1, 2); - // @00120678 LW t6, $0018(t7) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t7.UL0)); - // @0012067C ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00120680 ADDU a1, a1, t7 - this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + this.ee.t7.SD0))); - // @00120684 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00120688 LW v0, $0030(a1) - MobUt.LW(this.ee, this.ee.v0, (48u + this.ee.a1.UL0)); - } - - public virtual void funct00120690() - { - this.ee.pc = 1181340u; - // @00120690 LW t7, $0004(a0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); - // @00120694 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00120698 LHU v0, $0010(t7) - MobUt.LHU(this.ee, this.ee.v0, (16u + this.ee.t7.UL0)); - } - - public virtual void funct001206a0() - { - this.ee.pc = 1181372u; - // @001206A0 ADDIU sp, sp, $fff0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); - // @001206A4 LW t6, $0000(a0) - MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.a0.UL0)); - // @001206A8 SD s0, $0000(sp) - MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @001206AC SD ra, $0008(sp) - MobUt.SD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); - // @001206B0 LW v0, $001c(t6) - MobUt.LW(this.ee, this.ee.v0, (28u + this.ee.t6.UL0)); - // @001206B4 JALR ra, v0 - this.ee.ra.UD0 = 1181372u; - this.ee.pc = this.ee.v0.UL0; - // @001206B8 LW s0, $0004(a0) - MobUt.LW(this.ee, this.ee.s0, (4u + this.ee.a0.UL0)); - } - - public virtual void funct001206bc() - { - this.ee.pc = 1181380u; - // @001206BC BEQ v0, zero, $001206cc - if ((this.ee.v0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1181388u; - } - // @001206C0 DADDU t7, zero, zero - this.ee.t7.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001206c4() - { - this.ee.pc = 1181408u; - // @001206C4 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @001206C8 ADDU t7, s0, t7 - this.ee.t7.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t7.SD0))); - // @001206CC LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @001206D0 DADDU v0, t7, zero - this.ee.v0.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); - // @001206D4 LD ra, $0008(sp) - MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); - // @001206D8 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @001206DC ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00124a88() - { - this.ee.pc = 1198900u; - // @00124A88 ADDIU sp, sp, $fe70 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -400))); - // @00124A8C MTC1 zero, $f1 - this.ee.fpr[1].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @00124A90 SWC1 $f25, $018c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[25], (396u + this.ee.sp.UL0)); - // @00124A94 ADDIU t6, sp, $0010 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 16))); - // @00124A98 SWC1 $f23, $0184(sp) - MobUt.SWC1(this.ee, this.ee.fpr[23], (388u + this.ee.sp.UL0)); - // @00124A9C ADDIU t5, sp, $0020 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 32))); - // @00124AA0 SWC1 $f22, $0180(sp) - MobUt.SWC1(this.ee, this.ee.fpr[22], (384u + this.ee.sp.UL0)); - // @00124AA4 SWC1 $f20, $0178(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (376u + this.ee.sp.UL0)); - // @00124AA8 MOV.S $f23, $f12 - this.ee.fpr[23].f = this.ee.fpr[12].f; - // @00124AAC SD s1, $0148(sp) - MobUt.SD(this.ee, this.ee.s1, (328u + this.ee.sp.UL0)); - // @00124AB0 MOV.S $f22, $f13 - this.ee.fpr[22].f = this.ee.fpr[13].f; - // @00124AB4 SD s2, $0150(sp) - MobUt.SD(this.ee, this.ee.s2, (336u + this.ee.sp.UL0)); - // @00124AB8 MOV.S $f20, $f14 - this.ee.fpr[20].f = this.ee.fpr[14].f; - // @00124ABC SD s4, $0160(sp) - MobUt.SD(this.ee, this.ee.s4, (352u + this.ee.sp.UL0)); - // @00124AC0 MOV.S $f25, $f15 - this.ee.fpr[25].f = this.ee.fpr[15].f; - // @00124AC4 SD s5, $0168(sp) - MobUt.SD(this.ee, this.ee.s5, (360u + this.ee.sp.UL0)); - // @00124AC8 SD s0, $0140(sp) - MobUt.SD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); - // @00124ACC DADDU s4, a3, zero - this.ee.s4.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); - // @00124AD0 SD s3, $0158(sp) - MobUt.SD(this.ee, this.ee.s3, (344u + this.ee.sp.UL0)); - // @00124AD4 DADDU s5, a2, zero - this.ee.s5.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); - // @00124AD8 SD ra, $0170(sp) - MobUt.SD(this.ee, this.ee.ra, (368u + this.ee.sp.UL0)); - // @00124ADC DADDU s1, t0, zero - this.ee.s1.UD0 = (this.ee.t0.UD0 + this.ee.r0.UD0); - // @00124AE0 SWC1 $f24, $0188(sp) - MobUt.SWC1(this.ee, this.ee.fpr[24], (392u + this.ee.sp.UL0)); - // @00124AE4 ADDIU s2, sp, $00f0 - this.ee.s2.SD0 = ((int)((this.ee.sp.SD0 + 240))); - // @00124AE8 SWC1 $f21, $017c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[21], (380u + this.ee.sp.UL0)); - // @00124AEC SWC1 $f1, $0000(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.sp.UL0)); - // @00124AF0 SWC1 $f1, $0004(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (4u + this.ee.sp.UL0)); - // @00124AF4 SWC1 $f1, $0008(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (8u + this.ee.sp.UL0)); - // @00124AF8 SWC1 $f1, $000c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (12u + this.ee.sp.UL0)); - // @00124AFC SWC1 $f1, $0010(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (16u + this.ee.sp.UL0)); - // @00124B00 SWC1 $f1, $0014(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (20u + this.ee.sp.UL0)); - // @00124B04 SWC1 $f1, $0018(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (24u + this.ee.sp.UL0)); - // @00124B08 SWC1 $f1, $001c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (28u + this.ee.sp.UL0)); - // @00124B0C SWC1 $f1, $0020(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (32u + this.ee.sp.UL0)); - // @00124B10 SWC1 $f1, $0024(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (36u + this.ee.sp.UL0)); - // @00124B14 SWC1 $f1, $0028(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (40u + this.ee.sp.UL0)); - // @00124B18 SWC1 $f1, $002c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (44u + this.ee.sp.UL0)); - // @00124B1C LQC2 vf1, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); - // @00124B20 LQC2 vf2, $0000(a0) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a0.UL0)); - // @00124B24 VSUB.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); - // @00124B28 SQC2 vf1, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); - // @00124B2C BEQ sp, s2, $00124b3c - if ((this.ee.sp.UD0 == this.ee.s2.UD0)) - { - this.ee.pc = 1198908u; - } - // @00124B30 NOP - MobUt.Latency(); - } - - public virtual void funct00124b34() - { - this.ee.pc = 1198972u; - // @00124B34 LQ t0, $0000(s2) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); - // @00124B38 SQ t0, $0000(sp) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); - // @00124B3C LQC2 vf1, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @00124B40 VMUL.xyz vf2, vf1, vf1 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); - // @00124B44 VADDy.x vf2, vf2, vf2y - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); - // @00124B48 VADDz.x vf2, vf2, vf2z - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); - // @00124B4C VSQRT Q, vf2x - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); - // @00124B50 VWAITQ - MobUt.Latency(); - // @00124B54 CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - // @00124B58 VADDq.x vf2, vf0, Q - this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); - // @00124B5C MTC1 t0, $f24 - this.ee.fpr[24].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00124B60 VNOP - MobUt.Latency(); - // @00124B64 VDIV Q, vf0w, vf2x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); - // @00124B68 VWAITQ - MobUt.Latency(); - // @00124B6C VMULq.xyz vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - // @00124B70 SQC2 vf1, $0000(sp) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @00124B74 BEQ t1, zero, $001250ec - if ((this.ee.t1.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1200364u; - } - // @00124B78 LWC1 $f0, $0004(sp) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.sp.UL0)); - } - - public virtual void funct00124b7c() - { - this.ee.pc = 1198996u; - // @00124B7C LQC2 vf1, $0000(t1) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t1.UL0)); - // @00124B80 LQC2 vf2, $0000(a0) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a0.UL0)); - // @00124B84 VSUB.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); - // @00124B88 SQC2 vf1, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); - // @00124B8C BEQ t6, s2, $00124b9c - if ((this.ee.t6.UD0 == this.ee.s2.UD0)) - { - this.ee.pc = 1199004u; - } - // @00124B90 NOP - MobUt.Latency(); - } - - public virtual void funct00124b94() - { - this.ee.pc = 1199092u; - // @00124B94 LQ t0, $0000(s2) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); - // @00124B98 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @00124B9C LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00124BA0 VMUL.xyz vf2, vf1, vf1 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); - // @00124BA4 VADDy.x vf2, vf2, vf2y - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); - // @00124BA8 VADDz.x vf2, vf2, vf2z - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); - // @00124BAC VSQRT Q, vf2x - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); - // @00124BB0 VWAITQ - MobUt.Latency(); - // @00124BB4 CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - // @00124BB8 VADDq.x vf2, vf0, Q - this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); - // @00124BBC MTC1 t0, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00124BC0 VNOP - MobUt.Latency(); - // @00124BC4 VDIV Q, vf0w, vf2x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); - // @00124BC8 VWAITQ - MobUt.Latency(); - // @00124BCC VMULq.xyz vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - // @00124BD0 SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00124BD4 LQC2 vf1, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @00124BD8 LQC2 vf2, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); - // @00124BDC VSUB.xyzw vf3, vf0, vf0 - this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); - this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); - this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); - this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); - // @00124BE0 VOPMULA.xyz ACC, vf1, vf2 - this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); - this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); - this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); - // @00124BE4 VOPMSUB.xyz vf3, vf2, vf1 - this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); - this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); - this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); - // @00124BE8 SQC2 vf3, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.s2.UL0)); - // @00124BEC BEQ t5, s2, $00124bfc - if ((this.ee.t5.UD0 == this.ee.s2.UD0)) - { - this.ee.pc = 1199100u; - } - // @00124BF0 NOP - MobUt.Latency(); - } - - public virtual void funct00124bf4() - { - this.ee.pc = 1199188u; - // @00124BF4 LQ t0, $0000(s2) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); - // @00124BF8 SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @00124BFC LQC2 vf1, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); - // @00124C00 VMUL.xyz vf2, vf1, vf1 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); - // @00124C04 VADDy.x vf2, vf2, vf2y - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); - // @00124C08 VADDz.x vf2, vf2, vf2z - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); - // @00124C0C VSQRT Q, vf2x - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); - // @00124C10 VWAITQ - MobUt.Latency(); - // @00124C14 CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - // @00124C18 VADDq.x vf2, vf0, Q - this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); - // @00124C1C MTC1 t0, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00124C20 VNOP - MobUt.Latency(); - // @00124C24 VDIV Q, vf0w, vf2x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); - // @00124C28 VWAITQ - MobUt.Latency(); - // @00124C2C VMULq.xyz vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - // @00124C30 SQC2 vf1, $0000(t5) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); - // @00124C34 LQC2 vf1, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); - // @00124C38 LQC2 vf2, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.sp.UL0)); - // @00124C3C VSUB.xyzw vf3, vf0, vf0 - this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); - this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); - this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); - this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); - // @00124C40 VOPMULA.xyz ACC, vf1, vf2 - this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); - this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); - this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); - // @00124C44 VOPMSUB.xyz vf3, vf2, vf1 - this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); - this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); - this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); - // @00124C48 SQC2 vf3, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.s2.UL0)); - // @00124C4C BEQ t6, s2, $00124c5c - if ((this.ee.t6.UD0 == this.ee.s2.UD0)) - { - this.ee.pc = 1199196u; - } - // @00124C50 NOP - MobUt.Latency(); - } - - public virtual void funct00124c54() - { - this.ee.pc = 1199264u; - // @00124C54 LQ t0, $0000(s2) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); - // @00124C58 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @00124C5C LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00124C60 VMUL.xyz vf2, vf1, vf1 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); - // @00124C64 VADDy.x vf2, vf2, vf2y - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); - // @00124C68 VADDz.x vf2, vf2, vf2z - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); - // @00124C6C VSQRT Q, vf2x - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); - // @00124C70 VWAITQ - MobUt.Latency(); - // @00124C74 CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - // @00124C78 VADDq.x vf2, vf0, Q - this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); - // @00124C7C MTC1 t0, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00124C80 VNOP - MobUt.Latency(); - // @00124C84 VDIV Q, vf0w, vf2x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); - // @00124C88 VWAITQ - MobUt.Latency(); - // @00124C8C VMULq.xyz vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - // @00124C90 SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00124C94 ADDIU s3, sp, $0030 - this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 48))); - // @00124C98 BEQ s3, sp, $00124cac - if ((this.ee.s3.UD0 == this.ee.sp.UD0)) - { - this.ee.pc = 1199276u; - } - // @00124C9C ADDIU t7, sp, $0040 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); - } - - public virtual void funct00124c98() - { - this.ee.pc = 1199264u; - // @00124C98 BEQ s3, sp, $00124cac - if ((this.ee.s3.UD0 == this.ee.sp.UD0)) - { - this.ee.pc = 1199276u; - } - // @00124C9C ADDIU t7, sp, $0040 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); - } - - public virtual void funct00124ca0() - { - this.ee.pc = 1199284u; - // @00124CA0 LQ t0, $0000(sp) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); - // @00124CA4 SQ t0, $0000(s3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @00124CA8 ADDIU t7, sp, $0040 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); - // @00124CAC BEQL t7, t6, $00124cc0 - if ((this.ee.t7.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1199296u; - // @00124CB0 ADDIU t7, sp, $0050 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 80))); - } - } - - public virtual void funct00124cb4() - { - this.ee.pc = 1199304u; - // @00124CB4 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @00124CB8 SQ t0, $0000(t7) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @00124CBC ADDIU t7, sp, $0050 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 80))); - // @00124CC0 BEQL t7, t5, $00124cd4 - if ((this.ee.t7.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1199316u; - // @00124CC4 ADDIU t7, sp, $0060 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 96))); - } - } - - public virtual void funct00124cc8() - { - this.ee.pc = 1199336u; - // @00124CC8 LQ t0, $0000(t5) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @00124CCC SQ t0, $0000(t7) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @00124CD0 ADDIU t7, sp, $0060 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 96))); - // @00124CD4 SQC2 vf0, $0000(t7) - MobUt.SQC2(this.ee, this.ee.VF[0], (0u + this.ee.t7.UL0)); - // @00124CD8 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @00124CDC C.EQ.S $f20, $f0 - this.ee.fcr31_23 = (this.ee.fpr[20].f == this.ee.fpr[0].f); - // @00124CE0 BC1T $00124d98 - if (this.ee.fcr31_23) - { - this.ee.pc = 1199512u; - } - // @00124CE4 ADDIU s0, sp, $0070 - this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 112))); - } - - public virtual void funct00124ce8() - { - this.ee.pc = 1199344u; - // @00124CE8 JAL $0011b420 - this.ee.ra.UL0 = 1199344u; - this.ee.pc = 1160224u; - // @00124CEC DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00124cf0() - { - this.ee.pc = 1199356u; - // @00124CF0 MOV.S $f12, $f20 - this.ee.fpr[12].f = this.ee.fpr[20].f; - // @00124CF4 JAL $0011b450 - this.ee.ra.UL0 = 1199356u; - this.ee.pc = 1160272u; - // @00124CF8 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00124cfc() - { - this.ee.pc = 1199480u; - // @00124CFC ADDIU t7, sp, $0100 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 256))); - // @00124D00 LQC2 vf1, $0000(s3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); - // @00124D04 LQC2 vf2, $0010(s3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); - // @00124D08 LQC2 vf3, $0020(s3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); - // @00124D0C LQC2 vf4, $0030(s3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); - // @00124D10 LQC2 vf5, $0000(s0) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s0.UL0)); - // @00124D14 LQC2 vf6, $0010(s0) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.s0.UL0)); - // @00124D18 LQC2 vf7, $0020(s0) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.s0.UL0)); - // @00124D1C LQC2 vf8, $0030(s0) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.s0.UL0)); - // @00124D20 VMULAx.xyzw ACC, vf1, vf5x - // @00124D24 VMADDAy.xyzw ACC, vf2, vf5y - // @00124D28 VMADDAz.xyzw ACC, vf3, vf5z - // @00124D2C VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @00124D30 VMULAx.xyzw ACC, vf1, vf6x - // @00124D34 VMADDAy.xyzw ACC, vf2, vf6y - // @00124D38 VMADDAz.xyzw ACC, vf3, vf6z - // @00124D3C VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @00124D40 VMULAx.xyzw ACC, vf1, vf7x - // @00124D44 VMADDAy.xyzw ACC, vf2, vf7y - // @00124D48 VMADDAz.xyzw ACC, vf3, vf7z - // @00124D4C VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @00124D50 VMULAx.xyzw ACC, vf1, vf8x - // @00124D54 VMADDAy.xyzw ACC, vf2, vf8y - // @00124D58 VMADDAz.xyzw ACC, vf3, vf8z - // @00124D5C VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @00124D60 SQC2 vf5, $0000(t7) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @00124D64 SQC2 vf6, $0010(t7) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); - // @00124D68 SQC2 vf7, $0020(t7) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); - // @00124D6C SQC2 vf8, $0030(t7) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); - // @00124D70 BEQ s3, t7, $00124d98 - if ((this.ee.s3.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1199512u; - } - // @00124D74 NOP - MobUt.Latency(); - } - - public virtual void funct00124d78() - { - this.ee.pc = 1199520u; - // @00124D78 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @00124D7C LQ t1, $0010(t7) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); - // @00124D80 LQ t2, $0020(t7) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); - // @00124D84 LQ t3, $0030(t7) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); - // @00124D88 SQ t0, $0000(s3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @00124D8C SQ t1, $0010(s3) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s3.UL[0])); - // @00124D90 SQ t2, $0020(s3) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s3.UL[0])); - // @00124D94 SQ t3, $0030(s3) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.s3.UL[0])); - // @00124D98 BNEL s1, zero, $00124e04 - if ((this.ee.s1.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1199620u; - // @00124D9C ADD.S $f0, $f23, $f23 - this.ee.fpr[0].f = (this.ee.fpr[23].f + this.ee.fpr[23].f); - } - } - - public virtual void funct00124d98() - { - this.ee.pc = 1199520u; - // @00124D98 BNEL s1, zero, $00124e04 - if ((this.ee.s1.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1199620u; - // @00124D9C ADD.S $f0, $f23, $f23 - this.ee.fpr[0].f = (this.ee.fpr[23].f + this.ee.fpr[23].f); - } - } - - public virtual void funct00124da0() - { - this.ee.pc = 1199528u; - // @00124DA0 BEQ s4, s3, $00124dcc - if ((this.ee.s4.UD0 == this.ee.s3.UD0)) - { - this.ee.pc = 1199564u; - } - // @00124DA4 LD s0, $0140(sp) - MobUt.LD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); - } - - public virtual void funct00124da8() - { - this.ee.pc = 1199620u; - // @00124DA8 LQ t0, $0000(s3) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @00124DAC LQ t1, $0010(s3) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.s3.UL[0])); - // @00124DB0 LQ t2, $0020(s3) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.s3.UL[0])); - // @00124DB4 LQ t3, $0030(s3) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.s3.UL[0])); - // @00124DB8 SQ t0, $0000(s4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s4.UL[0])); - // @00124DBC SQ t1, $0010(s4) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s4.UL[0])); - // @00124DC0 SQ t2, $0020(s4) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s4.UL[0])); - // @00124DC4 SQ t3, $0030(s4) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.s4.UL[0])); - // @00124DC8 LD s0, $0140(sp) - MobUt.LD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); - // @00124DCC LD s1, $0148(sp) - MobUt.LD(this.ee, this.ee.s1, (328u + this.ee.sp.UL0)); - // @00124DD0 LD s2, $0150(sp) - MobUt.LD(this.ee, this.ee.s2, (336u + this.ee.sp.UL0)); - // @00124DD4 LD s3, $0158(sp) - MobUt.LD(this.ee, this.ee.s3, (344u + this.ee.sp.UL0)); - // @00124DD8 LD s4, $0160(sp) - MobUt.LD(this.ee, this.ee.s4, (352u + this.ee.sp.UL0)); - // @00124DDC LD s5, $0168(sp) - MobUt.LD(this.ee, this.ee.s5, (360u + this.ee.sp.UL0)); - // @00124DE0 LD ra, $0170(sp) - MobUt.LD(this.ee, this.ee.ra, (368u + this.ee.sp.UL0)); - // @00124DE4 LWC1 $f25, $018c(sp) - MobUt.LWC1(this.ee, this.ee.fpr[25], (396u + this.ee.sp.UL0)); - // @00124DE8 LWC1 $f24, $0188(sp) - MobUt.LWC1(this.ee, this.ee.fpr[24], (392u + this.ee.sp.UL0)); - // @00124DEC LWC1 $f23, $0184(sp) - MobUt.LWC1(this.ee, this.ee.fpr[23], (388u + this.ee.sp.UL0)); - // @00124DF0 LWC1 $f22, $0180(sp) - MobUt.LWC1(this.ee, this.ee.fpr[22], (384u + this.ee.sp.UL0)); - // @00124DF4 LWC1 $f21, $017c(sp) - MobUt.LWC1(this.ee, this.ee.fpr[21], (380u + this.ee.sp.UL0)); - // @00124DF8 LWC1 $f20, $0178(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (376u + this.ee.sp.UL0)); - // @00124DFC JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00124E00 ADDIU sp, sp, $0190 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 400))); - } - - public virtual void funct00124dcc() - { - this.ee.pc = 1199620u; - // @00124DCC LD s1, $0148(sp) - MobUt.LD(this.ee, this.ee.s1, (328u + this.ee.sp.UL0)); - // @00124DD0 LD s2, $0150(sp) - MobUt.LD(this.ee, this.ee.s2, (336u + this.ee.sp.UL0)); - // @00124DD4 LD s3, $0158(sp) - MobUt.LD(this.ee, this.ee.s3, (344u + this.ee.sp.UL0)); - // @00124DD8 LD s4, $0160(sp) - MobUt.LD(this.ee, this.ee.s4, (352u + this.ee.sp.UL0)); - // @00124DDC LD s5, $0168(sp) - MobUt.LD(this.ee, this.ee.s5, (360u + this.ee.sp.UL0)); - // @00124DE0 LD ra, $0170(sp) - MobUt.LD(this.ee, this.ee.ra, (368u + this.ee.sp.UL0)); - // @00124DE4 LWC1 $f25, $018c(sp) - MobUt.LWC1(this.ee, this.ee.fpr[25], (396u + this.ee.sp.UL0)); - // @00124DE8 LWC1 $f24, $0188(sp) - MobUt.LWC1(this.ee, this.ee.fpr[24], (392u + this.ee.sp.UL0)); - // @00124DEC LWC1 $f23, $0184(sp) - MobUt.LWC1(this.ee, this.ee.fpr[23], (388u + this.ee.sp.UL0)); - // @00124DF0 LWC1 $f22, $0180(sp) - MobUt.LWC1(this.ee, this.ee.fpr[22], (384u + this.ee.sp.UL0)); - // @00124DF4 LWC1 $f21, $017c(sp) - MobUt.LWC1(this.ee, this.ee.fpr[21], (380u + this.ee.sp.UL0)); - // @00124DF8 LWC1 $f20, $0178(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (376u + this.ee.sp.UL0)); - // @00124DFC JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00124E00 ADDIU sp, sp, $0190 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 400))); - } - - public virtual void funct00124e04() - { - this.ee.pc = 1199672u; - // @00124E04 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00124E08 MULA.S $f24, $f24 - this.ee.fpracc.f = (this.ee.fpr[24].f * this.ee.fpr[24].f); - // @00124E0C ADDIU t7, t7, $81f0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); - // @00124E10 MSUBA.S $f23, $f23 - this.ee.fpracc.f = MobUt.MSUB(this.ee.fpracc.f, this.ee.fpr[23].f, this.ee.fpr[23].f); - // @00124E14 MSUB.S $f1, $f22, $f22 - this.ee.fpr[1].f = (this.ee.fpracc.f - - (this.ee.fpr[22].f * this.ee.fpr[22].f)); - // @00124E18 MUL.S $f0, $f0, $f22 - this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[22].f); - // @00124E1C LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @00124E20 NOP - MobUt.Latency(); - // @00124E24 NOP - MobUt.Latency(); - // @00124E28 DIV.S $f21, $f1, $f0 - this.ee.fpr[21].f = (this.ee.fpr[1].f / this.ee.fpr[0].f); - // @00124E2C C.LT.S $f2, $f21 - this.ee.fcr31_23 = (this.ee.fpr[2].f < this.ee.fpr[21].f); - // @00124E30 BC1F $001250d0 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1200336u; - } - // @00124E34 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct00124e38() - { - this.ee.pc = 1199712u; - // @00124E38 MOV.S $f21, $f2 - this.ee.fpr[21].f = this.ee.fpr[2].f; - // @00124E3C MUL.S $f1, $f21, $f21 - this.ee.fpr[1].f = (this.ee.fpr[21].f * this.ee.fpr[21].f); - // @00124E40 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00124E44 ADDIU t7, t7, $81f0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); - // @00124E48 MTC1 zero, $f2 - this.ee.fpr[2].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @00124E4C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00124E50 SUB.S $f20, $f0, $f1 - this.ee.fpr[20].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); - // @00124E54 C.LT.S $f20, $f2 - this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[2].f); - // @00124E58 BC1TL $00124e60 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1199712u; - // @00124E5C MOV.S $f20, $f2 - this.ee.fpr[20].f = this.ee.fpr[2].f; - } - } - - public virtual void funct00124e3c() - { - this.ee.pc = 1199712u; - // @00124E3C MUL.S $f1, $f21, $f21 - this.ee.fpr[1].f = (this.ee.fpr[21].f * this.ee.fpr[21].f); - // @00124E40 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00124E44 ADDIU t7, t7, $81f0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); - // @00124E48 MTC1 zero, $f2 - this.ee.fpr[2].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @00124E4C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00124E50 SUB.S $f20, $f0, $f1 - this.ee.fpr[20].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); - // @00124E54 C.LT.S $f20, $f2 - this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[2].f); - // @00124E58 BC1TL $00124e60 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1199712u; - // @00124E5C MOV.S $f20, $f2 - this.ee.fpr[20].f = this.ee.fpr[2].f; - } - } - - public virtual void funct00124e40() - { - this.ee.pc = 1199712u; - // @00124E40 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00124E44 ADDIU t7, t7, $81f0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); - // @00124E48 MTC1 zero, $f2 - this.ee.fpr[2].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @00124E4C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00124E50 SUB.S $f20, $f0, $f1 - this.ee.fpr[20].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); - // @00124E54 C.LT.S $f20, $f2 - this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[2].f); - // @00124E58 BC1TL $00124e60 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1199712u; - // @00124E5C MOV.S $f20, $f2 - this.ee.fpr[20].f = this.ee.fpr[2].f; - } - } - - public virtual void funct00124e60() - { - this.ee.pc = 1199720u; - // @00124E60 BEQ s5, zero, $001250bc - if ((this.ee.s5.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1200316u; - } - // @00124E64 NOP - MobUt.Latency(); - } - - public virtual void funct00124e68() - { - this.ee.pc = 1199828u; - // @00124E68 NOP - MobUt.Latency(); - // @00124E6C NOP - MobUt.Latency(); - // @00124E70 SQRT.S $f0, $f20 - this.ee.fpr[0].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[20].f)))); - // @00124E74 NEG.S $f20, $f0 - this.ee.fpr[20].f = (0 - this.ee.fpr[0].f); - // @00124E78 SW zero, $0008(s1) - MobUt.SW(this.ee, this.ee.r0, (8u + this.ee.s1.UL0)); - // @00124E7C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00124E80 NEG.S $f0, $f20 - this.ee.fpr[0].f = (0 - this.ee.fpr[20].f); - // @00124E84 ADDIU t7, t7, $81f0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); - // @00124E88 LWC1 $f1, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.s1.UL0)); - // @00124E8C LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @00124E90 C.EQ.S $f25, $f1 - this.ee.fcr31_23 = (this.ee.fpr[25].f == this.ee.fpr[1].f); - // @00124E94 SWC1 $f2, $003c(s1) - MobUt.SWC1(this.ee, this.ee.fpr[2], (60u + this.ee.s1.UL0)); - // @00124E98 SWC1 $f0, $0010(s1) - MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.s1.UL0)); - // @00124E9C SWC1 $f21, $0000(s1) - MobUt.SWC1(this.ee, this.ee.fpr[21], (0u + this.ee.s1.UL0)); - // @00124EA0 SWC1 $f20, $0004(s1) - MobUt.SWC1(this.ee, this.ee.fpr[20], (4u + this.ee.s1.UL0)); - // @00124EA4 SW zero, $000c(s1) - MobUt.SW(this.ee, this.ee.r0, (12u + this.ee.s1.UL0)); - // @00124EA8 SWC1 $f21, $0014(s1) - MobUt.SWC1(this.ee, this.ee.fpr[21], (20u + this.ee.s1.UL0)); - // @00124EAC SW zero, $0018(s1) - MobUt.SW(this.ee, this.ee.r0, (24u + this.ee.s1.UL0)); - // @00124EB0 SW zero, $001c(s1) - MobUt.SW(this.ee, this.ee.r0, (28u + this.ee.s1.UL0)); - // @00124EB4 SW zero, $0020(s1) - MobUt.SW(this.ee, this.ee.r0, (32u + this.ee.s1.UL0)); - // @00124EB8 SW zero, $0024(s1) - MobUt.SW(this.ee, this.ee.r0, (36u + this.ee.s1.UL0)); - // @00124EBC SWC1 $f2, $0028(s1) - MobUt.SWC1(this.ee, this.ee.fpr[2], (40u + this.ee.s1.UL0)); - // @00124EC0 SW zero, $002c(s1) - MobUt.SW(this.ee, this.ee.r0, (44u + this.ee.s1.UL0)); - // @00124EC4 SW zero, $0030(s1) - MobUt.SW(this.ee, this.ee.r0, (48u + this.ee.s1.UL0)); - // @00124EC8 SW zero, $0034(s1) - MobUt.SW(this.ee, this.ee.r0, (52u + this.ee.s1.UL0)); - // @00124ECC BC1T $00124f84 - if (this.ee.fcr31_23) - { - this.ee.pc = 1200004u; - } - // @00124ED0 SW zero, $0038(s1) - MobUt.SW(this.ee, this.ee.r0, (56u + this.ee.s1.UL0)); - } - - public virtual void funct00124e7c() - { - this.ee.pc = 1199828u; - // @00124E7C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00124E80 NEG.S $f0, $f20 - this.ee.fpr[0].f = (0 - this.ee.fpr[20].f); - // @00124E84 ADDIU t7, t7, $81f0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); - // @00124E88 LWC1 $f1, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.s1.UL0)); - // @00124E8C LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @00124E90 C.EQ.S $f25, $f1 - this.ee.fcr31_23 = (this.ee.fpr[25].f == this.ee.fpr[1].f); - // @00124E94 SWC1 $f2, $003c(s1) - MobUt.SWC1(this.ee, this.ee.fpr[2], (60u + this.ee.s1.UL0)); - // @00124E98 SWC1 $f0, $0010(s1) - MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.s1.UL0)); - // @00124E9C SWC1 $f21, $0000(s1) - MobUt.SWC1(this.ee, this.ee.fpr[21], (0u + this.ee.s1.UL0)); - // @00124EA0 SWC1 $f20, $0004(s1) - MobUt.SWC1(this.ee, this.ee.fpr[20], (4u + this.ee.s1.UL0)); - // @00124EA4 SW zero, $000c(s1) - MobUt.SW(this.ee, this.ee.r0, (12u + this.ee.s1.UL0)); - // @00124EA8 SWC1 $f21, $0014(s1) - MobUt.SWC1(this.ee, this.ee.fpr[21], (20u + this.ee.s1.UL0)); - // @00124EAC SW zero, $0018(s1) - MobUt.SW(this.ee, this.ee.r0, (24u + this.ee.s1.UL0)); - // @00124EB0 SW zero, $001c(s1) - MobUt.SW(this.ee, this.ee.r0, (28u + this.ee.s1.UL0)); - // @00124EB4 SW zero, $0020(s1) - MobUt.SW(this.ee, this.ee.r0, (32u + this.ee.s1.UL0)); - // @00124EB8 SW zero, $0024(s1) - MobUt.SW(this.ee, this.ee.r0, (36u + this.ee.s1.UL0)); - // @00124EBC SWC1 $f2, $0028(s1) - MobUt.SWC1(this.ee, this.ee.fpr[2], (40u + this.ee.s1.UL0)); - // @00124EC0 SW zero, $002c(s1) - MobUt.SW(this.ee, this.ee.r0, (44u + this.ee.s1.UL0)); - // @00124EC4 SW zero, $0030(s1) - MobUt.SW(this.ee, this.ee.r0, (48u + this.ee.s1.UL0)); - // @00124EC8 SW zero, $0034(s1) - MobUt.SW(this.ee, this.ee.r0, (52u + this.ee.s1.UL0)); - // @00124ECC BC1T $00124f84 - if (this.ee.fcr31_23) - { - this.ee.pc = 1200004u; - } - // @00124ED0 SW zero, $0038(s1) - MobUt.SW(this.ee, this.ee.r0, (56u + this.ee.s1.UL0)); - } - - public virtual void funct00124ed4() - { - this.ee.pc = 1199840u; - // @00124ED4 ADDIU s0, sp, $0070 - this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 112))); - // @00124ED8 JAL $0011b420 - this.ee.ra.UL0 = 1199840u; - this.ee.pc = 1160224u; - // @00124EDC DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00124ee0() - { - this.ee.pc = 1199852u; - // @00124EE0 MOV.S $f12, $f25 - this.ee.fpr[12].f = this.ee.fpr[25].f; - // @00124EE4 JAL $0011b450 - this.ee.ra.UL0 = 1199852u; - this.ee.pc = 1160272u; - // @00124EE8 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00124eec() - { - this.ee.pc = 1199972u; - // @00124EEC LQC2 vf1, $0000(s1) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s1.UL0)); - // @00124EF0 LQC2 vf2, $0010(s1) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s1.UL0)); - // @00124EF4 LQC2 vf3, $0020(s1) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s1.UL0)); - // @00124EF8 LQC2 vf4, $0030(s1) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s1.UL0)); - // @00124EFC LQC2 vf5, $0000(s0) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s0.UL0)); - // @00124F00 LQC2 vf6, $0010(s0) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.s0.UL0)); - // @00124F04 LQC2 vf7, $0020(s0) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.s0.UL0)); - // @00124F08 LQC2 vf8, $0030(s0) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.s0.UL0)); - // @00124F0C VMULAx.xyzw ACC, vf1, vf5x - // @00124F10 VMADDAy.xyzw ACC, vf2, vf5y - // @00124F14 VMADDAz.xyzw ACC, vf3, vf5z - // @00124F18 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @00124F1C VMULAx.xyzw ACC, vf1, vf6x - // @00124F20 VMADDAy.xyzw ACC, vf2, vf6y - // @00124F24 VMADDAz.xyzw ACC, vf3, vf6z - // @00124F28 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @00124F2C VMULAx.xyzw ACC, vf1, vf7x - // @00124F30 VMADDAy.xyzw ACC, vf2, vf7y - // @00124F34 VMADDAz.xyzw ACC, vf3, vf7z - // @00124F38 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @00124F3C VMULAx.xyzw ACC, vf1, vf8x - // @00124F40 VMADDAy.xyzw ACC, vf2, vf8y - // @00124F44 VMADDAz.xyzw ACC, vf3, vf8z - // @00124F48 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @00124F4C SQC2 vf5, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s2.UL0)); - // @00124F50 SQC2 vf6, $0010(s2) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.s2.UL0)); - // @00124F54 SQC2 vf7, $0020(s2) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.s2.UL0)); - // @00124F58 SQC2 vf8, $0030(s2) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.s2.UL0)); - // @00124F5C BEQL s1, s2, $00124f88 - if ((this.ee.s1.UD0 == this.ee.s2.UD0)) - { - this.ee.pc = 1200008u; - // @00124F60 MUL.S $f2, $f22, $f21 - this.ee.fpr[2].f = (this.ee.fpr[22].f * this.ee.fpr[21].f); - } - } - - public virtual void funct00124f64() - { - this.ee.pc = 1200276u; - // @00124F64 LQ t0, $0000(s2) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); - // @00124F68 LQ t1, $0010(s2) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.s2.UL[0])); - // @00124F6C LQ t2, $0020(s2) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.s2.UL[0])); - // @00124F70 LQ t3, $0030(s2) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.s2.UL[0])); - // @00124F74 SQ t0, $0000(s1) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s1.UL[0])); - // @00124F78 SQ t1, $0010(s1) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s1.UL[0])); - // @00124F7C SQ t2, $0020(s1) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s1.UL[0])); - // @00124F80 SQ t3, $0030(s1) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.s1.UL[0])); - // @00124F84 MUL.S $f2, $f22, $f21 - this.ee.fpr[2].f = (this.ee.fpr[22].f * this.ee.fpr[21].f); - // @00124F88 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00124F8C MUL.S $f1, $f22, $f20 - this.ee.fpr[1].f = (this.ee.fpr[22].f * this.ee.fpr[20].f); - // @00124F90 ADDIU t7, t7, $81f0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); - // @00124F94 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00124F98 SW zero, $00b8(sp) - MobUt.SW(this.ee, this.ee.r0, (184u + this.ee.sp.UL0)); - // @00124F9C ADD.S $f2, $f23, $f2 - this.ee.fpr[2].f = (this.ee.fpr[23].f + this.ee.fpr[2].f); - // @00124FA0 ADDIU t7, sp, $00b0 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 176))); - // @00124FA4 NEG.S $f1, $f1 - this.ee.fpr[1].f = (0 - this.ee.fpr[1].f); - // @00124FA8 SWC1 $f0, $00ec(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (236u + this.ee.sp.UL0)); - // @00124FAC SWC1 $f0, $00d8(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (216u + this.ee.sp.UL0)); - // @00124FB0 MUL.S $f2, $f2, $f24 - this.ee.fpr[2].f = (this.ee.fpr[2].f * this.ee.fpr[24].f); - // @00124FB4 MUL.S $f1, $f1, $f24 - this.ee.fpr[1].f = (this.ee.fpr[1].f * this.ee.fpr[24].f); - // @00124FB8 SW zero, $00bc(sp) - MobUt.SW(this.ee, this.ee.r0, (188u + this.ee.sp.UL0)); - // @00124FBC SW zero, $00c8(sp) - MobUt.SW(this.ee, this.ee.r0, (200u + this.ee.sp.UL0)); - // @00124FC0 MULA.S $f2, $f2 - this.ee.fpracc.f = (this.ee.fpr[2].f * this.ee.fpr[2].f); - // @00124FC4 MADD.S $f0, $f1, $f1 - this.ee.fpr[0].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[1].f, this.ee.fpr[1].f); - // @00124FC8 SW zero, $00cc(sp) - MobUt.SW(this.ee, this.ee.r0, (204u + this.ee.sp.UL0)); - // @00124FCC SW zero, $00d0(sp) - MobUt.SW(this.ee, this.ee.r0, (208u + this.ee.sp.UL0)); - // @00124FD0 SW zero, $00d4(sp) - MobUt.SW(this.ee, this.ee.r0, (212u + this.ee.sp.UL0)); - // @00124FD4 NOP - MobUt.Latency(); - // @00124FD8 NOP - MobUt.Latency(); - // @00124FDC SQRT.S $f0, $f0 - this.ee.fpr[0].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[0].f)))); - // @00124FE0 SW zero, $00dc(sp) - MobUt.SW(this.ee, this.ee.r0, (220u + this.ee.sp.UL0)); - // @00124FE4 SW zero, $00e0(sp) - MobUt.SW(this.ee, this.ee.r0, (224u + this.ee.sp.UL0)); - // @00124FE8 SW zero, $00e4(sp) - MobUt.SW(this.ee, this.ee.r0, (228u + this.ee.sp.UL0)); - // @00124FEC SW zero, $00e8(sp) - MobUt.SW(this.ee, this.ee.r0, (232u + this.ee.sp.UL0)); - // @00124FF0 NOP - MobUt.Latency(); - // @00124FF4 NOP - MobUt.Latency(); - // @00124FF8 DIV.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f / this.ee.fpr[0].f); - // @00124FFC NOP - MobUt.Latency(); - // @00125000 NOP - MobUt.Latency(); - // @00125004 DIV.S $f2, $f2, $f0 - this.ee.fpr[2].f = (this.ee.fpr[2].f / this.ee.fpr[0].f); - // @00125008 NEG.S $f3, $f1 - this.ee.fpr[3].f = (0 - this.ee.fpr[1].f); - // @0012500C SWC1 $f1, $00b4(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (180u + this.ee.sp.UL0)); - // @00125010 SWC1 $f3, $00c0(sp) - MobUt.SWC1(this.ee, this.ee.fpr[3], (192u + this.ee.sp.UL0)); - // @00125014 SWC1 $f2, $00c4(sp) - MobUt.SWC1(this.ee, this.ee.fpr[2], (196u + this.ee.sp.UL0)); - // @00125018 SWC1 $f2, $00b0(sp) - MobUt.SWC1(this.ee, this.ee.fpr[2], (176u + this.ee.sp.UL0)); - // @0012501C LQC2 vf1, $0000(s3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); - // @00125020 LQC2 vf2, $0010(s3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); - // @00125024 LQC2 vf3, $0020(s3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); - // @00125028 LQC2 vf4, $0030(s3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); - // @0012502C LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @00125030 LQC2 vf6, $0010(t7) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); - // @00125034 LQC2 vf7, $0020(t7) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); - // @00125038 LQC2 vf8, $0030(t7) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); - // @0012503C VMULAx.xyzw ACC, vf1, vf5x - // @00125040 VMADDAy.xyzw ACC, vf2, vf5y - // @00125044 VMADDAz.xyzw ACC, vf3, vf5z - // @00125048 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012504C VMULAx.xyzw ACC, vf1, vf6x - // @00125050 VMADDAy.xyzw ACC, vf2, vf6y - // @00125054 VMADDAz.xyzw ACC, vf3, vf6z - // @00125058 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012505C VMULAx.xyzw ACC, vf1, vf7x - // @00125060 VMADDAy.xyzw ACC, vf2, vf7y - // @00125064 VMADDAz.xyzw ACC, vf3, vf7z - // @00125068 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012506C VMULAx.xyzw ACC, vf1, vf8x - // @00125070 VMADDAy.xyzw ACC, vf2, vf8y - // @00125074 VMADDAz.xyzw ACC, vf3, vf8z - // @00125078 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012507C SQC2 vf5, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s2.UL0)); - // @00125080 SQC2 vf6, $0010(s2) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.s2.UL0)); - // @00125084 SQC2 vf7, $0020(s2) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.s2.UL0)); - // @00125088 SQC2 vf8, $0030(s2) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.s2.UL0)); - // @0012508C BEQL s4, s2, $00124dcc - if ((this.ee.s4.UD0 == this.ee.s2.UD0)) - { - this.ee.pc = 1199564u; - // @00125090 LD s0, $0140(sp) - MobUt.LD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); - } - } - - public virtual void funct00124f84() - { - this.ee.pc = 1200276u; - // @00124F84 MUL.S $f2, $f22, $f21 - this.ee.fpr[2].f = (this.ee.fpr[22].f * this.ee.fpr[21].f); - // @00124F88 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00124F8C MUL.S $f1, $f22, $f20 - this.ee.fpr[1].f = (this.ee.fpr[22].f * this.ee.fpr[20].f); - // @00124F90 ADDIU t7, t7, $81f0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); - // @00124F94 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00124F98 SW zero, $00b8(sp) - MobUt.SW(this.ee, this.ee.r0, (184u + this.ee.sp.UL0)); - // @00124F9C ADD.S $f2, $f23, $f2 - this.ee.fpr[2].f = (this.ee.fpr[23].f + this.ee.fpr[2].f); - // @00124FA0 ADDIU t7, sp, $00b0 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 176))); - // @00124FA4 NEG.S $f1, $f1 - this.ee.fpr[1].f = (0 - this.ee.fpr[1].f); - // @00124FA8 SWC1 $f0, $00ec(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (236u + this.ee.sp.UL0)); - // @00124FAC SWC1 $f0, $00d8(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (216u + this.ee.sp.UL0)); - // @00124FB0 MUL.S $f2, $f2, $f24 - this.ee.fpr[2].f = (this.ee.fpr[2].f * this.ee.fpr[24].f); - // @00124FB4 MUL.S $f1, $f1, $f24 - this.ee.fpr[1].f = (this.ee.fpr[1].f * this.ee.fpr[24].f); - // @00124FB8 SW zero, $00bc(sp) - MobUt.SW(this.ee, this.ee.r0, (188u + this.ee.sp.UL0)); - // @00124FBC SW zero, $00c8(sp) - MobUt.SW(this.ee, this.ee.r0, (200u + this.ee.sp.UL0)); - // @00124FC0 MULA.S $f2, $f2 - this.ee.fpracc.f = (this.ee.fpr[2].f * this.ee.fpr[2].f); - // @00124FC4 MADD.S $f0, $f1, $f1 - this.ee.fpr[0].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[1].f, this.ee.fpr[1].f); - // @00124FC8 SW zero, $00cc(sp) - MobUt.SW(this.ee, this.ee.r0, (204u + this.ee.sp.UL0)); - // @00124FCC SW zero, $00d0(sp) - MobUt.SW(this.ee, this.ee.r0, (208u + this.ee.sp.UL0)); - // @00124FD0 SW zero, $00d4(sp) - MobUt.SW(this.ee, this.ee.r0, (212u + this.ee.sp.UL0)); - // @00124FD4 NOP - MobUt.Latency(); - // @00124FD8 NOP - MobUt.Latency(); - // @00124FDC SQRT.S $f0, $f0 - this.ee.fpr[0].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[0].f)))); - // @00124FE0 SW zero, $00dc(sp) - MobUt.SW(this.ee, this.ee.r0, (220u + this.ee.sp.UL0)); - // @00124FE4 SW zero, $00e0(sp) - MobUt.SW(this.ee, this.ee.r0, (224u + this.ee.sp.UL0)); - // @00124FE8 SW zero, $00e4(sp) - MobUt.SW(this.ee, this.ee.r0, (228u + this.ee.sp.UL0)); - // @00124FEC SW zero, $00e8(sp) - MobUt.SW(this.ee, this.ee.r0, (232u + this.ee.sp.UL0)); - // @00124FF0 NOP - MobUt.Latency(); - // @00124FF4 NOP - MobUt.Latency(); - // @00124FF8 DIV.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f / this.ee.fpr[0].f); - // @00124FFC NOP - MobUt.Latency(); - // @00125000 NOP - MobUt.Latency(); - // @00125004 DIV.S $f2, $f2, $f0 - this.ee.fpr[2].f = (this.ee.fpr[2].f / this.ee.fpr[0].f); - // @00125008 NEG.S $f3, $f1 - this.ee.fpr[3].f = (0 - this.ee.fpr[1].f); - // @0012500C SWC1 $f1, $00b4(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (180u + this.ee.sp.UL0)); - // @00125010 SWC1 $f3, $00c0(sp) - MobUt.SWC1(this.ee, this.ee.fpr[3], (192u + this.ee.sp.UL0)); - // @00125014 SWC1 $f2, $00c4(sp) - MobUt.SWC1(this.ee, this.ee.fpr[2], (196u + this.ee.sp.UL0)); - // @00125018 SWC1 $f2, $00b0(sp) - MobUt.SWC1(this.ee, this.ee.fpr[2], (176u + this.ee.sp.UL0)); - // @0012501C LQC2 vf1, $0000(s3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); - // @00125020 LQC2 vf2, $0010(s3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); - // @00125024 LQC2 vf3, $0020(s3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); - // @00125028 LQC2 vf4, $0030(s3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); - // @0012502C LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @00125030 LQC2 vf6, $0010(t7) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); - // @00125034 LQC2 vf7, $0020(t7) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); - // @00125038 LQC2 vf8, $0030(t7) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); - // @0012503C VMULAx.xyzw ACC, vf1, vf5x - // @00125040 VMADDAy.xyzw ACC, vf2, vf5y - // @00125044 VMADDAz.xyzw ACC, vf3, vf5z - // @00125048 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012504C VMULAx.xyzw ACC, vf1, vf6x - // @00125050 VMADDAy.xyzw ACC, vf2, vf6y - // @00125054 VMADDAz.xyzw ACC, vf3, vf6z - // @00125058 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012505C VMULAx.xyzw ACC, vf1, vf7x - // @00125060 VMADDAy.xyzw ACC, vf2, vf7y - // @00125064 VMADDAz.xyzw ACC, vf3, vf7z - // @00125068 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012506C VMULAx.xyzw ACC, vf1, vf8x - // @00125070 VMADDAy.xyzw ACC, vf2, vf8y - // @00125074 VMADDAz.xyzw ACC, vf3, vf8z - // @00125078 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012507C SQC2 vf5, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s2.UL0)); - // @00125080 SQC2 vf6, $0010(s2) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.s2.UL0)); - // @00125084 SQC2 vf7, $0020(s2) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.s2.UL0)); - // @00125088 SQC2 vf8, $0030(s2) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.s2.UL0)); - // @0012508C BEQL s4, s2, $00124dcc - if ((this.ee.s4.UD0 == this.ee.s2.UD0)) - { - this.ee.pc = 1199564u; - // @00125090 LD s0, $0140(sp) - MobUt.LD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); - } - } - - public virtual void funct00125094() - { - this.ee.pc = 1200316u; - // @00125094 LQ t0, $0000(s2) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); - // @00125098 LQ t1, $0010(s2) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.s2.UL[0])); - // @0012509C LQ t2, $0020(s2) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.s2.UL[0])); - // @001250A0 LQ t3, $0030(s2) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.s2.UL[0])); - // @001250A4 SQ t0, $0000(s4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s4.UL[0])); - // @001250A8 SQ t1, $0010(s4) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s4.UL[0])); - // @001250AC SQ t2, $0020(s4) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s4.UL[0])); - // @001250B0 SQ t3, $0030(s4) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.s4.UL[0])); - // @001250B4 BEQ zero, zero, $00124dcc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1199564u; - } - // @001250B8 LD s0, $0140(sp) - MobUt.LD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); - } - - public virtual void funct001250bc() - { - this.ee.pc = 1200336u; - // @001250BC NOP - MobUt.Latency(); - // @001250C0 NOP - MobUt.Latency(); - // @001250C4 SQRT.S $f20, $f20 - this.ee.fpr[20].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[20].f)))); - // @001250C8 BEQ zero, zero, $00124e7c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1199740u; - } - // @001250CC SW zero, $0008(s1) - MobUt.SW(this.ee, this.ee.r0, (8u + this.ee.s1.UL0)); - } - - public virtual void funct001250d0() - { - this.ee.pc = 1200356u; - // @001250D0 ADDIU t7, t7, $81f4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32268))); - // @001250D4 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @001250D8 C.LT.S $f21, $f0 - this.ee.fcr31_23 = (this.ee.fpr[21].f < this.ee.fpr[0].f); - // @001250DC BC1TL $00124e3c - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1199676u; - // @001250E0 MOV.S $f21, $f0 - this.ee.fpr[21].f = this.ee.fpr[0].f; - } - } - - public virtual void funct001250e4() - { - this.ee.pc = 1200364u; - // @001250E4 BEQ zero, zero, $00124e40 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1199680u; - } - // @001250E8 MUL.S $f1, $f21, $f21 - this.ee.fpr[1].f = (this.ee.fpr[21].f * this.ee.fpr[21].f); - } - - public virtual void funct001250ec() - { - this.ee.pc = 1200472u; - // @001250EC SWC1 $f1, $0018(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (24u + this.ee.sp.UL0)); - // @001250F0 NEG.S $f0, $f0 - this.ee.fpr[0].f = (0 - this.ee.fpr[0].f); - // @001250F4 LWC1 $f1, $0000(sp) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.sp.UL0)); - // @001250F8 SWC1 $f1, $0014(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (20u + this.ee.sp.UL0)); - // @001250FC SWC1 $f0, $0010(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.sp.UL0)); - // @00125100 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00125104 VMUL.xyz vf2, vf1, vf1 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); - // @00125108 VADDy.x vf2, vf2, vf2y - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); - // @0012510C VADDz.x vf2, vf2, vf2z - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); - // @00125110 VSQRT Q, vf2x - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); - // @00125114 VWAITQ - MobUt.Latency(); - // @00125118 CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - // @0012511C VADDq.x vf2, vf0, Q - this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); - // @00125120 MTC1 t0, $f1 - this.ee.fpr[1].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00125124 VNOP - MobUt.Latency(); - // @00125128 VDIV Q, vf0w, vf2x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); - // @0012512C VWAITQ - MobUt.Latency(); - // @00125130 VMULq.xyz vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - // @00125134 SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00125138 LQC2 vf1, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @0012513C LQC2 vf2, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); - // @00125140 VSUB.xyzw vf3, vf0, vf0 - this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); - this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); - this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); - this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); - // @00125144 VOPMULA.xyz ACC, vf1, vf2 - this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); - this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); - this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); - // @00125148 VOPMSUB.xyz vf3, vf2, vf1 - this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); - this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); - this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); - // @0012514C SQC2 vf3, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.s2.UL0)); - // @00125150 BEQ t5, s2, $00125160 - if ((this.ee.t5.UD0 == this.ee.s2.UD0)) - { - this.ee.pc = 1200480u; - } - // @00125154 NOP - MobUt.Latency(); - } - - public virtual void funct00125158() - { - this.ee.pc = 1200544u; - // @00125158 LQ t0, $0000(s2) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); - // @0012515C SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @00125160 LQC2 vf1, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); - // @00125164 VMUL.xyz vf2, vf1, vf1 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); - // @00125168 VADDy.x vf2, vf2, vf2y - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); - // @0012516C VADDz.x vf2, vf2, vf2z - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); - // @00125170 VSQRT Q, vf2x - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); - // @00125174 VWAITQ - MobUt.Latency(); - // @00125178 CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - // @0012517C VADDq.x vf2, vf0, Q - this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); - // @00125180 MTC1 t0, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00125184 VNOP - MobUt.Latency(); - // @00125188 VDIV Q, vf0w, vf2x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); - // @0012518C VWAITQ - MobUt.Latency(); - // @00125190 VMULq.xyz vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - // @00125194 SQC2 vf1, $0000(t5) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); - // @00125198 BEQ zero, zero, $00124c98 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1199256u; - } - // @0012519C ADDIU s3, sp, $0030 - this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 48))); - } - - public virtual void funct00127e20() - { - this.ee.pc = 1212020u; - // @00127E20 ADDIU sp, sp, $ff60 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -160))); - // @00127E24 DADDU v0, zero, zero - this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00127E28 SD s1, $0048(sp) - MobUt.SD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); - // @00127E2C SD s3, $0058(sp) - MobUt.SD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); - // @00127E30 SD s0, $0040(sp) - MobUt.SD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); - // @00127E34 DADDU s1, a1, zero - this.ee.s1.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - // @00127E38 SD s2, $0050(sp) - MobUt.SD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); - // @00127E3C SD s4, $0060(sp) - MobUt.SD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); - // @00127E40 SD s5, $0068(sp) - MobUt.SD(this.ee, this.ee.s5, (104u + this.ee.sp.UL0)); - // @00127E44 SD s6, $0070(sp) - MobUt.SD(this.ee, this.ee.s6, (112u + this.ee.sp.UL0)); - // @00127E48 SD s7, $0078(sp) - MobUt.SD(this.ee, this.ee.s7, (120u + this.ee.sp.UL0)); - // @00127E4C SD s8, $0080(sp) - MobUt.SD(this.ee, this.ee.s8, (128u + this.ee.sp.UL0)); - // @00127E50 SD ra, $0088(sp) - MobUt.SD(this.ee, this.ee.ra, (136u + this.ee.sp.UL0)); - // @00127E54 SWC1 $f23, $009c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[23], (156u + this.ee.sp.UL0)); - // @00127E58 SWC1 $f22, $0098(sp) - MobUt.SWC1(this.ee, this.ee.fpr[22], (152u + this.ee.sp.UL0)); - // @00127E5C SWC1 $f21, $0094(sp) - MobUt.SWC1(this.ee, this.ee.fpr[21], (148u + this.ee.sp.UL0)); - // @00127E60 SWC1 $f20, $0090(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (144u + this.ee.sp.UL0)); - // @00127E64 LD t6, $0000(a1) - MobUt.LD(this.ee, this.ee.t6, (0u + this.ee.a1.UL0)); - // @00127E68 ANDI t7, t6, $0007 - this.ee.t7.UD0 = ((ushort)((this.ee.t6.US0 & 7))); - // @00127E6C BEQ t7, zero, $00128254 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213012u; - } - // @00127E70 DADDU s3, a3, zero - this.ee.s3.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00127e74() - { - this.ee.pc = 1212032u; - // @00127E74 ANDI t7, t6, $0008 - this.ee.t7.UD0 = ((ushort)((this.ee.t6.US0 & 8))); - // @00127E78 BNE t7, zero, $00128254 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1213012u; - } - // @00127E7C NOP - MobUt.Latency(); - } - - public virtual void funct00127e80() - { - this.ee.pc = 1212040u; - // @00127E80 BEQ sp, a2, $00127e94 - if ((this.ee.sp.UD0 == this.ee.a2.UD0)) - { - this.ee.pc = 1212052u; - } - // @00127E84 ADDIU s2, sp, $0010 - this.ee.s2.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00127e88() - { - this.ee.pc = 1212080u; - // @00127E88 LQ t0, $0000(a2) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a2.UL[0])); - // @00127E8C SQ t0, $0000(sp) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); - // @00127E90 ADDIU s2, sp, $0010 - this.ee.s2.SD0 = ((int)((this.ee.sp.SD0 + 16))); - // @00127E94 ADDIU s0, sp, $0020 - this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 32))); - // @00127E98 LQC2 vf1, $0000(s3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); - // @00127E9C LQC2 vf2, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.sp.UL0)); - // @00127EA0 VSUB.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); - // @00127EA4 SQC2 vf1, $0000(s0) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s0.UL0)); - // @00127EA8 BEQL s2, s0, $00127ebc - if ((this.ee.s2.UD0 == this.ee.s0.UD0)) - { - this.ee.pc = 1212092u; - // @00127EAC LD t3, $0000(s1) - MobUt.LD(this.ee, this.ee.t3, (0u + this.ee.s1.UL0)); - } - } - - public virtual void funct00127e94() - { - this.ee.pc = 1212080u; - // @00127E94 ADDIU s0, sp, $0020 - this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 32))); - // @00127E98 LQC2 vf1, $0000(s3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); - // @00127E9C LQC2 vf2, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.sp.UL0)); - // @00127EA0 VSUB.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); - // @00127EA4 SQC2 vf1, $0000(s0) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s0.UL0)); - // @00127EA8 BEQL s2, s0, $00127ebc - if ((this.ee.s2.UD0 == this.ee.s0.UD0)) - { - this.ee.pc = 1212092u; - // @00127EAC LD t3, $0000(s1) - MobUt.LD(this.ee, this.ee.t3, (0u + this.ee.s1.UL0)); - } - } - - public virtual void funct00127eb0() - { - this.ee.pc = 1212108u; - // @00127EB0 LQ t0, $0000(s0) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s0.UL[0])); - // @00127EB4 SQ t0, $0000(s2) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); - // @00127EB8 LD t3, $0000(s1) - MobUt.LD(this.ee, this.ee.t3, (0u + this.ee.s1.UL0)); - // @00127EBC ADDIU t7, zero, $0001 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @00127EC0 ANDI t6, t3, $0007 - this.ee.t6.UD0 = ((ushort)((this.ee.t3.US0 & 7))); - // @00127EC4 BNEL t6, t7, $00128020 - if ((this.ee.t6.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1212448u; - // @00127EC8 LWC1 $f1, $000c(s1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (12u + this.ee.s1.UL0)); - } - } - - public virtual void funct00127ecc() - { - this.ee.pc = 1212164u; - // @00127ECC LWC1 $f21, $0010(s1) - MobUt.LWC1(this.ee, this.ee.fpr[21], (16u + this.ee.s1.UL0)); - // @00127ED0 LQC2 vf1, $0000(s2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); - // @00127ED4 VMUL.xyz vf1, vf1, vf1 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); - // @00127ED8 VADDy.x vf1, vf1, vf1y - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); - // @00127EDC VADDz.x vf1, vf1, vf1z - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); - // @00127EE0 VSQRT Q, vf1x - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[1].x)))); - // @00127EE4 VWAITQ - MobUt.Latency(); - // @00127EE8 CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - // @00127EEC MTC1 t0, $f2 - this.ee.fpr[2].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00127EF0 LWC1 $f12, $000c(s1) - MobUt.LWC1(this.ee, this.ee.fpr[12], (12u + this.ee.s1.UL0)); - // @00127EF4 MTC1 zero, $f3 - this.ee.fpr[3].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @00127EF8 C.EQ.S $f12, $f3 - this.ee.fcr31_23 = (this.ee.fpr[12].f == this.ee.fpr[3].f); - // @00127EFC BC1F $00127fd0 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1212368u; - } - // @00127F00 MOV.S $f1, $f2 - this.ee.fpr[1].f = this.ee.fpr[2].f; - } - - public virtual void funct00127f04() - { - this.ee.pc = 1212176u; - // @00127F04 C.LT.S $f21, $f2 - this.ee.fcr31_23 = (this.ee.fpr[21].f < this.ee.fpr[2].f); - // @00127F08 BC1F $00127f84 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1212292u; - } - // @00127F0C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct00127f10() - { - this.ee.pc = 1212276u; - // @00127F10 LQC2 vf1, $0000(s2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); - // @00127F14 VMUL.xyz vf2, vf1, vf1 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); - // @00127F18 VADDy.x vf2, vf2, vf2y - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); - // @00127F1C VADDz.x vf2, vf2, vf2z - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); - // @00127F20 VSQRT Q, vf2x - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); - // @00127F24 VWAITQ - MobUt.Latency(); - // @00127F28 CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - // @00127F2C VADDq.x vf2, vf0, Q - this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); - // @00127F30 MTC1 t0, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00127F34 VNOP - MobUt.Latency(); - // @00127F38 VDIV Q, vf0w, vf2x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); - // @00127F3C VWAITQ - MobUt.Latency(); - // @00127F40 VMULq.xyz vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - // @00127F44 SQC2 vf1, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); - // @00127F48 LQC2 vf1, $0000(s2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); - // @00127F4C MFC1 t0, $f1 - MobUt.MFC1(this.ee.t0, this.ee.fpr[1]); - // @00127F50 QMTC2 t0, vf2 - MobUt.QMTC2(this.ee.t0, this.ee.VF[2]); - // @00127F54 VMULx.xyzw vf1, vf1, vf2x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].x); - // @00127F58 SQC2 vf1, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); - // @00127F5C LQC2 vf1, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @00127F60 LQC2 vf2, $0000(s2) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.s2.UL0)); - // @00127F64 VADD.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y + this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z + this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w + this.ee.VF[2].w); - // @00127F68 SQC2 vf1, $0000(s0) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s0.UL0)); - // @00127F6C BEQ s3, s0, $00127f80 - if ((this.ee.s3.UD0 == this.ee.s0.UD0)) - { - this.ee.pc = 1212288u; - } - // @00127F70 ADDIU v0, zero, $0001 - this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); - } - - public virtual void funct00127f74() - { - this.ee.pc = 1212368u; - // @00127F74 LQ t0, $0000(s0) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s0.UL[0])); - // @00127F78 SQ t0, $0000(s3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @00127F7C ADDIU v0, zero, $0001 - this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @00127F80 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00127F84 LD s0, $0040(sp) - MobUt.LD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); - // @00127F88 ADDIU t7, t7, $8214 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32236))); - // @00127F8C LD s1, $0048(sp) - MobUt.LD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); - // @00127F90 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00127F94 LD s2, $0050(sp) - MobUt.LD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); - // @00127F98 SWC1 $f0, $000c(s3) - MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.s3.UL0)); - // @00127F9C LD s4, $0060(sp) - MobUt.LD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); - // @00127FA0 LD s3, $0058(sp) - MobUt.LD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); - // @00127FA4 LD s5, $0068(sp) - MobUt.LD(this.ee, this.ee.s5, (104u + this.ee.sp.UL0)); - // @00127FA8 LD s6, $0070(sp) - MobUt.LD(this.ee, this.ee.s6, (112u + this.ee.sp.UL0)); - // @00127FAC LD s7, $0078(sp) - MobUt.LD(this.ee, this.ee.s7, (120u + this.ee.sp.UL0)); - // @00127FB0 LD s8, $0080(sp) - MobUt.LD(this.ee, this.ee.s8, (128u + this.ee.sp.UL0)); - // @00127FB4 LD ra, $0088(sp) - MobUt.LD(this.ee, this.ee.ra, (136u + this.ee.sp.UL0)); - // @00127FB8 LWC1 $f23, $009c(sp) - MobUt.LWC1(this.ee, this.ee.fpr[23], (156u + this.ee.sp.UL0)); - // @00127FBC LWC1 $f22, $0098(sp) - MobUt.LWC1(this.ee, this.ee.fpr[22], (152u + this.ee.sp.UL0)); - // @00127FC0 LWC1 $f21, $0094(sp) - MobUt.LWC1(this.ee, this.ee.fpr[21], (148u + this.ee.sp.UL0)); - // @00127FC4 LWC1 $f20, $0090(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (144u + this.ee.sp.UL0)); - // @00127FC8 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00127FCC ADDIU sp, sp, $00a0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 160))); - } - - public virtual void funct00127f80() - { - this.ee.pc = 1212368u; - // @00127F80 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00127F84 LD s0, $0040(sp) - MobUt.LD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); - // @00127F88 ADDIU t7, t7, $8214 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32236))); - // @00127F8C LD s1, $0048(sp) - MobUt.LD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); - // @00127F90 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00127F94 LD s2, $0050(sp) - MobUt.LD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); - // @00127F98 SWC1 $f0, $000c(s3) - MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.s3.UL0)); - // @00127F9C LD s4, $0060(sp) - MobUt.LD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); - // @00127FA0 LD s3, $0058(sp) - MobUt.LD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); - // @00127FA4 LD s5, $0068(sp) - MobUt.LD(this.ee, this.ee.s5, (104u + this.ee.sp.UL0)); - // @00127FA8 LD s6, $0070(sp) - MobUt.LD(this.ee, this.ee.s6, (112u + this.ee.sp.UL0)); - // @00127FAC LD s7, $0078(sp) - MobUt.LD(this.ee, this.ee.s7, (120u + this.ee.sp.UL0)); - // @00127FB0 LD s8, $0080(sp) - MobUt.LD(this.ee, this.ee.s8, (128u + this.ee.sp.UL0)); - // @00127FB4 LD ra, $0088(sp) - MobUt.LD(this.ee, this.ee.ra, (136u + this.ee.sp.UL0)); - // @00127FB8 LWC1 $f23, $009c(sp) - MobUt.LWC1(this.ee, this.ee.fpr[23], (156u + this.ee.sp.UL0)); - // @00127FBC LWC1 $f22, $0098(sp) - MobUt.LWC1(this.ee, this.ee.fpr[22], (152u + this.ee.sp.UL0)); - // @00127FC0 LWC1 $f21, $0094(sp) - MobUt.LWC1(this.ee, this.ee.fpr[21], (148u + this.ee.sp.UL0)); - // @00127FC4 LWC1 $f20, $0090(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (144u + this.ee.sp.UL0)); - // @00127FC8 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00127FCC ADDIU sp, sp, $00a0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 160))); - } - - public virtual void funct00127f84() - { - this.ee.pc = 1212368u; - // @00127F84 LD s0, $0040(sp) - MobUt.LD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); - // @00127F88 ADDIU t7, t7, $8214 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32236))); - // @00127F8C LD s1, $0048(sp) - MobUt.LD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); - // @00127F90 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00127F94 LD s2, $0050(sp) - MobUt.LD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); - // @00127F98 SWC1 $f0, $000c(s3) - MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.s3.UL0)); - // @00127F9C LD s4, $0060(sp) - MobUt.LD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); - // @00127FA0 LD s3, $0058(sp) - MobUt.LD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); - // @00127FA4 LD s5, $0068(sp) - MobUt.LD(this.ee, this.ee.s5, (104u + this.ee.sp.UL0)); - // @00127FA8 LD s6, $0070(sp) - MobUt.LD(this.ee, this.ee.s6, (112u + this.ee.sp.UL0)); - // @00127FAC LD s7, $0078(sp) - MobUt.LD(this.ee, this.ee.s7, (120u + this.ee.sp.UL0)); - // @00127FB0 LD s8, $0080(sp) - MobUt.LD(this.ee, this.ee.s8, (128u + this.ee.sp.UL0)); - // @00127FB4 LD ra, $0088(sp) - MobUt.LD(this.ee, this.ee.ra, (136u + this.ee.sp.UL0)); - // @00127FB8 LWC1 $f23, $009c(sp) - MobUt.LWC1(this.ee, this.ee.fpr[23], (156u + this.ee.sp.UL0)); - // @00127FBC LWC1 $f22, $0098(sp) - MobUt.LWC1(this.ee, this.ee.fpr[22], (152u + this.ee.sp.UL0)); - // @00127FC0 LWC1 $f21, $0094(sp) - MobUt.LWC1(this.ee, this.ee.fpr[21], (148u + this.ee.sp.UL0)); - // @00127FC4 LWC1 $f20, $0090(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (144u + this.ee.sp.UL0)); - // @00127FC8 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00127FCC ADDIU sp, sp, $00a0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 160))); - } - - public virtual void funct00127fd0() - { - this.ee.pc = 1212392u; - // @00127FD0 LWC1 $f1, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.s1.UL0)); - // @00127FD4 SUB.S $f0, $f21, $f1 - this.ee.fpr[0].f = (this.ee.fpr[21].f - this.ee.fpr[1].f); - // @00127FD8 SUB.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f - this.ee.fpr[0].f); - // @00127FDC C.LT.S $f3, $f0 - this.ee.fcr31_23 = (this.ee.fpr[3].f < this.ee.fpr[0].f); - // @00127FE0 BC1F $00127f80 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1212288u; - } - // @00127FE4 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct00127fe8() - { - this.ee.pc = 1212424u; - // @00127FE8 NOP - MobUt.Latency(); - // @00127FEC NOP - MobUt.Latency(); - // @00127FF0 DIV.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); - // @00127FF4 ADDIU t7, t7, $8214 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32236))); - // @00127FF8 LWC1 $f20, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[20], (0u + this.ee.t7.UL0)); - // @00127FFC SUB.S $f12, $f12, $f20 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[20].f); - // @00128000 JAL $002ff8d8 - this.ee.ra.UL0 = 1212424u; - this.ee.pc = 3143896u; - // @00128004 MUL.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f * this.ee.fpr[0].f); - } - - public virtual void funct00128008() - { - this.ee.pc = 1212448u; - // @00128008 SUB.S $f20, $f20, $f0 - this.ee.fpr[20].f = (this.ee.fpr[20].f - this.ee.fpr[0].f); - // @0012800C LWC1 $f0, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.s1.UL0)); - // @00128010 SUB.S $f1, $f21, $f0 - this.ee.fpr[1].f = (this.ee.fpr[21].f - this.ee.fpr[0].f); - // @00128014 MUL.S $f0, $f0, $f20 - this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[20].f); - // @00128018 BEQ zero, zero, $00127f10 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212176u; - } - // @0012801C ADD.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); - } - - public virtual void funct00128020() - { - this.ee.pc = 1212556u; - // @00128020 DSRL t2, t3, 9 - MobUt.DSRL(this.ee.t2, this.ee.t3, 9); - // @00128024 DSRL t7, t3, 4 - MobUt.DSRL(this.ee.t7, this.ee.t3, 4); - // @00128028 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @0012802C DSRL t6, t3, 5 - MobUt.DSRL(this.ee.t6, this.ee.t3, 5); - // @00128030 DSRL t5, t3, 6 - MobUt.DSRL(this.ee.t5, this.ee.t3, 6); - // @00128034 DSRL t4, t3, 7 - MobUt.DSRL(this.ee.t4, this.ee.t3, 7); - // @00128038 C.EQ.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f == this.ee.fpr[0].f); - // @0012803C DSRL t3, t3, 8 - MobUt.DSRL(this.ee.t3, this.ee.t3, 8); - // @00128040 ANDI t7, t7, $00ff - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 255))); - // @00128044 ANDI t6, t6, $00ff - this.ee.t6.UD0 = ((ushort)((this.ee.t6.US0 & 255))); - // @00128048 ANDI t5, t5, $00ff - this.ee.t5.UD0 = ((ushort)((this.ee.t5.US0 & 255))); - // @0012804C ANDI t4, t4, $00ff - this.ee.t4.UD0 = ((ushort)((this.ee.t4.US0 & 255))); - // @00128050 ANDI t3, t3, $00ff - this.ee.t3.UD0 = ((ushort)((this.ee.t3.US0 & 255))); - // @00128054 ANDI t2, t2, $00ff - this.ee.t2.UD0 = ((ushort)((this.ee.t2.US0 & 255))); - // @00128058 ANDI t7, t7, $0001 - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 1))); - // @0012805C ANDI t6, t6, $0001 - this.ee.t6.UD0 = ((ushort)((this.ee.t6.US0 & 1))); - // @00128060 SB t7, $0020(sp) - MobUt.SB(this.ee, this.ee.t7, (32u + this.ee.sp.UL0)); - // @00128064 ANDI t5, t5, $0001 - this.ee.t5.UD0 = ((ushort)((this.ee.t5.US0 & 1))); - // @00128068 SB t6, $0021(sp) - MobUt.SB(this.ee, this.ee.t6, (33u + this.ee.sp.UL0)); - // @0012806C ANDI t4, t4, $0001 - this.ee.t4.UD0 = ((ushort)((this.ee.t4.US0 & 1))); - // @00128070 SB t5, $0022(sp) - MobUt.SB(this.ee, this.ee.t5, (34u + this.ee.sp.UL0)); - // @00128074 ANDI t3, t3, $0001 - this.ee.t3.UD0 = ((ushort)((this.ee.t3.US0 & 1))); - // @00128078 SB t4, $0023(sp) - MobUt.SB(this.ee, this.ee.t4, (35u + this.ee.sp.UL0)); - // @0012807C ANDI t2, t2, $0001 - this.ee.t2.UD0 = ((ushort)((this.ee.t2.US0 & 1))); - // @00128080 SB t3, $0024(sp) - MobUt.SB(this.ee, this.ee.t3, (36u + this.ee.sp.UL0)); - // @00128084 BC1F $00128118 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1212696u; - } - // @00128088 SB t2, $0025(sp) - MobUt.SB(this.ee, this.ee.t2, (37u + this.ee.sp.UL0)); - } - - public virtual void funct0012808c() - { - this.ee.pc = 1212592u; - // @0012808C ADDIU a1, s1, $0020 - this.ee.a1.SD0 = ((int)((this.ee.s1.SD0 + 32))); - // @00128090 DADDU t3, s2, zero - this.ee.t3.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @00128094 DADDU s0, zero, zero - this.ee.s0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00128098 DADDU t4, zero, zero - this.ee.t4.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @0012809C SLL t7, s0, 1 - MobUt.SLL(this.ee.t7, this.ee.s0, 1); - // @001280A0 ADDU t5, t7, sp - this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.sp.SD0))); - // @001280A4 LBU t6, $0020(t5) - MobUt.LBU(this.ee, this.ee.t6, (32u + this.ee.t5.UL0)); - // @001280A8 BEQL t6, zero, $001280c8 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212616u; - // @001280AC LBU t7, $0021(t5) - MobUt.LBU(this.ee, this.ee.t7, (33u + this.ee.t5.UL0)); - } - } - - public virtual void funct0012809c() - { - this.ee.pc = 1212592u; - // @0012809C SLL t7, s0, 1 - MobUt.SLL(this.ee.t7, this.ee.s0, 1); - // @001280A0 ADDU t5, t7, sp - this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.sp.SD0))); - // @001280A4 LBU t6, $0020(t5) - MobUt.LBU(this.ee, this.ee.t6, (32u + this.ee.t5.UL0)); - // @001280A8 BEQL t6, zero, $001280c8 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212616u; - // @001280AC LBU t7, $0021(t5) - MobUt.LBU(this.ee, this.ee.t7, (33u + this.ee.t5.UL0)); - } - } - - public virtual void funct001280b0() - { - this.ee.pc = 1212612u; - // @001280B0 LWC1 $f1, $fff0(a1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (4294967280u + this.ee.a1.UL0)); - // @001280B4 LWC1 $f0, $0000(t3) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t3.UL0)); - // @001280B8 C.LT.S $f0, $f1 - this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[1].f); - // @001280BC BC1T $001280e4 - if (this.ee.fcr31_23) - { - this.ee.pc = 1212644u; - } - // @001280C0 ADDU t7, sp, t4 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + this.ee.t4.SD0))); - } - - public virtual void funct001280c4() - { - this.ee.pc = 1212624u; - // @001280C4 LBU t7, $0021(t5) - MobUt.LBU(this.ee, this.ee.t7, (33u + this.ee.t5.UL0)); - // @001280C8 BEQL t7, zero, $001280fc - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212668u; - // @001280CC ADDIU s0, s0, $0001 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); - } - } - - public virtual void funct001280c8() - { - this.ee.pc = 1212624u; - // @001280C8 BEQL t7, zero, $001280fc - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212668u; - // @001280CC ADDIU s0, s0, $0001 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); - } - } - - public virtual void funct001280d0() - { - this.ee.pc = 1212644u; - // @001280D0 LWC1 $f1, $0000(a1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.a1.UL0)); - // @001280D4 LWC1 $f0, $0000(t3) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t3.UL0)); - // @001280D8 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @001280DC BC1F $001280f8 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1212664u; - } - // @001280E0 ADDU t7, sp, t4 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + this.ee.t4.SD0))); - } - - public virtual void funct001280e4() - { - this.ee.pc = 1212688u; - // @001280E4 ADDU t6, s3, t4 - this.ee.t6.SD0 = ((int)((this.ee.s3.SD0 + this.ee.t4.SD0))); - // @001280E8 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @001280EC ADDIU v0, zero, $0001 - this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @001280F0 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @001280F4 SWC1 $f0, $0000(t6) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @001280F8 ADDIU s0, s0, $0001 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); - // @001280FC ADDIU a1, a1, $0004 - this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 4))); - // @00128100 ADDIU t3, t3, $0004 - this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + 4))); - // @00128104 SLTI t7, s0, $0003 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); - // @00128108 BNE t7, zero, $0012809c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1212572u; - } - // @0012810C ADDIU t4, t4, $0004 - this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + 4))); - } - - public virtual void funct001280f8() - { - this.ee.pc = 1212688u; - // @001280F8 ADDIU s0, s0, $0001 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); - // @001280FC ADDIU a1, a1, $0004 - this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 4))); - // @00128100 ADDIU t3, t3, $0004 - this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + 4))); - // @00128104 SLTI t7, s0, $0003 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); - // @00128108 BNE t7, zero, $0012809c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1212572u; - } - // @0012810C ADDIU t4, t4, $0004 - this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + 4))); - } - - public virtual void funct001280fc() - { - this.ee.pc = 1212688u; - // @001280FC ADDIU a1, a1, $0004 - this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 4))); - // @00128100 ADDIU t3, t3, $0004 - this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + 4))); - // @00128104 SLTI t7, s0, $0003 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); - // @00128108 BNE t7, zero, $0012809c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1212572u; - } - // @0012810C ADDIU t4, t4, $0004 - this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + 4))); - } - - public virtual void funct00128110() - { - this.ee.pc = 1212696u; - // @00128110 BEQ zero, zero, $00127f84 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212292u; - } - // @00128114 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct00128118() - { - this.ee.pc = 1212768u; - // @00128118 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @0012811C MTC1 zero, $f21 - this.ee.fpr[21].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @00128120 ADDIU t7, t7, $8214 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32236))); - // @00128124 DADDU s0, zero, zero - this.ee.s0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00128128 LWC1 $f20, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[20], (0u + this.ee.t7.UL0)); - // @0012812C DADDU s4, s3, zero - this.ee.s4.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); - // @00128130 MOV.S $f22, $f21 - this.ee.fpr[22].f = this.ee.fpr[21].f; - // @00128134 DADDU s8, sp, zero - this.ee.s8.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); - // @00128138 ADDIU t7, s1, $0010 - this.ee.t7.SD0 = ((int)((this.ee.s1.SD0 + 16))); - // @0012813C MOV.S $f23, $f20 - this.ee.fpr[23].f = this.ee.fpr[20].f; - // @00128140 SW t7, $0030(sp) - MobUt.SW(this.ee, this.ee.t7, (48u + this.ee.sp.UL0)); - // @00128144 DADDU s7, zero, zero - this.ee.s7.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00128148 ADDIU s6, sp, $0021 - this.ee.s6.SD0 = ((int)((this.ee.sp.SD0 + 33))); - // @0012814C ADDIU t7, s1, $0020 - this.ee.t7.SD0 = ((int)((this.ee.s1.SD0 + 32))); - // @00128150 SW t7, $0034(sp) - MobUt.SW(this.ee, this.ee.t7, (52u + this.ee.sp.UL0)); - // @00128154 LBU t7, $ffff(s6) - MobUt.LBU(this.ee, this.ee.t7, (4294967295u + this.ee.s6.UL0)); - // @00128158 BEQ t7, zero, $001281f0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212912u; - } - // @0012815C LW t7, $0030(sp) - MobUt.LW(this.ee, this.ee.t7, (48u + this.ee.sp.UL0)); - } - - public virtual void funct00128154() - { - this.ee.pc = 1212768u; - // @00128154 LBU t7, $ffff(s6) - MobUt.LBU(this.ee, this.ee.t7, (4294967295u + this.ee.s6.UL0)); - // @00128158 BEQ t7, zero, $001281f0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212912u; - } - // @0012815C LW t7, $0030(sp) - MobUt.LW(this.ee, this.ee.t7, (48u + this.ee.sp.UL0)); - } - - public virtual void funct00128160() - { - this.ee.pc = 1212804u; - // @00128160 LWC1 $f12, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[12], (8u + this.ee.s1.UL0)); - // @00128164 ADDU s5, t7, s7 - this.ee.s5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s7.SD0))); - // @00128168 LWC1 $f1, $0000(s2) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s2.UL0)); - // @0012816C LWC1 $f0, $0000(s5) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.s5.UL0)); - // @00128170 ADD.S $f0, $f0, $f12 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[12].f); - // @00128174 SUB.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); - // @00128178 C.LT.S $f21, $f0 - this.ee.fcr31_23 = (this.ee.fpr[21].f < this.ee.fpr[0].f); - // @0012817C BC1FL $001281f4 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1212916u; - // @00128180 LBU t7, $0000(s6) - MobUt.LBU(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); - } - } - - public virtual void funct00128184() - { - this.ee.pc = 1212832u; - // @00128184 NOP - MobUt.Latency(); - // @00128188 NOP - MobUt.Latency(); - // @0012818C DIV.S $f0, $f0, $f12 - this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[12].f); - // @00128190 LWC1 $f12, $000c(s1) - MobUt.LWC1(this.ee, this.ee.fpr[12], (12u + this.ee.s1.UL0)); - // @00128194 SUB.S $f12, $f12, $f20 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[20].f); - // @00128198 JAL $002ff8d8 - this.ee.ra.UL0 = 1212832u; - this.ee.pc = 3143896u; - // @0012819C MUL.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f * this.ee.fpr[0].f); - } - - public virtual void funct001281a0() - { - this.ee.pc = 1212904u; - // @001281A0 LWC1 $f2, $0000(s5) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.s5.UL0)); - // @001281A4 ADDIU v0, zero, $0001 - this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @001281A8 LWC1 $f3, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[3], (8u + this.ee.s1.UL0)); - // @001281AC SUB.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f - this.ee.fpr[0].f); - // @001281B0 ADD.S $f2, $f2, $f3 - this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[3].f); - // @001281B4 LWC1 $f1, $0000(s8) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s8.UL0)); - // @001281B8 MUL.S $f0, $f3, $f0 - this.ee.fpr[0].f = (this.ee.fpr[3].f * this.ee.fpr[0].f); - // @001281BC ADD.S $f1, $f1, $f2 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[2].f); - // @001281C0 ADD.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); - // @001281C4 SWC1 $f1, $0000(s4) - MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s4.UL0)); - // @001281C8 ADDIU s0, s0, $0001 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); - // @001281CC ADDIU s4, s4, $0004 - this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 4))); - // @001281D0 ADDIU s8, s8, $0004 - this.ee.s8.SD0 = ((int)((this.ee.s8.SD0 + 4))); - // @001281D4 ADDIU s2, s2, $0004 - this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 4))); - // @001281D8 ADDIU s7, s7, $0004 - this.ee.s7.SD0 = ((int)((this.ee.s7.SD0 + 4))); - // @001281DC SLTI t7, s0, $0003 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); - // @001281E0 BNE t7, zero, $00128154 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1212756u; - } - // @001281E4 ADDIU s6, s6, $0002 - this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 2))); - } - - public virtual void funct001281b4() - { - this.ee.pc = 1212904u; - // @001281B4 LWC1 $f1, $0000(s8) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s8.UL0)); - // @001281B8 MUL.S $f0, $f3, $f0 - this.ee.fpr[0].f = (this.ee.fpr[3].f * this.ee.fpr[0].f); - // @001281BC ADD.S $f1, $f1, $f2 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[2].f); - // @001281C0 ADD.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); - // @001281C4 SWC1 $f1, $0000(s4) - MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s4.UL0)); - // @001281C8 ADDIU s0, s0, $0001 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); - // @001281CC ADDIU s4, s4, $0004 - this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 4))); - // @001281D0 ADDIU s8, s8, $0004 - this.ee.s8.SD0 = ((int)((this.ee.s8.SD0 + 4))); - // @001281D4 ADDIU s2, s2, $0004 - this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 4))); - // @001281D8 ADDIU s7, s7, $0004 - this.ee.s7.SD0 = ((int)((this.ee.s7.SD0 + 4))); - // @001281DC SLTI t7, s0, $0003 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); - // @001281E0 BNE t7, zero, $00128154 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1212756u; - } - // @001281E4 ADDIU s6, s6, $0002 - this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 2))); - } - - public virtual void funct001281c8() - { - this.ee.pc = 1212904u; - // @001281C8 ADDIU s0, s0, $0001 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); - // @001281CC ADDIU s4, s4, $0004 - this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 4))); - // @001281D0 ADDIU s8, s8, $0004 - this.ee.s8.SD0 = ((int)((this.ee.s8.SD0 + 4))); - // @001281D4 ADDIU s2, s2, $0004 - this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 4))); - // @001281D8 ADDIU s7, s7, $0004 - this.ee.s7.SD0 = ((int)((this.ee.s7.SD0 + 4))); - // @001281DC SLTI t7, s0, $0003 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); - // @001281E0 BNE t7, zero, $00128154 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1212756u; - } - // @001281E4 ADDIU s6, s6, $0002 - this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 2))); - } - - public virtual void funct001281cc() - { - this.ee.pc = 1212904u; - // @001281CC ADDIU s4, s4, $0004 - this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 4))); - // @001281D0 ADDIU s8, s8, $0004 - this.ee.s8.SD0 = ((int)((this.ee.s8.SD0 + 4))); - // @001281D4 ADDIU s2, s2, $0004 - this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 4))); - // @001281D8 ADDIU s7, s7, $0004 - this.ee.s7.SD0 = ((int)((this.ee.s7.SD0 + 4))); - // @001281DC SLTI t7, s0, $0003 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); - // @001281E0 BNE t7, zero, $00128154 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1212756u; - } - // @001281E4 ADDIU s6, s6, $0002 - this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 2))); - } - - public virtual void funct001281e8() - { - this.ee.pc = 1212912u; - // @001281E8 BEQ zero, zero, $00127f84 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212292u; - } - // @001281EC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct001281f0() - { - this.ee.pc = 1212924u; - // @001281F0 LBU t7, $0000(s6) - MobUt.LBU(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); - // @001281F4 BEQ t7, zero, $001281c8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212872u; - } - // @001281F8 LW t7, $0034(sp) - MobUt.LW(this.ee, this.ee.t7, (52u + this.ee.sp.UL0)); - } - - public virtual void funct001281f4() - { - this.ee.pc = 1212924u; - // @001281F4 BEQ t7, zero, $001281c8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212872u; - } - // @001281F8 LW t7, $0034(sp) - MobUt.LW(this.ee, this.ee.t7, (52u + this.ee.sp.UL0)); - } - - public virtual void funct001281fc() - { - this.ee.pc = 1212960u; - // @001281FC LWC1 $f12, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[12], (8u + this.ee.s1.UL0)); - // @00128200 ADDU s5, t7, s7 - this.ee.s5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s7.SD0))); - // @00128204 LWC1 $f1, $0000(s2) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s2.UL0)); - // @00128208 LWC1 $f0, $0000(s5) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.s5.UL0)); - // @0012820C SUB.S $f0, $f0, $f12 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); - // @00128210 SUB.S $f0, $f1, $f0 - this.ee.fpr[0].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); - // @00128214 C.LT.S $f22, $f0 - this.ee.fcr31_23 = (this.ee.fpr[22].f < this.ee.fpr[0].f); - // @00128218 BC1FL $001281cc - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1212876u; - // @0012821C ADDIU s0, s0, $0001 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); - } - } - - public virtual void funct00128220() - { - this.ee.pc = 1212988u; - // @00128220 NOP - MobUt.Latency(); - // @00128224 NOP - MobUt.Latency(); - // @00128228 DIV.S $f0, $f0, $f12 - this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[12].f); - // @0012822C LWC1 $f12, $000c(s1) - MobUt.LWC1(this.ee, this.ee.fpr[12], (12u + this.ee.s1.UL0)); - // @00128230 SUB.S $f12, $f12, $f23 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[23].f); - // @00128234 JAL $002ff8d8 - this.ee.ra.UL0 = 1212988u; - this.ee.pc = 3143896u; - // @00128238 MUL.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f * this.ee.fpr[0].f); - } - - public virtual void funct0012823c() - { - this.ee.pc = 1213012u; - // @0012823C LWC1 $f2, $0000(s5) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.s5.UL0)); - // @00128240 ADDIU v0, zero, $0001 - this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @00128244 LWC1 $f3, $0008(s1) - MobUt.LWC1(this.ee, this.ee.fpr[3], (8u + this.ee.s1.UL0)); - // @00128248 SUB.S $f0, $f23, $f0 - this.ee.fpr[0].f = (this.ee.fpr[23].f - this.ee.fpr[0].f); - // @0012824C BEQ zero, zero, $001281b4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212852u; - } - // @00128250 SUB.S $f2, $f2, $f3 - this.ee.fpr[2].f = (this.ee.fpr[2].f - this.ee.fpr[3].f); - } - - public virtual void funct00128254() - { - this.ee.pc = 1213024u; - // @00128254 SQC2 vf0, $0000(sp) - MobUt.SQC2(this.ee, this.ee.VF[0], (0u + this.ee.sp.UL0)); - // @00128258 BEQ zero, zero, $00127e94 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1212052u; - } - // @0012825C ADDIU s2, sp, $0010 - this.ee.s2.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00128260() - { - this.ee.pc = 1213076u; - // @00128260 ADDIU sp, sp, $ffe0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); - // @00128264 SD s0, $0000(sp) - MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @00128268 SD s1, $0008(sp) - MobUt.SD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); - // @0012826C SD s2, $0010(sp) - MobUt.SD(this.ee, this.ee.s2, (16u + this.ee.sp.UL0)); - // @00128270 DADDU s0, a1, zero - this.ee.s0.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - // @00128274 SD ra, $0018(sp) - MobUt.SD(this.ee, this.ee.ra, (24u + this.ee.sp.UL0)); - // @00128278 LW t7, $0014(a1) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.a1.UL0)); - // @0012827C LW s2, $0004(a0) - MobUt.LW(this.ee, this.ee.s2, (4u + this.ee.a0.UL0)); - // @00128280 LW t6, $0000(t7) - MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.t7.UL0)); - // @00128284 LHU s1, $0010(s2) - MobUt.LHU(this.ee, this.ee.s1, (16u + this.ee.s2.UL0)); - // @00128288 LW v0, $0020(t6) - MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t6.UL0)); - // @0012828C JALR ra, v0 - this.ee.ra.UD0 = 1213076u; - this.ee.pc = this.ee.v0.UL0; - // @00128290 DADDU a0, t7, zero - this.ee.a0.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00128294() - { - this.ee.pc = 1213084u; - // @00128294 BEQ s1, zero, $00128304 - if ((this.ee.s1.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213188u; - } - // @00128298 DADDU t2, zero, zero - this.ee.t2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012829c() - { - this.ee.pc = 1213108u; - // @0012829C LW t7, $001c(s0) - MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s0.UL0)); - // @001282A0 SLL t5, t2, 4 - MobUt.SLL(this.ee.t5, this.ee.t2, 4); - // @001282A4 ADDIU t6, v0, $0010 - this.ee.t6.SD0 = ((int)((this.ee.v0.SD0 + 16))); - // @001282A8 ADDU t7, t7, t5 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); - // @001282AC BEQL t7, t6, $001282c0 - if ((this.ee.t7.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1213120u; - // @001282B0 LW t7, $0020(s0) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s0.UL0)); - } - } - - public virtual void funct001282b4() - { - this.ee.pc = 1213136u; - // @001282B4 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @001282B8 SQ t0, $0000(t7) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @001282BC LW t7, $0020(s0) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s0.UL0)); - // @001282C0 ADDIU t6, v0, $0020 - this.ee.t6.SD0 = ((int)((this.ee.v0.SD0 + 32))); - // @001282C4 ADDU t7, t7, t5 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); - // @001282C8 BEQL t7, t6, $001282dc - if ((this.ee.t7.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1213148u; - // @001282CC LW t7, $0024(s0) - MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s0.UL0)); - } - } - - public virtual void funct001282d0() - { - this.ee.pc = 1213164u; - // @001282D0 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @001282D4 SQ t0, $0000(t7) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @001282D8 LW t7, $0024(s0) - MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s0.UL0)); - // @001282DC ADDIU t6, v0, $0030 - this.ee.t6.SD0 = ((int)((this.ee.v0.SD0 + 48))); - // @001282E0 ADDU t7, t7, t5 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); - // @001282E4 BEQL t7, t6, $001282f8 - if ((this.ee.t7.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1213176u; - // @001282E8 ADDIU t2, t2, $0001 - this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + 1))); - } - } - - public virtual void funct001282ec() - { - this.ee.pc = 1213188u; - // @001282EC LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @001282F0 SQ t0, $0000(t7) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @001282F4 ADDIU t2, t2, $0001 - this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + 1))); - // @001282F8 SLT t7, t2, s1 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t2.SD0 < this.ee.s1.SD0)); - // @001282FC BNE t7, zero, $0012829c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1213084u; - } - // @00128300 ADDIU v0, v0, $0040 - this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + 64))); - } - - public virtual void funct00128304() - { - this.ee.pc = 1213200u; - // @00128304 LW s1, $0028(s2) - MobUt.LW(this.ee, this.ee.s1, (40u + this.ee.s2.UL0)); - // @00128308 BEQL s1, zero, $00128384 - if ((this.ee.s1.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213316u; - // @0012830C LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - } - } - - public virtual void funct00128310() - { - this.ee.pc = 1213216u; - // @00128310 LW t7, $0024(s2) - MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s2.UL0)); - // @00128314 DADDU t2, zero, zero - this.ee.t2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00128318 BLEZ s1, $00128380 - if ((this.ee.s1.SD0 <= 0)) - { - this.ee.pc = 1213312u; - } - // @0012831C ADDU t3, s2, t7 - this.ee.t3.SD0 = ((int)((this.ee.s2.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct00128320() - { - this.ee.pc = 1213236u; - // @00128320 LHU t4, $0002(t3) - MobUt.LHU(this.ee, this.ee.t4, (2u + this.ee.t3.UL0)); - // @00128324 ANDI t6, t4, $ffff - this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @00128328 SLTIU t7, t6, $0009 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 9ul)); - // @0012832C BEQ t7, zero, $00128370 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213296u; - } - // @00128330 SLL t7, t6, 2 - MobUt.SLL(this.ee.t7, this.ee.t6, 2); - } - - public virtual void funct00128334() - { - this.ee.pc = 1213260u; - // @00128334 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @00128338 ADDIU t6, t6, $8218 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -32232))); - // @0012833C ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00128340 LW t5, $0000(t7) - MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); - // @00128344 JR t5 - this.ee.pc = this.ee.t5.UL[0]; - // @00128348 NOP - MobUt.Latency(); - } - - public virtual void funct0012834c() - { - this.ee.pc = 1213312u; - // @0012834C LHU t6, $0000(t3) - MobUt.LHU(this.ee, this.ee.t6, (0u + this.ee.t3.UL0)); - // @00128350 ANDI t5, t4, $ffff - this.ee.t5.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @00128354 LW t7, $001c(s0) - MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s0.UL0)); - // @00128358 SLL t5, t5, 2 - MobUt.SLL(this.ee.t5, this.ee.t5, 2); - // @0012835C SLL t6, t6, 4 - MobUt.SLL(this.ee.t6, this.ee.t6, 4); - // @00128360 LWC1 $f0, $0004(t3) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t3.UL0)); - // @00128364 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00128368 ADDU t7, t7, t5 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); - // @0012836C SWC1 $f0, $0000(t7) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00128370 ADDIU t2, t2, $0001 - this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + 1))); - // @00128374 SLT t7, t2, s1 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t2.SD0 < this.ee.s1.SD0)); - // @00128378 BNE t7, zero, $00128320 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1213216u; - } - // @0012837C ADDIU t3, t3, $0008 - this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + 8))); - } - - public virtual void funct00128370() - { - this.ee.pc = 1213312u; - // @00128370 ADDIU t2, t2, $0001 - this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + 1))); - // @00128374 SLT t7, t2, s1 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t2.SD0 < this.ee.s1.SD0)); - // @00128378 BNE t7, zero, $00128320 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1213216u; - } - // @0012837C ADDIU t3, t3, $0008 - this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + 8))); - } - - public virtual void funct00128380() - { - this.ee.pc = 1213336u; - // @00128380 LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @00128384 LD s1, $0008(sp) - MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); - // @00128388 LD s2, $0010(sp) - MobUt.LD(this.ee, this.ee.s2, (16u + this.ee.sp.UL0)); - // @0012838C LD ra, $0018(sp) - MobUt.LD(this.ee, this.ee.ra, (24u + this.ee.sp.UL0)); - // @00128390 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00128394 ADDIU sp, sp, $0020 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); - } - - public virtual void funct00128384() - { - this.ee.pc = 1213336u; - // @00128384 LD s1, $0008(sp) - MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); - // @00128388 LD s2, $0010(sp) - MobUt.LD(this.ee, this.ee.s2, (16u + this.ee.sp.UL0)); - // @0012838C LD ra, $0018(sp) - MobUt.LD(this.ee, this.ee.ra, (24u + this.ee.sp.UL0)); - // @00128390 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00128394 ADDIU sp, sp, $0020 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); - } - - public virtual void funct00128398() - { - this.ee.pc = 1213380u; - // @00128398 ANDI t7, t4, $ffff - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @0012839C LHU t5, $0000(t3) - MobUt.LHU(this.ee, this.ee.t5, (0u + this.ee.t3.UL0)); - // @001283A0 LW t6, $0020(s0) - MobUt.LW(this.ee, this.ee.t6, (32u + this.ee.s0.UL0)); - // @001283A4 ADDIU t7, t7, $fffd - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -3))); - // @001283A8 SLL t5, t5, 4 - MobUt.SLL(this.ee.t5, this.ee.t5, 4); - // @001283AC LWC1 $f0, $0004(t3) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t3.UL0)); - // @001283B0 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @001283B4 ADDU t6, t6, t5 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); - // @001283B8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @001283BC BEQ zero, zero, $00128370 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213296u; - } - // @001283C0 SWC1 $f0, $0000(t6) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - } - - public virtual void funct001283a8() - { - this.ee.pc = 1213380u; - // @001283A8 SLL t5, t5, 4 - MobUt.SLL(this.ee.t5, this.ee.t5, 4); - // @001283AC LWC1 $f0, $0004(t3) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t3.UL0)); - // @001283B0 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @001283B4 ADDU t6, t6, t5 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); - // @001283B8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @001283BC BEQ zero, zero, $00128370 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213296u; - } - // @001283C0 SWC1 $f0, $0000(t6) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - } - - public virtual void funct001283c4() - { - this.ee.pc = 1213400u; - // @001283C4 ANDI t7, t4, $ffff - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @001283C8 LHU t5, $0000(t3) - MobUt.LHU(this.ee, this.ee.t5, (0u + this.ee.t3.UL0)); - // @001283CC LW t6, $0024(s0) - MobUt.LW(this.ee, this.ee.t6, (36u + this.ee.s0.UL0)); - // @001283D0 BEQ zero, zero, $001283a8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213352u; - } - // @001283D4 ADDIU t7, t7, $fffa - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -6))); - } - - public virtual void funct001283d8() - { - this.ee.pc = 1213440u; - // @001283D8 LW t5, $0004(a0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.a0.UL0)); - // @001283DC LW t6, $0044(t5) - MobUt.LW(this.ee, this.ee.t6, (68u + this.ee.t5.UL0)); - // @001283E0 LW t4, $0020(t5) - MobUt.LW(this.ee, this.ee.t4, (32u + this.ee.t5.UL0)); - // @001283E4 ADDU t3, t5, t6 - this.ee.t3.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @001283E8 SLL t7, t4, 2 - MobUt.SLL(this.ee.t7, this.ee.t4, 2); - // @001283EC ADDU t7, t3, t7 - this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t7.SD0))); - // @001283F0 LWC1 $f0, $fffc(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4294967292u + this.ee.t7.UL0)); - // @001283F4 C.LE.S $f0, $f12 - this.ee.fcr31_23 = (this.ee.fpr[0].f <= this.ee.fpr[12].f); - // @001283F8 BC1FL $00128414 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1213460u; - // @001283FC LWC1 $f0, $0000(t3) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t3.UL0)); - } - } - - public virtual void funct00128400() - { - this.ee.pc = 1213460u; - // @00128400 ADDIU t7, t4, $ffff - this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + -1))); - // @00128404 SW t7, $0000(a1) - MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a1.UL0)); - // @00128408 LW t6, $0020(t5) - MobUt.LW(this.ee, this.ee.t6, (32u + this.ee.t5.UL0)); - // @0012840C JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00128410 SW t6, $0000(a2) - MobUt.SW(this.ee, this.ee.t6, (0u + this.ee.a2.UL0)); - } - - public virtual void funct00128414() - { - this.ee.pc = 1213472u; - // @00128414 C.LE.S $f12, $f0 - this.ee.fcr31_23 = (this.ee.fpr[12].f <= this.ee.fpr[0].f); - // @00128418 BC1FL $00128430 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1213488u; - // @0012841C SW zero, $0000(a1) - MobUt.SW(this.ee, this.ee.r0, (0u + this.ee.a1.UL0)); - } - } - - public virtual void funct00128420() - { - this.ee.pc = 1213488u; - // @00128420 ADDIU t7, zero, $ffff - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); - // @00128424 SW t7, $0000(a1) - MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a1.UL0)); - // @00128428 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0012842C SW zero, $0000(a2) - MobUt.SW(this.ee, this.ee.r0, (0u + this.ee.a2.UL0)); - } - - public virtual void funct00128430() - { - this.ee.pc = 1213520u; - // @00128430 LW t7, $0020(t5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.t5.UL0)); - // @00128434 ADDIU t6, t7, $ffff - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + -1))); - // @00128438 SW t6, $0000(a2) - MobUt.SW(this.ee, this.ee.t6, (0u + this.ee.a2.UL0)); - // @0012843C LW t5, $0000(a1) - MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.a1.UL0)); - // @00128440 SUBU t7, t6, t5 - this.ee.t7.SD0 = ((int)((this.ee.t6.UD0 - this.ee.t5.UD0))); - // @00128444 SLTI t7, t7, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < 2)); - // @00128448 BNE t7, zero, $00128490 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1213584u; - } - // @0012844C ADDU t7, t5, t6 - this.ee.t7.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - } - - public virtual void funct00128450() - { - this.ee.pc = 1213556u; - // @00128450 SRL t6, t7, 31 - MobUt.SRL(this.ee.t6, this.ee.t7, 31); - // @00128454 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00128458 SRA t7, t7, 1 - MobUt.SRA(this.ee.t7, this.ee.t7, 1); - // @0012845C SLL t6, t7, 2 - MobUt.SLL(this.ee.t6, this.ee.t7, 2); - // @00128460 ADDU t6, t6, t3 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t3.SD0))); - // @00128464 LWC1 $f0, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @00128468 C.LT.S $f12, $f0 - this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[0].f); - // @0012846C BC1FL $00128498 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1213592u; - // @00128470 C.LT.S $f0, $f12 - this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[12].f); - } - } - - public virtual void funct00128474() - { - this.ee.pc = 1213584u; - // @00128474 SW t7, $0000(a2) - MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a2.UL0)); - // @00128478 LW t6, $0000(a2) - MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.a2.UL0)); - // @0012847C LW t5, $0000(a1) - MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.a1.UL0)); - // @00128480 SUBU t7, t6, t5 - this.ee.t7.SD0 = ((int)((this.ee.t6.UD0 - this.ee.t5.UD0))); - // @00128484 SLTI t7, t7, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < 2)); - // @00128488 BEQ t7, zero, $00128450 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213520u; - } - // @0012848C ADDU t7, t5, t6 - this.ee.t7.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - } - - public virtual void funct00128478() - { - this.ee.pc = 1213584u; - // @00128478 LW t6, $0000(a2) - MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.a2.UL0)); - // @0012847C LW t5, $0000(a1) - MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.a1.UL0)); - // @00128480 SUBU t7, t6, t5 - this.ee.t7.SD0 = ((int)((this.ee.t6.UD0 - this.ee.t5.UD0))); - // @00128484 SLTI t7, t7, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < 2)); - // @00128488 BEQ t7, zero, $00128450 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213520u; - } - // @0012848C ADDU t7, t5, t6 - this.ee.t7.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - } - - public virtual void funct00128490() - { - this.ee.pc = 1213592u; - // @00128490 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00128494 NOP - MobUt.Latency(); - } - - public virtual void funct00128498() - { - this.ee.pc = 1213600u; - // @00128498 BC1FL $001284a8 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1213608u; - // @0012849C SW t7, $0000(a2) - MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a2.UL0)); - } - } - - public virtual void funct001284a0() - { - this.ee.pc = 1213608u; - // @001284A0 BEQ zero, zero, $00128478 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213560u; - } - // @001284A4 SW t7, $0000(a1) - MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a1.UL0)); - } - - public virtual void funct001284a8() - { - this.ee.pc = 1213616u; - // @001284A8 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @001284AC SW t7, $0000(a1) - MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a1.UL0)); - } - - public virtual void funct001284b0() - { - this.ee.pc = 1213744u; - // @001284B0 SUB.S $f16, $f16, $f13 - this.ee.fpr[16].f = (this.ee.fpr[16].f - this.ee.fpr[13].f); - // @001284B4 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @001284B8 ADDIU t7, t7, $823c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32196))); - // @001284BC SUB.S $f12, $f12, $f13 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[13].f); - // @001284C0 LWC1 $f7, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[7], (0u + this.ee.t7.UL0)); - // @001284C4 NOP - MobUt.Latency(); - // @001284C8 NOP - MobUt.Latency(); - // @001284CC DIV.S $f16, $f7, $f16 - this.ee.fpr[16].f = (this.ee.fpr[7].f / this.ee.fpr[16].f); - // @001284D0 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @001284D4 MUL.S $f5, $f12, $f12 - this.ee.fpr[5].f = (this.ee.fpr[12].f * this.ee.fpr[12].f); - // @001284D8 ADDIU t7, t7, $8240 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32192))); - // @001284DC LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @001284E0 MUL.S $f2, $f5, $f12 - this.ee.fpr[2].f = (this.ee.fpr[5].f * this.ee.fpr[12].f); - // @001284E4 MUL.S $f3, $f5, $f3 - this.ee.fpr[3].f = (this.ee.fpr[5].f * this.ee.fpr[3].f); - // @001284E8 MUL.S $f1, $f16, $f16 - this.ee.fpr[1].f = (this.ee.fpr[16].f * this.ee.fpr[16].f); - // @001284EC MUL.S $f5, $f5, $f16 - this.ee.fpr[5].f = (this.ee.fpr[5].f * this.ee.fpr[16].f); - // @001284F0 MUL.S $f2, $f2, $f1 - this.ee.fpr[2].f = (this.ee.fpr[2].f * this.ee.fpr[1].f); - // @001284F4 MUL.S $f3, $f3, $f1 - this.ee.fpr[3].f = (this.ee.fpr[3].f * this.ee.fpr[1].f); - // @001284F8 ADD.S $f6, $f5, $f5 - this.ee.fpr[6].f = (this.ee.fpr[5].f + this.ee.fpr[5].f); - // @001284FC ADD.S $f4, $f2, $f2 - this.ee.fpr[4].f = (this.ee.fpr[2].f + this.ee.fpr[2].f); - // @00128500 SUB.S $f5, $f2, $f5 - this.ee.fpr[5].f = (this.ee.fpr[2].f - this.ee.fpr[5].f); - // @00128504 MUL.S $f4, $f4, $f16 - this.ee.fpr[4].f = (this.ee.fpr[4].f * this.ee.fpr[16].f); - // @00128508 SUB.S $f2, $f2, $f6 - this.ee.fpr[2].f = (this.ee.fpr[2].f - this.ee.fpr[6].f); - // @0012850C SUB.S $f1, $f4, $f3 - this.ee.fpr[1].f = (this.ee.fpr[4].f - this.ee.fpr[3].f); - // @00128510 ADD.S $f2, $f2, $f12 - this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[12].f); - // @00128514 ADD.S $f1, $f1, $f7 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[7].f); - // @00128518 SUB.S $f3, $f3, $f4 - this.ee.fpr[3].f = (this.ee.fpr[3].f - this.ee.fpr[4].f); - // @0012851C MULA.S $f14, $f1 - this.ee.fpracc.f = (this.ee.fpr[14].f * this.ee.fpr[1].f); - // @00128520 MADDA.S $f17, $f3 - this.ee.fpracc.f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[17].f, this.ee.fpr[3].f); - // @00128524 MADDA.S $f15, $f2 - this.ee.fpracc.f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[15].f, this.ee.fpr[2].f); - // @00128528 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0012852C MADD.S $f0, $f18, $f5 - this.ee.fpr[0].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[18].f, this.ee.fpr[5].f); - } - - public virtual void funct00128530() - { - this.ee.pc = 1213892u; - // @00128530 ADDIU sp, sp, $ffa0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -96))); - // @00128534 LW t5, $0004(a0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.a0.UL0)); - // @00128538 SD s0, $0010(sp) - MobUt.SD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); - // @0012853C SD s1, $0018(sp) - MobUt.SD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); - // @00128540 SD s2, $0020(sp) - MobUt.SD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); - // @00128544 DADDU s0, a1, zero - this.ee.s0.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - // @00128548 SD s3, $0028(sp) - MobUt.SD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); - // @0012854C SD s4, $0030(sp) - MobUt.SD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); - // @00128550 SD s5, $0038(sp) - MobUt.SD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); - // @00128554 SD s6, $0040(sp) - MobUt.SD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); - // @00128558 SWC1 $f20, $0050(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (80u + this.ee.sp.UL0)); - // @0012855C SW a3, $0004(sp) - MobUt.SW(this.ee, this.ee.a3, (4u + this.ee.sp.UL0)); - // @00128560 SD ra, $0048(sp) - MobUt.SD(this.ee, this.ee.ra, (72u + this.ee.sp.UL0)); - // @00128564 MOV.S $f20, $f12 - this.ee.fpr[20].f = this.ee.fpr[12].f; - // @00128568 SW a2, $0000(sp) - MobUt.SW(this.ee, this.ee.a2, (0u + this.ee.sp.UL0)); - // @0012856C LHU t0, $0004(a1) - MobUt.LHU(this.ee, this.ee.t0, (4u + this.ee.a1.UL0)); - // @00128570 LW t6, $0040(t5) - MobUt.LW(this.ee, this.ee.t6, (64u + this.ee.t5.UL0)); - // @00128574 ANDI t4, t0, $ffff - this.ee.t4.UD0 = ((ushort)((this.ee.t0.US0 & 65535))); - // @00128578 LBU t1, $0003(a1) - MobUt.LBU(this.ee, this.ee.t1, (3u + this.ee.a1.UL0)); - // @0012857C ADDU s2, t5, t6 - this.ee.s2.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @00128580 LW t3, $0048(t5) - MobUt.LW(this.ee, this.ee.t3, (72u + this.ee.t5.UL0)); - // @00128584 SLL t7, t4, 3 - MobUt.SLL(this.ee.t7, this.ee.t4, 3); - // @00128588 ANDI t6, t1, $00ff - this.ee.t6.UD0 = ((ushort)((this.ee.t1.US0 & 255))); - // @0012858C ADDU s1, s2, t7 - this.ee.s1.SD0 = ((int)((this.ee.s2.SD0 + this.ee.t7.SD0))); - // @00128590 ADDU t4, t4, t6 - this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @00128594 LHU t2, $0000(s1) - MobUt.LHU(this.ee, this.ee.t2, (0u + this.ee.s1.UL0)); - // @00128598 SLL t4, t4, 3 - MobUt.SLL(this.ee.t4, this.ee.t4, 3); - // @0012859C LW t6, $0044(t5) - MobUt.LW(this.ee, this.ee.t6, (68u + this.ee.t5.UL0)); - // @001285A0 ADDU t4, s2, t4 - this.ee.t4.SD0 = ((int)((this.ee.s2.SD0 + this.ee.t4.SD0))); - // @001285A4 LW t7, $004c(t5) - MobUt.LW(this.ee, this.ee.t7, (76u + this.ee.t5.UL0)); - // @001285A8 SRL t2, t2, 2 - MobUt.SRL(this.ee.t2, this.ee.t2, 2); - // @001285AC ADDU s3, t5, t6 - this.ee.s3.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @001285B0 ADDU s5, t5, t3 - this.ee.s5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t3.SD0))); - // @001285B4 ADDU s6, t5, t7 - this.ee.s6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t7.SD0))); - // @001285B8 SLT a3, t2, a3 - this.ee.a3.UD0 = System.Convert.ToByte((this.ee.t2.SD0 < this.ee.a3.SD0)); - // @001285BC BNE a3, zero, $00128840 - if ((this.ee.a3.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1214528u; - } - // @001285C0 ADDIU s4, t4, $fff8 - this.ee.s4.SD0 = ((int)((this.ee.t4.SD0 + -8))); - } - - public virtual void funct001285c4() - { - this.ee.pc = 1213916u; - // @001285C4 LHU t7, $0002(a1) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.a1.UL0)); - // @001285C8 ADDIU t6, zero, $0001 - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @001285CC SRL t7, t7, 4 - MobUt.SRL(this.ee.t7, this.ee.t7, 4); - // @001285D0 ANDI t5, t7, $0003 - this.ee.t5.UD0 = ((ushort)((this.ee.t7.US0 & 3))); - // @001285D4 BEQ t5, t6, $00128804 - if ((this.ee.t5.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1214468u; - } - // @001285D8 SLTI t7, t5, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < 2)); - } - - public virtual void funct001285dc() - { - this.ee.pc = 1213924u; - // @001285DC BEQL t7, zero, $0012862c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213996u; - // @001285E0 ADDIU t7, zero, $0002 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); - } - } - - public virtual void funct001285e4() - { - this.ee.pc = 1213932u; - // @001285E4 BEQL t5, zero, $0012861c - if ((this.ee.t5.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213980u; - // @001285E8 LHU t7, $0002(s1) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); - } - } - - public virtual void funct001285f0() - { - this.ee.pc = 1213980u; - // @001285F0 LD s0, $0010(sp) - MobUt.LD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); - // @001285F4 LD s1, $0018(sp) - MobUt.LD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); - // @001285F8 LD s2, $0020(sp) - MobUt.LD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); - // @001285FC LD s3, $0028(sp) - MobUt.LD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); - // @00128600 LD s4, $0030(sp) - MobUt.LD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); - // @00128604 LD s5, $0038(sp) - MobUt.LD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); - // @00128608 LD s6, $0040(sp) - MobUt.LD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); - // @0012860C LD ra, $0048(sp) - MobUt.LD(this.ee, this.ee.ra, (72u + this.ee.sp.UL0)); - // @00128610 LWC1 $f20, $0050(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (80u + this.ee.sp.UL0)); - // @00128614 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00128618 ADDIU sp, sp, $0060 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 96))); - } - - public virtual void funct001285f4() - { - this.ee.pc = 1213980u; - // @001285F4 LD s1, $0018(sp) - MobUt.LD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); - // @001285F8 LD s2, $0020(sp) - MobUt.LD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); - // @001285FC LD s3, $0028(sp) - MobUt.LD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); - // @00128600 LD s4, $0030(sp) - MobUt.LD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); - // @00128604 LD s5, $0038(sp) - MobUt.LD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); - // @00128608 LD s6, $0040(sp) - MobUt.LD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); - // @0012860C LD ra, $0048(sp) - MobUt.LD(this.ee, this.ee.ra, (72u + this.ee.sp.UL0)); - // @00128610 LWC1 $f20, $0050(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (80u + this.ee.sp.UL0)); - // @00128614 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00128618 ADDIU sp, sp, $0060 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 96))); - } - - public virtual void funct0012861c() - { - this.ee.pc = 1213996u; - // @0012861C SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @00128620 ADDU t7, t7, s5 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s5.SD0))); - // @00128624 BEQ zero, zero, $001285f0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213936u; - } - // @00128628 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - } - - public virtual void funct0012862c() - { - this.ee.pc = 1214004u; - // @0012862C BNEL t5, t7, $001285f0 - if ((this.ee.t5.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1213936u; - // @00128630 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - } - } - - public virtual void funct00128634() - { - this.ee.pc = 1214044u; - // @00128634 LHU t7, $fff8(t4) - MobUt.LHU(this.ee, this.ee.t7, (4294967288u + this.ee.t4.UL0)); - // @00128638 SLL t6, t2, 2 - MobUt.SLL(this.ee.t6, this.ee.t2, 2); - // @0012863C ADDU t6, t6, s3 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); - // @00128640 ANDI t7, t7, $fffc - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 65532))); - // @00128644 LWC1 $f2, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t6.UL0)); - // @00128648 ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012864C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00128650 C.LT.S $f12, $f2 - this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[2].f); - // @00128654 BC1F $00128670 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1214064u; - } - // @00128658 SUB.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); - } - - public virtual void funct0012865c() - { - this.ee.pc = 1214060u; - // @0012865C ADD.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); - // @00128660 C.LT.S $f12, $f2 - this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[2].f); - // @00128664 BC1TL $00128660 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1214048u; - // @00128668 ADD.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); - } - } - - public virtual void funct00128660() - { - this.ee.pc = 1214060u; - // @00128660 C.LT.S $f12, $f2 - this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[2].f); - // @00128664 BC1TL $00128660 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1214048u; - // @00128668 ADD.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); - } - } - - public virtual void funct0012866c() - { - this.ee.pc = 1214080u; - // @0012866C MOV.S $f20, $f12 - this.ee.fpr[20].f = this.ee.fpr[12].f; - // @00128670 MOV.S $f12, $f20 - this.ee.fpr[12].f = this.ee.fpr[20].f; - // @00128674 DADDU a1, sp, zero - this.ee.a1.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); - // @00128678 JAL $001283d8 - this.ee.ra.UL0 = 1214080u; - this.ee.pc = 1213400u; - // @0012867C ADDIU a2, sp, $0004 - this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 4))); - } - - public virtual void funct00128670() - { - this.ee.pc = 1214080u; - // @00128670 MOV.S $f12, $f20 - this.ee.fpr[12].f = this.ee.fpr[20].f; - // @00128674 DADDU a1, sp, zero - this.ee.a1.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); - // @00128678 JAL $001283d8 - this.ee.ra.UL0 = 1214080u; - this.ee.pc = 1213400u; - // @0012867C ADDIU a2, sp, $0004 - this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 4))); - } - - public virtual void funct00128680() - { - this.ee.pc = 1214120u; - // @00128680 LBU t1, $0003(s0) - MobUt.LBU(this.ee, this.ee.t1, (3u + this.ee.s0.UL0)); - // @00128684 LHU t0, $0004(s0) - MobUt.LHU(this.ee, this.ee.t0, (4u + this.ee.s0.UL0)); - // @00128688 ANDI t4, t0, $ffff - this.ee.t4.UD0 = ((ushort)((this.ee.t0.US0 & 65535))); - // @0012868C ANDI t7, t1, $00ff - this.ee.t7.UD0 = ((ushort)((this.ee.t1.US0 & 255))); - // @00128690 ADDU t7, t4, t7 - this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t7.SD0))); - // @00128694 ADDIU a3, t7, $ffff - this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + -1))); - // @00128698 SUBU t0, a3, t4 - this.ee.t0.SD0 = ((int)((this.ee.a3.UD0 - this.ee.t4.UD0))); - // @0012869C SLTI t7, t0, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t0.SD0 < 2)); - // @001286A0 BNEL t7, zero, $00128708 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1214216u; - // @001286A4 LHU t4, $0000(s1) - MobUt.LHU(this.ee, this.ee.t4, (0u + this.ee.s1.UL0)); - } - } - - public virtual void funct0012868c() - { - this.ee.pc = 1214120u; - // @0012868C ANDI t7, t1, $00ff - this.ee.t7.UD0 = ((ushort)((this.ee.t1.US0 & 255))); - // @00128690 ADDU t7, t4, t7 - this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t7.SD0))); - // @00128694 ADDIU a3, t7, $ffff - this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + -1))); - // @00128698 SUBU t0, a3, t4 - this.ee.t0.SD0 = ((int)((this.ee.a3.UD0 - this.ee.t4.UD0))); - // @0012869C SLTI t7, t0, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t0.SD0 < 2)); - // @001286A0 BNEL t7, zero, $00128708 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1214216u; - // @001286A4 LHU t4, $0000(s1) - MobUt.LHU(this.ee, this.ee.t4, (0u + this.ee.s1.UL0)); - } - } - - public virtual void funct001286a8() - { - this.ee.pc = 1214176u; - // @001286A8 ADDU t7, t4, a3 - this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + this.ee.a3.SD0))); - // @001286AC SRL t6, t7, 31 - MobUt.SRL(this.ee.t6, this.ee.t7, 31); - // @001286B0 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @001286B4 SRA t3, t7, 1 - MobUt.SRA(this.ee.t3, this.ee.t7, 1); - // @001286B8 SLL t6, t3, 3 - MobUt.SLL(this.ee.t6, this.ee.t3, 3); - // @001286BC ADDU t1, s2, t6 - this.ee.t1.SD0 = ((int)((this.ee.s2.SD0 + this.ee.t6.SD0))); - // @001286C0 LHU t5, $0000(t1) - MobUt.LHU(this.ee, this.ee.t5, (0u + this.ee.t1.UL0)); - // @001286C4 SRL t5, t5, 2 - MobUt.SRL(this.ee.t5, this.ee.t5, 2); - // @001286C8 SLL t7, t5, 2 - MobUt.SLL(this.ee.t7, this.ee.t5, 2); - // @001286CC ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @001286D0 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @001286D4 C.EQ.S $f0, $f20 - this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[20].f); - // @001286D8 BC1T $001287fc - if (this.ee.fcr31_23) - { - this.ee.pc = 1214460u; - } - // @001286DC LW t6, $0000(sp) - MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.sp.UL0)); - } - - public virtual void funct001286ac() - { - this.ee.pc = 1214176u; - // @001286AC SRL t6, t7, 31 - MobUt.SRL(this.ee.t6, this.ee.t7, 31); - // @001286B0 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @001286B4 SRA t3, t7, 1 - MobUt.SRA(this.ee.t3, this.ee.t7, 1); - // @001286B8 SLL t6, t3, 3 - MobUt.SLL(this.ee.t6, this.ee.t3, 3); - // @001286BC ADDU t1, s2, t6 - this.ee.t1.SD0 = ((int)((this.ee.s2.SD0 + this.ee.t6.SD0))); - // @001286C0 LHU t5, $0000(t1) - MobUt.LHU(this.ee, this.ee.t5, (0u + this.ee.t1.UL0)); - // @001286C4 SRL t5, t5, 2 - MobUt.SRL(this.ee.t5, this.ee.t5, 2); - // @001286C8 SLL t7, t5, 2 - MobUt.SLL(this.ee.t7, this.ee.t5, 2); - // @001286CC ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @001286D0 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @001286D4 C.EQ.S $f0, $f20 - this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[20].f); - // @001286D8 BC1T $001287fc - if (this.ee.fcr31_23) - { - this.ee.pc = 1214460u; - } - // @001286DC LW t6, $0000(sp) - MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.sp.UL0)); - } - - public virtual void funct001286e0() - { - this.ee.pc = 1214188u; - // @001286E0 SLT t7, t5, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); - // @001286E4 BEQ t7, zero, $001287c0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214400u; - } - // @001286E8 LW t2, $0004(sp) - MobUt.LW(this.ee, this.ee.t2, (4u + this.ee.sp.UL0)); - } - - public virtual void funct001286ec() - { - this.ee.pc = 1214212u; - // @001286EC DADDU t4, t3, zero - this.ee.t4.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); - // @001286F0 DADDU s1, t1, zero - this.ee.s1.UD0 = (this.ee.t1.UD0 + this.ee.r0.UD0); - // @001286F4 SUBU t0, a3, t4 - this.ee.t0.SD0 = ((int)((this.ee.a3.UD0 - this.ee.t4.UD0))); - // @001286F8 SLTI t7, t0, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t0.SD0 < 2)); - // @001286FC BEQ t7, zero, $001286ac - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214124u; - } - // @00128700 ADDU t7, t4, a3 - this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + this.ee.a3.SD0))); - } - - public virtual void funct001286f4() - { - this.ee.pc = 1214212u; - // @001286F4 SUBU t0, a3, t4 - this.ee.t0.SD0 = ((int)((this.ee.a3.UD0 - this.ee.t4.UD0))); - // @001286F8 SLTI t7, t0, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t0.SD0 < 2)); - // @001286FC BEQ t7, zero, $001286ac - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214124u; - } - // @00128700 ADDU t7, t4, a3 - this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + this.ee.a3.SD0))); - } - - public virtual void funct00128704() - { - this.ee.pc = 1214232u; - // @00128704 LHU t4, $0000(s1) - MobUt.LHU(this.ee, this.ee.t4, (0u + this.ee.s1.UL0)); - // @00128708 ANDI t7, t4, $0003 - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 3))); - // @0012870C ANDI t1, t7, $ffff - this.ee.t1.UD0 = ((ushort)((this.ee.t7.US0 & 65535))); - // @00128710 BEQL t1, zero, $0012861c - if ((this.ee.t1.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213980u; - // @00128714 LHU t7, $0002(s1) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); - } - } - - public virtual void funct00128708() - { - this.ee.pc = 1214232u; - // @00128708 ANDI t7, t4, $0003 - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 3))); - // @0012870C ANDI t1, t7, $ffff - this.ee.t1.UD0 = ((ushort)((this.ee.t7.US0 & 65535))); - // @00128710 BEQL t1, zero, $0012861c - if ((this.ee.t1.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213980u; - // @00128714 LHU t7, $0002(s1) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); - } - } - - public virtual void funct00128718() - { - this.ee.pc = 1214336u; - // @00128718 LHU t7, $0002(s4) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s4.UL0)); - // @0012871C ANDI t4, t4, $ffff - this.ee.t4.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @00128720 LHU t3, $0006(s1) - MobUt.LHU(this.ee, this.ee.t3, (6u + this.ee.s1.UL0)); - // @00128724 ANDI t4, t4, $fffc - this.ee.t4.UD0 = ((ushort)((this.ee.t4.US0 & 65532))); - // @00128728 LHU t2, $0004(s4) - MobUt.LHU(this.ee, this.ee.t2, (4u + this.ee.s4.UL0)); - // @0012872C SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @00128730 LHU t6, $0002(s1) - MobUt.LHU(this.ee, this.ee.t6, (2u + this.ee.s1.UL0)); - // @00128734 ADDU t7, t7, s5 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s5.SD0))); - // @00128738 LHU t5, $0000(s4) - MobUt.LHU(this.ee, this.ee.t5, (0u + this.ee.s4.UL0)); - // @0012873C SLL t3, t3, 2 - MobUt.SLL(this.ee.t3, this.ee.t3, 2); - // @00128740 SLL t2, t2, 2 - MobUt.SLL(this.ee.t2, this.ee.t2, 2); - // @00128744 LWC1 $f17, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[17], (0u + this.ee.t7.UL0)); - // @00128748 SLL t6, t6, 2 - MobUt.SLL(this.ee.t6, this.ee.t6, 2); - // @0012874C ANDI t5, t5, $fffc - this.ee.t5.UD0 = ((ushort)((this.ee.t5.US0 & 65532))); - // @00128750 ADDU t2, t2, s6 - this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + this.ee.s6.SD0))); - // @00128754 ADDU t5, t5, s3 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s3.SD0))); - // @00128758 ADDU t4, t4, s3 - this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + this.ee.s3.SD0))); - // @0012875C LWC1 $f16, $0000(t5) - MobUt.LWC1(this.ee, this.ee.fpr[16], (0u + this.ee.t5.UL0)); - // @00128760 ADDU t6, t6, s5 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s5.SD0))); - // @00128764 LWC1 $f13, $0000(t4) - MobUt.LWC1(this.ee, this.ee.fpr[13], (0u + this.ee.t4.UL0)); - // @00128768 ADDU t3, t3, s6 - this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s6.SD0))); - // @0012876C LWC1 $f14, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t6.UL0)); - // @00128770 LWC1 $f15, $0000(t3) - MobUt.LWC1(this.ee, this.ee.fpr[15], (0u + this.ee.t3.UL0)); - // @00128774 ADDIU t7, zero, $0001 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @00128778 BEQ t1, t7, $0012879c - if ((this.ee.t1.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1214364u; - } - // @0012877C LWC1 $f18, $0000(t2) - MobUt.LWC1(this.ee, this.ee.fpr[18], (0u + this.ee.t2.UL0)); - } - - public virtual void funct00128780() - { - this.ee.pc = 1214348u; - // @00128780 ADDIU t7, zero, $0002 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); - // @00128784 BNEL t1, t7, $001285f0 - if ((this.ee.t1.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1213936u; - // @00128788 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - } - } - - public virtual void funct0012878c() - { - this.ee.pc = 1214356u; - // @0012878C JAL $001284b0 - this.ee.ra.UL0 = 1214356u; - this.ee.pc = 1213616u; - // @00128790 MOV.S $f12, $f20 - this.ee.fpr[12].f = this.ee.fpr[20].f; - } - - public virtual void funct00128794() - { - this.ee.pc = 1214364u; - // @00128794 BEQ zero, zero, $001285f4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213940u; - } - // @00128798 LD s0, $0010(sp) - MobUt.LD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); - } - - public virtual void funct0012879c() - { - this.ee.pc = 1214400u; - // @0012879C SUB.S $f0, $f17, $f14 - this.ee.fpr[0].f = (this.ee.fpr[17].f - this.ee.fpr[14].f); - // @001287A0 SUB.S $f1, $f20, $f13 - this.ee.fpr[1].f = (this.ee.fpr[20].f - this.ee.fpr[13].f); - // @001287A4 SUB.S $f2, $f16, $f13 - this.ee.fpr[2].f = (this.ee.fpr[16].f - this.ee.fpr[13].f); - // @001287A8 MUL.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[1].f); - // @001287AC NOP - MobUt.Latency(); - // @001287B0 NOP - MobUt.Latency(); - // @001287B4 DIV.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[2].f); - // @001287B8 BEQ zero, zero, $001285f0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213936u; - } - // @001287BC ADD.S $f0, $f14, $f0 - this.ee.fpr[0].f = (this.ee.fpr[14].f + this.ee.fpr[0].f); - } - - public virtual void funct001287c0() - { - this.ee.pc = 1214412u; - // @001287C0 SLT t7, t2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t2.SD0 < this.ee.t5.SD0)); - // @001287C4 BEQ t7, zero, $001287d8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214424u; - } - // @001287C8 NOP - MobUt.Latency(); - } - - public virtual void funct001287cc() - { - this.ee.pc = 1214424u; - // @001287CC DADDU a3, t3, zero - this.ee.a3.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); - // @001287D0 BEQ zero, zero, $001286f4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214196u; - } - // @001287D4 DADDU s4, t1, zero - this.ee.s4.UD0 = (this.ee.t1.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001287d8() - { - this.ee.pc = 1214432u; - // @001287D8 BEQL t5, t6, $001287f4 - if ((this.ee.t5.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1214452u; - // @001287DC DADDU s1, t1, zero - this.ee.s1.UD0 = (this.ee.t1.UD0 + this.ee.r0.UD0); - } - } - - public virtual void funct001287e0() - { - this.ee.pc = 1214440u; - // @001287E0 BNE t5, t2, $001286fc - if ((this.ee.t5.UD0 != this.ee.t2.UD0)) - { - this.ee.pc = 1214204u; - } - // @001287E4 SLTI t7, t0, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t0.SD0 < 2)); - } - - public virtual void funct001287e8() - { - this.ee.pc = 1214452u; - // @001287E8 DADDU s4, t1, zero - this.ee.s4.UD0 = (this.ee.t1.UD0 + this.ee.r0.UD0); - // @001287EC BEQ zero, zero, $00128704 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214212u; - } - // @001287F0 ADDIU s1, t1, $fff8 - this.ee.s1.SD0 = ((int)((this.ee.t1.SD0 + -8))); - } - - public virtual void funct001287f4() - { - this.ee.pc = 1214460u; - // @001287F4 BEQ zero, zero, $00128704 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214212u; - } - // @001287F8 ADDIU s4, t1, $0008 - this.ee.s4.SD0 = ((int)((this.ee.t1.SD0 + 8))); - } - - public virtual void funct001287fc() - { - this.ee.pc = 1214468u; - // @001287FC BEQ zero, zero, $0012861c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213980u; - } - // @00128800 LHU t7, $0002(t1) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.t1.UL0)); - } - - public virtual void funct00128804() - { - this.ee.pc = 1214528u; - // @00128804 SLL t7, t2, 2 - MobUt.SLL(this.ee.t7, this.ee.t2, 2); - // @00128808 LHU t6, $0004(s1) - MobUt.LHU(this.ee, this.ee.t6, (4u + this.ee.s1.UL0)); - // @0012880C ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @00128810 LHU t5, $0002(s1) - MobUt.LHU(this.ee, this.ee.t5, (2u + this.ee.s1.UL0)); - // @00128814 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00128818 SLL t6, t6, 2 - MobUt.SLL(this.ee.t6, this.ee.t6, 2); - // @0012881C ADDU t6, t6, s6 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s6.SD0))); - // @00128820 SLL t5, t5, 2 - MobUt.SLL(this.ee.t5, this.ee.t5, 2); - // @00128824 SUB.S $f0, $f0, $f12 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); - // @00128828 ADDU t5, t5, s5 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s5.SD0))); - // @0012882C LWC1 $f2, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t6.UL0)); - // @00128830 LWC1 $f1, $0000(t5) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t5.UL0)); - // @00128834 MUL.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[2].f); - // @00128838 BEQ zero, zero, $001285f0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213936u; - } - // @0012883C SUB.S $f0, $f1, $f0 - this.ee.fpr[0].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); - } - - public virtual void funct00128840() - { - this.ee.pc = 1214548u; - // @00128840 LHU t7, $fff8(t4) - MobUt.LHU(this.ee, this.ee.t7, (4294967288u + this.ee.t4.UL0)); - // @00128844 SRL t4, t7, 2 - MobUt.SRL(this.ee.t4, this.ee.t7, 2); - // @00128848 SLT a2, a2, t4 - this.ee.a2.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t4.SD0)); - // @0012884C BNEL a2, zero, $0012868c - if ((this.ee.a2.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1214092u; - // @00128850 ANDI t4, t0, $ffff - this.ee.t4.UD0 = ((ushort)((this.ee.t0.US0 & 65535))); - } - } - - public virtual void funct00128854() - { - this.ee.pc = 1214572u; - // @00128854 LHU t7, $0002(a1) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.a1.UL0)); - // @00128858 ADDIU t6, zero, $0001 - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @0012885C SRL t7, t7, 6 - MobUt.SRL(this.ee.t7, this.ee.t7, 6); - // @00128860 ANDI t5, t7, $0003 - this.ee.t5.UD0 = ((ushort)((this.ee.t7.US0 & 3))); - // @00128864 BEQ t5, t6, $001288d8 - if ((this.ee.t5.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1214680u; - } - // @00128868 SLTI t7, t5, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < 2)); - } - - public virtual void funct0012886c() - { - this.ee.pc = 1214580u; - // @0012886C BEQ t7, zero, $00128884 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214596u; - } - // @00128870 ADDIU t7, zero, $0002 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); - } - - public virtual void funct00128874() - { - this.ee.pc = 1214588u; - // @00128874 BNEL t5, zero, $001285f0 - if ((this.ee.t5.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1213936u; - // @00128878 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - } - } - - public virtual void funct0012887c() - { - this.ee.pc = 1214596u; - // @0012887C BEQ zero, zero, $0012861c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213980u; - } - // @00128880 LHU t7, $0002(s4) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s4.UL0)); - } - - public virtual void funct00128884() - { - this.ee.pc = 1214604u; - // @00128884 BNEL t5, t7, $001285f0 - if ((this.ee.t5.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1213936u; - // @00128888 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - } - } - - public virtual void funct0012888c() - { - this.ee.pc = 1214640u; - // @0012888C SLL t7, t2, 2 - MobUt.SLL(this.ee.t7, this.ee.t2, 2); - // @00128890 SLL t6, t4, 2 - MobUt.SLL(this.ee.t6, this.ee.t4, 2); - // @00128894 ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @00128898 ADDU t6, t6, s3 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); - // @0012889C LWC1 $f2, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t6.UL0)); - // @001288A0 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @001288A4 C.LT.S $f2, $f12 - this.ee.fcr31_23 = (this.ee.fpr[2].f < this.ee.fpr[12].f); - // @001288A8 BC1F $00128670 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1214064u; - } - // @001288AC SUB.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f - this.ee.fpr[0].f); - } - - public virtual void funct001288b0() - { - this.ee.pc = 1214672u; - // @001288B0 SUB.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - // @001288B4 C.LT.S $f2, $f12 - this.ee.fcr31_23 = (this.ee.fpr[2].f < this.ee.fpr[12].f); - // @001288B8 NOP - MobUt.Latency(); - // @001288BC NOP - MobUt.Latency(); - // @001288C0 NOP - MobUt.Latency(); - // @001288C4 NOP - MobUt.Latency(); - // @001288C8 BC1TL $001288b4 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1214644u; - // @001288CC SUB.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - } - } - - public virtual void funct001288b4() - { - this.ee.pc = 1214672u; - // @001288B4 C.LT.S $f2, $f12 - this.ee.fcr31_23 = (this.ee.fpr[2].f < this.ee.fpr[12].f); - // @001288B8 NOP - MobUt.Latency(); - // @001288BC NOP - MobUt.Latency(); - // @001288C0 NOP - MobUt.Latency(); - // @001288C4 NOP - MobUt.Latency(); - // @001288C8 BC1TL $001288b4 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1214644u; - // @001288CC SUB.S $f12, $f12, $f0 - this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - } - } - - public virtual void funct001288d0() - { - this.ee.pc = 1214680u; - // @001288D0 BEQ zero, zero, $00128670 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214064u; - } - // @001288D4 MOV.S $f20, $f12 - this.ee.fpr[20].f = this.ee.fpr[12].f; - } - - public virtual void funct001288d8() - { - this.ee.pc = 1214740u; - // @001288D8 SLL t7, t4, 2 - MobUt.SLL(this.ee.t7, this.ee.t4, 2); - // @001288DC LHU t6, $0006(s4) - MobUt.LHU(this.ee, this.ee.t6, (6u + this.ee.s4.UL0)); - // @001288E0 ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @001288E4 LHU t5, $0002(s4) - MobUt.LHU(this.ee, this.ee.t5, (2u + this.ee.s4.UL0)); - // @001288E8 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @001288EC SLL t6, t6, 2 - MobUt.SLL(this.ee.t6, this.ee.t6, 2); - // @001288F0 ADDU t6, t6, s6 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s6.SD0))); - // @001288F4 SLL t5, t5, 2 - MobUt.SLL(this.ee.t5, this.ee.t5, 2); - // @001288F8 SUB.S $f0, $f12, $f0 - this.ee.fpr[0].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - // @001288FC ADDU t5, t5, s5 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s5.SD0))); - // @00128900 LWC1 $f2, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t6.UL0)); - // @00128904 LWC1 $f1, $0000(t5) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t5.UL0)); - // @00128908 MUL.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[2].f); - // @0012890C BEQ zero, zero, $001285f0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1213936u; - } - // @00128910 ADD.S $f0, $f1, $f0 - this.ee.fpr[0].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); - } - - public virtual void funct00128918() - { - this.ee.pc = 1214808u; - // @00128918 ADDIU sp, sp, $ffb0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -80))); - // @0012891C SWC1 $f20, $0048(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (72u + this.ee.sp.UL0)); - // @00128920 ADDIU a2, sp, $0004 - this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 4))); - // @00128924 SD s5, $0038(sp) - MobUt.SD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); - // @00128928 MOV.S $f20, $f12 - this.ee.fpr[20].f = this.ee.fpr[12].f; - // @0012892C SD s4, $0030(sp) - MobUt.SD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); - // @00128930 SD s0, $0010(sp) - MobUt.SD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); - // @00128934 DADDU s5, a1, zero - this.ee.s5.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - // @00128938 SD s1, $0018(sp) - MobUt.SD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); - // @0012893C DADDU s4, a0, zero - this.ee.s4.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); - // @00128940 SD s2, $0020(sp) - MobUt.SD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); - // @00128944 DADDU a1, sp, zero - this.ee.a1.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); - // @00128948 SD s3, $0028(sp) - MobUt.SD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); - // @0012894C SD ra, $0040(sp) - MobUt.SD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); - // @00128950 JAL $001283d8 - this.ee.ra.UL0 = 1214808u; - this.ee.pc = 1213400u; - // @00128954 DADDU s2, zero, zero - this.ee.s2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00128958() - { - this.ee.pc = 1214828u; - // @00128958 LW s1, $0004(s4) - MobUt.LW(this.ee, this.ee.s1, (4u + this.ee.s4.UL0)); - // @0012895C LW t7, $0030(s1) - MobUt.LW(this.ee, this.ee.t7, (48u + this.ee.s1.UL0)); - // @00128960 LW s3, $0034(s1) - MobUt.LW(this.ee, this.ee.s3, (52u + this.ee.s1.UL0)); - // @00128964 BLEZ s3, $001289e4 - if ((this.ee.s3.SD0 <= 0)) - { - this.ee.pc = 1214948u; - } - // @00128968 ADDU s0, s1, t7 - this.ee.s0.SD0 = ((int)((this.ee.s1.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012896c() - { - this.ee.pc = 1214852u; - // @0012896C MOV.S $f12, $f20 - this.ee.fpr[12].f = this.ee.fpr[20].f; - // @00128970 LW a2, $0000(sp) - MobUt.LW(this.ee, this.ee.a2, (0u + this.ee.sp.UL0)); - // @00128974 LW a3, $0004(sp) - MobUt.LW(this.ee, this.ee.a3, (4u + this.ee.sp.UL0)); - // @00128978 DADDU a0, s4, zero - this.ee.a0.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - // @0012897C JAL $00128530 - this.ee.ra.UL0 = 1214852u; - this.ee.pc = 1213744u; - // @00128980 DADDU a1, s0, zero - this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00128984() - { - this.ee.pc = 1214876u; - // @00128984 LBU t4, $0002(s0) - MobUt.LBU(this.ee, this.ee.t4, (2u + this.ee.s0.UL0)); - // @00128988 ANDI t7, t4, $000f - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 15))); - // @0012898C ANDI t7, t7, $00ff - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 255))); - // @00128990 SLTIU t6, t7, $0009 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < 9ul)); - // @00128994 BEQ t6, zero, $001289d4 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214932u; - } - // @00128998 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - } - - public virtual void funct0012899c() - { - this.ee.pc = 1214900u; - // @0012899C SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @001289A0 ADDIU t6, t6, $8244 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -32188))); - // @001289A4 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @001289A8 LW t5, $0000(t7) - MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); - // @001289AC JR t5 - this.ee.pc = this.ee.t5.UL[0]; - // @001289B0 NOP - MobUt.Latency(); - } - - public virtual void funct001289b4() - { - this.ee.pc = 1214948u; - // @001289B4 LHU t7, $0000(s0) - MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); - // @001289B8 ANDI t5, t4, $000f - this.ee.t5.UD0 = ((ushort)((this.ee.t4.US0 & 15))); - // @001289BC LW t6, $001c(s5) - MobUt.LW(this.ee, this.ee.t6, (28u + this.ee.s5.UL0)); - // @001289C0 SLL t5, t5, 2 - MobUt.SLL(this.ee.t5, this.ee.t5, 2); - // @001289C4 SLL t7, t7, 4 - MobUt.SLL(this.ee.t7, this.ee.t7, 4); - // @001289C8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @001289CC ADDU t6, t6, t5 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); - // @001289D0 SWC1 $f0, $0000(t6) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @001289D4 ADDIU s2, s2, $0001 - this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); - // @001289D8 SLT t7, s2, s3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.s3.SD0)); - // @001289DC BNE t7, zero, $0012896c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1214828u; - } - // @001289E0 ADDIU s0, s0, $0006 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 6))); - } - - public virtual void funct001289d4() - { - this.ee.pc = 1214948u; - // @001289D4 ADDIU s2, s2, $0001 - this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); - // @001289D8 SLT t7, s2, s3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.s3.SD0)); - // @001289DC BNE t7, zero, $0012896c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1214828u; - } - // @001289E0 ADDIU s0, s0, $0006 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 6))); - } - - public virtual void funct001289e4() - { - this.ee.pc = 1214976u; - // @001289E4 LW t6, $0018(s1) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.s1.UL0)); - // @001289E8 DADDU s2, zero, zero - this.ee.s2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @001289EC LW t7, $0038(s1) - MobUt.LW(this.ee, this.ee.t7, (56u + this.ee.s1.UL0)); - // @001289F0 LW s3, $003c(s1) - MobUt.LW(this.ee, this.ee.s3, (60u + this.ee.s1.UL0)); - // @001289F4 ADDU s5, s1, t6 - this.ee.s5.SD0 = ((int)((this.ee.s1.SD0 + this.ee.t6.SD0))); - // @001289F8 BLEZ s3, $00128a74 - if ((this.ee.s3.SD0 <= 0)) - { - this.ee.pc = 1215092u; - } - // @001289FC ADDU s0, s1, t7 - this.ee.s0.SD0 = ((int)((this.ee.s1.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct00128a00() - { - this.ee.pc = 1215000u; - // @00128A00 MOV.S $f12, $f20 - this.ee.fpr[12].f = this.ee.fpr[20].f; - // @00128A04 LW a2, $0000(sp) - MobUt.LW(this.ee, this.ee.a2, (0u + this.ee.sp.UL0)); - // @00128A08 LW a3, $0004(sp) - MobUt.LW(this.ee, this.ee.a3, (4u + this.ee.sp.UL0)); - // @00128A0C DADDU a0, s4, zero - this.ee.a0.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - // @00128A10 JAL $00128530 - this.ee.ra.UL0 = 1215000u; - this.ee.pc = 1213744u; - // @00128A14 DADDU a1, s0, zero - this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00128a18() - { - this.ee.pc = 1215024u; - // @00128A18 LBU t4, $0002(s0) - MobUt.LBU(this.ee, this.ee.t4, (2u + this.ee.s0.UL0)); - // @00128A1C ANDI t7, t4, $000f - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 15))); - // @00128A20 ANDI t7, t7, $00ff - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 255))); - // @00128A24 SLTIU t6, t7, $0009 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < 9ul)); - // @00128A28 BEQ t6, zero, $00128a64 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215076u; - } - // @00128A2C LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - } - - public virtual void funct00128a30() - { - this.ee.pc = 1215048u; - // @00128A30 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @00128A34 ADDIU t6, t6, $8268 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -32152))); - // @00128A38 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00128A3C LW t5, $0000(t7) - MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); - // @00128A40 JR t5 - this.ee.pc = this.ee.t5.UL[0]; - // @00128A44 NOP - MobUt.Latency(); - } - - public virtual void funct00128a48() - { - this.ee.pc = 1215092u; - // @00128A48 LHU t7, $0000(s0) - MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); - // @00128A4C ANDI t6, t4, $000f - this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 15))); - // @00128A50 SLL t6, t6, 2 - MobUt.SLL(this.ee.t6, this.ee.t6, 2); - // @00128A54 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @00128A58 ADDU t7, s5, t7 - this.ee.t7.SD0 = ((int)((this.ee.s5.SD0 + this.ee.t7.SD0))); - // @00128A5C ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00128A60 SWC1 $f0, $0010(t7) - MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.t7.UL0)); - // @00128A64 ADDIU s2, s2, $0001 - this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); - // @00128A68 SLT t7, s2, s3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.s3.SD0)); - // @00128A6C BNE t7, zero, $00128a00 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1214976u; - } - // @00128A70 ADDIU s0, s0, $0006 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 6))); - } - - public virtual void funct00128a64() - { - this.ee.pc = 1215092u; - // @00128A64 ADDIU s2, s2, $0001 - this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); - // @00128A68 SLT t7, s2, s3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.s3.SD0)); - // @00128A6C BNE t7, zero, $00128a00 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1214976u; - } - // @00128A70 ADDIU s0, s0, $0006 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 6))); - } - - public virtual void funct00128a74() - { - this.ee.pc = 1215132u; - // @00128A74 LD s0, $0010(sp) - MobUt.LD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); - // @00128A78 LD s1, $0018(sp) - MobUt.LD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); - // @00128A7C LD s2, $0020(sp) - MobUt.LD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); - // @00128A80 LD s3, $0028(sp) - MobUt.LD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); - // @00128A84 LD s4, $0030(sp) - MobUt.LD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); - // @00128A88 LD s5, $0038(sp) - MobUt.LD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); - // @00128A8C LD ra, $0040(sp) - MobUt.LD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); - // @00128A90 LWC1 $f20, $0048(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (72u + this.ee.sp.UL0)); - // @00128A94 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00128A98 ADDIU sp, sp, $0050 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 80))); - } - - public virtual void funct00128a9c() - { - this.ee.pc = 1215168u; - // @00128A9C LHU t7, $0000(s0) - MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); - // @00128AA0 ANDI t6, t4, $000f - this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 15))); - // @00128AA4 ADDIU t6, t6, $fffd - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -3))); - // @00128AA8 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @00128AAC SLL t6, t6, 2 - MobUt.SLL(this.ee.t6, this.ee.t6, 2); - // @00128AB0 ADDU t7, s5, t7 - this.ee.t7.SD0 = ((int)((this.ee.s5.SD0 + this.ee.t7.SD0))); - // @00128AB4 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00128AB8 BEQ zero, zero, $00128a64 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215076u; - } - // @00128ABC SWC1 $f0, $0020(t7) - MobUt.SWC1(this.ee, this.ee.fpr[0], (32u + this.ee.t7.UL0)); - } - - public virtual void funct00128ac0() - { - this.ee.pc = 1215204u; - // @00128AC0 LHU t7, $0000(s0) - MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); - // @00128AC4 ANDI t6, t4, $000f - this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 15))); - // @00128AC8 ADDIU t6, t6, $fffa - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -6))); - // @00128ACC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @00128AD0 SLL t6, t6, 2 - MobUt.SLL(this.ee.t6, this.ee.t6, 2); - // @00128AD4 ADDU t7, s5, t7 - this.ee.t7.SD0 = ((int)((this.ee.s5.SD0 + this.ee.t7.SD0))); - // @00128AD8 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00128ADC BEQ zero, zero, $00128a64 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215076u; - } - // @00128AE0 SWC1 $f0, $0030(t7) - MobUt.SWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t7.UL0)); - } - - public virtual void funct00128ae4() - { - this.ee.pc = 1215244u; - // @00128AE4 ANDI t6, t4, $000f - this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 15))); - // @00128AE8 LHU t7, $0000(s0) - MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); - // @00128AEC LW t5, $0020(s5) - MobUt.LW(this.ee, this.ee.t5, (32u + this.ee.s5.UL0)); - // @00128AF0 ADDIU t6, t6, $fffd - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -3))); - // @00128AF4 SLL t7, t7, 4 - MobUt.SLL(this.ee.t7, this.ee.t7, 4); - // @00128AF8 SLL t6, t6, 2 - MobUt.SLL(this.ee.t6, this.ee.t6, 2); - // @00128AFC ADDU t5, t5, t7 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t7.SD0))); - // @00128B00 ADDU t5, t5, t6 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @00128B04 BEQ zero, zero, $001289d4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214932u; - } - // @00128B08 SWC1 $f0, $0000(t5) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); - } - - public virtual void funct00128af4() - { - this.ee.pc = 1215244u; - // @00128AF4 SLL t7, t7, 4 - MobUt.SLL(this.ee.t7, this.ee.t7, 4); - // @00128AF8 SLL t6, t6, 2 - MobUt.SLL(this.ee.t6, this.ee.t6, 2); - // @00128AFC ADDU t5, t5, t7 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t7.SD0))); - // @00128B00 ADDU t5, t5, t6 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @00128B04 BEQ zero, zero, $001289d4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1214932u; - } - // @00128B08 SWC1 $f0, $0000(t5) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); - } - - public virtual void funct00128b0c() - { - this.ee.pc = 1215264u; - // @00128B0C ANDI t6, t4, $000f - this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 15))); - // @00128B10 LHU t7, $0000(s0) - MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); - // @00128B14 LW t5, $0024(s5) - MobUt.LW(this.ee, this.ee.t5, (36u + this.ee.s5.UL0)); - // @00128B18 BEQ zero, zero, $00128af4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215220u; - } - // @00128B1C ADDIU t6, t6, $fffa - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -6))); - } - - public virtual void funct00128b20() - { - this.ee.pc = 1215276u; - // @00128B20 ADDIU sp, sp, $ffe0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); - // @00128B24 BEQ a2, a0, $00128b34 - if ((this.ee.a2.UD0 == this.ee.a0.UD0)) - { - this.ee.pc = 1215284u; - } - // @00128B28 NOP - MobUt.Latency(); - } - - public virtual void funct00128b2c() - { - this.ee.pc = 1215376u; - // @00128B2C LQ t0, $0000(a0) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a0.UL[0])); - // @00128B30 SQ t0, $0000(a2) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a2.UL[0])); - // @00128B34 LQC2 vf1, $0000(a2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a2.UL0)); - // @00128B38 VMUL.xyz vf2, vf1, vf1 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); - // @00128B3C VADDy.x vf2, vf2, vf2y - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); - // @00128B40 VADDz.x vf2, vf2, vf2z - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); - // @00128B44 VSQRT Q, vf2x - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); - // @00128B48 VWAITQ - MobUt.Latency(); - // @00128B4C CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - // @00128B50 VADDq.x vf2, vf0, Q - this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); - // @00128B54 MTC1 t0, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00128B58 VNOP - MobUt.Latency(); - // @00128B5C VDIV Q, vf0w, vf2x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); - // @00128B60 VWAITQ - MobUt.Latency(); - // @00128B64 VMULq.xyz vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - // @00128B68 SQC2 vf1, $0000(a2) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.a2.UL0)); - // @00128B6C ADDIU t5, sp, $0010 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 16))); - // @00128B70 LQC2 vf1, $0000(a0) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a0.UL0)); - // @00128B74 LQC2 vf2, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a1.UL0)); - // @00128B78 VSUB.xyzw vf3, vf0, vf0 - this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); - this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); - this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); - this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); - // @00128B7C VOPMULA.xyz ACC, vf1, vf2 - this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); - this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); - this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); - // @00128B80 VOPMSUB.xyz vf3, vf2, vf1 - this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); - this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); - this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); - // @00128B84 SQC2 vf3, $0000(t5) - MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.t5.UL0)); - // @00128B88 BEQ sp, t5, $00128b9c - if ((this.ee.sp.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1215388u; - } - // @00128B8C ADDIU t7, a2, $0010 - this.ee.t7.SD0 = ((int)((this.ee.a2.SD0 + 16))); - } - - public virtual void funct00128b90() - { - this.ee.pc = 1215420u; - // @00128B90 LQ t0, $0000(t5) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @00128B94 SQ t0, $0000(sp) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); - // @00128B98 ADDIU t7, a2, $0010 - this.ee.t7.SD0 = ((int)((this.ee.a2.SD0 + 16))); - // @00128B9C LQC2 vf1, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @00128BA0 LQC2 vf2, $0000(a0) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a0.UL0)); - // @00128BA4 VSUB.xyzw vf3, vf0, vf0 - this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); - this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); - this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); - this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); - // @00128BA8 VOPMULA.xyz ACC, vf1, vf2 - this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); - this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); - this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); - // @00128BAC VOPMSUB.xyz vf3, vf2, vf1 - this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); - this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); - this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); - // @00128BB0 SQC2 vf3, $0000(t5) - MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.t5.UL0)); - // @00128BB4 BEQ t7, t5, $00128bc4 - if ((this.ee.t7.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1215428u; - } - // @00128BB8 NOP - MobUt.Latency(); - } - - public virtual void funct00128bbc() - { - this.ee.pc = 1215520u; - // @00128BBC LQ t0, $0000(t5) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @00128BC0 SQ t0, $0000(t7) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @00128BC4 LQC2 vf1, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t7.UL0)); - // @00128BC8 VMUL.xyz vf2, vf1, vf1 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); - // @00128BCC VADDy.x vf2, vf2, vf2y - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); - // @00128BD0 VADDz.x vf2, vf2, vf2z - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); - // @00128BD4 VSQRT Q, vf2x - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); - // @00128BD8 VWAITQ - MobUt.Latency(); - // @00128BDC CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - // @00128BE0 VADDq.x vf2, vf0, Q - this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); - // @00128BE4 MTC1 t0, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00128BE8 VNOP - MobUt.Latency(); - // @00128BEC VDIV Q, vf0w, vf2x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); - // @00128BF0 VWAITQ - MobUt.Latency(); - // @00128BF4 VMULq.xyz vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - // @00128BF8 SQC2 vf1, $0000(t7) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t7.UL0)); - // @00128BFC ADDIU t6, a2, $0020 - this.ee.t6.SD0 = ((int)((this.ee.a2.SD0 + 32))); - // @00128C00 LQC2 vf1, $0000(a0) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a0.UL0)); - // @00128C04 LQC2 vf2, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t7.UL0)); - // @00128C08 VSUB.xyzw vf3, vf0, vf0 - this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); - this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); - this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); - this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); - // @00128C0C VOPMULA.xyz ACC, vf1, vf2 - this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); - this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); - this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); - // @00128C10 VOPMSUB.xyz vf3, vf2, vf1 - this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); - this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); - this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); - // @00128C14 SQC2 vf3, $0000(t5) - MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.t5.UL0)); - // @00128C18 BEQ t6, t5, $00128c28 - if ((this.ee.t6.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1215528u; - } - // @00128C1C NOP - MobUt.Latency(); - } - - public virtual void funct00128c20() - { - this.ee.pc = 1215608u; - // @00128C20 LQ t0, $0000(t5) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @00128C24 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @00128C28 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00128C2C VMUL.xyz vf2, vf1, vf1 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); - // @00128C30 VADDy.x vf2, vf2, vf2y - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); - // @00128C34 VADDz.x vf2, vf2, vf2z - this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); - // @00128C38 VSQRT Q, vf2x - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); - // @00128C3C VWAITQ - MobUt.Latency(); - // @00128C40 CFC2 t0, $vi22 - MobUt.CFC2(this.ee.t0, this.ee.VI[22]); - // @00128C44 VADDq.x vf2, vf0, Q - this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); - // @00128C48 MTC1 t0, $f1 - this.ee.fpr[1].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00128C4C VNOP - MobUt.Latency(); - // @00128C50 VDIV Q, vf0w, vf2x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); - // @00128C54 VWAITQ - MobUt.Latency(); - // @00128C58 VMULq.xyz vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - // @00128C5C SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00128C60 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @00128C64 SWC1 $f0, $000c(a2) - MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.a2.UL0)); - // @00128C68 SWC1 $f0, $002c(a2) - MobUt.SWC1(this.ee, this.ee.fpr[0], (44u + this.ee.a2.UL0)); - // @00128C6C SWC1 $f0, $001c(a2) - MobUt.SWC1(this.ee, this.ee.fpr[0], (28u + this.ee.a2.UL0)); - // @00128C70 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00128C74 ADDIU sp, sp, $0020 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); - } - - public virtual void funct00128c78() - { - this.ee.pc = 1215628u; - // @00128C78 ADDIU sp, sp, $ffc0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -64))); - // @00128C7C DADDU t5, a2, zero - this.ee.t5.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); - // @00128C80 DADDU t4, a3, zero - this.ee.t4.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); - // @00128C84 BLTZ a3, $00128d9c - if ((this.ee.a3.SD0 < 0)) - { - this.ee.pc = 1215900u; - } - // @00128C88 DADDU t3, t0, zero - this.ee.t3.UD0 = (this.ee.t0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00128c8c() - { - this.ee.pc = 1215648u; - // @00128C8C LW t6, $0004(a0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.a0.UL0)); - // @00128C90 LHU a2, $0010(t6) - MobUt.LHU(this.ee, this.ee.a2, (16u + this.ee.t6.UL0)); - // @00128C94 SLT t7, t5, a2 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.a2.SD0)); - // @00128C98 BEQ t7, zero, $00128d8c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215884u; - } - // @00128C9C DADDU a3, sp, zero - this.ee.a3.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00128ca0() - { - this.ee.pc = 1215692u; - // @00128CA0 LW t6, $002c(a1) - MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.a1.UL0)); - // @00128CA4 SLL t7, t5, 6 - MobUt.SLL(this.ee.t7, this.ee.t5, 6); - // @00128CA8 ADDU a2, t6, t7 - this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00128CAC ADDIU t7, a2, $0030 - this.ee.t7.SD0 = ((int)((this.ee.a2.SD0 + 48))); - // @00128CB0 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @00128CB4 SQ t0, $0000(a3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a3.UL[0])); - // @00128CB8 LW t6, $0004(a0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.a0.UL0)); - // @00128CBC LHU a3, $0010(t6) - MobUt.LHU(this.ee, this.ee.a3, (16u + this.ee.t6.UL0)); - // @00128CC0 SLT t7, t4, a3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.a3.SD0)); - // @00128CC4 BEQ t7, zero, $00128d7c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215868u; - } - // @00128CC8 ADDIU t5, sp, $0010 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00128ca8() - { - this.ee.pc = 1215692u; - // @00128CA8 ADDU a2, t6, t7 - this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00128CAC ADDIU t7, a2, $0030 - this.ee.t7.SD0 = ((int)((this.ee.a2.SD0 + 48))); - // @00128CB0 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @00128CB4 SQ t0, $0000(a3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a3.UL[0])); - // @00128CB8 LW t6, $0004(a0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.a0.UL0)); - // @00128CBC LHU a3, $0010(t6) - MobUt.LHU(this.ee, this.ee.a3, (16u + this.ee.t6.UL0)); - // @00128CC0 SLT t7, t4, a3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.a3.SD0)); - // @00128CC4 BEQ t7, zero, $00128d7c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215868u; - } - // @00128CC8 ADDIU t5, sp, $0010 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00128ccc() - { - this.ee.pc = 1215780u; - // @00128CCC LW t6, $002c(a1) - MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.a1.UL0)); - // @00128CD0 SLL t7, t4, 6 - MobUt.SLL(this.ee.t7, this.ee.t4, 6); - // @00128CD4 ADDU a0, t6, t7 - this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00128CD8 ADDIU t7, a0, $0030 - this.ee.t7.SD0 = ((int)((this.ee.a0.SD0 + 48))); - // @00128CDC LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @00128CE0 SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @00128CE4 ADDIU t6, sp, $0030 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 48))); - // @00128CE8 LQC2 vf1, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @00128CEC LQC2 vf2, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t5.UL0)); - // @00128CF0 VADD.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y + this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z + this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w + this.ee.VF[2].w); - // @00128CF4 SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00128CF8 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00128CFC ADDIU t7, t7, $828c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32116))); - // @00128D00 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00128D04 ADDIU t7, sp, $0020 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 32))); - // @00128D08 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00128D0C MFC1 t0, $f0 - MobUt.MFC1(this.ee.t0, this.ee.fpr[0]); - // @00128D10 QMTC2 t0, vf2 - MobUt.QMTC2(this.ee.t0, this.ee.VF[2]); - // @00128D14 VMULx.xyzw vf1, vf1, vf2x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].x); - // @00128D18 SQC2 vf1, $0000(t7) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t7.UL0)); - // @00128D1C BEQ t3, t7, $00128d2c - if ((this.ee.t3.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1215788u; - } - // @00128D20 NOP - MobUt.Latency(); - } - - public virtual void funct00128cd4() - { - this.ee.pc = 1215780u; - // @00128CD4 ADDU a0, t6, t7 - this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00128CD8 ADDIU t7, a0, $0030 - this.ee.t7.SD0 = ((int)((this.ee.a0.SD0 + 48))); - // @00128CDC LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @00128CE0 SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @00128CE4 ADDIU t6, sp, $0030 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 48))); - // @00128CE8 LQC2 vf1, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @00128CEC LQC2 vf2, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t5.UL0)); - // @00128CF0 VADD.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y + this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z + this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w + this.ee.VF[2].w); - // @00128CF4 SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00128CF8 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00128CFC ADDIU t7, t7, $828c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32116))); - // @00128D00 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00128D04 ADDIU t7, sp, $0020 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 32))); - // @00128D08 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00128D0C MFC1 t0, $f0 - MobUt.MFC1(this.ee.t0, this.ee.fpr[0]); - // @00128D10 QMTC2 t0, vf2 - MobUt.QMTC2(this.ee.t0, this.ee.VF[2]); - // @00128D14 VMULx.xyzw vf1, vf1, vf2x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].x); - // @00128D18 SQC2 vf1, $0000(t7) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t7.UL0)); - // @00128D1C BEQ t3, t7, $00128d2c - if ((this.ee.t3.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1215788u; - } - // @00128D20 NOP - MobUt.Latency(); - } - - public virtual void funct00128d24() - { - this.ee.pc = 1215796u; - // @00128D24 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @00128D28 SQ t0, $0000(t3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); - // @00128D2C BEQ t1, zero, $00128d74 - if ((this.ee.t1.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215860u; - } - // @00128D30 NOP - MobUt.Latency(); - } - - public virtual void funct00128d2c() - { - this.ee.pc = 1215796u; - // @00128D2C BEQ t1, zero, $00128d74 - if ((this.ee.t1.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215860u; - } - // @00128D30 NOP - MobUt.Latency(); - } - - public virtual void funct00128d34() - { - this.ee.pc = 1215804u; - // @00128D34 BEQ t2, zero, $00128d74 - if ((this.ee.t2.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215860u; - } - // @00128D38 NOP - MobUt.Latency(); - } - - public virtual void funct00128d3c() - { - this.ee.pc = 1215852u; - // @00128D3C LQC2 vf5, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); - // @00128D40 LQC2 vf1, $0000(t1) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t1.UL0)); - // @00128D44 LQC2 vf2, $0010(t1) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t1.UL0)); - // @00128D48 LQC2 vf3, $0020(t1) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t1.UL0)); - // @00128D4C LQC2 vf4, $0030(t1) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t1.UL0)); - // @00128D50 VMULAx.xyzw ACC, vf1, vf5x - // @00128D54 VMADDAy.xyzw ACC, vf2, vf5y - // @00128D58 VMADDAz.xyzw ACC, vf3, vf5z - // @00128D5C VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @00128D60 SQC2 vf5, $0000(sp) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.sp.UL0)); - // @00128D64 BEQ t2, sp, $00128d74 - if ((this.ee.t2.UD0 == this.ee.sp.UD0)) - { - this.ee.pc = 1215860u; - } - // @00128D68 NOP - MobUt.Latency(); - } - - public virtual void funct00128d6c() - { - this.ee.pc = 1215868u; - // @00128D6C LQ t0, $0000(sp) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); - // @00128D70 SQ t0, $0000(t2) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t2.UL[0])); - // @00128D74 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00128D78 ADDIU sp, sp, $0040 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 64))); - } - - public virtual void funct00128d7c() - { - this.ee.pc = 1215884u; - // @00128D7C SUBU t7, t4, a3 - this.ee.t7.SD0 = ((int)((this.ee.t4.UD0 - this.ee.a3.UD0))); - // @00128D80 LW t6, $0010(a0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.a0.UL0)); - // @00128D84 BEQ zero, zero, $00128cd4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215700u; - } - // @00128D88 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct00128d8c() - { - this.ee.pc = 1215900u; - // @00128D8C SUBU t7, t5, a2 - this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.a2.UD0))); - // @00128D90 LW t6, $0010(a0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.a0.UL0)); - // @00128D94 BEQ zero, zero, $00128ca8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215656u; - } - // @00128D98 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct00128d9c() - { - this.ee.pc = 1215920u; - // @00128D9C LW t7, $0004(a0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); - // @00128DA0 LHU a2, $0010(t7) - MobUt.LHU(this.ee, this.ee.a2, (16u + this.ee.t7.UL0)); - // @00128DA4 SLT t6, t5, a2 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.a2.SD0)); - // @00128DA8 BEQ t6, zero, $00128dd8 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215960u; - } - // @00128DAC SUBU t7, t5, a2 - this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.a2.UD0))); - } - - public virtual void funct00128db0() - { - this.ee.pc = 1215944u; - // @00128DB0 LW t6, $002c(a1) - MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.a1.UL0)); - // @00128DB4 SLL t7, t5, 6 - MobUt.SLL(this.ee.t7, this.ee.t5, 6); - // @00128DB8 ADDU a0, t6, t7 - this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00128DBC ADDIU a0, a0, $0030 - this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 48))); - // @00128DC0 BEQ t3, a0, $00128d2c - if ((this.ee.t3.UD0 == this.ee.a0.UD0)) - { - this.ee.pc = 1215788u; - } - // @00128DC4 NOP - MobUt.Latency(); - } - - public virtual void funct00128db8() - { - this.ee.pc = 1215944u; - // @00128DB8 ADDU a0, t6, t7 - this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00128DBC ADDIU a0, a0, $0030 - this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 48))); - // @00128DC0 BEQ t3, a0, $00128d2c - if ((this.ee.t3.UD0 == this.ee.a0.UD0)) - { - this.ee.pc = 1215788u; - } - // @00128DC4 NOP - MobUt.Latency(); - } - - public virtual void funct00128dc8() - { - this.ee.pc = 1215960u; - // @00128DC8 LQ t0, $0000(a0) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a0.UL[0])); - // @00128DCC SQ t0, $0000(t3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); - // @00128DD0 BEQ zero, zero, $00128d2c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215788u; - } - // @00128DD4 NOP - MobUt.Latency(); - } - - public virtual void funct00128dd8() - { - this.ee.pc = 1215972u; - // @00128DD8 LW t6, $0010(a0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.a0.UL0)); - // @00128DDC BEQ zero, zero, $00128db8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1215928u; - } - // @00128DE0 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct00128de8() - { - this.ee.pc = 1216024u; - // @00128DE8 ADDIU sp, sp, $fff0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); - // @00128DEC DADDU t3, a3, zero - this.ee.t3.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); - // @00128DF0 SD ra, $0000(sp) - MobUt.SD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); - // @00128DF4 DADDU t5, t0, zero - this.ee.t5.UD0 = (this.ee.t0.UD0 + this.ee.r0.UD0); - // @00128DF8 DADDU t4, t1, zero - this.ee.t4.UD0 = (this.ee.t1.UD0 + this.ee.r0.UD0); - // @00128DFC ADDIU a3, zero, $ffff - this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + -1))); - // @00128E00 LBU t6, $0000(a2) - MobUt.LBU(this.ee, this.ee.t6, (0u + this.ee.a2.UL0)); - // @00128E04 DADDU t0, t3, zero - this.ee.t0.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); - // @00128E08 DADDU t1, t5, zero - this.ee.t1.UD0 = (this.ee.t5.UD0 + this.ee.r0.UD0); - // @00128E0C ADDIU t7, zero, $0005 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 5))); - // @00128E10 BNE t6, t7, $00128e2c - if ((this.ee.t6.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1216044u; - } - // @00128E14 DADDU t2, t4, zero - this.ee.t2.UD0 = (this.ee.t4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00128e20() - { - this.ee.pc = 1216044u; - // @00128E20 LD ra, $0000(sp) - MobUt.LD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); - // @00128E24 J $00128c78 - this.ee.pc = 1215608u; - // @00128E28 ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00128e2c() - { - this.ee.pc = 1216060u; - // @00128E2C LHU a2, $0004(a2) - MobUt.LHU(this.ee, this.ee.a2, (4u + this.ee.a2.UL0)); - // @00128E30 DADDU t0, t3, zero - this.ee.t0.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); - // @00128E34 BEQ zero, zero, $00128e20 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216032u; - } - // @00128E38 DADDU t1, t5, zero - this.ee.t1.UD0 = (this.ee.t5.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00128e40() - { - this.ee.pc = 1216136u; - // @00128E40 ADDIU sp, sp, $ff90 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -112))); - // @00128E44 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @00128E48 SD s2, $0030(sp) - MobUt.SD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); - // @00128E4C ANDI a2, a2, $ffff - this.ee.a2.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); - // @00128E50 SD s4, $0040(sp) - MobUt.SD(this.ee, this.ee.s4, (64u + this.ee.sp.UL0)); - // @00128E54 SD s0, $0020(sp) - MobUt.SD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); - // @00128E58 DADDU s2, a0, zero - this.ee.s2.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); - // @00128E5C SD s1, $0028(sp) - MobUt.SD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); - // @00128E60 SD s3, $0038(sp) - MobUt.SD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); - // @00128E64 SD s5, $0048(sp) - MobUt.SD(this.ee, this.ee.s5, (72u + this.ee.sp.UL0)); - // @00128E68 SD s6, $0050(sp) - MobUt.SD(this.ee, this.ee.s6, (80u + this.ee.sp.UL0)); - // @00128E6C SD ra, $0058(sp) - MobUt.SD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); - // @00128E70 SWC1 $f20, $0060(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (96u + this.ee.sp.UL0)); - // @00128E74 LW s0, $0004(a0) - MobUt.LW(this.ee, this.ee.s0, (4u + this.ee.a0.UL0)); - // @00128E78 LW t4, $006c(s0) - MobUt.LW(this.ee, this.ee.t4, (108u + this.ee.s0.UL0)); - // @00128E7C SLTU t7, a2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.UD0 < this.ee.t4.UD0)); - // @00128E80 BEQ t7, zero, $00128ee8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @00128E84 DADDU s4, a1, zero - this.ee.s4.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00128e88() - { - this.ee.pc = 1216176u; - // @00128E88 ADDIU t7, zero, $000c - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 12))); - // @00128E8C LW t6, $0068(s0) - MobUt.LW(this.ee, this.ee.t6, (104u + this.ee.s0.UL0)); - // @00128E90 MULT t7, a2, t7 - this.ee.t7.SD0 = (((long)(this.ee.a2.SL0)) * ((long)(this.ee.t7.SL0))); - // @00128E94 ADDU s1, s0, t6 - this.ee.s1.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t6.SD0))); - // @00128E98 ADDU s3, s1, t7 - this.ee.s3.SD0 = ((int)((this.ee.s1.SD0 + this.ee.t7.SD0))); - // @00128E9C LBU t3, $0000(s3) - MobUt.LBU(this.ee, this.ee.t3, (0u + this.ee.s3.UL0)); - // @00128EA0 ANDI t6, t3, $00ff - this.ee.t6.UD0 = ((ushort)((this.ee.t3.US0 & 255))); - // @00128EA4 SLTIU t7, t6, $002c - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 44ul)); - // @00128EA8 BEQ t7, zero, $00128ee8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @00128EAC SLL t7, t6, 2 - MobUt.SLL(this.ee.t7, this.ee.t6, 2); - } - - public virtual void funct00128eb0() - { - this.ee.pc = 1216200u; - // @00128EB0 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @00128EB4 ADDIU t6, t6, $82a0 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -32096))); - // @00128EB8 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00128EBC LW t5, $0000(t7) - MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); - // @00128EC0 JR t5 - this.ee.pc = this.ee.t5.UL[0]; - // @00128EC4 NOP - MobUt.Latency(); - } - - public virtual void funct00128ee8() - { - this.ee.pc = 1216276u; - // @00128EE8 LD s0, $0020(sp) - MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); - // @00128EEC LD s1, $0028(sp) - MobUt.LD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); - // @00128EF0 LD s2, $0030(sp) - MobUt.LD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); - // @00128EF4 LD s3, $0038(sp) - MobUt.LD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); - // @00128EF8 LD s4, $0040(sp) - MobUt.LD(this.ee, this.ee.s4, (64u + this.ee.sp.UL0)); - // @00128EFC LD s5, $0048(sp) - MobUt.LD(this.ee, this.ee.s5, (72u + this.ee.sp.UL0)); - // @00128F00 LD s6, $0050(sp) - MobUt.LD(this.ee, this.ee.s6, (80u + this.ee.sp.UL0)); - // @00128F04 LD ra, $0058(sp) - MobUt.LD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); - // @00128F08 LWC1 $f20, $0060(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (96u + this.ee.sp.UL0)); - // @00128F0C JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00128F10 ADDIU sp, sp, $0070 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 112))); - } - - public virtual void funct00128eec() - { - this.ee.pc = 1216276u; - // @00128EEC LD s1, $0028(sp) - MobUt.LD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); - // @00128EF0 LD s2, $0030(sp) - MobUt.LD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); - // @00128EF4 LD s3, $0038(sp) - MobUt.LD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); - // @00128EF8 LD s4, $0040(sp) - MobUt.LD(this.ee, this.ee.s4, (64u + this.ee.sp.UL0)); - // @00128EFC LD s5, $0048(sp) - MobUt.LD(this.ee, this.ee.s5, (72u + this.ee.sp.UL0)); - // @00128F00 LD s6, $0050(sp) - MobUt.LD(this.ee, this.ee.s6, (80u + this.ee.sp.UL0)); - // @00128F04 LD ra, $0058(sp) - MobUt.LD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); - // @00128F08 LWC1 $f20, $0060(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (96u + this.ee.sp.UL0)); - // @00128F0C JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00128F10 ADDIU sp, sp, $0070 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 112))); - } - - public virtual void funct00128f64() - { - this.ee.pc = 1216364u; - // @00128F64 JAL $00128e40 - this.ee.ra.UL0 = 1216364u; - this.ee.pc = 1216064u; - // @00128F68 LHU a2, $0008(s3) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); - } - - public virtual void funct00128f6c() - { - this.ee.pc = 1216372u; - // @00128F6C JAL $002ff8a8 - this.ee.ra.UL0 = 1216372u; - this.ee.pc = 3143848u; - // @00128F70 MOV.S $f12, $f0 - this.ee.fpr[12].f = this.ee.fpr[0].f; - } - - public virtual void funct00128f74() - { - this.ee.pc = 1216392u; - // @00128F74 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00128F78 ADDIU t7, t7, $8294 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32108))); - // @00128F7C LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00128F80 BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @00128F84 MUL.S $f0, $f1, $f0 - this.ee.fpr[0].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct00128f80() - { - this.ee.pc = 1216392u; - // @00128F80 BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @00128F84 MUL.S $f0, $f1, $f0 - this.ee.fpr[0].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct0012904c() - { - this.ee.pc = 1216596u; - // @0012904C JAL $00128e40 - this.ee.ra.UL0 = 1216596u; - this.ee.pc = 1216064u; - // @00129050 LHU a2, $0008(s3) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); - } - - public virtual void funct00129054() - { - this.ee.pc = 1216616u; - // @00129054 MOV.S $f20, $f0 - this.ee.fpr[20].f = this.ee.fpr[0].f; - // @00129058 LHU a2, $000a(s3) - MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); - // @0012905C DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @00129060 JAL $00128e40 - this.ee.ra.UL0 = 1216616u; - this.ee.pc = 1216064u; - // @00129064 DADDU a1, s4, zero - this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00129068() - { - this.ee.pc = 1216636u; - // @00129068 MOV.S $f1, $f0 - this.ee.fpr[1].f = this.ee.fpr[0].f; - // @0012906C MOV.S $f0, $f20 - this.ee.fpr[0].f = this.ee.fpr[20].f; - // @00129070 C.LT.S $f20, $f1 - this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[1].f); - // @00129074 BC1T $00128eec - if (this.ee.fcr31_23) - { - this.ee.pc = 1216236u; - } - // @00129078 LD s0, $0020(sp) - MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); - } - - public virtual void funct00129074() - { - this.ee.pc = 1216636u; - // @00129074 BC1T $00128eec - if (this.ee.fcr31_23) - { - this.ee.pc = 1216236u; - } - // @00129078 LD s0, $0020(sp) - MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); - } - - public virtual void funct0012907c() - { - this.ee.pc = 1216644u; - // @0012907C BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @00129080 MOV.S $f0, $f1 - this.ee.fpr[0].f = this.ee.fpr[1].f; - } - - public virtual void funct00129084() - { - this.ee.pc = 1216652u; - // @00129084 JAL $00128e40 - this.ee.ra.UL0 = 1216652u; - this.ee.pc = 1216064u; - // @00129088 LHU a2, $0008(s3) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); - } - - public virtual void funct0012908c() - { - this.ee.pc = 1216672u; - // @0012908C MOV.S $f20, $f0 - this.ee.fpr[20].f = this.ee.fpr[0].f; - // @00129090 LHU a2, $000a(s3) - MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); - // @00129094 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @00129098 JAL $00128e40 - this.ee.ra.UL0 = 1216672u; - this.ee.pc = 1216064u; - // @0012909C DADDU a1, s4, zero - this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001290a0() - { - this.ee.pc = 1216688u; - // @001290A0 MOV.S $f1, $f0 - this.ee.fpr[1].f = this.ee.fpr[0].f; - // @001290A4 MOV.S $f0, $f20 - this.ee.fpr[0].f = this.ee.fpr[20].f; - // @001290A8 BEQ zero, zero, $00129074 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216628u; - } - // @001290AC C.LT.S $f1, $f20 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[20].f); - } - - public virtual void funct00129118() - { - this.ee.pc = 1216812u; - // @00129118 NOP - MobUt.Latency(); - // @0012911C NOP - MobUt.Latency(); - // @00129120 DIV.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f / this.ee.fpr[0].f); - // @00129124 BEQ zero, zero, $00128eec - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216236u; - } - // @00129128 LD s0, $0020(sp) - MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); - } - - public virtual void funct0012912c() - { - this.ee.pc = 1216836u; - // @0012912C LHU t7, $0008(s3) - MobUt.LHU(this.ee, this.ee.t7, (8u + this.ee.s3.UL0)); - // @00129130 ADDIU s0, zero, $000c - this.ee.s0.SD0 = ((int)((this.ee.r0.SD0 + 12))); - // @00129134 MULT t7, t7, s0 - this.ee.t7.SD0 = (((long)(this.ee.t7.SL0)) * ((long)(this.ee.s0.SL0))); - // @00129138 ADDU t7, t7, s1 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s1.SD0))); - // @0012913C JAL $00128e40 - this.ee.ra.UL0 = 1216836u; - this.ee.pc = 1216064u; - // @00129140 LHU a2, $0008(t7) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.t7.UL0)); - } - - public virtual void funct00129144() - { - this.ee.pc = 1216852u; - // @00129144 MTC1 zero, $f1 - this.ee.fpr[1].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @00129148 C.EQ.S $f0, $f1 - this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[1].f); - // @0012914C BC1T $00129184 - if (this.ee.fcr31_23) - { - this.ee.pc = 1216900u; - } - // @00129150 LHU t6, $0008(s3) - MobUt.LHU(this.ee, this.ee.t6, (8u + this.ee.s3.UL0)); - } - - public virtual void funct00129154() - { - this.ee.pc = 1216892u; - // @00129154 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @00129158 DADDU a1, s4, zero - this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - // @0012915C MULT t6, t6, s0 - this.ee.t6.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.s0.SL0))); - // @00129160 ADDU t6, t6, s1 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s1.SD0))); - // @00129164 LHU t7, $000a(t6) - MobUt.LHU(this.ee, this.ee.t7, (10u + this.ee.t6.UL0)); - // @00129168 MULT t7, t7, s0 - this.ee.t7.SD0 = (((long)(this.ee.t7.SL0)) * ((long)(this.ee.s0.SL0))); - // @0012916C ADDU t7, t7, s1 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s1.SD0))); - // @00129170 LHU a2, $0008(t7) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.t7.UL0)); - // @00129174 JAL $00128e40 - this.ee.ra.UL0 = 1216892u; - this.ee.pc = 1216064u; - // @00129178 NOP - MobUt.Latency(); - } - - public virtual void funct00129174() - { - this.ee.pc = 1216892u; - // @00129174 JAL $00128e40 - this.ee.ra.UL0 = 1216892u; - this.ee.pc = 1216064u; - // @00129178 NOP - MobUt.Latency(); - } - - public virtual void funct0012917c() - { - this.ee.pc = 1216900u; - // @0012917C BEQ zero, zero, $00128eec - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216236u; - } - // @00129180 LD s0, $0020(sp) - MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); - } - - public virtual void funct00129184() - { - this.ee.pc = 1216948u; - // @00129184 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @00129188 DADDU a1, s4, zero - this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - // @0012918C MULT t6, t6, s0 - this.ee.t6.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.s0.SL0))); - // @00129190 ADDU t6, t6, s1 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s1.SD0))); - // @00129194 LHU t7, $000a(t6) - MobUt.LHU(this.ee, this.ee.t7, (10u + this.ee.t6.UL0)); - // @00129198 MULT t7, t7, s0 - this.ee.t7.SD0 = (((long)(this.ee.t7.SL0)) * ((long)(this.ee.s0.SL0))); - // @0012919C ADDU t7, t7, s1 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s1.SD0))); - // @001291A0 LHU t6, $000a(t7) - MobUt.LHU(this.ee, this.ee.t6, (10u + this.ee.t7.UL0)); - // @001291A4 MULT t6, t6, s0 - this.ee.t6.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.s0.SL0))); - // @001291A8 ADDU t6, t6, s1 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s1.SD0))); - // @001291AC BEQ zero, zero, $00129174 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216884u; - } - // @001291B0 LHU a2, $0008(t6) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.t6.UL0)); - } - - public virtual void funct0012927c() - { - this.ee.pc = 1217156u; - // @0012927C JAL $00128e40 - this.ee.ra.UL0 = 1217156u; - this.ee.pc = 1216064u; - // @00129280 LHU a2, $0008(s3) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); - } - - public virtual void funct00129284() - { - this.ee.pc = 1217176u; - // @00129284 MOV.S $f20, $f0 - this.ee.fpr[20].f = this.ee.fpr[0].f; - // @00129288 LHU a2, $000a(s3) - MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); - // @0012928C DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @00129290 JAL $00128e40 - this.ee.ra.UL0 = 1217176u; - this.ee.pc = 1216064u; - // @00129294 DADDU a1, s4, zero - this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00129298() - { - this.ee.pc = 1217184u; - // @00129298 BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @0012929C ADD.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f + this.ee.fpr[0].f); - } - - public virtual void funct001292a0() - { - this.ee.pc = 1217192u; - // @001292A0 JAL $00128e40 - this.ee.ra.UL0 = 1217192u; - this.ee.pc = 1216064u; - // @001292A4 LHU a2, $0008(s3) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); - } - - public virtual void funct001292a8() - { - this.ee.pc = 1217212u; - // @001292A8 MOV.S $f20, $f0 - this.ee.fpr[20].f = this.ee.fpr[0].f; - // @001292AC LHU a2, $000a(s3) - MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); - // @001292B0 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @001292B4 JAL $00128e40 - this.ee.ra.UL0 = 1217212u; - this.ee.pc = 1216064u; - // @001292B8 DADDU a1, s4, zero - this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001292bc() - { - this.ee.pc = 1217220u; - // @001292BC BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @001292C0 SUB.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f - this.ee.fpr[0].f); - } - - public virtual void funct001292c4() - { - this.ee.pc = 1217228u; - // @001292C4 JAL $00128e40 - this.ee.ra.UL0 = 1217228u; - this.ee.pc = 1216064u; - // @001292C8 LHU a2, $0008(s3) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); - } - - public virtual void funct001292cc() - { - this.ee.pc = 1217248u; - // @001292CC MOV.S $f20, $f0 - this.ee.fpr[20].f = this.ee.fpr[0].f; - // @001292D0 LHU a2, $000a(s3) - MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); - // @001292D4 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @001292D8 JAL $00128e40 - this.ee.ra.UL0 = 1217248u; - this.ee.pc = 1216064u; - // @001292DC DADDU a1, s4, zero - this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001292e0() - { - this.ee.pc = 1217256u; - // @001292E0 BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @001292E4 MUL.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - } - - public virtual void funct001292e8() - { - this.ee.pc = 1217264u; - // @001292E8 JAL $00128e40 - this.ee.ra.UL0 = 1217264u; - this.ee.pc = 1216064u; - // @001292EC LHU a2, $0008(s3) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); - } - - public virtual void funct001292f0() - { - this.ee.pc = 1217284u; - // @001292F0 MOV.S $f20, $f0 - this.ee.fpr[20].f = this.ee.fpr[0].f; - // @001292F4 LHU a2, $000a(s3) - MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); - // @001292F8 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @001292FC JAL $00128e40 - this.ee.ra.UL0 = 1217284u; - this.ee.pc = 1216064u; - // @00129300 DADDU a1, s4, zero - this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00129304() - { - this.ee.pc = 1217292u; - // @00129304 BEQ zero, zero, $00129118 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216792u; - } - // @00129308 NOP - MobUt.Latency(); - } - - public virtual void funct00129370() - { - this.ee.pc = 1217408u; - // @00129370 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00129374 ADDIU t7, t7, $829c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32100))); - // @00129378 BC1T $00128ee8 - if (this.ee.fcr31_23) - { - this.ee.pc = 1216232u; - } - // @0012937C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - } - - public virtual void funct00129380() - { - this.ee.pc = 1217416u; - // @00129380 BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @00129384 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - } - - public virtual void funct00129388() - { - this.ee.pc = 1217424u; - // @00129388 JAL $00128e40 - this.ee.ra.UL0 = 1217424u; - this.ee.pc = 1216064u; - // @0012938C LHU a2, $0008(s3) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); - } - - public virtual void funct00129390() - { - this.ee.pc = 1217444u; - // @00129390 MOV.S $f20, $f0 - this.ee.fpr[20].f = this.ee.fpr[0].f; - // @00129394 LHU a2, $000a(s3) - MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); - // @00129398 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @0012939C JAL $00128e40 - this.ee.ra.UL0 = 1217444u; - this.ee.pc = 1216064u; - // @001293A0 DADDU a1, s4, zero - this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001293a4() - { - this.ee.pc = 1217452u; - // @001293A4 BEQ zero, zero, $00129370 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1217392u; - } - // @001293A8 C.LT.S $f0, $f20 - this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[20].f); - } - - public virtual void funct001293d0() - { - this.ee.pc = 1217496u; - // @001293D0 JAL $00128e40 - this.ee.ra.UL0 = 1217496u; - this.ee.pc = 1216064u; - // @001293D4 LHU a2, $0008(s3) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); - } - - public virtual void funct001293d8() - { - this.ee.pc = 1217516u; - // @001293D8 MOV.S $f20, $f0 - this.ee.fpr[20].f = this.ee.fpr[0].f; - // @001293DC LHU a2, $000a(s3) - MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); - // @001293E0 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @001293E4 JAL $00128e40 - this.ee.ra.UL0 = 1217516u; - this.ee.pc = 1216064u; - // @001293E8 DADDU a1, s4, zero - this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001293ec() - { - this.ee.pc = 1217524u; - // @001293EC BEQ zero, zero, $00129370 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1217392u; - } - // @001293F0 C.LT.S $f20, $f0 - this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[0].f); - } - - public virtual void funct0012949c() - { - this.ee.pc = 1217704u; - // @0012949C LUI t7, $0035 - this.ee.t7.SD0 = 3473408; - // @001294A0 BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @001294A4 LWC1 $f0, $44e0(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (17632u + this.ee.t7.UL0)); - } - - public virtual void funct001294a8() - { - this.ee.pc = 1217712u; - // @001294A8 BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @001294AC LWC1 $f0, $0004(s3) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.s3.UL0)); - } - - public virtual void funct001294b0() - { - this.ee.pc = 1217728u; - // @001294B0 LW t7, $0000(s3) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.s3.UL0)); - // @001294B4 ANDI t7, t7, $0100 - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 256))); - // @001294B8 BEQ t7, zero, $00129504 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1217796u; - } - // @001294BC LHU a2, $0002(s3) - MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.s3.UL0)); - } - - public virtual void funct001294d4() - { - this.ee.pc = 1217784u; - // @001294D4 SLL t7, a2, 6 - MobUt.SLL(this.ee.t7, this.ee.a2, 6); - // @001294D8 ADDU a0, t6, t7 - this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @001294DC SLL t7, t3, 24 - MobUt.SLL(this.ee.t7, this.ee.t3, 24); - // @001294E0 SRA t7, t7, 24 - MobUt.SRA(this.ee.t7, this.ee.t7, 24); - // @001294E4 ADDIU t7, t7, $ffe0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32))); - // @001294E8 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @001294EC ADDU t7, a0, t7 - this.ee.t7.SD0 = ((int)((this.ee.a0.SD0 + this.ee.t7.SD0))); - // @001294F0 BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @001294F4 LWC1 $f0, $0030(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t7.UL0)); - } - - public virtual void funct001294d8() - { - this.ee.pc = 1217784u; - // @001294D8 ADDU a0, t6, t7 - this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @001294DC SLL t7, t3, 24 - MobUt.SLL(this.ee.t7, this.ee.t3, 24); - // @001294E0 SRA t7, t7, 24 - MobUt.SRA(this.ee.t7, this.ee.t7, 24); - // @001294E4 ADDIU t7, t7, $ffe0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32))); - // @001294E8 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @001294EC ADDU t7, a0, t7 - this.ee.t7.SD0 = ((int)((this.ee.a0.SD0 + this.ee.t7.SD0))); - // @001294F0 BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @001294F4 LWC1 $f0, $0030(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t7.UL0)); - } - - public virtual void funct001294f8() - { - this.ee.pc = 1217796u; - // @001294F8 SUBU t7, a2, t5 - this.ee.t7.SD0 = ((int)((this.ee.a2.UD0 - this.ee.t5.UD0))); - // @001294FC BEQ zero, zero, $001294d8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1217752u; - } - // @00129500 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct00129504() - { - this.ee.pc = 1217812u; - // @00129504 LHU t5, $0010(s0) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.s0.UL0)); - // @00129508 SLT t7, a2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); - // @0012950C BEQL t7, zero, $001294f8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1217784u; - // @00129510 LW t6, $000c(a0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.a0.UL0)); - } - } - - public virtual void funct00129514() - { - this.ee.pc = 1217820u; - // @00129514 BEQ zero, zero, $001294d4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1217748u; - } - // @00129518 LW t6, $0028(a1) - MobUt.LW(this.ee, this.ee.t6, (40u + this.ee.a1.UL0)); - } - - public virtual void funct0012951c() - { - this.ee.pc = 1217836u; - // @0012951C LW t7, $0000(s3) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.s3.UL0)); - // @00129520 ANDI t7, t7, $0100 - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 256))); - // @00129524 BEQL t7, zero, $001295ac - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1217964u; - // @00129528 LHU a2, $0002(s3) - MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.s3.UL0)); - } - } - - public virtual void funct00129580() - { - this.ee.pc = 1217936u; - // @00129580 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00129584 ADDIU t7, t7, $8294 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32108))); - // @00129588 BEQ zero, zero, $00128f80 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216384u; - } - // @0012958C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - } - - public virtual void funct001295ac() - { - this.ee.pc = 1217980u; - // @001295AC LHU t5, $0010(s0) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.s0.UL0)); - // @001295B0 SLT t7, a2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); - // @001295B4 BEQ t7, zero, $001295e0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1218016u; - } - // @001295B8 SLL t7, a2, 4 - MobUt.SLL(this.ee.t7, this.ee.a2, 4); - } - - public virtual void funct001295bc() - { - this.ee.pc = 1218016u; - // @001295BC LW t6, $0020(a1) - MobUt.LW(this.ee, this.ee.t6, (32u + this.ee.a1.UL0)); - // @001295C0 ADDU a1, t6, t7 - this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @001295C4 SLL t7, t3, 24 - MobUt.SLL(this.ee.t7, this.ee.t3, 24); - // @001295C8 SRA t7, t7, 24 - MobUt.SRA(this.ee.t7, this.ee.t7, 24); - // @001295CC ADDIU t7, t7, $ffdd - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -35))); - // @001295D0 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @001295D4 ADDU t7, a1, t7 - this.ee.t7.SD0 = ((int)((this.ee.a1.SD0 + this.ee.t7.SD0))); - // @001295D8 BEQ zero, zero, $00129580 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1217920u; - } - // @001295DC LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - } - - public virtual void funct001295c4() - { - this.ee.pc = 1218016u; - // @001295C4 SLL t7, t3, 24 - MobUt.SLL(this.ee.t7, this.ee.t3, 24); - // @001295C8 SRA t7, t7, 24 - MobUt.SRA(this.ee.t7, this.ee.t7, 24); - // @001295CC ADDIU t7, t7, $ffdd - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -35))); - // @001295D0 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @001295D4 ADDU t7, a1, t7 - this.ee.t7.SD0 = ((int)((this.ee.a1.SD0 + this.ee.t7.SD0))); - // @001295D8 BEQ zero, zero, $00129580 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1217920u; - } - // @001295DC LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - } - - public virtual void funct001295e0() - { - this.ee.pc = 1218044u; - // @001295E0 LW t6, $0018(s0) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.s0.UL0)); - // @001295E4 SUBU t7, a2, t5 - this.ee.t7.SD0 = ((int)((this.ee.a2.UD0 - this.ee.t5.UD0))); - // @001295E8 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @001295EC ADDU t6, s0, t6 - this.ee.t6.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t6.SD0))); - // @001295F0 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @001295F4 BEQ zero, zero, $001295c4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1217988u; - } - // @001295F8 ADDIU a1, t6, $0020 - this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + 32))); - } - - public virtual void funct001295fc() - { - this.ee.pc = 1218060u; - // @001295FC LW t7, $0000(s3) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.s3.UL0)); - // @00129600 ANDI t7, t7, $0100 - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 256))); - // @00129604 BEQ t7, zero, $00129634 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1218100u; - } - // @00129608 SLL t6, t3, 24 - MobUt.SLL(this.ee.t6, this.ee.t3, 24); - } - - public virtual void funct00129634() - { - this.ee.pc = 1218120u; - // @00129634 LHU a2, $0002(s3) - MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.s3.UL0)); - // @00129638 LHU t5, $0010(s0) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.s0.UL0)); - // @0012963C SLT t7, a2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); - // @00129640 BEQ t7, zero, $0012966c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1218156u; - } - // @00129644 SLL t7, a2, 4 - MobUt.SLL(this.ee.t7, this.ee.a2, 4); - } - - public virtual void funct00129648() - { - this.ee.pc = 1218156u; - // @00129648 LW t6, $001c(a1) - MobUt.LW(this.ee, this.ee.t6, (28u + this.ee.a1.UL0)); - // @0012964C ADDU a1, t6, t7 - this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00129650 SLL t7, t3, 24 - MobUt.SLL(this.ee.t7, this.ee.t3, 24); - // @00129654 SRA t7, t7, 24 - MobUt.SRA(this.ee.t7, this.ee.t7, 24); - // @00129658 ADDIU t7, t7, $ffda - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -38))); - // @0012965C SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @00129660 ADDU t7, a1, t7 - this.ee.t7.SD0 = ((int)((this.ee.a1.SD0 + this.ee.t7.SD0))); - // @00129664 BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @00129668 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - } - - public virtual void funct00129650() - { - this.ee.pc = 1218156u; - // @00129650 SLL t7, t3, 24 - MobUt.SLL(this.ee.t7, this.ee.t3, 24); - // @00129654 SRA t7, t7, 24 - MobUt.SRA(this.ee.t7, this.ee.t7, 24); - // @00129658 ADDIU t7, t7, $ffda - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -38))); - // @0012965C SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @00129660 ADDU t7, a1, t7 - this.ee.t7.SD0 = ((int)((this.ee.a1.SD0 + this.ee.t7.SD0))); - // @00129664 BEQ zero, zero, $00128ee8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216232u; - } - // @00129668 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - } - - public virtual void funct0012966c() - { - this.ee.pc = 1218184u; - // @0012966C LW t6, $0018(s0) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.s0.UL0)); - // @00129670 SUBU t7, a2, t5 - this.ee.t7.SD0 = ((int)((this.ee.a2.UD0 - this.ee.t5.UD0))); - // @00129674 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @00129678 ADDU t6, s0, t6 - this.ee.t6.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t6.SD0))); - // @0012967C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00129680 BEQ zero, zero, $00129650 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1218128u; - } - // @00129684 ADDIU a1, t6, $0010 - this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + 16))); - } - - public virtual void funct00129688() - { - this.ee.pc = 1218192u; - // @00129688 JAL $00128e40 - this.ee.ra.UL0 = 1218192u; - this.ee.pc = 1216064u; - // @0012968C LHU a2, $0008(s3) - MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); - } - - public virtual void funct00129690() - { - this.ee.pc = 1218244u; - // @00129690 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00129694 LWC1 $f2, $0098(s0) - MobUt.LWC1(this.ee, this.ee.fpr[2], (152u + this.ee.s0.UL0)); - // @00129698 ADDIU t7, t7, $8298 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32104))); - // @0012969C DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @001296A0 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @001296A4 ADDIU a1, sp, $0010 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 16))); - // @001296A8 ADDIU a2, sp, $0014 - this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 20))); - // @001296AC MUL.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[1].f); - // @001296B0 NOP - MobUt.Latency(); - // @001296B4 NOP - MobUt.Latency(); - // @001296B8 DIV.S $f20, $f0, $f2 - this.ee.fpr[20].f = (this.ee.fpr[0].f / this.ee.fpr[2].f); - // @001296BC JAL $001283d8 - this.ee.ra.UL0 = 1218244u; - this.ee.pc = 1213400u; - // @001296C0 MOV.S $f12, $f20 - this.ee.fpr[12].f = this.ee.fpr[20].f; - } - - public virtual void funct001296c4() - { - this.ee.pc = 1218264u; - // @001296C4 LHU t5, $000a(s3) - MobUt.LHU(this.ee, this.ee.t5, (10u + this.ee.s3.UL0)); - // @001296C8 LW t6, $0034(s0) - MobUt.LW(this.ee, this.ee.t6, (52u + this.ee.s0.UL0)); - // @001296CC SLTU t7, t5, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.UD0 < this.ee.t6.UD0)); - // @001296D0 BNEL t7, zero, $00129728 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1218344u; - // @001296D4 ADDIU t6, zero, $0006 - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 6))); - } - } - - public virtual void funct001296d8() - { - this.ee.pc = 1218308u; - // @001296D8 SUBU t5, t5, t6 - this.ee.t5.SD0 = ((int)((this.ee.t5.UD0 - this.ee.t6.UD0))); - // @001296DC LW t7, $0038(s0) - MobUt.LW(this.ee, this.ee.t7, (56u + this.ee.s0.UL0)); - // @001296E0 ADDIU t6, zero, $0006 - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 6))); - // @001296E4 MULT t5, t5, t6 - this.ee.t5.SD0 = (((long)(this.ee.t5.SL0)) * ((long)(this.ee.t6.SL0))); - // @001296E8 ADDU t7, s0, t7 - this.ee.t7.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t7.SD0))); - // @001296EC ADDU a1, t7, t5 - this.ee.a1.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); - // @001296F0 MOV.S $f12, $f20 - this.ee.fpr[12].f = this.ee.fpr[20].f; - // @001296F4 LW a2, $0010(sp) - MobUt.LW(this.ee, this.ee.a2, (16u + this.ee.sp.UL0)); - // @001296F8 LW a3, $0014(sp) - MobUt.LW(this.ee, this.ee.a3, (20u + this.ee.sp.UL0)); - // @001296FC JAL $00128530 - this.ee.ra.UL0 = 1218308u; - this.ee.pc = 1213744u; - // @00129700 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00129704() - { - this.ee.pc = 1218324u; - // @00129704 LB t6, $0000(s3) - MobUt.LB(this.ee, this.ee.t6, (0u + this.ee.s3.UL0)); - // @00129708 ADDIU t7, zero, $002b - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 43))); - // @0012970C BNE t6, t7, $0012907c - if ((this.ee.t6.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1216636u; - } - // @00129710 MOV.S $f1, $f0 - this.ee.fpr[1].f = this.ee.fpr[0].f; - } - - public virtual void funct00129714() - { - this.ee.pc = 1218344u; - // @00129714 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00129718 ADDIU t7, t7, $8294 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32108))); - // @0012971C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00129720 BEQ zero, zero, $0012907c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1216636u; - } - // @00129724 MUL.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct00129a18() - { - this.ee.pc = 1219268u; - // @00129A18 ADDIU sp, sp, $fd00 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -768))); - // @00129A1C ADDIU t7, zero, $000c - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 12))); - // @00129A20 SD s0, $02a0(sp) - MobUt.SD(this.ee, this.ee.s0, (672u + this.ee.sp.UL0)); - // @00129A24 SD s1, $02a8(sp) - MobUt.SD(this.ee, this.ee.s1, (680u + this.ee.sp.UL0)); - // @00129A28 SD s5, $02c8(sp) - MobUt.SD(this.ee, this.ee.s5, (712u + this.ee.sp.UL0)); - // @00129A2C DADDU s0, a0, zero - this.ee.s0.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); - // @00129A30 SD s6, $02d0(sp) - MobUt.SD(this.ee, this.ee.s6, (720u + this.ee.sp.UL0)); - // @00129A34 SD s2, $02b0(sp) - MobUt.SD(this.ee, this.ee.s2, (688u + this.ee.sp.UL0)); - // @00129A38 DADDU s5, a1, zero - this.ee.s5.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - // @00129A3C SD s3, $02b8(sp) - MobUt.SD(this.ee, this.ee.s3, (696u + this.ee.sp.UL0)); - // @00129A40 SD s4, $02c0(sp) - MobUt.SD(this.ee, this.ee.s4, (704u + this.ee.sp.UL0)); - // @00129A44 SD s7, $02d8(sp) - MobUt.SD(this.ee, this.ee.s7, (728u + this.ee.sp.UL0)); - // @00129A48 SD s8, $02e0(sp) - MobUt.SD(this.ee, this.ee.s8, (736u + this.ee.sp.UL0)); - // @00129A4C SD ra, $02e8(sp) - MobUt.SD(this.ee, this.ee.ra, (744u + this.ee.sp.UL0)); - // @00129A50 SWC1 $f20, $02f0(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (752u + this.ee.sp.UL0)); - // @00129A54 LW t3, $0004(a0) - MobUt.LW(this.ee, this.ee.t3, (4u + this.ee.a0.UL0)); - // @00129A58 SW a2, $01f0(sp) - MobUt.SW(this.ee, this.ee.a2, (496u + this.ee.sp.UL0)); - // @00129A5C DADDU a0, sp, zero - this.ee.a0.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); - // @00129A60 SW t3, $01fc(sp) - MobUt.SW(this.ee, this.ee.t3, (508u + this.ee.sp.UL0)); - // @00129A64 SW a3, $01f4(sp) - MobUt.SW(this.ee, this.ee.a3, (500u + this.ee.sp.UL0)); - // @00129A68 LW t4, $01fc(sp) - MobUt.LW(this.ee, this.ee.t4, (508u + this.ee.sp.UL0)); - // @00129A6C LW t6, $0054(t3) - MobUt.LW(this.ee, this.ee.t6, (84u + this.ee.t3.UL0)); - // @00129A70 SW t0, $01f8(sp) - MobUt.SW(this.ee, this.ee.t0, (504u + this.ee.sp.UL0)); - // @00129A74 MULT t6, t6, t7 - this.ee.t6.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.t7.SL0))); - // @00129A78 LW t3, $0050(t3) - MobUt.LW(this.ee, this.ee.t3, (80u + this.ee.t3.UL0)); - // @00129A7C LW t5, $0060(t4) - MobUt.LW(this.ee, this.ee.t5, (96u + this.ee.t4.UL0)); - // @00129A80 ADDU s1, t4, t3 - this.ee.s1.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t3.SD0))); - // @00129A84 LW t7, $0064(t4) - MobUt.LW(this.ee, this.ee.t7, (100u + this.ee.t4.UL0)); - // @00129A88 LW t3, $01fc(sp) - MobUt.LW(this.ee, this.ee.t3, (508u + this.ee.sp.UL0)); - // @00129A8C ADDU t6, s1, t6 - this.ee.t6.SD0 = ((int)((this.ee.s1.SD0 + this.ee.t6.SD0))); - // @00129A90 LW t4, $001c(t4) - MobUt.LW(this.ee, this.ee.t4, (28u + this.ee.t4.UL0)); - // @00129A94 SLL t7, t7, 3 - MobUt.SLL(this.ee.t7, this.ee.t7, 3); - // @00129A98 ADDU s6, t3, t5 - this.ee.s6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t5.SD0))); - // @00129A9C LW t3, $00a0(t3) - MobUt.LW(this.ee, this.ee.t3, (160u + this.ee.t3.UL0)); - // @00129AA0 ADDU t7, s6, t7 - this.ee.t7.SD0 = ((int)((this.ee.s6.SD0 + this.ee.t7.SD0))); - // @00129AA4 LW t5, $01fc(sp) - MobUt.LW(this.ee, this.ee.t5, (508u + this.ee.sp.UL0)); - // @00129AA8 SW t6, $0204(sp) - MobUt.SW(this.ee, this.ee.t6, (516u + this.ee.sp.UL0)); - // @00129AAC ADDU t4, t5, t4 - this.ee.t4.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t4.SD0))); - // @00129AB0 SW t7, $0208(sp) - MobUt.SW(this.ee, this.ee.t7, (520u + this.ee.sp.UL0)); - // @00129AB4 ADDU t3, t5, t3 - this.ee.t3.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t3.SD0))); - // @00129AB8 SW t4, $0200(sp) - MobUt.SW(this.ee, this.ee.t4, (512u + this.ee.sp.UL0)); - // @00129ABC JAL $0011b420 - this.ee.ra.UL0 = 1219268u; - this.ee.pc = 1160224u; - // @00129AC0 SW t3, $020c(sp) - MobUt.SW(this.ee, this.ee.t3, (524u + this.ee.sp.UL0)); - } - - public virtual void funct00129ac4() - { - this.ee.pc = 1219288u; - // @00129AC4 SW zero, $0210(sp) - MobUt.SW(this.ee, this.ee.r0, (528u + this.ee.sp.UL0)); - // @00129AC8 LW t6, $01fc(sp) - MobUt.LW(this.ee, this.ee.t6, (508u + this.ee.sp.UL0)); - // @00129ACC LHU t7, $0012(t6) - MobUt.LHU(this.ee, this.ee.t7, (18u + this.ee.t6.UL0)); - // @00129AD0 BEQL t7, zero, $0012a4c0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1221824u; - // @00129AD4 LD s0, $02a0(sp) - MobUt.LD(this.ee, this.ee.s0, (672u + this.ee.sp.UL0)); - } - } - - public virtual void funct00129ad8() - { - this.ee.pc = 1219320u; - // @00129AD8 LW t7, $0200(sp) - MobUt.LW(this.ee, this.ee.t7, (512u + this.ee.sp.UL0)); - // @00129ADC LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @00129AE0 LW s4, $0000(t7) - MobUt.LW(this.ee, this.ee.s4, (0u + this.ee.t7.UL0)); - // @00129AE4 LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @00129AE8 ANDI s2, s4, $ffff - this.ee.s2.UD0 = ((ushort)((this.ee.s4.US0 & 65535))); - // @00129AEC SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @00129AF0 BEQL t7, zero, $0012d4f4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1234164u; - // @00129AF4 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct00129af8() - { - this.ee.pc = 1219340u; - // @00129AF8 LW a0, $0014(s5) - MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); - // @00129AFC LW t7, $0000(a0) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); - // @00129B00 LW v0, $0020(t7) - MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); - // @00129B04 JALR ra, v0 - this.ee.ra.UD0 = 1219340u; - this.ee.pc = this.ee.v0.UL0; - // @00129B08 SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - } - - public virtual void funct00129b0c() - { - this.ee.pc = 1219360u; - // @00129B0C ADDU v0, v0, s3 - this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.s3.SD0))); - // @00129B10 LH v0, $0004(v0) - MobUt.LH(this.ee, this.ee.v0, (4u + this.ee.v0.UL0)); - // @00129B14 LW t3, $0208(sp) - MobUt.LW(this.ee, this.ee.t3, (520u + this.ee.sp.UL0)); - // @00129B18 BEQ s6, t3, $0012d4ec - if ((this.ee.s6.UD0 == this.ee.t3.UD0)) - { - this.ee.pc = 1234156u; - } - // @00129B1C SW v0, $0214(sp) - MobUt.SW(this.ee, this.ee.v0, (532u + this.ee.sp.UL0)); - } - - public virtual void funct00129b10() - { - this.ee.pc = 1219360u; - // @00129B10 LH v0, $0004(v0) - MobUt.LH(this.ee, this.ee.v0, (4u + this.ee.v0.UL0)); - // @00129B14 LW t3, $0208(sp) - MobUt.LW(this.ee, this.ee.t3, (520u + this.ee.sp.UL0)); - // @00129B18 BEQ s6, t3, $0012d4ec - if ((this.ee.s6.UD0 == this.ee.t3.UD0)) - { - this.ee.pc = 1234156u; - } - // @00129B1C SW v0, $0214(sp) - MobUt.SW(this.ee, this.ee.v0, (532u + this.ee.sp.UL0)); - } - - public virtual void funct00129b20() - { - this.ee.pc = 1219380u; - // @00129B20 ANDI t6, s2, $ffff - this.ee.t6.UD0 = ((ushort)((this.ee.s2.US0 & 65535))); - // @00129B24 LHU t7, $0000(s6) - MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); - // @00129B28 DADDU s3, t6, zero - this.ee.s3.UD0 = (this.ee.t6.UD0 + this.ee.r0.UD0); - // @00129B2C BNE t7, t6, $00129bc4 - if ((this.ee.t7.UD0 != this.ee.t6.UD0)) - { - this.ee.pc = 1219524u; - } - // @00129B30 SLL s8, s2, 4 - MobUt.SLL(this.ee.s8, this.ee.s2, 4); - } - - public virtual void funct00129b34() - { - this.ee.pc = 1219396u; - // @00129B34 LHU a2, $0006(s6) - MobUt.LHU(this.ee, this.ee.a2, (6u + this.ee.s6.UL0)); - // @00129B38 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @00129B3C JAL $00128e40 - this.ee.ra.UL0 = 1219396u; - this.ee.pc = 1216064u; - // @00129B40 DADDU a1, s5, zero - this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00129b38() - { - this.ee.pc = 1219396u; - // @00129B38 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @00129B3C JAL $00128e40 - this.ee.ra.UL0 = 1219396u; - this.ee.pc = 1216064u; - // @00129B40 DADDU a1, s5, zero - this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00129b44() - { - this.ee.pc = 1219416u; - // @00129B44 LHU t4, $0002(s6) - MobUt.LHU(this.ee, this.ee.t4, (2u + this.ee.s6.UL0)); - // @00129B48 ANDI t6, t4, $ffff - this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @00129B4C SLTIU t7, t6, $0009 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 9ul)); - // @00129B50 BEQ t7, zero, $00129ba0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219488u; - } - // @00129B54 MOV.S $f1, $f0 - this.ee.fpr[1].f = this.ee.fpr[0].f; - } - - public virtual void funct00129b58() - { - this.ee.pc = 1219444u; - // @00129B58 SLL t7, t6, 2 - MobUt.SLL(this.ee.t7, this.ee.t6, 2); - // @00129B5C LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @00129B60 ADDIU t6, t6, $8368 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -31896))); - // @00129B64 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00129B68 LW t5, $0000(t7) - MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); - // @00129B6C JR t5 - this.ee.pc = this.ee.t5.UL[0]; - // @00129B70 NOP - MobUt.Latency(); - } - - public virtual void funct00129b74() - { - this.ee.pc = 1219464u; - // @00129B74 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @00129B78 LHU t3, $0010(t5) - MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t5.UL0)); - // @00129B7C SLT t7, s2, t3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); - // @00129B80 BEQL t7, zero, $0012d438 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233976u; - // @00129B84 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct00129b88() - { - this.ee.pc = 1219512u; - // @00129B88 LW t7, $001c(s5) - MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); - // @00129B8C ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @00129B90 ANDI t7, t4, $ffff - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @00129B94 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @00129B98 ADDU t7, t6, t7 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00129B9C SWC1 $f1, $0000(t7) - MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00129BA0 LUI t7, $ffdf - this.ee.t7.SD0 = -2162688; - // @00129BA4 LW t5, $0208(sp) - MobUt.LW(this.ee, this.ee.t5, (520u + this.ee.sp.UL0)); - // @00129BA8 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @00129BAC ADDIU s6, s6, $0008 - this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 8))); - // @00129BB0 BEQ s6, t5, $00129bc4 - if ((this.ee.s6.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1219524u; - } - // @00129BB4 AND s4, s4, t7 - this.ee.s4.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - } - - public virtual void funct00129b90() - { - this.ee.pc = 1219512u; - // @00129B90 ANDI t7, t4, $ffff - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @00129B94 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @00129B98 ADDU t7, t6, t7 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00129B9C SWC1 $f1, $0000(t7) - MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00129BA0 LUI t7, $ffdf - this.ee.t7.SD0 = -2162688; - // @00129BA4 LW t5, $0208(sp) - MobUt.LW(this.ee, this.ee.t5, (520u + this.ee.sp.UL0)); - // @00129BA8 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @00129BAC ADDIU s6, s6, $0008 - this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 8))); - // @00129BB0 BEQ s6, t5, $00129bc4 - if ((this.ee.s6.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1219524u; - } - // @00129BB4 AND s4, s4, t7 - this.ee.s4.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - } - - public virtual void funct00129b94() - { - this.ee.pc = 1219512u; - // @00129B94 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @00129B98 ADDU t7, t6, t7 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00129B9C SWC1 $f1, $0000(t7) - MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00129BA0 LUI t7, $ffdf - this.ee.t7.SD0 = -2162688; - // @00129BA4 LW t5, $0208(sp) - MobUt.LW(this.ee, this.ee.t5, (520u + this.ee.sp.UL0)); - // @00129BA8 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @00129BAC ADDIU s6, s6, $0008 - this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 8))); - // @00129BB0 BEQ s6, t5, $00129bc4 - if ((this.ee.s6.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1219524u; - } - // @00129BB4 AND s4, s4, t7 - this.ee.s4.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - } - - public virtual void funct00129ba0() - { - this.ee.pc = 1219512u; - // @00129BA0 LUI t7, $ffdf - this.ee.t7.SD0 = -2162688; - // @00129BA4 LW t5, $0208(sp) - MobUt.LW(this.ee, this.ee.t5, (520u + this.ee.sp.UL0)); - // @00129BA8 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @00129BAC ADDIU s6, s6, $0008 - this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 8))); - // @00129BB0 BEQ s6, t5, $00129bc4 - if ((this.ee.s6.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1219524u; - } - // @00129BB4 AND s4, s4, t7 - this.ee.s4.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - } - - public virtual void funct00129bb8() - { - this.ee.pc = 1219524u; - // @00129BB8 LHU t7, $0000(s6) - MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); - // @00129BBC BEQL t7, s3, $00129b38 - if ((this.ee.t7.UD0 == this.ee.s3.UD0)) - { - this.ee.pc = 1219384u; - // @00129BC0 LHU a2, $0006(s6) - MobUt.LHU(this.ee, this.ee.a2, (6u + this.ee.s6.UL0)); - } - } - - public virtual void funct00129bc4() - { - this.ee.pc = 1219560u; - // @00129BC4 SW zero, $0218(sp) - MobUt.SW(this.ee, this.ee.r0, (536u + this.ee.sp.UL0)); - // @00129BC8 ADDIU a2, zero, $ffff - this.ee.a2.SD0 = ((int)((this.ee.r0.SD0 + -1))); - // @00129BCC SW zero, $021c(sp) - MobUt.SW(this.ee, this.ee.r0, (540u + this.ee.sp.UL0)); - // @00129BD0 ADDIU a3, zero, $ffff - this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + -1))); - // @00129BD4 LW t6, $0204(sp) - MobUt.LW(this.ee, this.ee.t6, (516u + this.ee.sp.UL0)); - // @00129BD8 DADDU v0, zero, zero - this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00129BDC ADDIU v1, zero, $ffff - this.ee.v1.SD0 = ((int)((this.ee.r0.SD0 + -1))); - // @00129BE0 BEQ s1, t6, $00129c58 - if ((this.ee.s1.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1219672u; - } - // @00129BE4 DADDU t3, zero, zero - this.ee.t3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00129be8() - { - this.ee.pc = 1219576u; - // @00129BE8 ANDI t6, s2, $ffff - this.ee.t6.UD0 = ((ushort)((this.ee.s2.US0 & 65535))); - // @00129BEC LHU t7, $0002(s1) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); - // @00129BF0 BNE t7, t6, $00129c58 - if ((this.ee.t7.UD0 != this.ee.t6.UD0)) - { - this.ee.pc = 1219672u; - } - // @00129BF4 DADDU t4, t6, zero - this.ee.t4.UD0 = (this.ee.t6.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00129bf8() - { - this.ee.pc = 1219588u; - // @00129BF8 LBU t7, $0001(s1) - MobUt.LBU(this.ee, this.ee.t7, (1u + this.ee.s1.UL0)); - // @00129BFC BEQ t7, zero, $00129c40 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219648u; - } - // @00129C00 LW t7, $0204(sp) - MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); - } - - public virtual void funct00129bfc() - { - this.ee.pc = 1219588u; - // @00129BFC BEQ t7, zero, $00129c40 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219648u; - } - // @00129C00 LW t7, $0204(sp) - MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); - } - - public virtual void funct00129c04() - { - this.ee.pc = 1219604u; - // @00129C04 LBU t6, $0000(s1) - MobUt.LBU(this.ee, this.ee.t6, (0u + this.ee.s1.UL0)); - // @00129C08 SLTIU t7, t6, $000e - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 14ul)); - // @00129C0C BEQ t7, zero, $00129c3c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219644u; - } - // @00129C10 SLL t7, t6, 2 - MobUt.SLL(this.ee.t7, this.ee.t6, 2); - } - - public virtual void funct00129c14() - { - this.ee.pc = 1219628u; - // @00129C14 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @00129C18 ADDIU t6, t6, $838c - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -31860))); - // @00129C1C ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00129C20 LW t5, $0000(t7) - MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); - // @00129C24 JR t5 - this.ee.pc = this.ee.t5.UL[0]; - // @00129C28 NOP - MobUt.Latency(); - } - - public virtual void funct00129c2c() - { - this.ee.pc = 1219640u; - // @00129C2C ADDIU t7, zero, $ffff - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); - // @00129C30 BNE a2, t7, $0012d3b4 - if ((this.ee.a2.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1233844u; - } - // @00129C34 NOP - MobUt.Latency(); - } - - public virtual void funct00129c38() - { - this.ee.pc = 1219660u; - // @00129C38 LHU a2, $0004(s1) - MobUt.LHU(this.ee, this.ee.a2, (4u + this.ee.s1.UL0)); - // @00129C3C LW t7, $0204(sp) - MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); - // @00129C40 ADDIU s1, s1, $000c - this.ee.s1.SD0 = ((int)((this.ee.s1.SD0 + 12))); - // @00129C44 BEQ s1, t7, $00129c5c - if ((this.ee.s1.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1219676u; - } - // @00129C48 LUI t7, $0003 - this.ee.t7.SD0 = 196608; - } - - public virtual void funct00129c3c() - { - this.ee.pc = 1219660u; - // @00129C3C LW t7, $0204(sp) - MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); - // @00129C40 ADDIU s1, s1, $000c - this.ee.s1.SD0 = ((int)((this.ee.s1.SD0 + 12))); - // @00129C44 BEQ s1, t7, $00129c5c - if ((this.ee.s1.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1219676u; - } - // @00129C48 LUI t7, $0003 - this.ee.t7.SD0 = 196608; - } - - public virtual void funct00129c4c() - { - this.ee.pc = 1219672u; - // @00129C4C LHU t7, $0002(s1) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); - // @00129C50 BEQL t7, t4, $00129bfc - if ((this.ee.t7.UD0 == this.ee.t4.UD0)) - { - this.ee.pc = 1219580u; - // @00129C54 LBU t7, $0001(s1) - MobUt.LBU(this.ee, this.ee.t7, (1u + this.ee.s1.UL0)); - } - } - - public virtual void funct00129c58() - { - this.ee.pc = 1219688u; - // @00129C58 LUI t7, $0003 - this.ee.t7.SD0 = 196608; - // @00129C5C AND t6, s4, t7 - this.ee.t6.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @00129C60 BEQ t6, zero, $00129cf8 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219832u; - } - // @00129C64 SW zero, $0220(sp) - MobUt.SW(this.ee, this.ee.r0, (544u + this.ee.sp.UL0)); - } - - public virtual void funct00129c5c() - { - this.ee.pc = 1219688u; - // @00129C5C AND t6, s4, t7 - this.ee.t6.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @00129C60 BEQ t6, zero, $00129cf8 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219832u; - } - // @00129C64 SW zero, $0220(sp) - MobUt.SW(this.ee, this.ee.r0, (544u + this.ee.sp.UL0)); - } - - public virtual void funct00129c68() - { - this.ee.pc = 1219704u; - // @00129C68 LUI t7, $0080 - this.ee.t7.SD0 = 8388608; - // @00129C6C AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @00129C70 BEQ t7, zero, $0012d39c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233820u; - } - // @00129C74 LW t4, $020c(sp) - MobUt.LW(this.ee, this.ee.t4, (524u + this.ee.sp.UL0)); - } - - public virtual void funct00129c78() - { - this.ee.pc = 1219728u; - // @00129C78 LH t5, $0000(t4) - MobUt.LH(this.ee, this.ee.t5, (0u + this.ee.t4.UL0)); - // @00129C7C ADDIU t4, t4, $0002 - this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + 2))); - // @00129C80 SW t4, $020c(sp) - MobUt.SW(this.ee, this.ee.t4, (524u + this.ee.sp.UL0)); - // @00129C84 LW t6, $0204(sp) - MobUt.LW(this.ee, this.ee.t6, (516u + this.ee.sp.UL0)); - // @00129C88 BEQ s1, t6, $00129ce4 - if ((this.ee.s1.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1219812u; - } - // @00129C8C ADDIU t4, zero, $0005 - this.ee.t4.SD0 = ((int)((this.ee.r0.SD0 + 5))); - } - - public virtual void funct00129c84() - { - this.ee.pc = 1219728u; - // @00129C84 LW t6, $0204(sp) - MobUt.LW(this.ee, this.ee.t6, (516u + this.ee.sp.UL0)); - // @00129C88 BEQ s1, t6, $00129ce4 - if ((this.ee.s1.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1219812u; - } - // @00129C8C ADDIU t4, zero, $0005 - this.ee.t4.SD0 = ((int)((this.ee.r0.SD0 + 5))); - } - - public virtual void funct00129c90() - { - this.ee.pc = 1219740u; - // @00129C90 LBU t7, $0001(s1) - MobUt.LBU(this.ee, this.ee.t7, (1u + this.ee.s1.UL0)); - // @00129C94 BEQ t7, zero, $00129cd8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219800u; - } - // @00129C98 LW t7, $0204(sp) - MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); - } - - public virtual void funct00129c94() - { - this.ee.pc = 1219740u; - // @00129C94 BEQ t7, zero, $00129cd8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219800u; - } - // @00129C98 LW t7, $0204(sp) - MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); - } - - public virtual void funct00129c9c() - { - this.ee.pc = 1219752u; - // @00129C9C LHU t7, $0002(s1) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); - // @00129CA0 BNE t7, t5, $00129cd8 - if ((this.ee.t7.UD0 != this.ee.t5.UD0)) - { - this.ee.pc = 1219800u; - } - // @00129CA4 LW t7, $0204(sp) - MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); - } - - public virtual void funct00129ca8() - { - this.ee.pc = 1219764u; - // @00129CA8 LBU t6, $0000(s1) - MobUt.LBU(this.ee, this.ee.t6, (0u + this.ee.s1.UL0)); - // @00129CAC BLTZ t6, $00129ccc - if ((this.ee.t6.SD0 < 0)) - { - this.ee.pc = 1219788u; - } - // @00129CB0 DADDU t7, zero, zero - this.ee.t7.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00129cb4() - { - this.ee.pc = 1219776u; - // @00129CB4 SLTI t7, t6, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < 2)); - // @00129CB8 BNE t7, zero, $00129ccc - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1219788u; - } - // @00129CBC ADDIU t7, zero, $0001 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); - } - - public virtual void funct00129ccc() - { - this.ee.pc = 1219800u; - // @00129CCC ANDI t7, t7, $00ff - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 255))); - // @00129CD0 BNE t7, zero, $0012d390 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1233808u; - } - // @00129CD4 LW t7, $0204(sp) - MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); - } - - public virtual void funct00129cd8() - { - this.ee.pc = 1219812u; - // @00129CD8 ADDIU s1, s1, $000c - this.ee.s1.SD0 = ((int)((this.ee.s1.SD0 + 12))); - // @00129CDC BNEL s1, t7, $00129c94 - if ((this.ee.s1.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1219732u; - // @00129CE0 LBU t7, $0001(s1) - MobUt.LBU(this.ee, this.ee.t7, (1u + this.ee.s1.UL0)); - } - } - - public virtual void funct00129ce4() - { - this.ee.pc = 1219824u; - // @00129CE4 LW t4, $0220(sp) - MobUt.LW(this.ee, this.ee.t4, (544u + this.ee.sp.UL0)); - // @00129CE8 BNE t4, zero, $00129cf8 - if ((this.ee.t4.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1219832u; - } - // @00129CEC LUI t7, $fffc - this.ee.t7.SD0 = -262144; - } - - public virtual void funct00129cf8() - { - this.ee.pc = 1219840u; - // @00129CF8 BEQ t3, zero, $0012d2c8 - if ((this.ee.t3.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233608u; - } - // @00129CFC LW t7, $0214(sp) - MobUt.LW(this.ee, this.ee.t7, (532u + this.ee.sp.UL0)); - } - - public virtual void funct00129d00() - { - this.ee.pc = 1219868u; - // @00129D00 LHU t7, $0004(t3) - MobUt.LHU(this.ee, this.ee.t7, (4u + this.ee.t3.UL0)); - // @00129D04 LW t3, $0014(s0) - MobUt.LW(this.ee, this.ee.t3, (20u + this.ee.s0.UL0)); - // @00129D08 SLL t7, t7, 4 - MobUt.SLL(this.ee.t7, this.ee.t7, 4); - // @00129D0C ADDU t6, t3, t7 - this.ee.t6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t7.SD0))); - // @00129D10 ADDU t7, t3, s8 - this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); - // @00129D14 BEQ t7, t6, $00129d2c - if ((this.ee.t7.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1219884u; - } - // @00129D18 LW t5, $0214(sp) - MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); - } - - public virtual void funct00129d1c() - { - this.ee.pc = 1219892u; - // @00129D1C LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @00129D20 SQ t0, $0000(t7) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @00129D24 LW t3, $0014(s0) - MobUt.LW(this.ee, this.ee.t3, (20u + this.ee.s0.UL0)); - // @00129D28 LW t5, $0214(sp) - MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); - // @00129D2C BLTZ t5, $0012d27c - if ((this.ee.t5.SD0 < 0)) - { - this.ee.pc = 1233532u; - } - // @00129D30 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - } - - public virtual void funct00129d34() - { - this.ee.pc = 1219908u; - // @00129D34 LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @00129D38 SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @00129D3C BEQL t7, zero, $0012d264 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233508u; - // @00129D40 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct00129d44() - { - this.ee.pc = 1219976u; - // @00129D44 LW t7, $001c(s5) - MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); - // @00129D48 ADDU t5, t7, s8 - this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @00129D4C LW t6, $0214(sp) - MobUt.LW(this.ee, this.ee.t6, (532u + this.ee.sp.UL0)); - // @00129D50 ADDU t7, t3, s8 - this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); - // @00129D54 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00129D58 SLL t2, t6, 4 - MobUt.SLL(this.ee.t2, this.ee.t6, 4); - // @00129D5C ADDU t6, t3, t2 - this.ee.t6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t2.SD0))); - // @00129D60 LWC1 $f1, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); - // @00129D64 NOP - MobUt.Latency(); - // @00129D68 NOP - MobUt.Latency(); - // @00129D6C DIV.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); - // @00129D70 SWC1 $f0, $0000(t5) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); - // @00129D74 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @00129D78 LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @00129D7C SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @00129D80 BEQL t7, zero, $0012d24c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233484u; - // @00129D84 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct00129d4c() - { - this.ee.pc = 1219976u; - // @00129D4C LW t6, $0214(sp) - MobUt.LW(this.ee, this.ee.t6, (532u + this.ee.sp.UL0)); - // @00129D50 ADDU t7, t3, s8 - this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); - // @00129D54 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00129D58 SLL t2, t6, 4 - MobUt.SLL(this.ee.t2, this.ee.t6, 4); - // @00129D5C ADDU t6, t3, t2 - this.ee.t6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t2.SD0))); - // @00129D60 LWC1 $f1, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); - // @00129D64 NOP - MobUt.Latency(); - // @00129D68 NOP - MobUt.Latency(); - // @00129D6C DIV.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); - // @00129D70 SWC1 $f0, $0000(t5) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); - // @00129D74 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @00129D78 LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @00129D7C SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @00129D80 BEQL t7, zero, $0012d24c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233484u; - // @00129D84 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct00129d88() - { - this.ee.pc = 1220040u; - // @00129D88 LW t7, $001c(s5) - MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); - // @00129D8C ADDU t5, t7, s8 - this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @00129D90 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @00129D94 ADDU t6, t7, t2 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t2.SD0))); - // @00129D98 ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @00129D9C LWC1 $f1, $0004(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.t6.UL0)); - // @00129DA0 LWC1 $f0, $0004(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t7.UL0)); - // @00129DA4 NOP - MobUt.Latency(); - // @00129DA8 NOP - MobUt.Latency(); - // @00129DAC DIV.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); - // @00129DB0 SWC1 $f0, $0004(t5) - MobUt.SWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t5.UL0)); - // @00129DB4 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @00129DB8 LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @00129DBC SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @00129DC0 BEQL t7, zero, $0012d234 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233460u; - // @00129DC4 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct00129d90() - { - this.ee.pc = 1220040u; - // @00129D90 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @00129D94 ADDU t6, t7, t2 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t2.SD0))); - // @00129D98 ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @00129D9C LWC1 $f1, $0004(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.t6.UL0)); - // @00129DA0 LWC1 $f0, $0004(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t7.UL0)); - // @00129DA4 NOP - MobUt.Latency(); - // @00129DA8 NOP - MobUt.Latency(); - // @00129DAC DIV.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); - // @00129DB0 SWC1 $f0, $0004(t5) - MobUt.SWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t5.UL0)); - // @00129DB4 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @00129DB8 LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @00129DBC SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @00129DC0 BEQL t7, zero, $0012d234 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233460u; - // @00129DC4 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct00129dc8() - { - this.ee.pc = 1220100u; - // @00129DC8 LW t7, $001c(s5) - MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); - // @00129DCC ADDU t5, t7, s8 - this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @00129DD0 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @00129DD4 ADDU t6, t7, t2 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t2.SD0))); - // @00129DD8 ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @00129DDC LWC1 $f1, $0008(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.t6.UL0)); - // @00129DE0 LWC1 $f0, $0008(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.t7.UL0)); - // @00129DE4 NOP - MobUt.Latency(); - // @00129DE8 NOP - MobUt.Latency(); - // @00129DEC DIV.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); - // @00129DF0 SWC1 $f0, $0008(t5) - MobUt.SWC1(this.ee, this.ee.fpr[0], (8u + this.ee.t5.UL0)); - // @00129DF4 LUI t7, $0020 - this.ee.t7.SD0 = 2097152; - // @00129DF8 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @00129DFC BEQ t7, zero, $0012a9d0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223120u; - } - // @00129E00 LUI t7, $0040 - this.ee.t7.SD0 = 4194304; - } - - public virtual void funct00129dd0() - { - this.ee.pc = 1220100u; - // @00129DD0 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @00129DD4 ADDU t6, t7, t2 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t2.SD0))); - // @00129DD8 ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @00129DDC LWC1 $f1, $0008(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.t6.UL0)); - // @00129DE0 LWC1 $f0, $0008(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.t7.UL0)); - // @00129DE4 NOP - MobUt.Latency(); - // @00129DE8 NOP - MobUt.Latency(); - // @00129DEC DIV.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); - // @00129DF0 SWC1 $f0, $0008(t5) - MobUt.SWC1(this.ee, this.ee.fpr[0], (8u + this.ee.t5.UL0)); - // @00129DF4 LUI t7, $0020 - this.ee.t7.SD0 = 2097152; - // @00129DF8 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @00129DFC BEQ t7, zero, $0012a9d0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223120u; - } - // @00129E00 LUI t7, $0040 - this.ee.t7.SD0 = 4194304; - } - - public virtual void funct00129df8() - { - this.ee.pc = 1220100u; - // @00129DF8 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @00129DFC BEQ t7, zero, $0012a9d0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223120u; - } - // @00129E00 LUI t7, $0040 - this.ee.t7.SD0 = 4194304; - } - - public virtual void funct00129e04() - { - this.ee.pc = 1220112u; - // @00129E04 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @00129E08 BEQ t7, zero, $00129e60 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220192u; - } - // @00129E0C LW t3, $01f4(sp) - MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); - } - - public virtual void funct00129e10() - { - this.ee.pc = 1220132u; - // @00129E10 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @00129E14 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @00129E18 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @00129E1C BEQ t7, zero, $0012a9bc - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223100u; - } - // @00129E20 SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - } - - public virtual void funct00129e2c() - { - this.ee.pc = 1220156u; - // @00129E2C LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @00129E30 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @00129E34 BNEL t7, zero, $0012a9b4 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1223092u; - // @00129E38 LW t7, $0020(s5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); - } - } - - public virtual void funct00129e3c() - { - this.ee.pc = 1220188u; - // @00129E3C LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - // @00129E40 SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @00129E44 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @00129E48 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @00129E4C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00129E50 ADDIU a1, t6, $0020 - this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + 32))); - // @00129E54 JAL $0011b840 - this.ee.ra.UL0 = 1220188u; - this.ee.pc = 1161280u; - // @00129E58 NOP - MobUt.Latency(); - } - - public virtual void funct00129e40() - { - this.ee.pc = 1220188u; - // @00129E40 SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @00129E44 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @00129E48 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @00129E4C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00129E50 ADDIU a1, t6, $0020 - this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + 32))); - // @00129E54 JAL $0011b840 - this.ee.ra.UL0 = 1220188u; - this.ee.pc = 1161280u; - // @00129E58 NOP - MobUt.Latency(); - } - - public virtual void funct00129e54() - { - this.ee.pc = 1220188u; - // @00129E54 JAL $0011b840 - this.ee.ra.UL0 = 1220188u; - this.ee.pc = 1161280u; - // @00129E58 NOP - MobUt.Latency(); - } - - public virtual void funct00129e5c() - { - this.ee.pc = 1220200u; - // @00129E5C LW t3, $01f4(sp) - MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); - // @00129E60 BEQL t3, zero, $0012a498 - if ((this.ee.t3.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1221784u; - // @00129E64 LW t3, $01fc(sp) - MobUt.LW(this.ee, this.ee.t3, (508u + this.ee.sp.UL0)); - } - } - - public virtual void funct00129e60() - { - this.ee.pc = 1220200u; - // @00129E60 BEQL t3, zero, $0012a498 - if ((this.ee.t3.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1221784u; - // @00129E64 LW t3, $01fc(sp) - MobUt.LW(this.ee, this.ee.t3, (508u + this.ee.sp.UL0)); - } - } - - public virtual void funct0012a498() - { - this.ee.pc = 1221820u; - // @0012A498 LW t4, $0210(sp) - MobUt.LW(this.ee, this.ee.t4, (528u + this.ee.sp.UL0)); - // @0012A49C LW t5, $0200(sp) - MobUt.LW(this.ee, this.ee.t5, (512u + this.ee.sp.UL0)); - // @0012A4A0 LHU t7, $0012(t3) - MobUt.LHU(this.ee, this.ee.t7, (18u + this.ee.t3.UL0)); - // @0012A4A4 ADDIU t4, t4, $0001 - this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + 1))); - // @0012A4A8 ADDIU t5, t5, $0004 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + 4))); - // @0012A4AC SW t4, $0210(sp) - MobUt.SW(this.ee, this.ee.t4, (528u + this.ee.sp.UL0)); - // @0012A4B0 SLT t7, t4, t7 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.t7.SD0)); - // @0012A4B4 BNE t7, zero, $00129ad8 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1219288u; - } - // @0012A4B8 SW t5, $0200(sp) - MobUt.SW(this.ee, this.ee.t5, (512u + this.ee.sp.UL0)); - } - - public virtual void funct0012a4bc() - { - this.ee.pc = 1221872u; - // @0012A4BC LD s0, $02a0(sp) - MobUt.LD(this.ee, this.ee.s0, (672u + this.ee.sp.UL0)); - // @0012A4C0 LD s1, $02a8(sp) - MobUt.LD(this.ee, this.ee.s1, (680u + this.ee.sp.UL0)); - // @0012A4C4 LD s2, $02b0(sp) - MobUt.LD(this.ee, this.ee.s2, (688u + this.ee.sp.UL0)); - // @0012A4C8 LD s3, $02b8(sp) - MobUt.LD(this.ee, this.ee.s3, (696u + this.ee.sp.UL0)); - // @0012A4CC LD s4, $02c0(sp) - MobUt.LD(this.ee, this.ee.s4, (704u + this.ee.sp.UL0)); - // @0012A4D0 LD s5, $02c8(sp) - MobUt.LD(this.ee, this.ee.s5, (712u + this.ee.sp.UL0)); - // @0012A4D4 LD s6, $02d0(sp) - MobUt.LD(this.ee, this.ee.s6, (720u + this.ee.sp.UL0)); - // @0012A4D8 LD s7, $02d8(sp) - MobUt.LD(this.ee, this.ee.s7, (728u + this.ee.sp.UL0)); - // @0012A4DC LD s8, $02e0(sp) - MobUt.LD(this.ee, this.ee.s8, (736u + this.ee.sp.UL0)); - // @0012A4E0 LD ra, $02e8(sp) - MobUt.LD(this.ee, this.ee.ra, (744u + this.ee.sp.UL0)); - // @0012A4E4 LWC1 $f20, $02f0(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (752u + this.ee.sp.UL0)); - // @0012A4E8 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0012A4EC ADDIU sp, sp, $0300 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 768))); - } - - public virtual void funct0012a4c0() - { - this.ee.pc = 1221872u; - // @0012A4C0 LD s1, $02a8(sp) - MobUt.LD(this.ee, this.ee.s1, (680u + this.ee.sp.UL0)); - // @0012A4C4 LD s2, $02b0(sp) - MobUt.LD(this.ee, this.ee.s2, (688u + this.ee.sp.UL0)); - // @0012A4C8 LD s3, $02b8(sp) - MobUt.LD(this.ee, this.ee.s3, (696u + this.ee.sp.UL0)); - // @0012A4CC LD s4, $02c0(sp) - MobUt.LD(this.ee, this.ee.s4, (704u + this.ee.sp.UL0)); - // @0012A4D0 LD s5, $02c8(sp) - MobUt.LD(this.ee, this.ee.s5, (712u + this.ee.sp.UL0)); - // @0012A4D4 LD s6, $02d0(sp) - MobUt.LD(this.ee, this.ee.s6, (720u + this.ee.sp.UL0)); - // @0012A4D8 LD s7, $02d8(sp) - MobUt.LD(this.ee, this.ee.s7, (728u + this.ee.sp.UL0)); - // @0012A4DC LD s8, $02e0(sp) - MobUt.LD(this.ee, this.ee.s8, (736u + this.ee.sp.UL0)); - // @0012A4E0 LD ra, $02e8(sp) - MobUt.LD(this.ee, this.ee.ra, (744u + this.ee.sp.UL0)); - // @0012A4E4 LWC1 $f20, $02f0(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (752u + this.ee.sp.UL0)); - // @0012A4E8 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0012A4EC ADDIU sp, sp, $0300 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 768))); - } - - public virtual void funct0012a9b4() - { - this.ee.pc = 1223100u; - // @0012A9B4 BEQ zero, zero, $00129e54 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220180u; - } - // @0012A9B8 ADDU a1, t7, s8 - this.ee.a1.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - } - - public virtual void funct0012a9bc() - { - this.ee.pc = 1223120u; - // @0012A9BC SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - // @0012A9C0 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012A9C4 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012A9C8 BEQ zero, zero, $00129e2c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220140u; - } - // @0012A9CC ADDU a0, t6, t7 - this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012a9d0() - { - this.ee.pc = 1223156u; - // @0012A9D0 SRL t3, s4, 16 - MobUt.SRL(this.ee.t3, this.ee.s4, 16); - // @0012A9D4 MTC1 zero, $f20 - this.ee.fpr[20].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @0012A9D8 SW t3, $024c(sp) - MobUt.SW(this.ee, this.ee.t3, (588u + this.ee.sp.UL0)); - // @0012A9DC ANDI t6, t3, $0003 - this.ee.t6.UD0 = ((ushort)((this.ee.t3.US0 & 3))); - // @0012A9E0 SW zero, $0224(sp) - MobUt.SW(this.ee, this.ee.r0, (548u + this.ee.sp.UL0)); - // @0012A9E4 ADDIU t7, zero, $0001 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @0012A9E8 SW zero, $0228(sp) - MobUt.SW(this.ee, this.ee.r0, (552u + this.ee.sp.UL0)); - // @0012A9EC BEQ t6, t7, $0012caf0 - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1231600u; - } - // @0012A9F0 SW zero, $022c(sp) - MobUt.SW(this.ee, this.ee.r0, (556u + this.ee.sp.UL0)); - } - - public virtual void funct0012a9f4() - { - this.ee.pc = 1223164u; - // @0012A9F4 BEQ t6, zero, $0012ba08 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227272u; - } - // @0012A9F8 SLTIU t7, t6, $0004 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 4ul)); - } - - public virtual void funct0012a9fc() - { - this.ee.pc = 1223172u; - // @0012A9FC BEQ t7, zero, $0012ba08 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227272u; - } - // @0012AA00 LW t7, $0218(sp) - MobUt.LW(this.ee, this.ee.t7, (536u + this.ee.sp.UL0)); - } - - public virtual void funct0012aa04() - { - this.ee.pc = 1223180u; - // @0012AA04 BEQ t7, zero, $0012aa1c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223196u; - } - // @0012AA08 LW t3, $0218(sp) - MobUt.LW(this.ee, this.ee.t3, (536u + this.ee.sp.UL0)); - } - - public virtual void funct0012aa1c() - { - this.ee.pc = 1223216u; - // @0012AA1C LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012AA20 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012AA24 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012AA28 BEQ t7, zero, $0012b9ec - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227244u; - } - // @0012AA2C ADDIU t3, sp, $0090 - this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); - } - - public virtual void funct0012aa30() - { - this.ee.pc = 1223232u; - // @0012AA30 LW t7, $0024(s5) - MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s5.UL0)); - // @0012AA34 ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012AA38 BEQ t3, t6, $0012aa50 - if ((this.ee.t3.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1223248u; - } - // @0012AA3C LUI t5, $0038 - this.ee.t5.SD0 = 3670016; - } - - public virtual void funct0012aa38() - { - this.ee.pc = 1223232u; - // @0012AA38 BEQ t3, t6, $0012aa50 - if ((this.ee.t3.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1223248u; - } - // @0012AA3C LUI t5, $0038 - this.ee.t5.SD0 = 3670016; - } - - public virtual void funct0012aa40() - { - this.ee.pc = 1223280u; - // @0012AA40 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012AA44 SQ t0, $0000(t3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); - // @0012AA48 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012AA4C LUI t5, $0038 - this.ee.t5.SD0 = 3670016; - // @0012AA50 ADDIU t5, t5, $8364 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + -31900))); - // @0012AA54 LWC1 $f0, $0000(t5) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); - // @0012AA58 SWC1 $f0, $009c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); - // @0012AA5C LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012AA60 LW t4, $0214(sp) - MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); - // @0012AA64 SLT t7, t4, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.t6.SD0)); - // @0012AA68 BEQ t7, zero, $0012b9d4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227220u; - } - // @0012AA6C SLL t5, t4, 6 - MobUt.SLL(this.ee.t5, this.ee.t4, 6); - } - - public virtual void funct0012aa70() - { - this.ee.pc = 1223348u; - // @0012AA70 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012AA74 SW t5, $0250(sp) - MobUt.SW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); - // @0012AA78 ADDU t6, t7, t5 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); - // @0012AA7C ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012AA80 LQC2 vf5, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); - // @0012AA84 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012AA88 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012AA8C LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012AA90 LQC2 vf4, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); - // @0012AA94 VMULAx.xyzw ACC, vf1, vf5x - // @0012AA98 VMADDAy.xyzw ACC, vf2, vf5y - // @0012AA9C VMADDAz.xyzw ACC, vf3, vf5z - // @0012AAA0 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012AAA4 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012AAA8 ADDIU t6, sp, $0080 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012AAAC BEQ t6, t8, $0012aabc - if ((this.ee.t6.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1223356u; - } - // @0012AAB0 DADDU t7, t8, zero - this.ee.t7.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012aa7c() - { - this.ee.pc = 1223348u; - // @0012AA7C ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012AA80 LQC2 vf5, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); - // @0012AA84 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012AA88 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012AA8C LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012AA90 LQC2 vf4, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); - // @0012AA94 VMULAx.xyzw ACC, vf1, vf5x - // @0012AA98 VMADDAy.xyzw ACC, vf2, vf5y - // @0012AA9C VMADDAz.xyzw ACC, vf3, vf5z - // @0012AAA0 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012AAA4 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012AAA8 ADDIU t6, sp, $0080 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012AAAC BEQ t6, t8, $0012aabc - if ((this.ee.t6.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1223356u; - } - // @0012AAB0 DADDU t7, t8, zero - this.ee.t7.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012aab4() - { - this.ee.pc = 1223380u; - // @0012AAB4 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012AAB8 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012AABC LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - // @0012AAC0 ADDIU a1, sp, $0040 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 64))); - // @0012AAC4 LW t3, $0250(sp) - MobUt.LW(this.ee, this.ee.t3, (592u + this.ee.sp.UL0)); - // @0012AAC8 ADDU t7, t7, t3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t3.SD0))); - // @0012AACC BEQ a1, t7, $0012aaf4 - if ((this.ee.a1.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1223412u; - } - // @0012AAD0 NOP - MobUt.Latency(); - } - - public virtual void funct0012aad4() - { - this.ee.pc = 1223560u; - // @0012AAD4 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012AAD8 LQ t1, $0010(t7) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); - // @0012AADC LQ t2, $0020(t7) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); - // @0012AAE0 LQ t3, $0030(t7) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); - // @0012AAE4 SQ t0, $0000(a1) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @0012AAE8 SQ t1, $0010(a1) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); - // @0012AAEC SQ t2, $0020(a1) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); - // @0012AAF0 SQ t3, $0030(a1) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.a1.UL[0])); - // @0012AAF4 LQ t0, $0000(a1) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @0012AAF8 LQ t1, $0010(a1) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); - // @0012AAFC LQ t2, $0020(a1) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); - // @0012AB00 QMFC2 t3, vf0 - MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); - // @0012AB04 LQC2 vf4, $0030(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012AB08 PEXTLW t4, t1, t0 - this.ee.t4.UL[0] = this.ee.t0.UL[0]; - this.ee.t4.UL[1] = this.ee.t1.UL[0]; - this.ee.t4.UL[2] = this.ee.t0.UL[1]; - this.ee.t4.UL[3] = this.ee.t1.UL[1]; - // @0012AB0C PEXTUW t5, t1, t0 - this.ee.t5.UL[0] = this.ee.t0.UL[2]; - this.ee.t5.UL[1] = this.ee.t1.UL[2]; - this.ee.t5.UL[2] = this.ee.t0.UL[3]; - this.ee.t5.UL[3] = this.ee.t1.UL[3]; - // @0012AB10 PEXTLW t6, t3, t2 - this.ee.t6.UL[0] = this.ee.t2.UL[0]; - this.ee.t6.UL[1] = this.ee.t3.UL[0]; - this.ee.t6.UL[2] = this.ee.t2.UL[1]; - this.ee.t6.UL[3] = this.ee.t3.UL[1]; - // @0012AB14 PEXTUW t7, t3, t2 - this.ee.t7.UL[0] = this.ee.t2.UL[2]; - this.ee.t7.UL[1] = this.ee.t3.UL[2]; - this.ee.t7.UL[2] = this.ee.t2.UL[3]; - this.ee.t7.UL[3] = this.ee.t3.UL[3]; - // @0012AB18 PCPYLD t0, t6, t4 - this.ee.t0.UD1 = this.ee.t6.UD0; - this.ee.t0.UD0 = this.ee.t4.UD0; - // @0012AB1C PCPYUD t1, t4, t6 - this.ee.t1.UD0 = this.ee.t4.UD1; - this.ee.t1.UD1 = this.ee.t6.UD1; - // @0012AB20 PCPYLD t2, t7, t5 - this.ee.t2.UD1 = this.ee.t7.UD0; - this.ee.t2.UD0 = this.ee.t5.UD0; - // @0012AB24 QMTC2 t0, vf1 - MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); - // @0012AB28 QMTC2 t1, vf2 - MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); - // @0012AB2C QMTC2 t2, vf3 - MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); - // @0012AB30 VMULAx.xyz ACC, vf1, vf4x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[4].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[4].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[4].x); - // @0012AB34 VMADDAy.xyz ACC, vf2, vf4y - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[4].y); - // @0012AB38 VMADDz.xyz vf4, vf3, vf4z - this.ee.VF[4].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[4].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[4].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[4].z); - // @0012AB3C VSUB.xyz vf4, vf0, vf4 - this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); - this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); - this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); - // @0012AB40 SQ t0, $0000(a1) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @0012AB44 SQ t1, $0010(a1) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); - // @0012AB48 SQ t2, $0020(a1) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); - // @0012AB4C SQC2 vf4, $0030(a1) - MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012AB50 ADDIU t4, sp, $0080 - this.ee.t4.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012AB54 LQC2 vf5, $0000(t4) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t4.UL0)); - // @0012AB58 LQC2 vf1, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); - // @0012AB5C LQC2 vf2, $0010(a1) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); - // @0012AB60 LQC2 vf3, $0020(a1) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); - // @0012AB64 LQC2 vf4, $0030(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012AB68 VMULAx.xyzw ACC, vf1, vf5x - // @0012AB6C VMADDAy.xyzw ACC, vf2, vf5y - // @0012AB70 VMADDAz.xyzw ACC, vf3, vf5z - // @0012AB74 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012AB78 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012AB7C ADDIU t5, sp, $00a0 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 160))); - // @0012AB80 BEQ t5, t8, $0012ab90 - if ((this.ee.t5.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1223568u; - } - // @0012AB84 ADDIU t6, sp, $0120 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 288))); - } - - public virtual void funct0012ab88() - { - this.ee.pc = 1223580u; - // @0012AB88 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012AB8C SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012AB90 LW t7, $0204(sp) - MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); - // @0012AB94 BEQ s1, t7, $0012abc8 - if ((this.ee.s1.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1223624u; - } - // @0012AB98 ADDIU s7, s2, $0001 - this.ee.s7.SD0 = ((int)((this.ee.s2.SD0 + 1))); - } - - public virtual void funct0012ab9c() - { - this.ee.pc = 1223596u; - // @0012AB9C LHU t7, $0002(s1) - MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); - // @0012ABA0 ANDI t6, s7, $ffff - this.ee.t6.UD0 = ((ushort)((this.ee.s7.US0 & 65535))); - // @0012ABA4 BNEL t7, t6, $0012abcc - if ((this.ee.t7.UD0 != this.ee.t6.UD0)) - { - this.ee.pc = 1223628u; - // @0012ABA8 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012abc8() - { - this.ee.pc = 1223652u; - // @0012ABC8 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @0012ABCC LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @0012ABD0 LHU t2, $0010(t5) - MobUt.LHU(this.ee, this.ee.t2, (16u + this.ee.t5.UL0)); - // @0012ABD4 ADDU t4, t7, s8 - this.ee.t4.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012ABD8 SLT t7, s7, t2 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t2.SD0)); - // @0012ABDC BEQ t7, zero, $0012b9b8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227192u; - } - // @0012ABE0 ADDIU t3, t4, $0010 - this.ee.t3.SD0 = ((int)((this.ee.t4.SD0 + 16))); - } - - public virtual void funct0012abcc() - { - this.ee.pc = 1223652u; - // @0012ABCC LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @0012ABD0 LHU t2, $0010(t5) - MobUt.LHU(this.ee, this.ee.t2, (16u + this.ee.t5.UL0)); - // @0012ABD4 ADDU t4, t7, s8 - this.ee.t4.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012ABD8 SLT t7, s7, t2 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t2.SD0)); - // @0012ABDC BEQ t7, zero, $0012b9b8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227192u; - } - // @0012ABE0 ADDIU t3, t4, $0010 - this.ee.t3.SD0 = ((int)((this.ee.t4.SD0 + 16))); - } - - public virtual void funct0012abe4() - { - this.ee.pc = 1223692u; - // @0012ABE4 LW t6, $001c(s5) - MobUt.LW(this.ee, this.ee.t6, (28u + this.ee.s5.UL0)); - // @0012ABE8 SLL t7, s7, 4 - MobUt.SLL(this.ee.t7, this.ee.s7, 4); - // @0012ABEC ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012ABF0 ADDIU t5, sp, $0120 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012ABF4 LQC2 vf1, $0000(t4) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); - // @0012ABF8 LQC2 vf2, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); - // @0012ABFC VMUL.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].w); - // @0012AC00 SQC2 vf1, $0000(t5) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); - // @0012AC04 BEQ t3, t5, $0012ac14 - if ((this.ee.t3.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1223700u; - } - // @0012AC08 DADDU t6, t5, zero - this.ee.t6.UD0 = (this.ee.t5.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012abf0() - { - this.ee.pc = 1223692u; - // @0012ABF0 ADDIU t5, sp, $0120 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012ABF4 LQC2 vf1, $0000(t4) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); - // @0012ABF8 LQC2 vf2, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); - // @0012ABFC VMUL.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].w); - // @0012AC00 SQC2 vf1, $0000(t5) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); - // @0012AC04 BEQ t3, t5, $0012ac14 - if ((this.ee.t3.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1223700u; - } - // @0012AC08 DADDU t6, t5, zero - this.ee.t6.UD0 = (this.ee.t5.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012ac0c() - { - this.ee.pc = 1223728u; - // @0012AC0C LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012AC10 SQ t0, $0000(t3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); - // @0012AC14 LW a2, $0220(sp) - MobUt.LW(this.ee, this.ee.a2, (544u + this.ee.sp.UL0)); - // @0012AC18 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0012AC1C DADDU a1, s5, zero - this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); - // @0012AC20 ADDIU a3, sp, $00c0 - this.ee.a3.SD0 = ((int)((this.ee.sp.SD0 + 192))); - // @0012AC24 ADDIU t0, sp, $0040 - this.ee.t0.SD0 = ((int)((this.ee.sp.SD0 + 64))); - // @0012AC28 JAL $00128de8 - this.ee.ra.UL0 = 1223728u; - this.ee.pc = 1215976u; - // @0012AC2C ADDIU t1, sp, $00b0 - this.ee.t1.SD0 = ((int)((this.ee.sp.SD0 + 176))); - } - - public virtual void funct0012ac30() - { - this.ee.pc = 1223740u; - // @0012AC30 LW t7, $01f8(sp) - MobUt.LW(this.ee, this.ee.t7, (504u + this.ee.sp.UL0)); - // @0012AC34 BEQ t7, zero, $0012acd8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223896u; - } - // @0012AC38 LW t3, $0228(sp) - MobUt.LW(this.ee, this.ee.t3, (552u + this.ee.sp.UL0)); - } - - public virtual void funct0012ac3c() - { - this.ee.pc = 1223768u; - // @0012AC3C SW t7, $0224(sp) - MobUt.SW(this.ee, this.ee.t7, (548u + this.ee.sp.UL0)); - // @0012AC40 LD t5, $0010(t7) - MobUt.LD(this.ee, this.ee.t5, (16u + this.ee.t7.UL0)); - // @0012AC44 ADDIU t7, zero, $0001 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @0012AC48 DSLL32 t7, t7, 21 - MobUt.DSLL32(this.ee.t7, this.ee.t7, 21); - // @0012AC4C AND t7, t5, t7 - this.ee.t7.UD0 = (this.ee.t5.UD0 & this.ee.t7.UD0); - // @0012AC50 BNE t7, zero, $0012acd8 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1223896u; - } - // @0012AC54 LW t3, $0228(sp) - MobUt.LW(this.ee, this.ee.t3, (552u + this.ee.sp.UL0)); - } - - public virtual void funct0012ac58() - { - this.ee.pc = 1223796u; - // @0012AC58 ADDIU t4, zero, $0001 - this.ee.t4.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @0012AC5C ANDI t6, s2, $ffff - this.ee.t6.UD0 = ((ushort)((this.ee.s2.US0 & 65535))); - // @0012AC60 DSLL32 t4, t4, 21 - MobUt.DSLL32(this.ee.t4, this.ee.t4, 21); - // @0012AC64 LW t3, $0224(sp) - MobUt.LW(this.ee, this.ee.t3, (548u + this.ee.sp.UL0)); - // @0012AC68 LHU t7, $001c(t3) - MobUt.LHU(this.ee, this.ee.t7, (28u + this.ee.t3.UL0)); - // @0012AC6C BNE t7, t6, $0012b998 - if ((this.ee.t7.UD0 != this.ee.t6.UD0)) - { - this.ee.pc = 1227160u; - } - // @0012AC70 LW t7, $0224(sp) - MobUt.LW(this.ee, this.ee.t7, (548u + this.ee.sp.UL0)); - } - - public virtual void funct0012ac68() - { - this.ee.pc = 1223796u; - // @0012AC68 LHU t7, $001c(t3) - MobUt.LHU(this.ee, this.ee.t7, (28u + this.ee.t3.UL0)); - // @0012AC6C BNE t7, t6, $0012b998 - if ((this.ee.t7.UD0 != this.ee.t6.UD0)) - { - this.ee.pc = 1227160u; - } - // @0012AC70 LW t7, $0224(sp) - MobUt.LW(this.ee, this.ee.t7, (548u + this.ee.sp.UL0)); - } - - public virtual void funct0012ac74() - { - this.ee.pc = 1223840u; - // @0012AC74 DSRL32 t7, t5, 20 - MobUt.DSRL32(this.ee.t7, this.ee.t5, 20); - // @0012AC78 ADDIU t4, zero, $0001 - this.ee.t4.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @0012AC7C ANDI t7, t7, $0001 - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 1))); - // @0012AC80 SW t4, $0228(sp) - MobUt.SW(this.ee, this.ee.t4, (552u + this.ee.sp.UL0)); - // @0012AC84 SW t7, $022c(sp) - MobUt.SW(this.ee, this.ee.t7, (556u + this.ee.sp.UL0)); - // @0012AC88 ADDIU s3, zero, $0020 - this.ee.s3.SD0 = ((int)((this.ee.r0.SD0 + 32))); - // @0012AC8C LW a0, $0014(s5) - MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); - // @0012AC90 LW t7, $0000(a0) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); - // @0012AC94 LW v0, $0018(t7) - MobUt.LW(this.ee, this.ee.v0, (24u + this.ee.t7.UL0)); - // @0012AC98 JALR ra, v0 - this.ee.ra.UD0 = 1223840u; - this.ee.pc = this.ee.v0.UL0; - // @0012AC9C DADDU a1, s3, zero - this.ee.a1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012ac90() - { - this.ee.pc = 1223840u; - // @0012AC90 LW t7, $0000(a0) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); - // @0012AC94 LW v0, $0018(t7) - MobUt.LW(this.ee, this.ee.v0, (24u + this.ee.t7.UL0)); - // @0012AC98 JALR ra, v0 - this.ee.ra.UD0 = 1223840u; - this.ee.pc = this.ee.v0.UL0; - // @0012AC9C DADDU a1, s3, zero - this.ee.a1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012aca0() - { - this.ee.pc = 1223848u; - // @0012ACA0 BEQL s2, v0, $0012b97c - if ((this.ee.s2.UD0 == this.ee.v0.UD0)) - { - this.ee.pc = 1227132u; - // @0012ACA4 LW a0, $0014(s5) - MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); - } - } - - public virtual void funct0012aca8() - { - this.ee.pc = 1223864u; - // @0012ACA8 ADDIU s3, s3, $0001 - this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); - // @0012ACAC SLTI t7, s3, $0024 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s3.SD0 < 36)); - // @0012ACB0 BNEL t7, zero, $0012ac90 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1223824u; - // @0012ACB4 LW a0, $0014(s5) - MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); - } - } - - public virtual void funct0012acb8() - { - this.ee.pc = 1223892u; - // @0012ACB8 LW t5, $0224(sp) - MobUt.LW(this.ee, this.ee.t5, (548u + this.ee.sp.UL0)); - // @0012ACBC ADDIU t7, zero, $0001 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @0012ACC0 DSLL32 t7, t7, 19 - MobUt.DSLL32(this.ee.t7, this.ee.t7, 19); - // @0012ACC4 LD t6, $0010(t5) - MobUt.LD(this.ee, this.ee.t6, (16u + this.ee.t5.UL0)); - // @0012ACC8 AND t6, t6, t7 - this.ee.t6.UD0 = (this.ee.t6.UD0 & this.ee.t7.UD0); - // @0012ACCC BNEL t6, zero, $0012acd4 - if ((this.ee.t6.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1223892u; - // @0012ACD0 LWC1 $f20, $0018(t5) - MobUt.LWC1(this.ee, this.ee.fpr[20], (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct0012acd4() - { - this.ee.pc = 1223904u; - // @0012ACD4 LW t3, $0228(sp) - MobUt.LW(this.ee, this.ee.t3, (552u + this.ee.sp.UL0)); - // @0012ACD8 BEQ t3, zero, $0012af80 - if ((this.ee.t3.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1224576u; - } - // @0012ACDC LW t4, $01f0(sp) - MobUt.LW(this.ee, this.ee.t4, (496u + this.ee.sp.UL0)); - } - - public virtual void funct0012acd8() - { - this.ee.pc = 1223904u; - // @0012ACD8 BEQ t3, zero, $0012af80 - if ((this.ee.t3.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1224576u; - } - // @0012ACDC LW t4, $01f0(sp) - MobUt.LW(this.ee, this.ee.t4, (496u + this.ee.sp.UL0)); - } - - public virtual void funct0012ace0() - { - this.ee.pc = 1223964u; - // @0012ACE0 ADDIU t7, sp, $0130 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 304))); - // @0012ACE4 ADDIU s3, sp, $0140 - this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 320))); - // @0012ACE8 ADDIU t5, sp, $00c0 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 192))); - // @0012ACEC LQC2 vf5, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); - // @0012ACF0 LQC2 vf1, $0000(t4) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); - // @0012ACF4 LQC2 vf2, $0010(t4) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t4.UL0)); - // @0012ACF8 LQC2 vf3, $0020(t4) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t4.UL0)); - // @0012ACFC LQC2 vf4, $0030(t4) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t4.UL0)); - // @0012AD00 VMULAx.xyzw ACC, vf1, vf5x - // @0012AD04 VMADDAy.xyzw ACC, vf2, vf5y - // @0012AD08 VMADDAz.xyzw ACC, vf3, vf5z - // @0012AD0C VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012AD10 SQC2 vf5, $0000(s3) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s3.UL0)); - // @0012AD14 BEQ t7, s3, $0012ad28 - if ((this.ee.t7.UD0 == this.ee.s3.UD0)) - { - this.ee.pc = 1223976u; - } - // @0012AD18 LWC1 $f0, $0134(sp) - MobUt.LWC1(this.ee, this.ee.fpr[0], (308u + this.ee.sp.UL0)); - } - - public virtual void funct0012ad1c() - { - this.ee.pc = 1223992u; - // @0012AD1C LQ t0, $0000(s3) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @0012AD20 SQ t0, $0000(t7) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012AD24 LWC1 $f0, $0134(sp) - MobUt.LWC1(this.ee, this.ee.fpr[0], (308u + this.ee.sp.UL0)); - // @0012AD28 ADDIU t6, sp, $0120 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012AD2C ADD.S $f0, $f0, $f20 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[20].f); - // @0012AD30 BEQ t6, t7, $0012ad40 - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1224000u; - } - // @0012AD34 SWC1 $f0, $0134(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (308u + this.ee.sp.UL0)); - } - - public virtual void funct0012ad38() - { - this.ee.pc = 1224032u; - // @0012AD38 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012AD3C SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012AD40 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @0012AD44 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @0012AD48 LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @0012AD4C ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012AD50 ADDIU t7, t7, $0010 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16))); - // @0012AD54 SLT t6, s7, t4 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t4.SD0)); - // @0012AD58 BEQ t6, zero, $0012b964 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227108u; - } - // @0012AD5C SW t7, $0234(sp) - MobUt.SW(this.ee, this.ee.t7, (564u + this.ee.sp.UL0)); - } - - public virtual void funct0012ad60() - { - this.ee.pc = 1224052u; - // @0012AD60 LW a0, $0014(s5) - MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); - // @0012AD64 LW t7, $0000(a0) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); - // @0012AD68 LW v0, $0020(t7) - MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); - // @0012AD6C JALR ra, v0 - this.ee.ra.UD0 = 1224052u; - this.ee.pc = this.ee.v0.UL0; - // @0012AD70 NOP - MobUt.Latency(); - } - - public virtual void funct0012ad74() - { - this.ee.pc = 1224100u; - // @0012AD74 SLL t7, s7, 6 - MobUt.SLL(this.ee.t7, this.ee.s7, 6); - // @0012AD78 ADDU v0, v0, t7 - this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.t7.SD0))); - // @0012AD7C LW t7, $0234(sp) - MobUt.LW(this.ee, this.ee.t7, (564u + this.ee.sp.UL0)); - // @0012AD80 LWC1 $f2, $001c(v0) - MobUt.LWC1(this.ee, this.ee.fpr[2], (28u + this.ee.v0.UL0)); - // @0012AD84 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @0012AD88 LWC1 $f1, $0124(sp) - MobUt.LWC1(this.ee, this.ee.fpr[1], (292u + this.ee.sp.UL0)); - // @0012AD8C MUL.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[2].f); - // @0012AD90 LW t3, $022c(sp) - MobUt.LW(this.ee, this.ee.t3, (556u + this.ee.sp.UL0)); - // @0012AD94 ADD.S $f0, $f0, $f20 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[20].f); - // @0012AD98 SUB.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); - // @0012AD9C BEQ t3, zero, $0012ae00 - if ((this.ee.t3.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1224192u; - } - // @0012ADA0 SWC1 $f1, $0124(sp) - MobUt.SWC1(this.ee, this.ee.fpr[1], (292u + this.ee.sp.UL0)); - } - - public virtual void funct0012ae00() - { - this.ee.pc = 1224204u; - // @0012AE00 ADDIU a0, sp, $0120 - this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012AE04 JAL $00143ec8 - this.ee.ra.UL0 = 1224204u; - this.ee.pc = 1326792u; - // @0012AE08 DADDU a1, s3, zero - this.ee.a1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012ae0c() - { - this.ee.pc = 1224212u; - // @0012AE0C BEQ v0, zero, $0012af80 - if ((this.ee.v0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1224576u; - } - // @0012AE10 LW t5, $0224(sp) - MobUt.LW(this.ee, this.ee.t5, (548u + this.ee.sp.UL0)); - } - - public virtual void funct0012af80() - { - this.ee.pc = 1224588u; - // @0012AF80 LW t6, $0218(sp) - MobUt.LW(this.ee, this.ee.t6, (536u + this.ee.sp.UL0)); - // @0012AF84 BEQ t6, zero, $0012b7a8 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226664u; - } - // @0012AF88 LW t7, $0218(sp) - MobUt.LW(this.ee, this.ee.t7, (536u + this.ee.sp.UL0)); - } - - public virtual void funct0012b100() - { - this.ee.pc = 1224968u; - // @0012B100 JAL $00124a88 - this.ee.ra.UL0 = 1224968u; - this.ee.pc = 1198728u; - // @0012B104 NOP - MobUt.Latency(); - } - - public virtual void funct0012b108() - { - this.ee.pc = 1224984u; - // @0012B108 LUI t7, $0040 - this.ee.t7.SD0 = 4194304; - // @0012B10C AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @0012B110 BEQL t7, zero, $0012b158 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225048u; - // @0012B114 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012b158() - { - this.ee.pc = 1225064u; - // @0012B158 LHU t7, $0010(t7) - MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); - // @0012B15C SLT t6, s2, t7 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); - // @0012B160 BEQ t6, zero, $0012b6dc - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226460u; - } - // @0012B164 SUBU t7, s2, t7 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); - } - - public virtual void funct0012b168() - { - this.ee.pc = 1225112u; - // @0012B168 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012B16C ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012B170 LWC1 $f0, $0090(sp) - MobUt.LWC1(this.ee, this.ee.fpr[0], (144u + this.ee.sp.UL0)); - // @0012B174 SWC1 $f0, $0030(t6) - MobUt.SWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t6.UL0)); - // @0012B178 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012B17C LW t6, $0008(s0) - MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); - // @0012B180 LW t5, $0250(sp) - MobUt.LW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); - // @0012B184 LHU t4, $0010(t7) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t7.UL0)); - // @0012B188 ADDU t3, t6, t5 - this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); - // @0012B18C SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @0012B190 BEQ t7, zero, $0012b6c8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226440u; - } - // @0012B194 ADDU t5, t6, s3 - this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); - } - - public virtual void funct0012b170() - { - this.ee.pc = 1225112u; - // @0012B170 LWC1 $f0, $0090(sp) - MobUt.LWC1(this.ee, this.ee.fpr[0], (144u + this.ee.sp.UL0)); - // @0012B174 SWC1 $f0, $0030(t6) - MobUt.SWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t6.UL0)); - // @0012B178 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012B17C LW t6, $0008(s0) - MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); - // @0012B180 LW t5, $0250(sp) - MobUt.LW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); - // @0012B184 LHU t4, $0010(t7) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t7.UL0)); - // @0012B188 ADDU t3, t6, t5 - this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); - // @0012B18C SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @0012B190 BEQ t7, zero, $0012b6c8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226440u; - } - // @0012B194 ADDU t5, t6, s3 - this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); - } - - public virtual void funct0012b198() - { - this.ee.pc = 1225244u; - // @0012B198 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012B19C ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012B1A0 ADDIU t7, sp, $0120 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012B1A4 LQC2 vf1, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); - // @0012B1A8 LQC2 vf2, $0010(t3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); - // @0012B1AC LQC2 vf3, $0020(t3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); - // @0012B1B0 LQC2 vf4, $0030(t3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); - // @0012B1B4 LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012B1B8 LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012B1BC LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012B1C0 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012B1C4 VMULAx.xyzw ACC, vf1, vf5x - // @0012B1C8 VMADDAy.xyzw ACC, vf2, vf5y - // @0012B1CC VMADDAz.xyzw ACC, vf3, vf5z - // @0012B1D0 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012B1D4 VMULAx.xyzw ACC, vf1, vf6x - // @0012B1D8 VMADDAy.xyzw ACC, vf2, vf6y - // @0012B1DC VMADDAz.xyzw ACC, vf3, vf6z - // @0012B1E0 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012B1E4 VMULAx.xyzw ACC, vf1, vf7x - // @0012B1E8 VMADDAy.xyzw ACC, vf2, vf7y - // @0012B1EC VMADDAz.xyzw ACC, vf3, vf7z - // @0012B1F0 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012B1F4 VMULAx.xyzw ACC, vf1, vf8x - // @0012B1F8 VMADDAy.xyzw ACC, vf2, vf8y - // @0012B1FC VMADDAz.xyzw ACC, vf3, vf8z - // @0012B200 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012B204 SQC2 vf5, $0000(t7) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012B208 SQC2 vf6, $0010(t7) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); - // @0012B20C SQC2 vf7, $0020(t7) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); - // @0012B210 SQC2 vf8, $0030(t7) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); - // @0012B214 BEQ t5, t7, $0012b23c - if ((this.ee.t5.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1225276u; - } - // @0012B218 DADDU t4, t7, zero - this.ee.t4.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012b1a0() - { - this.ee.pc = 1225244u; - // @0012B1A0 ADDIU t7, sp, $0120 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012B1A4 LQC2 vf1, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); - // @0012B1A8 LQC2 vf2, $0010(t3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); - // @0012B1AC LQC2 vf3, $0020(t3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); - // @0012B1B0 LQC2 vf4, $0030(t3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); - // @0012B1B4 LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012B1B8 LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012B1BC LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012B1C0 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012B1C4 VMULAx.xyzw ACC, vf1, vf5x - // @0012B1C8 VMADDAy.xyzw ACC, vf2, vf5y - // @0012B1CC VMADDAz.xyzw ACC, vf3, vf5z - // @0012B1D0 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012B1D4 VMULAx.xyzw ACC, vf1, vf6x - // @0012B1D8 VMADDAy.xyzw ACC, vf2, vf6y - // @0012B1DC VMADDAz.xyzw ACC, vf3, vf6z - // @0012B1E0 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012B1E4 VMULAx.xyzw ACC, vf1, vf7x - // @0012B1E8 VMADDAy.xyzw ACC, vf2, vf7y - // @0012B1EC VMADDAz.xyzw ACC, vf3, vf7z - // @0012B1F0 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012B1F4 VMULAx.xyzw ACC, vf1, vf8x - // @0012B1F8 VMADDAy.xyzw ACC, vf2, vf8y - // @0012B1FC VMADDAz.xyzw ACC, vf3, vf8z - // @0012B200 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012B204 SQC2 vf5, $0000(t7) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012B208 SQC2 vf6, $0010(t7) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); - // @0012B20C SQC2 vf7, $0020(t7) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); - // @0012B210 SQC2 vf8, $0030(t7) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); - // @0012B214 BEQ t5, t7, $0012b23c - if ((this.ee.t5.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1225276u; - } - // @0012B218 DADDU t4, t7, zero - this.ee.t4.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012b21c() - { - this.ee.pc = 1225296u; - // @0012B21C LQ t0, $0000(t4) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); - // @0012B220 LQ t1, $0010(t4) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); - // @0012B224 LQ t2, $0020(t4) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); - // @0012B228 LQ t3, $0030(t4) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); - // @0012B22C SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012B230 SQ t1, $0010(t5) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); - // @0012B234 SQ t2, $0020(t5) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); - // @0012B238 SQ t3, $0030(t5) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); - // @0012B23C LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B240 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B244 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012B248 BEQ t7, zero, $0012b6b8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226424u; - } - // @0012B24C SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b250() - { - this.ee.pc = 1225320u; - // @0012B250 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012B254 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012B258 LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - // @0012B25C ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012B260 BEQL t6, t7, $0012b290 - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1225360u; - // @0012B264 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012b258() - { - this.ee.pc = 1225320u; - // @0012B258 LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - // @0012B25C ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012B260 BEQL t6, t7, $0012b290 - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1225360u; - // @0012B264 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012b268() - { - this.ee.pc = 1225372u; - // @0012B268 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012B26C LQ t1, $0010(t7) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); - // @0012B270 LQ t2, $0020(t7) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); - // @0012B274 LQ t3, $0030(t7) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); - // @0012B278 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012B27C SQ t1, $0010(t6) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); - // @0012B280 SQ t2, $0020(t6) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); - // @0012B284 SQ t3, $0030(t6) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); - // @0012B288 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B28C LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B290 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012B294 BEQ t7, zero, $0012b6a8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226408u; - } - // @0012B298 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b29c() - { - this.ee.pc = 1225448u; - // @0012B29C LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012B2A0 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012B2A4 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @0012B2A8 ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012B2AC LQC2 vf4, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); - // @0012B2B0 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012B2B4 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012B2B8 LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012B2BC VMULx.xyzw vf1, vf1, vf4x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); - // @0012B2C0 VMULy.xyzw vf2, vf2, vf4y - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); - this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); - // @0012B2C4 VMULz.xyzw vf3, vf3, vf4z - this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); - this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); - // @0012B2C8 SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012B2CC SQC2 vf2, $0010(t6) - MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012B2D0 SQC2 vf3, $0020(t6) - MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012B2D4 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B2D8 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B2DC SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012B2E0 BEQ t7, zero, $0012b698 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226392u; - } - // @0012B2E4 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b2a4() - { - this.ee.pc = 1225448u; - // @0012B2A4 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @0012B2A8 ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012B2AC LQC2 vf4, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); - // @0012B2B0 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012B2B4 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012B2B8 LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012B2BC VMULx.xyzw vf1, vf1, vf4x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); - // @0012B2C0 VMULy.xyzw vf2, vf2, vf4y - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); - this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); - // @0012B2C4 VMULz.xyzw vf3, vf3, vf4z - this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); - this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); - // @0012B2C8 SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012B2CC SQC2 vf2, $0010(t6) - MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012B2D0 SQC2 vf3, $0020(t6) - MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012B2D4 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B2D8 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B2DC SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012B2E0 BEQ t7, zero, $0012b698 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226392u; - } - // @0012B2E4 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b2e8() - { - this.ee.pc = 1225472u; - // @0012B2E8 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012B2EC ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012B2F0 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012B2F4 ADDIU t5, sp, $0080 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012B2F8 BEQL t6, t5, $0012b310 - if ((this.ee.t6.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1225488u; - // @0012B2FC LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012b2f0() - { - this.ee.pc = 1225472u; - // @0012B2F0 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012B2F4 ADDIU t5, sp, $0080 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012B2F8 BEQL t6, t5, $0012b310 - if ((this.ee.t6.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1225488u; - // @0012B2FC LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012b300() - { - this.ee.pc = 1225500u; - // @0012B300 LQ t0, $0000(t5) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012B304 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012B308 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B30C LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B310 SLT t7, s7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); - // @0012B314 BEQ t7, zero, $0012b68c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226380u; - } - // @0012B318 SUBU t7, s7, t6 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b31c() - { - this.ee.pc = 1225528u; - // @0012B31C LW t6, $0028(s5) - MobUt.LW(this.ee, this.ee.t6, (40u + this.ee.s5.UL0)); - // @0012B320 SLL t7, s7, 6 - MobUt.SLL(this.ee.t7, this.ee.s7, 6); - // @0012B324 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012B328 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B32C SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012B330 BEQ t7, zero, $0012b674 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226356u; - } - // @0012B334 ADDIU s4, t6, $0030 - this.ee.s4.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012b324() - { - this.ee.pc = 1225528u; - // @0012B324 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012B328 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B32C SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012B330 BEQ t7, zero, $0012b674 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226356u; - } - // @0012B334 ADDIU s4, t6, $0030 - this.ee.s4.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012b338() - { - this.ee.pc = 1225548u; - // @0012B338 LW a0, $0014(s5) - MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); - // @0012B33C LW t7, $0000(a0) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); - // @0012B340 LW v0, $0020(t7) - MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); - // @0012B344 JALR ra, v0 - this.ee.ra.UD0 = 1225548u; - this.ee.pc = this.ee.v0.UL0; - // @0012B348 NOP - MobUt.Latency(); - } - - public virtual void funct0012b34c() - { - this.ee.pc = 1225588u; - // @0012B34C ADDU v0, v0, s3 - this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.s3.SD0))); - // @0012B350 LWC1 $f0, $001c(v0) - MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); - // @0012B354 SWC1 $f0, $0000(s4) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.s4.UL0)); - // @0012B358 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012B35C LW t6, $0008(s0) - MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); - // @0012B360 LHU t3, $0010(t7) - MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t7.UL0)); - // @0012B364 ADDU t5, t6, s3 - this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); - // @0012B368 SLT t7, s7, t3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t3.SD0)); - // @0012B36C BEQ t7, zero, $0012b664 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226340u; - } - // @0012B370 ADDIU t4, t5, $0040 - this.ee.t4.SD0 = ((int)((this.ee.t5.SD0 + 64))); - } - - public virtual void funct0012b350() - { - this.ee.pc = 1225588u; - // @0012B350 LWC1 $f0, $001c(v0) - MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); - // @0012B354 SWC1 $f0, $0000(s4) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.s4.UL0)); - // @0012B358 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012B35C LW t6, $0008(s0) - MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); - // @0012B360 LHU t3, $0010(t7) - MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t7.UL0)); - // @0012B364 ADDU t5, t6, s3 - this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); - // @0012B368 SLT t7, s7, t3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t3.SD0)); - // @0012B36C BEQ t7, zero, $0012b664 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226340u; - } - // @0012B370 ADDIU t4, t5, $0040 - this.ee.t4.SD0 = ((int)((this.ee.t5.SD0 + 64))); - } - - public virtual void funct0012b374() - { - this.ee.pc = 1225724u; - // @0012B374 LW t6, $0028(s5) - MobUt.LW(this.ee, this.ee.t6, (40u + this.ee.s5.UL0)); - // @0012B378 SLL t7, s7, 6 - MobUt.SLL(this.ee.t7, this.ee.s7, 6); - // @0012B37C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B380 ADDIU t7, sp, $0120 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012B384 LQC2 vf1, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); - // @0012B388 LQC2 vf2, $0010(t5) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t5.UL0)); - // @0012B38C LQC2 vf3, $0020(t5) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t5.UL0)); - // @0012B390 LQC2 vf4, $0030(t5) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t5.UL0)); - // @0012B394 LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012B398 LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012B39C LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012B3A0 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012B3A4 VMULAx.xyzw ACC, vf1, vf5x - // @0012B3A8 VMADDAy.xyzw ACC, vf2, vf5y - // @0012B3AC VMADDAz.xyzw ACC, vf3, vf5z - // @0012B3B0 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012B3B4 VMULAx.xyzw ACC, vf1, vf6x - // @0012B3B8 VMADDAy.xyzw ACC, vf2, vf6y - // @0012B3BC VMADDAz.xyzw ACC, vf3, vf6z - // @0012B3C0 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012B3C4 VMULAx.xyzw ACC, vf1, vf7x - // @0012B3C8 VMADDAy.xyzw ACC, vf2, vf7y - // @0012B3CC VMADDAz.xyzw ACC, vf3, vf7z - // @0012B3D0 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012B3D4 VMULAx.xyzw ACC, vf1, vf8x - // @0012B3D8 VMADDAy.xyzw ACC, vf2, vf8y - // @0012B3DC VMADDAz.xyzw ACC, vf3, vf8z - // @0012B3E0 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012B3E4 SQC2 vf5, $0000(t7) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012B3E8 SQC2 vf6, $0010(t7) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); - // @0012B3EC SQC2 vf7, $0020(t7) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); - // @0012B3F0 SQC2 vf8, $0030(t7) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); - // @0012B3F4 BEQL t4, t7, $0012b424 - if ((this.ee.t4.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1225764u; - // @0012B3F8 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012b37c() - { - this.ee.pc = 1225724u; - // @0012B37C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B380 ADDIU t7, sp, $0120 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012B384 LQC2 vf1, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); - // @0012B388 LQC2 vf2, $0010(t5) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t5.UL0)); - // @0012B38C LQC2 vf3, $0020(t5) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t5.UL0)); - // @0012B390 LQC2 vf4, $0030(t5) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t5.UL0)); - // @0012B394 LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012B398 LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012B39C LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012B3A0 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012B3A4 VMULAx.xyzw ACC, vf1, vf5x - // @0012B3A8 VMADDAy.xyzw ACC, vf2, vf5y - // @0012B3AC VMADDAz.xyzw ACC, vf3, vf5z - // @0012B3B0 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012B3B4 VMULAx.xyzw ACC, vf1, vf6x - // @0012B3B8 VMADDAy.xyzw ACC, vf2, vf6y - // @0012B3BC VMADDAz.xyzw ACC, vf3, vf6z - // @0012B3C0 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012B3C4 VMULAx.xyzw ACC, vf1, vf7x - // @0012B3C8 VMADDAy.xyzw ACC, vf2, vf7y - // @0012B3CC VMADDAz.xyzw ACC, vf3, vf7z - // @0012B3D0 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012B3D4 VMULAx.xyzw ACC, vf1, vf8x - // @0012B3D8 VMADDAy.xyzw ACC, vf2, vf8y - // @0012B3DC VMADDAz.xyzw ACC, vf3, vf8z - // @0012B3E0 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012B3E4 SQC2 vf5, $0000(t7) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012B3E8 SQC2 vf6, $0010(t7) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); - // @0012B3EC SQC2 vf7, $0020(t7) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); - // @0012B3F0 SQC2 vf8, $0030(t7) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); - // @0012B3F4 BEQL t4, t7, $0012b424 - if ((this.ee.t4.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1225764u; - // @0012B3F8 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012b3fc() - { - this.ee.pc = 1225780u; - // @0012B3FC DADDU t5, t7, zero - this.ee.t5.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); - // @0012B400 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012B404 LQ t1, $0010(t7) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); - // @0012B408 LQ t2, $0020(t7) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); - // @0012B40C LQ t3, $0030(t7) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); - // @0012B410 SQ t0, $0000(t4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); - // @0012B414 SQ t1, $0010(t4) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); - // @0012B418 SQ t2, $0020(t4) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); - // @0012B41C SQ t3, $0030(t4) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); - // @0012B420 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B424 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B428 SLT t7, s7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); - // @0012B42C BEQ t7, zero, $0012b658 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226328u; - } - // @0012B430 SUBU t7, s7, t6 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b434() - { - this.ee.pc = 1225812u; - // @0012B434 LW t6, $002c(s5) - MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); - // @0012B438 SLL t7, s7, 6 - MobUt.SLL(this.ee.t7, this.ee.s7, 6); - // @0012B43C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B440 LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - // @0012B444 ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012B448 ADDIU t7, t7, $0040 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 64))); - // @0012B44C BEQL t6, t7, $0012b47c - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1225852u; - // @0012B450 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012b43c() - { - this.ee.pc = 1225812u; - // @0012B43C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B440 LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - // @0012B444 ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012B448 ADDIU t7, t7, $0040 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 64))); - // @0012B44C BEQL t6, t7, $0012b47c - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1225852u; - // @0012B450 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012b454() - { - this.ee.pc = 1225864u; - // @0012B454 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012B458 LQ t1, $0010(t7) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); - // @0012B45C LQ t2, $0020(t7) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); - // @0012B460 LQ t3, $0030(t7) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); - // @0012B464 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012B468 SQ t1, $0010(t6) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); - // @0012B46C SQ t2, $0020(t6) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); - // @0012B470 SQ t3, $0030(t6) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); - // @0012B474 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B478 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B47C SLT t7, s7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); - // @0012B480 BEQ t7, zero, $0012b64c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226316u; - } - // @0012B484 SUBU t7, s7, t6 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b488() - { - this.ee.pc = 1225948u; - // @0012B488 LW t6, $002c(s5) - MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); - // @0012B48C SLL t7, s7, 6 - MobUt.SLL(this.ee.t7, this.ee.s7, 6); - // @0012B490 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B494 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @0012B498 ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012B49C ADDIU t7, t7, $0010 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16))); - // @0012B4A0 LQC2 vf4, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); - // @0012B4A4 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012B4A8 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012B4AC LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012B4B0 VMULx.xyzw vf1, vf1, vf4x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); - // @0012B4B4 VMULy.xyzw vf2, vf2, vf4y - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); - this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); - // @0012B4B8 VMULz.xyzw vf3, vf3, vf4z - this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); - this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); - // @0012B4BC SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012B4C0 SQC2 vf2, $0010(t6) - MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012B4C4 SQC2 vf3, $0020(t6) - MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012B4C8 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B4CC LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B4D0 SLT t7, s7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); - // @0012B4D4 BEQ t7, zero, $0012b640 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226304u; - } - // @0012B4D8 SUBU t7, s7, t6 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b490() - { - this.ee.pc = 1225948u; - // @0012B490 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B494 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @0012B498 ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012B49C ADDIU t7, t7, $0010 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16))); - // @0012B4A0 LQC2 vf4, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); - // @0012B4A4 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012B4A8 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012B4AC LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012B4B0 VMULx.xyzw vf1, vf1, vf4x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); - // @0012B4B4 VMULy.xyzw vf2, vf2, vf4y - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); - this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); - // @0012B4B8 VMULz.xyzw vf3, vf3, vf4z - this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); - this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); - // @0012B4BC SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012B4C0 SQC2 vf2, $0010(t6) - MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012B4C4 SQC2 vf3, $0020(t6) - MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012B4C8 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B4CC LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B4D0 SLT t7, s7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); - // @0012B4D4 BEQ t7, zero, $0012b640 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226304u; - } - // @0012B4D8 SUBU t7, s7, t6 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b4dc() - { - this.ee.pc = 1225976u; - // @0012B4DC LW t6, $002c(s5) - MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); - // @0012B4E0 SLL t7, s7, 6 - MobUt.SLL(this.ee.t7, this.ee.s7, 6); - // @0012B4E4 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012B4E8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B4EC SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012B4F0 BEQ t7, zero, $0012b62c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226284u; - } - // @0012B4F4 ADDIU t3, t6, $0030 - this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012b4e4() - { - this.ee.pc = 1225976u; - // @0012B4E4 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012B4E8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B4EC SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012B4F0 BEQ t7, zero, $0012b62c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226284u; - } - // @0012B4F4 ADDIU t3, t6, $0030 - this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012b4f8() - { - this.ee.pc = 1226000u; - // @0012B4F8 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012B4FC ADDU v0, t7, s3 - this.ee.v0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012B500 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B504 SLT t7, s7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); - // @0012B508 BEQ t7, zero, $0012b620 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226272u; - } - // @0012B50C SUBU t7, s7, t6 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b500() - { - this.ee.pc = 1226000u; - // @0012B500 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B504 SLT t7, s7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); - // @0012B508 BEQ t7, zero, $0012b620 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226272u; - } - // @0012B50C SUBU t7, s7, t6 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b510() - { - this.ee.pc = 1226092u; - // @0012B510 LW t6, $0028(s5) - MobUt.LW(this.ee, this.ee.t6, (40u + this.ee.s5.UL0)); - // @0012B514 SLL t7, s7, 6 - MobUt.SLL(this.ee.t7, this.ee.s7, 6); - // @0012B518 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B51C ADDIU t7, t6, $0030 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012B520 LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012B524 LQC2 vf1, $0000(v0) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.v0.UL0)); - // @0012B528 LQC2 vf2, $0010(v0) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.v0.UL0)); - // @0012B52C LQC2 vf3, $0020(v0) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.v0.UL0)); - // @0012B530 LQC2 vf4, $0030(v0) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.v0.UL0)); - // @0012B534 VMULAx.xyz ACC, vf1, vf5x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); - // @0012B538 VMADDAy.xyz ACC, vf2, vf5y - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); - // @0012B53C VMADDAz.xyz ACC, vf3, vf5z - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); - // @0012B540 VMADDw.xyz vf5, vf4, vf0w - this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); - this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); - this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); - // @0012B544 VMOVE.w vf5, vf0 - this.ee.VF[5].w = this.ee.VF[0].w; - // @0012B548 SQC2 vf5, $0000(t3) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); - // @0012B54C LW t6, $0220(sp) - MobUt.LW(this.ee, this.ee.t6, (544u + this.ee.sp.UL0)); - // @0012B550 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B554 LHU a2, $0002(t6) - MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.t6.UL0)); - // @0012B558 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B55C ANDI t5, a2, $ffff - this.ee.t5.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); - // @0012B560 SLT t7, t5, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); - // @0012B564 BEQ t7, zero, $0012b610 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226256u; - } - // @0012B568 DADDU t3, t4, zero - this.ee.t3.UD0 = (this.ee.t4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012b518() - { - this.ee.pc = 1226092u; - // @0012B518 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B51C ADDIU t7, t6, $0030 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012B520 LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012B524 LQC2 vf1, $0000(v0) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.v0.UL0)); - // @0012B528 LQC2 vf2, $0010(v0) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.v0.UL0)); - // @0012B52C LQC2 vf3, $0020(v0) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.v0.UL0)); - // @0012B530 LQC2 vf4, $0030(v0) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.v0.UL0)); - // @0012B534 VMULAx.xyz ACC, vf1, vf5x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); - // @0012B538 VMADDAy.xyz ACC, vf2, vf5y - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); - // @0012B53C VMADDAz.xyz ACC, vf3, vf5z - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); - // @0012B540 VMADDw.xyz vf5, vf4, vf0w - this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); - this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); - this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); - // @0012B544 VMOVE.w vf5, vf0 - this.ee.VF[5].w = this.ee.VF[0].w; - // @0012B548 SQC2 vf5, $0000(t3) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); - // @0012B54C LW t6, $0220(sp) - MobUt.LW(this.ee, this.ee.t6, (544u + this.ee.sp.UL0)); - // @0012B550 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B554 LHU a2, $0002(t6) - MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.t6.UL0)); - // @0012B558 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B55C ANDI t5, a2, $ffff - this.ee.t5.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); - // @0012B560 SLT t7, t5, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); - // @0012B564 BEQ t7, zero, $0012b610 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226256u; - } - // @0012B568 DADDU t3, t4, zero - this.ee.t3.UD0 = (this.ee.t4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012b56c() - { - this.ee.pc = 1226124u; - // @0012B56C LW t6, $002c(s5) - MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); - // @0012B570 SLL t7, t5, 6 - MobUt.SLL(this.ee.t7, this.ee.t5, 6); - // @0012B574 ADDU t7, t6, t7 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B578 LHU t6, $0010(t3) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t3.UL0)); - // @0012B57C ADDIU t2, t7, $0030 - this.ee.t2.SD0 = ((int)((this.ee.t7.SD0 + 48))); - // @0012B580 SLT t7, s7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); - // @0012B584 BEQ t7, zero, $0012b604 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226244u; - } - // @0012B588 SUBU t7, s7, t6 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b574() - { - this.ee.pc = 1226124u; - // @0012B574 ADDU t7, t6, t7 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B578 LHU t6, $0010(t3) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t3.UL0)); - // @0012B57C ADDIU t2, t7, $0030 - this.ee.t2.SD0 = ((int)((this.ee.t7.SD0 + 48))); - // @0012B580 SLT t7, s7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); - // @0012B584 BEQ t7, zero, $0012b604 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226244u; - } - // @0012B588 SUBU t7, s7, t6 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b58c() - { - this.ee.pc = 1226156u; - // @0012B58C LW t6, $002c(s5) - MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); - // @0012B590 SLL t7, s7, 6 - MobUt.SLL(this.ee.t7, this.ee.s7, 6); - // @0012B594 LHU t5, $0010(t3) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t3.UL0)); - // @0012B598 ADDU t4, t6, t7 - this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B59C ANDI a2, a2, $ffff - this.ee.a2.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); - // @0012B5A0 SLT t7, a2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); - // @0012B5A4 BEQ t7, zero, $0012b5e8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226216u; - } - // @0012B5A8 SLL t7, a2, 4 - MobUt.SLL(this.ee.t7, this.ee.a2, 4); - } - - public virtual void funct0012b594() - { - this.ee.pc = 1226156u; - // @0012B594 LHU t5, $0010(t3) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t3.UL0)); - // @0012B598 ADDU t4, t6, t7 - this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B59C ANDI a2, a2, $ffff - this.ee.a2.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); - // @0012B5A0 SLT t7, a2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); - // @0012B5A4 BEQ t7, zero, $0012b5e8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226216u; - } - // @0012B5A8 SLL t7, a2, 4 - MobUt.SLL(this.ee.t7, this.ee.a2, 4); - } - - public virtual void funct0012b5ac() - { - this.ee.pc = 1226216u; - // @0012B5AC LW t6, $0024(s5) - MobUt.LW(this.ee, this.ee.t6, (36u + this.ee.s5.UL0)); - // @0012B5B0 ADDU a2, t6, t7 - this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B5B4 LQC2 vf5, $0000(a2) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.a2.UL0)); - // @0012B5B8 LQC2 vf1, $0000(t4) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); - // @0012B5BC LQC2 vf2, $0010(t4) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t4.UL0)); - // @0012B5C0 LQC2 vf3, $0020(t4) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t4.UL0)); - // @0012B5C4 LQC2 vf4, $0030(t4) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t4.UL0)); - // @0012B5C8 VMULAx.xyz ACC, vf1, vf5x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); - // @0012B5CC VMADDAy.xyz ACC, vf2, vf5y - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); - // @0012B5D0 VMADDAz.xyz ACC, vf3, vf5z - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); - // @0012B5D4 VMADDw.xyz vf5, vf4, vf0w - this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); - this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); - this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); - // @0012B5D8 VMOVE.w vf5, vf0 - this.ee.VF[5].w = this.ee.VF[0].w; - // @0012B5DC SQC2 vf5, $0000(t2) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t2.UL0)); - // @0012B5E0 BEQ zero, zero, $00129e60 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220192u; - } - // @0012B5E4 LW t3, $01f4(sp) - MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); - } - - public virtual void funct0012b5b4() - { - this.ee.pc = 1226216u; - // @0012B5B4 LQC2 vf5, $0000(a2) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.a2.UL0)); - // @0012B5B8 LQC2 vf1, $0000(t4) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); - // @0012B5BC LQC2 vf2, $0010(t4) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t4.UL0)); - // @0012B5C0 LQC2 vf3, $0020(t4) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t4.UL0)); - // @0012B5C4 LQC2 vf4, $0030(t4) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t4.UL0)); - // @0012B5C8 VMULAx.xyz ACC, vf1, vf5x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); - // @0012B5CC VMADDAy.xyz ACC, vf2, vf5y - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); - // @0012B5D0 VMADDAz.xyz ACC, vf3, vf5z - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); - // @0012B5D4 VMADDw.xyz vf5, vf4, vf0w - this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); - this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); - this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); - // @0012B5D8 VMOVE.w vf5, vf0 - this.ee.VF[5].w = this.ee.VF[0].w; - // @0012B5DC SQC2 vf5, $0000(t2) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t2.UL0)); - // @0012B5E0 BEQ zero, zero, $00129e60 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220192u; - } - // @0012B5E4 LW t3, $01f4(sp) - MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); - } - - public virtual void funct0012b5e8() - { - this.ee.pc = 1226244u; - // @0012B5E8 LW t6, $0018(t3) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t3.UL0)); - // @0012B5EC SUBU t7, a2, t5 - this.ee.t7.SD0 = ((int)((this.ee.a2.UD0 - this.ee.t5.UD0))); - // @0012B5F0 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B5F4 ADDU t6, t3, t6 - this.ee.t6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t6.SD0))); - // @0012B5F8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B5FC BEQ zero, zero, $0012b5b4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226164u; - } - // @0012B600 ADDIU a2, t6, $0030 - this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012b604() - { - this.ee.pc = 1226256u; - // @0012B604 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012B608 BEQ zero, zero, $0012b594 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226132u; - } - // @0012B60C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012b610() - { - this.ee.pc = 1226272u; - // @0012B610 SUBU t7, t5, t6 - this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.t6.UD0))); - // @0012B614 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012B618 BEQ zero, zero, $0012b574 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226100u; - } - // @0012B61C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012b620() - { - this.ee.pc = 1226284u; - // @0012B620 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012B624 BEQ zero, zero, $0012b518 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226008u; - } - // @0012B628 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012b62c() - { - this.ee.pc = 1226304u; - // @0012B62C SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012B630 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012B634 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B638 BEQ zero, zero, $0012b500 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225984u; - } - // @0012B63C ADDU v0, t6, t7 - this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012b640() - { - this.ee.pc = 1226316u; - // @0012B640 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012B644 BEQ zero, zero, $0012b4e4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225956u; - } - // @0012B648 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012b64c() - { - this.ee.pc = 1226328u; - // @0012B64C LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012B650 BEQ zero, zero, $0012b490 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225872u; - } - // @0012B654 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012b658() - { - this.ee.pc = 1226340u; - // @0012B658 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012B65C BEQ zero, zero, $0012b43c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225788u; - } - // @0012B660 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012b664() - { - this.ee.pc = 1226356u; - // @0012B664 SUBU t7, s7, t3 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t3.UD0))); - // @0012B668 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012B66C BEQ zero, zero, $0012b37c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225596u; - } - // @0012B670 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012b674() - { - this.ee.pc = 1226380u; - // @0012B674 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - // @0012B678 SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012B67C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B680 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012B684 BEQ zero, zero, $0012b350 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225552u; - } - // @0012B688 ADDU v0, t6, t7 - this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012b68c() - { - this.ee.pc = 1226392u; - // @0012B68C LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012B690 BEQ zero, zero, $0012b324 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225508u; - } - // @0012B694 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012b698() - { - this.ee.pc = 1226408u; - // @0012B698 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012B69C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B6A0 BEQ zero, zero, $0012b2f0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225456u; - } - // @0012B6A4 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012b6a8() - { - this.ee.pc = 1226424u; - // @0012B6A8 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012B6AC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B6B0 BEQ zero, zero, $0012b2a4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225380u; - } - // @0012B6B4 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012b6b8() - { - this.ee.pc = 1226440u; - // @0012B6B8 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012B6BC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B6C0 BEQ zero, zero, $0012b258 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225304u; - } - // @0012B6C4 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012b6c8() - { - this.ee.pc = 1226460u; - // @0012B6C8 SUBU t7, s2, t4 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); - // @0012B6CC LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012B6D0 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B6D4 BEQ zero, zero, $0012b1a0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225120u; - } - // @0012B6D8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012b6dc() - { - this.ee.pc = 1226476u; - // @0012B6DC LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012B6E0 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B6E4 BEQ zero, zero, $0012b170 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1225072u; - } - // @0012B6E8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012b7a8() - { - this.ee.pc = 1226692u; - // @0012B7A8 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B7AC LW t3, $0014(s0) - MobUt.LW(this.ee, this.ee.t3, (20u + this.ee.s0.UL0)); - // @0012B7B0 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012B7B4 ADDU t6, t3, s8 - this.ee.t6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); - // @0012B7B8 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012B7BC BEQ t7, zero, $0012b930 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227056u; - } - // @0012B7C0 SW t6, $0244(sp) - MobUt.SW(this.ee, this.ee.t6, (580u + this.ee.sp.UL0)); - } - - public virtual void funct0012b7c4() - { - this.ee.pc = 1226712u; - // @0012B7C4 LW a0, $0014(s5) - MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); - // @0012B7C8 LW t7, $0000(a0) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); - // @0012B7CC LW v0, $0020(t7) - MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); - // @0012B7D0 JALR ra, v0 - this.ee.ra.UD0 = 1226712u; - this.ee.pc = this.ee.v0.UL0; - // @0012B7D4 SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - } - - public virtual void funct0012b7d8() - { - this.ee.pc = 1226764u; - // @0012B7D8 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B7DC ADDU v0, v0, s3 - this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.s3.SD0))); - // @0012B7E0 LW t3, $0014(s0) - MobUt.LW(this.ee, this.ee.t3, (20u + this.ee.s0.UL0)); - // @0012B7E4 LW t7, $0244(sp) - MobUt.LW(this.ee, this.ee.t7, (580u + this.ee.sp.UL0)); - // @0012B7E8 LWC1 $f0, $001c(v0) - MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); - // @0012B7EC LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @0012B7F0 ADDU t7, t3, s8 - this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); - // @0012B7F4 ADDIU t7, t7, $0010 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16))); - // @0012B7F8 SW t7, $0248(sp) - MobUt.SW(this.ee, this.ee.t7, (584u + this.ee.sp.UL0)); - // @0012B7FC LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012B800 SLT t7, s7, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t5.SD0)); - // @0012B804 BEQ t7, zero, $0012b918 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227032u; - } - // @0012B808 MUL.S $f20, $f1, $f0 - this.ee.fpr[20].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct0012b7e4() - { - this.ee.pc = 1226764u; - // @0012B7E4 LW t7, $0244(sp) - MobUt.LW(this.ee, this.ee.t7, (580u + this.ee.sp.UL0)); - // @0012B7E8 LWC1 $f0, $001c(v0) - MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); - // @0012B7EC LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @0012B7F0 ADDU t7, t3, s8 - this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); - // @0012B7F4 ADDIU t7, t7, $0010 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16))); - // @0012B7F8 SW t7, $0248(sp) - MobUt.SW(this.ee, this.ee.t7, (584u + this.ee.sp.UL0)); - // @0012B7FC LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012B800 SLT t7, s7, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t5.SD0)); - // @0012B804 BEQ t7, zero, $0012b918 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227032u; - } - // @0012B808 MUL.S $f20, $f1, $f0 - this.ee.fpr[20].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct0012b80c() - { - this.ee.pc = 1226784u; - // @0012B80C LW a0, $0014(s5) - MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); - // @0012B810 LW t7, $0000(a0) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); - // @0012B814 LW v0, $0020(t7) - MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); - // @0012B818 JALR ra, v0 - this.ee.ra.UD0 = 1226784u; - this.ee.pc = this.ee.v0.UL0; - // @0012B81C NOP - MobUt.Latency(); - } - - public virtual void funct0012b820() - { - this.ee.pc = 1226824u; - // @0012B820 SLL t7, s7, 6 - MobUt.SLL(this.ee.t7, this.ee.s7, 6); - // @0012B824 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012B828 ADDU v0, v0, t7 - this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.t7.SD0))); - // @0012B82C LW t3, $0248(sp) - MobUt.LW(this.ee, this.ee.t3, (584u + this.ee.sp.UL0)); - // @0012B830 LWC1 $f0, $001c(v0) - MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); - // @0012B834 LWC1 $f1, $0000(t3) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t3.UL0)); - // @0012B838 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B83C SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012B840 BEQ t7, zero, $0012b904 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227012u; - } - // @0012B844 MUL.S $f13, $f1, $f0 - this.ee.fpr[13].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct0012b82c() - { - this.ee.pc = 1226824u; - // @0012B82C LW t3, $0248(sp) - MobUt.LW(this.ee, this.ee.t3, (584u + this.ee.sp.UL0)); - // @0012B830 LWC1 $f0, $001c(v0) - MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); - // @0012B834 LWC1 $f1, $0000(t3) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t3.UL0)); - // @0012B838 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B83C SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012B840 BEQ t7, zero, $0012b904 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227012u; - } - // @0012B844 MUL.S $f13, $f1, $f0 - this.ee.fpr[13].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct0012b848() - { - this.ee.pc = 1226848u; - // @0012B848 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012B84C ADDU a3, t7, s3 - this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012B850 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B854 SLT t7, s7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); - // @0012B858 BEQ t7, zero, $0012b8f8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227000u; - } - // @0012B85C SUBU t7, s7, t6 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b850() - { - this.ee.pc = 1226848u; - // @0012B850 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012B854 SLT t7, s7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); - // @0012B858 BEQ t7, zero, $0012b8f8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227000u; - } - // @0012B85C SUBU t7, s7, t6 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012b860() - { - this.ee.pc = 1226876u; - // @0012B860 LW t6, $0028(s5) - MobUt.LW(this.ee, this.ee.t6, (40u + this.ee.s5.UL0)); - // @0012B864 SLL t7, s7, 6 - MobUt.SLL(this.ee.t7, this.ee.s7, 6); - // @0012B868 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012B86C ADDU t0, t6, t7 - this.ee.t0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B870 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012B874 BEQL t7, zero, $0012b8e0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226976u; - // @0012B878 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012b868() - { - this.ee.pc = 1226876u; - // @0012B868 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012B86C ADDU t0, t6, t7 - this.ee.t0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B870 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012B874 BEQL t7, zero, $0012b8e0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226976u; - // @0012B878 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012b87c() - { - this.ee.pc = 1226900u; - // @0012B87C LW t7, $0020(s5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); - // @0012B880 ADDU t3, t7, s8 - this.ee.t3.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012B884 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012B888 SLT t7, s7, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t5.SD0)); - // @0012B88C BEQ t7, zero, $0012b8c4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226948u; - } - // @0012B890 SLL t7, s7, 4 - MobUt.SLL(this.ee.t7, this.ee.s7, 4); - } - - public virtual void funct0012b884() - { - this.ee.pc = 1226900u; - // @0012B884 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012B888 SLT t7, s7, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t5.SD0)); - // @0012B88C BEQ t7, zero, $0012b8c4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226948u; - } - // @0012B890 SLL t7, s7, 4 - MobUt.SLL(this.ee.t7, this.ee.s7, 4); - } - - public virtual void funct0012b894() - { - this.ee.pc = 1226948u; - // @0012B894 LW t6, $0020(s5) - MobUt.LW(this.ee, this.ee.t6, (32u + this.ee.s5.UL0)); - // @0012B898 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B89C LW t4, $024c(sp) - MobUt.LW(this.ee, this.ee.t4, (588u + this.ee.sp.UL0)); - // @0012B8A0 MOV.S $f12, $f20 - this.ee.fpr[12].f = this.ee.fpr[20].f; - // @0012B8A4 LWC1 $f14, $0000(t3) - MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t3.UL0)); - // @0012B8A8 ADDIU a0, sp, $00a0 - this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); - // @0012B8AC ANDI a2, t4, $0003 - this.ee.a2.UD0 = ((ushort)((this.ee.t4.US0 & 3))); - // @0012B8B0 LWC1 $f15, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[15], (0u + this.ee.t6.UL0)); - // @0012B8B4 ADDIU a2, a2, $fffe - this.ee.a2.SD0 = ((int)((this.ee.a2.SD0 + -2))); - // @0012B8B8 ADDIU a1, sp, $00b0 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); - // @0012B8BC BEQ zero, zero, $0012b100 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1224960u; - } - // @0012B8C0 DADDU t1, zero, zero - this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012b89c() - { - this.ee.pc = 1226948u; - // @0012B89C LW t4, $024c(sp) - MobUt.LW(this.ee, this.ee.t4, (588u + this.ee.sp.UL0)); - // @0012B8A0 MOV.S $f12, $f20 - this.ee.fpr[12].f = this.ee.fpr[20].f; - // @0012B8A4 LWC1 $f14, $0000(t3) - MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t3.UL0)); - // @0012B8A8 ADDIU a0, sp, $00a0 - this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); - // @0012B8AC ANDI a2, t4, $0003 - this.ee.a2.UD0 = ((ushort)((this.ee.t4.US0 & 3))); - // @0012B8B0 LWC1 $f15, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[15], (0u + this.ee.t6.UL0)); - // @0012B8B4 ADDIU a2, a2, $fffe - this.ee.a2.SD0 = ((int)((this.ee.a2.SD0 + -2))); - // @0012B8B8 ADDIU a1, sp, $00b0 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); - // @0012B8BC BEQ zero, zero, $0012b100 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1224960u; - } - // @0012B8C0 DADDU t1, zero, zero - this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012b8c4() - { - this.ee.pc = 1226976u; - // @0012B8C4 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - // @0012B8C8 SUBU t7, s7, t5 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t5.UD0))); - // @0012B8CC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B8D0 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012B8D4 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B8D8 BEQ zero, zero, $0012b89c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226908u; - } - // @0012B8DC ADDIU t6, t6, $0020 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); - } - - public virtual void funct0012b8e0() - { - this.ee.pc = 1227000u; - // @0012B8E0 SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012B8E4 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B8E8 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012B8EC ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B8F0 BEQ zero, zero, $0012b884 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226884u; - } - // @0012B8F4 ADDIU t3, t6, $0020 - this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + 32))); - } - - public virtual void funct0012b8f8() - { - this.ee.pc = 1227012u; - // @0012B8F8 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012B8FC BEQ zero, zero, $0012b868 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226856u; - } - // @0012B900 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012b904() - { - this.ee.pc = 1227032u; - // @0012B904 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - // @0012B908 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012B90C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B910 BEQ zero, zero, $0012b850 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226832u; - } - // @0012B914 ADDU a3, t6, t7 - this.ee.a3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012b918() - { - this.ee.pc = 1227056u; - // @0012B918 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - // @0012B91C SUBU t7, s7, t5 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t5.UD0))); - // @0012B920 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B924 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012B928 BEQ zero, zero, $0012b82c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226796u; - } - // @0012B92C ADDU v0, t6, t7 - this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012b930() - { - this.ee.pc = 1227084u; - // @0012B930 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - // @0012B934 SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012B938 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B93C SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - // @0012B940 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012B944 BEQ zero, zero, $0012b7e4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1226724u; - } - // @0012B948 ADDU v0, t6, t7 - this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012b97c() - { - this.ee.pc = 1227148u; - // @0012B97C LW t6, $0000(a0) - MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.a0.UL0)); - // @0012B980 LW t7, $0014(t6) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.t6.UL0)); - // @0012B984 JALR ra, t7 - this.ee.ra.UD0 = 1227148u; - this.ee.pc = this.ee.t7.UL0; - // @0012B988 ADDIU a1, s3, $ffe0 - this.ee.a1.SD0 = ((int)((this.ee.s3.SD0 + -32))); - } - - public virtual void funct0012b98c() - { - this.ee.pc = 1227156u; - // @0012B98C BEQ zero, zero, $0012acb8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223864u; - } - // @0012B990 MOV.S $f20, $f0 - this.ee.fpr[20].f = this.ee.fpr[0].f; - } - - public virtual void funct0012b998() - { - this.ee.pc = 1227184u; - // @0012B998 ADDIU t7, t7, $0020 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 32))); - // @0012B99C SW t7, $0224(sp) - MobUt.SW(this.ee, this.ee.t7, (548u + this.ee.sp.UL0)); - // @0012B9A0 LD t5, $0010(t7) - MobUt.LD(this.ee, this.ee.t5, (16u + this.ee.t7.UL0)); - // @0012B9A4 AND t7, t5, t4 - this.ee.t7.UD0 = (this.ee.t5.UD0 & this.ee.t4.UD0); - // @0012B9A8 BEQL t7, zero, $0012ac68 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223784u; - // @0012B9AC LW t3, $0224(sp) - MobUt.LW(this.ee, this.ee.t3, (548u + this.ee.sp.UL0)); - } - } - - public virtual void funct0012b9b0() - { - this.ee.pc = 1227192u; - // @0012B9B0 BEQ zero, zero, $0012acd8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223896u; - } - // @0012B9B4 LW t3, $0228(sp) - MobUt.LW(this.ee, this.ee.t3, (552u + this.ee.sp.UL0)); - } - - public virtual void funct0012b9b8() - { - this.ee.pc = 1227220u; - // @0012B9B8 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - // @0012B9BC SUBU t7, s7, t2 - this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t2.UD0))); - // @0012B9C0 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B9C4 ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012B9C8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012B9CC BEQ zero, zero, $0012abf0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223664u; - } - // @0012B9D0 ADDIU t6, t6, $0010 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 16))); - } - - public virtual void funct0012b9d4() - { - this.ee.pc = 1227244u; - // @0012B9D4 SUBU t7, t4, t6 - this.ee.t7.SD0 = ((int)((this.ee.t4.UD0 - this.ee.t6.UD0))); - // @0012B9D8 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012B9DC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B9E0 SW t5, $0250(sp) - MobUt.SW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); - // @0012B9E4 BEQ zero, zero, $0012aa7c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223292u; - } - // @0012B9E8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012b9ec() - { - this.ee.pc = 1227272u; - // @0012B9EC LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - // @0012B9F0 SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012B9F4 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012B9F8 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012B9FC ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012BA00 BEQ zero, zero, $0012aa38 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223224u; - } - // @0012BA04 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012ba08() - { - this.ee.pc = 1227284u; - // @0012BA08 ADDIU t7, zero, $ffff - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); - // @0012BA0C BNE a2, t7, $0012ba40 - if ((this.ee.a2.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1227328u; - } - // @0012BA10 LW t4, $0214(sp) - MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); - } - - public virtual void funct0012ba14() - { - this.ee.pc = 1227292u; - // @0012BA14 BNE a3, a2, $0012ba40 - if ((this.ee.a3.UD0 != this.ee.a2.UD0)) - { - this.ee.pc = 1227328u; - } - // @0012BA18 LW t7, $0218(sp) - MobUt.LW(this.ee, this.ee.t7, (536u + this.ee.sp.UL0)); - } - - public virtual void funct0012ba1c() - { - this.ee.pc = 1227300u; - // @0012BA1C BNE t7, zero, $0012ba40 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1227328u; - } - // @0012BA20 LUI t7, $000c - this.ee.t7.SD0 = 786432; - } - - public virtual void funct0012ba24() - { - this.ee.pc = 1227312u; - // @0012BA24 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @0012BA28 BNE t7, zero, $0012ba40 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1227328u; - } - // @0012BA2C NOP - MobUt.Latency(); - } - - public virtual void funct0012ba30() - { - this.ee.pc = 1227320u; - // @0012BA30 BNE v0, zero, $0012ba40 - if ((this.ee.v0.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1227328u; - } - // @0012BA34 LW t3, $021c(sp) - MobUt.LW(this.ee, this.ee.t3, (540u + this.ee.sp.UL0)); - } - - public virtual void funct0012ba38() - { - this.ee.pc = 1227328u; - // @0012BA38 BEQ t3, zero, $0012bb34 - if ((this.ee.t3.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227572u; - } - // @0012BA3C LUI t7, $0004 - this.ee.t7.SD0 = 262144; - } - - public virtual void funct0012ba40() - { - this.ee.pc = 1227336u; - // @0012BA40 BGEZL t4, $0012ca88 - if ((this.ee.t4.SD0 >= 0)) - { - this.ee.pc = 1231496u; - // @0012BA44 LW t6, $0004(s0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012ba48() - { - this.ee.pc = 1227348u; - // @0012BA48 ADDIU a1, sp, $0040 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 64))); - // @0012BA4C BEQ a1, sp, $0012ba74 - if ((this.ee.a1.UD0 == this.ee.sp.UD0)) - { - this.ee.pc = 1227380u; - } - // @0012BA50 NOP - MobUt.Latency(); - } - - public virtual void funct0012ba54() - { - this.ee.pc = 1227584u; - // @0012BA54 LQ t0, $0000(sp) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); - // @0012BA58 LQ t1, $0010(sp) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.sp.UL[0])); - // @0012BA5C LQ t2, $0020(sp) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.sp.UL[0])); - // @0012BA60 LQ t3, $0030(sp) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.sp.UL[0])); - // @0012BA64 SQ t0, $0000(a1) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @0012BA68 SQ t1, $0010(a1) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); - // @0012BA6C SQ t2, $0020(a1) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); - // @0012BA70 SQ t3, $0030(a1) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.a1.UL[0])); - // @0012BA74 LQC2 vf1, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); - // @0012BA78 LQC2 vf2, $0010(a1) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); - // @0012BA7C LQC2 vf3, $0020(a1) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); - // @0012BA80 LQC2 vf4, $0030(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012BA84 VOPMULA.xyz ACC, vf2, vf3 - this.ee.Vacc.x = (this.ee.VF[2].y * this.ee.VF[3].z); - this.ee.Vacc.y = (this.ee.VF[2].z * this.ee.VF[3].x); - this.ee.Vacc.z = (this.ee.VF[2].x * this.ee.VF[3].y); - // @0012BA88 VOPMSUB.xyz vf5, vf3, vf2 - this.ee.VF[5].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[3].y, this.ee.VF[2].z); - this.ee.VF[5].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[3].z, this.ee.VF[2].x); - this.ee.VF[5].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[3].x, this.ee.VF[2].y); - // @0012BA8C VOPMULA.xyz ACC, vf3, vf1 - this.ee.Vacc.x = (this.ee.VF[3].y * this.ee.VF[1].z); - this.ee.Vacc.y = (this.ee.VF[3].z * this.ee.VF[1].x); - this.ee.Vacc.z = (this.ee.VF[3].x * this.ee.VF[1].y); - // @0012BA90 VOPMSUB.xyz vf6, vf1, vf3 - this.ee.VF[6].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[1].y, this.ee.VF[3].z); - this.ee.VF[6].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[1].z, this.ee.VF[3].x); - this.ee.VF[6].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[1].x, this.ee.VF[3].y); - // @0012BA94 VOPMULA.xyz ACC, vf1, vf2 - this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); - this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); - this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); - // @0012BA98 VOPMSUB.xyz vf7, vf2, vf1 - this.ee.VF[7].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); - this.ee.VF[7].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); - this.ee.VF[7].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); - // @0012BA9C VMUL.xyz vf8, vf1, vf5 - this.ee.VF[8].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[5].x); - this.ee.VF[8].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[5].y); - this.ee.VF[8].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[5].z); - // @0012BAA0 VMUL.xyz vf1, vf4, vf5 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[5].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[5].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[5].z); - // @0012BAA4 VMUL.xyz vf2, vf4, vf6 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[6].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[6].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[6].z); - // @0012BAA8 VMUL.xyz vf3, vf4, vf7 - this.ee.VF[3].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[7].x); - this.ee.VF[3].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[7].y); - this.ee.VF[3].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[7].z); - // @0012BAAC VADDy.x vf8, vf8, vf8y - this.ee.VF[8].x = (this.ee.VF[8].x + this.ee.VF[8].y); - // @0012BAB0 VADDy.x vf1, vf1, vf1y - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); - // @0012BAB4 VADDx.y vf2, vf2, vf2x - this.ee.VF[2].y = (this.ee.VF[2].y + this.ee.VF[2].x); - // @0012BAB8 VADDx.z vf3, vf3, vf3x - this.ee.VF[3].z = (this.ee.VF[3].z + this.ee.VF[3].x); - // @0012BABC VADDz.x vf8, vf8, vf8z - this.ee.VF[8].x = (this.ee.VF[8].x + this.ee.VF[8].z); - // @0012BAC0 VADDz.x vf4, vf1, vf1z - this.ee.VF[4].x = (this.ee.VF[1].x + this.ee.VF[1].z); - // @0012BAC4 VADDz.y vf4, vf2, vf2z - this.ee.VF[4].y = (this.ee.VF[2].y + this.ee.VF[2].z); - // @0012BAC8 VADDy.z vf4, vf3, vf3y - this.ee.VF[4].z = (this.ee.VF[3].z + this.ee.VF[3].y); - // @0012BACC VDIV Q, vf0w, vf8x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[8].x); - // @0012BAD0 QMFC2 t0, vf5 - MobUt.QMFC2(this.ee.t0, this.ee.VF[5]); - // @0012BAD4 QMFC2 t1, vf6 - MobUt.QMFC2(this.ee.t1, this.ee.VF[6]); - // @0012BAD8 QMFC2 t2, vf7 - MobUt.QMFC2(this.ee.t2, this.ee.VF[7]); - // @0012BADC QMFC2 t3, vf0 - MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); - // @0012BAE0 PEXTLW t4, t1, t0 - this.ee.t4.UL[0] = this.ee.t0.UL[0]; - this.ee.t4.UL[1] = this.ee.t1.UL[0]; - this.ee.t4.UL[2] = this.ee.t0.UL[1]; - this.ee.t4.UL[3] = this.ee.t1.UL[1]; - // @0012BAE4 PEXTUW t5, t1, t0 - this.ee.t5.UL[0] = this.ee.t0.UL[2]; - this.ee.t5.UL[1] = this.ee.t1.UL[2]; - this.ee.t5.UL[2] = this.ee.t0.UL[3]; - this.ee.t5.UL[3] = this.ee.t1.UL[3]; - // @0012BAE8 PEXTLW t6, t3, t2 - this.ee.t6.UL[0] = this.ee.t2.UL[0]; - this.ee.t6.UL[1] = this.ee.t3.UL[0]; - this.ee.t6.UL[2] = this.ee.t2.UL[1]; - this.ee.t6.UL[3] = this.ee.t3.UL[1]; - // @0012BAEC PEXTUW t7, t3, t2 - this.ee.t7.UL[0] = this.ee.t2.UL[2]; - this.ee.t7.UL[1] = this.ee.t3.UL[2]; - this.ee.t7.UL[2] = this.ee.t2.UL[3]; - this.ee.t7.UL[3] = this.ee.t3.UL[3]; - // @0012BAF0 PCPYLD t0, t6, t4 - this.ee.t0.UD1 = this.ee.t6.UD0; - this.ee.t0.UD0 = this.ee.t4.UD0; - // @0012BAF4 PCPYUD t1, t4, t6 - this.ee.t1.UD0 = this.ee.t4.UD1; - this.ee.t1.UD1 = this.ee.t6.UD1; - // @0012BAF8 PCPYLD t2, t7, t5 - this.ee.t2.UD1 = this.ee.t7.UD0; - this.ee.t2.UD0 = this.ee.t5.UD0; - // @0012BAFC QMTC2 t0, vf1 - MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); - // @0012BB00 QMTC2 t1, vf2 - MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); - // @0012BB04 QMTC2 t2, vf3 - MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); - // @0012BB08 VSUB.xyz vf4, vf0, vf4 - this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); - this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); - this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); - // @0012BB0C VWAITQ - MobUt.Latency(); - // @0012BB10 VMULq.xyzw vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - this.ee.VF[1].w = (this.ee.VF[1].w * this.ee.Vq.f); - // @0012BB14 VMULq.xyzw vf2, vf2, Q - this.ee.VF[2].x = (this.ee.VF[2].x * this.ee.Vq.f); - this.ee.VF[2].y = (this.ee.VF[2].y * this.ee.Vq.f); - this.ee.VF[2].z = (this.ee.VF[2].z * this.ee.Vq.f); - this.ee.VF[2].w = (this.ee.VF[2].w * this.ee.Vq.f); - // @0012BB18 VMULq.xyzw vf3, vf3, Q - this.ee.VF[3].x = (this.ee.VF[3].x * this.ee.Vq.f); - this.ee.VF[3].y = (this.ee.VF[3].y * this.ee.Vq.f); - this.ee.VF[3].z = (this.ee.VF[3].z * this.ee.Vq.f); - this.ee.VF[3].w = (this.ee.VF[3].w * this.ee.Vq.f); - // @0012BB1C VMULq.xyz vf4, vf4, Q - this.ee.VF[4].x = (this.ee.VF[4].x * this.ee.Vq.f); - this.ee.VF[4].y = (this.ee.VF[4].y * this.ee.Vq.f); - this.ee.VF[4].z = (this.ee.VF[4].z * this.ee.Vq.f); - // @0012BB20 SQC2 vf1, $0000(a1) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); - // @0012BB24 SQC2 vf2, $0010(a1) - MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); - // @0012BB28 SQC2 vf3, $0020(a1) - MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); - // @0012BB2C SQC2 vf4, $0030(a1) - MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012BB30 LUI t7, $0004 - this.ee.t7.SD0 = 262144; - // @0012BB34 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @0012BB38 BEQ t7, zero, $0012c738 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230648u; - } - // @0012BB3C ADDIU t7, zero, $ffff - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); - } - - public virtual void funct0012ba74() - { - this.ee.pc = 1227584u; - // @0012BA74 LQC2 vf1, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); - // @0012BA78 LQC2 vf2, $0010(a1) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); - // @0012BA7C LQC2 vf3, $0020(a1) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); - // @0012BA80 LQC2 vf4, $0030(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012BA84 VOPMULA.xyz ACC, vf2, vf3 - this.ee.Vacc.x = (this.ee.VF[2].y * this.ee.VF[3].z); - this.ee.Vacc.y = (this.ee.VF[2].z * this.ee.VF[3].x); - this.ee.Vacc.z = (this.ee.VF[2].x * this.ee.VF[3].y); - // @0012BA88 VOPMSUB.xyz vf5, vf3, vf2 - this.ee.VF[5].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[3].y, this.ee.VF[2].z); - this.ee.VF[5].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[3].z, this.ee.VF[2].x); - this.ee.VF[5].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[3].x, this.ee.VF[2].y); - // @0012BA8C VOPMULA.xyz ACC, vf3, vf1 - this.ee.Vacc.x = (this.ee.VF[3].y * this.ee.VF[1].z); - this.ee.Vacc.y = (this.ee.VF[3].z * this.ee.VF[1].x); - this.ee.Vacc.z = (this.ee.VF[3].x * this.ee.VF[1].y); - // @0012BA90 VOPMSUB.xyz vf6, vf1, vf3 - this.ee.VF[6].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[1].y, this.ee.VF[3].z); - this.ee.VF[6].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[1].z, this.ee.VF[3].x); - this.ee.VF[6].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[1].x, this.ee.VF[3].y); - // @0012BA94 VOPMULA.xyz ACC, vf1, vf2 - this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); - this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); - this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); - // @0012BA98 VOPMSUB.xyz vf7, vf2, vf1 - this.ee.VF[7].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); - this.ee.VF[7].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); - this.ee.VF[7].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); - // @0012BA9C VMUL.xyz vf8, vf1, vf5 - this.ee.VF[8].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[5].x); - this.ee.VF[8].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[5].y); - this.ee.VF[8].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[5].z); - // @0012BAA0 VMUL.xyz vf1, vf4, vf5 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[5].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[5].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[5].z); - // @0012BAA4 VMUL.xyz vf2, vf4, vf6 - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[6].x); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[6].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[6].z); - // @0012BAA8 VMUL.xyz vf3, vf4, vf7 - this.ee.VF[3].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[7].x); - this.ee.VF[3].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[7].y); - this.ee.VF[3].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[7].z); - // @0012BAAC VADDy.x vf8, vf8, vf8y - this.ee.VF[8].x = (this.ee.VF[8].x + this.ee.VF[8].y); - // @0012BAB0 VADDy.x vf1, vf1, vf1y - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); - // @0012BAB4 VADDx.y vf2, vf2, vf2x - this.ee.VF[2].y = (this.ee.VF[2].y + this.ee.VF[2].x); - // @0012BAB8 VADDx.z vf3, vf3, vf3x - this.ee.VF[3].z = (this.ee.VF[3].z + this.ee.VF[3].x); - // @0012BABC VADDz.x vf8, vf8, vf8z - this.ee.VF[8].x = (this.ee.VF[8].x + this.ee.VF[8].z); - // @0012BAC0 VADDz.x vf4, vf1, vf1z - this.ee.VF[4].x = (this.ee.VF[1].x + this.ee.VF[1].z); - // @0012BAC4 VADDz.y vf4, vf2, vf2z - this.ee.VF[4].y = (this.ee.VF[2].y + this.ee.VF[2].z); - // @0012BAC8 VADDy.z vf4, vf3, vf3y - this.ee.VF[4].z = (this.ee.VF[3].z + this.ee.VF[3].y); - // @0012BACC VDIV Q, vf0w, vf8x - this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[8].x); - // @0012BAD0 QMFC2 t0, vf5 - MobUt.QMFC2(this.ee.t0, this.ee.VF[5]); - // @0012BAD4 QMFC2 t1, vf6 - MobUt.QMFC2(this.ee.t1, this.ee.VF[6]); - // @0012BAD8 QMFC2 t2, vf7 - MobUt.QMFC2(this.ee.t2, this.ee.VF[7]); - // @0012BADC QMFC2 t3, vf0 - MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); - // @0012BAE0 PEXTLW t4, t1, t0 - this.ee.t4.UL[0] = this.ee.t0.UL[0]; - this.ee.t4.UL[1] = this.ee.t1.UL[0]; - this.ee.t4.UL[2] = this.ee.t0.UL[1]; - this.ee.t4.UL[3] = this.ee.t1.UL[1]; - // @0012BAE4 PEXTUW t5, t1, t0 - this.ee.t5.UL[0] = this.ee.t0.UL[2]; - this.ee.t5.UL[1] = this.ee.t1.UL[2]; - this.ee.t5.UL[2] = this.ee.t0.UL[3]; - this.ee.t5.UL[3] = this.ee.t1.UL[3]; - // @0012BAE8 PEXTLW t6, t3, t2 - this.ee.t6.UL[0] = this.ee.t2.UL[0]; - this.ee.t6.UL[1] = this.ee.t3.UL[0]; - this.ee.t6.UL[2] = this.ee.t2.UL[1]; - this.ee.t6.UL[3] = this.ee.t3.UL[1]; - // @0012BAEC PEXTUW t7, t3, t2 - this.ee.t7.UL[0] = this.ee.t2.UL[2]; - this.ee.t7.UL[1] = this.ee.t3.UL[2]; - this.ee.t7.UL[2] = this.ee.t2.UL[3]; - this.ee.t7.UL[3] = this.ee.t3.UL[3]; - // @0012BAF0 PCPYLD t0, t6, t4 - this.ee.t0.UD1 = this.ee.t6.UD0; - this.ee.t0.UD0 = this.ee.t4.UD0; - // @0012BAF4 PCPYUD t1, t4, t6 - this.ee.t1.UD0 = this.ee.t4.UD1; - this.ee.t1.UD1 = this.ee.t6.UD1; - // @0012BAF8 PCPYLD t2, t7, t5 - this.ee.t2.UD1 = this.ee.t7.UD0; - this.ee.t2.UD0 = this.ee.t5.UD0; - // @0012BAFC QMTC2 t0, vf1 - MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); - // @0012BB00 QMTC2 t1, vf2 - MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); - // @0012BB04 QMTC2 t2, vf3 - MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); - // @0012BB08 VSUB.xyz vf4, vf0, vf4 - this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); - this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); - this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); - // @0012BB0C VWAITQ - MobUt.Latency(); - // @0012BB10 VMULq.xyzw vf1, vf1, Q - this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); - this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); - this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); - this.ee.VF[1].w = (this.ee.VF[1].w * this.ee.Vq.f); - // @0012BB14 VMULq.xyzw vf2, vf2, Q - this.ee.VF[2].x = (this.ee.VF[2].x * this.ee.Vq.f); - this.ee.VF[2].y = (this.ee.VF[2].y * this.ee.Vq.f); - this.ee.VF[2].z = (this.ee.VF[2].z * this.ee.Vq.f); - this.ee.VF[2].w = (this.ee.VF[2].w * this.ee.Vq.f); - // @0012BB18 VMULq.xyzw vf3, vf3, Q - this.ee.VF[3].x = (this.ee.VF[3].x * this.ee.Vq.f); - this.ee.VF[3].y = (this.ee.VF[3].y * this.ee.Vq.f); - this.ee.VF[3].z = (this.ee.VF[3].z * this.ee.Vq.f); - this.ee.VF[3].w = (this.ee.VF[3].w * this.ee.Vq.f); - // @0012BB1C VMULq.xyz vf4, vf4, Q - this.ee.VF[4].x = (this.ee.VF[4].x * this.ee.Vq.f); - this.ee.VF[4].y = (this.ee.VF[4].y * this.ee.Vq.f); - this.ee.VF[4].z = (this.ee.VF[4].z * this.ee.Vq.f); - // @0012BB20 SQC2 vf1, $0000(a1) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); - // @0012BB24 SQC2 vf2, $0010(a1) - MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); - // @0012BB28 SQC2 vf3, $0020(a1) - MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); - // @0012BB2C SQC2 vf4, $0030(a1) - MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012BB30 LUI t7, $0004 - this.ee.t7.SD0 = 262144; - // @0012BB34 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @0012BB38 BEQ t7, zero, $0012c738 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230648u; - } - // @0012BB3C ADDIU t7, zero, $ffff - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); - } - - public virtual void funct0012bb34() - { - this.ee.pc = 1227584u; - // @0012BB34 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @0012BB38 BEQ t7, zero, $0012c738 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230648u; - } - // @0012BB3C ADDIU t7, zero, $ffff - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); - } - - public virtual void funct0012bb40() - { - this.ee.pc = 1227604u; - // @0012BB40 LW t6, $0004(s0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); - // @0012BB44 LHU t6, $0010(t6) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); - // @0012BB48 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012BB4C BEQ t7, zero, $0012c720 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230624u; - } - // @0012BB50 ADDIU t5, sp, $0080 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); - } - - public virtual void funct0012bb54() - { - this.ee.pc = 1227628u; - // @0012BB54 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012BB58 SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - // @0012BB5C ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012BB60 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012BB64 BEQL t5, t6, $0012bb78 - if ((this.ee.t5.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1227640u; - // @0012BB68 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - } - } - - public virtual void funct0012bb60() - { - this.ee.pc = 1227628u; - // @0012BB60 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012BB64 BEQL t5, t6, $0012bb78 - if ((this.ee.t5.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1227640u; - // @0012BB68 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - } - } - - public virtual void funct0012bb6c() - { - this.ee.pc = 1227712u; - // @0012BB6C LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012BB70 SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012BB74 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @0012BB78 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012BB7C ADDIU t6, t6, $8364 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -31900))); - // @0012BB80 ADDIU t4, sp, $0090 - this.ee.t4.SD0 = ((int)((this.ee.sp.SD0 + 144))); - // @0012BB84 LWC1 $f0, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @0012BB88 ADDIU t7, sp, $0040 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); - // @0012BB8C SWC1 $f0, $008c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (140u + this.ee.sp.UL0)); - // @0012BB90 LQC2 vf5, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); - // @0012BB94 LQC2 vf1, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t7.UL0)); - // @0012BB98 LQC2 vf2, $0010(t7) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t7.UL0)); - // @0012BB9C LQC2 vf3, $0020(t7) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t7.UL0)); - // @0012BBA0 LQC2 vf4, $0030(t7) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t7.UL0)); - // @0012BBA4 VMULAx.xyzw ACC, vf1, vf5x - // @0012BBA8 VMADDAy.xyzw ACC, vf2, vf5y - // @0012BBAC VMADDAz.xyzw ACC, vf3, vf5z - // @0012BBB0 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012BBB4 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012BBB8 BEQL t4, t8, $0012bbcc - if ((this.ee.t4.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1227724u; - // @0012BBBC SWC1 $f0, $009c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); - } - } - - public virtual void funct0012bbc0() - { - this.ee.pc = 1227736u; - // @0012BBC0 LQ t0, $0000(t8) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); - // @0012BBC4 SQ t0, $0000(t4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); - // @0012BBC8 SWC1 $f0, $009c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); - // @0012BBCC LW t5, $0218(sp) - MobUt.LW(this.ee, this.ee.t5, (536u + this.ee.sp.UL0)); - // @0012BBD0 BEQ t5, zero, $0012c3e4 - if ((this.ee.t5.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229796u; - } - // @0012BBD4 ADDIU t7, zero, $0003 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 3))); - } - - public virtual void funct0012bbcc() - { - this.ee.pc = 1227736u; - // @0012BBCC LW t5, $0218(sp) - MobUt.LW(this.ee, this.ee.t5, (536u + this.ee.sp.UL0)); - // @0012BBD0 BEQ t5, zero, $0012c3e4 - if ((this.ee.t5.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229796u; - } - // @0012BBD4 ADDIU t7, zero, $0003 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 3))); - } - - public virtual void funct0012bbd8() - { - this.ee.pc = 1227752u; - // @0012BBD8 LBU t6, $0000(t5) - MobUt.LBU(this.ee, this.ee.t6, (0u + this.ee.t5.UL0)); - // @0012BBDC ANDI t5, t6, $00ff - this.ee.t5.UD0 = ((ushort)((this.ee.t6.US0 & 255))); - // @0012BBE0 BEQ t5, t7, $0012bf98 - if ((this.ee.t5.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1228696u; - } - // @0012BBE4 SLTI t7, t5, $0004 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < 4)); - } - - public virtual void funct0012bbe8() - { - this.ee.pc = 1227760u; - // @0012BBE8 BEQ t7, zero, $0012bf8c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228684u; - } - // @0012BBEC ADDIU t7, zero, $0002 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); - } - - public virtual void funct0012bbf0() - { - this.ee.pc = 1227768u; - // @0012BBF0 BEQ t5, t7, $0012bf48 - if ((this.ee.t5.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1228616u; - } - // @0012BBF4 LW t6, $0218(sp) - MobUt.LW(this.ee, this.ee.t6, (536u + this.ee.sp.UL0)); - } - - public virtual void funct0012bbfc() - { - this.ee.pc = 1227792u; - // @0012BBFC LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012BC00 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012BC04 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012BC08 BEQ t7, zero, $0012bf38 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228600u; - } - // @0012BC0C SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012bc10() - { - this.ee.pc = 1227812u; - // @0012BC10 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012BC14 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012BC18 ADDU t5, t5, s3 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s3.SD0))); - // @0012BC1C BEQL t6, t5, $0012bc4c - if ((this.ee.t6.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1227852u; - // @0012BC20 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012bc18() - { - this.ee.pc = 1227812u; - // @0012BC18 ADDU t5, t5, s3 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s3.SD0))); - // @0012BC1C BEQL t6, t5, $0012bc4c - if ((this.ee.t6.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1227852u; - // @0012BC20 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012bc24() - { - this.ee.pc = 1227864u; - // @0012BC24 LQ t0, $0000(t5) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012BC28 LQ t1, $0010(t5) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); - // @0012BC2C LQ t2, $0020(t5) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); - // @0012BC30 LQ t3, $0030(t5) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); - // @0012BC34 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012BC38 SQ t1, $0010(t6) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); - // @0012BC3C SQ t2, $0020(t6) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); - // @0012BC40 SQ t3, $0030(t6) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); - // @0012BC44 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012BC48 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012BC4C SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012BC50 BEQ t7, zero, $0012bf28 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228584u; - } - // @0012BC54 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012bc58() - { - this.ee.pc = 1227940u; - // @0012BC58 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012BC5C ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012BC60 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @0012BC64 ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012BC68 LQC2 vf4, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); - // @0012BC6C LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012BC70 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012BC74 LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012BC78 VMULx.xyzw vf1, vf1, vf4x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); - // @0012BC7C VMULy.xyzw vf2, vf2, vf4y - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); - this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); - // @0012BC80 VMULz.xyzw vf3, vf3, vf4z - this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); - this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); - // @0012BC84 SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012BC88 SQC2 vf2, $0010(t6) - MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012BC8C SQC2 vf3, $0020(t6) - MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012BC90 LW t6, $0004(s0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); - // @0012BC94 LHU t6, $0010(t6) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); - // @0012BC98 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012BC9C BEQ t7, zero, $0012bf18 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228568u; - } - // @0012BCA0 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012bc60() - { - this.ee.pc = 1227940u; - // @0012BC60 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @0012BC64 ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012BC68 LQC2 vf4, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); - // @0012BC6C LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012BC70 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012BC74 LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012BC78 VMULx.xyzw vf1, vf1, vf4x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); - // @0012BC7C VMULy.xyzw vf2, vf2, vf4y - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); - this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); - // @0012BC80 VMULz.xyzw vf3, vf3, vf4z - this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); - this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); - // @0012BC84 SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012BC88 SQC2 vf2, $0010(t6) - MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012BC8C SQC2 vf3, $0020(t6) - MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012BC90 LW t6, $0004(s0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); - // @0012BC94 LHU t6, $0010(t6) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); - // @0012BC98 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012BC9C BEQ t7, zero, $0012bf18 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228568u; - } - // @0012BCA0 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012bca4() - { - this.ee.pc = 1227964u; - // @0012BCA4 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012BCA8 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012BCAC ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012BCB0 ADDIU t7, sp, $0080 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012BCB4 BEQ t6, t7, $0012bcc8 - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1227976u; - } - // @0012BCB8 LW t3, $0218(sp) - MobUt.LW(this.ee, this.ee.t3, (536u + this.ee.sp.UL0)); - } - - public virtual void funct0012bcac() - { - this.ee.pc = 1227964u; - // @0012BCAC ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012BCB0 ADDIU t7, sp, $0080 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012BCB4 BEQ t6, t7, $0012bcc8 - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1227976u; - } - // @0012BCB8 LW t3, $0218(sp) - MobUt.LW(this.ee, this.ee.t3, (536u + this.ee.sp.UL0)); - } - - public virtual void funct0012bcbc() - { - this.ee.pc = 1227984u; - // @0012BCBC LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012BCC0 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012BCC4 LW t3, $0218(sp) - MobUt.LW(this.ee, this.ee.t3, (536u + this.ee.sp.UL0)); - // @0012BCC8 BNE t3, zero, $0012bce0 - if ((this.ee.t3.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1228000u; - } - // @0012BCCC LW t4, $0214(sp) - MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); - } - - public virtual void funct0012bcd0() - { - this.ee.pc = 1228000u; - // @0012BCD0 LUI t7, $0008 - this.ee.t7.SD0 = 524288; - // @0012BCD4 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @0012BCD8 BEQ t7, zero, $00129e60 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220192u; - } - // @0012BCDC LW t3, $01f4(sp) - MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); - } - - public virtual void funct0012bce0() - { - this.ee.pc = 1228008u; - // @0012BCE0 BGEZ t4, $0012bed8 - if ((this.ee.t4.SD0 >= 0)) - { - this.ee.pc = 1228504u; - } - // @0012BCE4 LW t5, $0214(sp) - MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); - } - - public virtual void funct0012bce8() - { - this.ee.pc = 1228020u; - // @0012BCE8 ADDIU a1, sp, $0040 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 64))); - // @0012BCEC BEQ a1, sp, $0012bd14 - if ((this.ee.a1.UD0 == this.ee.sp.UD0)) - { - this.ee.pc = 1228052u; - } - // @0012BCF0 NOP - MobUt.Latency(); - } - - public virtual void funct0012bcf4() - { - this.ee.pc = 1228164u; - // @0012BCF4 LQ t0, $0000(sp) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); - // @0012BCF8 LQ t1, $0010(sp) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.sp.UL[0])); - // @0012BCFC LQ t2, $0020(sp) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.sp.UL[0])); - // @0012BD00 LQ t3, $0030(sp) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.sp.UL[0])); - // @0012BD04 SQ t0, $0000(a1) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @0012BD08 SQ t1, $0010(a1) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); - // @0012BD0C SQ t2, $0020(a1) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); - // @0012BD10 SQ t3, $0030(a1) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.a1.UL[0])); - // @0012BD14 LQ t0, $0000(a1) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @0012BD18 LQ t1, $0010(a1) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); - // @0012BD1C LQ t2, $0020(a1) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); - // @0012BD20 QMFC2 t3, vf0 - MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); - // @0012BD24 LQC2 vf4, $0030(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012BD28 PEXTLW t4, t1, t0 - this.ee.t4.UL[0] = this.ee.t0.UL[0]; - this.ee.t4.UL[1] = this.ee.t1.UL[0]; - this.ee.t4.UL[2] = this.ee.t0.UL[1]; - this.ee.t4.UL[3] = this.ee.t1.UL[1]; - // @0012BD2C PEXTUW t5, t1, t0 - this.ee.t5.UL[0] = this.ee.t0.UL[2]; - this.ee.t5.UL[1] = this.ee.t1.UL[2]; - this.ee.t5.UL[2] = this.ee.t0.UL[3]; - this.ee.t5.UL[3] = this.ee.t1.UL[3]; - // @0012BD30 PEXTLW t6, t3, t2 - this.ee.t6.UL[0] = this.ee.t2.UL[0]; - this.ee.t6.UL[1] = this.ee.t3.UL[0]; - this.ee.t6.UL[2] = this.ee.t2.UL[1]; - this.ee.t6.UL[3] = this.ee.t3.UL[1]; - // @0012BD34 PEXTUW t7, t3, t2 - this.ee.t7.UL[0] = this.ee.t2.UL[2]; - this.ee.t7.UL[1] = this.ee.t3.UL[2]; - this.ee.t7.UL[2] = this.ee.t2.UL[3]; - this.ee.t7.UL[3] = this.ee.t3.UL[3]; - // @0012BD38 PCPYLD t0, t6, t4 - this.ee.t0.UD1 = this.ee.t6.UD0; - this.ee.t0.UD0 = this.ee.t4.UD0; - // @0012BD3C PCPYUD t1, t4, t6 - this.ee.t1.UD0 = this.ee.t4.UD1; - this.ee.t1.UD1 = this.ee.t6.UD1; - // @0012BD40 PCPYLD t2, t7, t5 - this.ee.t2.UD1 = this.ee.t7.UD0; - this.ee.t2.UD0 = this.ee.t5.UD0; - // @0012BD44 QMTC2 t0, vf1 - MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); - // @0012BD48 QMTC2 t1, vf2 - MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); - // @0012BD4C QMTC2 t2, vf3 - MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); - // @0012BD50 VMULAx.xyz ACC, vf1, vf4x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[4].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[4].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[4].x); - // @0012BD54 VMADDAy.xyz ACC, vf2, vf4y - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[4].y); - // @0012BD58 VMADDz.xyz vf4, vf3, vf4z - this.ee.VF[4].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[4].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[4].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[4].z); - // @0012BD5C VSUB.xyz vf4, vf0, vf4 - this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); - this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); - this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); - // @0012BD60 SQ t0, $0000(a1) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @0012BD64 SQ t1, $0010(a1) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); - // @0012BD68 SQ t2, $0020(a1) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); - // @0012BD6C SQC2 vf4, $0030(a1) - MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012BD70 LW a3, $0004(s0) - MobUt.LW(this.ee, this.ee.a3, (4u + this.ee.s0.UL0)); - // @0012BD74 LHU t6, $0010(a3) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.a3.UL0)); - // @0012BD78 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012BD7C BEQ t7, zero, $0012bec8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228488u; - } - // @0012BD80 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012bd14() - { - this.ee.pc = 1228164u; - // @0012BD14 LQ t0, $0000(a1) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @0012BD18 LQ t1, $0010(a1) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); - // @0012BD1C LQ t2, $0020(a1) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); - // @0012BD20 QMFC2 t3, vf0 - MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); - // @0012BD24 LQC2 vf4, $0030(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012BD28 PEXTLW t4, t1, t0 - this.ee.t4.UL[0] = this.ee.t0.UL[0]; - this.ee.t4.UL[1] = this.ee.t1.UL[0]; - this.ee.t4.UL[2] = this.ee.t0.UL[1]; - this.ee.t4.UL[3] = this.ee.t1.UL[1]; - // @0012BD2C PEXTUW t5, t1, t0 - this.ee.t5.UL[0] = this.ee.t0.UL[2]; - this.ee.t5.UL[1] = this.ee.t1.UL[2]; - this.ee.t5.UL[2] = this.ee.t0.UL[3]; - this.ee.t5.UL[3] = this.ee.t1.UL[3]; - // @0012BD30 PEXTLW t6, t3, t2 - this.ee.t6.UL[0] = this.ee.t2.UL[0]; - this.ee.t6.UL[1] = this.ee.t3.UL[0]; - this.ee.t6.UL[2] = this.ee.t2.UL[1]; - this.ee.t6.UL[3] = this.ee.t3.UL[1]; - // @0012BD34 PEXTUW t7, t3, t2 - this.ee.t7.UL[0] = this.ee.t2.UL[2]; - this.ee.t7.UL[1] = this.ee.t3.UL[2]; - this.ee.t7.UL[2] = this.ee.t2.UL[3]; - this.ee.t7.UL[3] = this.ee.t3.UL[3]; - // @0012BD38 PCPYLD t0, t6, t4 - this.ee.t0.UD1 = this.ee.t6.UD0; - this.ee.t0.UD0 = this.ee.t4.UD0; - // @0012BD3C PCPYUD t1, t4, t6 - this.ee.t1.UD0 = this.ee.t4.UD1; - this.ee.t1.UD1 = this.ee.t6.UD1; - // @0012BD40 PCPYLD t2, t7, t5 - this.ee.t2.UD1 = this.ee.t7.UD0; - this.ee.t2.UD0 = this.ee.t5.UD0; - // @0012BD44 QMTC2 t0, vf1 - MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); - // @0012BD48 QMTC2 t1, vf2 - MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); - // @0012BD4C QMTC2 t2, vf3 - MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); - // @0012BD50 VMULAx.xyz ACC, vf1, vf4x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[4].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[4].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[4].x); - // @0012BD54 VMADDAy.xyz ACC, vf2, vf4y - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[4].y); - // @0012BD58 VMADDz.xyz vf4, vf3, vf4z - this.ee.VF[4].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[4].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[4].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[4].z); - // @0012BD5C VSUB.xyz vf4, vf0, vf4 - this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); - this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); - this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); - // @0012BD60 SQ t0, $0000(a1) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @0012BD64 SQ t1, $0010(a1) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); - // @0012BD68 SQ t2, $0020(a1) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); - // @0012BD6C SQC2 vf4, $0030(a1) - MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012BD70 LW a3, $0004(s0) - MobUt.LW(this.ee, this.ee.a3, (4u + this.ee.s0.UL0)); - // @0012BD74 LHU t6, $0010(a3) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.a3.UL0)); - // @0012BD78 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012BD7C BEQ t7, zero, $0012bec8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228488u; - } - // @0012BD80 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012bd84() - { - this.ee.pc = 1228304u; - // @0012BD84 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012BD88 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012BD8C LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - // @0012BD90 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012BD94 ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012BD98 LQC2 vf1, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); - // @0012BD9C LQC2 vf2, $0010(a1) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); - // @0012BDA0 LQC2 vf3, $0020(a1) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); - // @0012BDA4 LQC2 vf4, $0030(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012BDA8 LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012BDAC LQC2 vf6, $0010(t7) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); - // @0012BDB0 LQC2 vf7, $0020(t7) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); - // @0012BDB4 LQC2 vf8, $0030(t7) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); - // @0012BDB8 VMULAx.xyzw ACC, vf1, vf5x - // @0012BDBC VMADDAy.xyzw ACC, vf2, vf5y - // @0012BDC0 VMADDAz.xyzw ACC, vf3, vf5z - // @0012BDC4 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012BDC8 VMULAx.xyzw ACC, vf1, vf6x - // @0012BDCC VMADDAy.xyzw ACC, vf2, vf6y - // @0012BDD0 VMADDAz.xyzw ACC, vf3, vf6z - // @0012BDD4 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012BDD8 VMULAx.xyzw ACC, vf1, vf7x - // @0012BDDC VMADDAy.xyzw ACC, vf2, vf7y - // @0012BDE0 VMADDAz.xyzw ACC, vf3, vf7z - // @0012BDE4 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012BDE8 VMULAx.xyzw ACC, vf1, vf8x - // @0012BDEC VMADDAy.xyzw ACC, vf2, vf8y - // @0012BDF0 VMADDAz.xyzw ACC, vf3, vf8z - // @0012BDF4 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012BDF8 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012BDFC SQC2 vf6, $0010(t8) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); - // @0012BE00 SQC2 vf7, $0020(t8) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); - // @0012BE04 SQC2 vf8, $0030(t8) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); - // @0012BE08 BEQL t6, t8, $0012be34 - if ((this.ee.t6.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1228340u; - // @0012BE0C LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012bd8c() - { - this.ee.pc = 1228304u; - // @0012BD8C LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - // @0012BD90 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012BD94 ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012BD98 LQC2 vf1, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); - // @0012BD9C LQC2 vf2, $0010(a1) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); - // @0012BDA0 LQC2 vf3, $0020(a1) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); - // @0012BDA4 LQC2 vf4, $0030(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); - // @0012BDA8 LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012BDAC LQC2 vf6, $0010(t7) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); - // @0012BDB0 LQC2 vf7, $0020(t7) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); - // @0012BDB4 LQC2 vf8, $0030(t7) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); - // @0012BDB8 VMULAx.xyzw ACC, vf1, vf5x - // @0012BDBC VMADDAy.xyzw ACC, vf2, vf5y - // @0012BDC0 VMADDAz.xyzw ACC, vf3, vf5z - // @0012BDC4 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012BDC8 VMULAx.xyzw ACC, vf1, vf6x - // @0012BDCC VMADDAy.xyzw ACC, vf2, vf6y - // @0012BDD0 VMADDAz.xyzw ACC, vf3, vf6z - // @0012BDD4 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012BDD8 VMULAx.xyzw ACC, vf1, vf7x - // @0012BDDC VMADDAy.xyzw ACC, vf2, vf7y - // @0012BDE0 VMADDAz.xyzw ACC, vf3, vf7z - // @0012BDE4 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012BDE8 VMULAx.xyzw ACC, vf1, vf8x - // @0012BDEC VMADDAy.xyzw ACC, vf2, vf8y - // @0012BDF0 VMADDAz.xyzw ACC, vf3, vf8z - // @0012BDF4 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012BDF8 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012BDFC SQC2 vf6, $0010(t8) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); - // @0012BE00 SQC2 vf7, $0020(t8) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); - // @0012BE04 SQC2 vf8, $0030(t8) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); - // @0012BE08 BEQL t6, t8, $0012be34 - if ((this.ee.t6.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1228340u; - // @0012BE0C LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012be10() - { - this.ee.pc = 1228356u; - // @0012BE10 LQ t0, $0000(t8) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); - // @0012BE14 LQ t1, $0010(t8) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t8.UL[0])); - // @0012BE18 LQ t2, $0020(t8) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t8.UL[0])); - // @0012BE1C LQ t3, $0030(t8) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t8.UL[0])); - // @0012BE20 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012BE24 SQ t1, $0010(t6) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); - // @0012BE28 SQ t2, $0020(t6) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); - // @0012BE2C SQ t3, $0030(t6) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); - // @0012BE30 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012BE34 LHU t7, $0010(t7) - MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); - // @0012BE38 SLT t6, s2, t7 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); - // @0012BE3C BEQ t6, zero, $0012beb8 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228472u; - } - // @0012BE40 SUBU t7, s2, t7 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); - } - - public virtual void funct0012be44() - { - this.ee.pc = 1228380u; - // @0012BE44 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012BE48 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012BE4C ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012BE50 ADDIU t7, sp, $0090 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 144))); - // @0012BE54 BEQL t6, t7, $0012be68 - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1228392u; - // @0012BE58 LUI t7, $0040 - this.ee.t7.SD0 = 4194304; - } - } - - public virtual void funct0012be4c() - { - this.ee.pc = 1228380u; - // @0012BE4C ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012BE50 ADDIU t7, sp, $0090 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 144))); - // @0012BE54 BEQL t6, t7, $0012be68 - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1228392u; - // @0012BE58 LUI t7, $0040 - this.ee.t7.SD0 = 4194304; - } - } - - public virtual void funct0012be5c() - { - this.ee.pc = 1228404u; - // @0012BE5C LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012BE60 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012BE64 LUI t7, $0040 - this.ee.t7.SD0 = 4194304; - // @0012BE68 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @0012BE6C BEQ t7, zero, $00129e60 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220192u; - } - // @0012BE70 LW t3, $01f4(sp) - MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); - } - - public virtual void funct0012be74() - { - this.ee.pc = 1228424u; - // @0012BE74 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012BE78 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012BE7C SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012BE80 BEQ t7, zero, $0012bea8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228456u; - } - // @0012BE84 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012be88() - { - this.ee.pc = 1228448u; - // @0012BE88 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012BE8C ADDU a0, t7, s3 - this.ee.a0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012BE90 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012BE94 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012BE98 BEQL t7, zero, $00129e40 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220160u; - // @0012BE9C LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012be90() - { - this.ee.pc = 1228448u; - // @0012BE90 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012BE94 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012BE98 BEQL t7, zero, $00129e40 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220160u; - // @0012BE9C LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012bea0() - { - this.ee.pc = 1228456u; - // @0012BEA0 BEQ zero, zero, $0012a9b4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1223092u; - } - // @0012BEA4 LW t7, $0020(s5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); - } - - public virtual void funct0012bea8() - { - this.ee.pc = 1228472u; - // @0012BEA8 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012BEAC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012BEB0 BEQ zero, zero, $0012be90 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228432u; - } - // @0012BEB4 ADDU a0, t6, t7 - this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012beb8() - { - this.ee.pc = 1228488u; - // @0012BEB8 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012BEBC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012BEC0 BEQ zero, zero, $0012be4c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228364u; - } - // @0012BEC4 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012bec8() - { - this.ee.pc = 1228504u; - // @0012BEC8 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012BECC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012BED0 BEQ zero, zero, $0012bd8c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228172u; - } - // @0012BED4 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012bed8() - { - this.ee.pc = 1228528u; - // @0012BED8 ADDIU a1, sp, $0040 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 64))); - // @0012BEDC LW t6, $0008(s0) - MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); - // @0012BEE0 SLL t7, t5, 6 - MobUt.SLL(this.ee.t7, this.ee.t5, 6); - // @0012BEE4 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012BEE8 BEQ a1, t6, $0012bd14 - if ((this.ee.a1.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1228052u; - } - // @0012BEEC NOP - MobUt.Latency(); - } - - public virtual void funct0012bef0() - { - this.ee.pc = 1228568u; - // @0012BEF0 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012BEF4 LQ t1, $0010(t6) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); - // @0012BEF8 LQ t2, $0020(t6) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); - // @0012BEFC LQ t3, $0030(t6) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); - // @0012BF00 SQ t0, $0000(a1) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @0012BF04 SQ t1, $0010(a1) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); - // @0012BF08 SQ t2, $0020(a1) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); - // @0012BF0C SQ t3, $0030(a1) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.a1.UL[0])); - // @0012BF10 BEQ zero, zero, $0012bd14 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228052u; - } - // @0012BF14 NOP - MobUt.Latency(); - } - - public virtual void funct0012bf18() - { - this.ee.pc = 1228584u; - // @0012BF18 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012BF1C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012BF20 BEQ zero, zero, $0012bcac - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227948u; - } - // @0012BF24 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012bf28() - { - this.ee.pc = 1228600u; - // @0012BF28 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012BF2C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012BF30 BEQ zero, zero, $0012bc60 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227872u; - } - // @0012BF34 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012bf38() - { - this.ee.pc = 1228616u; - // @0012BF38 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012BF3C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012BF40 BEQ zero, zero, $0012bc18 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227800u; - } - // @0012BF44 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012bf48() - { - this.ee.pc = 1228644u; - // @0012BF48 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - // @0012BF4C LHU t7, $0004(t6) - MobUt.LHU(this.ee, this.ee.t7, (4u + this.ee.t6.UL0)); - // @0012BF50 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012BF54 ADDU t6, t5, t7 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t7.SD0))); - // @0012BF58 ADDU t7, t5, s3 - this.ee.t7.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s3.SD0))); - // @0012BF5C BEQL t7, t6, $0012bc00 - if ((this.ee.t7.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1227776u; - // @0012BF60 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012bf64() - { - this.ee.pc = 1228684u; - // @0012BF64 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012BF68 LQ t1, $0010(t6) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); - // @0012BF6C LQ t2, $0020(t6) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); - // @0012BF70 LQ t3, $0030(t6) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); - // @0012BF74 SQ t0, $0000(t7) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012BF78 SQ t1, $0010(t7) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); - // @0012BF7C SQ t2, $0020(t7) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); - // @0012BF80 SQ t3, $0030(t7) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); - // @0012BF84 BEQ zero, zero, $0012bbfc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227772u; - } - // @0012BF88 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - } - - public virtual void funct0012bf8c() - { - this.ee.pc = 1228696u; - // @0012BF8C ADDIU t7, zero, $0005 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 5))); - // @0012BF90 BNEL t5, t7, $0012bbfc - if ((this.ee.t5.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1227772u; - // @0012BF94 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012bf98() - { - this.ee.pc = 1228712u; - // @0012BF98 ANDI t6, t6, $00ff - this.ee.t6.UD0 = ((ushort)((this.ee.t6.US0 & 255))); - // @0012BF9C ADDIU t7, zero, $0003 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 3))); - // @0012BFA0 BNE t6, t7, $0012c3dc - if ((this.ee.t6.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1229788u; - } - // @0012BFA4 LW t3, $0218(sp) - MobUt.LW(this.ee, this.ee.t3, (536u + this.ee.sp.UL0)); - } - - public virtual void funct0012bfa8() - { - this.ee.pc = 1228744u; - // @0012BFA8 LW t7, $0218(sp) - MobUt.LW(this.ee, this.ee.t7, (536u + this.ee.sp.UL0)); - // @0012BFAC LHU t5, $0004(t7) - MobUt.LHU(this.ee, this.ee.t5, (4u + this.ee.t7.UL0)); - // @0012BFB0 LW t6, $0004(s0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); - // @0012BFB4 ADDIU t4, sp, $00b0 - this.ee.t4.SD0 = ((int)((this.ee.sp.SD0 + 176))); - // @0012BFB8 LHU t6, $0010(t6) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); - // @0012BFBC SLT t7, t5, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); - // @0012BFC0 BEQ t7, zero, $0012c3cc - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229772u; - } - // @0012BFC4 ADDIU t3, sp, $0040 - this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 64))); - } - - public virtual void funct0012bfd0() - { - this.ee.pc = 1228812u; - // @0012BFD0 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012BFD4 ADDIU s7, sp, $0180 - this.ee.s7.SD0 = ((int)((this.ee.sp.SD0 + 384))); - // @0012BFD8 ADDIU t7, t6, $0030 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012BFDC LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012BFE0 LQC2 vf1, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); - // @0012BFE4 LQC2 vf2, $0010(t3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); - // @0012BFE8 LQC2 vf3, $0020(t3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); - // @0012BFEC LQC2 vf4, $0030(t3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); - // @0012BFF0 VMULAx.xyzw ACC, vf1, vf5x - // @0012BFF4 VMADDAy.xyzw ACC, vf2, vf5y - // @0012BFF8 VMADDAz.xyzw ACC, vf3, vf5z - // @0012BFFC VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C000 SQC2 vf5, $0000(s7) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s7.UL0)); - // @0012C004 BEQ t4, s7, $0012c018 - if ((this.ee.t4.UD0 == this.ee.s7.UD0)) - { - this.ee.pc = 1228824u; - } - // @0012C008 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - } - - public virtual void funct0012c00c() - { - this.ee.pc = 1228856u; - // @0012C00C LQ t0, $0000(s7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s7.UL[0])); - // @0012C010 SQ t0, $0000(t4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); - // @0012C014 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012C018 ADDIU t5, sp, $0090 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 144))); - // @0012C01C DADDU a0, t8, zero - this.ee.a0.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); - // @0012C020 LQC2 vf1, $0000(t4) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); - // @0012C024 LQC2 vf2, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t5.UL0)); - // @0012C028 VSUB.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); - // @0012C02C SQC2 vf1, $0000(s7) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s7.UL0)); - // @0012C030 BEQ t8, s7, $0012c044 - if ((this.ee.t8.UD0 == this.ee.s7.UD0)) - { - this.ee.pc = 1228868u; - } - // @0012C034 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - } - - public virtual void funct0012c038() - { - this.ee.pc = 1228908u; - // @0012C038 LQ t0, $0000(s7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s7.UL[0])); - // @0012C03C SQ t0, $0000(t8) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); - // @0012C040 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @0012C044 SW zero, $0130(sp) - MobUt.SW(this.ee, this.ee.r0, (304u + this.ee.sp.UL0)); - // @0012C048 ADDIU t6, t6, $8364 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -31900))); - // @0012C04C SW zero, $0138(sp) - MobUt.SW(this.ee, this.ee.r0, (312u + this.ee.sp.UL0)); - // @0012C050 LWC1 $f0, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @0012C054 SWC1 $f0, $0134(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (308u + this.ee.sp.UL0)); - // @0012C058 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012C05C LHU t7, $0010(t7) - MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); - // @0012C060 SLT t6, s2, t7 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); - // @0012C064 BEQ t6, zero, $0012c3bc - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229756u; - } - // @0012C068 SUBU t7, s2, t7 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); - } - - public virtual void funct0012c06c() - { - this.ee.pc = 1228924u; - // @0012C06C LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012C070 ADDU a2, t7, s3 - this.ee.a2.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012C074 JAL $00128b20 - this.ee.ra.UL0 = 1228924u; - this.ee.pc = 1215264u; - // @0012C078 ADDIU a1, sp, $0130 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 304))); - } - - public virtual void funct0012c074() - { - this.ee.pc = 1228924u; - // @0012C074 JAL $00128b20 - this.ee.ra.UL0 = 1228924u; - this.ee.pc = 1215264u; - // @0012C078 ADDIU a1, sp, $0130 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 304))); - } - - public virtual void funct0012c07c() - { - this.ee.pc = 1228932u; - // @0012C07C JAL $0011b420 - this.ee.ra.UL0 = 1228932u; - this.ee.pc = 1160224u; - // @0012C080 ADDIU a0, sp, $0140 - this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 320))); - } - - public virtual void funct0012c084() - { - this.ee.pc = 1228952u; - // @0012C084 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @0012C088 LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @0012C08C SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @0012C090 BEQL t7, zero, $0012c3a4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229732u; - // @0012C094 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct0012c098() - { - this.ee.pc = 1228972u; - // @0012C098 LW t7, $0020(s5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); - // @0012C09C ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012C0A0 LWC1 $f12, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[12], (0u + this.ee.t6.UL0)); - // @0012C0A4 JAL $0011b450 - this.ee.ra.UL0 = 1228972u; - this.ee.pc = 1160272u; - // @0012C0A8 ADDIU a0, sp, $0140 - this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 320))); - } - - public virtual void funct0012c0a0() - { - this.ee.pc = 1228972u; - // @0012C0A0 LWC1 $f12, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[12], (0u + this.ee.t6.UL0)); - // @0012C0A4 JAL $0011b450 - this.ee.ra.UL0 = 1228972u; - this.ee.pc = 1160272u; - // @0012C0A8 ADDIU a0, sp, $0140 - this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 320))); - } - - public virtual void funct0012c0ac() - { - this.ee.pc = 1228992u; - // @0012C0AC LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012C0B0 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012C0B4 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012C0B8 BEQ t7, zero, $0012c390 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229712u; - } - // @0012C0BC DADDU t5, t4, zero - this.ee.t5.UD0 = (this.ee.t4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012c0c0() - { - this.ee.pc = 1229016u; - // @0012C0C0 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012C0C4 ADDU t4, t7, s3 - this.ee.t4.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012C0C8 LHU t6, $0010(t5) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t5.UL0)); - // @0012C0CC SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012C0D0 BEQ t7, zero, $0012c380 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229696u; - } - // @0012C0D4 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012c0c8() - { - this.ee.pc = 1229016u; - // @0012C0C8 LHU t6, $0010(t5) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t5.UL0)); - // @0012C0CC SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012C0D0 BEQ t7, zero, $0012c380 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229696u; - } - // @0012C0D4 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012c0d8() - { - this.ee.pc = 1229152u; - // @0012C0D8 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012C0DC ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012C0E0 ADDIU t5, sp, $01b0 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 432))); - // @0012C0E4 ADDIU t7, sp, $0140 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 320))); - // @0012C0E8 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012C0EC LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012C0F0 LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012C0F4 LQC2 vf4, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); - // @0012C0F8 LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012C0FC LQC2 vf6, $0010(t7) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); - // @0012C100 LQC2 vf7, $0020(t7) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); - // @0012C104 LQC2 vf8, $0030(t7) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); - // @0012C108 VMULAx.xyzw ACC, vf1, vf5x - // @0012C10C VMADDAy.xyzw ACC, vf2, vf5y - // @0012C110 VMADDAz.xyzw ACC, vf3, vf5z - // @0012C114 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C118 VMULAx.xyzw ACC, vf1, vf6x - // @0012C11C VMADDAy.xyzw ACC, vf2, vf6y - // @0012C120 VMADDAz.xyzw ACC, vf3, vf6z - // @0012C124 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012C128 VMULAx.xyzw ACC, vf1, vf7x - // @0012C12C VMADDAy.xyzw ACC, vf2, vf7y - // @0012C130 VMADDAz.xyzw ACC, vf3, vf7z - // @0012C134 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012C138 VMULAx.xyzw ACC, vf1, vf8x - // @0012C13C VMADDAy.xyzw ACC, vf2, vf8y - // @0012C140 VMADDAz.xyzw ACC, vf3, vf8z - // @0012C144 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012C148 SQC2 vf5, $0000(t5) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); - // @0012C14C SQC2 vf6, $0010(t5) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t5.UL0)); - // @0012C150 SQC2 vf7, $0020(t5) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t5.UL0)); - // @0012C154 SQC2 vf8, $0030(t5) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t5.UL0)); - // @0012C158 BEQL t4, t5, $0012c184 - if ((this.ee.t4.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1229188u; - // @0012C15C LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012c0e0() - { - this.ee.pc = 1229152u; - // @0012C0E0 ADDIU t5, sp, $01b0 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 432))); - // @0012C0E4 ADDIU t7, sp, $0140 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 320))); - // @0012C0E8 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012C0EC LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012C0F0 LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012C0F4 LQC2 vf4, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); - // @0012C0F8 LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012C0FC LQC2 vf6, $0010(t7) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); - // @0012C100 LQC2 vf7, $0020(t7) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); - // @0012C104 LQC2 vf8, $0030(t7) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); - // @0012C108 VMULAx.xyzw ACC, vf1, vf5x - // @0012C10C VMADDAy.xyzw ACC, vf2, vf5y - // @0012C110 VMADDAz.xyzw ACC, vf3, vf5z - // @0012C114 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C118 VMULAx.xyzw ACC, vf1, vf6x - // @0012C11C VMADDAy.xyzw ACC, vf2, vf6y - // @0012C120 VMADDAz.xyzw ACC, vf3, vf6z - // @0012C124 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012C128 VMULAx.xyzw ACC, vf1, vf7x - // @0012C12C VMADDAy.xyzw ACC, vf2, vf7y - // @0012C130 VMADDAz.xyzw ACC, vf3, vf7z - // @0012C134 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012C138 VMULAx.xyzw ACC, vf1, vf8x - // @0012C13C VMADDAy.xyzw ACC, vf2, vf8y - // @0012C140 VMADDAz.xyzw ACC, vf3, vf8z - // @0012C144 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012C148 SQC2 vf5, $0000(t5) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); - // @0012C14C SQC2 vf6, $0010(t5) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t5.UL0)); - // @0012C150 SQC2 vf7, $0020(t5) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t5.UL0)); - // @0012C154 SQC2 vf8, $0030(t5) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t5.UL0)); - // @0012C158 BEQL t4, t5, $0012c184 - if ((this.ee.t4.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1229188u; - // @0012C15C LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012c160() - { - this.ee.pc = 1229204u; - // @0012C160 LQ t0, $0000(t5) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012C164 LQ t1, $0010(t5) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); - // @0012C168 LQ t2, $0020(t5) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); - // @0012C16C LQ t3, $0030(t5) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); - // @0012C170 SQ t0, $0000(t4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); - // @0012C174 SQ t1, $0010(t4) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); - // @0012C178 SQ t2, $0020(t4) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); - // @0012C17C SQ t3, $0030(t4) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); - // @0012C180 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012C184 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012C188 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012C18C BEQ t7, zero, $0012c370 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229680u; - } - // @0012C190 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012c194() - { - this.ee.pc = 1229228u; - // @0012C194 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012C198 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012C19C ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012C1A0 ADDIU t3, sp, $0090 - this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); - // @0012C1A4 BEQ t6, t3, $0012c1bc - if ((this.ee.t6.UD0 == this.ee.t3.UD0)) - { - this.ee.pc = 1229244u; - } - // @0012C1A8 LW t5, $0214(sp) - MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); - } - - public virtual void funct0012c19c() - { - this.ee.pc = 1229228u; - // @0012C19C ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012C1A0 ADDIU t3, sp, $0090 - this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); - // @0012C1A4 BEQ t6, t3, $0012c1bc - if ((this.ee.t6.UD0 == this.ee.t3.UD0)) - { - this.ee.pc = 1229244u; - } - // @0012C1A8 LW t5, $0214(sp) - MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); - } - - public virtual void funct0012c1ac() - { - this.ee.pc = 1229252u; - // @0012C1AC LQ t0, $0000(t3) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); - // @0012C1B0 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012C1B4 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012C1B8 LW t5, $0214(sp) - MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); - // @0012C1BC BGEZ t5, $0012c298 - if ((this.ee.t5.SD0 >= 0)) - { - this.ee.pc = 1229464u; - } - // @0012C1C0 LW t6, $0214(sp) - MobUt.LW(this.ee, this.ee.t6, (532u + this.ee.sp.UL0)); - } - - public virtual void funct0012c298() - { - this.ee.pc = 1229492u; - // @0012C298 LHU t3, $0010(t4) - MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t4.UL0)); - // @0012C29C SLL t7, t6, 6 - MobUt.SLL(this.ee.t7, this.ee.t6, 6); - // @0012C2A0 LW t6, $0008(s0) - MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); - // @0012C2A4 SLT t5, s2, t3 - this.ee.t5.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); - // @0012C2A8 ADDU t2, t6, t7 - this.ee.t2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012C2AC BEQ t5, zero, $0012c35c - if ((this.ee.t5.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229660u; - } - // @0012C2B0 ADDU t4, t6, s3 - this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); - } - - public virtual void funct0012c2b4() - { - this.ee.pc = 1229620u; - // @0012C2B4 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012C2B8 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012C2BC LQC2 vf1, $0000(t2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); - // @0012C2C0 LQC2 vf2, $0010(t2) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t2.UL0)); - // @0012C2C4 LQC2 vf3, $0020(t2) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t2.UL0)); - // @0012C2C8 LQC2 vf4, $0030(t2) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t2.UL0)); - // @0012C2CC LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012C2D0 LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012C2D4 LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012C2D8 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012C2DC VMULAx.xyzw ACC, vf1, vf5x - // @0012C2E0 VMADDAy.xyzw ACC, vf2, vf5y - // @0012C2E4 VMADDAz.xyzw ACC, vf3, vf5z - // @0012C2E8 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C2EC VMULAx.xyzw ACC, vf1, vf6x - // @0012C2F0 VMADDAy.xyzw ACC, vf2, vf6y - // @0012C2F4 VMADDAz.xyzw ACC, vf3, vf6z - // @0012C2F8 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012C2FC VMULAx.xyzw ACC, vf1, vf7x - // @0012C300 VMADDAy.xyzw ACC, vf2, vf7y - // @0012C304 VMADDAz.xyzw ACC, vf3, vf7z - // @0012C308 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012C30C VMULAx.xyzw ACC, vf1, vf8x - // @0012C310 VMADDAy.xyzw ACC, vf2, vf8y - // @0012C314 VMADDAz.xyzw ACC, vf3, vf8z - // @0012C318 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012C31C SQC2 vf5, $0000(s7) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s7.UL0)); - // @0012C320 SQC2 vf6, $0010(s7) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.s7.UL0)); - // @0012C324 SQC2 vf7, $0020(s7) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.s7.UL0)); - // @0012C328 SQC2 vf8, $0030(s7) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.s7.UL0)); - // @0012C32C BEQL t4, s7, $0012bbfc - if ((this.ee.t4.UD0 == this.ee.s7.UD0)) - { - this.ee.pc = 1227772u; - // @0012C330 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012c2bc() - { - this.ee.pc = 1229620u; - // @0012C2BC LQC2 vf1, $0000(t2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); - // @0012C2C0 LQC2 vf2, $0010(t2) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t2.UL0)); - // @0012C2C4 LQC2 vf3, $0020(t2) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t2.UL0)); - // @0012C2C8 LQC2 vf4, $0030(t2) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t2.UL0)); - // @0012C2CC LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012C2D0 LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012C2D4 LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012C2D8 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012C2DC VMULAx.xyzw ACC, vf1, vf5x - // @0012C2E0 VMADDAy.xyzw ACC, vf2, vf5y - // @0012C2E4 VMADDAz.xyzw ACC, vf3, vf5z - // @0012C2E8 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C2EC VMULAx.xyzw ACC, vf1, vf6x - // @0012C2F0 VMADDAy.xyzw ACC, vf2, vf6y - // @0012C2F4 VMADDAz.xyzw ACC, vf3, vf6z - // @0012C2F8 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012C2FC VMULAx.xyzw ACC, vf1, vf7x - // @0012C300 VMADDAy.xyzw ACC, vf2, vf7y - // @0012C304 VMADDAz.xyzw ACC, vf3, vf7z - // @0012C308 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012C30C VMULAx.xyzw ACC, vf1, vf8x - // @0012C310 VMADDAy.xyzw ACC, vf2, vf8y - // @0012C314 VMADDAz.xyzw ACC, vf3, vf8z - // @0012C318 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012C31C SQC2 vf5, $0000(s7) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s7.UL0)); - // @0012C320 SQC2 vf6, $0010(s7) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.s7.UL0)); - // @0012C324 SQC2 vf7, $0020(s7) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.s7.UL0)); - // @0012C328 SQC2 vf8, $0030(s7) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.s7.UL0)); - // @0012C32C BEQL t4, s7, $0012bbfc - if ((this.ee.t4.UD0 == this.ee.s7.UD0)) - { - this.ee.pc = 1227772u; - // @0012C330 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012c334() - { - this.ee.pc = 1229660u; - // @0012C334 LQ t0, $0000(s7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s7.UL[0])); - // @0012C338 LQ t1, $0010(s7) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.s7.UL[0])); - // @0012C33C LQ t2, $0020(s7) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.s7.UL[0])); - // @0012C340 LQ t3, $0030(s7) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.s7.UL[0])); - // @0012C344 SQ t0, $0000(t4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); - // @0012C348 SQ t1, $0010(t4) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); - // @0012C34C SQ t2, $0020(t4) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); - // @0012C350 SQ t3, $0030(t4) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); - // @0012C354 BEQ zero, zero, $0012bbfc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227772u; - } - // @0012C358 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - } - - public virtual void funct0012c35c() - { - this.ee.pc = 1229680u; - // @0012C35C SUBU t7, s2, t3 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); - // @0012C360 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012C364 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C368 BEQ zero, zero, $0012c2bc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229500u; - } - // @0012C36C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012c370() - { - this.ee.pc = 1229696u; - // @0012C370 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012C374 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C378 BEQ zero, zero, $0012c19c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229212u; - } - // @0012C37C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012c380() - { - this.ee.pc = 1229712u; - // @0012C380 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012C384 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C388 BEQ zero, zero, $0012c0e0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229024u; - } - // @0012C38C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012c390() - { - this.ee.pc = 1229732u; - // @0012C390 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - // @0012C394 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012C398 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C39C BEQ zero, zero, $0012c0c8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229000u; - } - // @0012C3A0 ADDU t4, t6, t7 - this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012c3a4() - { - this.ee.pc = 1229756u; - // @0012C3A4 SUBU t7, s2, t4 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); - // @0012C3A8 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C3AC ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012C3B0 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012C3B4 BEQ zero, zero, $0012c0a0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228960u; - } - // @0012C3B8 ADDIU t6, t6, $0020 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); - } - - public virtual void funct0012c3bc() - { - this.ee.pc = 1229772u; - // @0012C3BC LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012C3C0 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C3C4 BEQ zero, zero, $0012c074 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228916u; - } - // @0012C3C8 ADDU a2, t6, t7 - this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012c3cc() - { - this.ee.pc = 1229788u; - // @0012C3CC SUBU t7, t5, t6 - this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.t6.UD0))); - // @0012C3D0 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012C3D4 BEQ zero, zero, $0012bfd0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1228752u; - } - // @0012C3D8 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012c3e4() - { - this.ee.pc = 1229816u; - // @0012C3E4 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012C3E8 LHU t7, $0010(t7) - MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); - // @0012C3EC SLT t6, s2, t7 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); - // @0012C3F0 BEQ t6, zero, $0012c710 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230608u; - } - // @0012C3F4 SUBU t7, s2, t7 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); - } - - public virtual void funct0012c3f8() - { - this.ee.pc = 1229832u; - // @0012C3F8 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012C3FC ADDU a0, t7, s3 - this.ee.a0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012C400 JAL $0011b420 - this.ee.ra.UL0 = 1229832u; - this.ee.pc = 1160224u; - // @0012C404 NOP - MobUt.Latency(); - } - - public virtual void funct0012c400() - { - this.ee.pc = 1229832u; - // @0012C400 JAL $0011b420 - this.ee.ra.UL0 = 1229832u; - this.ee.pc = 1160224u; - // @0012C404 NOP - MobUt.Latency(); - } - - public virtual void funct0012c408() - { - this.ee.pc = 1229844u; - // @0012C408 LW t7, $021c(sp) - MobUt.LW(this.ee, this.ee.t7, (540u + this.ee.sp.UL0)); - // @0012C40C BEQ t7, zero, $0012c468 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229928u; - } - // @0012C410 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - } - - public virtual void funct0012c414() - { - this.ee.pc = 1229864u; - // @0012C414 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @0012C418 LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @0012C41C SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @0012C420 BEQ t7, zero, $0012c6f4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230580u; - } - // @0012C424 DADDU a2, t8, zero - this.ee.a2.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012c428() - { - this.ee.pc = 1229900u; - // @0012C428 LW t7, $0020(s5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); - // @0012C42C ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012C430 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012C434 SQ t0, $0000(a2) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a2.UL[0])); - // @0012C438 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @0012C43C LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @0012C440 SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @0012C444 BEQL t7, zero, $0012c6dc - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230556u; - // @0012C448 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct0012c430() - { - this.ee.pc = 1229900u; - // @0012C430 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012C434 SQ t0, $0000(a2) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a2.UL[0])); - // @0012C438 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @0012C43C LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @0012C440 SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @0012C444 BEQL t7, zero, $0012c6dc - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230556u; - // @0012C448 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct0012c44c() - { - this.ee.pc = 1229924u; - // @0012C44C LW t7, $0020(s5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); - // @0012C450 ADDU a3, t7, s8 - this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012C454 SQ t8, $0290(sp) - MobUt.SQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); - // @0012C458 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0012C45C JAL $00127e20 - this.ee.ra.UL0 = 1229924u; - this.ee.pc = 1211936u; - // @0012C460 LW a1, $021c(sp) - MobUt.LW(this.ee, this.ee.a1, (540u + this.ee.sp.UL0)); - } - - public virtual void funct0012c454() - { - this.ee.pc = 1229924u; - // @0012C454 SQ t8, $0290(sp) - MobUt.SQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); - // @0012C458 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0012C45C JAL $00127e20 - this.ee.ra.UL0 = 1229924u; - this.ee.pc = 1211936u; - // @0012C460 LW a1, $021c(sp) - MobUt.LW(this.ee, this.ee.a1, (540u + this.ee.sp.UL0)); - } - - public virtual void funct0012c464() - { - this.ee.pc = 1229948u; - // @0012C464 LQ t8, $0290(sp) - MobUt.LQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); - // @0012C468 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012C46C LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012C470 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012C474 BEQ t7, zero, $0012c6cc - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230540u; - } - // @0012C478 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012c468() - { - this.ee.pc = 1229948u; - // @0012C468 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012C46C LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012C470 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012C474 BEQ t7, zero, $0012c6cc - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230540u; - } - // @0012C478 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012c47c() - { - this.ee.pc = 1229972u; - // @0012C47C LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012C480 ADDU a0, t7, s3 - this.ee.a0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012C484 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012C488 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012C48C BEQL t7, zero, $0012c6b4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230516u; - // @0012C490 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012c484() - { - this.ee.pc = 1229972u; - // @0012C484 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012C488 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012C48C BEQL t7, zero, $0012c6b4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230516u; - // @0012C490 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012c494() - { - this.ee.pc = 1229988u; - // @0012C494 LW t7, $0020(s5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); - // @0012C498 ADDU a1, t7, s8 - this.ee.a1.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012C49C JAL $0011b528 - this.ee.ra.UL0 = 1229988u; - this.ee.pc = 1160488u; - // @0012C4A0 SQ t8, $0290(sp) - MobUt.SQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); - } - - public virtual void funct0012c49c() - { - this.ee.pc = 1229988u; - // @0012C49C JAL $0011b528 - this.ee.ra.UL0 = 1229988u; - this.ee.pc = 1160488u; - // @0012C4A0 SQ t8, $0290(sp) - MobUt.SQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); - } - - public virtual void funct0012c4a4() - { - this.ee.pc = 1230008u; - // @0012C4A4 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012C4A8 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012C4AC SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012C4B0 BEQ t7, zero, $0012c6a0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230496u; - } - // @0012C4B4 LQ t8, $0290(sp) - MobUt.LQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); - } - - public virtual void funct0012c4b8() - { - this.ee.pc = 1230032u; - // @0012C4B8 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012C4BC ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012C4C0 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012C4C4 ADDIU t3, sp, $0090 - this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); - // @0012C4C8 BEQ t6, t3, $0012c4e0 - if ((this.ee.t6.UD0 == this.ee.t3.UD0)) - { - this.ee.pc = 1230048u; - } - // @0012C4CC LW t5, $0214(sp) - MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); - } - - public virtual void funct0012c4c0() - { - this.ee.pc = 1230032u; - // @0012C4C0 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012C4C4 ADDIU t3, sp, $0090 - this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); - // @0012C4C8 BEQ t6, t3, $0012c4e0 - if ((this.ee.t6.UD0 == this.ee.t3.UD0)) - { - this.ee.pc = 1230048u; - } - // @0012C4CC LW t5, $0214(sp) - MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); - } - - public virtual void funct0012c4d0() - { - this.ee.pc = 1230056u; - // @0012C4D0 LQ t0, $0000(t3) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); - // @0012C4D4 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012C4D8 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012C4DC LW t5, $0214(sp) - MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); - // @0012C4E0 BLTZ t5, $0012c4f4 - if ((this.ee.t5.SD0 < 0)) - { - this.ee.pc = 1230068u; - } - // @0012C4E4 LUI t7, $0008 - this.ee.t7.SD0 = 524288; - } - - public virtual void funct0012c4e8() - { - this.ee.pc = 1230068u; - // @0012C4E8 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @0012C4EC BEQ t7, zero, $0012c5c8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230280u; - } - // @0012C4F0 LW t6, $0214(sp) - MobUt.LW(this.ee, this.ee.t6, (532u + this.ee.sp.UL0)); - } - - public virtual void funct0012c4f4() - { - this.ee.pc = 1230092u; - // @0012C4F4 LHU t4, $0010(t4) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t4.UL0)); - // @0012C4F8 DADDU t3, sp, zero - this.ee.t3.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); - // @0012C4FC LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - // @0012C500 SLT t6, s2, t4 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @0012C504 BEQ t6, zero, $0012c5b4 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230260u; - } - // @0012C508 ADDU t5, t7, s3 - this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - } - - public virtual void funct0012c50c() - { - this.ee.pc = 1230220u; - // @0012C50C LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012C510 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012C514 LQC2 vf1, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); - // @0012C518 LQC2 vf2, $0010(t3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); - // @0012C51C LQC2 vf3, $0020(t3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); - // @0012C520 LQC2 vf4, $0030(t3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); - // @0012C524 LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012C528 LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012C52C LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012C530 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012C534 VMULAx.xyzw ACC, vf1, vf5x - // @0012C538 VMADDAy.xyzw ACC, vf2, vf5y - // @0012C53C VMADDAz.xyzw ACC, vf3, vf5z - // @0012C540 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C544 VMULAx.xyzw ACC, vf1, vf6x - // @0012C548 VMADDAy.xyzw ACC, vf2, vf6y - // @0012C54C VMADDAz.xyzw ACC, vf3, vf6z - // @0012C550 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012C554 VMULAx.xyzw ACC, vf1, vf7x - // @0012C558 VMADDAy.xyzw ACC, vf2, vf7y - // @0012C55C VMADDAz.xyzw ACC, vf3, vf7z - // @0012C560 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012C564 VMULAx.xyzw ACC, vf1, vf8x - // @0012C568 VMADDAy.xyzw ACC, vf2, vf8y - // @0012C56C VMADDAz.xyzw ACC, vf3, vf8z - // @0012C570 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012C574 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012C578 SQC2 vf6, $0010(t8) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); - // @0012C57C SQC2 vf7, $0020(t8) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); - // @0012C580 SQC2 vf8, $0030(t8) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); - // @0012C584 BEQL t5, t8, $0012bbfc - if ((this.ee.t5.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1227772u; - // @0012C588 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012c514() - { - this.ee.pc = 1230220u; - // @0012C514 LQC2 vf1, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); - // @0012C518 LQC2 vf2, $0010(t3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); - // @0012C51C LQC2 vf3, $0020(t3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); - // @0012C520 LQC2 vf4, $0030(t3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); - // @0012C524 LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012C528 LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012C52C LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012C530 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012C534 VMULAx.xyzw ACC, vf1, vf5x - // @0012C538 VMADDAy.xyzw ACC, vf2, vf5y - // @0012C53C VMADDAz.xyzw ACC, vf3, vf5z - // @0012C540 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C544 VMULAx.xyzw ACC, vf1, vf6x - // @0012C548 VMADDAy.xyzw ACC, vf2, vf6y - // @0012C54C VMADDAz.xyzw ACC, vf3, vf6z - // @0012C550 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012C554 VMULAx.xyzw ACC, vf1, vf7x - // @0012C558 VMADDAy.xyzw ACC, vf2, vf7y - // @0012C55C VMADDAz.xyzw ACC, vf3, vf7z - // @0012C560 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012C564 VMULAx.xyzw ACC, vf1, vf8x - // @0012C568 VMADDAy.xyzw ACC, vf2, vf8y - // @0012C56C VMADDAz.xyzw ACC, vf3, vf8z - // @0012C570 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012C574 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012C578 SQC2 vf6, $0010(t8) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); - // @0012C57C SQC2 vf7, $0020(t8) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); - // @0012C580 SQC2 vf8, $0030(t8) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); - // @0012C584 BEQL t5, t8, $0012bbfc - if ((this.ee.t5.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1227772u; - // @0012C588 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012c58c() - { - this.ee.pc = 1230260u; - // @0012C58C LQ t0, $0000(t8) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); - // @0012C590 LQ t1, $0010(t8) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t8.UL[0])); - // @0012C594 LQ t2, $0020(t8) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t8.UL[0])); - // @0012C598 LQ t3, $0030(t8) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t8.UL[0])); - // @0012C59C SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012C5A0 SQ t1, $0010(t5) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); - // @0012C5A4 SQ t2, $0020(t5) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); - // @0012C5A8 SQ t3, $0030(t5) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); - // @0012C5AC BEQ zero, zero, $0012bbfc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227772u; - } - // @0012C5B0 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - } - - public virtual void funct0012c5b4() - { - this.ee.pc = 1230280u; - // @0012C5B4 SUBU t7, s2, t4 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); - // @0012C5B8 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012C5BC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C5C0 BEQ zero, zero, $0012c514 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230100u; - } - // @0012C5C4 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012c5c8() - { - this.ee.pc = 1230308u; - // @0012C5C8 LHU t3, $0010(t4) - MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t4.UL0)); - // @0012C5CC SLL t7, t6, 6 - MobUt.SLL(this.ee.t7, this.ee.t6, 6); - // @0012C5D0 LW t6, $0008(s0) - MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); - // @0012C5D4 SLT t5, s2, t3 - this.ee.t5.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); - // @0012C5D8 ADDU t2, t6, t7 - this.ee.t2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012C5DC BEQ t5, zero, $0012c68c - if ((this.ee.t5.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230476u; - } - // @0012C5E0 ADDU t4, t6, s3 - this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); - } - - public virtual void funct0012c5e4() - { - this.ee.pc = 1230436u; - // @0012C5E4 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012C5E8 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012C5EC LQC2 vf1, $0000(t2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); - // @0012C5F0 LQC2 vf2, $0010(t2) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t2.UL0)); - // @0012C5F4 LQC2 vf3, $0020(t2) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t2.UL0)); - // @0012C5F8 LQC2 vf4, $0030(t2) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t2.UL0)); - // @0012C5FC LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012C600 LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012C604 LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012C608 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012C60C VMULAx.xyzw ACC, vf1, vf5x - // @0012C610 VMADDAy.xyzw ACC, vf2, vf5y - // @0012C614 VMADDAz.xyzw ACC, vf3, vf5z - // @0012C618 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C61C VMULAx.xyzw ACC, vf1, vf6x - // @0012C620 VMADDAy.xyzw ACC, vf2, vf6y - // @0012C624 VMADDAz.xyzw ACC, vf3, vf6z - // @0012C628 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012C62C VMULAx.xyzw ACC, vf1, vf7x - // @0012C630 VMADDAy.xyzw ACC, vf2, vf7y - // @0012C634 VMADDAz.xyzw ACC, vf3, vf7z - // @0012C638 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012C63C VMULAx.xyzw ACC, vf1, vf8x - // @0012C640 VMADDAy.xyzw ACC, vf2, vf8y - // @0012C644 VMADDAz.xyzw ACC, vf3, vf8z - // @0012C648 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012C64C SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012C650 SQC2 vf6, $0010(t8) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); - // @0012C654 SQC2 vf7, $0020(t8) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); - // @0012C658 SQC2 vf8, $0030(t8) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); - // @0012C65C BEQL t4, t8, $0012bbfc - if ((this.ee.t4.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1227772u; - // @0012C660 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012c5ec() - { - this.ee.pc = 1230436u; - // @0012C5EC LQC2 vf1, $0000(t2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); - // @0012C5F0 LQC2 vf2, $0010(t2) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t2.UL0)); - // @0012C5F4 LQC2 vf3, $0020(t2) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t2.UL0)); - // @0012C5F8 LQC2 vf4, $0030(t2) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t2.UL0)); - // @0012C5FC LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012C600 LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012C604 LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012C608 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012C60C VMULAx.xyzw ACC, vf1, vf5x - // @0012C610 VMADDAy.xyzw ACC, vf2, vf5y - // @0012C614 VMADDAz.xyzw ACC, vf3, vf5z - // @0012C618 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C61C VMULAx.xyzw ACC, vf1, vf6x - // @0012C620 VMADDAy.xyzw ACC, vf2, vf6y - // @0012C624 VMADDAz.xyzw ACC, vf3, vf6z - // @0012C628 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012C62C VMULAx.xyzw ACC, vf1, vf7x - // @0012C630 VMADDAy.xyzw ACC, vf2, vf7y - // @0012C634 VMADDAz.xyzw ACC, vf3, vf7z - // @0012C638 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012C63C VMULAx.xyzw ACC, vf1, vf8x - // @0012C640 VMADDAy.xyzw ACC, vf2, vf8y - // @0012C644 VMADDAz.xyzw ACC, vf3, vf8z - // @0012C648 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012C64C SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012C650 SQC2 vf6, $0010(t8) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); - // @0012C654 SQC2 vf7, $0020(t8) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); - // @0012C658 SQC2 vf8, $0030(t8) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); - // @0012C65C BEQL t4, t8, $0012bbfc - if ((this.ee.t4.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1227772u; - // @0012C660 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012c664() - { - this.ee.pc = 1230476u; - // @0012C664 LQ t0, $0000(t8) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); - // @0012C668 LQ t1, $0010(t8) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t8.UL[0])); - // @0012C66C LQ t2, $0020(t8) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t8.UL[0])); - // @0012C670 LQ t3, $0030(t8) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t8.UL[0])); - // @0012C674 SQ t0, $0000(t4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); - // @0012C678 SQ t1, $0010(t4) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); - // @0012C67C SQ t2, $0020(t4) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); - // @0012C680 SQ t3, $0030(t4) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); - // @0012C684 BEQ zero, zero, $0012bbfc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227772u; - } - // @0012C688 LW t5, $0008(s0) - MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); - } - - public virtual void funct0012c68c() - { - this.ee.pc = 1230496u; - // @0012C68C SUBU t7, s2, t3 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); - // @0012C690 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012C694 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C698 BEQ zero, zero, $0012c5ec - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230316u; - } - // @0012C69C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012c6a0() - { - this.ee.pc = 1230516u; - // @0012C6A0 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - // @0012C6A4 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012C6A8 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C6AC BEQ zero, zero, $0012c4c0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230016u; - } - // @0012C6B0 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012c6b4() - { - this.ee.pc = 1230540u; - // @0012C6B4 SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012C6B8 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C6BC ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012C6C0 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012C6C4 BEQ zero, zero, $0012c49c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229980u; - } - // @0012C6C8 ADDIU a1, t6, $0020 - this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + 32))); - } - - public virtual void funct0012c6cc() - { - this.ee.pc = 1230556u; - // @0012C6CC LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012C6D0 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C6D4 BEQ zero, zero, $0012c484 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229956u; - } - // @0012C6D8 ADDU a0, t6, t7 - this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012c6dc() - { - this.ee.pc = 1230580u; - // @0012C6DC SUBU t7, s2, t4 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); - // @0012C6E0 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C6E4 ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012C6E8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012C6EC BEQ zero, zero, $0012c454 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229908u; - } - // @0012C6F0 ADDIU a3, t6, $0020 - this.ee.a3.SD0 = ((int)((this.ee.t6.SD0 + 32))); - } - - public virtual void funct0012c6f4() - { - this.ee.pc = 1230608u; - // @0012C6F4 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - // @0012C6F8 SUBU t7, s2, t4 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); - // @0012C6FC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C700 ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012C704 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012C708 BEQ zero, zero, $0012c430 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229872u; - } - // @0012C70C ADDIU t6, t6, $0020 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); - } - - public virtual void funct0012c710() - { - this.ee.pc = 1230624u; - // @0012C710 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012C714 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C718 BEQ zero, zero, $0012c400 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1229824u; - } - // @0012C71C ADDU a0, t6, t7 - this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012c720() - { - this.ee.pc = 1230648u; - // @0012C720 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - // @0012C724 SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - // @0012C728 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012C72C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012C730 BEQ zero, zero, $0012bb60 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227616u; - } - // @0012C734 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012c738() - { - this.ee.pc = 1230656u; - // @0012C738 BNEL a2, t7, $0012c74c - if ((this.ee.a2.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1230668u; - // @0012C73C SQ v0, $0260(sp) - MobUt.SQ(this.ee, this.ee.v0, (608u + this.ee.sp.UL[0])); - } - } - - public virtual void funct0012c740() - { - this.ee.pc = 1230664u; - // @0012C740 BEQL a3, a2, $0012c8d0 - if ((this.ee.a3.UD0 == this.ee.a2.UD0)) - { - this.ee.pc = 1231056u; - // @0012C744 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012c74c() - { - this.ee.pc = 1230700u; - // @0012C74C ADDIU s3, sp, $0040 - this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 64))); - // @0012C750 SQ v1, $0270(sp) - MobUt.SQ(this.ee, this.ee.v1, (624u + this.ee.sp.UL[0])); - // @0012C754 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0012C758 DADDU a1, s5, zero - this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); - // @0012C75C ADDIU t0, sp, $0080 - this.ee.t0.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012C760 DADDU t1, s3, zero - this.ee.t1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); - // @0012C764 JAL $00128c78 - this.ee.ra.UL0 = 1230700u; - this.ee.pc = 1215608u; - // @0012C768 ADDIU t2, sp, $0090 - this.ee.t2.SD0 = ((int)((this.ee.sp.SD0 + 144))); - } - - public virtual void funct0012c76c() - { - this.ee.pc = 1230736u; - // @0012C76C ADDIU s7, sp, $0090 - this.ee.s7.SD0 = ((int)((this.ee.sp.SD0 + 144))); - // @0012C770 LUI t3, $0038 - this.ee.t3.SD0 = 3670016; - // @0012C774 LQ v0, $0260(sp) - MobUt.LQ(this.ee, this.ee.v0, (608u + this.ee.sp.UL[0])); - // @0012C778 ADDIU t3, t3, $8364 - this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + -31900))); - // @0012C77C LQ v1, $0270(sp) - MobUt.LQ(this.ee, this.ee.v1, (624u + this.ee.sp.UL[0])); - // @0012C780 LWC1 $f0, $0000(t3) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t3.UL0)); - // @0012C784 ADDIU t5, sp, $0080 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012C788 BEQ v0, zero, $0012c848 - if ((this.ee.v0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230920u; - } - // @0012C78C SWC1 $f0, $009c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); - } - - public virtual void funct0012c790() - { - this.ee.pc = 1230756u; - // @0012C790 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012C794 LHU t7, $0010(t7) - MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); - // @0012C798 SLT t6, v1, t7 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.v1.SD0 < this.ee.t7.SD0)); - // @0012C79C BEQ t6, zero, $0012c8c4 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231044u; - } - // @0012C7A0 SUBU t7, v1, t7 - this.ee.t7.SD0 = ((int)((this.ee.v1.UD0 - this.ee.t7.UD0))); - } - - public virtual void funct0012c7ac() - { - this.ee.pc = 1230852u; - // @0012C7AC ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012C7B0 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012C7B4 ADDIU t7, t6, $0030 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012C7B8 LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012C7BC LQC2 vf1, $0000(s3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); - // @0012C7C0 LQC2 vf2, $0010(s3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); - // @0012C7C4 LQC2 vf3, $0020(s3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); - // @0012C7C8 LQC2 vf4, $0030(s3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); - // @0012C7CC VMULAx.xyzw ACC, vf1, vf5x - // @0012C7D0 VMADDAy.xyzw ACC, vf2, vf5y - // @0012C7D4 VMADDAz.xyzw ACC, vf3, vf5z - // @0012C7D8 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C7DC SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012C7E0 ADDIU s3, sp, $0130 - this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 304))); - // @0012C7E4 LQ t0, $0000(t8) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); - // @0012C7E8 SQ t0, $0000(s3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @0012C7EC SQ t5, $0280(sp) - MobUt.SQ(this.ee, this.ee.t5, (640u + this.ee.sp.UL[0])); - // @0012C7F0 DADDU a1, v0, zero - this.ee.a1.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); - // @0012C7F4 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0012C7F8 DADDU a2, s3, zero - this.ee.a2.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); - // @0012C7FC JAL $00127e20 - this.ee.ra.UL0 = 1230852u; - this.ee.pc = 1211936u; - // @0012C800 DADDU a3, s7, zero - this.ee.a3.UD0 = (this.ee.s7.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012c804() - { - this.ee.pc = 1230864u; - // @0012C804 LW t4, $0214(sp) - MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); - // @0012C808 BGEZ t4, $0012c860 - if ((this.ee.t4.SD0 >= 0)) - { - this.ee.pc = 1230944u; - } - // @0012C80C LQ t5, $0280(sp) - MobUt.LQ(this.ee, this.ee.t5, (640u + this.ee.sp.UL[0])); - } - - public virtual void funct0012c838() - { - this.ee.pc = 1230912u; - // @0012C838 BEQL t5, s3, $0012c84c - if ((this.ee.t5.UD0 == this.ee.s3.UD0)) - { - this.ee.pc = 1230924u; - // @0012C83C LUI t5, $0038 - this.ee.t5.SD0 = 3670016; - } - } - - public virtual void funct0012c840() - { - this.ee.pc = 1230944u; - // @0012C840 LQ t0, $0000(s3) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @0012C844 SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012C848 LUI t5, $0038 - this.ee.t5.SD0 = 3670016; - // @0012C84C SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - // @0012C850 ADDIU t5, t5, $8364 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + -31900))); - // @0012C854 LWC1 $f0, $0000(t5) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); - // @0012C858 BEQ zero, zero, $0012bbcc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227724u; - } - // @0012C85C SWC1 $f0, $008c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (140u + this.ee.sp.UL0)); - } - - public virtual void funct0012c848() - { - this.ee.pc = 1230944u; - // @0012C848 LUI t5, $0038 - this.ee.t5.SD0 = 3670016; - // @0012C84C SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - // @0012C850 ADDIU t5, t5, $8364 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + -31900))); - // @0012C854 LWC1 $f0, $0000(t5) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); - // @0012C858 BEQ zero, zero, $0012bbcc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227724u; - } - // @0012C85C SWC1 $f0, $008c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (140u + this.ee.sp.UL0)); - } - - public virtual void funct0012c858() - { - this.ee.pc = 1230944u; - // @0012C858 BEQ zero, zero, $0012bbcc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227724u; - } - // @0012C85C SWC1 $f0, $008c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (140u + this.ee.sp.UL0)); - } - - public virtual void funct0012c860() - { - this.ee.pc = 1230968u; - // @0012C860 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012C864 LW t3, $0214(sp) - MobUt.LW(this.ee, this.ee.t3, (532u + this.ee.sp.UL0)); - // @0012C868 LHU t7, $0010(t7) - MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); - // @0012C86C SLT t6, t3, t7 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t3.SD0 < this.ee.t7.SD0)); - // @0012C870 BEQ t6, zero, $0012c8b4 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231028u; - } - // @0012C874 LW t4, $0214(sp) - MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); - } - - public virtual void funct0012c880() - { - this.ee.pc = 1231028u; - // @0012C880 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012C884 LQC2 vf5, $0000(s7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s7.UL0)); - // @0012C888 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012C88C LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012C890 LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012C894 LQC2 vf4, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); - // @0012C898 VMULAx.xyzw ACC, vf1, vf5x - // @0012C89C VMADDAy.xyzw ACC, vf2, vf5y - // @0012C8A0 VMADDAz.xyzw ACC, vf3, vf5z - // @0012C8A4 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C8A8 SQC2 vf5, $0000(s3) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s3.UL0)); - // @0012C8AC BEQ zero, zero, $0012c838 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230904u; - } - // @0012C8B0 NOP - MobUt.Latency(); - } - - public virtual void funct0012c8b4() - { - this.ee.pc = 1231044u; - // @0012C8B4 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012C8B8 SUBU t7, t4, t7 - this.ee.t7.SD0 = ((int)((this.ee.t4.UD0 - this.ee.t7.UD0))); - // @0012C8BC BEQ zero, zero, $0012c880 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230976u; - } - // @0012C8C0 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012c8c4() - { - this.ee.pc = 1231056u; - // @0012C8C4 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012C8C8 BEQ zero, zero, $0012c7ac - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230764u; - } - // @0012C8CC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012c8d0() - { - this.ee.pc = 1231072u; - // @0012C8D0 LHU t4, $0010(t5) - MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); - // @0012C8D4 SLT t7, s2, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); - // @0012C8D8 BEQ t7, zero, $0012ca68 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231464u; - } - // @0012C8DC ADDIU s3, sp, $0090 - this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 144))); - } - - public virtual void funct0012c8e0() - { - this.ee.pc = 1231088u; - // @0012C8E0 LW t7, $0024(s5) - MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s5.UL0)); - // @0012C8E4 ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012C8E8 BEQL s3, t6, $0012c8fc - if ((this.ee.s3.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1231100u; - // @0012C8EC LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - } - } - - public virtual void funct0012c8e8() - { - this.ee.pc = 1231088u; - // @0012C8E8 BEQL s3, t6, $0012c8fc - if ((this.ee.s3.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1231100u; - // @0012C8EC LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - } - } - - public virtual void funct0012c8f0() - { - this.ee.pc = 1231116u; - // @0012C8F0 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012C8F4 SQ t0, $0000(s3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @0012C8F8 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @0012C8FC ADDIU t6, t6, $8364 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -31900))); - // @0012C900 LWC1 $f0, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @0012C904 BEQ v0, zero, $0012ca60 - if ((this.ee.v0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231456u; - } - // @0012C908 SWC1 $f0, $009c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); - } - - public virtual void funct0012c90c() - { - this.ee.pc = 1231136u; - // @0012C90C LW t6, $0004(s0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); - // @0012C910 LHU t6, $0010(t6) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); - // @0012C914 SLT t7, v1, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.v1.SD0 < this.ee.t6.SD0)); - // @0012C918 BEQ t7, zero, $0012ca50 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231440u; - } - // @0012C91C ADDIU t5, sp, $0040 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 64))); - } - - public virtual void funct0012c928() - { - this.ee.pc = 1231228u; - // @0012C928 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012C92C ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012C930 ADDIU t7, t6, $0030 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012C934 LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012C938 LQC2 vf1, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); - // @0012C93C LQC2 vf2, $0010(t5) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t5.UL0)); - // @0012C940 LQC2 vf3, $0020(t5) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t5.UL0)); - // @0012C944 LQC2 vf4, $0030(t5) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t5.UL0)); - // @0012C948 VMULAx.xyzw ACC, vf1, vf5x - // @0012C94C VMADDAy.xyzw ACC, vf2, vf5y - // @0012C950 VMADDAz.xyzw ACC, vf3, vf5z - // @0012C954 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C958 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012C95C ADDIU a2, sp, $0130 - this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 304))); - // @0012C960 LQ t0, $0000(t8) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); - // @0012C964 SQ t0, $0000(a2) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a2.UL[0])); - // @0012C968 SQ t8, $0290(sp) - MobUt.SQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); - // @0012C96C DADDU a1, v0, zero - this.ee.a1.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); - // @0012C970 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0012C974 JAL $00127e20 - this.ee.ra.UL0 = 1231228u; - this.ee.pc = 1211936u; - // @0012C978 DADDU a3, s3, zero - this.ee.a3.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012c97c() - { - this.ee.pc = 1231244u; - // @0012C97C LQ t8, $0290(sp) - MobUt.LQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); - // @0012C980 LW t7, $0214(sp) - MobUt.LW(this.ee, this.ee.t7, (532u + this.ee.sp.UL0)); - // @0012C984 BGEZL t7, $0012c9dc - if ((this.ee.t7.SD0 >= 0)) - { - this.ee.pc = 1231324u; - // @0012C988 LW t6, $0004(s0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012c980() - { - this.ee.pc = 1231244u; - // @0012C980 LW t7, $0214(sp) - MobUt.LW(this.ee, this.ee.t7, (532u + this.ee.sp.UL0)); - // @0012C984 BGEZL t7, $0012c9dc - if ((this.ee.t7.SD0 >= 0)) - { - this.ee.pc = 1231324u; - // @0012C988 LW t6, $0004(s0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012c98c() - { - this.ee.pc = 1231296u; - // @0012C98C ADDIU t7, sp, $0080 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012C990 LQC2 vf5, $0000(s3) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s3.UL0)); - // @0012C994 LQC2 vf1, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @0012C998 LQC2 vf2, $0010(sp) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.sp.UL0)); - // @0012C99C LQC2 vf3, $0020(sp) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.sp.UL0)); - // @0012C9A0 LQC2 vf4, $0030(sp) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.sp.UL0)); - // @0012C9A4 VMULAx.xyzw ACC, vf1, vf5x - // @0012C9A8 VMADDAy.xyzw ACC, vf2, vf5y - // @0012C9AC VMADDAz.xyzw ACC, vf3, vf5z - // @0012C9B0 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012C9B4 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012C9B8 BEQ t7, t8, $0012c9cc - if ((this.ee.t7.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1231308u; - } - // @0012C9BC LUI t4, $0038 - this.ee.t4.SD0 = 3670016; - } - - public virtual void funct0012c9c0() - { - this.ee.pc = 1231324u; - // @0012C9C0 LQ t0, $0000(t8) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); - // @0012C9C4 SQ t0, $0000(t7) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012C9C8 LUI t4, $0038 - this.ee.t4.SD0 = 3670016; - // @0012C9CC SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - // @0012C9D0 ADDIU t4, t4, $8364 - this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + -31900))); - // @0012C9D4 BEQ zero, zero, $0012c858 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230936u; - } - // @0012C9D8 LWC1 $f0, $0000(t4) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t4.UL0)); - } - - public virtual void funct0012c9cc() - { - this.ee.pc = 1231324u; - // @0012C9CC SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - // @0012C9D0 ADDIU t4, t4, $8364 - this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + -31900))); - // @0012C9D4 BEQ zero, zero, $0012c858 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1230936u; - } - // @0012C9D8 LWC1 $f0, $0000(t4) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t4.UL0)); - } - - public virtual void funct0012c9dc() - { - this.ee.pc = 1231344u; - // @0012C9DC LW t4, $0214(sp) - MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); - // @0012C9E0 LHU t6, $0010(t6) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); - // @0012C9E4 SLT t7, t4, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.t6.SD0)); - // @0012C9E8 BEQ t7, zero, $0012ca3c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231420u; - } - // @0012C9EC ADDIU t5, sp, $0080 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); - } - - public virtual void funct0012c9f0() - { - this.ee.pc = 1231404u; - // @0012C9F0 LW t6, $002c(s5) - MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); - // @0012C9F4 SLL t7, t4, 6 - MobUt.SLL(this.ee.t7, this.ee.t4, 6); - // @0012C9F8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012C9FC LQC2 vf5, $0000(s3) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s3.UL0)); - // @0012CA00 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012CA04 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012CA08 LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012CA0C LQC2 vf4, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); - // @0012CA10 VMULAx.xyzw ACC, vf1, vf5x - // @0012CA14 VMADDAy.xyzw ACC, vf2, vf5y - // @0012CA18 VMADDAz.xyzw ACC, vf3, vf5z - // @0012CA1C VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012CA20 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012CA24 BEQL t5, t8, $0012c9cc - if ((this.ee.t5.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1231308u; - // @0012CA28 LUI t4, $0038 - this.ee.t4.SD0 = 3670016; - } - } - - public virtual void funct0012c9f8() - { - this.ee.pc = 1231404u; - // @0012C9F8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012C9FC LQC2 vf5, $0000(s3) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s3.UL0)); - // @0012CA00 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012CA04 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012CA08 LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012CA0C LQC2 vf4, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); - // @0012CA10 VMULAx.xyzw ACC, vf1, vf5x - // @0012CA14 VMADDAy.xyzw ACC, vf2, vf5y - // @0012CA18 VMADDAz.xyzw ACC, vf3, vf5z - // @0012CA1C VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012CA20 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012CA24 BEQL t5, t8, $0012c9cc - if ((this.ee.t5.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1231308u; - // @0012CA28 LUI t4, $0038 - this.ee.t4.SD0 = 3670016; - } - } - - public virtual void funct0012ca2c() - { - this.ee.pc = 1231420u; - // @0012CA2C LQ t0, $0000(t8) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); - // @0012CA30 SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012CA34 BEQ zero, zero, $0012c9cc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231308u; - } - // @0012CA38 LUI t4, $0038 - this.ee.t4.SD0 = 3670016; - } - - public virtual void funct0012ca3c() - { - this.ee.pc = 1231440u; - // @0012CA3C LW t3, $0214(sp) - MobUt.LW(this.ee, this.ee.t3, (532u + this.ee.sp.UL0)); - // @0012CA40 SUBU t7, t3, t6 - this.ee.t7.SD0 = ((int)((this.ee.t3.UD0 - this.ee.t6.UD0))); - // @0012CA44 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012CA48 BEQ zero, zero, $0012c9f8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231352u; - } - // @0012CA4C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012ca50() - { - this.ee.pc = 1231456u; - // @0012CA50 SUBU t7, v1, t6 - this.ee.t7.SD0 = ((int)((this.ee.v1.UD0 - this.ee.t6.UD0))); - // @0012CA54 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012CA58 BEQ zero, zero, $0012c928 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231144u; - } - // @0012CA5C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012ca60() - { - this.ee.pc = 1231464u; - // @0012CA60 BEQ zero, zero, $0012c980 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231232u; - } - // @0012CA64 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - } - - public virtual void funct0012ca68() - { - this.ee.pc = 1231492u; - // @0012CA68 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - // @0012CA6C SUBU t7, s2, t4 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); - // @0012CA70 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012CA74 ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012CA78 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012CA7C BEQ zero, zero, $0012c8e8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231080u; - } - // @0012CA80 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012ca88() - { - this.ee.pc = 1231520u; - // @0012CA88 ADDIU a1, sp, $0040 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 64))); - // @0012CA8C LW t3, $0214(sp) - MobUt.LW(this.ee, this.ee.t3, (532u + this.ee.sp.UL0)); - // @0012CA90 LHU t6, $0010(t6) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); - // @0012CA94 SLT t7, t3, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t3.SD0 < this.ee.t6.SD0)); - // @0012CA98 BEQ t7, zero, $0012cadc - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231580u; - } - // @0012CA9C DADDU t5, a1, zero - this.ee.t5.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012caa0() - { - this.ee.pc = 1231540u; - // @0012CAA0 LW t6, $002c(s5) - MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); - // @0012CAA4 SLL t7, t3, 6 - MobUt.SLL(this.ee.t7, this.ee.t3, 6); - // @0012CAA8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012CAAC BEQ t5, t6, $0012ba74 - if ((this.ee.t5.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1227380u; - } - // @0012CAB0 NOP - MobUt.Latency(); - } - - public virtual void funct0012caa8() - { - this.ee.pc = 1231540u; - // @0012CAA8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012CAAC BEQ t5, t6, $0012ba74 - if ((this.ee.t5.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1227380u; - } - // @0012CAB0 NOP - MobUt.Latency(); - } - - public virtual void funct0012cab4() - { - this.ee.pc = 1231580u; - // @0012CAB4 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012CAB8 LQ t1, $0010(t6) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); - // @0012CABC LQ t2, $0020(t6) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); - // @0012CAC0 LQ t3, $0030(t6) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); - // @0012CAC4 SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012CAC8 SQ t1, $0010(t5) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); - // @0012CACC SQ t2, $0020(t5) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); - // @0012CAD0 SQ t3, $0030(t5) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); - // @0012CAD4 BEQ zero, zero, $0012ba74 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1227380u; - } - // @0012CAD8 NOP - MobUt.Latency(); - } - - public virtual void funct0012cadc() - { - this.ee.pc = 1231600u; - // @0012CADC LW t4, $0214(sp) - MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); - // @0012CAE0 SUBU t7, t4, t6 - this.ee.t7.SD0 = ((int)((this.ee.t4.UD0 - this.ee.t6.UD0))); - // @0012CAE4 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012CAE8 BEQ zero, zero, $0012caa8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231528u; - } - // @0012CAEC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012caf0() - { - this.ee.pc = 1231620u; - // @0012CAF0 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012CAF4 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012CAF8 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012CAFC BEQ t7, zero, $0012d218 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233432u; - } - // @0012CB00 ADDIU t3, sp, $0090 - this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); - } - - public virtual void funct0012cb04() - { - this.ee.pc = 1231636u; - // @0012CB04 LW t7, $0024(s5) - MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s5.UL0)); - // @0012CB08 ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012CB0C BEQ t3, t6, $0012cb24 - if ((this.ee.t3.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1231652u; - } - // @0012CB10 LUI t5, $0038 - this.ee.t5.SD0 = 3670016; - } - - public virtual void funct0012cb0c() - { - this.ee.pc = 1231636u; - // @0012CB0C BEQ t3, t6, $0012cb24 - if ((this.ee.t3.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1231652u; - } - // @0012CB10 LUI t5, $0038 - this.ee.t5.SD0 = 3670016; - } - - public virtual void funct0012cb14() - { - this.ee.pc = 1231684u; - // @0012CB14 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012CB18 SQ t0, $0000(t3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); - // @0012CB1C LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012CB20 LUI t5, $0038 - this.ee.t5.SD0 = 3670016; - // @0012CB24 ADDIU t5, t5, $8364 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + -31900))); - // @0012CB28 LWC1 $f0, $0000(t5) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); - // @0012CB2C SWC1 $f0, $009c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); - // @0012CB30 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012CB34 LW t4, $0214(sp) - MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); - // @0012CB38 SLT t7, t4, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.t6.SD0)); - // @0012CB3C BEQ t7, zero, $0012d200 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233408u; - } - // @0012CB40 SLL t5, t4, 6 - MobUt.SLL(this.ee.t5, this.ee.t4, 6); - } - - public virtual void funct0012cb44() - { - this.ee.pc = 1231756u; - // @0012CB44 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012CB48 SW t5, $0250(sp) - MobUt.SW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); - // @0012CB4C ADDU t6, t7, t5 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); - // @0012CB50 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012CB54 DADDU s7, t8, zero - this.ee.s7.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); - // @0012CB58 LQC2 vf5, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); - // @0012CB5C LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012CB60 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012CB64 LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012CB68 LQC2 vf4, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); - // @0012CB6C VMULAx.xyzw ACC, vf1, vf5x - // @0012CB70 VMADDAy.xyzw ACC, vf2, vf5y - // @0012CB74 VMADDAz.xyzw ACC, vf3, vf5z - // @0012CB78 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012CB7C SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012CB80 ADDIU t6, sp, $0080 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012CB84 BEQL t6, t8, $0012cb98 - if ((this.ee.t6.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1231768u; - // @0012CB88 LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012cb50() - { - this.ee.pc = 1231756u; - // @0012CB50 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012CB54 DADDU s7, t8, zero - this.ee.s7.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); - // @0012CB58 LQC2 vf5, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); - // @0012CB5C LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012CB60 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012CB64 LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012CB68 LQC2 vf4, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); - // @0012CB6C VMULAx.xyzw ACC, vf1, vf5x - // @0012CB70 VMADDAy.xyzw ACC, vf2, vf5y - // @0012CB74 VMADDAz.xyzw ACC, vf3, vf5z - // @0012CB78 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012CB7C SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012CB80 ADDIU t6, sp, $0080 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012CB84 BEQL t6, t8, $0012cb98 - if ((this.ee.t6.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1231768u; - // @0012CB88 LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012cb8c() - { - this.ee.pc = 1231788u; - // @0012CB8C LQ t0, $0000(t8) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); - // @0012CB90 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012CB94 LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - // @0012CB98 ADDIU s3, sp, $0040 - this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 64))); - // @0012CB9C LW t3, $0250(sp) - MobUt.LW(this.ee, this.ee.t3, (592u + this.ee.sp.UL0)); - // @0012CBA0 ADDU t7, t7, t3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t3.SD0))); - // @0012CBA4 BEQ s3, t7, $0012cbcc - if ((this.ee.s3.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1231820u; - } - // @0012CBA8 NOP - MobUt.Latency(); - } - - public virtual void funct0012cbac() - { - this.ee.pc = 1231968u; - // @0012CBAC LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012CBB0 LQ t1, $0010(t7) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); - // @0012CBB4 LQ t2, $0020(t7) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); - // @0012CBB8 LQ t3, $0030(t7) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); - // @0012CBBC SQ t0, $0000(s3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @0012CBC0 SQ t1, $0010(s3) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s3.UL[0])); - // @0012CBC4 SQ t2, $0020(s3) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s3.UL[0])); - // @0012CBC8 SQ t3, $0030(s3) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.s3.UL[0])); - // @0012CBCC LQ t0, $0000(s3) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @0012CBD0 LQ t1, $0010(s3) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.s3.UL[0])); - // @0012CBD4 LQ t2, $0020(s3) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.s3.UL[0])); - // @0012CBD8 QMFC2 t3, vf0 - MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); - // @0012CBDC LQC2 vf4, $0030(s3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); - // @0012CBE0 PEXTLW t4, t1, t0 - this.ee.t4.UL[0] = this.ee.t0.UL[0]; - this.ee.t4.UL[1] = this.ee.t1.UL[0]; - this.ee.t4.UL[2] = this.ee.t0.UL[1]; - this.ee.t4.UL[3] = this.ee.t1.UL[1]; - // @0012CBE4 PEXTUW t5, t1, t0 - this.ee.t5.UL[0] = this.ee.t0.UL[2]; - this.ee.t5.UL[1] = this.ee.t1.UL[2]; - this.ee.t5.UL[2] = this.ee.t0.UL[3]; - this.ee.t5.UL[3] = this.ee.t1.UL[3]; - // @0012CBE8 PEXTLW t6, t3, t2 - this.ee.t6.UL[0] = this.ee.t2.UL[0]; - this.ee.t6.UL[1] = this.ee.t3.UL[0]; - this.ee.t6.UL[2] = this.ee.t2.UL[1]; - this.ee.t6.UL[3] = this.ee.t3.UL[1]; - // @0012CBEC PEXTUW t7, t3, t2 - this.ee.t7.UL[0] = this.ee.t2.UL[2]; - this.ee.t7.UL[1] = this.ee.t3.UL[2]; - this.ee.t7.UL[2] = this.ee.t2.UL[3]; - this.ee.t7.UL[3] = this.ee.t3.UL[3]; - // @0012CBF0 PCPYLD t0, t6, t4 - this.ee.t0.UD1 = this.ee.t6.UD0; - this.ee.t0.UD0 = this.ee.t4.UD0; - // @0012CBF4 PCPYUD t1, t4, t6 - this.ee.t1.UD0 = this.ee.t4.UD1; - this.ee.t1.UD1 = this.ee.t6.UD1; - // @0012CBF8 PCPYLD t2, t7, t5 - this.ee.t2.UD1 = this.ee.t7.UD0; - this.ee.t2.UD0 = this.ee.t5.UD0; - // @0012CBFC QMTC2 t0, vf1 - MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); - // @0012CC00 QMTC2 t1, vf2 - MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); - // @0012CC04 QMTC2 t2, vf3 - MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); - // @0012CC08 VMULAx.xyz ACC, vf1, vf4x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[4].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[4].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[4].x); - // @0012CC0C VMADDAy.xyz ACC, vf2, vf4y - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[4].y); - // @0012CC10 VMADDz.xyz vf4, vf3, vf4z - this.ee.VF[4].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[4].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[4].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[4].z); - // @0012CC14 VSUB.xyz vf4, vf0, vf4 - this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); - this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); - this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); - // @0012CC18 SQ t0, $0000(s3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @0012CC1C SQ t1, $0010(s3) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s3.UL[0])); - // @0012CC20 SQ t2, $0020(s3) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s3.UL[0])); - // @0012CC24 SQC2 vf4, $0030(s3) - MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); - // @0012CC28 ADDIU t4, sp, $0080 - this.ee.t4.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012CC2C LQC2 vf5, $0000(t4) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t4.UL0)); - // @0012CC30 LQC2 vf1, $0000(s3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); - // @0012CC34 LQC2 vf2, $0010(s3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); - // @0012CC38 LQC2 vf3, $0020(s3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); - // @0012CC3C LQC2 vf4, $0030(s3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); - // @0012CC40 VMULAx.xyzw ACC, vf1, vf5x - // @0012CC44 VMADDAy.xyzw ACC, vf2, vf5y - // @0012CC48 VMADDAz.xyzw ACC, vf3, vf5z - // @0012CC4C VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012CC50 SQC2 vf5, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); - // @0012CC54 ADDIU t5, sp, $00a0 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 160))); - // @0012CC58 BEQ t5, t8, $0012cc6c - if ((this.ee.t5.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1231980u; - } - // @0012CC5C LW a2, $0220(sp) - MobUt.LW(this.ee, this.ee.a2, (544u + this.ee.sp.UL0)); - } - - public virtual void funct0012cc60() - { - this.ee.pc = 1232004u; - // @0012CC60 LQ t0, $0000(s7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s7.UL[0])); - // @0012CC64 SQ t0, $0000(t5) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012CC68 LW a2, $0220(sp) - MobUt.LW(this.ee, this.ee.a2, (544u + this.ee.sp.UL0)); - // @0012CC6C ADDIU a3, sp, $0110 - this.ee.a3.SD0 = ((int)((this.ee.sp.SD0 + 272))); - // @0012CC70 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @0012CC74 DADDU a1, s5, zero - this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); - // @0012CC78 DADDU t0, s3, zero - this.ee.t0.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); - // @0012CC7C JAL $00128de8 - this.ee.ra.UL0 = 1232004u; - this.ee.pc = 1215976u; - // @0012CC80 ADDIU t1, sp, $00b0 - this.ee.t1.SD0 = ((int)((this.ee.sp.SD0 + 176))); - } - - public virtual void funct0012cc84() - { - this.ee.pc = 1232016u; - // @0012CC84 LW t6, $0218(sp) - MobUt.LW(this.ee, this.ee.t6, (536u + this.ee.sp.UL0)); - // @0012CC88 BEQ t6, zero, $0012d12c - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233196u; - } - // @0012CC8C ADDIU t7, zero, $0004 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 4))); - } - - public virtual void funct0012cc90() - { - this.ee.pc = 1232028u; - // @0012CC90 LBU t6, $0000(t6) - MobUt.LBU(this.ee, this.ee.t6, (0u + this.ee.t6.UL0)); - // @0012CC94 BNEL t6, t7, $0012d130 - if ((this.ee.t6.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1233200u; - // @0012CC98 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012cc9c() - { - this.ee.pc = 1232056u; - // @0012CC9C LW t7, $0218(sp) - MobUt.LW(this.ee, this.ee.t7, (536u + this.ee.sp.UL0)); - // @0012CCA0 LW t6, $0004(s0) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); - // @0012CCA4 LHU t5, $0004(t7) - MobUt.LHU(this.ee, this.ee.t5, (4u + this.ee.t7.UL0)); - // @0012CCA8 LHU t6, $0010(t6) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); - // @0012CCAC SLT t7, t5, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); - // @0012CCB0 BEQ t7, zero, $0012d120 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233184u; - } - // @0012CCB4 SUBU t7, t5, t6 - this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012ccc0() - { - this.ee.pc = 1232144u; - // @0012CCC0 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012CCC4 ADDIU t7, t6, $0030 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012CCC8 LQC2 vf5, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); - // @0012CCCC LQC2 vf1, $0000(s3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); - // @0012CCD0 LQC2 vf2, $0010(s3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); - // @0012CCD4 LQC2 vf3, $0020(s3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); - // @0012CCD8 LQC2 vf4, $0030(s3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); - // @0012CCDC VMULAx.xyz ACC, vf1, vf5x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); - // @0012CCE0 VMADDAy.xyz ACC, vf2, vf5y - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); - // @0012CCE4 VMADDAz.xyz ACC, vf3, vf5z - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); - // @0012CCE8 VMADDw.xyz vf5, vf4, vf0w - this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); - this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); - this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); - // @0012CCEC VMOVE.w vf5, vf0 - this.ee.VF[5].w = this.ee.VF[0].w; - // @0012CCF0 SQC2 vf5, $0000(s7) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s7.UL0)); - // @0012CCF4 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012CCF8 LW t6, $0014(s0) - MobUt.LW(this.ee, this.ee.t6, (20u + this.ee.s0.UL0)); - // @0012CCFC LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012CD00 ADDU t6, t6, s8 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s8.SD0))); - // @0012CD04 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012CD08 BEQ t7, zero, $0012d104 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233156u; - } - // @0012CD0C SW t6, $0230(sp) - MobUt.SW(this.ee, this.ee.t6, (560u + this.ee.sp.UL0)); - } - - public virtual void funct0012cd10() - { - this.ee.pc = 1232164u; - // @0012CD10 LW a0, $0014(s5) - MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); - // @0012CD14 LW t7, $0000(a0) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); - // @0012CD18 LW v0, $0020(t7) - MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); - // @0012CD1C JALR ra, v0 - this.ee.ra.UD0 = 1232164u; - this.ee.pc = this.ee.v0.UL0; - // @0012CD20 SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - } - - public virtual void funct0012cd24() - { - this.ee.pc = 1232200u; - // @0012CD24 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012CD28 ADDU v0, v0, s3 - this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.s3.SD0))); - // @0012CD2C LW t3, $0230(sp) - MobUt.LW(this.ee, this.ee.t3, (560u + this.ee.sp.UL0)); - // @0012CD30 LWC1 $f0, $001c(v0) - MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); - // @0012CD34 LWC1 $f1, $0000(t3) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t3.UL0)); - // @0012CD38 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012CD3C SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012CD40 BEQ t7, zero, $0012d0f0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233136u; - } - // @0012CD44 MUL.S $f12, $f1, $f0 - this.ee.fpr[12].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct0012cd2c() - { - this.ee.pc = 1232200u; - // @0012CD2C LW t3, $0230(sp) - MobUt.LW(this.ee, this.ee.t3, (560u + this.ee.sp.UL0)); - // @0012CD30 LWC1 $f0, $001c(v0) - MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); - // @0012CD34 LWC1 $f1, $0000(t3) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t3.UL0)); - // @0012CD38 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012CD3C SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012CD40 BEQ t7, zero, $0012d0f0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233136u; - } - // @0012CD44 MUL.S $f12, $f1, $f0 - this.ee.fpr[12].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct0012cd48() - { - this.ee.pc = 1232224u; - // @0012CD48 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012CD4C ADDU a3, t7, s3 - this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012CD50 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012CD54 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012CD58 BEQL t7, zero, $0012d0d8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233112u; - // @0012CD5C LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012cd50() - { - this.ee.pc = 1232224u; - // @0012CD50 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012CD54 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012CD58 BEQL t7, zero, $0012d0d8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233112u; - // @0012CD5C LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012cd60() - { - this.ee.pc = 1232268u; - // @0012CD60 LW t7, $0020(s5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); - // @0012CD64 ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012CD68 LWC1 $f14, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t6.UL0)); - // @0012CD6C ADDIU a0, sp, $00a0 - this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); - // @0012CD70 MTC1 zero, $f13 - this.ee.fpr[13].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @0012CD74 ADDIU a1, sp, $00b0 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); - // @0012CD78 DADDU t1, s7, zero - this.ee.t1.UD0 = (this.ee.s7.UD0 + this.ee.r0.UD0); - // @0012CD7C DADDU a2, zero, zero - this.ee.a2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @0012CD80 DADDU t0, zero, zero - this.ee.t0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @0012CD84 JAL $00124a88 - this.ee.ra.UL0 = 1232268u; - this.ee.pc = 1198728u; - // @0012CD88 MOV.S $f15, $f13 - this.ee.fpr[15].f = this.ee.fpr[13].f; - } - - public virtual void funct0012cd68() - { - this.ee.pc = 1232268u; - // @0012CD68 LWC1 $f14, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t6.UL0)); - // @0012CD6C ADDIU a0, sp, $00a0 - this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); - // @0012CD70 MTC1 zero, $f13 - this.ee.fpr[13].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @0012CD74 ADDIU a1, sp, $00b0 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); - // @0012CD78 DADDU t1, s7, zero - this.ee.t1.UD0 = (this.ee.s7.UD0 + this.ee.r0.UD0); - // @0012CD7C DADDU a2, zero, zero - this.ee.a2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @0012CD80 DADDU t0, zero, zero - this.ee.t0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @0012CD84 JAL $00124a88 - this.ee.ra.UL0 = 1232268u; - this.ee.pc = 1198728u; - // @0012CD88 MOV.S $f15, $f13 - this.ee.fpr[15].f = this.ee.fpr[13].f; - } - - public virtual void funct0012cd84() - { - this.ee.pc = 1232268u; - // @0012CD84 JAL $00124a88 - this.ee.ra.UL0 = 1232268u; - this.ee.pc = 1198728u; - // @0012CD88 MOV.S $f15, $f13 - this.ee.fpr[15].f = this.ee.fpr[13].f; - } - - public virtual void funct0012cd8c() - { - this.ee.pc = 1232284u; - // @0012CD8C LUI t7, $0040 - this.ee.t7.SD0 = 4194304; - // @0012CD90 AND t7, s4, t7 - this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); - // @0012CD94 BEQL t7, zero, $0012cddc - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232348u; - // @0012CD98 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012cd9c() - { - this.ee.pc = 1232304u; - // @0012CD9C LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012CDA0 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012CDA4 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012CDA8 BEQ t7, zero, $0012d0c8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233096u; - } - // @0012CDAC SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012cdb0() - { - this.ee.pc = 1232328u; - // @0012CDB0 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012CDB4 ADDU a0, t7, s3 - this.ee.a0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012CDB8 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012CDBC SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012CDC0 BEQL t7, zero, $0012d0b0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233072u; - // @0012CDC4 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012cdc8() - { - this.ee.pc = 1232344u; - // @0012CDC8 LW t7, $0020(s5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); - // @0012CDCC ADDU a1, t7, s8 - this.ee.a1.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012CDD0 JAL $0011b840 - this.ee.ra.UL0 = 1232344u; - this.ee.pc = 1161280u; - // @0012CDD4 NOP - MobUt.Latency(); - } - - public virtual void funct0012cdd8() - { - this.ee.pc = 1232364u; - // @0012CDD8 LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012CDDC LHU t7, $0010(t7) - MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); - // @0012CDE0 SLT t6, s2, t7 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); - // @0012CDE4 BEQ t6, zero, $0012d0a0 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233056u; - } - // @0012CDE8 SUBU t7, s2, t7 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); - } - - public virtual void funct0012cddc() - { - this.ee.pc = 1232364u; - // @0012CDDC LHU t7, $0010(t7) - MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); - // @0012CDE0 SLT t6, s2, t7 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); - // @0012CDE4 BEQ t6, zero, $0012d0a0 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233056u; - } - // @0012CDE8 SUBU t7, s2, t7 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); - } - - public virtual void funct0012cdec() - { - this.ee.pc = 1232412u; - // @0012CDEC LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012CDF0 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012CDF4 LWC1 $f0, $0090(sp) - MobUt.LWC1(this.ee, this.ee.fpr[0], (144u + this.ee.sp.UL0)); - // @0012CDF8 SWC1 $f0, $0030(t6) - MobUt.SWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t6.UL0)); - // @0012CDFC LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012CE00 LW t6, $0008(s0) - MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); - // @0012CE04 LW t4, $0250(sp) - MobUt.LW(this.ee, this.ee.t4, (592u + this.ee.sp.UL0)); - // @0012CE08 LHU t5, $0010(t7) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t7.UL0)); - // @0012CE0C ADDU t3, t6, t4 - this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t4.SD0))); - // @0012CE10 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012CE14 BEQ t7, zero, $0012d08c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233036u; - } - // @0012CE18 ADDU t4, t6, s3 - this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); - } - - public virtual void funct0012cdf4() - { - this.ee.pc = 1232412u; - // @0012CDF4 LWC1 $f0, $0090(sp) - MobUt.LWC1(this.ee, this.ee.fpr[0], (144u + this.ee.sp.UL0)); - // @0012CDF8 SWC1 $f0, $0030(t6) - MobUt.SWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t6.UL0)); - // @0012CDFC LW t7, $0004(s0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); - // @0012CE00 LW t6, $0008(s0) - MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); - // @0012CE04 LW t4, $0250(sp) - MobUt.LW(this.ee, this.ee.t4, (592u + this.ee.sp.UL0)); - // @0012CE08 LHU t5, $0010(t7) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t7.UL0)); - // @0012CE0C ADDU t3, t6, t4 - this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t4.SD0))); - // @0012CE10 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012CE14 BEQ t7, zero, $0012d08c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233036u; - } - // @0012CE18 ADDU t4, t6, s3 - this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); - } - - public virtual void funct0012ce1c() - { - this.ee.pc = 1232544u; - // @0012CE1C LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012CE20 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012CE24 ADDIU t5, sp, $0130 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 304))); - // @0012CE28 LQC2 vf1, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); - // @0012CE2C LQC2 vf2, $0010(t3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); - // @0012CE30 LQC2 vf3, $0020(t3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); - // @0012CE34 LQC2 vf4, $0030(t3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); - // @0012CE38 LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012CE3C LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012CE40 LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012CE44 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012CE48 VMULAx.xyzw ACC, vf1, vf5x - // @0012CE4C VMADDAy.xyzw ACC, vf2, vf5y - // @0012CE50 VMADDAz.xyzw ACC, vf3, vf5z - // @0012CE54 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012CE58 VMULAx.xyzw ACC, vf1, vf6x - // @0012CE5C VMADDAy.xyzw ACC, vf2, vf6y - // @0012CE60 VMADDAz.xyzw ACC, vf3, vf6z - // @0012CE64 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012CE68 VMULAx.xyzw ACC, vf1, vf7x - // @0012CE6C VMADDAy.xyzw ACC, vf2, vf7y - // @0012CE70 VMADDAz.xyzw ACC, vf3, vf7z - // @0012CE74 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012CE78 VMULAx.xyzw ACC, vf1, vf8x - // @0012CE7C VMADDAy.xyzw ACC, vf2, vf8y - // @0012CE80 VMADDAz.xyzw ACC, vf3, vf8z - // @0012CE84 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012CE88 SQC2 vf5, $0000(t5) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); - // @0012CE8C SQC2 vf6, $0010(t5) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t5.UL0)); - // @0012CE90 SQC2 vf7, $0020(t5) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t5.UL0)); - // @0012CE94 SQC2 vf8, $0030(t5) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t5.UL0)); - // @0012CE98 BEQL t4, t5, $0012cec4 - if ((this.ee.t4.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1232580u; - // @0012CE9C LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012ce24() - { - this.ee.pc = 1232544u; - // @0012CE24 ADDIU t5, sp, $0130 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 304))); - // @0012CE28 LQC2 vf1, $0000(t3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); - // @0012CE2C LQC2 vf2, $0010(t3) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); - // @0012CE30 LQC2 vf3, $0020(t3) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); - // @0012CE34 LQC2 vf4, $0030(t3) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); - // @0012CE38 LQC2 vf5, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); - // @0012CE3C LQC2 vf6, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); - // @0012CE40 LQC2 vf7, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); - // @0012CE44 LQC2 vf8, $0030(t6) - MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); - // @0012CE48 VMULAx.xyzw ACC, vf1, vf5x - // @0012CE4C VMADDAy.xyzw ACC, vf2, vf5y - // @0012CE50 VMADDAz.xyzw ACC, vf3, vf5z - // @0012CE54 VMADDw.xyzw vf5, vf4, vf5w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); - // @0012CE58 VMULAx.xyzw ACC, vf1, vf6x - // @0012CE5C VMADDAy.xyzw ACC, vf2, vf6y - // @0012CE60 VMADDAz.xyzw ACC, vf3, vf6z - // @0012CE64 VMADDw.xyzw vf6, vf4, vf6w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); - // @0012CE68 VMULAx.xyzw ACC, vf1, vf7x - // @0012CE6C VMADDAy.xyzw ACC, vf2, vf7y - // @0012CE70 VMADDAz.xyzw ACC, vf3, vf7z - // @0012CE74 VMADDw.xyzw vf7, vf4, vf7w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); - // @0012CE78 VMULAx.xyzw ACC, vf1, vf8x - // @0012CE7C VMADDAy.xyzw ACC, vf2, vf8y - // @0012CE80 VMADDAz.xyzw ACC, vf3, vf8z - // @0012CE84 VMADDw.xyzw vf8, vf4, vf8w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); - // @0012CE88 SQC2 vf5, $0000(t5) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); - // @0012CE8C SQC2 vf6, $0010(t5) - MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t5.UL0)); - // @0012CE90 SQC2 vf7, $0020(t5) - MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t5.UL0)); - // @0012CE94 SQC2 vf8, $0030(t5) - MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t5.UL0)); - // @0012CE98 BEQL t4, t5, $0012cec4 - if ((this.ee.t4.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1232580u; - // @0012CE9C LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - } - } - - public virtual void funct0012cea0() - { - this.ee.pc = 1232596u; - // @0012CEA0 LQ t0, $0000(t5) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012CEA4 LQ t1, $0010(t5) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); - // @0012CEA8 LQ t2, $0020(t5) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); - // @0012CEAC LQ t3, $0030(t5) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); - // @0012CEB0 SQ t0, $0000(t4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); - // @0012CEB4 SQ t1, $0010(t4) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); - // @0012CEB8 SQ t2, $0020(t4) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); - // @0012CEBC SQ t3, $0030(t4) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); - // @0012CEC0 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012CEC4 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012CEC8 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012CECC BEQ t7, zero, $0012d07c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233020u; - } - // @0012CED0 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012ced4() - { - this.ee.pc = 1232620u; - // @0012CED4 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012CED8 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012CEDC LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - // @0012CEE0 ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012CEE4 BEQL t6, t7, $0012cf14 - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1232660u; - // @0012CEE8 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012cedc() - { - this.ee.pc = 1232620u; - // @0012CEDC LW t7, $0008(s0) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); - // @0012CEE0 ADDU t7, t7, s3 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012CEE4 BEQL t6, t7, $0012cf14 - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1232660u; - // @0012CEE8 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012ceec() - { - this.ee.pc = 1232672u; - // @0012CEEC LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0012CEF0 LQ t1, $0010(t7) - MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); - // @0012CEF4 LQ t2, $0020(t7) - MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); - // @0012CEF8 LQ t3, $0030(t7) - MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); - // @0012CEFC SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012CF00 SQ t1, $0010(t6) - MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); - // @0012CF04 SQ t2, $0020(t6) - MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); - // @0012CF08 SQ t3, $0030(t6) - MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); - // @0012CF0C LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012CF10 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012CF14 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012CF18 BEQ t7, zero, $0012d06c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233004u; - } - // @0012CF1C SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012cf20() - { - this.ee.pc = 1232748u; - // @0012CF20 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012CF24 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012CF28 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @0012CF2C ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012CF30 LQC2 vf4, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); - // @0012CF34 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012CF38 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012CF3C LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012CF40 VMULx.xyzw vf1, vf1, vf4x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); - // @0012CF44 VMULy.xyzw vf2, vf2, vf4y - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); - this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); - // @0012CF48 VMULz.xyzw vf3, vf3, vf4z - this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); - this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); - // @0012CF4C SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012CF50 SQC2 vf2, $0010(t6) - MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012CF54 SQC2 vf3, $0020(t6) - MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012CF58 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012CF5C LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012CF60 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012CF64 BEQ t7, zero, $0012d05c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232988u; - } - // @0012CF68 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012cf28() - { - this.ee.pc = 1232748u; - // @0012CF28 LW t7, $0014(s0) - MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); - // @0012CF2C ADDU t7, t7, s8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012CF30 LQC2 vf4, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); - // @0012CF34 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012CF38 LQC2 vf2, $0010(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012CF3C LQC2 vf3, $0020(t6) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012CF40 VMULx.xyzw vf1, vf1, vf4x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); - // @0012CF44 VMULy.xyzw vf2, vf2, vf4y - this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); - this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); - this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); - this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); - // @0012CF48 VMULz.xyzw vf3, vf3, vf4z - this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); - this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); - this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); - this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); - // @0012CF4C SQC2 vf1, $0000(t6) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0012CF50 SQC2 vf2, $0010(t6) - MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); - // @0012CF54 SQC2 vf3, $0020(t6) - MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); - // @0012CF58 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012CF5C LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012CF60 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012CF64 BEQ t7, zero, $0012d05c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232988u; - } - // @0012CF68 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012cf6c() - { - this.ee.pc = 1232772u; - // @0012CF6C LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012CF70 ADDU t6, t7, s3 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012CF74 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012CF78 ADDIU t5, sp, $0080 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012CF7C BEQL t6, t5, $0012cf94 - if ((this.ee.t6.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1232788u; - // @0012CF80 LW t6, $0220(sp) - MobUt.LW(this.ee, this.ee.t6, (544u + this.ee.sp.UL0)); - } - } - - public virtual void funct0012cf74() - { - this.ee.pc = 1232772u; - // @0012CF74 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - // @0012CF78 ADDIU t5, sp, $0080 - this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @0012CF7C BEQL t6, t5, $0012cf94 - if ((this.ee.t6.UD0 == this.ee.t5.UD0)) - { - this.ee.pc = 1232788u; - // @0012CF80 LW t6, $0220(sp) - MobUt.LW(this.ee, this.ee.t6, (544u + this.ee.sp.UL0)); - } - } - - public virtual void funct0012cf84() - { - this.ee.pc = 1232812u; - // @0012CF84 LQ t0, $0000(t5) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); - // @0012CF88 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012CF8C LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012CF90 LW t6, $0220(sp) - MobUt.LW(this.ee, this.ee.t6, (544u + this.ee.sp.UL0)); - // @0012CF94 LHU a2, $0002(t6) - MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.t6.UL0)); - // @0012CF98 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012CF9C ANDI t5, a2, $ffff - this.ee.t5.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); - // @0012CFA0 SLT t7, t5, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); - // @0012CFA4 BEQ t7, zero, $0012d050 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232976u; - } - // @0012CFA8 SUBU t7, t5, t6 - this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.t6.UD0))); - } - - public virtual void funct0012cfac() - { - this.ee.pc = 1232840u; - // @0012CFAC LW t6, $002c(s5) - MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); - // @0012CFB0 SLL t7, t5, 6 - MobUt.SLL(this.ee.t7, this.ee.t5, 6); - // @0012CFB4 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012CFB8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012CFBC SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012CFC0 BEQ t7, zero, $0012d03c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232956u; - } - // @0012CFC4 ADDIU t3, t6, $0030 - this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012cfb4() - { - this.ee.pc = 1232840u; - // @0012CFB4 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012CFB8 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012CFBC SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012CFC0 BEQ t7, zero, $0012d03c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232956u; - } - // @0012CFC4 ADDIU t3, t6, $0030 - this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012cfc8() - { - this.ee.pc = 1232868u; - // @0012CFC8 LW t7, $002c(s5) - MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); - // @0012CFCC ADDU v0, t7, s3 - this.ee.v0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012CFD0 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012CFD4 ANDI a2, a2, $ffff - this.ee.a2.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); - // @0012CFD8 SLT t7, a2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); - // @0012CFDC BEQ t7, zero, $0012d020 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232928u; - } - // @0012CFE0 SLL t7, a2, 4 - MobUt.SLL(this.ee.t7, this.ee.a2, 4); - } - - public virtual void funct0012cfd0() - { - this.ee.pc = 1232868u; - // @0012CFD0 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012CFD4 ANDI a2, a2, $ffff - this.ee.a2.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); - // @0012CFD8 SLT t7, a2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); - // @0012CFDC BEQ t7, zero, $0012d020 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232928u; - } - // @0012CFE0 SLL t7, a2, 4 - MobUt.SLL(this.ee.t7, this.ee.a2, 4); - } - - public virtual void funct0012cfe4() - { - this.ee.pc = 1232928u; - // @0012CFE4 LW t6, $0024(s5) - MobUt.LW(this.ee, this.ee.t6, (36u + this.ee.s5.UL0)); - // @0012CFE8 ADDU a2, t6, t7 - this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012CFEC LQC2 vf5, $0000(a2) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.a2.UL0)); - // @0012CFF0 LQC2 vf1, $0000(v0) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.v0.UL0)); - // @0012CFF4 LQC2 vf2, $0010(v0) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.v0.UL0)); - // @0012CFF8 LQC2 vf3, $0020(v0) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.v0.UL0)); - // @0012CFFC LQC2 vf4, $0030(v0) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.v0.UL0)); - // @0012D000 VMULAx.xyz ACC, vf1, vf5x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); - // @0012D004 VMADDAy.xyz ACC, vf2, vf5y - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); - // @0012D008 VMADDAz.xyz ACC, vf3, vf5z - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); - // @0012D00C VMADDw.xyz vf5, vf4, vf0w - this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); - this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); - this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); - // @0012D010 VMOVE.w vf5, vf0 - this.ee.VF[5].w = this.ee.VF[0].w; - // @0012D014 SQC2 vf5, $0000(t3) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); - // @0012D018 BEQ zero, zero, $00129e60 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220192u; - } - // @0012D01C LW t3, $01f4(sp) - MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); - } - - public virtual void funct0012cfec() - { - this.ee.pc = 1232928u; - // @0012CFEC LQC2 vf5, $0000(a2) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.a2.UL0)); - // @0012CFF0 LQC2 vf1, $0000(v0) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.v0.UL0)); - // @0012CFF4 LQC2 vf2, $0010(v0) - MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.v0.UL0)); - // @0012CFF8 LQC2 vf3, $0020(v0) - MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.v0.UL0)); - // @0012CFFC LQC2 vf4, $0030(v0) - MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.v0.UL0)); - // @0012D000 VMULAx.xyz ACC, vf1, vf5x - this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); - this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); - this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); - // @0012D004 VMADDAy.xyz ACC, vf2, vf5y - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); - // @0012D008 VMADDAz.xyz ACC, vf3, vf5z - this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); - this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); - this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); - // @0012D00C VMADDw.xyz vf5, vf4, vf0w - this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); - this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); - this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); - // @0012D010 VMOVE.w vf5, vf0 - this.ee.VF[5].w = this.ee.VF[0].w; - // @0012D014 SQC2 vf5, $0000(t3) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); - // @0012D018 BEQ zero, zero, $00129e60 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220192u; - } - // @0012D01C LW t3, $01f4(sp) - MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); - } - - public virtual void funct0012d020() - { - this.ee.pc = 1232956u; - // @0012D020 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - // @0012D024 SUBU t7, a2, t5 - this.ee.t7.SD0 = ((int)((this.ee.a2.UD0 - this.ee.t5.UD0))); - // @0012D028 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D02C ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012D030 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D034 BEQ zero, zero, $0012cfec - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232876u; - } - // @0012D038 ADDIU a2, t6, $0030 - this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012d03c() - { - this.ee.pc = 1232976u; - // @0012D03C SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012D040 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012D044 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D048 BEQ zero, zero, $0012cfd0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232848u; - } - // @0012D04C ADDU v0, t6, t7 - this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012d050() - { - this.ee.pc = 1232988u; - // @0012D050 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012D054 BEQ zero, zero, $0012cfb4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232820u; - } - // @0012D058 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012d05c() - { - this.ee.pc = 1233004u; - // @0012D05C LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012D060 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D064 BEQ zero, zero, $0012cf74 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232756u; - } - // @0012D068 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012d06c() - { - this.ee.pc = 1233020u; - // @0012D06C LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012D070 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D074 BEQ zero, zero, $0012cf28 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232680u; - } - // @0012D078 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012d07c() - { - this.ee.pc = 1233036u; - // @0012D07C LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012D080 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D084 BEQ zero, zero, $0012cedc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232604u; - } - // @0012D088 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012d08c() - { - this.ee.pc = 1233056u; - // @0012D08C SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012D090 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012D094 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D098 BEQ zero, zero, $0012ce24 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232420u; - } - // @0012D09C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012d0a0() - { - this.ee.pc = 1233072u; - // @0012D0A0 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012D0A4 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D0A8 BEQ zero, zero, $0012cdf4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232372u; - } - // @0012D0AC ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012d0d8() - { - this.ee.pc = 1233136u; - // @0012D0D8 SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012D0DC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D0E0 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012D0E4 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D0E8 BEQ zero, zero, $0012cd68 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232232u; - } - // @0012D0EC ADDIU t6, t6, $0020 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); - } - - public virtual void funct0012d0f0() - { - this.ee.pc = 1233156u; - // @0012D0F0 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - // @0012D0F4 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012D0F8 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D0FC BEQ zero, zero, $0012cd50 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232208u; - } - // @0012D100 ADDU a3, t6, t7 - this.ee.a3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012d104() - { - this.ee.pc = 1233184u; - // @0012D104 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - // @0012D108 SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012D10C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D110 SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - // @0012D114 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012D118 BEQ zero, zero, $0012cd2c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232172u; - } - // @0012D11C ADDU v0, t6, t7 - this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012d120() - { - this.ee.pc = 1233196u; - // @0012D120 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012D124 BEQ zero, zero, $0012ccc0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232064u; - } - // @0012D128 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - } - - public virtual void funct0012d12c() - { - this.ee.pc = 1233220u; - // @0012D12C LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012D130 LW t6, $0014(s0) - MobUt.LW(this.ee, this.ee.t6, (20u + this.ee.s0.UL0)); - // @0012D134 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012D138 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012D13C BEQ t7, zero, $0012d1e4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233380u; - } - // @0012D140 ADDU s7, t6, s8 - this.ee.s7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s8.SD0))); - } - - public virtual void funct0012d144() - { - this.ee.pc = 1233240u; - // @0012D144 LW a0, $0014(s5) - MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); - // @0012D148 LW t7, $0000(a0) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); - // @0012D14C LW v0, $0020(t7) - MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); - // @0012D150 JALR ra, v0 - this.ee.ra.UD0 = 1233240u; - this.ee.pc = this.ee.v0.UL0; - // @0012D154 SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - } - - public virtual void funct0012d158() - { - this.ee.pc = 1233272u; - // @0012D158 LW t4, $0004(s0) - MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); - // @0012D15C ADDU v0, v0, s3 - this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.s3.SD0))); - // @0012D160 LWC1 $f1, $0000(s7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s7.UL0)); - // @0012D164 LWC1 $f0, $001c(v0) - MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); - // @0012D168 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012D16C SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012D170 BEQ t7, zero, $0012d1d0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233360u; - } - // @0012D174 MUL.S $f12, $f1, $f0 - this.ee.fpr[12].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct0012d160() - { - this.ee.pc = 1233272u; - // @0012D160 LWC1 $f1, $0000(s7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s7.UL0)); - // @0012D164 LWC1 $f0, $001c(v0) - MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); - // @0012D168 LHU t6, $0010(t4) - MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); - // @0012D16C SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @0012D170 BEQ t7, zero, $0012d1d0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233360u; - } - // @0012D174 MUL.S $f12, $f1, $f0 - this.ee.fpr[12].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct0012d178() - { - this.ee.pc = 1233296u; - // @0012D178 LW t7, $0028(s5) - MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); - // @0012D17C ADDU a3, t7, s3 - this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); - // @0012D180 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012D184 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012D188 BEQL t7, zero, $0012d1b8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233336u; - // @0012D18C LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012d180() - { - this.ee.pc = 1233296u; - // @0012D180 LHU t5, $0010(t4) - MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); - // @0012D184 SLT t7, s2, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); - // @0012D188 BEQL t7, zero, $0012d1b8 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233336u; - // @0012D18C LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - } - } - - public virtual void funct0012d190() - { - this.ee.pc = 1233336u; - // @0012D190 LW t7, $0020(s5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); - // @0012D194 ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012D198 LWC1 $f14, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t6.UL0)); - // @0012D19C ADDIU a0, sp, $00a0 - this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); - // @0012D1A0 MTC1 zero, $f13 - this.ee.fpr[13].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @0012D1A4 ADDIU a1, sp, $00b0 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); - // @0012D1A8 DADDU a2, zero, zero - this.ee.a2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @0012D1AC DADDU t0, zero, zero - this.ee.t0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @0012D1B0 BEQ zero, zero, $0012cd84 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232260u; - } - // @0012D1B4 DADDU t1, zero, zero - this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012d198() - { - this.ee.pc = 1233336u; - // @0012D198 LWC1 $f14, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t6.UL0)); - // @0012D19C ADDIU a0, sp, $00a0 - this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); - // @0012D1A0 MTC1 zero, $f13 - this.ee.fpr[13].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @0012D1A4 ADDIU a1, sp, $00b0 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); - // @0012D1A8 DADDU a2, zero, zero - this.ee.a2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @0012D1AC DADDU t0, zero, zero - this.ee.t0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @0012D1B0 BEQ zero, zero, $0012cd84 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1232260u; - } - // @0012D1B4 DADDU t1, zero, zero - this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012d1b8() - { - this.ee.pc = 1233360u; - // @0012D1B8 SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012D1BC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D1C0 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012D1C4 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D1C8 BEQ zero, zero, $0012d198 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233304u; - } - // @0012D1CC ADDIU t6, t6, $0020 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); - } - - public virtual void funct0012d1d0() - { - this.ee.pc = 1233380u; - // @0012D1D0 SUBU t7, s2, t6 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); - // @0012D1D4 LW t6, $000c(s0) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @0012D1D8 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D1DC BEQ zero, zero, $0012d180 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233280u; - } - // @0012D1E0 ADDU a3, t6, t7 - this.ee.a3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012d1e4() - { - this.ee.pc = 1233408u; - // @0012D1E4 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - // @0012D1E8 SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012D1EC SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D1F0 SLL s3, s2, 6 - MobUt.SLL(this.ee.s3, this.ee.s2, 6); - // @0012D1F4 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012D1F8 BEQ zero, zero, $0012d160 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233248u; - } - // @0012D1FC ADDU v0, t6, t7 - this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012d200() - { - this.ee.pc = 1233432u; - // @0012D200 SUBU t7, t4, t6 - this.ee.t7.SD0 = ((int)((this.ee.t4.UD0 - this.ee.t6.UD0))); - // @0012D204 LW t6, $0010(s0) - MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @0012D208 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D20C SW t5, $0250(sp) - MobUt.SW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); - // @0012D210 BEQ zero, zero, $0012cb50 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231696u; - } - // @0012D214 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0012d218() - { - this.ee.pc = 1233460u; - // @0012D218 LW t6, $0018(t4) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); - // @0012D21C SUBU t7, s2, t5 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); - // @0012D220 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D224 ADDU t6, t4, t6 - this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); - // @0012D228 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D22C BEQ zero, zero, $0012cb0c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1231628u; - } - // @0012D230 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012d234() - { - this.ee.pc = 1233484u; - // @0012D234 SUBU t7, s2, t4 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); - // @0012D238 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D23C ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012D240 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D244 BEQ zero, zero, $00129dd0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220048u; - } - // @0012D248 ADDIU t5, t6, $0010 - this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + 16))); - } - - public virtual void funct0012d24c() - { - this.ee.pc = 1233508u; - // @0012D24C SUBU t7, s2, t4 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); - // @0012D250 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D254 ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012D258 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D25C BEQ zero, zero, $00129d90 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219984u; - } - // @0012D260 ADDIU t5, t6, $0010 - this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + 16))); - } - - public virtual void funct0012d264() - { - this.ee.pc = 1233532u; - // @0012D264 SUBU t7, s2, t4 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); - // @0012D268 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D26C ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012D270 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D274 BEQ zero, zero, $00129d4c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219916u; - } - // @0012D278 ADDIU t5, t6, $0010 - this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + 16))); - } - - public virtual void funct0012d2c8() - { - this.ee.pc = 1233616u; - // @0012D2C8 BLTZ t7, $0012d33c - if ((this.ee.t7.SD0 < 0)) - { - this.ee.pc = 1233724u; - } - // @0012D2CC SLL t7, t7, 4 - MobUt.SLL(this.ee.t7, this.ee.t7, 4); - } - - public virtual void funct0012d2d0() - { - this.ee.pc = 1233644u; - // @0012D2D0 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @0012D2D4 LW t6, $0014(s0) - MobUt.LW(this.ee, this.ee.t6, (20u + this.ee.s0.UL0)); - // @0012D2D8 LHU t3, $0010(t5) - MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t5.UL0)); - // @0012D2DC ADDU t2, t6, t7 - this.ee.t2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D2E0 SLT t7, s2, t3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); - // @0012D2E4 BEQ t7, zero, $0012d320 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233696u; - } - // @0012D2E8 ADDU t4, t6, s8 - this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s8.SD0))); - } - - public virtual void funct0012d2ec() - { - this.ee.pc = 1233680u; - // @0012D2EC LW t7, $001c(s5) - MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); - // @0012D2F0 ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012D2F4 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012D2F8 LQC2 vf1, $0000(t2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); - // @0012D2FC LQC2 vf2, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); - // @0012D300 VMUL.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].w); - // @0012D304 SQC2 vf1, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t8.UL0)); - // @0012D308 BEQL t4, t8, $00129df8 - if ((this.ee.t4.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1220088u; - // @0012D30C LUI t7, $0020 - this.ee.t7.SD0 = 2097152; - } - } - - public virtual void funct0012d2f4() - { - this.ee.pc = 1233680u; - // @0012D2F4 ADDIU t8, sp, $0120 - this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); - // @0012D2F8 LQC2 vf1, $0000(t2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); - // @0012D2FC LQC2 vf2, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); - // @0012D300 VMUL.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].w); - // @0012D304 SQC2 vf1, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t8.UL0)); - // @0012D308 BEQL t4, t8, $00129df8 - if ((this.ee.t4.UD0 == this.ee.t8.UD0)) - { - this.ee.pc = 1220088u; - // @0012D30C LUI t7, $0020 - this.ee.t7.SD0 = 2097152; - } - } - - public virtual void funct0012d310() - { - this.ee.pc = 1233696u; - // @0012D310 LQ t0, $0000(t8) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); - // @0012D314 SQ t0, $0000(t4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); - // @0012D318 BEQ zero, zero, $00129df8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220088u; - } - // @0012D31C LUI t7, $0020 - this.ee.t7.SD0 = 2097152; - } - - public virtual void funct0012d320() - { - this.ee.pc = 1233724u; - // @0012D320 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - // @0012D324 SUBU t7, s2, t3 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); - // @0012D328 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D32C ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012D330 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D334 BEQ zero, zero, $0012d2f4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233652u; - } - // @0012D338 ADDIU t6, t6, $0010 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 16))); - } - - public virtual void funct0012d33c() - { - this.ee.pc = 1233748u; - // @0012D33C LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @0012D340 LW t6, $0014(s0) - MobUt.LW(this.ee, this.ee.t6, (20u + this.ee.s0.UL0)); - // @0012D344 LHU t3, $0010(t5) - MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t5.UL0)); - // @0012D348 SLT t7, s2, t3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); - // @0012D34C BEQ t7, zero, $0012d374 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233780u; - } - // @0012D350 ADDU t4, t6, s8 - this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s8.SD0))); - } - - public virtual void funct0012d354() - { - this.ee.pc = 1233764u; - // @0012D354 LW t7, $001c(s5) - MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); - // @0012D358 ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012D35C BEQL t4, t6, $00129df8 - if ((this.ee.t4.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1220088u; - // @0012D360 LUI t7, $0020 - this.ee.t7.SD0 = 2097152; - } - } - - public virtual void funct0012d35c() - { - this.ee.pc = 1233764u; - // @0012D35C BEQL t4, t6, $00129df8 - if ((this.ee.t4.UD0 == this.ee.t6.UD0)) - { - this.ee.pc = 1220088u; - // @0012D360 LUI t7, $0020 - this.ee.t7.SD0 = 2097152; - } - } - - public virtual void funct0012d364() - { - this.ee.pc = 1233780u; - // @0012D364 LQ t0, $0000(t6) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0012D368 SQ t0, $0000(t4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); - // @0012D36C BEQ zero, zero, $00129df8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1220088u; - } - // @0012D370 LUI t7, $0020 - this.ee.t7.SD0 = 2097152; - } - - public virtual void funct0012d374() - { - this.ee.pc = 1233808u; - // @0012D374 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - // @0012D378 SUBU t7, s2, t3 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); - // @0012D37C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D380 ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012D384 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D388 BEQ zero, zero, $0012d35c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1233756u; - } - // @0012D38C ADDIU t6, t6, $0010 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 16))); - } - - public virtual void funct0012d390() - { - this.ee.pc = 1233820u; - // @0012D390 SW s1, $0220(sp) - MobUt.SW(this.ee, this.ee.s1, (544u + this.ee.sp.UL0)); - // @0012D394 BEQ zero, zero, $00129ce4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219812u; - } - // @0012D398 ADDIU s1, s1, $000c - this.ee.s1.SD0 = ((int)((this.ee.s1.SD0 + 12))); - } - - public virtual void funct0012d39c() - { - this.ee.pc = 1233844u; - // @0012D39C LUI t7, $0001 - this.ee.t7.SD0 = 65536; - // @0012D3A0 ADDIU t5, s2, $0001 - this.ee.t5.SD0 = ((int)((this.ee.s2.SD0 + 1))); - // @0012D3A4 XOR t7, t6, t7 - MobUt.XOR(this.ee.t7, this.ee.t6, this.ee.t7); - // @0012D3A8 ADDIU t6, s2, $0002 - this.ee.t6.SD0 = ((int)((this.ee.s2.SD0 + 2))); - // @0012D3AC BEQ zero, zero, $00129c84 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219716u; - } - // @0012D3B0 MOVN t5, t6, t7 - if ((this.ee.t7.UD0 != 0)) - { - this.ee.t5.UD0 = this.ee.t6.UD0; - } - } - - public virtual void funct0012d3b4() - { - this.ee.pc = 1233852u; - // @0012D3B4 BEQL a3, t7, $00129c3c - if ((this.ee.a3.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1219644u; - // @0012D3B8 LHU a3, $0004(s1) - MobUt.LHU(this.ee, this.ee.a3, (4u + this.ee.s1.UL0)); - } - } - - public virtual void funct0012d3c8() - { - this.ee.pc = 1233872u; - // @0012D3C8 BEQ zero, zero, $00129c3c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219644u; - } - // @0012D3CC SW s1, $0218(sp) - MobUt.SW(this.ee, this.ee.s1, (536u + this.ee.sp.UL0)); - } - - public virtual void funct0012d3e0() - { - this.ee.pc = 1233896u; - // @0012D3E0 BEQ zero, zero, $00129c3c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219644u; - } - // @0012D3E4 DADDU t3, s1, zero - this.ee.t3.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0012d3e8() - { - this.ee.pc = 1233936u; - // @0012D3E8 LW t7, $01fc(sp) - MobUt.LW(this.ee, this.ee.t7, (508u + this.ee.sp.UL0)); - // @0012D3EC LHU t5, $0006(s1) - MobUt.LHU(this.ee, this.ee.t5, (6u + this.ee.s1.UL0)); - // @0012D3F0 LW t6, $005c(t7) - MobUt.LW(this.ee, this.ee.t6, (92u + this.ee.t7.UL0)); - // @0012D3F4 LHU v1, $0004(s1) - MobUt.LHU(this.ee, this.ee.v1, (4u + this.ee.s1.UL0)); - // @0012D3F8 ADDIU t7, zero, $0030 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 48))); - // @0012D3FC MULT t5, t5, t7 - this.ee.t5.SD0 = (((long)(this.ee.t5.SL0)) * ((long)(this.ee.t7.SL0))); - // @0012D400 LW t7, $01fc(sp) - MobUt.LW(this.ee, this.ee.t7, (508u + this.ee.sp.UL0)); - // @0012D404 ADDU t6, t7, t6 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @0012D408 BEQ zero, zero, $00129c3c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219644u; - } - // @0012D40C ADDU v0, t6, t5 - this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); - } - - public virtual void funct0012d410() - { - this.ee.pc = 1233976u; - // @0012D410 LW t6, $01fc(sp) - MobUt.LW(this.ee, this.ee.t6, (508u + this.ee.sp.UL0)); - // @0012D414 LHU t5, $0006(s1) - MobUt.LHU(this.ee, this.ee.t5, (6u + this.ee.s1.UL0)); - // @0012D418 LW t7, $005c(t6) - MobUt.LW(this.ee, this.ee.t7, (92u + this.ee.t6.UL0)); - // @0012D41C ADDIU t6, zero, $0030 - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 48))); - // @0012D420 MULT t5, t5, t6 - this.ee.t5.SD0 = (((long)(this.ee.t5.SL0)) * ((long)(this.ee.t6.SL0))); - // @0012D424 LW t6, $01fc(sp) - MobUt.LW(this.ee, this.ee.t6, (508u + this.ee.sp.UL0)); - // @0012D428 ADDU t7, t6, t7 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D42C ADDU t7, t7, t5 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); - // @0012D430 BEQ zero, zero, $00129c3c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219644u; - } - // @0012D434 SW t7, $021c(sp) - MobUt.SW(this.ee, this.ee.t7, (540u + this.ee.sp.UL0)); - } - - public virtual void funct0012d438() - { - this.ee.pc = 1234000u; - // @0012D438 SUBU t7, s2, t3 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); - // @0012D43C SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D440 ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012D444 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D448 BEQ zero, zero, $00129b90 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219472u; - } - // @0012D44C ADDIU t6, t6, $0010 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 16))); - } - - public virtual void funct0012d450() - { - this.ee.pc = 1234020u; - // @0012D450 LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @0012D454 LHU t3, $0010(t5) - MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t5.UL0)); - // @0012D458 SLT t7, s2, t3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); - // @0012D45C BEQL t7, zero, $0012d494 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1234068u; - // @0012D460 LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct0012d464() - { - this.ee.pc = 1234068u; - // @0012D464 LW t7, $0020(s5) - MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); - // @0012D468 ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012D46C ANDI t7, t4, $ffff - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @0012D470 LUI t4, $0038 - this.ee.t4.SD0 = 3670016; - // @0012D474 ADDIU t7, t7, $fffd - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -3))); - // @0012D478 ADDIU t4, t4, $8360 - this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + -31904))); - // @0012D47C SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @0012D480 LWC1 $f0, $0000(t4) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t4.UL0)); - // @0012D484 ADDU t7, t6, t7 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D488 MUL.S $f0, $f1, $f0 - this.ee.fpr[0].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - // @0012D48C BEQ zero, zero, $00129ba0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219488u; - } - // @0012D490 SWC1 $f0, $0000(t7) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - } - - public virtual void funct0012d46c() - { - this.ee.pc = 1234068u; - // @0012D46C ANDI t7, t4, $ffff - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @0012D470 LUI t4, $0038 - this.ee.t4.SD0 = 3670016; - // @0012D474 ADDIU t7, t7, $fffd - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -3))); - // @0012D478 ADDIU t4, t4, $8360 - this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + -31904))); - // @0012D47C SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @0012D480 LWC1 $f0, $0000(t4) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t4.UL0)); - // @0012D484 ADDU t7, t6, t7 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D488 MUL.S $f0, $f1, $f0 - this.ee.fpr[0].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - // @0012D48C BEQ zero, zero, $00129ba0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219488u; - } - // @0012D490 SWC1 $f0, $0000(t7) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - } - - public virtual void funct0012d494() - { - this.ee.pc = 1234092u; - // @0012D494 SUBU t7, s2, t3 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); - // @0012D498 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D49C ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012D4A0 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D4A4 BEQ zero, zero, $0012d46c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1234028u; - } - // @0012D4A8 ADDIU t6, t6, $0020 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); - } - - public virtual void funct0012d4ac() - { - this.ee.pc = 1234112u; - // @0012D4AC LW t5, $0004(s0) - MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); - // @0012D4B0 LHU t3, $0010(t5) - MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t5.UL0)); - // @0012D4B4 SLT t7, s2, t3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); - // @0012D4B8 BEQL t7, zero, $0012d4d4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1234132u; - // @0012D4BC LW t6, $0018(t5) - MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); - } - } - - public virtual void funct0012d4c0() - { - this.ee.pc = 1234132u; - // @0012D4C0 LW t7, $0024(s5) - MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s5.UL0)); - // @0012D4C4 ADDU t6, t7, s8 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); - // @0012D4C8 ANDI t7, t4, $ffff - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @0012D4CC BEQ zero, zero, $00129b94 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219476u; - } - // @0012D4D0 ADDIU t7, t7, $fffa - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -6))); - } - - public virtual void funct0012d4c8() - { - this.ee.pc = 1234132u; - // @0012D4C8 ANDI t7, t4, $ffff - this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); - // @0012D4CC BEQ zero, zero, $00129b94 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219476u; - } - // @0012D4D0 ADDIU t7, t7, $fffa - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -6))); - } - - public virtual void funct0012d4d4() - { - this.ee.pc = 1234156u; - // @0012D4D4 SUBU t7, s2, t3 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); - // @0012D4D8 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D4DC ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012D4E0 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @0012D4E4 BEQ zero, zero, $0012d4c8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1234120u; - } - // @0012D4E8 ADDIU t6, t6, $0030 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); - } - - public virtual void funct0012d4ec() - { - this.ee.pc = 1234164u; - // @0012D4EC BEQ zero, zero, $00129bc4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219524u; - } - // @0012D4F0 SLL s8, s2, 4 - MobUt.SLL(this.ee.s8, this.ee.s2, 4); - } - - public virtual void funct0012d4f4() - { - this.ee.pc = 1234184u; - // @0012D4F4 SUBU t7, s2, t4 - this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); - // @0012D4F8 SLL t7, t7, 6 - MobUt.SLL(this.ee.t7, this.ee.t7, 6); - // @0012D4FC ADDU t6, t5, t6 - this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0012D500 BEQ zero, zero, $00129b10 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1219344u; - } - // @0012D504 ADDU v0, t6, t7 - this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct00141bd0() - { - this.ee.pc = 1317852u; - // @00141BD0 LW t7, $0000(a0) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); - // @00141BD4 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00141BD8 LW v0, $000c(t7) - MobUt.LW(this.ee, this.ee.v0, (12u + this.ee.t7.UL0)); - } - - public virtual void funct00141be0() - { - this.ee.pc = 1317864u; - // @00141BE0 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00141BE4 SW a1, $003c(a0) - MobUt.SW(this.ee, this.ee.a1, (60u + this.ee.a0.UL0)); - } - - public virtual void funct00141be8() - { - this.ee.pc = 1317940u; - // @00141BE8 LHU t6, $0002(a1) - MobUt.LHU(this.ee, this.ee.t6, (2u + this.ee.a1.UL0)); - // @00141BEC LW t7, $0010(a0) - MobUt.LW(this.ee, this.ee.t7, (16u + this.ee.a0.UL0)); - // @00141BF0 SLL t6, t6, 4 - MobUt.SLL(this.ee.t6, this.ee.t6, 4); - // @00141BF4 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00141BF8 SW t7, $0000(a2) - MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a2.UL0)); - // @00141BFC LHU t6, $0004(a1) - MobUt.LHU(this.ee, this.ee.t6, (4u + this.ee.a1.UL0)); - // @00141C00 LW t7, $0010(a0) - MobUt.LW(this.ee, this.ee.t7, (16u + this.ee.a0.UL0)); - // @00141C04 SLL t6, t6, 4 - MobUt.SLL(this.ee.t6, this.ee.t6, 4); - // @00141C08 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00141C0C SW t7, $0004(a2) - MobUt.SW(this.ee, this.ee.t7, (4u + this.ee.a2.UL0)); - // @00141C10 LHU t6, $0006(a1) - MobUt.LHU(this.ee, this.ee.t6, (6u + this.ee.a1.UL0)); - // @00141C14 LW t7, $0010(a0) - MobUt.LW(this.ee, this.ee.t7, (16u + this.ee.a0.UL0)); - // @00141C18 SLL t6, t6, 4 - MobUt.SLL(this.ee.t6, this.ee.t6, 4); - // @00141C1C ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00141C20 SW t7, $0008(a2) - MobUt.SW(this.ee, this.ee.t7, (8u + this.ee.a2.UL0)); - // @00141C24 LHU t6, $0008(a1) - MobUt.LHU(this.ee, this.ee.t6, (8u + this.ee.a1.UL0)); - // @00141C28 ORI t7, zero, $ffff - this.ee.t7.UD0 = (this.ee.r0.UD0 | 65535); - // @00141C2C BEQ t6, t7, $00141c4c - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1317964u; - } - // @00141C30 SLL t5, t6, 4 - MobUt.SLL(this.ee.t5, this.ee.t6, 4); - } - - public virtual void funct00141c34() - { - this.ee.pc = 1317964u; - // @00141C34 LW t7, $0010(a0) - MobUt.LW(this.ee, this.ee.t7, (16u + this.ee.a0.UL0)); - // @00141C38 ADDIU t6, zero, $0004 - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 4))); - // @00141C3C ADDU t7, t7, t5 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); - // @00141C40 SW t6, $0010(a2) - MobUt.SW(this.ee, this.ee.t6, (16u + this.ee.a2.UL0)); - // @00141C44 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00141C48 SW t7, $000c(a2) - MobUt.SW(this.ee, this.ee.t7, (12u + this.ee.a2.UL0)); - } - - public virtual void funct00141e78() - { - this.ee.pc = 1318548u; - // @00141E78 ANDI a3, a3, $00ff - this.ee.a3.UD0 = ((ushort)((this.ee.a3.US0 & 255))); - // @00141E7C SW a1, $0040(a0) - MobUt.SW(this.ee, this.ee.a1, (64u + this.ee.a0.UL0)); - // @00141E80 ANDI t0, t0, $00ff - this.ee.t0.UD0 = ((ushort)((this.ee.t0.US0 & 255))); - // @00141E84 SW a2, $0044(a0) - MobUt.SW(this.ee, this.ee.a2, (68u + this.ee.a0.UL0)); - // @00141E88 SB t0, $00d3(a0) - MobUt.SB(this.ee, this.ee.t0, (211u + this.ee.a0.UL0)); - // @00141E8C JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00141E90 SB a3, $00d0(a0) - MobUt.SB(this.ee, this.ee.a3, (208u + this.ee.a0.UL0)); - } - - public virtual void funct00141e98() - { - this.ee.pc = 1318636u; - // @00141E98 ADDIU sp, sp, $ffa0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -96))); - // @00141E9C SLL a1, a1, 5 - MobUt.SLL(this.ee.a1, this.ee.a1, 5); - // @00141EA0 SD s1, $0018(sp) - MobUt.SD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); - // @00141EA4 SD s5, $0038(sp) - MobUt.SD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); - // @00141EA8 SD s6, $0040(sp) - MobUt.SD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); - // @00141EAC DADDU s1, a0, zero - this.ee.s1.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); - // @00141EB0 SD s7, $0048(sp) - MobUt.SD(this.ee, this.ee.s7, (72u + this.ee.sp.UL0)); - // @00141EB4 DADDU s5, a2, zero - this.ee.s5.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); - // @00141EB8 SD s0, $0010(sp) - MobUt.SD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); - // @00141EBC DADDU s6, a3, zero - this.ee.s6.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); - // @00141EC0 SD s2, $0020(sp) - MobUt.SD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); - // @00141EC4 SD s3, $0028(sp) - MobUt.SD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); - // @00141EC8 SD s4, $0030(sp) - MobUt.SD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); - // @00141ECC SD s8, $0050(sp) - MobUt.SD(this.ee, this.ee.s8, (80u + this.ee.sp.UL0)); - // @00141ED0 SD ra, $0058(sp) - MobUt.SD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); - // @00141ED4 LW t7, $0004(a0) - MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); - // @00141ED8 SW t0, $0000(sp) - MobUt.SW(this.ee, this.ee.t0, (0u + this.ee.sp.UL0)); - // @00141EDC ADDU s7, t7, a1 - this.ee.s7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.a1.SD0))); - // @00141EE0 ADDIU a0, s7, $0010 - this.ee.a0.SD0 = ((int)((this.ee.s7.SD0 + 16))); - // @00141EE4 JAL $001457e0 - this.ee.ra.UL0 = 1318636u; - this.ee.pc = 1333216u; - // @00141EE8 DADDU a1, a2, zero - this.ee.a1.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00141eec() - { - this.ee.pc = 1318644u; - // @00141EEC BEQ v0, zero, $00142090 - if ((this.ee.v0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1319056u; - } - // @00141EF0 LD s0, $0010(sp) - MobUt.LD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); - } - - public virtual void funct00141ef4() - { - this.ee.pc = 1318664u; - // @00141EF4 LHU s8, $001e(s7) - MobUt.LHU(this.ee, this.ee.s8, (30u + this.ee.s7.UL0)); - // @00141EF8 LHU s3, $001c(s7) - MobUt.LHU(this.ee, this.ee.s3, (28u + this.ee.s7.UL0)); - // @00141EFC SLT t7, s3, s8 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s3.SD0 < this.ee.s8.SD0)); - // @00141F00 BEQ t7, zero, $0014204c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1318988u; - } - // @00141F04 ADDIU t7, zero, $0014 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 20))); - } - - public virtual void funct00141f08() - { - this.ee.pc = 1318688u; - // @00141F08 MULT s4, s3, t7 - this.ee.s4.SD0 = (((long)(this.ee.s3.SL0)) * ((long)(this.ee.t7.SL0))); - // @00141F0C LW t7, $0008(s1) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s1.UL0)); - // @00141F10 ADDU s0, t7, s4 - this.ee.s0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s4.SD0))); - // @00141F14 LBU t6, $0010(s0) - MobUt.LBU(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @00141F18 BEQL t6, zero, $00142040 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1318976u; - // @00141F1C ADDIU s3, s3, $0001 - this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); - } - } - - public virtual void funct00141f0c() - { - this.ee.pc = 1318688u; - // @00141F0C LW t7, $0008(s1) - MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s1.UL0)); - // @00141F10 ADDU s0, t7, s4 - this.ee.s0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s4.SD0))); - // @00141F14 LBU t6, $0010(s0) - MobUt.LBU(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); - // @00141F18 BEQL t6, zero, $00142040 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1318976u; - // @00141F1C ADDIU s3, s3, $0001 - this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); - } - } - - public virtual void funct00141f20() - { - this.ee.pc = 1318700u; - // @00141F20 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @00141F24 JAL $001457e0 - this.ee.ra.UL0 = 1318700u; - this.ee.pc = 1333216u; - // @00141F28 DADDU a1, s5, zero - this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00141f2c() - { - this.ee.pc = 1318708u; - // @00141F2C BEQL v0, zero, $00142040 - if ((this.ee.v0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1318976u; - // @00141F30 ADDIU s3, s3, $0001 - this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); - } - } - - public virtual void funct00141f34() - { - this.ee.pc = 1318728u; - // @00141F34 LHU s2, $000c(s0) - MobUt.LHU(this.ee, this.ee.s2, (12u + this.ee.s0.UL0)); - // @00141F38 LHU s0, $000e(s0) - MobUt.LHU(this.ee, this.ee.s0, (14u + this.ee.s0.UL0)); - // @00141F3C SLT t7, s2, s0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.s0.SD0)); - // @00141F40 BEQ t7, zero, $0014203c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1318972u; - } - // @00141F44 SW s0, $0004(sp) - MobUt.SW(this.ee, this.ee.s0, (4u + this.ee.sp.UL0)); - } - - public virtual void funct00141f48() - { - this.ee.pc = 1318768u; - // @00141F48 LW t6, $000c(s1) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s1.UL0)); - // @00141F4C SLL t7, s2, 4 - MobUt.SLL(this.ee.t7, this.ee.s2, 4); - // @00141F50 LW t4, $0014(s1) - MobUt.LW(this.ee, this.ee.t4, (20u + this.ee.s1.UL0)); - // @00141F54 ADDU s0, t6, t7 - this.ee.s0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00141F58 LBU t5, $00d0(s1) - MobUt.LBU(this.ee, this.ee.t5, (208u + this.ee.s1.UL0)); - // @00141F5C LHU t7, $000e(s0) - MobUt.LHU(this.ee, this.ee.t7, (14u + this.ee.s0.UL0)); - // @00141F60 ADDIU t6, zero, $0001 - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @00141F64 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @00141F68 BNE t5, t6, $001420bc - if ((this.ee.t5.UD0 != this.ee.t6.UD0)) - { - this.ee.pc = 1319100u; - } - // @00141F6C ADDU a2, t4, t7 - this.ee.a2.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct00141f4c() - { - this.ee.pc = 1318768u; - // @00141F4C SLL t7, s2, 4 - MobUt.SLL(this.ee.t7, this.ee.s2, 4); - // @00141F50 LW t4, $0014(s1) - MobUt.LW(this.ee, this.ee.t4, (20u + this.ee.s1.UL0)); - // @00141F54 ADDU s0, t6, t7 - this.ee.s0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00141F58 LBU t5, $00d0(s1) - MobUt.LBU(this.ee, this.ee.t5, (208u + this.ee.s1.UL0)); - // @00141F5C LHU t7, $000e(s0) - MobUt.LHU(this.ee, this.ee.t7, (14u + this.ee.s0.UL0)); - // @00141F60 ADDIU t6, zero, $0001 - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @00141F64 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @00141F68 BNE t5, t6, $001420bc - if ((this.ee.t5.UD0 != this.ee.t6.UD0)) - { - this.ee.pc = 1319100u; - } - // @00141F6C ADDU a2, t4, t7 - this.ee.a2.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct00141f88() - { - this.ee.pc = 1318804u; - // @00141F88 ANDI t7, t7, $00ff - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 255))); - // @00141F8C BEQ t7, zero, $0014202c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1318956u; - } - // @00141F90 LW t6, $0004(sp) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.sp.UL0)); - } - - public virtual void funct00141f94() - { - this.ee.pc = 1318816u; - // @00141F94 LBU t7, $00d3(s1) - MobUt.LBU(this.ee, this.ee.t7, (211u + this.ee.s1.UL0)); - // @00141F98 BEQ t7, zero, $00141fb4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1318836u; - } - // @00141F9C DADDU t6, zero, zero - this.ee.t6.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00141fb4() - { - this.ee.pc = 1318848u; - // @00141FB4 ANDI t7, t6, $00ff - this.ee.t7.UD0 = ((ushort)((this.ee.t6.US0 & 255))); - // @00141FB8 BNEL t7, zero, $00141fd8 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1318872u; - // @00141FBC LHU t6, $000c(s0) - MobUt.LHU(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - } - } - - public virtual void funct00141fc0() - { - this.ee.pc = 1318860u; - // @00141FC0 LW a1, $0000(sp) - MobUt.LW(this.ee, this.ee.a1, (0u + this.ee.sp.UL0)); - // @00141FC4 JAL $0032d8d0 - this.ee.ra.UL0 = 1318860u; - this.ee.pc = 3332304u; - // @00141FC8 DADDU a0, s1, zero - this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00141fcc() - { - this.ee.pc = 1318868u; - // @00141FCC BEQ v0, zero, $0014202c - if ((this.ee.v0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1318956u; - } - // @00141FD0 LW t6, $0004(sp) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.sp.UL0)); - } - - public virtual void funct00141fd4() - { - this.ee.pc = 1318884u; - // @00141FD4 LHU t6, $000c(s0) - MobUt.LHU(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); - // @00141FD8 ORI t7, zero, $ffff - this.ee.t7.UD0 = (this.ee.r0.UD0 | 65535); - // @00141FDC BEQ t6, t7, $00142000 - if ((this.ee.t6.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1318912u; - } - // @00141FE0 ADDIU t5, zero, $000c - this.ee.t5.SD0 = ((int)((this.ee.r0.SD0 + 12))); - } - - public virtual void funct00141fe4() - { - this.ee.pc = 1318904u; - // @00141FE4 LW a0, $001c(s1) - MobUt.LW(this.ee, this.ee.a0, (28u + this.ee.s1.UL0)); - // @00141FE8 MULT t7, t6, t5 - this.ee.t7.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.t5.SL0))); - // @00141FEC DADDU a1, s5, zero - this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); - // @00141FF0 JAL $001457e0 - this.ee.ra.UL0 = 1318904u; - this.ee.pc = 1333216u; - // @00141FF4 ADDU a0, a0, t7 - this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct00141ff8() - { - this.ee.pc = 1318912u; - // @00141FF8 BEQ v0, zero, $0014202c - if ((this.ee.v0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1318956u; - } - // @00141FFC LW t6, $0004(sp) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.sp.UL0)); - } - - public virtual void funct00142000() - { - this.ee.pc = 1318928u; - // @00142000 LHU t6, $0000(s6) - MobUt.LHU(this.ee, this.ee.t6, (0u + this.ee.s6.UL0)); - // @00142004 SLTIU t7, t6, $03ff - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 1023ul)); - // @00142008 BEQ t7, zero, $0014208c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1319052u; - } - // @0014200C SLL t6, t6, 1 - MobUt.SLL(this.ee.t6, this.ee.t6, 1); - } - - public virtual void funct00142010() - { - this.ee.pc = 1318972u; - // @00142010 LW t7, $003c(s1) - MobUt.LW(this.ee, this.ee.t7, (60u + this.ee.s1.UL0)); - // @00142014 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00142018 SH s2, $0000(t6) - MobUt.SH(this.ee, this.ee.s2, (0u + this.ee.t6.UL0)); - // @0014201C LHU t7, $0000(s6) - MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); - // @00142020 ADDIU t7, t7, $0001 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 1))); - // @00142024 SH t7, $0000(s6) - MobUt.SH(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); - // @00142028 LW t6, $0004(sp) - MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.sp.UL0)); - // @0014202C ADDIU s2, s2, $0001 - this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); - // @00142030 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @00142034 BNEL t7, zero, $00141f4c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1318732u; - // @00142038 LW t6, $000c(s1) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s1.UL0)); - } - } - - public virtual void funct0014202c() - { - this.ee.pc = 1318972u; - // @0014202C ADDIU s2, s2, $0001 - this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); - // @00142030 SLT t7, s2, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); - // @00142034 BNEL t7, zero, $00141f4c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1318732u; - // @00142038 LW t6, $000c(s1) - MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s1.UL0)); - } - } - - public virtual void funct0014203c() - { - this.ee.pc = 1318988u; - // @0014203C ADDIU s3, s3, $0001 - this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); - // @00142040 SLT t7, s3, s8 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s3.SD0 < this.ee.s8.SD0)); - // @00142044 BNE t7, zero, $00141f0c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1318668u; - } - // @00142048 ADDIU s4, s4, $0014 - this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 20))); - } - - public virtual void funct00142040() - { - this.ee.pc = 1318988u; - // @00142040 SLT t7, s3, s8 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s3.SD0 < this.ee.s8.SD0)); - // @00142044 BNE t7, zero, $00141f0c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1318668u; - } - // @00142048 ADDIU s4, s4, $0014 - this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 20))); - } - - public virtual void funct0014204c() - { - this.ee.pc = 1319016u; - // @0014204C DADDU s0, s7, zero - this.ee.s0.UD0 = (this.ee.s7.UD0 + this.ee.r0.UD0); - // @00142050 DADDU s2, zero, zero - this.ee.s2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00142054 ADDIU s3, zero, $ffff - this.ee.s3.SD0 = ((int)((this.ee.r0.SD0 + -1))); - // @00142058 LH t7, $0000(s0) - MobUt.LH(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); - // @0014205C ADDIU s0, s0, $0002 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 2))); - // @00142060 BEQ t7, s3, $0014208c - if ((this.ee.t7.UD0 == this.ee.s3.UD0)) - { - this.ee.pc = 1319052u; - } - // @00142064 DADDU a1, t7, zero - this.ee.a1.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0014205c() - { - this.ee.pc = 1319016u; - // @0014205C ADDIU s0, s0, $0002 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 2))); - // @00142060 BEQ t7, s3, $0014208c - if ((this.ee.t7.UD0 == this.ee.s3.UD0)) - { - this.ee.pc = 1319052u; - } - // @00142064 DADDU a1, t7, zero - this.ee.a1.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00142068() - { - this.ee.pc = 1319040u; - // @00142068 LW t0, $0000(sp) - MobUt.LW(this.ee, this.ee.t0, (0u + this.ee.sp.UL0)); - // @0014206C DADDU a0, s1, zero - this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); - // @00142070 DADDU a2, s5, zero - this.ee.a2.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); - // @00142074 DADDU a3, s6, zero - this.ee.a3.UD0 = (this.ee.s6.UD0 + this.ee.r0.UD0); - // @00142078 JAL $00141e98 - this.ee.ra.UL0 = 1319040u; - this.ee.pc = 1318552u; - // @0014207C ADDIU s2, s2, $0001 - this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); - } - - public virtual void funct00142080() - { - this.ee.pc = 1319052u; - // @00142080 SLTI t7, s2, $0008 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < 8)); - // @00142084 BNEL t7, zero, $0014205c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1319004u; - // @00142088 LH t7, $0000(s0) - MobUt.LH(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); - } - } - - public virtual void funct0014208c() - { - this.ee.pc = 1319100u; - // @0014208C LD s0, $0010(sp) - MobUt.LD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); - // @00142090 LD s1, $0018(sp) - MobUt.LD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); - // @00142094 LD s2, $0020(sp) - MobUt.LD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); - // @00142098 LD s3, $0028(sp) - MobUt.LD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); - // @0014209C LD s4, $0030(sp) - MobUt.LD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); - // @001420A0 LD s5, $0038(sp) - MobUt.LD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); - // @001420A4 LD s6, $0040(sp) - MobUt.LD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); - // @001420A8 LD s7, $0048(sp) - MobUt.LD(this.ee, this.ee.s7, (72u + this.ee.sp.UL0)); - // @001420AC LD s8, $0050(sp) - MobUt.LD(this.ee, this.ee.s8, (80u + this.ee.sp.UL0)); - // @001420B0 LD ra, $0058(sp) - MobUt.LD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); - // @001420B4 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @001420B8 ADDIU sp, sp, $0060 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 96))); - } - - public virtual void funct00142090() - { - this.ee.pc = 1319100u; - // @00142090 LD s1, $0018(sp) - MobUt.LD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); - // @00142094 LD s2, $0020(sp) - MobUt.LD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); - // @00142098 LD s3, $0028(sp) - MobUt.LD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); - // @0014209C LD s4, $0030(sp) - MobUt.LD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); - // @001420A0 LD s5, $0038(sp) - MobUt.LD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); - // @001420A4 LD s6, $0040(sp) - MobUt.LD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); - // @001420A8 LD s7, $0048(sp) - MobUt.LD(this.ee, this.ee.s7, (72u + this.ee.sp.UL0)); - // @001420AC LD s8, $0050(sp) - MobUt.LD(this.ee, this.ee.s8, (80u + this.ee.sp.UL0)); - // @001420B0 LD ra, $0058(sp) - MobUt.LD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); - // @001420B4 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @001420B8 ADDIU sp, sp, $0060 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 96))); - } - - public virtual void funct001420bc() - { - this.ee.pc = 1319128u; - // @001420BC LW t5, $0000(a2) - MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.a2.UL0)); - // @001420C0 LW t7, $0040(s1) - MobUt.LW(this.ee, this.ee.t7, (64u + this.ee.s1.UL0)); - // @001420C4 LW t6, $0044(s1) - MobUt.LW(this.ee, this.ee.t6, (68u + this.ee.s1.UL0)); - // @001420C8 AND t7, t5, t7 - this.ee.t7.UD0 = (this.ee.t5.UD0 & this.ee.t7.UD0); - // @001420CC XOR t7, t7, t6 - MobUt.XOR(this.ee.t7, this.ee.t7, this.ee.t6); - // @001420D0 BEQ zero, zero, $00141f88 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1318792u; - } - // @001420D4 SLTIU t7, t7, $0001 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < 1ul)); - } - - public virtual void funct001420d8() - { - this.ee.pc = 1319220u; - // @001420D8 ADDIU sp, sp, $ff30 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -208))); - // @001420DC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @001420E0 SD s1, $0078(sp) - MobUt.SD(this.ee, this.ee.s1, (120u + this.ee.sp.UL0)); - // @001420E4 ADDIU t7, t7, $873c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30916))); - // @001420E8 SD s2, $0080(sp) - MobUt.SD(this.ee, this.ee.s2, (128u + this.ee.sp.UL0)); - // @001420EC SD s3, $0088(sp) - MobUt.SD(this.ee, this.ee.s3, (136u + this.ee.sp.UL0)); - // @001420F0 DADDU s1, a0, zero - this.ee.s1.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); - // @001420F4 SD s6, $00a0(sp) - MobUt.SD(this.ee, this.ee.s6, (160u + this.ee.sp.UL0)); - // @001420F8 DADDU s2, a1, zero - this.ee.s2.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - // @001420FC SD s7, $00a8(sp) - MobUt.SD(this.ee, this.ee.s7, (168u + this.ee.sp.UL0)); - // @00142100 DADDU s3, zero, zero - this.ee.s3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00142104 SD s0, $0070(sp) - MobUt.SD(this.ee, this.ee.s0, (112u + this.ee.sp.UL0)); - // @00142108 DADDU s6, a3, zero - this.ee.s6.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); - // @0014210C SD s4, $0090(sp) - MobUt.SD(this.ee, this.ee.s4, (144u + this.ee.sp.UL0)); - // @00142110 DADDU s7, a2, zero - this.ee.s7.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); - // @00142114 SD s5, $0098(sp) - MobUt.SD(this.ee, this.ee.s5, (152u + this.ee.sp.UL0)); - // @00142118 SD s8, $00b0(sp) - MobUt.SD(this.ee, this.ee.s8, (176u + this.ee.sp.UL0)); - // @0014211C SD ra, $00b8(sp) - MobUt.SD(this.ee, this.ee.ra, (184u + this.ee.sp.UL0)); - // @00142120 SWC1 $f20, $00c0(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (192u + this.ee.sp.UL0)); - // @00142124 LWC1 $f20, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[20], (0u + this.ee.t7.UL0)); - // @00142128 ORI t7, zero, $ffff - this.ee.t7.UD0 = (this.ee.r0.UD0 | 65535); - // @0014212C BLEZ a2, $00142218 - if ((this.ee.a2.SD0 <= 0)) - { - this.ee.pc = 1319448u; - } - // @00142130 SW t7, $0060(sp) - MobUt.SW(this.ee, this.ee.t7, (96u + this.ee.sp.UL0)); - } - - public virtual void funct00142134() - { - this.ee.pc = 1319272u; - // @00142134 ADDIU s8, sp, $0010 - this.ee.s8.SD0 = ((int)((this.ee.sp.SD0 + 16))); - // @00142138 ADDIU s4, sp, $0030 - this.ee.s4.SD0 = ((int)((this.ee.sp.SD0 + 48))); - // @0014213C LW t7, $003c(s1) - MobUt.LW(this.ee, this.ee.t7, (60u + this.ee.s1.UL0)); - // @00142140 SLL t6, s3, 1 - MobUt.SLL(this.ee.t6, this.ee.s3, 1); - // @00142144 LW s0, $000c(s1) - MobUt.LW(this.ee, this.ee.s0, (12u + this.ee.s1.UL0)); - // @00142148 DADDU a0, s1, zero - this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); - // @0014214C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00142150 DADDU a2, s8, zero - this.ee.a2.UD0 = (this.ee.s8.UD0 + this.ee.r0.UD0); - // @00142154 LHU s5, $0000(t6) - MobUt.LHU(this.ee, this.ee.s5, (0u + this.ee.t6.UL0)); - // @00142158 SLL t7, s5, 4 - MobUt.SLL(this.ee.t7, this.ee.s5, 4); - // @0014215C ADDU s0, s0, t7 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t7.SD0))); - // @00142160 JAL $00141be8 - this.ee.ra.UL0 = 1319272u; - this.ee.pc = 1317864u; - // @00142164 DADDU a1, s0, zero - this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00142140() - { - this.ee.pc = 1319272u; - // @00142140 SLL t6, s3, 1 - MobUt.SLL(this.ee.t6, this.ee.s3, 1); - // @00142144 LW s0, $000c(s1) - MobUt.LW(this.ee, this.ee.s0, (12u + this.ee.s1.UL0)); - // @00142148 DADDU a0, s1, zero - this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); - // @0014214C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @00142150 DADDU a2, s8, zero - this.ee.a2.UD0 = (this.ee.s8.UD0 + this.ee.r0.UD0); - // @00142154 LHU s5, $0000(t6) - MobUt.LHU(this.ee, this.ee.s5, (0u + this.ee.t6.UL0)); - // @00142158 SLL t7, s5, 4 - MobUt.SLL(this.ee.t7, this.ee.s5, 4); - // @0014215C ADDU s0, s0, t7 - this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t7.SD0))); - // @00142160 JAL $00141be8 - this.ee.ra.UL0 = 1319272u; - this.ee.pc = 1317864u; - // @00142164 DADDU a1, s0, zero - this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00142168() - { - this.ee.pc = 1319316u; - // @00142168 LHU t6, $000a(s0) - MobUt.LHU(this.ee, this.ee.t6, (10u + this.ee.s0.UL0)); - // @0014216C LW t7, $0018(s1) - MobUt.LW(this.ee, this.ee.t7, (24u + this.ee.s1.UL0)); - // @00142170 SLL t6, t6, 4 - MobUt.SLL(this.ee.t6, this.ee.t6, 4); - // @00142174 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @00142178 LQ t0, $0000(t7) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @0014217C SQ t0, $0000(s4) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s4.UL[0])); - // @00142180 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @00142184 DADDU a1, s8, zero - this.ee.a1.UD0 = (this.ee.s8.UD0 + this.ee.r0.UD0); - // @00142188 DADDU a2, s4, zero - this.ee.a2.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - // @0014218C JAL $00162670 - this.ee.ra.UL0 = 1319316u; - this.ee.pc = 1451632u; - // @00142190 DADDU a3, sp, zero - this.ee.a3.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00142194() - { - this.ee.pc = 1319324u; - // @00142194 BEQ v0, zero, $00142208 - if ((this.ee.v0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1319432u; - } - // @00142198 ADDIU t6, sp, $0040 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 64))); - } - - public virtual void funct00142208() - { - this.ee.pc = 1319448u; - // @00142208 ADDIU s3, s3, $0001 - this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); - // @0014220C SLT t7, s3, s7 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s3.SD0 < this.ee.s7.SD0)); - // @00142210 BNEL t7, zero, $00142140 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1319232u; - // @00142214 LW t7, $003c(s1) - MobUt.LW(this.ee, this.ee.t7, (60u + this.ee.s1.UL0)); - } - } - - public virtual void funct00142218() - { - this.ee.pc = 1319504u; - // @00142218 LW v0, $0060(sp) - MobUt.LW(this.ee, this.ee.v0, (96u + this.ee.sp.UL0)); - // @0014221C LD s0, $0070(sp) - MobUt.LD(this.ee, this.ee.s0, (112u + this.ee.sp.UL0)); - // @00142220 LD s1, $0078(sp) - MobUt.LD(this.ee, this.ee.s1, (120u + this.ee.sp.UL0)); - // @00142224 LD s2, $0080(sp) - MobUt.LD(this.ee, this.ee.s2, (128u + this.ee.sp.UL0)); - // @00142228 LD s3, $0088(sp) - MobUt.LD(this.ee, this.ee.s3, (136u + this.ee.sp.UL0)); - // @0014222C LD s4, $0090(sp) - MobUt.LD(this.ee, this.ee.s4, (144u + this.ee.sp.UL0)); - // @00142230 LD s5, $0098(sp) - MobUt.LD(this.ee, this.ee.s5, (152u + this.ee.sp.UL0)); - // @00142234 LD s6, $00a0(sp) - MobUt.LD(this.ee, this.ee.s6, (160u + this.ee.sp.UL0)); - // @00142238 LD s7, $00a8(sp) - MobUt.LD(this.ee, this.ee.s7, (168u + this.ee.sp.UL0)); - // @0014223C LD s8, $00b0(sp) - MobUt.LD(this.ee, this.ee.s8, (176u + this.ee.sp.UL0)); - // @00142240 LD ra, $00b8(sp) - MobUt.LD(this.ee, this.ee.ra, (184u + this.ee.sp.UL0)); - // @00142244 LWC1 $f20, $00c0(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (192u + this.ee.sp.UL0)); - // @00142248 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0014224C ADDIU sp, sp, $00d0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 208))); - } - - public virtual void funct00142250() - { - this.ee.pc = 1319592u; - // @00142250 ADDIU sp, sp, $f730 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -2256))); - // @00142254 SD s1, $0898(sp) - MobUt.SD(this.ee, this.ee.s1, (2200u + this.ee.sp.UL0)); - // @00142258 SD s4, $08b0(sp) - MobUt.SD(this.ee, this.ee.s4, (2224u + this.ee.sp.UL0)); - // @0014225C SD s5, $08b8(sp) - MobUt.SD(this.ee, this.ee.s5, (2232u + this.ee.sp.UL0)); - // @00142260 DADDU s1, a0, zero - this.ee.s1.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); - // @00142264 SD s6, $08c0(sp) - MobUt.SD(this.ee, this.ee.s6, (2240u + this.ee.sp.UL0)); - // @00142268 DADDU s4, a2, zero - this.ee.s4.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); - // @0014226C SD s0, $0890(sp) - MobUt.SD(this.ee, this.ee.s0, (2192u + this.ee.sp.UL0)); - // @00142270 DADDU s5, t0, zero - this.ee.s5.UD0 = (this.ee.t0.UD0 + this.ee.r0.UD0); - // @00142274 SD s2, $08a0(sp) - MobUt.SD(this.ee, this.ee.s2, (2208u + this.ee.sp.UL0)); - // @00142278 DADDU s6, a3, zero - this.ee.s6.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); - // @0014227C SD s3, $08a8(sp) - MobUt.SD(this.ee, this.ee.s3, (2216u + this.ee.sp.UL0)); - // @00142280 SD ra, $08c8(sp) - MobUt.SD(this.ee, this.ee.ra, (2248u + this.ee.sp.UL0)); - // @00142284 LQ t0, $0000(a1) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @00142288 SQ t0, $0000(sp) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); - // @0014228C ADDIU a1, a1, $0010 - this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); - // @00142290 ADDIU t6, sp, $0010 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 16))); - // @00142294 LQ t0, $0000(a1) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @00142298 SQ t0, $0000(t6) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); - // @0014229C LBU t7, $00d1(a0) - MobUt.LBU(this.ee, this.ee.t7, (209u + this.ee.a0.UL0)); - // @001422A0 BNE t7, zero, $00142320 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1319712u; - } - // @001422A4 ADDIU s2, sp, $0020 - this.ee.s2.SD0 = ((int)((this.ee.sp.SD0 + 32))); - } - - public virtual void funct00142320() - { - this.ee.pc = 1319724u; - // @00142320 ADDIU s3, sp, $0030 - this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 48))); - // @00142324 BEQ s3, sp, $00142338 - if ((this.ee.s3.UD0 == this.ee.sp.UD0)) - { - this.ee.pc = 1319736u; - } - // @00142328 ADDIU t7, sp, $0040 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); - } - - public virtual void funct0014232c() - { - this.ee.pc = 1319760u; - // @0014232C LQ t0, $0000(sp) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); - // @00142330 SQ t0, $0000(s3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @00142334 ADDIU t7, sp, $0040 - this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); - // @00142338 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @0014233C LQC2 vf2, $0000(sp) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.sp.UL0)); - // @00142340 VSUB.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); - // @00142344 SQC2 vf1, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); - // @00142348 BEQL t7, s2, $0014235c - if ((this.ee.t7.UD0 == this.ee.s2.UD0)) - { - this.ee.pc = 1319772u; - // @0014234C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - } - - public virtual void funct00142350() - { - this.ee.pc = 1319804u; - // @00142350 LQ t0, $0000(s2) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); - // @00142354 SQ t0, $0000(t7) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); - // @00142358 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @0014235C ADDIU s0, sp, $0050 - this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 80))); - // @00142360 ADDIU t7, t7, $8740 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30912))); - // @00142364 DADDU a1, sp, zero - this.ee.a1.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); - // @00142368 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @0014236C DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @00142370 SWC1 $f0, $003c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (60u + this.ee.sp.UL0)); - // @00142374 JAL $00144878 - this.ee.ra.UL0 = 1319804u; - this.ee.pc = 1329272u; - // @00142378 SWC1 $f0, $004c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[0], (76u + this.ee.sp.UL0)); - } - - public virtual void funct0014237c() - { - this.ee.pc = 1319812u; - // @0014237C JAL $00145090 - this.ee.ra.UL0 = 1319812u; - this.ee.pc = 1331344u; - // @00142380 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00142384() - { - this.ee.pc = 1319820u; - // @00142384 JAL $00141bd0 - this.ee.ra.UL0 = 1319820u; - this.ee.pc = 1317840u; - // @00142388 DADDU a0, s1, zero - this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0014238c() - { - this.ee.pc = 1319836u; - // @0014238C DADDU a2, v0, zero - this.ee.a2.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); - // @00142390 DADDU a0, s2, zero - this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @00142394 JAL $001450b0 - this.ee.ra.UL0 = 1319836u; - this.ee.pc = 1331376u; - // @00142398 DADDU a1, s0, zero - this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0014239c() - { - this.ee.pc = 1319852u; - // @0014239C SH zero, $0070(sp) - MobUt.SH(this.ee, this.ee.r0, (112u + this.ee.sp.UL0)); - // @001423A0 ADDIU a1, sp, $0080 - this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 128))); - // @001423A4 JAL $00141be0 - this.ee.ra.UL0 = 1319852u; - this.ee.pc = 1317856u; - // @001423A8 DADDU a0, s1, zero - this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001423ac() - { - this.ee.pc = 1319876u; - // @001423AC DADDU a2, s2, zero - this.ee.a2.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @001423B0 ADDIU a3, sp, $0070 - this.ee.a3.SD0 = ((int)((this.ee.sp.SD0 + 112))); - // @001423B4 DADDU t0, s5, zero - this.ee.t0.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); - // @001423B8 DADDU a0, s1, zero - this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); - // @001423BC JAL $00141e98 - this.ee.ra.UL0 = 1319876u; - this.ee.pc = 1318552u; - // @001423C0 DADDU a1, zero, zero - this.ee.a1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001423c4() - { - this.ee.pc = 1319896u; - // @001423C4 LHU a2, $0070(sp) - MobUt.LHU(this.ee, this.ee.a2, (112u + this.ee.sp.UL0)); - // @001423C8 DADDU a1, s3, zero - this.ee.a1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); - // @001423CC DADDU a0, s1, zero - this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); - // @001423D0 JAL $001420d8 - this.ee.ra.UL0 = 1319896u; - this.ee.pc = 1319128u; - // @001423D4 DADDU a3, s4, zero - this.ee.a3.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001423d8() - { - this.ee.pc = 1319912u; - // @001423D8 SH v0, $0000(s6) - MobUt.SH(this.ee, this.ee.v0, (0u + this.ee.s6.UL0)); - // @001423DC ORI t7, zero, $ffff - this.ee.t7.UD0 = (this.ee.r0.UD0 | 65535); - // @001423E0 BEQ v0, t7, $00142438 - if ((this.ee.v0.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1319992u; - } - // @001423E4 DADDU t6, zero, zero - this.ee.t6.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00142438() - { - this.ee.pc = 1320036u; - // @00142438 LD s0, $0890(sp) - MobUt.LD(this.ee, this.ee.s0, (2192u + this.ee.sp.UL0)); - // @0014243C DADDU v0, t6, zero - this.ee.v0.UD0 = (this.ee.t6.UD0 + this.ee.r0.UD0); - // @00142440 LD s1, $0898(sp) - MobUt.LD(this.ee, this.ee.s1, (2200u + this.ee.sp.UL0)); - // @00142444 LD s2, $08a0(sp) - MobUt.LD(this.ee, this.ee.s2, (2208u + this.ee.sp.UL0)); - // @00142448 LD s3, $08a8(sp) - MobUt.LD(this.ee, this.ee.s3, (2216u + this.ee.sp.UL0)); - // @0014244C LD s4, $08b0(sp) - MobUt.LD(this.ee, this.ee.s4, (2224u + this.ee.sp.UL0)); - // @00142450 LD s5, $08b8(sp) - MobUt.LD(this.ee, this.ee.s5, (2232u + this.ee.sp.UL0)); - // @00142454 LD s6, $08c0(sp) - MobUt.LD(this.ee, this.ee.s6, (2240u + this.ee.sp.UL0)); - // @00142458 LD ra, $08c8(sp) - MobUt.LD(this.ee, this.ee.ra, (2248u + this.ee.sp.UL0)); - // @0014245C JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00142460 ADDIU sp, sp, $08d0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 2256))); - } - - public virtual void funct00143ec8() - { - this.ee.pc = 1326864u; - // @00143EC8 ADDIU sp, sp, $ffb0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -80))); - // @00143ECC DADDU t1, zero, zero - this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00143ED0 SD s2, $0030(sp) - MobUt.SD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); - // @00143ED4 ADDIU t2, sp, $0014 - this.ee.t2.SD0 = ((int)((this.ee.sp.SD0 + 20))); - // @00143ED8 SD s3, $0038(sp) - MobUt.SD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); - // @00143EDC ADDIU t3, zero, $000f - this.ee.t3.SD0 = ((int)((this.ee.r0.SD0 + 15))); - // @00143EE0 SD ra, $0040(sp) - MobUt.SD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); - // @00143EE4 DADDU s2, a1, zero - this.ee.s2.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - // @00143EE8 SD s0, $0020(sp) - MobUt.SD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); - // @00143EEC DADDU s3, a0, zero - this.ee.s3.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); - // @00143EF0 SD s1, $0028(sp) - MobUt.SD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); - // @00143EF4 ADDIU a2, sp, $0010 - this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 16))); - // @00143EF8 SW zero, $0014(sp) - MobUt.SW(this.ee, this.ee.r0, (20u + this.ee.sp.UL0)); - // @00143EFC ADDIU a3, zero, $0200 - this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 512))); - // @00143F00 SW zero, $0000(sp) - MobUt.SW(this.ee, this.ee.r0, (0u + this.ee.sp.UL0)); - // @00143F04 ADDIU t0, zero, $0200 - this.ee.t0.SD0 = ((int)((this.ee.r0.SD0 + 512))); - // @00143F08 JAL $00165aa8 - this.ee.ra.UL0 = 1326864u; - this.ee.pc = 1465000u; - // @00143F0C LUI s1, $0035 - this.ee.s1.SD0 = 3473408; - } - - public virtual void funct00143f10() - { - this.ee.pc = 1326892u; - // @00143F10 LW a0, $5134(s1) - MobUt.LW(this.ee, this.ee.a0, (20788u + this.ee.s1.UL0)); - // @00143F14 DADDU s0, v0, zero - this.ee.s0.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); - // @00143F18 ADDIU a1, zero, $0200 - this.ee.a1.SD0 = ((int)((this.ee.r0.SD0 + 512))); - // @00143F1C ADDIU a2, zero, $0200 - this.ee.a2.SD0 = ((int)((this.ee.r0.SD0 + 512))); - // @00143F20 DADDU a3, zero, zero - this.ee.a3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00143F24 JAL $00141e78 - this.ee.ra.UL0 = 1326892u; - this.ee.pc = 1318520u; - // @00143F28 DADDU t0, zero, zero - this.ee.t0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00143f2c() - { - this.ee.pc = 1326916u; - // @00143F2C LW a0, $5134(s1) - MobUt.LW(this.ee, this.ee.a0, (20788u + this.ee.s1.UL0)); - // @00143F30 DADDU a1, s3, zero - this.ee.a1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); - // @00143F34 DADDU a2, s2, zero - this.ee.a2.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); - // @00143F38 ADDIU a3, sp, $0010 - this.ee.a3.SD0 = ((int)((this.ee.sp.SD0 + 16))); - // @00143F3C JAL $00142250 - this.ee.ra.UL0 = 1326916u; - this.ee.pc = 1319504u; - // @00143F40 ADDIU t0, zero, $000f - this.ee.t0.SD0 = ((int)((this.ee.r0.SD0 + 15))); - } - - public virtual void funct00143f44() - { - this.ee.pc = 1326956u; - // @00143F44 OR s0, s0, v0 - this.ee.s0.UD0 = (this.ee.s0.UD0 | this.ee.v0.UD0); - // @00143F48 LD s1, $0028(sp) - MobUt.LD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); - // @00143F4C SLTU s0, zero, s0 - this.ee.s0.UD0 = System.Convert.ToByte((this.ee.r0.UD0 < this.ee.s0.UD0)); - // @00143F50 LD s2, $0030(sp) - MobUt.LD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); - // @00143F54 DADDU v0, s0, zero - this.ee.v0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - // @00143F58 LD s3, $0038(sp) - MobUt.LD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); - // @00143F5C LD s0, $0020(sp) - MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); - // @00143F60 LD ra, $0040(sp) - MobUt.LD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); - // @00143F64 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00143F68 ADDIU sp, sp, $0050 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 80))); - } - - public virtual void funct00144878() - { - this.ee.pc = 1329296u; - // @00144878 ADDIU sp, sp, $fff0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); - // @0014487C ADDIU a2, a1, $0010 - this.ee.a2.SD0 = ((int)((this.ee.a1.SD0 + 16))); - // @00144880 SD ra, $0000(sp) - MobUt.SD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); - // @00144884 LD ra, $0000(sp) - MobUt.LD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); - // @00144888 J $00144a40 - this.ee.pc = 1329728u; - // @0014488C ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00144a40() - { - this.ee.pc = 1329748u; - // @00144A40 LWC1 $f1, $0000(a1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.a1.UL0)); - // @00144A44 LWC1 $f0, $0000(a2) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.a2.UL0)); - // @00144A48 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @00144A4C BC1FL $00144ab4 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1329844u; - // @00144A50 SWC1 $f0, $0000(a0) - MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.a0.UL0)); - } - } - - public virtual void funct00144a5c() - { - this.ee.pc = 1329780u; - // @00144A5C SWC1 $f0, $000c(a0) - MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.a0.UL0)); - // @00144A60 LWC1 $f1, $0004(a1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.a1.UL0)); - // @00144A64 LWC1 $f0, $0004(a2) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.a2.UL0)); - // @00144A68 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @00144A6C BC1FL $00144aac - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1329836u; - // @00144A70 SWC1 $f0, $0004(a0) - MobUt.SWC1(this.ee, this.ee.fpr[0], (4u + this.ee.a0.UL0)); - } - } - - public virtual void funct00144a74() - { - this.ee.pc = 1329812u; - // @00144A74 SWC1 $f1, $0004(a0) - MobUt.SWC1(this.ee, this.ee.fpr[1], (4u + this.ee.a0.UL0)); - // @00144A78 LWC1 $f0, $0004(a2) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.a2.UL0)); - // @00144A7C SWC1 $f0, $0010(a0) - MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.a0.UL0)); - // @00144A80 LWC1 $f1, $0008(a1) - MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.a1.UL0)); - // @00144A84 LWC1 $f0, $0008(a2) - MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.a2.UL0)); - // @00144A88 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @00144A8C BC1FL $00144aa4 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1329828u; - // @00144A90 SWC1 $f0, $0008(a0) - MobUt.SWC1(this.ee, this.ee.fpr[0], (8u + this.ee.a0.UL0)); - } - } - - public virtual void funct00144a9c() - { - this.ee.pc = 1329828u; - // @00144A9C JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00144AA0 SWC1 $f0, $0014(a0) - MobUt.SWC1(this.ee, this.ee.fpr[0], (20u + this.ee.a0.UL0)); - } - - public virtual void funct00144aa4() - { - this.ee.pc = 1329836u; - // @00144AA4 BEQ zero, zero, $00144a9c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1329820u; - } - // @00144AA8 LWC1 $f0, $0008(a1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.a1.UL0)); - } - - public virtual void funct00144ab4() - { - this.ee.pc = 1329852u; - // @00144AB4 BEQ zero, zero, $00144a5c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1329756u; - } - // @00144AB8 LWC1 $f0, $0000(a1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.a1.UL0)); - } - - public virtual void funct00145090() - { - this.ee.pc = 1331372u; - // @00145090 SH zero, $0000(a0) - MobUt.SH(this.ee, this.ee.r0, (0u + this.ee.a0.UL0)); - // @00145094 SH zero, $000a(a0) - MobUt.SH(this.ee, this.ee.r0, (10u + this.ee.a0.UL0)); - // @00145098 SH zero, $0008(a0) - MobUt.SH(this.ee, this.ee.r0, (8u + this.ee.a0.UL0)); - // @0014509C SH zero, $0006(a0) - MobUt.SH(this.ee, this.ee.r0, (6u + this.ee.a0.UL0)); - // @001450A0 SH zero, $0004(a0) - MobUt.SH(this.ee, this.ee.r0, (4u + this.ee.a0.UL0)); - // @001450A4 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @001450A8 SH zero, $0002(a0) - MobUt.SH(this.ee, this.ee.r0, (2u + this.ee.a0.UL0)); - } - - public virtual void funct001450b0() - { - this.ee.pc = 1331424u; - // @001450B0 LUI t7, $0035 - this.ee.t7.SD0 = 3473408; - // @001450B4 LWC1 $f0, $0000(a1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.a1.UL0)); - // @001450B8 SLL t6, a2, 2 - MobUt.SLL(this.ee.t6, this.ee.a2, 2); - // @001450BC ADDIU t7, t7, $5660 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 22112))); - // @001450C0 ADDU t7, t6, t7 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @001450C4 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @001450C8 LUI t7, $0035 - this.ee.t7.SD0 = 3473408; - // @001450CC SUB.S $f1, $f0, $f2 - this.ee.fpr[1].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); - // @001450D0 ADDIU t7, t7, $5670 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 22128))); - // @001450D4 ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @001450D8 BEQ a2, zero, $001450e4 - if ((this.ee.a2.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1331428u; - } - // @001450DC LWC1 $f3, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t6.UL0)); - } - - public virtual void funct001450e4() - { - this.ee.pc = 1331452u; - // @001450E4 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @001450E8 ADDIU t7, t7, $87d4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30764))); - // @001450EC LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @001450F0 C.LT.S $f0, $f1 - this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[1].f); - // @001450F4 BC1TL $00145134 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1331508u; - // @001450F8 CVT.W.S $f0, $f1 - MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); - } - } - - public virtual void funct00145134() - { - this.ee.pc = 1331528u; - // @00145134 MFC1 t7, $f0 - MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); - // @00145138 SH t7, $0000(a0) - MobUt.SH(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); - // @0014513C LWC1 $f0, $0004(a1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.a1.UL0)); - // @00145140 BEQ a2, zero, $0014514c - if ((this.ee.a2.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1331532u; - } - // @00145144 SUB.S $f1, $f0, $f2 - this.ee.fpr[1].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); - } - - public virtual void funct0014514c() - { - this.ee.pc = 1331556u; - // @0014514C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00145150 ADDIU t7, t7, $87d4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30764))); - // @00145154 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00145158 C.LT.S $f0, $f1 - this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[1].f); - // @0014515C BC1TL $0014519c - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1331612u; - // @00145160 CVT.W.S $f0, $f1 - MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); - } - } - - public virtual void funct0014519c() - { - this.ee.pc = 1331632u; - // @0014519C MFC1 t7, $f0 - MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); - // @001451A0 SH t7, $0002(a0) - MobUt.SH(this.ee, this.ee.t7, (2u + this.ee.a0.UL0)); - // @001451A4 LWC1 $f0, $0008(a1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.a1.UL0)); - // @001451A8 BEQ a2, zero, $001451b4 - if ((this.ee.a2.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1331636u; - } - // @001451AC SUB.S $f1, $f0, $f2 - this.ee.fpr[1].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); - } - - public virtual void funct001451b4() - { - this.ee.pc = 1331660u; - // @001451B4 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @001451B8 ADDIU t7, t7, $87d4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30764))); - // @001451BC LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @001451C0 C.LT.S $f0, $f1 - this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[1].f); - // @001451C4 BC1TL $00145204 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1331716u; - // @001451C8 CVT.W.S $f0, $f1 - MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); - } - } - - public virtual void funct00145204() - { - this.ee.pc = 1331736u; - // @00145204 MFC1 t7, $f0 - MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); - // @00145208 SH t7, $0004(a0) - MobUt.SH(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); - // @0014520C LWC1 $f0, $000c(a1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (12u + this.ee.a1.UL0)); - // @00145210 BEQ a2, zero, $0014521c - if ((this.ee.a2.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1331740u; - } - // @00145214 ADD.S $f1, $f0, $f2 - this.ee.fpr[1].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - } - - public virtual void funct0014521c() - { - this.ee.pc = 1331764u; - // @0014521C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00145220 ADDIU t7, t7, $87e0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30752))); - // @00145224 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00145228 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @0014522C BC1TL $0014526c - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1331820u; - // @00145230 CVT.W.S $f0, $f1 - MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); - } - } - - public virtual void funct0014526c() - { - this.ee.pc = 1331840u; - // @0014526C MFC1 t7, $f0 - MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); - // @00145270 SH t7, $0006(a0) - MobUt.SH(this.ee, this.ee.t7, (6u + this.ee.a0.UL0)); - // @00145274 LWC1 $f0, $0010(a1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (16u + this.ee.a1.UL0)); - // @00145278 BEQ a2, zero, $00145284 - if ((this.ee.a2.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1331844u; - } - // @0014527C ADD.S $f1, $f0, $f2 - this.ee.fpr[1].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - } - - public virtual void funct00145284() - { - this.ee.pc = 1331868u; - // @00145284 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00145288 ADDIU t7, t7, $87e0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30752))); - // @0014528C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00145290 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @00145294 BC1TL $001452d4 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1331924u; - // @00145298 CVT.W.S $f0, $f1 - MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); - } - } - - public virtual void funct001452d4() - { - this.ee.pc = 1331944u; - // @001452D4 MFC1 t7, $f0 - MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); - // @001452D8 SH t7, $0008(a0) - MobUt.SH(this.ee, this.ee.t7, (8u + this.ee.a0.UL0)); - // @001452DC LWC1 $f0, $0014(a1) - MobUt.LWC1(this.ee, this.ee.fpr[0], (20u + this.ee.a1.UL0)); - // @001452E0 BEQ a2, zero, $001452ec - if ((this.ee.a2.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1331948u; - } - // @001452E4 ADD.S $f1, $f0, $f2 - this.ee.fpr[1].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - } - - public virtual void funct001452ec() - { - this.ee.pc = 1331972u; - // @001452EC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @001452F0 ADDIU t7, t7, $87e0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30752))); - // @001452F4 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @001452F8 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @001452FC BC1TL $0014533c - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1332028u; - // @00145300 CVT.W.S $f0, $f1 - MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); - } - } - - public virtual void funct0014533c() - { - this.ee.pc = 1332040u; - // @0014533C MFC1 t7, $f0 - MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); - // @00145340 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00145344 SH t7, $000a(a0) - MobUt.SH(this.ee, this.ee.t7, (10u + this.ee.a0.UL0)); - } - - public virtual void funct001457e0() - { - this.ee.pc = 1333236u; - // @001457E0 LH t7, $0006(a0) - MobUt.LH(this.ee, this.ee.t7, (6u + this.ee.a0.UL0)); - // @001457E4 LH t6, $0000(a1) - MobUt.LH(this.ee, this.ee.t6, (0u + this.ee.a1.UL0)); - // @001457E8 SLT t7, t7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); - // @001457EC BNE t7, zero, $00145854 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1333332u; - } - // @001457F0 DADDU v0, zero, zero - this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001457f4() - { - this.ee.pc = 1333256u; - // @001457F4 LH t6, $0000(a0) - MobUt.LH(this.ee, this.ee.t6, (0u + this.ee.a0.UL0)); - // @001457F8 LH t7, $0006(a1) - MobUt.LH(this.ee, this.ee.t7, (6u + this.ee.a1.UL0)); - // @001457FC SLT t7, t7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); - // @00145800 BNE t7, zero, $00145854 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1333332u; - } - // @00145804 NOP - MobUt.Latency(); - } - - public virtual void funct00145808() - { - this.ee.pc = 1333276u; - // @00145808 LH t7, $0008(a0) - MobUt.LH(this.ee, this.ee.t7, (8u + this.ee.a0.UL0)); - // @0014580C LH t6, $0002(a1) - MobUt.LH(this.ee, this.ee.t6, (2u + this.ee.a1.UL0)); - // @00145810 SLT t7, t7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); - // @00145814 BNE t7, zero, $00145854 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1333332u; - } - // @00145818 NOP - MobUt.Latency(); - } - - public virtual void funct0014581c() - { - this.ee.pc = 1333296u; - // @0014581C LH t6, $0002(a0) - MobUt.LH(this.ee, this.ee.t6, (2u + this.ee.a0.UL0)); - // @00145820 LH t7, $0008(a1) - MobUt.LH(this.ee, this.ee.t7, (8u + this.ee.a1.UL0)); - // @00145824 SLT t7, t7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); - // @00145828 BNE t7, zero, $00145854 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1333332u; - } - // @0014582C NOP - MobUt.Latency(); - } - - public virtual void funct00145830() - { - this.ee.pc = 1333316u; - // @00145830 LH t7, $000a(a0) - MobUt.LH(this.ee, this.ee.t7, (10u + this.ee.a0.UL0)); - // @00145834 LH t6, $0004(a1) - MobUt.LH(this.ee, this.ee.t6, (4u + this.ee.a1.UL0)); - // @00145838 SLT t7, t7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); - // @0014583C BNE t7, zero, $00145854 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1333332u; - } - // @00145840 NOP - MobUt.Latency(); - } - - public virtual void funct00145844() - { - this.ee.pc = 1333340u; - // @00145844 LH t6, $0004(a0) - MobUt.LH(this.ee, this.ee.t6, (4u + this.ee.a0.UL0)); - // @00145848 LH t7, $000a(a1) - MobUt.LH(this.ee, this.ee.t7, (10u + this.ee.a1.UL0)); - // @0014584C SLT t7, t7, t6 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); - // @00145850 SLTIU v0, t7, $0001 - this.ee.v0.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < 1ul)); - // @00145854 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00145858 NOP - MobUt.Latency(); - } - - public virtual void funct00145854() - { - this.ee.pc = 1333340u; - // @00145854 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00145858 NOP - MobUt.Latency(); - } - - public virtual void funct001622f8() - { - this.ee.pc = 1450784u; - // @001622F8 ADDIU sp, sp, $ff90 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -112))); - // @001622FC LW v0, $0010(a0) - MobUt.LW(this.ee, this.ee.v0, (16u + this.ee.a0.UL0)); - // @00162300 SD s0, $0040(sp) - MobUt.SD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); - // @00162304 ADDIU t7, zero, $0003 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 3))); - // @00162308 SD s1, $0048(sp) - MobUt.SD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); - // @0016230C SD s2, $0050(sp) - MobUt.SD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); - // @00162310 SD s3, $0058(sp) - MobUt.SD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); - // @00162314 SD s4, $0060(sp) - MobUt.SD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); - // @00162318 BNE v0, t7, $0016246c - if ((this.ee.v0.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 1451116u; - } - // @0016231C LUI t7, $0036 - this.ee.t7.SD0 = 3538944; - } - - public virtual void funct00162328() - { - this.ee.pc = 1450800u; - // @00162328 BLEZ v0, $00162464 - if ((this.ee.v0.SD0 <= 0)) - { - this.ee.pc = 1451108u; - } - // @0016232C DADDU t1, zero, zero - this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00162330() - { - this.ee.pc = 1450904u; - // @00162330 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00162334 ADDIU t3, sp, $0030 - this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 48))); - // @00162338 ADDIU t7, t7, $8ce0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -29472))); - // @0016233C ADDIU v1, sp, $0010 - this.ee.v1.SD0 = ((int)((this.ee.sp.SD0 + 16))); - // @00162340 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00162344 ADDIU a3, sp, $0020 - this.ee.a3.SD0 = ((int)((this.ee.sp.SD0 + 32))); - // @00162348 DADDU s3, sp, zero - this.ee.s3.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); - // @0016234C DADDU s2, t3, zero - this.ee.s2.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); - // @00162350 DADDU s1, t3, zero - this.ee.s1.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); - // @00162354 DADDU s0, v1, zero - this.ee.s0.UD0 = (this.ee.v1.UD0 + this.ee.r0.UD0); - // @00162358 DADDU t9, sp, zero - this.ee.t9.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); - // @0016235C DADDU t8, t3, zero - this.ee.t8.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); - // @00162360 SLL t6, t1, 2 - MobUt.SLL(this.ee.t6, this.ee.t1, 2); - // @00162364 ADDU t5, t6, s4 - this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s4.SD0))); - // @00162368 ADDU t2, t6, a0 - this.ee.t2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.a0.SD0))); - // @0016236C LW t7, $0000(t5) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.t5.UL0)); - // @00162370 LW t4, $0000(t2) - MobUt.LW(this.ee, this.ee.t4, (0u + this.ee.t2.UL0)); - // @00162374 SLL t7, t7, 2 - MobUt.SLL(this.ee.t7, this.ee.t7, 2); - // @00162378 ADDU t7, t7, a0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.a0.SD0))); - // @0016237C LW t6, $0000(t7) - MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.t7.UL0)); - // @00162380 LQC2 vf1, $0000(t6) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); - // @00162384 LQC2 vf2, $0000(t4) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t4.UL0)); - // @00162388 VSUB.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); - // @0016238C SQC2 vf1, $0000(s2) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); - // @00162390 BEQL sp, t3, $001623a4 - if ((this.ee.sp.UD0 == this.ee.t3.UD0)) - { - this.ee.pc = 1450916u; - // @00162394 LW t7, $0000(t2) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.t2.UL0)); - } - } - - public virtual void funct00162398() - { - this.ee.pc = 1450940u; - // @00162398 LQ t0, $0000(t3) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); - // @0016239C SQ t0, $0000(s3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); - // @001623A0 LW t7, $0000(t2) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.t2.UL0)); - // @001623A4 LQC2 vf1, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); - // @001623A8 LQC2 vf2, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t7.UL0)); - // @001623AC VSUB.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); - // @001623B0 SQC2 vf1, $0000(s1) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s1.UL0)); - // @001623B4 BEQ v1, t3, $001623c4 - if ((this.ee.v1.UD0 == this.ee.t3.UD0)) - { - this.ee.pc = 1450948u; - } - // @001623B8 NOP - MobUt.Latency(); - } - - public virtual void funct001623bc() - { - this.ee.pc = 1450980u; - // @001623BC LQ t0, $0000(t3) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); - // @001623C0 SQ t0, $0000(v1) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.v1.UL[0])); - // @001623C4 LQC2 vf1, $0000(s0) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s0.UL0)); - // @001623C8 LQC2 vf2, $0000(t9) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t9.UL0)); - // @001623CC VSUB.xyzw vf3, vf0, vf0 - this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); - this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); - this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); - this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); - // @001623D0 VOPMULA.xyz ACC, vf1, vf2 - this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); - this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); - this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); - // @001623D4 VOPMSUB.xyz vf3, vf2, vf1 - this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); - this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); - this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); - // @001623D8 SQC2 vf3, $0000(t8) - MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.t8.UL0)); - // @001623DC BEQ a3, t3, $001623ec - if ((this.ee.a3.UD0 == this.ee.t3.UD0)) - { - this.ee.pc = 1450988u; - } - // @001623E0 NOP - MobUt.Latency(); - } - - public virtual void funct001623e4() - { - this.ee.pc = 1451032u; - // @001623E4 LQ t0, $0000(t3) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); - // @001623E8 SQ t0, $0000(a3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a3.UL[0])); - // @001623EC LQC2 vf1, $0000(a3) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a3.UL0)); - // @001623F0 LQC2 vf2, $0000(a2) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a2.UL0)); - // @001623F4 VMUL.xyz vf1, vf1, vf2 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); - // @001623F8 VADDy.x vf1, vf1, vf1y - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); - // @001623FC VADDz.x vf1, vf1, vf1z - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); - // @00162400 QMFC2 t0, vf1 - MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); - // @00162404 MTC1 t0, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @00162408 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @0016240C ADDIU t1, t1, $0001 - this.ee.t1.SD0 = ((int)((this.ee.t1.SD0 + 1))); - // @00162410 BC1F $00162448 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 1451080u; - } - // @00162414 SLT t7, t1, v0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t1.SD0 < this.ee.v0.SD0)); - } - - public virtual void funct00162418() - { - this.ee.pc = 1451044u; - // @00162418 DADDU t7, a3, zero - this.ee.t7.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); - // @0016241C BEQ sp, t7, $0016242c - if ((this.ee.sp.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1451052u; - } - // @00162420 DADDU v0, zero, zero - this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct0016241c() - { - this.ee.pc = 1451044u; - // @0016241C BEQ sp, t7, $0016242c - if ((this.ee.sp.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 1451052u; - } - // @00162420 DADDU v0, zero, zero - this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00162424() - { - this.ee.pc = 1451052u; - // @00162424 BEQ zero, zero, $0016241c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1451036u; - } - // @00162428 ADDIU t7, t7, $fff0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -16))); - } - - public virtual void funct0016242c() - { - this.ee.pc = 1451080u; - // @0016242C LD s0, $0040(sp) - MobUt.LD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); - // @00162430 LD s1, $0048(sp) - MobUt.LD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); - // @00162434 LD s2, $0050(sp) - MobUt.LD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); - // @00162438 LD s3, $0058(sp) - MobUt.LD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); - // @0016243C LD s4, $0060(sp) - MobUt.LD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); - // @00162440 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00162444 ADDIU sp, sp, $0070 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 112))); - } - - public virtual void funct0016246c() - { - this.ee.pc = 1451124u; - // @0016246C BEQ zero, zero, $00162328 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1450792u; - } - // @00162470 ADDIU s4, t7, $a090 - this.ee.s4.SD0 = ((int)((this.ee.t7.SD0 + -24432))); - } - - public virtual void funct00162670() - { - this.ee.pc = 1451696u; - // @00162670 ADDIU sp, sp, $ffe0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); - // @00162674 DADDU t4, a1, zero - this.ee.t4.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - // @00162678 SD ra, $0010(sp) - MobUt.SD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - // @0016267C DADDU a1, a3, zero - this.ee.a1.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); - // @00162680 ADDIU t5, a0, $0010 - this.ee.t5.SD0 = ((int)((this.ee.a0.SD0 + 16))); - // @00162684 LQC2 vf1, $0000(a2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a2.UL0)); - // @00162688 LQC2 vf2, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t5.UL0)); - // @0016268C VMUL.xyz vf1, vf1, vf2 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); - // @00162690 VADDy.x vf1, vf1, vf1y - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); - // @00162694 VADDz.x vf1, vf1, vf1z - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); - // @00162698 QMFC2 t0, vf1 - MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); - // @0016269C MTC1 t0, $f2 - this.ee.fpr[2].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @001626A0 MTC1 zero, $f3 - this.ee.fpr[3].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @001626A4 C.LE.S $f3, $f2 - this.ee.fcr31_23 = (this.ee.fpr[3].f <= this.ee.fpr[2].f); - // @001626A8 BC1T $00162774 - if (this.ee.fcr31_23) - { - this.ee.pc = 1451892u; - } - // @001626AC DADDU v0, zero, zero - this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct001626b0() - { - this.ee.pc = 1451796u; - // @001626B0 LW t7, $0000(t4) - MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.t4.UL0)); - // @001626B4 LQC2 vf1, $0000(a2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a2.UL0)); - // @001626B8 LQC2 vf2, $0000(t7) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t7.UL0)); - // @001626BC VMUL.xyz vf1, vf1, vf2 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); - // @001626C0 VADDy.x vf1, vf1, vf1y - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); - // @001626C4 VADDz.x vf1, vf1, vf1z - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); - // @001626C8 QMFC2 t0, vf1 - MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); - // @001626CC MTC1 t0, $f1 - this.ee.fpr[1].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @001626D0 LQC2 vf1, $0000(a2) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a2.UL0)); - // @001626D4 LQC2 vf2, $0000(a0) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a0.UL0)); - // @001626D8 VMUL.xyz vf1, vf1, vf2 - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); - // @001626DC VADDy.x vf1, vf1, vf1y - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); - // @001626E0 VADDz.x vf1, vf1, vf1z - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); - // @001626E4 QMFC2 t0, vf1 - MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); - // @001626E8 MTC1 t0, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); - // @001626EC SUB.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); - // @001626F0 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @001626F4 ADDIU t7, t7, $8ce8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -29464))); - // @001626F8 NOP - MobUt.Latency(); - // @001626FC NOP - MobUt.Latency(); - // @00162700 DIV.S $f1, $f1, $f2 - this.ee.fpr[1].f = (this.ee.fpr[1].f / this.ee.fpr[2].f); - // @00162704 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00162708 C.LT.S $f0, $f1 - this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[1].f); - // @0016270C BC1TL $00162778 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1451896u; - // @00162710 LD ra, $0010(sp) - MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - } - } - - public virtual void funct00162714() - { - this.ee.pc = 1451808u; - // @00162714 C.LT.S $f1, $f3 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[3].f); - // @00162718 BC1TL $00162778 - if ((this.ee.fcr31_23 == true)) - { - this.ee.pc = 1451896u; - // @0016271C LD ra, $0010(sp) - MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - } - } - - public virtual void funct00162720() - { - this.ee.pc = 1451836u; - // @00162720 LQC2 vf1, $0000(t5) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); - // @00162724 MFC1 t0, $f1 - MobUt.MFC1(this.ee.t0, this.ee.fpr[1]); - // @00162728 QMTC2 t0, vf2 - MobUt.QMTC2(this.ee.t0, this.ee.VF[2]); - // @0016272C VMULx.xyzw vf1, vf1, vf2x - this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); - this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].x); - this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].x); - this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].x); - // @00162730 SQC2 vf1, $0000(sp) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @00162734 BEQ a3, sp, $00162744 - if ((this.ee.a3.UD0 == this.ee.sp.UD0)) - { - this.ee.pc = 1451844u; - } - // @00162738 NOP - MobUt.Latency(); - } - - public virtual void funct0016273c() - { - this.ee.pc = 1451868u; - // @0016273C LQ t0, $0000(sp) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); - // @00162740 SQ t0, $0000(a3) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a3.UL[0])); - // @00162744 LQC2 vf1, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); - // @00162748 LQC2 vf2, $0000(a0) - MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a0.UL0)); - // @0016274C VADD.xyzw vf1, vf1, vf2 - this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[2].x); - this.ee.VF[1].y = (this.ee.VF[1].y + this.ee.VF[2].y); - this.ee.VF[1].z = (this.ee.VF[1].z + this.ee.VF[2].z); - this.ee.VF[1].w = (this.ee.VF[1].w + this.ee.VF[2].w); - // @00162750 SQC2 vf1, $0000(sp) - MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); - // @00162754 BEQL a1, sp, $00162768 - if ((this.ee.a1.UD0 == this.ee.sp.UD0)) - { - this.ee.pc = 1451880u; - // @00162758 SWC1 $f0, $000c(a1) - MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.a1.UL0)); - } - } - - public virtual void funct0016275c() - { - this.ee.pc = 1451888u; - // @0016275C LQ t0, $0000(sp) - MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); - // @00162760 SQ t0, $0000(a1) - MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); - // @00162764 SWC1 $f0, $000c(a1) - MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.a1.UL0)); - // @00162768 JAL $001622f8 - this.ee.ra.UL0 = 1451888u; - this.ee.pc = 1450744u; - // @0016276C DADDU a0, t4, zero - this.ee.a0.UD0 = (this.ee.t4.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00162770() - { - this.ee.pc = 1451904u; - // @00162770 SLTU v0, zero, v0 - this.ee.v0.UD0 = System.Convert.ToByte((this.ee.r0.UD0 < this.ee.v0.UD0)); - // @00162774 LD ra, $0010(sp) - MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - // @00162778 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0016277C ADDIU sp, sp, $0020 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); - } - - public virtual void funct00162778() - { - this.ee.pc = 1451904u; - // @00162778 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0016277C ADDIU sp, sp, $0020 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); - } - - public virtual void funct00165aa8() - { - this.ee.pc = 1465116u; - // @00165AA8 ADDIU sp, sp, $ff90 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -112))); - // @00165AAC SW zero, $0000(t2) - MobUt.SW(this.ee, this.ee.r0, (0u + this.ee.t2.UL0)); - // @00165AB0 ADDIU t7, zero, $ffff - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); - // @00165AB4 SD s0, $0020(sp) - MobUt.SD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); - // @00165AB8 SH t7, $0010(sp) - MobUt.SH(this.ee, this.ee.t7, (16u + this.ee.sp.UL0)); - // @00165ABC ADDIU t6, sp, $0070 - this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 112))); - // @00165AC0 SD s2, $0030(sp) - MobUt.SD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); - // @00165AC4 DADDU s0, zero, zero - this.ee.s0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00165AC8 SD s3, $0038(sp) - MobUt.SD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); - // @00165ACC SD s4, $0040(sp) - MobUt.SD(this.ee, this.ee.s4, (64u + this.ee.sp.UL0)); - // @00165AD0 ANDI s2, t1, $00ff - this.ee.s2.UD0 = ((ushort)((this.ee.t1.US0 & 255))); - // @00165AD4 SD s5, $0048(sp) - MobUt.SD(this.ee, this.ee.s5, (72u + this.ee.sp.UL0)); - // @00165AD8 DADDU s3, t0, zero - this.ee.s3.UD0 = (this.ee.t0.UD0 + this.ee.r0.UD0); - // @00165ADC SD s6, $0050(sp) - MobUt.SD(this.ee, this.ee.s6, (80u + this.ee.sp.UL0)); - // @00165AE0 DADDU s4, a3, zero - this.ee.s4.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); - // @00165AE4 SD s7, $0058(sp) - MobUt.SD(this.ee, this.ee.s7, (88u + this.ee.sp.UL0)); - // @00165AE8 DADDU s5, a1, zero - this.ee.s5.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); - // @00165AEC SD s8, $0060(sp) - MobUt.SD(this.ee, this.ee.s8, (96u + this.ee.sp.UL0)); - // @00165AF0 DADDU s6, a2, zero - this.ee.s6.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); - // @00165AF4 SH t7, $0000(a2) - MobUt.SH(this.ee, this.ee.t7, (0u + this.ee.a2.UL0)); - // @00165AF8 DADDU s7, t2, zero - this.ee.s7.UD0 = (this.ee.t2.UD0 + this.ee.r0.UD0); - // @00165AFC SD s1, $0028(sp) - MobUt.SD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); - // @00165B00 DADDU s8, t3, zero - this.ee.s8.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); - // @00165B04 SD ra, $0068(sp) - MobUt.SD(this.ee, this.ee.ra, (104u + this.ee.sp.UL0)); - // @00165B08 SW a0, $0014(sp) - MobUt.SW(this.ee, this.ee.a0, (20u + this.ee.sp.UL0)); - // @00165B0C LW s1, $0000(t6) - MobUt.LW(this.ee, this.ee.s1, (0u + this.ee.t6.UL0)); - // @00165B10 SW zero, $0018(sp) - MobUt.SW(this.ee, this.ee.r0, (24u + this.ee.sp.UL0)); - // @00165B14 JAL $00165be0 - this.ee.ra.UL0 = 1465116u; - this.ee.pc = 1465312u; - // @00165B18 DADDU a0, s0, zero - this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00165b1c() - { - this.ee.pc = 1465124u; - // @00165B1C BNE v0, zero, $00165b58 - if ((this.ee.v0.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 1465176u; - } - // @00165B20 DADDU s0, v0, zero - this.ee.s0.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00165b24() - { - this.ee.pc = 1465176u; - // @00165B24 LW v0, $0018(sp) - MobUt.LW(this.ee, this.ee.v0, (24u + this.ee.sp.UL0)); - // @00165B28 LD s0, $0020(sp) - MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); - // @00165B2C LD s1, $0028(sp) - MobUt.LD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); - // @00165B30 LD s2, $0030(sp) - MobUt.LD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); - // @00165B34 LD s3, $0038(sp) - MobUt.LD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); - // @00165B38 LD s4, $0040(sp) - MobUt.LD(this.ee, this.ee.s4, (64u + this.ee.sp.UL0)); - // @00165B3C LD s5, $0048(sp) - MobUt.LD(this.ee, this.ee.s5, (72u + this.ee.sp.UL0)); - // @00165B40 LD s6, $0050(sp) - MobUt.LD(this.ee, this.ee.s6, (80u + this.ee.sp.UL0)); - // @00165B44 LD s7, $0058(sp) - MobUt.LD(this.ee, this.ee.s7, (88u + this.ee.sp.UL0)); - // @00165B48 LD s8, $0060(sp) - MobUt.LD(this.ee, this.ee.s8, (96u + this.ee.sp.UL0)); - // @00165B4C LD ra, $0068(sp) - MobUt.LD(this.ee, this.ee.ra, (104u + this.ee.sp.UL0)); - // @00165B50 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00165B54 ADDIU sp, sp, $0070 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 112))); - } - - public virtual void funct00165be0() - { - this.ee.pc = 1465328u; - // @00165BE0 LUI t7, $0052 - this.ee.t7.SD0 = 5373952; - // @00165BE4 LW t6, $e8c0(t7) - MobUt.LW(this.ee, this.ee.t6, (4294961344u + this.ee.t7.UL0)); - // @00165BE8 BEQ a0, zero, $00165bf4 - if ((this.ee.a0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1465332u; - } - // @00165BEC DADDU v0, t6, zero - this.ee.v0.UD0 = (this.ee.t6.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00165bf4() - { - this.ee.pc = 1465340u; - // @00165BF4 BEQ v0, zero, $00165c0c - if ((this.ee.v0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 1465356u; - } - // @00165BF8 DADDU a0, v0, zero - this.ee.a0.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00165c0c() - { - this.ee.pc = 1465364u; - // @00165C0C JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00165C10 NOP - MobUt.Latency(); - } - - public virtual void funct002fa938() - { - this.ee.pc = 3123608u; - // @002FA938 LUI t0, $0037 - this.ee.t0.SD0 = 3604480; - // @002FA93C ADDIU t0, t0, $12e0 - this.ee.t0.SD0 = ((int)((this.ee.t0.SD0 + 4832))); - // @002FA940 LQC2 vf5, $0000(t0) - MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t0.UL0)); - // @002FA944 VMR32.w vf6, vf6 - this.ee.VF[6].w = this.ee.VF[6].x; - // @002FA948 VADDx.x vf4, vf0, vf6x - this.ee.VF[4].x = (this.ee.VF[0].x + this.ee.VF[6].x); - // @002FA94C VMUL.x vf6, vf6, vf6 - this.ee.VF[6].x = MobUt.MUL(this.ee.VF[6].x, this.ee.VF[6].x); - // @002FA950 VMULx.yzw vf4, vf4, vf0x - this.ee.VF[4].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[0].x); - this.ee.VF[4].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[0].x); - this.ee.VF[4].w = MobUt.MUL(this.ee.VF[4].w, this.ee.VF[0].x); - // @002FA954 VMULw.xyzw vf8, vf5, vf6w - this.ee.VF[8].x = MobUt.MUL(this.ee.VF[5].x, this.ee.VF[6].w); - this.ee.VF[8].y = MobUt.MUL(this.ee.VF[5].y, this.ee.VF[6].w); - this.ee.VF[8].z = MobUt.MUL(this.ee.VF[5].z, this.ee.VF[6].w); - this.ee.VF[8].w = MobUt.MUL(this.ee.VF[5].w, this.ee.VF[6].w); - // @002FA958 VSUB.xyzw vf5, vf0, vf0 - this.ee.VF[5].x = (this.ee.VF[0].x - this.ee.VF[0].x); - this.ee.VF[5].y = (this.ee.VF[0].y - this.ee.VF[0].y); - this.ee.VF[5].z = (this.ee.VF[0].z - this.ee.VF[0].z); - this.ee.VF[5].w = (this.ee.VF[0].w - this.ee.VF[0].w); - // @002FA95C VMULx.xyzw vf8, vf8, vf6x - this.ee.VF[8].x = MobUt.MUL(this.ee.VF[8].x, this.ee.VF[6].x); - this.ee.VF[8].y = MobUt.MUL(this.ee.VF[8].y, this.ee.VF[6].x); - this.ee.VF[8].z = MobUt.MUL(this.ee.VF[8].z, this.ee.VF[6].x); - this.ee.VF[8].w = MobUt.MUL(this.ee.VF[8].w, this.ee.VF[6].x); - // @002FA960 VMULx.xyz vf8, vf8, vf6x - this.ee.VF[8].x = MobUt.MUL(this.ee.VF[8].x, this.ee.VF[6].x); - this.ee.VF[8].y = MobUt.MUL(this.ee.VF[8].y, this.ee.VF[6].x); - this.ee.VF[8].z = MobUt.MUL(this.ee.VF[8].z, this.ee.VF[6].x); - // @002FA964 VADDw.x vf4, vf4, vf8w - this.ee.VF[4].x = (this.ee.VF[4].x + this.ee.VF[8].w); - // @002FA968 VMULx.xy vf8, vf8, vf6x - this.ee.VF[8].x = MobUt.MUL(this.ee.VF[8].x, this.ee.VF[6].x); - this.ee.VF[8].y = MobUt.MUL(this.ee.VF[8].y, this.ee.VF[6].x); - // @002FA96C VADDz.x vf4, vf4, vf8z - this.ee.VF[4].x = (this.ee.VF[4].x + this.ee.VF[8].z); - // @002FA970 VMULx.x vf8, vf8, vf6x - this.ee.VF[8].x = MobUt.MUL(this.ee.VF[8].x, this.ee.VF[6].x); - // @002FA974 VADDy.x vf4, vf4, vf8y - this.ee.VF[4].x = (this.ee.VF[4].x + this.ee.VF[8].y); - // @002FA978 VADDx.x vf4, vf4, vf8x - this.ee.VF[4].x = (this.ee.VF[4].x + this.ee.VF[8].x); - // @002FA97C VADDx.xy vf4, vf5, vf4x - this.ee.VF[4].x = (this.ee.VF[5].x + this.ee.VF[4].x); - this.ee.VF[4].y = (this.ee.VF[5].y + this.ee.VF[4].x); - // @002FA980 VMUL.x vf7, vf4, vf4 - this.ee.VF[7].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[4].x); - // @002FA984 VSUBx.w vf7, vf0, vf7x - this.ee.VF[7].w = (this.ee.VF[0].w - this.ee.VF[7].x); - // @002FA988 VSQRT Q, vf7w - this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[7].w)))); - // @002FA98C VWAITQ - MobUt.Latency(); - // @002FA990 BNE a3, zero, $002fa9a0 - if ((this.ee.a3.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3123616u; - } - // @002FA994 VADDq.x vf7, vf0, Q - this.ee.VF[7].x = (this.ee.VF[0].x + this.ee.Vq.f); - } - - public virtual void funct002fa998() - { - this.ee.pc = 3123616u; - // @002FA998 BEQ zero, zero, $002fa9a4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3123620u; - } - // @002FA99C VADDx.x vf4, vf5, vf7x - this.ee.VF[4].x = (this.ee.VF[5].x + this.ee.VF[7].x); - } - - public virtual void funct002fa9a0() - { - this.ee.pc = 3123628u; - // @002FA9A0 VSUBx.x vf4, vf5, vf7x - this.ee.VF[4].x = (this.ee.VF[5].x - this.ee.VF[7].x); - // @002FA9A4 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @002FA9A8 NOP - MobUt.Latency(); - } - - public virtual void funct002fa9a4() - { - this.ee.pc = 3123628u; - // @002FA9A4 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @002FA9A8 NOP - MobUt.Latency(); - } - - public virtual void funct002fa9b0() - { - this.ee.pc = 3123660u; - // @002FA9B0 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @002FA9B4 C.LT.S $f12, $f0 - this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[0].f); - // @002FA9B8 LUI at, $3fc9 - this.ee.at.SD0 = 1070137344; - // @002FA9BC ORI at, at, $0fdb - this.ee.at.UD0 = (this.ee.at.UD0 | 4059); - // @002FA9C0 MTC1 at, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.at.UL[0]); - // @002FA9C4 BC1F $002fa9d8 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 3123672u; - } - // @002FA9C8 NOP - MobUt.Latency(); - } - - public virtual void funct002fa9cc() - { - this.ee.pc = 3123672u; - // @002FA9CC ADD.S $f12, $f0, $f12 - this.ee.fpr[12].f = (this.ee.fpr[0].f + this.ee.fpr[12].f); - // @002FA9D0 J $002fa9e0 - this.ee.pc = 3123680u; - // @002FA9D4 ADDIU a3, zero, $0001 - this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 1))); - } - - public virtual void funct002fa9d8() - { - this.ee.pc = 3123700u; - // @002FA9D8 SUB.S $f12, $f0, $f12 - this.ee.fpr[12].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); - // @002FA9DC DADDU a3, zero, zero - this.ee.a3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @002FA9E0 MFC1 t0, $f12 - MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); - // @002FA9E4 QMTC2 t0, vf6 - MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); - // @002FA9E8 DADDU a2, ra, zero - this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); - // @002FA9EC JAL $002fa938 - this.ee.ra.UL0 = 3123700u; - this.ee.pc = 3123512u; - // @002FA9F0 NOP - MobUt.Latency(); - } - - public virtual void funct002fa9e0() - { - this.ee.pc = 3123700u; - // @002FA9E0 MFC1 t0, $f12 - MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); - // @002FA9E4 QMTC2 t0, vf6 - MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); - // @002FA9E8 DADDU a2, ra, zero - this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); - // @002FA9EC JAL $002fa938 - this.ee.ra.UL0 = 3123700u; - this.ee.pc = 3123512u; - // @002FA9F0 NOP - MobUt.Latency(); - } - - public virtual void funct002fa9f4() - { - this.ee.pc = 3123788u; - // @002FA9F4 DADDU ra, a2, zero - this.ee.ra.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); - // @002FA9F8 VMOVE.xyzw vf6, vf5 - this.ee.VF[6].x = this.ee.VF[5].x; - this.ee.VF[6].y = this.ee.VF[5].y; - this.ee.VF[6].z = this.ee.VF[5].z; - this.ee.VF[6].w = this.ee.VF[5].w; - // @002FA9FC VMOVE.xyzw vf7, vf5 - this.ee.VF[7].x = this.ee.VF[5].x; - this.ee.VF[7].y = this.ee.VF[5].y; - this.ee.VF[7].z = this.ee.VF[5].z; - this.ee.VF[7].w = this.ee.VF[5].w; - // @002FAA00 VMOVE.xyzw vf9, vf0 - this.ee.VF[9].x = this.ee.VF[0].x; - this.ee.VF[9].y = this.ee.VF[0].y; - this.ee.VF[9].z = this.ee.VF[0].z; - this.ee.VF[9].w = this.ee.VF[0].w; - // @002FAA04 VSUB.xyz vf9, vf9, vf9 - this.ee.VF[9].x = (this.ee.VF[9].x - this.ee.VF[9].x); - this.ee.VF[9].y = (this.ee.VF[9].y - this.ee.VF[9].y); - this.ee.VF[9].z = (this.ee.VF[9].z - this.ee.VF[9].z); - // @002FAA08 VMR32.xyzw vf8, vf9 - this.ee.VF[8].x = this.ee.VF[9].y; - this.ee.VF[8].y = this.ee.VF[9].z; - this.ee.VF[8].z = this.ee.VF[9].w; - this.ee.VF[8].w = this.ee.VF[9].x; - // @002FAA0C VSUB.zw vf4, vf4, vf4 - this.ee.VF[4].z = (this.ee.VF[4].z - this.ee.VF[4].z); - this.ee.VF[4].w = (this.ee.VF[4].w - this.ee.VF[4].w); - // @002FAA10 VADDx.y vf6, vf5, vf4x - this.ee.VF[6].y = (this.ee.VF[5].y + this.ee.VF[4].x); - // @002FAA14 VADDy.x vf6, vf5, vf4y - this.ee.VF[6].x = (this.ee.VF[5].x + this.ee.VF[4].y); - // @002FAA18 VSUBx.x vf7, vf5, vf4x - this.ee.VF[7].x = (this.ee.VF[5].x - this.ee.VF[4].x); - // @002FAA1C VADDy.y vf7, vf5, vf4y - this.ee.VF[7].y = (this.ee.VF[5].y + this.ee.VF[4].y); - // @002FAA20 ADDIU a3, zero, $0004 - this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 4))); - // @002FAA24 LQC2 vf4, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); - // @002FAA28 VMULAx.xyzw ACC, vf6, vf4x - // @002FAA2C VMADDAy.xyzw ACC, vf7, vf4y - // @002FAA30 VMADDAz.xyzw ACC, vf8, vf4z - // @002FAA34 VMADDw.xyzw vf5, vf9, vf4w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); - // @002FAA38 SQC2 vf5, $0000(a0) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); - // @002FAA3C ADDI a3, a3, $ffff - this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); - // @002FAA40 ADDI a1, a1, $0010 - this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); - // @002FAA44 BNE zero, a3, $002faa24 - if ((this.ee.r0.UD0 != this.ee.a3.UD0)) - { - this.ee.pc = 3123748u; - } - // @002FAA48 ADDI a0, a0, $0010 - this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); - } - - public virtual void funct002faa24() - { - this.ee.pc = 3123788u; - // @002FAA24 LQC2 vf4, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); - // @002FAA28 VMULAx.xyzw ACC, vf6, vf4x - // @002FAA2C VMADDAy.xyzw ACC, vf7, vf4y - // @002FAA30 VMADDAz.xyzw ACC, vf8, vf4z - // @002FAA34 VMADDw.xyzw vf5, vf9, vf4w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); - // @002FAA38 SQC2 vf5, $0000(a0) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); - // @002FAA3C ADDI a3, a3, $ffff - this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); - // @002FAA40 ADDI a1, a1, $0010 - this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); - // @002FAA44 BNE zero, a3, $002faa24 - if ((this.ee.r0.UD0 != this.ee.a3.UD0)) - { - this.ee.pc = 3123748u; - } - // @002FAA48 ADDI a0, a0, $0010 - this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); - } - - public virtual void funct002faa4c() - { - this.ee.pc = 3123796u; - // @002FAA4C JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @002FAA50 NOP - MobUt.Latency(); - } - - public virtual void funct002faa58() - { - this.ee.pc = 3123828u; - // @002FAA58 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @002FAA5C C.LT.S $f12, $f0 - this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[0].f); - // @002FAA60 LUI at, $3fc9 - this.ee.at.SD0 = 1070137344; - // @002FAA64 ORI at, at, $0fdb - this.ee.at.UD0 = (this.ee.at.UD0 | 4059); - // @002FAA68 MTC1 at, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.at.UL[0]); - // @002FAA6C BC1F $002faa80 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 3123840u; - } - // @002FAA70 NOP - MobUt.Latency(); - } - - public virtual void funct002faa74() - { - this.ee.pc = 3123840u; - // @002FAA74 ADD.S $f12, $f0, $f12 - this.ee.fpr[12].f = (this.ee.fpr[0].f + this.ee.fpr[12].f); - // @002FAA78 J $002faa88 - this.ee.pc = 3123848u; - // @002FAA7C ADDIU a3, zero, $0001 - this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 1))); - } - - public virtual void funct002faa80() - { - this.ee.pc = 3123868u; - // @002FAA80 SUB.S $f12, $f0, $f12 - this.ee.fpr[12].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); - // @002FAA84 DADDU a3, zero, zero - this.ee.a3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @002FAA88 MFC1 t0, $f12 - MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); - // @002FAA8C QMTC2 t0, vf6 - MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); - // @002FAA90 DADDU a2, ra, zero - this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); - // @002FAA94 JAL $002fa938 - this.ee.ra.UL0 = 3123868u; - this.ee.pc = 3123512u; - // @002FAA98 NOP - MobUt.Latency(); - } - - public virtual void funct002faa88() - { - this.ee.pc = 3123868u; - // @002FAA88 MFC1 t0, $f12 - MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); - // @002FAA8C QMTC2 t0, vf6 - MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); - // @002FAA90 DADDU a2, ra, zero - this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); - // @002FAA94 JAL $002fa938 - this.ee.ra.UL0 = 3123868u; - this.ee.pc = 3123512u; - // @002FAA98 NOP - MobUt.Latency(); - } - - public virtual void funct002faa9c() - { - this.ee.pc = 3123960u; - // @002FAA9C DADDU ra, a2, zero - this.ee.ra.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); - // @002FAAA0 VMOVE.xyzw vf6, vf5 - this.ee.VF[6].x = this.ee.VF[5].x; - this.ee.VF[6].y = this.ee.VF[5].y; - this.ee.VF[6].z = this.ee.VF[5].z; - this.ee.VF[6].w = this.ee.VF[5].w; - // @002FAAA4 VMOVE.xyzw vf7, vf5 - this.ee.VF[7].x = this.ee.VF[5].x; - this.ee.VF[7].y = this.ee.VF[5].y; - this.ee.VF[7].z = this.ee.VF[5].z; - this.ee.VF[7].w = this.ee.VF[5].w; - // @002FAAA8 VMOVE.xyzw vf8, vf5 - this.ee.VF[8].x = this.ee.VF[5].x; - this.ee.VF[8].y = this.ee.VF[5].y; - this.ee.VF[8].z = this.ee.VF[5].z; - this.ee.VF[8].w = this.ee.VF[5].w; - // @002FAAAC VMOVE.xyzw vf9, vf5 - this.ee.VF[9].x = this.ee.VF[5].x; - this.ee.VF[9].y = this.ee.VF[5].y; - this.ee.VF[9].z = this.ee.VF[5].z; - this.ee.VF[9].w = this.ee.VF[5].w; - // @002FAAB0 VADDw.x vf6, vf5, vf0w - this.ee.VF[6].x = (this.ee.VF[5].x + this.ee.VF[0].w); - // @002FAAB4 VADDw.w vf9, vf5, vf0w - this.ee.VF[9].w = (this.ee.VF[5].w + this.ee.VF[0].w); - // @002FAAB8 VSUB.zw vf4, vf4, vf4 - this.ee.VF[4].z = (this.ee.VF[4].z - this.ee.VF[4].z); - this.ee.VF[4].w = (this.ee.VF[4].w - this.ee.VF[4].w); - // @002FAABC VADDx.z vf7, vf5, vf4x - this.ee.VF[7].z = (this.ee.VF[5].z + this.ee.VF[4].x); - // @002FAAC0 VADDy.y vf7, vf5, vf4y - this.ee.VF[7].y = (this.ee.VF[5].y + this.ee.VF[4].y); - // @002FAAC4 VSUBx.y vf8, vf5, vf4x - this.ee.VF[8].y = (this.ee.VF[5].y - this.ee.VF[4].x); - // @002FAAC8 VADDy.z vf8, vf5, vf4y - this.ee.VF[8].z = (this.ee.VF[5].z + this.ee.VF[4].y); - // @002FAACC ADDIU a3, zero, $0004 - this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 4))); - // @002FAAD0 LQC2 vf4, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); - // @002FAAD4 VMULAx.xyzw ACC, vf6, vf4x - // @002FAAD8 VMADDAy.xyzw ACC, vf7, vf4y - // @002FAADC VMADDAz.xyzw ACC, vf8, vf4z - // @002FAAE0 VMADDw.xyzw vf5, vf9, vf4w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); - // @002FAAE4 SQC2 vf5, $0000(a0) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); - // @002FAAE8 ADDI a3, a3, $ffff - this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); - // @002FAAEC ADDI a1, a1, $0010 - this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); - // @002FAAF0 BNE zero, a3, $002faad0 - if ((this.ee.r0.UD0 != this.ee.a3.UD0)) - { - this.ee.pc = 3123920u; - } - // @002FAAF4 ADDI a0, a0, $0010 - this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); - } - - public virtual void funct002faad0() - { - this.ee.pc = 3123960u; - // @002FAAD0 LQC2 vf4, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); - // @002FAAD4 VMULAx.xyzw ACC, vf6, vf4x - // @002FAAD8 VMADDAy.xyzw ACC, vf7, vf4y - // @002FAADC VMADDAz.xyzw ACC, vf8, vf4z - // @002FAAE0 VMADDw.xyzw vf5, vf9, vf4w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); - // @002FAAE4 SQC2 vf5, $0000(a0) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); - // @002FAAE8 ADDI a3, a3, $ffff - this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); - // @002FAAEC ADDI a1, a1, $0010 - this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); - // @002FAAF0 BNE zero, a3, $002faad0 - if ((this.ee.r0.UD0 != this.ee.a3.UD0)) - { - this.ee.pc = 3123920u; - } - // @002FAAF4 ADDI a0, a0, $0010 - this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); - } - - public virtual void funct002faaf8() - { - this.ee.pc = 3123968u; - // @002FAAF8 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @002FAAFC NOP - MobUt.Latency(); - } - - public virtual void funct002fab00() - { - this.ee.pc = 3123996u; - // @002FAB00 MTC1 zero, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); - // @002FAB04 C.LT.S $f12, $f0 - this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[0].f); - // @002FAB08 LUI at, $3fc9 - this.ee.at.SD0 = 1070137344; - // @002FAB0C ORI at, at, $0fdb - this.ee.at.UD0 = (this.ee.at.UD0 | 4059); - // @002FAB10 MTC1 at, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.at.UL[0]); - // @002FAB14 BC1F $002fab28 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 3124008u; - } - // @002FAB18 NOP - MobUt.Latency(); - } - - public virtual void funct002fab1c() - { - this.ee.pc = 3124008u; - // @002FAB1C ADD.S $f12, $f0, $f12 - this.ee.fpr[12].f = (this.ee.fpr[0].f + this.ee.fpr[12].f); - // @002FAB20 J $002fab30 - this.ee.pc = 3124016u; - // @002FAB24 ADDIU a3, zero, $0001 - this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 1))); - } - - public virtual void funct002fab28() - { - this.ee.pc = 3124036u; - // @002FAB28 SUB.S $f12, $f0, $f12 - this.ee.fpr[12].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); - // @002FAB2C DADDU a3, zero, zero - this.ee.a3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @002FAB30 MFC1 t0, $f12 - MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); - // @002FAB34 QMTC2 t0, vf6 - MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); - // @002FAB38 DADDU a2, ra, zero - this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); - // @002FAB3C JAL $002fa938 - this.ee.ra.UL0 = 3124036u; - this.ee.pc = 3123512u; - // @002FAB40 NOP - MobUt.Latency(); - } - - public virtual void funct002fab30() - { - this.ee.pc = 3124036u; - // @002FAB30 MFC1 t0, $f12 - MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); - // @002FAB34 QMTC2 t0, vf6 - MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); - // @002FAB38 DADDU a2, ra, zero - this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); - // @002FAB3C JAL $002fa938 - this.ee.ra.UL0 = 3124036u; - this.ee.pc = 3123512u; - // @002FAB40 NOP - MobUt.Latency(); - } - - public virtual void funct002fab44() - { - this.ee.pc = 3124128u; - // @002FAB44 DADDU ra, a2, zero - this.ee.ra.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); - // @002FAB48 VMOVE.xyzw vf6, vf5 - this.ee.VF[6].x = this.ee.VF[5].x; - this.ee.VF[6].y = this.ee.VF[5].y; - this.ee.VF[6].z = this.ee.VF[5].z; - this.ee.VF[6].w = this.ee.VF[5].w; - // @002FAB4C VMOVE.xyzw vf7, vf5 - this.ee.VF[7].x = this.ee.VF[5].x; - this.ee.VF[7].y = this.ee.VF[5].y; - this.ee.VF[7].z = this.ee.VF[5].z; - this.ee.VF[7].w = this.ee.VF[5].w; - // @002FAB50 VMOVE.xyzw vf8, vf5 - this.ee.VF[8].x = this.ee.VF[5].x; - this.ee.VF[8].y = this.ee.VF[5].y; - this.ee.VF[8].z = this.ee.VF[5].z; - this.ee.VF[8].w = this.ee.VF[5].w; - // @002FAB54 VMOVE.xyzw vf9, vf5 - this.ee.VF[9].x = this.ee.VF[5].x; - this.ee.VF[9].y = this.ee.VF[5].y; - this.ee.VF[9].z = this.ee.VF[5].z; - this.ee.VF[9].w = this.ee.VF[5].w; - // @002FAB58 VADDw.y vf7, vf5, vf0w - this.ee.VF[7].y = (this.ee.VF[5].y + this.ee.VF[0].w); - // @002FAB5C VADDw.w vf9, vf5, vf0w - this.ee.VF[9].w = (this.ee.VF[5].w + this.ee.VF[0].w); - // @002FAB60 VSUB.zw vf4, vf4, vf4 - this.ee.VF[4].z = (this.ee.VF[4].z - this.ee.VF[4].z); - this.ee.VF[4].w = (this.ee.VF[4].w - this.ee.VF[4].w); - // @002FAB64 VSUBx.z vf6, vf5, vf4x - this.ee.VF[6].z = (this.ee.VF[5].z - this.ee.VF[4].x); - // @002FAB68 VADDy.x vf6, vf5, vf4y - this.ee.VF[6].x = (this.ee.VF[5].x + this.ee.VF[4].y); - // @002FAB6C VADDx.x vf8, vf5, vf4x - this.ee.VF[8].x = (this.ee.VF[5].x + this.ee.VF[4].x); - // @002FAB70 VADDy.z vf8, vf5, vf4y - this.ee.VF[8].z = (this.ee.VF[5].z + this.ee.VF[4].y); - // @002FAB74 ADDIU a3, zero, $0004 - this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 4))); - // @002FAB78 LQC2 vf4, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); - // @002FAB7C VMULAx.xyzw ACC, vf6, vf4x - // @002FAB80 VMADDAy.xyzw ACC, vf7, vf4y - // @002FAB84 VMADDAz.xyzw ACC, vf8, vf4z - // @002FAB88 VMADDw.xyzw vf5, vf9, vf4w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); - // @002FAB8C SQC2 vf5, $0000(a0) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); - // @002FAB90 ADDI a3, a3, $ffff - this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); - // @002FAB94 ADDI a1, a1, $0010 - this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); - // @002FAB98 BNE zero, a3, $002fab78 - if ((this.ee.r0.UD0 != this.ee.a3.UD0)) - { - this.ee.pc = 3124088u; - } - // @002FAB9C ADDI a0, a0, $0010 - this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); - } - - public virtual void funct002fab78() - { - this.ee.pc = 3124128u; - // @002FAB78 LQC2 vf4, $0000(a1) - MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); - // @002FAB7C VMULAx.xyzw ACC, vf6, vf4x - // @002FAB80 VMADDAy.xyzw ACC, vf7, vf4y - // @002FAB84 VMADDAz.xyzw ACC, vf8, vf4z - // @002FAB88 VMADDw.xyzw vf5, vf9, vf4w - MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); - // @002FAB8C SQC2 vf5, $0000(a0) - MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); - // @002FAB90 ADDI a3, a3, $ffff - this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); - // @002FAB94 ADDI a1, a1, $0010 - this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); - // @002FAB98 BNE zero, a3, $002fab78 - if ((this.ee.r0.UD0 != this.ee.a3.UD0)) - { - this.ee.pc = 3124088u; - } - // @002FAB9C ADDI a0, a0, $0010 - this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); - } - - public virtual void funct002faba0() - { - this.ee.pc = 3124136u; - // @002FABA0 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @002FABA4 NOP - MobUt.Latency(); - } - - public virtual void funct002ff210() - { - this.ee.pc = 3142212u; - // @002FF210 ADDIU sp, sp, $ffe0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); - // @002FF214 SD s1, $0008(sp) - MobUt.SD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); - // @002FF218 LUI t6, $7fff - this.ee.t6.SD0 = 2147418112; - // @002FF21C SD s0, $0000(sp) - MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @002FF220 ORI t6, t6, $ffff - this.ee.t6.UD0 = (this.ee.t6.UD0 | 65535); - // @002FF224 MFC1 s1, $f12 - MobUt.MFC1(this.ee.s1, this.ee.fpr[12]); - // @002FF228 LUI t7, $507f - this.ee.t7.SD0 = 1350500352; - // @002FF22C ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @002FF230 SD ra, $0010(sp) - MobUt.SD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - // @002FF234 AND s0, s1, t6 - this.ee.s0.UD0 = (this.ee.s1.UD0 & this.ee.t6.UD0); - // @002FF238 SLT t7, t7, s0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); - // @002FF23C BEQ t7, zero, $002ff278 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3142264u; - } - // @002FF240 MOV.S $f6, $f12 - this.ee.fpr[6].f = this.ee.fpr[12].f; - } - - public virtual void funct002ff260() - { - this.ee.pc = 3142264u; - // @002FF260 MOV.S $f0, $f4 - this.ee.fpr[0].f = this.ee.fpr[4].f; - // @002FF264 LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @002FF268 LD s1, $0008(sp) - MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); - // @002FF26C LD ra, $0010(sp) - MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - // @002FF270 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @002FF274 ADDIU sp, sp, $0020 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); - } - - public virtual void funct002ff278() - { - this.ee.pc = 3142284u; - // @002FF278 LUI t7, $3edf - this.ee.t7.SD0 = 1054801920; - // @002FF27C ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @002FF280 SLT t7, t7, s0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); - // @002FF284 BNE t7, zero, $002ff400 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3142656u; - } - // @002FF288 LUI t7, $30ff - this.ee.t7.SD0 = 822018048; - } - - public virtual void funct002ff28c() - { - this.ee.pc = 3142300u; - // @002FF28C ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @002FF290 SLT t7, t7, s0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); - // @002FF294 BNE t7, zero, $002ff2c8 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3142344u; - } - // @002FF298 ADDIU t6, zero, $ffff - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + -1))); - } - - public virtual void funct002ff29c() - { - this.ee.pc = 3142340u; - // @002FF29C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF2A0 ADDIU t7, t7, $4794 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18324))); - // @002FF2A4 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @002FF2A8 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF2AC ADD.S $f0, $f12, $f0 - this.ee.fpr[0].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); - // @002FF2B0 ADDIU t7, t7, $4798 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18328))); - // @002FF2B4 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @002FF2B8 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @002FF2BC BC1T $002ff260 - if (this.ee.fcr31_23) - { - this.ee.pc = 3142240u; - } - // @002FF2C0 MOV.S $f4, $f12 - this.ee.fpr[4].f = this.ee.fpr[12].f; - } - - public virtual void funct002ff2c8() - { - this.ee.pc = 3142568u; - // @002FF2C8 MUL.S $f5, $f6, $f6 - this.ee.fpr[5].f = (this.ee.fpr[6].f * this.ee.fpr[6].f); - // @002FF2CC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF2D0 ADDIU t7, t7, $47a8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18344))); - // @002FF2D4 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @002FF2D8 MUL.S $f4, $f5, $f5 - this.ee.fpr[4].f = (this.ee.fpr[5].f * this.ee.fpr[5].f); - // @002FF2DC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF2E0 ADDIU t7, t7, $47ac - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18348))); - // @002FF2E4 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @002FF2E8 MUL.S $f0, $f4, $f0 - this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); - // @002FF2EC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF2F0 ADDIU t7, t7, $47b0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18352))); - // @002FF2F4 MUL.S $f1, $f4, $f1 - this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); - // @002FF2F8 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF2FC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF300 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @002FF304 ADDIU t7, t7, $47b4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18356))); - // @002FF308 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @002FF30C MUL.S $f0, $f4, $f0 - this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); - // @002FF310 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF314 ADDIU t7, t7, $47b8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18360))); - // @002FF318 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @002FF31C LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF320 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF324 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @002FF328 ADDIU t7, t7, $47bc - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18364))); - // @002FF32C MUL.S $f1, $f4, $f1 - this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); - // @002FF330 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @002FF334 MUL.S $f0, $f4, $f0 - this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); - // @002FF338 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF33C ADDIU t7, t7, $47c0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18368))); - // @002FF340 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @002FF344 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF348 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF34C ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @002FF350 ADDIU t7, t7, $47c4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18372))); - // @002FF354 MUL.S $f1, $f4, $f1 - this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); - // @002FF358 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @002FF35C MUL.S $f0, $f4, $f0 - this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); - // @002FF360 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF364 ADDIU t7, t7, $47c8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18376))); - // @002FF368 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @002FF36C LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF370 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF374 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @002FF378 ADDIU t7, t7, $47cc - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18380))); - // @002FF37C MUL.S $f1, $f4, $f1 - this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); - // @002FF380 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @002FF384 MUL.S $f0, $f4, $f0 - this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); - // @002FF388 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF38C ADDIU t7, t7, $47d0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18384))); - // @002FF390 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @002FF394 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF398 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @002FF39C MUL.S $f4, $f4, $f1 - this.ee.fpr[4].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); - // @002FF3A0 BGEZ t6, $002ff3b8 - if ((this.ee.t6.SD0 >= 0)) - { - this.ee.pc = 3142584u; - } - // @002FF3A4 MUL.S $f0, $f5, $f0 - this.ee.fpr[0].f = (this.ee.fpr[5].f * this.ee.fpr[0].f); - } - - public virtual void funct002ff2cc() - { - this.ee.pc = 3142568u; - // @002FF2CC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF2D0 ADDIU t7, t7, $47a8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18344))); - // @002FF2D4 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @002FF2D8 MUL.S $f4, $f5, $f5 - this.ee.fpr[4].f = (this.ee.fpr[5].f * this.ee.fpr[5].f); - // @002FF2DC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF2E0 ADDIU t7, t7, $47ac - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18348))); - // @002FF2E4 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @002FF2E8 MUL.S $f0, $f4, $f0 - this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); - // @002FF2EC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF2F0 ADDIU t7, t7, $47b0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18352))); - // @002FF2F4 MUL.S $f1, $f4, $f1 - this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); - // @002FF2F8 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF2FC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF300 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @002FF304 ADDIU t7, t7, $47b4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18356))); - // @002FF308 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @002FF30C MUL.S $f0, $f4, $f0 - this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); - // @002FF310 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF314 ADDIU t7, t7, $47b8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18360))); - // @002FF318 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @002FF31C LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF320 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF324 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @002FF328 ADDIU t7, t7, $47bc - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18364))); - // @002FF32C MUL.S $f1, $f4, $f1 - this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); - // @002FF330 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @002FF334 MUL.S $f0, $f4, $f0 - this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); - // @002FF338 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF33C ADDIU t7, t7, $47c0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18368))); - // @002FF340 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @002FF344 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF348 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF34C ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @002FF350 ADDIU t7, t7, $47c4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18372))); - // @002FF354 MUL.S $f1, $f4, $f1 - this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); - // @002FF358 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @002FF35C MUL.S $f0, $f4, $f0 - this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); - // @002FF360 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF364 ADDIU t7, t7, $47c8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18376))); - // @002FF368 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @002FF36C LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF370 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF374 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @002FF378 ADDIU t7, t7, $47cc - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18380))); - // @002FF37C MUL.S $f1, $f4, $f1 - this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); - // @002FF380 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @002FF384 MUL.S $f0, $f4, $f0 - this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); - // @002FF388 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF38C ADDIU t7, t7, $47d0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18384))); - // @002FF390 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @002FF394 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF398 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @002FF39C MUL.S $f4, $f4, $f1 - this.ee.fpr[4].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); - // @002FF3A0 BGEZ t6, $002ff3b8 - if ((this.ee.t6.SD0 >= 0)) - { - this.ee.pc = 3142584u; - } - // @002FF3A4 MUL.S $f0, $f5, $f0 - this.ee.fpr[0].f = (this.ee.fpr[5].f * this.ee.fpr[0].f); - } - - public virtual void funct002ff3a8() - { - this.ee.pc = 3142584u; - // @002FF3A8 ADD.S $f0, $f0, $f4 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[4].f); - // @002FF3AC MUL.S $f0, $f6, $f0 - this.ee.fpr[0].f = (this.ee.fpr[6].f * this.ee.fpr[0].f); - // @002FF3B0 BEQ zero, zero, $002ff260 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3142240u; - } - // @002FF3B4 SUB.S $f4, $f6, $f0 - this.ee.fpr[4].f = (this.ee.fpr[6].f - this.ee.fpr[0].f); - } - - public virtual void funct002ff3b8() - { - this.ee.pc = 3142644u; - // @002FF3B8 ADD.S $f0, $f0, $f4 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[4].f); - // @002FF3BC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF3C0 SLL t6, t6, 2 - MobUt.SLL(this.ee.t6, this.ee.t6, 2); - // @002FF3C4 ADDIU t7, t7, $4748 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18248))); - // @002FF3C8 ADDU t7, t6, t7 - this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @002FF3CC LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF3D0 MUL.S $f0, $f6, $f0 - this.ee.fpr[0].f = (this.ee.fpr[6].f * this.ee.fpr[0].f); - // @002FF3D4 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF3D8 ADDIU t7, t7, $4738 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18232))); - // @002FF3DC ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @002FF3E0 SUB.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); - // @002FF3E4 LWC1 $f1, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); - // @002FF3E8 SUB.S $f0, $f0, $f6 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[6].f); - // @002FF3EC BGEZ s1, $002ff3f8 - if ((this.ee.s1.SD0 >= 0)) - { - this.ee.pc = 3142648u; - } - // @002FF3F0 SUB.S $f0, $f1, $f0 - this.ee.fpr[0].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); - } - - public virtual void funct002ff3f8() - { - this.ee.pc = 3142656u; - // @002FF3F8 BEQ zero, zero, $002ff260 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3142240u; - } - // @002FF3FC MOV.S $f4, $f0 - this.ee.fpr[4].f = this.ee.fpr[0].f; - } - - public virtual void funct002ff400() - { - this.ee.pc = 3142664u; - // @002FF400 JAL $002ff660 - this.ee.ra.UL0 = 3142664u; - this.ee.pc = 3143264u; - // @002FF404 NOP - MobUt.Latency(); - } - - public virtual void funct002ff408() - { - this.ee.pc = 3142684u; - // @002FF408 LUI t7, $3f97 - this.ee.t7.SD0 = 1066860544; - // @002FF40C ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @002FF410 SLT t7, t7, s0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); - // @002FF414 BNE t7, zero, $002ff484 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3142788u; - } - // @002FF418 MOV.S $f6, $f0 - this.ee.fpr[6].f = this.ee.fpr[0].f; - } - - public virtual void funct002ff41c() - { - this.ee.pc = 3142704u; - // @002FF41C LUI t7, $3f2f - this.ee.t7.SD0 = 1060044800; - // @002FF420 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @002FF424 SLT t7, t7, s0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); - // @002FF428 BNE t7, zero, $002ff46c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3142764u; - } - // @002FF42C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct002ff430() - { - this.ee.pc = 3142764u; - // @002FF430 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF434 ADD.S $f0, $f0, $f0 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[0].f); - // @002FF438 ADDIU t7, t7, $479c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18332))); - // @002FF43C DADDU t6, zero, zero - this.ee.t6.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @002FF440 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @002FF444 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF448 ADD.S $f1, $f6, $f1 - this.ee.fpr[1].f = (this.ee.fpr[6].f + this.ee.fpr[1].f); - // @002FF44C ADDIU t7, t7, $4798 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18328))); - // @002FF450 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF454 SUB.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); - // @002FF458 NOP - MobUt.Latency(); - // @002FF45C NOP - MobUt.Latency(); - // @002FF460 DIV.S $f6, $f0, $f1 - this.ee.fpr[6].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); - // @002FF464 BEQ zero, zero, $002ff2cc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3142348u; - } - // @002FF468 MUL.S $f5, $f6, $f6 - this.ee.fpr[5].f = (this.ee.fpr[6].f * this.ee.fpr[6].f); - } - - public virtual void funct002ff458() - { - this.ee.pc = 3142764u; - // @002FF458 NOP - MobUt.Latency(); - // @002FF45C NOP - MobUt.Latency(); - // @002FF460 DIV.S $f6, $f0, $f1 - this.ee.fpr[6].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); - // @002FF464 BEQ zero, zero, $002ff2cc - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3142348u; - } - // @002FF468 MUL.S $f5, $f6, $f6 - this.ee.fpr[5].f = (this.ee.fpr[6].f * this.ee.fpr[6].f); - } - - public virtual void funct002ff46c() - { - this.ee.pc = 3142788u; - // @002FF46C ADDIU t6, zero, $0001 - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @002FF470 ADDIU t7, t7, $4798 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18328))); - // @002FF474 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @002FF478 ADD.S $f1, $f6, $f0 - this.ee.fpr[1].f = (this.ee.fpr[6].f + this.ee.fpr[0].f); - // @002FF47C BEQ zero, zero, $002ff458 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3142744u; - } - // @002FF480 SUB.S $f0, $f6, $f0 - this.ee.fpr[0].f = (this.ee.fpr[6].f - this.ee.fpr[0].f); - } - - public virtual void funct002ff484() - { - this.ee.pc = 3142808u; - // @002FF484 LUI t7, $401b - this.ee.t7.SD0 = 1075511296; - // @002FF488 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @002FF48C SLT t7, t7, s0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); - // @002FF490 BNE t7, zero, $002ff4c4 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3142852u; - } - // @002FF494 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct002ff498() - { - this.ee.pc = 3142852u; - // @002FF498 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF49C ADDIU t6, zero, $0002 - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 2))); - // @002FF4A0 ADDIU t7, t7, $47a0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18336))); - // @002FF4A4 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @002FF4A8 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @002FF4AC MUL.S $f1, $f6, $f0 - this.ee.fpr[1].f = (this.ee.fpr[6].f * this.ee.fpr[0].f); - // @002FF4B0 ADDIU t7, t7, $4798 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18328))); - // @002FF4B4 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @002FF4B8 SUB.S $f0, $f6, $f0 - this.ee.fpr[0].f = (this.ee.fpr[6].f - this.ee.fpr[0].f); - // @002FF4BC BEQ zero, zero, $002ff458 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3142744u; - } - // @002FF4C0 ADD.S $f1, $f1, $f2 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[2].f); - } - - public virtual void funct002ff4c4() - { - this.ee.pc = 3142880u; - // @002FF4C4 ADDIU t7, t7, $47a4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18340))); - // @002FF4C8 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @002FF4CC NOP - MobUt.Latency(); - // @002FF4D0 NOP - MobUt.Latency(); - // @002FF4D4 DIV.S $f6, $f0, $f6 - this.ee.fpr[6].f = (this.ee.fpr[0].f / this.ee.fpr[6].f); - // @002FF4D8 BEQ zero, zero, $002ff2c8 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3142344u; - } - // @002FF4DC ADDIU t6, zero, $0003 - this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 3))); - } - - public virtual void funct002ff660() - { - this.ee.pc = 3143288u; - // @002FF660 MFC1 t6, $f12 - MobUt.MFC1(this.ee.t6, this.ee.fpr[12]); - // @002FF664 LUI t7, $7fff - this.ee.t7.SD0 = 2147418112; - // @002FF668 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @002FF66C AND t6, t6, t7 - this.ee.t6.UD0 = (this.ee.t6.UD0 & this.ee.t7.UD0); - // @002FF670 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @002FF674 MTC1 t6, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); - } - - public virtual void funct002ff8a8() - { - this.ee.pc = 3143868u; - // @002FF8A8 ADDIU sp, sp, $fff0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); - // @002FF8AC SD ra, $0000(sp) - MobUt.SD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); - // @002FF8B0 LD ra, $0000(sp) - MobUt.LD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); - // @002FF8B4 J $00300058 - this.ee.pc = 3145816u; - // @002FF8B8 ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct002ff8c0() - { - this.ee.pc = 3143892u; - // @002FF8C0 ADDIU sp, sp, $fff0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); - // @002FF8C4 SD ra, $0000(sp) - MobUt.SD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); - // @002FF8C8 LD ra, $0000(sp) - MobUt.LD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); - // @002FF8CC J $003003f0 - this.ee.pc = 3146736u; - // @002FF8D0 ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct002ff8d8() - { - this.ee.pc = 3143916u; - // @002FF8D8 ADDIU sp, sp, $fff0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); - // @002FF8DC SD ra, $0000(sp) - MobUt.SD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); - // @002FF8E0 LD ra, $0000(sp) - MobUt.LD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); - // @002FF8E4 J $003005b8 - this.ee.pc = 3147192u; - // @002FF8E8 ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00300058() - { - this.ee.pc = 3145872u; - // @00300058 ADDIU sp, sp, $ffd0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -48))); - // @0030005C LUI t7, $7fff - this.ee.t7.SD0 = 2147418112; - // @00300060 SD s1, $0008(sp) - MobUt.SD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); - // @00300064 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @00300068 SD s0, $0000(sp) - MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @0030006C LUI t6, $3f80 - this.ee.t6.SD0 = 1065353216; - // @00300070 MFC1 s1, $f12 - MobUt.MFC1(this.ee.s1, this.ee.fpr[12]); - // @00300074 SD ra, $0010(sp) - MobUt.SD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - // @00300078 SWC1 $f22, $0020(sp) - MobUt.SWC1(this.ee, this.ee.fpr[22], (32u + this.ee.sp.UL0)); - // @0030007C AND s0, s1, t7 - this.ee.s0.UD0 = (this.ee.s1.UD0 & this.ee.t7.UD0); - // @00300080 SWC1 $f21, $001c(sp) - MobUt.SWC1(this.ee, this.ee.fpr[21], (28u + this.ee.sp.UL0)); - // @00300084 SWC1 $f20, $0018(sp) - MobUt.SWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); - // @00300088 BNE s0, t6, $003000d4 - if ((this.ee.s0.UD0 != this.ee.t6.UD0)) - { - this.ee.pc = 3145940u; - } - // @0030008C SLT t7, t6, s0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < this.ee.s0.SD0)); - } - - public virtual void funct00300090() - { - this.ee.pc = 3145940u; - // @00300090 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300094 ADDIU t7, t7, $48b8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18616))); - // @00300098 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @0030009C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003000A0 MULA.S $f12, $f0 - this.ee.fpracc.f = (this.ee.fpr[12].f * this.ee.fpr[0].f); - // @003000A4 ADDIU t7, t7, $48bc - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18620))); - // @003000A8 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @003000AC MADD.S $f4, $f12, $f1 - this.ee.fpr[4].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[12].f, this.ee.fpr[1].f); - // @003000B0 MOV.S $f0, $f4 - this.ee.fpr[0].f = this.ee.fpr[4].f; - // @003000B4 LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @003000B8 LD s1, $0008(sp) - MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); - // @003000BC LD ra, $0010(sp) - MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - // @003000C0 LWC1 $f22, $0020(sp) - MobUt.LWC1(this.ee, this.ee.fpr[22], (32u + this.ee.sp.UL0)); - // @003000C4 LWC1 $f21, $001c(sp) - MobUt.LWC1(this.ee, this.ee.fpr[21], (28u + this.ee.sp.UL0)); - // @003000C8 LWC1 $f20, $0018(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); - // @003000CC JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @003000D0 ADDIU sp, sp, $0030 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 48))); - } - - public virtual void funct003000b0() - { - this.ee.pc = 3145940u; - // @003000B0 MOV.S $f0, $f4 - this.ee.fpr[0].f = this.ee.fpr[4].f; - // @003000B4 LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @003000B8 LD s1, $0008(sp) - MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); - // @003000BC LD ra, $0010(sp) - MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - // @003000C0 LWC1 $f22, $0020(sp) - MobUt.LWC1(this.ee, this.ee.fpr[22], (32u + this.ee.sp.UL0)); - // @003000C4 LWC1 $f21, $001c(sp) - MobUt.LWC1(this.ee, this.ee.fpr[21], (28u + this.ee.sp.UL0)); - // @003000C8 LWC1 $f20, $0018(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); - // @003000CC JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @003000D0 ADDIU sp, sp, $0030 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 48))); - } - - public virtual void funct003000b4() - { - this.ee.pc = 3145940u; - // @003000B4 LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @003000B8 LD s1, $0008(sp) - MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); - // @003000BC LD ra, $0010(sp) - MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); - // @003000C0 LWC1 $f22, $0020(sp) - MobUt.LWC1(this.ee, this.ee.fpr[22], (32u + this.ee.sp.UL0)); - // @003000C4 LWC1 $f21, $001c(sp) - MobUt.LWC1(this.ee, this.ee.fpr[21], (28u + this.ee.sp.UL0)); - // @003000C8 LWC1 $f20, $0018(sp) - MobUt.LWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); - // @003000CC JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @003000D0 ADDIU sp, sp, $0030 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 48))); - } - - public virtual void funct003000d4() - { - this.ee.pc = 3145948u; - // @003000D4 BEQ t7, zero, $003000f4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3145972u; - } - // @003000D8 LUI t7, $3eff - this.ee.t7.SD0 = 1056899072; - } - - public virtual void funct003000dc() - { - this.ee.pc = 3145972u; - // @003000DC SUB.S $f0, $f12, $f12 - this.ee.fpr[0].f = (this.ee.fpr[12].f - this.ee.fpr[12].f); - // @003000E0 NOP - MobUt.Latency(); - // @003000E4 NOP - MobUt.Latency(); - // @003000E8 DIV.S $f4, $f0, $f0 - this.ee.fpr[4].f = (this.ee.fpr[0].f / this.ee.fpr[0].f); - // @003000EC BEQ zero, zero, $003000b4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3145908u; - } - // @003000F0 MOV.S $f0, $f4 - this.ee.fpr[0].f = this.ee.fpr[4].f; - } - - public virtual void funct003000f4() - { - this.ee.pc = 3145988u; - // @003000F4 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @003000F8 SLT t7, t7, s0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); - // @003000FC BNE t7, zero, $0030013c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3146044u; - } - // @00300100 LUI t7, $31ff - this.ee.t7.SD0 = 838795264; - } - - public virtual void funct00300104() - { - this.ee.pc = 3146004u; - // @00300104 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @00300108 SLT t7, t7, s0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); - // @0030010C BNE t7, zero, $00300308 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3146504u; - } - // @00300110 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct00300114() - { - this.ee.pc = 3146044u; - // @00300114 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300118 ADDIU t7, t7, $48c0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18624))); - // @0030011C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00300120 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300124 ADD.S $f0, $f12, $f0 - this.ee.fpr[0].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); - // @00300128 ADDIU t7, t7, $48c4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18628))); - // @0030012C LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00300130 C.LT.S $f1, $f0 - this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); - // @00300134 BC1T $003000b0 - if (this.ee.fcr31_23) - { - this.ee.pc = 3145904u; - } - // @00300138 MOV.S $f4, $f12 - this.ee.fpr[4].f = this.ee.fpr[12].f; - } - - public virtual void funct0030013c() - { - this.ee.pc = 3146052u; - // @0030013C JAL $002ff660 - this.ee.ra.UL0 = 3146052u; - this.ee.pc = 3143264u; - // @00300140 NOP - MobUt.Latency(); - } - - public virtual void funct00300144() - { - this.ee.pc = 3146288u; - // @00300144 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300148 ADDIU t7, t7, $48c4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18628))); - // @0030014C LWC1 $f4, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[4], (0u + this.ee.t7.UL0)); - // @00300150 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300154 SUB.S $f0, $f4, $f0 - this.ee.fpr[0].f = (this.ee.fpr[4].f - this.ee.fpr[0].f); - // @00300158 ADDIU t7, t7, $48f0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18672))); - // @0030015C LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00300160 MUL.S $f20, $f0, $f1 - this.ee.fpr[20].f = (this.ee.fpr[0].f * this.ee.fpr[1].f); - // @00300164 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300168 ADDIU t7, t7, $48c8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18632))); - // @0030016C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00300170 MOV.S $f12, $f20 - this.ee.fpr[12].f = this.ee.fpr[20].f; - // @00300174 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300178 MUL.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - // @0030017C ADDIU t7, t7, $48cc - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18636))); - // @00300180 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00300184 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300188 MUL.S $f1, $f20, $f1 - this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); - // @0030018C ADDIU t7, t7, $48d0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18640))); - // @00300190 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @00300194 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300198 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @0030019C ADDIU t7, t7, $48d4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18644))); - // @003001A0 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @003001A4 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003001A8 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @003001AC ADDIU t7, t7, $48d8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18648))); - // @003001B0 MUL.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - // @003001B4 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @003001B8 MUL.S $f1, $f20, $f1 - this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); - // @003001BC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003001C0 ADDIU t7, t7, $48dc - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18652))); - // @003001C4 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @003001C8 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @003001CC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003001D0 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @003001D4 ADDIU t7, t7, $48e0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18656))); - // @003001D8 MUL.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - // @003001DC LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @003001E0 MUL.S $f1, $f20, $f1 - this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); - // @003001E4 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003001E8 ADDIU t7, t7, $48e4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18660))); - // @003001EC ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @003001F0 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @003001F4 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @003001F8 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003001FC MUL.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - // @00300200 ADDIU t7, t7, $48e8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18664))); - // @00300204 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @00300208 MUL.S $f1, $f20, $f1 - this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); - // @0030020C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300210 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @00300214 ADDIU t7, t7, $48ec - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18668))); - // @00300218 ADD.S $f22, $f1, $f4 - this.ee.fpr[22].f = (this.ee.fpr[1].f + this.ee.fpr[4].f); - // @0030021C MUL.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - // @00300220 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00300224 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @00300228 JAL $00301800 - this.ee.ra.UL0 = 3146288u; - this.ee.pc = 3151872u; - // @0030022C MUL.S $f21, $f20, $f0 - this.ee.fpr[21].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - } - - public virtual void funct00300230() - { - this.ee.pc = 3146308u; - // @00300230 LUI t7, $3f79 - this.ee.t7.SD0 = 1064894464; - // @00300234 ORI t7, t7, $9999 - this.ee.t7.UD0 = (this.ee.t7.UD0 | 39321); - // @00300238 SLT t7, t7, s0 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); - // @0030023C BEQ t7, zero, $00300290 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3146384u; - } - // @00300240 MFC1 t5, $f0 - MobUt.MFC1(this.ee.t5, this.ee.fpr[0]); - } - - public virtual void funct00300244() - { - this.ee.pc = 3146376u; - // @00300244 NOP - MobUt.Latency(); - // @00300248 NOP - MobUt.Latency(); - // @0030024C DIV.S $f21, $f21, $f22 - this.ee.fpr[21].f = (this.ee.fpr[21].f / this.ee.fpr[22].f); - // @00300250 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300254 MTC1 t5, $f1 - this.ee.fpr[1].f = MobUt.UL2F(this.ee.t5.UL[0]); - // @00300258 ADDIU t7, t7, $48bc - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18620))); - // @0030025C MUL.S $f0, $f0, $f21 - this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[21].f); - // @00300260 ADD.S $f0, $f1, $f0 - this.ee.fpr[0].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); - // @00300264 ADD.S $f0, $f0, $f0 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[0].f); - // @00300268 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @0030026C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300270 SUB.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); - // @00300274 ADDIU t7, t7, $48b8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18616))); - // @00300278 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @0030027C SUB.S $f20, $f2, $f0 - this.ee.fpr[20].f = (this.ee.fpr[2].f - this.ee.fpr[0].f); - // @00300280 BGTZ s1, $003000b0 - if ((this.ee.s1.SD0 > 0)) - { - this.ee.pc = 3145904u; - } - // @00300284 MOV.S $f4, $f20 - this.ee.fpr[4].f = this.ee.fpr[20].f; - } - - public virtual void funct00300280() - { - this.ee.pc = 3146376u; - // @00300280 BGTZ s1, $003000b0 - if ((this.ee.s1.SD0 > 0)) - { - this.ee.pc = 3145904u; - } - // @00300284 MOV.S $f4, $f20 - this.ee.fpr[4].f = this.ee.fpr[20].f; - } - - public virtual void funct00300288() - { - this.ee.pc = 3146384u; - // @00300288 BEQ zero, zero, $003000b0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3145904u; - } - // @0030028C NEG.S $f4, $f20 - this.ee.fpr[4].f = (0 - this.ee.fpr[20].f); - } - - public virtual void funct00300290() - { - this.ee.pc = 3146504u; - // @00300290 ADDIU t7, zero, $f000 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -4096))); - // @00300294 MTC1 t5, $f2 - this.ee.fpr[2].f = MobUt.UL2F(this.ee.t5.UL[0]); - // @00300298 AND t6, t5, t7 - this.ee.t6.UD0 = (this.ee.t5.UD0 & this.ee.t7.UD0); - // @0030029C NOP - MobUt.Latency(); - // @003002A0 NOP - MobUt.Latency(); - // @003002A4 DIV.S $f4, $f21, $f22 - this.ee.fpr[4].f = (this.ee.fpr[21].f / this.ee.fpr[22].f); - // @003002A8 MTC1 t6, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); - // @003002AC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003002B0 MTC1 t6, $f6 - this.ee.fpr[6].f = MobUt.UL2F(this.ee.t6.UL[0]); - // @003002B4 ADDIU t7, t7, $48f4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18676))); - // @003002B8 MUL.S $f1, $f0, $f0 - this.ee.fpr[1].f = (this.ee.fpr[0].f * this.ee.fpr[0].f); - // @003002BC ADD.S $f3, $f2, $f0 - this.ee.fpr[3].f = (this.ee.fpr[2].f + this.ee.fpr[0].f); - // @003002C0 LWC1 $f5, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[5], (0u + this.ee.t7.UL0)); - // @003002C4 SUB.S $f1, $f20, $f1 - this.ee.fpr[1].f = (this.ee.fpr[20].f - this.ee.fpr[1].f); - // @003002C8 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003002CC ADD.S $f0, $f6, $f6 - this.ee.fpr[0].f = (this.ee.fpr[6].f + this.ee.fpr[6].f); - // @003002D0 ADDIU t7, t7, $48bc - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18620))); - // @003002D4 ADD.S $f2, $f2, $f2 - this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[2].f); - // @003002D8 NOP - MobUt.Latency(); - // @003002DC NOP - MobUt.Latency(); - // @003002E0 DIV.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f / this.ee.fpr[3].f); - // @003002E4 SUB.S $f22, $f5, $f0 - this.ee.fpr[22].f = (this.ee.fpr[5].f - this.ee.fpr[0].f); - // @003002E8 MUL.S $f2, $f2, $f4 - this.ee.fpr[2].f = (this.ee.fpr[2].f * this.ee.fpr[4].f); - // @003002EC LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @003002F0 ADD.S $f1, $f1, $f1 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[1].f); - // @003002F4 SUB.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); - // @003002F8 SUB.S $f21, $f2, $f0 - this.ee.fpr[21].f = (this.ee.fpr[2].f - this.ee.fpr[0].f); - // @003002FC SUB.S $f1, $f21, $f22 - this.ee.fpr[1].f = (this.ee.fpr[21].f - this.ee.fpr[22].f); - // @00300300 BEQ zero, zero, $00300280 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3146368u; - } - // @00300304 SUB.S $f20, $f5, $f1 - this.ee.fpr[20].f = (this.ee.fpr[5].f - this.ee.fpr[1].f); - } - - public virtual void funct00300308() - { - this.ee.pc = 3146736u; - // @00300308 MUL.S $f20, $f12, $f12 - this.ee.fpr[20].f = (this.ee.fpr[12].f * this.ee.fpr[12].f); - // @0030030C ADDIU t7, t7, $48c8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18632))); - // @00300310 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00300314 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300318 MUL.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - // @0030031C ADDIU t7, t7, $48cc - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18636))); - // @00300320 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00300324 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300328 MUL.S $f1, $f20, $f1 - this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); - // @0030032C ADDIU t7, t7, $48d0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18640))); - // @00300330 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @00300334 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300338 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @0030033C ADDIU t7, t7, $48d4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18644))); - // @00300340 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @00300344 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300348 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @0030034C ADDIU t7, t7, $48d8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18648))); - // @00300350 MUL.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - // @00300354 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @00300358 MUL.S $f1, $f20, $f1 - this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); - // @0030035C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300360 ADDIU t7, t7, $48dc - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18652))); - // @00300364 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @00300368 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @0030036C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300370 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @00300374 ADDIU t7, t7, $48e0 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18656))); - // @00300378 MUL.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - // @0030037C LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @00300380 MUL.S $f1, $f20, $f1 - this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); - // @00300384 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300388 ADDIU t7, t7, $48e4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18660))); - // @0030038C ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @00300390 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @00300394 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300398 ADD.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @0030039C ADDIU t7, t7, $48e8 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18664))); - // @003003A0 MUL.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - // @003003A4 LWC1 $f2, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); - // @003003A8 MUL.S $f1, $f20, $f1 - this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); - // @003003AC LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003003B0 ADDIU t7, t7, $48c4 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18628))); - // @003003B4 ADD.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); - // @003003B8 LWC1 $f3, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); - // @003003BC ADD.S $f22, $f1, $f3 - this.ee.fpr[22].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); - // @003003C0 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003003C4 MUL.S $f0, $f20, $f0 - this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - // @003003C8 ADDIU t7, t7, $48ec - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18668))); - // @003003CC LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @003003D0 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @003003D4 MUL.S $f21, $f20, $f0 - this.ee.fpr[21].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); - // @003003D8 NOP - MobUt.Latency(); - // @003003DC NOP - MobUt.Latency(); - // @003003E0 DIV.S $f21, $f21, $f22 - this.ee.fpr[21].f = (this.ee.fpr[21].f / this.ee.fpr[22].f); - // @003003E4 MUL.S $f0, $f12, $f21 - this.ee.fpr[0].f = (this.ee.fpr[12].f * this.ee.fpr[21].f); - // @003003E8 BEQ zero, zero, $003000b0 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3145904u; - } - // @003003EC ADD.S $f4, $f12, $f0 - this.ee.fpr[4].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); - } - - public virtual void funct003003f0() - { - this.ee.pc = 3146784u; - // @003003F0 MOV.S $f0, $f12 - this.ee.fpr[0].f = this.ee.fpr[12].f; - // @003003F4 ADDIU sp, sp, $fff0 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); - // @003003F8 LUI t6, $7fff - this.ee.t6.SD0 = 2147418112; - // @003003FC MFC1 t4, $f13 - MobUt.MFC1(this.ee.t4, this.ee.fpr[13]); - // @00300400 MFC1 t3, $f12 - MobUt.MFC1(this.ee.t3, this.ee.fpr[12]); - // @00300404 ORI t6, t6, $ffff - this.ee.t6.UD0 = (this.ee.t6.UD0 | 65535); - // @00300408 SD s0, $0000(sp) - MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @0030040C AND t1, t4, t6 - this.ee.t1.UD0 = (this.ee.t4.UD0 & this.ee.t6.UD0); - // @00300410 SD ra, $0008(sp) - MobUt.SD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); - // @00300414 LUI t7, $3f80 - this.ee.t7.SD0 = 1065353216; - // @00300418 BNE t4, t7, $00300430 - if ((this.ee.t4.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 3146800u; - } - // @0030041C AND t2, t3, t6 - this.ee.t2.UD0 = (this.ee.t3.UD0 & this.ee.t6.UD0); - } - - public virtual void funct00300420() - { - this.ee.pc = 3146800u; - // @00300420 LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @00300424 LD ra, $0008(sp) - MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); - // @00300428 J $002ff210 - this.ee.pc = 3142160u; - // @0030042C ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00300430() - { - this.ee.pc = 3146832u; - // @00300430 SRA t7, t4, 30 - MobUt.SRA(this.ee.t7, this.ee.t4, 30); - // @00300434 LUI t6, $007f - this.ee.t6.SD0 = 8323072; - // @00300438 ANDI t7, t7, $0002 - this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 2))); - // @0030043C SRL t5, t3, 31 - MobUt.SRL(this.ee.t5, this.ee.t3, 31); - // @00300440 ORI t6, t6, $ffff - this.ee.t6.UD0 = (this.ee.t6.UD0 | 65535); - // @00300444 SLT t6, t6, t2 - this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < this.ee.t2.SD0)); - // @00300448 BNE t6, zero, $00300490 - if ((this.ee.t6.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3146896u; - } - // @0030044C OR s0, t5, t7 - this.ee.s0.UD0 = (this.ee.t5.UD0 | this.ee.t7.UD0); - } - - public virtual void funct00300450() - { - this.ee.pc = 3146848u; - // @00300450 LUI t6, $4049 - this.ee.t6.SD0 = 1078525952; - // @00300454 ADDIU t7, zero, $0002 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); - // @00300458 BEQ s0, t7, $0030047c - if ((this.ee.s0.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 3146876u; - } - // @0030045C ORI t6, t6, $0fda - this.ee.t6.UD0 = (this.ee.t6.UD0 | 4058); - } - - public virtual void funct00300460() - { - this.ee.pc = 3146860u; - // @00300460 SLTI t7, s0, $0003 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); - // @00300464 BEQL t7, zero, $003005a4 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3147172u; - // @00300468 LUI t6, $c049 - this.ee.t6.SD0 = -1068957696; - } - } - - public virtual void funct0030046c() - { - this.ee.pc = 3146868u; - // @0030046C BLTZ s0, $00300494 - if ((this.ee.s0.SD0 < 0)) - { - this.ee.pc = 3146900u; - } - // @00300470 LUI t7, $007f - this.ee.t7.SD0 = 8323072; - } - - public virtual void funct00300474() - { - this.ee.pc = 3146896u; - // @00300474 NOP - MobUt.Latency(); - // @00300478 MFC1 t6, $f0 - MobUt.MFC1(this.ee.t6, this.ee.fpr[0]); - // @0030047C MTC1 t6, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); - // @00300480 LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @00300484 LD ra, $0008(sp) - MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); - // @00300488 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0030048C ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00300478() - { - this.ee.pc = 3146896u; - // @00300478 MFC1 t6, $f0 - MobUt.MFC1(this.ee.t6, this.ee.fpr[0]); - // @0030047C MTC1 t6, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); - // @00300480 LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @00300484 LD ra, $0008(sp) - MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); - // @00300488 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0030048C ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct0030047c() - { - this.ee.pc = 3146896u; - // @0030047C MTC1 t6, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); - // @00300480 LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @00300484 LD ra, $0008(sp) - MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); - // @00300488 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0030048C ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00300480() - { - this.ee.pc = 3146896u; - // @00300480 LD s0, $0000(sp) - MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); - // @00300484 LD ra, $0008(sp) - MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); - // @00300488 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0030048C ADDIU sp, sp, $0010 - this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); - } - - public virtual void funct00300490() - { - this.ee.pc = 3146916u; - // @00300490 LUI t7, $007f - this.ee.t7.SD0 = 8323072; - // @00300494 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @00300498 SLT t7, t7, t1 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t1.SD0)); - // @0030049C BNE t7, zero, $003004dc - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3146972u; - } - // @003004A0 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct003004a4() - { - this.ee.pc = 3146940u; - // @003004A4 LUI t7, $bfc9 - this.ee.t7.SD0 = -1077346304; - // @003004A8 ORI t7, t7, $0fda - this.ee.t7.UD0 = (this.ee.t7.UD0 | 4058); - // @003004AC CTC2 t7, $vi22 - // @003004B0 VNOP - MobUt.Latency(); - // @003004B4 BLTZ t3, $003004c8 - if ((this.ee.t3.SD0 < 0)) - { - this.ee.pc = 3146952u; - } - // @003004B8 LUI t7, $3fc9 - this.ee.t7.SD0 = 1070137344; - } - - public virtual void funct003004c8() - { - this.ee.pc = 3146972u; - // @003004C8 VWAITQ - MobUt.Latency(); - // @003004CC CFC2 t6, $vi22 - MobUt.CFC2(this.ee.t6, this.ee.VI[22]); - // @003004D0 VNOP - MobUt.Latency(); - // @003004D4 BEQ zero, zero, $00300480 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3146880u; - } - // @003004D8 MTC1 t6, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); - } - - public virtual void funct003004dc() - { - this.ee.pc = 3147000u; - // @003004DC SUBU t6, t2, t1 - this.ee.t6.SD0 = ((int)((this.ee.t2.UD0 - this.ee.t1.UD0))); - // @003004E0 ADDIU t7, t7, $4910 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18704))); - // @003004E4 SRA t6, t6, 23 - MobUt.SRA(this.ee.t6, this.ee.t6, 23); - // @003004E8 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @003004EC SLTI t7, t6, $003d - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < 61)); - // @003004F0 BEQ t7, zero, $0030052c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3147052u; - } - // @003004F4 ADDIU t7, zero, $0001 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); - } - - public virtual void funct003004f8() - { - this.ee.pc = 3147008u; - // @003004F8 BGEZ t4, $00300508 - if ((this.ee.t4.SD0 >= 0)) - { - this.ee.pc = 3147016u; - } - // @003004FC SLTI t7, t6, $ffc4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < -60)); - } - - public virtual void funct00300500() - { - this.ee.pc = 3147016u; - // @00300500 BNE t7, zero, $00300528 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3147048u; - } - // @00300504 MTC1 zero, $f1 - this.ee.fpr[1].f = MobUt.UL2F(this.ee.r0.UL[0]); - } - - public virtual void funct00300508() - { - this.ee.pc = 3147036u; - // @00300508 NOP - MobUt.Latency(); - // @0030050C NOP - MobUt.Latency(); - // @00300510 DIV.S $f12, $f0, $f13 - this.ee.fpr[12].f = (this.ee.fpr[0].f / this.ee.fpr[13].f); - // @00300514 JAL $002ff660 - this.ee.ra.UL0 = 3147036u; - this.ee.pc = 3143264u; - // @00300518 NOP - MobUt.Latency(); - } - - public virtual void funct0030051c() - { - this.ee.pc = 3147044u; - // @0030051C JAL $002ff210 - this.ee.ra.UL0 = 3147044u; - this.ee.pc = 3142160u; - // @00300520 MOV.S $f12, $f0 - this.ee.fpr[12].f = this.ee.fpr[0].f; - } - - public virtual void funct00300524() - { - this.ee.pc = 3147060u; - // @00300524 MOV.S $f1, $f0 - this.ee.fpr[1].f = this.ee.fpr[0].f; - // @00300528 ADDIU t7, zero, $0001 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); - // @0030052C BEQ s0, t7, $00300594 - if ((this.ee.s0.UD0 == this.ee.t7.UD0)) - { - this.ee.pc = 3147156u; - } - // @00300530 SLTI t7, s0, $0002 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 2)); - } - - public virtual void funct00300534() - { - this.ee.pc = 3147068u; - // @00300534 BEQ t7, zero, $00300568 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3147112u; - } - // @00300538 ADDIU t7, zero, $0002 - this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); - } - - public virtual void funct0030053c() - { - this.ee.pc = 3147076u; - // @0030053C BEQ s0, zero, $0030047c - if ((this.ee.s0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3146876u; - } - // @00300540 MFC1 t6, $f1 - MobUt.MFC1(this.ee.t6, this.ee.fpr[1]); - } - - public virtual void funct00300548() - { - this.ee.pc = 3147112u; - // @00300548 ADDIU t7, t7, $4914 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18708))); - // @0030054C LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00300550 SUB.S $f0, $f1, $f0 - this.ee.fpr[0].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); - // @00300554 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300558 ADDIU t7, t7, $4918 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18712))); - // @0030055C LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00300560 BEQ zero, zero, $00300478 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3146872u; - } - // @00300564 SUB.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); - } - - public virtual void funct00300568() - { - this.ee.pc = 3147120u; - // @00300568 BNE s0, t7, $00300548 - if ((this.ee.s0.UD0 != this.ee.t7.UD0)) - { - this.ee.pc = 3147080u; - } - // @0030056C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct00300570() - { - this.ee.pc = 3147156u; - // @00300570 ADDIU t7, t7, $4914 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18708))); - // @00300574 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00300578 SUB.S $f0, $f1, $f0 - this.ee.fpr[0].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); - // @0030057C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300580 ADDIU t7, t7, $4918 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18712))); - // @00300584 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00300588 SUB.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); - // @0030058C BEQ zero, zero, $0030047c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3146876u; - } - // @00300590 MFC1 t6, $f1 - MobUt.MFC1(this.ee.t6, this.ee.fpr[1]); - } - - public virtual void funct00300594() - { - this.ee.pc = 3147172u; - // @00300594 MFC1 t6, $f1 - MobUt.MFC1(this.ee.t6, this.ee.fpr[1]); - // @00300598 LUI t7, $8000 - this.ee.t7.SD0 = -2147483648; - // @0030059C BEQ zero, zero, $0030047c - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3146876u; - } - // @003005A0 XOR t6, t6, t7 - MobUt.XOR(this.ee.t6, this.ee.t6, this.ee.t7); - } - - public virtual void funct003005b8() - { - this.ee.pc = 3147228u; - // @003005B8 MFC1 t4, $f12 - MobUt.MFC1(this.ee.t4, this.ee.fpr[12]); - // @003005BC LUI t6, $7fff - this.ee.t6.SD0 = 2147418112; - // @003005C0 LUI t7, $42b2 - this.ee.t7.SD0 = 1118961664; - // @003005C4 ORI t6, t6, $ffff - this.ee.t6.UD0 = (this.ee.t6.UD0 | 65535); - // @003005C8 ORI t7, t7, $d4fc - this.ee.t7.UD0 = (this.ee.t7.UD0 | 54524); - // @003005CC AND t3, t4, t6 - this.ee.t3.UD0 = (this.ee.t4.UD0 & this.ee.t6.UD0); - // @003005D0 SLT t7, t7, t4 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t4.SD0)); - // @003005D4 BEQ t7, zero, $003005ec - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3147244u; - } - // @003005D8 SRL t2, t4, 31 - MobUt.SRL(this.ee.t2, this.ee.t4, 31); - } - - public virtual void funct003005e4() - { - this.ee.pc = 3147244u; - // @003005E4 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @003005E8 MTC1 t5, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t5.UL[0]); - } - - public virtual void funct003005ec() - { - this.ee.pc = 3147252u; - // @003005EC BGEZ t4, $0030060c - if ((this.ee.t4.SD0 >= 0)) - { - this.ee.pc = 3147276u; - } - // @003005F0 LUI t7, $3eb1 - this.ee.t7.SD0 = 1051787264; - } - - public virtual void funct003005f4() - { - this.ee.pc = 3147272u; - // @003005F4 LUI t7, $42ae - this.ee.t7.SD0 = 1118699520; - // @003005F8 ORI t7, t7, $ac50 - this.ee.t7.UD0 = (this.ee.t7.UD0 | 44112); - // @003005FC SLTU t7, t7, t3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < this.ee.t3.UD0)); - // @00300600 BNE t7, zero, $003005e4 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3147236u; - } - // @00300604 DADDU t5, zero, zero - this.ee.t5.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - - public virtual void funct00300608() - { - this.ee.pc = 3147292u; - // @00300608 LUI t7, $3eb1 - this.ee.t7.SD0 = 1051787264; - // @0030060C ORI t7, t7, $7218 - this.ee.t7.UD0 = (this.ee.t7.UD0 | 29208); - // @00300610 SLTU t7, t7, t3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < this.ee.t3.UD0)); - // @00300614 BEQ t7, zero, $003007e0 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3147744u; - } - // @00300618 LUI t7, $3f85 - this.ee.t7.SD0 = 1065680896; - } - - public virtual void funct0030061c() - { - this.ee.pc = 3147308u; - // @0030061C ORI t7, t7, $1591 - this.ee.t7.UD0 = (this.ee.t7.UD0 | 5521); - // @00300620 SLTU t7, t7, t3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < this.ee.t3.UD0)); - // @00300624 BNE t7, zero, $00300784 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3147652u; - } - // @00300628 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - } - - public virtual void funct0030062c() - { - this.ee.pc = 3147472u; - // @0030062C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300630 SLL t5, t2, 2 - MobUt.SLL(this.ee.t5, this.ee.t2, 2); - // @00300634 ADDIU t7, t7, $4938 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18744))); - // @00300638 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @0030063C ADDU t7, t5, t7 - this.ee.t7.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t7.SD0))); - // @00300640 ADDIU t6, t6, $4940 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18752))); - // @00300644 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @00300648 ADDU t5, t5, t6 - this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); - // @0030064C LWC1 $f4, $0000(t5) - MobUt.LWC1(this.ee, this.ee.fpr[4], (0u + this.ee.t5.UL0)); - // @00300650 SUB.S $f3, $f12, $f0 - this.ee.fpr[3].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - // @00300654 SUBU t7, zero, t2 - this.ee.t7.SD0 = ((int)((this.ee.r0.UD0 - this.ee.t2.UD0))); - // @00300658 SUBU t7, t7, t2 - this.ee.t7.SD0 = ((int)((this.ee.t7.UD0 - this.ee.t2.UD0))); - // @0030065C ADDIU t1, t7, $0001 - this.ee.t1.SD0 = ((int)((this.ee.t7.SD0 + 1))); - // @00300660 SUB.S $f12, $f3, $f4 - this.ee.fpr[12].f = (this.ee.fpr[3].f - this.ee.fpr[4].f); - // @00300664 MUL.S $f2, $f12, $f12 - this.ee.fpr[2].f = (this.ee.fpr[12].f * this.ee.fpr[12].f); - // @00300668 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @0030066C ADDIU t6, t6, $4978 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18808))); - // @00300670 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300674 LWC1 $f0, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @00300678 ADDIU t7, t7, $497c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18812))); - // @0030067C LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00300680 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @00300684 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @00300688 ADDIU t6, t6, $4980 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18816))); - // @0030068C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300690 ADDIU t7, t7, $4984 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18820))); - // @00300694 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @00300698 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @0030069C LWC1 $f1, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); - // @003006A0 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @003006A4 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @003006A8 ADDIU t6, t6, $4988 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18824))); - // @003006AC MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @003006B0 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @003006B4 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @003006B8 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @003006BC LWC1 $f1, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); - // @003006C0 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @003006C4 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @003006C8 BNE t1, zero, $0030070c - if ((this.ee.t1.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3147532u; - } - // @003006CC SUB.S $f2, $f12, $f0 - this.ee.fpr[2].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - } - - public virtual void funct00300660() - { - this.ee.pc = 3147472u; - // @00300660 SUB.S $f12, $f3, $f4 - this.ee.fpr[12].f = (this.ee.fpr[3].f - this.ee.fpr[4].f); - // @00300664 MUL.S $f2, $f12, $f12 - this.ee.fpr[2].f = (this.ee.fpr[12].f * this.ee.fpr[12].f); - // @00300668 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @0030066C ADDIU t6, t6, $4978 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18808))); - // @00300670 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300674 LWC1 $f0, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @00300678 ADDIU t7, t7, $497c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18812))); - // @0030067C LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00300680 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @00300684 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @00300688 ADDIU t6, t6, $4980 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18816))); - // @0030068C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300690 ADDIU t7, t7, $4984 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18820))); - // @00300694 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @00300698 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @0030069C LWC1 $f1, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); - // @003006A0 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @003006A4 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @003006A8 ADDIU t6, t6, $4988 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18824))); - // @003006AC MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @003006B0 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @003006B4 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @003006B8 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @003006BC LWC1 $f1, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); - // @003006C0 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @003006C4 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @003006C8 BNE t1, zero, $0030070c - if ((this.ee.t1.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3147532u; - } - // @003006CC SUB.S $f2, $f12, $f0 - this.ee.fpr[2].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - } - - public virtual void funct00300664() - { - this.ee.pc = 3147472u; - // @00300664 MUL.S $f2, $f12, $f12 - this.ee.fpr[2].f = (this.ee.fpr[12].f * this.ee.fpr[12].f); - // @00300668 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @0030066C ADDIU t6, t6, $4978 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18808))); - // @00300670 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300674 LWC1 $f0, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @00300678 ADDIU t7, t7, $497c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18812))); - // @0030067C LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00300680 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @00300684 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @00300688 ADDIU t6, t6, $4980 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18816))); - // @0030068C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300690 ADDIU t7, t7, $4984 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18820))); - // @00300694 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @00300698 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @0030069C LWC1 $f1, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); - // @003006A0 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @003006A4 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @003006A8 ADDIU t6, t6, $4988 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18824))); - // @003006AC MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @003006B0 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @003006B4 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @003006B8 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @003006BC LWC1 $f1, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); - // @003006C0 ADD.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); - // @003006C4 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @003006C8 BNE t1, zero, $0030070c - if ((this.ee.t1.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3147532u; - } - // @003006CC SUB.S $f2, $f12, $f0 - this.ee.fpr[2].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - } - - public virtual void funct003006d0() - { - this.ee.pc = 3147532u; - // @003006D0 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003006D4 MUL.S $f0, $f12, $f2 - this.ee.fpr[0].f = (this.ee.fpr[12].f * this.ee.fpr[2].f); - // @003006D8 ADDIU t7, t7, $498c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18828))); - // @003006DC LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @003006E0 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @003006E4 ADDIU t6, t6, $4970 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18800))); - // @003006E8 SUB.S $f1, $f2, $f1 - this.ee.fpr[1].f = (this.ee.fpr[2].f - this.ee.fpr[1].f); - // @003006EC NOP - MobUt.Latency(); - // @003006F0 NOP - MobUt.Latency(); - // @003006F4 DIV.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); - // @003006F8 SUB.S $f0, $f0, $f12 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); - // @003006FC LWC1 $f1, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); - // @00300700 SUB.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); - // @00300704 BEQ zero, zero, $003005e4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3147236u; - } - // @00300708 MFC1 t5, $f1 - MobUt.MFC1(this.ee.t5, this.ee.fpr[1]); - } - - public virtual void funct00300704() - { - this.ee.pc = 3147532u; - // @00300704 BEQ zero, zero, $003005e4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3147236u; - } - // @00300708 MFC1 t5, $f1 - MobUt.MFC1(this.ee.t5, this.ee.fpr[1]); - } - - public virtual void funct0030070c() - { - this.ee.pc = 3147600u; - // @0030070C LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @00300710 MUL.S $f1, $f12, $f2 - this.ee.fpr[1].f = (this.ee.fpr[12].f * this.ee.fpr[2].f); - // @00300714 ADDIU t6, t6, $498c - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18828))); - // @00300718 SLTI t7, t1, $ff83 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t1.SD0 < -125)); - // @0030071C LWC1 $f0, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @00300720 SUB.S $f0, $f0, $f2 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); - // @00300724 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @00300728 ADDIU t6, t6, $4970 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18800))); - // @0030072C NOP - MobUt.Latency(); - // @00300730 NOP - MobUt.Latency(); - // @00300734 DIV.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f / this.ee.fpr[0].f); - // @00300738 SUB.S $f1, $f4, $f1 - this.ee.fpr[1].f = (this.ee.fpr[4].f - this.ee.fpr[1].f); - // @0030073C LWC1 $f0, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @00300740 SUB.S $f1, $f1, $f3 - this.ee.fpr[1].f = (this.ee.fpr[1].f - this.ee.fpr[3].f); - // @00300744 SUB.S $f0, $f0, $f1 - this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); - // @00300748 BNE t7, zero, $0030075c - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3147612u; - } - // @0030074C MFC1 t6, $f0 - MobUt.MFC1(this.ee.t6, this.ee.fpr[0]); - } - - public virtual void funct00300750() - { - this.ee.pc = 3147612u; - // @00300750 SLL t7, t1, 23 - MobUt.SLL(this.ee.t7, this.ee.t1, 23); - // @00300754 BEQ zero, zero, $003005e4 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3147236u; - } - // @00300758 ADDU t5, t6, t7 - this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - } - - public virtual void funct0030075c() - { - this.ee.pc = 3147652u; - // @0030075C MFC1 t7, $f0 - MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); - // @00300760 ADDIU t6, t1, $0064 - this.ee.t6.SD0 = ((int)((this.ee.t1.SD0 + 100))); - // @00300764 SLL t6, t6, 23 - MobUt.SLL(this.ee.t6, this.ee.t6, 23); - // @00300768 ADDU t6, t7, t6 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @0030076C LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300770 MTC1 t6, $f1 - this.ee.fpr[1].f = MobUt.UL2F(this.ee.t6.UL[0]); - // @00300774 ADDIU t7, t7, $4990 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18832))); - // @00300778 LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @0030077C BEQ zero, zero, $00300704 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3147524u; - } - // @00300780 MUL.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); - } - - public virtual void funct00300784() - { - this.ee.pc = 3147744u; - // @00300784 SLL t6, t2, 2 - MobUt.SLL(this.ee.t6, this.ee.t2, 2); - // @00300788 ADDIU t7, t7, $4964 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18788))); - // @0030078C LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @00300790 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @00300794 MUL.S $f1, $f12, $f1 - this.ee.fpr[1].f = (this.ee.fpr[12].f * this.ee.fpr[1].f); - // @00300798 ADDIU t7, t7, $4928 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18728))); - // @0030079C ADDU t6, t6, t7 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); - // @003007A0 LWC1 $f0, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @003007A4 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003007A8 ADDIU t7, t7, $496c - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18796))); - // @003007AC ADD.S $f1, $f1, $f0 - this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); - // @003007B0 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - // @003007B4 ADDIU t6, t6, $4968 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18792))); - // @003007B8 CVT.W.S $f0, $f1 - MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); - // @003007BC MFC1 t1, $f0 - MobUt.MFC1(this.ee.t1, this.ee.fpr[0]); - // @003007C0 LWC1 $f1, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); - // @003007C4 MTC1 t1, $f2 - this.ee.fpr[2].f = MobUt.UL2F(this.ee.t1.UL[0]); - // @003007C8 LWC1 $f0, $0000(t6) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); - // @003007CC CVT.S.W $f2, $f2 - MobUt.CVT_S(this.ee.fpr[2], this.ee.fpr[2]); - // @003007D0 MUL.S $f0, $f2, $f0 - this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); - // @003007D4 MUL.S $f4, $f2, $f1 - this.ee.fpr[4].f = (this.ee.fpr[2].f * this.ee.fpr[1].f); - // @003007D8 BEQ zero, zero, $00300660 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3147360u; - } - // @003007DC SUB.S $f3, $f12, $f0 - this.ee.fpr[3].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); - } - - public virtual void funct003007e0() - { - this.ee.pc = 3147764u; - // @003007E0 LUI t7, $317f - this.ee.t7.SD0 = 830406656; - // @003007E4 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @003007E8 SLTU t7, t7, t3 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < this.ee.t3.UD0)); - // @003007EC BNEL t7, zero, $00300664 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3147364u; - // @003007F0 DADDU t1, zero, zero - this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - } - } - - public virtual void funct00301800() - { - this.ee.pc = 3151908u; - // @00301800 LUI t7, $7fff - this.ee.t7.SD0 = 2147418112; - // @00301804 MFC1 t6, $f12 - MobUt.MFC1(this.ee.t6, this.ee.fpr[12]); - // @00301808 ORI t7, t7, $ffff - this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); - // @0030180C LUI t4, $007f - this.ee.t4.SD0 = 8323072; - // @00301810 AND t7, t6, t7 - this.ee.t7.UD0 = (this.ee.t6.UD0 & this.ee.t7.UD0); - // @00301814 ORI t4, t4, $ffff - this.ee.t4.UD0 = (this.ee.t4.UD0 | 65535); - // @00301818 SLTU t7, t4, t7 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.UD0 < this.ee.t7.UD0)); - // @0030181C BEQ t7, zero, $00301840 - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3151936u; - } - // @00301820 MFC1 t5, $f12 - MobUt.MFC1(this.ee.t5, this.ee.fpr[12]); - } - - public virtual void funct00301824() - { - this.ee.pc = 3151916u; - // @00301824 BGEZL t6, $00301848 - if ((this.ee.t6.SD0 >= 0)) - { - this.ee.pc = 3151944u; - // @00301828 SRA t1, t6, 23 - MobUt.SRA(this.ee.t1, this.ee.t6, 23); - } - } - - public virtual void funct00301840() - { - this.ee.pc = 3151944u; - // @00301840 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @00301844 MTC1 t5, $f0 - this.ee.fpr[0].f = MobUt.UL2F(this.ee.t5.UL[0]); - } - - public virtual void funct00301848() - { - this.ee.pc = 3152004u; - // @00301848 ADDIU t1, t1, $ff81 - this.ee.t1.SD0 = ((int)((this.ee.t1.SD0 + -127))); - // @0030184C AND t7, t6, t4 - this.ee.t7.UD0 = (this.ee.t6.UD0 & this.ee.t4.UD0); - // @00301850 ANDI t5, t1, $0001 - this.ee.t5.UD0 = ((ushort)((this.ee.t1.US0 & 1))); - // @00301854 LUI t6, $0080 - this.ee.t6.SD0 = 8388608; - // @00301858 SRA t1, t1, 1 - MobUt.SRA(this.ee.t1, this.ee.t1, 1); - // @0030185C OR t6, t7, t6 - this.ee.t6.UD0 = (this.ee.t7.UD0 | this.ee.t6.UD0); - // @00301860 DADDU t3, zero, zero - this.ee.t3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @00301864 SLLV t6, t6, t5 - MobUt.SLLV(this.ee.t6, this.ee.t6, this.ee.t5); - // @00301868 DADDU t2, zero, zero - this.ee.t2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); - // @0030186C SLL t6, t6, 1 - MobUt.SLL(this.ee.t6, this.ee.t6, 1); - // @00301870 LUI t4, $0100 - this.ee.t4.SD0 = 16777216; - // @00301874 ADDU t5, t3, t4 - this.ee.t5.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t4.SD0))); - // @00301878 SLT t7, t6, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < this.ee.t5.SD0)); - // @0030187C BNEL t7, zero, $00301894 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3152020u; - // @00301880 SRL t4, t4, 1 - MobUt.SRL(this.ee.t4, this.ee.t4, 1); - } - } - - public virtual void funct00301874() - { - this.ee.pc = 3152004u; - // @00301874 ADDU t5, t3, t4 - this.ee.t5.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t4.SD0))); - // @00301878 SLT t7, t6, t5 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < this.ee.t5.SD0)); - // @0030187C BNEL t7, zero, $00301894 - if ((this.ee.t7.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3152020u; - // @00301880 SRL t4, t4, 1 - MobUt.SRL(this.ee.t4, this.ee.t4, 1); - } - } - - public virtual void funct00301884() - { - this.ee.pc = 3152028u; - // @00301884 SUBU t6, t6, t5 - this.ee.t6.SD0 = ((int)((this.ee.t6.UD0 - this.ee.t5.UD0))); - // @00301888 ADDU t3, t5, t4 - this.ee.t3.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t4.SD0))); - // @0030188C ADDU t2, t2, t4 - this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + this.ee.t4.SD0))); - // @00301890 SRL t4, t4, 1 - MobUt.SRL(this.ee.t4, this.ee.t4, 1); - // @00301894 BNE t4, zero, $00301874 - if ((this.ee.t4.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3151988u; - } - // @00301898 SLL t6, t6, 1 - MobUt.SLL(this.ee.t6, this.ee.t6, 1); - } - - public virtual void funct00301894() - { - this.ee.pc = 3152028u; - // @00301894 BNE t4, zero, $00301874 - if ((this.ee.t4.UD0 != this.ee.r0.UD0)) - { - this.ee.pc = 3151988u; - } - // @00301898 SLL t6, t6, 1 - MobUt.SLL(this.ee.t6, this.ee.t6, 1); - } - - public virtual void funct0030189c() - { - this.ee.pc = 3152036u; - // @0030189C BEQ t6, zero, $003018c8 - if ((this.ee.t6.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3152072u; - } - // @003018A0 SRA t7, t2, 1 - MobUt.SRA(this.ee.t7, this.ee.t2, 1); - } - - public virtual void funct003018a4() - { - this.ee.pc = 3152060u; - // @003018A4 LUI t7, $0038 - this.ee.t7.SD0 = 3670016; - // @003018A8 ADDIU t7, t7, $4f00 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 20224))); - // @003018AC LWC1 $f0, $0000(t7) - MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); - // @003018B0 C.LE.S $f0, $f0 - this.ee.fcr31_23 = (this.ee.fpr[0].f <= this.ee.fpr[0].f); - // @003018B4 BC1FL $003018c8 - if ((this.ee.fcr31_23 == false)) - { - this.ee.pc = 3152072u; - // @003018B8 SRA t7, t2, 1 - MobUt.SRA(this.ee.t7, this.ee.t2, 1); - } - } - - public virtual void funct003018bc() - { - this.ee.pc = 3152092u; - // @003018BC ANDI t7, t2, $0001 - this.ee.t7.UD0 = ((ushort)((this.ee.t2.US0 & 1))); - // @003018C0 ADDU t2, t2, t7 - this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + this.ee.t7.SD0))); - // @003018C4 SRA t7, t2, 1 - MobUt.SRA(this.ee.t7, this.ee.t2, 1); - // @003018C8 LUI t6, $3f00 - this.ee.t6.SD0 = 1056964608; - // @003018CC ADDU t6, t7, t6 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @003018D0 SLL t5, t1, 23 - MobUt.SLL(this.ee.t5, this.ee.t1, 23); - // @003018D4 BEQ zero, zero, $00301840 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3151936u; - } - // @003018D8 ADDU t5, t6, t5 - this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); - } - - public virtual void funct003018c8() - { - this.ee.pc = 3152092u; - // @003018C8 LUI t6, $3f00 - this.ee.t6.SD0 = 1056964608; - // @003018CC ADDU t6, t7, t6 - this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @003018D0 SLL t5, t1, 23 - MobUt.SLL(this.ee.t5, this.ee.t1, 23); - // @003018D4 BEQ zero, zero, $00301840 - if ((this.ee.r0.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3151936u; - } - // @003018D8 ADDU t5, t6, t5 - this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); - } - - public virtual void funct0032d8d0() - { - this.ee.pc = 3332316u; - // @0032D8D0 SLTIU t7, a1, $0010 - this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a1.UD0 < 16ul)); - // @0032D8D4 BEQ t7, zero, $0032d95c - if ((this.ee.t7.UD0 == this.ee.r0.UD0)) - { - this.ee.pc = 3332444u; - } - // @0032D8D8 LUI t6, $0038 - this.ee.t6.SD0 = 3670016; - } - - public virtual void funct0032d8dc() - { - this.ee.pc = 3332340u; - // @0032D8DC SLL t7, a1, 2 - MobUt.SLL(this.ee.t7, this.ee.a1, 2); - // @0032D8E0 ADDIU t6, t6, $8764 - this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -30876))); - // @0032D8E4 ADDU t7, t7, t6 - this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); - // @0032D8E8 LW t5, $0000(t7) - MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); - // @0032D8EC JR t5 - this.ee.pc = this.ee.t5.UL[0]; - // @0032D8F0 NOP - MobUt.Latency(); - } - - public virtual void funct0032d964() - { - this.ee.pc = 3332460u; - // @0032D964 JR ra - this.ee.pc = this.ee.ra.UL[0]; - // @0032D968 ADDIU v0, zero, $0001 - this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); - } - - private void initstate() - { - this.initregs(); - this.initfns(); - } - - private void initregs() - { - this.ee.r0.UD0 = 0ul; - this.ee.r0.UD1 = 0ul; - this.ee.at.UD0 = 1070141403ul; - this.ee.at.UD1 = 0ul; - this.ee.v0.UD0 = 229ul; - this.ee.v0.UD1 = 0ul; - this.ee.v1.UD0 = 3728656ul; - this.ee.v1.UD1 = 11678ul; - this.ee.a0.UD0 = 10454288ul; - this.ee.a0.UD1 = 11633ul; - this.ee.a1.UD0 = 28030352ul; - this.ee.a1.UD1 = 0ul; - this.ee.a2.UD0 = 3730592ul; - this.ee.a2.UD1 = 0ul; - this.ee.a3.UD0 = 0ul; - this.ee.a3.UD1 = 0ul; - this.ee.t0.UD0 = 3730800ul; - this.ee.t0.UD1 = 1059810839ul; - this.ee.t1.UD0 = 4575657221408423936ul; - this.ee.t1.UD1 = 0ul; - this.ee.t2.UD0 = 3207294487ul; - this.ee.t2.UD1 = 1061036071ul; - this.ee.t3.UD0 = 3306101109ul; - this.ee.t3.UD1 = 4575657224709998879ul; - this.ee.t4.UD0 = 8ul; - this.ee.t4.UD1 = 4575657221408423936ul; - this.ee.t5.UD0 = 10454432ul; - this.ee.t5.UD1 = 0ul; - this.ee.t6.UD0 = 0ul; - this.ee.t6.UD1 = 6660591616ul; - this.ee.t7.UD0 = 1ul; - this.ee.t7.UD1 = 78ul; - this.ee.s0.UD0 = 10454432ul; - this.ee.s0.UD1 = 0ul; - this.ee.s1.UD0 = 10454288ul; - this.ee.s1.UD1 = 0ul; - this.ee.s2.UD0 = 28030352ul; - this.ee.s2.UD1 = 0ul; - this.ee.s3.UD0 = 3730800ul; - this.ee.s3.UD1 = 0ul; - this.ee.s4.UD0 = 28029104ul; - this.ee.s4.UD1 = 0ul; - this.ee.s5.UD0 = 0ul; - this.ee.s5.UD1 = 0ul; - this.ee.s6.UD0 = 3730800ul; - this.ee.s6.UD1 = 0ul; - this.ee.s7.UD0 = 0ul; - this.ee.s7.UD1 = 0ul; - this.ee.t8.UD0 = 3728624ul; - this.ee.t8.UD1 = 0ul; - this.ee.t9.UD0 = 3728640ul; - this.ee.t9.UD1 = 0ul; - this.ee.k0.UD0 = 1879247891ul; - this.ee.k0.UD1 = 0ul; - this.ee.k1.UD0 = 0ul; - this.ee.k1.UD1 = 0ul; - this.ee.gp.UD0 = 3704508ul; - this.ee.gp.UD1 = 0ul; - this.ee.sp.UD0 = 3730592ul; - this.ee.sp.UD1 = 0ul; - this.ee.s8.UD0 = 0ul; - this.ee.s8.UD1 = 0ul; - this.ee.ra.UD0 = 1248400ul; - this.ee.ra.UD1 = 0ul; - this.ee.fpr[0].f = MobUt.UL2F(3212836864u); - this.ee.fpr[1].f = MobUt.UL2F(1065211454u); - this.ee.fpr[2].f = MobUt.UL2F(1088754307u); - this.ee.fpr[3].f = MobUt.UL2F(1007317092u); - this.ee.fpr[4].f = MobUt.UL2F(967154684u); - this.ee.fpr[5].f = MobUt.UL2F(3201396739u); - this.ee.fpr[6].f = MobUt.UL2F(1063086025u); - this.ee.fpr[7].f = MobUt.UL2F(1065353216u); - this.ee.fpr[8].f = MobUt.UL2F(1147806946u); - this.ee.fpr[9].f = MobUt.UL2F(1124209790u); - this.ee.fpr[10].f = MobUt.UL2F(1108805435u); - this.ee.fpr[11].f = MobUt.UL2F(0u); - this.ee.fpr[12].f = MobUt.UL2F(1090519040u); - this.ee.fpr[13].f = MobUt.UL2F(0u); - this.ee.fpr[14].f = MobUt.UL2F(3241277924u); - this.ee.fpr[15].f = MobUt.UL2F(3160289907u); - this.ee.fpr[16].f = MobUt.UL2F(1004365769u); - this.ee.fpr[17].f = MobUt.UL2F(3240795268u); - this.ee.fpr[18].f = MobUt.UL2F(3165876745u); - this.ee.fpr[19].f = MobUt.UL2F(1065353216u); - this.ee.fpr[20].f = MobUt.UL2F(1090519040u); - this.ee.fpr[21].f = MobUt.UL2F(0u); - this.ee.fpr[22].f = MobUt.UL2F(0u); - this.ee.fpr[23].f = MobUt.UL2F(0u); - this.ee.fpr[24].f = MobUt.UL2F(0u); - this.ee.fpr[25].f = MobUt.UL2F(0u); - this.ee.fpr[26].f = MobUt.UL2F(0u); - this.ee.fpr[27].f = MobUt.UL2F(0u); - this.ee.fpr[28].f = MobUt.UL2F(0u); - this.ee.fpr[29].f = MobUt.UL2F(0u); - this.ee.fpr[30].f = MobUt.UL2F(0u); - this.ee.fpr[31].f = MobUt.UL2F(0u); - this.ee.fpracc.f = MobUt.UL2F(3241375643u); - this.ee.VF[0].x = MobUt.UL2F(0u); - this.ee.VF[0].y = MobUt.UL2F(0u); - this.ee.VF[0].z = MobUt.UL2F(0u); - this.ee.VF[0].w = MobUt.UL2F(1065353216u); - this.ee.VF[1].x = MobUt.UL2F(1059810839u); - this.ee.VF[1].y = MobUt.UL2F(2147483648u); - this.ee.VF[1].z = MobUt.UL2F(3208519719u); - this.ee.VF[1].w = MobUt.UL2F(2147483648u); - this.ee.VF[2].x = MobUt.UL2F(3212836864u); - this.ee.VF[2].y = MobUt.UL2F(4294967295u); - this.ee.VF[2].z = MobUt.UL2F(1059810839u); - this.ee.VF[2].w = MobUt.UL2F(0u); - this.ee.VF[3].x = MobUt.UL2F(3207294487u); - this.ee.VF[3].y = MobUt.UL2F(2147483648u); - this.ee.VF[3].z = MobUt.UL2F(1061036071u); - this.ee.VF[3].w = MobUt.UL2F(0u); - this.ee.VF[4].x = MobUt.UL2F(3306101109u); - this.ee.VF[4].y = MobUt.UL2F(0u); - this.ee.VF[4].z = MobUt.UL2F(3301574943u); - this.ee.VF[4].w = MobUt.UL2F(1065353216u); - this.ee.VF[5].x = MobUt.UL2F(1061036071u); - this.ee.VF[5].y = MobUt.UL2F(0u); - this.ee.VF[5].z = MobUt.UL2F(1059810839u); - this.ee.VF[5].w = MobUt.UL2F(0u); - this.ee.VF[6].x = MobUt.UL2F(0u); - this.ee.VF[6].y = MobUt.UL2F(1065353216u); - this.ee.VF[6].z = MobUt.UL2F(0u); - this.ee.VF[6].w = MobUt.UL2F(0u); - this.ee.VF[7].x = MobUt.UL2F(3207294487u); - this.ee.VF[7].y = MobUt.UL2F(0u); - this.ee.VF[7].z = MobUt.UL2F(1061036071u); - this.ee.VF[7].w = MobUt.UL2F(0u); - this.ee.VF[8].x = MobUt.UL2F(3306101109u); - this.ee.VF[8].y = MobUt.UL2F(0u); - this.ee.VF[8].z = MobUt.UL2F(3301574943u); - this.ee.VF[8].w = MobUt.UL2F(1065353216u); - this.ee.VF[9].x = MobUt.UL2F(0u); - this.ee.VF[9].y = MobUt.UL2F(0u); - this.ee.VF[9].z = MobUt.UL2F(0u); - this.ee.VF[9].w = MobUt.UL2F(1065353216u); - this.ee.VF[10].x = MobUt.UL2F(1221302671u); - this.ee.VF[10].y = MobUt.UL2F(1221302671u); - this.ee.VF[10].z = MobUt.UL2F(3290595208u); - this.ee.VF[10].w = MobUt.UL2F(1129027983u); - this.ee.VF[11].x = MobUt.UL2F(1278239296u); - this.ee.VF[11].y = MobUt.UL2F(1277754648u); - this.ee.VF[11].z = MobUt.UL2F(1266599817u); - this.ee.VF[11].w = MobUt.UL2F(1186077023u); - this.ee.VF[12].x = MobUt.UL2F(1157627904u); - this.ee.VF[12].y = MobUt.UL2F(1157627904u); - this.ee.VF[12].z = MobUt.UL2F(1249902592u); - this.ee.VF[12].w = MobUt.UL2F(1249902592u); - this.ee.VF[13].x = MobUt.UL2F(0u); - this.ee.VF[13].y = MobUt.UL2F(0u); - this.ee.VF[13].z = MobUt.UL2F(0u); - this.ee.VF[13].w = MobUt.UL2F(1132462080u); - this.ee.VF[14].x = MobUt.UL2F(0u); - this.ee.VF[14].y = MobUt.UL2F(0u); - this.ee.VF[14].z = MobUt.UL2F(0u); - this.ee.VF[14].w = MobUt.UL2F(1153433600u); - this.ee.VF[15].x = MobUt.UL2F(1068826624u); - this.ee.VF[15].y = MobUt.UL2F(1065746432u); - this.ee.VF[15].z = MobUt.UL2F(1060896768u); - this.ee.VF[15].w = MobUt.UL2F(1068761088u); - this.ee.VF[16].x = MobUt.UL2F(32435u); - this.ee.VF[16].y = MobUt.UL2F(31091u); - this.ee.VF[16].z = MobUt.UL2F(11678u); - this.ee.VF[16].w = MobUt.UL2F(943151540u); - this.ee.VF[17].x = MobUt.UL2F(3301739238u); - this.ee.VF[17].y = MobUt.UL2F(3321541486u); - this.ee.VF[17].z = MobUt.UL2F(1186077023u); - this.ee.VF[17].w = MobUt.UL2F(1065353216u); - this.ee.VF[18].x = MobUt.UL2F(1154255590u); - this.ee.VF[18].y = MobUt.UL2F(1174057838u); - this.ee.VF[18].z = MobUt.UL2F(3333560671u); - this.ee.VF[18].w = MobUt.UL2F(3221225472u); - this.ee.VF[19].x = MobUt.UL2F(0u); - this.ee.VF[19].y = MobUt.UL2F(0u); - this.ee.VF[19].z = MobUt.UL2F(0u); - this.ee.VF[19].w = MobUt.UL2F(1065353216u); - this.ee.VF[20].x = MobUt.UL2F(32224u); - this.ee.VF[20].y = MobUt.UL2F(30845u); - this.ee.VF[20].z = MobUt.UL2F(11719u); - this.ee.VF[20].w = MobUt.UL2F(364746u); - this.ee.VF[21].x = MobUt.UL2F(1158017723u); - this.ee.VF[21].y = MobUt.UL2F(1159360723u); - this.ee.VF[21].z = MobUt.UL2F(1144462391u); - this.ee.VF[21].w = MobUt.UL2F(1186077023u); - this.ee.VF[22].x = MobUt.UL2F(1157913735u); - this.ee.VF[22].y = MobUt.UL2F(1159493858u); - this.ee.VF[22].z = MobUt.UL2F(1144462391u); - this.ee.VF[22].w = MobUt.UL2F(1186077023u); - this.ee.VF[23].x = MobUt.UL2F(32688u); - this.ee.VF[23].y = MobUt.UL2F(31347u); - this.ee.VF[23].z = MobUt.UL2F(11719u); - this.ee.VF[23].w = MobUt.UL2F(364746u); - this.ee.VF[24].x = MobUt.UL2F(1278158170u); - this.ee.VF[24].y = MobUt.UL2F(1277666762u); - this.ee.VF[24].z = MobUt.UL2F(1144462391u); - this.ee.VF[24].w = MobUt.UL2F(1186077023u); - this.ee.VF[25].x = MobUt.UL2F(3293934063u); - this.ee.VF[25].y = MobUt.UL2F(3292049472u); - this.ee.VF[25].z = MobUt.UL2F(1066904244u); - this.ee.VF[25].w = MobUt.UL2F(3200124770u); - this.ee.VF[26].x = MobUt.UL2F(1174396132u); - this.ee.VF[26].y = MobUt.UL2F(1282769649u); - this.ee.VF[26].z = MobUt.UL2F(1044218678u); - this.ee.VF[26].w = MobUt.UL2F(3178066551u); - this.ee.VF[27].x = MobUt.UL2F(1157627904u); - this.ee.VF[27].y = MobUt.UL2F(1157627904u); - this.ee.VF[27].z = MobUt.UL2F(1249902592u); - this.ee.VF[27].w = MobUt.UL2F(1249902592u); - this.ee.VF[28].x = MobUt.UL2F(1177474794u); - this.ee.VF[28].y = MobUt.UL2F(0u); - this.ee.VF[28].z = MobUt.UL2F(0u); - this.ee.VF[28].w = MobUt.UL2F(0u); - this.ee.VF[29].x = MobUt.UL2F(0u); - this.ee.VF[29].y = MobUt.UL2F(1178429652u); - this.ee.VF[29].z = MobUt.UL2F(0u); - this.ee.VF[29].w = MobUt.UL2F(0u); - this.ee.VF[30].x = MobUt.UL2F(1221302671u); - this.ee.VF[30].y = MobUt.UL2F(1221302671u); - this.ee.VF[30].z = MobUt.UL2F(3290595208u); - this.ee.VF[30].w = MobUt.UL2F(1129027983u); - this.ee.VF[31].x = MobUt.UL2F(1278239296u); - this.ee.VF[31].y = MobUt.UL2F(1277754648u); - this.ee.VF[31].z = MobUt.UL2F(1266599817u); - this.ee.VF[31].w = MobUt.UL2F(1186077023u); - } - - private void initfns() - { - this.dicti2a[1160224u] = new MobUt.Tx8(this.funct0011b420); - this.dicti2a[1160272u] = new MobUt.Tx8(this.funct0011b450); - this.dicti2a[1160300u] = new MobUt.Tx8(this.funct0011b46c); - this.dicti2a[1160308u] = new MobUt.Tx8(this.funct0011b474); - this.dicti2a[1160324u] = new MobUt.Tx8(this.funct0011b484); - this.dicti2a[1160488u] = new MobUt.Tx8(this.funct0011b528); - this.dicti2a[1160536u] = new MobUt.Tx8(this.funct0011b558); - this.dicti2a[1160544u] = new MobUt.Tx8(this.funct0011b560); - this.dicti2a[1160560u] = new MobUt.Tx8(this.funct0011b570); - this.dicti2a[1160576u] = new MobUt.Tx8(this.funct0011b580); - this.dicti2a[1160584u] = new MobUt.Tx8(this.funct0011b588); - this.dicti2a[1160600u] = new MobUt.Tx8(this.funct0011b598); - this.dicti2a[1160616u] = new MobUt.Tx8(this.funct0011b5a8); - this.dicti2a[1160624u] = new MobUt.Tx8(this.funct0011b5b0); - this.dicti2a[1160640u] = new MobUt.Tx8(this.funct0011b5c0); - this.dicti2a[1161280u] = new MobUt.Tx8(this.funct0011b840); - this.dicti2a[1161332u] = new MobUt.Tx8(this.funct0011b874); - this.dicti2a[1161356u] = new MobUt.Tx8(this.funct0011b88c); - this.dicti2a[1161364u] = new MobUt.Tx8(this.funct0011b894); - this.dicti2a[1161412u] = new MobUt.Tx8(this.funct0011b8c4); - this.dicti2a[1161420u] = new MobUt.Tx8(this.funct0011b8cc); - this.dicti2a[1161432u] = new MobUt.Tx8(this.funct0011b8d8); - this.dicti2a[1161448u] = new MobUt.Tx8(this.funct0011b8e8); - this.dicti2a[1161456u] = new MobUt.Tx8(this.funct0011b8f0); - this.dicti2a[1161472u] = new MobUt.Tx8(this.funct0011b900); - this.dicti2a[1161492u] = new MobUt.Tx8(this.funct0011b914); - this.dicti2a[1161512u] = new MobUt.Tx8(this.funct0011b928); - this.dicti2a[1161576u] = new MobUt.Tx8(this.funct0011b968); - this.dicti2a[1161596u] = new MobUt.Tx8(this.funct0011b97c); - this.dicti2a[1161616u] = new MobUt.Tx8(this.funct0011b990); - this.dicti2a[1161692u] = new MobUt.Tx8(this.funct0011b9dc); - this.dicti2a[1161736u] = new MobUt.Tx8(this.funct0011ba08); - this.dicti2a[1161760u] = new MobUt.Tx8(this.funct0011ba20); - this.dicti2a[1161808u] = new MobUt.Tx8(this.funct0011ba50); - this.dicti2a[1161820u] = new MobUt.Tx8(this.funct0011ba5c); - this.dicti2a[1161832u] = new MobUt.Tx8(this.funct0011ba68); - this.dicti2a[1161860u] = new MobUt.Tx8(this.funct0011ba84); - this.dicti2a[1161888u] = new MobUt.Tx8(this.funct0011baa0); - this.dicti2a[1162696u] = new MobUt.Tx8(this.funct0011bdc8); - this.dicti2a[1162712u] = new MobUt.Tx8(this.funct0011bdd8); - this.dicti2a[1162732u] = new MobUt.Tx8(this.funct0011bdec); - this.dicti2a[1162752u] = new MobUt.Tx8(this.funct0011be00); - this.dicti2a[1162780u] = new MobUt.Tx8(this.funct0011be1c); - this.dicti2a[1162788u] = new MobUt.Tx8(this.funct0011be24); - this.dicti2a[1162812u] = new MobUt.Tx8(this.funct0011be3c); - this.dicti2a[1162828u] = new MobUt.Tx8(this.funct0011be4c); - this.dicti2a[1162840u] = new MobUt.Tx8(this.funct0011be58); - this.dicti2a[1181264u] = new MobUt.Tx8(this.funct00120650); - this.dicti2a[1181296u] = new MobUt.Tx8(this.funct00120670); - this.dicti2a[1181328u] = new MobUt.Tx8(this.funct00120690); - this.dicti2a[1181344u] = new MobUt.Tx8(this.funct001206a0); - this.dicti2a[1181372u] = new MobUt.Tx8(this.funct001206bc); - this.dicti2a[1181380u] = new MobUt.Tx8(this.funct001206c4); - this.dicti2a[1198728u] = new MobUt.Tx8(this.funct00124a88); - this.dicti2a[1198900u] = new MobUt.Tx8(this.funct00124b34); - this.dicti2a[1198972u] = new MobUt.Tx8(this.funct00124b7c); - this.dicti2a[1198996u] = new MobUt.Tx8(this.funct00124b94); - this.dicti2a[1199092u] = new MobUt.Tx8(this.funct00124bf4); - this.dicti2a[1199188u] = new MobUt.Tx8(this.funct00124c54); - this.dicti2a[1199256u] = new MobUt.Tx8(this.funct00124c98); - this.dicti2a[1199264u] = new MobUt.Tx8(this.funct00124ca0); - this.dicti2a[1199284u] = new MobUt.Tx8(this.funct00124cb4); - this.dicti2a[1199304u] = new MobUt.Tx8(this.funct00124cc8); - this.dicti2a[1199336u] = new MobUt.Tx8(this.funct00124ce8); - this.dicti2a[1199344u] = new MobUt.Tx8(this.funct00124cf0); - this.dicti2a[1199356u] = new MobUt.Tx8(this.funct00124cfc); - this.dicti2a[1199480u] = new MobUt.Tx8(this.funct00124d78); - this.dicti2a[1199512u] = new MobUt.Tx8(this.funct00124d98); - this.dicti2a[1199520u] = new MobUt.Tx8(this.funct00124da0); - this.dicti2a[1199528u] = new MobUt.Tx8(this.funct00124da8); - this.dicti2a[1199564u] = new MobUt.Tx8(this.funct00124dcc); - this.dicti2a[1199620u] = new MobUt.Tx8(this.funct00124e04); - this.dicti2a[1199672u] = new MobUt.Tx8(this.funct00124e38); - this.dicti2a[1199676u] = new MobUt.Tx8(this.funct00124e3c); - this.dicti2a[1199680u] = new MobUt.Tx8(this.funct00124e40); - this.dicti2a[1199712u] = new MobUt.Tx8(this.funct00124e60); - this.dicti2a[1199720u] = new MobUt.Tx8(this.funct00124e68); - this.dicti2a[1199740u] = new MobUt.Tx8(this.funct00124e7c); - this.dicti2a[1199828u] = new MobUt.Tx8(this.funct00124ed4); - this.dicti2a[1199840u] = new MobUt.Tx8(this.funct00124ee0); - this.dicti2a[1199852u] = new MobUt.Tx8(this.funct00124eec); - this.dicti2a[1199972u] = new MobUt.Tx8(this.funct00124f64); - this.dicti2a[1200004u] = new MobUt.Tx8(this.funct00124f84); - this.dicti2a[1200276u] = new MobUt.Tx8(this.funct00125094); - this.dicti2a[1200316u] = new MobUt.Tx8(this.funct001250bc); - this.dicti2a[1200336u] = new MobUt.Tx8(this.funct001250d0); - this.dicti2a[1200356u] = new MobUt.Tx8(this.funct001250e4); - this.dicti2a[1200364u] = new MobUt.Tx8(this.funct001250ec); - this.dicti2a[1200472u] = new MobUt.Tx8(this.funct00125158); - this.dicti2a[1211936u] = new MobUt.Tx8(this.funct00127e20); - this.dicti2a[1212020u] = new MobUt.Tx8(this.funct00127e74); - this.dicti2a[1212032u] = new MobUt.Tx8(this.funct00127e80); - this.dicti2a[1212040u] = new MobUt.Tx8(this.funct00127e88); - this.dicti2a[1212052u] = new MobUt.Tx8(this.funct00127e94); - this.dicti2a[1212080u] = new MobUt.Tx8(this.funct00127eb0); - this.dicti2a[1212108u] = new MobUt.Tx8(this.funct00127ecc); - this.dicti2a[1212164u] = new MobUt.Tx8(this.funct00127f04); - this.dicti2a[1212176u] = new MobUt.Tx8(this.funct00127f10); - this.dicti2a[1212276u] = new MobUt.Tx8(this.funct00127f74); - this.dicti2a[1212288u] = new MobUt.Tx8(this.funct00127f80); - this.dicti2a[1212292u] = new MobUt.Tx8(this.funct00127f84); - this.dicti2a[1212368u] = new MobUt.Tx8(this.funct00127fd0); - this.dicti2a[1212392u] = new MobUt.Tx8(this.funct00127fe8); - this.dicti2a[1212424u] = new MobUt.Tx8(this.funct00128008); - this.dicti2a[1212448u] = new MobUt.Tx8(this.funct00128020); - this.dicti2a[1212556u] = new MobUt.Tx8(this.funct0012808c); - this.dicti2a[1212572u] = new MobUt.Tx8(this.funct0012809c); - this.dicti2a[1212592u] = new MobUt.Tx8(this.funct001280b0); - this.dicti2a[1212612u] = new MobUt.Tx8(this.funct001280c4); - this.dicti2a[1212616u] = new MobUt.Tx8(this.funct001280c8); - this.dicti2a[1212624u] = new MobUt.Tx8(this.funct001280d0); - this.dicti2a[1212644u] = new MobUt.Tx8(this.funct001280e4); - this.dicti2a[1212664u] = new MobUt.Tx8(this.funct001280f8); - this.dicti2a[1212668u] = new MobUt.Tx8(this.funct001280fc); - this.dicti2a[1212688u] = new MobUt.Tx8(this.funct00128110); - this.dicti2a[1212696u] = new MobUt.Tx8(this.funct00128118); - this.dicti2a[1212756u] = new MobUt.Tx8(this.funct00128154); - this.dicti2a[1212768u] = new MobUt.Tx8(this.funct00128160); - this.dicti2a[1212804u] = new MobUt.Tx8(this.funct00128184); - this.dicti2a[1212832u] = new MobUt.Tx8(this.funct001281a0); - this.dicti2a[1212852u] = new MobUt.Tx8(this.funct001281b4); - this.dicti2a[1212872u] = new MobUt.Tx8(this.funct001281c8); - this.dicti2a[1212876u] = new MobUt.Tx8(this.funct001281cc); - this.dicti2a[1212904u] = new MobUt.Tx8(this.funct001281e8); - this.dicti2a[1212912u] = new MobUt.Tx8(this.funct001281f0); - this.dicti2a[1212916u] = new MobUt.Tx8(this.funct001281f4); - this.dicti2a[1212924u] = new MobUt.Tx8(this.funct001281fc); - this.dicti2a[1212960u] = new MobUt.Tx8(this.funct00128220); - this.dicti2a[1212988u] = new MobUt.Tx8(this.funct0012823c); - this.dicti2a[1213012u] = new MobUt.Tx8(this.funct00128254); - this.dicti2a[1213024u] = new MobUt.Tx8(this.funct00128260); - this.dicti2a[1213076u] = new MobUt.Tx8(this.funct00128294); - this.dicti2a[1213084u] = new MobUt.Tx8(this.funct0012829c); - this.dicti2a[1213108u] = new MobUt.Tx8(this.funct001282b4); - this.dicti2a[1213136u] = new MobUt.Tx8(this.funct001282d0); - this.dicti2a[1213164u] = new MobUt.Tx8(this.funct001282ec); - this.dicti2a[1213188u] = new MobUt.Tx8(this.funct00128304); - this.dicti2a[1213200u] = new MobUt.Tx8(this.funct00128310); - this.dicti2a[1213216u] = new MobUt.Tx8(this.funct00128320); - this.dicti2a[1213236u] = new MobUt.Tx8(this.funct00128334); - this.dicti2a[1213260u] = new MobUt.Tx8(this.funct0012834c); - this.dicti2a[1213296u] = new MobUt.Tx8(this.funct00128370); - this.dicti2a[1213312u] = new MobUt.Tx8(this.funct00128380); - this.dicti2a[1213316u] = new MobUt.Tx8(this.funct00128384); - this.dicti2a[1213336u] = new MobUt.Tx8(this.funct00128398); - this.dicti2a[1213352u] = new MobUt.Tx8(this.funct001283a8); - this.dicti2a[1213380u] = new MobUt.Tx8(this.funct001283c4); - this.dicti2a[1213400u] = new MobUt.Tx8(this.funct001283d8); - this.dicti2a[1213440u] = new MobUt.Tx8(this.funct00128400); - this.dicti2a[1213460u] = new MobUt.Tx8(this.funct00128414); - this.dicti2a[1213472u] = new MobUt.Tx8(this.funct00128420); - this.dicti2a[1213488u] = new MobUt.Tx8(this.funct00128430); - this.dicti2a[1213520u] = new MobUt.Tx8(this.funct00128450); - this.dicti2a[1213556u] = new MobUt.Tx8(this.funct00128474); - this.dicti2a[1213560u] = new MobUt.Tx8(this.funct00128478); - this.dicti2a[1213584u] = new MobUt.Tx8(this.funct00128490); - this.dicti2a[1213592u] = new MobUt.Tx8(this.funct00128498); - this.dicti2a[1213600u] = new MobUt.Tx8(this.funct001284a0); - this.dicti2a[1213608u] = new MobUt.Tx8(this.funct001284a8); - this.dicti2a[1213616u] = new MobUt.Tx8(this.funct001284b0); - this.dicti2a[1213744u] = new MobUt.Tx8(this.funct00128530); - this.dicti2a[1213892u] = new MobUt.Tx8(this.funct001285c4); - this.dicti2a[1213916u] = new MobUt.Tx8(this.funct001285dc); - this.dicti2a[1213924u] = new MobUt.Tx8(this.funct001285e4); - this.dicti2a[1213936u] = new MobUt.Tx8(this.funct001285f0); - this.dicti2a[1213940u] = new MobUt.Tx8(this.funct001285f4); - this.dicti2a[1213980u] = new MobUt.Tx8(this.funct0012861c); - this.dicti2a[1213996u] = new MobUt.Tx8(this.funct0012862c); - this.dicti2a[1214004u] = new MobUt.Tx8(this.funct00128634); - this.dicti2a[1214044u] = new MobUt.Tx8(this.funct0012865c); - this.dicti2a[1214048u] = new MobUt.Tx8(this.funct00128660); - this.dicti2a[1214060u] = new MobUt.Tx8(this.funct0012866c); - this.dicti2a[1214064u] = new MobUt.Tx8(this.funct00128670); - this.dicti2a[1214080u] = new MobUt.Tx8(this.funct00128680); - this.dicti2a[1214092u] = new MobUt.Tx8(this.funct0012868c); - this.dicti2a[1214120u] = new MobUt.Tx8(this.funct001286a8); - this.dicti2a[1214124u] = new MobUt.Tx8(this.funct001286ac); - this.dicti2a[1214176u] = new MobUt.Tx8(this.funct001286e0); - this.dicti2a[1214188u] = new MobUt.Tx8(this.funct001286ec); - this.dicti2a[1214196u] = new MobUt.Tx8(this.funct001286f4); - this.dicti2a[1214212u] = new MobUt.Tx8(this.funct00128704); - this.dicti2a[1214216u] = new MobUt.Tx8(this.funct00128708); - this.dicti2a[1214232u] = new MobUt.Tx8(this.funct00128718); - this.dicti2a[1214336u] = new MobUt.Tx8(this.funct00128780); - this.dicti2a[1214348u] = new MobUt.Tx8(this.funct0012878c); - this.dicti2a[1214356u] = new MobUt.Tx8(this.funct00128794); - this.dicti2a[1214364u] = new MobUt.Tx8(this.funct0012879c); - this.dicti2a[1214400u] = new MobUt.Tx8(this.funct001287c0); - this.dicti2a[1214412u] = new MobUt.Tx8(this.funct001287cc); - this.dicti2a[1214424u] = new MobUt.Tx8(this.funct001287d8); - this.dicti2a[1214432u] = new MobUt.Tx8(this.funct001287e0); - this.dicti2a[1214440u] = new MobUt.Tx8(this.funct001287e8); - this.dicti2a[1214452u] = new MobUt.Tx8(this.funct001287f4); - this.dicti2a[1214460u] = new MobUt.Tx8(this.funct001287fc); - this.dicti2a[1214468u] = new MobUt.Tx8(this.funct00128804); - this.dicti2a[1214528u] = new MobUt.Tx8(this.funct00128840); - this.dicti2a[1214548u] = new MobUt.Tx8(this.funct00128854); - this.dicti2a[1214572u] = new MobUt.Tx8(this.funct0012886c); - this.dicti2a[1214580u] = new MobUt.Tx8(this.funct00128874); - this.dicti2a[1214588u] = new MobUt.Tx8(this.funct0012887c); - this.dicti2a[1214596u] = new MobUt.Tx8(this.funct00128884); - this.dicti2a[1214604u] = new MobUt.Tx8(this.funct0012888c); - this.dicti2a[1214640u] = new MobUt.Tx8(this.funct001288b0); - this.dicti2a[1214644u] = new MobUt.Tx8(this.funct001288b4); - this.dicti2a[1214672u] = new MobUt.Tx8(this.funct001288d0); - this.dicti2a[1214680u] = new MobUt.Tx8(this.funct001288d8); - this.dicti2a[1214744u] = new MobUt.Tx8(this.funct00128918); - this.dicti2a[1214808u] = new MobUt.Tx8(this.funct00128958); - this.dicti2a[1214828u] = new MobUt.Tx8(this.funct0012896c); - this.dicti2a[1214852u] = new MobUt.Tx8(this.funct00128984); - this.dicti2a[1214876u] = new MobUt.Tx8(this.funct0012899c); - this.dicti2a[1214900u] = new MobUt.Tx8(this.funct001289b4); - this.dicti2a[1214932u] = new MobUt.Tx8(this.funct001289d4); - this.dicti2a[1214948u] = new MobUt.Tx8(this.funct001289e4); - this.dicti2a[1214976u] = new MobUt.Tx8(this.funct00128a00); - this.dicti2a[1215000u] = new MobUt.Tx8(this.funct00128a18); - this.dicti2a[1215024u] = new MobUt.Tx8(this.funct00128a30); - this.dicti2a[1215048u] = new MobUt.Tx8(this.funct00128a48); - this.dicti2a[1215076u] = new MobUt.Tx8(this.funct00128a64); - this.dicti2a[1215092u] = new MobUt.Tx8(this.funct00128a74); - this.dicti2a[1215132u] = new MobUt.Tx8(this.funct00128a9c); - this.dicti2a[1215168u] = new MobUt.Tx8(this.funct00128ac0); - this.dicti2a[1215204u] = new MobUt.Tx8(this.funct00128ae4); - this.dicti2a[1215220u] = new MobUt.Tx8(this.funct00128af4); - this.dicti2a[1215244u] = new MobUt.Tx8(this.funct00128b0c); - this.dicti2a[1215264u] = new MobUt.Tx8(this.funct00128b20); - this.dicti2a[1215276u] = new MobUt.Tx8(this.funct00128b2c); - this.dicti2a[1215376u] = new MobUt.Tx8(this.funct00128b90); - this.dicti2a[1215420u] = new MobUt.Tx8(this.funct00128bbc); - this.dicti2a[1215520u] = new MobUt.Tx8(this.funct00128c20); - this.dicti2a[1215608u] = new MobUt.Tx8(this.funct00128c78); - this.dicti2a[1215628u] = new MobUt.Tx8(this.funct00128c8c); - this.dicti2a[1215648u] = new MobUt.Tx8(this.funct00128ca0); - this.dicti2a[1215656u] = new MobUt.Tx8(this.funct00128ca8); - this.dicti2a[1215692u] = new MobUt.Tx8(this.funct00128ccc); - this.dicti2a[1215700u] = new MobUt.Tx8(this.funct00128cd4); - this.dicti2a[1215780u] = new MobUt.Tx8(this.funct00128d24); - this.dicti2a[1215788u] = new MobUt.Tx8(this.funct00128d2c); - this.dicti2a[1215796u] = new MobUt.Tx8(this.funct00128d34); - this.dicti2a[1215804u] = new MobUt.Tx8(this.funct00128d3c); - this.dicti2a[1215852u] = new MobUt.Tx8(this.funct00128d6c); - this.dicti2a[1215868u] = new MobUt.Tx8(this.funct00128d7c); - this.dicti2a[1215884u] = new MobUt.Tx8(this.funct00128d8c); - this.dicti2a[1215900u] = new MobUt.Tx8(this.funct00128d9c); - this.dicti2a[1215920u] = new MobUt.Tx8(this.funct00128db0); - this.dicti2a[1215928u] = new MobUt.Tx8(this.funct00128db8); - this.dicti2a[1215944u] = new MobUt.Tx8(this.funct00128dc8); - this.dicti2a[1215960u] = new MobUt.Tx8(this.funct00128dd8); - this.dicti2a[1215976u] = new MobUt.Tx8(this.funct00128de8); - this.dicti2a[1216032u] = new MobUt.Tx8(this.funct00128e20); - this.dicti2a[1216044u] = new MobUt.Tx8(this.funct00128e2c); - this.dicti2a[1216064u] = new MobUt.Tx8(this.funct00128e40); - this.dicti2a[1216136u] = new MobUt.Tx8(this.funct00128e88); - this.dicti2a[1216176u] = new MobUt.Tx8(this.funct00128eb0); - this.dicti2a[1216232u] = new MobUt.Tx8(this.funct00128ee8); - this.dicti2a[1216236u] = new MobUt.Tx8(this.funct00128eec); - this.dicti2a[1216356u] = new MobUt.Tx8(this.funct00128f64); - this.dicti2a[1216364u] = new MobUt.Tx8(this.funct00128f6c); - this.dicti2a[1216372u] = new MobUt.Tx8(this.funct00128f74); - this.dicti2a[1216384u] = new MobUt.Tx8(this.funct00128f80); - this.dicti2a[1216588u] = new MobUt.Tx8(this.funct0012904c); - this.dicti2a[1216596u] = new MobUt.Tx8(this.funct00129054); - this.dicti2a[1216616u] = new MobUt.Tx8(this.funct00129068); - this.dicti2a[1216628u] = new MobUt.Tx8(this.funct00129074); - this.dicti2a[1216636u] = new MobUt.Tx8(this.funct0012907c); - this.dicti2a[1216644u] = new MobUt.Tx8(this.funct00129084); - this.dicti2a[1216652u] = new MobUt.Tx8(this.funct0012908c); - this.dicti2a[1216672u] = new MobUt.Tx8(this.funct001290a0); - this.dicti2a[1216792u] = new MobUt.Tx8(this.funct00129118); - this.dicti2a[1216812u] = new MobUt.Tx8(this.funct0012912c); - this.dicti2a[1216836u] = new MobUt.Tx8(this.funct00129144); - this.dicti2a[1216852u] = new MobUt.Tx8(this.funct00129154); - this.dicti2a[1216884u] = new MobUt.Tx8(this.funct00129174); - this.dicti2a[1216892u] = new MobUt.Tx8(this.funct0012917c); - this.dicti2a[1216900u] = new MobUt.Tx8(this.funct00129184); - this.dicti2a[1217148u] = new MobUt.Tx8(this.funct0012927c); - this.dicti2a[1217156u] = new MobUt.Tx8(this.funct00129284); - this.dicti2a[1217176u] = new MobUt.Tx8(this.funct00129298); - this.dicti2a[1217184u] = new MobUt.Tx8(this.funct001292a0); - this.dicti2a[1217192u] = new MobUt.Tx8(this.funct001292a8); - this.dicti2a[1217212u] = new MobUt.Tx8(this.funct001292bc); - this.dicti2a[1217220u] = new MobUt.Tx8(this.funct001292c4); - this.dicti2a[1217228u] = new MobUt.Tx8(this.funct001292cc); - this.dicti2a[1217248u] = new MobUt.Tx8(this.funct001292e0); - this.dicti2a[1217256u] = new MobUt.Tx8(this.funct001292e8); - this.dicti2a[1217264u] = new MobUt.Tx8(this.funct001292f0); - this.dicti2a[1217284u] = new MobUt.Tx8(this.funct00129304); - this.dicti2a[1217392u] = new MobUt.Tx8(this.funct00129370); - this.dicti2a[1217408u] = new MobUt.Tx8(this.funct00129380); - this.dicti2a[1217416u] = new MobUt.Tx8(this.funct00129388); - this.dicti2a[1217424u] = new MobUt.Tx8(this.funct00129390); - this.dicti2a[1217444u] = new MobUt.Tx8(this.funct001293a4); - this.dicti2a[1217488u] = new MobUt.Tx8(this.funct001293d0); - this.dicti2a[1217496u] = new MobUt.Tx8(this.funct001293d8); - this.dicti2a[1217516u] = new MobUt.Tx8(this.funct001293ec); - this.dicti2a[1217692u] = new MobUt.Tx8(this.funct0012949c); - this.dicti2a[1217704u] = new MobUt.Tx8(this.funct001294a8); - this.dicti2a[1217712u] = new MobUt.Tx8(this.funct001294b0); - this.dicti2a[1217748u] = new MobUt.Tx8(this.funct001294d4); - this.dicti2a[1217752u] = new MobUt.Tx8(this.funct001294d8); - this.dicti2a[1217784u] = new MobUt.Tx8(this.funct001294f8); - this.dicti2a[1217796u] = new MobUt.Tx8(this.funct00129504); - this.dicti2a[1217812u] = new MobUt.Tx8(this.funct00129514); - this.dicti2a[1217820u] = new MobUt.Tx8(this.funct0012951c); - this.dicti2a[1217920u] = new MobUt.Tx8(this.funct00129580); - this.dicti2a[1217964u] = new MobUt.Tx8(this.funct001295ac); - this.dicti2a[1217980u] = new MobUt.Tx8(this.funct001295bc); - this.dicti2a[1217988u] = new MobUt.Tx8(this.funct001295c4); - this.dicti2a[1218016u] = new MobUt.Tx8(this.funct001295e0); - this.dicti2a[1218044u] = new MobUt.Tx8(this.funct001295fc); - this.dicti2a[1218100u] = new MobUt.Tx8(this.funct00129634); - this.dicti2a[1218120u] = new MobUt.Tx8(this.funct00129648); - this.dicti2a[1218128u] = new MobUt.Tx8(this.funct00129650); - this.dicti2a[1218156u] = new MobUt.Tx8(this.funct0012966c); - this.dicti2a[1218184u] = new MobUt.Tx8(this.funct00129688); - this.dicti2a[1218192u] = new MobUt.Tx8(this.funct00129690); - this.dicti2a[1218244u] = new MobUt.Tx8(this.funct001296c4); - this.dicti2a[1218264u] = new MobUt.Tx8(this.funct001296d8); - this.dicti2a[1218308u] = new MobUt.Tx8(this.funct00129704); - this.dicti2a[1218324u] = new MobUt.Tx8(this.funct00129714); - this.dicti2a[1219096u] = new MobUt.Tx8(this.funct00129a18); - this.dicti2a[1219268u] = new MobUt.Tx8(this.funct00129ac4); - this.dicti2a[1219288u] = new MobUt.Tx8(this.funct00129ad8); - this.dicti2a[1219320u] = new MobUt.Tx8(this.funct00129af8); - this.dicti2a[1219340u] = new MobUt.Tx8(this.funct00129b0c); - this.dicti2a[1219344u] = new MobUt.Tx8(this.funct00129b10); - this.dicti2a[1219360u] = new MobUt.Tx8(this.funct00129b20); - this.dicti2a[1219380u] = new MobUt.Tx8(this.funct00129b34); - this.dicti2a[1219384u] = new MobUt.Tx8(this.funct00129b38); - this.dicti2a[1219396u] = new MobUt.Tx8(this.funct00129b44); - this.dicti2a[1219416u] = new MobUt.Tx8(this.funct00129b58); - this.dicti2a[1219444u] = new MobUt.Tx8(this.funct00129b74); - this.dicti2a[1219464u] = new MobUt.Tx8(this.funct00129b88); - this.dicti2a[1219472u] = new MobUt.Tx8(this.funct00129b90); - this.dicti2a[1219476u] = new MobUt.Tx8(this.funct00129b94); - this.dicti2a[1219488u] = new MobUt.Tx8(this.funct00129ba0); - this.dicti2a[1219512u] = new MobUt.Tx8(this.funct00129bb8); - this.dicti2a[1219524u] = new MobUt.Tx8(this.funct00129bc4); - this.dicti2a[1219560u] = new MobUt.Tx8(this.funct00129be8); - this.dicti2a[1219576u] = new MobUt.Tx8(this.funct00129bf8); - this.dicti2a[1219580u] = new MobUt.Tx8(this.funct00129bfc); - this.dicti2a[1219588u] = new MobUt.Tx8(this.funct00129c04); - this.dicti2a[1219604u] = new MobUt.Tx8(this.funct00129c14); - this.dicti2a[1219628u] = new MobUt.Tx8(this.funct00129c2c); - this.dicti2a[1219640u] = new MobUt.Tx8(this.funct00129c38); - this.dicti2a[1219644u] = new MobUt.Tx8(this.funct00129c3c); - this.dicti2a[1219660u] = new MobUt.Tx8(this.funct00129c4c); - this.dicti2a[1219672u] = new MobUt.Tx8(this.funct00129c58); - this.dicti2a[1219676u] = new MobUt.Tx8(this.funct00129c5c); - this.dicti2a[1219688u] = new MobUt.Tx8(this.funct00129c68); - this.dicti2a[1219704u] = new MobUt.Tx8(this.funct00129c78); - this.dicti2a[1219716u] = new MobUt.Tx8(this.funct00129c84); - this.dicti2a[1219728u] = new MobUt.Tx8(this.funct00129c90); - this.dicti2a[1219732u] = new MobUt.Tx8(this.funct00129c94); - this.dicti2a[1219740u] = new MobUt.Tx8(this.funct00129c9c); - this.dicti2a[1219752u] = new MobUt.Tx8(this.funct00129ca8); - this.dicti2a[1219764u] = new MobUt.Tx8(this.funct00129cb4); - this.dicti2a[1219788u] = new MobUt.Tx8(this.funct00129ccc); - this.dicti2a[1219800u] = new MobUt.Tx8(this.funct00129cd8); - this.dicti2a[1219812u] = new MobUt.Tx8(this.funct00129ce4); - this.dicti2a[1219832u] = new MobUt.Tx8(this.funct00129cf8); - this.dicti2a[1219840u] = new MobUt.Tx8(this.funct00129d00); - this.dicti2a[1219868u] = new MobUt.Tx8(this.funct00129d1c); - this.dicti2a[1219892u] = new MobUt.Tx8(this.funct00129d34); - this.dicti2a[1219908u] = new MobUt.Tx8(this.funct00129d44); - this.dicti2a[1219916u] = new MobUt.Tx8(this.funct00129d4c); - this.dicti2a[1219976u] = new MobUt.Tx8(this.funct00129d88); - this.dicti2a[1219984u] = new MobUt.Tx8(this.funct00129d90); - this.dicti2a[1220040u] = new MobUt.Tx8(this.funct00129dc8); - this.dicti2a[1220048u] = new MobUt.Tx8(this.funct00129dd0); - this.dicti2a[1220088u] = new MobUt.Tx8(this.funct00129df8); - this.dicti2a[1220100u] = new MobUt.Tx8(this.funct00129e04); - this.dicti2a[1220112u] = new MobUt.Tx8(this.funct00129e10); - this.dicti2a[1220140u] = new MobUt.Tx8(this.funct00129e2c); - this.dicti2a[1220156u] = new MobUt.Tx8(this.funct00129e3c); - this.dicti2a[1220160u] = new MobUt.Tx8(this.funct00129e40); - this.dicti2a[1220180u] = new MobUt.Tx8(this.funct00129e54); - this.dicti2a[1220188u] = new MobUt.Tx8(this.funct00129e5c); - this.dicti2a[1220192u] = new MobUt.Tx8(this.funct00129e60); - this.dicti2a[1221784u] = new MobUt.Tx8(this.funct0012a498); - this.dicti2a[1221820u] = new MobUt.Tx8(this.funct0012a4bc); - this.dicti2a[1221824u] = new MobUt.Tx8(this.funct0012a4c0); - this.dicti2a[1223092u] = new MobUt.Tx8(this.funct0012a9b4); - this.dicti2a[1223100u] = new MobUt.Tx8(this.funct0012a9bc); - this.dicti2a[1223120u] = new MobUt.Tx8(this.funct0012a9d0); - this.dicti2a[1223156u] = new MobUt.Tx8(this.funct0012a9f4); - this.dicti2a[1223164u] = new MobUt.Tx8(this.funct0012a9fc); - this.dicti2a[1223172u] = new MobUt.Tx8(this.funct0012aa04); - this.dicti2a[1223196u] = new MobUt.Tx8(this.funct0012aa1c); - this.dicti2a[1223216u] = new MobUt.Tx8(this.funct0012aa30); - this.dicti2a[1223224u] = new MobUt.Tx8(this.funct0012aa38); - this.dicti2a[1223232u] = new MobUt.Tx8(this.funct0012aa40); - this.dicti2a[1223280u] = new MobUt.Tx8(this.funct0012aa70); - this.dicti2a[1223292u] = new MobUt.Tx8(this.funct0012aa7c); - this.dicti2a[1223348u] = new MobUt.Tx8(this.funct0012aab4); - this.dicti2a[1223380u] = new MobUt.Tx8(this.funct0012aad4); - this.dicti2a[1223560u] = new MobUt.Tx8(this.funct0012ab88); - this.dicti2a[1223580u] = new MobUt.Tx8(this.funct0012ab9c); - this.dicti2a[1223624u] = new MobUt.Tx8(this.funct0012abc8); - this.dicti2a[1223628u] = new MobUt.Tx8(this.funct0012abcc); - this.dicti2a[1223652u] = new MobUt.Tx8(this.funct0012abe4); - this.dicti2a[1223664u] = new MobUt.Tx8(this.funct0012abf0); - this.dicti2a[1223692u] = new MobUt.Tx8(this.funct0012ac0c); - this.dicti2a[1223728u] = new MobUt.Tx8(this.funct0012ac30); - this.dicti2a[1223740u] = new MobUt.Tx8(this.funct0012ac3c); - this.dicti2a[1223768u] = new MobUt.Tx8(this.funct0012ac58); - this.dicti2a[1223784u] = new MobUt.Tx8(this.funct0012ac68); - this.dicti2a[1223796u] = new MobUt.Tx8(this.funct0012ac74); - this.dicti2a[1223824u] = new MobUt.Tx8(this.funct0012ac90); - this.dicti2a[1223840u] = new MobUt.Tx8(this.funct0012aca0); - this.dicti2a[1223848u] = new MobUt.Tx8(this.funct0012aca8); - this.dicti2a[1223864u] = new MobUt.Tx8(this.funct0012acb8); - this.dicti2a[1223892u] = new MobUt.Tx8(this.funct0012acd4); - this.dicti2a[1223896u] = new MobUt.Tx8(this.funct0012acd8); - this.dicti2a[1223904u] = new MobUt.Tx8(this.funct0012ace0); - this.dicti2a[1223964u] = new MobUt.Tx8(this.funct0012ad1c); - this.dicti2a[1223992u] = new MobUt.Tx8(this.funct0012ad38); - this.dicti2a[1224032u] = new MobUt.Tx8(this.funct0012ad60); - this.dicti2a[1224052u] = new MobUt.Tx8(this.funct0012ad74); - this.dicti2a[1224192u] = new MobUt.Tx8(this.funct0012ae00); - this.dicti2a[1224204u] = new MobUt.Tx8(this.funct0012ae0c); - this.dicti2a[1224576u] = new MobUt.Tx8(this.funct0012af80); - this.dicti2a[1224960u] = new MobUt.Tx8(this.funct0012b100); - this.dicti2a[1224968u] = new MobUt.Tx8(this.funct0012b108); - this.dicti2a[1225048u] = new MobUt.Tx8(this.funct0012b158); - this.dicti2a[1225064u] = new MobUt.Tx8(this.funct0012b168); - this.dicti2a[1225072u] = new MobUt.Tx8(this.funct0012b170); - this.dicti2a[1225112u] = new MobUt.Tx8(this.funct0012b198); - this.dicti2a[1225120u] = new MobUt.Tx8(this.funct0012b1a0); - this.dicti2a[1225244u] = new MobUt.Tx8(this.funct0012b21c); - this.dicti2a[1225296u] = new MobUt.Tx8(this.funct0012b250); - this.dicti2a[1225304u] = new MobUt.Tx8(this.funct0012b258); - this.dicti2a[1225320u] = new MobUt.Tx8(this.funct0012b268); - this.dicti2a[1225372u] = new MobUt.Tx8(this.funct0012b29c); - this.dicti2a[1225380u] = new MobUt.Tx8(this.funct0012b2a4); - this.dicti2a[1225448u] = new MobUt.Tx8(this.funct0012b2e8); - this.dicti2a[1225456u] = new MobUt.Tx8(this.funct0012b2f0); - this.dicti2a[1225472u] = new MobUt.Tx8(this.funct0012b300); - this.dicti2a[1225500u] = new MobUt.Tx8(this.funct0012b31c); - this.dicti2a[1225508u] = new MobUt.Tx8(this.funct0012b324); - this.dicti2a[1225528u] = new MobUt.Tx8(this.funct0012b338); - this.dicti2a[1225548u] = new MobUt.Tx8(this.funct0012b34c); - this.dicti2a[1225552u] = new MobUt.Tx8(this.funct0012b350); - this.dicti2a[1225588u] = new MobUt.Tx8(this.funct0012b374); - this.dicti2a[1225596u] = new MobUt.Tx8(this.funct0012b37c); - this.dicti2a[1225724u] = new MobUt.Tx8(this.funct0012b3fc); - this.dicti2a[1225780u] = new MobUt.Tx8(this.funct0012b434); - this.dicti2a[1225788u] = new MobUt.Tx8(this.funct0012b43c); - this.dicti2a[1225812u] = new MobUt.Tx8(this.funct0012b454); - this.dicti2a[1225864u] = new MobUt.Tx8(this.funct0012b488); - this.dicti2a[1225872u] = new MobUt.Tx8(this.funct0012b490); - this.dicti2a[1225948u] = new MobUt.Tx8(this.funct0012b4dc); - this.dicti2a[1225956u] = new MobUt.Tx8(this.funct0012b4e4); - this.dicti2a[1225976u] = new MobUt.Tx8(this.funct0012b4f8); - this.dicti2a[1225984u] = new MobUt.Tx8(this.funct0012b500); - this.dicti2a[1226000u] = new MobUt.Tx8(this.funct0012b510); - this.dicti2a[1226008u] = new MobUt.Tx8(this.funct0012b518); - this.dicti2a[1226092u] = new MobUt.Tx8(this.funct0012b56c); - this.dicti2a[1226100u] = new MobUt.Tx8(this.funct0012b574); - this.dicti2a[1226124u] = new MobUt.Tx8(this.funct0012b58c); - this.dicti2a[1226132u] = new MobUt.Tx8(this.funct0012b594); - this.dicti2a[1226156u] = new MobUt.Tx8(this.funct0012b5ac); - this.dicti2a[1226164u] = new MobUt.Tx8(this.funct0012b5b4); - this.dicti2a[1226216u] = new MobUt.Tx8(this.funct0012b5e8); - this.dicti2a[1226244u] = new MobUt.Tx8(this.funct0012b604); - this.dicti2a[1226256u] = new MobUt.Tx8(this.funct0012b610); - this.dicti2a[1226272u] = new MobUt.Tx8(this.funct0012b620); - this.dicti2a[1226284u] = new MobUt.Tx8(this.funct0012b62c); - this.dicti2a[1226304u] = new MobUt.Tx8(this.funct0012b640); - this.dicti2a[1226316u] = new MobUt.Tx8(this.funct0012b64c); - this.dicti2a[1226328u] = new MobUt.Tx8(this.funct0012b658); - this.dicti2a[1226340u] = new MobUt.Tx8(this.funct0012b664); - this.dicti2a[1226356u] = new MobUt.Tx8(this.funct0012b674); - this.dicti2a[1226380u] = new MobUt.Tx8(this.funct0012b68c); - this.dicti2a[1226392u] = new MobUt.Tx8(this.funct0012b698); - this.dicti2a[1226408u] = new MobUt.Tx8(this.funct0012b6a8); - this.dicti2a[1226424u] = new MobUt.Tx8(this.funct0012b6b8); - this.dicti2a[1226440u] = new MobUt.Tx8(this.funct0012b6c8); - this.dicti2a[1226460u] = new MobUt.Tx8(this.funct0012b6dc); - this.dicti2a[1226664u] = new MobUt.Tx8(this.funct0012b7a8); - this.dicti2a[1226692u] = new MobUt.Tx8(this.funct0012b7c4); - this.dicti2a[1226712u] = new MobUt.Tx8(this.funct0012b7d8); - this.dicti2a[1226724u] = new MobUt.Tx8(this.funct0012b7e4); - this.dicti2a[1226764u] = new MobUt.Tx8(this.funct0012b80c); - this.dicti2a[1226784u] = new MobUt.Tx8(this.funct0012b820); - this.dicti2a[1226796u] = new MobUt.Tx8(this.funct0012b82c); - this.dicti2a[1226824u] = new MobUt.Tx8(this.funct0012b848); - this.dicti2a[1226832u] = new MobUt.Tx8(this.funct0012b850); - this.dicti2a[1226848u] = new MobUt.Tx8(this.funct0012b860); - this.dicti2a[1226856u] = new MobUt.Tx8(this.funct0012b868); - this.dicti2a[1226876u] = new MobUt.Tx8(this.funct0012b87c); - this.dicti2a[1226884u] = new MobUt.Tx8(this.funct0012b884); - this.dicti2a[1226900u] = new MobUt.Tx8(this.funct0012b894); - this.dicti2a[1226908u] = new MobUt.Tx8(this.funct0012b89c); - this.dicti2a[1226948u] = new MobUt.Tx8(this.funct0012b8c4); - this.dicti2a[1226976u] = new MobUt.Tx8(this.funct0012b8e0); - this.dicti2a[1227000u] = new MobUt.Tx8(this.funct0012b8f8); - this.dicti2a[1227012u] = new MobUt.Tx8(this.funct0012b904); - this.dicti2a[1227032u] = new MobUt.Tx8(this.funct0012b918); - this.dicti2a[1227056u] = new MobUt.Tx8(this.funct0012b930); - this.dicti2a[1227132u] = new MobUt.Tx8(this.funct0012b97c); - this.dicti2a[1227148u] = new MobUt.Tx8(this.funct0012b98c); - this.dicti2a[1227160u] = new MobUt.Tx8(this.funct0012b998); - this.dicti2a[1227184u] = new MobUt.Tx8(this.funct0012b9b0); - this.dicti2a[1227192u] = new MobUt.Tx8(this.funct0012b9b8); - this.dicti2a[1227220u] = new MobUt.Tx8(this.funct0012b9d4); - this.dicti2a[1227244u] = new MobUt.Tx8(this.funct0012b9ec); - this.dicti2a[1227272u] = new MobUt.Tx8(this.funct0012ba08); - this.dicti2a[1227284u] = new MobUt.Tx8(this.funct0012ba14); - this.dicti2a[1227292u] = new MobUt.Tx8(this.funct0012ba1c); - this.dicti2a[1227300u] = new MobUt.Tx8(this.funct0012ba24); - this.dicti2a[1227312u] = new MobUt.Tx8(this.funct0012ba30); - this.dicti2a[1227320u] = new MobUt.Tx8(this.funct0012ba38); - this.dicti2a[1227328u] = new MobUt.Tx8(this.funct0012ba40); - this.dicti2a[1227336u] = new MobUt.Tx8(this.funct0012ba48); - this.dicti2a[1227348u] = new MobUt.Tx8(this.funct0012ba54); - this.dicti2a[1227380u] = new MobUt.Tx8(this.funct0012ba74); - this.dicti2a[1227572u] = new MobUt.Tx8(this.funct0012bb34); - this.dicti2a[1227584u] = new MobUt.Tx8(this.funct0012bb40); - this.dicti2a[1227604u] = new MobUt.Tx8(this.funct0012bb54); - this.dicti2a[1227616u] = new MobUt.Tx8(this.funct0012bb60); - this.dicti2a[1227628u] = new MobUt.Tx8(this.funct0012bb6c); - this.dicti2a[1227712u] = new MobUt.Tx8(this.funct0012bbc0); - this.dicti2a[1227724u] = new MobUt.Tx8(this.funct0012bbcc); - this.dicti2a[1227736u] = new MobUt.Tx8(this.funct0012bbd8); - this.dicti2a[1227752u] = new MobUt.Tx8(this.funct0012bbe8); - this.dicti2a[1227760u] = new MobUt.Tx8(this.funct0012bbf0); - this.dicti2a[1227772u] = new MobUt.Tx8(this.funct0012bbfc); - this.dicti2a[1227792u] = new MobUt.Tx8(this.funct0012bc10); - this.dicti2a[1227800u] = new MobUt.Tx8(this.funct0012bc18); - this.dicti2a[1227812u] = new MobUt.Tx8(this.funct0012bc24); - this.dicti2a[1227864u] = new MobUt.Tx8(this.funct0012bc58); - this.dicti2a[1227872u] = new MobUt.Tx8(this.funct0012bc60); - this.dicti2a[1227940u] = new MobUt.Tx8(this.funct0012bca4); - this.dicti2a[1227948u] = new MobUt.Tx8(this.funct0012bcac); - this.dicti2a[1227964u] = new MobUt.Tx8(this.funct0012bcbc); - this.dicti2a[1227984u] = new MobUt.Tx8(this.funct0012bcd0); - this.dicti2a[1228000u] = new MobUt.Tx8(this.funct0012bce0); - this.dicti2a[1228008u] = new MobUt.Tx8(this.funct0012bce8); - this.dicti2a[1228020u] = new MobUt.Tx8(this.funct0012bcf4); - this.dicti2a[1228052u] = new MobUt.Tx8(this.funct0012bd14); - this.dicti2a[1228164u] = new MobUt.Tx8(this.funct0012bd84); - this.dicti2a[1228172u] = new MobUt.Tx8(this.funct0012bd8c); - this.dicti2a[1228304u] = new MobUt.Tx8(this.funct0012be10); - this.dicti2a[1228356u] = new MobUt.Tx8(this.funct0012be44); - this.dicti2a[1228364u] = new MobUt.Tx8(this.funct0012be4c); - this.dicti2a[1228380u] = new MobUt.Tx8(this.funct0012be5c); - this.dicti2a[1228404u] = new MobUt.Tx8(this.funct0012be74); - this.dicti2a[1228424u] = new MobUt.Tx8(this.funct0012be88); - this.dicti2a[1228432u] = new MobUt.Tx8(this.funct0012be90); - this.dicti2a[1228448u] = new MobUt.Tx8(this.funct0012bea0); - this.dicti2a[1228456u] = new MobUt.Tx8(this.funct0012bea8); - this.dicti2a[1228472u] = new MobUt.Tx8(this.funct0012beb8); - this.dicti2a[1228488u] = new MobUt.Tx8(this.funct0012bec8); - this.dicti2a[1228504u] = new MobUt.Tx8(this.funct0012bed8); - this.dicti2a[1228528u] = new MobUt.Tx8(this.funct0012bef0); - this.dicti2a[1228568u] = new MobUt.Tx8(this.funct0012bf18); - this.dicti2a[1228584u] = new MobUt.Tx8(this.funct0012bf28); - this.dicti2a[1228600u] = new MobUt.Tx8(this.funct0012bf38); - this.dicti2a[1228616u] = new MobUt.Tx8(this.funct0012bf48); - this.dicti2a[1228644u] = new MobUt.Tx8(this.funct0012bf64); - this.dicti2a[1228684u] = new MobUt.Tx8(this.funct0012bf8c); - this.dicti2a[1228696u] = new MobUt.Tx8(this.funct0012bf98); - this.dicti2a[1228712u] = new MobUt.Tx8(this.funct0012bfa8); - this.dicti2a[1228752u] = new MobUt.Tx8(this.funct0012bfd0); - this.dicti2a[1228812u] = new MobUt.Tx8(this.funct0012c00c); - this.dicti2a[1228856u] = new MobUt.Tx8(this.funct0012c038); - this.dicti2a[1228908u] = new MobUt.Tx8(this.funct0012c06c); - this.dicti2a[1228916u] = new MobUt.Tx8(this.funct0012c074); - this.dicti2a[1228924u] = new MobUt.Tx8(this.funct0012c07c); - this.dicti2a[1228932u] = new MobUt.Tx8(this.funct0012c084); - this.dicti2a[1228952u] = new MobUt.Tx8(this.funct0012c098); - this.dicti2a[1228960u] = new MobUt.Tx8(this.funct0012c0a0); - this.dicti2a[1228972u] = new MobUt.Tx8(this.funct0012c0ac); - this.dicti2a[1228992u] = new MobUt.Tx8(this.funct0012c0c0); - this.dicti2a[1229000u] = new MobUt.Tx8(this.funct0012c0c8); - this.dicti2a[1229016u] = new MobUt.Tx8(this.funct0012c0d8); - this.dicti2a[1229024u] = new MobUt.Tx8(this.funct0012c0e0); - this.dicti2a[1229152u] = new MobUt.Tx8(this.funct0012c160); - this.dicti2a[1229204u] = new MobUt.Tx8(this.funct0012c194); - this.dicti2a[1229212u] = new MobUt.Tx8(this.funct0012c19c); - this.dicti2a[1229228u] = new MobUt.Tx8(this.funct0012c1ac); - this.dicti2a[1229464u] = new MobUt.Tx8(this.funct0012c298); - this.dicti2a[1229492u] = new MobUt.Tx8(this.funct0012c2b4); - this.dicti2a[1229500u] = new MobUt.Tx8(this.funct0012c2bc); - this.dicti2a[1229620u] = new MobUt.Tx8(this.funct0012c334); - this.dicti2a[1229660u] = new MobUt.Tx8(this.funct0012c35c); - this.dicti2a[1229680u] = new MobUt.Tx8(this.funct0012c370); - this.dicti2a[1229696u] = new MobUt.Tx8(this.funct0012c380); - this.dicti2a[1229712u] = new MobUt.Tx8(this.funct0012c390); - this.dicti2a[1229732u] = new MobUt.Tx8(this.funct0012c3a4); - this.dicti2a[1229756u] = new MobUt.Tx8(this.funct0012c3bc); - this.dicti2a[1229772u] = new MobUt.Tx8(this.funct0012c3cc); - this.dicti2a[1229796u] = new MobUt.Tx8(this.funct0012c3e4); - this.dicti2a[1229816u] = new MobUt.Tx8(this.funct0012c3f8); - this.dicti2a[1229824u] = new MobUt.Tx8(this.funct0012c400); - this.dicti2a[1229832u] = new MobUt.Tx8(this.funct0012c408); - this.dicti2a[1229844u] = new MobUt.Tx8(this.funct0012c414); - this.dicti2a[1229864u] = new MobUt.Tx8(this.funct0012c428); - this.dicti2a[1229872u] = new MobUt.Tx8(this.funct0012c430); - this.dicti2a[1229900u] = new MobUt.Tx8(this.funct0012c44c); - this.dicti2a[1229908u] = new MobUt.Tx8(this.funct0012c454); - this.dicti2a[1229924u] = new MobUt.Tx8(this.funct0012c464); - this.dicti2a[1229928u] = new MobUt.Tx8(this.funct0012c468); - this.dicti2a[1229948u] = new MobUt.Tx8(this.funct0012c47c); - this.dicti2a[1229956u] = new MobUt.Tx8(this.funct0012c484); - this.dicti2a[1229972u] = new MobUt.Tx8(this.funct0012c494); - this.dicti2a[1229980u] = new MobUt.Tx8(this.funct0012c49c); - this.dicti2a[1229988u] = new MobUt.Tx8(this.funct0012c4a4); - this.dicti2a[1230008u] = new MobUt.Tx8(this.funct0012c4b8); - this.dicti2a[1230016u] = new MobUt.Tx8(this.funct0012c4c0); - this.dicti2a[1230032u] = new MobUt.Tx8(this.funct0012c4d0); - this.dicti2a[1230056u] = new MobUt.Tx8(this.funct0012c4e8); - this.dicti2a[1230068u] = new MobUt.Tx8(this.funct0012c4f4); - this.dicti2a[1230092u] = new MobUt.Tx8(this.funct0012c50c); - this.dicti2a[1230100u] = new MobUt.Tx8(this.funct0012c514); - this.dicti2a[1230220u] = new MobUt.Tx8(this.funct0012c58c); - this.dicti2a[1230260u] = new MobUt.Tx8(this.funct0012c5b4); - this.dicti2a[1230280u] = new MobUt.Tx8(this.funct0012c5c8); - this.dicti2a[1230308u] = new MobUt.Tx8(this.funct0012c5e4); - this.dicti2a[1230316u] = new MobUt.Tx8(this.funct0012c5ec); - this.dicti2a[1230436u] = new MobUt.Tx8(this.funct0012c664); - this.dicti2a[1230476u] = new MobUt.Tx8(this.funct0012c68c); - this.dicti2a[1230496u] = new MobUt.Tx8(this.funct0012c6a0); - this.dicti2a[1230516u] = new MobUt.Tx8(this.funct0012c6b4); - this.dicti2a[1230540u] = new MobUt.Tx8(this.funct0012c6cc); - this.dicti2a[1230556u] = new MobUt.Tx8(this.funct0012c6dc); - this.dicti2a[1230580u] = new MobUt.Tx8(this.funct0012c6f4); - this.dicti2a[1230608u] = new MobUt.Tx8(this.funct0012c710); - this.dicti2a[1230624u] = new MobUt.Tx8(this.funct0012c720); - this.dicti2a[1230648u] = new MobUt.Tx8(this.funct0012c738); - this.dicti2a[1230656u] = new MobUt.Tx8(this.funct0012c740); - this.dicti2a[1230668u] = new MobUt.Tx8(this.funct0012c74c); - this.dicti2a[1230700u] = new MobUt.Tx8(this.funct0012c76c); - this.dicti2a[1230736u] = new MobUt.Tx8(this.funct0012c790); - this.dicti2a[1230764u] = new MobUt.Tx8(this.funct0012c7ac); - this.dicti2a[1230852u] = new MobUt.Tx8(this.funct0012c804); - this.dicti2a[1230904u] = new MobUt.Tx8(this.funct0012c838); - this.dicti2a[1230912u] = new MobUt.Tx8(this.funct0012c840); - this.dicti2a[1230920u] = new MobUt.Tx8(this.funct0012c848); - this.dicti2a[1230936u] = new MobUt.Tx8(this.funct0012c858); - this.dicti2a[1230944u] = new MobUt.Tx8(this.funct0012c860); - this.dicti2a[1230976u] = new MobUt.Tx8(this.funct0012c880); - this.dicti2a[1231028u] = new MobUt.Tx8(this.funct0012c8b4); - this.dicti2a[1231044u] = new MobUt.Tx8(this.funct0012c8c4); - this.dicti2a[1231056u] = new MobUt.Tx8(this.funct0012c8d0); - this.dicti2a[1231072u] = new MobUt.Tx8(this.funct0012c8e0); - this.dicti2a[1231080u] = new MobUt.Tx8(this.funct0012c8e8); - this.dicti2a[1231088u] = new MobUt.Tx8(this.funct0012c8f0); - this.dicti2a[1231116u] = new MobUt.Tx8(this.funct0012c90c); - this.dicti2a[1231144u] = new MobUt.Tx8(this.funct0012c928); - this.dicti2a[1231228u] = new MobUt.Tx8(this.funct0012c97c); - this.dicti2a[1231232u] = new MobUt.Tx8(this.funct0012c980); - this.dicti2a[1231244u] = new MobUt.Tx8(this.funct0012c98c); - this.dicti2a[1231296u] = new MobUt.Tx8(this.funct0012c9c0); - this.dicti2a[1231308u] = new MobUt.Tx8(this.funct0012c9cc); - this.dicti2a[1231324u] = new MobUt.Tx8(this.funct0012c9dc); - this.dicti2a[1231344u] = new MobUt.Tx8(this.funct0012c9f0); - this.dicti2a[1231352u] = new MobUt.Tx8(this.funct0012c9f8); - this.dicti2a[1231404u] = new MobUt.Tx8(this.funct0012ca2c); - this.dicti2a[1231420u] = new MobUt.Tx8(this.funct0012ca3c); - this.dicti2a[1231440u] = new MobUt.Tx8(this.funct0012ca50); - this.dicti2a[1231456u] = new MobUt.Tx8(this.funct0012ca60); - this.dicti2a[1231464u] = new MobUt.Tx8(this.funct0012ca68); - this.dicti2a[1231496u] = new MobUt.Tx8(this.funct0012ca88); - this.dicti2a[1231520u] = new MobUt.Tx8(this.funct0012caa0); - this.dicti2a[1231528u] = new MobUt.Tx8(this.funct0012caa8); - this.dicti2a[1231540u] = new MobUt.Tx8(this.funct0012cab4); - this.dicti2a[1231580u] = new MobUt.Tx8(this.funct0012cadc); - this.dicti2a[1231600u] = new MobUt.Tx8(this.funct0012caf0); - this.dicti2a[1231620u] = new MobUt.Tx8(this.funct0012cb04); - this.dicti2a[1231628u] = new MobUt.Tx8(this.funct0012cb0c); - this.dicti2a[1231636u] = new MobUt.Tx8(this.funct0012cb14); - this.dicti2a[1231684u] = new MobUt.Tx8(this.funct0012cb44); - this.dicti2a[1231696u] = new MobUt.Tx8(this.funct0012cb50); - this.dicti2a[1231756u] = new MobUt.Tx8(this.funct0012cb8c); - this.dicti2a[1231788u] = new MobUt.Tx8(this.funct0012cbac); - this.dicti2a[1231968u] = new MobUt.Tx8(this.funct0012cc60); - this.dicti2a[1232004u] = new MobUt.Tx8(this.funct0012cc84); - this.dicti2a[1232016u] = new MobUt.Tx8(this.funct0012cc90); - this.dicti2a[1232028u] = new MobUt.Tx8(this.funct0012cc9c); - this.dicti2a[1232064u] = new MobUt.Tx8(this.funct0012ccc0); - this.dicti2a[1232144u] = new MobUt.Tx8(this.funct0012cd10); - this.dicti2a[1232164u] = new MobUt.Tx8(this.funct0012cd24); - this.dicti2a[1232172u] = new MobUt.Tx8(this.funct0012cd2c); - this.dicti2a[1232200u] = new MobUt.Tx8(this.funct0012cd48); - this.dicti2a[1232208u] = new MobUt.Tx8(this.funct0012cd50); - this.dicti2a[1232224u] = new MobUt.Tx8(this.funct0012cd60); - this.dicti2a[1232232u] = new MobUt.Tx8(this.funct0012cd68); - this.dicti2a[1232260u] = new MobUt.Tx8(this.funct0012cd84); - this.dicti2a[1232268u] = new MobUt.Tx8(this.funct0012cd8c); - this.dicti2a[1232284u] = new MobUt.Tx8(this.funct0012cd9c); - this.dicti2a[1232304u] = new MobUt.Tx8(this.funct0012cdb0); - this.dicti2a[1232328u] = new MobUt.Tx8(this.funct0012cdc8); - this.dicti2a[1232344u] = new MobUt.Tx8(this.funct0012cdd8); - this.dicti2a[1232348u] = new MobUt.Tx8(this.funct0012cddc); - this.dicti2a[1232364u] = new MobUt.Tx8(this.funct0012cdec); - this.dicti2a[1232372u] = new MobUt.Tx8(this.funct0012cdf4); - this.dicti2a[1232412u] = new MobUt.Tx8(this.funct0012ce1c); - this.dicti2a[1232420u] = new MobUt.Tx8(this.funct0012ce24); - this.dicti2a[1232544u] = new MobUt.Tx8(this.funct0012cea0); - this.dicti2a[1232596u] = new MobUt.Tx8(this.funct0012ced4); - this.dicti2a[1232604u] = new MobUt.Tx8(this.funct0012cedc); - this.dicti2a[1232620u] = new MobUt.Tx8(this.funct0012ceec); - this.dicti2a[1232672u] = new MobUt.Tx8(this.funct0012cf20); - this.dicti2a[1232680u] = new MobUt.Tx8(this.funct0012cf28); - this.dicti2a[1232748u] = new MobUt.Tx8(this.funct0012cf6c); - this.dicti2a[1232756u] = new MobUt.Tx8(this.funct0012cf74); - this.dicti2a[1232772u] = new MobUt.Tx8(this.funct0012cf84); - this.dicti2a[1232812u] = new MobUt.Tx8(this.funct0012cfac); - this.dicti2a[1232820u] = new MobUt.Tx8(this.funct0012cfb4); - this.dicti2a[1232840u] = new MobUt.Tx8(this.funct0012cfc8); - this.dicti2a[1232848u] = new MobUt.Tx8(this.funct0012cfd0); - this.dicti2a[1232868u] = new MobUt.Tx8(this.funct0012cfe4); - this.dicti2a[1232876u] = new MobUt.Tx8(this.funct0012cfec); - this.dicti2a[1232928u] = new MobUt.Tx8(this.funct0012d020); - this.dicti2a[1232956u] = new MobUt.Tx8(this.funct0012d03c); - this.dicti2a[1232976u] = new MobUt.Tx8(this.funct0012d050); - this.dicti2a[1232988u] = new MobUt.Tx8(this.funct0012d05c); - this.dicti2a[1233004u] = new MobUt.Tx8(this.funct0012d06c); - this.dicti2a[1233020u] = new MobUt.Tx8(this.funct0012d07c); - this.dicti2a[1233036u] = new MobUt.Tx8(this.funct0012d08c); - this.dicti2a[1233056u] = new MobUt.Tx8(this.funct0012d0a0); - this.dicti2a[1233112u] = new MobUt.Tx8(this.funct0012d0d8); - this.dicti2a[1233136u] = new MobUt.Tx8(this.funct0012d0f0); - this.dicti2a[1233156u] = new MobUt.Tx8(this.funct0012d104); - this.dicti2a[1233184u] = new MobUt.Tx8(this.funct0012d120); - this.dicti2a[1233196u] = new MobUt.Tx8(this.funct0012d12c); - this.dicti2a[1233220u] = new MobUt.Tx8(this.funct0012d144); - this.dicti2a[1233240u] = new MobUt.Tx8(this.funct0012d158); - this.dicti2a[1233248u] = new MobUt.Tx8(this.funct0012d160); - this.dicti2a[1233272u] = new MobUt.Tx8(this.funct0012d178); - this.dicti2a[1233280u] = new MobUt.Tx8(this.funct0012d180); - this.dicti2a[1233296u] = new MobUt.Tx8(this.funct0012d190); - this.dicti2a[1233304u] = new MobUt.Tx8(this.funct0012d198); - this.dicti2a[1233336u] = new MobUt.Tx8(this.funct0012d1b8); - this.dicti2a[1233360u] = new MobUt.Tx8(this.funct0012d1d0); - this.dicti2a[1233380u] = new MobUt.Tx8(this.funct0012d1e4); - this.dicti2a[1233408u] = new MobUt.Tx8(this.funct0012d200); - this.dicti2a[1233432u] = new MobUt.Tx8(this.funct0012d218); - this.dicti2a[1233460u] = new MobUt.Tx8(this.funct0012d234); - this.dicti2a[1233484u] = new MobUt.Tx8(this.funct0012d24c); - this.dicti2a[1233508u] = new MobUt.Tx8(this.funct0012d264); - this.dicti2a[1233608u] = new MobUt.Tx8(this.funct0012d2c8); - this.dicti2a[1233616u] = new MobUt.Tx8(this.funct0012d2d0); - this.dicti2a[1233644u] = new MobUt.Tx8(this.funct0012d2ec); - this.dicti2a[1233652u] = new MobUt.Tx8(this.funct0012d2f4); - this.dicti2a[1233680u] = new MobUt.Tx8(this.funct0012d310); - this.dicti2a[1233696u] = new MobUt.Tx8(this.funct0012d320); - this.dicti2a[1233724u] = new MobUt.Tx8(this.funct0012d33c); - this.dicti2a[1233748u] = new MobUt.Tx8(this.funct0012d354); - this.dicti2a[1233756u] = new MobUt.Tx8(this.funct0012d35c); - this.dicti2a[1233764u] = new MobUt.Tx8(this.funct0012d364); - this.dicti2a[1233780u] = new MobUt.Tx8(this.funct0012d374); - this.dicti2a[1233808u] = new MobUt.Tx8(this.funct0012d390); - this.dicti2a[1233820u] = new MobUt.Tx8(this.funct0012d39c); - this.dicti2a[1233844u] = new MobUt.Tx8(this.funct0012d3b4); - this.dicti2a[1233864u] = new MobUt.Tx8(this.funct0012d3c8); - this.dicti2a[1233888u] = new MobUt.Tx8(this.funct0012d3e0); - this.dicti2a[1233896u] = new MobUt.Tx8(this.funct0012d3e8); - this.dicti2a[1233936u] = new MobUt.Tx8(this.funct0012d410); - this.dicti2a[1233976u] = new MobUt.Tx8(this.funct0012d438); - this.dicti2a[1234000u] = new MobUt.Tx8(this.funct0012d450); - this.dicti2a[1234020u] = new MobUt.Tx8(this.funct0012d464); - this.dicti2a[1234028u] = new MobUt.Tx8(this.funct0012d46c); - this.dicti2a[1234068u] = new MobUt.Tx8(this.funct0012d494); - this.dicti2a[1234092u] = new MobUt.Tx8(this.funct0012d4ac); - this.dicti2a[1234112u] = new MobUt.Tx8(this.funct0012d4c0); - this.dicti2a[1234120u] = new MobUt.Tx8(this.funct0012d4c8); - this.dicti2a[1234132u] = new MobUt.Tx8(this.funct0012d4d4); - this.dicti2a[1234156u] = new MobUt.Tx8(this.funct0012d4ec); - this.dicti2a[1234164u] = new MobUt.Tx8(this.funct0012d4f4); - this.dicti2a[1317840u] = new MobUt.Tx8(this.funct00141bd0); - this.dicti2a[1317856u] = new MobUt.Tx8(this.funct00141be0); - this.dicti2a[1317864u] = new MobUt.Tx8(this.funct00141be8); - this.dicti2a[1317940u] = new MobUt.Tx8(this.funct00141c34); - this.dicti2a[1318520u] = new MobUt.Tx8(this.funct00141e78); - this.dicti2a[1318552u] = new MobUt.Tx8(this.funct00141e98); - this.dicti2a[1318636u] = new MobUt.Tx8(this.funct00141eec); - this.dicti2a[1318644u] = new MobUt.Tx8(this.funct00141ef4); - this.dicti2a[1318664u] = new MobUt.Tx8(this.funct00141f08); - this.dicti2a[1318668u] = new MobUt.Tx8(this.funct00141f0c); - this.dicti2a[1318688u] = new MobUt.Tx8(this.funct00141f20); - this.dicti2a[1318700u] = new MobUt.Tx8(this.funct00141f2c); - this.dicti2a[1318708u] = new MobUt.Tx8(this.funct00141f34); - this.dicti2a[1318728u] = new MobUt.Tx8(this.funct00141f48); - this.dicti2a[1318732u] = new MobUt.Tx8(this.funct00141f4c); - this.dicti2a[1318792u] = new MobUt.Tx8(this.funct00141f88); - this.dicti2a[1318804u] = new MobUt.Tx8(this.funct00141f94); - this.dicti2a[1318836u] = new MobUt.Tx8(this.funct00141fb4); - this.dicti2a[1318848u] = new MobUt.Tx8(this.funct00141fc0); - this.dicti2a[1318860u] = new MobUt.Tx8(this.funct00141fcc); - this.dicti2a[1318868u] = new MobUt.Tx8(this.funct00141fd4); - this.dicti2a[1318884u] = new MobUt.Tx8(this.funct00141fe4); - this.dicti2a[1318904u] = new MobUt.Tx8(this.funct00141ff8); - this.dicti2a[1318912u] = new MobUt.Tx8(this.funct00142000); - this.dicti2a[1318928u] = new MobUt.Tx8(this.funct00142010); - this.dicti2a[1318956u] = new MobUt.Tx8(this.funct0014202c); - this.dicti2a[1318972u] = new MobUt.Tx8(this.funct0014203c); - this.dicti2a[1318976u] = new MobUt.Tx8(this.funct00142040); - this.dicti2a[1318988u] = new MobUt.Tx8(this.funct0014204c); - this.dicti2a[1319004u] = new MobUt.Tx8(this.funct0014205c); - this.dicti2a[1319016u] = new MobUt.Tx8(this.funct00142068); - this.dicti2a[1319040u] = new MobUt.Tx8(this.funct00142080); - this.dicti2a[1319052u] = new MobUt.Tx8(this.funct0014208c); - this.dicti2a[1319056u] = new MobUt.Tx8(this.funct00142090); - this.dicti2a[1319100u] = new MobUt.Tx8(this.funct001420bc); - this.dicti2a[1319128u] = new MobUt.Tx8(this.funct001420d8); - this.dicti2a[1319220u] = new MobUt.Tx8(this.funct00142134); - this.dicti2a[1319232u] = new MobUt.Tx8(this.funct00142140); - this.dicti2a[1319272u] = new MobUt.Tx8(this.funct00142168); - this.dicti2a[1319316u] = new MobUt.Tx8(this.funct00142194); - this.dicti2a[1319432u] = new MobUt.Tx8(this.funct00142208); - this.dicti2a[1319448u] = new MobUt.Tx8(this.funct00142218); - this.dicti2a[1319504u] = new MobUt.Tx8(this.funct00142250); - this.dicti2a[1319712u] = new MobUt.Tx8(this.funct00142320); - this.dicti2a[1319724u] = new MobUt.Tx8(this.funct0014232c); - this.dicti2a[1319760u] = new MobUt.Tx8(this.funct00142350); - this.dicti2a[1319804u] = new MobUt.Tx8(this.funct0014237c); - this.dicti2a[1319812u] = new MobUt.Tx8(this.funct00142384); - this.dicti2a[1319820u] = new MobUt.Tx8(this.funct0014238c); - this.dicti2a[1319836u] = new MobUt.Tx8(this.funct0014239c); - this.dicti2a[1319852u] = new MobUt.Tx8(this.funct001423ac); - this.dicti2a[1319876u] = new MobUt.Tx8(this.funct001423c4); - this.dicti2a[1319896u] = new MobUt.Tx8(this.funct001423d8); - this.dicti2a[1319992u] = new MobUt.Tx8(this.funct00142438); - this.dicti2a[1326792u] = new MobUt.Tx8(this.funct00143ec8); - this.dicti2a[1326864u] = new MobUt.Tx8(this.funct00143f10); - this.dicti2a[1326892u] = new MobUt.Tx8(this.funct00143f2c); - this.dicti2a[1326916u] = new MobUt.Tx8(this.funct00143f44); - this.dicti2a[1329272u] = new MobUt.Tx8(this.funct00144878); - this.dicti2a[1329728u] = new MobUt.Tx8(this.funct00144a40); - this.dicti2a[1329756u] = new MobUt.Tx8(this.funct00144a5c); - this.dicti2a[1329780u] = new MobUt.Tx8(this.funct00144a74); - this.dicti2a[1329820u] = new MobUt.Tx8(this.funct00144a9c); - this.dicti2a[1329828u] = new MobUt.Tx8(this.funct00144aa4); - this.dicti2a[1329844u] = new MobUt.Tx8(this.funct00144ab4); - this.dicti2a[1331344u] = new MobUt.Tx8(this.funct00145090); - this.dicti2a[1331376u] = new MobUt.Tx8(this.funct001450b0); - this.dicti2a[1331428u] = new MobUt.Tx8(this.funct001450e4); - this.dicti2a[1331508u] = new MobUt.Tx8(this.funct00145134); - this.dicti2a[1331532u] = new MobUt.Tx8(this.funct0014514c); - this.dicti2a[1331612u] = new MobUt.Tx8(this.funct0014519c); - this.dicti2a[1331636u] = new MobUt.Tx8(this.funct001451b4); - this.dicti2a[1331716u] = new MobUt.Tx8(this.funct00145204); - this.dicti2a[1331740u] = new MobUt.Tx8(this.funct0014521c); - this.dicti2a[1331820u] = new MobUt.Tx8(this.funct0014526c); - this.dicti2a[1331844u] = new MobUt.Tx8(this.funct00145284); - this.dicti2a[1331924u] = new MobUt.Tx8(this.funct001452d4); - this.dicti2a[1331948u] = new MobUt.Tx8(this.funct001452ec); - this.dicti2a[1332028u] = new MobUt.Tx8(this.funct0014533c); - this.dicti2a[1333216u] = new MobUt.Tx8(this.funct001457e0); - this.dicti2a[1333236u] = new MobUt.Tx8(this.funct001457f4); - this.dicti2a[1333256u] = new MobUt.Tx8(this.funct00145808); - this.dicti2a[1333276u] = new MobUt.Tx8(this.funct0014581c); - this.dicti2a[1333296u] = new MobUt.Tx8(this.funct00145830); - this.dicti2a[1333316u] = new MobUt.Tx8(this.funct00145844); - this.dicti2a[1333332u] = new MobUt.Tx8(this.funct00145854); - this.dicti2a[1450744u] = new MobUt.Tx8(this.funct001622f8); - this.dicti2a[1450792u] = new MobUt.Tx8(this.funct00162328); - this.dicti2a[1450800u] = new MobUt.Tx8(this.funct00162330); - this.dicti2a[1450904u] = new MobUt.Tx8(this.funct00162398); - this.dicti2a[1450940u] = new MobUt.Tx8(this.funct001623bc); - this.dicti2a[1450980u] = new MobUt.Tx8(this.funct001623e4); - this.dicti2a[1451032u] = new MobUt.Tx8(this.funct00162418); - this.dicti2a[1451036u] = new MobUt.Tx8(this.funct0016241c); - this.dicti2a[1451044u] = new MobUt.Tx8(this.funct00162424); - this.dicti2a[1451052u] = new MobUt.Tx8(this.funct0016242c); - this.dicti2a[1451116u] = new MobUt.Tx8(this.funct0016246c); - this.dicti2a[1451632u] = new MobUt.Tx8(this.funct00162670); - this.dicti2a[1451696u] = new MobUt.Tx8(this.funct001626b0); - this.dicti2a[1451796u] = new MobUt.Tx8(this.funct00162714); - this.dicti2a[1451808u] = new MobUt.Tx8(this.funct00162720); - this.dicti2a[1451836u] = new MobUt.Tx8(this.funct0016273c); - this.dicti2a[1451868u] = new MobUt.Tx8(this.funct0016275c); - this.dicti2a[1451888u] = new MobUt.Tx8(this.funct00162770); - this.dicti2a[1451896u] = new MobUt.Tx8(this.funct00162778); - this.dicti2a[1465000u] = new MobUt.Tx8(this.funct00165aa8); - this.dicti2a[1465116u] = new MobUt.Tx8(this.funct00165b1c); - this.dicti2a[1465124u] = new MobUt.Tx8(this.funct00165b24); - this.dicti2a[1465312u] = new MobUt.Tx8(this.funct00165be0); - this.dicti2a[1465332u] = new MobUt.Tx8(this.funct00165bf4); - this.dicti2a[1465356u] = new MobUt.Tx8(this.funct00165c0c); - this.dicti2a[3123512u] = new MobUt.Tx8(this.funct002fa938); - this.dicti2a[3123608u] = new MobUt.Tx8(this.funct002fa998); - this.dicti2a[3123616u] = new MobUt.Tx8(this.funct002fa9a0); - this.dicti2a[3123620u] = new MobUt.Tx8(this.funct002fa9a4); - this.dicti2a[3123632u] = new MobUt.Tx8(this.funct002fa9b0); - this.dicti2a[3123660u] = new MobUt.Tx8(this.funct002fa9cc); - this.dicti2a[3123672u] = new MobUt.Tx8(this.funct002fa9d8); - this.dicti2a[3123680u] = new MobUt.Tx8(this.funct002fa9e0); - this.dicti2a[3123700u] = new MobUt.Tx8(this.funct002fa9f4); - this.dicti2a[3123748u] = new MobUt.Tx8(this.funct002faa24); - this.dicti2a[3123788u] = new MobUt.Tx8(this.funct002faa4c); - this.dicti2a[3123800u] = new MobUt.Tx8(this.funct002faa58); - this.dicti2a[3123828u] = new MobUt.Tx8(this.funct002faa74); - this.dicti2a[3123840u] = new MobUt.Tx8(this.funct002faa80); - this.dicti2a[3123848u] = new MobUt.Tx8(this.funct002faa88); - this.dicti2a[3123868u] = new MobUt.Tx8(this.funct002faa9c); - this.dicti2a[3123920u] = new MobUt.Tx8(this.funct002faad0); - this.dicti2a[3123960u] = new MobUt.Tx8(this.funct002faaf8); - this.dicti2a[3123968u] = new MobUt.Tx8(this.funct002fab00); - this.dicti2a[3123996u] = new MobUt.Tx8(this.funct002fab1c); - this.dicti2a[3124008u] = new MobUt.Tx8(this.funct002fab28); - this.dicti2a[3124016u] = new MobUt.Tx8(this.funct002fab30); - this.dicti2a[3124036u] = new MobUt.Tx8(this.funct002fab44); - this.dicti2a[3124088u] = new MobUt.Tx8(this.funct002fab78); - this.dicti2a[3124128u] = new MobUt.Tx8(this.funct002faba0); - this.dicti2a[3142160u] = new MobUt.Tx8(this.funct002ff210); - this.dicti2a[3142240u] = new MobUt.Tx8(this.funct002ff260); - this.dicti2a[3142264u] = new MobUt.Tx8(this.funct002ff278); - this.dicti2a[3142284u] = new MobUt.Tx8(this.funct002ff28c); - this.dicti2a[3142300u] = new MobUt.Tx8(this.funct002ff29c); - this.dicti2a[3142344u] = new MobUt.Tx8(this.funct002ff2c8); - this.dicti2a[3142348u] = new MobUt.Tx8(this.funct002ff2cc); - this.dicti2a[3142568u] = new MobUt.Tx8(this.funct002ff3a8); - this.dicti2a[3142584u] = new MobUt.Tx8(this.funct002ff3b8); - this.dicti2a[3142648u] = new MobUt.Tx8(this.funct002ff3f8); - this.dicti2a[3142656u] = new MobUt.Tx8(this.funct002ff400); - this.dicti2a[3142664u] = new MobUt.Tx8(this.funct002ff408); - this.dicti2a[3142684u] = new MobUt.Tx8(this.funct002ff41c); - this.dicti2a[3142704u] = new MobUt.Tx8(this.funct002ff430); - this.dicti2a[3142744u] = new MobUt.Tx8(this.funct002ff458); - this.dicti2a[3142764u] = new MobUt.Tx8(this.funct002ff46c); - this.dicti2a[3142788u] = new MobUt.Tx8(this.funct002ff484); - this.dicti2a[3142808u] = new MobUt.Tx8(this.funct002ff498); - this.dicti2a[3142852u] = new MobUt.Tx8(this.funct002ff4c4); - this.dicti2a[3143264u] = new MobUt.Tx8(this.funct002ff660); - this.dicti2a[3143848u] = new MobUt.Tx8(this.funct002ff8a8); - this.dicti2a[3143872u] = new MobUt.Tx8(this.funct002ff8c0); - this.dicti2a[3143896u] = new MobUt.Tx8(this.funct002ff8d8); - this.dicti2a[3145816u] = new MobUt.Tx8(this.funct00300058); - this.dicti2a[3145872u] = new MobUt.Tx8(this.funct00300090); - this.dicti2a[3145904u] = new MobUt.Tx8(this.funct003000b0); - this.dicti2a[3145908u] = new MobUt.Tx8(this.funct003000b4); - this.dicti2a[3145940u] = new MobUt.Tx8(this.funct003000d4); - this.dicti2a[3145948u] = new MobUt.Tx8(this.funct003000dc); - this.dicti2a[3145972u] = new MobUt.Tx8(this.funct003000f4); - this.dicti2a[3145988u] = new MobUt.Tx8(this.funct00300104); - this.dicti2a[3146004u] = new MobUt.Tx8(this.funct00300114); - this.dicti2a[3146044u] = new MobUt.Tx8(this.funct0030013c); - this.dicti2a[3146052u] = new MobUt.Tx8(this.funct00300144); - this.dicti2a[3146288u] = new MobUt.Tx8(this.funct00300230); - this.dicti2a[3146308u] = new MobUt.Tx8(this.funct00300244); - this.dicti2a[3146368u] = new MobUt.Tx8(this.funct00300280); - this.dicti2a[3146376u] = new MobUt.Tx8(this.funct00300288); - this.dicti2a[3146384u] = new MobUt.Tx8(this.funct00300290); - this.dicti2a[3146504u] = new MobUt.Tx8(this.funct00300308); - this.dicti2a[3146736u] = new MobUt.Tx8(this.funct003003f0); - this.dicti2a[3146784u] = new MobUt.Tx8(this.funct00300420); - this.dicti2a[3146800u] = new MobUt.Tx8(this.funct00300430); - this.dicti2a[3146832u] = new MobUt.Tx8(this.funct00300450); - this.dicti2a[3146848u] = new MobUt.Tx8(this.funct00300460); - this.dicti2a[3146860u] = new MobUt.Tx8(this.funct0030046c); - this.dicti2a[3146868u] = new MobUt.Tx8(this.funct00300474); - this.dicti2a[3146872u] = new MobUt.Tx8(this.funct00300478); - this.dicti2a[3146876u] = new MobUt.Tx8(this.funct0030047c); - this.dicti2a[3146880u] = new MobUt.Tx8(this.funct00300480); - this.dicti2a[3146896u] = new MobUt.Tx8(this.funct00300490); - this.dicti2a[3146916u] = new MobUt.Tx8(this.funct003004a4); - this.dicti2a[3146952u] = new MobUt.Tx8(this.funct003004c8); - this.dicti2a[3146972u] = new MobUt.Tx8(this.funct003004dc); - this.dicti2a[3147000u] = new MobUt.Tx8(this.funct003004f8); - this.dicti2a[3147008u] = new MobUt.Tx8(this.funct00300500); - this.dicti2a[3147016u] = new MobUt.Tx8(this.funct00300508); - this.dicti2a[3147036u] = new MobUt.Tx8(this.funct0030051c); - this.dicti2a[3147044u] = new MobUt.Tx8(this.funct00300524); - this.dicti2a[3147060u] = new MobUt.Tx8(this.funct00300534); - this.dicti2a[3147068u] = new MobUt.Tx8(this.funct0030053c); - this.dicti2a[3147080u] = new MobUt.Tx8(this.funct00300548); - this.dicti2a[3147112u] = new MobUt.Tx8(this.funct00300568); - this.dicti2a[3147120u] = new MobUt.Tx8(this.funct00300570); - this.dicti2a[3147156u] = new MobUt.Tx8(this.funct00300594); - this.dicti2a[3147192u] = new MobUt.Tx8(this.funct003005b8); - this.dicti2a[3147236u] = new MobUt.Tx8(this.funct003005e4); - this.dicti2a[3147244u] = new MobUt.Tx8(this.funct003005ec); - this.dicti2a[3147252u] = new MobUt.Tx8(this.funct003005f4); - this.dicti2a[3147272u] = new MobUt.Tx8(this.funct00300608); - this.dicti2a[3147292u] = new MobUt.Tx8(this.funct0030061c); - this.dicti2a[3147308u] = new MobUt.Tx8(this.funct0030062c); - this.dicti2a[3147360u] = new MobUt.Tx8(this.funct00300660); - this.dicti2a[3147364u] = new MobUt.Tx8(this.funct00300664); - this.dicti2a[3147472u] = new MobUt.Tx8(this.funct003006d0); - this.dicti2a[3147524u] = new MobUt.Tx8(this.funct00300704); - this.dicti2a[3147532u] = new MobUt.Tx8(this.funct0030070c); - this.dicti2a[3147600u] = new MobUt.Tx8(this.funct00300750); - this.dicti2a[3147612u] = new MobUt.Tx8(this.funct0030075c); - this.dicti2a[3147652u] = new MobUt.Tx8(this.funct00300784); - this.dicti2a[3147744u] = new MobUt.Tx8(this.funct003007e0); - this.dicti2a[3151872u] = new MobUt.Tx8(this.funct00301800); - this.dicti2a[3151908u] = new MobUt.Tx8(this.funct00301824); - this.dicti2a[3151936u] = new MobUt.Tx8(this.funct00301840); - this.dicti2a[3151944u] = new MobUt.Tx8(this.funct00301848); - this.dicti2a[3151988u] = new MobUt.Tx8(this.funct00301874); - this.dicti2a[3152004u] = new MobUt.Tx8(this.funct00301884); - this.dicti2a[3152020u] = new MobUt.Tx8(this.funct00301894); - this.dicti2a[3152028u] = new MobUt.Tx8(this.funct0030189c); - this.dicti2a[3152036u] = new MobUt.Tx8(this.funct003018a4); - this.dicti2a[3152060u] = new MobUt.Tx8(this.funct003018bc); - this.dicti2a[3152072u] = new MobUt.Tx8(this.funct003018c8); - this.dicti2a[3332304u] = new MobUt.Tx8(this.funct0032d8d0); - this.dicti2a[3332316u] = new MobUt.Tx8(this.funct0032d8dc); - this.dicti2a[3332452u] = new MobUt.Tx8(this.funct0032d964); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset.EmuRunner +{ + public partial class Mobrc1 + { + + private CustEE ee = new CustEE(); + + private SortedDictionary dicti2a = new SortedDictionary(); + + public virtual void funct0011b420() + { + this.ee.pc = 1160272u; + // @0011B420 LUI t7, $0035 + this.ee.t7.SD0 = 3473408; + // @0011B424 ADDIU t7, t7, $4260 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16992))); + // @0011B428 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0011B42C LQ t1, $0010(t7) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); + // @0011B430 LQ t2, $0020(t7) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); + // @0011B434 LQ t3, $0030(t7) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); + // @0011B438 SQ t0, $0000(a0) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a0.UL[0])); + // @0011B43C SQ t1, $0010(a0) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a0.UL[0])); + // @0011B440 SQ t2, $0020(a0) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a0.UL[0])); + // @0011B444 SQ t3, $0030(a0) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.a0.UL[0])); + // @0011B448 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0011B44C NOP + MobUt.Latency(); + } + + public virtual void funct0011b450() + { + this.ee.pc = 1160300u; + // @0011B450 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @0011B454 ADDIU sp, sp, $fff0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); + // @0011B458 SD s0, $0000(sp) + MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @0011B45C C.EQ.S $f12, $f0 + this.ee.fcr31_23 = (this.ee.fpr[12].f == this.ee.fpr[0].f); + // @0011B460 SD ra, $0008(sp) + MobUt.SD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); + // @0011B464 BC1T $0011b484 + if (this.ee.fcr31_23) + { + this.ee.pc = 1160324u; + } + // @0011B468 DADDU s0, a0, zero + this.ee.s0.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0011b46c() + { + this.ee.pc = 1160308u; + // @0011B46C JAL $0011bdc8 + this.ee.ra.UL0 = 1160308u; + this.ee.pc = 1162696u; + // @0011B470 NOP + MobUt.Latency(); + } + + public virtual void funct0011b474() + { + this.ee.pc = 1160324u; + // @0011B474 MOV.S $f12, $f0 + this.ee.fpr[12].f = this.ee.fpr[0].f; + // @0011B478 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0011B47C JAL $002faa58 + this.ee.ra.UL0 = 1160324u; + this.ee.pc = 3123800u; + // @0011B480 DADDU a1, s0, zero + this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0011b484() + { + this.ee.pc = 1160344u; + // @0011B484 DADDU v0, s0, zero + this.ee.v0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0011B488 LD ra, $0008(sp) + MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); + // @0011B48C LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @0011B490 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0011B494 ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct0011b528() + { + this.ee.pc = 1160536u; + // @0011B528 ADDIU sp, sp, $ffe0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); + // @0011B52C SD s0, $0000(sp) + MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @0011B530 SD s1, $0008(sp) + MobUt.SD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); + // @0011B534 SWC1 $f20, $0018(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); + // @0011B538 DADDU s0, a0, zero + this.ee.s0.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); + // @0011B53C SD ra, $0010(sp) + MobUt.SD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + // @0011B540 DADDU s1, a1, zero + this.ee.s1.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + // @0011B544 MTC1 zero, $f20 + this.ee.fpr[20].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @0011B548 LWC1 $f0, $0000(a1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.a1.UL0)); + // @0011B54C C.EQ.S $f0, $f20 + this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[20].f); + // @0011B550 BC1T $0011b570 + if (this.ee.fcr31_23) + { + this.ee.pc = 1160560u; + } + // @0011B554 MOV.S $f12, $f0 + this.ee.fpr[12].f = this.ee.fpr[0].f; + } + + public virtual void funct0011b558() + { + this.ee.pc = 1160544u; + // @0011B558 JAL $0011bdc8 + this.ee.ra.UL0 = 1160544u; + this.ee.pc = 1162696u; + // @0011B55C NOP + MobUt.Latency(); + } + + public virtual void funct0011b560() + { + this.ee.pc = 1160560u; + // @0011B560 MOV.S $f12, $f0 + this.ee.fpr[12].f = this.ee.fpr[0].f; + // @0011B564 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0011B568 JAL $002faa58 + this.ee.ra.UL0 = 1160560u; + this.ee.pc = 3123800u; + // @0011B56C DADDU a1, s0, zero + this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0011b570() + { + this.ee.pc = 1160576u; + // @0011B570 LWC1 $f0, $0004(s1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.s1.UL0)); + // @0011B574 C.EQ.S $f0, $f20 + this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[20].f); + // @0011B578 BC1T $0011b598 + if (this.ee.fcr31_23) + { + this.ee.pc = 1160600u; + } + // @0011B57C MOV.S $f12, $f0 + this.ee.fpr[12].f = this.ee.fpr[0].f; + } + + public virtual void funct0011b580() + { + this.ee.pc = 1160584u; + // @0011B580 JAL $0011bdc8 + this.ee.ra.UL0 = 1160584u; + this.ee.pc = 1162696u; + // @0011B584 NOP + MobUt.Latency(); + } + + public virtual void funct0011b588() + { + this.ee.pc = 1160600u; + // @0011B588 MOV.S $f12, $f0 + this.ee.fpr[12].f = this.ee.fpr[0].f; + // @0011B58C DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0011B590 JAL $002fab00 + this.ee.ra.UL0 = 1160600u; + this.ee.pc = 3123968u; + // @0011B594 DADDU a1, s0, zero + this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0011b598() + { + this.ee.pc = 1160616u; + // @0011B598 LWC1 $f0, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.s1.UL0)); + // @0011B59C C.EQ.S $f0, $f20 + this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[20].f); + // @0011B5A0 BC1T $0011b5c0 + if (this.ee.fcr31_23) + { + this.ee.pc = 1160640u; + } + // @0011B5A4 MOV.S $f12, $f0 + this.ee.fpr[12].f = this.ee.fpr[0].f; + } + + public virtual void funct0011b5a8() + { + this.ee.pc = 1160624u; + // @0011B5A8 JAL $0011bdc8 + this.ee.ra.UL0 = 1160624u; + this.ee.pc = 1162696u; + // @0011B5AC NOP + MobUt.Latency(); + } + + public virtual void funct0011b5b0() + { + this.ee.pc = 1160640u; + // @0011B5B0 MOV.S $f12, $f0 + this.ee.fpr[12].f = this.ee.fpr[0].f; + // @0011B5B4 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0011B5B8 JAL $002fa9b0 + this.ee.ra.UL0 = 1160640u; + this.ee.pc = 3123632u; + // @0011B5BC DADDU a1, s0, zero + this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0011b5c0() + { + this.ee.pc = 1160668u; + // @0011B5C0 DADDU v0, s0, zero + this.ee.v0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0011B5C4 LD s1, $0008(sp) + MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); + // @0011B5C8 LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @0011B5CC LD ra, $0010(sp) + MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + // @0011B5D0 LWC1 $f20, $0018(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); + // @0011B5D4 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0011B5D8 ADDIU sp, sp, $0020 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); + } + + public virtual void funct0011b840() + { + this.ee.pc = 1161332u; + // @0011B840 ADDIU sp, sp, $ffb0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -80))); + // @0011B844 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @0011B848 SD s0, $0030(sp) + MobUt.SD(this.ee, this.ee.s0, (48u + this.ee.sp.UL0)); + // @0011B84C ADDIU t7, t7, $8104 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32508))); + // @0011B850 SD s1, $0038(sp) + MobUt.SD(this.ee, this.ee.s1, (56u + this.ee.sp.UL0)); + // @0011B854 SD ra, $0040(sp) + MobUt.SD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); + // @0011B858 DADDU s0, a0, zero + this.ee.s0.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); + // @0011B85C SWC1 $f20, $0048(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (72u + this.ee.sp.UL0)); + // @0011B860 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @0011B864 LWC1 $f20, $0008(a0) + MobUt.LWC1(this.ee, this.ee.fpr[20], (8u + this.ee.a0.UL0)); + // @0011B868 C.LT.S $f20, $f0 + this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[0].f); + // @0011B86C BC1T $0011b88c + if (this.ee.fcr31_23) + { + this.ee.pc = 1161356u; + } + // @0011B870 DADDU s1, a1, zero + this.ee.s1.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0011b874() + { + this.ee.pc = 1161356u; + // @0011B874 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @0011B878 ADDIU t7, t7, $8108 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32504))); + // @0011B87C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @0011B880 C.LT.S $f0, $f20 + this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[20].f); + // @0011B884 BC1FL $0011b894 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1161364u; + // @0011B888 LWC1 $f13, $0000(s0) + MobUt.LWC1(this.ee, this.ee.fpr[13], (0u + this.ee.s0.UL0)); + } + } + + public virtual void funct0011b88c() + { + this.ee.pc = 1161412u; + // @0011B88C MOV.S $f20, $f0 + this.ee.fpr[20].f = this.ee.fpr[0].f; + // @0011B890 LWC1 $f13, $0000(s0) + MobUt.LWC1(this.ee, this.ee.fpr[13], (0u + this.ee.s0.UL0)); + // @0011B894 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @0011B898 LWC1 $f12, $0004(s0) + MobUt.LWC1(this.ee, this.ee.fpr[12], (4u + this.ee.s0.UL0)); + // @0011B89C ADDIU t7, t7, $810c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32500))); + // @0011B8A0 MULA.S $f13, $f13 + this.ee.fpracc.f = (this.ee.fpr[13].f * this.ee.fpr[13].f); + // @0011B8A4 MADD.S $f0, $f12, $f12 + this.ee.fpr[0].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[12].f, this.ee.fpr[12].f); + // @0011B8A8 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @0011B8AC NOP + MobUt.Latency(); + // @0011B8B0 NOP + MobUt.Latency(); + // @0011B8B4 SQRT.S $f0, $f0 + this.ee.fpr[0].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[0].f)))); + // @0011B8B8 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @0011B8BC BC1F $0011ba50 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1161808u; + } + // @0011B8C0 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + } + + public virtual void funct0011b894() + { + this.ee.pc = 1161412u; + // @0011B894 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @0011B898 LWC1 $f12, $0004(s0) + MobUt.LWC1(this.ee, this.ee.fpr[12], (4u + this.ee.s0.UL0)); + // @0011B89C ADDIU t7, t7, $810c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32500))); + // @0011B8A0 MULA.S $f13, $f13 + this.ee.fpracc.f = (this.ee.fpr[13].f * this.ee.fpr[13].f); + // @0011B8A4 MADD.S $f0, $f12, $f12 + this.ee.fpr[0].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[12].f, this.ee.fpr[12].f); + // @0011B8A8 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @0011B8AC NOP + MobUt.Latency(); + // @0011B8B0 NOP + MobUt.Latency(); + // @0011B8B4 SQRT.S $f0, $f0 + this.ee.fpr[0].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[0].f)))); + // @0011B8B8 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @0011B8BC BC1F $0011ba50 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1161808u; + } + // @0011B8C0 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + } + + public virtual void funct0011b8c4() + { + this.ee.pc = 1161420u; + // @0011B8C4 JAL $002ff8c0 + this.ee.ra.UL0 = 1161420u; + this.ee.pc = 3143872u; + // @0011B8C8 NOP + MobUt.Latency(); + } + + public virtual void funct0011b8cc() + { + this.ee.pc = 1161432u; + // @0011B8CC NEG.S $f12, $f20 + this.ee.fpr[12].f = (0 - this.ee.fpr[20].f); + // @0011B8D0 JAL $002ff8a8 + this.ee.ra.UL0 = 1161432u; + this.ee.pc = 3143848u; + // @0011B8D4 SWC1 $f0, $0028(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (40u + this.ee.sp.UL0)); + } + + public virtual void funct0011b8d8() + { + this.ee.pc = 1161448u; + // @0011B8D8 SWC1 $f0, $0024(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (36u + this.ee.sp.UL0)); + // @0011B8DC LWC1 $f13, $0028(s0) + MobUt.LWC1(this.ee, this.ee.fpr[13], (40u + this.ee.s0.UL0)); + // @0011B8E0 JAL $002ff8c0 + this.ee.ra.UL0 = 1161448u; + this.ee.pc = 3143872u; + // @0011B8E4 LWC1 $f12, $0018(s0) + MobUt.LWC1(this.ee, this.ee.fpr[12], (24u + this.ee.s0.UL0)); + } + + public virtual void funct0011b8e8() + { + this.ee.pc = 1161472u; + // @0011B8E8 MOV.S $f1, $f0 + this.ee.fpr[1].f = this.ee.fpr[0].f; + // @0011B8EC SWC1 $f0, $0020(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (32u + this.ee.sp.UL0)); + // @0011B8F0 LWC1 $f12, $0000(s1) + MobUt.LWC1(this.ee, this.ee.fpr[12], (0u + this.ee.s1.UL0)); + // @0011B8F4 ADDIU s0, sp, $0010 + this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 16))); + // @0011B8F8 JAL $0011bdc8 + this.ee.ra.UL0 = 1161472u; + this.ee.pc = 1162696u; + // @0011B8FC SUB.S $f12, $f1, $f12 + this.ee.fpr[12].f = (this.ee.fpr[1].f - this.ee.fpr[12].f); + } + + public virtual void funct0011b8f0() + { + this.ee.pc = 1161472u; + // @0011B8F0 LWC1 $f12, $0000(s1) + MobUt.LWC1(this.ee, this.ee.fpr[12], (0u + this.ee.s1.UL0)); + // @0011B8F4 ADDIU s0, sp, $0010 + this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 16))); + // @0011B8F8 JAL $0011bdc8 + this.ee.ra.UL0 = 1161472u; + this.ee.pc = 1162696u; + // @0011B8FC SUB.S $f12, $f1, $f12 + this.ee.fpr[12].f = (this.ee.fpr[1].f - this.ee.fpr[12].f); + } + + public virtual void funct0011b900() + { + this.ee.pc = 1161492u; + // @0011B900 LWC1 $f1, $0004(s1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.s1.UL0)); + // @0011B904 LWC1 $f12, $0024(sp) + MobUt.LWC1(this.ee, this.ee.fpr[12], (36u + this.ee.sp.UL0)); + // @0011B908 SWC1 $f0, $0000(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.sp.UL0)); + // @0011B90C JAL $0011bdc8 + this.ee.ra.UL0 = 1161492u; + this.ee.pc = 1162696u; + // @0011B910 SUB.S $f12, $f12, $f1 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[1].f); + } + + public virtual void funct0011b914() + { + this.ee.pc = 1161512u; + // @0011B914 LWC1 $f1, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.s1.UL0)); + // @0011B918 LWC1 $f12, $0028(sp) + MobUt.LWC1(this.ee, this.ee.fpr[12], (40u + this.ee.sp.UL0)); + // @0011B91C SWC1 $f0, $0004(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (4u + this.ee.sp.UL0)); + // @0011B920 JAL $0011bdc8 + this.ee.ra.UL0 = 1161512u; + this.ee.pc = 1162696u; + // @0011B924 SUB.S $f12, $f12, $f1 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[1].f); + } + + public virtual void funct0011b928() + { + this.ee.pc = 1161576u; + // @0011B928 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @0011B92C LWC1 $f1, $0020(sp) + MobUt.LWC1(this.ee, this.ee.fpr[1], (32u + this.ee.sp.UL0)); + // @0011B930 ADDIU t7, t7, $8114 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32492))); + // @0011B934 LWC1 $f2, $0028(sp) + MobUt.LWC1(this.ee, this.ee.fpr[2], (40u + this.ee.sp.UL0)); + // @0011B938 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @0011B93C SWC1 $f0, $0008(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (8u + this.ee.sp.UL0)); + // @0011B940 ADD.S $f2, $f2, $f3 + this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[3].f); + // @0011B944 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @0011B948 LWC1 $f0, $0024(sp) + MobUt.LWC1(this.ee, this.ee.fpr[0], (36u + this.ee.sp.UL0)); + // @0011B94C LWC1 $f12, $0000(s1) + MobUt.LWC1(this.ee, this.ee.fpr[12], (0u + this.ee.s1.UL0)); + // @0011B950 SWC1 $f2, $0028(sp) + MobUt.SWC1(this.ee, this.ee.fpr[2], (40u + this.ee.sp.UL0)); + // @0011B954 SUB.S $f3, $f3, $f0 + this.ee.fpr[3].f = (this.ee.fpr[3].f - this.ee.fpr[0].f); + // @0011B958 SUB.S $f12, $f1, $f12 + this.ee.fpr[12].f = (this.ee.fpr[1].f - this.ee.fpr[12].f); + // @0011B95C SWC1 $f1, $0020(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (32u + this.ee.sp.UL0)); + // @0011B960 JAL $0011bdc8 + this.ee.ra.UL0 = 1161576u; + this.ee.pc = 1162696u; + // @0011B964 SWC1 $f3, $0024(sp) + MobUt.SWC1(this.ee, this.ee.fpr[3], (36u + this.ee.sp.UL0)); + } + + public virtual void funct0011b968() + { + this.ee.pc = 1161596u; + // @0011B968 LWC1 $f1, $0004(s1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.s1.UL0)); + // @0011B96C LWC1 $f12, $0024(sp) + MobUt.LWC1(this.ee, this.ee.fpr[12], (36u + this.ee.sp.UL0)); + // @0011B970 SWC1 $f0, $0010(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.sp.UL0)); + // @0011B974 JAL $0011bdc8 + this.ee.ra.UL0 = 1161596u; + this.ee.pc = 1162696u; + // @0011B978 SUB.S $f12, $f12, $f1 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[1].f); + } + + public virtual void funct0011b97c() + { + this.ee.pc = 1161616u; + // @0011B97C LWC1 $f1, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.s1.UL0)); + // @0011B980 LWC1 $f12, $0028(sp) + MobUt.LWC1(this.ee, this.ee.fpr[12], (40u + this.ee.sp.UL0)); + // @0011B984 SWC1 $f0, $0014(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (20u + this.ee.sp.UL0)); + // @0011B988 JAL $0011bdc8 + this.ee.ra.UL0 = 1161616u; + this.ee.pc = 1162696u; + // @0011B98C SUB.S $f12, $f12, $f1 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[1].f); + } + + public virtual void funct0011b990() + { + this.ee.pc = 1161692u; + // @0011B990 SWC1 $f0, $0018(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (24u + this.ee.sp.UL0)); + // @0011B994 MOV.S $f5, $f0 + this.ee.fpr[5].f = this.ee.fpr[0].f; + // @0011B998 LQC2 vf1, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @0011B99C LQC2 vf2, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.sp.UL0)); + // @0011B9A0 VMUL.xyz vf1, vf1, vf2 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); + // @0011B9A4 VADDy.x vf1, vf1, vf1y + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); + // @0011B9A8 VADDz.x vf1, vf1, vf1z + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); + // @0011B9AC QMFC2 t0, vf1 + MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); + // @0011B9B0 MTC1 t0, $f1 + this.ee.fpr[1].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @0011B9B4 LQC2 vf1, $0000(s0) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s0.UL0)); + // @0011B9B8 LQC2 vf2, $0000(s0) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.s0.UL0)); + // @0011B9BC VMUL.xyz vf1, vf1, vf2 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); + // @0011B9C0 VADDy.x vf1, vf1, vf1y + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); + // @0011B9C4 VADDz.x vf1, vf1, vf1z + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); + // @0011B9C8 QMFC2 t0, vf1 + MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); + // @0011B9CC MTC1 t0, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @0011B9D0 C.LE.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f <= this.ee.fpr[0].f); + // @0011B9D4 BC1F $0011ba20 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1161760u; + } + // @0011B9D8 LWC1 $f2, $0000(sp) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.sp.UL0)); + } + + public virtual void funct0011b9dc() + { + this.ee.pc = 1161760u; + // @0011B9DC LWC1 $f0, $0000(s1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.s1.UL0)); + // @0011B9E0 LWC1 $f3, $0004(s1) + MobUt.LWC1(this.ee, this.ee.fpr[3], (4u + this.ee.s1.UL0)); + // @0011B9E4 ADD.S $f2, $f2, $f0 + this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[0].f); + // @0011B9E8 LWC1 $f4, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[4], (8u + this.ee.s1.UL0)); + // @0011B9EC LWC1 $f1, $0004(sp) + MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.sp.UL0)); + // @0011B9F0 LWC1 $f0, $0008(sp) + MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.sp.UL0)); + // @0011B9F4 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @0011B9F8 ADD.S $f0, $f0, $f4 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[4].f); + // @0011B9FC SWC1 $f2, $0000(s1) + MobUt.SWC1(this.ee, this.ee.fpr[2], (0u + this.ee.s1.UL0)); + // @0011BA00 SWC1 $f1, $0004(s1) + MobUt.SWC1(this.ee, this.ee.fpr[1], (4u + this.ee.s1.UL0)); + // @0011BA04 SWC1 $f0, $0008(s1) + MobUt.SWC1(this.ee, this.ee.fpr[0], (8u + this.ee.s1.UL0)); + // @0011BA08 LD s0, $0030(sp) + MobUt.LD(this.ee, this.ee.s0, (48u + this.ee.sp.UL0)); + // @0011BA0C LD s1, $0038(sp) + MobUt.LD(this.ee, this.ee.s1, (56u + this.ee.sp.UL0)); + // @0011BA10 LD ra, $0040(sp) + MobUt.LD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); + // @0011BA14 LWC1 $f20, $0048(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (72u + this.ee.sp.UL0)); + // @0011BA18 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0011BA1C ADDIU sp, sp, $0050 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 80))); + } + + public virtual void funct0011ba08() + { + this.ee.pc = 1161760u; + // @0011BA08 LD s0, $0030(sp) + MobUt.LD(this.ee, this.ee.s0, (48u + this.ee.sp.UL0)); + // @0011BA0C LD s1, $0038(sp) + MobUt.LD(this.ee, this.ee.s1, (56u + this.ee.sp.UL0)); + // @0011BA10 LD ra, $0040(sp) + MobUt.LD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); + // @0011BA14 LWC1 $f20, $0048(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (72u + this.ee.sp.UL0)); + // @0011BA18 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0011BA1C ADDIU sp, sp, $0050 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 80))); + } + + public virtual void funct0011ba20() + { + this.ee.pc = 1161808u; + // @0011BA20 LWC1 $f3, $0000(s1) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.s1.UL0)); + // @0011BA24 LWC1 $f4, $0004(s1) + MobUt.LWC1(this.ee, this.ee.fpr[4], (4u + this.ee.s1.UL0)); + // @0011BA28 LWC1 $f2, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[2], (8u + this.ee.s1.UL0)); + // @0011BA2C LWC1 $f1, $0010(sp) + MobUt.LWC1(this.ee, this.ee.fpr[1], (16u + this.ee.sp.UL0)); + // @0011BA30 LWC1 $f0, $0014(sp) + MobUt.LWC1(this.ee, this.ee.fpr[0], (20u + this.ee.sp.UL0)); + // @0011BA34 ADD.S $f2, $f5, $f2 + this.ee.fpr[2].f = (this.ee.fpr[5].f + this.ee.fpr[2].f); + // @0011BA38 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @0011BA3C ADD.S $f0, $f0, $f4 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[4].f); + // @0011BA40 SWC1 $f2, $0008(s1) + MobUt.SWC1(this.ee, this.ee.fpr[2], (8u + this.ee.s1.UL0)); + // @0011BA44 SWC1 $f1, $0000(s1) + MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s1.UL0)); + // @0011BA48 BEQ zero, zero, $0011ba08 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1161736u; + } + // @0011BA4C SWC1 $f0, $0004(s1) + MobUt.SWC1(this.ee, this.ee.fpr[0], (4u + this.ee.s1.UL0)); + } + + public virtual void funct0011ba50() + { + this.ee.pc = 1161820u; + // @0011BA50 C.LT.S $f0, $f20 + this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[20].f); + // @0011BA54 BC1F $0011bab0 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1161904u; + } + // @0011BA58 LWC1 $f13, $0014(s0) + MobUt.LWC1(this.ee, this.ee.fpr[13], (20u + this.ee.s0.UL0)); + } + + public virtual void funct0011ba5c() + { + this.ee.pc = 1161832u; + // @0011BA5C LWC1 $f12, $0010(s0) + MobUt.LWC1(this.ee, this.ee.fpr[12], (16u + this.ee.s0.UL0)); + // @0011BA60 JAL $002ff8c0 + this.ee.ra.UL0 = 1161832u; + this.ee.pc = 3143872u; + // @0011BA64 NEG.S $f12, $f12 + this.ee.fpr[12].f = (0 - this.ee.fpr[12].f); + } + + public virtual void funct0011ba68() + { + this.ee.pc = 1161860u; + // @0011BA68 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @0011BA6C NEG.S $f12, $f20 + this.ee.fpr[12].f = (0 - this.ee.fpr[20].f); + // @0011BA70 ADDIU t7, t7, $8110 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32496))); + // @0011BA74 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @0011BA78 MUL.S $f1, $f0, $f1 + this.ee.fpr[1].f = (this.ee.fpr[0].f * this.ee.fpr[1].f); + // @0011BA7C JAL $002ff8a8 + this.ee.ra.UL0 = 1161860u; + this.ee.pc = 3143848u; + // @0011BA80 SWC1 $f1, $0020(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (32u + this.ee.sp.UL0)); + } + + public virtual void funct0011ba84() + { + this.ee.pc = 1161888u; + // @0011BA84 LWC1 $f1, $0020(sp) + MobUt.LWC1(this.ee, this.ee.fpr[1], (32u + this.ee.sp.UL0)); + // @0011BA88 SWC1 $f0, $0024(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (36u + this.ee.sp.UL0)); + // @0011BA8C SWC1 $f1, $0028(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (40u + this.ee.sp.UL0)); + // @0011BA90 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @0011BA94 C.LE.S $f0, $f20 + this.ee.fcr31_23 = (this.ee.fpr[0].f <= this.ee.fpr[20].f); + // @0011BA98 BC1F $0011baa8 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1161896u; + } + // @0011BA9C NEG.S $f0, $f1 + this.ee.fpr[0].f = (0 - this.ee.fpr[1].f); + } + + public virtual void funct0011baa0() + { + this.ee.pc = 1161896u; + // @0011BAA0 BEQ zero, zero, $0011b8f0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1161456u; + } + // @0011BAA4 SWC1 $f1, $0028(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (40u + this.ee.sp.UL0)); + } + + public virtual void funct0011bdc8() + { + this.ee.pc = 1162712u; + // @0011BDC8 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @0011BDCC C.LT.S $f0, $f12 + this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[12].f); + // @0011BDD0 BC1F $0011be24 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1162788u; + } + // @0011BDD4 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct0011bdd8() + { + this.ee.pc = 1162732u; + // @0011BDD8 ADDIU t7, t7, $8120 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32480))); + // @0011BDDC LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @0011BDE0 C.LT.S $f0, $f12 + this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[12].f); + // @0011BDE4 BC1F $0011be1c + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1162780u; + } + // @0011BDE8 NOP + MobUt.Latency(); + } + + public virtual void funct0011bdec() + { + this.ee.pc = 1162780u; + // @0011BDEC MOV.S $f1, $f0 + this.ee.fpr[1].f = this.ee.fpr[0].f; + // @0011BDF0 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @0011BDF4 ADDIU t7, t7, $8124 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32476))); + // @0011BDF8 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @0011BDFC SUB.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + // @0011BE00 C.LT.S $f1, $f12 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[12].f); + // @0011BE04 NOP + MobUt.Latency(); + // @0011BE08 NOP + MobUt.Latency(); + // @0011BE0C NOP + MobUt.Latency(); + // @0011BE10 NOP + MobUt.Latency(); + // @0011BE14 BC1TL $0011be00 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1162752u; + // @0011BE18 SUB.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + } + } + + public virtual void funct0011be00() + { + this.ee.pc = 1162780u; + // @0011BE00 C.LT.S $f1, $f12 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[12].f); + // @0011BE04 NOP + MobUt.Latency(); + // @0011BE08 NOP + MobUt.Latency(); + // @0011BE0C NOP + MobUt.Latency(); + // @0011BE10 NOP + MobUt.Latency(); + // @0011BE14 BC1TL $0011be00 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1162752u; + // @0011BE18 SUB.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + } + } + + public virtual void funct0011be1c() + { + this.ee.pc = 1162788u; + // @0011BE1C JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0011BE20 MOV.S $f0, $f12 + this.ee.fpr[0].f = this.ee.fpr[12].f; + } + + public virtual void funct0011be24() + { + this.ee.pc = 1162812u; + // @0011BE24 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @0011BE28 ADDIU t7, t7, $8128 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32472))); + // @0011BE2C LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @0011BE30 C.LT.S $f12, $f1 + this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[1].f); + // @0011BE34 BC1F $0011be1c + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1162780u; + } + // @0011BE38 NOP + MobUt.Latency(); + } + + public virtual void funct0011be3c() + { + this.ee.pc = 1162840u; + // @0011BE3C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @0011BE40 ADDIU t7, t7, $8124 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32476))); + // @0011BE44 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @0011BE48 ADD.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); + // @0011BE4C C.LT.S $f12, $f1 + this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[1].f); + // @0011BE50 BC1TL $0011be4c + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1162828u; + // @0011BE54 ADD.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); + } + } + + public virtual void funct0011be4c() + { + this.ee.pc = 1162840u; + // @0011BE4C C.LT.S $f12, $f1 + this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[1].f); + // @0011BE50 BC1TL $0011be4c + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1162828u; + // @0011BE54 ADD.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); + } + } + + public virtual void funct0011be58() + { + this.ee.pc = 1162848u; + // @0011BE58 BEQ zero, zero, $0011be1c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1162780u; + } + // @0011BE5C NOP + MobUt.Latency(); + } + + public virtual void funct00120650() + { + this.ee.pc = 1181292u; + // @00120650 LW t7, $0004(a0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); + // @00120654 SLL a1, a1, 2 + MobUt.SLL(this.ee.a1, this.ee.a1, 2); + // @00120658 LW t6, $0018(t7) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t7.UL0)); + // @0012065C ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00120660 ADDU t7, t7, a1 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.a1.SD0))); + // @00120664 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00120668 LWC1 $f0, $0020(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (32u + this.ee.t7.UL0)); + } + + public virtual void funct00120670() + { + this.ee.pc = 1181324u; + // @00120670 LW t7, $0004(a0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); + // @00120674 SLL a1, a1, 2 + MobUt.SLL(this.ee.a1, this.ee.a1, 2); + // @00120678 LW t6, $0018(t7) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t7.UL0)); + // @0012067C ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00120680 ADDU a1, a1, t7 + this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + this.ee.t7.SD0))); + // @00120684 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00120688 LW v0, $0030(a1) + MobUt.LW(this.ee, this.ee.v0, (48u + this.ee.a1.UL0)); + } + + public virtual void funct00120690() + { + this.ee.pc = 1181340u; + // @00120690 LW t7, $0004(a0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); + // @00120694 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00120698 LHU v0, $0010(t7) + MobUt.LHU(this.ee, this.ee.v0, (16u + this.ee.t7.UL0)); + } + + public virtual void funct001206a0() + { + this.ee.pc = 1181372u; + // @001206A0 ADDIU sp, sp, $fff0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); + // @001206A4 LW t6, $0000(a0) + MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.a0.UL0)); + // @001206A8 SD s0, $0000(sp) + MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @001206AC SD ra, $0008(sp) + MobUt.SD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); + // @001206B0 LW v0, $001c(t6) + MobUt.LW(this.ee, this.ee.v0, (28u + this.ee.t6.UL0)); + // @001206B4 JALR ra, v0 + this.ee.ra.UD0 = 1181372u; + this.ee.pc = this.ee.v0.UL0; + // @001206B8 LW s0, $0004(a0) + MobUt.LW(this.ee, this.ee.s0, (4u + this.ee.a0.UL0)); + } + + public virtual void funct001206bc() + { + this.ee.pc = 1181380u; + // @001206BC BEQ v0, zero, $001206cc + if ((this.ee.v0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1181388u; + } + // @001206C0 DADDU t7, zero, zero + this.ee.t7.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001206c4() + { + this.ee.pc = 1181408u; + // @001206C4 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @001206C8 ADDU t7, s0, t7 + this.ee.t7.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t7.SD0))); + // @001206CC LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @001206D0 DADDU v0, t7, zero + this.ee.v0.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); + // @001206D4 LD ra, $0008(sp) + MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); + // @001206D8 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @001206DC ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00124a88() + { + this.ee.pc = 1198900u; + // @00124A88 ADDIU sp, sp, $fe70 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -400))); + // @00124A8C MTC1 zero, $f1 + this.ee.fpr[1].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @00124A90 SWC1 $f25, $018c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[25], (396u + this.ee.sp.UL0)); + // @00124A94 ADDIU t6, sp, $0010 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 16))); + // @00124A98 SWC1 $f23, $0184(sp) + MobUt.SWC1(this.ee, this.ee.fpr[23], (388u + this.ee.sp.UL0)); + // @00124A9C ADDIU t5, sp, $0020 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 32))); + // @00124AA0 SWC1 $f22, $0180(sp) + MobUt.SWC1(this.ee, this.ee.fpr[22], (384u + this.ee.sp.UL0)); + // @00124AA4 SWC1 $f20, $0178(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (376u + this.ee.sp.UL0)); + // @00124AA8 MOV.S $f23, $f12 + this.ee.fpr[23].f = this.ee.fpr[12].f; + // @00124AAC SD s1, $0148(sp) + MobUt.SD(this.ee, this.ee.s1, (328u + this.ee.sp.UL0)); + // @00124AB0 MOV.S $f22, $f13 + this.ee.fpr[22].f = this.ee.fpr[13].f; + // @00124AB4 SD s2, $0150(sp) + MobUt.SD(this.ee, this.ee.s2, (336u + this.ee.sp.UL0)); + // @00124AB8 MOV.S $f20, $f14 + this.ee.fpr[20].f = this.ee.fpr[14].f; + // @00124ABC SD s4, $0160(sp) + MobUt.SD(this.ee, this.ee.s4, (352u + this.ee.sp.UL0)); + // @00124AC0 MOV.S $f25, $f15 + this.ee.fpr[25].f = this.ee.fpr[15].f; + // @00124AC4 SD s5, $0168(sp) + MobUt.SD(this.ee, this.ee.s5, (360u + this.ee.sp.UL0)); + // @00124AC8 SD s0, $0140(sp) + MobUt.SD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); + // @00124ACC DADDU s4, a3, zero + this.ee.s4.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); + // @00124AD0 SD s3, $0158(sp) + MobUt.SD(this.ee, this.ee.s3, (344u + this.ee.sp.UL0)); + // @00124AD4 DADDU s5, a2, zero + this.ee.s5.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); + // @00124AD8 SD ra, $0170(sp) + MobUt.SD(this.ee, this.ee.ra, (368u + this.ee.sp.UL0)); + // @00124ADC DADDU s1, t0, zero + this.ee.s1.UD0 = (this.ee.t0.UD0 + this.ee.r0.UD0); + // @00124AE0 SWC1 $f24, $0188(sp) + MobUt.SWC1(this.ee, this.ee.fpr[24], (392u + this.ee.sp.UL0)); + // @00124AE4 ADDIU s2, sp, $00f0 + this.ee.s2.SD0 = ((int)((this.ee.sp.SD0 + 240))); + // @00124AE8 SWC1 $f21, $017c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[21], (380u + this.ee.sp.UL0)); + // @00124AEC SWC1 $f1, $0000(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.sp.UL0)); + // @00124AF0 SWC1 $f1, $0004(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (4u + this.ee.sp.UL0)); + // @00124AF4 SWC1 $f1, $0008(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (8u + this.ee.sp.UL0)); + // @00124AF8 SWC1 $f1, $000c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (12u + this.ee.sp.UL0)); + // @00124AFC SWC1 $f1, $0010(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (16u + this.ee.sp.UL0)); + // @00124B00 SWC1 $f1, $0014(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (20u + this.ee.sp.UL0)); + // @00124B04 SWC1 $f1, $0018(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (24u + this.ee.sp.UL0)); + // @00124B08 SWC1 $f1, $001c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (28u + this.ee.sp.UL0)); + // @00124B0C SWC1 $f1, $0020(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (32u + this.ee.sp.UL0)); + // @00124B10 SWC1 $f1, $0024(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (36u + this.ee.sp.UL0)); + // @00124B14 SWC1 $f1, $0028(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (40u + this.ee.sp.UL0)); + // @00124B18 SWC1 $f1, $002c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (44u + this.ee.sp.UL0)); + // @00124B1C LQC2 vf1, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); + // @00124B20 LQC2 vf2, $0000(a0) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a0.UL0)); + // @00124B24 VSUB.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); + // @00124B28 SQC2 vf1, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); + // @00124B2C BEQ sp, s2, $00124b3c + if ((this.ee.sp.UD0 == this.ee.s2.UD0)) + { + this.ee.pc = 1198908u; + } + // @00124B30 NOP + MobUt.Latency(); + } + + public virtual void funct00124b34() + { + this.ee.pc = 1198972u; + // @00124B34 LQ t0, $0000(s2) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); + // @00124B38 SQ t0, $0000(sp) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); + // @00124B3C LQC2 vf1, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @00124B40 VMUL.xyz vf2, vf1, vf1 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); + // @00124B44 VADDy.x vf2, vf2, vf2y + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); + // @00124B48 VADDz.x vf2, vf2, vf2z + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); + // @00124B4C VSQRT Q, vf2x + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); + // @00124B50 VWAITQ + MobUt.Latency(); + // @00124B54 CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + // @00124B58 VADDq.x vf2, vf0, Q + this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); + // @00124B5C MTC1 t0, $f24 + this.ee.fpr[24].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00124B60 VNOP + MobUt.Latency(); + // @00124B64 VDIV Q, vf0w, vf2x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); + // @00124B68 VWAITQ + MobUt.Latency(); + // @00124B6C VMULq.xyz vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + // @00124B70 SQC2 vf1, $0000(sp) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @00124B74 BEQ t1, zero, $001250ec + if ((this.ee.t1.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1200364u; + } + // @00124B78 LWC1 $f0, $0004(sp) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.sp.UL0)); + } + + public virtual void funct00124b7c() + { + this.ee.pc = 1198996u; + // @00124B7C LQC2 vf1, $0000(t1) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t1.UL0)); + // @00124B80 LQC2 vf2, $0000(a0) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a0.UL0)); + // @00124B84 VSUB.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); + // @00124B88 SQC2 vf1, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); + // @00124B8C BEQ t6, s2, $00124b9c + if ((this.ee.t6.UD0 == this.ee.s2.UD0)) + { + this.ee.pc = 1199004u; + } + // @00124B90 NOP + MobUt.Latency(); + } + + public virtual void funct00124b94() + { + this.ee.pc = 1199092u; + // @00124B94 LQ t0, $0000(s2) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); + // @00124B98 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @00124B9C LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00124BA0 VMUL.xyz vf2, vf1, vf1 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); + // @00124BA4 VADDy.x vf2, vf2, vf2y + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); + // @00124BA8 VADDz.x vf2, vf2, vf2z + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); + // @00124BAC VSQRT Q, vf2x + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); + // @00124BB0 VWAITQ + MobUt.Latency(); + // @00124BB4 CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + // @00124BB8 VADDq.x vf2, vf0, Q + this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); + // @00124BBC MTC1 t0, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00124BC0 VNOP + MobUt.Latency(); + // @00124BC4 VDIV Q, vf0w, vf2x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); + // @00124BC8 VWAITQ + MobUt.Latency(); + // @00124BCC VMULq.xyz vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + // @00124BD0 SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00124BD4 LQC2 vf1, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @00124BD8 LQC2 vf2, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); + // @00124BDC VSUB.xyzw vf3, vf0, vf0 + this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); + this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); + this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); + this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); + // @00124BE0 VOPMULA.xyz ACC, vf1, vf2 + this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); + this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); + this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); + // @00124BE4 VOPMSUB.xyz vf3, vf2, vf1 + this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); + this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); + this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); + // @00124BE8 SQC2 vf3, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.s2.UL0)); + // @00124BEC BEQ t5, s2, $00124bfc + if ((this.ee.t5.UD0 == this.ee.s2.UD0)) + { + this.ee.pc = 1199100u; + } + // @00124BF0 NOP + MobUt.Latency(); + } + + public virtual void funct00124bf4() + { + this.ee.pc = 1199188u; + // @00124BF4 LQ t0, $0000(s2) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); + // @00124BF8 SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @00124BFC LQC2 vf1, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); + // @00124C00 VMUL.xyz vf2, vf1, vf1 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); + // @00124C04 VADDy.x vf2, vf2, vf2y + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); + // @00124C08 VADDz.x vf2, vf2, vf2z + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); + // @00124C0C VSQRT Q, vf2x + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); + // @00124C10 VWAITQ + MobUt.Latency(); + // @00124C14 CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + // @00124C18 VADDq.x vf2, vf0, Q + this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); + // @00124C1C MTC1 t0, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00124C20 VNOP + MobUt.Latency(); + // @00124C24 VDIV Q, vf0w, vf2x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); + // @00124C28 VWAITQ + MobUt.Latency(); + // @00124C2C VMULq.xyz vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + // @00124C30 SQC2 vf1, $0000(t5) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); + // @00124C34 LQC2 vf1, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); + // @00124C38 LQC2 vf2, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.sp.UL0)); + // @00124C3C VSUB.xyzw vf3, vf0, vf0 + this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); + this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); + this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); + this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); + // @00124C40 VOPMULA.xyz ACC, vf1, vf2 + this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); + this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); + this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); + // @00124C44 VOPMSUB.xyz vf3, vf2, vf1 + this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); + this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); + this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); + // @00124C48 SQC2 vf3, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.s2.UL0)); + // @00124C4C BEQ t6, s2, $00124c5c + if ((this.ee.t6.UD0 == this.ee.s2.UD0)) + { + this.ee.pc = 1199196u; + } + // @00124C50 NOP + MobUt.Latency(); + } + + public virtual void funct00124c54() + { + this.ee.pc = 1199264u; + // @00124C54 LQ t0, $0000(s2) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); + // @00124C58 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @00124C5C LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00124C60 VMUL.xyz vf2, vf1, vf1 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); + // @00124C64 VADDy.x vf2, vf2, vf2y + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); + // @00124C68 VADDz.x vf2, vf2, vf2z + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); + // @00124C6C VSQRT Q, vf2x + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); + // @00124C70 VWAITQ + MobUt.Latency(); + // @00124C74 CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + // @00124C78 VADDq.x vf2, vf0, Q + this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); + // @00124C7C MTC1 t0, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00124C80 VNOP + MobUt.Latency(); + // @00124C84 VDIV Q, vf0w, vf2x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); + // @00124C88 VWAITQ + MobUt.Latency(); + // @00124C8C VMULq.xyz vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + // @00124C90 SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00124C94 ADDIU s3, sp, $0030 + this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 48))); + // @00124C98 BEQ s3, sp, $00124cac + if ((this.ee.s3.UD0 == this.ee.sp.UD0)) + { + this.ee.pc = 1199276u; + } + // @00124C9C ADDIU t7, sp, $0040 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); + } + + public virtual void funct00124c98() + { + this.ee.pc = 1199264u; + // @00124C98 BEQ s3, sp, $00124cac + if ((this.ee.s3.UD0 == this.ee.sp.UD0)) + { + this.ee.pc = 1199276u; + } + // @00124C9C ADDIU t7, sp, $0040 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); + } + + public virtual void funct00124ca0() + { + this.ee.pc = 1199284u; + // @00124CA0 LQ t0, $0000(sp) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); + // @00124CA4 SQ t0, $0000(s3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @00124CA8 ADDIU t7, sp, $0040 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); + // @00124CAC BEQL t7, t6, $00124cc0 + if ((this.ee.t7.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1199296u; + // @00124CB0 ADDIU t7, sp, $0050 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 80))); + } + } + + public virtual void funct00124cb4() + { + this.ee.pc = 1199304u; + // @00124CB4 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @00124CB8 SQ t0, $0000(t7) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @00124CBC ADDIU t7, sp, $0050 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 80))); + // @00124CC0 BEQL t7, t5, $00124cd4 + if ((this.ee.t7.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1199316u; + // @00124CC4 ADDIU t7, sp, $0060 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 96))); + } + } + + public virtual void funct00124cc8() + { + this.ee.pc = 1199336u; + // @00124CC8 LQ t0, $0000(t5) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @00124CCC SQ t0, $0000(t7) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @00124CD0 ADDIU t7, sp, $0060 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 96))); + // @00124CD4 SQC2 vf0, $0000(t7) + MobUt.SQC2(this.ee, this.ee.VF[0], (0u + this.ee.t7.UL0)); + // @00124CD8 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @00124CDC C.EQ.S $f20, $f0 + this.ee.fcr31_23 = (this.ee.fpr[20].f == this.ee.fpr[0].f); + // @00124CE0 BC1T $00124d98 + if (this.ee.fcr31_23) + { + this.ee.pc = 1199512u; + } + // @00124CE4 ADDIU s0, sp, $0070 + this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 112))); + } + + public virtual void funct00124ce8() + { + this.ee.pc = 1199344u; + // @00124CE8 JAL $0011b420 + this.ee.ra.UL0 = 1199344u; + this.ee.pc = 1160224u; + // @00124CEC DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00124cf0() + { + this.ee.pc = 1199356u; + // @00124CF0 MOV.S $f12, $f20 + this.ee.fpr[12].f = this.ee.fpr[20].f; + // @00124CF4 JAL $0011b450 + this.ee.ra.UL0 = 1199356u; + this.ee.pc = 1160272u; + // @00124CF8 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00124cfc() + { + this.ee.pc = 1199480u; + // @00124CFC ADDIU t7, sp, $0100 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 256))); + // @00124D00 LQC2 vf1, $0000(s3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); + // @00124D04 LQC2 vf2, $0010(s3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); + // @00124D08 LQC2 vf3, $0020(s3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); + // @00124D0C LQC2 vf4, $0030(s3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); + // @00124D10 LQC2 vf5, $0000(s0) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s0.UL0)); + // @00124D14 LQC2 vf6, $0010(s0) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.s0.UL0)); + // @00124D18 LQC2 vf7, $0020(s0) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.s0.UL0)); + // @00124D1C LQC2 vf8, $0030(s0) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.s0.UL0)); + // @00124D20 VMULAx.xyzw ACC, vf1, vf5x + // @00124D24 VMADDAy.xyzw ACC, vf2, vf5y + // @00124D28 VMADDAz.xyzw ACC, vf3, vf5z + // @00124D2C VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @00124D30 VMULAx.xyzw ACC, vf1, vf6x + // @00124D34 VMADDAy.xyzw ACC, vf2, vf6y + // @00124D38 VMADDAz.xyzw ACC, vf3, vf6z + // @00124D3C VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @00124D40 VMULAx.xyzw ACC, vf1, vf7x + // @00124D44 VMADDAy.xyzw ACC, vf2, vf7y + // @00124D48 VMADDAz.xyzw ACC, vf3, vf7z + // @00124D4C VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @00124D50 VMULAx.xyzw ACC, vf1, vf8x + // @00124D54 VMADDAy.xyzw ACC, vf2, vf8y + // @00124D58 VMADDAz.xyzw ACC, vf3, vf8z + // @00124D5C VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @00124D60 SQC2 vf5, $0000(t7) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @00124D64 SQC2 vf6, $0010(t7) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); + // @00124D68 SQC2 vf7, $0020(t7) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); + // @00124D6C SQC2 vf8, $0030(t7) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); + // @00124D70 BEQ s3, t7, $00124d98 + if ((this.ee.s3.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1199512u; + } + // @00124D74 NOP + MobUt.Latency(); + } + + public virtual void funct00124d78() + { + this.ee.pc = 1199520u; + // @00124D78 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @00124D7C LQ t1, $0010(t7) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); + // @00124D80 LQ t2, $0020(t7) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); + // @00124D84 LQ t3, $0030(t7) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); + // @00124D88 SQ t0, $0000(s3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @00124D8C SQ t1, $0010(s3) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s3.UL[0])); + // @00124D90 SQ t2, $0020(s3) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s3.UL[0])); + // @00124D94 SQ t3, $0030(s3) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.s3.UL[0])); + // @00124D98 BNEL s1, zero, $00124e04 + if ((this.ee.s1.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1199620u; + // @00124D9C ADD.S $f0, $f23, $f23 + this.ee.fpr[0].f = (this.ee.fpr[23].f + this.ee.fpr[23].f); + } + } + + public virtual void funct00124d98() + { + this.ee.pc = 1199520u; + // @00124D98 BNEL s1, zero, $00124e04 + if ((this.ee.s1.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1199620u; + // @00124D9C ADD.S $f0, $f23, $f23 + this.ee.fpr[0].f = (this.ee.fpr[23].f + this.ee.fpr[23].f); + } + } + + public virtual void funct00124da0() + { + this.ee.pc = 1199528u; + // @00124DA0 BEQ s4, s3, $00124dcc + if ((this.ee.s4.UD0 == this.ee.s3.UD0)) + { + this.ee.pc = 1199564u; + } + // @00124DA4 LD s0, $0140(sp) + MobUt.LD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); + } + + public virtual void funct00124da8() + { + this.ee.pc = 1199620u; + // @00124DA8 LQ t0, $0000(s3) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @00124DAC LQ t1, $0010(s3) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.s3.UL[0])); + // @00124DB0 LQ t2, $0020(s3) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.s3.UL[0])); + // @00124DB4 LQ t3, $0030(s3) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.s3.UL[0])); + // @00124DB8 SQ t0, $0000(s4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s4.UL[0])); + // @00124DBC SQ t1, $0010(s4) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s4.UL[0])); + // @00124DC0 SQ t2, $0020(s4) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s4.UL[0])); + // @00124DC4 SQ t3, $0030(s4) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.s4.UL[0])); + // @00124DC8 LD s0, $0140(sp) + MobUt.LD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); + // @00124DCC LD s1, $0148(sp) + MobUt.LD(this.ee, this.ee.s1, (328u + this.ee.sp.UL0)); + // @00124DD0 LD s2, $0150(sp) + MobUt.LD(this.ee, this.ee.s2, (336u + this.ee.sp.UL0)); + // @00124DD4 LD s3, $0158(sp) + MobUt.LD(this.ee, this.ee.s3, (344u + this.ee.sp.UL0)); + // @00124DD8 LD s4, $0160(sp) + MobUt.LD(this.ee, this.ee.s4, (352u + this.ee.sp.UL0)); + // @00124DDC LD s5, $0168(sp) + MobUt.LD(this.ee, this.ee.s5, (360u + this.ee.sp.UL0)); + // @00124DE0 LD ra, $0170(sp) + MobUt.LD(this.ee, this.ee.ra, (368u + this.ee.sp.UL0)); + // @00124DE4 LWC1 $f25, $018c(sp) + MobUt.LWC1(this.ee, this.ee.fpr[25], (396u + this.ee.sp.UL0)); + // @00124DE8 LWC1 $f24, $0188(sp) + MobUt.LWC1(this.ee, this.ee.fpr[24], (392u + this.ee.sp.UL0)); + // @00124DEC LWC1 $f23, $0184(sp) + MobUt.LWC1(this.ee, this.ee.fpr[23], (388u + this.ee.sp.UL0)); + // @00124DF0 LWC1 $f22, $0180(sp) + MobUt.LWC1(this.ee, this.ee.fpr[22], (384u + this.ee.sp.UL0)); + // @00124DF4 LWC1 $f21, $017c(sp) + MobUt.LWC1(this.ee, this.ee.fpr[21], (380u + this.ee.sp.UL0)); + // @00124DF8 LWC1 $f20, $0178(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (376u + this.ee.sp.UL0)); + // @00124DFC JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00124E00 ADDIU sp, sp, $0190 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 400))); + } + + public virtual void funct00124dcc() + { + this.ee.pc = 1199620u; + // @00124DCC LD s1, $0148(sp) + MobUt.LD(this.ee, this.ee.s1, (328u + this.ee.sp.UL0)); + // @00124DD0 LD s2, $0150(sp) + MobUt.LD(this.ee, this.ee.s2, (336u + this.ee.sp.UL0)); + // @00124DD4 LD s3, $0158(sp) + MobUt.LD(this.ee, this.ee.s3, (344u + this.ee.sp.UL0)); + // @00124DD8 LD s4, $0160(sp) + MobUt.LD(this.ee, this.ee.s4, (352u + this.ee.sp.UL0)); + // @00124DDC LD s5, $0168(sp) + MobUt.LD(this.ee, this.ee.s5, (360u + this.ee.sp.UL0)); + // @00124DE0 LD ra, $0170(sp) + MobUt.LD(this.ee, this.ee.ra, (368u + this.ee.sp.UL0)); + // @00124DE4 LWC1 $f25, $018c(sp) + MobUt.LWC1(this.ee, this.ee.fpr[25], (396u + this.ee.sp.UL0)); + // @00124DE8 LWC1 $f24, $0188(sp) + MobUt.LWC1(this.ee, this.ee.fpr[24], (392u + this.ee.sp.UL0)); + // @00124DEC LWC1 $f23, $0184(sp) + MobUt.LWC1(this.ee, this.ee.fpr[23], (388u + this.ee.sp.UL0)); + // @00124DF0 LWC1 $f22, $0180(sp) + MobUt.LWC1(this.ee, this.ee.fpr[22], (384u + this.ee.sp.UL0)); + // @00124DF4 LWC1 $f21, $017c(sp) + MobUt.LWC1(this.ee, this.ee.fpr[21], (380u + this.ee.sp.UL0)); + // @00124DF8 LWC1 $f20, $0178(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (376u + this.ee.sp.UL0)); + // @00124DFC JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00124E00 ADDIU sp, sp, $0190 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 400))); + } + + public virtual void funct00124e04() + { + this.ee.pc = 1199672u; + // @00124E04 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00124E08 MULA.S $f24, $f24 + this.ee.fpracc.f = (this.ee.fpr[24].f * this.ee.fpr[24].f); + // @00124E0C ADDIU t7, t7, $81f0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); + // @00124E10 MSUBA.S $f23, $f23 + this.ee.fpracc.f = MobUt.MSUB(this.ee.fpracc.f, this.ee.fpr[23].f, this.ee.fpr[23].f); + // @00124E14 MSUB.S $f1, $f22, $f22 + this.ee.fpr[1].f = (this.ee.fpracc.f + - (this.ee.fpr[22].f * this.ee.fpr[22].f)); + // @00124E18 MUL.S $f0, $f0, $f22 + this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[22].f); + // @00124E1C LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @00124E20 NOP + MobUt.Latency(); + // @00124E24 NOP + MobUt.Latency(); + // @00124E28 DIV.S $f21, $f1, $f0 + this.ee.fpr[21].f = (this.ee.fpr[1].f / this.ee.fpr[0].f); + // @00124E2C C.LT.S $f2, $f21 + this.ee.fcr31_23 = (this.ee.fpr[2].f < this.ee.fpr[21].f); + // @00124E30 BC1F $001250d0 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1200336u; + } + // @00124E34 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct00124e38() + { + this.ee.pc = 1199712u; + // @00124E38 MOV.S $f21, $f2 + this.ee.fpr[21].f = this.ee.fpr[2].f; + // @00124E3C MUL.S $f1, $f21, $f21 + this.ee.fpr[1].f = (this.ee.fpr[21].f * this.ee.fpr[21].f); + // @00124E40 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00124E44 ADDIU t7, t7, $81f0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); + // @00124E48 MTC1 zero, $f2 + this.ee.fpr[2].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @00124E4C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00124E50 SUB.S $f20, $f0, $f1 + this.ee.fpr[20].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); + // @00124E54 C.LT.S $f20, $f2 + this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[2].f); + // @00124E58 BC1TL $00124e60 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1199712u; + // @00124E5C MOV.S $f20, $f2 + this.ee.fpr[20].f = this.ee.fpr[2].f; + } + } + + public virtual void funct00124e3c() + { + this.ee.pc = 1199712u; + // @00124E3C MUL.S $f1, $f21, $f21 + this.ee.fpr[1].f = (this.ee.fpr[21].f * this.ee.fpr[21].f); + // @00124E40 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00124E44 ADDIU t7, t7, $81f0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); + // @00124E48 MTC1 zero, $f2 + this.ee.fpr[2].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @00124E4C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00124E50 SUB.S $f20, $f0, $f1 + this.ee.fpr[20].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); + // @00124E54 C.LT.S $f20, $f2 + this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[2].f); + // @00124E58 BC1TL $00124e60 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1199712u; + // @00124E5C MOV.S $f20, $f2 + this.ee.fpr[20].f = this.ee.fpr[2].f; + } + } + + public virtual void funct00124e40() + { + this.ee.pc = 1199712u; + // @00124E40 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00124E44 ADDIU t7, t7, $81f0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); + // @00124E48 MTC1 zero, $f2 + this.ee.fpr[2].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @00124E4C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00124E50 SUB.S $f20, $f0, $f1 + this.ee.fpr[20].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); + // @00124E54 C.LT.S $f20, $f2 + this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[2].f); + // @00124E58 BC1TL $00124e60 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1199712u; + // @00124E5C MOV.S $f20, $f2 + this.ee.fpr[20].f = this.ee.fpr[2].f; + } + } + + public virtual void funct00124e60() + { + this.ee.pc = 1199720u; + // @00124E60 BEQ s5, zero, $001250bc + if ((this.ee.s5.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1200316u; + } + // @00124E64 NOP + MobUt.Latency(); + } + + public virtual void funct00124e68() + { + this.ee.pc = 1199828u; + // @00124E68 NOP + MobUt.Latency(); + // @00124E6C NOP + MobUt.Latency(); + // @00124E70 SQRT.S $f0, $f20 + this.ee.fpr[0].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[20].f)))); + // @00124E74 NEG.S $f20, $f0 + this.ee.fpr[20].f = (0 - this.ee.fpr[0].f); + // @00124E78 SW zero, $0008(s1) + MobUt.SW(this.ee, this.ee.r0, (8u + this.ee.s1.UL0)); + // @00124E7C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00124E80 NEG.S $f0, $f20 + this.ee.fpr[0].f = (0 - this.ee.fpr[20].f); + // @00124E84 ADDIU t7, t7, $81f0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); + // @00124E88 LWC1 $f1, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.s1.UL0)); + // @00124E8C LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @00124E90 C.EQ.S $f25, $f1 + this.ee.fcr31_23 = (this.ee.fpr[25].f == this.ee.fpr[1].f); + // @00124E94 SWC1 $f2, $003c(s1) + MobUt.SWC1(this.ee, this.ee.fpr[2], (60u + this.ee.s1.UL0)); + // @00124E98 SWC1 $f0, $0010(s1) + MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.s1.UL0)); + // @00124E9C SWC1 $f21, $0000(s1) + MobUt.SWC1(this.ee, this.ee.fpr[21], (0u + this.ee.s1.UL0)); + // @00124EA0 SWC1 $f20, $0004(s1) + MobUt.SWC1(this.ee, this.ee.fpr[20], (4u + this.ee.s1.UL0)); + // @00124EA4 SW zero, $000c(s1) + MobUt.SW(this.ee, this.ee.r0, (12u + this.ee.s1.UL0)); + // @00124EA8 SWC1 $f21, $0014(s1) + MobUt.SWC1(this.ee, this.ee.fpr[21], (20u + this.ee.s1.UL0)); + // @00124EAC SW zero, $0018(s1) + MobUt.SW(this.ee, this.ee.r0, (24u + this.ee.s1.UL0)); + // @00124EB0 SW zero, $001c(s1) + MobUt.SW(this.ee, this.ee.r0, (28u + this.ee.s1.UL0)); + // @00124EB4 SW zero, $0020(s1) + MobUt.SW(this.ee, this.ee.r0, (32u + this.ee.s1.UL0)); + // @00124EB8 SW zero, $0024(s1) + MobUt.SW(this.ee, this.ee.r0, (36u + this.ee.s1.UL0)); + // @00124EBC SWC1 $f2, $0028(s1) + MobUt.SWC1(this.ee, this.ee.fpr[2], (40u + this.ee.s1.UL0)); + // @00124EC0 SW zero, $002c(s1) + MobUt.SW(this.ee, this.ee.r0, (44u + this.ee.s1.UL0)); + // @00124EC4 SW zero, $0030(s1) + MobUt.SW(this.ee, this.ee.r0, (48u + this.ee.s1.UL0)); + // @00124EC8 SW zero, $0034(s1) + MobUt.SW(this.ee, this.ee.r0, (52u + this.ee.s1.UL0)); + // @00124ECC BC1T $00124f84 + if (this.ee.fcr31_23) + { + this.ee.pc = 1200004u; + } + // @00124ED0 SW zero, $0038(s1) + MobUt.SW(this.ee, this.ee.r0, (56u + this.ee.s1.UL0)); + } + + public virtual void funct00124e7c() + { + this.ee.pc = 1199828u; + // @00124E7C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00124E80 NEG.S $f0, $f20 + this.ee.fpr[0].f = (0 - this.ee.fpr[20].f); + // @00124E84 ADDIU t7, t7, $81f0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); + // @00124E88 LWC1 $f1, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.s1.UL0)); + // @00124E8C LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @00124E90 C.EQ.S $f25, $f1 + this.ee.fcr31_23 = (this.ee.fpr[25].f == this.ee.fpr[1].f); + // @00124E94 SWC1 $f2, $003c(s1) + MobUt.SWC1(this.ee, this.ee.fpr[2], (60u + this.ee.s1.UL0)); + // @00124E98 SWC1 $f0, $0010(s1) + MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.s1.UL0)); + // @00124E9C SWC1 $f21, $0000(s1) + MobUt.SWC1(this.ee, this.ee.fpr[21], (0u + this.ee.s1.UL0)); + // @00124EA0 SWC1 $f20, $0004(s1) + MobUt.SWC1(this.ee, this.ee.fpr[20], (4u + this.ee.s1.UL0)); + // @00124EA4 SW zero, $000c(s1) + MobUt.SW(this.ee, this.ee.r0, (12u + this.ee.s1.UL0)); + // @00124EA8 SWC1 $f21, $0014(s1) + MobUt.SWC1(this.ee, this.ee.fpr[21], (20u + this.ee.s1.UL0)); + // @00124EAC SW zero, $0018(s1) + MobUt.SW(this.ee, this.ee.r0, (24u + this.ee.s1.UL0)); + // @00124EB0 SW zero, $001c(s1) + MobUt.SW(this.ee, this.ee.r0, (28u + this.ee.s1.UL0)); + // @00124EB4 SW zero, $0020(s1) + MobUt.SW(this.ee, this.ee.r0, (32u + this.ee.s1.UL0)); + // @00124EB8 SW zero, $0024(s1) + MobUt.SW(this.ee, this.ee.r0, (36u + this.ee.s1.UL0)); + // @00124EBC SWC1 $f2, $0028(s1) + MobUt.SWC1(this.ee, this.ee.fpr[2], (40u + this.ee.s1.UL0)); + // @00124EC0 SW zero, $002c(s1) + MobUt.SW(this.ee, this.ee.r0, (44u + this.ee.s1.UL0)); + // @00124EC4 SW zero, $0030(s1) + MobUt.SW(this.ee, this.ee.r0, (48u + this.ee.s1.UL0)); + // @00124EC8 SW zero, $0034(s1) + MobUt.SW(this.ee, this.ee.r0, (52u + this.ee.s1.UL0)); + // @00124ECC BC1T $00124f84 + if (this.ee.fcr31_23) + { + this.ee.pc = 1200004u; + } + // @00124ED0 SW zero, $0038(s1) + MobUt.SW(this.ee, this.ee.r0, (56u + this.ee.s1.UL0)); + } + + public virtual void funct00124ed4() + { + this.ee.pc = 1199840u; + // @00124ED4 ADDIU s0, sp, $0070 + this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 112))); + // @00124ED8 JAL $0011b420 + this.ee.ra.UL0 = 1199840u; + this.ee.pc = 1160224u; + // @00124EDC DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00124ee0() + { + this.ee.pc = 1199852u; + // @00124EE0 MOV.S $f12, $f25 + this.ee.fpr[12].f = this.ee.fpr[25].f; + // @00124EE4 JAL $0011b450 + this.ee.ra.UL0 = 1199852u; + this.ee.pc = 1160272u; + // @00124EE8 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00124eec() + { + this.ee.pc = 1199972u; + // @00124EEC LQC2 vf1, $0000(s1) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s1.UL0)); + // @00124EF0 LQC2 vf2, $0010(s1) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s1.UL0)); + // @00124EF4 LQC2 vf3, $0020(s1) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s1.UL0)); + // @00124EF8 LQC2 vf4, $0030(s1) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s1.UL0)); + // @00124EFC LQC2 vf5, $0000(s0) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s0.UL0)); + // @00124F00 LQC2 vf6, $0010(s0) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.s0.UL0)); + // @00124F04 LQC2 vf7, $0020(s0) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.s0.UL0)); + // @00124F08 LQC2 vf8, $0030(s0) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.s0.UL0)); + // @00124F0C VMULAx.xyzw ACC, vf1, vf5x + // @00124F10 VMADDAy.xyzw ACC, vf2, vf5y + // @00124F14 VMADDAz.xyzw ACC, vf3, vf5z + // @00124F18 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @00124F1C VMULAx.xyzw ACC, vf1, vf6x + // @00124F20 VMADDAy.xyzw ACC, vf2, vf6y + // @00124F24 VMADDAz.xyzw ACC, vf3, vf6z + // @00124F28 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @00124F2C VMULAx.xyzw ACC, vf1, vf7x + // @00124F30 VMADDAy.xyzw ACC, vf2, vf7y + // @00124F34 VMADDAz.xyzw ACC, vf3, vf7z + // @00124F38 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @00124F3C VMULAx.xyzw ACC, vf1, vf8x + // @00124F40 VMADDAy.xyzw ACC, vf2, vf8y + // @00124F44 VMADDAz.xyzw ACC, vf3, vf8z + // @00124F48 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @00124F4C SQC2 vf5, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s2.UL0)); + // @00124F50 SQC2 vf6, $0010(s2) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.s2.UL0)); + // @00124F54 SQC2 vf7, $0020(s2) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.s2.UL0)); + // @00124F58 SQC2 vf8, $0030(s2) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.s2.UL0)); + // @00124F5C BEQL s1, s2, $00124f88 + if ((this.ee.s1.UD0 == this.ee.s2.UD0)) + { + this.ee.pc = 1200008u; + // @00124F60 MUL.S $f2, $f22, $f21 + this.ee.fpr[2].f = (this.ee.fpr[22].f * this.ee.fpr[21].f); + } + } + + public virtual void funct00124f64() + { + this.ee.pc = 1200276u; + // @00124F64 LQ t0, $0000(s2) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); + // @00124F68 LQ t1, $0010(s2) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.s2.UL[0])); + // @00124F6C LQ t2, $0020(s2) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.s2.UL[0])); + // @00124F70 LQ t3, $0030(s2) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.s2.UL[0])); + // @00124F74 SQ t0, $0000(s1) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s1.UL[0])); + // @00124F78 SQ t1, $0010(s1) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s1.UL[0])); + // @00124F7C SQ t2, $0020(s1) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s1.UL[0])); + // @00124F80 SQ t3, $0030(s1) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.s1.UL[0])); + // @00124F84 MUL.S $f2, $f22, $f21 + this.ee.fpr[2].f = (this.ee.fpr[22].f * this.ee.fpr[21].f); + // @00124F88 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00124F8C MUL.S $f1, $f22, $f20 + this.ee.fpr[1].f = (this.ee.fpr[22].f * this.ee.fpr[20].f); + // @00124F90 ADDIU t7, t7, $81f0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); + // @00124F94 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00124F98 SW zero, $00b8(sp) + MobUt.SW(this.ee, this.ee.r0, (184u + this.ee.sp.UL0)); + // @00124F9C ADD.S $f2, $f23, $f2 + this.ee.fpr[2].f = (this.ee.fpr[23].f + this.ee.fpr[2].f); + // @00124FA0 ADDIU t7, sp, $00b0 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 176))); + // @00124FA4 NEG.S $f1, $f1 + this.ee.fpr[1].f = (0 - this.ee.fpr[1].f); + // @00124FA8 SWC1 $f0, $00ec(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (236u + this.ee.sp.UL0)); + // @00124FAC SWC1 $f0, $00d8(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (216u + this.ee.sp.UL0)); + // @00124FB0 MUL.S $f2, $f2, $f24 + this.ee.fpr[2].f = (this.ee.fpr[2].f * this.ee.fpr[24].f); + // @00124FB4 MUL.S $f1, $f1, $f24 + this.ee.fpr[1].f = (this.ee.fpr[1].f * this.ee.fpr[24].f); + // @00124FB8 SW zero, $00bc(sp) + MobUt.SW(this.ee, this.ee.r0, (188u + this.ee.sp.UL0)); + // @00124FBC SW zero, $00c8(sp) + MobUt.SW(this.ee, this.ee.r0, (200u + this.ee.sp.UL0)); + // @00124FC0 MULA.S $f2, $f2 + this.ee.fpracc.f = (this.ee.fpr[2].f * this.ee.fpr[2].f); + // @00124FC4 MADD.S $f0, $f1, $f1 + this.ee.fpr[0].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[1].f, this.ee.fpr[1].f); + // @00124FC8 SW zero, $00cc(sp) + MobUt.SW(this.ee, this.ee.r0, (204u + this.ee.sp.UL0)); + // @00124FCC SW zero, $00d0(sp) + MobUt.SW(this.ee, this.ee.r0, (208u + this.ee.sp.UL0)); + // @00124FD0 SW zero, $00d4(sp) + MobUt.SW(this.ee, this.ee.r0, (212u + this.ee.sp.UL0)); + // @00124FD4 NOP + MobUt.Latency(); + // @00124FD8 NOP + MobUt.Latency(); + // @00124FDC SQRT.S $f0, $f0 + this.ee.fpr[0].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[0].f)))); + // @00124FE0 SW zero, $00dc(sp) + MobUt.SW(this.ee, this.ee.r0, (220u + this.ee.sp.UL0)); + // @00124FE4 SW zero, $00e0(sp) + MobUt.SW(this.ee, this.ee.r0, (224u + this.ee.sp.UL0)); + // @00124FE8 SW zero, $00e4(sp) + MobUt.SW(this.ee, this.ee.r0, (228u + this.ee.sp.UL0)); + // @00124FEC SW zero, $00e8(sp) + MobUt.SW(this.ee, this.ee.r0, (232u + this.ee.sp.UL0)); + // @00124FF0 NOP + MobUt.Latency(); + // @00124FF4 NOP + MobUt.Latency(); + // @00124FF8 DIV.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f / this.ee.fpr[0].f); + // @00124FFC NOP + MobUt.Latency(); + // @00125000 NOP + MobUt.Latency(); + // @00125004 DIV.S $f2, $f2, $f0 + this.ee.fpr[2].f = (this.ee.fpr[2].f / this.ee.fpr[0].f); + // @00125008 NEG.S $f3, $f1 + this.ee.fpr[3].f = (0 - this.ee.fpr[1].f); + // @0012500C SWC1 $f1, $00b4(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (180u + this.ee.sp.UL0)); + // @00125010 SWC1 $f3, $00c0(sp) + MobUt.SWC1(this.ee, this.ee.fpr[3], (192u + this.ee.sp.UL0)); + // @00125014 SWC1 $f2, $00c4(sp) + MobUt.SWC1(this.ee, this.ee.fpr[2], (196u + this.ee.sp.UL0)); + // @00125018 SWC1 $f2, $00b0(sp) + MobUt.SWC1(this.ee, this.ee.fpr[2], (176u + this.ee.sp.UL0)); + // @0012501C LQC2 vf1, $0000(s3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); + // @00125020 LQC2 vf2, $0010(s3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); + // @00125024 LQC2 vf3, $0020(s3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); + // @00125028 LQC2 vf4, $0030(s3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); + // @0012502C LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @00125030 LQC2 vf6, $0010(t7) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); + // @00125034 LQC2 vf7, $0020(t7) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); + // @00125038 LQC2 vf8, $0030(t7) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); + // @0012503C VMULAx.xyzw ACC, vf1, vf5x + // @00125040 VMADDAy.xyzw ACC, vf2, vf5y + // @00125044 VMADDAz.xyzw ACC, vf3, vf5z + // @00125048 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012504C VMULAx.xyzw ACC, vf1, vf6x + // @00125050 VMADDAy.xyzw ACC, vf2, vf6y + // @00125054 VMADDAz.xyzw ACC, vf3, vf6z + // @00125058 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012505C VMULAx.xyzw ACC, vf1, vf7x + // @00125060 VMADDAy.xyzw ACC, vf2, vf7y + // @00125064 VMADDAz.xyzw ACC, vf3, vf7z + // @00125068 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012506C VMULAx.xyzw ACC, vf1, vf8x + // @00125070 VMADDAy.xyzw ACC, vf2, vf8y + // @00125074 VMADDAz.xyzw ACC, vf3, vf8z + // @00125078 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012507C SQC2 vf5, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s2.UL0)); + // @00125080 SQC2 vf6, $0010(s2) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.s2.UL0)); + // @00125084 SQC2 vf7, $0020(s2) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.s2.UL0)); + // @00125088 SQC2 vf8, $0030(s2) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.s2.UL0)); + // @0012508C BEQL s4, s2, $00124dcc + if ((this.ee.s4.UD0 == this.ee.s2.UD0)) + { + this.ee.pc = 1199564u; + // @00125090 LD s0, $0140(sp) + MobUt.LD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); + } + } + + public virtual void funct00124f84() + { + this.ee.pc = 1200276u; + // @00124F84 MUL.S $f2, $f22, $f21 + this.ee.fpr[2].f = (this.ee.fpr[22].f * this.ee.fpr[21].f); + // @00124F88 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00124F8C MUL.S $f1, $f22, $f20 + this.ee.fpr[1].f = (this.ee.fpr[22].f * this.ee.fpr[20].f); + // @00124F90 ADDIU t7, t7, $81f0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32272))); + // @00124F94 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00124F98 SW zero, $00b8(sp) + MobUt.SW(this.ee, this.ee.r0, (184u + this.ee.sp.UL0)); + // @00124F9C ADD.S $f2, $f23, $f2 + this.ee.fpr[2].f = (this.ee.fpr[23].f + this.ee.fpr[2].f); + // @00124FA0 ADDIU t7, sp, $00b0 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 176))); + // @00124FA4 NEG.S $f1, $f1 + this.ee.fpr[1].f = (0 - this.ee.fpr[1].f); + // @00124FA8 SWC1 $f0, $00ec(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (236u + this.ee.sp.UL0)); + // @00124FAC SWC1 $f0, $00d8(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (216u + this.ee.sp.UL0)); + // @00124FB0 MUL.S $f2, $f2, $f24 + this.ee.fpr[2].f = (this.ee.fpr[2].f * this.ee.fpr[24].f); + // @00124FB4 MUL.S $f1, $f1, $f24 + this.ee.fpr[1].f = (this.ee.fpr[1].f * this.ee.fpr[24].f); + // @00124FB8 SW zero, $00bc(sp) + MobUt.SW(this.ee, this.ee.r0, (188u + this.ee.sp.UL0)); + // @00124FBC SW zero, $00c8(sp) + MobUt.SW(this.ee, this.ee.r0, (200u + this.ee.sp.UL0)); + // @00124FC0 MULA.S $f2, $f2 + this.ee.fpracc.f = (this.ee.fpr[2].f * this.ee.fpr[2].f); + // @00124FC4 MADD.S $f0, $f1, $f1 + this.ee.fpr[0].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[1].f, this.ee.fpr[1].f); + // @00124FC8 SW zero, $00cc(sp) + MobUt.SW(this.ee, this.ee.r0, (204u + this.ee.sp.UL0)); + // @00124FCC SW zero, $00d0(sp) + MobUt.SW(this.ee, this.ee.r0, (208u + this.ee.sp.UL0)); + // @00124FD0 SW zero, $00d4(sp) + MobUt.SW(this.ee, this.ee.r0, (212u + this.ee.sp.UL0)); + // @00124FD4 NOP + MobUt.Latency(); + // @00124FD8 NOP + MobUt.Latency(); + // @00124FDC SQRT.S $f0, $f0 + this.ee.fpr[0].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[0].f)))); + // @00124FE0 SW zero, $00dc(sp) + MobUt.SW(this.ee, this.ee.r0, (220u + this.ee.sp.UL0)); + // @00124FE4 SW zero, $00e0(sp) + MobUt.SW(this.ee, this.ee.r0, (224u + this.ee.sp.UL0)); + // @00124FE8 SW zero, $00e4(sp) + MobUt.SW(this.ee, this.ee.r0, (228u + this.ee.sp.UL0)); + // @00124FEC SW zero, $00e8(sp) + MobUt.SW(this.ee, this.ee.r0, (232u + this.ee.sp.UL0)); + // @00124FF0 NOP + MobUt.Latency(); + // @00124FF4 NOP + MobUt.Latency(); + // @00124FF8 DIV.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f / this.ee.fpr[0].f); + // @00124FFC NOP + MobUt.Latency(); + // @00125000 NOP + MobUt.Latency(); + // @00125004 DIV.S $f2, $f2, $f0 + this.ee.fpr[2].f = (this.ee.fpr[2].f / this.ee.fpr[0].f); + // @00125008 NEG.S $f3, $f1 + this.ee.fpr[3].f = (0 - this.ee.fpr[1].f); + // @0012500C SWC1 $f1, $00b4(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (180u + this.ee.sp.UL0)); + // @00125010 SWC1 $f3, $00c0(sp) + MobUt.SWC1(this.ee, this.ee.fpr[3], (192u + this.ee.sp.UL0)); + // @00125014 SWC1 $f2, $00c4(sp) + MobUt.SWC1(this.ee, this.ee.fpr[2], (196u + this.ee.sp.UL0)); + // @00125018 SWC1 $f2, $00b0(sp) + MobUt.SWC1(this.ee, this.ee.fpr[2], (176u + this.ee.sp.UL0)); + // @0012501C LQC2 vf1, $0000(s3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); + // @00125020 LQC2 vf2, $0010(s3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); + // @00125024 LQC2 vf3, $0020(s3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); + // @00125028 LQC2 vf4, $0030(s3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); + // @0012502C LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @00125030 LQC2 vf6, $0010(t7) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); + // @00125034 LQC2 vf7, $0020(t7) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); + // @00125038 LQC2 vf8, $0030(t7) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); + // @0012503C VMULAx.xyzw ACC, vf1, vf5x + // @00125040 VMADDAy.xyzw ACC, vf2, vf5y + // @00125044 VMADDAz.xyzw ACC, vf3, vf5z + // @00125048 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012504C VMULAx.xyzw ACC, vf1, vf6x + // @00125050 VMADDAy.xyzw ACC, vf2, vf6y + // @00125054 VMADDAz.xyzw ACC, vf3, vf6z + // @00125058 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012505C VMULAx.xyzw ACC, vf1, vf7x + // @00125060 VMADDAy.xyzw ACC, vf2, vf7y + // @00125064 VMADDAz.xyzw ACC, vf3, vf7z + // @00125068 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012506C VMULAx.xyzw ACC, vf1, vf8x + // @00125070 VMADDAy.xyzw ACC, vf2, vf8y + // @00125074 VMADDAz.xyzw ACC, vf3, vf8z + // @00125078 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012507C SQC2 vf5, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s2.UL0)); + // @00125080 SQC2 vf6, $0010(s2) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.s2.UL0)); + // @00125084 SQC2 vf7, $0020(s2) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.s2.UL0)); + // @00125088 SQC2 vf8, $0030(s2) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.s2.UL0)); + // @0012508C BEQL s4, s2, $00124dcc + if ((this.ee.s4.UD0 == this.ee.s2.UD0)) + { + this.ee.pc = 1199564u; + // @00125090 LD s0, $0140(sp) + MobUt.LD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); + } + } + + public virtual void funct00125094() + { + this.ee.pc = 1200316u; + // @00125094 LQ t0, $0000(s2) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); + // @00125098 LQ t1, $0010(s2) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.s2.UL[0])); + // @0012509C LQ t2, $0020(s2) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.s2.UL[0])); + // @001250A0 LQ t3, $0030(s2) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.s2.UL[0])); + // @001250A4 SQ t0, $0000(s4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s4.UL[0])); + // @001250A8 SQ t1, $0010(s4) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s4.UL[0])); + // @001250AC SQ t2, $0020(s4) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s4.UL[0])); + // @001250B0 SQ t3, $0030(s4) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.s4.UL[0])); + // @001250B4 BEQ zero, zero, $00124dcc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1199564u; + } + // @001250B8 LD s0, $0140(sp) + MobUt.LD(this.ee, this.ee.s0, (320u + this.ee.sp.UL0)); + } + + public virtual void funct001250bc() + { + this.ee.pc = 1200336u; + // @001250BC NOP + MobUt.Latency(); + // @001250C0 NOP + MobUt.Latency(); + // @001250C4 SQRT.S $f20, $f20 + this.ee.fpr[20].f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.fpr[20].f)))); + // @001250C8 BEQ zero, zero, $00124e7c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1199740u; + } + // @001250CC SW zero, $0008(s1) + MobUt.SW(this.ee, this.ee.r0, (8u + this.ee.s1.UL0)); + } + + public virtual void funct001250d0() + { + this.ee.pc = 1200356u; + // @001250D0 ADDIU t7, t7, $81f4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32268))); + // @001250D4 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @001250D8 C.LT.S $f21, $f0 + this.ee.fcr31_23 = (this.ee.fpr[21].f < this.ee.fpr[0].f); + // @001250DC BC1TL $00124e3c + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1199676u; + // @001250E0 MOV.S $f21, $f0 + this.ee.fpr[21].f = this.ee.fpr[0].f; + } + } + + public virtual void funct001250e4() + { + this.ee.pc = 1200364u; + // @001250E4 BEQ zero, zero, $00124e40 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1199680u; + } + // @001250E8 MUL.S $f1, $f21, $f21 + this.ee.fpr[1].f = (this.ee.fpr[21].f * this.ee.fpr[21].f); + } + + public virtual void funct001250ec() + { + this.ee.pc = 1200472u; + // @001250EC SWC1 $f1, $0018(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (24u + this.ee.sp.UL0)); + // @001250F0 NEG.S $f0, $f0 + this.ee.fpr[0].f = (0 - this.ee.fpr[0].f); + // @001250F4 LWC1 $f1, $0000(sp) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.sp.UL0)); + // @001250F8 SWC1 $f1, $0014(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (20u + this.ee.sp.UL0)); + // @001250FC SWC1 $f0, $0010(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.sp.UL0)); + // @00125100 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00125104 VMUL.xyz vf2, vf1, vf1 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); + // @00125108 VADDy.x vf2, vf2, vf2y + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); + // @0012510C VADDz.x vf2, vf2, vf2z + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); + // @00125110 VSQRT Q, vf2x + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); + // @00125114 VWAITQ + MobUt.Latency(); + // @00125118 CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + // @0012511C VADDq.x vf2, vf0, Q + this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); + // @00125120 MTC1 t0, $f1 + this.ee.fpr[1].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00125124 VNOP + MobUt.Latency(); + // @00125128 VDIV Q, vf0w, vf2x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); + // @0012512C VWAITQ + MobUt.Latency(); + // @00125130 VMULq.xyz vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + // @00125134 SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00125138 LQC2 vf1, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @0012513C LQC2 vf2, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); + // @00125140 VSUB.xyzw vf3, vf0, vf0 + this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); + this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); + this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); + this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); + // @00125144 VOPMULA.xyz ACC, vf1, vf2 + this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); + this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); + this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); + // @00125148 VOPMSUB.xyz vf3, vf2, vf1 + this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); + this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); + this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); + // @0012514C SQC2 vf3, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.s2.UL0)); + // @00125150 BEQ t5, s2, $00125160 + if ((this.ee.t5.UD0 == this.ee.s2.UD0)) + { + this.ee.pc = 1200480u; + } + // @00125154 NOP + MobUt.Latency(); + } + + public virtual void funct00125158() + { + this.ee.pc = 1200544u; + // @00125158 LQ t0, $0000(s2) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); + // @0012515C SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @00125160 LQC2 vf1, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); + // @00125164 VMUL.xyz vf2, vf1, vf1 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); + // @00125168 VADDy.x vf2, vf2, vf2y + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); + // @0012516C VADDz.x vf2, vf2, vf2z + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); + // @00125170 VSQRT Q, vf2x + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); + // @00125174 VWAITQ + MobUt.Latency(); + // @00125178 CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + // @0012517C VADDq.x vf2, vf0, Q + this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); + // @00125180 MTC1 t0, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00125184 VNOP + MobUt.Latency(); + // @00125188 VDIV Q, vf0w, vf2x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); + // @0012518C VWAITQ + MobUt.Latency(); + // @00125190 VMULq.xyz vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + // @00125194 SQC2 vf1, $0000(t5) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); + // @00125198 BEQ zero, zero, $00124c98 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1199256u; + } + // @0012519C ADDIU s3, sp, $0030 + this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 48))); + } + + public virtual void funct00127e20() + { + this.ee.pc = 1212020u; + // @00127E20 ADDIU sp, sp, $ff60 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -160))); + // @00127E24 DADDU v0, zero, zero + this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00127E28 SD s1, $0048(sp) + MobUt.SD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); + // @00127E2C SD s3, $0058(sp) + MobUt.SD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); + // @00127E30 SD s0, $0040(sp) + MobUt.SD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); + // @00127E34 DADDU s1, a1, zero + this.ee.s1.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + // @00127E38 SD s2, $0050(sp) + MobUt.SD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); + // @00127E3C SD s4, $0060(sp) + MobUt.SD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); + // @00127E40 SD s5, $0068(sp) + MobUt.SD(this.ee, this.ee.s5, (104u + this.ee.sp.UL0)); + // @00127E44 SD s6, $0070(sp) + MobUt.SD(this.ee, this.ee.s6, (112u + this.ee.sp.UL0)); + // @00127E48 SD s7, $0078(sp) + MobUt.SD(this.ee, this.ee.s7, (120u + this.ee.sp.UL0)); + // @00127E4C SD s8, $0080(sp) + MobUt.SD(this.ee, this.ee.s8, (128u + this.ee.sp.UL0)); + // @00127E50 SD ra, $0088(sp) + MobUt.SD(this.ee, this.ee.ra, (136u + this.ee.sp.UL0)); + // @00127E54 SWC1 $f23, $009c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[23], (156u + this.ee.sp.UL0)); + // @00127E58 SWC1 $f22, $0098(sp) + MobUt.SWC1(this.ee, this.ee.fpr[22], (152u + this.ee.sp.UL0)); + // @00127E5C SWC1 $f21, $0094(sp) + MobUt.SWC1(this.ee, this.ee.fpr[21], (148u + this.ee.sp.UL0)); + // @00127E60 SWC1 $f20, $0090(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (144u + this.ee.sp.UL0)); + // @00127E64 LD t6, $0000(a1) + MobUt.LD(this.ee, this.ee.t6, (0u + this.ee.a1.UL0)); + // @00127E68 ANDI t7, t6, $0007 + this.ee.t7.UD0 = ((ushort)((this.ee.t6.US0 & 7))); + // @00127E6C BEQ t7, zero, $00128254 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213012u; + } + // @00127E70 DADDU s3, a3, zero + this.ee.s3.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00127e74() + { + this.ee.pc = 1212032u; + // @00127E74 ANDI t7, t6, $0008 + this.ee.t7.UD0 = ((ushort)((this.ee.t6.US0 & 8))); + // @00127E78 BNE t7, zero, $00128254 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1213012u; + } + // @00127E7C NOP + MobUt.Latency(); + } + + public virtual void funct00127e80() + { + this.ee.pc = 1212040u; + // @00127E80 BEQ sp, a2, $00127e94 + if ((this.ee.sp.UD0 == this.ee.a2.UD0)) + { + this.ee.pc = 1212052u; + } + // @00127E84 ADDIU s2, sp, $0010 + this.ee.s2.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00127e88() + { + this.ee.pc = 1212080u; + // @00127E88 LQ t0, $0000(a2) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a2.UL[0])); + // @00127E8C SQ t0, $0000(sp) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); + // @00127E90 ADDIU s2, sp, $0010 + this.ee.s2.SD0 = ((int)((this.ee.sp.SD0 + 16))); + // @00127E94 ADDIU s0, sp, $0020 + this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 32))); + // @00127E98 LQC2 vf1, $0000(s3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); + // @00127E9C LQC2 vf2, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.sp.UL0)); + // @00127EA0 VSUB.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); + // @00127EA4 SQC2 vf1, $0000(s0) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s0.UL0)); + // @00127EA8 BEQL s2, s0, $00127ebc + if ((this.ee.s2.UD0 == this.ee.s0.UD0)) + { + this.ee.pc = 1212092u; + // @00127EAC LD t3, $0000(s1) + MobUt.LD(this.ee, this.ee.t3, (0u + this.ee.s1.UL0)); + } + } + + public virtual void funct00127e94() + { + this.ee.pc = 1212080u; + // @00127E94 ADDIU s0, sp, $0020 + this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 32))); + // @00127E98 LQC2 vf1, $0000(s3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); + // @00127E9C LQC2 vf2, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.sp.UL0)); + // @00127EA0 VSUB.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); + // @00127EA4 SQC2 vf1, $0000(s0) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s0.UL0)); + // @00127EA8 BEQL s2, s0, $00127ebc + if ((this.ee.s2.UD0 == this.ee.s0.UD0)) + { + this.ee.pc = 1212092u; + // @00127EAC LD t3, $0000(s1) + MobUt.LD(this.ee, this.ee.t3, (0u + this.ee.s1.UL0)); + } + } + + public virtual void funct00127eb0() + { + this.ee.pc = 1212108u; + // @00127EB0 LQ t0, $0000(s0) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s0.UL[0])); + // @00127EB4 SQ t0, $0000(s2) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); + // @00127EB8 LD t3, $0000(s1) + MobUt.LD(this.ee, this.ee.t3, (0u + this.ee.s1.UL0)); + // @00127EBC ADDIU t7, zero, $0001 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @00127EC0 ANDI t6, t3, $0007 + this.ee.t6.UD0 = ((ushort)((this.ee.t3.US0 & 7))); + // @00127EC4 BNEL t6, t7, $00128020 + if ((this.ee.t6.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1212448u; + // @00127EC8 LWC1 $f1, $000c(s1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (12u + this.ee.s1.UL0)); + } + } + + public virtual void funct00127ecc() + { + this.ee.pc = 1212164u; + // @00127ECC LWC1 $f21, $0010(s1) + MobUt.LWC1(this.ee, this.ee.fpr[21], (16u + this.ee.s1.UL0)); + // @00127ED0 LQC2 vf1, $0000(s2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); + // @00127ED4 VMUL.xyz vf1, vf1, vf1 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); + // @00127ED8 VADDy.x vf1, vf1, vf1y + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); + // @00127EDC VADDz.x vf1, vf1, vf1z + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); + // @00127EE0 VSQRT Q, vf1x + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[1].x)))); + // @00127EE4 VWAITQ + MobUt.Latency(); + // @00127EE8 CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + // @00127EEC MTC1 t0, $f2 + this.ee.fpr[2].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00127EF0 LWC1 $f12, $000c(s1) + MobUt.LWC1(this.ee, this.ee.fpr[12], (12u + this.ee.s1.UL0)); + // @00127EF4 MTC1 zero, $f3 + this.ee.fpr[3].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @00127EF8 C.EQ.S $f12, $f3 + this.ee.fcr31_23 = (this.ee.fpr[12].f == this.ee.fpr[3].f); + // @00127EFC BC1F $00127fd0 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1212368u; + } + // @00127F00 MOV.S $f1, $f2 + this.ee.fpr[1].f = this.ee.fpr[2].f; + } + + public virtual void funct00127f04() + { + this.ee.pc = 1212176u; + // @00127F04 C.LT.S $f21, $f2 + this.ee.fcr31_23 = (this.ee.fpr[21].f < this.ee.fpr[2].f); + // @00127F08 BC1F $00127f84 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1212292u; + } + // @00127F0C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct00127f10() + { + this.ee.pc = 1212276u; + // @00127F10 LQC2 vf1, $0000(s2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); + // @00127F14 VMUL.xyz vf2, vf1, vf1 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); + // @00127F18 VADDy.x vf2, vf2, vf2y + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); + // @00127F1C VADDz.x vf2, vf2, vf2z + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); + // @00127F20 VSQRT Q, vf2x + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); + // @00127F24 VWAITQ + MobUt.Latency(); + // @00127F28 CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + // @00127F2C VADDq.x vf2, vf0, Q + this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); + // @00127F30 MTC1 t0, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00127F34 VNOP + MobUt.Latency(); + // @00127F38 VDIV Q, vf0w, vf2x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); + // @00127F3C VWAITQ + MobUt.Latency(); + // @00127F40 VMULq.xyz vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + // @00127F44 SQC2 vf1, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); + // @00127F48 LQC2 vf1, $0000(s2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); + // @00127F4C MFC1 t0, $f1 + MobUt.MFC1(this.ee.t0, this.ee.fpr[1]); + // @00127F50 QMTC2 t0, vf2 + MobUt.QMTC2(this.ee.t0, this.ee.VF[2]); + // @00127F54 VMULx.xyzw vf1, vf1, vf2x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].x); + // @00127F58 SQC2 vf1, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); + // @00127F5C LQC2 vf1, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @00127F60 LQC2 vf2, $0000(s2) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.s2.UL0)); + // @00127F64 VADD.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y + this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z + this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w + this.ee.VF[2].w); + // @00127F68 SQC2 vf1, $0000(s0) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s0.UL0)); + // @00127F6C BEQ s3, s0, $00127f80 + if ((this.ee.s3.UD0 == this.ee.s0.UD0)) + { + this.ee.pc = 1212288u; + } + // @00127F70 ADDIU v0, zero, $0001 + this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); + } + + public virtual void funct00127f74() + { + this.ee.pc = 1212368u; + // @00127F74 LQ t0, $0000(s0) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s0.UL[0])); + // @00127F78 SQ t0, $0000(s3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @00127F7C ADDIU v0, zero, $0001 + this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @00127F80 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00127F84 LD s0, $0040(sp) + MobUt.LD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); + // @00127F88 ADDIU t7, t7, $8214 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32236))); + // @00127F8C LD s1, $0048(sp) + MobUt.LD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); + // @00127F90 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00127F94 LD s2, $0050(sp) + MobUt.LD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); + // @00127F98 SWC1 $f0, $000c(s3) + MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.s3.UL0)); + // @00127F9C LD s4, $0060(sp) + MobUt.LD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); + // @00127FA0 LD s3, $0058(sp) + MobUt.LD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); + // @00127FA4 LD s5, $0068(sp) + MobUt.LD(this.ee, this.ee.s5, (104u + this.ee.sp.UL0)); + // @00127FA8 LD s6, $0070(sp) + MobUt.LD(this.ee, this.ee.s6, (112u + this.ee.sp.UL0)); + // @00127FAC LD s7, $0078(sp) + MobUt.LD(this.ee, this.ee.s7, (120u + this.ee.sp.UL0)); + // @00127FB0 LD s8, $0080(sp) + MobUt.LD(this.ee, this.ee.s8, (128u + this.ee.sp.UL0)); + // @00127FB4 LD ra, $0088(sp) + MobUt.LD(this.ee, this.ee.ra, (136u + this.ee.sp.UL0)); + // @00127FB8 LWC1 $f23, $009c(sp) + MobUt.LWC1(this.ee, this.ee.fpr[23], (156u + this.ee.sp.UL0)); + // @00127FBC LWC1 $f22, $0098(sp) + MobUt.LWC1(this.ee, this.ee.fpr[22], (152u + this.ee.sp.UL0)); + // @00127FC0 LWC1 $f21, $0094(sp) + MobUt.LWC1(this.ee, this.ee.fpr[21], (148u + this.ee.sp.UL0)); + // @00127FC4 LWC1 $f20, $0090(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (144u + this.ee.sp.UL0)); + // @00127FC8 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00127FCC ADDIU sp, sp, $00a0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 160))); + } + + public virtual void funct00127f80() + { + this.ee.pc = 1212368u; + // @00127F80 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00127F84 LD s0, $0040(sp) + MobUt.LD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); + // @00127F88 ADDIU t7, t7, $8214 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32236))); + // @00127F8C LD s1, $0048(sp) + MobUt.LD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); + // @00127F90 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00127F94 LD s2, $0050(sp) + MobUt.LD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); + // @00127F98 SWC1 $f0, $000c(s3) + MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.s3.UL0)); + // @00127F9C LD s4, $0060(sp) + MobUt.LD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); + // @00127FA0 LD s3, $0058(sp) + MobUt.LD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); + // @00127FA4 LD s5, $0068(sp) + MobUt.LD(this.ee, this.ee.s5, (104u + this.ee.sp.UL0)); + // @00127FA8 LD s6, $0070(sp) + MobUt.LD(this.ee, this.ee.s6, (112u + this.ee.sp.UL0)); + // @00127FAC LD s7, $0078(sp) + MobUt.LD(this.ee, this.ee.s7, (120u + this.ee.sp.UL0)); + // @00127FB0 LD s8, $0080(sp) + MobUt.LD(this.ee, this.ee.s8, (128u + this.ee.sp.UL0)); + // @00127FB4 LD ra, $0088(sp) + MobUt.LD(this.ee, this.ee.ra, (136u + this.ee.sp.UL0)); + // @00127FB8 LWC1 $f23, $009c(sp) + MobUt.LWC1(this.ee, this.ee.fpr[23], (156u + this.ee.sp.UL0)); + // @00127FBC LWC1 $f22, $0098(sp) + MobUt.LWC1(this.ee, this.ee.fpr[22], (152u + this.ee.sp.UL0)); + // @00127FC0 LWC1 $f21, $0094(sp) + MobUt.LWC1(this.ee, this.ee.fpr[21], (148u + this.ee.sp.UL0)); + // @00127FC4 LWC1 $f20, $0090(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (144u + this.ee.sp.UL0)); + // @00127FC8 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00127FCC ADDIU sp, sp, $00a0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 160))); + } + + public virtual void funct00127f84() + { + this.ee.pc = 1212368u; + // @00127F84 LD s0, $0040(sp) + MobUt.LD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); + // @00127F88 ADDIU t7, t7, $8214 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32236))); + // @00127F8C LD s1, $0048(sp) + MobUt.LD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); + // @00127F90 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00127F94 LD s2, $0050(sp) + MobUt.LD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); + // @00127F98 SWC1 $f0, $000c(s3) + MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.s3.UL0)); + // @00127F9C LD s4, $0060(sp) + MobUt.LD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); + // @00127FA0 LD s3, $0058(sp) + MobUt.LD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); + // @00127FA4 LD s5, $0068(sp) + MobUt.LD(this.ee, this.ee.s5, (104u + this.ee.sp.UL0)); + // @00127FA8 LD s6, $0070(sp) + MobUt.LD(this.ee, this.ee.s6, (112u + this.ee.sp.UL0)); + // @00127FAC LD s7, $0078(sp) + MobUt.LD(this.ee, this.ee.s7, (120u + this.ee.sp.UL0)); + // @00127FB0 LD s8, $0080(sp) + MobUt.LD(this.ee, this.ee.s8, (128u + this.ee.sp.UL0)); + // @00127FB4 LD ra, $0088(sp) + MobUt.LD(this.ee, this.ee.ra, (136u + this.ee.sp.UL0)); + // @00127FB8 LWC1 $f23, $009c(sp) + MobUt.LWC1(this.ee, this.ee.fpr[23], (156u + this.ee.sp.UL0)); + // @00127FBC LWC1 $f22, $0098(sp) + MobUt.LWC1(this.ee, this.ee.fpr[22], (152u + this.ee.sp.UL0)); + // @00127FC0 LWC1 $f21, $0094(sp) + MobUt.LWC1(this.ee, this.ee.fpr[21], (148u + this.ee.sp.UL0)); + // @00127FC4 LWC1 $f20, $0090(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (144u + this.ee.sp.UL0)); + // @00127FC8 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00127FCC ADDIU sp, sp, $00a0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 160))); + } + + public virtual void funct00127fd0() + { + this.ee.pc = 1212392u; + // @00127FD0 LWC1 $f1, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.s1.UL0)); + // @00127FD4 SUB.S $f0, $f21, $f1 + this.ee.fpr[0].f = (this.ee.fpr[21].f - this.ee.fpr[1].f); + // @00127FD8 SUB.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f - this.ee.fpr[0].f); + // @00127FDC C.LT.S $f3, $f0 + this.ee.fcr31_23 = (this.ee.fpr[3].f < this.ee.fpr[0].f); + // @00127FE0 BC1F $00127f80 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1212288u; + } + // @00127FE4 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct00127fe8() + { + this.ee.pc = 1212424u; + // @00127FE8 NOP + MobUt.Latency(); + // @00127FEC NOP + MobUt.Latency(); + // @00127FF0 DIV.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); + // @00127FF4 ADDIU t7, t7, $8214 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32236))); + // @00127FF8 LWC1 $f20, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[20], (0u + this.ee.t7.UL0)); + // @00127FFC SUB.S $f12, $f12, $f20 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[20].f); + // @00128000 JAL $002ff8d8 + this.ee.ra.UL0 = 1212424u; + this.ee.pc = 3143896u; + // @00128004 MUL.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f * this.ee.fpr[0].f); + } + + public virtual void funct00128008() + { + this.ee.pc = 1212448u; + // @00128008 SUB.S $f20, $f20, $f0 + this.ee.fpr[20].f = (this.ee.fpr[20].f - this.ee.fpr[0].f); + // @0012800C LWC1 $f0, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.s1.UL0)); + // @00128010 SUB.S $f1, $f21, $f0 + this.ee.fpr[1].f = (this.ee.fpr[21].f - this.ee.fpr[0].f); + // @00128014 MUL.S $f0, $f0, $f20 + this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[20].f); + // @00128018 BEQ zero, zero, $00127f10 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212176u; + } + // @0012801C ADD.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); + } + + public virtual void funct00128020() + { + this.ee.pc = 1212556u; + // @00128020 DSRL t2, t3, 9 + MobUt.DSRL(this.ee.t2, this.ee.t3, 9); + // @00128024 DSRL t7, t3, 4 + MobUt.DSRL(this.ee.t7, this.ee.t3, 4); + // @00128028 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @0012802C DSRL t6, t3, 5 + MobUt.DSRL(this.ee.t6, this.ee.t3, 5); + // @00128030 DSRL t5, t3, 6 + MobUt.DSRL(this.ee.t5, this.ee.t3, 6); + // @00128034 DSRL t4, t3, 7 + MobUt.DSRL(this.ee.t4, this.ee.t3, 7); + // @00128038 C.EQ.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f == this.ee.fpr[0].f); + // @0012803C DSRL t3, t3, 8 + MobUt.DSRL(this.ee.t3, this.ee.t3, 8); + // @00128040 ANDI t7, t7, $00ff + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 255))); + // @00128044 ANDI t6, t6, $00ff + this.ee.t6.UD0 = ((ushort)((this.ee.t6.US0 & 255))); + // @00128048 ANDI t5, t5, $00ff + this.ee.t5.UD0 = ((ushort)((this.ee.t5.US0 & 255))); + // @0012804C ANDI t4, t4, $00ff + this.ee.t4.UD0 = ((ushort)((this.ee.t4.US0 & 255))); + // @00128050 ANDI t3, t3, $00ff + this.ee.t3.UD0 = ((ushort)((this.ee.t3.US0 & 255))); + // @00128054 ANDI t2, t2, $00ff + this.ee.t2.UD0 = ((ushort)((this.ee.t2.US0 & 255))); + // @00128058 ANDI t7, t7, $0001 + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 1))); + // @0012805C ANDI t6, t6, $0001 + this.ee.t6.UD0 = ((ushort)((this.ee.t6.US0 & 1))); + // @00128060 SB t7, $0020(sp) + MobUt.SB(this.ee, this.ee.t7, (32u + this.ee.sp.UL0)); + // @00128064 ANDI t5, t5, $0001 + this.ee.t5.UD0 = ((ushort)((this.ee.t5.US0 & 1))); + // @00128068 SB t6, $0021(sp) + MobUt.SB(this.ee, this.ee.t6, (33u + this.ee.sp.UL0)); + // @0012806C ANDI t4, t4, $0001 + this.ee.t4.UD0 = ((ushort)((this.ee.t4.US0 & 1))); + // @00128070 SB t5, $0022(sp) + MobUt.SB(this.ee, this.ee.t5, (34u + this.ee.sp.UL0)); + // @00128074 ANDI t3, t3, $0001 + this.ee.t3.UD0 = ((ushort)((this.ee.t3.US0 & 1))); + // @00128078 SB t4, $0023(sp) + MobUt.SB(this.ee, this.ee.t4, (35u + this.ee.sp.UL0)); + // @0012807C ANDI t2, t2, $0001 + this.ee.t2.UD0 = ((ushort)((this.ee.t2.US0 & 1))); + // @00128080 SB t3, $0024(sp) + MobUt.SB(this.ee, this.ee.t3, (36u + this.ee.sp.UL0)); + // @00128084 BC1F $00128118 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1212696u; + } + // @00128088 SB t2, $0025(sp) + MobUt.SB(this.ee, this.ee.t2, (37u + this.ee.sp.UL0)); + } + + public virtual void funct0012808c() + { + this.ee.pc = 1212592u; + // @0012808C ADDIU a1, s1, $0020 + this.ee.a1.SD0 = ((int)((this.ee.s1.SD0 + 32))); + // @00128090 DADDU t3, s2, zero + this.ee.t3.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @00128094 DADDU s0, zero, zero + this.ee.s0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00128098 DADDU t4, zero, zero + this.ee.t4.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @0012809C SLL t7, s0, 1 + MobUt.SLL(this.ee.t7, this.ee.s0, 1); + // @001280A0 ADDU t5, t7, sp + this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.sp.SD0))); + // @001280A4 LBU t6, $0020(t5) + MobUt.LBU(this.ee, this.ee.t6, (32u + this.ee.t5.UL0)); + // @001280A8 BEQL t6, zero, $001280c8 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212616u; + // @001280AC LBU t7, $0021(t5) + MobUt.LBU(this.ee, this.ee.t7, (33u + this.ee.t5.UL0)); + } + } + + public virtual void funct0012809c() + { + this.ee.pc = 1212592u; + // @0012809C SLL t7, s0, 1 + MobUt.SLL(this.ee.t7, this.ee.s0, 1); + // @001280A0 ADDU t5, t7, sp + this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.sp.SD0))); + // @001280A4 LBU t6, $0020(t5) + MobUt.LBU(this.ee, this.ee.t6, (32u + this.ee.t5.UL0)); + // @001280A8 BEQL t6, zero, $001280c8 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212616u; + // @001280AC LBU t7, $0021(t5) + MobUt.LBU(this.ee, this.ee.t7, (33u + this.ee.t5.UL0)); + } + } + + public virtual void funct001280b0() + { + this.ee.pc = 1212612u; + // @001280B0 LWC1 $f1, $fff0(a1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (4294967280u + this.ee.a1.UL0)); + // @001280B4 LWC1 $f0, $0000(t3) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t3.UL0)); + // @001280B8 C.LT.S $f0, $f1 + this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[1].f); + // @001280BC BC1T $001280e4 + if (this.ee.fcr31_23) + { + this.ee.pc = 1212644u; + } + // @001280C0 ADDU t7, sp, t4 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + this.ee.t4.SD0))); + } + + public virtual void funct001280c4() + { + this.ee.pc = 1212624u; + // @001280C4 LBU t7, $0021(t5) + MobUt.LBU(this.ee, this.ee.t7, (33u + this.ee.t5.UL0)); + // @001280C8 BEQL t7, zero, $001280fc + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212668u; + // @001280CC ADDIU s0, s0, $0001 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); + } + } + + public virtual void funct001280c8() + { + this.ee.pc = 1212624u; + // @001280C8 BEQL t7, zero, $001280fc + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212668u; + // @001280CC ADDIU s0, s0, $0001 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); + } + } + + public virtual void funct001280d0() + { + this.ee.pc = 1212644u; + // @001280D0 LWC1 $f1, $0000(a1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.a1.UL0)); + // @001280D4 LWC1 $f0, $0000(t3) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t3.UL0)); + // @001280D8 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @001280DC BC1F $001280f8 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1212664u; + } + // @001280E0 ADDU t7, sp, t4 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + this.ee.t4.SD0))); + } + + public virtual void funct001280e4() + { + this.ee.pc = 1212688u; + // @001280E4 ADDU t6, s3, t4 + this.ee.t6.SD0 = ((int)((this.ee.s3.SD0 + this.ee.t4.SD0))); + // @001280E8 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @001280EC ADDIU v0, zero, $0001 + this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @001280F0 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @001280F4 SWC1 $f0, $0000(t6) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @001280F8 ADDIU s0, s0, $0001 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); + // @001280FC ADDIU a1, a1, $0004 + this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 4))); + // @00128100 ADDIU t3, t3, $0004 + this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + 4))); + // @00128104 SLTI t7, s0, $0003 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); + // @00128108 BNE t7, zero, $0012809c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1212572u; + } + // @0012810C ADDIU t4, t4, $0004 + this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + 4))); + } + + public virtual void funct001280f8() + { + this.ee.pc = 1212688u; + // @001280F8 ADDIU s0, s0, $0001 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); + // @001280FC ADDIU a1, a1, $0004 + this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 4))); + // @00128100 ADDIU t3, t3, $0004 + this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + 4))); + // @00128104 SLTI t7, s0, $0003 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); + // @00128108 BNE t7, zero, $0012809c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1212572u; + } + // @0012810C ADDIU t4, t4, $0004 + this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + 4))); + } + + public virtual void funct001280fc() + { + this.ee.pc = 1212688u; + // @001280FC ADDIU a1, a1, $0004 + this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 4))); + // @00128100 ADDIU t3, t3, $0004 + this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + 4))); + // @00128104 SLTI t7, s0, $0003 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); + // @00128108 BNE t7, zero, $0012809c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1212572u; + } + // @0012810C ADDIU t4, t4, $0004 + this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + 4))); + } + + public virtual void funct00128110() + { + this.ee.pc = 1212696u; + // @00128110 BEQ zero, zero, $00127f84 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212292u; + } + // @00128114 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct00128118() + { + this.ee.pc = 1212768u; + // @00128118 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @0012811C MTC1 zero, $f21 + this.ee.fpr[21].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @00128120 ADDIU t7, t7, $8214 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32236))); + // @00128124 DADDU s0, zero, zero + this.ee.s0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00128128 LWC1 $f20, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[20], (0u + this.ee.t7.UL0)); + // @0012812C DADDU s4, s3, zero + this.ee.s4.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); + // @00128130 MOV.S $f22, $f21 + this.ee.fpr[22].f = this.ee.fpr[21].f; + // @00128134 DADDU s8, sp, zero + this.ee.s8.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); + // @00128138 ADDIU t7, s1, $0010 + this.ee.t7.SD0 = ((int)((this.ee.s1.SD0 + 16))); + // @0012813C MOV.S $f23, $f20 + this.ee.fpr[23].f = this.ee.fpr[20].f; + // @00128140 SW t7, $0030(sp) + MobUt.SW(this.ee, this.ee.t7, (48u + this.ee.sp.UL0)); + // @00128144 DADDU s7, zero, zero + this.ee.s7.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00128148 ADDIU s6, sp, $0021 + this.ee.s6.SD0 = ((int)((this.ee.sp.SD0 + 33))); + // @0012814C ADDIU t7, s1, $0020 + this.ee.t7.SD0 = ((int)((this.ee.s1.SD0 + 32))); + // @00128150 SW t7, $0034(sp) + MobUt.SW(this.ee, this.ee.t7, (52u + this.ee.sp.UL0)); + // @00128154 LBU t7, $ffff(s6) + MobUt.LBU(this.ee, this.ee.t7, (4294967295u + this.ee.s6.UL0)); + // @00128158 BEQ t7, zero, $001281f0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212912u; + } + // @0012815C LW t7, $0030(sp) + MobUt.LW(this.ee, this.ee.t7, (48u + this.ee.sp.UL0)); + } + + public virtual void funct00128154() + { + this.ee.pc = 1212768u; + // @00128154 LBU t7, $ffff(s6) + MobUt.LBU(this.ee, this.ee.t7, (4294967295u + this.ee.s6.UL0)); + // @00128158 BEQ t7, zero, $001281f0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212912u; + } + // @0012815C LW t7, $0030(sp) + MobUt.LW(this.ee, this.ee.t7, (48u + this.ee.sp.UL0)); + } + + public virtual void funct00128160() + { + this.ee.pc = 1212804u; + // @00128160 LWC1 $f12, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[12], (8u + this.ee.s1.UL0)); + // @00128164 ADDU s5, t7, s7 + this.ee.s5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s7.SD0))); + // @00128168 LWC1 $f1, $0000(s2) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s2.UL0)); + // @0012816C LWC1 $f0, $0000(s5) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.s5.UL0)); + // @00128170 ADD.S $f0, $f0, $f12 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[12].f); + // @00128174 SUB.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); + // @00128178 C.LT.S $f21, $f0 + this.ee.fcr31_23 = (this.ee.fpr[21].f < this.ee.fpr[0].f); + // @0012817C BC1FL $001281f4 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1212916u; + // @00128180 LBU t7, $0000(s6) + MobUt.LBU(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); + } + } + + public virtual void funct00128184() + { + this.ee.pc = 1212832u; + // @00128184 NOP + MobUt.Latency(); + // @00128188 NOP + MobUt.Latency(); + // @0012818C DIV.S $f0, $f0, $f12 + this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[12].f); + // @00128190 LWC1 $f12, $000c(s1) + MobUt.LWC1(this.ee, this.ee.fpr[12], (12u + this.ee.s1.UL0)); + // @00128194 SUB.S $f12, $f12, $f20 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[20].f); + // @00128198 JAL $002ff8d8 + this.ee.ra.UL0 = 1212832u; + this.ee.pc = 3143896u; + // @0012819C MUL.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f * this.ee.fpr[0].f); + } + + public virtual void funct001281a0() + { + this.ee.pc = 1212904u; + // @001281A0 LWC1 $f2, $0000(s5) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.s5.UL0)); + // @001281A4 ADDIU v0, zero, $0001 + this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @001281A8 LWC1 $f3, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[3], (8u + this.ee.s1.UL0)); + // @001281AC SUB.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f - this.ee.fpr[0].f); + // @001281B0 ADD.S $f2, $f2, $f3 + this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[3].f); + // @001281B4 LWC1 $f1, $0000(s8) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s8.UL0)); + // @001281B8 MUL.S $f0, $f3, $f0 + this.ee.fpr[0].f = (this.ee.fpr[3].f * this.ee.fpr[0].f); + // @001281BC ADD.S $f1, $f1, $f2 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[2].f); + // @001281C0 ADD.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); + // @001281C4 SWC1 $f1, $0000(s4) + MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s4.UL0)); + // @001281C8 ADDIU s0, s0, $0001 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); + // @001281CC ADDIU s4, s4, $0004 + this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 4))); + // @001281D0 ADDIU s8, s8, $0004 + this.ee.s8.SD0 = ((int)((this.ee.s8.SD0 + 4))); + // @001281D4 ADDIU s2, s2, $0004 + this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 4))); + // @001281D8 ADDIU s7, s7, $0004 + this.ee.s7.SD0 = ((int)((this.ee.s7.SD0 + 4))); + // @001281DC SLTI t7, s0, $0003 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); + // @001281E0 BNE t7, zero, $00128154 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1212756u; + } + // @001281E4 ADDIU s6, s6, $0002 + this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 2))); + } + + public virtual void funct001281b4() + { + this.ee.pc = 1212904u; + // @001281B4 LWC1 $f1, $0000(s8) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s8.UL0)); + // @001281B8 MUL.S $f0, $f3, $f0 + this.ee.fpr[0].f = (this.ee.fpr[3].f * this.ee.fpr[0].f); + // @001281BC ADD.S $f1, $f1, $f2 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[2].f); + // @001281C0 ADD.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); + // @001281C4 SWC1 $f1, $0000(s4) + MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s4.UL0)); + // @001281C8 ADDIU s0, s0, $0001 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); + // @001281CC ADDIU s4, s4, $0004 + this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 4))); + // @001281D0 ADDIU s8, s8, $0004 + this.ee.s8.SD0 = ((int)((this.ee.s8.SD0 + 4))); + // @001281D4 ADDIU s2, s2, $0004 + this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 4))); + // @001281D8 ADDIU s7, s7, $0004 + this.ee.s7.SD0 = ((int)((this.ee.s7.SD0 + 4))); + // @001281DC SLTI t7, s0, $0003 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); + // @001281E0 BNE t7, zero, $00128154 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1212756u; + } + // @001281E4 ADDIU s6, s6, $0002 + this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 2))); + } + + public virtual void funct001281c8() + { + this.ee.pc = 1212904u; + // @001281C8 ADDIU s0, s0, $0001 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); + // @001281CC ADDIU s4, s4, $0004 + this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 4))); + // @001281D0 ADDIU s8, s8, $0004 + this.ee.s8.SD0 = ((int)((this.ee.s8.SD0 + 4))); + // @001281D4 ADDIU s2, s2, $0004 + this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 4))); + // @001281D8 ADDIU s7, s7, $0004 + this.ee.s7.SD0 = ((int)((this.ee.s7.SD0 + 4))); + // @001281DC SLTI t7, s0, $0003 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); + // @001281E0 BNE t7, zero, $00128154 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1212756u; + } + // @001281E4 ADDIU s6, s6, $0002 + this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 2))); + } + + public virtual void funct001281cc() + { + this.ee.pc = 1212904u; + // @001281CC ADDIU s4, s4, $0004 + this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 4))); + // @001281D0 ADDIU s8, s8, $0004 + this.ee.s8.SD0 = ((int)((this.ee.s8.SD0 + 4))); + // @001281D4 ADDIU s2, s2, $0004 + this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 4))); + // @001281D8 ADDIU s7, s7, $0004 + this.ee.s7.SD0 = ((int)((this.ee.s7.SD0 + 4))); + // @001281DC SLTI t7, s0, $0003 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); + // @001281E0 BNE t7, zero, $00128154 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1212756u; + } + // @001281E4 ADDIU s6, s6, $0002 + this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 2))); + } + + public virtual void funct001281e8() + { + this.ee.pc = 1212912u; + // @001281E8 BEQ zero, zero, $00127f84 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212292u; + } + // @001281EC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct001281f0() + { + this.ee.pc = 1212924u; + // @001281F0 LBU t7, $0000(s6) + MobUt.LBU(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); + // @001281F4 BEQ t7, zero, $001281c8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212872u; + } + // @001281F8 LW t7, $0034(sp) + MobUt.LW(this.ee, this.ee.t7, (52u + this.ee.sp.UL0)); + } + + public virtual void funct001281f4() + { + this.ee.pc = 1212924u; + // @001281F4 BEQ t7, zero, $001281c8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212872u; + } + // @001281F8 LW t7, $0034(sp) + MobUt.LW(this.ee, this.ee.t7, (52u + this.ee.sp.UL0)); + } + + public virtual void funct001281fc() + { + this.ee.pc = 1212960u; + // @001281FC LWC1 $f12, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[12], (8u + this.ee.s1.UL0)); + // @00128200 ADDU s5, t7, s7 + this.ee.s5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s7.SD0))); + // @00128204 LWC1 $f1, $0000(s2) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s2.UL0)); + // @00128208 LWC1 $f0, $0000(s5) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.s5.UL0)); + // @0012820C SUB.S $f0, $f0, $f12 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); + // @00128210 SUB.S $f0, $f1, $f0 + this.ee.fpr[0].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); + // @00128214 C.LT.S $f22, $f0 + this.ee.fcr31_23 = (this.ee.fpr[22].f < this.ee.fpr[0].f); + // @00128218 BC1FL $001281cc + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1212876u; + // @0012821C ADDIU s0, s0, $0001 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 1))); + } + } + + public virtual void funct00128220() + { + this.ee.pc = 1212988u; + // @00128220 NOP + MobUt.Latency(); + // @00128224 NOP + MobUt.Latency(); + // @00128228 DIV.S $f0, $f0, $f12 + this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[12].f); + // @0012822C LWC1 $f12, $000c(s1) + MobUt.LWC1(this.ee, this.ee.fpr[12], (12u + this.ee.s1.UL0)); + // @00128230 SUB.S $f12, $f12, $f23 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[23].f); + // @00128234 JAL $002ff8d8 + this.ee.ra.UL0 = 1212988u; + this.ee.pc = 3143896u; + // @00128238 MUL.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f * this.ee.fpr[0].f); + } + + public virtual void funct0012823c() + { + this.ee.pc = 1213012u; + // @0012823C LWC1 $f2, $0000(s5) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.s5.UL0)); + // @00128240 ADDIU v0, zero, $0001 + this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @00128244 LWC1 $f3, $0008(s1) + MobUt.LWC1(this.ee, this.ee.fpr[3], (8u + this.ee.s1.UL0)); + // @00128248 SUB.S $f0, $f23, $f0 + this.ee.fpr[0].f = (this.ee.fpr[23].f - this.ee.fpr[0].f); + // @0012824C BEQ zero, zero, $001281b4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212852u; + } + // @00128250 SUB.S $f2, $f2, $f3 + this.ee.fpr[2].f = (this.ee.fpr[2].f - this.ee.fpr[3].f); + } + + public virtual void funct00128254() + { + this.ee.pc = 1213024u; + // @00128254 SQC2 vf0, $0000(sp) + MobUt.SQC2(this.ee, this.ee.VF[0], (0u + this.ee.sp.UL0)); + // @00128258 BEQ zero, zero, $00127e94 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1212052u; + } + // @0012825C ADDIU s2, sp, $0010 + this.ee.s2.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00128260() + { + this.ee.pc = 1213076u; + // @00128260 ADDIU sp, sp, $ffe0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); + // @00128264 SD s0, $0000(sp) + MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @00128268 SD s1, $0008(sp) + MobUt.SD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); + // @0012826C SD s2, $0010(sp) + MobUt.SD(this.ee, this.ee.s2, (16u + this.ee.sp.UL0)); + // @00128270 DADDU s0, a1, zero + this.ee.s0.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + // @00128274 SD ra, $0018(sp) + MobUt.SD(this.ee, this.ee.ra, (24u + this.ee.sp.UL0)); + // @00128278 LW t7, $0014(a1) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.a1.UL0)); + // @0012827C LW s2, $0004(a0) + MobUt.LW(this.ee, this.ee.s2, (4u + this.ee.a0.UL0)); + // @00128280 LW t6, $0000(t7) + MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.t7.UL0)); + // @00128284 LHU s1, $0010(s2) + MobUt.LHU(this.ee, this.ee.s1, (16u + this.ee.s2.UL0)); + // @00128288 LW v0, $0020(t6) + MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t6.UL0)); + // @0012828C JALR ra, v0 + this.ee.ra.UD0 = 1213076u; + this.ee.pc = this.ee.v0.UL0; + // @00128290 DADDU a0, t7, zero + this.ee.a0.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00128294() + { + this.ee.pc = 1213084u; + // @00128294 BEQ s1, zero, $00128304 + if ((this.ee.s1.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213188u; + } + // @00128298 DADDU t2, zero, zero + this.ee.t2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012829c() + { + this.ee.pc = 1213108u; + // @0012829C LW t7, $001c(s0) + MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s0.UL0)); + // @001282A0 SLL t5, t2, 4 + MobUt.SLL(this.ee.t5, this.ee.t2, 4); + // @001282A4 ADDIU t6, v0, $0010 + this.ee.t6.SD0 = ((int)((this.ee.v0.SD0 + 16))); + // @001282A8 ADDU t7, t7, t5 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); + // @001282AC BEQL t7, t6, $001282c0 + if ((this.ee.t7.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1213120u; + // @001282B0 LW t7, $0020(s0) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s0.UL0)); + } + } + + public virtual void funct001282b4() + { + this.ee.pc = 1213136u; + // @001282B4 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @001282B8 SQ t0, $0000(t7) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @001282BC LW t7, $0020(s0) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s0.UL0)); + // @001282C0 ADDIU t6, v0, $0020 + this.ee.t6.SD0 = ((int)((this.ee.v0.SD0 + 32))); + // @001282C4 ADDU t7, t7, t5 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); + // @001282C8 BEQL t7, t6, $001282dc + if ((this.ee.t7.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1213148u; + // @001282CC LW t7, $0024(s0) + MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s0.UL0)); + } + } + + public virtual void funct001282d0() + { + this.ee.pc = 1213164u; + // @001282D0 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @001282D4 SQ t0, $0000(t7) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @001282D8 LW t7, $0024(s0) + MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s0.UL0)); + // @001282DC ADDIU t6, v0, $0030 + this.ee.t6.SD0 = ((int)((this.ee.v0.SD0 + 48))); + // @001282E0 ADDU t7, t7, t5 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); + // @001282E4 BEQL t7, t6, $001282f8 + if ((this.ee.t7.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1213176u; + // @001282E8 ADDIU t2, t2, $0001 + this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + 1))); + } + } + + public virtual void funct001282ec() + { + this.ee.pc = 1213188u; + // @001282EC LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @001282F0 SQ t0, $0000(t7) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @001282F4 ADDIU t2, t2, $0001 + this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + 1))); + // @001282F8 SLT t7, t2, s1 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t2.SD0 < this.ee.s1.SD0)); + // @001282FC BNE t7, zero, $0012829c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1213084u; + } + // @00128300 ADDIU v0, v0, $0040 + this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + 64))); + } + + public virtual void funct00128304() + { + this.ee.pc = 1213200u; + // @00128304 LW s1, $0028(s2) + MobUt.LW(this.ee, this.ee.s1, (40u + this.ee.s2.UL0)); + // @00128308 BEQL s1, zero, $00128384 + if ((this.ee.s1.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213316u; + // @0012830C LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + } + } + + public virtual void funct00128310() + { + this.ee.pc = 1213216u; + // @00128310 LW t7, $0024(s2) + MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s2.UL0)); + // @00128314 DADDU t2, zero, zero + this.ee.t2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00128318 BLEZ s1, $00128380 + if ((this.ee.s1.SD0 <= 0)) + { + this.ee.pc = 1213312u; + } + // @0012831C ADDU t3, s2, t7 + this.ee.t3.SD0 = ((int)((this.ee.s2.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct00128320() + { + this.ee.pc = 1213236u; + // @00128320 LHU t4, $0002(t3) + MobUt.LHU(this.ee, this.ee.t4, (2u + this.ee.t3.UL0)); + // @00128324 ANDI t6, t4, $ffff + this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @00128328 SLTIU t7, t6, $0009 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 9ul)); + // @0012832C BEQ t7, zero, $00128370 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213296u; + } + // @00128330 SLL t7, t6, 2 + MobUt.SLL(this.ee.t7, this.ee.t6, 2); + } + + public virtual void funct00128334() + { + this.ee.pc = 1213260u; + // @00128334 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @00128338 ADDIU t6, t6, $8218 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -32232))); + // @0012833C ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00128340 LW t5, $0000(t7) + MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); + // @00128344 JR t5 + this.ee.pc = this.ee.t5.UL[0]; + // @00128348 NOP + MobUt.Latency(); + } + + public virtual void funct0012834c() + { + this.ee.pc = 1213312u; + // @0012834C LHU t6, $0000(t3) + MobUt.LHU(this.ee, this.ee.t6, (0u + this.ee.t3.UL0)); + // @00128350 ANDI t5, t4, $ffff + this.ee.t5.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @00128354 LW t7, $001c(s0) + MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s0.UL0)); + // @00128358 SLL t5, t5, 2 + MobUt.SLL(this.ee.t5, this.ee.t5, 2); + // @0012835C SLL t6, t6, 4 + MobUt.SLL(this.ee.t6, this.ee.t6, 4); + // @00128360 LWC1 $f0, $0004(t3) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t3.UL0)); + // @00128364 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00128368 ADDU t7, t7, t5 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); + // @0012836C SWC1 $f0, $0000(t7) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00128370 ADDIU t2, t2, $0001 + this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + 1))); + // @00128374 SLT t7, t2, s1 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t2.SD0 < this.ee.s1.SD0)); + // @00128378 BNE t7, zero, $00128320 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1213216u; + } + // @0012837C ADDIU t3, t3, $0008 + this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + 8))); + } + + public virtual void funct00128370() + { + this.ee.pc = 1213312u; + // @00128370 ADDIU t2, t2, $0001 + this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + 1))); + // @00128374 SLT t7, t2, s1 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t2.SD0 < this.ee.s1.SD0)); + // @00128378 BNE t7, zero, $00128320 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1213216u; + } + // @0012837C ADDIU t3, t3, $0008 + this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + 8))); + } + + public virtual void funct00128380() + { + this.ee.pc = 1213336u; + // @00128380 LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @00128384 LD s1, $0008(sp) + MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); + // @00128388 LD s2, $0010(sp) + MobUt.LD(this.ee, this.ee.s2, (16u + this.ee.sp.UL0)); + // @0012838C LD ra, $0018(sp) + MobUt.LD(this.ee, this.ee.ra, (24u + this.ee.sp.UL0)); + // @00128390 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00128394 ADDIU sp, sp, $0020 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); + } + + public virtual void funct00128384() + { + this.ee.pc = 1213336u; + // @00128384 LD s1, $0008(sp) + MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); + // @00128388 LD s2, $0010(sp) + MobUt.LD(this.ee, this.ee.s2, (16u + this.ee.sp.UL0)); + // @0012838C LD ra, $0018(sp) + MobUt.LD(this.ee, this.ee.ra, (24u + this.ee.sp.UL0)); + // @00128390 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00128394 ADDIU sp, sp, $0020 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); + } + + public virtual void funct00128398() + { + this.ee.pc = 1213380u; + // @00128398 ANDI t7, t4, $ffff + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @0012839C LHU t5, $0000(t3) + MobUt.LHU(this.ee, this.ee.t5, (0u + this.ee.t3.UL0)); + // @001283A0 LW t6, $0020(s0) + MobUt.LW(this.ee, this.ee.t6, (32u + this.ee.s0.UL0)); + // @001283A4 ADDIU t7, t7, $fffd + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -3))); + // @001283A8 SLL t5, t5, 4 + MobUt.SLL(this.ee.t5, this.ee.t5, 4); + // @001283AC LWC1 $f0, $0004(t3) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t3.UL0)); + // @001283B0 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @001283B4 ADDU t6, t6, t5 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); + // @001283B8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @001283BC BEQ zero, zero, $00128370 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213296u; + } + // @001283C0 SWC1 $f0, $0000(t6) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + } + + public virtual void funct001283a8() + { + this.ee.pc = 1213380u; + // @001283A8 SLL t5, t5, 4 + MobUt.SLL(this.ee.t5, this.ee.t5, 4); + // @001283AC LWC1 $f0, $0004(t3) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t3.UL0)); + // @001283B0 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @001283B4 ADDU t6, t6, t5 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); + // @001283B8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @001283BC BEQ zero, zero, $00128370 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213296u; + } + // @001283C0 SWC1 $f0, $0000(t6) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + } + + public virtual void funct001283c4() + { + this.ee.pc = 1213400u; + // @001283C4 ANDI t7, t4, $ffff + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @001283C8 LHU t5, $0000(t3) + MobUt.LHU(this.ee, this.ee.t5, (0u + this.ee.t3.UL0)); + // @001283CC LW t6, $0024(s0) + MobUt.LW(this.ee, this.ee.t6, (36u + this.ee.s0.UL0)); + // @001283D0 BEQ zero, zero, $001283a8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213352u; + } + // @001283D4 ADDIU t7, t7, $fffa + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -6))); + } + + public virtual void funct001283d8() + { + this.ee.pc = 1213440u; + // @001283D8 LW t5, $0004(a0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.a0.UL0)); + // @001283DC LW t6, $0044(t5) + MobUt.LW(this.ee, this.ee.t6, (68u + this.ee.t5.UL0)); + // @001283E0 LW t4, $0020(t5) + MobUt.LW(this.ee, this.ee.t4, (32u + this.ee.t5.UL0)); + // @001283E4 ADDU t3, t5, t6 + this.ee.t3.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @001283E8 SLL t7, t4, 2 + MobUt.SLL(this.ee.t7, this.ee.t4, 2); + // @001283EC ADDU t7, t3, t7 + this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t7.SD0))); + // @001283F0 LWC1 $f0, $fffc(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4294967292u + this.ee.t7.UL0)); + // @001283F4 C.LE.S $f0, $f12 + this.ee.fcr31_23 = (this.ee.fpr[0].f <= this.ee.fpr[12].f); + // @001283F8 BC1FL $00128414 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1213460u; + // @001283FC LWC1 $f0, $0000(t3) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t3.UL0)); + } + } + + public virtual void funct00128400() + { + this.ee.pc = 1213460u; + // @00128400 ADDIU t7, t4, $ffff + this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + -1))); + // @00128404 SW t7, $0000(a1) + MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a1.UL0)); + // @00128408 LW t6, $0020(t5) + MobUt.LW(this.ee, this.ee.t6, (32u + this.ee.t5.UL0)); + // @0012840C JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00128410 SW t6, $0000(a2) + MobUt.SW(this.ee, this.ee.t6, (0u + this.ee.a2.UL0)); + } + + public virtual void funct00128414() + { + this.ee.pc = 1213472u; + // @00128414 C.LE.S $f12, $f0 + this.ee.fcr31_23 = (this.ee.fpr[12].f <= this.ee.fpr[0].f); + // @00128418 BC1FL $00128430 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1213488u; + // @0012841C SW zero, $0000(a1) + MobUt.SW(this.ee, this.ee.r0, (0u + this.ee.a1.UL0)); + } + } + + public virtual void funct00128420() + { + this.ee.pc = 1213488u; + // @00128420 ADDIU t7, zero, $ffff + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); + // @00128424 SW t7, $0000(a1) + MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a1.UL0)); + // @00128428 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0012842C SW zero, $0000(a2) + MobUt.SW(this.ee, this.ee.r0, (0u + this.ee.a2.UL0)); + } + + public virtual void funct00128430() + { + this.ee.pc = 1213520u; + // @00128430 LW t7, $0020(t5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.t5.UL0)); + // @00128434 ADDIU t6, t7, $ffff + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + -1))); + // @00128438 SW t6, $0000(a2) + MobUt.SW(this.ee, this.ee.t6, (0u + this.ee.a2.UL0)); + // @0012843C LW t5, $0000(a1) + MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.a1.UL0)); + // @00128440 SUBU t7, t6, t5 + this.ee.t7.SD0 = ((int)((this.ee.t6.UD0 - this.ee.t5.UD0))); + // @00128444 SLTI t7, t7, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < 2)); + // @00128448 BNE t7, zero, $00128490 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1213584u; + } + // @0012844C ADDU t7, t5, t6 + this.ee.t7.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + } + + public virtual void funct00128450() + { + this.ee.pc = 1213556u; + // @00128450 SRL t6, t7, 31 + MobUt.SRL(this.ee.t6, this.ee.t7, 31); + // @00128454 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00128458 SRA t7, t7, 1 + MobUt.SRA(this.ee.t7, this.ee.t7, 1); + // @0012845C SLL t6, t7, 2 + MobUt.SLL(this.ee.t6, this.ee.t7, 2); + // @00128460 ADDU t6, t6, t3 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t3.SD0))); + // @00128464 LWC1 $f0, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @00128468 C.LT.S $f12, $f0 + this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[0].f); + // @0012846C BC1FL $00128498 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1213592u; + // @00128470 C.LT.S $f0, $f12 + this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[12].f); + } + } + + public virtual void funct00128474() + { + this.ee.pc = 1213584u; + // @00128474 SW t7, $0000(a2) + MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a2.UL0)); + // @00128478 LW t6, $0000(a2) + MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.a2.UL0)); + // @0012847C LW t5, $0000(a1) + MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.a1.UL0)); + // @00128480 SUBU t7, t6, t5 + this.ee.t7.SD0 = ((int)((this.ee.t6.UD0 - this.ee.t5.UD0))); + // @00128484 SLTI t7, t7, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < 2)); + // @00128488 BEQ t7, zero, $00128450 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213520u; + } + // @0012848C ADDU t7, t5, t6 + this.ee.t7.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + } + + public virtual void funct00128478() + { + this.ee.pc = 1213584u; + // @00128478 LW t6, $0000(a2) + MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.a2.UL0)); + // @0012847C LW t5, $0000(a1) + MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.a1.UL0)); + // @00128480 SUBU t7, t6, t5 + this.ee.t7.SD0 = ((int)((this.ee.t6.UD0 - this.ee.t5.UD0))); + // @00128484 SLTI t7, t7, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < 2)); + // @00128488 BEQ t7, zero, $00128450 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213520u; + } + // @0012848C ADDU t7, t5, t6 + this.ee.t7.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + } + + public virtual void funct00128490() + { + this.ee.pc = 1213592u; + // @00128490 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00128494 NOP + MobUt.Latency(); + } + + public virtual void funct00128498() + { + this.ee.pc = 1213600u; + // @00128498 BC1FL $001284a8 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1213608u; + // @0012849C SW t7, $0000(a2) + MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a2.UL0)); + } + } + + public virtual void funct001284a0() + { + this.ee.pc = 1213608u; + // @001284A0 BEQ zero, zero, $00128478 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213560u; + } + // @001284A4 SW t7, $0000(a1) + MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a1.UL0)); + } + + public virtual void funct001284a8() + { + this.ee.pc = 1213616u; + // @001284A8 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @001284AC SW t7, $0000(a1) + MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a1.UL0)); + } + + public virtual void funct001284b0() + { + this.ee.pc = 1213744u; + // @001284B0 SUB.S $f16, $f16, $f13 + this.ee.fpr[16].f = (this.ee.fpr[16].f - this.ee.fpr[13].f); + // @001284B4 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @001284B8 ADDIU t7, t7, $823c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32196))); + // @001284BC SUB.S $f12, $f12, $f13 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[13].f); + // @001284C0 LWC1 $f7, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[7], (0u + this.ee.t7.UL0)); + // @001284C4 NOP + MobUt.Latency(); + // @001284C8 NOP + MobUt.Latency(); + // @001284CC DIV.S $f16, $f7, $f16 + this.ee.fpr[16].f = (this.ee.fpr[7].f / this.ee.fpr[16].f); + // @001284D0 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @001284D4 MUL.S $f5, $f12, $f12 + this.ee.fpr[5].f = (this.ee.fpr[12].f * this.ee.fpr[12].f); + // @001284D8 ADDIU t7, t7, $8240 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32192))); + // @001284DC LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @001284E0 MUL.S $f2, $f5, $f12 + this.ee.fpr[2].f = (this.ee.fpr[5].f * this.ee.fpr[12].f); + // @001284E4 MUL.S $f3, $f5, $f3 + this.ee.fpr[3].f = (this.ee.fpr[5].f * this.ee.fpr[3].f); + // @001284E8 MUL.S $f1, $f16, $f16 + this.ee.fpr[1].f = (this.ee.fpr[16].f * this.ee.fpr[16].f); + // @001284EC MUL.S $f5, $f5, $f16 + this.ee.fpr[5].f = (this.ee.fpr[5].f * this.ee.fpr[16].f); + // @001284F0 MUL.S $f2, $f2, $f1 + this.ee.fpr[2].f = (this.ee.fpr[2].f * this.ee.fpr[1].f); + // @001284F4 MUL.S $f3, $f3, $f1 + this.ee.fpr[3].f = (this.ee.fpr[3].f * this.ee.fpr[1].f); + // @001284F8 ADD.S $f6, $f5, $f5 + this.ee.fpr[6].f = (this.ee.fpr[5].f + this.ee.fpr[5].f); + // @001284FC ADD.S $f4, $f2, $f2 + this.ee.fpr[4].f = (this.ee.fpr[2].f + this.ee.fpr[2].f); + // @00128500 SUB.S $f5, $f2, $f5 + this.ee.fpr[5].f = (this.ee.fpr[2].f - this.ee.fpr[5].f); + // @00128504 MUL.S $f4, $f4, $f16 + this.ee.fpr[4].f = (this.ee.fpr[4].f * this.ee.fpr[16].f); + // @00128508 SUB.S $f2, $f2, $f6 + this.ee.fpr[2].f = (this.ee.fpr[2].f - this.ee.fpr[6].f); + // @0012850C SUB.S $f1, $f4, $f3 + this.ee.fpr[1].f = (this.ee.fpr[4].f - this.ee.fpr[3].f); + // @00128510 ADD.S $f2, $f2, $f12 + this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[12].f); + // @00128514 ADD.S $f1, $f1, $f7 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[7].f); + // @00128518 SUB.S $f3, $f3, $f4 + this.ee.fpr[3].f = (this.ee.fpr[3].f - this.ee.fpr[4].f); + // @0012851C MULA.S $f14, $f1 + this.ee.fpracc.f = (this.ee.fpr[14].f * this.ee.fpr[1].f); + // @00128520 MADDA.S $f17, $f3 + this.ee.fpracc.f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[17].f, this.ee.fpr[3].f); + // @00128524 MADDA.S $f15, $f2 + this.ee.fpracc.f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[15].f, this.ee.fpr[2].f); + // @00128528 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0012852C MADD.S $f0, $f18, $f5 + this.ee.fpr[0].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[18].f, this.ee.fpr[5].f); + } + + public virtual void funct00128530() + { + this.ee.pc = 1213892u; + // @00128530 ADDIU sp, sp, $ffa0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -96))); + // @00128534 LW t5, $0004(a0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.a0.UL0)); + // @00128538 SD s0, $0010(sp) + MobUt.SD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); + // @0012853C SD s1, $0018(sp) + MobUt.SD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); + // @00128540 SD s2, $0020(sp) + MobUt.SD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); + // @00128544 DADDU s0, a1, zero + this.ee.s0.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + // @00128548 SD s3, $0028(sp) + MobUt.SD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); + // @0012854C SD s4, $0030(sp) + MobUt.SD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); + // @00128550 SD s5, $0038(sp) + MobUt.SD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); + // @00128554 SD s6, $0040(sp) + MobUt.SD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); + // @00128558 SWC1 $f20, $0050(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (80u + this.ee.sp.UL0)); + // @0012855C SW a3, $0004(sp) + MobUt.SW(this.ee, this.ee.a3, (4u + this.ee.sp.UL0)); + // @00128560 SD ra, $0048(sp) + MobUt.SD(this.ee, this.ee.ra, (72u + this.ee.sp.UL0)); + // @00128564 MOV.S $f20, $f12 + this.ee.fpr[20].f = this.ee.fpr[12].f; + // @00128568 SW a2, $0000(sp) + MobUt.SW(this.ee, this.ee.a2, (0u + this.ee.sp.UL0)); + // @0012856C LHU t0, $0004(a1) + MobUt.LHU(this.ee, this.ee.t0, (4u + this.ee.a1.UL0)); + // @00128570 LW t6, $0040(t5) + MobUt.LW(this.ee, this.ee.t6, (64u + this.ee.t5.UL0)); + // @00128574 ANDI t4, t0, $ffff + this.ee.t4.UD0 = ((ushort)((this.ee.t0.US0 & 65535))); + // @00128578 LBU t1, $0003(a1) + MobUt.LBU(this.ee, this.ee.t1, (3u + this.ee.a1.UL0)); + // @0012857C ADDU s2, t5, t6 + this.ee.s2.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @00128580 LW t3, $0048(t5) + MobUt.LW(this.ee, this.ee.t3, (72u + this.ee.t5.UL0)); + // @00128584 SLL t7, t4, 3 + MobUt.SLL(this.ee.t7, this.ee.t4, 3); + // @00128588 ANDI t6, t1, $00ff + this.ee.t6.UD0 = ((ushort)((this.ee.t1.US0 & 255))); + // @0012858C ADDU s1, s2, t7 + this.ee.s1.SD0 = ((int)((this.ee.s2.SD0 + this.ee.t7.SD0))); + // @00128590 ADDU t4, t4, t6 + this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @00128594 LHU t2, $0000(s1) + MobUt.LHU(this.ee, this.ee.t2, (0u + this.ee.s1.UL0)); + // @00128598 SLL t4, t4, 3 + MobUt.SLL(this.ee.t4, this.ee.t4, 3); + // @0012859C LW t6, $0044(t5) + MobUt.LW(this.ee, this.ee.t6, (68u + this.ee.t5.UL0)); + // @001285A0 ADDU t4, s2, t4 + this.ee.t4.SD0 = ((int)((this.ee.s2.SD0 + this.ee.t4.SD0))); + // @001285A4 LW t7, $004c(t5) + MobUt.LW(this.ee, this.ee.t7, (76u + this.ee.t5.UL0)); + // @001285A8 SRL t2, t2, 2 + MobUt.SRL(this.ee.t2, this.ee.t2, 2); + // @001285AC ADDU s3, t5, t6 + this.ee.s3.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @001285B0 ADDU s5, t5, t3 + this.ee.s5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t3.SD0))); + // @001285B4 ADDU s6, t5, t7 + this.ee.s6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t7.SD0))); + // @001285B8 SLT a3, t2, a3 + this.ee.a3.UD0 = System.Convert.ToByte((this.ee.t2.SD0 < this.ee.a3.SD0)); + // @001285BC BNE a3, zero, $00128840 + if ((this.ee.a3.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1214528u; + } + // @001285C0 ADDIU s4, t4, $fff8 + this.ee.s4.SD0 = ((int)((this.ee.t4.SD0 + -8))); + } + + public virtual void funct001285c4() + { + this.ee.pc = 1213916u; + // @001285C4 LHU t7, $0002(a1) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.a1.UL0)); + // @001285C8 ADDIU t6, zero, $0001 + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @001285CC SRL t7, t7, 4 + MobUt.SRL(this.ee.t7, this.ee.t7, 4); + // @001285D0 ANDI t5, t7, $0003 + this.ee.t5.UD0 = ((ushort)((this.ee.t7.US0 & 3))); + // @001285D4 BEQ t5, t6, $00128804 + if ((this.ee.t5.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1214468u; + } + // @001285D8 SLTI t7, t5, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < 2)); + } + + public virtual void funct001285dc() + { + this.ee.pc = 1213924u; + // @001285DC BEQL t7, zero, $0012862c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213996u; + // @001285E0 ADDIU t7, zero, $0002 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); + } + } + + public virtual void funct001285e4() + { + this.ee.pc = 1213932u; + // @001285E4 BEQL t5, zero, $0012861c + if ((this.ee.t5.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213980u; + // @001285E8 LHU t7, $0002(s1) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); + } + } + + public virtual void funct001285f0() + { + this.ee.pc = 1213980u; + // @001285F0 LD s0, $0010(sp) + MobUt.LD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); + // @001285F4 LD s1, $0018(sp) + MobUt.LD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); + // @001285F8 LD s2, $0020(sp) + MobUt.LD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); + // @001285FC LD s3, $0028(sp) + MobUt.LD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); + // @00128600 LD s4, $0030(sp) + MobUt.LD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); + // @00128604 LD s5, $0038(sp) + MobUt.LD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); + // @00128608 LD s6, $0040(sp) + MobUt.LD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); + // @0012860C LD ra, $0048(sp) + MobUt.LD(this.ee, this.ee.ra, (72u + this.ee.sp.UL0)); + // @00128610 LWC1 $f20, $0050(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (80u + this.ee.sp.UL0)); + // @00128614 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00128618 ADDIU sp, sp, $0060 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 96))); + } + + public virtual void funct001285f4() + { + this.ee.pc = 1213980u; + // @001285F4 LD s1, $0018(sp) + MobUt.LD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); + // @001285F8 LD s2, $0020(sp) + MobUt.LD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); + // @001285FC LD s3, $0028(sp) + MobUt.LD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); + // @00128600 LD s4, $0030(sp) + MobUt.LD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); + // @00128604 LD s5, $0038(sp) + MobUt.LD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); + // @00128608 LD s6, $0040(sp) + MobUt.LD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); + // @0012860C LD ra, $0048(sp) + MobUt.LD(this.ee, this.ee.ra, (72u + this.ee.sp.UL0)); + // @00128610 LWC1 $f20, $0050(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (80u + this.ee.sp.UL0)); + // @00128614 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00128618 ADDIU sp, sp, $0060 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 96))); + } + + public virtual void funct0012861c() + { + this.ee.pc = 1213996u; + // @0012861C SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @00128620 ADDU t7, t7, s5 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s5.SD0))); + // @00128624 BEQ zero, zero, $001285f0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213936u; + } + // @00128628 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + } + + public virtual void funct0012862c() + { + this.ee.pc = 1214004u; + // @0012862C BNEL t5, t7, $001285f0 + if ((this.ee.t5.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1213936u; + // @00128630 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + } + } + + public virtual void funct00128634() + { + this.ee.pc = 1214044u; + // @00128634 LHU t7, $fff8(t4) + MobUt.LHU(this.ee, this.ee.t7, (4294967288u + this.ee.t4.UL0)); + // @00128638 SLL t6, t2, 2 + MobUt.SLL(this.ee.t6, this.ee.t2, 2); + // @0012863C ADDU t6, t6, s3 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); + // @00128640 ANDI t7, t7, $fffc + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 65532))); + // @00128644 LWC1 $f2, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t6.UL0)); + // @00128648 ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012864C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00128650 C.LT.S $f12, $f2 + this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[2].f); + // @00128654 BC1F $00128670 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1214064u; + } + // @00128658 SUB.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); + } + + public virtual void funct0012865c() + { + this.ee.pc = 1214060u; + // @0012865C ADD.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); + // @00128660 C.LT.S $f12, $f2 + this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[2].f); + // @00128664 BC1TL $00128660 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1214048u; + // @00128668 ADD.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); + } + } + + public virtual void funct00128660() + { + this.ee.pc = 1214060u; + // @00128660 C.LT.S $f12, $f2 + this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[2].f); + // @00128664 BC1TL $00128660 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1214048u; + // @00128668 ADD.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); + } + } + + public virtual void funct0012866c() + { + this.ee.pc = 1214080u; + // @0012866C MOV.S $f20, $f12 + this.ee.fpr[20].f = this.ee.fpr[12].f; + // @00128670 MOV.S $f12, $f20 + this.ee.fpr[12].f = this.ee.fpr[20].f; + // @00128674 DADDU a1, sp, zero + this.ee.a1.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); + // @00128678 JAL $001283d8 + this.ee.ra.UL0 = 1214080u; + this.ee.pc = 1213400u; + // @0012867C ADDIU a2, sp, $0004 + this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 4))); + } + + public virtual void funct00128670() + { + this.ee.pc = 1214080u; + // @00128670 MOV.S $f12, $f20 + this.ee.fpr[12].f = this.ee.fpr[20].f; + // @00128674 DADDU a1, sp, zero + this.ee.a1.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); + // @00128678 JAL $001283d8 + this.ee.ra.UL0 = 1214080u; + this.ee.pc = 1213400u; + // @0012867C ADDIU a2, sp, $0004 + this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 4))); + } + + public virtual void funct00128680() + { + this.ee.pc = 1214120u; + // @00128680 LBU t1, $0003(s0) + MobUt.LBU(this.ee, this.ee.t1, (3u + this.ee.s0.UL0)); + // @00128684 LHU t0, $0004(s0) + MobUt.LHU(this.ee, this.ee.t0, (4u + this.ee.s0.UL0)); + // @00128688 ANDI t4, t0, $ffff + this.ee.t4.UD0 = ((ushort)((this.ee.t0.US0 & 65535))); + // @0012868C ANDI t7, t1, $00ff + this.ee.t7.UD0 = ((ushort)((this.ee.t1.US0 & 255))); + // @00128690 ADDU t7, t4, t7 + this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t7.SD0))); + // @00128694 ADDIU a3, t7, $ffff + this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + -1))); + // @00128698 SUBU t0, a3, t4 + this.ee.t0.SD0 = ((int)((this.ee.a3.UD0 - this.ee.t4.UD0))); + // @0012869C SLTI t7, t0, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t0.SD0 < 2)); + // @001286A0 BNEL t7, zero, $00128708 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1214216u; + // @001286A4 LHU t4, $0000(s1) + MobUt.LHU(this.ee, this.ee.t4, (0u + this.ee.s1.UL0)); + } + } + + public virtual void funct0012868c() + { + this.ee.pc = 1214120u; + // @0012868C ANDI t7, t1, $00ff + this.ee.t7.UD0 = ((ushort)((this.ee.t1.US0 & 255))); + // @00128690 ADDU t7, t4, t7 + this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t7.SD0))); + // @00128694 ADDIU a3, t7, $ffff + this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + -1))); + // @00128698 SUBU t0, a3, t4 + this.ee.t0.SD0 = ((int)((this.ee.a3.UD0 - this.ee.t4.UD0))); + // @0012869C SLTI t7, t0, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t0.SD0 < 2)); + // @001286A0 BNEL t7, zero, $00128708 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1214216u; + // @001286A4 LHU t4, $0000(s1) + MobUt.LHU(this.ee, this.ee.t4, (0u + this.ee.s1.UL0)); + } + } + + public virtual void funct001286a8() + { + this.ee.pc = 1214176u; + // @001286A8 ADDU t7, t4, a3 + this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + this.ee.a3.SD0))); + // @001286AC SRL t6, t7, 31 + MobUt.SRL(this.ee.t6, this.ee.t7, 31); + // @001286B0 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @001286B4 SRA t3, t7, 1 + MobUt.SRA(this.ee.t3, this.ee.t7, 1); + // @001286B8 SLL t6, t3, 3 + MobUt.SLL(this.ee.t6, this.ee.t3, 3); + // @001286BC ADDU t1, s2, t6 + this.ee.t1.SD0 = ((int)((this.ee.s2.SD0 + this.ee.t6.SD0))); + // @001286C0 LHU t5, $0000(t1) + MobUt.LHU(this.ee, this.ee.t5, (0u + this.ee.t1.UL0)); + // @001286C4 SRL t5, t5, 2 + MobUt.SRL(this.ee.t5, this.ee.t5, 2); + // @001286C8 SLL t7, t5, 2 + MobUt.SLL(this.ee.t7, this.ee.t5, 2); + // @001286CC ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @001286D0 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @001286D4 C.EQ.S $f0, $f20 + this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[20].f); + // @001286D8 BC1T $001287fc + if (this.ee.fcr31_23) + { + this.ee.pc = 1214460u; + } + // @001286DC LW t6, $0000(sp) + MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.sp.UL0)); + } + + public virtual void funct001286ac() + { + this.ee.pc = 1214176u; + // @001286AC SRL t6, t7, 31 + MobUt.SRL(this.ee.t6, this.ee.t7, 31); + // @001286B0 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @001286B4 SRA t3, t7, 1 + MobUt.SRA(this.ee.t3, this.ee.t7, 1); + // @001286B8 SLL t6, t3, 3 + MobUt.SLL(this.ee.t6, this.ee.t3, 3); + // @001286BC ADDU t1, s2, t6 + this.ee.t1.SD0 = ((int)((this.ee.s2.SD0 + this.ee.t6.SD0))); + // @001286C0 LHU t5, $0000(t1) + MobUt.LHU(this.ee, this.ee.t5, (0u + this.ee.t1.UL0)); + // @001286C4 SRL t5, t5, 2 + MobUt.SRL(this.ee.t5, this.ee.t5, 2); + // @001286C8 SLL t7, t5, 2 + MobUt.SLL(this.ee.t7, this.ee.t5, 2); + // @001286CC ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @001286D0 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @001286D4 C.EQ.S $f0, $f20 + this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[20].f); + // @001286D8 BC1T $001287fc + if (this.ee.fcr31_23) + { + this.ee.pc = 1214460u; + } + // @001286DC LW t6, $0000(sp) + MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.sp.UL0)); + } + + public virtual void funct001286e0() + { + this.ee.pc = 1214188u; + // @001286E0 SLT t7, t5, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); + // @001286E4 BEQ t7, zero, $001287c0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214400u; + } + // @001286E8 LW t2, $0004(sp) + MobUt.LW(this.ee, this.ee.t2, (4u + this.ee.sp.UL0)); + } + + public virtual void funct001286ec() + { + this.ee.pc = 1214212u; + // @001286EC DADDU t4, t3, zero + this.ee.t4.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); + // @001286F0 DADDU s1, t1, zero + this.ee.s1.UD0 = (this.ee.t1.UD0 + this.ee.r0.UD0); + // @001286F4 SUBU t0, a3, t4 + this.ee.t0.SD0 = ((int)((this.ee.a3.UD0 - this.ee.t4.UD0))); + // @001286F8 SLTI t7, t0, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t0.SD0 < 2)); + // @001286FC BEQ t7, zero, $001286ac + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214124u; + } + // @00128700 ADDU t7, t4, a3 + this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + this.ee.a3.SD0))); + } + + public virtual void funct001286f4() + { + this.ee.pc = 1214212u; + // @001286F4 SUBU t0, a3, t4 + this.ee.t0.SD0 = ((int)((this.ee.a3.UD0 - this.ee.t4.UD0))); + // @001286F8 SLTI t7, t0, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t0.SD0 < 2)); + // @001286FC BEQ t7, zero, $001286ac + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214124u; + } + // @00128700 ADDU t7, t4, a3 + this.ee.t7.SD0 = ((int)((this.ee.t4.SD0 + this.ee.a3.SD0))); + } + + public virtual void funct00128704() + { + this.ee.pc = 1214232u; + // @00128704 LHU t4, $0000(s1) + MobUt.LHU(this.ee, this.ee.t4, (0u + this.ee.s1.UL0)); + // @00128708 ANDI t7, t4, $0003 + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 3))); + // @0012870C ANDI t1, t7, $ffff + this.ee.t1.UD0 = ((ushort)((this.ee.t7.US0 & 65535))); + // @00128710 BEQL t1, zero, $0012861c + if ((this.ee.t1.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213980u; + // @00128714 LHU t7, $0002(s1) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); + } + } + + public virtual void funct00128708() + { + this.ee.pc = 1214232u; + // @00128708 ANDI t7, t4, $0003 + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 3))); + // @0012870C ANDI t1, t7, $ffff + this.ee.t1.UD0 = ((ushort)((this.ee.t7.US0 & 65535))); + // @00128710 BEQL t1, zero, $0012861c + if ((this.ee.t1.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213980u; + // @00128714 LHU t7, $0002(s1) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); + } + } + + public virtual void funct00128718() + { + this.ee.pc = 1214336u; + // @00128718 LHU t7, $0002(s4) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s4.UL0)); + // @0012871C ANDI t4, t4, $ffff + this.ee.t4.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @00128720 LHU t3, $0006(s1) + MobUt.LHU(this.ee, this.ee.t3, (6u + this.ee.s1.UL0)); + // @00128724 ANDI t4, t4, $fffc + this.ee.t4.UD0 = ((ushort)((this.ee.t4.US0 & 65532))); + // @00128728 LHU t2, $0004(s4) + MobUt.LHU(this.ee, this.ee.t2, (4u + this.ee.s4.UL0)); + // @0012872C SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @00128730 LHU t6, $0002(s1) + MobUt.LHU(this.ee, this.ee.t6, (2u + this.ee.s1.UL0)); + // @00128734 ADDU t7, t7, s5 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s5.SD0))); + // @00128738 LHU t5, $0000(s4) + MobUt.LHU(this.ee, this.ee.t5, (0u + this.ee.s4.UL0)); + // @0012873C SLL t3, t3, 2 + MobUt.SLL(this.ee.t3, this.ee.t3, 2); + // @00128740 SLL t2, t2, 2 + MobUt.SLL(this.ee.t2, this.ee.t2, 2); + // @00128744 LWC1 $f17, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[17], (0u + this.ee.t7.UL0)); + // @00128748 SLL t6, t6, 2 + MobUt.SLL(this.ee.t6, this.ee.t6, 2); + // @0012874C ANDI t5, t5, $fffc + this.ee.t5.UD0 = ((ushort)((this.ee.t5.US0 & 65532))); + // @00128750 ADDU t2, t2, s6 + this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + this.ee.s6.SD0))); + // @00128754 ADDU t5, t5, s3 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s3.SD0))); + // @00128758 ADDU t4, t4, s3 + this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + this.ee.s3.SD0))); + // @0012875C LWC1 $f16, $0000(t5) + MobUt.LWC1(this.ee, this.ee.fpr[16], (0u + this.ee.t5.UL0)); + // @00128760 ADDU t6, t6, s5 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s5.SD0))); + // @00128764 LWC1 $f13, $0000(t4) + MobUt.LWC1(this.ee, this.ee.fpr[13], (0u + this.ee.t4.UL0)); + // @00128768 ADDU t3, t3, s6 + this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s6.SD0))); + // @0012876C LWC1 $f14, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t6.UL0)); + // @00128770 LWC1 $f15, $0000(t3) + MobUt.LWC1(this.ee, this.ee.fpr[15], (0u + this.ee.t3.UL0)); + // @00128774 ADDIU t7, zero, $0001 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @00128778 BEQ t1, t7, $0012879c + if ((this.ee.t1.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1214364u; + } + // @0012877C LWC1 $f18, $0000(t2) + MobUt.LWC1(this.ee, this.ee.fpr[18], (0u + this.ee.t2.UL0)); + } + + public virtual void funct00128780() + { + this.ee.pc = 1214348u; + // @00128780 ADDIU t7, zero, $0002 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); + // @00128784 BNEL t1, t7, $001285f0 + if ((this.ee.t1.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1213936u; + // @00128788 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + } + } + + public virtual void funct0012878c() + { + this.ee.pc = 1214356u; + // @0012878C JAL $001284b0 + this.ee.ra.UL0 = 1214356u; + this.ee.pc = 1213616u; + // @00128790 MOV.S $f12, $f20 + this.ee.fpr[12].f = this.ee.fpr[20].f; + } + + public virtual void funct00128794() + { + this.ee.pc = 1214364u; + // @00128794 BEQ zero, zero, $001285f4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213940u; + } + // @00128798 LD s0, $0010(sp) + MobUt.LD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); + } + + public virtual void funct0012879c() + { + this.ee.pc = 1214400u; + // @0012879C SUB.S $f0, $f17, $f14 + this.ee.fpr[0].f = (this.ee.fpr[17].f - this.ee.fpr[14].f); + // @001287A0 SUB.S $f1, $f20, $f13 + this.ee.fpr[1].f = (this.ee.fpr[20].f - this.ee.fpr[13].f); + // @001287A4 SUB.S $f2, $f16, $f13 + this.ee.fpr[2].f = (this.ee.fpr[16].f - this.ee.fpr[13].f); + // @001287A8 MUL.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[1].f); + // @001287AC NOP + MobUt.Latency(); + // @001287B0 NOP + MobUt.Latency(); + // @001287B4 DIV.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[2].f); + // @001287B8 BEQ zero, zero, $001285f0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213936u; + } + // @001287BC ADD.S $f0, $f14, $f0 + this.ee.fpr[0].f = (this.ee.fpr[14].f + this.ee.fpr[0].f); + } + + public virtual void funct001287c0() + { + this.ee.pc = 1214412u; + // @001287C0 SLT t7, t2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t2.SD0 < this.ee.t5.SD0)); + // @001287C4 BEQ t7, zero, $001287d8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214424u; + } + // @001287C8 NOP + MobUt.Latency(); + } + + public virtual void funct001287cc() + { + this.ee.pc = 1214424u; + // @001287CC DADDU a3, t3, zero + this.ee.a3.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); + // @001287D0 BEQ zero, zero, $001286f4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214196u; + } + // @001287D4 DADDU s4, t1, zero + this.ee.s4.UD0 = (this.ee.t1.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001287d8() + { + this.ee.pc = 1214432u; + // @001287D8 BEQL t5, t6, $001287f4 + if ((this.ee.t5.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1214452u; + // @001287DC DADDU s1, t1, zero + this.ee.s1.UD0 = (this.ee.t1.UD0 + this.ee.r0.UD0); + } + } + + public virtual void funct001287e0() + { + this.ee.pc = 1214440u; + // @001287E0 BNE t5, t2, $001286fc + if ((this.ee.t5.UD0 != this.ee.t2.UD0)) + { + this.ee.pc = 1214204u; + } + // @001287E4 SLTI t7, t0, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t0.SD0 < 2)); + } + + public virtual void funct001287e8() + { + this.ee.pc = 1214452u; + // @001287E8 DADDU s4, t1, zero + this.ee.s4.UD0 = (this.ee.t1.UD0 + this.ee.r0.UD0); + // @001287EC BEQ zero, zero, $00128704 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214212u; + } + // @001287F0 ADDIU s1, t1, $fff8 + this.ee.s1.SD0 = ((int)((this.ee.t1.SD0 + -8))); + } + + public virtual void funct001287f4() + { + this.ee.pc = 1214460u; + // @001287F4 BEQ zero, zero, $00128704 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214212u; + } + // @001287F8 ADDIU s4, t1, $0008 + this.ee.s4.SD0 = ((int)((this.ee.t1.SD0 + 8))); + } + + public virtual void funct001287fc() + { + this.ee.pc = 1214468u; + // @001287FC BEQ zero, zero, $0012861c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213980u; + } + // @00128800 LHU t7, $0002(t1) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.t1.UL0)); + } + + public virtual void funct00128804() + { + this.ee.pc = 1214528u; + // @00128804 SLL t7, t2, 2 + MobUt.SLL(this.ee.t7, this.ee.t2, 2); + // @00128808 LHU t6, $0004(s1) + MobUt.LHU(this.ee, this.ee.t6, (4u + this.ee.s1.UL0)); + // @0012880C ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @00128810 LHU t5, $0002(s1) + MobUt.LHU(this.ee, this.ee.t5, (2u + this.ee.s1.UL0)); + // @00128814 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00128818 SLL t6, t6, 2 + MobUt.SLL(this.ee.t6, this.ee.t6, 2); + // @0012881C ADDU t6, t6, s6 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s6.SD0))); + // @00128820 SLL t5, t5, 2 + MobUt.SLL(this.ee.t5, this.ee.t5, 2); + // @00128824 SUB.S $f0, $f0, $f12 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); + // @00128828 ADDU t5, t5, s5 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s5.SD0))); + // @0012882C LWC1 $f2, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t6.UL0)); + // @00128830 LWC1 $f1, $0000(t5) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t5.UL0)); + // @00128834 MUL.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[2].f); + // @00128838 BEQ zero, zero, $001285f0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213936u; + } + // @0012883C SUB.S $f0, $f1, $f0 + this.ee.fpr[0].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); + } + + public virtual void funct00128840() + { + this.ee.pc = 1214548u; + // @00128840 LHU t7, $fff8(t4) + MobUt.LHU(this.ee, this.ee.t7, (4294967288u + this.ee.t4.UL0)); + // @00128844 SRL t4, t7, 2 + MobUt.SRL(this.ee.t4, this.ee.t7, 2); + // @00128848 SLT a2, a2, t4 + this.ee.a2.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t4.SD0)); + // @0012884C BNEL a2, zero, $0012868c + if ((this.ee.a2.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1214092u; + // @00128850 ANDI t4, t0, $ffff + this.ee.t4.UD0 = ((ushort)((this.ee.t0.US0 & 65535))); + } + } + + public virtual void funct00128854() + { + this.ee.pc = 1214572u; + // @00128854 LHU t7, $0002(a1) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.a1.UL0)); + // @00128858 ADDIU t6, zero, $0001 + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @0012885C SRL t7, t7, 6 + MobUt.SRL(this.ee.t7, this.ee.t7, 6); + // @00128860 ANDI t5, t7, $0003 + this.ee.t5.UD0 = ((ushort)((this.ee.t7.US0 & 3))); + // @00128864 BEQ t5, t6, $001288d8 + if ((this.ee.t5.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1214680u; + } + // @00128868 SLTI t7, t5, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < 2)); + } + + public virtual void funct0012886c() + { + this.ee.pc = 1214580u; + // @0012886C BEQ t7, zero, $00128884 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214596u; + } + // @00128870 ADDIU t7, zero, $0002 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); + } + + public virtual void funct00128874() + { + this.ee.pc = 1214588u; + // @00128874 BNEL t5, zero, $001285f0 + if ((this.ee.t5.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1213936u; + // @00128878 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + } + } + + public virtual void funct0012887c() + { + this.ee.pc = 1214596u; + // @0012887C BEQ zero, zero, $0012861c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213980u; + } + // @00128880 LHU t7, $0002(s4) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s4.UL0)); + } + + public virtual void funct00128884() + { + this.ee.pc = 1214604u; + // @00128884 BNEL t5, t7, $001285f0 + if ((this.ee.t5.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1213936u; + // @00128888 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + } + } + + public virtual void funct0012888c() + { + this.ee.pc = 1214640u; + // @0012888C SLL t7, t2, 2 + MobUt.SLL(this.ee.t7, this.ee.t2, 2); + // @00128890 SLL t6, t4, 2 + MobUt.SLL(this.ee.t6, this.ee.t4, 2); + // @00128894 ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @00128898 ADDU t6, t6, s3 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); + // @0012889C LWC1 $f2, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t6.UL0)); + // @001288A0 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @001288A4 C.LT.S $f2, $f12 + this.ee.fcr31_23 = (this.ee.fpr[2].f < this.ee.fpr[12].f); + // @001288A8 BC1F $00128670 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1214064u; + } + // @001288AC SUB.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f - this.ee.fpr[0].f); + } + + public virtual void funct001288b0() + { + this.ee.pc = 1214672u; + // @001288B0 SUB.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + // @001288B4 C.LT.S $f2, $f12 + this.ee.fcr31_23 = (this.ee.fpr[2].f < this.ee.fpr[12].f); + // @001288B8 NOP + MobUt.Latency(); + // @001288BC NOP + MobUt.Latency(); + // @001288C0 NOP + MobUt.Latency(); + // @001288C4 NOP + MobUt.Latency(); + // @001288C8 BC1TL $001288b4 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1214644u; + // @001288CC SUB.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + } + } + + public virtual void funct001288b4() + { + this.ee.pc = 1214672u; + // @001288B4 C.LT.S $f2, $f12 + this.ee.fcr31_23 = (this.ee.fpr[2].f < this.ee.fpr[12].f); + // @001288B8 NOP + MobUt.Latency(); + // @001288BC NOP + MobUt.Latency(); + // @001288C0 NOP + MobUt.Latency(); + // @001288C4 NOP + MobUt.Latency(); + // @001288C8 BC1TL $001288b4 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1214644u; + // @001288CC SUB.S $f12, $f12, $f0 + this.ee.fpr[12].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + } + } + + public virtual void funct001288d0() + { + this.ee.pc = 1214680u; + // @001288D0 BEQ zero, zero, $00128670 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214064u; + } + // @001288D4 MOV.S $f20, $f12 + this.ee.fpr[20].f = this.ee.fpr[12].f; + } + + public virtual void funct001288d8() + { + this.ee.pc = 1214740u; + // @001288D8 SLL t7, t4, 2 + MobUt.SLL(this.ee.t7, this.ee.t4, 2); + // @001288DC LHU t6, $0006(s4) + MobUt.LHU(this.ee, this.ee.t6, (6u + this.ee.s4.UL0)); + // @001288E0 ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @001288E4 LHU t5, $0002(s4) + MobUt.LHU(this.ee, this.ee.t5, (2u + this.ee.s4.UL0)); + // @001288E8 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @001288EC SLL t6, t6, 2 + MobUt.SLL(this.ee.t6, this.ee.t6, 2); + // @001288F0 ADDU t6, t6, s6 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s6.SD0))); + // @001288F4 SLL t5, t5, 2 + MobUt.SLL(this.ee.t5, this.ee.t5, 2); + // @001288F8 SUB.S $f0, $f12, $f0 + this.ee.fpr[0].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + // @001288FC ADDU t5, t5, s5 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s5.SD0))); + // @00128900 LWC1 $f2, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t6.UL0)); + // @00128904 LWC1 $f1, $0000(t5) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t5.UL0)); + // @00128908 MUL.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[2].f); + // @0012890C BEQ zero, zero, $001285f0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1213936u; + } + // @00128910 ADD.S $f0, $f1, $f0 + this.ee.fpr[0].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); + } + + public virtual void funct00128918() + { + this.ee.pc = 1214808u; + // @00128918 ADDIU sp, sp, $ffb0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -80))); + // @0012891C SWC1 $f20, $0048(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (72u + this.ee.sp.UL0)); + // @00128920 ADDIU a2, sp, $0004 + this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 4))); + // @00128924 SD s5, $0038(sp) + MobUt.SD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); + // @00128928 MOV.S $f20, $f12 + this.ee.fpr[20].f = this.ee.fpr[12].f; + // @0012892C SD s4, $0030(sp) + MobUt.SD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); + // @00128930 SD s0, $0010(sp) + MobUt.SD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); + // @00128934 DADDU s5, a1, zero + this.ee.s5.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + // @00128938 SD s1, $0018(sp) + MobUt.SD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); + // @0012893C DADDU s4, a0, zero + this.ee.s4.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); + // @00128940 SD s2, $0020(sp) + MobUt.SD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); + // @00128944 DADDU a1, sp, zero + this.ee.a1.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); + // @00128948 SD s3, $0028(sp) + MobUt.SD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); + // @0012894C SD ra, $0040(sp) + MobUt.SD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); + // @00128950 JAL $001283d8 + this.ee.ra.UL0 = 1214808u; + this.ee.pc = 1213400u; + // @00128954 DADDU s2, zero, zero + this.ee.s2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00128958() + { + this.ee.pc = 1214828u; + // @00128958 LW s1, $0004(s4) + MobUt.LW(this.ee, this.ee.s1, (4u + this.ee.s4.UL0)); + // @0012895C LW t7, $0030(s1) + MobUt.LW(this.ee, this.ee.t7, (48u + this.ee.s1.UL0)); + // @00128960 LW s3, $0034(s1) + MobUt.LW(this.ee, this.ee.s3, (52u + this.ee.s1.UL0)); + // @00128964 BLEZ s3, $001289e4 + if ((this.ee.s3.SD0 <= 0)) + { + this.ee.pc = 1214948u; + } + // @00128968 ADDU s0, s1, t7 + this.ee.s0.SD0 = ((int)((this.ee.s1.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012896c() + { + this.ee.pc = 1214852u; + // @0012896C MOV.S $f12, $f20 + this.ee.fpr[12].f = this.ee.fpr[20].f; + // @00128970 LW a2, $0000(sp) + MobUt.LW(this.ee, this.ee.a2, (0u + this.ee.sp.UL0)); + // @00128974 LW a3, $0004(sp) + MobUt.LW(this.ee, this.ee.a3, (4u + this.ee.sp.UL0)); + // @00128978 DADDU a0, s4, zero + this.ee.a0.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + // @0012897C JAL $00128530 + this.ee.ra.UL0 = 1214852u; + this.ee.pc = 1213744u; + // @00128980 DADDU a1, s0, zero + this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00128984() + { + this.ee.pc = 1214876u; + // @00128984 LBU t4, $0002(s0) + MobUt.LBU(this.ee, this.ee.t4, (2u + this.ee.s0.UL0)); + // @00128988 ANDI t7, t4, $000f + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 15))); + // @0012898C ANDI t7, t7, $00ff + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 255))); + // @00128990 SLTIU t6, t7, $0009 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < 9ul)); + // @00128994 BEQ t6, zero, $001289d4 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214932u; + } + // @00128998 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + } + + public virtual void funct0012899c() + { + this.ee.pc = 1214900u; + // @0012899C SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @001289A0 ADDIU t6, t6, $8244 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -32188))); + // @001289A4 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @001289A8 LW t5, $0000(t7) + MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); + // @001289AC JR t5 + this.ee.pc = this.ee.t5.UL[0]; + // @001289B0 NOP + MobUt.Latency(); + } + + public virtual void funct001289b4() + { + this.ee.pc = 1214948u; + // @001289B4 LHU t7, $0000(s0) + MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); + // @001289B8 ANDI t5, t4, $000f + this.ee.t5.UD0 = ((ushort)((this.ee.t4.US0 & 15))); + // @001289BC LW t6, $001c(s5) + MobUt.LW(this.ee, this.ee.t6, (28u + this.ee.s5.UL0)); + // @001289C0 SLL t5, t5, 2 + MobUt.SLL(this.ee.t5, this.ee.t5, 2); + // @001289C4 SLL t7, t7, 4 + MobUt.SLL(this.ee.t7, this.ee.t7, 4); + // @001289C8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @001289CC ADDU t6, t6, t5 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); + // @001289D0 SWC1 $f0, $0000(t6) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @001289D4 ADDIU s2, s2, $0001 + this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); + // @001289D8 SLT t7, s2, s3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.s3.SD0)); + // @001289DC BNE t7, zero, $0012896c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1214828u; + } + // @001289E0 ADDIU s0, s0, $0006 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 6))); + } + + public virtual void funct001289d4() + { + this.ee.pc = 1214948u; + // @001289D4 ADDIU s2, s2, $0001 + this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); + // @001289D8 SLT t7, s2, s3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.s3.SD0)); + // @001289DC BNE t7, zero, $0012896c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1214828u; + } + // @001289E0 ADDIU s0, s0, $0006 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 6))); + } + + public virtual void funct001289e4() + { + this.ee.pc = 1214976u; + // @001289E4 LW t6, $0018(s1) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.s1.UL0)); + // @001289E8 DADDU s2, zero, zero + this.ee.s2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @001289EC LW t7, $0038(s1) + MobUt.LW(this.ee, this.ee.t7, (56u + this.ee.s1.UL0)); + // @001289F0 LW s3, $003c(s1) + MobUt.LW(this.ee, this.ee.s3, (60u + this.ee.s1.UL0)); + // @001289F4 ADDU s5, s1, t6 + this.ee.s5.SD0 = ((int)((this.ee.s1.SD0 + this.ee.t6.SD0))); + // @001289F8 BLEZ s3, $00128a74 + if ((this.ee.s3.SD0 <= 0)) + { + this.ee.pc = 1215092u; + } + // @001289FC ADDU s0, s1, t7 + this.ee.s0.SD0 = ((int)((this.ee.s1.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct00128a00() + { + this.ee.pc = 1215000u; + // @00128A00 MOV.S $f12, $f20 + this.ee.fpr[12].f = this.ee.fpr[20].f; + // @00128A04 LW a2, $0000(sp) + MobUt.LW(this.ee, this.ee.a2, (0u + this.ee.sp.UL0)); + // @00128A08 LW a3, $0004(sp) + MobUt.LW(this.ee, this.ee.a3, (4u + this.ee.sp.UL0)); + // @00128A0C DADDU a0, s4, zero + this.ee.a0.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + // @00128A10 JAL $00128530 + this.ee.ra.UL0 = 1215000u; + this.ee.pc = 1213744u; + // @00128A14 DADDU a1, s0, zero + this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00128a18() + { + this.ee.pc = 1215024u; + // @00128A18 LBU t4, $0002(s0) + MobUt.LBU(this.ee, this.ee.t4, (2u + this.ee.s0.UL0)); + // @00128A1C ANDI t7, t4, $000f + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 15))); + // @00128A20 ANDI t7, t7, $00ff + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 255))); + // @00128A24 SLTIU t6, t7, $0009 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < 9ul)); + // @00128A28 BEQ t6, zero, $00128a64 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215076u; + } + // @00128A2C LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + } + + public virtual void funct00128a30() + { + this.ee.pc = 1215048u; + // @00128A30 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @00128A34 ADDIU t6, t6, $8268 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -32152))); + // @00128A38 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00128A3C LW t5, $0000(t7) + MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); + // @00128A40 JR t5 + this.ee.pc = this.ee.t5.UL[0]; + // @00128A44 NOP + MobUt.Latency(); + } + + public virtual void funct00128a48() + { + this.ee.pc = 1215092u; + // @00128A48 LHU t7, $0000(s0) + MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); + // @00128A4C ANDI t6, t4, $000f + this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 15))); + // @00128A50 SLL t6, t6, 2 + MobUt.SLL(this.ee.t6, this.ee.t6, 2); + // @00128A54 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @00128A58 ADDU t7, s5, t7 + this.ee.t7.SD0 = ((int)((this.ee.s5.SD0 + this.ee.t7.SD0))); + // @00128A5C ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00128A60 SWC1 $f0, $0010(t7) + MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.t7.UL0)); + // @00128A64 ADDIU s2, s2, $0001 + this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); + // @00128A68 SLT t7, s2, s3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.s3.SD0)); + // @00128A6C BNE t7, zero, $00128a00 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1214976u; + } + // @00128A70 ADDIU s0, s0, $0006 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 6))); + } + + public virtual void funct00128a64() + { + this.ee.pc = 1215092u; + // @00128A64 ADDIU s2, s2, $0001 + this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); + // @00128A68 SLT t7, s2, s3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.s3.SD0)); + // @00128A6C BNE t7, zero, $00128a00 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1214976u; + } + // @00128A70 ADDIU s0, s0, $0006 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 6))); + } + + public virtual void funct00128a74() + { + this.ee.pc = 1215132u; + // @00128A74 LD s0, $0010(sp) + MobUt.LD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); + // @00128A78 LD s1, $0018(sp) + MobUt.LD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); + // @00128A7C LD s2, $0020(sp) + MobUt.LD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); + // @00128A80 LD s3, $0028(sp) + MobUt.LD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); + // @00128A84 LD s4, $0030(sp) + MobUt.LD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); + // @00128A88 LD s5, $0038(sp) + MobUt.LD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); + // @00128A8C LD ra, $0040(sp) + MobUt.LD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); + // @00128A90 LWC1 $f20, $0048(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (72u + this.ee.sp.UL0)); + // @00128A94 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00128A98 ADDIU sp, sp, $0050 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 80))); + } + + public virtual void funct00128a9c() + { + this.ee.pc = 1215168u; + // @00128A9C LHU t7, $0000(s0) + MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); + // @00128AA0 ANDI t6, t4, $000f + this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 15))); + // @00128AA4 ADDIU t6, t6, $fffd + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -3))); + // @00128AA8 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @00128AAC SLL t6, t6, 2 + MobUt.SLL(this.ee.t6, this.ee.t6, 2); + // @00128AB0 ADDU t7, s5, t7 + this.ee.t7.SD0 = ((int)((this.ee.s5.SD0 + this.ee.t7.SD0))); + // @00128AB4 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00128AB8 BEQ zero, zero, $00128a64 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215076u; + } + // @00128ABC SWC1 $f0, $0020(t7) + MobUt.SWC1(this.ee, this.ee.fpr[0], (32u + this.ee.t7.UL0)); + } + + public virtual void funct00128ac0() + { + this.ee.pc = 1215204u; + // @00128AC0 LHU t7, $0000(s0) + MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); + // @00128AC4 ANDI t6, t4, $000f + this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 15))); + // @00128AC8 ADDIU t6, t6, $fffa + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -6))); + // @00128ACC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @00128AD0 SLL t6, t6, 2 + MobUt.SLL(this.ee.t6, this.ee.t6, 2); + // @00128AD4 ADDU t7, s5, t7 + this.ee.t7.SD0 = ((int)((this.ee.s5.SD0 + this.ee.t7.SD0))); + // @00128AD8 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00128ADC BEQ zero, zero, $00128a64 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215076u; + } + // @00128AE0 SWC1 $f0, $0030(t7) + MobUt.SWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t7.UL0)); + } + + public virtual void funct00128ae4() + { + this.ee.pc = 1215244u; + // @00128AE4 ANDI t6, t4, $000f + this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 15))); + // @00128AE8 LHU t7, $0000(s0) + MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); + // @00128AEC LW t5, $0020(s5) + MobUt.LW(this.ee, this.ee.t5, (32u + this.ee.s5.UL0)); + // @00128AF0 ADDIU t6, t6, $fffd + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -3))); + // @00128AF4 SLL t7, t7, 4 + MobUt.SLL(this.ee.t7, this.ee.t7, 4); + // @00128AF8 SLL t6, t6, 2 + MobUt.SLL(this.ee.t6, this.ee.t6, 2); + // @00128AFC ADDU t5, t5, t7 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t7.SD0))); + // @00128B00 ADDU t5, t5, t6 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @00128B04 BEQ zero, zero, $001289d4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214932u; + } + // @00128B08 SWC1 $f0, $0000(t5) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); + } + + public virtual void funct00128af4() + { + this.ee.pc = 1215244u; + // @00128AF4 SLL t7, t7, 4 + MobUt.SLL(this.ee.t7, this.ee.t7, 4); + // @00128AF8 SLL t6, t6, 2 + MobUt.SLL(this.ee.t6, this.ee.t6, 2); + // @00128AFC ADDU t5, t5, t7 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t7.SD0))); + // @00128B00 ADDU t5, t5, t6 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @00128B04 BEQ zero, zero, $001289d4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1214932u; + } + // @00128B08 SWC1 $f0, $0000(t5) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); + } + + public virtual void funct00128b0c() + { + this.ee.pc = 1215264u; + // @00128B0C ANDI t6, t4, $000f + this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 15))); + // @00128B10 LHU t7, $0000(s0) + MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); + // @00128B14 LW t5, $0024(s5) + MobUt.LW(this.ee, this.ee.t5, (36u + this.ee.s5.UL0)); + // @00128B18 BEQ zero, zero, $00128af4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215220u; + } + // @00128B1C ADDIU t6, t6, $fffa + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -6))); + } + + public virtual void funct00128b20() + { + this.ee.pc = 1215276u; + // @00128B20 ADDIU sp, sp, $ffe0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); + // @00128B24 BEQ a2, a0, $00128b34 + if ((this.ee.a2.UD0 == this.ee.a0.UD0)) + { + this.ee.pc = 1215284u; + } + // @00128B28 NOP + MobUt.Latency(); + } + + public virtual void funct00128b2c() + { + this.ee.pc = 1215376u; + // @00128B2C LQ t0, $0000(a0) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a0.UL[0])); + // @00128B30 SQ t0, $0000(a2) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a2.UL[0])); + // @00128B34 LQC2 vf1, $0000(a2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a2.UL0)); + // @00128B38 VMUL.xyz vf2, vf1, vf1 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); + // @00128B3C VADDy.x vf2, vf2, vf2y + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); + // @00128B40 VADDz.x vf2, vf2, vf2z + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); + // @00128B44 VSQRT Q, vf2x + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); + // @00128B48 VWAITQ + MobUt.Latency(); + // @00128B4C CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + // @00128B50 VADDq.x vf2, vf0, Q + this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); + // @00128B54 MTC1 t0, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00128B58 VNOP + MobUt.Latency(); + // @00128B5C VDIV Q, vf0w, vf2x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); + // @00128B60 VWAITQ + MobUt.Latency(); + // @00128B64 VMULq.xyz vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + // @00128B68 SQC2 vf1, $0000(a2) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.a2.UL0)); + // @00128B6C ADDIU t5, sp, $0010 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 16))); + // @00128B70 LQC2 vf1, $0000(a0) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a0.UL0)); + // @00128B74 LQC2 vf2, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a1.UL0)); + // @00128B78 VSUB.xyzw vf3, vf0, vf0 + this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); + this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); + this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); + this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); + // @00128B7C VOPMULA.xyz ACC, vf1, vf2 + this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); + this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); + this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); + // @00128B80 VOPMSUB.xyz vf3, vf2, vf1 + this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); + this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); + this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); + // @00128B84 SQC2 vf3, $0000(t5) + MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.t5.UL0)); + // @00128B88 BEQ sp, t5, $00128b9c + if ((this.ee.sp.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1215388u; + } + // @00128B8C ADDIU t7, a2, $0010 + this.ee.t7.SD0 = ((int)((this.ee.a2.SD0 + 16))); + } + + public virtual void funct00128b90() + { + this.ee.pc = 1215420u; + // @00128B90 LQ t0, $0000(t5) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @00128B94 SQ t0, $0000(sp) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); + // @00128B98 ADDIU t7, a2, $0010 + this.ee.t7.SD0 = ((int)((this.ee.a2.SD0 + 16))); + // @00128B9C LQC2 vf1, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @00128BA0 LQC2 vf2, $0000(a0) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a0.UL0)); + // @00128BA4 VSUB.xyzw vf3, vf0, vf0 + this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); + this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); + this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); + this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); + // @00128BA8 VOPMULA.xyz ACC, vf1, vf2 + this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); + this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); + this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); + // @00128BAC VOPMSUB.xyz vf3, vf2, vf1 + this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); + this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); + this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); + // @00128BB0 SQC2 vf3, $0000(t5) + MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.t5.UL0)); + // @00128BB4 BEQ t7, t5, $00128bc4 + if ((this.ee.t7.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1215428u; + } + // @00128BB8 NOP + MobUt.Latency(); + } + + public virtual void funct00128bbc() + { + this.ee.pc = 1215520u; + // @00128BBC LQ t0, $0000(t5) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @00128BC0 SQ t0, $0000(t7) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @00128BC4 LQC2 vf1, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t7.UL0)); + // @00128BC8 VMUL.xyz vf2, vf1, vf1 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); + // @00128BCC VADDy.x vf2, vf2, vf2y + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); + // @00128BD0 VADDz.x vf2, vf2, vf2z + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); + // @00128BD4 VSQRT Q, vf2x + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); + // @00128BD8 VWAITQ + MobUt.Latency(); + // @00128BDC CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + // @00128BE0 VADDq.x vf2, vf0, Q + this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); + // @00128BE4 MTC1 t0, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00128BE8 VNOP + MobUt.Latency(); + // @00128BEC VDIV Q, vf0w, vf2x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); + // @00128BF0 VWAITQ + MobUt.Latency(); + // @00128BF4 VMULq.xyz vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + // @00128BF8 SQC2 vf1, $0000(t7) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t7.UL0)); + // @00128BFC ADDIU t6, a2, $0020 + this.ee.t6.SD0 = ((int)((this.ee.a2.SD0 + 32))); + // @00128C00 LQC2 vf1, $0000(a0) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a0.UL0)); + // @00128C04 LQC2 vf2, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t7.UL0)); + // @00128C08 VSUB.xyzw vf3, vf0, vf0 + this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); + this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); + this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); + this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); + // @00128C0C VOPMULA.xyz ACC, vf1, vf2 + this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); + this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); + this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); + // @00128C10 VOPMSUB.xyz vf3, vf2, vf1 + this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); + this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); + this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); + // @00128C14 SQC2 vf3, $0000(t5) + MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.t5.UL0)); + // @00128C18 BEQ t6, t5, $00128c28 + if ((this.ee.t6.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1215528u; + } + // @00128C1C NOP + MobUt.Latency(); + } + + public virtual void funct00128c20() + { + this.ee.pc = 1215608u; + // @00128C20 LQ t0, $0000(t5) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @00128C24 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @00128C28 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00128C2C VMUL.xyz vf2, vf1, vf1 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[1].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[1].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[1].z); + // @00128C30 VADDy.x vf2, vf2, vf2y + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].y); + // @00128C34 VADDz.x vf2, vf2, vf2z + this.ee.VF[2].x = (this.ee.VF[2].x + this.ee.VF[2].z); + // @00128C38 VSQRT Q, vf2x + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[2].x)))); + // @00128C3C VWAITQ + MobUt.Latency(); + // @00128C40 CFC2 t0, $vi22 + MobUt.CFC2(this.ee.t0, this.ee.VI[22]); + // @00128C44 VADDq.x vf2, vf0, Q + this.ee.VF[2].x = (this.ee.VF[0].x + this.ee.Vq.f); + // @00128C48 MTC1 t0, $f1 + this.ee.fpr[1].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00128C4C VNOP + MobUt.Latency(); + // @00128C50 VDIV Q, vf0w, vf2x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[2].x); + // @00128C54 VWAITQ + MobUt.Latency(); + // @00128C58 VMULq.xyz vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + // @00128C5C SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00128C60 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @00128C64 SWC1 $f0, $000c(a2) + MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.a2.UL0)); + // @00128C68 SWC1 $f0, $002c(a2) + MobUt.SWC1(this.ee, this.ee.fpr[0], (44u + this.ee.a2.UL0)); + // @00128C6C SWC1 $f0, $001c(a2) + MobUt.SWC1(this.ee, this.ee.fpr[0], (28u + this.ee.a2.UL0)); + // @00128C70 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00128C74 ADDIU sp, sp, $0020 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); + } + + public virtual void funct00128c78() + { + this.ee.pc = 1215628u; + // @00128C78 ADDIU sp, sp, $ffc0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -64))); + // @00128C7C DADDU t5, a2, zero + this.ee.t5.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); + // @00128C80 DADDU t4, a3, zero + this.ee.t4.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); + // @00128C84 BLTZ a3, $00128d9c + if ((this.ee.a3.SD0 < 0)) + { + this.ee.pc = 1215900u; + } + // @00128C88 DADDU t3, t0, zero + this.ee.t3.UD0 = (this.ee.t0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00128c8c() + { + this.ee.pc = 1215648u; + // @00128C8C LW t6, $0004(a0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.a0.UL0)); + // @00128C90 LHU a2, $0010(t6) + MobUt.LHU(this.ee, this.ee.a2, (16u + this.ee.t6.UL0)); + // @00128C94 SLT t7, t5, a2 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.a2.SD0)); + // @00128C98 BEQ t7, zero, $00128d8c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215884u; + } + // @00128C9C DADDU a3, sp, zero + this.ee.a3.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00128ca0() + { + this.ee.pc = 1215692u; + // @00128CA0 LW t6, $002c(a1) + MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.a1.UL0)); + // @00128CA4 SLL t7, t5, 6 + MobUt.SLL(this.ee.t7, this.ee.t5, 6); + // @00128CA8 ADDU a2, t6, t7 + this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00128CAC ADDIU t7, a2, $0030 + this.ee.t7.SD0 = ((int)((this.ee.a2.SD0 + 48))); + // @00128CB0 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @00128CB4 SQ t0, $0000(a3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a3.UL[0])); + // @00128CB8 LW t6, $0004(a0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.a0.UL0)); + // @00128CBC LHU a3, $0010(t6) + MobUt.LHU(this.ee, this.ee.a3, (16u + this.ee.t6.UL0)); + // @00128CC0 SLT t7, t4, a3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.a3.SD0)); + // @00128CC4 BEQ t7, zero, $00128d7c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215868u; + } + // @00128CC8 ADDIU t5, sp, $0010 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00128ca8() + { + this.ee.pc = 1215692u; + // @00128CA8 ADDU a2, t6, t7 + this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00128CAC ADDIU t7, a2, $0030 + this.ee.t7.SD0 = ((int)((this.ee.a2.SD0 + 48))); + // @00128CB0 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @00128CB4 SQ t0, $0000(a3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a3.UL[0])); + // @00128CB8 LW t6, $0004(a0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.a0.UL0)); + // @00128CBC LHU a3, $0010(t6) + MobUt.LHU(this.ee, this.ee.a3, (16u + this.ee.t6.UL0)); + // @00128CC0 SLT t7, t4, a3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.a3.SD0)); + // @00128CC4 BEQ t7, zero, $00128d7c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215868u; + } + // @00128CC8 ADDIU t5, sp, $0010 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00128ccc() + { + this.ee.pc = 1215780u; + // @00128CCC LW t6, $002c(a1) + MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.a1.UL0)); + // @00128CD0 SLL t7, t4, 6 + MobUt.SLL(this.ee.t7, this.ee.t4, 6); + // @00128CD4 ADDU a0, t6, t7 + this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00128CD8 ADDIU t7, a0, $0030 + this.ee.t7.SD0 = ((int)((this.ee.a0.SD0 + 48))); + // @00128CDC LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @00128CE0 SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @00128CE4 ADDIU t6, sp, $0030 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 48))); + // @00128CE8 LQC2 vf1, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @00128CEC LQC2 vf2, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t5.UL0)); + // @00128CF0 VADD.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y + this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z + this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w + this.ee.VF[2].w); + // @00128CF4 SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00128CF8 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00128CFC ADDIU t7, t7, $828c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32116))); + // @00128D00 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00128D04 ADDIU t7, sp, $0020 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 32))); + // @00128D08 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00128D0C MFC1 t0, $f0 + MobUt.MFC1(this.ee.t0, this.ee.fpr[0]); + // @00128D10 QMTC2 t0, vf2 + MobUt.QMTC2(this.ee.t0, this.ee.VF[2]); + // @00128D14 VMULx.xyzw vf1, vf1, vf2x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].x); + // @00128D18 SQC2 vf1, $0000(t7) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t7.UL0)); + // @00128D1C BEQ t3, t7, $00128d2c + if ((this.ee.t3.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1215788u; + } + // @00128D20 NOP + MobUt.Latency(); + } + + public virtual void funct00128cd4() + { + this.ee.pc = 1215780u; + // @00128CD4 ADDU a0, t6, t7 + this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00128CD8 ADDIU t7, a0, $0030 + this.ee.t7.SD0 = ((int)((this.ee.a0.SD0 + 48))); + // @00128CDC LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @00128CE0 SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @00128CE4 ADDIU t6, sp, $0030 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 48))); + // @00128CE8 LQC2 vf1, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @00128CEC LQC2 vf2, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t5.UL0)); + // @00128CF0 VADD.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y + this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z + this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w + this.ee.VF[2].w); + // @00128CF4 SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00128CF8 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00128CFC ADDIU t7, t7, $828c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32116))); + // @00128D00 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00128D04 ADDIU t7, sp, $0020 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 32))); + // @00128D08 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00128D0C MFC1 t0, $f0 + MobUt.MFC1(this.ee.t0, this.ee.fpr[0]); + // @00128D10 QMTC2 t0, vf2 + MobUt.QMTC2(this.ee.t0, this.ee.VF[2]); + // @00128D14 VMULx.xyzw vf1, vf1, vf2x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].x); + // @00128D18 SQC2 vf1, $0000(t7) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t7.UL0)); + // @00128D1C BEQ t3, t7, $00128d2c + if ((this.ee.t3.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1215788u; + } + // @00128D20 NOP + MobUt.Latency(); + } + + public virtual void funct00128d24() + { + this.ee.pc = 1215796u; + // @00128D24 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @00128D28 SQ t0, $0000(t3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); + // @00128D2C BEQ t1, zero, $00128d74 + if ((this.ee.t1.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215860u; + } + // @00128D30 NOP + MobUt.Latency(); + } + + public virtual void funct00128d2c() + { + this.ee.pc = 1215796u; + // @00128D2C BEQ t1, zero, $00128d74 + if ((this.ee.t1.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215860u; + } + // @00128D30 NOP + MobUt.Latency(); + } + + public virtual void funct00128d34() + { + this.ee.pc = 1215804u; + // @00128D34 BEQ t2, zero, $00128d74 + if ((this.ee.t2.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215860u; + } + // @00128D38 NOP + MobUt.Latency(); + } + + public virtual void funct00128d3c() + { + this.ee.pc = 1215852u; + // @00128D3C LQC2 vf5, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); + // @00128D40 LQC2 vf1, $0000(t1) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t1.UL0)); + // @00128D44 LQC2 vf2, $0010(t1) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t1.UL0)); + // @00128D48 LQC2 vf3, $0020(t1) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t1.UL0)); + // @00128D4C LQC2 vf4, $0030(t1) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t1.UL0)); + // @00128D50 VMULAx.xyzw ACC, vf1, vf5x + // @00128D54 VMADDAy.xyzw ACC, vf2, vf5y + // @00128D58 VMADDAz.xyzw ACC, vf3, vf5z + // @00128D5C VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @00128D60 SQC2 vf5, $0000(sp) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.sp.UL0)); + // @00128D64 BEQ t2, sp, $00128d74 + if ((this.ee.t2.UD0 == this.ee.sp.UD0)) + { + this.ee.pc = 1215860u; + } + // @00128D68 NOP + MobUt.Latency(); + } + + public virtual void funct00128d6c() + { + this.ee.pc = 1215868u; + // @00128D6C LQ t0, $0000(sp) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); + // @00128D70 SQ t0, $0000(t2) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t2.UL[0])); + // @00128D74 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00128D78 ADDIU sp, sp, $0040 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 64))); + } + + public virtual void funct00128d7c() + { + this.ee.pc = 1215884u; + // @00128D7C SUBU t7, t4, a3 + this.ee.t7.SD0 = ((int)((this.ee.t4.UD0 - this.ee.a3.UD0))); + // @00128D80 LW t6, $0010(a0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.a0.UL0)); + // @00128D84 BEQ zero, zero, $00128cd4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215700u; + } + // @00128D88 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct00128d8c() + { + this.ee.pc = 1215900u; + // @00128D8C SUBU t7, t5, a2 + this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.a2.UD0))); + // @00128D90 LW t6, $0010(a0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.a0.UL0)); + // @00128D94 BEQ zero, zero, $00128ca8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215656u; + } + // @00128D98 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct00128d9c() + { + this.ee.pc = 1215920u; + // @00128D9C LW t7, $0004(a0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); + // @00128DA0 LHU a2, $0010(t7) + MobUt.LHU(this.ee, this.ee.a2, (16u + this.ee.t7.UL0)); + // @00128DA4 SLT t6, t5, a2 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.a2.SD0)); + // @00128DA8 BEQ t6, zero, $00128dd8 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215960u; + } + // @00128DAC SUBU t7, t5, a2 + this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.a2.UD0))); + } + + public virtual void funct00128db0() + { + this.ee.pc = 1215944u; + // @00128DB0 LW t6, $002c(a1) + MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.a1.UL0)); + // @00128DB4 SLL t7, t5, 6 + MobUt.SLL(this.ee.t7, this.ee.t5, 6); + // @00128DB8 ADDU a0, t6, t7 + this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00128DBC ADDIU a0, a0, $0030 + this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 48))); + // @00128DC0 BEQ t3, a0, $00128d2c + if ((this.ee.t3.UD0 == this.ee.a0.UD0)) + { + this.ee.pc = 1215788u; + } + // @00128DC4 NOP + MobUt.Latency(); + } + + public virtual void funct00128db8() + { + this.ee.pc = 1215944u; + // @00128DB8 ADDU a0, t6, t7 + this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00128DBC ADDIU a0, a0, $0030 + this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 48))); + // @00128DC0 BEQ t3, a0, $00128d2c + if ((this.ee.t3.UD0 == this.ee.a0.UD0)) + { + this.ee.pc = 1215788u; + } + // @00128DC4 NOP + MobUt.Latency(); + } + + public virtual void funct00128dc8() + { + this.ee.pc = 1215960u; + // @00128DC8 LQ t0, $0000(a0) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a0.UL[0])); + // @00128DCC SQ t0, $0000(t3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); + // @00128DD0 BEQ zero, zero, $00128d2c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215788u; + } + // @00128DD4 NOP + MobUt.Latency(); + } + + public virtual void funct00128dd8() + { + this.ee.pc = 1215972u; + // @00128DD8 LW t6, $0010(a0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.a0.UL0)); + // @00128DDC BEQ zero, zero, $00128db8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1215928u; + } + // @00128DE0 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct00128de8() + { + this.ee.pc = 1216024u; + // @00128DE8 ADDIU sp, sp, $fff0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); + // @00128DEC DADDU t3, a3, zero + this.ee.t3.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); + // @00128DF0 SD ra, $0000(sp) + MobUt.SD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); + // @00128DF4 DADDU t5, t0, zero + this.ee.t5.UD0 = (this.ee.t0.UD0 + this.ee.r0.UD0); + // @00128DF8 DADDU t4, t1, zero + this.ee.t4.UD0 = (this.ee.t1.UD0 + this.ee.r0.UD0); + // @00128DFC ADDIU a3, zero, $ffff + this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + -1))); + // @00128E00 LBU t6, $0000(a2) + MobUt.LBU(this.ee, this.ee.t6, (0u + this.ee.a2.UL0)); + // @00128E04 DADDU t0, t3, zero + this.ee.t0.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); + // @00128E08 DADDU t1, t5, zero + this.ee.t1.UD0 = (this.ee.t5.UD0 + this.ee.r0.UD0); + // @00128E0C ADDIU t7, zero, $0005 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 5))); + // @00128E10 BNE t6, t7, $00128e2c + if ((this.ee.t6.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1216044u; + } + // @00128E14 DADDU t2, t4, zero + this.ee.t2.UD0 = (this.ee.t4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00128e20() + { + this.ee.pc = 1216044u; + // @00128E20 LD ra, $0000(sp) + MobUt.LD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); + // @00128E24 J $00128c78 + this.ee.pc = 1215608u; + // @00128E28 ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00128e2c() + { + this.ee.pc = 1216060u; + // @00128E2C LHU a2, $0004(a2) + MobUt.LHU(this.ee, this.ee.a2, (4u + this.ee.a2.UL0)); + // @00128E30 DADDU t0, t3, zero + this.ee.t0.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); + // @00128E34 BEQ zero, zero, $00128e20 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216032u; + } + // @00128E38 DADDU t1, t5, zero + this.ee.t1.UD0 = (this.ee.t5.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00128e40() + { + this.ee.pc = 1216136u; + // @00128E40 ADDIU sp, sp, $ff90 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -112))); + // @00128E44 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @00128E48 SD s2, $0030(sp) + MobUt.SD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); + // @00128E4C ANDI a2, a2, $ffff + this.ee.a2.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); + // @00128E50 SD s4, $0040(sp) + MobUt.SD(this.ee, this.ee.s4, (64u + this.ee.sp.UL0)); + // @00128E54 SD s0, $0020(sp) + MobUt.SD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); + // @00128E58 DADDU s2, a0, zero + this.ee.s2.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); + // @00128E5C SD s1, $0028(sp) + MobUt.SD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); + // @00128E60 SD s3, $0038(sp) + MobUt.SD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); + // @00128E64 SD s5, $0048(sp) + MobUt.SD(this.ee, this.ee.s5, (72u + this.ee.sp.UL0)); + // @00128E68 SD s6, $0050(sp) + MobUt.SD(this.ee, this.ee.s6, (80u + this.ee.sp.UL0)); + // @00128E6C SD ra, $0058(sp) + MobUt.SD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); + // @00128E70 SWC1 $f20, $0060(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (96u + this.ee.sp.UL0)); + // @00128E74 LW s0, $0004(a0) + MobUt.LW(this.ee, this.ee.s0, (4u + this.ee.a0.UL0)); + // @00128E78 LW t4, $006c(s0) + MobUt.LW(this.ee, this.ee.t4, (108u + this.ee.s0.UL0)); + // @00128E7C SLTU t7, a2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.UD0 < this.ee.t4.UD0)); + // @00128E80 BEQ t7, zero, $00128ee8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @00128E84 DADDU s4, a1, zero + this.ee.s4.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00128e88() + { + this.ee.pc = 1216176u; + // @00128E88 ADDIU t7, zero, $000c + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 12))); + // @00128E8C LW t6, $0068(s0) + MobUt.LW(this.ee, this.ee.t6, (104u + this.ee.s0.UL0)); + // @00128E90 MULT t7, a2, t7 + this.ee.t7.SD0 = (((long)(this.ee.a2.SL0)) * ((long)(this.ee.t7.SL0))); + // @00128E94 ADDU s1, s0, t6 + this.ee.s1.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t6.SD0))); + // @00128E98 ADDU s3, s1, t7 + this.ee.s3.SD0 = ((int)((this.ee.s1.SD0 + this.ee.t7.SD0))); + // @00128E9C LBU t3, $0000(s3) + MobUt.LBU(this.ee, this.ee.t3, (0u + this.ee.s3.UL0)); + // @00128EA0 ANDI t6, t3, $00ff + this.ee.t6.UD0 = ((ushort)((this.ee.t3.US0 & 255))); + // @00128EA4 SLTIU t7, t6, $002c + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 44ul)); + // @00128EA8 BEQ t7, zero, $00128ee8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @00128EAC SLL t7, t6, 2 + MobUt.SLL(this.ee.t7, this.ee.t6, 2); + } + + public virtual void funct00128eb0() + { + this.ee.pc = 1216200u; + // @00128EB0 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @00128EB4 ADDIU t6, t6, $82a0 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -32096))); + // @00128EB8 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00128EBC LW t5, $0000(t7) + MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); + // @00128EC0 JR t5 + this.ee.pc = this.ee.t5.UL[0]; + // @00128EC4 NOP + MobUt.Latency(); + } + + public virtual void funct00128ee8() + { + this.ee.pc = 1216276u; + // @00128EE8 LD s0, $0020(sp) + MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); + // @00128EEC LD s1, $0028(sp) + MobUt.LD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); + // @00128EF0 LD s2, $0030(sp) + MobUt.LD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); + // @00128EF4 LD s3, $0038(sp) + MobUt.LD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); + // @00128EF8 LD s4, $0040(sp) + MobUt.LD(this.ee, this.ee.s4, (64u + this.ee.sp.UL0)); + // @00128EFC LD s5, $0048(sp) + MobUt.LD(this.ee, this.ee.s5, (72u + this.ee.sp.UL0)); + // @00128F00 LD s6, $0050(sp) + MobUt.LD(this.ee, this.ee.s6, (80u + this.ee.sp.UL0)); + // @00128F04 LD ra, $0058(sp) + MobUt.LD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); + // @00128F08 LWC1 $f20, $0060(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (96u + this.ee.sp.UL0)); + // @00128F0C JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00128F10 ADDIU sp, sp, $0070 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 112))); + } + + public virtual void funct00128eec() + { + this.ee.pc = 1216276u; + // @00128EEC LD s1, $0028(sp) + MobUt.LD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); + // @00128EF0 LD s2, $0030(sp) + MobUt.LD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); + // @00128EF4 LD s3, $0038(sp) + MobUt.LD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); + // @00128EF8 LD s4, $0040(sp) + MobUt.LD(this.ee, this.ee.s4, (64u + this.ee.sp.UL0)); + // @00128EFC LD s5, $0048(sp) + MobUt.LD(this.ee, this.ee.s5, (72u + this.ee.sp.UL0)); + // @00128F00 LD s6, $0050(sp) + MobUt.LD(this.ee, this.ee.s6, (80u + this.ee.sp.UL0)); + // @00128F04 LD ra, $0058(sp) + MobUt.LD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); + // @00128F08 LWC1 $f20, $0060(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (96u + this.ee.sp.UL0)); + // @00128F0C JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00128F10 ADDIU sp, sp, $0070 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 112))); + } + + public virtual void funct00128f64() + { + this.ee.pc = 1216364u; + // @00128F64 JAL $00128e40 + this.ee.ra.UL0 = 1216364u; + this.ee.pc = 1216064u; + // @00128F68 LHU a2, $0008(s3) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); + } + + public virtual void funct00128f6c() + { + this.ee.pc = 1216372u; + // @00128F6C JAL $002ff8a8 + this.ee.ra.UL0 = 1216372u; + this.ee.pc = 3143848u; + // @00128F70 MOV.S $f12, $f0 + this.ee.fpr[12].f = this.ee.fpr[0].f; + } + + public virtual void funct00128f74() + { + this.ee.pc = 1216392u; + // @00128F74 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00128F78 ADDIU t7, t7, $8294 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32108))); + // @00128F7C LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00128F80 BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @00128F84 MUL.S $f0, $f1, $f0 + this.ee.fpr[0].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct00128f80() + { + this.ee.pc = 1216392u; + // @00128F80 BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @00128F84 MUL.S $f0, $f1, $f0 + this.ee.fpr[0].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct0012904c() + { + this.ee.pc = 1216596u; + // @0012904C JAL $00128e40 + this.ee.ra.UL0 = 1216596u; + this.ee.pc = 1216064u; + // @00129050 LHU a2, $0008(s3) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); + } + + public virtual void funct00129054() + { + this.ee.pc = 1216616u; + // @00129054 MOV.S $f20, $f0 + this.ee.fpr[20].f = this.ee.fpr[0].f; + // @00129058 LHU a2, $000a(s3) + MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); + // @0012905C DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @00129060 JAL $00128e40 + this.ee.ra.UL0 = 1216616u; + this.ee.pc = 1216064u; + // @00129064 DADDU a1, s4, zero + this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00129068() + { + this.ee.pc = 1216636u; + // @00129068 MOV.S $f1, $f0 + this.ee.fpr[1].f = this.ee.fpr[0].f; + // @0012906C MOV.S $f0, $f20 + this.ee.fpr[0].f = this.ee.fpr[20].f; + // @00129070 C.LT.S $f20, $f1 + this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[1].f); + // @00129074 BC1T $00128eec + if (this.ee.fcr31_23) + { + this.ee.pc = 1216236u; + } + // @00129078 LD s0, $0020(sp) + MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); + } + + public virtual void funct00129074() + { + this.ee.pc = 1216636u; + // @00129074 BC1T $00128eec + if (this.ee.fcr31_23) + { + this.ee.pc = 1216236u; + } + // @00129078 LD s0, $0020(sp) + MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); + } + + public virtual void funct0012907c() + { + this.ee.pc = 1216644u; + // @0012907C BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @00129080 MOV.S $f0, $f1 + this.ee.fpr[0].f = this.ee.fpr[1].f; + } + + public virtual void funct00129084() + { + this.ee.pc = 1216652u; + // @00129084 JAL $00128e40 + this.ee.ra.UL0 = 1216652u; + this.ee.pc = 1216064u; + // @00129088 LHU a2, $0008(s3) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); + } + + public virtual void funct0012908c() + { + this.ee.pc = 1216672u; + // @0012908C MOV.S $f20, $f0 + this.ee.fpr[20].f = this.ee.fpr[0].f; + // @00129090 LHU a2, $000a(s3) + MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); + // @00129094 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @00129098 JAL $00128e40 + this.ee.ra.UL0 = 1216672u; + this.ee.pc = 1216064u; + // @0012909C DADDU a1, s4, zero + this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001290a0() + { + this.ee.pc = 1216688u; + // @001290A0 MOV.S $f1, $f0 + this.ee.fpr[1].f = this.ee.fpr[0].f; + // @001290A4 MOV.S $f0, $f20 + this.ee.fpr[0].f = this.ee.fpr[20].f; + // @001290A8 BEQ zero, zero, $00129074 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216628u; + } + // @001290AC C.LT.S $f1, $f20 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[20].f); + } + + public virtual void funct00129118() + { + this.ee.pc = 1216812u; + // @00129118 NOP + MobUt.Latency(); + // @0012911C NOP + MobUt.Latency(); + // @00129120 DIV.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f / this.ee.fpr[0].f); + // @00129124 BEQ zero, zero, $00128eec + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216236u; + } + // @00129128 LD s0, $0020(sp) + MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); + } + + public virtual void funct0012912c() + { + this.ee.pc = 1216836u; + // @0012912C LHU t7, $0008(s3) + MobUt.LHU(this.ee, this.ee.t7, (8u + this.ee.s3.UL0)); + // @00129130 ADDIU s0, zero, $000c + this.ee.s0.SD0 = ((int)((this.ee.r0.SD0 + 12))); + // @00129134 MULT t7, t7, s0 + this.ee.t7.SD0 = (((long)(this.ee.t7.SL0)) * ((long)(this.ee.s0.SL0))); + // @00129138 ADDU t7, t7, s1 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s1.SD0))); + // @0012913C JAL $00128e40 + this.ee.ra.UL0 = 1216836u; + this.ee.pc = 1216064u; + // @00129140 LHU a2, $0008(t7) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.t7.UL0)); + } + + public virtual void funct00129144() + { + this.ee.pc = 1216852u; + // @00129144 MTC1 zero, $f1 + this.ee.fpr[1].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @00129148 C.EQ.S $f0, $f1 + this.ee.fcr31_23 = (this.ee.fpr[0].f == this.ee.fpr[1].f); + // @0012914C BC1T $00129184 + if (this.ee.fcr31_23) + { + this.ee.pc = 1216900u; + } + // @00129150 LHU t6, $0008(s3) + MobUt.LHU(this.ee, this.ee.t6, (8u + this.ee.s3.UL0)); + } + + public virtual void funct00129154() + { + this.ee.pc = 1216892u; + // @00129154 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @00129158 DADDU a1, s4, zero + this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + // @0012915C MULT t6, t6, s0 + this.ee.t6.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.s0.SL0))); + // @00129160 ADDU t6, t6, s1 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s1.SD0))); + // @00129164 LHU t7, $000a(t6) + MobUt.LHU(this.ee, this.ee.t7, (10u + this.ee.t6.UL0)); + // @00129168 MULT t7, t7, s0 + this.ee.t7.SD0 = (((long)(this.ee.t7.SL0)) * ((long)(this.ee.s0.SL0))); + // @0012916C ADDU t7, t7, s1 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s1.SD0))); + // @00129170 LHU a2, $0008(t7) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.t7.UL0)); + // @00129174 JAL $00128e40 + this.ee.ra.UL0 = 1216892u; + this.ee.pc = 1216064u; + // @00129178 NOP + MobUt.Latency(); + } + + public virtual void funct00129174() + { + this.ee.pc = 1216892u; + // @00129174 JAL $00128e40 + this.ee.ra.UL0 = 1216892u; + this.ee.pc = 1216064u; + // @00129178 NOP + MobUt.Latency(); + } + + public virtual void funct0012917c() + { + this.ee.pc = 1216900u; + // @0012917C BEQ zero, zero, $00128eec + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216236u; + } + // @00129180 LD s0, $0020(sp) + MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); + } + + public virtual void funct00129184() + { + this.ee.pc = 1216948u; + // @00129184 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @00129188 DADDU a1, s4, zero + this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + // @0012918C MULT t6, t6, s0 + this.ee.t6.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.s0.SL0))); + // @00129190 ADDU t6, t6, s1 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s1.SD0))); + // @00129194 LHU t7, $000a(t6) + MobUt.LHU(this.ee, this.ee.t7, (10u + this.ee.t6.UL0)); + // @00129198 MULT t7, t7, s0 + this.ee.t7.SD0 = (((long)(this.ee.t7.SL0)) * ((long)(this.ee.s0.SL0))); + // @0012919C ADDU t7, t7, s1 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s1.SD0))); + // @001291A0 LHU t6, $000a(t7) + MobUt.LHU(this.ee, this.ee.t6, (10u + this.ee.t7.UL0)); + // @001291A4 MULT t6, t6, s0 + this.ee.t6.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.s0.SL0))); + // @001291A8 ADDU t6, t6, s1 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s1.SD0))); + // @001291AC BEQ zero, zero, $00129174 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216884u; + } + // @001291B0 LHU a2, $0008(t6) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.t6.UL0)); + } + + public virtual void funct0012927c() + { + this.ee.pc = 1217156u; + // @0012927C JAL $00128e40 + this.ee.ra.UL0 = 1217156u; + this.ee.pc = 1216064u; + // @00129280 LHU a2, $0008(s3) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); + } + + public virtual void funct00129284() + { + this.ee.pc = 1217176u; + // @00129284 MOV.S $f20, $f0 + this.ee.fpr[20].f = this.ee.fpr[0].f; + // @00129288 LHU a2, $000a(s3) + MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); + // @0012928C DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @00129290 JAL $00128e40 + this.ee.ra.UL0 = 1217176u; + this.ee.pc = 1216064u; + // @00129294 DADDU a1, s4, zero + this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00129298() + { + this.ee.pc = 1217184u; + // @00129298 BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @0012929C ADD.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f + this.ee.fpr[0].f); + } + + public virtual void funct001292a0() + { + this.ee.pc = 1217192u; + // @001292A0 JAL $00128e40 + this.ee.ra.UL0 = 1217192u; + this.ee.pc = 1216064u; + // @001292A4 LHU a2, $0008(s3) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); + } + + public virtual void funct001292a8() + { + this.ee.pc = 1217212u; + // @001292A8 MOV.S $f20, $f0 + this.ee.fpr[20].f = this.ee.fpr[0].f; + // @001292AC LHU a2, $000a(s3) + MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); + // @001292B0 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @001292B4 JAL $00128e40 + this.ee.ra.UL0 = 1217212u; + this.ee.pc = 1216064u; + // @001292B8 DADDU a1, s4, zero + this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001292bc() + { + this.ee.pc = 1217220u; + // @001292BC BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @001292C0 SUB.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f - this.ee.fpr[0].f); + } + + public virtual void funct001292c4() + { + this.ee.pc = 1217228u; + // @001292C4 JAL $00128e40 + this.ee.ra.UL0 = 1217228u; + this.ee.pc = 1216064u; + // @001292C8 LHU a2, $0008(s3) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); + } + + public virtual void funct001292cc() + { + this.ee.pc = 1217248u; + // @001292CC MOV.S $f20, $f0 + this.ee.fpr[20].f = this.ee.fpr[0].f; + // @001292D0 LHU a2, $000a(s3) + MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); + // @001292D4 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @001292D8 JAL $00128e40 + this.ee.ra.UL0 = 1217248u; + this.ee.pc = 1216064u; + // @001292DC DADDU a1, s4, zero + this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001292e0() + { + this.ee.pc = 1217256u; + // @001292E0 BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @001292E4 MUL.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + } + + public virtual void funct001292e8() + { + this.ee.pc = 1217264u; + // @001292E8 JAL $00128e40 + this.ee.ra.UL0 = 1217264u; + this.ee.pc = 1216064u; + // @001292EC LHU a2, $0008(s3) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); + } + + public virtual void funct001292f0() + { + this.ee.pc = 1217284u; + // @001292F0 MOV.S $f20, $f0 + this.ee.fpr[20].f = this.ee.fpr[0].f; + // @001292F4 LHU a2, $000a(s3) + MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); + // @001292F8 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @001292FC JAL $00128e40 + this.ee.ra.UL0 = 1217284u; + this.ee.pc = 1216064u; + // @00129300 DADDU a1, s4, zero + this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00129304() + { + this.ee.pc = 1217292u; + // @00129304 BEQ zero, zero, $00129118 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216792u; + } + // @00129308 NOP + MobUt.Latency(); + } + + public virtual void funct00129370() + { + this.ee.pc = 1217408u; + // @00129370 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00129374 ADDIU t7, t7, $829c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32100))); + // @00129378 BC1T $00128ee8 + if (this.ee.fcr31_23) + { + this.ee.pc = 1216232u; + } + // @0012937C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + } + + public virtual void funct00129380() + { + this.ee.pc = 1217416u; + // @00129380 BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @00129384 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + } + + public virtual void funct00129388() + { + this.ee.pc = 1217424u; + // @00129388 JAL $00128e40 + this.ee.ra.UL0 = 1217424u; + this.ee.pc = 1216064u; + // @0012938C LHU a2, $0008(s3) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); + } + + public virtual void funct00129390() + { + this.ee.pc = 1217444u; + // @00129390 MOV.S $f20, $f0 + this.ee.fpr[20].f = this.ee.fpr[0].f; + // @00129394 LHU a2, $000a(s3) + MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); + // @00129398 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @0012939C JAL $00128e40 + this.ee.ra.UL0 = 1217444u; + this.ee.pc = 1216064u; + // @001293A0 DADDU a1, s4, zero + this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001293a4() + { + this.ee.pc = 1217452u; + // @001293A4 BEQ zero, zero, $00129370 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1217392u; + } + // @001293A8 C.LT.S $f0, $f20 + this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[20].f); + } + + public virtual void funct001293d0() + { + this.ee.pc = 1217496u; + // @001293D0 JAL $00128e40 + this.ee.ra.UL0 = 1217496u; + this.ee.pc = 1216064u; + // @001293D4 LHU a2, $0008(s3) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); + } + + public virtual void funct001293d8() + { + this.ee.pc = 1217516u; + // @001293D8 MOV.S $f20, $f0 + this.ee.fpr[20].f = this.ee.fpr[0].f; + // @001293DC LHU a2, $000a(s3) + MobUt.LHU(this.ee, this.ee.a2, (10u + this.ee.s3.UL0)); + // @001293E0 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @001293E4 JAL $00128e40 + this.ee.ra.UL0 = 1217516u; + this.ee.pc = 1216064u; + // @001293E8 DADDU a1, s4, zero + this.ee.a1.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001293ec() + { + this.ee.pc = 1217524u; + // @001293EC BEQ zero, zero, $00129370 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1217392u; + } + // @001293F0 C.LT.S $f20, $f0 + this.ee.fcr31_23 = (this.ee.fpr[20].f < this.ee.fpr[0].f); + } + + public virtual void funct0012949c() + { + this.ee.pc = 1217704u; + // @0012949C LUI t7, $0035 + this.ee.t7.SD0 = 3473408; + // @001294A0 BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @001294A4 LWC1 $f0, $44e0(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (17632u + this.ee.t7.UL0)); + } + + public virtual void funct001294a8() + { + this.ee.pc = 1217712u; + // @001294A8 BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @001294AC LWC1 $f0, $0004(s3) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.s3.UL0)); + } + + public virtual void funct001294b0() + { + this.ee.pc = 1217728u; + // @001294B0 LW t7, $0000(s3) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.s3.UL0)); + // @001294B4 ANDI t7, t7, $0100 + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 256))); + // @001294B8 BEQ t7, zero, $00129504 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1217796u; + } + // @001294BC LHU a2, $0002(s3) + MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.s3.UL0)); + } + + public virtual void funct001294d4() + { + this.ee.pc = 1217784u; + // @001294D4 SLL t7, a2, 6 + MobUt.SLL(this.ee.t7, this.ee.a2, 6); + // @001294D8 ADDU a0, t6, t7 + this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @001294DC SLL t7, t3, 24 + MobUt.SLL(this.ee.t7, this.ee.t3, 24); + // @001294E0 SRA t7, t7, 24 + MobUt.SRA(this.ee.t7, this.ee.t7, 24); + // @001294E4 ADDIU t7, t7, $ffe0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32))); + // @001294E8 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @001294EC ADDU t7, a0, t7 + this.ee.t7.SD0 = ((int)((this.ee.a0.SD0 + this.ee.t7.SD0))); + // @001294F0 BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @001294F4 LWC1 $f0, $0030(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t7.UL0)); + } + + public virtual void funct001294d8() + { + this.ee.pc = 1217784u; + // @001294D8 ADDU a0, t6, t7 + this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @001294DC SLL t7, t3, 24 + MobUt.SLL(this.ee.t7, this.ee.t3, 24); + // @001294E0 SRA t7, t7, 24 + MobUt.SRA(this.ee.t7, this.ee.t7, 24); + // @001294E4 ADDIU t7, t7, $ffe0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32))); + // @001294E8 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @001294EC ADDU t7, a0, t7 + this.ee.t7.SD0 = ((int)((this.ee.a0.SD0 + this.ee.t7.SD0))); + // @001294F0 BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @001294F4 LWC1 $f0, $0030(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t7.UL0)); + } + + public virtual void funct001294f8() + { + this.ee.pc = 1217796u; + // @001294F8 SUBU t7, a2, t5 + this.ee.t7.SD0 = ((int)((this.ee.a2.UD0 - this.ee.t5.UD0))); + // @001294FC BEQ zero, zero, $001294d8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1217752u; + } + // @00129500 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct00129504() + { + this.ee.pc = 1217812u; + // @00129504 LHU t5, $0010(s0) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.s0.UL0)); + // @00129508 SLT t7, a2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); + // @0012950C BEQL t7, zero, $001294f8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1217784u; + // @00129510 LW t6, $000c(a0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.a0.UL0)); + } + } + + public virtual void funct00129514() + { + this.ee.pc = 1217820u; + // @00129514 BEQ zero, zero, $001294d4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1217748u; + } + // @00129518 LW t6, $0028(a1) + MobUt.LW(this.ee, this.ee.t6, (40u + this.ee.a1.UL0)); + } + + public virtual void funct0012951c() + { + this.ee.pc = 1217836u; + // @0012951C LW t7, $0000(s3) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.s3.UL0)); + // @00129520 ANDI t7, t7, $0100 + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 256))); + // @00129524 BEQL t7, zero, $001295ac + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1217964u; + // @00129528 LHU a2, $0002(s3) + MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.s3.UL0)); + } + } + + public virtual void funct00129580() + { + this.ee.pc = 1217936u; + // @00129580 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00129584 ADDIU t7, t7, $8294 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32108))); + // @00129588 BEQ zero, zero, $00128f80 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216384u; + } + // @0012958C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + } + + public virtual void funct001295ac() + { + this.ee.pc = 1217980u; + // @001295AC LHU t5, $0010(s0) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.s0.UL0)); + // @001295B0 SLT t7, a2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); + // @001295B4 BEQ t7, zero, $001295e0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1218016u; + } + // @001295B8 SLL t7, a2, 4 + MobUt.SLL(this.ee.t7, this.ee.a2, 4); + } + + public virtual void funct001295bc() + { + this.ee.pc = 1218016u; + // @001295BC LW t6, $0020(a1) + MobUt.LW(this.ee, this.ee.t6, (32u + this.ee.a1.UL0)); + // @001295C0 ADDU a1, t6, t7 + this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @001295C4 SLL t7, t3, 24 + MobUt.SLL(this.ee.t7, this.ee.t3, 24); + // @001295C8 SRA t7, t7, 24 + MobUt.SRA(this.ee.t7, this.ee.t7, 24); + // @001295CC ADDIU t7, t7, $ffdd + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -35))); + // @001295D0 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @001295D4 ADDU t7, a1, t7 + this.ee.t7.SD0 = ((int)((this.ee.a1.SD0 + this.ee.t7.SD0))); + // @001295D8 BEQ zero, zero, $00129580 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1217920u; + } + // @001295DC LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + } + + public virtual void funct001295c4() + { + this.ee.pc = 1218016u; + // @001295C4 SLL t7, t3, 24 + MobUt.SLL(this.ee.t7, this.ee.t3, 24); + // @001295C8 SRA t7, t7, 24 + MobUt.SRA(this.ee.t7, this.ee.t7, 24); + // @001295CC ADDIU t7, t7, $ffdd + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -35))); + // @001295D0 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @001295D4 ADDU t7, a1, t7 + this.ee.t7.SD0 = ((int)((this.ee.a1.SD0 + this.ee.t7.SD0))); + // @001295D8 BEQ zero, zero, $00129580 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1217920u; + } + // @001295DC LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + } + + public virtual void funct001295e0() + { + this.ee.pc = 1218044u; + // @001295E0 LW t6, $0018(s0) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.s0.UL0)); + // @001295E4 SUBU t7, a2, t5 + this.ee.t7.SD0 = ((int)((this.ee.a2.UD0 - this.ee.t5.UD0))); + // @001295E8 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @001295EC ADDU t6, s0, t6 + this.ee.t6.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t6.SD0))); + // @001295F0 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @001295F4 BEQ zero, zero, $001295c4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1217988u; + } + // @001295F8 ADDIU a1, t6, $0020 + this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + 32))); + } + + public virtual void funct001295fc() + { + this.ee.pc = 1218060u; + // @001295FC LW t7, $0000(s3) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.s3.UL0)); + // @00129600 ANDI t7, t7, $0100 + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 256))); + // @00129604 BEQ t7, zero, $00129634 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1218100u; + } + // @00129608 SLL t6, t3, 24 + MobUt.SLL(this.ee.t6, this.ee.t3, 24); + } + + public virtual void funct00129634() + { + this.ee.pc = 1218120u; + // @00129634 LHU a2, $0002(s3) + MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.s3.UL0)); + // @00129638 LHU t5, $0010(s0) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.s0.UL0)); + // @0012963C SLT t7, a2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); + // @00129640 BEQ t7, zero, $0012966c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1218156u; + } + // @00129644 SLL t7, a2, 4 + MobUt.SLL(this.ee.t7, this.ee.a2, 4); + } + + public virtual void funct00129648() + { + this.ee.pc = 1218156u; + // @00129648 LW t6, $001c(a1) + MobUt.LW(this.ee, this.ee.t6, (28u + this.ee.a1.UL0)); + // @0012964C ADDU a1, t6, t7 + this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00129650 SLL t7, t3, 24 + MobUt.SLL(this.ee.t7, this.ee.t3, 24); + // @00129654 SRA t7, t7, 24 + MobUt.SRA(this.ee.t7, this.ee.t7, 24); + // @00129658 ADDIU t7, t7, $ffda + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -38))); + // @0012965C SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @00129660 ADDU t7, a1, t7 + this.ee.t7.SD0 = ((int)((this.ee.a1.SD0 + this.ee.t7.SD0))); + // @00129664 BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @00129668 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + } + + public virtual void funct00129650() + { + this.ee.pc = 1218156u; + // @00129650 SLL t7, t3, 24 + MobUt.SLL(this.ee.t7, this.ee.t3, 24); + // @00129654 SRA t7, t7, 24 + MobUt.SRA(this.ee.t7, this.ee.t7, 24); + // @00129658 ADDIU t7, t7, $ffda + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -38))); + // @0012965C SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @00129660 ADDU t7, a1, t7 + this.ee.t7.SD0 = ((int)((this.ee.a1.SD0 + this.ee.t7.SD0))); + // @00129664 BEQ zero, zero, $00128ee8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216232u; + } + // @00129668 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + } + + public virtual void funct0012966c() + { + this.ee.pc = 1218184u; + // @0012966C LW t6, $0018(s0) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.s0.UL0)); + // @00129670 SUBU t7, a2, t5 + this.ee.t7.SD0 = ((int)((this.ee.a2.UD0 - this.ee.t5.UD0))); + // @00129674 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @00129678 ADDU t6, s0, t6 + this.ee.t6.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t6.SD0))); + // @0012967C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00129680 BEQ zero, zero, $00129650 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1218128u; + } + // @00129684 ADDIU a1, t6, $0010 + this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + 16))); + } + + public virtual void funct00129688() + { + this.ee.pc = 1218192u; + // @00129688 JAL $00128e40 + this.ee.ra.UL0 = 1218192u; + this.ee.pc = 1216064u; + // @0012968C LHU a2, $0008(s3) + MobUt.LHU(this.ee, this.ee.a2, (8u + this.ee.s3.UL0)); + } + + public virtual void funct00129690() + { + this.ee.pc = 1218244u; + // @00129690 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00129694 LWC1 $f2, $0098(s0) + MobUt.LWC1(this.ee, this.ee.fpr[2], (152u + this.ee.s0.UL0)); + // @00129698 ADDIU t7, t7, $8298 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32104))); + // @0012969C DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @001296A0 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @001296A4 ADDIU a1, sp, $0010 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 16))); + // @001296A8 ADDIU a2, sp, $0014 + this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 20))); + // @001296AC MUL.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[1].f); + // @001296B0 NOP + MobUt.Latency(); + // @001296B4 NOP + MobUt.Latency(); + // @001296B8 DIV.S $f20, $f0, $f2 + this.ee.fpr[20].f = (this.ee.fpr[0].f / this.ee.fpr[2].f); + // @001296BC JAL $001283d8 + this.ee.ra.UL0 = 1218244u; + this.ee.pc = 1213400u; + // @001296C0 MOV.S $f12, $f20 + this.ee.fpr[12].f = this.ee.fpr[20].f; + } + + public virtual void funct001296c4() + { + this.ee.pc = 1218264u; + // @001296C4 LHU t5, $000a(s3) + MobUt.LHU(this.ee, this.ee.t5, (10u + this.ee.s3.UL0)); + // @001296C8 LW t6, $0034(s0) + MobUt.LW(this.ee, this.ee.t6, (52u + this.ee.s0.UL0)); + // @001296CC SLTU t7, t5, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.UD0 < this.ee.t6.UD0)); + // @001296D0 BNEL t7, zero, $00129728 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1218344u; + // @001296D4 ADDIU t6, zero, $0006 + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 6))); + } + } + + public virtual void funct001296d8() + { + this.ee.pc = 1218308u; + // @001296D8 SUBU t5, t5, t6 + this.ee.t5.SD0 = ((int)((this.ee.t5.UD0 - this.ee.t6.UD0))); + // @001296DC LW t7, $0038(s0) + MobUt.LW(this.ee, this.ee.t7, (56u + this.ee.s0.UL0)); + // @001296E0 ADDIU t6, zero, $0006 + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 6))); + // @001296E4 MULT t5, t5, t6 + this.ee.t5.SD0 = (((long)(this.ee.t5.SL0)) * ((long)(this.ee.t6.SL0))); + // @001296E8 ADDU t7, s0, t7 + this.ee.t7.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t7.SD0))); + // @001296EC ADDU a1, t7, t5 + this.ee.a1.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); + // @001296F0 MOV.S $f12, $f20 + this.ee.fpr[12].f = this.ee.fpr[20].f; + // @001296F4 LW a2, $0010(sp) + MobUt.LW(this.ee, this.ee.a2, (16u + this.ee.sp.UL0)); + // @001296F8 LW a3, $0014(sp) + MobUt.LW(this.ee, this.ee.a3, (20u + this.ee.sp.UL0)); + // @001296FC JAL $00128530 + this.ee.ra.UL0 = 1218308u; + this.ee.pc = 1213744u; + // @00129700 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00129704() + { + this.ee.pc = 1218324u; + // @00129704 LB t6, $0000(s3) + MobUt.LB(this.ee, this.ee.t6, (0u + this.ee.s3.UL0)); + // @00129708 ADDIU t7, zero, $002b + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 43))); + // @0012970C BNE t6, t7, $0012907c + if ((this.ee.t6.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1216636u; + } + // @00129710 MOV.S $f1, $f0 + this.ee.fpr[1].f = this.ee.fpr[0].f; + } + + public virtual void funct00129714() + { + this.ee.pc = 1218344u; + // @00129714 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00129718 ADDIU t7, t7, $8294 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -32108))); + // @0012971C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00129720 BEQ zero, zero, $0012907c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1216636u; + } + // @00129724 MUL.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct00129a18() + { + this.ee.pc = 1219268u; + // @00129A18 ADDIU sp, sp, $fd00 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -768))); + // @00129A1C ADDIU t7, zero, $000c + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 12))); + // @00129A20 SD s0, $02a0(sp) + MobUt.SD(this.ee, this.ee.s0, (672u + this.ee.sp.UL0)); + // @00129A24 SD s1, $02a8(sp) + MobUt.SD(this.ee, this.ee.s1, (680u + this.ee.sp.UL0)); + // @00129A28 SD s5, $02c8(sp) + MobUt.SD(this.ee, this.ee.s5, (712u + this.ee.sp.UL0)); + // @00129A2C DADDU s0, a0, zero + this.ee.s0.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); + // @00129A30 SD s6, $02d0(sp) + MobUt.SD(this.ee, this.ee.s6, (720u + this.ee.sp.UL0)); + // @00129A34 SD s2, $02b0(sp) + MobUt.SD(this.ee, this.ee.s2, (688u + this.ee.sp.UL0)); + // @00129A38 DADDU s5, a1, zero + this.ee.s5.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + // @00129A3C SD s3, $02b8(sp) + MobUt.SD(this.ee, this.ee.s3, (696u + this.ee.sp.UL0)); + // @00129A40 SD s4, $02c0(sp) + MobUt.SD(this.ee, this.ee.s4, (704u + this.ee.sp.UL0)); + // @00129A44 SD s7, $02d8(sp) + MobUt.SD(this.ee, this.ee.s7, (728u + this.ee.sp.UL0)); + // @00129A48 SD s8, $02e0(sp) + MobUt.SD(this.ee, this.ee.s8, (736u + this.ee.sp.UL0)); + // @00129A4C SD ra, $02e8(sp) + MobUt.SD(this.ee, this.ee.ra, (744u + this.ee.sp.UL0)); + // @00129A50 SWC1 $f20, $02f0(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (752u + this.ee.sp.UL0)); + // @00129A54 LW t3, $0004(a0) + MobUt.LW(this.ee, this.ee.t3, (4u + this.ee.a0.UL0)); + // @00129A58 SW a2, $01f0(sp) + MobUt.SW(this.ee, this.ee.a2, (496u + this.ee.sp.UL0)); + // @00129A5C DADDU a0, sp, zero + this.ee.a0.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); + // @00129A60 SW t3, $01fc(sp) + MobUt.SW(this.ee, this.ee.t3, (508u + this.ee.sp.UL0)); + // @00129A64 SW a3, $01f4(sp) + MobUt.SW(this.ee, this.ee.a3, (500u + this.ee.sp.UL0)); + // @00129A68 LW t4, $01fc(sp) + MobUt.LW(this.ee, this.ee.t4, (508u + this.ee.sp.UL0)); + // @00129A6C LW t6, $0054(t3) + MobUt.LW(this.ee, this.ee.t6, (84u + this.ee.t3.UL0)); + // @00129A70 SW t0, $01f8(sp) + MobUt.SW(this.ee, this.ee.t0, (504u + this.ee.sp.UL0)); + // @00129A74 MULT t6, t6, t7 + this.ee.t6.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.t7.SL0))); + // @00129A78 LW t3, $0050(t3) + MobUt.LW(this.ee, this.ee.t3, (80u + this.ee.t3.UL0)); + // @00129A7C LW t5, $0060(t4) + MobUt.LW(this.ee, this.ee.t5, (96u + this.ee.t4.UL0)); + // @00129A80 ADDU s1, t4, t3 + this.ee.s1.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t3.SD0))); + // @00129A84 LW t7, $0064(t4) + MobUt.LW(this.ee, this.ee.t7, (100u + this.ee.t4.UL0)); + // @00129A88 LW t3, $01fc(sp) + MobUt.LW(this.ee, this.ee.t3, (508u + this.ee.sp.UL0)); + // @00129A8C ADDU t6, s1, t6 + this.ee.t6.SD0 = ((int)((this.ee.s1.SD0 + this.ee.t6.SD0))); + // @00129A90 LW t4, $001c(t4) + MobUt.LW(this.ee, this.ee.t4, (28u + this.ee.t4.UL0)); + // @00129A94 SLL t7, t7, 3 + MobUt.SLL(this.ee.t7, this.ee.t7, 3); + // @00129A98 ADDU s6, t3, t5 + this.ee.s6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t5.SD0))); + // @00129A9C LW t3, $00a0(t3) + MobUt.LW(this.ee, this.ee.t3, (160u + this.ee.t3.UL0)); + // @00129AA0 ADDU t7, s6, t7 + this.ee.t7.SD0 = ((int)((this.ee.s6.SD0 + this.ee.t7.SD0))); + // @00129AA4 LW t5, $01fc(sp) + MobUt.LW(this.ee, this.ee.t5, (508u + this.ee.sp.UL0)); + // @00129AA8 SW t6, $0204(sp) + MobUt.SW(this.ee, this.ee.t6, (516u + this.ee.sp.UL0)); + // @00129AAC ADDU t4, t5, t4 + this.ee.t4.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t4.SD0))); + // @00129AB0 SW t7, $0208(sp) + MobUt.SW(this.ee, this.ee.t7, (520u + this.ee.sp.UL0)); + // @00129AB4 ADDU t3, t5, t3 + this.ee.t3.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t3.SD0))); + // @00129AB8 SW t4, $0200(sp) + MobUt.SW(this.ee, this.ee.t4, (512u + this.ee.sp.UL0)); + // @00129ABC JAL $0011b420 + this.ee.ra.UL0 = 1219268u; + this.ee.pc = 1160224u; + // @00129AC0 SW t3, $020c(sp) + MobUt.SW(this.ee, this.ee.t3, (524u + this.ee.sp.UL0)); + } + + public virtual void funct00129ac4() + { + this.ee.pc = 1219288u; + // @00129AC4 SW zero, $0210(sp) + MobUt.SW(this.ee, this.ee.r0, (528u + this.ee.sp.UL0)); + // @00129AC8 LW t6, $01fc(sp) + MobUt.LW(this.ee, this.ee.t6, (508u + this.ee.sp.UL0)); + // @00129ACC LHU t7, $0012(t6) + MobUt.LHU(this.ee, this.ee.t7, (18u + this.ee.t6.UL0)); + // @00129AD0 BEQL t7, zero, $0012a4c0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1221824u; + // @00129AD4 LD s0, $02a0(sp) + MobUt.LD(this.ee, this.ee.s0, (672u + this.ee.sp.UL0)); + } + } + + public virtual void funct00129ad8() + { + this.ee.pc = 1219320u; + // @00129AD8 LW t7, $0200(sp) + MobUt.LW(this.ee, this.ee.t7, (512u + this.ee.sp.UL0)); + // @00129ADC LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @00129AE0 LW s4, $0000(t7) + MobUt.LW(this.ee, this.ee.s4, (0u + this.ee.t7.UL0)); + // @00129AE4 LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @00129AE8 ANDI s2, s4, $ffff + this.ee.s2.UD0 = ((ushort)((this.ee.s4.US0 & 65535))); + // @00129AEC SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @00129AF0 BEQL t7, zero, $0012d4f4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1234164u; + // @00129AF4 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct00129af8() + { + this.ee.pc = 1219340u; + // @00129AF8 LW a0, $0014(s5) + MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); + // @00129AFC LW t7, $0000(a0) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); + // @00129B00 LW v0, $0020(t7) + MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); + // @00129B04 JALR ra, v0 + this.ee.ra.UD0 = 1219340u; + this.ee.pc = this.ee.v0.UL0; + // @00129B08 SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + } + + public virtual void funct00129b0c() + { + this.ee.pc = 1219360u; + // @00129B0C ADDU v0, v0, s3 + this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.s3.SD0))); + // @00129B10 LH v0, $0004(v0) + MobUt.LH(this.ee, this.ee.v0, (4u + this.ee.v0.UL0)); + // @00129B14 LW t3, $0208(sp) + MobUt.LW(this.ee, this.ee.t3, (520u + this.ee.sp.UL0)); + // @00129B18 BEQ s6, t3, $0012d4ec + if ((this.ee.s6.UD0 == this.ee.t3.UD0)) + { + this.ee.pc = 1234156u; + } + // @00129B1C SW v0, $0214(sp) + MobUt.SW(this.ee, this.ee.v0, (532u + this.ee.sp.UL0)); + } + + public virtual void funct00129b10() + { + this.ee.pc = 1219360u; + // @00129B10 LH v0, $0004(v0) + MobUt.LH(this.ee, this.ee.v0, (4u + this.ee.v0.UL0)); + // @00129B14 LW t3, $0208(sp) + MobUt.LW(this.ee, this.ee.t3, (520u + this.ee.sp.UL0)); + // @00129B18 BEQ s6, t3, $0012d4ec + if ((this.ee.s6.UD0 == this.ee.t3.UD0)) + { + this.ee.pc = 1234156u; + } + // @00129B1C SW v0, $0214(sp) + MobUt.SW(this.ee, this.ee.v0, (532u + this.ee.sp.UL0)); + } + + public virtual void funct00129b20() + { + this.ee.pc = 1219380u; + // @00129B20 ANDI t6, s2, $ffff + this.ee.t6.UD0 = ((ushort)((this.ee.s2.US0 & 65535))); + // @00129B24 LHU t7, $0000(s6) + MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); + // @00129B28 DADDU s3, t6, zero + this.ee.s3.UD0 = (this.ee.t6.UD0 + this.ee.r0.UD0); + // @00129B2C BNE t7, t6, $00129bc4 + if ((this.ee.t7.UD0 != this.ee.t6.UD0)) + { + this.ee.pc = 1219524u; + } + // @00129B30 SLL s8, s2, 4 + MobUt.SLL(this.ee.s8, this.ee.s2, 4); + } + + public virtual void funct00129b34() + { + this.ee.pc = 1219396u; + // @00129B34 LHU a2, $0006(s6) + MobUt.LHU(this.ee, this.ee.a2, (6u + this.ee.s6.UL0)); + // @00129B38 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @00129B3C JAL $00128e40 + this.ee.ra.UL0 = 1219396u; + this.ee.pc = 1216064u; + // @00129B40 DADDU a1, s5, zero + this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00129b38() + { + this.ee.pc = 1219396u; + // @00129B38 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @00129B3C JAL $00128e40 + this.ee.ra.UL0 = 1219396u; + this.ee.pc = 1216064u; + // @00129B40 DADDU a1, s5, zero + this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00129b44() + { + this.ee.pc = 1219416u; + // @00129B44 LHU t4, $0002(s6) + MobUt.LHU(this.ee, this.ee.t4, (2u + this.ee.s6.UL0)); + // @00129B48 ANDI t6, t4, $ffff + this.ee.t6.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @00129B4C SLTIU t7, t6, $0009 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 9ul)); + // @00129B50 BEQ t7, zero, $00129ba0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219488u; + } + // @00129B54 MOV.S $f1, $f0 + this.ee.fpr[1].f = this.ee.fpr[0].f; + } + + public virtual void funct00129b58() + { + this.ee.pc = 1219444u; + // @00129B58 SLL t7, t6, 2 + MobUt.SLL(this.ee.t7, this.ee.t6, 2); + // @00129B5C LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @00129B60 ADDIU t6, t6, $8368 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -31896))); + // @00129B64 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00129B68 LW t5, $0000(t7) + MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); + // @00129B6C JR t5 + this.ee.pc = this.ee.t5.UL[0]; + // @00129B70 NOP + MobUt.Latency(); + } + + public virtual void funct00129b74() + { + this.ee.pc = 1219464u; + // @00129B74 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @00129B78 LHU t3, $0010(t5) + MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t5.UL0)); + // @00129B7C SLT t7, s2, t3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); + // @00129B80 BEQL t7, zero, $0012d438 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233976u; + // @00129B84 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct00129b88() + { + this.ee.pc = 1219512u; + // @00129B88 LW t7, $001c(s5) + MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); + // @00129B8C ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @00129B90 ANDI t7, t4, $ffff + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @00129B94 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @00129B98 ADDU t7, t6, t7 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00129B9C SWC1 $f1, $0000(t7) + MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00129BA0 LUI t7, $ffdf + this.ee.t7.SD0 = -2162688; + // @00129BA4 LW t5, $0208(sp) + MobUt.LW(this.ee, this.ee.t5, (520u + this.ee.sp.UL0)); + // @00129BA8 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @00129BAC ADDIU s6, s6, $0008 + this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 8))); + // @00129BB0 BEQ s6, t5, $00129bc4 + if ((this.ee.s6.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1219524u; + } + // @00129BB4 AND s4, s4, t7 + this.ee.s4.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + } + + public virtual void funct00129b90() + { + this.ee.pc = 1219512u; + // @00129B90 ANDI t7, t4, $ffff + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @00129B94 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @00129B98 ADDU t7, t6, t7 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00129B9C SWC1 $f1, $0000(t7) + MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00129BA0 LUI t7, $ffdf + this.ee.t7.SD0 = -2162688; + // @00129BA4 LW t5, $0208(sp) + MobUt.LW(this.ee, this.ee.t5, (520u + this.ee.sp.UL0)); + // @00129BA8 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @00129BAC ADDIU s6, s6, $0008 + this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 8))); + // @00129BB0 BEQ s6, t5, $00129bc4 + if ((this.ee.s6.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1219524u; + } + // @00129BB4 AND s4, s4, t7 + this.ee.s4.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + } + + public virtual void funct00129b94() + { + this.ee.pc = 1219512u; + // @00129B94 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @00129B98 ADDU t7, t6, t7 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00129B9C SWC1 $f1, $0000(t7) + MobUt.SWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00129BA0 LUI t7, $ffdf + this.ee.t7.SD0 = -2162688; + // @00129BA4 LW t5, $0208(sp) + MobUt.LW(this.ee, this.ee.t5, (520u + this.ee.sp.UL0)); + // @00129BA8 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @00129BAC ADDIU s6, s6, $0008 + this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 8))); + // @00129BB0 BEQ s6, t5, $00129bc4 + if ((this.ee.s6.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1219524u; + } + // @00129BB4 AND s4, s4, t7 + this.ee.s4.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + } + + public virtual void funct00129ba0() + { + this.ee.pc = 1219512u; + // @00129BA0 LUI t7, $ffdf + this.ee.t7.SD0 = -2162688; + // @00129BA4 LW t5, $0208(sp) + MobUt.LW(this.ee, this.ee.t5, (520u + this.ee.sp.UL0)); + // @00129BA8 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @00129BAC ADDIU s6, s6, $0008 + this.ee.s6.SD0 = ((int)((this.ee.s6.SD0 + 8))); + // @00129BB0 BEQ s6, t5, $00129bc4 + if ((this.ee.s6.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1219524u; + } + // @00129BB4 AND s4, s4, t7 + this.ee.s4.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + } + + public virtual void funct00129bb8() + { + this.ee.pc = 1219524u; + // @00129BB8 LHU t7, $0000(s6) + MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); + // @00129BBC BEQL t7, s3, $00129b38 + if ((this.ee.t7.UD0 == this.ee.s3.UD0)) + { + this.ee.pc = 1219384u; + // @00129BC0 LHU a2, $0006(s6) + MobUt.LHU(this.ee, this.ee.a2, (6u + this.ee.s6.UL0)); + } + } + + public virtual void funct00129bc4() + { + this.ee.pc = 1219560u; + // @00129BC4 SW zero, $0218(sp) + MobUt.SW(this.ee, this.ee.r0, (536u + this.ee.sp.UL0)); + // @00129BC8 ADDIU a2, zero, $ffff + this.ee.a2.SD0 = ((int)((this.ee.r0.SD0 + -1))); + // @00129BCC SW zero, $021c(sp) + MobUt.SW(this.ee, this.ee.r0, (540u + this.ee.sp.UL0)); + // @00129BD0 ADDIU a3, zero, $ffff + this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + -1))); + // @00129BD4 LW t6, $0204(sp) + MobUt.LW(this.ee, this.ee.t6, (516u + this.ee.sp.UL0)); + // @00129BD8 DADDU v0, zero, zero + this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00129BDC ADDIU v1, zero, $ffff + this.ee.v1.SD0 = ((int)((this.ee.r0.SD0 + -1))); + // @00129BE0 BEQ s1, t6, $00129c58 + if ((this.ee.s1.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1219672u; + } + // @00129BE4 DADDU t3, zero, zero + this.ee.t3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00129be8() + { + this.ee.pc = 1219576u; + // @00129BE8 ANDI t6, s2, $ffff + this.ee.t6.UD0 = ((ushort)((this.ee.s2.US0 & 65535))); + // @00129BEC LHU t7, $0002(s1) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); + // @00129BF0 BNE t7, t6, $00129c58 + if ((this.ee.t7.UD0 != this.ee.t6.UD0)) + { + this.ee.pc = 1219672u; + } + // @00129BF4 DADDU t4, t6, zero + this.ee.t4.UD0 = (this.ee.t6.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00129bf8() + { + this.ee.pc = 1219588u; + // @00129BF8 LBU t7, $0001(s1) + MobUt.LBU(this.ee, this.ee.t7, (1u + this.ee.s1.UL0)); + // @00129BFC BEQ t7, zero, $00129c40 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219648u; + } + // @00129C00 LW t7, $0204(sp) + MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); + } + + public virtual void funct00129bfc() + { + this.ee.pc = 1219588u; + // @00129BFC BEQ t7, zero, $00129c40 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219648u; + } + // @00129C00 LW t7, $0204(sp) + MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); + } + + public virtual void funct00129c04() + { + this.ee.pc = 1219604u; + // @00129C04 LBU t6, $0000(s1) + MobUt.LBU(this.ee, this.ee.t6, (0u + this.ee.s1.UL0)); + // @00129C08 SLTIU t7, t6, $000e + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 14ul)); + // @00129C0C BEQ t7, zero, $00129c3c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219644u; + } + // @00129C10 SLL t7, t6, 2 + MobUt.SLL(this.ee.t7, this.ee.t6, 2); + } + + public virtual void funct00129c14() + { + this.ee.pc = 1219628u; + // @00129C14 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @00129C18 ADDIU t6, t6, $838c + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -31860))); + // @00129C1C ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00129C20 LW t5, $0000(t7) + MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); + // @00129C24 JR t5 + this.ee.pc = this.ee.t5.UL[0]; + // @00129C28 NOP + MobUt.Latency(); + } + + public virtual void funct00129c2c() + { + this.ee.pc = 1219640u; + // @00129C2C ADDIU t7, zero, $ffff + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); + // @00129C30 BNE a2, t7, $0012d3b4 + if ((this.ee.a2.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1233844u; + } + // @00129C34 NOP + MobUt.Latency(); + } + + public virtual void funct00129c38() + { + this.ee.pc = 1219660u; + // @00129C38 LHU a2, $0004(s1) + MobUt.LHU(this.ee, this.ee.a2, (4u + this.ee.s1.UL0)); + // @00129C3C LW t7, $0204(sp) + MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); + // @00129C40 ADDIU s1, s1, $000c + this.ee.s1.SD0 = ((int)((this.ee.s1.SD0 + 12))); + // @00129C44 BEQ s1, t7, $00129c5c + if ((this.ee.s1.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1219676u; + } + // @00129C48 LUI t7, $0003 + this.ee.t7.SD0 = 196608; + } + + public virtual void funct00129c3c() + { + this.ee.pc = 1219660u; + // @00129C3C LW t7, $0204(sp) + MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); + // @00129C40 ADDIU s1, s1, $000c + this.ee.s1.SD0 = ((int)((this.ee.s1.SD0 + 12))); + // @00129C44 BEQ s1, t7, $00129c5c + if ((this.ee.s1.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1219676u; + } + // @00129C48 LUI t7, $0003 + this.ee.t7.SD0 = 196608; + } + + public virtual void funct00129c4c() + { + this.ee.pc = 1219672u; + // @00129C4C LHU t7, $0002(s1) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); + // @00129C50 BEQL t7, t4, $00129bfc + if ((this.ee.t7.UD0 == this.ee.t4.UD0)) + { + this.ee.pc = 1219580u; + // @00129C54 LBU t7, $0001(s1) + MobUt.LBU(this.ee, this.ee.t7, (1u + this.ee.s1.UL0)); + } + } + + public virtual void funct00129c58() + { + this.ee.pc = 1219688u; + // @00129C58 LUI t7, $0003 + this.ee.t7.SD0 = 196608; + // @00129C5C AND t6, s4, t7 + this.ee.t6.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @00129C60 BEQ t6, zero, $00129cf8 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219832u; + } + // @00129C64 SW zero, $0220(sp) + MobUt.SW(this.ee, this.ee.r0, (544u + this.ee.sp.UL0)); + } + + public virtual void funct00129c5c() + { + this.ee.pc = 1219688u; + // @00129C5C AND t6, s4, t7 + this.ee.t6.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @00129C60 BEQ t6, zero, $00129cf8 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219832u; + } + // @00129C64 SW zero, $0220(sp) + MobUt.SW(this.ee, this.ee.r0, (544u + this.ee.sp.UL0)); + } + + public virtual void funct00129c68() + { + this.ee.pc = 1219704u; + // @00129C68 LUI t7, $0080 + this.ee.t7.SD0 = 8388608; + // @00129C6C AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @00129C70 BEQ t7, zero, $0012d39c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233820u; + } + // @00129C74 LW t4, $020c(sp) + MobUt.LW(this.ee, this.ee.t4, (524u + this.ee.sp.UL0)); + } + + public virtual void funct00129c78() + { + this.ee.pc = 1219728u; + // @00129C78 LH t5, $0000(t4) + MobUt.LH(this.ee, this.ee.t5, (0u + this.ee.t4.UL0)); + // @00129C7C ADDIU t4, t4, $0002 + this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + 2))); + // @00129C80 SW t4, $020c(sp) + MobUt.SW(this.ee, this.ee.t4, (524u + this.ee.sp.UL0)); + // @00129C84 LW t6, $0204(sp) + MobUt.LW(this.ee, this.ee.t6, (516u + this.ee.sp.UL0)); + // @00129C88 BEQ s1, t6, $00129ce4 + if ((this.ee.s1.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1219812u; + } + // @00129C8C ADDIU t4, zero, $0005 + this.ee.t4.SD0 = ((int)((this.ee.r0.SD0 + 5))); + } + + public virtual void funct00129c84() + { + this.ee.pc = 1219728u; + // @00129C84 LW t6, $0204(sp) + MobUt.LW(this.ee, this.ee.t6, (516u + this.ee.sp.UL0)); + // @00129C88 BEQ s1, t6, $00129ce4 + if ((this.ee.s1.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1219812u; + } + // @00129C8C ADDIU t4, zero, $0005 + this.ee.t4.SD0 = ((int)((this.ee.r0.SD0 + 5))); + } + + public virtual void funct00129c90() + { + this.ee.pc = 1219740u; + // @00129C90 LBU t7, $0001(s1) + MobUt.LBU(this.ee, this.ee.t7, (1u + this.ee.s1.UL0)); + // @00129C94 BEQ t7, zero, $00129cd8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219800u; + } + // @00129C98 LW t7, $0204(sp) + MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); + } + + public virtual void funct00129c94() + { + this.ee.pc = 1219740u; + // @00129C94 BEQ t7, zero, $00129cd8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219800u; + } + // @00129C98 LW t7, $0204(sp) + MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); + } + + public virtual void funct00129c9c() + { + this.ee.pc = 1219752u; + // @00129C9C LHU t7, $0002(s1) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); + // @00129CA0 BNE t7, t5, $00129cd8 + if ((this.ee.t7.UD0 != this.ee.t5.UD0)) + { + this.ee.pc = 1219800u; + } + // @00129CA4 LW t7, $0204(sp) + MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); + } + + public virtual void funct00129ca8() + { + this.ee.pc = 1219764u; + // @00129CA8 LBU t6, $0000(s1) + MobUt.LBU(this.ee, this.ee.t6, (0u + this.ee.s1.UL0)); + // @00129CAC BLTZ t6, $00129ccc + if ((this.ee.t6.SD0 < 0)) + { + this.ee.pc = 1219788u; + } + // @00129CB0 DADDU t7, zero, zero + this.ee.t7.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00129cb4() + { + this.ee.pc = 1219776u; + // @00129CB4 SLTI t7, t6, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < 2)); + // @00129CB8 BNE t7, zero, $00129ccc + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1219788u; + } + // @00129CBC ADDIU t7, zero, $0001 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); + } + + public virtual void funct00129ccc() + { + this.ee.pc = 1219800u; + // @00129CCC ANDI t7, t7, $00ff + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 255))); + // @00129CD0 BNE t7, zero, $0012d390 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1233808u; + } + // @00129CD4 LW t7, $0204(sp) + MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); + } + + public virtual void funct00129cd8() + { + this.ee.pc = 1219812u; + // @00129CD8 ADDIU s1, s1, $000c + this.ee.s1.SD0 = ((int)((this.ee.s1.SD0 + 12))); + // @00129CDC BNEL s1, t7, $00129c94 + if ((this.ee.s1.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1219732u; + // @00129CE0 LBU t7, $0001(s1) + MobUt.LBU(this.ee, this.ee.t7, (1u + this.ee.s1.UL0)); + } + } + + public virtual void funct00129ce4() + { + this.ee.pc = 1219824u; + // @00129CE4 LW t4, $0220(sp) + MobUt.LW(this.ee, this.ee.t4, (544u + this.ee.sp.UL0)); + // @00129CE8 BNE t4, zero, $00129cf8 + if ((this.ee.t4.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1219832u; + } + // @00129CEC LUI t7, $fffc + this.ee.t7.SD0 = -262144; + } + + public virtual void funct00129cf8() + { + this.ee.pc = 1219840u; + // @00129CF8 BEQ t3, zero, $0012d2c8 + if ((this.ee.t3.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233608u; + } + // @00129CFC LW t7, $0214(sp) + MobUt.LW(this.ee, this.ee.t7, (532u + this.ee.sp.UL0)); + } + + public virtual void funct00129d00() + { + this.ee.pc = 1219868u; + // @00129D00 LHU t7, $0004(t3) + MobUt.LHU(this.ee, this.ee.t7, (4u + this.ee.t3.UL0)); + // @00129D04 LW t3, $0014(s0) + MobUt.LW(this.ee, this.ee.t3, (20u + this.ee.s0.UL0)); + // @00129D08 SLL t7, t7, 4 + MobUt.SLL(this.ee.t7, this.ee.t7, 4); + // @00129D0C ADDU t6, t3, t7 + this.ee.t6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t7.SD0))); + // @00129D10 ADDU t7, t3, s8 + this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); + // @00129D14 BEQ t7, t6, $00129d2c + if ((this.ee.t7.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1219884u; + } + // @00129D18 LW t5, $0214(sp) + MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); + } + + public virtual void funct00129d1c() + { + this.ee.pc = 1219892u; + // @00129D1C LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @00129D20 SQ t0, $0000(t7) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @00129D24 LW t3, $0014(s0) + MobUt.LW(this.ee, this.ee.t3, (20u + this.ee.s0.UL0)); + // @00129D28 LW t5, $0214(sp) + MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); + // @00129D2C BLTZ t5, $0012d27c + if ((this.ee.t5.SD0 < 0)) + { + this.ee.pc = 1233532u; + } + // @00129D30 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + } + + public virtual void funct00129d34() + { + this.ee.pc = 1219908u; + // @00129D34 LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @00129D38 SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @00129D3C BEQL t7, zero, $0012d264 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233508u; + // @00129D40 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct00129d44() + { + this.ee.pc = 1219976u; + // @00129D44 LW t7, $001c(s5) + MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); + // @00129D48 ADDU t5, t7, s8 + this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @00129D4C LW t6, $0214(sp) + MobUt.LW(this.ee, this.ee.t6, (532u + this.ee.sp.UL0)); + // @00129D50 ADDU t7, t3, s8 + this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); + // @00129D54 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00129D58 SLL t2, t6, 4 + MobUt.SLL(this.ee.t2, this.ee.t6, 4); + // @00129D5C ADDU t6, t3, t2 + this.ee.t6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t2.SD0))); + // @00129D60 LWC1 $f1, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); + // @00129D64 NOP + MobUt.Latency(); + // @00129D68 NOP + MobUt.Latency(); + // @00129D6C DIV.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); + // @00129D70 SWC1 $f0, $0000(t5) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); + // @00129D74 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @00129D78 LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @00129D7C SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @00129D80 BEQL t7, zero, $0012d24c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233484u; + // @00129D84 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct00129d4c() + { + this.ee.pc = 1219976u; + // @00129D4C LW t6, $0214(sp) + MobUt.LW(this.ee, this.ee.t6, (532u + this.ee.sp.UL0)); + // @00129D50 ADDU t7, t3, s8 + this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); + // @00129D54 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00129D58 SLL t2, t6, 4 + MobUt.SLL(this.ee.t2, this.ee.t6, 4); + // @00129D5C ADDU t6, t3, t2 + this.ee.t6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t2.SD0))); + // @00129D60 LWC1 $f1, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); + // @00129D64 NOP + MobUt.Latency(); + // @00129D68 NOP + MobUt.Latency(); + // @00129D6C DIV.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); + // @00129D70 SWC1 $f0, $0000(t5) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); + // @00129D74 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @00129D78 LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @00129D7C SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @00129D80 BEQL t7, zero, $0012d24c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233484u; + // @00129D84 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct00129d88() + { + this.ee.pc = 1220040u; + // @00129D88 LW t7, $001c(s5) + MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); + // @00129D8C ADDU t5, t7, s8 + this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @00129D90 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @00129D94 ADDU t6, t7, t2 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t2.SD0))); + // @00129D98 ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @00129D9C LWC1 $f1, $0004(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.t6.UL0)); + // @00129DA0 LWC1 $f0, $0004(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t7.UL0)); + // @00129DA4 NOP + MobUt.Latency(); + // @00129DA8 NOP + MobUt.Latency(); + // @00129DAC DIV.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); + // @00129DB0 SWC1 $f0, $0004(t5) + MobUt.SWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t5.UL0)); + // @00129DB4 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @00129DB8 LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @00129DBC SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @00129DC0 BEQL t7, zero, $0012d234 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233460u; + // @00129DC4 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct00129d90() + { + this.ee.pc = 1220040u; + // @00129D90 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @00129D94 ADDU t6, t7, t2 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t2.SD0))); + // @00129D98 ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @00129D9C LWC1 $f1, $0004(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.t6.UL0)); + // @00129DA0 LWC1 $f0, $0004(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t7.UL0)); + // @00129DA4 NOP + MobUt.Latency(); + // @00129DA8 NOP + MobUt.Latency(); + // @00129DAC DIV.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); + // @00129DB0 SWC1 $f0, $0004(t5) + MobUt.SWC1(this.ee, this.ee.fpr[0], (4u + this.ee.t5.UL0)); + // @00129DB4 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @00129DB8 LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @00129DBC SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @00129DC0 BEQL t7, zero, $0012d234 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233460u; + // @00129DC4 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct00129dc8() + { + this.ee.pc = 1220100u; + // @00129DC8 LW t7, $001c(s5) + MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); + // @00129DCC ADDU t5, t7, s8 + this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @00129DD0 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @00129DD4 ADDU t6, t7, t2 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t2.SD0))); + // @00129DD8 ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @00129DDC LWC1 $f1, $0008(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.t6.UL0)); + // @00129DE0 LWC1 $f0, $0008(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.t7.UL0)); + // @00129DE4 NOP + MobUt.Latency(); + // @00129DE8 NOP + MobUt.Latency(); + // @00129DEC DIV.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); + // @00129DF0 SWC1 $f0, $0008(t5) + MobUt.SWC1(this.ee, this.ee.fpr[0], (8u + this.ee.t5.UL0)); + // @00129DF4 LUI t7, $0020 + this.ee.t7.SD0 = 2097152; + // @00129DF8 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @00129DFC BEQ t7, zero, $0012a9d0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223120u; + } + // @00129E00 LUI t7, $0040 + this.ee.t7.SD0 = 4194304; + } + + public virtual void funct00129dd0() + { + this.ee.pc = 1220100u; + // @00129DD0 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @00129DD4 ADDU t6, t7, t2 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t2.SD0))); + // @00129DD8 ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @00129DDC LWC1 $f1, $0008(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.t6.UL0)); + // @00129DE0 LWC1 $f0, $0008(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.t7.UL0)); + // @00129DE4 NOP + MobUt.Latency(); + // @00129DE8 NOP + MobUt.Latency(); + // @00129DEC DIV.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); + // @00129DF0 SWC1 $f0, $0008(t5) + MobUt.SWC1(this.ee, this.ee.fpr[0], (8u + this.ee.t5.UL0)); + // @00129DF4 LUI t7, $0020 + this.ee.t7.SD0 = 2097152; + // @00129DF8 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @00129DFC BEQ t7, zero, $0012a9d0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223120u; + } + // @00129E00 LUI t7, $0040 + this.ee.t7.SD0 = 4194304; + } + + public virtual void funct00129df8() + { + this.ee.pc = 1220100u; + // @00129DF8 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @00129DFC BEQ t7, zero, $0012a9d0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223120u; + } + // @00129E00 LUI t7, $0040 + this.ee.t7.SD0 = 4194304; + } + + public virtual void funct00129e04() + { + this.ee.pc = 1220112u; + // @00129E04 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @00129E08 BEQ t7, zero, $00129e60 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220192u; + } + // @00129E0C LW t3, $01f4(sp) + MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); + } + + public virtual void funct00129e10() + { + this.ee.pc = 1220132u; + // @00129E10 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @00129E14 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @00129E18 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @00129E1C BEQ t7, zero, $0012a9bc + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223100u; + } + // @00129E20 SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + } + + public virtual void funct00129e2c() + { + this.ee.pc = 1220156u; + // @00129E2C LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @00129E30 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @00129E34 BNEL t7, zero, $0012a9b4 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1223092u; + // @00129E38 LW t7, $0020(s5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); + } + } + + public virtual void funct00129e3c() + { + this.ee.pc = 1220188u; + // @00129E3C LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + // @00129E40 SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @00129E44 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @00129E48 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @00129E4C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00129E50 ADDIU a1, t6, $0020 + this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + 32))); + // @00129E54 JAL $0011b840 + this.ee.ra.UL0 = 1220188u; + this.ee.pc = 1161280u; + // @00129E58 NOP + MobUt.Latency(); + } + + public virtual void funct00129e40() + { + this.ee.pc = 1220188u; + // @00129E40 SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @00129E44 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @00129E48 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @00129E4C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00129E50 ADDIU a1, t6, $0020 + this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + 32))); + // @00129E54 JAL $0011b840 + this.ee.ra.UL0 = 1220188u; + this.ee.pc = 1161280u; + // @00129E58 NOP + MobUt.Latency(); + } + + public virtual void funct00129e54() + { + this.ee.pc = 1220188u; + // @00129E54 JAL $0011b840 + this.ee.ra.UL0 = 1220188u; + this.ee.pc = 1161280u; + // @00129E58 NOP + MobUt.Latency(); + } + + public virtual void funct00129e5c() + { + this.ee.pc = 1220200u; + // @00129E5C LW t3, $01f4(sp) + MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); + // @00129E60 BEQL t3, zero, $0012a498 + if ((this.ee.t3.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1221784u; + // @00129E64 LW t3, $01fc(sp) + MobUt.LW(this.ee, this.ee.t3, (508u + this.ee.sp.UL0)); + } + } + + public virtual void funct00129e60() + { + this.ee.pc = 1220200u; + // @00129E60 BEQL t3, zero, $0012a498 + if ((this.ee.t3.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1221784u; + // @00129E64 LW t3, $01fc(sp) + MobUt.LW(this.ee, this.ee.t3, (508u + this.ee.sp.UL0)); + } + } + + public virtual void funct0012a498() + { + this.ee.pc = 1221820u; + // @0012A498 LW t4, $0210(sp) + MobUt.LW(this.ee, this.ee.t4, (528u + this.ee.sp.UL0)); + // @0012A49C LW t5, $0200(sp) + MobUt.LW(this.ee, this.ee.t5, (512u + this.ee.sp.UL0)); + // @0012A4A0 LHU t7, $0012(t3) + MobUt.LHU(this.ee, this.ee.t7, (18u + this.ee.t3.UL0)); + // @0012A4A4 ADDIU t4, t4, $0001 + this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + 1))); + // @0012A4A8 ADDIU t5, t5, $0004 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + 4))); + // @0012A4AC SW t4, $0210(sp) + MobUt.SW(this.ee, this.ee.t4, (528u + this.ee.sp.UL0)); + // @0012A4B0 SLT t7, t4, t7 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.t7.SD0)); + // @0012A4B4 BNE t7, zero, $00129ad8 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1219288u; + } + // @0012A4B8 SW t5, $0200(sp) + MobUt.SW(this.ee, this.ee.t5, (512u + this.ee.sp.UL0)); + } + + public virtual void funct0012a4bc() + { + this.ee.pc = 1221872u; + // @0012A4BC LD s0, $02a0(sp) + MobUt.LD(this.ee, this.ee.s0, (672u + this.ee.sp.UL0)); + // @0012A4C0 LD s1, $02a8(sp) + MobUt.LD(this.ee, this.ee.s1, (680u + this.ee.sp.UL0)); + // @0012A4C4 LD s2, $02b0(sp) + MobUt.LD(this.ee, this.ee.s2, (688u + this.ee.sp.UL0)); + // @0012A4C8 LD s3, $02b8(sp) + MobUt.LD(this.ee, this.ee.s3, (696u + this.ee.sp.UL0)); + // @0012A4CC LD s4, $02c0(sp) + MobUt.LD(this.ee, this.ee.s4, (704u + this.ee.sp.UL0)); + // @0012A4D0 LD s5, $02c8(sp) + MobUt.LD(this.ee, this.ee.s5, (712u + this.ee.sp.UL0)); + // @0012A4D4 LD s6, $02d0(sp) + MobUt.LD(this.ee, this.ee.s6, (720u + this.ee.sp.UL0)); + // @0012A4D8 LD s7, $02d8(sp) + MobUt.LD(this.ee, this.ee.s7, (728u + this.ee.sp.UL0)); + // @0012A4DC LD s8, $02e0(sp) + MobUt.LD(this.ee, this.ee.s8, (736u + this.ee.sp.UL0)); + // @0012A4E0 LD ra, $02e8(sp) + MobUt.LD(this.ee, this.ee.ra, (744u + this.ee.sp.UL0)); + // @0012A4E4 LWC1 $f20, $02f0(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (752u + this.ee.sp.UL0)); + // @0012A4E8 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0012A4EC ADDIU sp, sp, $0300 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 768))); + } + + public virtual void funct0012a4c0() + { + this.ee.pc = 1221872u; + // @0012A4C0 LD s1, $02a8(sp) + MobUt.LD(this.ee, this.ee.s1, (680u + this.ee.sp.UL0)); + // @0012A4C4 LD s2, $02b0(sp) + MobUt.LD(this.ee, this.ee.s2, (688u + this.ee.sp.UL0)); + // @0012A4C8 LD s3, $02b8(sp) + MobUt.LD(this.ee, this.ee.s3, (696u + this.ee.sp.UL0)); + // @0012A4CC LD s4, $02c0(sp) + MobUt.LD(this.ee, this.ee.s4, (704u + this.ee.sp.UL0)); + // @0012A4D0 LD s5, $02c8(sp) + MobUt.LD(this.ee, this.ee.s5, (712u + this.ee.sp.UL0)); + // @0012A4D4 LD s6, $02d0(sp) + MobUt.LD(this.ee, this.ee.s6, (720u + this.ee.sp.UL0)); + // @0012A4D8 LD s7, $02d8(sp) + MobUt.LD(this.ee, this.ee.s7, (728u + this.ee.sp.UL0)); + // @0012A4DC LD s8, $02e0(sp) + MobUt.LD(this.ee, this.ee.s8, (736u + this.ee.sp.UL0)); + // @0012A4E0 LD ra, $02e8(sp) + MobUt.LD(this.ee, this.ee.ra, (744u + this.ee.sp.UL0)); + // @0012A4E4 LWC1 $f20, $02f0(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (752u + this.ee.sp.UL0)); + // @0012A4E8 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0012A4EC ADDIU sp, sp, $0300 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 768))); + } + + public virtual void funct0012a9b4() + { + this.ee.pc = 1223100u; + // @0012A9B4 BEQ zero, zero, $00129e54 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220180u; + } + // @0012A9B8 ADDU a1, t7, s8 + this.ee.a1.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + } + + public virtual void funct0012a9bc() + { + this.ee.pc = 1223120u; + // @0012A9BC SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + // @0012A9C0 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012A9C4 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012A9C8 BEQ zero, zero, $00129e2c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220140u; + } + // @0012A9CC ADDU a0, t6, t7 + this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012a9d0() + { + this.ee.pc = 1223156u; + // @0012A9D0 SRL t3, s4, 16 + MobUt.SRL(this.ee.t3, this.ee.s4, 16); + // @0012A9D4 MTC1 zero, $f20 + this.ee.fpr[20].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @0012A9D8 SW t3, $024c(sp) + MobUt.SW(this.ee, this.ee.t3, (588u + this.ee.sp.UL0)); + // @0012A9DC ANDI t6, t3, $0003 + this.ee.t6.UD0 = ((ushort)((this.ee.t3.US0 & 3))); + // @0012A9E0 SW zero, $0224(sp) + MobUt.SW(this.ee, this.ee.r0, (548u + this.ee.sp.UL0)); + // @0012A9E4 ADDIU t7, zero, $0001 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @0012A9E8 SW zero, $0228(sp) + MobUt.SW(this.ee, this.ee.r0, (552u + this.ee.sp.UL0)); + // @0012A9EC BEQ t6, t7, $0012caf0 + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1231600u; + } + // @0012A9F0 SW zero, $022c(sp) + MobUt.SW(this.ee, this.ee.r0, (556u + this.ee.sp.UL0)); + } + + public virtual void funct0012a9f4() + { + this.ee.pc = 1223164u; + // @0012A9F4 BEQ t6, zero, $0012ba08 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227272u; + } + // @0012A9F8 SLTIU t7, t6, $0004 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 4ul)); + } + + public virtual void funct0012a9fc() + { + this.ee.pc = 1223172u; + // @0012A9FC BEQ t7, zero, $0012ba08 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227272u; + } + // @0012AA00 LW t7, $0218(sp) + MobUt.LW(this.ee, this.ee.t7, (536u + this.ee.sp.UL0)); + } + + public virtual void funct0012aa04() + { + this.ee.pc = 1223180u; + // @0012AA04 BEQ t7, zero, $0012aa1c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223196u; + } + // @0012AA08 LW t3, $0218(sp) + MobUt.LW(this.ee, this.ee.t3, (536u + this.ee.sp.UL0)); + } + + public virtual void funct0012aa1c() + { + this.ee.pc = 1223216u; + // @0012AA1C LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012AA20 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012AA24 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012AA28 BEQ t7, zero, $0012b9ec + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227244u; + } + // @0012AA2C ADDIU t3, sp, $0090 + this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); + } + + public virtual void funct0012aa30() + { + this.ee.pc = 1223232u; + // @0012AA30 LW t7, $0024(s5) + MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s5.UL0)); + // @0012AA34 ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012AA38 BEQ t3, t6, $0012aa50 + if ((this.ee.t3.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1223248u; + } + // @0012AA3C LUI t5, $0038 + this.ee.t5.SD0 = 3670016; + } + + public virtual void funct0012aa38() + { + this.ee.pc = 1223232u; + // @0012AA38 BEQ t3, t6, $0012aa50 + if ((this.ee.t3.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1223248u; + } + // @0012AA3C LUI t5, $0038 + this.ee.t5.SD0 = 3670016; + } + + public virtual void funct0012aa40() + { + this.ee.pc = 1223280u; + // @0012AA40 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012AA44 SQ t0, $0000(t3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); + // @0012AA48 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012AA4C LUI t5, $0038 + this.ee.t5.SD0 = 3670016; + // @0012AA50 ADDIU t5, t5, $8364 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + -31900))); + // @0012AA54 LWC1 $f0, $0000(t5) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); + // @0012AA58 SWC1 $f0, $009c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); + // @0012AA5C LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012AA60 LW t4, $0214(sp) + MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); + // @0012AA64 SLT t7, t4, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.t6.SD0)); + // @0012AA68 BEQ t7, zero, $0012b9d4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227220u; + } + // @0012AA6C SLL t5, t4, 6 + MobUt.SLL(this.ee.t5, this.ee.t4, 6); + } + + public virtual void funct0012aa70() + { + this.ee.pc = 1223348u; + // @0012AA70 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012AA74 SW t5, $0250(sp) + MobUt.SW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); + // @0012AA78 ADDU t6, t7, t5 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); + // @0012AA7C ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012AA80 LQC2 vf5, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); + // @0012AA84 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012AA88 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012AA8C LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012AA90 LQC2 vf4, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); + // @0012AA94 VMULAx.xyzw ACC, vf1, vf5x + // @0012AA98 VMADDAy.xyzw ACC, vf2, vf5y + // @0012AA9C VMADDAz.xyzw ACC, vf3, vf5z + // @0012AAA0 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012AAA4 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012AAA8 ADDIU t6, sp, $0080 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012AAAC BEQ t6, t8, $0012aabc + if ((this.ee.t6.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1223356u; + } + // @0012AAB0 DADDU t7, t8, zero + this.ee.t7.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012aa7c() + { + this.ee.pc = 1223348u; + // @0012AA7C ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012AA80 LQC2 vf5, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); + // @0012AA84 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012AA88 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012AA8C LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012AA90 LQC2 vf4, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); + // @0012AA94 VMULAx.xyzw ACC, vf1, vf5x + // @0012AA98 VMADDAy.xyzw ACC, vf2, vf5y + // @0012AA9C VMADDAz.xyzw ACC, vf3, vf5z + // @0012AAA0 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012AAA4 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012AAA8 ADDIU t6, sp, $0080 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012AAAC BEQ t6, t8, $0012aabc + if ((this.ee.t6.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1223356u; + } + // @0012AAB0 DADDU t7, t8, zero + this.ee.t7.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012aab4() + { + this.ee.pc = 1223380u; + // @0012AAB4 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012AAB8 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012AABC LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + // @0012AAC0 ADDIU a1, sp, $0040 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 64))); + // @0012AAC4 LW t3, $0250(sp) + MobUt.LW(this.ee, this.ee.t3, (592u + this.ee.sp.UL0)); + // @0012AAC8 ADDU t7, t7, t3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t3.SD0))); + // @0012AACC BEQ a1, t7, $0012aaf4 + if ((this.ee.a1.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1223412u; + } + // @0012AAD0 NOP + MobUt.Latency(); + } + + public virtual void funct0012aad4() + { + this.ee.pc = 1223560u; + // @0012AAD4 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012AAD8 LQ t1, $0010(t7) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); + // @0012AADC LQ t2, $0020(t7) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); + // @0012AAE0 LQ t3, $0030(t7) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); + // @0012AAE4 SQ t0, $0000(a1) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @0012AAE8 SQ t1, $0010(a1) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); + // @0012AAEC SQ t2, $0020(a1) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); + // @0012AAF0 SQ t3, $0030(a1) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.a1.UL[0])); + // @0012AAF4 LQ t0, $0000(a1) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @0012AAF8 LQ t1, $0010(a1) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); + // @0012AAFC LQ t2, $0020(a1) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); + // @0012AB00 QMFC2 t3, vf0 + MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); + // @0012AB04 LQC2 vf4, $0030(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012AB08 PEXTLW t4, t1, t0 + this.ee.t4.UL[0] = this.ee.t0.UL[0]; + this.ee.t4.UL[1] = this.ee.t1.UL[0]; + this.ee.t4.UL[2] = this.ee.t0.UL[1]; + this.ee.t4.UL[3] = this.ee.t1.UL[1]; + // @0012AB0C PEXTUW t5, t1, t0 + this.ee.t5.UL[0] = this.ee.t0.UL[2]; + this.ee.t5.UL[1] = this.ee.t1.UL[2]; + this.ee.t5.UL[2] = this.ee.t0.UL[3]; + this.ee.t5.UL[3] = this.ee.t1.UL[3]; + // @0012AB10 PEXTLW t6, t3, t2 + this.ee.t6.UL[0] = this.ee.t2.UL[0]; + this.ee.t6.UL[1] = this.ee.t3.UL[0]; + this.ee.t6.UL[2] = this.ee.t2.UL[1]; + this.ee.t6.UL[3] = this.ee.t3.UL[1]; + // @0012AB14 PEXTUW t7, t3, t2 + this.ee.t7.UL[0] = this.ee.t2.UL[2]; + this.ee.t7.UL[1] = this.ee.t3.UL[2]; + this.ee.t7.UL[2] = this.ee.t2.UL[3]; + this.ee.t7.UL[3] = this.ee.t3.UL[3]; + // @0012AB18 PCPYLD t0, t6, t4 + this.ee.t0.UD1 = this.ee.t6.UD0; + this.ee.t0.UD0 = this.ee.t4.UD0; + // @0012AB1C PCPYUD t1, t4, t6 + this.ee.t1.UD0 = this.ee.t4.UD1; + this.ee.t1.UD1 = this.ee.t6.UD1; + // @0012AB20 PCPYLD t2, t7, t5 + this.ee.t2.UD1 = this.ee.t7.UD0; + this.ee.t2.UD0 = this.ee.t5.UD0; + // @0012AB24 QMTC2 t0, vf1 + MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); + // @0012AB28 QMTC2 t1, vf2 + MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); + // @0012AB2C QMTC2 t2, vf3 + MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); + // @0012AB30 VMULAx.xyz ACC, vf1, vf4x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[4].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[4].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[4].x); + // @0012AB34 VMADDAy.xyz ACC, vf2, vf4y + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[4].y); + // @0012AB38 VMADDz.xyz vf4, vf3, vf4z + this.ee.VF[4].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[4].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[4].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[4].z); + // @0012AB3C VSUB.xyz vf4, vf0, vf4 + this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); + this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); + this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); + // @0012AB40 SQ t0, $0000(a1) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @0012AB44 SQ t1, $0010(a1) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); + // @0012AB48 SQ t2, $0020(a1) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); + // @0012AB4C SQC2 vf4, $0030(a1) + MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012AB50 ADDIU t4, sp, $0080 + this.ee.t4.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012AB54 LQC2 vf5, $0000(t4) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t4.UL0)); + // @0012AB58 LQC2 vf1, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); + // @0012AB5C LQC2 vf2, $0010(a1) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); + // @0012AB60 LQC2 vf3, $0020(a1) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); + // @0012AB64 LQC2 vf4, $0030(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012AB68 VMULAx.xyzw ACC, vf1, vf5x + // @0012AB6C VMADDAy.xyzw ACC, vf2, vf5y + // @0012AB70 VMADDAz.xyzw ACC, vf3, vf5z + // @0012AB74 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012AB78 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012AB7C ADDIU t5, sp, $00a0 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 160))); + // @0012AB80 BEQ t5, t8, $0012ab90 + if ((this.ee.t5.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1223568u; + } + // @0012AB84 ADDIU t6, sp, $0120 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 288))); + } + + public virtual void funct0012ab88() + { + this.ee.pc = 1223580u; + // @0012AB88 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012AB8C SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012AB90 LW t7, $0204(sp) + MobUt.LW(this.ee, this.ee.t7, (516u + this.ee.sp.UL0)); + // @0012AB94 BEQ s1, t7, $0012abc8 + if ((this.ee.s1.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1223624u; + } + // @0012AB98 ADDIU s7, s2, $0001 + this.ee.s7.SD0 = ((int)((this.ee.s2.SD0 + 1))); + } + + public virtual void funct0012ab9c() + { + this.ee.pc = 1223596u; + // @0012AB9C LHU t7, $0002(s1) + MobUt.LHU(this.ee, this.ee.t7, (2u + this.ee.s1.UL0)); + // @0012ABA0 ANDI t6, s7, $ffff + this.ee.t6.UD0 = ((ushort)((this.ee.s7.US0 & 65535))); + // @0012ABA4 BNEL t7, t6, $0012abcc + if ((this.ee.t7.UD0 != this.ee.t6.UD0)) + { + this.ee.pc = 1223628u; + // @0012ABA8 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012abc8() + { + this.ee.pc = 1223652u; + // @0012ABC8 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @0012ABCC LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @0012ABD0 LHU t2, $0010(t5) + MobUt.LHU(this.ee, this.ee.t2, (16u + this.ee.t5.UL0)); + // @0012ABD4 ADDU t4, t7, s8 + this.ee.t4.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012ABD8 SLT t7, s7, t2 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t2.SD0)); + // @0012ABDC BEQ t7, zero, $0012b9b8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227192u; + } + // @0012ABE0 ADDIU t3, t4, $0010 + this.ee.t3.SD0 = ((int)((this.ee.t4.SD0 + 16))); + } + + public virtual void funct0012abcc() + { + this.ee.pc = 1223652u; + // @0012ABCC LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @0012ABD0 LHU t2, $0010(t5) + MobUt.LHU(this.ee, this.ee.t2, (16u + this.ee.t5.UL0)); + // @0012ABD4 ADDU t4, t7, s8 + this.ee.t4.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012ABD8 SLT t7, s7, t2 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t2.SD0)); + // @0012ABDC BEQ t7, zero, $0012b9b8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227192u; + } + // @0012ABE0 ADDIU t3, t4, $0010 + this.ee.t3.SD0 = ((int)((this.ee.t4.SD0 + 16))); + } + + public virtual void funct0012abe4() + { + this.ee.pc = 1223692u; + // @0012ABE4 LW t6, $001c(s5) + MobUt.LW(this.ee, this.ee.t6, (28u + this.ee.s5.UL0)); + // @0012ABE8 SLL t7, s7, 4 + MobUt.SLL(this.ee.t7, this.ee.s7, 4); + // @0012ABEC ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012ABF0 ADDIU t5, sp, $0120 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012ABF4 LQC2 vf1, $0000(t4) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); + // @0012ABF8 LQC2 vf2, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); + // @0012ABFC VMUL.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].w); + // @0012AC00 SQC2 vf1, $0000(t5) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); + // @0012AC04 BEQ t3, t5, $0012ac14 + if ((this.ee.t3.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1223700u; + } + // @0012AC08 DADDU t6, t5, zero + this.ee.t6.UD0 = (this.ee.t5.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012abf0() + { + this.ee.pc = 1223692u; + // @0012ABF0 ADDIU t5, sp, $0120 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012ABF4 LQC2 vf1, $0000(t4) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); + // @0012ABF8 LQC2 vf2, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); + // @0012ABFC VMUL.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].w); + // @0012AC00 SQC2 vf1, $0000(t5) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); + // @0012AC04 BEQ t3, t5, $0012ac14 + if ((this.ee.t3.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1223700u; + } + // @0012AC08 DADDU t6, t5, zero + this.ee.t6.UD0 = (this.ee.t5.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012ac0c() + { + this.ee.pc = 1223728u; + // @0012AC0C LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012AC10 SQ t0, $0000(t3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); + // @0012AC14 LW a2, $0220(sp) + MobUt.LW(this.ee, this.ee.a2, (544u + this.ee.sp.UL0)); + // @0012AC18 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0012AC1C DADDU a1, s5, zero + this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); + // @0012AC20 ADDIU a3, sp, $00c0 + this.ee.a3.SD0 = ((int)((this.ee.sp.SD0 + 192))); + // @0012AC24 ADDIU t0, sp, $0040 + this.ee.t0.SD0 = ((int)((this.ee.sp.SD0 + 64))); + // @0012AC28 JAL $00128de8 + this.ee.ra.UL0 = 1223728u; + this.ee.pc = 1215976u; + // @0012AC2C ADDIU t1, sp, $00b0 + this.ee.t1.SD0 = ((int)((this.ee.sp.SD0 + 176))); + } + + public virtual void funct0012ac30() + { + this.ee.pc = 1223740u; + // @0012AC30 LW t7, $01f8(sp) + MobUt.LW(this.ee, this.ee.t7, (504u + this.ee.sp.UL0)); + // @0012AC34 BEQ t7, zero, $0012acd8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223896u; + } + // @0012AC38 LW t3, $0228(sp) + MobUt.LW(this.ee, this.ee.t3, (552u + this.ee.sp.UL0)); + } + + public virtual void funct0012ac3c() + { + this.ee.pc = 1223768u; + // @0012AC3C SW t7, $0224(sp) + MobUt.SW(this.ee, this.ee.t7, (548u + this.ee.sp.UL0)); + // @0012AC40 LD t5, $0010(t7) + MobUt.LD(this.ee, this.ee.t5, (16u + this.ee.t7.UL0)); + // @0012AC44 ADDIU t7, zero, $0001 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @0012AC48 DSLL32 t7, t7, 21 + MobUt.DSLL32(this.ee.t7, this.ee.t7, 21); + // @0012AC4C AND t7, t5, t7 + this.ee.t7.UD0 = (this.ee.t5.UD0 & this.ee.t7.UD0); + // @0012AC50 BNE t7, zero, $0012acd8 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1223896u; + } + // @0012AC54 LW t3, $0228(sp) + MobUt.LW(this.ee, this.ee.t3, (552u + this.ee.sp.UL0)); + } + + public virtual void funct0012ac58() + { + this.ee.pc = 1223796u; + // @0012AC58 ADDIU t4, zero, $0001 + this.ee.t4.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @0012AC5C ANDI t6, s2, $ffff + this.ee.t6.UD0 = ((ushort)((this.ee.s2.US0 & 65535))); + // @0012AC60 DSLL32 t4, t4, 21 + MobUt.DSLL32(this.ee.t4, this.ee.t4, 21); + // @0012AC64 LW t3, $0224(sp) + MobUt.LW(this.ee, this.ee.t3, (548u + this.ee.sp.UL0)); + // @0012AC68 LHU t7, $001c(t3) + MobUt.LHU(this.ee, this.ee.t7, (28u + this.ee.t3.UL0)); + // @0012AC6C BNE t7, t6, $0012b998 + if ((this.ee.t7.UD0 != this.ee.t6.UD0)) + { + this.ee.pc = 1227160u; + } + // @0012AC70 LW t7, $0224(sp) + MobUt.LW(this.ee, this.ee.t7, (548u + this.ee.sp.UL0)); + } + + public virtual void funct0012ac68() + { + this.ee.pc = 1223796u; + // @0012AC68 LHU t7, $001c(t3) + MobUt.LHU(this.ee, this.ee.t7, (28u + this.ee.t3.UL0)); + // @0012AC6C BNE t7, t6, $0012b998 + if ((this.ee.t7.UD0 != this.ee.t6.UD0)) + { + this.ee.pc = 1227160u; + } + // @0012AC70 LW t7, $0224(sp) + MobUt.LW(this.ee, this.ee.t7, (548u + this.ee.sp.UL0)); + } + + public virtual void funct0012ac74() + { + this.ee.pc = 1223840u; + // @0012AC74 DSRL32 t7, t5, 20 + MobUt.DSRL32(this.ee.t7, this.ee.t5, 20); + // @0012AC78 ADDIU t4, zero, $0001 + this.ee.t4.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @0012AC7C ANDI t7, t7, $0001 + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 1))); + // @0012AC80 SW t4, $0228(sp) + MobUt.SW(this.ee, this.ee.t4, (552u + this.ee.sp.UL0)); + // @0012AC84 SW t7, $022c(sp) + MobUt.SW(this.ee, this.ee.t7, (556u + this.ee.sp.UL0)); + // @0012AC88 ADDIU s3, zero, $0020 + this.ee.s3.SD0 = ((int)((this.ee.r0.SD0 + 32))); + // @0012AC8C LW a0, $0014(s5) + MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); + // @0012AC90 LW t7, $0000(a0) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); + // @0012AC94 LW v0, $0018(t7) + MobUt.LW(this.ee, this.ee.v0, (24u + this.ee.t7.UL0)); + // @0012AC98 JALR ra, v0 + this.ee.ra.UD0 = 1223840u; + this.ee.pc = this.ee.v0.UL0; + // @0012AC9C DADDU a1, s3, zero + this.ee.a1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012ac90() + { + this.ee.pc = 1223840u; + // @0012AC90 LW t7, $0000(a0) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); + // @0012AC94 LW v0, $0018(t7) + MobUt.LW(this.ee, this.ee.v0, (24u + this.ee.t7.UL0)); + // @0012AC98 JALR ra, v0 + this.ee.ra.UD0 = 1223840u; + this.ee.pc = this.ee.v0.UL0; + // @0012AC9C DADDU a1, s3, zero + this.ee.a1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012aca0() + { + this.ee.pc = 1223848u; + // @0012ACA0 BEQL s2, v0, $0012b97c + if ((this.ee.s2.UD0 == this.ee.v0.UD0)) + { + this.ee.pc = 1227132u; + // @0012ACA4 LW a0, $0014(s5) + MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); + } + } + + public virtual void funct0012aca8() + { + this.ee.pc = 1223864u; + // @0012ACA8 ADDIU s3, s3, $0001 + this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); + // @0012ACAC SLTI t7, s3, $0024 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s3.SD0 < 36)); + // @0012ACB0 BNEL t7, zero, $0012ac90 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1223824u; + // @0012ACB4 LW a0, $0014(s5) + MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); + } + } + + public virtual void funct0012acb8() + { + this.ee.pc = 1223892u; + // @0012ACB8 LW t5, $0224(sp) + MobUt.LW(this.ee, this.ee.t5, (548u + this.ee.sp.UL0)); + // @0012ACBC ADDIU t7, zero, $0001 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @0012ACC0 DSLL32 t7, t7, 19 + MobUt.DSLL32(this.ee.t7, this.ee.t7, 19); + // @0012ACC4 LD t6, $0010(t5) + MobUt.LD(this.ee, this.ee.t6, (16u + this.ee.t5.UL0)); + // @0012ACC8 AND t6, t6, t7 + this.ee.t6.UD0 = (this.ee.t6.UD0 & this.ee.t7.UD0); + // @0012ACCC BNEL t6, zero, $0012acd4 + if ((this.ee.t6.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1223892u; + // @0012ACD0 LWC1 $f20, $0018(t5) + MobUt.LWC1(this.ee, this.ee.fpr[20], (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct0012acd4() + { + this.ee.pc = 1223904u; + // @0012ACD4 LW t3, $0228(sp) + MobUt.LW(this.ee, this.ee.t3, (552u + this.ee.sp.UL0)); + // @0012ACD8 BEQ t3, zero, $0012af80 + if ((this.ee.t3.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1224576u; + } + // @0012ACDC LW t4, $01f0(sp) + MobUt.LW(this.ee, this.ee.t4, (496u + this.ee.sp.UL0)); + } + + public virtual void funct0012acd8() + { + this.ee.pc = 1223904u; + // @0012ACD8 BEQ t3, zero, $0012af80 + if ((this.ee.t3.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1224576u; + } + // @0012ACDC LW t4, $01f0(sp) + MobUt.LW(this.ee, this.ee.t4, (496u + this.ee.sp.UL0)); + } + + public virtual void funct0012ace0() + { + this.ee.pc = 1223964u; + // @0012ACE0 ADDIU t7, sp, $0130 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 304))); + // @0012ACE4 ADDIU s3, sp, $0140 + this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 320))); + // @0012ACE8 ADDIU t5, sp, $00c0 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 192))); + // @0012ACEC LQC2 vf5, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); + // @0012ACF0 LQC2 vf1, $0000(t4) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); + // @0012ACF4 LQC2 vf2, $0010(t4) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t4.UL0)); + // @0012ACF8 LQC2 vf3, $0020(t4) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t4.UL0)); + // @0012ACFC LQC2 vf4, $0030(t4) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t4.UL0)); + // @0012AD00 VMULAx.xyzw ACC, vf1, vf5x + // @0012AD04 VMADDAy.xyzw ACC, vf2, vf5y + // @0012AD08 VMADDAz.xyzw ACC, vf3, vf5z + // @0012AD0C VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012AD10 SQC2 vf5, $0000(s3) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s3.UL0)); + // @0012AD14 BEQ t7, s3, $0012ad28 + if ((this.ee.t7.UD0 == this.ee.s3.UD0)) + { + this.ee.pc = 1223976u; + } + // @0012AD18 LWC1 $f0, $0134(sp) + MobUt.LWC1(this.ee, this.ee.fpr[0], (308u + this.ee.sp.UL0)); + } + + public virtual void funct0012ad1c() + { + this.ee.pc = 1223992u; + // @0012AD1C LQ t0, $0000(s3) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @0012AD20 SQ t0, $0000(t7) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012AD24 LWC1 $f0, $0134(sp) + MobUt.LWC1(this.ee, this.ee.fpr[0], (308u + this.ee.sp.UL0)); + // @0012AD28 ADDIU t6, sp, $0120 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012AD2C ADD.S $f0, $f0, $f20 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[20].f); + // @0012AD30 BEQ t6, t7, $0012ad40 + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1224000u; + } + // @0012AD34 SWC1 $f0, $0134(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (308u + this.ee.sp.UL0)); + } + + public virtual void funct0012ad38() + { + this.ee.pc = 1224032u; + // @0012AD38 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012AD3C SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012AD40 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @0012AD44 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @0012AD48 LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @0012AD4C ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012AD50 ADDIU t7, t7, $0010 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16))); + // @0012AD54 SLT t6, s7, t4 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t4.SD0)); + // @0012AD58 BEQ t6, zero, $0012b964 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227108u; + } + // @0012AD5C SW t7, $0234(sp) + MobUt.SW(this.ee, this.ee.t7, (564u + this.ee.sp.UL0)); + } + + public virtual void funct0012ad60() + { + this.ee.pc = 1224052u; + // @0012AD60 LW a0, $0014(s5) + MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); + // @0012AD64 LW t7, $0000(a0) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); + // @0012AD68 LW v0, $0020(t7) + MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); + // @0012AD6C JALR ra, v0 + this.ee.ra.UD0 = 1224052u; + this.ee.pc = this.ee.v0.UL0; + // @0012AD70 NOP + MobUt.Latency(); + } + + public virtual void funct0012ad74() + { + this.ee.pc = 1224100u; + // @0012AD74 SLL t7, s7, 6 + MobUt.SLL(this.ee.t7, this.ee.s7, 6); + // @0012AD78 ADDU v0, v0, t7 + this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.t7.SD0))); + // @0012AD7C LW t7, $0234(sp) + MobUt.LW(this.ee, this.ee.t7, (564u + this.ee.sp.UL0)); + // @0012AD80 LWC1 $f2, $001c(v0) + MobUt.LWC1(this.ee, this.ee.fpr[2], (28u + this.ee.v0.UL0)); + // @0012AD84 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @0012AD88 LWC1 $f1, $0124(sp) + MobUt.LWC1(this.ee, this.ee.fpr[1], (292u + this.ee.sp.UL0)); + // @0012AD8C MUL.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[2].f); + // @0012AD90 LW t3, $022c(sp) + MobUt.LW(this.ee, this.ee.t3, (556u + this.ee.sp.UL0)); + // @0012AD94 ADD.S $f0, $f0, $f20 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[20].f); + // @0012AD98 SUB.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); + // @0012AD9C BEQ t3, zero, $0012ae00 + if ((this.ee.t3.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1224192u; + } + // @0012ADA0 SWC1 $f1, $0124(sp) + MobUt.SWC1(this.ee, this.ee.fpr[1], (292u + this.ee.sp.UL0)); + } + + public virtual void funct0012ae00() + { + this.ee.pc = 1224204u; + // @0012AE00 ADDIU a0, sp, $0120 + this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012AE04 JAL $00143ec8 + this.ee.ra.UL0 = 1224204u; + this.ee.pc = 1326792u; + // @0012AE08 DADDU a1, s3, zero + this.ee.a1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012ae0c() + { + this.ee.pc = 1224212u; + // @0012AE0C BEQ v0, zero, $0012af80 + if ((this.ee.v0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1224576u; + } + // @0012AE10 LW t5, $0224(sp) + MobUt.LW(this.ee, this.ee.t5, (548u + this.ee.sp.UL0)); + } + + public virtual void funct0012af80() + { + this.ee.pc = 1224588u; + // @0012AF80 LW t6, $0218(sp) + MobUt.LW(this.ee, this.ee.t6, (536u + this.ee.sp.UL0)); + // @0012AF84 BEQ t6, zero, $0012b7a8 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226664u; + } + // @0012AF88 LW t7, $0218(sp) + MobUt.LW(this.ee, this.ee.t7, (536u + this.ee.sp.UL0)); + } + + public virtual void funct0012b100() + { + this.ee.pc = 1224968u; + // @0012B100 JAL $00124a88 + this.ee.ra.UL0 = 1224968u; + this.ee.pc = 1198728u; + // @0012B104 NOP + MobUt.Latency(); + } + + public virtual void funct0012b108() + { + this.ee.pc = 1224984u; + // @0012B108 LUI t7, $0040 + this.ee.t7.SD0 = 4194304; + // @0012B10C AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @0012B110 BEQL t7, zero, $0012b158 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225048u; + // @0012B114 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012b158() + { + this.ee.pc = 1225064u; + // @0012B158 LHU t7, $0010(t7) + MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); + // @0012B15C SLT t6, s2, t7 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); + // @0012B160 BEQ t6, zero, $0012b6dc + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226460u; + } + // @0012B164 SUBU t7, s2, t7 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); + } + + public virtual void funct0012b168() + { + this.ee.pc = 1225112u; + // @0012B168 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012B16C ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012B170 LWC1 $f0, $0090(sp) + MobUt.LWC1(this.ee, this.ee.fpr[0], (144u + this.ee.sp.UL0)); + // @0012B174 SWC1 $f0, $0030(t6) + MobUt.SWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t6.UL0)); + // @0012B178 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012B17C LW t6, $0008(s0) + MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); + // @0012B180 LW t5, $0250(sp) + MobUt.LW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); + // @0012B184 LHU t4, $0010(t7) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t7.UL0)); + // @0012B188 ADDU t3, t6, t5 + this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); + // @0012B18C SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @0012B190 BEQ t7, zero, $0012b6c8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226440u; + } + // @0012B194 ADDU t5, t6, s3 + this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); + } + + public virtual void funct0012b170() + { + this.ee.pc = 1225112u; + // @0012B170 LWC1 $f0, $0090(sp) + MobUt.LWC1(this.ee, this.ee.fpr[0], (144u + this.ee.sp.UL0)); + // @0012B174 SWC1 $f0, $0030(t6) + MobUt.SWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t6.UL0)); + // @0012B178 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012B17C LW t6, $0008(s0) + MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); + // @0012B180 LW t5, $0250(sp) + MobUt.LW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); + // @0012B184 LHU t4, $0010(t7) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t7.UL0)); + // @0012B188 ADDU t3, t6, t5 + this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); + // @0012B18C SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @0012B190 BEQ t7, zero, $0012b6c8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226440u; + } + // @0012B194 ADDU t5, t6, s3 + this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); + } + + public virtual void funct0012b198() + { + this.ee.pc = 1225244u; + // @0012B198 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012B19C ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012B1A0 ADDIU t7, sp, $0120 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012B1A4 LQC2 vf1, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); + // @0012B1A8 LQC2 vf2, $0010(t3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); + // @0012B1AC LQC2 vf3, $0020(t3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); + // @0012B1B0 LQC2 vf4, $0030(t3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); + // @0012B1B4 LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012B1B8 LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012B1BC LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012B1C0 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012B1C4 VMULAx.xyzw ACC, vf1, vf5x + // @0012B1C8 VMADDAy.xyzw ACC, vf2, vf5y + // @0012B1CC VMADDAz.xyzw ACC, vf3, vf5z + // @0012B1D0 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012B1D4 VMULAx.xyzw ACC, vf1, vf6x + // @0012B1D8 VMADDAy.xyzw ACC, vf2, vf6y + // @0012B1DC VMADDAz.xyzw ACC, vf3, vf6z + // @0012B1E0 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012B1E4 VMULAx.xyzw ACC, vf1, vf7x + // @0012B1E8 VMADDAy.xyzw ACC, vf2, vf7y + // @0012B1EC VMADDAz.xyzw ACC, vf3, vf7z + // @0012B1F0 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012B1F4 VMULAx.xyzw ACC, vf1, vf8x + // @0012B1F8 VMADDAy.xyzw ACC, vf2, vf8y + // @0012B1FC VMADDAz.xyzw ACC, vf3, vf8z + // @0012B200 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012B204 SQC2 vf5, $0000(t7) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012B208 SQC2 vf6, $0010(t7) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); + // @0012B20C SQC2 vf7, $0020(t7) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); + // @0012B210 SQC2 vf8, $0030(t7) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); + // @0012B214 BEQ t5, t7, $0012b23c + if ((this.ee.t5.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1225276u; + } + // @0012B218 DADDU t4, t7, zero + this.ee.t4.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012b1a0() + { + this.ee.pc = 1225244u; + // @0012B1A0 ADDIU t7, sp, $0120 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012B1A4 LQC2 vf1, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); + // @0012B1A8 LQC2 vf2, $0010(t3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); + // @0012B1AC LQC2 vf3, $0020(t3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); + // @0012B1B0 LQC2 vf4, $0030(t3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); + // @0012B1B4 LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012B1B8 LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012B1BC LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012B1C0 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012B1C4 VMULAx.xyzw ACC, vf1, vf5x + // @0012B1C8 VMADDAy.xyzw ACC, vf2, vf5y + // @0012B1CC VMADDAz.xyzw ACC, vf3, vf5z + // @0012B1D0 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012B1D4 VMULAx.xyzw ACC, vf1, vf6x + // @0012B1D8 VMADDAy.xyzw ACC, vf2, vf6y + // @0012B1DC VMADDAz.xyzw ACC, vf3, vf6z + // @0012B1E0 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012B1E4 VMULAx.xyzw ACC, vf1, vf7x + // @0012B1E8 VMADDAy.xyzw ACC, vf2, vf7y + // @0012B1EC VMADDAz.xyzw ACC, vf3, vf7z + // @0012B1F0 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012B1F4 VMULAx.xyzw ACC, vf1, vf8x + // @0012B1F8 VMADDAy.xyzw ACC, vf2, vf8y + // @0012B1FC VMADDAz.xyzw ACC, vf3, vf8z + // @0012B200 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012B204 SQC2 vf5, $0000(t7) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012B208 SQC2 vf6, $0010(t7) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); + // @0012B20C SQC2 vf7, $0020(t7) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); + // @0012B210 SQC2 vf8, $0030(t7) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); + // @0012B214 BEQ t5, t7, $0012b23c + if ((this.ee.t5.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1225276u; + } + // @0012B218 DADDU t4, t7, zero + this.ee.t4.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012b21c() + { + this.ee.pc = 1225296u; + // @0012B21C LQ t0, $0000(t4) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); + // @0012B220 LQ t1, $0010(t4) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); + // @0012B224 LQ t2, $0020(t4) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); + // @0012B228 LQ t3, $0030(t4) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); + // @0012B22C SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012B230 SQ t1, $0010(t5) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); + // @0012B234 SQ t2, $0020(t5) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); + // @0012B238 SQ t3, $0030(t5) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); + // @0012B23C LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B240 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B244 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012B248 BEQ t7, zero, $0012b6b8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226424u; + } + // @0012B24C SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b250() + { + this.ee.pc = 1225320u; + // @0012B250 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012B254 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012B258 LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + // @0012B25C ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012B260 BEQL t6, t7, $0012b290 + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1225360u; + // @0012B264 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012b258() + { + this.ee.pc = 1225320u; + // @0012B258 LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + // @0012B25C ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012B260 BEQL t6, t7, $0012b290 + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1225360u; + // @0012B264 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012b268() + { + this.ee.pc = 1225372u; + // @0012B268 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012B26C LQ t1, $0010(t7) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); + // @0012B270 LQ t2, $0020(t7) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); + // @0012B274 LQ t3, $0030(t7) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); + // @0012B278 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012B27C SQ t1, $0010(t6) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); + // @0012B280 SQ t2, $0020(t6) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); + // @0012B284 SQ t3, $0030(t6) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); + // @0012B288 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B28C LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B290 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012B294 BEQ t7, zero, $0012b6a8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226408u; + } + // @0012B298 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b29c() + { + this.ee.pc = 1225448u; + // @0012B29C LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012B2A0 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012B2A4 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @0012B2A8 ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012B2AC LQC2 vf4, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); + // @0012B2B0 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012B2B4 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012B2B8 LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012B2BC VMULx.xyzw vf1, vf1, vf4x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); + // @0012B2C0 VMULy.xyzw vf2, vf2, vf4y + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); + this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); + // @0012B2C4 VMULz.xyzw vf3, vf3, vf4z + this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); + this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); + // @0012B2C8 SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012B2CC SQC2 vf2, $0010(t6) + MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012B2D0 SQC2 vf3, $0020(t6) + MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012B2D4 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B2D8 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B2DC SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012B2E0 BEQ t7, zero, $0012b698 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226392u; + } + // @0012B2E4 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b2a4() + { + this.ee.pc = 1225448u; + // @0012B2A4 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @0012B2A8 ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012B2AC LQC2 vf4, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); + // @0012B2B0 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012B2B4 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012B2B8 LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012B2BC VMULx.xyzw vf1, vf1, vf4x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); + // @0012B2C0 VMULy.xyzw vf2, vf2, vf4y + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); + this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); + // @0012B2C4 VMULz.xyzw vf3, vf3, vf4z + this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); + this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); + // @0012B2C8 SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012B2CC SQC2 vf2, $0010(t6) + MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012B2D0 SQC2 vf3, $0020(t6) + MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012B2D4 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B2D8 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B2DC SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012B2E0 BEQ t7, zero, $0012b698 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226392u; + } + // @0012B2E4 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b2e8() + { + this.ee.pc = 1225472u; + // @0012B2E8 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012B2EC ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012B2F0 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012B2F4 ADDIU t5, sp, $0080 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012B2F8 BEQL t6, t5, $0012b310 + if ((this.ee.t6.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1225488u; + // @0012B2FC LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012b2f0() + { + this.ee.pc = 1225472u; + // @0012B2F0 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012B2F4 ADDIU t5, sp, $0080 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012B2F8 BEQL t6, t5, $0012b310 + if ((this.ee.t6.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1225488u; + // @0012B2FC LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012b300() + { + this.ee.pc = 1225500u; + // @0012B300 LQ t0, $0000(t5) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012B304 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012B308 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B30C LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B310 SLT t7, s7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); + // @0012B314 BEQ t7, zero, $0012b68c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226380u; + } + // @0012B318 SUBU t7, s7, t6 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b31c() + { + this.ee.pc = 1225528u; + // @0012B31C LW t6, $0028(s5) + MobUt.LW(this.ee, this.ee.t6, (40u + this.ee.s5.UL0)); + // @0012B320 SLL t7, s7, 6 + MobUt.SLL(this.ee.t7, this.ee.s7, 6); + // @0012B324 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012B328 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B32C SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012B330 BEQ t7, zero, $0012b674 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226356u; + } + // @0012B334 ADDIU s4, t6, $0030 + this.ee.s4.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012b324() + { + this.ee.pc = 1225528u; + // @0012B324 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012B328 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B32C SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012B330 BEQ t7, zero, $0012b674 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226356u; + } + // @0012B334 ADDIU s4, t6, $0030 + this.ee.s4.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012b338() + { + this.ee.pc = 1225548u; + // @0012B338 LW a0, $0014(s5) + MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); + // @0012B33C LW t7, $0000(a0) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); + // @0012B340 LW v0, $0020(t7) + MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); + // @0012B344 JALR ra, v0 + this.ee.ra.UD0 = 1225548u; + this.ee.pc = this.ee.v0.UL0; + // @0012B348 NOP + MobUt.Latency(); + } + + public virtual void funct0012b34c() + { + this.ee.pc = 1225588u; + // @0012B34C ADDU v0, v0, s3 + this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.s3.SD0))); + // @0012B350 LWC1 $f0, $001c(v0) + MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); + // @0012B354 SWC1 $f0, $0000(s4) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.s4.UL0)); + // @0012B358 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012B35C LW t6, $0008(s0) + MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); + // @0012B360 LHU t3, $0010(t7) + MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t7.UL0)); + // @0012B364 ADDU t5, t6, s3 + this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); + // @0012B368 SLT t7, s7, t3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t3.SD0)); + // @0012B36C BEQ t7, zero, $0012b664 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226340u; + } + // @0012B370 ADDIU t4, t5, $0040 + this.ee.t4.SD0 = ((int)((this.ee.t5.SD0 + 64))); + } + + public virtual void funct0012b350() + { + this.ee.pc = 1225588u; + // @0012B350 LWC1 $f0, $001c(v0) + MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); + // @0012B354 SWC1 $f0, $0000(s4) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.s4.UL0)); + // @0012B358 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012B35C LW t6, $0008(s0) + MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); + // @0012B360 LHU t3, $0010(t7) + MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t7.UL0)); + // @0012B364 ADDU t5, t6, s3 + this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); + // @0012B368 SLT t7, s7, t3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t3.SD0)); + // @0012B36C BEQ t7, zero, $0012b664 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226340u; + } + // @0012B370 ADDIU t4, t5, $0040 + this.ee.t4.SD0 = ((int)((this.ee.t5.SD0 + 64))); + } + + public virtual void funct0012b374() + { + this.ee.pc = 1225724u; + // @0012B374 LW t6, $0028(s5) + MobUt.LW(this.ee, this.ee.t6, (40u + this.ee.s5.UL0)); + // @0012B378 SLL t7, s7, 6 + MobUt.SLL(this.ee.t7, this.ee.s7, 6); + // @0012B37C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B380 ADDIU t7, sp, $0120 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012B384 LQC2 vf1, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); + // @0012B388 LQC2 vf2, $0010(t5) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t5.UL0)); + // @0012B38C LQC2 vf3, $0020(t5) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t5.UL0)); + // @0012B390 LQC2 vf4, $0030(t5) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t5.UL0)); + // @0012B394 LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012B398 LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012B39C LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012B3A0 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012B3A4 VMULAx.xyzw ACC, vf1, vf5x + // @0012B3A8 VMADDAy.xyzw ACC, vf2, vf5y + // @0012B3AC VMADDAz.xyzw ACC, vf3, vf5z + // @0012B3B0 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012B3B4 VMULAx.xyzw ACC, vf1, vf6x + // @0012B3B8 VMADDAy.xyzw ACC, vf2, vf6y + // @0012B3BC VMADDAz.xyzw ACC, vf3, vf6z + // @0012B3C0 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012B3C4 VMULAx.xyzw ACC, vf1, vf7x + // @0012B3C8 VMADDAy.xyzw ACC, vf2, vf7y + // @0012B3CC VMADDAz.xyzw ACC, vf3, vf7z + // @0012B3D0 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012B3D4 VMULAx.xyzw ACC, vf1, vf8x + // @0012B3D8 VMADDAy.xyzw ACC, vf2, vf8y + // @0012B3DC VMADDAz.xyzw ACC, vf3, vf8z + // @0012B3E0 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012B3E4 SQC2 vf5, $0000(t7) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012B3E8 SQC2 vf6, $0010(t7) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); + // @0012B3EC SQC2 vf7, $0020(t7) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); + // @0012B3F0 SQC2 vf8, $0030(t7) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); + // @0012B3F4 BEQL t4, t7, $0012b424 + if ((this.ee.t4.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1225764u; + // @0012B3F8 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012b37c() + { + this.ee.pc = 1225724u; + // @0012B37C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B380 ADDIU t7, sp, $0120 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012B384 LQC2 vf1, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); + // @0012B388 LQC2 vf2, $0010(t5) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t5.UL0)); + // @0012B38C LQC2 vf3, $0020(t5) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t5.UL0)); + // @0012B390 LQC2 vf4, $0030(t5) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t5.UL0)); + // @0012B394 LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012B398 LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012B39C LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012B3A0 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012B3A4 VMULAx.xyzw ACC, vf1, vf5x + // @0012B3A8 VMADDAy.xyzw ACC, vf2, vf5y + // @0012B3AC VMADDAz.xyzw ACC, vf3, vf5z + // @0012B3B0 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012B3B4 VMULAx.xyzw ACC, vf1, vf6x + // @0012B3B8 VMADDAy.xyzw ACC, vf2, vf6y + // @0012B3BC VMADDAz.xyzw ACC, vf3, vf6z + // @0012B3C0 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012B3C4 VMULAx.xyzw ACC, vf1, vf7x + // @0012B3C8 VMADDAy.xyzw ACC, vf2, vf7y + // @0012B3CC VMADDAz.xyzw ACC, vf3, vf7z + // @0012B3D0 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012B3D4 VMULAx.xyzw ACC, vf1, vf8x + // @0012B3D8 VMADDAy.xyzw ACC, vf2, vf8y + // @0012B3DC VMADDAz.xyzw ACC, vf3, vf8z + // @0012B3E0 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012B3E4 SQC2 vf5, $0000(t7) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012B3E8 SQC2 vf6, $0010(t7) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); + // @0012B3EC SQC2 vf7, $0020(t7) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); + // @0012B3F0 SQC2 vf8, $0030(t7) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); + // @0012B3F4 BEQL t4, t7, $0012b424 + if ((this.ee.t4.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1225764u; + // @0012B3F8 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012b3fc() + { + this.ee.pc = 1225780u; + // @0012B3FC DADDU t5, t7, zero + this.ee.t5.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); + // @0012B400 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012B404 LQ t1, $0010(t7) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); + // @0012B408 LQ t2, $0020(t7) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); + // @0012B40C LQ t3, $0030(t7) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); + // @0012B410 SQ t0, $0000(t4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); + // @0012B414 SQ t1, $0010(t4) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); + // @0012B418 SQ t2, $0020(t4) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); + // @0012B41C SQ t3, $0030(t4) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); + // @0012B420 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B424 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B428 SLT t7, s7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); + // @0012B42C BEQ t7, zero, $0012b658 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226328u; + } + // @0012B430 SUBU t7, s7, t6 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b434() + { + this.ee.pc = 1225812u; + // @0012B434 LW t6, $002c(s5) + MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); + // @0012B438 SLL t7, s7, 6 + MobUt.SLL(this.ee.t7, this.ee.s7, 6); + // @0012B43C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B440 LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + // @0012B444 ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012B448 ADDIU t7, t7, $0040 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 64))); + // @0012B44C BEQL t6, t7, $0012b47c + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1225852u; + // @0012B450 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012b43c() + { + this.ee.pc = 1225812u; + // @0012B43C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B440 LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + // @0012B444 ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012B448 ADDIU t7, t7, $0040 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 64))); + // @0012B44C BEQL t6, t7, $0012b47c + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1225852u; + // @0012B450 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012b454() + { + this.ee.pc = 1225864u; + // @0012B454 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012B458 LQ t1, $0010(t7) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); + // @0012B45C LQ t2, $0020(t7) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); + // @0012B460 LQ t3, $0030(t7) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); + // @0012B464 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012B468 SQ t1, $0010(t6) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); + // @0012B46C SQ t2, $0020(t6) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); + // @0012B470 SQ t3, $0030(t6) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); + // @0012B474 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B478 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B47C SLT t7, s7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); + // @0012B480 BEQ t7, zero, $0012b64c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226316u; + } + // @0012B484 SUBU t7, s7, t6 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b488() + { + this.ee.pc = 1225948u; + // @0012B488 LW t6, $002c(s5) + MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); + // @0012B48C SLL t7, s7, 6 + MobUt.SLL(this.ee.t7, this.ee.s7, 6); + // @0012B490 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B494 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @0012B498 ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012B49C ADDIU t7, t7, $0010 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16))); + // @0012B4A0 LQC2 vf4, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); + // @0012B4A4 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012B4A8 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012B4AC LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012B4B0 VMULx.xyzw vf1, vf1, vf4x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); + // @0012B4B4 VMULy.xyzw vf2, vf2, vf4y + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); + this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); + // @0012B4B8 VMULz.xyzw vf3, vf3, vf4z + this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); + this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); + // @0012B4BC SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012B4C0 SQC2 vf2, $0010(t6) + MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012B4C4 SQC2 vf3, $0020(t6) + MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012B4C8 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B4CC LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B4D0 SLT t7, s7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); + // @0012B4D4 BEQ t7, zero, $0012b640 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226304u; + } + // @0012B4D8 SUBU t7, s7, t6 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b490() + { + this.ee.pc = 1225948u; + // @0012B490 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B494 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @0012B498 ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012B49C ADDIU t7, t7, $0010 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16))); + // @0012B4A0 LQC2 vf4, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); + // @0012B4A4 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012B4A8 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012B4AC LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012B4B0 VMULx.xyzw vf1, vf1, vf4x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); + // @0012B4B4 VMULy.xyzw vf2, vf2, vf4y + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); + this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); + // @0012B4B8 VMULz.xyzw vf3, vf3, vf4z + this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); + this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); + // @0012B4BC SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012B4C0 SQC2 vf2, $0010(t6) + MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012B4C4 SQC2 vf3, $0020(t6) + MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012B4C8 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B4CC LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B4D0 SLT t7, s7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); + // @0012B4D4 BEQ t7, zero, $0012b640 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226304u; + } + // @0012B4D8 SUBU t7, s7, t6 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b4dc() + { + this.ee.pc = 1225976u; + // @0012B4DC LW t6, $002c(s5) + MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); + // @0012B4E0 SLL t7, s7, 6 + MobUt.SLL(this.ee.t7, this.ee.s7, 6); + // @0012B4E4 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012B4E8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B4EC SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012B4F0 BEQ t7, zero, $0012b62c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226284u; + } + // @0012B4F4 ADDIU t3, t6, $0030 + this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012b4e4() + { + this.ee.pc = 1225976u; + // @0012B4E4 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012B4E8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B4EC SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012B4F0 BEQ t7, zero, $0012b62c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226284u; + } + // @0012B4F4 ADDIU t3, t6, $0030 + this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012b4f8() + { + this.ee.pc = 1226000u; + // @0012B4F8 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012B4FC ADDU v0, t7, s3 + this.ee.v0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012B500 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B504 SLT t7, s7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); + // @0012B508 BEQ t7, zero, $0012b620 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226272u; + } + // @0012B50C SUBU t7, s7, t6 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b500() + { + this.ee.pc = 1226000u; + // @0012B500 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B504 SLT t7, s7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); + // @0012B508 BEQ t7, zero, $0012b620 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226272u; + } + // @0012B50C SUBU t7, s7, t6 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b510() + { + this.ee.pc = 1226092u; + // @0012B510 LW t6, $0028(s5) + MobUt.LW(this.ee, this.ee.t6, (40u + this.ee.s5.UL0)); + // @0012B514 SLL t7, s7, 6 + MobUt.SLL(this.ee.t7, this.ee.s7, 6); + // @0012B518 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B51C ADDIU t7, t6, $0030 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012B520 LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012B524 LQC2 vf1, $0000(v0) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.v0.UL0)); + // @0012B528 LQC2 vf2, $0010(v0) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.v0.UL0)); + // @0012B52C LQC2 vf3, $0020(v0) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.v0.UL0)); + // @0012B530 LQC2 vf4, $0030(v0) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.v0.UL0)); + // @0012B534 VMULAx.xyz ACC, vf1, vf5x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); + // @0012B538 VMADDAy.xyz ACC, vf2, vf5y + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); + // @0012B53C VMADDAz.xyz ACC, vf3, vf5z + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); + // @0012B540 VMADDw.xyz vf5, vf4, vf0w + this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); + this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); + this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); + // @0012B544 VMOVE.w vf5, vf0 + this.ee.VF[5].w = this.ee.VF[0].w; + // @0012B548 SQC2 vf5, $0000(t3) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); + // @0012B54C LW t6, $0220(sp) + MobUt.LW(this.ee, this.ee.t6, (544u + this.ee.sp.UL0)); + // @0012B550 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B554 LHU a2, $0002(t6) + MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.t6.UL0)); + // @0012B558 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B55C ANDI t5, a2, $ffff + this.ee.t5.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); + // @0012B560 SLT t7, t5, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); + // @0012B564 BEQ t7, zero, $0012b610 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226256u; + } + // @0012B568 DADDU t3, t4, zero + this.ee.t3.UD0 = (this.ee.t4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012b518() + { + this.ee.pc = 1226092u; + // @0012B518 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B51C ADDIU t7, t6, $0030 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012B520 LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012B524 LQC2 vf1, $0000(v0) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.v0.UL0)); + // @0012B528 LQC2 vf2, $0010(v0) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.v0.UL0)); + // @0012B52C LQC2 vf3, $0020(v0) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.v0.UL0)); + // @0012B530 LQC2 vf4, $0030(v0) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.v0.UL0)); + // @0012B534 VMULAx.xyz ACC, vf1, vf5x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); + // @0012B538 VMADDAy.xyz ACC, vf2, vf5y + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); + // @0012B53C VMADDAz.xyz ACC, vf3, vf5z + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); + // @0012B540 VMADDw.xyz vf5, vf4, vf0w + this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); + this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); + this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); + // @0012B544 VMOVE.w vf5, vf0 + this.ee.VF[5].w = this.ee.VF[0].w; + // @0012B548 SQC2 vf5, $0000(t3) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); + // @0012B54C LW t6, $0220(sp) + MobUt.LW(this.ee, this.ee.t6, (544u + this.ee.sp.UL0)); + // @0012B550 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B554 LHU a2, $0002(t6) + MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.t6.UL0)); + // @0012B558 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B55C ANDI t5, a2, $ffff + this.ee.t5.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); + // @0012B560 SLT t7, t5, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); + // @0012B564 BEQ t7, zero, $0012b610 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226256u; + } + // @0012B568 DADDU t3, t4, zero + this.ee.t3.UD0 = (this.ee.t4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012b56c() + { + this.ee.pc = 1226124u; + // @0012B56C LW t6, $002c(s5) + MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); + // @0012B570 SLL t7, t5, 6 + MobUt.SLL(this.ee.t7, this.ee.t5, 6); + // @0012B574 ADDU t7, t6, t7 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B578 LHU t6, $0010(t3) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t3.UL0)); + // @0012B57C ADDIU t2, t7, $0030 + this.ee.t2.SD0 = ((int)((this.ee.t7.SD0 + 48))); + // @0012B580 SLT t7, s7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); + // @0012B584 BEQ t7, zero, $0012b604 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226244u; + } + // @0012B588 SUBU t7, s7, t6 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b574() + { + this.ee.pc = 1226124u; + // @0012B574 ADDU t7, t6, t7 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B578 LHU t6, $0010(t3) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t3.UL0)); + // @0012B57C ADDIU t2, t7, $0030 + this.ee.t2.SD0 = ((int)((this.ee.t7.SD0 + 48))); + // @0012B580 SLT t7, s7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); + // @0012B584 BEQ t7, zero, $0012b604 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226244u; + } + // @0012B588 SUBU t7, s7, t6 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b58c() + { + this.ee.pc = 1226156u; + // @0012B58C LW t6, $002c(s5) + MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); + // @0012B590 SLL t7, s7, 6 + MobUt.SLL(this.ee.t7, this.ee.s7, 6); + // @0012B594 LHU t5, $0010(t3) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t3.UL0)); + // @0012B598 ADDU t4, t6, t7 + this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B59C ANDI a2, a2, $ffff + this.ee.a2.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); + // @0012B5A0 SLT t7, a2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); + // @0012B5A4 BEQ t7, zero, $0012b5e8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226216u; + } + // @0012B5A8 SLL t7, a2, 4 + MobUt.SLL(this.ee.t7, this.ee.a2, 4); + } + + public virtual void funct0012b594() + { + this.ee.pc = 1226156u; + // @0012B594 LHU t5, $0010(t3) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t3.UL0)); + // @0012B598 ADDU t4, t6, t7 + this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B59C ANDI a2, a2, $ffff + this.ee.a2.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); + // @0012B5A0 SLT t7, a2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); + // @0012B5A4 BEQ t7, zero, $0012b5e8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226216u; + } + // @0012B5A8 SLL t7, a2, 4 + MobUt.SLL(this.ee.t7, this.ee.a2, 4); + } + + public virtual void funct0012b5ac() + { + this.ee.pc = 1226216u; + // @0012B5AC LW t6, $0024(s5) + MobUt.LW(this.ee, this.ee.t6, (36u + this.ee.s5.UL0)); + // @0012B5B0 ADDU a2, t6, t7 + this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B5B4 LQC2 vf5, $0000(a2) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.a2.UL0)); + // @0012B5B8 LQC2 vf1, $0000(t4) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); + // @0012B5BC LQC2 vf2, $0010(t4) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t4.UL0)); + // @0012B5C0 LQC2 vf3, $0020(t4) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t4.UL0)); + // @0012B5C4 LQC2 vf4, $0030(t4) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t4.UL0)); + // @0012B5C8 VMULAx.xyz ACC, vf1, vf5x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); + // @0012B5CC VMADDAy.xyz ACC, vf2, vf5y + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); + // @0012B5D0 VMADDAz.xyz ACC, vf3, vf5z + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); + // @0012B5D4 VMADDw.xyz vf5, vf4, vf0w + this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); + this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); + this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); + // @0012B5D8 VMOVE.w vf5, vf0 + this.ee.VF[5].w = this.ee.VF[0].w; + // @0012B5DC SQC2 vf5, $0000(t2) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t2.UL0)); + // @0012B5E0 BEQ zero, zero, $00129e60 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220192u; + } + // @0012B5E4 LW t3, $01f4(sp) + MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); + } + + public virtual void funct0012b5b4() + { + this.ee.pc = 1226216u; + // @0012B5B4 LQC2 vf5, $0000(a2) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.a2.UL0)); + // @0012B5B8 LQC2 vf1, $0000(t4) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); + // @0012B5BC LQC2 vf2, $0010(t4) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t4.UL0)); + // @0012B5C0 LQC2 vf3, $0020(t4) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t4.UL0)); + // @0012B5C4 LQC2 vf4, $0030(t4) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t4.UL0)); + // @0012B5C8 VMULAx.xyz ACC, vf1, vf5x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); + // @0012B5CC VMADDAy.xyz ACC, vf2, vf5y + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); + // @0012B5D0 VMADDAz.xyz ACC, vf3, vf5z + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); + // @0012B5D4 VMADDw.xyz vf5, vf4, vf0w + this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); + this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); + this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); + // @0012B5D8 VMOVE.w vf5, vf0 + this.ee.VF[5].w = this.ee.VF[0].w; + // @0012B5DC SQC2 vf5, $0000(t2) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t2.UL0)); + // @0012B5E0 BEQ zero, zero, $00129e60 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220192u; + } + // @0012B5E4 LW t3, $01f4(sp) + MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); + } + + public virtual void funct0012b5e8() + { + this.ee.pc = 1226244u; + // @0012B5E8 LW t6, $0018(t3) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t3.UL0)); + // @0012B5EC SUBU t7, a2, t5 + this.ee.t7.SD0 = ((int)((this.ee.a2.UD0 - this.ee.t5.UD0))); + // @0012B5F0 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B5F4 ADDU t6, t3, t6 + this.ee.t6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t6.SD0))); + // @0012B5F8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B5FC BEQ zero, zero, $0012b5b4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226164u; + } + // @0012B600 ADDIU a2, t6, $0030 + this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012b604() + { + this.ee.pc = 1226256u; + // @0012B604 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012B608 BEQ zero, zero, $0012b594 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226132u; + } + // @0012B60C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012b610() + { + this.ee.pc = 1226272u; + // @0012B610 SUBU t7, t5, t6 + this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.t6.UD0))); + // @0012B614 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012B618 BEQ zero, zero, $0012b574 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226100u; + } + // @0012B61C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012b620() + { + this.ee.pc = 1226284u; + // @0012B620 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012B624 BEQ zero, zero, $0012b518 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226008u; + } + // @0012B628 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012b62c() + { + this.ee.pc = 1226304u; + // @0012B62C SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012B630 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012B634 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B638 BEQ zero, zero, $0012b500 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225984u; + } + // @0012B63C ADDU v0, t6, t7 + this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012b640() + { + this.ee.pc = 1226316u; + // @0012B640 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012B644 BEQ zero, zero, $0012b4e4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225956u; + } + // @0012B648 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012b64c() + { + this.ee.pc = 1226328u; + // @0012B64C LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012B650 BEQ zero, zero, $0012b490 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225872u; + } + // @0012B654 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012b658() + { + this.ee.pc = 1226340u; + // @0012B658 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012B65C BEQ zero, zero, $0012b43c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225788u; + } + // @0012B660 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012b664() + { + this.ee.pc = 1226356u; + // @0012B664 SUBU t7, s7, t3 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t3.UD0))); + // @0012B668 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012B66C BEQ zero, zero, $0012b37c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225596u; + } + // @0012B670 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012b674() + { + this.ee.pc = 1226380u; + // @0012B674 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + // @0012B678 SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012B67C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B680 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012B684 BEQ zero, zero, $0012b350 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225552u; + } + // @0012B688 ADDU v0, t6, t7 + this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012b68c() + { + this.ee.pc = 1226392u; + // @0012B68C LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012B690 BEQ zero, zero, $0012b324 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225508u; + } + // @0012B694 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012b698() + { + this.ee.pc = 1226408u; + // @0012B698 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012B69C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B6A0 BEQ zero, zero, $0012b2f0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225456u; + } + // @0012B6A4 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012b6a8() + { + this.ee.pc = 1226424u; + // @0012B6A8 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012B6AC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B6B0 BEQ zero, zero, $0012b2a4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225380u; + } + // @0012B6B4 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012b6b8() + { + this.ee.pc = 1226440u; + // @0012B6B8 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012B6BC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B6C0 BEQ zero, zero, $0012b258 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225304u; + } + // @0012B6C4 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012b6c8() + { + this.ee.pc = 1226460u; + // @0012B6C8 SUBU t7, s2, t4 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); + // @0012B6CC LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012B6D0 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B6D4 BEQ zero, zero, $0012b1a0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225120u; + } + // @0012B6D8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012b6dc() + { + this.ee.pc = 1226476u; + // @0012B6DC LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012B6E0 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B6E4 BEQ zero, zero, $0012b170 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1225072u; + } + // @0012B6E8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012b7a8() + { + this.ee.pc = 1226692u; + // @0012B7A8 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B7AC LW t3, $0014(s0) + MobUt.LW(this.ee, this.ee.t3, (20u + this.ee.s0.UL0)); + // @0012B7B0 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012B7B4 ADDU t6, t3, s8 + this.ee.t6.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); + // @0012B7B8 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012B7BC BEQ t7, zero, $0012b930 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227056u; + } + // @0012B7C0 SW t6, $0244(sp) + MobUt.SW(this.ee, this.ee.t6, (580u + this.ee.sp.UL0)); + } + + public virtual void funct0012b7c4() + { + this.ee.pc = 1226712u; + // @0012B7C4 LW a0, $0014(s5) + MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); + // @0012B7C8 LW t7, $0000(a0) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); + // @0012B7CC LW v0, $0020(t7) + MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); + // @0012B7D0 JALR ra, v0 + this.ee.ra.UD0 = 1226712u; + this.ee.pc = this.ee.v0.UL0; + // @0012B7D4 SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + } + + public virtual void funct0012b7d8() + { + this.ee.pc = 1226764u; + // @0012B7D8 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B7DC ADDU v0, v0, s3 + this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.s3.SD0))); + // @0012B7E0 LW t3, $0014(s0) + MobUt.LW(this.ee, this.ee.t3, (20u + this.ee.s0.UL0)); + // @0012B7E4 LW t7, $0244(sp) + MobUt.LW(this.ee, this.ee.t7, (580u + this.ee.sp.UL0)); + // @0012B7E8 LWC1 $f0, $001c(v0) + MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); + // @0012B7EC LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @0012B7F0 ADDU t7, t3, s8 + this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); + // @0012B7F4 ADDIU t7, t7, $0010 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16))); + // @0012B7F8 SW t7, $0248(sp) + MobUt.SW(this.ee, this.ee.t7, (584u + this.ee.sp.UL0)); + // @0012B7FC LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012B800 SLT t7, s7, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t5.SD0)); + // @0012B804 BEQ t7, zero, $0012b918 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227032u; + } + // @0012B808 MUL.S $f20, $f1, $f0 + this.ee.fpr[20].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct0012b7e4() + { + this.ee.pc = 1226764u; + // @0012B7E4 LW t7, $0244(sp) + MobUt.LW(this.ee, this.ee.t7, (580u + this.ee.sp.UL0)); + // @0012B7E8 LWC1 $f0, $001c(v0) + MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); + // @0012B7EC LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @0012B7F0 ADDU t7, t3, s8 + this.ee.t7.SD0 = ((int)((this.ee.t3.SD0 + this.ee.s8.SD0))); + // @0012B7F4 ADDIU t7, t7, $0010 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 16))); + // @0012B7F8 SW t7, $0248(sp) + MobUt.SW(this.ee, this.ee.t7, (584u + this.ee.sp.UL0)); + // @0012B7FC LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012B800 SLT t7, s7, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t5.SD0)); + // @0012B804 BEQ t7, zero, $0012b918 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227032u; + } + // @0012B808 MUL.S $f20, $f1, $f0 + this.ee.fpr[20].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct0012b80c() + { + this.ee.pc = 1226784u; + // @0012B80C LW a0, $0014(s5) + MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); + // @0012B810 LW t7, $0000(a0) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); + // @0012B814 LW v0, $0020(t7) + MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); + // @0012B818 JALR ra, v0 + this.ee.ra.UD0 = 1226784u; + this.ee.pc = this.ee.v0.UL0; + // @0012B81C NOP + MobUt.Latency(); + } + + public virtual void funct0012b820() + { + this.ee.pc = 1226824u; + // @0012B820 SLL t7, s7, 6 + MobUt.SLL(this.ee.t7, this.ee.s7, 6); + // @0012B824 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012B828 ADDU v0, v0, t7 + this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.t7.SD0))); + // @0012B82C LW t3, $0248(sp) + MobUt.LW(this.ee, this.ee.t3, (584u + this.ee.sp.UL0)); + // @0012B830 LWC1 $f0, $001c(v0) + MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); + // @0012B834 LWC1 $f1, $0000(t3) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t3.UL0)); + // @0012B838 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B83C SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012B840 BEQ t7, zero, $0012b904 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227012u; + } + // @0012B844 MUL.S $f13, $f1, $f0 + this.ee.fpr[13].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct0012b82c() + { + this.ee.pc = 1226824u; + // @0012B82C LW t3, $0248(sp) + MobUt.LW(this.ee, this.ee.t3, (584u + this.ee.sp.UL0)); + // @0012B830 LWC1 $f0, $001c(v0) + MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); + // @0012B834 LWC1 $f1, $0000(t3) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t3.UL0)); + // @0012B838 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B83C SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012B840 BEQ t7, zero, $0012b904 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227012u; + } + // @0012B844 MUL.S $f13, $f1, $f0 + this.ee.fpr[13].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct0012b848() + { + this.ee.pc = 1226848u; + // @0012B848 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012B84C ADDU a3, t7, s3 + this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012B850 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B854 SLT t7, s7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); + // @0012B858 BEQ t7, zero, $0012b8f8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227000u; + } + // @0012B85C SUBU t7, s7, t6 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b850() + { + this.ee.pc = 1226848u; + // @0012B850 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012B854 SLT t7, s7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t6.SD0)); + // @0012B858 BEQ t7, zero, $0012b8f8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227000u; + } + // @0012B85C SUBU t7, s7, t6 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012b860() + { + this.ee.pc = 1226876u; + // @0012B860 LW t6, $0028(s5) + MobUt.LW(this.ee, this.ee.t6, (40u + this.ee.s5.UL0)); + // @0012B864 SLL t7, s7, 6 + MobUt.SLL(this.ee.t7, this.ee.s7, 6); + // @0012B868 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012B86C ADDU t0, t6, t7 + this.ee.t0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B870 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012B874 BEQL t7, zero, $0012b8e0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226976u; + // @0012B878 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012b868() + { + this.ee.pc = 1226876u; + // @0012B868 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012B86C ADDU t0, t6, t7 + this.ee.t0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B870 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012B874 BEQL t7, zero, $0012b8e0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226976u; + // @0012B878 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012b87c() + { + this.ee.pc = 1226900u; + // @0012B87C LW t7, $0020(s5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); + // @0012B880 ADDU t3, t7, s8 + this.ee.t3.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012B884 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012B888 SLT t7, s7, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t5.SD0)); + // @0012B88C BEQ t7, zero, $0012b8c4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226948u; + } + // @0012B890 SLL t7, s7, 4 + MobUt.SLL(this.ee.t7, this.ee.s7, 4); + } + + public virtual void funct0012b884() + { + this.ee.pc = 1226900u; + // @0012B884 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012B888 SLT t7, s7, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s7.SD0 < this.ee.t5.SD0)); + // @0012B88C BEQ t7, zero, $0012b8c4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226948u; + } + // @0012B890 SLL t7, s7, 4 + MobUt.SLL(this.ee.t7, this.ee.s7, 4); + } + + public virtual void funct0012b894() + { + this.ee.pc = 1226948u; + // @0012B894 LW t6, $0020(s5) + MobUt.LW(this.ee, this.ee.t6, (32u + this.ee.s5.UL0)); + // @0012B898 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B89C LW t4, $024c(sp) + MobUt.LW(this.ee, this.ee.t4, (588u + this.ee.sp.UL0)); + // @0012B8A0 MOV.S $f12, $f20 + this.ee.fpr[12].f = this.ee.fpr[20].f; + // @0012B8A4 LWC1 $f14, $0000(t3) + MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t3.UL0)); + // @0012B8A8 ADDIU a0, sp, $00a0 + this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); + // @0012B8AC ANDI a2, t4, $0003 + this.ee.a2.UD0 = ((ushort)((this.ee.t4.US0 & 3))); + // @0012B8B0 LWC1 $f15, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[15], (0u + this.ee.t6.UL0)); + // @0012B8B4 ADDIU a2, a2, $fffe + this.ee.a2.SD0 = ((int)((this.ee.a2.SD0 + -2))); + // @0012B8B8 ADDIU a1, sp, $00b0 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); + // @0012B8BC BEQ zero, zero, $0012b100 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1224960u; + } + // @0012B8C0 DADDU t1, zero, zero + this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012b89c() + { + this.ee.pc = 1226948u; + // @0012B89C LW t4, $024c(sp) + MobUt.LW(this.ee, this.ee.t4, (588u + this.ee.sp.UL0)); + // @0012B8A0 MOV.S $f12, $f20 + this.ee.fpr[12].f = this.ee.fpr[20].f; + // @0012B8A4 LWC1 $f14, $0000(t3) + MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t3.UL0)); + // @0012B8A8 ADDIU a0, sp, $00a0 + this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); + // @0012B8AC ANDI a2, t4, $0003 + this.ee.a2.UD0 = ((ushort)((this.ee.t4.US0 & 3))); + // @0012B8B0 LWC1 $f15, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[15], (0u + this.ee.t6.UL0)); + // @0012B8B4 ADDIU a2, a2, $fffe + this.ee.a2.SD0 = ((int)((this.ee.a2.SD0 + -2))); + // @0012B8B8 ADDIU a1, sp, $00b0 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); + // @0012B8BC BEQ zero, zero, $0012b100 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1224960u; + } + // @0012B8C0 DADDU t1, zero, zero + this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012b8c4() + { + this.ee.pc = 1226976u; + // @0012B8C4 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + // @0012B8C8 SUBU t7, s7, t5 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t5.UD0))); + // @0012B8CC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B8D0 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012B8D4 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B8D8 BEQ zero, zero, $0012b89c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226908u; + } + // @0012B8DC ADDIU t6, t6, $0020 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); + } + + public virtual void funct0012b8e0() + { + this.ee.pc = 1227000u; + // @0012B8E0 SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012B8E4 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B8E8 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012B8EC ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B8F0 BEQ zero, zero, $0012b884 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226884u; + } + // @0012B8F4 ADDIU t3, t6, $0020 + this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + 32))); + } + + public virtual void funct0012b8f8() + { + this.ee.pc = 1227012u; + // @0012B8F8 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012B8FC BEQ zero, zero, $0012b868 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226856u; + } + // @0012B900 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012b904() + { + this.ee.pc = 1227032u; + // @0012B904 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + // @0012B908 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012B90C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B910 BEQ zero, zero, $0012b850 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226832u; + } + // @0012B914 ADDU a3, t6, t7 + this.ee.a3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012b918() + { + this.ee.pc = 1227056u; + // @0012B918 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + // @0012B91C SUBU t7, s7, t5 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t5.UD0))); + // @0012B920 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B924 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012B928 BEQ zero, zero, $0012b82c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226796u; + } + // @0012B92C ADDU v0, t6, t7 + this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012b930() + { + this.ee.pc = 1227084u; + // @0012B930 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + // @0012B934 SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012B938 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B93C SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + // @0012B940 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012B944 BEQ zero, zero, $0012b7e4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1226724u; + } + // @0012B948 ADDU v0, t6, t7 + this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012b97c() + { + this.ee.pc = 1227148u; + // @0012B97C LW t6, $0000(a0) + MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.a0.UL0)); + // @0012B980 LW t7, $0014(t6) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.t6.UL0)); + // @0012B984 JALR ra, t7 + this.ee.ra.UD0 = 1227148u; + this.ee.pc = this.ee.t7.UL0; + // @0012B988 ADDIU a1, s3, $ffe0 + this.ee.a1.SD0 = ((int)((this.ee.s3.SD0 + -32))); + } + + public virtual void funct0012b98c() + { + this.ee.pc = 1227156u; + // @0012B98C BEQ zero, zero, $0012acb8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223864u; + } + // @0012B990 MOV.S $f20, $f0 + this.ee.fpr[20].f = this.ee.fpr[0].f; + } + + public virtual void funct0012b998() + { + this.ee.pc = 1227184u; + // @0012B998 ADDIU t7, t7, $0020 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 32))); + // @0012B99C SW t7, $0224(sp) + MobUt.SW(this.ee, this.ee.t7, (548u + this.ee.sp.UL0)); + // @0012B9A0 LD t5, $0010(t7) + MobUt.LD(this.ee, this.ee.t5, (16u + this.ee.t7.UL0)); + // @0012B9A4 AND t7, t5, t4 + this.ee.t7.UD0 = (this.ee.t5.UD0 & this.ee.t4.UD0); + // @0012B9A8 BEQL t7, zero, $0012ac68 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223784u; + // @0012B9AC LW t3, $0224(sp) + MobUt.LW(this.ee, this.ee.t3, (548u + this.ee.sp.UL0)); + } + } + + public virtual void funct0012b9b0() + { + this.ee.pc = 1227192u; + // @0012B9B0 BEQ zero, zero, $0012acd8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223896u; + } + // @0012B9B4 LW t3, $0228(sp) + MobUt.LW(this.ee, this.ee.t3, (552u + this.ee.sp.UL0)); + } + + public virtual void funct0012b9b8() + { + this.ee.pc = 1227220u; + // @0012B9B8 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + // @0012B9BC SUBU t7, s7, t2 + this.ee.t7.SD0 = ((int)((this.ee.s7.UD0 - this.ee.t2.UD0))); + // @0012B9C0 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B9C4 ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012B9C8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012B9CC BEQ zero, zero, $0012abf0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223664u; + } + // @0012B9D0 ADDIU t6, t6, $0010 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 16))); + } + + public virtual void funct0012b9d4() + { + this.ee.pc = 1227244u; + // @0012B9D4 SUBU t7, t4, t6 + this.ee.t7.SD0 = ((int)((this.ee.t4.UD0 - this.ee.t6.UD0))); + // @0012B9D8 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012B9DC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B9E0 SW t5, $0250(sp) + MobUt.SW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); + // @0012B9E4 BEQ zero, zero, $0012aa7c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223292u; + } + // @0012B9E8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012b9ec() + { + this.ee.pc = 1227272u; + // @0012B9EC LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + // @0012B9F0 SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012B9F4 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012B9F8 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012B9FC ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012BA00 BEQ zero, zero, $0012aa38 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223224u; + } + // @0012BA04 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012ba08() + { + this.ee.pc = 1227284u; + // @0012BA08 ADDIU t7, zero, $ffff + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); + // @0012BA0C BNE a2, t7, $0012ba40 + if ((this.ee.a2.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1227328u; + } + // @0012BA10 LW t4, $0214(sp) + MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); + } + + public virtual void funct0012ba14() + { + this.ee.pc = 1227292u; + // @0012BA14 BNE a3, a2, $0012ba40 + if ((this.ee.a3.UD0 != this.ee.a2.UD0)) + { + this.ee.pc = 1227328u; + } + // @0012BA18 LW t7, $0218(sp) + MobUt.LW(this.ee, this.ee.t7, (536u + this.ee.sp.UL0)); + } + + public virtual void funct0012ba1c() + { + this.ee.pc = 1227300u; + // @0012BA1C BNE t7, zero, $0012ba40 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1227328u; + } + // @0012BA20 LUI t7, $000c + this.ee.t7.SD0 = 786432; + } + + public virtual void funct0012ba24() + { + this.ee.pc = 1227312u; + // @0012BA24 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @0012BA28 BNE t7, zero, $0012ba40 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1227328u; + } + // @0012BA2C NOP + MobUt.Latency(); + } + + public virtual void funct0012ba30() + { + this.ee.pc = 1227320u; + // @0012BA30 BNE v0, zero, $0012ba40 + if ((this.ee.v0.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1227328u; + } + // @0012BA34 LW t3, $021c(sp) + MobUt.LW(this.ee, this.ee.t3, (540u + this.ee.sp.UL0)); + } + + public virtual void funct0012ba38() + { + this.ee.pc = 1227328u; + // @0012BA38 BEQ t3, zero, $0012bb34 + if ((this.ee.t3.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227572u; + } + // @0012BA3C LUI t7, $0004 + this.ee.t7.SD0 = 262144; + } + + public virtual void funct0012ba40() + { + this.ee.pc = 1227336u; + // @0012BA40 BGEZL t4, $0012ca88 + if ((this.ee.t4.SD0 >= 0)) + { + this.ee.pc = 1231496u; + // @0012BA44 LW t6, $0004(s0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012ba48() + { + this.ee.pc = 1227348u; + // @0012BA48 ADDIU a1, sp, $0040 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 64))); + // @0012BA4C BEQ a1, sp, $0012ba74 + if ((this.ee.a1.UD0 == this.ee.sp.UD0)) + { + this.ee.pc = 1227380u; + } + // @0012BA50 NOP + MobUt.Latency(); + } + + public virtual void funct0012ba54() + { + this.ee.pc = 1227584u; + // @0012BA54 LQ t0, $0000(sp) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); + // @0012BA58 LQ t1, $0010(sp) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.sp.UL[0])); + // @0012BA5C LQ t2, $0020(sp) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.sp.UL[0])); + // @0012BA60 LQ t3, $0030(sp) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.sp.UL[0])); + // @0012BA64 SQ t0, $0000(a1) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @0012BA68 SQ t1, $0010(a1) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); + // @0012BA6C SQ t2, $0020(a1) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); + // @0012BA70 SQ t3, $0030(a1) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.a1.UL[0])); + // @0012BA74 LQC2 vf1, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); + // @0012BA78 LQC2 vf2, $0010(a1) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); + // @0012BA7C LQC2 vf3, $0020(a1) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); + // @0012BA80 LQC2 vf4, $0030(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012BA84 VOPMULA.xyz ACC, vf2, vf3 + this.ee.Vacc.x = (this.ee.VF[2].y * this.ee.VF[3].z); + this.ee.Vacc.y = (this.ee.VF[2].z * this.ee.VF[3].x); + this.ee.Vacc.z = (this.ee.VF[2].x * this.ee.VF[3].y); + // @0012BA88 VOPMSUB.xyz vf5, vf3, vf2 + this.ee.VF[5].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[3].y, this.ee.VF[2].z); + this.ee.VF[5].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[3].z, this.ee.VF[2].x); + this.ee.VF[5].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[3].x, this.ee.VF[2].y); + // @0012BA8C VOPMULA.xyz ACC, vf3, vf1 + this.ee.Vacc.x = (this.ee.VF[3].y * this.ee.VF[1].z); + this.ee.Vacc.y = (this.ee.VF[3].z * this.ee.VF[1].x); + this.ee.Vacc.z = (this.ee.VF[3].x * this.ee.VF[1].y); + // @0012BA90 VOPMSUB.xyz vf6, vf1, vf3 + this.ee.VF[6].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[1].y, this.ee.VF[3].z); + this.ee.VF[6].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[1].z, this.ee.VF[3].x); + this.ee.VF[6].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[1].x, this.ee.VF[3].y); + // @0012BA94 VOPMULA.xyz ACC, vf1, vf2 + this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); + this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); + this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); + // @0012BA98 VOPMSUB.xyz vf7, vf2, vf1 + this.ee.VF[7].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); + this.ee.VF[7].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); + this.ee.VF[7].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); + // @0012BA9C VMUL.xyz vf8, vf1, vf5 + this.ee.VF[8].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[5].x); + this.ee.VF[8].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[5].y); + this.ee.VF[8].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[5].z); + // @0012BAA0 VMUL.xyz vf1, vf4, vf5 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[5].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[5].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[5].z); + // @0012BAA4 VMUL.xyz vf2, vf4, vf6 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[6].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[6].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[6].z); + // @0012BAA8 VMUL.xyz vf3, vf4, vf7 + this.ee.VF[3].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[7].x); + this.ee.VF[3].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[7].y); + this.ee.VF[3].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[7].z); + // @0012BAAC VADDy.x vf8, vf8, vf8y + this.ee.VF[8].x = (this.ee.VF[8].x + this.ee.VF[8].y); + // @0012BAB0 VADDy.x vf1, vf1, vf1y + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); + // @0012BAB4 VADDx.y vf2, vf2, vf2x + this.ee.VF[2].y = (this.ee.VF[2].y + this.ee.VF[2].x); + // @0012BAB8 VADDx.z vf3, vf3, vf3x + this.ee.VF[3].z = (this.ee.VF[3].z + this.ee.VF[3].x); + // @0012BABC VADDz.x vf8, vf8, vf8z + this.ee.VF[8].x = (this.ee.VF[8].x + this.ee.VF[8].z); + // @0012BAC0 VADDz.x vf4, vf1, vf1z + this.ee.VF[4].x = (this.ee.VF[1].x + this.ee.VF[1].z); + // @0012BAC4 VADDz.y vf4, vf2, vf2z + this.ee.VF[4].y = (this.ee.VF[2].y + this.ee.VF[2].z); + // @0012BAC8 VADDy.z vf4, vf3, vf3y + this.ee.VF[4].z = (this.ee.VF[3].z + this.ee.VF[3].y); + // @0012BACC VDIV Q, vf0w, vf8x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[8].x); + // @0012BAD0 QMFC2 t0, vf5 + MobUt.QMFC2(this.ee.t0, this.ee.VF[5]); + // @0012BAD4 QMFC2 t1, vf6 + MobUt.QMFC2(this.ee.t1, this.ee.VF[6]); + // @0012BAD8 QMFC2 t2, vf7 + MobUt.QMFC2(this.ee.t2, this.ee.VF[7]); + // @0012BADC QMFC2 t3, vf0 + MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); + // @0012BAE0 PEXTLW t4, t1, t0 + this.ee.t4.UL[0] = this.ee.t0.UL[0]; + this.ee.t4.UL[1] = this.ee.t1.UL[0]; + this.ee.t4.UL[2] = this.ee.t0.UL[1]; + this.ee.t4.UL[3] = this.ee.t1.UL[1]; + // @0012BAE4 PEXTUW t5, t1, t0 + this.ee.t5.UL[0] = this.ee.t0.UL[2]; + this.ee.t5.UL[1] = this.ee.t1.UL[2]; + this.ee.t5.UL[2] = this.ee.t0.UL[3]; + this.ee.t5.UL[3] = this.ee.t1.UL[3]; + // @0012BAE8 PEXTLW t6, t3, t2 + this.ee.t6.UL[0] = this.ee.t2.UL[0]; + this.ee.t6.UL[1] = this.ee.t3.UL[0]; + this.ee.t6.UL[2] = this.ee.t2.UL[1]; + this.ee.t6.UL[3] = this.ee.t3.UL[1]; + // @0012BAEC PEXTUW t7, t3, t2 + this.ee.t7.UL[0] = this.ee.t2.UL[2]; + this.ee.t7.UL[1] = this.ee.t3.UL[2]; + this.ee.t7.UL[2] = this.ee.t2.UL[3]; + this.ee.t7.UL[3] = this.ee.t3.UL[3]; + // @0012BAF0 PCPYLD t0, t6, t4 + this.ee.t0.UD1 = this.ee.t6.UD0; + this.ee.t0.UD0 = this.ee.t4.UD0; + // @0012BAF4 PCPYUD t1, t4, t6 + this.ee.t1.UD0 = this.ee.t4.UD1; + this.ee.t1.UD1 = this.ee.t6.UD1; + // @0012BAF8 PCPYLD t2, t7, t5 + this.ee.t2.UD1 = this.ee.t7.UD0; + this.ee.t2.UD0 = this.ee.t5.UD0; + // @0012BAFC QMTC2 t0, vf1 + MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); + // @0012BB00 QMTC2 t1, vf2 + MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); + // @0012BB04 QMTC2 t2, vf3 + MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); + // @0012BB08 VSUB.xyz vf4, vf0, vf4 + this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); + this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); + this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); + // @0012BB0C VWAITQ + MobUt.Latency(); + // @0012BB10 VMULq.xyzw vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + this.ee.VF[1].w = (this.ee.VF[1].w * this.ee.Vq.f); + // @0012BB14 VMULq.xyzw vf2, vf2, Q + this.ee.VF[2].x = (this.ee.VF[2].x * this.ee.Vq.f); + this.ee.VF[2].y = (this.ee.VF[2].y * this.ee.Vq.f); + this.ee.VF[2].z = (this.ee.VF[2].z * this.ee.Vq.f); + this.ee.VF[2].w = (this.ee.VF[2].w * this.ee.Vq.f); + // @0012BB18 VMULq.xyzw vf3, vf3, Q + this.ee.VF[3].x = (this.ee.VF[3].x * this.ee.Vq.f); + this.ee.VF[3].y = (this.ee.VF[3].y * this.ee.Vq.f); + this.ee.VF[3].z = (this.ee.VF[3].z * this.ee.Vq.f); + this.ee.VF[3].w = (this.ee.VF[3].w * this.ee.Vq.f); + // @0012BB1C VMULq.xyz vf4, vf4, Q + this.ee.VF[4].x = (this.ee.VF[4].x * this.ee.Vq.f); + this.ee.VF[4].y = (this.ee.VF[4].y * this.ee.Vq.f); + this.ee.VF[4].z = (this.ee.VF[4].z * this.ee.Vq.f); + // @0012BB20 SQC2 vf1, $0000(a1) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); + // @0012BB24 SQC2 vf2, $0010(a1) + MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); + // @0012BB28 SQC2 vf3, $0020(a1) + MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); + // @0012BB2C SQC2 vf4, $0030(a1) + MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012BB30 LUI t7, $0004 + this.ee.t7.SD0 = 262144; + // @0012BB34 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @0012BB38 BEQ t7, zero, $0012c738 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230648u; + } + // @0012BB3C ADDIU t7, zero, $ffff + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); + } + + public virtual void funct0012ba74() + { + this.ee.pc = 1227584u; + // @0012BA74 LQC2 vf1, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); + // @0012BA78 LQC2 vf2, $0010(a1) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); + // @0012BA7C LQC2 vf3, $0020(a1) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); + // @0012BA80 LQC2 vf4, $0030(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012BA84 VOPMULA.xyz ACC, vf2, vf3 + this.ee.Vacc.x = (this.ee.VF[2].y * this.ee.VF[3].z); + this.ee.Vacc.y = (this.ee.VF[2].z * this.ee.VF[3].x); + this.ee.Vacc.z = (this.ee.VF[2].x * this.ee.VF[3].y); + // @0012BA88 VOPMSUB.xyz vf5, vf3, vf2 + this.ee.VF[5].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[3].y, this.ee.VF[2].z); + this.ee.VF[5].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[3].z, this.ee.VF[2].x); + this.ee.VF[5].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[3].x, this.ee.VF[2].y); + // @0012BA8C VOPMULA.xyz ACC, vf3, vf1 + this.ee.Vacc.x = (this.ee.VF[3].y * this.ee.VF[1].z); + this.ee.Vacc.y = (this.ee.VF[3].z * this.ee.VF[1].x); + this.ee.Vacc.z = (this.ee.VF[3].x * this.ee.VF[1].y); + // @0012BA90 VOPMSUB.xyz vf6, vf1, vf3 + this.ee.VF[6].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[1].y, this.ee.VF[3].z); + this.ee.VF[6].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[1].z, this.ee.VF[3].x); + this.ee.VF[6].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[1].x, this.ee.VF[3].y); + // @0012BA94 VOPMULA.xyz ACC, vf1, vf2 + this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); + this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); + this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); + // @0012BA98 VOPMSUB.xyz vf7, vf2, vf1 + this.ee.VF[7].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); + this.ee.VF[7].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); + this.ee.VF[7].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); + // @0012BA9C VMUL.xyz vf8, vf1, vf5 + this.ee.VF[8].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[5].x); + this.ee.VF[8].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[5].y); + this.ee.VF[8].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[5].z); + // @0012BAA0 VMUL.xyz vf1, vf4, vf5 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[5].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[5].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[5].z); + // @0012BAA4 VMUL.xyz vf2, vf4, vf6 + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[6].x); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[6].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[6].z); + // @0012BAA8 VMUL.xyz vf3, vf4, vf7 + this.ee.VF[3].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[7].x); + this.ee.VF[3].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[7].y); + this.ee.VF[3].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[7].z); + // @0012BAAC VADDy.x vf8, vf8, vf8y + this.ee.VF[8].x = (this.ee.VF[8].x + this.ee.VF[8].y); + // @0012BAB0 VADDy.x vf1, vf1, vf1y + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); + // @0012BAB4 VADDx.y vf2, vf2, vf2x + this.ee.VF[2].y = (this.ee.VF[2].y + this.ee.VF[2].x); + // @0012BAB8 VADDx.z vf3, vf3, vf3x + this.ee.VF[3].z = (this.ee.VF[3].z + this.ee.VF[3].x); + // @0012BABC VADDz.x vf8, vf8, vf8z + this.ee.VF[8].x = (this.ee.VF[8].x + this.ee.VF[8].z); + // @0012BAC0 VADDz.x vf4, vf1, vf1z + this.ee.VF[4].x = (this.ee.VF[1].x + this.ee.VF[1].z); + // @0012BAC4 VADDz.y vf4, vf2, vf2z + this.ee.VF[4].y = (this.ee.VF[2].y + this.ee.VF[2].z); + // @0012BAC8 VADDy.z vf4, vf3, vf3y + this.ee.VF[4].z = (this.ee.VF[3].z + this.ee.VF[3].y); + // @0012BACC VDIV Q, vf0w, vf8x + this.ee.Vq.f = (this.ee.VF[0].w / this.ee.VF[8].x); + // @0012BAD0 QMFC2 t0, vf5 + MobUt.QMFC2(this.ee.t0, this.ee.VF[5]); + // @0012BAD4 QMFC2 t1, vf6 + MobUt.QMFC2(this.ee.t1, this.ee.VF[6]); + // @0012BAD8 QMFC2 t2, vf7 + MobUt.QMFC2(this.ee.t2, this.ee.VF[7]); + // @0012BADC QMFC2 t3, vf0 + MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); + // @0012BAE0 PEXTLW t4, t1, t0 + this.ee.t4.UL[0] = this.ee.t0.UL[0]; + this.ee.t4.UL[1] = this.ee.t1.UL[0]; + this.ee.t4.UL[2] = this.ee.t0.UL[1]; + this.ee.t4.UL[3] = this.ee.t1.UL[1]; + // @0012BAE4 PEXTUW t5, t1, t0 + this.ee.t5.UL[0] = this.ee.t0.UL[2]; + this.ee.t5.UL[1] = this.ee.t1.UL[2]; + this.ee.t5.UL[2] = this.ee.t0.UL[3]; + this.ee.t5.UL[3] = this.ee.t1.UL[3]; + // @0012BAE8 PEXTLW t6, t3, t2 + this.ee.t6.UL[0] = this.ee.t2.UL[0]; + this.ee.t6.UL[1] = this.ee.t3.UL[0]; + this.ee.t6.UL[2] = this.ee.t2.UL[1]; + this.ee.t6.UL[3] = this.ee.t3.UL[1]; + // @0012BAEC PEXTUW t7, t3, t2 + this.ee.t7.UL[0] = this.ee.t2.UL[2]; + this.ee.t7.UL[1] = this.ee.t3.UL[2]; + this.ee.t7.UL[2] = this.ee.t2.UL[3]; + this.ee.t7.UL[3] = this.ee.t3.UL[3]; + // @0012BAF0 PCPYLD t0, t6, t4 + this.ee.t0.UD1 = this.ee.t6.UD0; + this.ee.t0.UD0 = this.ee.t4.UD0; + // @0012BAF4 PCPYUD t1, t4, t6 + this.ee.t1.UD0 = this.ee.t4.UD1; + this.ee.t1.UD1 = this.ee.t6.UD1; + // @0012BAF8 PCPYLD t2, t7, t5 + this.ee.t2.UD1 = this.ee.t7.UD0; + this.ee.t2.UD0 = this.ee.t5.UD0; + // @0012BAFC QMTC2 t0, vf1 + MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); + // @0012BB00 QMTC2 t1, vf2 + MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); + // @0012BB04 QMTC2 t2, vf3 + MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); + // @0012BB08 VSUB.xyz vf4, vf0, vf4 + this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); + this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); + this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); + // @0012BB0C VWAITQ + MobUt.Latency(); + // @0012BB10 VMULq.xyzw vf1, vf1, Q + this.ee.VF[1].x = (this.ee.VF[1].x * this.ee.Vq.f); + this.ee.VF[1].y = (this.ee.VF[1].y * this.ee.Vq.f); + this.ee.VF[1].z = (this.ee.VF[1].z * this.ee.Vq.f); + this.ee.VF[1].w = (this.ee.VF[1].w * this.ee.Vq.f); + // @0012BB14 VMULq.xyzw vf2, vf2, Q + this.ee.VF[2].x = (this.ee.VF[2].x * this.ee.Vq.f); + this.ee.VF[2].y = (this.ee.VF[2].y * this.ee.Vq.f); + this.ee.VF[2].z = (this.ee.VF[2].z * this.ee.Vq.f); + this.ee.VF[2].w = (this.ee.VF[2].w * this.ee.Vq.f); + // @0012BB18 VMULq.xyzw vf3, vf3, Q + this.ee.VF[3].x = (this.ee.VF[3].x * this.ee.Vq.f); + this.ee.VF[3].y = (this.ee.VF[3].y * this.ee.Vq.f); + this.ee.VF[3].z = (this.ee.VF[3].z * this.ee.Vq.f); + this.ee.VF[3].w = (this.ee.VF[3].w * this.ee.Vq.f); + // @0012BB1C VMULq.xyz vf4, vf4, Q + this.ee.VF[4].x = (this.ee.VF[4].x * this.ee.Vq.f); + this.ee.VF[4].y = (this.ee.VF[4].y * this.ee.Vq.f); + this.ee.VF[4].z = (this.ee.VF[4].z * this.ee.Vq.f); + // @0012BB20 SQC2 vf1, $0000(a1) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); + // @0012BB24 SQC2 vf2, $0010(a1) + MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); + // @0012BB28 SQC2 vf3, $0020(a1) + MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); + // @0012BB2C SQC2 vf4, $0030(a1) + MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012BB30 LUI t7, $0004 + this.ee.t7.SD0 = 262144; + // @0012BB34 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @0012BB38 BEQ t7, zero, $0012c738 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230648u; + } + // @0012BB3C ADDIU t7, zero, $ffff + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); + } + + public virtual void funct0012bb34() + { + this.ee.pc = 1227584u; + // @0012BB34 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @0012BB38 BEQ t7, zero, $0012c738 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230648u; + } + // @0012BB3C ADDIU t7, zero, $ffff + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); + } + + public virtual void funct0012bb40() + { + this.ee.pc = 1227604u; + // @0012BB40 LW t6, $0004(s0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); + // @0012BB44 LHU t6, $0010(t6) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); + // @0012BB48 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012BB4C BEQ t7, zero, $0012c720 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230624u; + } + // @0012BB50 ADDIU t5, sp, $0080 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); + } + + public virtual void funct0012bb54() + { + this.ee.pc = 1227628u; + // @0012BB54 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012BB58 SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + // @0012BB5C ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012BB60 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012BB64 BEQL t5, t6, $0012bb78 + if ((this.ee.t5.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1227640u; + // @0012BB68 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + } + } + + public virtual void funct0012bb60() + { + this.ee.pc = 1227628u; + // @0012BB60 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012BB64 BEQL t5, t6, $0012bb78 + if ((this.ee.t5.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1227640u; + // @0012BB68 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + } + } + + public virtual void funct0012bb6c() + { + this.ee.pc = 1227712u; + // @0012BB6C LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012BB70 SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012BB74 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @0012BB78 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012BB7C ADDIU t6, t6, $8364 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -31900))); + // @0012BB80 ADDIU t4, sp, $0090 + this.ee.t4.SD0 = ((int)((this.ee.sp.SD0 + 144))); + // @0012BB84 LWC1 $f0, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @0012BB88 ADDIU t7, sp, $0040 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); + // @0012BB8C SWC1 $f0, $008c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (140u + this.ee.sp.UL0)); + // @0012BB90 LQC2 vf5, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); + // @0012BB94 LQC2 vf1, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t7.UL0)); + // @0012BB98 LQC2 vf2, $0010(t7) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t7.UL0)); + // @0012BB9C LQC2 vf3, $0020(t7) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t7.UL0)); + // @0012BBA0 LQC2 vf4, $0030(t7) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t7.UL0)); + // @0012BBA4 VMULAx.xyzw ACC, vf1, vf5x + // @0012BBA8 VMADDAy.xyzw ACC, vf2, vf5y + // @0012BBAC VMADDAz.xyzw ACC, vf3, vf5z + // @0012BBB0 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012BBB4 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012BBB8 BEQL t4, t8, $0012bbcc + if ((this.ee.t4.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1227724u; + // @0012BBBC SWC1 $f0, $009c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); + } + } + + public virtual void funct0012bbc0() + { + this.ee.pc = 1227736u; + // @0012BBC0 LQ t0, $0000(t8) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); + // @0012BBC4 SQ t0, $0000(t4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); + // @0012BBC8 SWC1 $f0, $009c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); + // @0012BBCC LW t5, $0218(sp) + MobUt.LW(this.ee, this.ee.t5, (536u + this.ee.sp.UL0)); + // @0012BBD0 BEQ t5, zero, $0012c3e4 + if ((this.ee.t5.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229796u; + } + // @0012BBD4 ADDIU t7, zero, $0003 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 3))); + } + + public virtual void funct0012bbcc() + { + this.ee.pc = 1227736u; + // @0012BBCC LW t5, $0218(sp) + MobUt.LW(this.ee, this.ee.t5, (536u + this.ee.sp.UL0)); + // @0012BBD0 BEQ t5, zero, $0012c3e4 + if ((this.ee.t5.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229796u; + } + // @0012BBD4 ADDIU t7, zero, $0003 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 3))); + } + + public virtual void funct0012bbd8() + { + this.ee.pc = 1227752u; + // @0012BBD8 LBU t6, $0000(t5) + MobUt.LBU(this.ee, this.ee.t6, (0u + this.ee.t5.UL0)); + // @0012BBDC ANDI t5, t6, $00ff + this.ee.t5.UD0 = ((ushort)((this.ee.t6.US0 & 255))); + // @0012BBE0 BEQ t5, t7, $0012bf98 + if ((this.ee.t5.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1228696u; + } + // @0012BBE4 SLTI t7, t5, $0004 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < 4)); + } + + public virtual void funct0012bbe8() + { + this.ee.pc = 1227760u; + // @0012BBE8 BEQ t7, zero, $0012bf8c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228684u; + } + // @0012BBEC ADDIU t7, zero, $0002 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); + } + + public virtual void funct0012bbf0() + { + this.ee.pc = 1227768u; + // @0012BBF0 BEQ t5, t7, $0012bf48 + if ((this.ee.t5.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1228616u; + } + // @0012BBF4 LW t6, $0218(sp) + MobUt.LW(this.ee, this.ee.t6, (536u + this.ee.sp.UL0)); + } + + public virtual void funct0012bbfc() + { + this.ee.pc = 1227792u; + // @0012BBFC LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012BC00 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012BC04 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012BC08 BEQ t7, zero, $0012bf38 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228600u; + } + // @0012BC0C SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012bc10() + { + this.ee.pc = 1227812u; + // @0012BC10 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012BC14 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012BC18 ADDU t5, t5, s3 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s3.SD0))); + // @0012BC1C BEQL t6, t5, $0012bc4c + if ((this.ee.t6.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1227852u; + // @0012BC20 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012bc18() + { + this.ee.pc = 1227812u; + // @0012BC18 ADDU t5, t5, s3 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s3.SD0))); + // @0012BC1C BEQL t6, t5, $0012bc4c + if ((this.ee.t6.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1227852u; + // @0012BC20 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012bc24() + { + this.ee.pc = 1227864u; + // @0012BC24 LQ t0, $0000(t5) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012BC28 LQ t1, $0010(t5) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); + // @0012BC2C LQ t2, $0020(t5) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); + // @0012BC30 LQ t3, $0030(t5) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); + // @0012BC34 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012BC38 SQ t1, $0010(t6) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); + // @0012BC3C SQ t2, $0020(t6) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); + // @0012BC40 SQ t3, $0030(t6) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); + // @0012BC44 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012BC48 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012BC4C SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012BC50 BEQ t7, zero, $0012bf28 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228584u; + } + // @0012BC54 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012bc58() + { + this.ee.pc = 1227940u; + // @0012BC58 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012BC5C ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012BC60 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @0012BC64 ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012BC68 LQC2 vf4, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); + // @0012BC6C LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012BC70 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012BC74 LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012BC78 VMULx.xyzw vf1, vf1, vf4x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); + // @0012BC7C VMULy.xyzw vf2, vf2, vf4y + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); + this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); + // @0012BC80 VMULz.xyzw vf3, vf3, vf4z + this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); + this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); + // @0012BC84 SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012BC88 SQC2 vf2, $0010(t6) + MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012BC8C SQC2 vf3, $0020(t6) + MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012BC90 LW t6, $0004(s0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); + // @0012BC94 LHU t6, $0010(t6) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); + // @0012BC98 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012BC9C BEQ t7, zero, $0012bf18 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228568u; + } + // @0012BCA0 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012bc60() + { + this.ee.pc = 1227940u; + // @0012BC60 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @0012BC64 ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012BC68 LQC2 vf4, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); + // @0012BC6C LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012BC70 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012BC74 LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012BC78 VMULx.xyzw vf1, vf1, vf4x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); + // @0012BC7C VMULy.xyzw vf2, vf2, vf4y + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); + this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); + // @0012BC80 VMULz.xyzw vf3, vf3, vf4z + this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); + this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); + // @0012BC84 SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012BC88 SQC2 vf2, $0010(t6) + MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012BC8C SQC2 vf3, $0020(t6) + MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012BC90 LW t6, $0004(s0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); + // @0012BC94 LHU t6, $0010(t6) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); + // @0012BC98 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012BC9C BEQ t7, zero, $0012bf18 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228568u; + } + // @0012BCA0 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012bca4() + { + this.ee.pc = 1227964u; + // @0012BCA4 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012BCA8 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012BCAC ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012BCB0 ADDIU t7, sp, $0080 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012BCB4 BEQ t6, t7, $0012bcc8 + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1227976u; + } + // @0012BCB8 LW t3, $0218(sp) + MobUt.LW(this.ee, this.ee.t3, (536u + this.ee.sp.UL0)); + } + + public virtual void funct0012bcac() + { + this.ee.pc = 1227964u; + // @0012BCAC ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012BCB0 ADDIU t7, sp, $0080 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012BCB4 BEQ t6, t7, $0012bcc8 + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1227976u; + } + // @0012BCB8 LW t3, $0218(sp) + MobUt.LW(this.ee, this.ee.t3, (536u + this.ee.sp.UL0)); + } + + public virtual void funct0012bcbc() + { + this.ee.pc = 1227984u; + // @0012BCBC LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012BCC0 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012BCC4 LW t3, $0218(sp) + MobUt.LW(this.ee, this.ee.t3, (536u + this.ee.sp.UL0)); + // @0012BCC8 BNE t3, zero, $0012bce0 + if ((this.ee.t3.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1228000u; + } + // @0012BCCC LW t4, $0214(sp) + MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); + } + + public virtual void funct0012bcd0() + { + this.ee.pc = 1228000u; + // @0012BCD0 LUI t7, $0008 + this.ee.t7.SD0 = 524288; + // @0012BCD4 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @0012BCD8 BEQ t7, zero, $00129e60 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220192u; + } + // @0012BCDC LW t3, $01f4(sp) + MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); + } + + public virtual void funct0012bce0() + { + this.ee.pc = 1228008u; + // @0012BCE0 BGEZ t4, $0012bed8 + if ((this.ee.t4.SD0 >= 0)) + { + this.ee.pc = 1228504u; + } + // @0012BCE4 LW t5, $0214(sp) + MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); + } + + public virtual void funct0012bce8() + { + this.ee.pc = 1228020u; + // @0012BCE8 ADDIU a1, sp, $0040 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 64))); + // @0012BCEC BEQ a1, sp, $0012bd14 + if ((this.ee.a1.UD0 == this.ee.sp.UD0)) + { + this.ee.pc = 1228052u; + } + // @0012BCF0 NOP + MobUt.Latency(); + } + + public virtual void funct0012bcf4() + { + this.ee.pc = 1228164u; + // @0012BCF4 LQ t0, $0000(sp) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); + // @0012BCF8 LQ t1, $0010(sp) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.sp.UL[0])); + // @0012BCFC LQ t2, $0020(sp) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.sp.UL[0])); + // @0012BD00 LQ t3, $0030(sp) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.sp.UL[0])); + // @0012BD04 SQ t0, $0000(a1) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @0012BD08 SQ t1, $0010(a1) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); + // @0012BD0C SQ t2, $0020(a1) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); + // @0012BD10 SQ t3, $0030(a1) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.a1.UL[0])); + // @0012BD14 LQ t0, $0000(a1) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @0012BD18 LQ t1, $0010(a1) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); + // @0012BD1C LQ t2, $0020(a1) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); + // @0012BD20 QMFC2 t3, vf0 + MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); + // @0012BD24 LQC2 vf4, $0030(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012BD28 PEXTLW t4, t1, t0 + this.ee.t4.UL[0] = this.ee.t0.UL[0]; + this.ee.t4.UL[1] = this.ee.t1.UL[0]; + this.ee.t4.UL[2] = this.ee.t0.UL[1]; + this.ee.t4.UL[3] = this.ee.t1.UL[1]; + // @0012BD2C PEXTUW t5, t1, t0 + this.ee.t5.UL[0] = this.ee.t0.UL[2]; + this.ee.t5.UL[1] = this.ee.t1.UL[2]; + this.ee.t5.UL[2] = this.ee.t0.UL[3]; + this.ee.t5.UL[3] = this.ee.t1.UL[3]; + // @0012BD30 PEXTLW t6, t3, t2 + this.ee.t6.UL[0] = this.ee.t2.UL[0]; + this.ee.t6.UL[1] = this.ee.t3.UL[0]; + this.ee.t6.UL[2] = this.ee.t2.UL[1]; + this.ee.t6.UL[3] = this.ee.t3.UL[1]; + // @0012BD34 PEXTUW t7, t3, t2 + this.ee.t7.UL[0] = this.ee.t2.UL[2]; + this.ee.t7.UL[1] = this.ee.t3.UL[2]; + this.ee.t7.UL[2] = this.ee.t2.UL[3]; + this.ee.t7.UL[3] = this.ee.t3.UL[3]; + // @0012BD38 PCPYLD t0, t6, t4 + this.ee.t0.UD1 = this.ee.t6.UD0; + this.ee.t0.UD0 = this.ee.t4.UD0; + // @0012BD3C PCPYUD t1, t4, t6 + this.ee.t1.UD0 = this.ee.t4.UD1; + this.ee.t1.UD1 = this.ee.t6.UD1; + // @0012BD40 PCPYLD t2, t7, t5 + this.ee.t2.UD1 = this.ee.t7.UD0; + this.ee.t2.UD0 = this.ee.t5.UD0; + // @0012BD44 QMTC2 t0, vf1 + MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); + // @0012BD48 QMTC2 t1, vf2 + MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); + // @0012BD4C QMTC2 t2, vf3 + MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); + // @0012BD50 VMULAx.xyz ACC, vf1, vf4x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[4].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[4].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[4].x); + // @0012BD54 VMADDAy.xyz ACC, vf2, vf4y + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[4].y); + // @0012BD58 VMADDz.xyz vf4, vf3, vf4z + this.ee.VF[4].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[4].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[4].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[4].z); + // @0012BD5C VSUB.xyz vf4, vf0, vf4 + this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); + this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); + this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); + // @0012BD60 SQ t0, $0000(a1) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @0012BD64 SQ t1, $0010(a1) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); + // @0012BD68 SQ t2, $0020(a1) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); + // @0012BD6C SQC2 vf4, $0030(a1) + MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012BD70 LW a3, $0004(s0) + MobUt.LW(this.ee, this.ee.a3, (4u + this.ee.s0.UL0)); + // @0012BD74 LHU t6, $0010(a3) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.a3.UL0)); + // @0012BD78 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012BD7C BEQ t7, zero, $0012bec8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228488u; + } + // @0012BD80 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012bd14() + { + this.ee.pc = 1228164u; + // @0012BD14 LQ t0, $0000(a1) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @0012BD18 LQ t1, $0010(a1) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); + // @0012BD1C LQ t2, $0020(a1) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); + // @0012BD20 QMFC2 t3, vf0 + MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); + // @0012BD24 LQC2 vf4, $0030(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012BD28 PEXTLW t4, t1, t0 + this.ee.t4.UL[0] = this.ee.t0.UL[0]; + this.ee.t4.UL[1] = this.ee.t1.UL[0]; + this.ee.t4.UL[2] = this.ee.t0.UL[1]; + this.ee.t4.UL[3] = this.ee.t1.UL[1]; + // @0012BD2C PEXTUW t5, t1, t0 + this.ee.t5.UL[0] = this.ee.t0.UL[2]; + this.ee.t5.UL[1] = this.ee.t1.UL[2]; + this.ee.t5.UL[2] = this.ee.t0.UL[3]; + this.ee.t5.UL[3] = this.ee.t1.UL[3]; + // @0012BD30 PEXTLW t6, t3, t2 + this.ee.t6.UL[0] = this.ee.t2.UL[0]; + this.ee.t6.UL[1] = this.ee.t3.UL[0]; + this.ee.t6.UL[2] = this.ee.t2.UL[1]; + this.ee.t6.UL[3] = this.ee.t3.UL[1]; + // @0012BD34 PEXTUW t7, t3, t2 + this.ee.t7.UL[0] = this.ee.t2.UL[2]; + this.ee.t7.UL[1] = this.ee.t3.UL[2]; + this.ee.t7.UL[2] = this.ee.t2.UL[3]; + this.ee.t7.UL[3] = this.ee.t3.UL[3]; + // @0012BD38 PCPYLD t0, t6, t4 + this.ee.t0.UD1 = this.ee.t6.UD0; + this.ee.t0.UD0 = this.ee.t4.UD0; + // @0012BD3C PCPYUD t1, t4, t6 + this.ee.t1.UD0 = this.ee.t4.UD1; + this.ee.t1.UD1 = this.ee.t6.UD1; + // @0012BD40 PCPYLD t2, t7, t5 + this.ee.t2.UD1 = this.ee.t7.UD0; + this.ee.t2.UD0 = this.ee.t5.UD0; + // @0012BD44 QMTC2 t0, vf1 + MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); + // @0012BD48 QMTC2 t1, vf2 + MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); + // @0012BD4C QMTC2 t2, vf3 + MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); + // @0012BD50 VMULAx.xyz ACC, vf1, vf4x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[4].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[4].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[4].x); + // @0012BD54 VMADDAy.xyz ACC, vf2, vf4y + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[4].y); + // @0012BD58 VMADDz.xyz vf4, vf3, vf4z + this.ee.VF[4].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[4].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[4].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[4].z); + // @0012BD5C VSUB.xyz vf4, vf0, vf4 + this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); + this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); + this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); + // @0012BD60 SQ t0, $0000(a1) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @0012BD64 SQ t1, $0010(a1) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); + // @0012BD68 SQ t2, $0020(a1) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); + // @0012BD6C SQC2 vf4, $0030(a1) + MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012BD70 LW a3, $0004(s0) + MobUt.LW(this.ee, this.ee.a3, (4u + this.ee.s0.UL0)); + // @0012BD74 LHU t6, $0010(a3) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.a3.UL0)); + // @0012BD78 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012BD7C BEQ t7, zero, $0012bec8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228488u; + } + // @0012BD80 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012bd84() + { + this.ee.pc = 1228304u; + // @0012BD84 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012BD88 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012BD8C LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + // @0012BD90 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012BD94 ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012BD98 LQC2 vf1, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); + // @0012BD9C LQC2 vf2, $0010(a1) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); + // @0012BDA0 LQC2 vf3, $0020(a1) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); + // @0012BDA4 LQC2 vf4, $0030(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012BDA8 LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012BDAC LQC2 vf6, $0010(t7) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); + // @0012BDB0 LQC2 vf7, $0020(t7) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); + // @0012BDB4 LQC2 vf8, $0030(t7) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); + // @0012BDB8 VMULAx.xyzw ACC, vf1, vf5x + // @0012BDBC VMADDAy.xyzw ACC, vf2, vf5y + // @0012BDC0 VMADDAz.xyzw ACC, vf3, vf5z + // @0012BDC4 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012BDC8 VMULAx.xyzw ACC, vf1, vf6x + // @0012BDCC VMADDAy.xyzw ACC, vf2, vf6y + // @0012BDD0 VMADDAz.xyzw ACC, vf3, vf6z + // @0012BDD4 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012BDD8 VMULAx.xyzw ACC, vf1, vf7x + // @0012BDDC VMADDAy.xyzw ACC, vf2, vf7y + // @0012BDE0 VMADDAz.xyzw ACC, vf3, vf7z + // @0012BDE4 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012BDE8 VMULAx.xyzw ACC, vf1, vf8x + // @0012BDEC VMADDAy.xyzw ACC, vf2, vf8y + // @0012BDF0 VMADDAz.xyzw ACC, vf3, vf8z + // @0012BDF4 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012BDF8 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012BDFC SQC2 vf6, $0010(t8) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); + // @0012BE00 SQC2 vf7, $0020(t8) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); + // @0012BE04 SQC2 vf8, $0030(t8) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); + // @0012BE08 BEQL t6, t8, $0012be34 + if ((this.ee.t6.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1228340u; + // @0012BE0C LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012bd8c() + { + this.ee.pc = 1228304u; + // @0012BD8C LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + // @0012BD90 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012BD94 ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012BD98 LQC2 vf1, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); + // @0012BD9C LQC2 vf2, $0010(a1) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.a1.UL0)); + // @0012BDA0 LQC2 vf3, $0020(a1) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.a1.UL0)); + // @0012BDA4 LQC2 vf4, $0030(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.a1.UL0)); + // @0012BDA8 LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012BDAC LQC2 vf6, $0010(t7) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); + // @0012BDB0 LQC2 vf7, $0020(t7) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); + // @0012BDB4 LQC2 vf8, $0030(t7) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); + // @0012BDB8 VMULAx.xyzw ACC, vf1, vf5x + // @0012BDBC VMADDAy.xyzw ACC, vf2, vf5y + // @0012BDC0 VMADDAz.xyzw ACC, vf3, vf5z + // @0012BDC4 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012BDC8 VMULAx.xyzw ACC, vf1, vf6x + // @0012BDCC VMADDAy.xyzw ACC, vf2, vf6y + // @0012BDD0 VMADDAz.xyzw ACC, vf3, vf6z + // @0012BDD4 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012BDD8 VMULAx.xyzw ACC, vf1, vf7x + // @0012BDDC VMADDAy.xyzw ACC, vf2, vf7y + // @0012BDE0 VMADDAz.xyzw ACC, vf3, vf7z + // @0012BDE4 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012BDE8 VMULAx.xyzw ACC, vf1, vf8x + // @0012BDEC VMADDAy.xyzw ACC, vf2, vf8y + // @0012BDF0 VMADDAz.xyzw ACC, vf3, vf8z + // @0012BDF4 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012BDF8 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012BDFC SQC2 vf6, $0010(t8) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); + // @0012BE00 SQC2 vf7, $0020(t8) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); + // @0012BE04 SQC2 vf8, $0030(t8) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); + // @0012BE08 BEQL t6, t8, $0012be34 + if ((this.ee.t6.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1228340u; + // @0012BE0C LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012be10() + { + this.ee.pc = 1228356u; + // @0012BE10 LQ t0, $0000(t8) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); + // @0012BE14 LQ t1, $0010(t8) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t8.UL[0])); + // @0012BE18 LQ t2, $0020(t8) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t8.UL[0])); + // @0012BE1C LQ t3, $0030(t8) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t8.UL[0])); + // @0012BE20 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012BE24 SQ t1, $0010(t6) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); + // @0012BE28 SQ t2, $0020(t6) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); + // @0012BE2C SQ t3, $0030(t6) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); + // @0012BE30 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012BE34 LHU t7, $0010(t7) + MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); + // @0012BE38 SLT t6, s2, t7 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); + // @0012BE3C BEQ t6, zero, $0012beb8 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228472u; + } + // @0012BE40 SUBU t7, s2, t7 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); + } + + public virtual void funct0012be44() + { + this.ee.pc = 1228380u; + // @0012BE44 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012BE48 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012BE4C ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012BE50 ADDIU t7, sp, $0090 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 144))); + // @0012BE54 BEQL t6, t7, $0012be68 + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1228392u; + // @0012BE58 LUI t7, $0040 + this.ee.t7.SD0 = 4194304; + } + } + + public virtual void funct0012be4c() + { + this.ee.pc = 1228380u; + // @0012BE4C ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012BE50 ADDIU t7, sp, $0090 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 144))); + // @0012BE54 BEQL t6, t7, $0012be68 + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1228392u; + // @0012BE58 LUI t7, $0040 + this.ee.t7.SD0 = 4194304; + } + } + + public virtual void funct0012be5c() + { + this.ee.pc = 1228404u; + // @0012BE5C LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012BE60 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012BE64 LUI t7, $0040 + this.ee.t7.SD0 = 4194304; + // @0012BE68 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @0012BE6C BEQ t7, zero, $00129e60 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220192u; + } + // @0012BE70 LW t3, $01f4(sp) + MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); + } + + public virtual void funct0012be74() + { + this.ee.pc = 1228424u; + // @0012BE74 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012BE78 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012BE7C SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012BE80 BEQ t7, zero, $0012bea8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228456u; + } + // @0012BE84 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012be88() + { + this.ee.pc = 1228448u; + // @0012BE88 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012BE8C ADDU a0, t7, s3 + this.ee.a0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012BE90 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012BE94 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012BE98 BEQL t7, zero, $00129e40 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220160u; + // @0012BE9C LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012be90() + { + this.ee.pc = 1228448u; + // @0012BE90 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012BE94 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012BE98 BEQL t7, zero, $00129e40 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220160u; + // @0012BE9C LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012bea0() + { + this.ee.pc = 1228456u; + // @0012BEA0 BEQ zero, zero, $0012a9b4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1223092u; + } + // @0012BEA4 LW t7, $0020(s5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); + } + + public virtual void funct0012bea8() + { + this.ee.pc = 1228472u; + // @0012BEA8 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012BEAC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012BEB0 BEQ zero, zero, $0012be90 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228432u; + } + // @0012BEB4 ADDU a0, t6, t7 + this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012beb8() + { + this.ee.pc = 1228488u; + // @0012BEB8 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012BEBC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012BEC0 BEQ zero, zero, $0012be4c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228364u; + } + // @0012BEC4 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012bec8() + { + this.ee.pc = 1228504u; + // @0012BEC8 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012BECC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012BED0 BEQ zero, zero, $0012bd8c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228172u; + } + // @0012BED4 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012bed8() + { + this.ee.pc = 1228528u; + // @0012BED8 ADDIU a1, sp, $0040 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 64))); + // @0012BEDC LW t6, $0008(s0) + MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); + // @0012BEE0 SLL t7, t5, 6 + MobUt.SLL(this.ee.t7, this.ee.t5, 6); + // @0012BEE4 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012BEE8 BEQ a1, t6, $0012bd14 + if ((this.ee.a1.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1228052u; + } + // @0012BEEC NOP + MobUt.Latency(); + } + + public virtual void funct0012bef0() + { + this.ee.pc = 1228568u; + // @0012BEF0 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012BEF4 LQ t1, $0010(t6) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); + // @0012BEF8 LQ t2, $0020(t6) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); + // @0012BEFC LQ t3, $0030(t6) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); + // @0012BF00 SQ t0, $0000(a1) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @0012BF04 SQ t1, $0010(a1) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.a1.UL[0])); + // @0012BF08 SQ t2, $0020(a1) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.a1.UL[0])); + // @0012BF0C SQ t3, $0030(a1) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.a1.UL[0])); + // @0012BF10 BEQ zero, zero, $0012bd14 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228052u; + } + // @0012BF14 NOP + MobUt.Latency(); + } + + public virtual void funct0012bf18() + { + this.ee.pc = 1228584u; + // @0012BF18 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012BF1C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012BF20 BEQ zero, zero, $0012bcac + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227948u; + } + // @0012BF24 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012bf28() + { + this.ee.pc = 1228600u; + // @0012BF28 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012BF2C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012BF30 BEQ zero, zero, $0012bc60 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227872u; + } + // @0012BF34 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012bf38() + { + this.ee.pc = 1228616u; + // @0012BF38 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012BF3C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012BF40 BEQ zero, zero, $0012bc18 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227800u; + } + // @0012BF44 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012bf48() + { + this.ee.pc = 1228644u; + // @0012BF48 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + // @0012BF4C LHU t7, $0004(t6) + MobUt.LHU(this.ee, this.ee.t7, (4u + this.ee.t6.UL0)); + // @0012BF50 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012BF54 ADDU t6, t5, t7 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t7.SD0))); + // @0012BF58 ADDU t7, t5, s3 + this.ee.t7.SD0 = ((int)((this.ee.t5.SD0 + this.ee.s3.SD0))); + // @0012BF5C BEQL t7, t6, $0012bc00 + if ((this.ee.t7.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1227776u; + // @0012BF60 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012bf64() + { + this.ee.pc = 1228684u; + // @0012BF64 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012BF68 LQ t1, $0010(t6) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); + // @0012BF6C LQ t2, $0020(t6) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); + // @0012BF70 LQ t3, $0030(t6) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); + // @0012BF74 SQ t0, $0000(t7) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012BF78 SQ t1, $0010(t7) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); + // @0012BF7C SQ t2, $0020(t7) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); + // @0012BF80 SQ t3, $0030(t7) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); + // @0012BF84 BEQ zero, zero, $0012bbfc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227772u; + } + // @0012BF88 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + } + + public virtual void funct0012bf8c() + { + this.ee.pc = 1228696u; + // @0012BF8C ADDIU t7, zero, $0005 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 5))); + // @0012BF90 BNEL t5, t7, $0012bbfc + if ((this.ee.t5.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1227772u; + // @0012BF94 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012bf98() + { + this.ee.pc = 1228712u; + // @0012BF98 ANDI t6, t6, $00ff + this.ee.t6.UD0 = ((ushort)((this.ee.t6.US0 & 255))); + // @0012BF9C ADDIU t7, zero, $0003 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 3))); + // @0012BFA0 BNE t6, t7, $0012c3dc + if ((this.ee.t6.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1229788u; + } + // @0012BFA4 LW t3, $0218(sp) + MobUt.LW(this.ee, this.ee.t3, (536u + this.ee.sp.UL0)); + } + + public virtual void funct0012bfa8() + { + this.ee.pc = 1228744u; + // @0012BFA8 LW t7, $0218(sp) + MobUt.LW(this.ee, this.ee.t7, (536u + this.ee.sp.UL0)); + // @0012BFAC LHU t5, $0004(t7) + MobUt.LHU(this.ee, this.ee.t5, (4u + this.ee.t7.UL0)); + // @0012BFB0 LW t6, $0004(s0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); + // @0012BFB4 ADDIU t4, sp, $00b0 + this.ee.t4.SD0 = ((int)((this.ee.sp.SD0 + 176))); + // @0012BFB8 LHU t6, $0010(t6) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); + // @0012BFBC SLT t7, t5, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); + // @0012BFC0 BEQ t7, zero, $0012c3cc + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229772u; + } + // @0012BFC4 ADDIU t3, sp, $0040 + this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 64))); + } + + public virtual void funct0012bfd0() + { + this.ee.pc = 1228812u; + // @0012BFD0 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012BFD4 ADDIU s7, sp, $0180 + this.ee.s7.SD0 = ((int)((this.ee.sp.SD0 + 384))); + // @0012BFD8 ADDIU t7, t6, $0030 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012BFDC LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012BFE0 LQC2 vf1, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); + // @0012BFE4 LQC2 vf2, $0010(t3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); + // @0012BFE8 LQC2 vf3, $0020(t3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); + // @0012BFEC LQC2 vf4, $0030(t3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); + // @0012BFF0 VMULAx.xyzw ACC, vf1, vf5x + // @0012BFF4 VMADDAy.xyzw ACC, vf2, vf5y + // @0012BFF8 VMADDAz.xyzw ACC, vf3, vf5z + // @0012BFFC VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C000 SQC2 vf5, $0000(s7) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s7.UL0)); + // @0012C004 BEQ t4, s7, $0012c018 + if ((this.ee.t4.UD0 == this.ee.s7.UD0)) + { + this.ee.pc = 1228824u; + } + // @0012C008 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + } + + public virtual void funct0012c00c() + { + this.ee.pc = 1228856u; + // @0012C00C LQ t0, $0000(s7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s7.UL[0])); + // @0012C010 SQ t0, $0000(t4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); + // @0012C014 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012C018 ADDIU t5, sp, $0090 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 144))); + // @0012C01C DADDU a0, t8, zero + this.ee.a0.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); + // @0012C020 LQC2 vf1, $0000(t4) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t4.UL0)); + // @0012C024 LQC2 vf2, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t5.UL0)); + // @0012C028 VSUB.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); + // @0012C02C SQC2 vf1, $0000(s7) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s7.UL0)); + // @0012C030 BEQ t8, s7, $0012c044 + if ((this.ee.t8.UD0 == this.ee.s7.UD0)) + { + this.ee.pc = 1228868u; + } + // @0012C034 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + } + + public virtual void funct0012c038() + { + this.ee.pc = 1228908u; + // @0012C038 LQ t0, $0000(s7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s7.UL[0])); + // @0012C03C SQ t0, $0000(t8) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); + // @0012C040 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @0012C044 SW zero, $0130(sp) + MobUt.SW(this.ee, this.ee.r0, (304u + this.ee.sp.UL0)); + // @0012C048 ADDIU t6, t6, $8364 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -31900))); + // @0012C04C SW zero, $0138(sp) + MobUt.SW(this.ee, this.ee.r0, (312u + this.ee.sp.UL0)); + // @0012C050 LWC1 $f0, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @0012C054 SWC1 $f0, $0134(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (308u + this.ee.sp.UL0)); + // @0012C058 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012C05C LHU t7, $0010(t7) + MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); + // @0012C060 SLT t6, s2, t7 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); + // @0012C064 BEQ t6, zero, $0012c3bc + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229756u; + } + // @0012C068 SUBU t7, s2, t7 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); + } + + public virtual void funct0012c06c() + { + this.ee.pc = 1228924u; + // @0012C06C LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012C070 ADDU a2, t7, s3 + this.ee.a2.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012C074 JAL $00128b20 + this.ee.ra.UL0 = 1228924u; + this.ee.pc = 1215264u; + // @0012C078 ADDIU a1, sp, $0130 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 304))); + } + + public virtual void funct0012c074() + { + this.ee.pc = 1228924u; + // @0012C074 JAL $00128b20 + this.ee.ra.UL0 = 1228924u; + this.ee.pc = 1215264u; + // @0012C078 ADDIU a1, sp, $0130 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 304))); + } + + public virtual void funct0012c07c() + { + this.ee.pc = 1228932u; + // @0012C07C JAL $0011b420 + this.ee.ra.UL0 = 1228932u; + this.ee.pc = 1160224u; + // @0012C080 ADDIU a0, sp, $0140 + this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 320))); + } + + public virtual void funct0012c084() + { + this.ee.pc = 1228952u; + // @0012C084 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @0012C088 LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @0012C08C SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @0012C090 BEQL t7, zero, $0012c3a4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229732u; + // @0012C094 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct0012c098() + { + this.ee.pc = 1228972u; + // @0012C098 LW t7, $0020(s5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); + // @0012C09C ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012C0A0 LWC1 $f12, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[12], (0u + this.ee.t6.UL0)); + // @0012C0A4 JAL $0011b450 + this.ee.ra.UL0 = 1228972u; + this.ee.pc = 1160272u; + // @0012C0A8 ADDIU a0, sp, $0140 + this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 320))); + } + + public virtual void funct0012c0a0() + { + this.ee.pc = 1228972u; + // @0012C0A0 LWC1 $f12, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[12], (0u + this.ee.t6.UL0)); + // @0012C0A4 JAL $0011b450 + this.ee.ra.UL0 = 1228972u; + this.ee.pc = 1160272u; + // @0012C0A8 ADDIU a0, sp, $0140 + this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 320))); + } + + public virtual void funct0012c0ac() + { + this.ee.pc = 1228992u; + // @0012C0AC LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012C0B0 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012C0B4 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012C0B8 BEQ t7, zero, $0012c390 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229712u; + } + // @0012C0BC DADDU t5, t4, zero + this.ee.t5.UD0 = (this.ee.t4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012c0c0() + { + this.ee.pc = 1229016u; + // @0012C0C0 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012C0C4 ADDU t4, t7, s3 + this.ee.t4.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012C0C8 LHU t6, $0010(t5) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t5.UL0)); + // @0012C0CC SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012C0D0 BEQ t7, zero, $0012c380 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229696u; + } + // @0012C0D4 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012c0c8() + { + this.ee.pc = 1229016u; + // @0012C0C8 LHU t6, $0010(t5) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t5.UL0)); + // @0012C0CC SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012C0D0 BEQ t7, zero, $0012c380 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229696u; + } + // @0012C0D4 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012c0d8() + { + this.ee.pc = 1229152u; + // @0012C0D8 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012C0DC ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012C0E0 ADDIU t5, sp, $01b0 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 432))); + // @0012C0E4 ADDIU t7, sp, $0140 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 320))); + // @0012C0E8 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012C0EC LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012C0F0 LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012C0F4 LQC2 vf4, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); + // @0012C0F8 LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012C0FC LQC2 vf6, $0010(t7) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); + // @0012C100 LQC2 vf7, $0020(t7) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); + // @0012C104 LQC2 vf8, $0030(t7) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); + // @0012C108 VMULAx.xyzw ACC, vf1, vf5x + // @0012C10C VMADDAy.xyzw ACC, vf2, vf5y + // @0012C110 VMADDAz.xyzw ACC, vf3, vf5z + // @0012C114 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C118 VMULAx.xyzw ACC, vf1, vf6x + // @0012C11C VMADDAy.xyzw ACC, vf2, vf6y + // @0012C120 VMADDAz.xyzw ACC, vf3, vf6z + // @0012C124 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012C128 VMULAx.xyzw ACC, vf1, vf7x + // @0012C12C VMADDAy.xyzw ACC, vf2, vf7y + // @0012C130 VMADDAz.xyzw ACC, vf3, vf7z + // @0012C134 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012C138 VMULAx.xyzw ACC, vf1, vf8x + // @0012C13C VMADDAy.xyzw ACC, vf2, vf8y + // @0012C140 VMADDAz.xyzw ACC, vf3, vf8z + // @0012C144 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012C148 SQC2 vf5, $0000(t5) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); + // @0012C14C SQC2 vf6, $0010(t5) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t5.UL0)); + // @0012C150 SQC2 vf7, $0020(t5) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t5.UL0)); + // @0012C154 SQC2 vf8, $0030(t5) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t5.UL0)); + // @0012C158 BEQL t4, t5, $0012c184 + if ((this.ee.t4.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1229188u; + // @0012C15C LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012c0e0() + { + this.ee.pc = 1229152u; + // @0012C0E0 ADDIU t5, sp, $01b0 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 432))); + // @0012C0E4 ADDIU t7, sp, $0140 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 320))); + // @0012C0E8 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012C0EC LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012C0F0 LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012C0F4 LQC2 vf4, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); + // @0012C0F8 LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012C0FC LQC2 vf6, $0010(t7) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t7.UL0)); + // @0012C100 LQC2 vf7, $0020(t7) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t7.UL0)); + // @0012C104 LQC2 vf8, $0030(t7) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t7.UL0)); + // @0012C108 VMULAx.xyzw ACC, vf1, vf5x + // @0012C10C VMADDAy.xyzw ACC, vf2, vf5y + // @0012C110 VMADDAz.xyzw ACC, vf3, vf5z + // @0012C114 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C118 VMULAx.xyzw ACC, vf1, vf6x + // @0012C11C VMADDAy.xyzw ACC, vf2, vf6y + // @0012C120 VMADDAz.xyzw ACC, vf3, vf6z + // @0012C124 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012C128 VMULAx.xyzw ACC, vf1, vf7x + // @0012C12C VMADDAy.xyzw ACC, vf2, vf7y + // @0012C130 VMADDAz.xyzw ACC, vf3, vf7z + // @0012C134 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012C138 VMULAx.xyzw ACC, vf1, vf8x + // @0012C13C VMADDAy.xyzw ACC, vf2, vf8y + // @0012C140 VMADDAz.xyzw ACC, vf3, vf8z + // @0012C144 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012C148 SQC2 vf5, $0000(t5) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); + // @0012C14C SQC2 vf6, $0010(t5) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t5.UL0)); + // @0012C150 SQC2 vf7, $0020(t5) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t5.UL0)); + // @0012C154 SQC2 vf8, $0030(t5) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t5.UL0)); + // @0012C158 BEQL t4, t5, $0012c184 + if ((this.ee.t4.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1229188u; + // @0012C15C LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012c160() + { + this.ee.pc = 1229204u; + // @0012C160 LQ t0, $0000(t5) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012C164 LQ t1, $0010(t5) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); + // @0012C168 LQ t2, $0020(t5) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); + // @0012C16C LQ t3, $0030(t5) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); + // @0012C170 SQ t0, $0000(t4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); + // @0012C174 SQ t1, $0010(t4) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); + // @0012C178 SQ t2, $0020(t4) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); + // @0012C17C SQ t3, $0030(t4) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); + // @0012C180 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012C184 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012C188 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012C18C BEQ t7, zero, $0012c370 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229680u; + } + // @0012C190 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012c194() + { + this.ee.pc = 1229228u; + // @0012C194 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012C198 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012C19C ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012C1A0 ADDIU t3, sp, $0090 + this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); + // @0012C1A4 BEQ t6, t3, $0012c1bc + if ((this.ee.t6.UD0 == this.ee.t3.UD0)) + { + this.ee.pc = 1229244u; + } + // @0012C1A8 LW t5, $0214(sp) + MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); + } + + public virtual void funct0012c19c() + { + this.ee.pc = 1229228u; + // @0012C19C ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012C1A0 ADDIU t3, sp, $0090 + this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); + // @0012C1A4 BEQ t6, t3, $0012c1bc + if ((this.ee.t6.UD0 == this.ee.t3.UD0)) + { + this.ee.pc = 1229244u; + } + // @0012C1A8 LW t5, $0214(sp) + MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); + } + + public virtual void funct0012c1ac() + { + this.ee.pc = 1229252u; + // @0012C1AC LQ t0, $0000(t3) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); + // @0012C1B0 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012C1B4 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012C1B8 LW t5, $0214(sp) + MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); + // @0012C1BC BGEZ t5, $0012c298 + if ((this.ee.t5.SD0 >= 0)) + { + this.ee.pc = 1229464u; + } + // @0012C1C0 LW t6, $0214(sp) + MobUt.LW(this.ee, this.ee.t6, (532u + this.ee.sp.UL0)); + } + + public virtual void funct0012c298() + { + this.ee.pc = 1229492u; + // @0012C298 LHU t3, $0010(t4) + MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t4.UL0)); + // @0012C29C SLL t7, t6, 6 + MobUt.SLL(this.ee.t7, this.ee.t6, 6); + // @0012C2A0 LW t6, $0008(s0) + MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); + // @0012C2A4 SLT t5, s2, t3 + this.ee.t5.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); + // @0012C2A8 ADDU t2, t6, t7 + this.ee.t2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012C2AC BEQ t5, zero, $0012c35c + if ((this.ee.t5.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229660u; + } + // @0012C2B0 ADDU t4, t6, s3 + this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); + } + + public virtual void funct0012c2b4() + { + this.ee.pc = 1229620u; + // @0012C2B4 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012C2B8 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012C2BC LQC2 vf1, $0000(t2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); + // @0012C2C0 LQC2 vf2, $0010(t2) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t2.UL0)); + // @0012C2C4 LQC2 vf3, $0020(t2) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t2.UL0)); + // @0012C2C8 LQC2 vf4, $0030(t2) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t2.UL0)); + // @0012C2CC LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012C2D0 LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012C2D4 LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012C2D8 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012C2DC VMULAx.xyzw ACC, vf1, vf5x + // @0012C2E0 VMADDAy.xyzw ACC, vf2, vf5y + // @0012C2E4 VMADDAz.xyzw ACC, vf3, vf5z + // @0012C2E8 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C2EC VMULAx.xyzw ACC, vf1, vf6x + // @0012C2F0 VMADDAy.xyzw ACC, vf2, vf6y + // @0012C2F4 VMADDAz.xyzw ACC, vf3, vf6z + // @0012C2F8 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012C2FC VMULAx.xyzw ACC, vf1, vf7x + // @0012C300 VMADDAy.xyzw ACC, vf2, vf7y + // @0012C304 VMADDAz.xyzw ACC, vf3, vf7z + // @0012C308 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012C30C VMULAx.xyzw ACC, vf1, vf8x + // @0012C310 VMADDAy.xyzw ACC, vf2, vf8y + // @0012C314 VMADDAz.xyzw ACC, vf3, vf8z + // @0012C318 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012C31C SQC2 vf5, $0000(s7) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s7.UL0)); + // @0012C320 SQC2 vf6, $0010(s7) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.s7.UL0)); + // @0012C324 SQC2 vf7, $0020(s7) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.s7.UL0)); + // @0012C328 SQC2 vf8, $0030(s7) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.s7.UL0)); + // @0012C32C BEQL t4, s7, $0012bbfc + if ((this.ee.t4.UD0 == this.ee.s7.UD0)) + { + this.ee.pc = 1227772u; + // @0012C330 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012c2bc() + { + this.ee.pc = 1229620u; + // @0012C2BC LQC2 vf1, $0000(t2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); + // @0012C2C0 LQC2 vf2, $0010(t2) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t2.UL0)); + // @0012C2C4 LQC2 vf3, $0020(t2) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t2.UL0)); + // @0012C2C8 LQC2 vf4, $0030(t2) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t2.UL0)); + // @0012C2CC LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012C2D0 LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012C2D4 LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012C2D8 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012C2DC VMULAx.xyzw ACC, vf1, vf5x + // @0012C2E0 VMADDAy.xyzw ACC, vf2, vf5y + // @0012C2E4 VMADDAz.xyzw ACC, vf3, vf5z + // @0012C2E8 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C2EC VMULAx.xyzw ACC, vf1, vf6x + // @0012C2F0 VMADDAy.xyzw ACC, vf2, vf6y + // @0012C2F4 VMADDAz.xyzw ACC, vf3, vf6z + // @0012C2F8 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012C2FC VMULAx.xyzw ACC, vf1, vf7x + // @0012C300 VMADDAy.xyzw ACC, vf2, vf7y + // @0012C304 VMADDAz.xyzw ACC, vf3, vf7z + // @0012C308 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012C30C VMULAx.xyzw ACC, vf1, vf8x + // @0012C310 VMADDAy.xyzw ACC, vf2, vf8y + // @0012C314 VMADDAz.xyzw ACC, vf3, vf8z + // @0012C318 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012C31C SQC2 vf5, $0000(s7) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s7.UL0)); + // @0012C320 SQC2 vf6, $0010(s7) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.s7.UL0)); + // @0012C324 SQC2 vf7, $0020(s7) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.s7.UL0)); + // @0012C328 SQC2 vf8, $0030(s7) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.s7.UL0)); + // @0012C32C BEQL t4, s7, $0012bbfc + if ((this.ee.t4.UD0 == this.ee.s7.UD0)) + { + this.ee.pc = 1227772u; + // @0012C330 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012c334() + { + this.ee.pc = 1229660u; + // @0012C334 LQ t0, $0000(s7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s7.UL[0])); + // @0012C338 LQ t1, $0010(s7) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.s7.UL[0])); + // @0012C33C LQ t2, $0020(s7) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.s7.UL[0])); + // @0012C340 LQ t3, $0030(s7) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.s7.UL[0])); + // @0012C344 SQ t0, $0000(t4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); + // @0012C348 SQ t1, $0010(t4) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); + // @0012C34C SQ t2, $0020(t4) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); + // @0012C350 SQ t3, $0030(t4) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); + // @0012C354 BEQ zero, zero, $0012bbfc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227772u; + } + // @0012C358 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + } + + public virtual void funct0012c35c() + { + this.ee.pc = 1229680u; + // @0012C35C SUBU t7, s2, t3 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); + // @0012C360 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012C364 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C368 BEQ zero, zero, $0012c2bc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229500u; + } + // @0012C36C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012c370() + { + this.ee.pc = 1229696u; + // @0012C370 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012C374 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C378 BEQ zero, zero, $0012c19c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229212u; + } + // @0012C37C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012c380() + { + this.ee.pc = 1229712u; + // @0012C380 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012C384 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C388 BEQ zero, zero, $0012c0e0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229024u; + } + // @0012C38C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012c390() + { + this.ee.pc = 1229732u; + // @0012C390 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + // @0012C394 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012C398 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C39C BEQ zero, zero, $0012c0c8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229000u; + } + // @0012C3A0 ADDU t4, t6, t7 + this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012c3a4() + { + this.ee.pc = 1229756u; + // @0012C3A4 SUBU t7, s2, t4 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); + // @0012C3A8 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C3AC ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012C3B0 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012C3B4 BEQ zero, zero, $0012c0a0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228960u; + } + // @0012C3B8 ADDIU t6, t6, $0020 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); + } + + public virtual void funct0012c3bc() + { + this.ee.pc = 1229772u; + // @0012C3BC LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012C3C0 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C3C4 BEQ zero, zero, $0012c074 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228916u; + } + // @0012C3C8 ADDU a2, t6, t7 + this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012c3cc() + { + this.ee.pc = 1229788u; + // @0012C3CC SUBU t7, t5, t6 + this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.t6.UD0))); + // @0012C3D0 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012C3D4 BEQ zero, zero, $0012bfd0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1228752u; + } + // @0012C3D8 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012c3e4() + { + this.ee.pc = 1229816u; + // @0012C3E4 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012C3E8 LHU t7, $0010(t7) + MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); + // @0012C3EC SLT t6, s2, t7 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); + // @0012C3F0 BEQ t6, zero, $0012c710 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230608u; + } + // @0012C3F4 SUBU t7, s2, t7 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); + } + + public virtual void funct0012c3f8() + { + this.ee.pc = 1229832u; + // @0012C3F8 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012C3FC ADDU a0, t7, s3 + this.ee.a0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012C400 JAL $0011b420 + this.ee.ra.UL0 = 1229832u; + this.ee.pc = 1160224u; + // @0012C404 NOP + MobUt.Latency(); + } + + public virtual void funct0012c400() + { + this.ee.pc = 1229832u; + // @0012C400 JAL $0011b420 + this.ee.ra.UL0 = 1229832u; + this.ee.pc = 1160224u; + // @0012C404 NOP + MobUt.Latency(); + } + + public virtual void funct0012c408() + { + this.ee.pc = 1229844u; + // @0012C408 LW t7, $021c(sp) + MobUt.LW(this.ee, this.ee.t7, (540u + this.ee.sp.UL0)); + // @0012C40C BEQ t7, zero, $0012c468 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229928u; + } + // @0012C410 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + } + + public virtual void funct0012c414() + { + this.ee.pc = 1229864u; + // @0012C414 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @0012C418 LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @0012C41C SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @0012C420 BEQ t7, zero, $0012c6f4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230580u; + } + // @0012C424 DADDU a2, t8, zero + this.ee.a2.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012c428() + { + this.ee.pc = 1229900u; + // @0012C428 LW t7, $0020(s5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); + // @0012C42C ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012C430 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012C434 SQ t0, $0000(a2) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a2.UL[0])); + // @0012C438 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @0012C43C LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @0012C440 SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @0012C444 BEQL t7, zero, $0012c6dc + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230556u; + // @0012C448 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct0012c430() + { + this.ee.pc = 1229900u; + // @0012C430 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012C434 SQ t0, $0000(a2) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a2.UL[0])); + // @0012C438 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @0012C43C LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @0012C440 SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @0012C444 BEQL t7, zero, $0012c6dc + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230556u; + // @0012C448 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct0012c44c() + { + this.ee.pc = 1229924u; + // @0012C44C LW t7, $0020(s5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); + // @0012C450 ADDU a3, t7, s8 + this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012C454 SQ t8, $0290(sp) + MobUt.SQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); + // @0012C458 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0012C45C JAL $00127e20 + this.ee.ra.UL0 = 1229924u; + this.ee.pc = 1211936u; + // @0012C460 LW a1, $021c(sp) + MobUt.LW(this.ee, this.ee.a1, (540u + this.ee.sp.UL0)); + } + + public virtual void funct0012c454() + { + this.ee.pc = 1229924u; + // @0012C454 SQ t8, $0290(sp) + MobUt.SQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); + // @0012C458 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0012C45C JAL $00127e20 + this.ee.ra.UL0 = 1229924u; + this.ee.pc = 1211936u; + // @0012C460 LW a1, $021c(sp) + MobUt.LW(this.ee, this.ee.a1, (540u + this.ee.sp.UL0)); + } + + public virtual void funct0012c464() + { + this.ee.pc = 1229948u; + // @0012C464 LQ t8, $0290(sp) + MobUt.LQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); + // @0012C468 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012C46C LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012C470 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012C474 BEQ t7, zero, $0012c6cc + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230540u; + } + // @0012C478 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012c468() + { + this.ee.pc = 1229948u; + // @0012C468 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012C46C LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012C470 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012C474 BEQ t7, zero, $0012c6cc + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230540u; + } + // @0012C478 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012c47c() + { + this.ee.pc = 1229972u; + // @0012C47C LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012C480 ADDU a0, t7, s3 + this.ee.a0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012C484 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012C488 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012C48C BEQL t7, zero, $0012c6b4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230516u; + // @0012C490 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012c484() + { + this.ee.pc = 1229972u; + // @0012C484 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012C488 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012C48C BEQL t7, zero, $0012c6b4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230516u; + // @0012C490 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012c494() + { + this.ee.pc = 1229988u; + // @0012C494 LW t7, $0020(s5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); + // @0012C498 ADDU a1, t7, s8 + this.ee.a1.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012C49C JAL $0011b528 + this.ee.ra.UL0 = 1229988u; + this.ee.pc = 1160488u; + // @0012C4A0 SQ t8, $0290(sp) + MobUt.SQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); + } + + public virtual void funct0012c49c() + { + this.ee.pc = 1229988u; + // @0012C49C JAL $0011b528 + this.ee.ra.UL0 = 1229988u; + this.ee.pc = 1160488u; + // @0012C4A0 SQ t8, $0290(sp) + MobUt.SQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); + } + + public virtual void funct0012c4a4() + { + this.ee.pc = 1230008u; + // @0012C4A4 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012C4A8 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012C4AC SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012C4B0 BEQ t7, zero, $0012c6a0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230496u; + } + // @0012C4B4 LQ t8, $0290(sp) + MobUt.LQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); + } + + public virtual void funct0012c4b8() + { + this.ee.pc = 1230032u; + // @0012C4B8 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012C4BC ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012C4C0 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012C4C4 ADDIU t3, sp, $0090 + this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); + // @0012C4C8 BEQ t6, t3, $0012c4e0 + if ((this.ee.t6.UD0 == this.ee.t3.UD0)) + { + this.ee.pc = 1230048u; + } + // @0012C4CC LW t5, $0214(sp) + MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); + } + + public virtual void funct0012c4c0() + { + this.ee.pc = 1230032u; + // @0012C4C0 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012C4C4 ADDIU t3, sp, $0090 + this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); + // @0012C4C8 BEQ t6, t3, $0012c4e0 + if ((this.ee.t6.UD0 == this.ee.t3.UD0)) + { + this.ee.pc = 1230048u; + } + // @0012C4CC LW t5, $0214(sp) + MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); + } + + public virtual void funct0012c4d0() + { + this.ee.pc = 1230056u; + // @0012C4D0 LQ t0, $0000(t3) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); + // @0012C4D4 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012C4D8 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012C4DC LW t5, $0214(sp) + MobUt.LW(this.ee, this.ee.t5, (532u + this.ee.sp.UL0)); + // @0012C4E0 BLTZ t5, $0012c4f4 + if ((this.ee.t5.SD0 < 0)) + { + this.ee.pc = 1230068u; + } + // @0012C4E4 LUI t7, $0008 + this.ee.t7.SD0 = 524288; + } + + public virtual void funct0012c4e8() + { + this.ee.pc = 1230068u; + // @0012C4E8 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @0012C4EC BEQ t7, zero, $0012c5c8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230280u; + } + // @0012C4F0 LW t6, $0214(sp) + MobUt.LW(this.ee, this.ee.t6, (532u + this.ee.sp.UL0)); + } + + public virtual void funct0012c4f4() + { + this.ee.pc = 1230092u; + // @0012C4F4 LHU t4, $0010(t4) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t4.UL0)); + // @0012C4F8 DADDU t3, sp, zero + this.ee.t3.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); + // @0012C4FC LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + // @0012C500 SLT t6, s2, t4 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @0012C504 BEQ t6, zero, $0012c5b4 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230260u; + } + // @0012C508 ADDU t5, t7, s3 + this.ee.t5.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + } + + public virtual void funct0012c50c() + { + this.ee.pc = 1230220u; + // @0012C50C LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012C510 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012C514 LQC2 vf1, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); + // @0012C518 LQC2 vf2, $0010(t3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); + // @0012C51C LQC2 vf3, $0020(t3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); + // @0012C520 LQC2 vf4, $0030(t3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); + // @0012C524 LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012C528 LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012C52C LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012C530 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012C534 VMULAx.xyzw ACC, vf1, vf5x + // @0012C538 VMADDAy.xyzw ACC, vf2, vf5y + // @0012C53C VMADDAz.xyzw ACC, vf3, vf5z + // @0012C540 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C544 VMULAx.xyzw ACC, vf1, vf6x + // @0012C548 VMADDAy.xyzw ACC, vf2, vf6y + // @0012C54C VMADDAz.xyzw ACC, vf3, vf6z + // @0012C550 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012C554 VMULAx.xyzw ACC, vf1, vf7x + // @0012C558 VMADDAy.xyzw ACC, vf2, vf7y + // @0012C55C VMADDAz.xyzw ACC, vf3, vf7z + // @0012C560 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012C564 VMULAx.xyzw ACC, vf1, vf8x + // @0012C568 VMADDAy.xyzw ACC, vf2, vf8y + // @0012C56C VMADDAz.xyzw ACC, vf3, vf8z + // @0012C570 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012C574 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012C578 SQC2 vf6, $0010(t8) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); + // @0012C57C SQC2 vf7, $0020(t8) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); + // @0012C580 SQC2 vf8, $0030(t8) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); + // @0012C584 BEQL t5, t8, $0012bbfc + if ((this.ee.t5.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1227772u; + // @0012C588 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012c514() + { + this.ee.pc = 1230220u; + // @0012C514 LQC2 vf1, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); + // @0012C518 LQC2 vf2, $0010(t3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); + // @0012C51C LQC2 vf3, $0020(t3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); + // @0012C520 LQC2 vf4, $0030(t3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); + // @0012C524 LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012C528 LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012C52C LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012C530 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012C534 VMULAx.xyzw ACC, vf1, vf5x + // @0012C538 VMADDAy.xyzw ACC, vf2, vf5y + // @0012C53C VMADDAz.xyzw ACC, vf3, vf5z + // @0012C540 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C544 VMULAx.xyzw ACC, vf1, vf6x + // @0012C548 VMADDAy.xyzw ACC, vf2, vf6y + // @0012C54C VMADDAz.xyzw ACC, vf3, vf6z + // @0012C550 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012C554 VMULAx.xyzw ACC, vf1, vf7x + // @0012C558 VMADDAy.xyzw ACC, vf2, vf7y + // @0012C55C VMADDAz.xyzw ACC, vf3, vf7z + // @0012C560 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012C564 VMULAx.xyzw ACC, vf1, vf8x + // @0012C568 VMADDAy.xyzw ACC, vf2, vf8y + // @0012C56C VMADDAz.xyzw ACC, vf3, vf8z + // @0012C570 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012C574 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012C578 SQC2 vf6, $0010(t8) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); + // @0012C57C SQC2 vf7, $0020(t8) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); + // @0012C580 SQC2 vf8, $0030(t8) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); + // @0012C584 BEQL t5, t8, $0012bbfc + if ((this.ee.t5.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1227772u; + // @0012C588 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012c58c() + { + this.ee.pc = 1230260u; + // @0012C58C LQ t0, $0000(t8) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); + // @0012C590 LQ t1, $0010(t8) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t8.UL[0])); + // @0012C594 LQ t2, $0020(t8) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t8.UL[0])); + // @0012C598 LQ t3, $0030(t8) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t8.UL[0])); + // @0012C59C SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012C5A0 SQ t1, $0010(t5) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); + // @0012C5A4 SQ t2, $0020(t5) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); + // @0012C5A8 SQ t3, $0030(t5) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); + // @0012C5AC BEQ zero, zero, $0012bbfc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227772u; + } + // @0012C5B0 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + } + + public virtual void funct0012c5b4() + { + this.ee.pc = 1230280u; + // @0012C5B4 SUBU t7, s2, t4 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); + // @0012C5B8 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012C5BC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C5C0 BEQ zero, zero, $0012c514 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230100u; + } + // @0012C5C4 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012c5c8() + { + this.ee.pc = 1230308u; + // @0012C5C8 LHU t3, $0010(t4) + MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t4.UL0)); + // @0012C5CC SLL t7, t6, 6 + MobUt.SLL(this.ee.t7, this.ee.t6, 6); + // @0012C5D0 LW t6, $0008(s0) + MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); + // @0012C5D4 SLT t5, s2, t3 + this.ee.t5.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); + // @0012C5D8 ADDU t2, t6, t7 + this.ee.t2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012C5DC BEQ t5, zero, $0012c68c + if ((this.ee.t5.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230476u; + } + // @0012C5E0 ADDU t4, t6, s3 + this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); + } + + public virtual void funct0012c5e4() + { + this.ee.pc = 1230436u; + // @0012C5E4 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012C5E8 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012C5EC LQC2 vf1, $0000(t2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); + // @0012C5F0 LQC2 vf2, $0010(t2) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t2.UL0)); + // @0012C5F4 LQC2 vf3, $0020(t2) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t2.UL0)); + // @0012C5F8 LQC2 vf4, $0030(t2) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t2.UL0)); + // @0012C5FC LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012C600 LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012C604 LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012C608 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012C60C VMULAx.xyzw ACC, vf1, vf5x + // @0012C610 VMADDAy.xyzw ACC, vf2, vf5y + // @0012C614 VMADDAz.xyzw ACC, vf3, vf5z + // @0012C618 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C61C VMULAx.xyzw ACC, vf1, vf6x + // @0012C620 VMADDAy.xyzw ACC, vf2, vf6y + // @0012C624 VMADDAz.xyzw ACC, vf3, vf6z + // @0012C628 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012C62C VMULAx.xyzw ACC, vf1, vf7x + // @0012C630 VMADDAy.xyzw ACC, vf2, vf7y + // @0012C634 VMADDAz.xyzw ACC, vf3, vf7z + // @0012C638 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012C63C VMULAx.xyzw ACC, vf1, vf8x + // @0012C640 VMADDAy.xyzw ACC, vf2, vf8y + // @0012C644 VMADDAz.xyzw ACC, vf3, vf8z + // @0012C648 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012C64C SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012C650 SQC2 vf6, $0010(t8) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); + // @0012C654 SQC2 vf7, $0020(t8) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); + // @0012C658 SQC2 vf8, $0030(t8) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); + // @0012C65C BEQL t4, t8, $0012bbfc + if ((this.ee.t4.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1227772u; + // @0012C660 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012c5ec() + { + this.ee.pc = 1230436u; + // @0012C5EC LQC2 vf1, $0000(t2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); + // @0012C5F0 LQC2 vf2, $0010(t2) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t2.UL0)); + // @0012C5F4 LQC2 vf3, $0020(t2) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t2.UL0)); + // @0012C5F8 LQC2 vf4, $0030(t2) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t2.UL0)); + // @0012C5FC LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012C600 LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012C604 LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012C608 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012C60C VMULAx.xyzw ACC, vf1, vf5x + // @0012C610 VMADDAy.xyzw ACC, vf2, vf5y + // @0012C614 VMADDAz.xyzw ACC, vf3, vf5z + // @0012C618 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C61C VMULAx.xyzw ACC, vf1, vf6x + // @0012C620 VMADDAy.xyzw ACC, vf2, vf6y + // @0012C624 VMADDAz.xyzw ACC, vf3, vf6z + // @0012C628 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012C62C VMULAx.xyzw ACC, vf1, vf7x + // @0012C630 VMADDAy.xyzw ACC, vf2, vf7y + // @0012C634 VMADDAz.xyzw ACC, vf3, vf7z + // @0012C638 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012C63C VMULAx.xyzw ACC, vf1, vf8x + // @0012C640 VMADDAy.xyzw ACC, vf2, vf8y + // @0012C644 VMADDAz.xyzw ACC, vf3, vf8z + // @0012C648 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012C64C SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012C650 SQC2 vf6, $0010(t8) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t8.UL0)); + // @0012C654 SQC2 vf7, $0020(t8) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t8.UL0)); + // @0012C658 SQC2 vf8, $0030(t8) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t8.UL0)); + // @0012C65C BEQL t4, t8, $0012bbfc + if ((this.ee.t4.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1227772u; + // @0012C660 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012c664() + { + this.ee.pc = 1230476u; + // @0012C664 LQ t0, $0000(t8) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); + // @0012C668 LQ t1, $0010(t8) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t8.UL[0])); + // @0012C66C LQ t2, $0020(t8) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t8.UL[0])); + // @0012C670 LQ t3, $0030(t8) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t8.UL[0])); + // @0012C674 SQ t0, $0000(t4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); + // @0012C678 SQ t1, $0010(t4) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); + // @0012C67C SQ t2, $0020(t4) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); + // @0012C680 SQ t3, $0030(t4) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); + // @0012C684 BEQ zero, zero, $0012bbfc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227772u; + } + // @0012C688 LW t5, $0008(s0) + MobUt.LW(this.ee, this.ee.t5, (8u + this.ee.s0.UL0)); + } + + public virtual void funct0012c68c() + { + this.ee.pc = 1230496u; + // @0012C68C SUBU t7, s2, t3 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); + // @0012C690 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012C694 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C698 BEQ zero, zero, $0012c5ec + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230316u; + } + // @0012C69C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012c6a0() + { + this.ee.pc = 1230516u; + // @0012C6A0 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + // @0012C6A4 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012C6A8 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C6AC BEQ zero, zero, $0012c4c0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230016u; + } + // @0012C6B0 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012c6b4() + { + this.ee.pc = 1230540u; + // @0012C6B4 SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012C6B8 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C6BC ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012C6C0 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012C6C4 BEQ zero, zero, $0012c49c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229980u; + } + // @0012C6C8 ADDIU a1, t6, $0020 + this.ee.a1.SD0 = ((int)((this.ee.t6.SD0 + 32))); + } + + public virtual void funct0012c6cc() + { + this.ee.pc = 1230556u; + // @0012C6CC LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012C6D0 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C6D4 BEQ zero, zero, $0012c484 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229956u; + } + // @0012C6D8 ADDU a0, t6, t7 + this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012c6dc() + { + this.ee.pc = 1230580u; + // @0012C6DC SUBU t7, s2, t4 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); + // @0012C6E0 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C6E4 ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012C6E8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012C6EC BEQ zero, zero, $0012c454 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229908u; + } + // @0012C6F0 ADDIU a3, t6, $0020 + this.ee.a3.SD0 = ((int)((this.ee.t6.SD0 + 32))); + } + + public virtual void funct0012c6f4() + { + this.ee.pc = 1230608u; + // @0012C6F4 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + // @0012C6F8 SUBU t7, s2, t4 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); + // @0012C6FC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C700 ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012C704 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012C708 BEQ zero, zero, $0012c430 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229872u; + } + // @0012C70C ADDIU t6, t6, $0020 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); + } + + public virtual void funct0012c710() + { + this.ee.pc = 1230624u; + // @0012C710 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012C714 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C718 BEQ zero, zero, $0012c400 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1229824u; + } + // @0012C71C ADDU a0, t6, t7 + this.ee.a0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012c720() + { + this.ee.pc = 1230648u; + // @0012C720 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + // @0012C724 SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + // @0012C728 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012C72C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012C730 BEQ zero, zero, $0012bb60 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227616u; + } + // @0012C734 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012c738() + { + this.ee.pc = 1230656u; + // @0012C738 BNEL a2, t7, $0012c74c + if ((this.ee.a2.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1230668u; + // @0012C73C SQ v0, $0260(sp) + MobUt.SQ(this.ee, this.ee.v0, (608u + this.ee.sp.UL[0])); + } + } + + public virtual void funct0012c740() + { + this.ee.pc = 1230664u; + // @0012C740 BEQL a3, a2, $0012c8d0 + if ((this.ee.a3.UD0 == this.ee.a2.UD0)) + { + this.ee.pc = 1231056u; + // @0012C744 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012c74c() + { + this.ee.pc = 1230700u; + // @0012C74C ADDIU s3, sp, $0040 + this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 64))); + // @0012C750 SQ v1, $0270(sp) + MobUt.SQ(this.ee, this.ee.v1, (624u + this.ee.sp.UL[0])); + // @0012C754 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0012C758 DADDU a1, s5, zero + this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); + // @0012C75C ADDIU t0, sp, $0080 + this.ee.t0.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012C760 DADDU t1, s3, zero + this.ee.t1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); + // @0012C764 JAL $00128c78 + this.ee.ra.UL0 = 1230700u; + this.ee.pc = 1215608u; + // @0012C768 ADDIU t2, sp, $0090 + this.ee.t2.SD0 = ((int)((this.ee.sp.SD0 + 144))); + } + + public virtual void funct0012c76c() + { + this.ee.pc = 1230736u; + // @0012C76C ADDIU s7, sp, $0090 + this.ee.s7.SD0 = ((int)((this.ee.sp.SD0 + 144))); + // @0012C770 LUI t3, $0038 + this.ee.t3.SD0 = 3670016; + // @0012C774 LQ v0, $0260(sp) + MobUt.LQ(this.ee, this.ee.v0, (608u + this.ee.sp.UL[0])); + // @0012C778 ADDIU t3, t3, $8364 + this.ee.t3.SD0 = ((int)((this.ee.t3.SD0 + -31900))); + // @0012C77C LQ v1, $0270(sp) + MobUt.LQ(this.ee, this.ee.v1, (624u + this.ee.sp.UL[0])); + // @0012C780 LWC1 $f0, $0000(t3) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t3.UL0)); + // @0012C784 ADDIU t5, sp, $0080 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012C788 BEQ v0, zero, $0012c848 + if ((this.ee.v0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230920u; + } + // @0012C78C SWC1 $f0, $009c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); + } + + public virtual void funct0012c790() + { + this.ee.pc = 1230756u; + // @0012C790 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012C794 LHU t7, $0010(t7) + MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); + // @0012C798 SLT t6, v1, t7 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.v1.SD0 < this.ee.t7.SD0)); + // @0012C79C BEQ t6, zero, $0012c8c4 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231044u; + } + // @0012C7A0 SUBU t7, v1, t7 + this.ee.t7.SD0 = ((int)((this.ee.v1.UD0 - this.ee.t7.UD0))); + } + + public virtual void funct0012c7ac() + { + this.ee.pc = 1230852u; + // @0012C7AC ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012C7B0 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012C7B4 ADDIU t7, t6, $0030 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012C7B8 LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012C7BC LQC2 vf1, $0000(s3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); + // @0012C7C0 LQC2 vf2, $0010(s3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); + // @0012C7C4 LQC2 vf3, $0020(s3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); + // @0012C7C8 LQC2 vf4, $0030(s3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); + // @0012C7CC VMULAx.xyzw ACC, vf1, vf5x + // @0012C7D0 VMADDAy.xyzw ACC, vf2, vf5y + // @0012C7D4 VMADDAz.xyzw ACC, vf3, vf5z + // @0012C7D8 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C7DC SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012C7E0 ADDIU s3, sp, $0130 + this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 304))); + // @0012C7E4 LQ t0, $0000(t8) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); + // @0012C7E8 SQ t0, $0000(s3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @0012C7EC SQ t5, $0280(sp) + MobUt.SQ(this.ee, this.ee.t5, (640u + this.ee.sp.UL[0])); + // @0012C7F0 DADDU a1, v0, zero + this.ee.a1.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); + // @0012C7F4 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0012C7F8 DADDU a2, s3, zero + this.ee.a2.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); + // @0012C7FC JAL $00127e20 + this.ee.ra.UL0 = 1230852u; + this.ee.pc = 1211936u; + // @0012C800 DADDU a3, s7, zero + this.ee.a3.UD0 = (this.ee.s7.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012c804() + { + this.ee.pc = 1230864u; + // @0012C804 LW t4, $0214(sp) + MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); + // @0012C808 BGEZ t4, $0012c860 + if ((this.ee.t4.SD0 >= 0)) + { + this.ee.pc = 1230944u; + } + // @0012C80C LQ t5, $0280(sp) + MobUt.LQ(this.ee, this.ee.t5, (640u + this.ee.sp.UL[0])); + } + + public virtual void funct0012c838() + { + this.ee.pc = 1230912u; + // @0012C838 BEQL t5, s3, $0012c84c + if ((this.ee.t5.UD0 == this.ee.s3.UD0)) + { + this.ee.pc = 1230924u; + // @0012C83C LUI t5, $0038 + this.ee.t5.SD0 = 3670016; + } + } + + public virtual void funct0012c840() + { + this.ee.pc = 1230944u; + // @0012C840 LQ t0, $0000(s3) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @0012C844 SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012C848 LUI t5, $0038 + this.ee.t5.SD0 = 3670016; + // @0012C84C SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + // @0012C850 ADDIU t5, t5, $8364 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + -31900))); + // @0012C854 LWC1 $f0, $0000(t5) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); + // @0012C858 BEQ zero, zero, $0012bbcc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227724u; + } + // @0012C85C SWC1 $f0, $008c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (140u + this.ee.sp.UL0)); + } + + public virtual void funct0012c848() + { + this.ee.pc = 1230944u; + // @0012C848 LUI t5, $0038 + this.ee.t5.SD0 = 3670016; + // @0012C84C SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + // @0012C850 ADDIU t5, t5, $8364 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + -31900))); + // @0012C854 LWC1 $f0, $0000(t5) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); + // @0012C858 BEQ zero, zero, $0012bbcc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227724u; + } + // @0012C85C SWC1 $f0, $008c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (140u + this.ee.sp.UL0)); + } + + public virtual void funct0012c858() + { + this.ee.pc = 1230944u; + // @0012C858 BEQ zero, zero, $0012bbcc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227724u; + } + // @0012C85C SWC1 $f0, $008c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (140u + this.ee.sp.UL0)); + } + + public virtual void funct0012c860() + { + this.ee.pc = 1230968u; + // @0012C860 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012C864 LW t3, $0214(sp) + MobUt.LW(this.ee, this.ee.t3, (532u + this.ee.sp.UL0)); + // @0012C868 LHU t7, $0010(t7) + MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); + // @0012C86C SLT t6, t3, t7 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t3.SD0 < this.ee.t7.SD0)); + // @0012C870 BEQ t6, zero, $0012c8b4 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231028u; + } + // @0012C874 LW t4, $0214(sp) + MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); + } + + public virtual void funct0012c880() + { + this.ee.pc = 1231028u; + // @0012C880 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012C884 LQC2 vf5, $0000(s7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s7.UL0)); + // @0012C888 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012C88C LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012C890 LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012C894 LQC2 vf4, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); + // @0012C898 VMULAx.xyzw ACC, vf1, vf5x + // @0012C89C VMADDAy.xyzw ACC, vf2, vf5y + // @0012C8A0 VMADDAz.xyzw ACC, vf3, vf5z + // @0012C8A4 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C8A8 SQC2 vf5, $0000(s3) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s3.UL0)); + // @0012C8AC BEQ zero, zero, $0012c838 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230904u; + } + // @0012C8B0 NOP + MobUt.Latency(); + } + + public virtual void funct0012c8b4() + { + this.ee.pc = 1231044u; + // @0012C8B4 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012C8B8 SUBU t7, t4, t7 + this.ee.t7.SD0 = ((int)((this.ee.t4.UD0 - this.ee.t7.UD0))); + // @0012C8BC BEQ zero, zero, $0012c880 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230976u; + } + // @0012C8C0 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012c8c4() + { + this.ee.pc = 1231056u; + // @0012C8C4 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012C8C8 BEQ zero, zero, $0012c7ac + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230764u; + } + // @0012C8CC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012c8d0() + { + this.ee.pc = 1231072u; + // @0012C8D0 LHU t4, $0010(t5) + MobUt.LHU(this.ee, this.ee.t4, (16u + this.ee.t5.UL0)); + // @0012C8D4 SLT t7, s2, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t4.SD0)); + // @0012C8D8 BEQ t7, zero, $0012ca68 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231464u; + } + // @0012C8DC ADDIU s3, sp, $0090 + this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 144))); + } + + public virtual void funct0012c8e0() + { + this.ee.pc = 1231088u; + // @0012C8E0 LW t7, $0024(s5) + MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s5.UL0)); + // @0012C8E4 ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012C8E8 BEQL s3, t6, $0012c8fc + if ((this.ee.s3.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1231100u; + // @0012C8EC LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + } + } + + public virtual void funct0012c8e8() + { + this.ee.pc = 1231088u; + // @0012C8E8 BEQL s3, t6, $0012c8fc + if ((this.ee.s3.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1231100u; + // @0012C8EC LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + } + } + + public virtual void funct0012c8f0() + { + this.ee.pc = 1231116u; + // @0012C8F0 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012C8F4 SQ t0, $0000(s3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @0012C8F8 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @0012C8FC ADDIU t6, t6, $8364 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -31900))); + // @0012C900 LWC1 $f0, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @0012C904 BEQ v0, zero, $0012ca60 + if ((this.ee.v0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231456u; + } + // @0012C908 SWC1 $f0, $009c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); + } + + public virtual void funct0012c90c() + { + this.ee.pc = 1231136u; + // @0012C90C LW t6, $0004(s0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); + // @0012C910 LHU t6, $0010(t6) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); + // @0012C914 SLT t7, v1, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.v1.SD0 < this.ee.t6.SD0)); + // @0012C918 BEQ t7, zero, $0012ca50 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231440u; + } + // @0012C91C ADDIU t5, sp, $0040 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 64))); + } + + public virtual void funct0012c928() + { + this.ee.pc = 1231228u; + // @0012C928 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012C92C ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012C930 ADDIU t7, t6, $0030 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012C934 LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012C938 LQC2 vf1, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); + // @0012C93C LQC2 vf2, $0010(t5) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t5.UL0)); + // @0012C940 LQC2 vf3, $0020(t5) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t5.UL0)); + // @0012C944 LQC2 vf4, $0030(t5) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t5.UL0)); + // @0012C948 VMULAx.xyzw ACC, vf1, vf5x + // @0012C94C VMADDAy.xyzw ACC, vf2, vf5y + // @0012C950 VMADDAz.xyzw ACC, vf3, vf5z + // @0012C954 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C958 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012C95C ADDIU a2, sp, $0130 + this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 304))); + // @0012C960 LQ t0, $0000(t8) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); + // @0012C964 SQ t0, $0000(a2) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a2.UL[0])); + // @0012C968 SQ t8, $0290(sp) + MobUt.SQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); + // @0012C96C DADDU a1, v0, zero + this.ee.a1.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); + // @0012C970 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0012C974 JAL $00127e20 + this.ee.ra.UL0 = 1231228u; + this.ee.pc = 1211936u; + // @0012C978 DADDU a3, s3, zero + this.ee.a3.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012c97c() + { + this.ee.pc = 1231244u; + // @0012C97C LQ t8, $0290(sp) + MobUt.LQ(this.ee, this.ee.t8, (656u + this.ee.sp.UL[0])); + // @0012C980 LW t7, $0214(sp) + MobUt.LW(this.ee, this.ee.t7, (532u + this.ee.sp.UL0)); + // @0012C984 BGEZL t7, $0012c9dc + if ((this.ee.t7.SD0 >= 0)) + { + this.ee.pc = 1231324u; + // @0012C988 LW t6, $0004(s0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012c980() + { + this.ee.pc = 1231244u; + // @0012C980 LW t7, $0214(sp) + MobUt.LW(this.ee, this.ee.t7, (532u + this.ee.sp.UL0)); + // @0012C984 BGEZL t7, $0012c9dc + if ((this.ee.t7.SD0 >= 0)) + { + this.ee.pc = 1231324u; + // @0012C988 LW t6, $0004(s0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012c98c() + { + this.ee.pc = 1231296u; + // @0012C98C ADDIU t7, sp, $0080 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012C990 LQC2 vf5, $0000(s3) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s3.UL0)); + // @0012C994 LQC2 vf1, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @0012C998 LQC2 vf2, $0010(sp) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.sp.UL0)); + // @0012C99C LQC2 vf3, $0020(sp) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.sp.UL0)); + // @0012C9A0 LQC2 vf4, $0030(sp) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.sp.UL0)); + // @0012C9A4 VMULAx.xyzw ACC, vf1, vf5x + // @0012C9A8 VMADDAy.xyzw ACC, vf2, vf5y + // @0012C9AC VMADDAz.xyzw ACC, vf3, vf5z + // @0012C9B0 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012C9B4 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012C9B8 BEQ t7, t8, $0012c9cc + if ((this.ee.t7.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1231308u; + } + // @0012C9BC LUI t4, $0038 + this.ee.t4.SD0 = 3670016; + } + + public virtual void funct0012c9c0() + { + this.ee.pc = 1231324u; + // @0012C9C0 LQ t0, $0000(t8) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); + // @0012C9C4 SQ t0, $0000(t7) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012C9C8 LUI t4, $0038 + this.ee.t4.SD0 = 3670016; + // @0012C9CC SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + // @0012C9D0 ADDIU t4, t4, $8364 + this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + -31900))); + // @0012C9D4 BEQ zero, zero, $0012c858 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230936u; + } + // @0012C9D8 LWC1 $f0, $0000(t4) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t4.UL0)); + } + + public virtual void funct0012c9cc() + { + this.ee.pc = 1231324u; + // @0012C9CC SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + // @0012C9D0 ADDIU t4, t4, $8364 + this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + -31900))); + // @0012C9D4 BEQ zero, zero, $0012c858 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1230936u; + } + // @0012C9D8 LWC1 $f0, $0000(t4) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t4.UL0)); + } + + public virtual void funct0012c9dc() + { + this.ee.pc = 1231344u; + // @0012C9DC LW t4, $0214(sp) + MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); + // @0012C9E0 LHU t6, $0010(t6) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); + // @0012C9E4 SLT t7, t4, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.t6.SD0)); + // @0012C9E8 BEQ t7, zero, $0012ca3c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231420u; + } + // @0012C9EC ADDIU t5, sp, $0080 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); + } + + public virtual void funct0012c9f0() + { + this.ee.pc = 1231404u; + // @0012C9F0 LW t6, $002c(s5) + MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); + // @0012C9F4 SLL t7, t4, 6 + MobUt.SLL(this.ee.t7, this.ee.t4, 6); + // @0012C9F8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012C9FC LQC2 vf5, $0000(s3) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s3.UL0)); + // @0012CA00 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012CA04 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012CA08 LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012CA0C LQC2 vf4, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); + // @0012CA10 VMULAx.xyzw ACC, vf1, vf5x + // @0012CA14 VMADDAy.xyzw ACC, vf2, vf5y + // @0012CA18 VMADDAz.xyzw ACC, vf3, vf5z + // @0012CA1C VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012CA20 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012CA24 BEQL t5, t8, $0012c9cc + if ((this.ee.t5.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1231308u; + // @0012CA28 LUI t4, $0038 + this.ee.t4.SD0 = 3670016; + } + } + + public virtual void funct0012c9f8() + { + this.ee.pc = 1231404u; + // @0012C9F8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012C9FC LQC2 vf5, $0000(s3) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.s3.UL0)); + // @0012CA00 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012CA04 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012CA08 LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012CA0C LQC2 vf4, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); + // @0012CA10 VMULAx.xyzw ACC, vf1, vf5x + // @0012CA14 VMADDAy.xyzw ACC, vf2, vf5y + // @0012CA18 VMADDAz.xyzw ACC, vf3, vf5z + // @0012CA1C VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012CA20 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012CA24 BEQL t5, t8, $0012c9cc + if ((this.ee.t5.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1231308u; + // @0012CA28 LUI t4, $0038 + this.ee.t4.SD0 = 3670016; + } + } + + public virtual void funct0012ca2c() + { + this.ee.pc = 1231420u; + // @0012CA2C LQ t0, $0000(t8) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); + // @0012CA30 SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012CA34 BEQ zero, zero, $0012c9cc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231308u; + } + // @0012CA38 LUI t4, $0038 + this.ee.t4.SD0 = 3670016; + } + + public virtual void funct0012ca3c() + { + this.ee.pc = 1231440u; + // @0012CA3C LW t3, $0214(sp) + MobUt.LW(this.ee, this.ee.t3, (532u + this.ee.sp.UL0)); + // @0012CA40 SUBU t7, t3, t6 + this.ee.t7.SD0 = ((int)((this.ee.t3.UD0 - this.ee.t6.UD0))); + // @0012CA44 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012CA48 BEQ zero, zero, $0012c9f8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231352u; + } + // @0012CA4C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012ca50() + { + this.ee.pc = 1231456u; + // @0012CA50 SUBU t7, v1, t6 + this.ee.t7.SD0 = ((int)((this.ee.v1.UD0 - this.ee.t6.UD0))); + // @0012CA54 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012CA58 BEQ zero, zero, $0012c928 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231144u; + } + // @0012CA5C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012ca60() + { + this.ee.pc = 1231464u; + // @0012CA60 BEQ zero, zero, $0012c980 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231232u; + } + // @0012CA64 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + } + + public virtual void funct0012ca68() + { + this.ee.pc = 1231492u; + // @0012CA68 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + // @0012CA6C SUBU t7, s2, t4 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); + // @0012CA70 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012CA74 ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012CA78 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012CA7C BEQ zero, zero, $0012c8e8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231080u; + } + // @0012CA80 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012ca88() + { + this.ee.pc = 1231520u; + // @0012CA88 ADDIU a1, sp, $0040 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 64))); + // @0012CA8C LW t3, $0214(sp) + MobUt.LW(this.ee, this.ee.t3, (532u + this.ee.sp.UL0)); + // @0012CA90 LHU t6, $0010(t6) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); + // @0012CA94 SLT t7, t3, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t3.SD0 < this.ee.t6.SD0)); + // @0012CA98 BEQ t7, zero, $0012cadc + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231580u; + } + // @0012CA9C DADDU t5, a1, zero + this.ee.t5.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012caa0() + { + this.ee.pc = 1231540u; + // @0012CAA0 LW t6, $002c(s5) + MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); + // @0012CAA4 SLL t7, t3, 6 + MobUt.SLL(this.ee.t7, this.ee.t3, 6); + // @0012CAA8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012CAAC BEQ t5, t6, $0012ba74 + if ((this.ee.t5.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1227380u; + } + // @0012CAB0 NOP + MobUt.Latency(); + } + + public virtual void funct0012caa8() + { + this.ee.pc = 1231540u; + // @0012CAA8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012CAAC BEQ t5, t6, $0012ba74 + if ((this.ee.t5.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1227380u; + } + // @0012CAB0 NOP + MobUt.Latency(); + } + + public virtual void funct0012cab4() + { + this.ee.pc = 1231580u; + // @0012CAB4 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012CAB8 LQ t1, $0010(t6) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); + // @0012CABC LQ t2, $0020(t6) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); + // @0012CAC0 LQ t3, $0030(t6) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); + // @0012CAC4 SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012CAC8 SQ t1, $0010(t5) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); + // @0012CACC SQ t2, $0020(t5) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); + // @0012CAD0 SQ t3, $0030(t5) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); + // @0012CAD4 BEQ zero, zero, $0012ba74 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1227380u; + } + // @0012CAD8 NOP + MobUt.Latency(); + } + + public virtual void funct0012cadc() + { + this.ee.pc = 1231600u; + // @0012CADC LW t4, $0214(sp) + MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); + // @0012CAE0 SUBU t7, t4, t6 + this.ee.t7.SD0 = ((int)((this.ee.t4.UD0 - this.ee.t6.UD0))); + // @0012CAE4 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012CAE8 BEQ zero, zero, $0012caa8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231528u; + } + // @0012CAEC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012caf0() + { + this.ee.pc = 1231620u; + // @0012CAF0 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012CAF4 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012CAF8 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012CAFC BEQ t7, zero, $0012d218 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233432u; + } + // @0012CB00 ADDIU t3, sp, $0090 + this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 144))); + } + + public virtual void funct0012cb04() + { + this.ee.pc = 1231636u; + // @0012CB04 LW t7, $0024(s5) + MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s5.UL0)); + // @0012CB08 ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012CB0C BEQ t3, t6, $0012cb24 + if ((this.ee.t3.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1231652u; + } + // @0012CB10 LUI t5, $0038 + this.ee.t5.SD0 = 3670016; + } + + public virtual void funct0012cb0c() + { + this.ee.pc = 1231636u; + // @0012CB0C BEQ t3, t6, $0012cb24 + if ((this.ee.t3.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1231652u; + } + // @0012CB10 LUI t5, $0038 + this.ee.t5.SD0 = 3670016; + } + + public virtual void funct0012cb14() + { + this.ee.pc = 1231684u; + // @0012CB14 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012CB18 SQ t0, $0000(t3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); + // @0012CB1C LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012CB20 LUI t5, $0038 + this.ee.t5.SD0 = 3670016; + // @0012CB24 ADDIU t5, t5, $8364 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + -31900))); + // @0012CB28 LWC1 $f0, $0000(t5) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t5.UL0)); + // @0012CB2C SWC1 $f0, $009c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (156u + this.ee.sp.UL0)); + // @0012CB30 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012CB34 LW t4, $0214(sp) + MobUt.LW(this.ee, this.ee.t4, (532u + this.ee.sp.UL0)); + // @0012CB38 SLT t7, t4, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.SD0 < this.ee.t6.SD0)); + // @0012CB3C BEQ t7, zero, $0012d200 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233408u; + } + // @0012CB40 SLL t5, t4, 6 + MobUt.SLL(this.ee.t5, this.ee.t4, 6); + } + + public virtual void funct0012cb44() + { + this.ee.pc = 1231756u; + // @0012CB44 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012CB48 SW t5, $0250(sp) + MobUt.SW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); + // @0012CB4C ADDU t6, t7, t5 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); + // @0012CB50 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012CB54 DADDU s7, t8, zero + this.ee.s7.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); + // @0012CB58 LQC2 vf5, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); + // @0012CB5C LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012CB60 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012CB64 LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012CB68 LQC2 vf4, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); + // @0012CB6C VMULAx.xyzw ACC, vf1, vf5x + // @0012CB70 VMADDAy.xyzw ACC, vf2, vf5y + // @0012CB74 VMADDAz.xyzw ACC, vf3, vf5z + // @0012CB78 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012CB7C SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012CB80 ADDIU t6, sp, $0080 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012CB84 BEQL t6, t8, $0012cb98 + if ((this.ee.t6.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1231768u; + // @0012CB88 LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012cb50() + { + this.ee.pc = 1231756u; + // @0012CB50 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012CB54 DADDU s7, t8, zero + this.ee.s7.UD0 = (this.ee.t8.UD0 + this.ee.r0.UD0); + // @0012CB58 LQC2 vf5, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); + // @0012CB5C LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012CB60 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012CB64 LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012CB68 LQC2 vf4, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t6.UL0)); + // @0012CB6C VMULAx.xyzw ACC, vf1, vf5x + // @0012CB70 VMADDAy.xyzw ACC, vf2, vf5y + // @0012CB74 VMADDAz.xyzw ACC, vf3, vf5z + // @0012CB78 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012CB7C SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012CB80 ADDIU t6, sp, $0080 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012CB84 BEQL t6, t8, $0012cb98 + if ((this.ee.t6.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1231768u; + // @0012CB88 LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012cb8c() + { + this.ee.pc = 1231788u; + // @0012CB8C LQ t0, $0000(t8) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); + // @0012CB90 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012CB94 LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + // @0012CB98 ADDIU s3, sp, $0040 + this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 64))); + // @0012CB9C LW t3, $0250(sp) + MobUt.LW(this.ee, this.ee.t3, (592u + this.ee.sp.UL0)); + // @0012CBA0 ADDU t7, t7, t3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t3.SD0))); + // @0012CBA4 BEQ s3, t7, $0012cbcc + if ((this.ee.s3.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1231820u; + } + // @0012CBA8 NOP + MobUt.Latency(); + } + + public virtual void funct0012cbac() + { + this.ee.pc = 1231968u; + // @0012CBAC LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012CBB0 LQ t1, $0010(t7) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); + // @0012CBB4 LQ t2, $0020(t7) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); + // @0012CBB8 LQ t3, $0030(t7) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); + // @0012CBBC SQ t0, $0000(s3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @0012CBC0 SQ t1, $0010(s3) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s3.UL[0])); + // @0012CBC4 SQ t2, $0020(s3) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s3.UL[0])); + // @0012CBC8 SQ t3, $0030(s3) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.s3.UL[0])); + // @0012CBCC LQ t0, $0000(s3) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @0012CBD0 LQ t1, $0010(s3) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.s3.UL[0])); + // @0012CBD4 LQ t2, $0020(s3) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.s3.UL[0])); + // @0012CBD8 QMFC2 t3, vf0 + MobUt.QMFC2(this.ee.t3, this.ee.VF[0]); + // @0012CBDC LQC2 vf4, $0030(s3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); + // @0012CBE0 PEXTLW t4, t1, t0 + this.ee.t4.UL[0] = this.ee.t0.UL[0]; + this.ee.t4.UL[1] = this.ee.t1.UL[0]; + this.ee.t4.UL[2] = this.ee.t0.UL[1]; + this.ee.t4.UL[3] = this.ee.t1.UL[1]; + // @0012CBE4 PEXTUW t5, t1, t0 + this.ee.t5.UL[0] = this.ee.t0.UL[2]; + this.ee.t5.UL[1] = this.ee.t1.UL[2]; + this.ee.t5.UL[2] = this.ee.t0.UL[3]; + this.ee.t5.UL[3] = this.ee.t1.UL[3]; + // @0012CBE8 PEXTLW t6, t3, t2 + this.ee.t6.UL[0] = this.ee.t2.UL[0]; + this.ee.t6.UL[1] = this.ee.t3.UL[0]; + this.ee.t6.UL[2] = this.ee.t2.UL[1]; + this.ee.t6.UL[3] = this.ee.t3.UL[1]; + // @0012CBEC PEXTUW t7, t3, t2 + this.ee.t7.UL[0] = this.ee.t2.UL[2]; + this.ee.t7.UL[1] = this.ee.t3.UL[2]; + this.ee.t7.UL[2] = this.ee.t2.UL[3]; + this.ee.t7.UL[3] = this.ee.t3.UL[3]; + // @0012CBF0 PCPYLD t0, t6, t4 + this.ee.t0.UD1 = this.ee.t6.UD0; + this.ee.t0.UD0 = this.ee.t4.UD0; + // @0012CBF4 PCPYUD t1, t4, t6 + this.ee.t1.UD0 = this.ee.t4.UD1; + this.ee.t1.UD1 = this.ee.t6.UD1; + // @0012CBF8 PCPYLD t2, t7, t5 + this.ee.t2.UD1 = this.ee.t7.UD0; + this.ee.t2.UD0 = this.ee.t5.UD0; + // @0012CBFC QMTC2 t0, vf1 + MobUt.QMTC2(this.ee.t0, this.ee.VF[1]); + // @0012CC00 QMTC2 t1, vf2 + MobUt.QMTC2(this.ee.t1, this.ee.VF[2]); + // @0012CC04 QMTC2 t2, vf3 + MobUt.QMTC2(this.ee.t2, this.ee.VF[3]); + // @0012CC08 VMULAx.xyz ACC, vf1, vf4x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[4].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[4].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[4].x); + // @0012CC0C VMADDAy.xyz ACC, vf2, vf4y + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[4].y); + // @0012CC10 VMADDz.xyz vf4, vf3, vf4z + this.ee.VF[4].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[4].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[4].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[4].z); + // @0012CC14 VSUB.xyz vf4, vf0, vf4 + this.ee.VF[4].x = (this.ee.VF[0].x - this.ee.VF[4].x); + this.ee.VF[4].y = (this.ee.VF[0].y - this.ee.VF[4].y); + this.ee.VF[4].z = (this.ee.VF[0].z - this.ee.VF[4].z); + // @0012CC18 SQ t0, $0000(s3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @0012CC1C SQ t1, $0010(s3) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.s3.UL[0])); + // @0012CC20 SQ t2, $0020(s3) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.s3.UL[0])); + // @0012CC24 SQC2 vf4, $0030(s3) + MobUt.SQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); + // @0012CC28 ADDIU t4, sp, $0080 + this.ee.t4.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012CC2C LQC2 vf5, $0000(t4) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t4.UL0)); + // @0012CC30 LQC2 vf1, $0000(s3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); + // @0012CC34 LQC2 vf2, $0010(s3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); + // @0012CC38 LQC2 vf3, $0020(s3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); + // @0012CC3C LQC2 vf4, $0030(s3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); + // @0012CC40 VMULAx.xyzw ACC, vf1, vf5x + // @0012CC44 VMADDAy.xyzw ACC, vf2, vf5y + // @0012CC48 VMADDAz.xyzw ACC, vf3, vf5z + // @0012CC4C VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012CC50 SQC2 vf5, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t8.UL0)); + // @0012CC54 ADDIU t5, sp, $00a0 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 160))); + // @0012CC58 BEQ t5, t8, $0012cc6c + if ((this.ee.t5.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1231980u; + } + // @0012CC5C LW a2, $0220(sp) + MobUt.LW(this.ee, this.ee.a2, (544u + this.ee.sp.UL0)); + } + + public virtual void funct0012cc60() + { + this.ee.pc = 1232004u; + // @0012CC60 LQ t0, $0000(s7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s7.UL[0])); + // @0012CC64 SQ t0, $0000(t5) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012CC68 LW a2, $0220(sp) + MobUt.LW(this.ee, this.ee.a2, (544u + this.ee.sp.UL0)); + // @0012CC6C ADDIU a3, sp, $0110 + this.ee.a3.SD0 = ((int)((this.ee.sp.SD0 + 272))); + // @0012CC70 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @0012CC74 DADDU a1, s5, zero + this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); + // @0012CC78 DADDU t0, s3, zero + this.ee.t0.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); + // @0012CC7C JAL $00128de8 + this.ee.ra.UL0 = 1232004u; + this.ee.pc = 1215976u; + // @0012CC80 ADDIU t1, sp, $00b0 + this.ee.t1.SD0 = ((int)((this.ee.sp.SD0 + 176))); + } + + public virtual void funct0012cc84() + { + this.ee.pc = 1232016u; + // @0012CC84 LW t6, $0218(sp) + MobUt.LW(this.ee, this.ee.t6, (536u + this.ee.sp.UL0)); + // @0012CC88 BEQ t6, zero, $0012d12c + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233196u; + } + // @0012CC8C ADDIU t7, zero, $0004 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 4))); + } + + public virtual void funct0012cc90() + { + this.ee.pc = 1232028u; + // @0012CC90 LBU t6, $0000(t6) + MobUt.LBU(this.ee, this.ee.t6, (0u + this.ee.t6.UL0)); + // @0012CC94 BNEL t6, t7, $0012d130 + if ((this.ee.t6.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1233200u; + // @0012CC98 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012cc9c() + { + this.ee.pc = 1232056u; + // @0012CC9C LW t7, $0218(sp) + MobUt.LW(this.ee, this.ee.t7, (536u + this.ee.sp.UL0)); + // @0012CCA0 LW t6, $0004(s0) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.s0.UL0)); + // @0012CCA4 LHU t5, $0004(t7) + MobUt.LHU(this.ee, this.ee.t5, (4u + this.ee.t7.UL0)); + // @0012CCA8 LHU t6, $0010(t6) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t6.UL0)); + // @0012CCAC SLT t7, t5, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); + // @0012CCB0 BEQ t7, zero, $0012d120 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233184u; + } + // @0012CCB4 SUBU t7, t5, t6 + this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012ccc0() + { + this.ee.pc = 1232144u; + // @0012CCC0 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012CCC4 ADDIU t7, t6, $0030 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012CCC8 LQC2 vf5, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t7.UL0)); + // @0012CCCC LQC2 vf1, $0000(s3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s3.UL0)); + // @0012CCD0 LQC2 vf2, $0010(s3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.s3.UL0)); + // @0012CCD4 LQC2 vf3, $0020(s3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.s3.UL0)); + // @0012CCD8 LQC2 vf4, $0030(s3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.s3.UL0)); + // @0012CCDC VMULAx.xyz ACC, vf1, vf5x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); + // @0012CCE0 VMADDAy.xyz ACC, vf2, vf5y + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); + // @0012CCE4 VMADDAz.xyz ACC, vf3, vf5z + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); + // @0012CCE8 VMADDw.xyz vf5, vf4, vf0w + this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); + this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); + this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); + // @0012CCEC VMOVE.w vf5, vf0 + this.ee.VF[5].w = this.ee.VF[0].w; + // @0012CCF0 SQC2 vf5, $0000(s7) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.s7.UL0)); + // @0012CCF4 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012CCF8 LW t6, $0014(s0) + MobUt.LW(this.ee, this.ee.t6, (20u + this.ee.s0.UL0)); + // @0012CCFC LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012CD00 ADDU t6, t6, s8 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s8.SD0))); + // @0012CD04 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012CD08 BEQ t7, zero, $0012d104 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233156u; + } + // @0012CD0C SW t6, $0230(sp) + MobUt.SW(this.ee, this.ee.t6, (560u + this.ee.sp.UL0)); + } + + public virtual void funct0012cd10() + { + this.ee.pc = 1232164u; + // @0012CD10 LW a0, $0014(s5) + MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); + // @0012CD14 LW t7, $0000(a0) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); + // @0012CD18 LW v0, $0020(t7) + MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); + // @0012CD1C JALR ra, v0 + this.ee.ra.UD0 = 1232164u; + this.ee.pc = this.ee.v0.UL0; + // @0012CD20 SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + } + + public virtual void funct0012cd24() + { + this.ee.pc = 1232200u; + // @0012CD24 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012CD28 ADDU v0, v0, s3 + this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.s3.SD0))); + // @0012CD2C LW t3, $0230(sp) + MobUt.LW(this.ee, this.ee.t3, (560u + this.ee.sp.UL0)); + // @0012CD30 LWC1 $f0, $001c(v0) + MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); + // @0012CD34 LWC1 $f1, $0000(t3) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t3.UL0)); + // @0012CD38 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012CD3C SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012CD40 BEQ t7, zero, $0012d0f0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233136u; + } + // @0012CD44 MUL.S $f12, $f1, $f0 + this.ee.fpr[12].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct0012cd2c() + { + this.ee.pc = 1232200u; + // @0012CD2C LW t3, $0230(sp) + MobUt.LW(this.ee, this.ee.t3, (560u + this.ee.sp.UL0)); + // @0012CD30 LWC1 $f0, $001c(v0) + MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); + // @0012CD34 LWC1 $f1, $0000(t3) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t3.UL0)); + // @0012CD38 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012CD3C SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012CD40 BEQ t7, zero, $0012d0f0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233136u; + } + // @0012CD44 MUL.S $f12, $f1, $f0 + this.ee.fpr[12].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct0012cd48() + { + this.ee.pc = 1232224u; + // @0012CD48 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012CD4C ADDU a3, t7, s3 + this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012CD50 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012CD54 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012CD58 BEQL t7, zero, $0012d0d8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233112u; + // @0012CD5C LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012cd50() + { + this.ee.pc = 1232224u; + // @0012CD50 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012CD54 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012CD58 BEQL t7, zero, $0012d0d8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233112u; + // @0012CD5C LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012cd60() + { + this.ee.pc = 1232268u; + // @0012CD60 LW t7, $0020(s5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); + // @0012CD64 ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012CD68 LWC1 $f14, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t6.UL0)); + // @0012CD6C ADDIU a0, sp, $00a0 + this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); + // @0012CD70 MTC1 zero, $f13 + this.ee.fpr[13].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @0012CD74 ADDIU a1, sp, $00b0 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); + // @0012CD78 DADDU t1, s7, zero + this.ee.t1.UD0 = (this.ee.s7.UD0 + this.ee.r0.UD0); + // @0012CD7C DADDU a2, zero, zero + this.ee.a2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @0012CD80 DADDU t0, zero, zero + this.ee.t0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @0012CD84 JAL $00124a88 + this.ee.ra.UL0 = 1232268u; + this.ee.pc = 1198728u; + // @0012CD88 MOV.S $f15, $f13 + this.ee.fpr[15].f = this.ee.fpr[13].f; + } + + public virtual void funct0012cd68() + { + this.ee.pc = 1232268u; + // @0012CD68 LWC1 $f14, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t6.UL0)); + // @0012CD6C ADDIU a0, sp, $00a0 + this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); + // @0012CD70 MTC1 zero, $f13 + this.ee.fpr[13].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @0012CD74 ADDIU a1, sp, $00b0 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); + // @0012CD78 DADDU t1, s7, zero + this.ee.t1.UD0 = (this.ee.s7.UD0 + this.ee.r0.UD0); + // @0012CD7C DADDU a2, zero, zero + this.ee.a2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @0012CD80 DADDU t0, zero, zero + this.ee.t0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @0012CD84 JAL $00124a88 + this.ee.ra.UL0 = 1232268u; + this.ee.pc = 1198728u; + // @0012CD88 MOV.S $f15, $f13 + this.ee.fpr[15].f = this.ee.fpr[13].f; + } + + public virtual void funct0012cd84() + { + this.ee.pc = 1232268u; + // @0012CD84 JAL $00124a88 + this.ee.ra.UL0 = 1232268u; + this.ee.pc = 1198728u; + // @0012CD88 MOV.S $f15, $f13 + this.ee.fpr[15].f = this.ee.fpr[13].f; + } + + public virtual void funct0012cd8c() + { + this.ee.pc = 1232284u; + // @0012CD8C LUI t7, $0040 + this.ee.t7.SD0 = 4194304; + // @0012CD90 AND t7, s4, t7 + this.ee.t7.UD0 = (this.ee.s4.UD0 & this.ee.t7.UD0); + // @0012CD94 BEQL t7, zero, $0012cddc + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232348u; + // @0012CD98 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012cd9c() + { + this.ee.pc = 1232304u; + // @0012CD9C LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012CDA0 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012CDA4 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012CDA8 BEQ t7, zero, $0012d0c8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233096u; + } + // @0012CDAC SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012cdb0() + { + this.ee.pc = 1232328u; + // @0012CDB0 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012CDB4 ADDU a0, t7, s3 + this.ee.a0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012CDB8 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012CDBC SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012CDC0 BEQL t7, zero, $0012d0b0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233072u; + // @0012CDC4 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012cdc8() + { + this.ee.pc = 1232344u; + // @0012CDC8 LW t7, $0020(s5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); + // @0012CDCC ADDU a1, t7, s8 + this.ee.a1.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012CDD0 JAL $0011b840 + this.ee.ra.UL0 = 1232344u; + this.ee.pc = 1161280u; + // @0012CDD4 NOP + MobUt.Latency(); + } + + public virtual void funct0012cdd8() + { + this.ee.pc = 1232364u; + // @0012CDD8 LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012CDDC LHU t7, $0010(t7) + MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); + // @0012CDE0 SLT t6, s2, t7 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); + // @0012CDE4 BEQ t6, zero, $0012d0a0 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233056u; + } + // @0012CDE8 SUBU t7, s2, t7 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); + } + + public virtual void funct0012cddc() + { + this.ee.pc = 1232364u; + // @0012CDDC LHU t7, $0010(t7) + MobUt.LHU(this.ee, this.ee.t7, (16u + this.ee.t7.UL0)); + // @0012CDE0 SLT t6, s2, t7 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t7.SD0)); + // @0012CDE4 BEQ t6, zero, $0012d0a0 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233056u; + } + // @0012CDE8 SUBU t7, s2, t7 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t7.UD0))); + } + + public virtual void funct0012cdec() + { + this.ee.pc = 1232412u; + // @0012CDEC LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012CDF0 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012CDF4 LWC1 $f0, $0090(sp) + MobUt.LWC1(this.ee, this.ee.fpr[0], (144u + this.ee.sp.UL0)); + // @0012CDF8 SWC1 $f0, $0030(t6) + MobUt.SWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t6.UL0)); + // @0012CDFC LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012CE00 LW t6, $0008(s0) + MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); + // @0012CE04 LW t4, $0250(sp) + MobUt.LW(this.ee, this.ee.t4, (592u + this.ee.sp.UL0)); + // @0012CE08 LHU t5, $0010(t7) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t7.UL0)); + // @0012CE0C ADDU t3, t6, t4 + this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t4.SD0))); + // @0012CE10 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012CE14 BEQ t7, zero, $0012d08c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233036u; + } + // @0012CE18 ADDU t4, t6, s3 + this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); + } + + public virtual void funct0012cdf4() + { + this.ee.pc = 1232412u; + // @0012CDF4 LWC1 $f0, $0090(sp) + MobUt.LWC1(this.ee, this.ee.fpr[0], (144u + this.ee.sp.UL0)); + // @0012CDF8 SWC1 $f0, $0030(t6) + MobUt.SWC1(this.ee, this.ee.fpr[0], (48u + this.ee.t6.UL0)); + // @0012CDFC LW t7, $0004(s0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.s0.UL0)); + // @0012CE00 LW t6, $0008(s0) + MobUt.LW(this.ee, this.ee.t6, (8u + this.ee.s0.UL0)); + // @0012CE04 LW t4, $0250(sp) + MobUt.LW(this.ee, this.ee.t4, (592u + this.ee.sp.UL0)); + // @0012CE08 LHU t5, $0010(t7) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t7.UL0)); + // @0012CE0C ADDU t3, t6, t4 + this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t4.SD0))); + // @0012CE10 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012CE14 BEQ t7, zero, $0012d08c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233036u; + } + // @0012CE18 ADDU t4, t6, s3 + this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s3.SD0))); + } + + public virtual void funct0012ce1c() + { + this.ee.pc = 1232544u; + // @0012CE1C LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012CE20 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012CE24 ADDIU t5, sp, $0130 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 304))); + // @0012CE28 LQC2 vf1, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); + // @0012CE2C LQC2 vf2, $0010(t3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); + // @0012CE30 LQC2 vf3, $0020(t3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); + // @0012CE34 LQC2 vf4, $0030(t3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); + // @0012CE38 LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012CE3C LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012CE40 LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012CE44 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012CE48 VMULAx.xyzw ACC, vf1, vf5x + // @0012CE4C VMADDAy.xyzw ACC, vf2, vf5y + // @0012CE50 VMADDAz.xyzw ACC, vf3, vf5z + // @0012CE54 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012CE58 VMULAx.xyzw ACC, vf1, vf6x + // @0012CE5C VMADDAy.xyzw ACC, vf2, vf6y + // @0012CE60 VMADDAz.xyzw ACC, vf3, vf6z + // @0012CE64 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012CE68 VMULAx.xyzw ACC, vf1, vf7x + // @0012CE6C VMADDAy.xyzw ACC, vf2, vf7y + // @0012CE70 VMADDAz.xyzw ACC, vf3, vf7z + // @0012CE74 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012CE78 VMULAx.xyzw ACC, vf1, vf8x + // @0012CE7C VMADDAy.xyzw ACC, vf2, vf8y + // @0012CE80 VMADDAz.xyzw ACC, vf3, vf8z + // @0012CE84 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012CE88 SQC2 vf5, $0000(t5) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); + // @0012CE8C SQC2 vf6, $0010(t5) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t5.UL0)); + // @0012CE90 SQC2 vf7, $0020(t5) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t5.UL0)); + // @0012CE94 SQC2 vf8, $0030(t5) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t5.UL0)); + // @0012CE98 BEQL t4, t5, $0012cec4 + if ((this.ee.t4.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1232580u; + // @0012CE9C LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012ce24() + { + this.ee.pc = 1232544u; + // @0012CE24 ADDIU t5, sp, $0130 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 304))); + // @0012CE28 LQC2 vf1, $0000(t3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t3.UL0)); + // @0012CE2C LQC2 vf2, $0010(t3) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t3.UL0)); + // @0012CE30 LQC2 vf3, $0020(t3) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t3.UL0)); + // @0012CE34 LQC2 vf4, $0030(t3) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.t3.UL0)); + // @0012CE38 LQC2 vf5, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t6.UL0)); + // @0012CE3C LQC2 vf6, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[6], (16u + this.ee.t6.UL0)); + // @0012CE40 LQC2 vf7, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[7], (32u + this.ee.t6.UL0)); + // @0012CE44 LQC2 vf8, $0030(t6) + MobUt.LQC2(this.ee, this.ee.VF[8], (48u + this.ee.t6.UL0)); + // @0012CE48 VMULAx.xyzw ACC, vf1, vf5x + // @0012CE4C VMADDAy.xyzw ACC, vf2, vf5y + // @0012CE50 VMADDAz.xyzw ACC, vf3, vf5z + // @0012CE54 VMADDw.xyzw vf5, vf4, vf5w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[5].x, this.ee.VF[2], this.ee.VF[5].y, this.ee.VF[3], this.ee.VF[5].z, this.ee.VF[4], this.ee.VF[5].w, this.ee.VF[5]); + // @0012CE58 VMULAx.xyzw ACC, vf1, vf6x + // @0012CE5C VMADDAy.xyzw ACC, vf2, vf6y + // @0012CE60 VMADDAz.xyzw ACC, vf3, vf6z + // @0012CE64 VMADDw.xyzw vf6, vf4, vf6w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[6].x, this.ee.VF[2], this.ee.VF[6].y, this.ee.VF[3], this.ee.VF[6].z, this.ee.VF[4], this.ee.VF[6].w, this.ee.VF[6]); + // @0012CE68 VMULAx.xyzw ACC, vf1, vf7x + // @0012CE6C VMADDAy.xyzw ACC, vf2, vf7y + // @0012CE70 VMADDAz.xyzw ACC, vf3, vf7z + // @0012CE74 VMADDw.xyzw vf7, vf4, vf7w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[7].x, this.ee.VF[2], this.ee.VF[7].y, this.ee.VF[3], this.ee.VF[7].z, this.ee.VF[4], this.ee.VF[7].w, this.ee.VF[7]); + // @0012CE78 VMULAx.xyzw ACC, vf1, vf8x + // @0012CE7C VMADDAy.xyzw ACC, vf2, vf8y + // @0012CE80 VMADDAz.xyzw ACC, vf3, vf8z + // @0012CE84 VMADDw.xyzw vf8, vf4, vf8w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[1], this.ee.VF[8].x, this.ee.VF[2], this.ee.VF[8].y, this.ee.VF[3], this.ee.VF[8].z, this.ee.VF[4], this.ee.VF[8].w, this.ee.VF[8]); + // @0012CE88 SQC2 vf5, $0000(t5) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t5.UL0)); + // @0012CE8C SQC2 vf6, $0010(t5) + MobUt.SQC2(this.ee, this.ee.VF[6], (16u + this.ee.t5.UL0)); + // @0012CE90 SQC2 vf7, $0020(t5) + MobUt.SQC2(this.ee, this.ee.VF[7], (32u + this.ee.t5.UL0)); + // @0012CE94 SQC2 vf8, $0030(t5) + MobUt.SQC2(this.ee, this.ee.VF[8], (48u + this.ee.t5.UL0)); + // @0012CE98 BEQL t4, t5, $0012cec4 + if ((this.ee.t4.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1232580u; + // @0012CE9C LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + } + } + + public virtual void funct0012cea0() + { + this.ee.pc = 1232596u; + // @0012CEA0 LQ t0, $0000(t5) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012CEA4 LQ t1, $0010(t5) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t5.UL[0])); + // @0012CEA8 LQ t2, $0020(t5) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t5.UL[0])); + // @0012CEAC LQ t3, $0030(t5) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t5.UL[0])); + // @0012CEB0 SQ t0, $0000(t4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); + // @0012CEB4 SQ t1, $0010(t4) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t4.UL[0])); + // @0012CEB8 SQ t2, $0020(t4) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t4.UL[0])); + // @0012CEBC SQ t3, $0030(t4) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t4.UL[0])); + // @0012CEC0 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012CEC4 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012CEC8 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012CECC BEQ t7, zero, $0012d07c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233020u; + } + // @0012CED0 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012ced4() + { + this.ee.pc = 1232620u; + // @0012CED4 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012CED8 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012CEDC LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + // @0012CEE0 ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012CEE4 BEQL t6, t7, $0012cf14 + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1232660u; + // @0012CEE8 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012cedc() + { + this.ee.pc = 1232620u; + // @0012CEDC LW t7, $0008(s0) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s0.UL0)); + // @0012CEE0 ADDU t7, t7, s3 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012CEE4 BEQL t6, t7, $0012cf14 + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1232660u; + // @0012CEE8 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012ceec() + { + this.ee.pc = 1232672u; + // @0012CEEC LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0012CEF0 LQ t1, $0010(t7) + MobUt.LQ(this.ee, this.ee.t1, (16u + this.ee.t7.UL[0])); + // @0012CEF4 LQ t2, $0020(t7) + MobUt.LQ(this.ee, this.ee.t2, (32u + this.ee.t7.UL[0])); + // @0012CEF8 LQ t3, $0030(t7) + MobUt.LQ(this.ee, this.ee.t3, (48u + this.ee.t7.UL[0])); + // @0012CEFC SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012CF00 SQ t1, $0010(t6) + MobUt.SQ(this.ee, this.ee.t1, (16u + this.ee.t6.UL[0])); + // @0012CF04 SQ t2, $0020(t6) + MobUt.SQ(this.ee, this.ee.t2, (32u + this.ee.t6.UL[0])); + // @0012CF08 SQ t3, $0030(t6) + MobUt.SQ(this.ee, this.ee.t3, (48u + this.ee.t6.UL[0])); + // @0012CF0C LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012CF10 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012CF14 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012CF18 BEQ t7, zero, $0012d06c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233004u; + } + // @0012CF1C SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012cf20() + { + this.ee.pc = 1232748u; + // @0012CF20 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012CF24 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012CF28 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @0012CF2C ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012CF30 LQC2 vf4, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); + // @0012CF34 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012CF38 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012CF3C LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012CF40 VMULx.xyzw vf1, vf1, vf4x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); + // @0012CF44 VMULy.xyzw vf2, vf2, vf4y + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); + this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); + // @0012CF48 VMULz.xyzw vf3, vf3, vf4z + this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); + this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); + // @0012CF4C SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012CF50 SQC2 vf2, $0010(t6) + MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012CF54 SQC2 vf3, $0020(t6) + MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012CF58 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012CF5C LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012CF60 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012CF64 BEQ t7, zero, $0012d05c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232988u; + } + // @0012CF68 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012cf28() + { + this.ee.pc = 1232748u; + // @0012CF28 LW t7, $0014(s0) + MobUt.LW(this.ee, this.ee.t7, (20u + this.ee.s0.UL0)); + // @0012CF2C ADDU t7, t7, s8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012CF30 LQC2 vf4, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.t7.UL0)); + // @0012CF34 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012CF38 LQC2 vf2, $0010(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012CF3C LQC2 vf3, $0020(t6) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012CF40 VMULx.xyzw vf1, vf1, vf4x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[4].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[4].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[4].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[4].x); + // @0012CF44 VMULy.xyzw vf2, vf2, vf4y + this.ee.VF[2].x = MobUt.MUL(this.ee.VF[2].x, this.ee.VF[4].y); + this.ee.VF[2].y = MobUt.MUL(this.ee.VF[2].y, this.ee.VF[4].y); + this.ee.VF[2].z = MobUt.MUL(this.ee.VF[2].z, this.ee.VF[4].y); + this.ee.VF[2].w = MobUt.MUL(this.ee.VF[2].w, this.ee.VF[4].y); + // @0012CF48 VMULz.xyzw vf3, vf3, vf4z + this.ee.VF[3].x = MobUt.MUL(this.ee.VF[3].x, this.ee.VF[4].z); + this.ee.VF[3].y = MobUt.MUL(this.ee.VF[3].y, this.ee.VF[4].z); + this.ee.VF[3].z = MobUt.MUL(this.ee.VF[3].z, this.ee.VF[4].z); + this.ee.VF[3].w = MobUt.MUL(this.ee.VF[3].w, this.ee.VF[4].z); + // @0012CF4C SQC2 vf1, $0000(t6) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0012CF50 SQC2 vf2, $0010(t6) + MobUt.SQC2(this.ee, this.ee.VF[2], (16u + this.ee.t6.UL0)); + // @0012CF54 SQC2 vf3, $0020(t6) + MobUt.SQC2(this.ee, this.ee.VF[3], (32u + this.ee.t6.UL0)); + // @0012CF58 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012CF5C LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012CF60 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012CF64 BEQ t7, zero, $0012d05c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232988u; + } + // @0012CF68 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012cf6c() + { + this.ee.pc = 1232772u; + // @0012CF6C LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012CF70 ADDU t6, t7, s3 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012CF74 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012CF78 ADDIU t5, sp, $0080 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012CF7C BEQL t6, t5, $0012cf94 + if ((this.ee.t6.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1232788u; + // @0012CF80 LW t6, $0220(sp) + MobUt.LW(this.ee, this.ee.t6, (544u + this.ee.sp.UL0)); + } + } + + public virtual void funct0012cf74() + { + this.ee.pc = 1232772u; + // @0012CF74 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + // @0012CF78 ADDIU t5, sp, $0080 + this.ee.t5.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @0012CF7C BEQL t6, t5, $0012cf94 + if ((this.ee.t6.UD0 == this.ee.t5.UD0)) + { + this.ee.pc = 1232788u; + // @0012CF80 LW t6, $0220(sp) + MobUt.LW(this.ee, this.ee.t6, (544u + this.ee.sp.UL0)); + } + } + + public virtual void funct0012cf84() + { + this.ee.pc = 1232812u; + // @0012CF84 LQ t0, $0000(t5) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t5.UL[0])); + // @0012CF88 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012CF8C LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012CF90 LW t6, $0220(sp) + MobUt.LW(this.ee, this.ee.t6, (544u + this.ee.sp.UL0)); + // @0012CF94 LHU a2, $0002(t6) + MobUt.LHU(this.ee, this.ee.a2, (2u + this.ee.t6.UL0)); + // @0012CF98 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012CF9C ANDI t5, a2, $ffff + this.ee.t5.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); + // @0012CFA0 SLT t7, t5, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t5.SD0 < this.ee.t6.SD0)); + // @0012CFA4 BEQ t7, zero, $0012d050 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232976u; + } + // @0012CFA8 SUBU t7, t5, t6 + this.ee.t7.SD0 = ((int)((this.ee.t5.UD0 - this.ee.t6.UD0))); + } + + public virtual void funct0012cfac() + { + this.ee.pc = 1232840u; + // @0012CFAC LW t6, $002c(s5) + MobUt.LW(this.ee, this.ee.t6, (44u + this.ee.s5.UL0)); + // @0012CFB0 SLL t7, t5, 6 + MobUt.SLL(this.ee.t7, this.ee.t5, 6); + // @0012CFB4 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012CFB8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012CFBC SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012CFC0 BEQ t7, zero, $0012d03c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232956u; + } + // @0012CFC4 ADDIU t3, t6, $0030 + this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012cfb4() + { + this.ee.pc = 1232840u; + // @0012CFB4 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012CFB8 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012CFBC SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012CFC0 BEQ t7, zero, $0012d03c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232956u; + } + // @0012CFC4 ADDIU t3, t6, $0030 + this.ee.t3.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012cfc8() + { + this.ee.pc = 1232868u; + // @0012CFC8 LW t7, $002c(s5) + MobUt.LW(this.ee, this.ee.t7, (44u + this.ee.s5.UL0)); + // @0012CFCC ADDU v0, t7, s3 + this.ee.v0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012CFD0 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012CFD4 ANDI a2, a2, $ffff + this.ee.a2.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); + // @0012CFD8 SLT t7, a2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); + // @0012CFDC BEQ t7, zero, $0012d020 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232928u; + } + // @0012CFE0 SLL t7, a2, 4 + MobUt.SLL(this.ee.t7, this.ee.a2, 4); + } + + public virtual void funct0012cfd0() + { + this.ee.pc = 1232868u; + // @0012CFD0 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012CFD4 ANDI a2, a2, $ffff + this.ee.a2.UD0 = ((ushort)((this.ee.a2.US0 & 65535))); + // @0012CFD8 SLT t7, a2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a2.SD0 < this.ee.t5.SD0)); + // @0012CFDC BEQ t7, zero, $0012d020 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232928u; + } + // @0012CFE0 SLL t7, a2, 4 + MobUt.SLL(this.ee.t7, this.ee.a2, 4); + } + + public virtual void funct0012cfe4() + { + this.ee.pc = 1232928u; + // @0012CFE4 LW t6, $0024(s5) + MobUt.LW(this.ee, this.ee.t6, (36u + this.ee.s5.UL0)); + // @0012CFE8 ADDU a2, t6, t7 + this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012CFEC LQC2 vf5, $0000(a2) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.a2.UL0)); + // @0012CFF0 LQC2 vf1, $0000(v0) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.v0.UL0)); + // @0012CFF4 LQC2 vf2, $0010(v0) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.v0.UL0)); + // @0012CFF8 LQC2 vf3, $0020(v0) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.v0.UL0)); + // @0012CFFC LQC2 vf4, $0030(v0) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.v0.UL0)); + // @0012D000 VMULAx.xyz ACC, vf1, vf5x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); + // @0012D004 VMADDAy.xyz ACC, vf2, vf5y + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); + // @0012D008 VMADDAz.xyz ACC, vf3, vf5z + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); + // @0012D00C VMADDw.xyz vf5, vf4, vf0w + this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); + this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); + this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); + // @0012D010 VMOVE.w vf5, vf0 + this.ee.VF[5].w = this.ee.VF[0].w; + // @0012D014 SQC2 vf5, $0000(t3) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); + // @0012D018 BEQ zero, zero, $00129e60 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220192u; + } + // @0012D01C LW t3, $01f4(sp) + MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); + } + + public virtual void funct0012cfec() + { + this.ee.pc = 1232928u; + // @0012CFEC LQC2 vf5, $0000(a2) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.a2.UL0)); + // @0012CFF0 LQC2 vf1, $0000(v0) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.v0.UL0)); + // @0012CFF4 LQC2 vf2, $0010(v0) + MobUt.LQC2(this.ee, this.ee.VF[2], (16u + this.ee.v0.UL0)); + // @0012CFF8 LQC2 vf3, $0020(v0) + MobUt.LQC2(this.ee, this.ee.VF[3], (32u + this.ee.v0.UL0)); + // @0012CFFC LQC2 vf4, $0030(v0) + MobUt.LQC2(this.ee, this.ee.VF[4], (48u + this.ee.v0.UL0)); + // @0012D000 VMULAx.xyz ACC, vf1, vf5x + this.ee.Vacc.x = (this.ee.VF[1].x * this.ee.VF[5].x); + this.ee.Vacc.y = (this.ee.VF[1].y * this.ee.VF[5].x); + this.ee.Vacc.z = (this.ee.VF[1].z * this.ee.VF[5].x); + // @0012D004 VMADDAy.xyz ACC, vf2, vf5y + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[2].x, this.ee.VF[5].y); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[2].y, this.ee.VF[5].y); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[2].z, this.ee.VF[5].y); + // @0012D008 VMADDAz.xyz ACC, vf3, vf5z + this.ee.Vacc.x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[3].x, this.ee.VF[5].z); + this.ee.Vacc.y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[3].y, this.ee.VF[5].z); + this.ee.Vacc.z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[3].z, this.ee.VF[5].z); + // @0012D00C VMADDw.xyz vf5, vf4, vf0w + this.ee.VF[5].x = MobUt.MADD(this.ee.Vacc.x, this.ee.VF[4].x, this.ee.VF[0].w); + this.ee.VF[5].y = MobUt.MADD(this.ee.Vacc.y, this.ee.VF[4].y, this.ee.VF[0].w); + this.ee.VF[5].z = MobUt.MADD(this.ee.Vacc.z, this.ee.VF[4].z, this.ee.VF[0].w); + // @0012D010 VMOVE.w vf5, vf0 + this.ee.VF[5].w = this.ee.VF[0].w; + // @0012D014 SQC2 vf5, $0000(t3) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.t3.UL0)); + // @0012D018 BEQ zero, zero, $00129e60 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220192u; + } + // @0012D01C LW t3, $01f4(sp) + MobUt.LW(this.ee, this.ee.t3, (500u + this.ee.sp.UL0)); + } + + public virtual void funct0012d020() + { + this.ee.pc = 1232956u; + // @0012D020 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + // @0012D024 SUBU t7, a2, t5 + this.ee.t7.SD0 = ((int)((this.ee.a2.UD0 - this.ee.t5.UD0))); + // @0012D028 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D02C ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012D030 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D034 BEQ zero, zero, $0012cfec + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232876u; + } + // @0012D038 ADDIU a2, t6, $0030 + this.ee.a2.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012d03c() + { + this.ee.pc = 1232976u; + // @0012D03C SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012D040 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012D044 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D048 BEQ zero, zero, $0012cfd0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232848u; + } + // @0012D04C ADDU v0, t6, t7 + this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012d050() + { + this.ee.pc = 1232988u; + // @0012D050 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012D054 BEQ zero, zero, $0012cfb4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232820u; + } + // @0012D058 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012d05c() + { + this.ee.pc = 1233004u; + // @0012D05C LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012D060 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D064 BEQ zero, zero, $0012cf74 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232756u; + } + // @0012D068 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012d06c() + { + this.ee.pc = 1233020u; + // @0012D06C LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012D070 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D074 BEQ zero, zero, $0012cf28 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232680u; + } + // @0012D078 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012d07c() + { + this.ee.pc = 1233036u; + // @0012D07C LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012D080 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D084 BEQ zero, zero, $0012cedc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232604u; + } + // @0012D088 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012d08c() + { + this.ee.pc = 1233056u; + // @0012D08C SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012D090 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012D094 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D098 BEQ zero, zero, $0012ce24 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232420u; + } + // @0012D09C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012d0a0() + { + this.ee.pc = 1233072u; + // @0012D0A0 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012D0A4 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D0A8 BEQ zero, zero, $0012cdf4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232372u; + } + // @0012D0AC ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012d0d8() + { + this.ee.pc = 1233136u; + // @0012D0D8 SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012D0DC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D0E0 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012D0E4 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D0E8 BEQ zero, zero, $0012cd68 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232232u; + } + // @0012D0EC ADDIU t6, t6, $0020 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); + } + + public virtual void funct0012d0f0() + { + this.ee.pc = 1233156u; + // @0012D0F0 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + // @0012D0F4 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012D0F8 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D0FC BEQ zero, zero, $0012cd50 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232208u; + } + // @0012D100 ADDU a3, t6, t7 + this.ee.a3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012d104() + { + this.ee.pc = 1233184u; + // @0012D104 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + // @0012D108 SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012D10C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D110 SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + // @0012D114 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012D118 BEQ zero, zero, $0012cd2c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232172u; + } + // @0012D11C ADDU v0, t6, t7 + this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012d120() + { + this.ee.pc = 1233196u; + // @0012D120 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012D124 BEQ zero, zero, $0012ccc0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232064u; + } + // @0012D128 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + } + + public virtual void funct0012d12c() + { + this.ee.pc = 1233220u; + // @0012D12C LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012D130 LW t6, $0014(s0) + MobUt.LW(this.ee, this.ee.t6, (20u + this.ee.s0.UL0)); + // @0012D134 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012D138 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012D13C BEQ t7, zero, $0012d1e4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233380u; + } + // @0012D140 ADDU s7, t6, s8 + this.ee.s7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s8.SD0))); + } + + public virtual void funct0012d144() + { + this.ee.pc = 1233240u; + // @0012D144 LW a0, $0014(s5) + MobUt.LW(this.ee, this.ee.a0, (20u + this.ee.s5.UL0)); + // @0012D148 LW t7, $0000(a0) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); + // @0012D14C LW v0, $0020(t7) + MobUt.LW(this.ee, this.ee.v0, (32u + this.ee.t7.UL0)); + // @0012D150 JALR ra, v0 + this.ee.ra.UD0 = 1233240u; + this.ee.pc = this.ee.v0.UL0; + // @0012D154 SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + } + + public virtual void funct0012d158() + { + this.ee.pc = 1233272u; + // @0012D158 LW t4, $0004(s0) + MobUt.LW(this.ee, this.ee.t4, (4u + this.ee.s0.UL0)); + // @0012D15C ADDU v0, v0, s3 + this.ee.v0.SD0 = ((int)((this.ee.v0.SD0 + this.ee.s3.SD0))); + // @0012D160 LWC1 $f1, $0000(s7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s7.UL0)); + // @0012D164 LWC1 $f0, $001c(v0) + MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); + // @0012D168 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012D16C SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012D170 BEQ t7, zero, $0012d1d0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233360u; + } + // @0012D174 MUL.S $f12, $f1, $f0 + this.ee.fpr[12].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct0012d160() + { + this.ee.pc = 1233272u; + // @0012D160 LWC1 $f1, $0000(s7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.s7.UL0)); + // @0012D164 LWC1 $f0, $001c(v0) + MobUt.LWC1(this.ee, this.ee.fpr[0], (28u + this.ee.v0.UL0)); + // @0012D168 LHU t6, $0010(t4) + MobUt.LHU(this.ee, this.ee.t6, (16u + this.ee.t4.UL0)); + // @0012D16C SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @0012D170 BEQ t7, zero, $0012d1d0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233360u; + } + // @0012D174 MUL.S $f12, $f1, $f0 + this.ee.fpr[12].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct0012d178() + { + this.ee.pc = 1233296u; + // @0012D178 LW t7, $0028(s5) + MobUt.LW(this.ee, this.ee.t7, (40u + this.ee.s5.UL0)); + // @0012D17C ADDU a3, t7, s3 + this.ee.a3.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s3.SD0))); + // @0012D180 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012D184 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012D188 BEQL t7, zero, $0012d1b8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233336u; + // @0012D18C LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012d180() + { + this.ee.pc = 1233296u; + // @0012D180 LHU t5, $0010(t4) + MobUt.LHU(this.ee, this.ee.t5, (16u + this.ee.t4.UL0)); + // @0012D184 SLT t7, s2, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t5.SD0)); + // @0012D188 BEQL t7, zero, $0012d1b8 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233336u; + // @0012D18C LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + } + } + + public virtual void funct0012d190() + { + this.ee.pc = 1233336u; + // @0012D190 LW t7, $0020(s5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); + // @0012D194 ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012D198 LWC1 $f14, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t6.UL0)); + // @0012D19C ADDIU a0, sp, $00a0 + this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); + // @0012D1A0 MTC1 zero, $f13 + this.ee.fpr[13].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @0012D1A4 ADDIU a1, sp, $00b0 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); + // @0012D1A8 DADDU a2, zero, zero + this.ee.a2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @0012D1AC DADDU t0, zero, zero + this.ee.t0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @0012D1B0 BEQ zero, zero, $0012cd84 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232260u; + } + // @0012D1B4 DADDU t1, zero, zero + this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012d198() + { + this.ee.pc = 1233336u; + // @0012D198 LWC1 $f14, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[14], (0u + this.ee.t6.UL0)); + // @0012D19C ADDIU a0, sp, $00a0 + this.ee.a0.SD0 = ((int)((this.ee.sp.SD0 + 160))); + // @0012D1A0 MTC1 zero, $f13 + this.ee.fpr[13].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @0012D1A4 ADDIU a1, sp, $00b0 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 176))); + // @0012D1A8 DADDU a2, zero, zero + this.ee.a2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @0012D1AC DADDU t0, zero, zero + this.ee.t0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @0012D1B0 BEQ zero, zero, $0012cd84 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1232260u; + } + // @0012D1B4 DADDU t1, zero, zero + this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012d1b8() + { + this.ee.pc = 1233360u; + // @0012D1B8 SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012D1BC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D1C0 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012D1C4 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D1C8 BEQ zero, zero, $0012d198 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233304u; + } + // @0012D1CC ADDIU t6, t6, $0020 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); + } + + public virtual void funct0012d1d0() + { + this.ee.pc = 1233380u; + // @0012D1D0 SUBU t7, s2, t6 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t6.UD0))); + // @0012D1D4 LW t6, $000c(s0) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @0012D1D8 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D1DC BEQ zero, zero, $0012d180 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233280u; + } + // @0012D1E0 ADDU a3, t6, t7 + this.ee.a3.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012d1e4() + { + this.ee.pc = 1233408u; + // @0012D1E4 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + // @0012D1E8 SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012D1EC SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D1F0 SLL s3, s2, 6 + MobUt.SLL(this.ee.s3, this.ee.s2, 6); + // @0012D1F4 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012D1F8 BEQ zero, zero, $0012d160 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233248u; + } + // @0012D1FC ADDU v0, t6, t7 + this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012d200() + { + this.ee.pc = 1233432u; + // @0012D200 SUBU t7, t4, t6 + this.ee.t7.SD0 = ((int)((this.ee.t4.UD0 - this.ee.t6.UD0))); + // @0012D204 LW t6, $0010(s0) + MobUt.LW(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @0012D208 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D20C SW t5, $0250(sp) + MobUt.SW(this.ee, this.ee.t5, (592u + this.ee.sp.UL0)); + // @0012D210 BEQ zero, zero, $0012cb50 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231696u; + } + // @0012D214 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0012d218() + { + this.ee.pc = 1233460u; + // @0012D218 LW t6, $0018(t4) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t4.UL0)); + // @0012D21C SUBU t7, s2, t5 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t5.UD0))); + // @0012D220 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D224 ADDU t6, t4, t6 + this.ee.t6.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t6.SD0))); + // @0012D228 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D22C BEQ zero, zero, $0012cb0c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1231628u; + } + // @0012D230 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012d234() + { + this.ee.pc = 1233484u; + // @0012D234 SUBU t7, s2, t4 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); + // @0012D238 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D23C ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012D240 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D244 BEQ zero, zero, $00129dd0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220048u; + } + // @0012D248 ADDIU t5, t6, $0010 + this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + 16))); + } + + public virtual void funct0012d24c() + { + this.ee.pc = 1233508u; + // @0012D24C SUBU t7, s2, t4 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); + // @0012D250 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D254 ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012D258 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D25C BEQ zero, zero, $00129d90 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219984u; + } + // @0012D260 ADDIU t5, t6, $0010 + this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + 16))); + } + + public virtual void funct0012d264() + { + this.ee.pc = 1233532u; + // @0012D264 SUBU t7, s2, t4 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); + // @0012D268 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D26C ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012D270 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D274 BEQ zero, zero, $00129d4c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219916u; + } + // @0012D278 ADDIU t5, t6, $0010 + this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + 16))); + } + + public virtual void funct0012d2c8() + { + this.ee.pc = 1233616u; + // @0012D2C8 BLTZ t7, $0012d33c + if ((this.ee.t7.SD0 < 0)) + { + this.ee.pc = 1233724u; + } + // @0012D2CC SLL t7, t7, 4 + MobUt.SLL(this.ee.t7, this.ee.t7, 4); + } + + public virtual void funct0012d2d0() + { + this.ee.pc = 1233644u; + // @0012D2D0 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @0012D2D4 LW t6, $0014(s0) + MobUt.LW(this.ee, this.ee.t6, (20u + this.ee.s0.UL0)); + // @0012D2D8 LHU t3, $0010(t5) + MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t5.UL0)); + // @0012D2DC ADDU t2, t6, t7 + this.ee.t2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D2E0 SLT t7, s2, t3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); + // @0012D2E4 BEQ t7, zero, $0012d320 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233696u; + } + // @0012D2E8 ADDU t4, t6, s8 + this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s8.SD0))); + } + + public virtual void funct0012d2ec() + { + this.ee.pc = 1233680u; + // @0012D2EC LW t7, $001c(s5) + MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); + // @0012D2F0 ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012D2F4 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012D2F8 LQC2 vf1, $0000(t2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); + // @0012D2FC LQC2 vf2, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); + // @0012D300 VMUL.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].w); + // @0012D304 SQC2 vf1, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t8.UL0)); + // @0012D308 BEQL t4, t8, $00129df8 + if ((this.ee.t4.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1220088u; + // @0012D30C LUI t7, $0020 + this.ee.t7.SD0 = 2097152; + } + } + + public virtual void funct0012d2f4() + { + this.ee.pc = 1233680u; + // @0012D2F4 ADDIU t8, sp, $0120 + this.ee.t8.SD0 = ((int)((this.ee.sp.SD0 + 288))); + // @0012D2F8 LQC2 vf1, $0000(t2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t2.UL0)); + // @0012D2FC LQC2 vf2, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t6.UL0)); + // @0012D300 VMUL.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].w); + // @0012D304 SQC2 vf1, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.t8.UL0)); + // @0012D308 BEQL t4, t8, $00129df8 + if ((this.ee.t4.UD0 == this.ee.t8.UD0)) + { + this.ee.pc = 1220088u; + // @0012D30C LUI t7, $0020 + this.ee.t7.SD0 = 2097152; + } + } + + public virtual void funct0012d310() + { + this.ee.pc = 1233696u; + // @0012D310 LQ t0, $0000(t8) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t8.UL[0])); + // @0012D314 SQ t0, $0000(t4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); + // @0012D318 BEQ zero, zero, $00129df8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220088u; + } + // @0012D31C LUI t7, $0020 + this.ee.t7.SD0 = 2097152; + } + + public virtual void funct0012d320() + { + this.ee.pc = 1233724u; + // @0012D320 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + // @0012D324 SUBU t7, s2, t3 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); + // @0012D328 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D32C ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012D330 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D334 BEQ zero, zero, $0012d2f4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233652u; + } + // @0012D338 ADDIU t6, t6, $0010 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 16))); + } + + public virtual void funct0012d33c() + { + this.ee.pc = 1233748u; + // @0012D33C LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @0012D340 LW t6, $0014(s0) + MobUt.LW(this.ee, this.ee.t6, (20u + this.ee.s0.UL0)); + // @0012D344 LHU t3, $0010(t5) + MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t5.UL0)); + // @0012D348 SLT t7, s2, t3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); + // @0012D34C BEQ t7, zero, $0012d374 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233780u; + } + // @0012D350 ADDU t4, t6, s8 + this.ee.t4.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s8.SD0))); + } + + public virtual void funct0012d354() + { + this.ee.pc = 1233764u; + // @0012D354 LW t7, $001c(s5) + MobUt.LW(this.ee, this.ee.t7, (28u + this.ee.s5.UL0)); + // @0012D358 ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012D35C BEQL t4, t6, $00129df8 + if ((this.ee.t4.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1220088u; + // @0012D360 LUI t7, $0020 + this.ee.t7.SD0 = 2097152; + } + } + + public virtual void funct0012d35c() + { + this.ee.pc = 1233764u; + // @0012D35C BEQL t4, t6, $00129df8 + if ((this.ee.t4.UD0 == this.ee.t6.UD0)) + { + this.ee.pc = 1220088u; + // @0012D360 LUI t7, $0020 + this.ee.t7.SD0 = 2097152; + } + } + + public virtual void funct0012d364() + { + this.ee.pc = 1233780u; + // @0012D364 LQ t0, $0000(t6) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0012D368 SQ t0, $0000(t4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t4.UL[0])); + // @0012D36C BEQ zero, zero, $00129df8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1220088u; + } + // @0012D370 LUI t7, $0020 + this.ee.t7.SD0 = 2097152; + } + + public virtual void funct0012d374() + { + this.ee.pc = 1233808u; + // @0012D374 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + // @0012D378 SUBU t7, s2, t3 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); + // @0012D37C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D380 ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012D384 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D388 BEQ zero, zero, $0012d35c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1233756u; + } + // @0012D38C ADDIU t6, t6, $0010 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 16))); + } + + public virtual void funct0012d390() + { + this.ee.pc = 1233820u; + // @0012D390 SW s1, $0220(sp) + MobUt.SW(this.ee, this.ee.s1, (544u + this.ee.sp.UL0)); + // @0012D394 BEQ zero, zero, $00129ce4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219812u; + } + // @0012D398 ADDIU s1, s1, $000c + this.ee.s1.SD0 = ((int)((this.ee.s1.SD0 + 12))); + } + + public virtual void funct0012d39c() + { + this.ee.pc = 1233844u; + // @0012D39C LUI t7, $0001 + this.ee.t7.SD0 = 65536; + // @0012D3A0 ADDIU t5, s2, $0001 + this.ee.t5.SD0 = ((int)((this.ee.s2.SD0 + 1))); + // @0012D3A4 XOR t7, t6, t7 + MobUt.XOR(this.ee.t7, this.ee.t6, this.ee.t7); + // @0012D3A8 ADDIU t6, s2, $0002 + this.ee.t6.SD0 = ((int)((this.ee.s2.SD0 + 2))); + // @0012D3AC BEQ zero, zero, $00129c84 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219716u; + } + // @0012D3B0 MOVN t5, t6, t7 + if ((this.ee.t7.UD0 != 0)) + { + this.ee.t5.UD0 = this.ee.t6.UD0; + } + } + + public virtual void funct0012d3b4() + { + this.ee.pc = 1233852u; + // @0012D3B4 BEQL a3, t7, $00129c3c + if ((this.ee.a3.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1219644u; + // @0012D3B8 LHU a3, $0004(s1) + MobUt.LHU(this.ee, this.ee.a3, (4u + this.ee.s1.UL0)); + } + } + + public virtual void funct0012d3c8() + { + this.ee.pc = 1233872u; + // @0012D3C8 BEQ zero, zero, $00129c3c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219644u; + } + // @0012D3CC SW s1, $0218(sp) + MobUt.SW(this.ee, this.ee.s1, (536u + this.ee.sp.UL0)); + } + + public virtual void funct0012d3e0() + { + this.ee.pc = 1233896u; + // @0012D3E0 BEQ zero, zero, $00129c3c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219644u; + } + // @0012D3E4 DADDU t3, s1, zero + this.ee.t3.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0012d3e8() + { + this.ee.pc = 1233936u; + // @0012D3E8 LW t7, $01fc(sp) + MobUt.LW(this.ee, this.ee.t7, (508u + this.ee.sp.UL0)); + // @0012D3EC LHU t5, $0006(s1) + MobUt.LHU(this.ee, this.ee.t5, (6u + this.ee.s1.UL0)); + // @0012D3F0 LW t6, $005c(t7) + MobUt.LW(this.ee, this.ee.t6, (92u + this.ee.t7.UL0)); + // @0012D3F4 LHU v1, $0004(s1) + MobUt.LHU(this.ee, this.ee.v1, (4u + this.ee.s1.UL0)); + // @0012D3F8 ADDIU t7, zero, $0030 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 48))); + // @0012D3FC MULT t5, t5, t7 + this.ee.t5.SD0 = (((long)(this.ee.t5.SL0)) * ((long)(this.ee.t7.SL0))); + // @0012D400 LW t7, $01fc(sp) + MobUt.LW(this.ee, this.ee.t7, (508u + this.ee.sp.UL0)); + // @0012D404 ADDU t6, t7, t6 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @0012D408 BEQ zero, zero, $00129c3c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219644u; + } + // @0012D40C ADDU v0, t6, t5 + this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); + } + + public virtual void funct0012d410() + { + this.ee.pc = 1233976u; + // @0012D410 LW t6, $01fc(sp) + MobUt.LW(this.ee, this.ee.t6, (508u + this.ee.sp.UL0)); + // @0012D414 LHU t5, $0006(s1) + MobUt.LHU(this.ee, this.ee.t5, (6u + this.ee.s1.UL0)); + // @0012D418 LW t7, $005c(t6) + MobUt.LW(this.ee, this.ee.t7, (92u + this.ee.t6.UL0)); + // @0012D41C ADDIU t6, zero, $0030 + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 48))); + // @0012D420 MULT t5, t5, t6 + this.ee.t5.SD0 = (((long)(this.ee.t5.SL0)) * ((long)(this.ee.t6.SL0))); + // @0012D424 LW t6, $01fc(sp) + MobUt.LW(this.ee, this.ee.t6, (508u + this.ee.sp.UL0)); + // @0012D428 ADDU t7, t6, t7 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D42C ADDU t7, t7, t5 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); + // @0012D430 BEQ zero, zero, $00129c3c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219644u; + } + // @0012D434 SW t7, $021c(sp) + MobUt.SW(this.ee, this.ee.t7, (540u + this.ee.sp.UL0)); + } + + public virtual void funct0012d438() + { + this.ee.pc = 1234000u; + // @0012D438 SUBU t7, s2, t3 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); + // @0012D43C SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D440 ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012D444 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D448 BEQ zero, zero, $00129b90 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219472u; + } + // @0012D44C ADDIU t6, t6, $0010 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 16))); + } + + public virtual void funct0012d450() + { + this.ee.pc = 1234020u; + // @0012D450 LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @0012D454 LHU t3, $0010(t5) + MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t5.UL0)); + // @0012D458 SLT t7, s2, t3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); + // @0012D45C BEQL t7, zero, $0012d494 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1234068u; + // @0012D460 LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct0012d464() + { + this.ee.pc = 1234068u; + // @0012D464 LW t7, $0020(s5) + MobUt.LW(this.ee, this.ee.t7, (32u + this.ee.s5.UL0)); + // @0012D468 ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012D46C ANDI t7, t4, $ffff + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @0012D470 LUI t4, $0038 + this.ee.t4.SD0 = 3670016; + // @0012D474 ADDIU t7, t7, $fffd + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -3))); + // @0012D478 ADDIU t4, t4, $8360 + this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + -31904))); + // @0012D47C SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @0012D480 LWC1 $f0, $0000(t4) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t4.UL0)); + // @0012D484 ADDU t7, t6, t7 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D488 MUL.S $f0, $f1, $f0 + this.ee.fpr[0].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + // @0012D48C BEQ zero, zero, $00129ba0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219488u; + } + // @0012D490 SWC1 $f0, $0000(t7) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + } + + public virtual void funct0012d46c() + { + this.ee.pc = 1234068u; + // @0012D46C ANDI t7, t4, $ffff + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @0012D470 LUI t4, $0038 + this.ee.t4.SD0 = 3670016; + // @0012D474 ADDIU t7, t7, $fffd + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -3))); + // @0012D478 ADDIU t4, t4, $8360 + this.ee.t4.SD0 = ((int)((this.ee.t4.SD0 + -31904))); + // @0012D47C SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @0012D480 LWC1 $f0, $0000(t4) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t4.UL0)); + // @0012D484 ADDU t7, t6, t7 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D488 MUL.S $f0, $f1, $f0 + this.ee.fpr[0].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + // @0012D48C BEQ zero, zero, $00129ba0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219488u; + } + // @0012D490 SWC1 $f0, $0000(t7) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + } + + public virtual void funct0012d494() + { + this.ee.pc = 1234092u; + // @0012D494 SUBU t7, s2, t3 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); + // @0012D498 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D49C ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012D4A0 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D4A4 BEQ zero, zero, $0012d46c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1234028u; + } + // @0012D4A8 ADDIU t6, t6, $0020 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 32))); + } + + public virtual void funct0012d4ac() + { + this.ee.pc = 1234112u; + // @0012D4AC LW t5, $0004(s0) + MobUt.LW(this.ee, this.ee.t5, (4u + this.ee.s0.UL0)); + // @0012D4B0 LHU t3, $0010(t5) + MobUt.LHU(this.ee, this.ee.t3, (16u + this.ee.t5.UL0)); + // @0012D4B4 SLT t7, s2, t3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t3.SD0)); + // @0012D4B8 BEQL t7, zero, $0012d4d4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1234132u; + // @0012D4BC LW t6, $0018(t5) + MobUt.LW(this.ee, this.ee.t6, (24u + this.ee.t5.UL0)); + } + } + + public virtual void funct0012d4c0() + { + this.ee.pc = 1234132u; + // @0012D4C0 LW t7, $0024(s5) + MobUt.LW(this.ee, this.ee.t7, (36u + this.ee.s5.UL0)); + // @0012D4C4 ADDU t6, t7, s8 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s8.SD0))); + // @0012D4C8 ANDI t7, t4, $ffff + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @0012D4CC BEQ zero, zero, $00129b94 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219476u; + } + // @0012D4D0 ADDIU t7, t7, $fffa + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -6))); + } + + public virtual void funct0012d4c8() + { + this.ee.pc = 1234132u; + // @0012D4C8 ANDI t7, t4, $ffff + this.ee.t7.UD0 = ((ushort)((this.ee.t4.US0 & 65535))); + // @0012D4CC BEQ zero, zero, $00129b94 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219476u; + } + // @0012D4D0 ADDIU t7, t7, $fffa + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -6))); + } + + public virtual void funct0012d4d4() + { + this.ee.pc = 1234156u; + // @0012D4D4 SUBU t7, s2, t3 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t3.UD0))); + // @0012D4D8 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D4DC ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012D4E0 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @0012D4E4 BEQ zero, zero, $0012d4c8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1234120u; + } + // @0012D4E8 ADDIU t6, t6, $0030 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 48))); + } + + public virtual void funct0012d4ec() + { + this.ee.pc = 1234164u; + // @0012D4EC BEQ zero, zero, $00129bc4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219524u; + } + // @0012D4F0 SLL s8, s2, 4 + MobUt.SLL(this.ee.s8, this.ee.s2, 4); + } + + public virtual void funct0012d4f4() + { + this.ee.pc = 1234184u; + // @0012D4F4 SUBU t7, s2, t4 + this.ee.t7.SD0 = ((int)((this.ee.s2.UD0 - this.ee.t4.UD0))); + // @0012D4F8 SLL t7, t7, 6 + MobUt.SLL(this.ee.t7, this.ee.t7, 6); + // @0012D4FC ADDU t6, t5, t6 + this.ee.t6.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0012D500 BEQ zero, zero, $00129b10 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1219344u; + } + // @0012D504 ADDU v0, t6, t7 + this.ee.v0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct00141bd0() + { + this.ee.pc = 1317852u; + // @00141BD0 LW t7, $0000(a0) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); + // @00141BD4 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00141BD8 LW v0, $000c(t7) + MobUt.LW(this.ee, this.ee.v0, (12u + this.ee.t7.UL0)); + } + + public virtual void funct00141be0() + { + this.ee.pc = 1317864u; + // @00141BE0 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00141BE4 SW a1, $003c(a0) + MobUt.SW(this.ee, this.ee.a1, (60u + this.ee.a0.UL0)); + } + + public virtual void funct00141be8() + { + this.ee.pc = 1317940u; + // @00141BE8 LHU t6, $0002(a1) + MobUt.LHU(this.ee, this.ee.t6, (2u + this.ee.a1.UL0)); + // @00141BEC LW t7, $0010(a0) + MobUt.LW(this.ee, this.ee.t7, (16u + this.ee.a0.UL0)); + // @00141BF0 SLL t6, t6, 4 + MobUt.SLL(this.ee.t6, this.ee.t6, 4); + // @00141BF4 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00141BF8 SW t7, $0000(a2) + MobUt.SW(this.ee, this.ee.t7, (0u + this.ee.a2.UL0)); + // @00141BFC LHU t6, $0004(a1) + MobUt.LHU(this.ee, this.ee.t6, (4u + this.ee.a1.UL0)); + // @00141C00 LW t7, $0010(a0) + MobUt.LW(this.ee, this.ee.t7, (16u + this.ee.a0.UL0)); + // @00141C04 SLL t6, t6, 4 + MobUt.SLL(this.ee.t6, this.ee.t6, 4); + // @00141C08 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00141C0C SW t7, $0004(a2) + MobUt.SW(this.ee, this.ee.t7, (4u + this.ee.a2.UL0)); + // @00141C10 LHU t6, $0006(a1) + MobUt.LHU(this.ee, this.ee.t6, (6u + this.ee.a1.UL0)); + // @00141C14 LW t7, $0010(a0) + MobUt.LW(this.ee, this.ee.t7, (16u + this.ee.a0.UL0)); + // @00141C18 SLL t6, t6, 4 + MobUt.SLL(this.ee.t6, this.ee.t6, 4); + // @00141C1C ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00141C20 SW t7, $0008(a2) + MobUt.SW(this.ee, this.ee.t7, (8u + this.ee.a2.UL0)); + // @00141C24 LHU t6, $0008(a1) + MobUt.LHU(this.ee, this.ee.t6, (8u + this.ee.a1.UL0)); + // @00141C28 ORI t7, zero, $ffff + this.ee.t7.UD0 = (this.ee.r0.UD0 | 65535); + // @00141C2C BEQ t6, t7, $00141c4c + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1317964u; + } + // @00141C30 SLL t5, t6, 4 + MobUt.SLL(this.ee.t5, this.ee.t6, 4); + } + + public virtual void funct00141c34() + { + this.ee.pc = 1317964u; + // @00141C34 LW t7, $0010(a0) + MobUt.LW(this.ee, this.ee.t7, (16u + this.ee.a0.UL0)); + // @00141C38 ADDIU t6, zero, $0004 + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 4))); + // @00141C3C ADDU t7, t7, t5 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t5.SD0))); + // @00141C40 SW t6, $0010(a2) + MobUt.SW(this.ee, this.ee.t6, (16u + this.ee.a2.UL0)); + // @00141C44 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00141C48 SW t7, $000c(a2) + MobUt.SW(this.ee, this.ee.t7, (12u + this.ee.a2.UL0)); + } + + public virtual void funct00141e78() + { + this.ee.pc = 1318548u; + // @00141E78 ANDI a3, a3, $00ff + this.ee.a3.UD0 = ((ushort)((this.ee.a3.US0 & 255))); + // @00141E7C SW a1, $0040(a0) + MobUt.SW(this.ee, this.ee.a1, (64u + this.ee.a0.UL0)); + // @00141E80 ANDI t0, t0, $00ff + this.ee.t0.UD0 = ((ushort)((this.ee.t0.US0 & 255))); + // @00141E84 SW a2, $0044(a0) + MobUt.SW(this.ee, this.ee.a2, (68u + this.ee.a0.UL0)); + // @00141E88 SB t0, $00d3(a0) + MobUt.SB(this.ee, this.ee.t0, (211u + this.ee.a0.UL0)); + // @00141E8C JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00141E90 SB a3, $00d0(a0) + MobUt.SB(this.ee, this.ee.a3, (208u + this.ee.a0.UL0)); + } + + public virtual void funct00141e98() + { + this.ee.pc = 1318636u; + // @00141E98 ADDIU sp, sp, $ffa0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -96))); + // @00141E9C SLL a1, a1, 5 + MobUt.SLL(this.ee.a1, this.ee.a1, 5); + // @00141EA0 SD s1, $0018(sp) + MobUt.SD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); + // @00141EA4 SD s5, $0038(sp) + MobUt.SD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); + // @00141EA8 SD s6, $0040(sp) + MobUt.SD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); + // @00141EAC DADDU s1, a0, zero + this.ee.s1.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); + // @00141EB0 SD s7, $0048(sp) + MobUt.SD(this.ee, this.ee.s7, (72u + this.ee.sp.UL0)); + // @00141EB4 DADDU s5, a2, zero + this.ee.s5.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); + // @00141EB8 SD s0, $0010(sp) + MobUt.SD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); + // @00141EBC DADDU s6, a3, zero + this.ee.s6.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); + // @00141EC0 SD s2, $0020(sp) + MobUt.SD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); + // @00141EC4 SD s3, $0028(sp) + MobUt.SD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); + // @00141EC8 SD s4, $0030(sp) + MobUt.SD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); + // @00141ECC SD s8, $0050(sp) + MobUt.SD(this.ee, this.ee.s8, (80u + this.ee.sp.UL0)); + // @00141ED0 SD ra, $0058(sp) + MobUt.SD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); + // @00141ED4 LW t7, $0004(a0) + MobUt.LW(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); + // @00141ED8 SW t0, $0000(sp) + MobUt.SW(this.ee, this.ee.t0, (0u + this.ee.sp.UL0)); + // @00141EDC ADDU s7, t7, a1 + this.ee.s7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.a1.SD0))); + // @00141EE0 ADDIU a0, s7, $0010 + this.ee.a0.SD0 = ((int)((this.ee.s7.SD0 + 16))); + // @00141EE4 JAL $001457e0 + this.ee.ra.UL0 = 1318636u; + this.ee.pc = 1333216u; + // @00141EE8 DADDU a1, a2, zero + this.ee.a1.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00141eec() + { + this.ee.pc = 1318644u; + // @00141EEC BEQ v0, zero, $00142090 + if ((this.ee.v0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1319056u; + } + // @00141EF0 LD s0, $0010(sp) + MobUt.LD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); + } + + public virtual void funct00141ef4() + { + this.ee.pc = 1318664u; + // @00141EF4 LHU s8, $001e(s7) + MobUt.LHU(this.ee, this.ee.s8, (30u + this.ee.s7.UL0)); + // @00141EF8 LHU s3, $001c(s7) + MobUt.LHU(this.ee, this.ee.s3, (28u + this.ee.s7.UL0)); + // @00141EFC SLT t7, s3, s8 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s3.SD0 < this.ee.s8.SD0)); + // @00141F00 BEQ t7, zero, $0014204c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1318988u; + } + // @00141F04 ADDIU t7, zero, $0014 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 20))); + } + + public virtual void funct00141f08() + { + this.ee.pc = 1318688u; + // @00141F08 MULT s4, s3, t7 + this.ee.s4.SD0 = (((long)(this.ee.s3.SL0)) * ((long)(this.ee.t7.SL0))); + // @00141F0C LW t7, $0008(s1) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s1.UL0)); + // @00141F10 ADDU s0, t7, s4 + this.ee.s0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s4.SD0))); + // @00141F14 LBU t6, $0010(s0) + MobUt.LBU(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @00141F18 BEQL t6, zero, $00142040 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1318976u; + // @00141F1C ADDIU s3, s3, $0001 + this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); + } + } + + public virtual void funct00141f0c() + { + this.ee.pc = 1318688u; + // @00141F0C LW t7, $0008(s1) + MobUt.LW(this.ee, this.ee.t7, (8u + this.ee.s1.UL0)); + // @00141F10 ADDU s0, t7, s4 + this.ee.s0.SD0 = ((int)((this.ee.t7.SD0 + this.ee.s4.SD0))); + // @00141F14 LBU t6, $0010(s0) + MobUt.LBU(this.ee, this.ee.t6, (16u + this.ee.s0.UL0)); + // @00141F18 BEQL t6, zero, $00142040 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1318976u; + // @00141F1C ADDIU s3, s3, $0001 + this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); + } + } + + public virtual void funct00141f20() + { + this.ee.pc = 1318700u; + // @00141F20 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @00141F24 JAL $001457e0 + this.ee.ra.UL0 = 1318700u; + this.ee.pc = 1333216u; + // @00141F28 DADDU a1, s5, zero + this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00141f2c() + { + this.ee.pc = 1318708u; + // @00141F2C BEQL v0, zero, $00142040 + if ((this.ee.v0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1318976u; + // @00141F30 ADDIU s3, s3, $0001 + this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); + } + } + + public virtual void funct00141f34() + { + this.ee.pc = 1318728u; + // @00141F34 LHU s2, $000c(s0) + MobUt.LHU(this.ee, this.ee.s2, (12u + this.ee.s0.UL0)); + // @00141F38 LHU s0, $000e(s0) + MobUt.LHU(this.ee, this.ee.s0, (14u + this.ee.s0.UL0)); + // @00141F3C SLT t7, s2, s0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.s0.SD0)); + // @00141F40 BEQ t7, zero, $0014203c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1318972u; + } + // @00141F44 SW s0, $0004(sp) + MobUt.SW(this.ee, this.ee.s0, (4u + this.ee.sp.UL0)); + } + + public virtual void funct00141f48() + { + this.ee.pc = 1318768u; + // @00141F48 LW t6, $000c(s1) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s1.UL0)); + // @00141F4C SLL t7, s2, 4 + MobUt.SLL(this.ee.t7, this.ee.s2, 4); + // @00141F50 LW t4, $0014(s1) + MobUt.LW(this.ee, this.ee.t4, (20u + this.ee.s1.UL0)); + // @00141F54 ADDU s0, t6, t7 + this.ee.s0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00141F58 LBU t5, $00d0(s1) + MobUt.LBU(this.ee, this.ee.t5, (208u + this.ee.s1.UL0)); + // @00141F5C LHU t7, $000e(s0) + MobUt.LHU(this.ee, this.ee.t7, (14u + this.ee.s0.UL0)); + // @00141F60 ADDIU t6, zero, $0001 + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @00141F64 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @00141F68 BNE t5, t6, $001420bc + if ((this.ee.t5.UD0 != this.ee.t6.UD0)) + { + this.ee.pc = 1319100u; + } + // @00141F6C ADDU a2, t4, t7 + this.ee.a2.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct00141f4c() + { + this.ee.pc = 1318768u; + // @00141F4C SLL t7, s2, 4 + MobUt.SLL(this.ee.t7, this.ee.s2, 4); + // @00141F50 LW t4, $0014(s1) + MobUt.LW(this.ee, this.ee.t4, (20u + this.ee.s1.UL0)); + // @00141F54 ADDU s0, t6, t7 + this.ee.s0.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00141F58 LBU t5, $00d0(s1) + MobUt.LBU(this.ee, this.ee.t5, (208u + this.ee.s1.UL0)); + // @00141F5C LHU t7, $000e(s0) + MobUt.LHU(this.ee, this.ee.t7, (14u + this.ee.s0.UL0)); + // @00141F60 ADDIU t6, zero, $0001 + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @00141F64 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @00141F68 BNE t5, t6, $001420bc + if ((this.ee.t5.UD0 != this.ee.t6.UD0)) + { + this.ee.pc = 1319100u; + } + // @00141F6C ADDU a2, t4, t7 + this.ee.a2.SD0 = ((int)((this.ee.t4.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct00141f88() + { + this.ee.pc = 1318804u; + // @00141F88 ANDI t7, t7, $00ff + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 255))); + // @00141F8C BEQ t7, zero, $0014202c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1318956u; + } + // @00141F90 LW t6, $0004(sp) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.sp.UL0)); + } + + public virtual void funct00141f94() + { + this.ee.pc = 1318816u; + // @00141F94 LBU t7, $00d3(s1) + MobUt.LBU(this.ee, this.ee.t7, (211u + this.ee.s1.UL0)); + // @00141F98 BEQ t7, zero, $00141fb4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1318836u; + } + // @00141F9C DADDU t6, zero, zero + this.ee.t6.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00141fb4() + { + this.ee.pc = 1318848u; + // @00141FB4 ANDI t7, t6, $00ff + this.ee.t7.UD0 = ((ushort)((this.ee.t6.US0 & 255))); + // @00141FB8 BNEL t7, zero, $00141fd8 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1318872u; + // @00141FBC LHU t6, $000c(s0) + MobUt.LHU(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + } + } + + public virtual void funct00141fc0() + { + this.ee.pc = 1318860u; + // @00141FC0 LW a1, $0000(sp) + MobUt.LW(this.ee, this.ee.a1, (0u + this.ee.sp.UL0)); + // @00141FC4 JAL $0032d8d0 + this.ee.ra.UL0 = 1318860u; + this.ee.pc = 3332304u; + // @00141FC8 DADDU a0, s1, zero + this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00141fcc() + { + this.ee.pc = 1318868u; + // @00141FCC BEQ v0, zero, $0014202c + if ((this.ee.v0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1318956u; + } + // @00141FD0 LW t6, $0004(sp) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.sp.UL0)); + } + + public virtual void funct00141fd4() + { + this.ee.pc = 1318884u; + // @00141FD4 LHU t6, $000c(s0) + MobUt.LHU(this.ee, this.ee.t6, (12u + this.ee.s0.UL0)); + // @00141FD8 ORI t7, zero, $ffff + this.ee.t7.UD0 = (this.ee.r0.UD0 | 65535); + // @00141FDC BEQ t6, t7, $00142000 + if ((this.ee.t6.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1318912u; + } + // @00141FE0 ADDIU t5, zero, $000c + this.ee.t5.SD0 = ((int)((this.ee.r0.SD0 + 12))); + } + + public virtual void funct00141fe4() + { + this.ee.pc = 1318904u; + // @00141FE4 LW a0, $001c(s1) + MobUt.LW(this.ee, this.ee.a0, (28u + this.ee.s1.UL0)); + // @00141FE8 MULT t7, t6, t5 + this.ee.t7.SD0 = (((long)(this.ee.t6.SL0)) * ((long)(this.ee.t5.SL0))); + // @00141FEC DADDU a1, s5, zero + this.ee.a1.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); + // @00141FF0 JAL $001457e0 + this.ee.ra.UL0 = 1318904u; + this.ee.pc = 1333216u; + // @00141FF4 ADDU a0, a0, t7 + this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct00141ff8() + { + this.ee.pc = 1318912u; + // @00141FF8 BEQ v0, zero, $0014202c + if ((this.ee.v0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1318956u; + } + // @00141FFC LW t6, $0004(sp) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.sp.UL0)); + } + + public virtual void funct00142000() + { + this.ee.pc = 1318928u; + // @00142000 LHU t6, $0000(s6) + MobUt.LHU(this.ee, this.ee.t6, (0u + this.ee.s6.UL0)); + // @00142004 SLTIU t7, t6, $03ff + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.UD0 < 1023ul)); + // @00142008 BEQ t7, zero, $0014208c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1319052u; + } + // @0014200C SLL t6, t6, 1 + MobUt.SLL(this.ee.t6, this.ee.t6, 1); + } + + public virtual void funct00142010() + { + this.ee.pc = 1318972u; + // @00142010 LW t7, $003c(s1) + MobUt.LW(this.ee, this.ee.t7, (60u + this.ee.s1.UL0)); + // @00142014 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00142018 SH s2, $0000(t6) + MobUt.SH(this.ee, this.ee.s2, (0u + this.ee.t6.UL0)); + // @0014201C LHU t7, $0000(s6) + MobUt.LHU(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); + // @00142020 ADDIU t7, t7, $0001 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 1))); + // @00142024 SH t7, $0000(s6) + MobUt.SH(this.ee, this.ee.t7, (0u + this.ee.s6.UL0)); + // @00142028 LW t6, $0004(sp) + MobUt.LW(this.ee, this.ee.t6, (4u + this.ee.sp.UL0)); + // @0014202C ADDIU s2, s2, $0001 + this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); + // @00142030 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @00142034 BNEL t7, zero, $00141f4c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1318732u; + // @00142038 LW t6, $000c(s1) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s1.UL0)); + } + } + + public virtual void funct0014202c() + { + this.ee.pc = 1318972u; + // @0014202C ADDIU s2, s2, $0001 + this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); + // @00142030 SLT t7, s2, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < this.ee.t6.SD0)); + // @00142034 BNEL t7, zero, $00141f4c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1318732u; + // @00142038 LW t6, $000c(s1) + MobUt.LW(this.ee, this.ee.t6, (12u + this.ee.s1.UL0)); + } + } + + public virtual void funct0014203c() + { + this.ee.pc = 1318988u; + // @0014203C ADDIU s3, s3, $0001 + this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); + // @00142040 SLT t7, s3, s8 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s3.SD0 < this.ee.s8.SD0)); + // @00142044 BNE t7, zero, $00141f0c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1318668u; + } + // @00142048 ADDIU s4, s4, $0014 + this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 20))); + } + + public virtual void funct00142040() + { + this.ee.pc = 1318988u; + // @00142040 SLT t7, s3, s8 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s3.SD0 < this.ee.s8.SD0)); + // @00142044 BNE t7, zero, $00141f0c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1318668u; + } + // @00142048 ADDIU s4, s4, $0014 + this.ee.s4.SD0 = ((int)((this.ee.s4.SD0 + 20))); + } + + public virtual void funct0014204c() + { + this.ee.pc = 1319016u; + // @0014204C DADDU s0, s7, zero + this.ee.s0.UD0 = (this.ee.s7.UD0 + this.ee.r0.UD0); + // @00142050 DADDU s2, zero, zero + this.ee.s2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00142054 ADDIU s3, zero, $ffff + this.ee.s3.SD0 = ((int)((this.ee.r0.SD0 + -1))); + // @00142058 LH t7, $0000(s0) + MobUt.LH(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); + // @0014205C ADDIU s0, s0, $0002 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 2))); + // @00142060 BEQ t7, s3, $0014208c + if ((this.ee.t7.UD0 == this.ee.s3.UD0)) + { + this.ee.pc = 1319052u; + } + // @00142064 DADDU a1, t7, zero + this.ee.a1.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0014205c() + { + this.ee.pc = 1319016u; + // @0014205C ADDIU s0, s0, $0002 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + 2))); + // @00142060 BEQ t7, s3, $0014208c + if ((this.ee.t7.UD0 == this.ee.s3.UD0)) + { + this.ee.pc = 1319052u; + } + // @00142064 DADDU a1, t7, zero + this.ee.a1.UD0 = (this.ee.t7.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00142068() + { + this.ee.pc = 1319040u; + // @00142068 LW t0, $0000(sp) + MobUt.LW(this.ee, this.ee.t0, (0u + this.ee.sp.UL0)); + // @0014206C DADDU a0, s1, zero + this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); + // @00142070 DADDU a2, s5, zero + this.ee.a2.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); + // @00142074 DADDU a3, s6, zero + this.ee.a3.UD0 = (this.ee.s6.UD0 + this.ee.r0.UD0); + // @00142078 JAL $00141e98 + this.ee.ra.UL0 = 1319040u; + this.ee.pc = 1318552u; + // @0014207C ADDIU s2, s2, $0001 + this.ee.s2.SD0 = ((int)((this.ee.s2.SD0 + 1))); + } + + public virtual void funct00142080() + { + this.ee.pc = 1319052u; + // @00142080 SLTI t7, s2, $0008 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s2.SD0 < 8)); + // @00142084 BNEL t7, zero, $0014205c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1319004u; + // @00142088 LH t7, $0000(s0) + MobUt.LH(this.ee, this.ee.t7, (0u + this.ee.s0.UL0)); + } + } + + public virtual void funct0014208c() + { + this.ee.pc = 1319100u; + // @0014208C LD s0, $0010(sp) + MobUt.LD(this.ee, this.ee.s0, (16u + this.ee.sp.UL0)); + // @00142090 LD s1, $0018(sp) + MobUt.LD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); + // @00142094 LD s2, $0020(sp) + MobUt.LD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); + // @00142098 LD s3, $0028(sp) + MobUt.LD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); + // @0014209C LD s4, $0030(sp) + MobUt.LD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); + // @001420A0 LD s5, $0038(sp) + MobUt.LD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); + // @001420A4 LD s6, $0040(sp) + MobUt.LD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); + // @001420A8 LD s7, $0048(sp) + MobUt.LD(this.ee, this.ee.s7, (72u + this.ee.sp.UL0)); + // @001420AC LD s8, $0050(sp) + MobUt.LD(this.ee, this.ee.s8, (80u + this.ee.sp.UL0)); + // @001420B0 LD ra, $0058(sp) + MobUt.LD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); + // @001420B4 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @001420B8 ADDIU sp, sp, $0060 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 96))); + } + + public virtual void funct00142090() + { + this.ee.pc = 1319100u; + // @00142090 LD s1, $0018(sp) + MobUt.LD(this.ee, this.ee.s1, (24u + this.ee.sp.UL0)); + // @00142094 LD s2, $0020(sp) + MobUt.LD(this.ee, this.ee.s2, (32u + this.ee.sp.UL0)); + // @00142098 LD s3, $0028(sp) + MobUt.LD(this.ee, this.ee.s3, (40u + this.ee.sp.UL0)); + // @0014209C LD s4, $0030(sp) + MobUt.LD(this.ee, this.ee.s4, (48u + this.ee.sp.UL0)); + // @001420A0 LD s5, $0038(sp) + MobUt.LD(this.ee, this.ee.s5, (56u + this.ee.sp.UL0)); + // @001420A4 LD s6, $0040(sp) + MobUt.LD(this.ee, this.ee.s6, (64u + this.ee.sp.UL0)); + // @001420A8 LD s7, $0048(sp) + MobUt.LD(this.ee, this.ee.s7, (72u + this.ee.sp.UL0)); + // @001420AC LD s8, $0050(sp) + MobUt.LD(this.ee, this.ee.s8, (80u + this.ee.sp.UL0)); + // @001420B0 LD ra, $0058(sp) + MobUt.LD(this.ee, this.ee.ra, (88u + this.ee.sp.UL0)); + // @001420B4 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @001420B8 ADDIU sp, sp, $0060 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 96))); + } + + public virtual void funct001420bc() + { + this.ee.pc = 1319128u; + // @001420BC LW t5, $0000(a2) + MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.a2.UL0)); + // @001420C0 LW t7, $0040(s1) + MobUt.LW(this.ee, this.ee.t7, (64u + this.ee.s1.UL0)); + // @001420C4 LW t6, $0044(s1) + MobUt.LW(this.ee, this.ee.t6, (68u + this.ee.s1.UL0)); + // @001420C8 AND t7, t5, t7 + this.ee.t7.UD0 = (this.ee.t5.UD0 & this.ee.t7.UD0); + // @001420CC XOR t7, t7, t6 + MobUt.XOR(this.ee.t7, this.ee.t7, this.ee.t6); + // @001420D0 BEQ zero, zero, $00141f88 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1318792u; + } + // @001420D4 SLTIU t7, t7, $0001 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < 1ul)); + } + + public virtual void funct001420d8() + { + this.ee.pc = 1319220u; + // @001420D8 ADDIU sp, sp, $ff30 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -208))); + // @001420DC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @001420E0 SD s1, $0078(sp) + MobUt.SD(this.ee, this.ee.s1, (120u + this.ee.sp.UL0)); + // @001420E4 ADDIU t7, t7, $873c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30916))); + // @001420E8 SD s2, $0080(sp) + MobUt.SD(this.ee, this.ee.s2, (128u + this.ee.sp.UL0)); + // @001420EC SD s3, $0088(sp) + MobUt.SD(this.ee, this.ee.s3, (136u + this.ee.sp.UL0)); + // @001420F0 DADDU s1, a0, zero + this.ee.s1.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); + // @001420F4 SD s6, $00a0(sp) + MobUt.SD(this.ee, this.ee.s6, (160u + this.ee.sp.UL0)); + // @001420F8 DADDU s2, a1, zero + this.ee.s2.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + // @001420FC SD s7, $00a8(sp) + MobUt.SD(this.ee, this.ee.s7, (168u + this.ee.sp.UL0)); + // @00142100 DADDU s3, zero, zero + this.ee.s3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00142104 SD s0, $0070(sp) + MobUt.SD(this.ee, this.ee.s0, (112u + this.ee.sp.UL0)); + // @00142108 DADDU s6, a3, zero + this.ee.s6.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); + // @0014210C SD s4, $0090(sp) + MobUt.SD(this.ee, this.ee.s4, (144u + this.ee.sp.UL0)); + // @00142110 DADDU s7, a2, zero + this.ee.s7.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); + // @00142114 SD s5, $0098(sp) + MobUt.SD(this.ee, this.ee.s5, (152u + this.ee.sp.UL0)); + // @00142118 SD s8, $00b0(sp) + MobUt.SD(this.ee, this.ee.s8, (176u + this.ee.sp.UL0)); + // @0014211C SD ra, $00b8(sp) + MobUt.SD(this.ee, this.ee.ra, (184u + this.ee.sp.UL0)); + // @00142120 SWC1 $f20, $00c0(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (192u + this.ee.sp.UL0)); + // @00142124 LWC1 $f20, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[20], (0u + this.ee.t7.UL0)); + // @00142128 ORI t7, zero, $ffff + this.ee.t7.UD0 = (this.ee.r0.UD0 | 65535); + // @0014212C BLEZ a2, $00142218 + if ((this.ee.a2.SD0 <= 0)) + { + this.ee.pc = 1319448u; + } + // @00142130 SW t7, $0060(sp) + MobUt.SW(this.ee, this.ee.t7, (96u + this.ee.sp.UL0)); + } + + public virtual void funct00142134() + { + this.ee.pc = 1319272u; + // @00142134 ADDIU s8, sp, $0010 + this.ee.s8.SD0 = ((int)((this.ee.sp.SD0 + 16))); + // @00142138 ADDIU s4, sp, $0030 + this.ee.s4.SD0 = ((int)((this.ee.sp.SD0 + 48))); + // @0014213C LW t7, $003c(s1) + MobUt.LW(this.ee, this.ee.t7, (60u + this.ee.s1.UL0)); + // @00142140 SLL t6, s3, 1 + MobUt.SLL(this.ee.t6, this.ee.s3, 1); + // @00142144 LW s0, $000c(s1) + MobUt.LW(this.ee, this.ee.s0, (12u + this.ee.s1.UL0)); + // @00142148 DADDU a0, s1, zero + this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); + // @0014214C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00142150 DADDU a2, s8, zero + this.ee.a2.UD0 = (this.ee.s8.UD0 + this.ee.r0.UD0); + // @00142154 LHU s5, $0000(t6) + MobUt.LHU(this.ee, this.ee.s5, (0u + this.ee.t6.UL0)); + // @00142158 SLL t7, s5, 4 + MobUt.SLL(this.ee.t7, this.ee.s5, 4); + // @0014215C ADDU s0, s0, t7 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t7.SD0))); + // @00142160 JAL $00141be8 + this.ee.ra.UL0 = 1319272u; + this.ee.pc = 1317864u; + // @00142164 DADDU a1, s0, zero + this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00142140() + { + this.ee.pc = 1319272u; + // @00142140 SLL t6, s3, 1 + MobUt.SLL(this.ee.t6, this.ee.s3, 1); + // @00142144 LW s0, $000c(s1) + MobUt.LW(this.ee, this.ee.s0, (12u + this.ee.s1.UL0)); + // @00142148 DADDU a0, s1, zero + this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); + // @0014214C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @00142150 DADDU a2, s8, zero + this.ee.a2.UD0 = (this.ee.s8.UD0 + this.ee.r0.UD0); + // @00142154 LHU s5, $0000(t6) + MobUt.LHU(this.ee, this.ee.s5, (0u + this.ee.t6.UL0)); + // @00142158 SLL t7, s5, 4 + MobUt.SLL(this.ee.t7, this.ee.s5, 4); + // @0014215C ADDU s0, s0, t7 + this.ee.s0.SD0 = ((int)((this.ee.s0.SD0 + this.ee.t7.SD0))); + // @00142160 JAL $00141be8 + this.ee.ra.UL0 = 1319272u; + this.ee.pc = 1317864u; + // @00142164 DADDU a1, s0, zero + this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00142168() + { + this.ee.pc = 1319316u; + // @00142168 LHU t6, $000a(s0) + MobUt.LHU(this.ee, this.ee.t6, (10u + this.ee.s0.UL0)); + // @0014216C LW t7, $0018(s1) + MobUt.LW(this.ee, this.ee.t7, (24u + this.ee.s1.UL0)); + // @00142170 SLL t6, t6, 4 + MobUt.SLL(this.ee.t6, this.ee.t6, 4); + // @00142174 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @00142178 LQ t0, $0000(t7) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @0014217C SQ t0, $0000(s4) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s4.UL[0])); + // @00142180 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @00142184 DADDU a1, s8, zero + this.ee.a1.UD0 = (this.ee.s8.UD0 + this.ee.r0.UD0); + // @00142188 DADDU a2, s4, zero + this.ee.a2.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + // @0014218C JAL $00162670 + this.ee.ra.UL0 = 1319316u; + this.ee.pc = 1451632u; + // @00142190 DADDU a3, sp, zero + this.ee.a3.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00142194() + { + this.ee.pc = 1319324u; + // @00142194 BEQ v0, zero, $00142208 + if ((this.ee.v0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1319432u; + } + // @00142198 ADDIU t6, sp, $0040 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 64))); + } + + public virtual void funct00142208() + { + this.ee.pc = 1319448u; + // @00142208 ADDIU s3, s3, $0001 + this.ee.s3.SD0 = ((int)((this.ee.s3.SD0 + 1))); + // @0014220C SLT t7, s3, s7 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s3.SD0 < this.ee.s7.SD0)); + // @00142210 BNEL t7, zero, $00142140 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1319232u; + // @00142214 LW t7, $003c(s1) + MobUt.LW(this.ee, this.ee.t7, (60u + this.ee.s1.UL0)); + } + } + + public virtual void funct00142218() + { + this.ee.pc = 1319504u; + // @00142218 LW v0, $0060(sp) + MobUt.LW(this.ee, this.ee.v0, (96u + this.ee.sp.UL0)); + // @0014221C LD s0, $0070(sp) + MobUt.LD(this.ee, this.ee.s0, (112u + this.ee.sp.UL0)); + // @00142220 LD s1, $0078(sp) + MobUt.LD(this.ee, this.ee.s1, (120u + this.ee.sp.UL0)); + // @00142224 LD s2, $0080(sp) + MobUt.LD(this.ee, this.ee.s2, (128u + this.ee.sp.UL0)); + // @00142228 LD s3, $0088(sp) + MobUt.LD(this.ee, this.ee.s3, (136u + this.ee.sp.UL0)); + // @0014222C LD s4, $0090(sp) + MobUt.LD(this.ee, this.ee.s4, (144u + this.ee.sp.UL0)); + // @00142230 LD s5, $0098(sp) + MobUt.LD(this.ee, this.ee.s5, (152u + this.ee.sp.UL0)); + // @00142234 LD s6, $00a0(sp) + MobUt.LD(this.ee, this.ee.s6, (160u + this.ee.sp.UL0)); + // @00142238 LD s7, $00a8(sp) + MobUt.LD(this.ee, this.ee.s7, (168u + this.ee.sp.UL0)); + // @0014223C LD s8, $00b0(sp) + MobUt.LD(this.ee, this.ee.s8, (176u + this.ee.sp.UL0)); + // @00142240 LD ra, $00b8(sp) + MobUt.LD(this.ee, this.ee.ra, (184u + this.ee.sp.UL0)); + // @00142244 LWC1 $f20, $00c0(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (192u + this.ee.sp.UL0)); + // @00142248 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0014224C ADDIU sp, sp, $00d0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 208))); + } + + public virtual void funct00142250() + { + this.ee.pc = 1319592u; + // @00142250 ADDIU sp, sp, $f730 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -2256))); + // @00142254 SD s1, $0898(sp) + MobUt.SD(this.ee, this.ee.s1, (2200u + this.ee.sp.UL0)); + // @00142258 SD s4, $08b0(sp) + MobUt.SD(this.ee, this.ee.s4, (2224u + this.ee.sp.UL0)); + // @0014225C SD s5, $08b8(sp) + MobUt.SD(this.ee, this.ee.s5, (2232u + this.ee.sp.UL0)); + // @00142260 DADDU s1, a0, zero + this.ee.s1.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); + // @00142264 SD s6, $08c0(sp) + MobUt.SD(this.ee, this.ee.s6, (2240u + this.ee.sp.UL0)); + // @00142268 DADDU s4, a2, zero + this.ee.s4.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); + // @0014226C SD s0, $0890(sp) + MobUt.SD(this.ee, this.ee.s0, (2192u + this.ee.sp.UL0)); + // @00142270 DADDU s5, t0, zero + this.ee.s5.UD0 = (this.ee.t0.UD0 + this.ee.r0.UD0); + // @00142274 SD s2, $08a0(sp) + MobUt.SD(this.ee, this.ee.s2, (2208u + this.ee.sp.UL0)); + // @00142278 DADDU s6, a3, zero + this.ee.s6.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); + // @0014227C SD s3, $08a8(sp) + MobUt.SD(this.ee, this.ee.s3, (2216u + this.ee.sp.UL0)); + // @00142280 SD ra, $08c8(sp) + MobUt.SD(this.ee, this.ee.ra, (2248u + this.ee.sp.UL0)); + // @00142284 LQ t0, $0000(a1) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @00142288 SQ t0, $0000(sp) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); + // @0014228C ADDIU a1, a1, $0010 + this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); + // @00142290 ADDIU t6, sp, $0010 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 16))); + // @00142294 LQ t0, $0000(a1) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @00142298 SQ t0, $0000(t6) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t6.UL[0])); + // @0014229C LBU t7, $00d1(a0) + MobUt.LBU(this.ee, this.ee.t7, (209u + this.ee.a0.UL0)); + // @001422A0 BNE t7, zero, $00142320 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1319712u; + } + // @001422A4 ADDIU s2, sp, $0020 + this.ee.s2.SD0 = ((int)((this.ee.sp.SD0 + 32))); + } + + public virtual void funct00142320() + { + this.ee.pc = 1319724u; + // @00142320 ADDIU s3, sp, $0030 + this.ee.s3.SD0 = ((int)((this.ee.sp.SD0 + 48))); + // @00142324 BEQ s3, sp, $00142338 + if ((this.ee.s3.UD0 == this.ee.sp.UD0)) + { + this.ee.pc = 1319736u; + } + // @00142328 ADDIU t7, sp, $0040 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); + } + + public virtual void funct0014232c() + { + this.ee.pc = 1319760u; + // @0014232C LQ t0, $0000(sp) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); + // @00142330 SQ t0, $0000(s3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @00142334 ADDIU t7, sp, $0040 + this.ee.t7.SD0 = ((int)((this.ee.sp.SD0 + 64))); + // @00142338 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @0014233C LQC2 vf2, $0000(sp) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.sp.UL0)); + // @00142340 VSUB.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); + // @00142344 SQC2 vf1, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); + // @00142348 BEQL t7, s2, $0014235c + if ((this.ee.t7.UD0 == this.ee.s2.UD0)) + { + this.ee.pc = 1319772u; + // @0014234C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + } + + public virtual void funct00142350() + { + this.ee.pc = 1319804u; + // @00142350 LQ t0, $0000(s2) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.s2.UL[0])); + // @00142354 SQ t0, $0000(t7) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.t7.UL[0])); + // @00142358 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @0014235C ADDIU s0, sp, $0050 + this.ee.s0.SD0 = ((int)((this.ee.sp.SD0 + 80))); + // @00142360 ADDIU t7, t7, $8740 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30912))); + // @00142364 DADDU a1, sp, zero + this.ee.a1.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); + // @00142368 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @0014236C DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @00142370 SWC1 $f0, $003c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (60u + this.ee.sp.UL0)); + // @00142374 JAL $00144878 + this.ee.ra.UL0 = 1319804u; + this.ee.pc = 1329272u; + // @00142378 SWC1 $f0, $004c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[0], (76u + this.ee.sp.UL0)); + } + + public virtual void funct0014237c() + { + this.ee.pc = 1319812u; + // @0014237C JAL $00145090 + this.ee.ra.UL0 = 1319812u; + this.ee.pc = 1331344u; + // @00142380 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00142384() + { + this.ee.pc = 1319820u; + // @00142384 JAL $00141bd0 + this.ee.ra.UL0 = 1319820u; + this.ee.pc = 1317840u; + // @00142388 DADDU a0, s1, zero + this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0014238c() + { + this.ee.pc = 1319836u; + // @0014238C DADDU a2, v0, zero + this.ee.a2.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); + // @00142390 DADDU a0, s2, zero + this.ee.a0.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @00142394 JAL $001450b0 + this.ee.ra.UL0 = 1319836u; + this.ee.pc = 1331376u; + // @00142398 DADDU a1, s0, zero + this.ee.a1.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0014239c() + { + this.ee.pc = 1319852u; + // @0014239C SH zero, $0070(sp) + MobUt.SH(this.ee, this.ee.r0, (112u + this.ee.sp.UL0)); + // @001423A0 ADDIU a1, sp, $0080 + this.ee.a1.SD0 = ((int)((this.ee.sp.SD0 + 128))); + // @001423A4 JAL $00141be0 + this.ee.ra.UL0 = 1319852u; + this.ee.pc = 1317856u; + // @001423A8 DADDU a0, s1, zero + this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001423ac() + { + this.ee.pc = 1319876u; + // @001423AC DADDU a2, s2, zero + this.ee.a2.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @001423B0 ADDIU a3, sp, $0070 + this.ee.a3.SD0 = ((int)((this.ee.sp.SD0 + 112))); + // @001423B4 DADDU t0, s5, zero + this.ee.t0.UD0 = (this.ee.s5.UD0 + this.ee.r0.UD0); + // @001423B8 DADDU a0, s1, zero + this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); + // @001423BC JAL $00141e98 + this.ee.ra.UL0 = 1319876u; + this.ee.pc = 1318552u; + // @001423C0 DADDU a1, zero, zero + this.ee.a1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001423c4() + { + this.ee.pc = 1319896u; + // @001423C4 LHU a2, $0070(sp) + MobUt.LHU(this.ee, this.ee.a2, (112u + this.ee.sp.UL0)); + // @001423C8 DADDU a1, s3, zero + this.ee.a1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); + // @001423CC DADDU a0, s1, zero + this.ee.a0.UD0 = (this.ee.s1.UD0 + this.ee.r0.UD0); + // @001423D0 JAL $001420d8 + this.ee.ra.UL0 = 1319896u; + this.ee.pc = 1319128u; + // @001423D4 DADDU a3, s4, zero + this.ee.a3.UD0 = (this.ee.s4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001423d8() + { + this.ee.pc = 1319912u; + // @001423D8 SH v0, $0000(s6) + MobUt.SH(this.ee, this.ee.v0, (0u + this.ee.s6.UL0)); + // @001423DC ORI t7, zero, $ffff + this.ee.t7.UD0 = (this.ee.r0.UD0 | 65535); + // @001423E0 BEQ v0, t7, $00142438 + if ((this.ee.v0.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1319992u; + } + // @001423E4 DADDU t6, zero, zero + this.ee.t6.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00142438() + { + this.ee.pc = 1320036u; + // @00142438 LD s0, $0890(sp) + MobUt.LD(this.ee, this.ee.s0, (2192u + this.ee.sp.UL0)); + // @0014243C DADDU v0, t6, zero + this.ee.v0.UD0 = (this.ee.t6.UD0 + this.ee.r0.UD0); + // @00142440 LD s1, $0898(sp) + MobUt.LD(this.ee, this.ee.s1, (2200u + this.ee.sp.UL0)); + // @00142444 LD s2, $08a0(sp) + MobUt.LD(this.ee, this.ee.s2, (2208u + this.ee.sp.UL0)); + // @00142448 LD s3, $08a8(sp) + MobUt.LD(this.ee, this.ee.s3, (2216u + this.ee.sp.UL0)); + // @0014244C LD s4, $08b0(sp) + MobUt.LD(this.ee, this.ee.s4, (2224u + this.ee.sp.UL0)); + // @00142450 LD s5, $08b8(sp) + MobUt.LD(this.ee, this.ee.s5, (2232u + this.ee.sp.UL0)); + // @00142454 LD s6, $08c0(sp) + MobUt.LD(this.ee, this.ee.s6, (2240u + this.ee.sp.UL0)); + // @00142458 LD ra, $08c8(sp) + MobUt.LD(this.ee, this.ee.ra, (2248u + this.ee.sp.UL0)); + // @0014245C JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00142460 ADDIU sp, sp, $08d0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 2256))); + } + + public virtual void funct00143ec8() + { + this.ee.pc = 1326864u; + // @00143EC8 ADDIU sp, sp, $ffb0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -80))); + // @00143ECC DADDU t1, zero, zero + this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00143ED0 SD s2, $0030(sp) + MobUt.SD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); + // @00143ED4 ADDIU t2, sp, $0014 + this.ee.t2.SD0 = ((int)((this.ee.sp.SD0 + 20))); + // @00143ED8 SD s3, $0038(sp) + MobUt.SD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); + // @00143EDC ADDIU t3, zero, $000f + this.ee.t3.SD0 = ((int)((this.ee.r0.SD0 + 15))); + // @00143EE0 SD ra, $0040(sp) + MobUt.SD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); + // @00143EE4 DADDU s2, a1, zero + this.ee.s2.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + // @00143EE8 SD s0, $0020(sp) + MobUt.SD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); + // @00143EEC DADDU s3, a0, zero + this.ee.s3.UD0 = (this.ee.a0.UD0 + this.ee.r0.UD0); + // @00143EF0 SD s1, $0028(sp) + MobUt.SD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); + // @00143EF4 ADDIU a2, sp, $0010 + this.ee.a2.SD0 = ((int)((this.ee.sp.SD0 + 16))); + // @00143EF8 SW zero, $0014(sp) + MobUt.SW(this.ee, this.ee.r0, (20u + this.ee.sp.UL0)); + // @00143EFC ADDIU a3, zero, $0200 + this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 512))); + // @00143F00 SW zero, $0000(sp) + MobUt.SW(this.ee, this.ee.r0, (0u + this.ee.sp.UL0)); + // @00143F04 ADDIU t0, zero, $0200 + this.ee.t0.SD0 = ((int)((this.ee.r0.SD0 + 512))); + // @00143F08 JAL $00165aa8 + this.ee.ra.UL0 = 1326864u; + this.ee.pc = 1465000u; + // @00143F0C LUI s1, $0035 + this.ee.s1.SD0 = 3473408; + } + + public virtual void funct00143f10() + { + this.ee.pc = 1326892u; + // @00143F10 LW a0, $5134(s1) + MobUt.LW(this.ee, this.ee.a0, (20788u + this.ee.s1.UL0)); + // @00143F14 DADDU s0, v0, zero + this.ee.s0.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); + // @00143F18 ADDIU a1, zero, $0200 + this.ee.a1.SD0 = ((int)((this.ee.r0.SD0 + 512))); + // @00143F1C ADDIU a2, zero, $0200 + this.ee.a2.SD0 = ((int)((this.ee.r0.SD0 + 512))); + // @00143F20 DADDU a3, zero, zero + this.ee.a3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00143F24 JAL $00141e78 + this.ee.ra.UL0 = 1326892u; + this.ee.pc = 1318520u; + // @00143F28 DADDU t0, zero, zero + this.ee.t0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00143f2c() + { + this.ee.pc = 1326916u; + // @00143F2C LW a0, $5134(s1) + MobUt.LW(this.ee, this.ee.a0, (20788u + this.ee.s1.UL0)); + // @00143F30 DADDU a1, s3, zero + this.ee.a1.UD0 = (this.ee.s3.UD0 + this.ee.r0.UD0); + // @00143F34 DADDU a2, s2, zero + this.ee.a2.UD0 = (this.ee.s2.UD0 + this.ee.r0.UD0); + // @00143F38 ADDIU a3, sp, $0010 + this.ee.a3.SD0 = ((int)((this.ee.sp.SD0 + 16))); + // @00143F3C JAL $00142250 + this.ee.ra.UL0 = 1326916u; + this.ee.pc = 1319504u; + // @00143F40 ADDIU t0, zero, $000f + this.ee.t0.SD0 = ((int)((this.ee.r0.SD0 + 15))); + } + + public virtual void funct00143f44() + { + this.ee.pc = 1326956u; + // @00143F44 OR s0, s0, v0 + this.ee.s0.UD0 = (this.ee.s0.UD0 | this.ee.v0.UD0); + // @00143F48 LD s1, $0028(sp) + MobUt.LD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); + // @00143F4C SLTU s0, zero, s0 + this.ee.s0.UD0 = System.Convert.ToByte((this.ee.r0.UD0 < this.ee.s0.UD0)); + // @00143F50 LD s2, $0030(sp) + MobUt.LD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); + // @00143F54 DADDU v0, s0, zero + this.ee.v0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + // @00143F58 LD s3, $0038(sp) + MobUt.LD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); + // @00143F5C LD s0, $0020(sp) + MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); + // @00143F60 LD ra, $0040(sp) + MobUt.LD(this.ee, this.ee.ra, (64u + this.ee.sp.UL0)); + // @00143F64 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00143F68 ADDIU sp, sp, $0050 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 80))); + } + + public virtual void funct00144878() + { + this.ee.pc = 1329296u; + // @00144878 ADDIU sp, sp, $fff0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); + // @0014487C ADDIU a2, a1, $0010 + this.ee.a2.SD0 = ((int)((this.ee.a1.SD0 + 16))); + // @00144880 SD ra, $0000(sp) + MobUt.SD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); + // @00144884 LD ra, $0000(sp) + MobUt.LD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); + // @00144888 J $00144a40 + this.ee.pc = 1329728u; + // @0014488C ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00144a40() + { + this.ee.pc = 1329748u; + // @00144A40 LWC1 $f1, $0000(a1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.a1.UL0)); + // @00144A44 LWC1 $f0, $0000(a2) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.a2.UL0)); + // @00144A48 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @00144A4C BC1FL $00144ab4 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1329844u; + // @00144A50 SWC1 $f0, $0000(a0) + MobUt.SWC1(this.ee, this.ee.fpr[0], (0u + this.ee.a0.UL0)); + } + } + + public virtual void funct00144a5c() + { + this.ee.pc = 1329780u; + // @00144A5C SWC1 $f0, $000c(a0) + MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.a0.UL0)); + // @00144A60 LWC1 $f1, $0004(a1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (4u + this.ee.a1.UL0)); + // @00144A64 LWC1 $f0, $0004(a2) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.a2.UL0)); + // @00144A68 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @00144A6C BC1FL $00144aac + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1329836u; + // @00144A70 SWC1 $f0, $0004(a0) + MobUt.SWC1(this.ee, this.ee.fpr[0], (4u + this.ee.a0.UL0)); + } + } + + public virtual void funct00144a74() + { + this.ee.pc = 1329812u; + // @00144A74 SWC1 $f1, $0004(a0) + MobUt.SWC1(this.ee, this.ee.fpr[1], (4u + this.ee.a0.UL0)); + // @00144A78 LWC1 $f0, $0004(a2) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.a2.UL0)); + // @00144A7C SWC1 $f0, $0010(a0) + MobUt.SWC1(this.ee, this.ee.fpr[0], (16u + this.ee.a0.UL0)); + // @00144A80 LWC1 $f1, $0008(a1) + MobUt.LWC1(this.ee, this.ee.fpr[1], (8u + this.ee.a1.UL0)); + // @00144A84 LWC1 $f0, $0008(a2) + MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.a2.UL0)); + // @00144A88 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @00144A8C BC1FL $00144aa4 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1329828u; + // @00144A90 SWC1 $f0, $0008(a0) + MobUt.SWC1(this.ee, this.ee.fpr[0], (8u + this.ee.a0.UL0)); + } + } + + public virtual void funct00144a9c() + { + this.ee.pc = 1329828u; + // @00144A9C JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00144AA0 SWC1 $f0, $0014(a0) + MobUt.SWC1(this.ee, this.ee.fpr[0], (20u + this.ee.a0.UL0)); + } + + public virtual void funct00144aa4() + { + this.ee.pc = 1329836u; + // @00144AA4 BEQ zero, zero, $00144a9c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1329820u; + } + // @00144AA8 LWC1 $f0, $0008(a1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.a1.UL0)); + } + + public virtual void funct00144ab4() + { + this.ee.pc = 1329852u; + // @00144AB4 BEQ zero, zero, $00144a5c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1329756u; + } + // @00144AB8 LWC1 $f0, $0000(a1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.a1.UL0)); + } + + public virtual void funct00145090() + { + this.ee.pc = 1331372u; + // @00145090 SH zero, $0000(a0) + MobUt.SH(this.ee, this.ee.r0, (0u + this.ee.a0.UL0)); + // @00145094 SH zero, $000a(a0) + MobUt.SH(this.ee, this.ee.r0, (10u + this.ee.a0.UL0)); + // @00145098 SH zero, $0008(a0) + MobUt.SH(this.ee, this.ee.r0, (8u + this.ee.a0.UL0)); + // @0014509C SH zero, $0006(a0) + MobUt.SH(this.ee, this.ee.r0, (6u + this.ee.a0.UL0)); + // @001450A0 SH zero, $0004(a0) + MobUt.SH(this.ee, this.ee.r0, (4u + this.ee.a0.UL0)); + // @001450A4 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @001450A8 SH zero, $0002(a0) + MobUt.SH(this.ee, this.ee.r0, (2u + this.ee.a0.UL0)); + } + + public virtual void funct001450b0() + { + this.ee.pc = 1331424u; + // @001450B0 LUI t7, $0035 + this.ee.t7.SD0 = 3473408; + // @001450B4 LWC1 $f0, $0000(a1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.a1.UL0)); + // @001450B8 SLL t6, a2, 2 + MobUt.SLL(this.ee.t6, this.ee.a2, 2); + // @001450BC ADDIU t7, t7, $5660 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 22112))); + // @001450C0 ADDU t7, t6, t7 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @001450C4 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @001450C8 LUI t7, $0035 + this.ee.t7.SD0 = 3473408; + // @001450CC SUB.S $f1, $f0, $f2 + this.ee.fpr[1].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); + // @001450D0 ADDIU t7, t7, $5670 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 22128))); + // @001450D4 ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @001450D8 BEQ a2, zero, $001450e4 + if ((this.ee.a2.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1331428u; + } + // @001450DC LWC1 $f3, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t6.UL0)); + } + + public virtual void funct001450e4() + { + this.ee.pc = 1331452u; + // @001450E4 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @001450E8 ADDIU t7, t7, $87d4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30764))); + // @001450EC LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @001450F0 C.LT.S $f0, $f1 + this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[1].f); + // @001450F4 BC1TL $00145134 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1331508u; + // @001450F8 CVT.W.S $f0, $f1 + MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); + } + } + + public virtual void funct00145134() + { + this.ee.pc = 1331528u; + // @00145134 MFC1 t7, $f0 + MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); + // @00145138 SH t7, $0000(a0) + MobUt.SH(this.ee, this.ee.t7, (0u + this.ee.a0.UL0)); + // @0014513C LWC1 $f0, $0004(a1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (4u + this.ee.a1.UL0)); + // @00145140 BEQ a2, zero, $0014514c + if ((this.ee.a2.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1331532u; + } + // @00145144 SUB.S $f1, $f0, $f2 + this.ee.fpr[1].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); + } + + public virtual void funct0014514c() + { + this.ee.pc = 1331556u; + // @0014514C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00145150 ADDIU t7, t7, $87d4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30764))); + // @00145154 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00145158 C.LT.S $f0, $f1 + this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[1].f); + // @0014515C BC1TL $0014519c + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1331612u; + // @00145160 CVT.W.S $f0, $f1 + MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); + } + } + + public virtual void funct0014519c() + { + this.ee.pc = 1331632u; + // @0014519C MFC1 t7, $f0 + MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); + // @001451A0 SH t7, $0002(a0) + MobUt.SH(this.ee, this.ee.t7, (2u + this.ee.a0.UL0)); + // @001451A4 LWC1 $f0, $0008(a1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (8u + this.ee.a1.UL0)); + // @001451A8 BEQ a2, zero, $001451b4 + if ((this.ee.a2.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1331636u; + } + // @001451AC SUB.S $f1, $f0, $f2 + this.ee.fpr[1].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); + } + + public virtual void funct001451b4() + { + this.ee.pc = 1331660u; + // @001451B4 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @001451B8 ADDIU t7, t7, $87d4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30764))); + // @001451BC LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @001451C0 C.LT.S $f0, $f1 + this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[1].f); + // @001451C4 BC1TL $00145204 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1331716u; + // @001451C8 CVT.W.S $f0, $f1 + MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); + } + } + + public virtual void funct00145204() + { + this.ee.pc = 1331736u; + // @00145204 MFC1 t7, $f0 + MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); + // @00145208 SH t7, $0004(a0) + MobUt.SH(this.ee, this.ee.t7, (4u + this.ee.a0.UL0)); + // @0014520C LWC1 $f0, $000c(a1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (12u + this.ee.a1.UL0)); + // @00145210 BEQ a2, zero, $0014521c + if ((this.ee.a2.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1331740u; + } + // @00145214 ADD.S $f1, $f0, $f2 + this.ee.fpr[1].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + } + + public virtual void funct0014521c() + { + this.ee.pc = 1331764u; + // @0014521C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00145220 ADDIU t7, t7, $87e0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30752))); + // @00145224 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00145228 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @0014522C BC1TL $0014526c + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1331820u; + // @00145230 CVT.W.S $f0, $f1 + MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); + } + } + + public virtual void funct0014526c() + { + this.ee.pc = 1331840u; + // @0014526C MFC1 t7, $f0 + MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); + // @00145270 SH t7, $0006(a0) + MobUt.SH(this.ee, this.ee.t7, (6u + this.ee.a0.UL0)); + // @00145274 LWC1 $f0, $0010(a1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (16u + this.ee.a1.UL0)); + // @00145278 BEQ a2, zero, $00145284 + if ((this.ee.a2.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1331844u; + } + // @0014527C ADD.S $f1, $f0, $f2 + this.ee.fpr[1].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + } + + public virtual void funct00145284() + { + this.ee.pc = 1331868u; + // @00145284 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00145288 ADDIU t7, t7, $87e0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30752))); + // @0014528C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00145290 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @00145294 BC1TL $001452d4 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1331924u; + // @00145298 CVT.W.S $f0, $f1 + MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); + } + } + + public virtual void funct001452d4() + { + this.ee.pc = 1331944u; + // @001452D4 MFC1 t7, $f0 + MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); + // @001452D8 SH t7, $0008(a0) + MobUt.SH(this.ee, this.ee.t7, (8u + this.ee.a0.UL0)); + // @001452DC LWC1 $f0, $0014(a1) + MobUt.LWC1(this.ee, this.ee.fpr[0], (20u + this.ee.a1.UL0)); + // @001452E0 BEQ a2, zero, $001452ec + if ((this.ee.a2.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1331948u; + } + // @001452E4 ADD.S $f1, $f0, $f2 + this.ee.fpr[1].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + } + + public virtual void funct001452ec() + { + this.ee.pc = 1331972u; + // @001452EC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @001452F0 ADDIU t7, t7, $87e0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -30752))); + // @001452F4 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @001452F8 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @001452FC BC1TL $0014533c + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1332028u; + // @00145300 CVT.W.S $f0, $f1 + MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); + } + } + + public virtual void funct0014533c() + { + this.ee.pc = 1332040u; + // @0014533C MFC1 t7, $f0 + MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); + // @00145340 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00145344 SH t7, $000a(a0) + MobUt.SH(this.ee, this.ee.t7, (10u + this.ee.a0.UL0)); + } + + public virtual void funct001457e0() + { + this.ee.pc = 1333236u; + // @001457E0 LH t7, $0006(a0) + MobUt.LH(this.ee, this.ee.t7, (6u + this.ee.a0.UL0)); + // @001457E4 LH t6, $0000(a1) + MobUt.LH(this.ee, this.ee.t6, (0u + this.ee.a1.UL0)); + // @001457E8 SLT t7, t7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); + // @001457EC BNE t7, zero, $00145854 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1333332u; + } + // @001457F0 DADDU v0, zero, zero + this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001457f4() + { + this.ee.pc = 1333256u; + // @001457F4 LH t6, $0000(a0) + MobUt.LH(this.ee, this.ee.t6, (0u + this.ee.a0.UL0)); + // @001457F8 LH t7, $0006(a1) + MobUt.LH(this.ee, this.ee.t7, (6u + this.ee.a1.UL0)); + // @001457FC SLT t7, t7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); + // @00145800 BNE t7, zero, $00145854 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1333332u; + } + // @00145804 NOP + MobUt.Latency(); + } + + public virtual void funct00145808() + { + this.ee.pc = 1333276u; + // @00145808 LH t7, $0008(a0) + MobUt.LH(this.ee, this.ee.t7, (8u + this.ee.a0.UL0)); + // @0014580C LH t6, $0002(a1) + MobUt.LH(this.ee, this.ee.t6, (2u + this.ee.a1.UL0)); + // @00145810 SLT t7, t7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); + // @00145814 BNE t7, zero, $00145854 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1333332u; + } + // @00145818 NOP + MobUt.Latency(); + } + + public virtual void funct0014581c() + { + this.ee.pc = 1333296u; + // @0014581C LH t6, $0002(a0) + MobUt.LH(this.ee, this.ee.t6, (2u + this.ee.a0.UL0)); + // @00145820 LH t7, $0008(a1) + MobUt.LH(this.ee, this.ee.t7, (8u + this.ee.a1.UL0)); + // @00145824 SLT t7, t7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); + // @00145828 BNE t7, zero, $00145854 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1333332u; + } + // @0014582C NOP + MobUt.Latency(); + } + + public virtual void funct00145830() + { + this.ee.pc = 1333316u; + // @00145830 LH t7, $000a(a0) + MobUt.LH(this.ee, this.ee.t7, (10u + this.ee.a0.UL0)); + // @00145834 LH t6, $0004(a1) + MobUt.LH(this.ee, this.ee.t6, (4u + this.ee.a1.UL0)); + // @00145838 SLT t7, t7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); + // @0014583C BNE t7, zero, $00145854 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1333332u; + } + // @00145840 NOP + MobUt.Latency(); + } + + public virtual void funct00145844() + { + this.ee.pc = 1333340u; + // @00145844 LH t6, $0004(a0) + MobUt.LH(this.ee, this.ee.t6, (4u + this.ee.a0.UL0)); + // @00145848 LH t7, $000a(a1) + MobUt.LH(this.ee, this.ee.t7, (10u + this.ee.a1.UL0)); + // @0014584C SLT t7, t7, t6 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t6.SD0)); + // @00145850 SLTIU v0, t7, $0001 + this.ee.v0.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < 1ul)); + // @00145854 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00145858 NOP + MobUt.Latency(); + } + + public virtual void funct00145854() + { + this.ee.pc = 1333340u; + // @00145854 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00145858 NOP + MobUt.Latency(); + } + + public virtual void funct001622f8() + { + this.ee.pc = 1450784u; + // @001622F8 ADDIU sp, sp, $ff90 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -112))); + // @001622FC LW v0, $0010(a0) + MobUt.LW(this.ee, this.ee.v0, (16u + this.ee.a0.UL0)); + // @00162300 SD s0, $0040(sp) + MobUt.SD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); + // @00162304 ADDIU t7, zero, $0003 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 3))); + // @00162308 SD s1, $0048(sp) + MobUt.SD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); + // @0016230C SD s2, $0050(sp) + MobUt.SD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); + // @00162310 SD s3, $0058(sp) + MobUt.SD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); + // @00162314 SD s4, $0060(sp) + MobUt.SD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); + // @00162318 BNE v0, t7, $0016246c + if ((this.ee.v0.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 1451116u; + } + // @0016231C LUI t7, $0036 + this.ee.t7.SD0 = 3538944; + } + + public virtual void funct00162328() + { + this.ee.pc = 1450800u; + // @00162328 BLEZ v0, $00162464 + if ((this.ee.v0.SD0 <= 0)) + { + this.ee.pc = 1451108u; + } + // @0016232C DADDU t1, zero, zero + this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00162330() + { + this.ee.pc = 1450904u; + // @00162330 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00162334 ADDIU t3, sp, $0030 + this.ee.t3.SD0 = ((int)((this.ee.sp.SD0 + 48))); + // @00162338 ADDIU t7, t7, $8ce0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -29472))); + // @0016233C ADDIU v1, sp, $0010 + this.ee.v1.SD0 = ((int)((this.ee.sp.SD0 + 16))); + // @00162340 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00162344 ADDIU a3, sp, $0020 + this.ee.a3.SD0 = ((int)((this.ee.sp.SD0 + 32))); + // @00162348 DADDU s3, sp, zero + this.ee.s3.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); + // @0016234C DADDU s2, t3, zero + this.ee.s2.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); + // @00162350 DADDU s1, t3, zero + this.ee.s1.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); + // @00162354 DADDU s0, v1, zero + this.ee.s0.UD0 = (this.ee.v1.UD0 + this.ee.r0.UD0); + // @00162358 DADDU t9, sp, zero + this.ee.t9.UD0 = (this.ee.sp.UD0 + this.ee.r0.UD0); + // @0016235C DADDU t8, t3, zero + this.ee.t8.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); + // @00162360 SLL t6, t1, 2 + MobUt.SLL(this.ee.t6, this.ee.t1, 2); + // @00162364 ADDU t5, t6, s4 + this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.s4.SD0))); + // @00162368 ADDU t2, t6, a0 + this.ee.t2.SD0 = ((int)((this.ee.t6.SD0 + this.ee.a0.SD0))); + // @0016236C LW t7, $0000(t5) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.t5.UL0)); + // @00162370 LW t4, $0000(t2) + MobUt.LW(this.ee, this.ee.t4, (0u + this.ee.t2.UL0)); + // @00162374 SLL t7, t7, 2 + MobUt.SLL(this.ee.t7, this.ee.t7, 2); + // @00162378 ADDU t7, t7, a0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.a0.SD0))); + // @0016237C LW t6, $0000(t7) + MobUt.LW(this.ee, this.ee.t6, (0u + this.ee.t7.UL0)); + // @00162380 LQC2 vf1, $0000(t6) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t6.UL0)); + // @00162384 LQC2 vf2, $0000(t4) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t4.UL0)); + // @00162388 VSUB.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); + // @0016238C SQC2 vf1, $0000(s2) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s2.UL0)); + // @00162390 BEQL sp, t3, $001623a4 + if ((this.ee.sp.UD0 == this.ee.t3.UD0)) + { + this.ee.pc = 1450916u; + // @00162394 LW t7, $0000(t2) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.t2.UL0)); + } + } + + public virtual void funct00162398() + { + this.ee.pc = 1450940u; + // @00162398 LQ t0, $0000(t3) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); + // @0016239C SQ t0, $0000(s3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.s3.UL[0])); + // @001623A0 LW t7, $0000(t2) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.t2.UL0)); + // @001623A4 LQC2 vf1, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); + // @001623A8 LQC2 vf2, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t7.UL0)); + // @001623AC VSUB.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x - this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y - this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z - this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w - this.ee.VF[2].w); + // @001623B0 SQC2 vf1, $0000(s1) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.s1.UL0)); + // @001623B4 BEQ v1, t3, $001623c4 + if ((this.ee.v1.UD0 == this.ee.t3.UD0)) + { + this.ee.pc = 1450948u; + } + // @001623B8 NOP + MobUt.Latency(); + } + + public virtual void funct001623bc() + { + this.ee.pc = 1450980u; + // @001623BC LQ t0, $0000(t3) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); + // @001623C0 SQ t0, $0000(v1) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.v1.UL[0])); + // @001623C4 LQC2 vf1, $0000(s0) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.s0.UL0)); + // @001623C8 LQC2 vf2, $0000(t9) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t9.UL0)); + // @001623CC VSUB.xyzw vf3, vf0, vf0 + this.ee.VF[3].x = (this.ee.VF[0].x - this.ee.VF[0].x); + this.ee.VF[3].y = (this.ee.VF[0].y - this.ee.VF[0].y); + this.ee.VF[3].z = (this.ee.VF[0].z - this.ee.VF[0].z); + this.ee.VF[3].w = (this.ee.VF[0].w - this.ee.VF[0].w); + // @001623D0 VOPMULA.xyz ACC, vf1, vf2 + this.ee.Vacc.x = (this.ee.VF[1].y * this.ee.VF[2].z); + this.ee.Vacc.y = (this.ee.VF[1].z * this.ee.VF[2].x); + this.ee.Vacc.z = (this.ee.VF[1].x * this.ee.VF[2].y); + // @001623D4 VOPMSUB.xyz vf3, vf2, vf1 + this.ee.VF[3].x = MobUt.OPMSUB(this.ee.Vacc.x, this.ee.VF[2].y, this.ee.VF[1].z); + this.ee.VF[3].y = MobUt.OPMSUB(this.ee.Vacc.y, this.ee.VF[2].z, this.ee.VF[1].x); + this.ee.VF[3].z = MobUt.OPMSUB(this.ee.Vacc.z, this.ee.VF[2].x, this.ee.VF[1].y); + // @001623D8 SQC2 vf3, $0000(t8) + MobUt.SQC2(this.ee, this.ee.VF[3], (0u + this.ee.t8.UL0)); + // @001623DC BEQ a3, t3, $001623ec + if ((this.ee.a3.UD0 == this.ee.t3.UD0)) + { + this.ee.pc = 1450988u; + } + // @001623E0 NOP + MobUt.Latency(); + } + + public virtual void funct001623e4() + { + this.ee.pc = 1451032u; + // @001623E4 LQ t0, $0000(t3) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.t3.UL[0])); + // @001623E8 SQ t0, $0000(a3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a3.UL[0])); + // @001623EC LQC2 vf1, $0000(a3) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a3.UL0)); + // @001623F0 LQC2 vf2, $0000(a2) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a2.UL0)); + // @001623F4 VMUL.xyz vf1, vf1, vf2 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); + // @001623F8 VADDy.x vf1, vf1, vf1y + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); + // @001623FC VADDz.x vf1, vf1, vf1z + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); + // @00162400 QMFC2 t0, vf1 + MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); + // @00162404 MTC1 t0, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @00162408 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @0016240C ADDIU t1, t1, $0001 + this.ee.t1.SD0 = ((int)((this.ee.t1.SD0 + 1))); + // @00162410 BC1F $00162448 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 1451080u; + } + // @00162414 SLT t7, t1, v0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t1.SD0 < this.ee.v0.SD0)); + } + + public virtual void funct00162418() + { + this.ee.pc = 1451044u; + // @00162418 DADDU t7, a3, zero + this.ee.t7.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); + // @0016241C BEQ sp, t7, $0016242c + if ((this.ee.sp.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1451052u; + } + // @00162420 DADDU v0, zero, zero + this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct0016241c() + { + this.ee.pc = 1451044u; + // @0016241C BEQ sp, t7, $0016242c + if ((this.ee.sp.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 1451052u; + } + // @00162420 DADDU v0, zero, zero + this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00162424() + { + this.ee.pc = 1451052u; + // @00162424 BEQ zero, zero, $0016241c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1451036u; + } + // @00162428 ADDIU t7, t7, $fff0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -16))); + } + + public virtual void funct0016242c() + { + this.ee.pc = 1451080u; + // @0016242C LD s0, $0040(sp) + MobUt.LD(this.ee, this.ee.s0, (64u + this.ee.sp.UL0)); + // @00162430 LD s1, $0048(sp) + MobUt.LD(this.ee, this.ee.s1, (72u + this.ee.sp.UL0)); + // @00162434 LD s2, $0050(sp) + MobUt.LD(this.ee, this.ee.s2, (80u + this.ee.sp.UL0)); + // @00162438 LD s3, $0058(sp) + MobUt.LD(this.ee, this.ee.s3, (88u + this.ee.sp.UL0)); + // @0016243C LD s4, $0060(sp) + MobUt.LD(this.ee, this.ee.s4, (96u + this.ee.sp.UL0)); + // @00162440 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00162444 ADDIU sp, sp, $0070 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 112))); + } + + public virtual void funct0016246c() + { + this.ee.pc = 1451124u; + // @0016246C BEQ zero, zero, $00162328 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1450792u; + } + // @00162470 ADDIU s4, t7, $a090 + this.ee.s4.SD0 = ((int)((this.ee.t7.SD0 + -24432))); + } + + public virtual void funct00162670() + { + this.ee.pc = 1451696u; + // @00162670 ADDIU sp, sp, $ffe0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); + // @00162674 DADDU t4, a1, zero + this.ee.t4.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + // @00162678 SD ra, $0010(sp) + MobUt.SD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + // @0016267C DADDU a1, a3, zero + this.ee.a1.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); + // @00162680 ADDIU t5, a0, $0010 + this.ee.t5.SD0 = ((int)((this.ee.a0.SD0 + 16))); + // @00162684 LQC2 vf1, $0000(a2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a2.UL0)); + // @00162688 LQC2 vf2, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t5.UL0)); + // @0016268C VMUL.xyz vf1, vf1, vf2 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); + // @00162690 VADDy.x vf1, vf1, vf1y + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); + // @00162694 VADDz.x vf1, vf1, vf1z + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); + // @00162698 QMFC2 t0, vf1 + MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); + // @0016269C MTC1 t0, $f2 + this.ee.fpr[2].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @001626A0 MTC1 zero, $f3 + this.ee.fpr[3].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @001626A4 C.LE.S $f3, $f2 + this.ee.fcr31_23 = (this.ee.fpr[3].f <= this.ee.fpr[2].f); + // @001626A8 BC1T $00162774 + if (this.ee.fcr31_23) + { + this.ee.pc = 1451892u; + } + // @001626AC DADDU v0, zero, zero + this.ee.v0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct001626b0() + { + this.ee.pc = 1451796u; + // @001626B0 LW t7, $0000(t4) + MobUt.LW(this.ee, this.ee.t7, (0u + this.ee.t4.UL0)); + // @001626B4 LQC2 vf1, $0000(a2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a2.UL0)); + // @001626B8 LQC2 vf2, $0000(t7) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.t7.UL0)); + // @001626BC VMUL.xyz vf1, vf1, vf2 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); + // @001626C0 VADDy.x vf1, vf1, vf1y + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); + // @001626C4 VADDz.x vf1, vf1, vf1z + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); + // @001626C8 QMFC2 t0, vf1 + MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); + // @001626CC MTC1 t0, $f1 + this.ee.fpr[1].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @001626D0 LQC2 vf1, $0000(a2) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a2.UL0)); + // @001626D4 LQC2 vf2, $0000(a0) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a0.UL0)); + // @001626D8 VMUL.xyz vf1, vf1, vf2 + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].y); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].z); + // @001626DC VADDy.x vf1, vf1, vf1y + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].y); + // @001626E0 VADDz.x vf1, vf1, vf1z + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[1].z); + // @001626E4 QMFC2 t0, vf1 + MobUt.QMFC2(this.ee.t0, this.ee.VF[1]); + // @001626E8 MTC1 t0, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t0.UL[0]); + // @001626EC SUB.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); + // @001626F0 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @001626F4 ADDIU t7, t7, $8ce8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + -29464))); + // @001626F8 NOP + MobUt.Latency(); + // @001626FC NOP + MobUt.Latency(); + // @00162700 DIV.S $f1, $f1, $f2 + this.ee.fpr[1].f = (this.ee.fpr[1].f / this.ee.fpr[2].f); + // @00162704 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00162708 C.LT.S $f0, $f1 + this.ee.fcr31_23 = (this.ee.fpr[0].f < this.ee.fpr[1].f); + // @0016270C BC1TL $00162778 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1451896u; + // @00162710 LD ra, $0010(sp) + MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + } + } + + public virtual void funct00162714() + { + this.ee.pc = 1451808u; + // @00162714 C.LT.S $f1, $f3 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[3].f); + // @00162718 BC1TL $00162778 + if ((this.ee.fcr31_23 == true)) + { + this.ee.pc = 1451896u; + // @0016271C LD ra, $0010(sp) + MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + } + } + + public virtual void funct00162720() + { + this.ee.pc = 1451836u; + // @00162720 LQC2 vf1, $0000(t5) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.t5.UL0)); + // @00162724 MFC1 t0, $f1 + MobUt.MFC1(this.ee.t0, this.ee.fpr[1]); + // @00162728 QMTC2 t0, vf2 + MobUt.QMTC2(this.ee.t0, this.ee.VF[2]); + // @0016272C VMULx.xyzw vf1, vf1, vf2x + this.ee.VF[1].x = MobUt.MUL(this.ee.VF[1].x, this.ee.VF[2].x); + this.ee.VF[1].y = MobUt.MUL(this.ee.VF[1].y, this.ee.VF[2].x); + this.ee.VF[1].z = MobUt.MUL(this.ee.VF[1].z, this.ee.VF[2].x); + this.ee.VF[1].w = MobUt.MUL(this.ee.VF[1].w, this.ee.VF[2].x); + // @00162730 SQC2 vf1, $0000(sp) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @00162734 BEQ a3, sp, $00162744 + if ((this.ee.a3.UD0 == this.ee.sp.UD0)) + { + this.ee.pc = 1451844u; + } + // @00162738 NOP + MobUt.Latency(); + } + + public virtual void funct0016273c() + { + this.ee.pc = 1451868u; + // @0016273C LQ t0, $0000(sp) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); + // @00162740 SQ t0, $0000(a3) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a3.UL[0])); + // @00162744 LQC2 vf1, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[1], (0u + this.ee.a1.UL0)); + // @00162748 LQC2 vf2, $0000(a0) + MobUt.LQC2(this.ee, this.ee.VF[2], (0u + this.ee.a0.UL0)); + // @0016274C VADD.xyzw vf1, vf1, vf2 + this.ee.VF[1].x = (this.ee.VF[1].x + this.ee.VF[2].x); + this.ee.VF[1].y = (this.ee.VF[1].y + this.ee.VF[2].y); + this.ee.VF[1].z = (this.ee.VF[1].z + this.ee.VF[2].z); + this.ee.VF[1].w = (this.ee.VF[1].w + this.ee.VF[2].w); + // @00162750 SQC2 vf1, $0000(sp) + MobUt.SQC2(this.ee, this.ee.VF[1], (0u + this.ee.sp.UL0)); + // @00162754 BEQL a1, sp, $00162768 + if ((this.ee.a1.UD0 == this.ee.sp.UD0)) + { + this.ee.pc = 1451880u; + // @00162758 SWC1 $f0, $000c(a1) + MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.a1.UL0)); + } + } + + public virtual void funct0016275c() + { + this.ee.pc = 1451888u; + // @0016275C LQ t0, $0000(sp) + MobUt.LQ(this.ee, this.ee.t0, (0u + this.ee.sp.UL[0])); + // @00162760 SQ t0, $0000(a1) + MobUt.SQ(this.ee, this.ee.t0, (0u + this.ee.a1.UL[0])); + // @00162764 SWC1 $f0, $000c(a1) + MobUt.SWC1(this.ee, this.ee.fpr[0], (12u + this.ee.a1.UL0)); + // @00162768 JAL $001622f8 + this.ee.ra.UL0 = 1451888u; + this.ee.pc = 1450744u; + // @0016276C DADDU a0, t4, zero + this.ee.a0.UD0 = (this.ee.t4.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00162770() + { + this.ee.pc = 1451904u; + // @00162770 SLTU v0, zero, v0 + this.ee.v0.UD0 = System.Convert.ToByte((this.ee.r0.UD0 < this.ee.v0.UD0)); + // @00162774 LD ra, $0010(sp) + MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + // @00162778 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0016277C ADDIU sp, sp, $0020 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); + } + + public virtual void funct00162778() + { + this.ee.pc = 1451904u; + // @00162778 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0016277C ADDIU sp, sp, $0020 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); + } + + public virtual void funct00165aa8() + { + this.ee.pc = 1465116u; + // @00165AA8 ADDIU sp, sp, $ff90 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -112))); + // @00165AAC SW zero, $0000(t2) + MobUt.SW(this.ee, this.ee.r0, (0u + this.ee.t2.UL0)); + // @00165AB0 ADDIU t7, zero, $ffff + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -1))); + // @00165AB4 SD s0, $0020(sp) + MobUt.SD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); + // @00165AB8 SH t7, $0010(sp) + MobUt.SH(this.ee, this.ee.t7, (16u + this.ee.sp.UL0)); + // @00165ABC ADDIU t6, sp, $0070 + this.ee.t6.SD0 = ((int)((this.ee.sp.SD0 + 112))); + // @00165AC0 SD s2, $0030(sp) + MobUt.SD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); + // @00165AC4 DADDU s0, zero, zero + this.ee.s0.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00165AC8 SD s3, $0038(sp) + MobUt.SD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); + // @00165ACC SD s4, $0040(sp) + MobUt.SD(this.ee, this.ee.s4, (64u + this.ee.sp.UL0)); + // @00165AD0 ANDI s2, t1, $00ff + this.ee.s2.UD0 = ((ushort)((this.ee.t1.US0 & 255))); + // @00165AD4 SD s5, $0048(sp) + MobUt.SD(this.ee, this.ee.s5, (72u + this.ee.sp.UL0)); + // @00165AD8 DADDU s3, t0, zero + this.ee.s3.UD0 = (this.ee.t0.UD0 + this.ee.r0.UD0); + // @00165ADC SD s6, $0050(sp) + MobUt.SD(this.ee, this.ee.s6, (80u + this.ee.sp.UL0)); + // @00165AE0 DADDU s4, a3, zero + this.ee.s4.UD0 = (this.ee.a3.UD0 + this.ee.r0.UD0); + // @00165AE4 SD s7, $0058(sp) + MobUt.SD(this.ee, this.ee.s7, (88u + this.ee.sp.UL0)); + // @00165AE8 DADDU s5, a1, zero + this.ee.s5.UD0 = (this.ee.a1.UD0 + this.ee.r0.UD0); + // @00165AEC SD s8, $0060(sp) + MobUt.SD(this.ee, this.ee.s8, (96u + this.ee.sp.UL0)); + // @00165AF0 DADDU s6, a2, zero + this.ee.s6.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); + // @00165AF4 SH t7, $0000(a2) + MobUt.SH(this.ee, this.ee.t7, (0u + this.ee.a2.UL0)); + // @00165AF8 DADDU s7, t2, zero + this.ee.s7.UD0 = (this.ee.t2.UD0 + this.ee.r0.UD0); + // @00165AFC SD s1, $0028(sp) + MobUt.SD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); + // @00165B00 DADDU s8, t3, zero + this.ee.s8.UD0 = (this.ee.t3.UD0 + this.ee.r0.UD0); + // @00165B04 SD ra, $0068(sp) + MobUt.SD(this.ee, this.ee.ra, (104u + this.ee.sp.UL0)); + // @00165B08 SW a0, $0014(sp) + MobUt.SW(this.ee, this.ee.a0, (20u + this.ee.sp.UL0)); + // @00165B0C LW s1, $0000(t6) + MobUt.LW(this.ee, this.ee.s1, (0u + this.ee.t6.UL0)); + // @00165B10 SW zero, $0018(sp) + MobUt.SW(this.ee, this.ee.r0, (24u + this.ee.sp.UL0)); + // @00165B14 JAL $00165be0 + this.ee.ra.UL0 = 1465116u; + this.ee.pc = 1465312u; + // @00165B18 DADDU a0, s0, zero + this.ee.a0.UD0 = (this.ee.s0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00165b1c() + { + this.ee.pc = 1465124u; + // @00165B1C BNE v0, zero, $00165b58 + if ((this.ee.v0.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 1465176u; + } + // @00165B20 DADDU s0, v0, zero + this.ee.s0.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00165b24() + { + this.ee.pc = 1465176u; + // @00165B24 LW v0, $0018(sp) + MobUt.LW(this.ee, this.ee.v0, (24u + this.ee.sp.UL0)); + // @00165B28 LD s0, $0020(sp) + MobUt.LD(this.ee, this.ee.s0, (32u + this.ee.sp.UL0)); + // @00165B2C LD s1, $0028(sp) + MobUt.LD(this.ee, this.ee.s1, (40u + this.ee.sp.UL0)); + // @00165B30 LD s2, $0030(sp) + MobUt.LD(this.ee, this.ee.s2, (48u + this.ee.sp.UL0)); + // @00165B34 LD s3, $0038(sp) + MobUt.LD(this.ee, this.ee.s3, (56u + this.ee.sp.UL0)); + // @00165B38 LD s4, $0040(sp) + MobUt.LD(this.ee, this.ee.s4, (64u + this.ee.sp.UL0)); + // @00165B3C LD s5, $0048(sp) + MobUt.LD(this.ee, this.ee.s5, (72u + this.ee.sp.UL0)); + // @00165B40 LD s6, $0050(sp) + MobUt.LD(this.ee, this.ee.s6, (80u + this.ee.sp.UL0)); + // @00165B44 LD s7, $0058(sp) + MobUt.LD(this.ee, this.ee.s7, (88u + this.ee.sp.UL0)); + // @00165B48 LD s8, $0060(sp) + MobUt.LD(this.ee, this.ee.s8, (96u + this.ee.sp.UL0)); + // @00165B4C LD ra, $0068(sp) + MobUt.LD(this.ee, this.ee.ra, (104u + this.ee.sp.UL0)); + // @00165B50 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00165B54 ADDIU sp, sp, $0070 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 112))); + } + + public virtual void funct00165be0() + { + this.ee.pc = 1465328u; + // @00165BE0 LUI t7, $0052 + this.ee.t7.SD0 = 5373952; + // @00165BE4 LW t6, $e8c0(t7) + MobUt.LW(this.ee, this.ee.t6, (4294961344u + this.ee.t7.UL0)); + // @00165BE8 BEQ a0, zero, $00165bf4 + if ((this.ee.a0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1465332u; + } + // @00165BEC DADDU v0, t6, zero + this.ee.v0.UD0 = (this.ee.t6.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00165bf4() + { + this.ee.pc = 1465340u; + // @00165BF4 BEQ v0, zero, $00165c0c + if ((this.ee.v0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 1465356u; + } + // @00165BF8 DADDU a0, v0, zero + this.ee.a0.UD0 = (this.ee.v0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00165c0c() + { + this.ee.pc = 1465364u; + // @00165C0C JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00165C10 NOP + MobUt.Latency(); + } + + public virtual void funct002fa938() + { + this.ee.pc = 3123608u; + // @002FA938 LUI t0, $0037 + this.ee.t0.SD0 = 3604480; + // @002FA93C ADDIU t0, t0, $12e0 + this.ee.t0.SD0 = ((int)((this.ee.t0.SD0 + 4832))); + // @002FA940 LQC2 vf5, $0000(t0) + MobUt.LQC2(this.ee, this.ee.VF[5], (0u + this.ee.t0.UL0)); + // @002FA944 VMR32.w vf6, vf6 + this.ee.VF[6].w = this.ee.VF[6].x; + // @002FA948 VADDx.x vf4, vf0, vf6x + this.ee.VF[4].x = (this.ee.VF[0].x + this.ee.VF[6].x); + // @002FA94C VMUL.x vf6, vf6, vf6 + this.ee.VF[6].x = MobUt.MUL(this.ee.VF[6].x, this.ee.VF[6].x); + // @002FA950 VMULx.yzw vf4, vf4, vf0x + this.ee.VF[4].y = MobUt.MUL(this.ee.VF[4].y, this.ee.VF[0].x); + this.ee.VF[4].z = MobUt.MUL(this.ee.VF[4].z, this.ee.VF[0].x); + this.ee.VF[4].w = MobUt.MUL(this.ee.VF[4].w, this.ee.VF[0].x); + // @002FA954 VMULw.xyzw vf8, vf5, vf6w + this.ee.VF[8].x = MobUt.MUL(this.ee.VF[5].x, this.ee.VF[6].w); + this.ee.VF[8].y = MobUt.MUL(this.ee.VF[5].y, this.ee.VF[6].w); + this.ee.VF[8].z = MobUt.MUL(this.ee.VF[5].z, this.ee.VF[6].w); + this.ee.VF[8].w = MobUt.MUL(this.ee.VF[5].w, this.ee.VF[6].w); + // @002FA958 VSUB.xyzw vf5, vf0, vf0 + this.ee.VF[5].x = (this.ee.VF[0].x - this.ee.VF[0].x); + this.ee.VF[5].y = (this.ee.VF[0].y - this.ee.VF[0].y); + this.ee.VF[5].z = (this.ee.VF[0].z - this.ee.VF[0].z); + this.ee.VF[5].w = (this.ee.VF[0].w - this.ee.VF[0].w); + // @002FA95C VMULx.xyzw vf8, vf8, vf6x + this.ee.VF[8].x = MobUt.MUL(this.ee.VF[8].x, this.ee.VF[6].x); + this.ee.VF[8].y = MobUt.MUL(this.ee.VF[8].y, this.ee.VF[6].x); + this.ee.VF[8].z = MobUt.MUL(this.ee.VF[8].z, this.ee.VF[6].x); + this.ee.VF[8].w = MobUt.MUL(this.ee.VF[8].w, this.ee.VF[6].x); + // @002FA960 VMULx.xyz vf8, vf8, vf6x + this.ee.VF[8].x = MobUt.MUL(this.ee.VF[8].x, this.ee.VF[6].x); + this.ee.VF[8].y = MobUt.MUL(this.ee.VF[8].y, this.ee.VF[6].x); + this.ee.VF[8].z = MobUt.MUL(this.ee.VF[8].z, this.ee.VF[6].x); + // @002FA964 VADDw.x vf4, vf4, vf8w + this.ee.VF[4].x = (this.ee.VF[4].x + this.ee.VF[8].w); + // @002FA968 VMULx.xy vf8, vf8, vf6x + this.ee.VF[8].x = MobUt.MUL(this.ee.VF[8].x, this.ee.VF[6].x); + this.ee.VF[8].y = MobUt.MUL(this.ee.VF[8].y, this.ee.VF[6].x); + // @002FA96C VADDz.x vf4, vf4, vf8z + this.ee.VF[4].x = (this.ee.VF[4].x + this.ee.VF[8].z); + // @002FA970 VMULx.x vf8, vf8, vf6x + this.ee.VF[8].x = MobUt.MUL(this.ee.VF[8].x, this.ee.VF[6].x); + // @002FA974 VADDy.x vf4, vf4, vf8y + this.ee.VF[4].x = (this.ee.VF[4].x + this.ee.VF[8].y); + // @002FA978 VADDx.x vf4, vf4, vf8x + this.ee.VF[4].x = (this.ee.VF[4].x + this.ee.VF[8].x); + // @002FA97C VADDx.xy vf4, vf5, vf4x + this.ee.VF[4].x = (this.ee.VF[5].x + this.ee.VF[4].x); + this.ee.VF[4].y = (this.ee.VF[5].y + this.ee.VF[4].x); + // @002FA980 VMUL.x vf7, vf4, vf4 + this.ee.VF[7].x = MobUt.MUL(this.ee.VF[4].x, this.ee.VF[4].x); + // @002FA984 VSUBx.w vf7, vf0, vf7x + this.ee.VF[7].w = (this.ee.VF[0].w - this.ee.VF[7].x); + // @002FA988 VSQRT Q, vf7w + this.ee.Vq.f = ((float)(System.Math.Sqrt(System.Math.Abs(this.ee.VF[7].w)))); + // @002FA98C VWAITQ + MobUt.Latency(); + // @002FA990 BNE a3, zero, $002fa9a0 + if ((this.ee.a3.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3123616u; + } + // @002FA994 VADDq.x vf7, vf0, Q + this.ee.VF[7].x = (this.ee.VF[0].x + this.ee.Vq.f); + } + + public virtual void funct002fa998() + { + this.ee.pc = 3123616u; + // @002FA998 BEQ zero, zero, $002fa9a4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3123620u; + } + // @002FA99C VADDx.x vf4, vf5, vf7x + this.ee.VF[4].x = (this.ee.VF[5].x + this.ee.VF[7].x); + } + + public virtual void funct002fa9a0() + { + this.ee.pc = 3123628u; + // @002FA9A0 VSUBx.x vf4, vf5, vf7x + this.ee.VF[4].x = (this.ee.VF[5].x - this.ee.VF[7].x); + // @002FA9A4 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @002FA9A8 NOP + MobUt.Latency(); + } + + public virtual void funct002fa9a4() + { + this.ee.pc = 3123628u; + // @002FA9A4 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @002FA9A8 NOP + MobUt.Latency(); + } + + public virtual void funct002fa9b0() + { + this.ee.pc = 3123660u; + // @002FA9B0 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @002FA9B4 C.LT.S $f12, $f0 + this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[0].f); + // @002FA9B8 LUI at, $3fc9 + this.ee.at.SD0 = 1070137344; + // @002FA9BC ORI at, at, $0fdb + this.ee.at.UD0 = (this.ee.at.UD0 | 4059); + // @002FA9C0 MTC1 at, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.at.UL[0]); + // @002FA9C4 BC1F $002fa9d8 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 3123672u; + } + // @002FA9C8 NOP + MobUt.Latency(); + } + + public virtual void funct002fa9cc() + { + this.ee.pc = 3123672u; + // @002FA9CC ADD.S $f12, $f0, $f12 + this.ee.fpr[12].f = (this.ee.fpr[0].f + this.ee.fpr[12].f); + // @002FA9D0 J $002fa9e0 + this.ee.pc = 3123680u; + // @002FA9D4 ADDIU a3, zero, $0001 + this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 1))); + } + + public virtual void funct002fa9d8() + { + this.ee.pc = 3123700u; + // @002FA9D8 SUB.S $f12, $f0, $f12 + this.ee.fpr[12].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); + // @002FA9DC DADDU a3, zero, zero + this.ee.a3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @002FA9E0 MFC1 t0, $f12 + MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); + // @002FA9E4 QMTC2 t0, vf6 + MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); + // @002FA9E8 DADDU a2, ra, zero + this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); + // @002FA9EC JAL $002fa938 + this.ee.ra.UL0 = 3123700u; + this.ee.pc = 3123512u; + // @002FA9F0 NOP + MobUt.Latency(); + } + + public virtual void funct002fa9e0() + { + this.ee.pc = 3123700u; + // @002FA9E0 MFC1 t0, $f12 + MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); + // @002FA9E4 QMTC2 t0, vf6 + MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); + // @002FA9E8 DADDU a2, ra, zero + this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); + // @002FA9EC JAL $002fa938 + this.ee.ra.UL0 = 3123700u; + this.ee.pc = 3123512u; + // @002FA9F0 NOP + MobUt.Latency(); + } + + public virtual void funct002fa9f4() + { + this.ee.pc = 3123788u; + // @002FA9F4 DADDU ra, a2, zero + this.ee.ra.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); + // @002FA9F8 VMOVE.xyzw vf6, vf5 + this.ee.VF[6].x = this.ee.VF[5].x; + this.ee.VF[6].y = this.ee.VF[5].y; + this.ee.VF[6].z = this.ee.VF[5].z; + this.ee.VF[6].w = this.ee.VF[5].w; + // @002FA9FC VMOVE.xyzw vf7, vf5 + this.ee.VF[7].x = this.ee.VF[5].x; + this.ee.VF[7].y = this.ee.VF[5].y; + this.ee.VF[7].z = this.ee.VF[5].z; + this.ee.VF[7].w = this.ee.VF[5].w; + // @002FAA00 VMOVE.xyzw vf9, vf0 + this.ee.VF[9].x = this.ee.VF[0].x; + this.ee.VF[9].y = this.ee.VF[0].y; + this.ee.VF[9].z = this.ee.VF[0].z; + this.ee.VF[9].w = this.ee.VF[0].w; + // @002FAA04 VSUB.xyz vf9, vf9, vf9 + this.ee.VF[9].x = (this.ee.VF[9].x - this.ee.VF[9].x); + this.ee.VF[9].y = (this.ee.VF[9].y - this.ee.VF[9].y); + this.ee.VF[9].z = (this.ee.VF[9].z - this.ee.VF[9].z); + // @002FAA08 VMR32.xyzw vf8, vf9 + this.ee.VF[8].x = this.ee.VF[9].y; + this.ee.VF[8].y = this.ee.VF[9].z; + this.ee.VF[8].z = this.ee.VF[9].w; + this.ee.VF[8].w = this.ee.VF[9].x; + // @002FAA0C VSUB.zw vf4, vf4, vf4 + this.ee.VF[4].z = (this.ee.VF[4].z - this.ee.VF[4].z); + this.ee.VF[4].w = (this.ee.VF[4].w - this.ee.VF[4].w); + // @002FAA10 VADDx.y vf6, vf5, vf4x + this.ee.VF[6].y = (this.ee.VF[5].y + this.ee.VF[4].x); + // @002FAA14 VADDy.x vf6, vf5, vf4y + this.ee.VF[6].x = (this.ee.VF[5].x + this.ee.VF[4].y); + // @002FAA18 VSUBx.x vf7, vf5, vf4x + this.ee.VF[7].x = (this.ee.VF[5].x - this.ee.VF[4].x); + // @002FAA1C VADDy.y vf7, vf5, vf4y + this.ee.VF[7].y = (this.ee.VF[5].y + this.ee.VF[4].y); + // @002FAA20 ADDIU a3, zero, $0004 + this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 4))); + // @002FAA24 LQC2 vf4, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); + // @002FAA28 VMULAx.xyzw ACC, vf6, vf4x + // @002FAA2C VMADDAy.xyzw ACC, vf7, vf4y + // @002FAA30 VMADDAz.xyzw ACC, vf8, vf4z + // @002FAA34 VMADDw.xyzw vf5, vf9, vf4w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); + // @002FAA38 SQC2 vf5, $0000(a0) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); + // @002FAA3C ADDI a3, a3, $ffff + this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); + // @002FAA40 ADDI a1, a1, $0010 + this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); + // @002FAA44 BNE zero, a3, $002faa24 + if ((this.ee.r0.UD0 != this.ee.a3.UD0)) + { + this.ee.pc = 3123748u; + } + // @002FAA48 ADDI a0, a0, $0010 + this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); + } + + public virtual void funct002faa24() + { + this.ee.pc = 3123788u; + // @002FAA24 LQC2 vf4, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); + // @002FAA28 VMULAx.xyzw ACC, vf6, vf4x + // @002FAA2C VMADDAy.xyzw ACC, vf7, vf4y + // @002FAA30 VMADDAz.xyzw ACC, vf8, vf4z + // @002FAA34 VMADDw.xyzw vf5, vf9, vf4w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); + // @002FAA38 SQC2 vf5, $0000(a0) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); + // @002FAA3C ADDI a3, a3, $ffff + this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); + // @002FAA40 ADDI a1, a1, $0010 + this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); + // @002FAA44 BNE zero, a3, $002faa24 + if ((this.ee.r0.UD0 != this.ee.a3.UD0)) + { + this.ee.pc = 3123748u; + } + // @002FAA48 ADDI a0, a0, $0010 + this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); + } + + public virtual void funct002faa4c() + { + this.ee.pc = 3123796u; + // @002FAA4C JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @002FAA50 NOP + MobUt.Latency(); + } + + public virtual void funct002faa58() + { + this.ee.pc = 3123828u; + // @002FAA58 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @002FAA5C C.LT.S $f12, $f0 + this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[0].f); + // @002FAA60 LUI at, $3fc9 + this.ee.at.SD0 = 1070137344; + // @002FAA64 ORI at, at, $0fdb + this.ee.at.UD0 = (this.ee.at.UD0 | 4059); + // @002FAA68 MTC1 at, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.at.UL[0]); + // @002FAA6C BC1F $002faa80 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 3123840u; + } + // @002FAA70 NOP + MobUt.Latency(); + } + + public virtual void funct002faa74() + { + this.ee.pc = 3123840u; + // @002FAA74 ADD.S $f12, $f0, $f12 + this.ee.fpr[12].f = (this.ee.fpr[0].f + this.ee.fpr[12].f); + // @002FAA78 J $002faa88 + this.ee.pc = 3123848u; + // @002FAA7C ADDIU a3, zero, $0001 + this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 1))); + } + + public virtual void funct002faa80() + { + this.ee.pc = 3123868u; + // @002FAA80 SUB.S $f12, $f0, $f12 + this.ee.fpr[12].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); + // @002FAA84 DADDU a3, zero, zero + this.ee.a3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @002FAA88 MFC1 t0, $f12 + MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); + // @002FAA8C QMTC2 t0, vf6 + MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); + // @002FAA90 DADDU a2, ra, zero + this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); + // @002FAA94 JAL $002fa938 + this.ee.ra.UL0 = 3123868u; + this.ee.pc = 3123512u; + // @002FAA98 NOP + MobUt.Latency(); + } + + public virtual void funct002faa88() + { + this.ee.pc = 3123868u; + // @002FAA88 MFC1 t0, $f12 + MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); + // @002FAA8C QMTC2 t0, vf6 + MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); + // @002FAA90 DADDU a2, ra, zero + this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); + // @002FAA94 JAL $002fa938 + this.ee.ra.UL0 = 3123868u; + this.ee.pc = 3123512u; + // @002FAA98 NOP + MobUt.Latency(); + } + + public virtual void funct002faa9c() + { + this.ee.pc = 3123960u; + // @002FAA9C DADDU ra, a2, zero + this.ee.ra.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); + // @002FAAA0 VMOVE.xyzw vf6, vf5 + this.ee.VF[6].x = this.ee.VF[5].x; + this.ee.VF[6].y = this.ee.VF[5].y; + this.ee.VF[6].z = this.ee.VF[5].z; + this.ee.VF[6].w = this.ee.VF[5].w; + // @002FAAA4 VMOVE.xyzw vf7, vf5 + this.ee.VF[7].x = this.ee.VF[5].x; + this.ee.VF[7].y = this.ee.VF[5].y; + this.ee.VF[7].z = this.ee.VF[5].z; + this.ee.VF[7].w = this.ee.VF[5].w; + // @002FAAA8 VMOVE.xyzw vf8, vf5 + this.ee.VF[8].x = this.ee.VF[5].x; + this.ee.VF[8].y = this.ee.VF[5].y; + this.ee.VF[8].z = this.ee.VF[5].z; + this.ee.VF[8].w = this.ee.VF[5].w; + // @002FAAAC VMOVE.xyzw vf9, vf5 + this.ee.VF[9].x = this.ee.VF[5].x; + this.ee.VF[9].y = this.ee.VF[5].y; + this.ee.VF[9].z = this.ee.VF[5].z; + this.ee.VF[9].w = this.ee.VF[5].w; + // @002FAAB0 VADDw.x vf6, vf5, vf0w + this.ee.VF[6].x = (this.ee.VF[5].x + this.ee.VF[0].w); + // @002FAAB4 VADDw.w vf9, vf5, vf0w + this.ee.VF[9].w = (this.ee.VF[5].w + this.ee.VF[0].w); + // @002FAAB8 VSUB.zw vf4, vf4, vf4 + this.ee.VF[4].z = (this.ee.VF[4].z - this.ee.VF[4].z); + this.ee.VF[4].w = (this.ee.VF[4].w - this.ee.VF[4].w); + // @002FAABC VADDx.z vf7, vf5, vf4x + this.ee.VF[7].z = (this.ee.VF[5].z + this.ee.VF[4].x); + // @002FAAC0 VADDy.y vf7, vf5, vf4y + this.ee.VF[7].y = (this.ee.VF[5].y + this.ee.VF[4].y); + // @002FAAC4 VSUBx.y vf8, vf5, vf4x + this.ee.VF[8].y = (this.ee.VF[5].y - this.ee.VF[4].x); + // @002FAAC8 VADDy.z vf8, vf5, vf4y + this.ee.VF[8].z = (this.ee.VF[5].z + this.ee.VF[4].y); + // @002FAACC ADDIU a3, zero, $0004 + this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 4))); + // @002FAAD0 LQC2 vf4, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); + // @002FAAD4 VMULAx.xyzw ACC, vf6, vf4x + // @002FAAD8 VMADDAy.xyzw ACC, vf7, vf4y + // @002FAADC VMADDAz.xyzw ACC, vf8, vf4z + // @002FAAE0 VMADDw.xyzw vf5, vf9, vf4w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); + // @002FAAE4 SQC2 vf5, $0000(a0) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); + // @002FAAE8 ADDI a3, a3, $ffff + this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); + // @002FAAEC ADDI a1, a1, $0010 + this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); + // @002FAAF0 BNE zero, a3, $002faad0 + if ((this.ee.r0.UD0 != this.ee.a3.UD0)) + { + this.ee.pc = 3123920u; + } + // @002FAAF4 ADDI a0, a0, $0010 + this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); + } + + public virtual void funct002faad0() + { + this.ee.pc = 3123960u; + // @002FAAD0 LQC2 vf4, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); + // @002FAAD4 VMULAx.xyzw ACC, vf6, vf4x + // @002FAAD8 VMADDAy.xyzw ACC, vf7, vf4y + // @002FAADC VMADDAz.xyzw ACC, vf8, vf4z + // @002FAAE0 VMADDw.xyzw vf5, vf9, vf4w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); + // @002FAAE4 SQC2 vf5, $0000(a0) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); + // @002FAAE8 ADDI a3, a3, $ffff + this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); + // @002FAAEC ADDI a1, a1, $0010 + this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); + // @002FAAF0 BNE zero, a3, $002faad0 + if ((this.ee.r0.UD0 != this.ee.a3.UD0)) + { + this.ee.pc = 3123920u; + } + // @002FAAF4 ADDI a0, a0, $0010 + this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); + } + + public virtual void funct002faaf8() + { + this.ee.pc = 3123968u; + // @002FAAF8 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @002FAAFC NOP + MobUt.Latency(); + } + + public virtual void funct002fab00() + { + this.ee.pc = 3123996u; + // @002FAB00 MTC1 zero, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.r0.UL[0]); + // @002FAB04 C.LT.S $f12, $f0 + this.ee.fcr31_23 = (this.ee.fpr[12].f < this.ee.fpr[0].f); + // @002FAB08 LUI at, $3fc9 + this.ee.at.SD0 = 1070137344; + // @002FAB0C ORI at, at, $0fdb + this.ee.at.UD0 = (this.ee.at.UD0 | 4059); + // @002FAB10 MTC1 at, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.at.UL[0]); + // @002FAB14 BC1F $002fab28 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 3124008u; + } + // @002FAB18 NOP + MobUt.Latency(); + } + + public virtual void funct002fab1c() + { + this.ee.pc = 3124008u; + // @002FAB1C ADD.S $f12, $f0, $f12 + this.ee.fpr[12].f = (this.ee.fpr[0].f + this.ee.fpr[12].f); + // @002FAB20 J $002fab30 + this.ee.pc = 3124016u; + // @002FAB24 ADDIU a3, zero, $0001 + this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 1))); + } + + public virtual void funct002fab28() + { + this.ee.pc = 3124036u; + // @002FAB28 SUB.S $f12, $f0, $f12 + this.ee.fpr[12].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); + // @002FAB2C DADDU a3, zero, zero + this.ee.a3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @002FAB30 MFC1 t0, $f12 + MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); + // @002FAB34 QMTC2 t0, vf6 + MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); + // @002FAB38 DADDU a2, ra, zero + this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); + // @002FAB3C JAL $002fa938 + this.ee.ra.UL0 = 3124036u; + this.ee.pc = 3123512u; + // @002FAB40 NOP + MobUt.Latency(); + } + + public virtual void funct002fab30() + { + this.ee.pc = 3124036u; + // @002FAB30 MFC1 t0, $f12 + MobUt.MFC1(this.ee.t0, this.ee.fpr[12]); + // @002FAB34 QMTC2 t0, vf6 + MobUt.QMTC2(this.ee.t0, this.ee.VF[6]); + // @002FAB38 DADDU a2, ra, zero + this.ee.a2.UD0 = (this.ee.ra.UD0 + this.ee.r0.UD0); + // @002FAB3C JAL $002fa938 + this.ee.ra.UL0 = 3124036u; + this.ee.pc = 3123512u; + // @002FAB40 NOP + MobUt.Latency(); + } + + public virtual void funct002fab44() + { + this.ee.pc = 3124128u; + // @002FAB44 DADDU ra, a2, zero + this.ee.ra.UD0 = (this.ee.a2.UD0 + this.ee.r0.UD0); + // @002FAB48 VMOVE.xyzw vf6, vf5 + this.ee.VF[6].x = this.ee.VF[5].x; + this.ee.VF[6].y = this.ee.VF[5].y; + this.ee.VF[6].z = this.ee.VF[5].z; + this.ee.VF[6].w = this.ee.VF[5].w; + // @002FAB4C VMOVE.xyzw vf7, vf5 + this.ee.VF[7].x = this.ee.VF[5].x; + this.ee.VF[7].y = this.ee.VF[5].y; + this.ee.VF[7].z = this.ee.VF[5].z; + this.ee.VF[7].w = this.ee.VF[5].w; + // @002FAB50 VMOVE.xyzw vf8, vf5 + this.ee.VF[8].x = this.ee.VF[5].x; + this.ee.VF[8].y = this.ee.VF[5].y; + this.ee.VF[8].z = this.ee.VF[5].z; + this.ee.VF[8].w = this.ee.VF[5].w; + // @002FAB54 VMOVE.xyzw vf9, vf5 + this.ee.VF[9].x = this.ee.VF[5].x; + this.ee.VF[9].y = this.ee.VF[5].y; + this.ee.VF[9].z = this.ee.VF[5].z; + this.ee.VF[9].w = this.ee.VF[5].w; + // @002FAB58 VADDw.y vf7, vf5, vf0w + this.ee.VF[7].y = (this.ee.VF[5].y + this.ee.VF[0].w); + // @002FAB5C VADDw.w vf9, vf5, vf0w + this.ee.VF[9].w = (this.ee.VF[5].w + this.ee.VF[0].w); + // @002FAB60 VSUB.zw vf4, vf4, vf4 + this.ee.VF[4].z = (this.ee.VF[4].z - this.ee.VF[4].z); + this.ee.VF[4].w = (this.ee.VF[4].w - this.ee.VF[4].w); + // @002FAB64 VSUBx.z vf6, vf5, vf4x + this.ee.VF[6].z = (this.ee.VF[5].z - this.ee.VF[4].x); + // @002FAB68 VADDy.x vf6, vf5, vf4y + this.ee.VF[6].x = (this.ee.VF[5].x + this.ee.VF[4].y); + // @002FAB6C VADDx.x vf8, vf5, vf4x + this.ee.VF[8].x = (this.ee.VF[5].x + this.ee.VF[4].x); + // @002FAB70 VADDy.z vf8, vf5, vf4y + this.ee.VF[8].z = (this.ee.VF[5].z + this.ee.VF[4].y); + // @002FAB74 ADDIU a3, zero, $0004 + this.ee.a3.SD0 = ((int)((this.ee.r0.SD0 + 4))); + // @002FAB78 LQC2 vf4, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); + // @002FAB7C VMULAx.xyzw ACC, vf6, vf4x + // @002FAB80 VMADDAy.xyzw ACC, vf7, vf4y + // @002FAB84 VMADDAz.xyzw ACC, vf8, vf4z + // @002FAB88 VMADDw.xyzw vf5, vf9, vf4w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); + // @002FAB8C SQC2 vf5, $0000(a0) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); + // @002FAB90 ADDI a3, a3, $ffff + this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); + // @002FAB94 ADDI a1, a1, $0010 + this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); + // @002FAB98 BNE zero, a3, $002fab78 + if ((this.ee.r0.UD0 != this.ee.a3.UD0)) + { + this.ee.pc = 3124088u; + } + // @002FAB9C ADDI a0, a0, $0010 + this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); + } + + public virtual void funct002fab78() + { + this.ee.pc = 3124128u; + // @002FAB78 LQC2 vf4, $0000(a1) + MobUt.LQC2(this.ee, this.ee.VF[4], (0u + this.ee.a1.UL0)); + // @002FAB7C VMULAx.xyzw ACC, vf6, vf4x + // @002FAB80 VMADDAy.xyzw ACC, vf7, vf4y + // @002FAB84 VMADDAz.xyzw ACC, vf8, vf4z + // @002FAB88 VMADDw.xyzw vf5, vf9, vf4w + MobUt.VMx16(this.ee.Vacc, this.ee.VF[6], this.ee.VF[4].x, this.ee.VF[7], this.ee.VF[4].y, this.ee.VF[8], this.ee.VF[4].z, this.ee.VF[9], this.ee.VF[4].w, this.ee.VF[5]); + // @002FAB8C SQC2 vf5, $0000(a0) + MobUt.SQC2(this.ee, this.ee.VF[5], (0u + this.ee.a0.UL0)); + // @002FAB90 ADDI a3, a3, $ffff + this.ee.a3.SD0 = ((int)((this.ee.a3.SD0 + -1))); + // @002FAB94 ADDI a1, a1, $0010 + this.ee.a1.SD0 = ((int)((this.ee.a1.SD0 + 16))); + // @002FAB98 BNE zero, a3, $002fab78 + if ((this.ee.r0.UD0 != this.ee.a3.UD0)) + { + this.ee.pc = 3124088u; + } + // @002FAB9C ADDI a0, a0, $0010 + this.ee.a0.SD0 = ((int)((this.ee.a0.SD0 + 16))); + } + + public virtual void funct002faba0() + { + this.ee.pc = 3124136u; + // @002FABA0 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @002FABA4 NOP + MobUt.Latency(); + } + + public virtual void funct002ff210() + { + this.ee.pc = 3142212u; + // @002FF210 ADDIU sp, sp, $ffe0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -32))); + // @002FF214 SD s1, $0008(sp) + MobUt.SD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); + // @002FF218 LUI t6, $7fff + this.ee.t6.SD0 = 2147418112; + // @002FF21C SD s0, $0000(sp) + MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @002FF220 ORI t6, t6, $ffff + this.ee.t6.UD0 = (this.ee.t6.UD0 | 65535); + // @002FF224 MFC1 s1, $f12 + MobUt.MFC1(this.ee.s1, this.ee.fpr[12]); + // @002FF228 LUI t7, $507f + this.ee.t7.SD0 = 1350500352; + // @002FF22C ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @002FF230 SD ra, $0010(sp) + MobUt.SD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + // @002FF234 AND s0, s1, t6 + this.ee.s0.UD0 = (this.ee.s1.UD0 & this.ee.t6.UD0); + // @002FF238 SLT t7, t7, s0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); + // @002FF23C BEQ t7, zero, $002ff278 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3142264u; + } + // @002FF240 MOV.S $f6, $f12 + this.ee.fpr[6].f = this.ee.fpr[12].f; + } + + public virtual void funct002ff260() + { + this.ee.pc = 3142264u; + // @002FF260 MOV.S $f0, $f4 + this.ee.fpr[0].f = this.ee.fpr[4].f; + // @002FF264 LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @002FF268 LD s1, $0008(sp) + MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); + // @002FF26C LD ra, $0010(sp) + MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + // @002FF270 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @002FF274 ADDIU sp, sp, $0020 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 32))); + } + + public virtual void funct002ff278() + { + this.ee.pc = 3142284u; + // @002FF278 LUI t7, $3edf + this.ee.t7.SD0 = 1054801920; + // @002FF27C ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @002FF280 SLT t7, t7, s0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); + // @002FF284 BNE t7, zero, $002ff400 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3142656u; + } + // @002FF288 LUI t7, $30ff + this.ee.t7.SD0 = 822018048; + } + + public virtual void funct002ff28c() + { + this.ee.pc = 3142300u; + // @002FF28C ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @002FF290 SLT t7, t7, s0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); + // @002FF294 BNE t7, zero, $002ff2c8 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3142344u; + } + // @002FF298 ADDIU t6, zero, $ffff + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + -1))); + } + + public virtual void funct002ff29c() + { + this.ee.pc = 3142340u; + // @002FF29C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF2A0 ADDIU t7, t7, $4794 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18324))); + // @002FF2A4 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @002FF2A8 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF2AC ADD.S $f0, $f12, $f0 + this.ee.fpr[0].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); + // @002FF2B0 ADDIU t7, t7, $4798 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18328))); + // @002FF2B4 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @002FF2B8 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @002FF2BC BC1T $002ff260 + if (this.ee.fcr31_23) + { + this.ee.pc = 3142240u; + } + // @002FF2C0 MOV.S $f4, $f12 + this.ee.fpr[4].f = this.ee.fpr[12].f; + } + + public virtual void funct002ff2c8() + { + this.ee.pc = 3142568u; + // @002FF2C8 MUL.S $f5, $f6, $f6 + this.ee.fpr[5].f = (this.ee.fpr[6].f * this.ee.fpr[6].f); + // @002FF2CC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF2D0 ADDIU t7, t7, $47a8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18344))); + // @002FF2D4 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @002FF2D8 MUL.S $f4, $f5, $f5 + this.ee.fpr[4].f = (this.ee.fpr[5].f * this.ee.fpr[5].f); + // @002FF2DC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF2E0 ADDIU t7, t7, $47ac + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18348))); + // @002FF2E4 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @002FF2E8 MUL.S $f0, $f4, $f0 + this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); + // @002FF2EC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF2F0 ADDIU t7, t7, $47b0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18352))); + // @002FF2F4 MUL.S $f1, $f4, $f1 + this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); + // @002FF2F8 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF2FC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF300 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @002FF304 ADDIU t7, t7, $47b4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18356))); + // @002FF308 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @002FF30C MUL.S $f0, $f4, $f0 + this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); + // @002FF310 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF314 ADDIU t7, t7, $47b8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18360))); + // @002FF318 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @002FF31C LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF320 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF324 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @002FF328 ADDIU t7, t7, $47bc + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18364))); + // @002FF32C MUL.S $f1, $f4, $f1 + this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); + // @002FF330 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @002FF334 MUL.S $f0, $f4, $f0 + this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); + // @002FF338 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF33C ADDIU t7, t7, $47c0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18368))); + // @002FF340 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @002FF344 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF348 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF34C ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @002FF350 ADDIU t7, t7, $47c4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18372))); + // @002FF354 MUL.S $f1, $f4, $f1 + this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); + // @002FF358 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @002FF35C MUL.S $f0, $f4, $f0 + this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); + // @002FF360 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF364 ADDIU t7, t7, $47c8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18376))); + // @002FF368 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @002FF36C LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF370 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF374 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @002FF378 ADDIU t7, t7, $47cc + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18380))); + // @002FF37C MUL.S $f1, $f4, $f1 + this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); + // @002FF380 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @002FF384 MUL.S $f0, $f4, $f0 + this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); + // @002FF388 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF38C ADDIU t7, t7, $47d0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18384))); + // @002FF390 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @002FF394 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF398 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @002FF39C MUL.S $f4, $f4, $f1 + this.ee.fpr[4].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); + // @002FF3A0 BGEZ t6, $002ff3b8 + if ((this.ee.t6.SD0 >= 0)) + { + this.ee.pc = 3142584u; + } + // @002FF3A4 MUL.S $f0, $f5, $f0 + this.ee.fpr[0].f = (this.ee.fpr[5].f * this.ee.fpr[0].f); + } + + public virtual void funct002ff2cc() + { + this.ee.pc = 3142568u; + // @002FF2CC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF2D0 ADDIU t7, t7, $47a8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18344))); + // @002FF2D4 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @002FF2D8 MUL.S $f4, $f5, $f5 + this.ee.fpr[4].f = (this.ee.fpr[5].f * this.ee.fpr[5].f); + // @002FF2DC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF2E0 ADDIU t7, t7, $47ac + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18348))); + // @002FF2E4 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @002FF2E8 MUL.S $f0, $f4, $f0 + this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); + // @002FF2EC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF2F0 ADDIU t7, t7, $47b0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18352))); + // @002FF2F4 MUL.S $f1, $f4, $f1 + this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); + // @002FF2F8 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF2FC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF300 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @002FF304 ADDIU t7, t7, $47b4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18356))); + // @002FF308 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @002FF30C MUL.S $f0, $f4, $f0 + this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); + // @002FF310 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF314 ADDIU t7, t7, $47b8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18360))); + // @002FF318 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @002FF31C LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF320 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF324 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @002FF328 ADDIU t7, t7, $47bc + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18364))); + // @002FF32C MUL.S $f1, $f4, $f1 + this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); + // @002FF330 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @002FF334 MUL.S $f0, $f4, $f0 + this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); + // @002FF338 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF33C ADDIU t7, t7, $47c0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18368))); + // @002FF340 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @002FF344 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF348 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF34C ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @002FF350 ADDIU t7, t7, $47c4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18372))); + // @002FF354 MUL.S $f1, $f4, $f1 + this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); + // @002FF358 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @002FF35C MUL.S $f0, $f4, $f0 + this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); + // @002FF360 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF364 ADDIU t7, t7, $47c8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18376))); + // @002FF368 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @002FF36C LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF370 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF374 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @002FF378 ADDIU t7, t7, $47cc + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18380))); + // @002FF37C MUL.S $f1, $f4, $f1 + this.ee.fpr[1].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); + // @002FF380 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @002FF384 MUL.S $f0, $f4, $f0 + this.ee.fpr[0].f = (this.ee.fpr[4].f * this.ee.fpr[0].f); + // @002FF388 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF38C ADDIU t7, t7, $47d0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18384))); + // @002FF390 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @002FF394 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF398 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @002FF39C MUL.S $f4, $f4, $f1 + this.ee.fpr[4].f = (this.ee.fpr[4].f * this.ee.fpr[1].f); + // @002FF3A0 BGEZ t6, $002ff3b8 + if ((this.ee.t6.SD0 >= 0)) + { + this.ee.pc = 3142584u; + } + // @002FF3A4 MUL.S $f0, $f5, $f0 + this.ee.fpr[0].f = (this.ee.fpr[5].f * this.ee.fpr[0].f); + } + + public virtual void funct002ff3a8() + { + this.ee.pc = 3142584u; + // @002FF3A8 ADD.S $f0, $f0, $f4 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[4].f); + // @002FF3AC MUL.S $f0, $f6, $f0 + this.ee.fpr[0].f = (this.ee.fpr[6].f * this.ee.fpr[0].f); + // @002FF3B0 BEQ zero, zero, $002ff260 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3142240u; + } + // @002FF3B4 SUB.S $f4, $f6, $f0 + this.ee.fpr[4].f = (this.ee.fpr[6].f - this.ee.fpr[0].f); + } + + public virtual void funct002ff3b8() + { + this.ee.pc = 3142644u; + // @002FF3B8 ADD.S $f0, $f0, $f4 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[4].f); + // @002FF3BC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF3C0 SLL t6, t6, 2 + MobUt.SLL(this.ee.t6, this.ee.t6, 2); + // @002FF3C4 ADDIU t7, t7, $4748 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18248))); + // @002FF3C8 ADDU t7, t6, t7 + this.ee.t7.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @002FF3CC LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF3D0 MUL.S $f0, $f6, $f0 + this.ee.fpr[0].f = (this.ee.fpr[6].f * this.ee.fpr[0].f); + // @002FF3D4 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF3D8 ADDIU t7, t7, $4738 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18232))); + // @002FF3DC ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @002FF3E0 SUB.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); + // @002FF3E4 LWC1 $f1, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); + // @002FF3E8 SUB.S $f0, $f0, $f6 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[6].f); + // @002FF3EC BGEZ s1, $002ff3f8 + if ((this.ee.s1.SD0 >= 0)) + { + this.ee.pc = 3142648u; + } + // @002FF3F0 SUB.S $f0, $f1, $f0 + this.ee.fpr[0].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); + } + + public virtual void funct002ff3f8() + { + this.ee.pc = 3142656u; + // @002FF3F8 BEQ zero, zero, $002ff260 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3142240u; + } + // @002FF3FC MOV.S $f4, $f0 + this.ee.fpr[4].f = this.ee.fpr[0].f; + } + + public virtual void funct002ff400() + { + this.ee.pc = 3142664u; + // @002FF400 JAL $002ff660 + this.ee.ra.UL0 = 3142664u; + this.ee.pc = 3143264u; + // @002FF404 NOP + MobUt.Latency(); + } + + public virtual void funct002ff408() + { + this.ee.pc = 3142684u; + // @002FF408 LUI t7, $3f97 + this.ee.t7.SD0 = 1066860544; + // @002FF40C ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @002FF410 SLT t7, t7, s0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); + // @002FF414 BNE t7, zero, $002ff484 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3142788u; + } + // @002FF418 MOV.S $f6, $f0 + this.ee.fpr[6].f = this.ee.fpr[0].f; + } + + public virtual void funct002ff41c() + { + this.ee.pc = 3142704u; + // @002FF41C LUI t7, $3f2f + this.ee.t7.SD0 = 1060044800; + // @002FF420 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @002FF424 SLT t7, t7, s0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); + // @002FF428 BNE t7, zero, $002ff46c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3142764u; + } + // @002FF42C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct002ff430() + { + this.ee.pc = 3142764u; + // @002FF430 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF434 ADD.S $f0, $f0, $f0 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[0].f); + // @002FF438 ADDIU t7, t7, $479c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18332))); + // @002FF43C DADDU t6, zero, zero + this.ee.t6.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @002FF440 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @002FF444 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF448 ADD.S $f1, $f6, $f1 + this.ee.fpr[1].f = (this.ee.fpr[6].f + this.ee.fpr[1].f); + // @002FF44C ADDIU t7, t7, $4798 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18328))); + // @002FF450 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF454 SUB.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); + // @002FF458 NOP + MobUt.Latency(); + // @002FF45C NOP + MobUt.Latency(); + // @002FF460 DIV.S $f6, $f0, $f1 + this.ee.fpr[6].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); + // @002FF464 BEQ zero, zero, $002ff2cc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3142348u; + } + // @002FF468 MUL.S $f5, $f6, $f6 + this.ee.fpr[5].f = (this.ee.fpr[6].f * this.ee.fpr[6].f); + } + + public virtual void funct002ff458() + { + this.ee.pc = 3142764u; + // @002FF458 NOP + MobUt.Latency(); + // @002FF45C NOP + MobUt.Latency(); + // @002FF460 DIV.S $f6, $f0, $f1 + this.ee.fpr[6].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); + // @002FF464 BEQ zero, zero, $002ff2cc + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3142348u; + } + // @002FF468 MUL.S $f5, $f6, $f6 + this.ee.fpr[5].f = (this.ee.fpr[6].f * this.ee.fpr[6].f); + } + + public virtual void funct002ff46c() + { + this.ee.pc = 3142788u; + // @002FF46C ADDIU t6, zero, $0001 + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @002FF470 ADDIU t7, t7, $4798 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18328))); + // @002FF474 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @002FF478 ADD.S $f1, $f6, $f0 + this.ee.fpr[1].f = (this.ee.fpr[6].f + this.ee.fpr[0].f); + // @002FF47C BEQ zero, zero, $002ff458 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3142744u; + } + // @002FF480 SUB.S $f0, $f6, $f0 + this.ee.fpr[0].f = (this.ee.fpr[6].f - this.ee.fpr[0].f); + } + + public virtual void funct002ff484() + { + this.ee.pc = 3142808u; + // @002FF484 LUI t7, $401b + this.ee.t7.SD0 = 1075511296; + // @002FF488 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @002FF48C SLT t7, t7, s0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); + // @002FF490 BNE t7, zero, $002ff4c4 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3142852u; + } + // @002FF494 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct002ff498() + { + this.ee.pc = 3142852u; + // @002FF498 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF49C ADDIU t6, zero, $0002 + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 2))); + // @002FF4A0 ADDIU t7, t7, $47a0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18336))); + // @002FF4A4 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @002FF4A8 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @002FF4AC MUL.S $f1, $f6, $f0 + this.ee.fpr[1].f = (this.ee.fpr[6].f * this.ee.fpr[0].f); + // @002FF4B0 ADDIU t7, t7, $4798 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18328))); + // @002FF4B4 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @002FF4B8 SUB.S $f0, $f6, $f0 + this.ee.fpr[0].f = (this.ee.fpr[6].f - this.ee.fpr[0].f); + // @002FF4BC BEQ zero, zero, $002ff458 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3142744u; + } + // @002FF4C0 ADD.S $f1, $f1, $f2 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[2].f); + } + + public virtual void funct002ff4c4() + { + this.ee.pc = 3142880u; + // @002FF4C4 ADDIU t7, t7, $47a4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18340))); + // @002FF4C8 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @002FF4CC NOP + MobUt.Latency(); + // @002FF4D0 NOP + MobUt.Latency(); + // @002FF4D4 DIV.S $f6, $f0, $f6 + this.ee.fpr[6].f = (this.ee.fpr[0].f / this.ee.fpr[6].f); + // @002FF4D8 BEQ zero, zero, $002ff2c8 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3142344u; + } + // @002FF4DC ADDIU t6, zero, $0003 + this.ee.t6.SD0 = ((int)((this.ee.r0.SD0 + 3))); + } + + public virtual void funct002ff660() + { + this.ee.pc = 3143288u; + // @002FF660 MFC1 t6, $f12 + MobUt.MFC1(this.ee.t6, this.ee.fpr[12]); + // @002FF664 LUI t7, $7fff + this.ee.t7.SD0 = 2147418112; + // @002FF668 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @002FF66C AND t6, t6, t7 + this.ee.t6.UD0 = (this.ee.t6.UD0 & this.ee.t7.UD0); + // @002FF670 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @002FF674 MTC1 t6, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); + } + + public virtual void funct002ff8a8() + { + this.ee.pc = 3143868u; + // @002FF8A8 ADDIU sp, sp, $fff0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); + // @002FF8AC SD ra, $0000(sp) + MobUt.SD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); + // @002FF8B0 LD ra, $0000(sp) + MobUt.LD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); + // @002FF8B4 J $00300058 + this.ee.pc = 3145816u; + // @002FF8B8 ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct002ff8c0() + { + this.ee.pc = 3143892u; + // @002FF8C0 ADDIU sp, sp, $fff0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); + // @002FF8C4 SD ra, $0000(sp) + MobUt.SD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); + // @002FF8C8 LD ra, $0000(sp) + MobUt.LD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); + // @002FF8CC J $003003f0 + this.ee.pc = 3146736u; + // @002FF8D0 ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct002ff8d8() + { + this.ee.pc = 3143916u; + // @002FF8D8 ADDIU sp, sp, $fff0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); + // @002FF8DC SD ra, $0000(sp) + MobUt.SD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); + // @002FF8E0 LD ra, $0000(sp) + MobUt.LD(this.ee, this.ee.ra, (0u + this.ee.sp.UL0)); + // @002FF8E4 J $003005b8 + this.ee.pc = 3147192u; + // @002FF8E8 ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00300058() + { + this.ee.pc = 3145872u; + // @00300058 ADDIU sp, sp, $ffd0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -48))); + // @0030005C LUI t7, $7fff + this.ee.t7.SD0 = 2147418112; + // @00300060 SD s1, $0008(sp) + MobUt.SD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); + // @00300064 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @00300068 SD s0, $0000(sp) + MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @0030006C LUI t6, $3f80 + this.ee.t6.SD0 = 1065353216; + // @00300070 MFC1 s1, $f12 + MobUt.MFC1(this.ee.s1, this.ee.fpr[12]); + // @00300074 SD ra, $0010(sp) + MobUt.SD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + // @00300078 SWC1 $f22, $0020(sp) + MobUt.SWC1(this.ee, this.ee.fpr[22], (32u + this.ee.sp.UL0)); + // @0030007C AND s0, s1, t7 + this.ee.s0.UD0 = (this.ee.s1.UD0 & this.ee.t7.UD0); + // @00300080 SWC1 $f21, $001c(sp) + MobUt.SWC1(this.ee, this.ee.fpr[21], (28u + this.ee.sp.UL0)); + // @00300084 SWC1 $f20, $0018(sp) + MobUt.SWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); + // @00300088 BNE s0, t6, $003000d4 + if ((this.ee.s0.UD0 != this.ee.t6.UD0)) + { + this.ee.pc = 3145940u; + } + // @0030008C SLT t7, t6, s0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < this.ee.s0.SD0)); + } + + public virtual void funct00300090() + { + this.ee.pc = 3145940u; + // @00300090 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300094 ADDIU t7, t7, $48b8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18616))); + // @00300098 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @0030009C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003000A0 MULA.S $f12, $f0 + this.ee.fpracc.f = (this.ee.fpr[12].f * this.ee.fpr[0].f); + // @003000A4 ADDIU t7, t7, $48bc + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18620))); + // @003000A8 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @003000AC MADD.S $f4, $f12, $f1 + this.ee.fpr[4].f = MobUt.MADD(this.ee.fpracc.f, this.ee.fpr[12].f, this.ee.fpr[1].f); + // @003000B0 MOV.S $f0, $f4 + this.ee.fpr[0].f = this.ee.fpr[4].f; + // @003000B4 LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @003000B8 LD s1, $0008(sp) + MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); + // @003000BC LD ra, $0010(sp) + MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + // @003000C0 LWC1 $f22, $0020(sp) + MobUt.LWC1(this.ee, this.ee.fpr[22], (32u + this.ee.sp.UL0)); + // @003000C4 LWC1 $f21, $001c(sp) + MobUt.LWC1(this.ee, this.ee.fpr[21], (28u + this.ee.sp.UL0)); + // @003000C8 LWC1 $f20, $0018(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); + // @003000CC JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @003000D0 ADDIU sp, sp, $0030 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 48))); + } + + public virtual void funct003000b0() + { + this.ee.pc = 3145940u; + // @003000B0 MOV.S $f0, $f4 + this.ee.fpr[0].f = this.ee.fpr[4].f; + // @003000B4 LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @003000B8 LD s1, $0008(sp) + MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); + // @003000BC LD ra, $0010(sp) + MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + // @003000C0 LWC1 $f22, $0020(sp) + MobUt.LWC1(this.ee, this.ee.fpr[22], (32u + this.ee.sp.UL0)); + // @003000C4 LWC1 $f21, $001c(sp) + MobUt.LWC1(this.ee, this.ee.fpr[21], (28u + this.ee.sp.UL0)); + // @003000C8 LWC1 $f20, $0018(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); + // @003000CC JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @003000D0 ADDIU sp, sp, $0030 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 48))); + } + + public virtual void funct003000b4() + { + this.ee.pc = 3145940u; + // @003000B4 LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @003000B8 LD s1, $0008(sp) + MobUt.LD(this.ee, this.ee.s1, (8u + this.ee.sp.UL0)); + // @003000BC LD ra, $0010(sp) + MobUt.LD(this.ee, this.ee.ra, (16u + this.ee.sp.UL0)); + // @003000C0 LWC1 $f22, $0020(sp) + MobUt.LWC1(this.ee, this.ee.fpr[22], (32u + this.ee.sp.UL0)); + // @003000C4 LWC1 $f21, $001c(sp) + MobUt.LWC1(this.ee, this.ee.fpr[21], (28u + this.ee.sp.UL0)); + // @003000C8 LWC1 $f20, $0018(sp) + MobUt.LWC1(this.ee, this.ee.fpr[20], (24u + this.ee.sp.UL0)); + // @003000CC JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @003000D0 ADDIU sp, sp, $0030 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 48))); + } + + public virtual void funct003000d4() + { + this.ee.pc = 3145948u; + // @003000D4 BEQ t7, zero, $003000f4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3145972u; + } + // @003000D8 LUI t7, $3eff + this.ee.t7.SD0 = 1056899072; + } + + public virtual void funct003000dc() + { + this.ee.pc = 3145972u; + // @003000DC SUB.S $f0, $f12, $f12 + this.ee.fpr[0].f = (this.ee.fpr[12].f - this.ee.fpr[12].f); + // @003000E0 NOP + MobUt.Latency(); + // @003000E4 NOP + MobUt.Latency(); + // @003000E8 DIV.S $f4, $f0, $f0 + this.ee.fpr[4].f = (this.ee.fpr[0].f / this.ee.fpr[0].f); + // @003000EC BEQ zero, zero, $003000b4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3145908u; + } + // @003000F0 MOV.S $f0, $f4 + this.ee.fpr[0].f = this.ee.fpr[4].f; + } + + public virtual void funct003000f4() + { + this.ee.pc = 3145988u; + // @003000F4 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @003000F8 SLT t7, t7, s0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); + // @003000FC BNE t7, zero, $0030013c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3146044u; + } + // @00300100 LUI t7, $31ff + this.ee.t7.SD0 = 838795264; + } + + public virtual void funct00300104() + { + this.ee.pc = 3146004u; + // @00300104 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @00300108 SLT t7, t7, s0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); + // @0030010C BNE t7, zero, $00300308 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3146504u; + } + // @00300110 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct00300114() + { + this.ee.pc = 3146044u; + // @00300114 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300118 ADDIU t7, t7, $48c0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18624))); + // @0030011C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00300120 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300124 ADD.S $f0, $f12, $f0 + this.ee.fpr[0].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); + // @00300128 ADDIU t7, t7, $48c4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18628))); + // @0030012C LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00300130 C.LT.S $f1, $f0 + this.ee.fcr31_23 = (this.ee.fpr[1].f < this.ee.fpr[0].f); + // @00300134 BC1T $003000b0 + if (this.ee.fcr31_23) + { + this.ee.pc = 3145904u; + } + // @00300138 MOV.S $f4, $f12 + this.ee.fpr[4].f = this.ee.fpr[12].f; + } + + public virtual void funct0030013c() + { + this.ee.pc = 3146052u; + // @0030013C JAL $002ff660 + this.ee.ra.UL0 = 3146052u; + this.ee.pc = 3143264u; + // @00300140 NOP + MobUt.Latency(); + } + + public virtual void funct00300144() + { + this.ee.pc = 3146288u; + // @00300144 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300148 ADDIU t7, t7, $48c4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18628))); + // @0030014C LWC1 $f4, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[4], (0u + this.ee.t7.UL0)); + // @00300150 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300154 SUB.S $f0, $f4, $f0 + this.ee.fpr[0].f = (this.ee.fpr[4].f - this.ee.fpr[0].f); + // @00300158 ADDIU t7, t7, $48f0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18672))); + // @0030015C LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00300160 MUL.S $f20, $f0, $f1 + this.ee.fpr[20].f = (this.ee.fpr[0].f * this.ee.fpr[1].f); + // @00300164 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300168 ADDIU t7, t7, $48c8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18632))); + // @0030016C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00300170 MOV.S $f12, $f20 + this.ee.fpr[12].f = this.ee.fpr[20].f; + // @00300174 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300178 MUL.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + // @0030017C ADDIU t7, t7, $48cc + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18636))); + // @00300180 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00300184 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300188 MUL.S $f1, $f20, $f1 + this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); + // @0030018C ADDIU t7, t7, $48d0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18640))); + // @00300190 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @00300194 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300198 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @0030019C ADDIU t7, t7, $48d4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18644))); + // @003001A0 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @003001A4 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003001A8 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @003001AC ADDIU t7, t7, $48d8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18648))); + // @003001B0 MUL.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + // @003001B4 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @003001B8 MUL.S $f1, $f20, $f1 + this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); + // @003001BC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003001C0 ADDIU t7, t7, $48dc + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18652))); + // @003001C4 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @003001C8 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @003001CC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003001D0 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @003001D4 ADDIU t7, t7, $48e0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18656))); + // @003001D8 MUL.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + // @003001DC LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @003001E0 MUL.S $f1, $f20, $f1 + this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); + // @003001E4 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003001E8 ADDIU t7, t7, $48e4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18660))); + // @003001EC ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @003001F0 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @003001F4 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @003001F8 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003001FC MUL.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + // @00300200 ADDIU t7, t7, $48e8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18664))); + // @00300204 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @00300208 MUL.S $f1, $f20, $f1 + this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); + // @0030020C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300210 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @00300214 ADDIU t7, t7, $48ec + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18668))); + // @00300218 ADD.S $f22, $f1, $f4 + this.ee.fpr[22].f = (this.ee.fpr[1].f + this.ee.fpr[4].f); + // @0030021C MUL.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + // @00300220 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00300224 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @00300228 JAL $00301800 + this.ee.ra.UL0 = 3146288u; + this.ee.pc = 3151872u; + // @0030022C MUL.S $f21, $f20, $f0 + this.ee.fpr[21].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + } + + public virtual void funct00300230() + { + this.ee.pc = 3146308u; + // @00300230 LUI t7, $3f79 + this.ee.t7.SD0 = 1064894464; + // @00300234 ORI t7, t7, $9999 + this.ee.t7.UD0 = (this.ee.t7.UD0 | 39321); + // @00300238 SLT t7, t7, s0 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.s0.SD0)); + // @0030023C BEQ t7, zero, $00300290 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3146384u; + } + // @00300240 MFC1 t5, $f0 + MobUt.MFC1(this.ee.t5, this.ee.fpr[0]); + } + + public virtual void funct00300244() + { + this.ee.pc = 3146376u; + // @00300244 NOP + MobUt.Latency(); + // @00300248 NOP + MobUt.Latency(); + // @0030024C DIV.S $f21, $f21, $f22 + this.ee.fpr[21].f = (this.ee.fpr[21].f / this.ee.fpr[22].f); + // @00300250 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300254 MTC1 t5, $f1 + this.ee.fpr[1].f = MobUt.UL2F(this.ee.t5.UL[0]); + // @00300258 ADDIU t7, t7, $48bc + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18620))); + // @0030025C MUL.S $f0, $f0, $f21 + this.ee.fpr[0].f = (this.ee.fpr[0].f * this.ee.fpr[21].f); + // @00300260 ADD.S $f0, $f1, $f0 + this.ee.fpr[0].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); + // @00300264 ADD.S $f0, $f0, $f0 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[0].f); + // @00300268 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @0030026C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300270 SUB.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); + // @00300274 ADDIU t7, t7, $48b8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18616))); + // @00300278 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @0030027C SUB.S $f20, $f2, $f0 + this.ee.fpr[20].f = (this.ee.fpr[2].f - this.ee.fpr[0].f); + // @00300280 BGTZ s1, $003000b0 + if ((this.ee.s1.SD0 > 0)) + { + this.ee.pc = 3145904u; + } + // @00300284 MOV.S $f4, $f20 + this.ee.fpr[4].f = this.ee.fpr[20].f; + } + + public virtual void funct00300280() + { + this.ee.pc = 3146376u; + // @00300280 BGTZ s1, $003000b0 + if ((this.ee.s1.SD0 > 0)) + { + this.ee.pc = 3145904u; + } + // @00300284 MOV.S $f4, $f20 + this.ee.fpr[4].f = this.ee.fpr[20].f; + } + + public virtual void funct00300288() + { + this.ee.pc = 3146384u; + // @00300288 BEQ zero, zero, $003000b0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3145904u; + } + // @0030028C NEG.S $f4, $f20 + this.ee.fpr[4].f = (0 - this.ee.fpr[20].f); + } + + public virtual void funct00300290() + { + this.ee.pc = 3146504u; + // @00300290 ADDIU t7, zero, $f000 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + -4096))); + // @00300294 MTC1 t5, $f2 + this.ee.fpr[2].f = MobUt.UL2F(this.ee.t5.UL[0]); + // @00300298 AND t6, t5, t7 + this.ee.t6.UD0 = (this.ee.t5.UD0 & this.ee.t7.UD0); + // @0030029C NOP + MobUt.Latency(); + // @003002A0 NOP + MobUt.Latency(); + // @003002A4 DIV.S $f4, $f21, $f22 + this.ee.fpr[4].f = (this.ee.fpr[21].f / this.ee.fpr[22].f); + // @003002A8 MTC1 t6, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); + // @003002AC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003002B0 MTC1 t6, $f6 + this.ee.fpr[6].f = MobUt.UL2F(this.ee.t6.UL[0]); + // @003002B4 ADDIU t7, t7, $48f4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18676))); + // @003002B8 MUL.S $f1, $f0, $f0 + this.ee.fpr[1].f = (this.ee.fpr[0].f * this.ee.fpr[0].f); + // @003002BC ADD.S $f3, $f2, $f0 + this.ee.fpr[3].f = (this.ee.fpr[2].f + this.ee.fpr[0].f); + // @003002C0 LWC1 $f5, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[5], (0u + this.ee.t7.UL0)); + // @003002C4 SUB.S $f1, $f20, $f1 + this.ee.fpr[1].f = (this.ee.fpr[20].f - this.ee.fpr[1].f); + // @003002C8 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003002CC ADD.S $f0, $f6, $f6 + this.ee.fpr[0].f = (this.ee.fpr[6].f + this.ee.fpr[6].f); + // @003002D0 ADDIU t7, t7, $48bc + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18620))); + // @003002D4 ADD.S $f2, $f2, $f2 + this.ee.fpr[2].f = (this.ee.fpr[2].f + this.ee.fpr[2].f); + // @003002D8 NOP + MobUt.Latency(); + // @003002DC NOP + MobUt.Latency(); + // @003002E0 DIV.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f / this.ee.fpr[3].f); + // @003002E4 SUB.S $f22, $f5, $f0 + this.ee.fpr[22].f = (this.ee.fpr[5].f - this.ee.fpr[0].f); + // @003002E8 MUL.S $f2, $f2, $f4 + this.ee.fpr[2].f = (this.ee.fpr[2].f * this.ee.fpr[4].f); + // @003002EC LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @003002F0 ADD.S $f1, $f1, $f1 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[1].f); + // @003002F4 SUB.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); + // @003002F8 SUB.S $f21, $f2, $f0 + this.ee.fpr[21].f = (this.ee.fpr[2].f - this.ee.fpr[0].f); + // @003002FC SUB.S $f1, $f21, $f22 + this.ee.fpr[1].f = (this.ee.fpr[21].f - this.ee.fpr[22].f); + // @00300300 BEQ zero, zero, $00300280 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3146368u; + } + // @00300304 SUB.S $f20, $f5, $f1 + this.ee.fpr[20].f = (this.ee.fpr[5].f - this.ee.fpr[1].f); + } + + public virtual void funct00300308() + { + this.ee.pc = 3146736u; + // @00300308 MUL.S $f20, $f12, $f12 + this.ee.fpr[20].f = (this.ee.fpr[12].f * this.ee.fpr[12].f); + // @0030030C ADDIU t7, t7, $48c8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18632))); + // @00300310 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00300314 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300318 MUL.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + // @0030031C ADDIU t7, t7, $48cc + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18636))); + // @00300320 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00300324 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300328 MUL.S $f1, $f20, $f1 + this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); + // @0030032C ADDIU t7, t7, $48d0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18640))); + // @00300330 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @00300334 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300338 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @0030033C ADDIU t7, t7, $48d4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18644))); + // @00300340 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @00300344 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300348 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @0030034C ADDIU t7, t7, $48d8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18648))); + // @00300350 MUL.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + // @00300354 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @00300358 MUL.S $f1, $f20, $f1 + this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); + // @0030035C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300360 ADDIU t7, t7, $48dc + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18652))); + // @00300364 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @00300368 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @0030036C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300370 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @00300374 ADDIU t7, t7, $48e0 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18656))); + // @00300378 MUL.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + // @0030037C LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @00300380 MUL.S $f1, $f20, $f1 + this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); + // @00300384 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300388 ADDIU t7, t7, $48e4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18660))); + // @0030038C ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @00300390 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @00300394 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300398 ADD.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @0030039C ADDIU t7, t7, $48e8 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18664))); + // @003003A0 MUL.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + // @003003A4 LWC1 $f2, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[2], (0u + this.ee.t7.UL0)); + // @003003A8 MUL.S $f1, $f20, $f1 + this.ee.fpr[1].f = (this.ee.fpr[20].f * this.ee.fpr[1].f); + // @003003AC LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003003B0 ADDIU t7, t7, $48c4 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18628))); + // @003003B4 ADD.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[2].f); + // @003003B8 LWC1 $f3, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[3], (0u + this.ee.t7.UL0)); + // @003003BC ADD.S $f22, $f1, $f3 + this.ee.fpr[22].f = (this.ee.fpr[1].f + this.ee.fpr[3].f); + // @003003C0 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003003C4 MUL.S $f0, $f20, $f0 + this.ee.fpr[0].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + // @003003C8 ADDIU t7, t7, $48ec + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18668))); + // @003003CC LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @003003D0 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @003003D4 MUL.S $f21, $f20, $f0 + this.ee.fpr[21].f = (this.ee.fpr[20].f * this.ee.fpr[0].f); + // @003003D8 NOP + MobUt.Latency(); + // @003003DC NOP + MobUt.Latency(); + // @003003E0 DIV.S $f21, $f21, $f22 + this.ee.fpr[21].f = (this.ee.fpr[21].f / this.ee.fpr[22].f); + // @003003E4 MUL.S $f0, $f12, $f21 + this.ee.fpr[0].f = (this.ee.fpr[12].f * this.ee.fpr[21].f); + // @003003E8 BEQ zero, zero, $003000b0 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3145904u; + } + // @003003EC ADD.S $f4, $f12, $f0 + this.ee.fpr[4].f = (this.ee.fpr[12].f + this.ee.fpr[0].f); + } + + public virtual void funct003003f0() + { + this.ee.pc = 3146784u; + // @003003F0 MOV.S $f0, $f12 + this.ee.fpr[0].f = this.ee.fpr[12].f; + // @003003F4 ADDIU sp, sp, $fff0 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + -16))); + // @003003F8 LUI t6, $7fff + this.ee.t6.SD0 = 2147418112; + // @003003FC MFC1 t4, $f13 + MobUt.MFC1(this.ee.t4, this.ee.fpr[13]); + // @00300400 MFC1 t3, $f12 + MobUt.MFC1(this.ee.t3, this.ee.fpr[12]); + // @00300404 ORI t6, t6, $ffff + this.ee.t6.UD0 = (this.ee.t6.UD0 | 65535); + // @00300408 SD s0, $0000(sp) + MobUt.SD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @0030040C AND t1, t4, t6 + this.ee.t1.UD0 = (this.ee.t4.UD0 & this.ee.t6.UD0); + // @00300410 SD ra, $0008(sp) + MobUt.SD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); + // @00300414 LUI t7, $3f80 + this.ee.t7.SD0 = 1065353216; + // @00300418 BNE t4, t7, $00300430 + if ((this.ee.t4.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 3146800u; + } + // @0030041C AND t2, t3, t6 + this.ee.t2.UD0 = (this.ee.t3.UD0 & this.ee.t6.UD0); + } + + public virtual void funct00300420() + { + this.ee.pc = 3146800u; + // @00300420 LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @00300424 LD ra, $0008(sp) + MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); + // @00300428 J $002ff210 + this.ee.pc = 3142160u; + // @0030042C ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00300430() + { + this.ee.pc = 3146832u; + // @00300430 SRA t7, t4, 30 + MobUt.SRA(this.ee.t7, this.ee.t4, 30); + // @00300434 LUI t6, $007f + this.ee.t6.SD0 = 8323072; + // @00300438 ANDI t7, t7, $0002 + this.ee.t7.UD0 = ((ushort)((this.ee.t7.US0 & 2))); + // @0030043C SRL t5, t3, 31 + MobUt.SRL(this.ee.t5, this.ee.t3, 31); + // @00300440 ORI t6, t6, $ffff + this.ee.t6.UD0 = (this.ee.t6.UD0 | 65535); + // @00300444 SLT t6, t6, t2 + this.ee.t6.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < this.ee.t2.SD0)); + // @00300448 BNE t6, zero, $00300490 + if ((this.ee.t6.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3146896u; + } + // @0030044C OR s0, t5, t7 + this.ee.s0.UD0 = (this.ee.t5.UD0 | this.ee.t7.UD0); + } + + public virtual void funct00300450() + { + this.ee.pc = 3146848u; + // @00300450 LUI t6, $4049 + this.ee.t6.SD0 = 1078525952; + // @00300454 ADDIU t7, zero, $0002 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); + // @00300458 BEQ s0, t7, $0030047c + if ((this.ee.s0.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 3146876u; + } + // @0030045C ORI t6, t6, $0fda + this.ee.t6.UD0 = (this.ee.t6.UD0 | 4058); + } + + public virtual void funct00300460() + { + this.ee.pc = 3146860u; + // @00300460 SLTI t7, s0, $0003 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 3)); + // @00300464 BEQL t7, zero, $003005a4 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3147172u; + // @00300468 LUI t6, $c049 + this.ee.t6.SD0 = -1068957696; + } + } + + public virtual void funct0030046c() + { + this.ee.pc = 3146868u; + // @0030046C BLTZ s0, $00300494 + if ((this.ee.s0.SD0 < 0)) + { + this.ee.pc = 3146900u; + } + // @00300470 LUI t7, $007f + this.ee.t7.SD0 = 8323072; + } + + public virtual void funct00300474() + { + this.ee.pc = 3146896u; + // @00300474 NOP + MobUt.Latency(); + // @00300478 MFC1 t6, $f0 + MobUt.MFC1(this.ee.t6, this.ee.fpr[0]); + // @0030047C MTC1 t6, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); + // @00300480 LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @00300484 LD ra, $0008(sp) + MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); + // @00300488 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0030048C ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00300478() + { + this.ee.pc = 3146896u; + // @00300478 MFC1 t6, $f0 + MobUt.MFC1(this.ee.t6, this.ee.fpr[0]); + // @0030047C MTC1 t6, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); + // @00300480 LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @00300484 LD ra, $0008(sp) + MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); + // @00300488 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0030048C ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct0030047c() + { + this.ee.pc = 3146896u; + // @0030047C MTC1 t6, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); + // @00300480 LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @00300484 LD ra, $0008(sp) + MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); + // @00300488 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0030048C ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00300480() + { + this.ee.pc = 3146896u; + // @00300480 LD s0, $0000(sp) + MobUt.LD(this.ee, this.ee.s0, (0u + this.ee.sp.UL0)); + // @00300484 LD ra, $0008(sp) + MobUt.LD(this.ee, this.ee.ra, (8u + this.ee.sp.UL0)); + // @00300488 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0030048C ADDIU sp, sp, $0010 + this.ee.sp.SD0 = ((int)((this.ee.sp.SD0 + 16))); + } + + public virtual void funct00300490() + { + this.ee.pc = 3146916u; + // @00300490 LUI t7, $007f + this.ee.t7.SD0 = 8323072; + // @00300494 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @00300498 SLT t7, t7, t1 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t1.SD0)); + // @0030049C BNE t7, zero, $003004dc + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3146972u; + } + // @003004A0 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct003004a4() + { + this.ee.pc = 3146940u; + // @003004A4 LUI t7, $bfc9 + this.ee.t7.SD0 = -1077346304; + // @003004A8 ORI t7, t7, $0fda + this.ee.t7.UD0 = (this.ee.t7.UD0 | 4058); + // @003004AC CTC2 t7, $vi22 + // @003004B0 VNOP + MobUt.Latency(); + // @003004B4 BLTZ t3, $003004c8 + if ((this.ee.t3.SD0 < 0)) + { + this.ee.pc = 3146952u; + } + // @003004B8 LUI t7, $3fc9 + this.ee.t7.SD0 = 1070137344; + } + + public virtual void funct003004c8() + { + this.ee.pc = 3146972u; + // @003004C8 VWAITQ + MobUt.Latency(); + // @003004CC CFC2 t6, $vi22 + MobUt.CFC2(this.ee.t6, this.ee.VI[22]); + // @003004D0 VNOP + MobUt.Latency(); + // @003004D4 BEQ zero, zero, $00300480 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3146880u; + } + // @003004D8 MTC1 t6, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t6.UL[0]); + } + + public virtual void funct003004dc() + { + this.ee.pc = 3147000u; + // @003004DC SUBU t6, t2, t1 + this.ee.t6.SD0 = ((int)((this.ee.t2.UD0 - this.ee.t1.UD0))); + // @003004E0 ADDIU t7, t7, $4910 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18704))); + // @003004E4 SRA t6, t6, 23 + MobUt.SRA(this.ee.t6, this.ee.t6, 23); + // @003004E8 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @003004EC SLTI t7, t6, $003d + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < 61)); + // @003004F0 BEQ t7, zero, $0030052c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3147052u; + } + // @003004F4 ADDIU t7, zero, $0001 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); + } + + public virtual void funct003004f8() + { + this.ee.pc = 3147008u; + // @003004F8 BGEZ t4, $00300508 + if ((this.ee.t4.SD0 >= 0)) + { + this.ee.pc = 3147016u; + } + // @003004FC SLTI t7, t6, $ffc4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < -60)); + } + + public virtual void funct00300500() + { + this.ee.pc = 3147016u; + // @00300500 BNE t7, zero, $00300528 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3147048u; + } + // @00300504 MTC1 zero, $f1 + this.ee.fpr[1].f = MobUt.UL2F(this.ee.r0.UL[0]); + } + + public virtual void funct00300508() + { + this.ee.pc = 3147036u; + // @00300508 NOP + MobUt.Latency(); + // @0030050C NOP + MobUt.Latency(); + // @00300510 DIV.S $f12, $f0, $f13 + this.ee.fpr[12].f = (this.ee.fpr[0].f / this.ee.fpr[13].f); + // @00300514 JAL $002ff660 + this.ee.ra.UL0 = 3147036u; + this.ee.pc = 3143264u; + // @00300518 NOP + MobUt.Latency(); + } + + public virtual void funct0030051c() + { + this.ee.pc = 3147044u; + // @0030051C JAL $002ff210 + this.ee.ra.UL0 = 3147044u; + this.ee.pc = 3142160u; + // @00300520 MOV.S $f12, $f0 + this.ee.fpr[12].f = this.ee.fpr[0].f; + } + + public virtual void funct00300524() + { + this.ee.pc = 3147060u; + // @00300524 MOV.S $f1, $f0 + this.ee.fpr[1].f = this.ee.fpr[0].f; + // @00300528 ADDIU t7, zero, $0001 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 1))); + // @0030052C BEQ s0, t7, $00300594 + if ((this.ee.s0.UD0 == this.ee.t7.UD0)) + { + this.ee.pc = 3147156u; + } + // @00300530 SLTI t7, s0, $0002 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.s0.SD0 < 2)); + } + + public virtual void funct00300534() + { + this.ee.pc = 3147068u; + // @00300534 BEQ t7, zero, $00300568 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3147112u; + } + // @00300538 ADDIU t7, zero, $0002 + this.ee.t7.SD0 = ((int)((this.ee.r0.SD0 + 2))); + } + + public virtual void funct0030053c() + { + this.ee.pc = 3147076u; + // @0030053C BEQ s0, zero, $0030047c + if ((this.ee.s0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3146876u; + } + // @00300540 MFC1 t6, $f1 + MobUt.MFC1(this.ee.t6, this.ee.fpr[1]); + } + + public virtual void funct00300548() + { + this.ee.pc = 3147112u; + // @00300548 ADDIU t7, t7, $4914 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18708))); + // @0030054C LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00300550 SUB.S $f0, $f1, $f0 + this.ee.fpr[0].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); + // @00300554 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300558 ADDIU t7, t7, $4918 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18712))); + // @0030055C LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00300560 BEQ zero, zero, $00300478 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3146872u; + } + // @00300564 SUB.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); + } + + public virtual void funct00300568() + { + this.ee.pc = 3147120u; + // @00300568 BNE s0, t7, $00300548 + if ((this.ee.s0.UD0 != this.ee.t7.UD0)) + { + this.ee.pc = 3147080u; + } + // @0030056C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct00300570() + { + this.ee.pc = 3147156u; + // @00300570 ADDIU t7, t7, $4914 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18708))); + // @00300574 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00300578 SUB.S $f0, $f1, $f0 + this.ee.fpr[0].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); + // @0030057C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300580 ADDIU t7, t7, $4918 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18712))); + // @00300584 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00300588 SUB.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); + // @0030058C BEQ zero, zero, $0030047c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3146876u; + } + // @00300590 MFC1 t6, $f1 + MobUt.MFC1(this.ee.t6, this.ee.fpr[1]); + } + + public virtual void funct00300594() + { + this.ee.pc = 3147172u; + // @00300594 MFC1 t6, $f1 + MobUt.MFC1(this.ee.t6, this.ee.fpr[1]); + // @00300598 LUI t7, $8000 + this.ee.t7.SD0 = -2147483648; + // @0030059C BEQ zero, zero, $0030047c + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3146876u; + } + // @003005A0 XOR t6, t6, t7 + MobUt.XOR(this.ee.t6, this.ee.t6, this.ee.t7); + } + + public virtual void funct003005b8() + { + this.ee.pc = 3147228u; + // @003005B8 MFC1 t4, $f12 + MobUt.MFC1(this.ee.t4, this.ee.fpr[12]); + // @003005BC LUI t6, $7fff + this.ee.t6.SD0 = 2147418112; + // @003005C0 LUI t7, $42b2 + this.ee.t7.SD0 = 1118961664; + // @003005C4 ORI t6, t6, $ffff + this.ee.t6.UD0 = (this.ee.t6.UD0 | 65535); + // @003005C8 ORI t7, t7, $d4fc + this.ee.t7.UD0 = (this.ee.t7.UD0 | 54524); + // @003005CC AND t3, t4, t6 + this.ee.t3.UD0 = (this.ee.t4.UD0 & this.ee.t6.UD0); + // @003005D0 SLT t7, t7, t4 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.SD0 < this.ee.t4.SD0)); + // @003005D4 BEQ t7, zero, $003005ec + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3147244u; + } + // @003005D8 SRL t2, t4, 31 + MobUt.SRL(this.ee.t2, this.ee.t4, 31); + } + + public virtual void funct003005e4() + { + this.ee.pc = 3147244u; + // @003005E4 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @003005E8 MTC1 t5, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t5.UL[0]); + } + + public virtual void funct003005ec() + { + this.ee.pc = 3147252u; + // @003005EC BGEZ t4, $0030060c + if ((this.ee.t4.SD0 >= 0)) + { + this.ee.pc = 3147276u; + } + // @003005F0 LUI t7, $3eb1 + this.ee.t7.SD0 = 1051787264; + } + + public virtual void funct003005f4() + { + this.ee.pc = 3147272u; + // @003005F4 LUI t7, $42ae + this.ee.t7.SD0 = 1118699520; + // @003005F8 ORI t7, t7, $ac50 + this.ee.t7.UD0 = (this.ee.t7.UD0 | 44112); + // @003005FC SLTU t7, t7, t3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < this.ee.t3.UD0)); + // @00300600 BNE t7, zero, $003005e4 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3147236u; + } + // @00300604 DADDU t5, zero, zero + this.ee.t5.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + + public virtual void funct00300608() + { + this.ee.pc = 3147292u; + // @00300608 LUI t7, $3eb1 + this.ee.t7.SD0 = 1051787264; + // @0030060C ORI t7, t7, $7218 + this.ee.t7.UD0 = (this.ee.t7.UD0 | 29208); + // @00300610 SLTU t7, t7, t3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < this.ee.t3.UD0)); + // @00300614 BEQ t7, zero, $003007e0 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3147744u; + } + // @00300618 LUI t7, $3f85 + this.ee.t7.SD0 = 1065680896; + } + + public virtual void funct0030061c() + { + this.ee.pc = 3147308u; + // @0030061C ORI t7, t7, $1591 + this.ee.t7.UD0 = (this.ee.t7.UD0 | 5521); + // @00300620 SLTU t7, t7, t3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < this.ee.t3.UD0)); + // @00300624 BNE t7, zero, $00300784 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3147652u; + } + // @00300628 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + } + + public virtual void funct0030062c() + { + this.ee.pc = 3147472u; + // @0030062C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300630 SLL t5, t2, 2 + MobUt.SLL(this.ee.t5, this.ee.t2, 2); + // @00300634 ADDIU t7, t7, $4938 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18744))); + // @00300638 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @0030063C ADDU t7, t5, t7 + this.ee.t7.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t7.SD0))); + // @00300640 ADDIU t6, t6, $4940 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18752))); + // @00300644 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @00300648 ADDU t5, t5, t6 + this.ee.t5.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t6.SD0))); + // @0030064C LWC1 $f4, $0000(t5) + MobUt.LWC1(this.ee, this.ee.fpr[4], (0u + this.ee.t5.UL0)); + // @00300650 SUB.S $f3, $f12, $f0 + this.ee.fpr[3].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + // @00300654 SUBU t7, zero, t2 + this.ee.t7.SD0 = ((int)((this.ee.r0.UD0 - this.ee.t2.UD0))); + // @00300658 SUBU t7, t7, t2 + this.ee.t7.SD0 = ((int)((this.ee.t7.UD0 - this.ee.t2.UD0))); + // @0030065C ADDIU t1, t7, $0001 + this.ee.t1.SD0 = ((int)((this.ee.t7.SD0 + 1))); + // @00300660 SUB.S $f12, $f3, $f4 + this.ee.fpr[12].f = (this.ee.fpr[3].f - this.ee.fpr[4].f); + // @00300664 MUL.S $f2, $f12, $f12 + this.ee.fpr[2].f = (this.ee.fpr[12].f * this.ee.fpr[12].f); + // @00300668 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @0030066C ADDIU t6, t6, $4978 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18808))); + // @00300670 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300674 LWC1 $f0, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @00300678 ADDIU t7, t7, $497c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18812))); + // @0030067C LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00300680 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @00300684 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @00300688 ADDIU t6, t6, $4980 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18816))); + // @0030068C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300690 ADDIU t7, t7, $4984 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18820))); + // @00300694 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @00300698 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @0030069C LWC1 $f1, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); + // @003006A0 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @003006A4 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @003006A8 ADDIU t6, t6, $4988 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18824))); + // @003006AC MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @003006B0 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @003006B4 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @003006B8 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @003006BC LWC1 $f1, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); + // @003006C0 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @003006C4 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @003006C8 BNE t1, zero, $0030070c + if ((this.ee.t1.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3147532u; + } + // @003006CC SUB.S $f2, $f12, $f0 + this.ee.fpr[2].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + } + + public virtual void funct00300660() + { + this.ee.pc = 3147472u; + // @00300660 SUB.S $f12, $f3, $f4 + this.ee.fpr[12].f = (this.ee.fpr[3].f - this.ee.fpr[4].f); + // @00300664 MUL.S $f2, $f12, $f12 + this.ee.fpr[2].f = (this.ee.fpr[12].f * this.ee.fpr[12].f); + // @00300668 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @0030066C ADDIU t6, t6, $4978 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18808))); + // @00300670 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300674 LWC1 $f0, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @00300678 ADDIU t7, t7, $497c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18812))); + // @0030067C LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00300680 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @00300684 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @00300688 ADDIU t6, t6, $4980 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18816))); + // @0030068C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300690 ADDIU t7, t7, $4984 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18820))); + // @00300694 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @00300698 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @0030069C LWC1 $f1, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); + // @003006A0 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @003006A4 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @003006A8 ADDIU t6, t6, $4988 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18824))); + // @003006AC MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @003006B0 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @003006B4 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @003006B8 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @003006BC LWC1 $f1, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); + // @003006C0 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @003006C4 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @003006C8 BNE t1, zero, $0030070c + if ((this.ee.t1.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3147532u; + } + // @003006CC SUB.S $f2, $f12, $f0 + this.ee.fpr[2].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + } + + public virtual void funct00300664() + { + this.ee.pc = 3147472u; + // @00300664 MUL.S $f2, $f12, $f12 + this.ee.fpr[2].f = (this.ee.fpr[12].f * this.ee.fpr[12].f); + // @00300668 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @0030066C ADDIU t6, t6, $4978 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18808))); + // @00300670 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300674 LWC1 $f0, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @00300678 ADDIU t7, t7, $497c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18812))); + // @0030067C LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00300680 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @00300684 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @00300688 ADDIU t6, t6, $4980 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18816))); + // @0030068C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300690 ADDIU t7, t7, $4984 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18820))); + // @00300694 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @00300698 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @0030069C LWC1 $f1, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); + // @003006A0 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @003006A4 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @003006A8 ADDIU t6, t6, $4988 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18824))); + // @003006AC MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @003006B0 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @003006B4 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @003006B8 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @003006BC LWC1 $f1, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); + // @003006C0 ADD.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f + this.ee.fpr[1].f); + // @003006C4 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @003006C8 BNE t1, zero, $0030070c + if ((this.ee.t1.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3147532u; + } + // @003006CC SUB.S $f2, $f12, $f0 + this.ee.fpr[2].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + } + + public virtual void funct003006d0() + { + this.ee.pc = 3147532u; + // @003006D0 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003006D4 MUL.S $f0, $f12, $f2 + this.ee.fpr[0].f = (this.ee.fpr[12].f * this.ee.fpr[2].f); + // @003006D8 ADDIU t7, t7, $498c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18828))); + // @003006DC LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @003006E0 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @003006E4 ADDIU t6, t6, $4970 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18800))); + // @003006E8 SUB.S $f1, $f2, $f1 + this.ee.fpr[1].f = (this.ee.fpr[2].f - this.ee.fpr[1].f); + // @003006EC NOP + MobUt.Latency(); + // @003006F0 NOP + MobUt.Latency(); + // @003006F4 DIV.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f / this.ee.fpr[1].f); + // @003006F8 SUB.S $f0, $f0, $f12 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[12].f); + // @003006FC LWC1 $f1, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t6.UL0)); + // @00300700 SUB.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f - this.ee.fpr[0].f); + // @00300704 BEQ zero, zero, $003005e4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3147236u; + } + // @00300708 MFC1 t5, $f1 + MobUt.MFC1(this.ee.t5, this.ee.fpr[1]); + } + + public virtual void funct00300704() + { + this.ee.pc = 3147532u; + // @00300704 BEQ zero, zero, $003005e4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3147236u; + } + // @00300708 MFC1 t5, $f1 + MobUt.MFC1(this.ee.t5, this.ee.fpr[1]); + } + + public virtual void funct0030070c() + { + this.ee.pc = 3147600u; + // @0030070C LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @00300710 MUL.S $f1, $f12, $f2 + this.ee.fpr[1].f = (this.ee.fpr[12].f * this.ee.fpr[2].f); + // @00300714 ADDIU t6, t6, $498c + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18828))); + // @00300718 SLTI t7, t1, $ff83 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t1.SD0 < -125)); + // @0030071C LWC1 $f0, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @00300720 SUB.S $f0, $f0, $f2 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[2].f); + // @00300724 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @00300728 ADDIU t6, t6, $4970 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18800))); + // @0030072C NOP + MobUt.Latency(); + // @00300730 NOP + MobUt.Latency(); + // @00300734 DIV.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f / this.ee.fpr[0].f); + // @00300738 SUB.S $f1, $f4, $f1 + this.ee.fpr[1].f = (this.ee.fpr[4].f - this.ee.fpr[1].f); + // @0030073C LWC1 $f0, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @00300740 SUB.S $f1, $f1, $f3 + this.ee.fpr[1].f = (this.ee.fpr[1].f - this.ee.fpr[3].f); + // @00300744 SUB.S $f0, $f0, $f1 + this.ee.fpr[0].f = (this.ee.fpr[0].f - this.ee.fpr[1].f); + // @00300748 BNE t7, zero, $0030075c + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3147612u; + } + // @0030074C MFC1 t6, $f0 + MobUt.MFC1(this.ee.t6, this.ee.fpr[0]); + } + + public virtual void funct00300750() + { + this.ee.pc = 3147612u; + // @00300750 SLL t7, t1, 23 + MobUt.SLL(this.ee.t7, this.ee.t1, 23); + // @00300754 BEQ zero, zero, $003005e4 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3147236u; + } + // @00300758 ADDU t5, t6, t7 + this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + } + + public virtual void funct0030075c() + { + this.ee.pc = 3147652u; + // @0030075C MFC1 t7, $f0 + MobUt.MFC1(this.ee.t7, this.ee.fpr[0]); + // @00300760 ADDIU t6, t1, $0064 + this.ee.t6.SD0 = ((int)((this.ee.t1.SD0 + 100))); + // @00300764 SLL t6, t6, 23 + MobUt.SLL(this.ee.t6, this.ee.t6, 23); + // @00300768 ADDU t6, t7, t6 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @0030076C LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300770 MTC1 t6, $f1 + this.ee.fpr[1].f = MobUt.UL2F(this.ee.t6.UL[0]); + // @00300774 ADDIU t7, t7, $4990 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18832))); + // @00300778 LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @0030077C BEQ zero, zero, $00300704 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3147524u; + } + // @00300780 MUL.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f * this.ee.fpr[0].f); + } + + public virtual void funct00300784() + { + this.ee.pc = 3147744u; + // @00300784 SLL t6, t2, 2 + MobUt.SLL(this.ee.t6, this.ee.t2, 2); + // @00300788 ADDIU t7, t7, $4964 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18788))); + // @0030078C LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @00300790 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @00300794 MUL.S $f1, $f12, $f1 + this.ee.fpr[1].f = (this.ee.fpr[12].f * this.ee.fpr[1].f); + // @00300798 ADDIU t7, t7, $4928 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18728))); + // @0030079C ADDU t6, t6, t7 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t7.SD0))); + // @003007A0 LWC1 $f0, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @003007A4 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003007A8 ADDIU t7, t7, $496c + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 18796))); + // @003007AC ADD.S $f1, $f1, $f0 + this.ee.fpr[1].f = (this.ee.fpr[1].f + this.ee.fpr[0].f); + // @003007B0 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + // @003007B4 ADDIU t6, t6, $4968 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + 18792))); + // @003007B8 CVT.W.S $f0, $f1 + MobUt.CVT_W(this.ee.fpr[0], this.ee.fpr[1]); + // @003007BC MFC1 t1, $f0 + MobUt.MFC1(this.ee.t1, this.ee.fpr[0]); + // @003007C0 LWC1 $f1, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[1], (0u + this.ee.t7.UL0)); + // @003007C4 MTC1 t1, $f2 + this.ee.fpr[2].f = MobUt.UL2F(this.ee.t1.UL[0]); + // @003007C8 LWC1 $f0, $0000(t6) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t6.UL0)); + // @003007CC CVT.S.W $f2, $f2 + MobUt.CVT_S(this.ee.fpr[2], this.ee.fpr[2]); + // @003007D0 MUL.S $f0, $f2, $f0 + this.ee.fpr[0].f = (this.ee.fpr[2].f * this.ee.fpr[0].f); + // @003007D4 MUL.S $f4, $f2, $f1 + this.ee.fpr[4].f = (this.ee.fpr[2].f * this.ee.fpr[1].f); + // @003007D8 BEQ zero, zero, $00300660 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3147360u; + } + // @003007DC SUB.S $f3, $f12, $f0 + this.ee.fpr[3].f = (this.ee.fpr[12].f - this.ee.fpr[0].f); + } + + public virtual void funct003007e0() + { + this.ee.pc = 3147764u; + // @003007E0 LUI t7, $317f + this.ee.t7.SD0 = 830406656; + // @003007E4 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @003007E8 SLTU t7, t7, t3 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t7.UD0 < this.ee.t3.UD0)); + // @003007EC BNEL t7, zero, $00300664 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3147364u; + // @003007F0 DADDU t1, zero, zero + this.ee.t1.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + } + } + + public virtual void funct00301800() + { + this.ee.pc = 3151908u; + // @00301800 LUI t7, $7fff + this.ee.t7.SD0 = 2147418112; + // @00301804 MFC1 t6, $f12 + MobUt.MFC1(this.ee.t6, this.ee.fpr[12]); + // @00301808 ORI t7, t7, $ffff + this.ee.t7.UD0 = (this.ee.t7.UD0 | 65535); + // @0030180C LUI t4, $007f + this.ee.t4.SD0 = 8323072; + // @00301810 AND t7, t6, t7 + this.ee.t7.UD0 = (this.ee.t6.UD0 & this.ee.t7.UD0); + // @00301814 ORI t4, t4, $ffff + this.ee.t4.UD0 = (this.ee.t4.UD0 | 65535); + // @00301818 SLTU t7, t4, t7 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t4.UD0 < this.ee.t7.UD0)); + // @0030181C BEQ t7, zero, $00301840 + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3151936u; + } + // @00301820 MFC1 t5, $f12 + MobUt.MFC1(this.ee.t5, this.ee.fpr[12]); + } + + public virtual void funct00301824() + { + this.ee.pc = 3151916u; + // @00301824 BGEZL t6, $00301848 + if ((this.ee.t6.SD0 >= 0)) + { + this.ee.pc = 3151944u; + // @00301828 SRA t1, t6, 23 + MobUt.SRA(this.ee.t1, this.ee.t6, 23); + } + } + + public virtual void funct00301840() + { + this.ee.pc = 3151944u; + // @00301840 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @00301844 MTC1 t5, $f0 + this.ee.fpr[0].f = MobUt.UL2F(this.ee.t5.UL[0]); + } + + public virtual void funct00301848() + { + this.ee.pc = 3152004u; + // @00301848 ADDIU t1, t1, $ff81 + this.ee.t1.SD0 = ((int)((this.ee.t1.SD0 + -127))); + // @0030184C AND t7, t6, t4 + this.ee.t7.UD0 = (this.ee.t6.UD0 & this.ee.t4.UD0); + // @00301850 ANDI t5, t1, $0001 + this.ee.t5.UD0 = ((ushort)((this.ee.t1.US0 & 1))); + // @00301854 LUI t6, $0080 + this.ee.t6.SD0 = 8388608; + // @00301858 SRA t1, t1, 1 + MobUt.SRA(this.ee.t1, this.ee.t1, 1); + // @0030185C OR t6, t7, t6 + this.ee.t6.UD0 = (this.ee.t7.UD0 | this.ee.t6.UD0); + // @00301860 DADDU t3, zero, zero + this.ee.t3.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @00301864 SLLV t6, t6, t5 + MobUt.SLLV(this.ee.t6, this.ee.t6, this.ee.t5); + // @00301868 DADDU t2, zero, zero + this.ee.t2.UD0 = (this.ee.r0.UD0 + this.ee.r0.UD0); + // @0030186C SLL t6, t6, 1 + MobUt.SLL(this.ee.t6, this.ee.t6, 1); + // @00301870 LUI t4, $0100 + this.ee.t4.SD0 = 16777216; + // @00301874 ADDU t5, t3, t4 + this.ee.t5.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t4.SD0))); + // @00301878 SLT t7, t6, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < this.ee.t5.SD0)); + // @0030187C BNEL t7, zero, $00301894 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3152020u; + // @00301880 SRL t4, t4, 1 + MobUt.SRL(this.ee.t4, this.ee.t4, 1); + } + } + + public virtual void funct00301874() + { + this.ee.pc = 3152004u; + // @00301874 ADDU t5, t3, t4 + this.ee.t5.SD0 = ((int)((this.ee.t3.SD0 + this.ee.t4.SD0))); + // @00301878 SLT t7, t6, t5 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.t6.SD0 < this.ee.t5.SD0)); + // @0030187C BNEL t7, zero, $00301894 + if ((this.ee.t7.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3152020u; + // @00301880 SRL t4, t4, 1 + MobUt.SRL(this.ee.t4, this.ee.t4, 1); + } + } + + public virtual void funct00301884() + { + this.ee.pc = 3152028u; + // @00301884 SUBU t6, t6, t5 + this.ee.t6.SD0 = ((int)((this.ee.t6.UD0 - this.ee.t5.UD0))); + // @00301888 ADDU t3, t5, t4 + this.ee.t3.SD0 = ((int)((this.ee.t5.SD0 + this.ee.t4.SD0))); + // @0030188C ADDU t2, t2, t4 + this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + this.ee.t4.SD0))); + // @00301890 SRL t4, t4, 1 + MobUt.SRL(this.ee.t4, this.ee.t4, 1); + // @00301894 BNE t4, zero, $00301874 + if ((this.ee.t4.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3151988u; + } + // @00301898 SLL t6, t6, 1 + MobUt.SLL(this.ee.t6, this.ee.t6, 1); + } + + public virtual void funct00301894() + { + this.ee.pc = 3152028u; + // @00301894 BNE t4, zero, $00301874 + if ((this.ee.t4.UD0 != this.ee.r0.UD0)) + { + this.ee.pc = 3151988u; + } + // @00301898 SLL t6, t6, 1 + MobUt.SLL(this.ee.t6, this.ee.t6, 1); + } + + public virtual void funct0030189c() + { + this.ee.pc = 3152036u; + // @0030189C BEQ t6, zero, $003018c8 + if ((this.ee.t6.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3152072u; + } + // @003018A0 SRA t7, t2, 1 + MobUt.SRA(this.ee.t7, this.ee.t2, 1); + } + + public virtual void funct003018a4() + { + this.ee.pc = 3152060u; + // @003018A4 LUI t7, $0038 + this.ee.t7.SD0 = 3670016; + // @003018A8 ADDIU t7, t7, $4f00 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + 20224))); + // @003018AC LWC1 $f0, $0000(t7) + MobUt.LWC1(this.ee, this.ee.fpr[0], (0u + this.ee.t7.UL0)); + // @003018B0 C.LE.S $f0, $f0 + this.ee.fcr31_23 = (this.ee.fpr[0].f <= this.ee.fpr[0].f); + // @003018B4 BC1FL $003018c8 + if ((this.ee.fcr31_23 == false)) + { + this.ee.pc = 3152072u; + // @003018B8 SRA t7, t2, 1 + MobUt.SRA(this.ee.t7, this.ee.t2, 1); + } + } + + public virtual void funct003018bc() + { + this.ee.pc = 3152092u; + // @003018BC ANDI t7, t2, $0001 + this.ee.t7.UD0 = ((ushort)((this.ee.t2.US0 & 1))); + // @003018C0 ADDU t2, t2, t7 + this.ee.t2.SD0 = ((int)((this.ee.t2.SD0 + this.ee.t7.SD0))); + // @003018C4 SRA t7, t2, 1 + MobUt.SRA(this.ee.t7, this.ee.t2, 1); + // @003018C8 LUI t6, $3f00 + this.ee.t6.SD0 = 1056964608; + // @003018CC ADDU t6, t7, t6 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @003018D0 SLL t5, t1, 23 + MobUt.SLL(this.ee.t5, this.ee.t1, 23); + // @003018D4 BEQ zero, zero, $00301840 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3151936u; + } + // @003018D8 ADDU t5, t6, t5 + this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); + } + + public virtual void funct003018c8() + { + this.ee.pc = 3152092u; + // @003018C8 LUI t6, $3f00 + this.ee.t6.SD0 = 1056964608; + // @003018CC ADDU t6, t7, t6 + this.ee.t6.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @003018D0 SLL t5, t1, 23 + MobUt.SLL(this.ee.t5, this.ee.t1, 23); + // @003018D4 BEQ zero, zero, $00301840 + if ((this.ee.r0.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3151936u; + } + // @003018D8 ADDU t5, t6, t5 + this.ee.t5.SD0 = ((int)((this.ee.t6.SD0 + this.ee.t5.SD0))); + } + + public virtual void funct0032d8d0() + { + this.ee.pc = 3332316u; + // @0032D8D0 SLTIU t7, a1, $0010 + this.ee.t7.UD0 = System.Convert.ToByte((this.ee.a1.UD0 < 16ul)); + // @0032D8D4 BEQ t7, zero, $0032d95c + if ((this.ee.t7.UD0 == this.ee.r0.UD0)) + { + this.ee.pc = 3332444u; + } + // @0032D8D8 LUI t6, $0038 + this.ee.t6.SD0 = 3670016; + } + + public virtual void funct0032d8dc() + { + this.ee.pc = 3332340u; + // @0032D8DC SLL t7, a1, 2 + MobUt.SLL(this.ee.t7, this.ee.a1, 2); + // @0032D8E0 ADDIU t6, t6, $8764 + this.ee.t6.SD0 = ((int)((this.ee.t6.SD0 + -30876))); + // @0032D8E4 ADDU t7, t7, t6 + this.ee.t7.SD0 = ((int)((this.ee.t7.SD0 + this.ee.t6.SD0))); + // @0032D8E8 LW t5, $0000(t7) + MobUt.LW(this.ee, this.ee.t5, (0u + this.ee.t7.UL0)); + // @0032D8EC JR t5 + this.ee.pc = this.ee.t5.UL[0]; + // @0032D8F0 NOP + MobUt.Latency(); + } + + public virtual void funct0032d964() + { + this.ee.pc = 3332460u; + // @0032D964 JR ra + this.ee.pc = this.ee.ra.UL[0]; + // @0032D968 ADDIU v0, zero, $0001 + this.ee.v0.SD0 = ((int)((this.ee.r0.SD0 + 1))); + } + + private void initstate() + { + this.initregs(); + this.initfns(); + } + + private void initregs() + { + this.ee.r0.UD0 = 0ul; + this.ee.r0.UD1 = 0ul; + this.ee.at.UD0 = 1070141403ul; + this.ee.at.UD1 = 0ul; + this.ee.v0.UD0 = 229ul; + this.ee.v0.UD1 = 0ul; + this.ee.v1.UD0 = 3728656ul; + this.ee.v1.UD1 = 11678ul; + this.ee.a0.UD0 = 10454288ul; + this.ee.a0.UD1 = 11633ul; + this.ee.a1.UD0 = 28030352ul; + this.ee.a1.UD1 = 0ul; + this.ee.a2.UD0 = 3730592ul; + this.ee.a2.UD1 = 0ul; + this.ee.a3.UD0 = 0ul; + this.ee.a3.UD1 = 0ul; + this.ee.t0.UD0 = 3730800ul; + this.ee.t0.UD1 = 1059810839ul; + this.ee.t1.UD0 = 4575657221408423936ul; + this.ee.t1.UD1 = 0ul; + this.ee.t2.UD0 = 3207294487ul; + this.ee.t2.UD1 = 1061036071ul; + this.ee.t3.UD0 = 3306101109ul; + this.ee.t3.UD1 = 4575657224709998879ul; + this.ee.t4.UD0 = 8ul; + this.ee.t4.UD1 = 4575657221408423936ul; + this.ee.t5.UD0 = 10454432ul; + this.ee.t5.UD1 = 0ul; + this.ee.t6.UD0 = 0ul; + this.ee.t6.UD1 = 6660591616ul; + this.ee.t7.UD0 = 1ul; + this.ee.t7.UD1 = 78ul; + this.ee.s0.UD0 = 10454432ul; + this.ee.s0.UD1 = 0ul; + this.ee.s1.UD0 = 10454288ul; + this.ee.s1.UD1 = 0ul; + this.ee.s2.UD0 = 28030352ul; + this.ee.s2.UD1 = 0ul; + this.ee.s3.UD0 = 3730800ul; + this.ee.s3.UD1 = 0ul; + this.ee.s4.UD0 = 28029104ul; + this.ee.s4.UD1 = 0ul; + this.ee.s5.UD0 = 0ul; + this.ee.s5.UD1 = 0ul; + this.ee.s6.UD0 = 3730800ul; + this.ee.s6.UD1 = 0ul; + this.ee.s7.UD0 = 0ul; + this.ee.s7.UD1 = 0ul; + this.ee.t8.UD0 = 3728624ul; + this.ee.t8.UD1 = 0ul; + this.ee.t9.UD0 = 3728640ul; + this.ee.t9.UD1 = 0ul; + this.ee.k0.UD0 = 1879247891ul; + this.ee.k0.UD1 = 0ul; + this.ee.k1.UD0 = 0ul; + this.ee.k1.UD1 = 0ul; + this.ee.gp.UD0 = 3704508ul; + this.ee.gp.UD1 = 0ul; + this.ee.sp.UD0 = 3730592ul; + this.ee.sp.UD1 = 0ul; + this.ee.s8.UD0 = 0ul; + this.ee.s8.UD1 = 0ul; + this.ee.ra.UD0 = 1248400ul; + this.ee.ra.UD1 = 0ul; + this.ee.fpr[0].f = MobUt.UL2F(3212836864u); + this.ee.fpr[1].f = MobUt.UL2F(1065211454u); + this.ee.fpr[2].f = MobUt.UL2F(1088754307u); + this.ee.fpr[3].f = MobUt.UL2F(1007317092u); + this.ee.fpr[4].f = MobUt.UL2F(967154684u); + this.ee.fpr[5].f = MobUt.UL2F(3201396739u); + this.ee.fpr[6].f = MobUt.UL2F(1063086025u); + this.ee.fpr[7].f = MobUt.UL2F(1065353216u); + this.ee.fpr[8].f = MobUt.UL2F(1147806946u); + this.ee.fpr[9].f = MobUt.UL2F(1124209790u); + this.ee.fpr[10].f = MobUt.UL2F(1108805435u); + this.ee.fpr[11].f = MobUt.UL2F(0u); + this.ee.fpr[12].f = MobUt.UL2F(1090519040u); + this.ee.fpr[13].f = MobUt.UL2F(0u); + this.ee.fpr[14].f = MobUt.UL2F(3241277924u); + this.ee.fpr[15].f = MobUt.UL2F(3160289907u); + this.ee.fpr[16].f = MobUt.UL2F(1004365769u); + this.ee.fpr[17].f = MobUt.UL2F(3240795268u); + this.ee.fpr[18].f = MobUt.UL2F(3165876745u); + this.ee.fpr[19].f = MobUt.UL2F(1065353216u); + this.ee.fpr[20].f = MobUt.UL2F(1090519040u); + this.ee.fpr[21].f = MobUt.UL2F(0u); + this.ee.fpr[22].f = MobUt.UL2F(0u); + this.ee.fpr[23].f = MobUt.UL2F(0u); + this.ee.fpr[24].f = MobUt.UL2F(0u); + this.ee.fpr[25].f = MobUt.UL2F(0u); + this.ee.fpr[26].f = MobUt.UL2F(0u); + this.ee.fpr[27].f = MobUt.UL2F(0u); + this.ee.fpr[28].f = MobUt.UL2F(0u); + this.ee.fpr[29].f = MobUt.UL2F(0u); + this.ee.fpr[30].f = MobUt.UL2F(0u); + this.ee.fpr[31].f = MobUt.UL2F(0u); + this.ee.fpracc.f = MobUt.UL2F(3241375643u); + this.ee.VF[0].x = MobUt.UL2F(0u); + this.ee.VF[0].y = MobUt.UL2F(0u); + this.ee.VF[0].z = MobUt.UL2F(0u); + this.ee.VF[0].w = MobUt.UL2F(1065353216u); + this.ee.VF[1].x = MobUt.UL2F(1059810839u); + this.ee.VF[1].y = MobUt.UL2F(2147483648u); + this.ee.VF[1].z = MobUt.UL2F(3208519719u); + this.ee.VF[1].w = MobUt.UL2F(2147483648u); + this.ee.VF[2].x = MobUt.UL2F(3212836864u); + this.ee.VF[2].y = MobUt.UL2F(4294967295u); + this.ee.VF[2].z = MobUt.UL2F(1059810839u); + this.ee.VF[2].w = MobUt.UL2F(0u); + this.ee.VF[3].x = MobUt.UL2F(3207294487u); + this.ee.VF[3].y = MobUt.UL2F(2147483648u); + this.ee.VF[3].z = MobUt.UL2F(1061036071u); + this.ee.VF[3].w = MobUt.UL2F(0u); + this.ee.VF[4].x = MobUt.UL2F(3306101109u); + this.ee.VF[4].y = MobUt.UL2F(0u); + this.ee.VF[4].z = MobUt.UL2F(3301574943u); + this.ee.VF[4].w = MobUt.UL2F(1065353216u); + this.ee.VF[5].x = MobUt.UL2F(1061036071u); + this.ee.VF[5].y = MobUt.UL2F(0u); + this.ee.VF[5].z = MobUt.UL2F(1059810839u); + this.ee.VF[5].w = MobUt.UL2F(0u); + this.ee.VF[6].x = MobUt.UL2F(0u); + this.ee.VF[6].y = MobUt.UL2F(1065353216u); + this.ee.VF[6].z = MobUt.UL2F(0u); + this.ee.VF[6].w = MobUt.UL2F(0u); + this.ee.VF[7].x = MobUt.UL2F(3207294487u); + this.ee.VF[7].y = MobUt.UL2F(0u); + this.ee.VF[7].z = MobUt.UL2F(1061036071u); + this.ee.VF[7].w = MobUt.UL2F(0u); + this.ee.VF[8].x = MobUt.UL2F(3306101109u); + this.ee.VF[8].y = MobUt.UL2F(0u); + this.ee.VF[8].z = MobUt.UL2F(3301574943u); + this.ee.VF[8].w = MobUt.UL2F(1065353216u); + this.ee.VF[9].x = MobUt.UL2F(0u); + this.ee.VF[9].y = MobUt.UL2F(0u); + this.ee.VF[9].z = MobUt.UL2F(0u); + this.ee.VF[9].w = MobUt.UL2F(1065353216u); + this.ee.VF[10].x = MobUt.UL2F(1221302671u); + this.ee.VF[10].y = MobUt.UL2F(1221302671u); + this.ee.VF[10].z = MobUt.UL2F(3290595208u); + this.ee.VF[10].w = MobUt.UL2F(1129027983u); + this.ee.VF[11].x = MobUt.UL2F(1278239296u); + this.ee.VF[11].y = MobUt.UL2F(1277754648u); + this.ee.VF[11].z = MobUt.UL2F(1266599817u); + this.ee.VF[11].w = MobUt.UL2F(1186077023u); + this.ee.VF[12].x = MobUt.UL2F(1157627904u); + this.ee.VF[12].y = MobUt.UL2F(1157627904u); + this.ee.VF[12].z = MobUt.UL2F(1249902592u); + this.ee.VF[12].w = MobUt.UL2F(1249902592u); + this.ee.VF[13].x = MobUt.UL2F(0u); + this.ee.VF[13].y = MobUt.UL2F(0u); + this.ee.VF[13].z = MobUt.UL2F(0u); + this.ee.VF[13].w = MobUt.UL2F(1132462080u); + this.ee.VF[14].x = MobUt.UL2F(0u); + this.ee.VF[14].y = MobUt.UL2F(0u); + this.ee.VF[14].z = MobUt.UL2F(0u); + this.ee.VF[14].w = MobUt.UL2F(1153433600u); + this.ee.VF[15].x = MobUt.UL2F(1068826624u); + this.ee.VF[15].y = MobUt.UL2F(1065746432u); + this.ee.VF[15].z = MobUt.UL2F(1060896768u); + this.ee.VF[15].w = MobUt.UL2F(1068761088u); + this.ee.VF[16].x = MobUt.UL2F(32435u); + this.ee.VF[16].y = MobUt.UL2F(31091u); + this.ee.VF[16].z = MobUt.UL2F(11678u); + this.ee.VF[16].w = MobUt.UL2F(943151540u); + this.ee.VF[17].x = MobUt.UL2F(3301739238u); + this.ee.VF[17].y = MobUt.UL2F(3321541486u); + this.ee.VF[17].z = MobUt.UL2F(1186077023u); + this.ee.VF[17].w = MobUt.UL2F(1065353216u); + this.ee.VF[18].x = MobUt.UL2F(1154255590u); + this.ee.VF[18].y = MobUt.UL2F(1174057838u); + this.ee.VF[18].z = MobUt.UL2F(3333560671u); + this.ee.VF[18].w = MobUt.UL2F(3221225472u); + this.ee.VF[19].x = MobUt.UL2F(0u); + this.ee.VF[19].y = MobUt.UL2F(0u); + this.ee.VF[19].z = MobUt.UL2F(0u); + this.ee.VF[19].w = MobUt.UL2F(1065353216u); + this.ee.VF[20].x = MobUt.UL2F(32224u); + this.ee.VF[20].y = MobUt.UL2F(30845u); + this.ee.VF[20].z = MobUt.UL2F(11719u); + this.ee.VF[20].w = MobUt.UL2F(364746u); + this.ee.VF[21].x = MobUt.UL2F(1158017723u); + this.ee.VF[21].y = MobUt.UL2F(1159360723u); + this.ee.VF[21].z = MobUt.UL2F(1144462391u); + this.ee.VF[21].w = MobUt.UL2F(1186077023u); + this.ee.VF[22].x = MobUt.UL2F(1157913735u); + this.ee.VF[22].y = MobUt.UL2F(1159493858u); + this.ee.VF[22].z = MobUt.UL2F(1144462391u); + this.ee.VF[22].w = MobUt.UL2F(1186077023u); + this.ee.VF[23].x = MobUt.UL2F(32688u); + this.ee.VF[23].y = MobUt.UL2F(31347u); + this.ee.VF[23].z = MobUt.UL2F(11719u); + this.ee.VF[23].w = MobUt.UL2F(364746u); + this.ee.VF[24].x = MobUt.UL2F(1278158170u); + this.ee.VF[24].y = MobUt.UL2F(1277666762u); + this.ee.VF[24].z = MobUt.UL2F(1144462391u); + this.ee.VF[24].w = MobUt.UL2F(1186077023u); + this.ee.VF[25].x = MobUt.UL2F(3293934063u); + this.ee.VF[25].y = MobUt.UL2F(3292049472u); + this.ee.VF[25].z = MobUt.UL2F(1066904244u); + this.ee.VF[25].w = MobUt.UL2F(3200124770u); + this.ee.VF[26].x = MobUt.UL2F(1174396132u); + this.ee.VF[26].y = MobUt.UL2F(1282769649u); + this.ee.VF[26].z = MobUt.UL2F(1044218678u); + this.ee.VF[26].w = MobUt.UL2F(3178066551u); + this.ee.VF[27].x = MobUt.UL2F(1157627904u); + this.ee.VF[27].y = MobUt.UL2F(1157627904u); + this.ee.VF[27].z = MobUt.UL2F(1249902592u); + this.ee.VF[27].w = MobUt.UL2F(1249902592u); + this.ee.VF[28].x = MobUt.UL2F(1177474794u); + this.ee.VF[28].y = MobUt.UL2F(0u); + this.ee.VF[28].z = MobUt.UL2F(0u); + this.ee.VF[28].w = MobUt.UL2F(0u); + this.ee.VF[29].x = MobUt.UL2F(0u); + this.ee.VF[29].y = MobUt.UL2F(1178429652u); + this.ee.VF[29].z = MobUt.UL2F(0u); + this.ee.VF[29].w = MobUt.UL2F(0u); + this.ee.VF[30].x = MobUt.UL2F(1221302671u); + this.ee.VF[30].y = MobUt.UL2F(1221302671u); + this.ee.VF[30].z = MobUt.UL2F(3290595208u); + this.ee.VF[30].w = MobUt.UL2F(1129027983u); + this.ee.VF[31].x = MobUt.UL2F(1278239296u); + this.ee.VF[31].y = MobUt.UL2F(1277754648u); + this.ee.VF[31].z = MobUt.UL2F(1266599817u); + this.ee.VF[31].w = MobUt.UL2F(1186077023u); + } + + private void initfns() + { + this.dicti2a[1160224u] = new MobUt.Tx8(this.funct0011b420); + this.dicti2a[1160272u] = new MobUt.Tx8(this.funct0011b450); + this.dicti2a[1160300u] = new MobUt.Tx8(this.funct0011b46c); + this.dicti2a[1160308u] = new MobUt.Tx8(this.funct0011b474); + this.dicti2a[1160324u] = new MobUt.Tx8(this.funct0011b484); + this.dicti2a[1160488u] = new MobUt.Tx8(this.funct0011b528); + this.dicti2a[1160536u] = new MobUt.Tx8(this.funct0011b558); + this.dicti2a[1160544u] = new MobUt.Tx8(this.funct0011b560); + this.dicti2a[1160560u] = new MobUt.Tx8(this.funct0011b570); + this.dicti2a[1160576u] = new MobUt.Tx8(this.funct0011b580); + this.dicti2a[1160584u] = new MobUt.Tx8(this.funct0011b588); + this.dicti2a[1160600u] = new MobUt.Tx8(this.funct0011b598); + this.dicti2a[1160616u] = new MobUt.Tx8(this.funct0011b5a8); + this.dicti2a[1160624u] = new MobUt.Tx8(this.funct0011b5b0); + this.dicti2a[1160640u] = new MobUt.Tx8(this.funct0011b5c0); + this.dicti2a[1161280u] = new MobUt.Tx8(this.funct0011b840); + this.dicti2a[1161332u] = new MobUt.Tx8(this.funct0011b874); + this.dicti2a[1161356u] = new MobUt.Tx8(this.funct0011b88c); + this.dicti2a[1161364u] = new MobUt.Tx8(this.funct0011b894); + this.dicti2a[1161412u] = new MobUt.Tx8(this.funct0011b8c4); + this.dicti2a[1161420u] = new MobUt.Tx8(this.funct0011b8cc); + this.dicti2a[1161432u] = new MobUt.Tx8(this.funct0011b8d8); + this.dicti2a[1161448u] = new MobUt.Tx8(this.funct0011b8e8); + this.dicti2a[1161456u] = new MobUt.Tx8(this.funct0011b8f0); + this.dicti2a[1161472u] = new MobUt.Tx8(this.funct0011b900); + this.dicti2a[1161492u] = new MobUt.Tx8(this.funct0011b914); + this.dicti2a[1161512u] = new MobUt.Tx8(this.funct0011b928); + this.dicti2a[1161576u] = new MobUt.Tx8(this.funct0011b968); + this.dicti2a[1161596u] = new MobUt.Tx8(this.funct0011b97c); + this.dicti2a[1161616u] = new MobUt.Tx8(this.funct0011b990); + this.dicti2a[1161692u] = new MobUt.Tx8(this.funct0011b9dc); + this.dicti2a[1161736u] = new MobUt.Tx8(this.funct0011ba08); + this.dicti2a[1161760u] = new MobUt.Tx8(this.funct0011ba20); + this.dicti2a[1161808u] = new MobUt.Tx8(this.funct0011ba50); + this.dicti2a[1161820u] = new MobUt.Tx8(this.funct0011ba5c); + this.dicti2a[1161832u] = new MobUt.Tx8(this.funct0011ba68); + this.dicti2a[1161860u] = new MobUt.Tx8(this.funct0011ba84); + this.dicti2a[1161888u] = new MobUt.Tx8(this.funct0011baa0); + this.dicti2a[1162696u] = new MobUt.Tx8(this.funct0011bdc8); + this.dicti2a[1162712u] = new MobUt.Tx8(this.funct0011bdd8); + this.dicti2a[1162732u] = new MobUt.Tx8(this.funct0011bdec); + this.dicti2a[1162752u] = new MobUt.Tx8(this.funct0011be00); + this.dicti2a[1162780u] = new MobUt.Tx8(this.funct0011be1c); + this.dicti2a[1162788u] = new MobUt.Tx8(this.funct0011be24); + this.dicti2a[1162812u] = new MobUt.Tx8(this.funct0011be3c); + this.dicti2a[1162828u] = new MobUt.Tx8(this.funct0011be4c); + this.dicti2a[1162840u] = new MobUt.Tx8(this.funct0011be58); + this.dicti2a[1181264u] = new MobUt.Tx8(this.funct00120650); + this.dicti2a[1181296u] = new MobUt.Tx8(this.funct00120670); + this.dicti2a[1181328u] = new MobUt.Tx8(this.funct00120690); + this.dicti2a[1181344u] = new MobUt.Tx8(this.funct001206a0); + this.dicti2a[1181372u] = new MobUt.Tx8(this.funct001206bc); + this.dicti2a[1181380u] = new MobUt.Tx8(this.funct001206c4); + this.dicti2a[1198728u] = new MobUt.Tx8(this.funct00124a88); + this.dicti2a[1198900u] = new MobUt.Tx8(this.funct00124b34); + this.dicti2a[1198972u] = new MobUt.Tx8(this.funct00124b7c); + this.dicti2a[1198996u] = new MobUt.Tx8(this.funct00124b94); + this.dicti2a[1199092u] = new MobUt.Tx8(this.funct00124bf4); + this.dicti2a[1199188u] = new MobUt.Tx8(this.funct00124c54); + this.dicti2a[1199256u] = new MobUt.Tx8(this.funct00124c98); + this.dicti2a[1199264u] = new MobUt.Tx8(this.funct00124ca0); + this.dicti2a[1199284u] = new MobUt.Tx8(this.funct00124cb4); + this.dicti2a[1199304u] = new MobUt.Tx8(this.funct00124cc8); + this.dicti2a[1199336u] = new MobUt.Tx8(this.funct00124ce8); + this.dicti2a[1199344u] = new MobUt.Tx8(this.funct00124cf0); + this.dicti2a[1199356u] = new MobUt.Tx8(this.funct00124cfc); + this.dicti2a[1199480u] = new MobUt.Tx8(this.funct00124d78); + this.dicti2a[1199512u] = new MobUt.Tx8(this.funct00124d98); + this.dicti2a[1199520u] = new MobUt.Tx8(this.funct00124da0); + this.dicti2a[1199528u] = new MobUt.Tx8(this.funct00124da8); + this.dicti2a[1199564u] = new MobUt.Tx8(this.funct00124dcc); + this.dicti2a[1199620u] = new MobUt.Tx8(this.funct00124e04); + this.dicti2a[1199672u] = new MobUt.Tx8(this.funct00124e38); + this.dicti2a[1199676u] = new MobUt.Tx8(this.funct00124e3c); + this.dicti2a[1199680u] = new MobUt.Tx8(this.funct00124e40); + this.dicti2a[1199712u] = new MobUt.Tx8(this.funct00124e60); + this.dicti2a[1199720u] = new MobUt.Tx8(this.funct00124e68); + this.dicti2a[1199740u] = new MobUt.Tx8(this.funct00124e7c); + this.dicti2a[1199828u] = new MobUt.Tx8(this.funct00124ed4); + this.dicti2a[1199840u] = new MobUt.Tx8(this.funct00124ee0); + this.dicti2a[1199852u] = new MobUt.Tx8(this.funct00124eec); + this.dicti2a[1199972u] = new MobUt.Tx8(this.funct00124f64); + this.dicti2a[1200004u] = new MobUt.Tx8(this.funct00124f84); + this.dicti2a[1200276u] = new MobUt.Tx8(this.funct00125094); + this.dicti2a[1200316u] = new MobUt.Tx8(this.funct001250bc); + this.dicti2a[1200336u] = new MobUt.Tx8(this.funct001250d0); + this.dicti2a[1200356u] = new MobUt.Tx8(this.funct001250e4); + this.dicti2a[1200364u] = new MobUt.Tx8(this.funct001250ec); + this.dicti2a[1200472u] = new MobUt.Tx8(this.funct00125158); + this.dicti2a[1211936u] = new MobUt.Tx8(this.funct00127e20); + this.dicti2a[1212020u] = new MobUt.Tx8(this.funct00127e74); + this.dicti2a[1212032u] = new MobUt.Tx8(this.funct00127e80); + this.dicti2a[1212040u] = new MobUt.Tx8(this.funct00127e88); + this.dicti2a[1212052u] = new MobUt.Tx8(this.funct00127e94); + this.dicti2a[1212080u] = new MobUt.Tx8(this.funct00127eb0); + this.dicti2a[1212108u] = new MobUt.Tx8(this.funct00127ecc); + this.dicti2a[1212164u] = new MobUt.Tx8(this.funct00127f04); + this.dicti2a[1212176u] = new MobUt.Tx8(this.funct00127f10); + this.dicti2a[1212276u] = new MobUt.Tx8(this.funct00127f74); + this.dicti2a[1212288u] = new MobUt.Tx8(this.funct00127f80); + this.dicti2a[1212292u] = new MobUt.Tx8(this.funct00127f84); + this.dicti2a[1212368u] = new MobUt.Tx8(this.funct00127fd0); + this.dicti2a[1212392u] = new MobUt.Tx8(this.funct00127fe8); + this.dicti2a[1212424u] = new MobUt.Tx8(this.funct00128008); + this.dicti2a[1212448u] = new MobUt.Tx8(this.funct00128020); + this.dicti2a[1212556u] = new MobUt.Tx8(this.funct0012808c); + this.dicti2a[1212572u] = new MobUt.Tx8(this.funct0012809c); + this.dicti2a[1212592u] = new MobUt.Tx8(this.funct001280b0); + this.dicti2a[1212612u] = new MobUt.Tx8(this.funct001280c4); + this.dicti2a[1212616u] = new MobUt.Tx8(this.funct001280c8); + this.dicti2a[1212624u] = new MobUt.Tx8(this.funct001280d0); + this.dicti2a[1212644u] = new MobUt.Tx8(this.funct001280e4); + this.dicti2a[1212664u] = new MobUt.Tx8(this.funct001280f8); + this.dicti2a[1212668u] = new MobUt.Tx8(this.funct001280fc); + this.dicti2a[1212688u] = new MobUt.Tx8(this.funct00128110); + this.dicti2a[1212696u] = new MobUt.Tx8(this.funct00128118); + this.dicti2a[1212756u] = new MobUt.Tx8(this.funct00128154); + this.dicti2a[1212768u] = new MobUt.Tx8(this.funct00128160); + this.dicti2a[1212804u] = new MobUt.Tx8(this.funct00128184); + this.dicti2a[1212832u] = new MobUt.Tx8(this.funct001281a0); + this.dicti2a[1212852u] = new MobUt.Tx8(this.funct001281b4); + this.dicti2a[1212872u] = new MobUt.Tx8(this.funct001281c8); + this.dicti2a[1212876u] = new MobUt.Tx8(this.funct001281cc); + this.dicti2a[1212904u] = new MobUt.Tx8(this.funct001281e8); + this.dicti2a[1212912u] = new MobUt.Tx8(this.funct001281f0); + this.dicti2a[1212916u] = new MobUt.Tx8(this.funct001281f4); + this.dicti2a[1212924u] = new MobUt.Tx8(this.funct001281fc); + this.dicti2a[1212960u] = new MobUt.Tx8(this.funct00128220); + this.dicti2a[1212988u] = new MobUt.Tx8(this.funct0012823c); + this.dicti2a[1213012u] = new MobUt.Tx8(this.funct00128254); + this.dicti2a[1213024u] = new MobUt.Tx8(this.funct00128260); + this.dicti2a[1213076u] = new MobUt.Tx8(this.funct00128294); + this.dicti2a[1213084u] = new MobUt.Tx8(this.funct0012829c); + this.dicti2a[1213108u] = new MobUt.Tx8(this.funct001282b4); + this.dicti2a[1213136u] = new MobUt.Tx8(this.funct001282d0); + this.dicti2a[1213164u] = new MobUt.Tx8(this.funct001282ec); + this.dicti2a[1213188u] = new MobUt.Tx8(this.funct00128304); + this.dicti2a[1213200u] = new MobUt.Tx8(this.funct00128310); + this.dicti2a[1213216u] = new MobUt.Tx8(this.funct00128320); + this.dicti2a[1213236u] = new MobUt.Tx8(this.funct00128334); + this.dicti2a[1213260u] = new MobUt.Tx8(this.funct0012834c); + this.dicti2a[1213296u] = new MobUt.Tx8(this.funct00128370); + this.dicti2a[1213312u] = new MobUt.Tx8(this.funct00128380); + this.dicti2a[1213316u] = new MobUt.Tx8(this.funct00128384); + this.dicti2a[1213336u] = new MobUt.Tx8(this.funct00128398); + this.dicti2a[1213352u] = new MobUt.Tx8(this.funct001283a8); + this.dicti2a[1213380u] = new MobUt.Tx8(this.funct001283c4); + this.dicti2a[1213400u] = new MobUt.Tx8(this.funct001283d8); + this.dicti2a[1213440u] = new MobUt.Tx8(this.funct00128400); + this.dicti2a[1213460u] = new MobUt.Tx8(this.funct00128414); + this.dicti2a[1213472u] = new MobUt.Tx8(this.funct00128420); + this.dicti2a[1213488u] = new MobUt.Tx8(this.funct00128430); + this.dicti2a[1213520u] = new MobUt.Tx8(this.funct00128450); + this.dicti2a[1213556u] = new MobUt.Tx8(this.funct00128474); + this.dicti2a[1213560u] = new MobUt.Tx8(this.funct00128478); + this.dicti2a[1213584u] = new MobUt.Tx8(this.funct00128490); + this.dicti2a[1213592u] = new MobUt.Tx8(this.funct00128498); + this.dicti2a[1213600u] = new MobUt.Tx8(this.funct001284a0); + this.dicti2a[1213608u] = new MobUt.Tx8(this.funct001284a8); + this.dicti2a[1213616u] = new MobUt.Tx8(this.funct001284b0); + this.dicti2a[1213744u] = new MobUt.Tx8(this.funct00128530); + this.dicti2a[1213892u] = new MobUt.Tx8(this.funct001285c4); + this.dicti2a[1213916u] = new MobUt.Tx8(this.funct001285dc); + this.dicti2a[1213924u] = new MobUt.Tx8(this.funct001285e4); + this.dicti2a[1213936u] = new MobUt.Tx8(this.funct001285f0); + this.dicti2a[1213940u] = new MobUt.Tx8(this.funct001285f4); + this.dicti2a[1213980u] = new MobUt.Tx8(this.funct0012861c); + this.dicti2a[1213996u] = new MobUt.Tx8(this.funct0012862c); + this.dicti2a[1214004u] = new MobUt.Tx8(this.funct00128634); + this.dicti2a[1214044u] = new MobUt.Tx8(this.funct0012865c); + this.dicti2a[1214048u] = new MobUt.Tx8(this.funct00128660); + this.dicti2a[1214060u] = new MobUt.Tx8(this.funct0012866c); + this.dicti2a[1214064u] = new MobUt.Tx8(this.funct00128670); + this.dicti2a[1214080u] = new MobUt.Tx8(this.funct00128680); + this.dicti2a[1214092u] = new MobUt.Tx8(this.funct0012868c); + this.dicti2a[1214120u] = new MobUt.Tx8(this.funct001286a8); + this.dicti2a[1214124u] = new MobUt.Tx8(this.funct001286ac); + this.dicti2a[1214176u] = new MobUt.Tx8(this.funct001286e0); + this.dicti2a[1214188u] = new MobUt.Tx8(this.funct001286ec); + this.dicti2a[1214196u] = new MobUt.Tx8(this.funct001286f4); + this.dicti2a[1214212u] = new MobUt.Tx8(this.funct00128704); + this.dicti2a[1214216u] = new MobUt.Tx8(this.funct00128708); + this.dicti2a[1214232u] = new MobUt.Tx8(this.funct00128718); + this.dicti2a[1214336u] = new MobUt.Tx8(this.funct00128780); + this.dicti2a[1214348u] = new MobUt.Tx8(this.funct0012878c); + this.dicti2a[1214356u] = new MobUt.Tx8(this.funct00128794); + this.dicti2a[1214364u] = new MobUt.Tx8(this.funct0012879c); + this.dicti2a[1214400u] = new MobUt.Tx8(this.funct001287c0); + this.dicti2a[1214412u] = new MobUt.Tx8(this.funct001287cc); + this.dicti2a[1214424u] = new MobUt.Tx8(this.funct001287d8); + this.dicti2a[1214432u] = new MobUt.Tx8(this.funct001287e0); + this.dicti2a[1214440u] = new MobUt.Tx8(this.funct001287e8); + this.dicti2a[1214452u] = new MobUt.Tx8(this.funct001287f4); + this.dicti2a[1214460u] = new MobUt.Tx8(this.funct001287fc); + this.dicti2a[1214468u] = new MobUt.Tx8(this.funct00128804); + this.dicti2a[1214528u] = new MobUt.Tx8(this.funct00128840); + this.dicti2a[1214548u] = new MobUt.Tx8(this.funct00128854); + this.dicti2a[1214572u] = new MobUt.Tx8(this.funct0012886c); + this.dicti2a[1214580u] = new MobUt.Tx8(this.funct00128874); + this.dicti2a[1214588u] = new MobUt.Tx8(this.funct0012887c); + this.dicti2a[1214596u] = new MobUt.Tx8(this.funct00128884); + this.dicti2a[1214604u] = new MobUt.Tx8(this.funct0012888c); + this.dicti2a[1214640u] = new MobUt.Tx8(this.funct001288b0); + this.dicti2a[1214644u] = new MobUt.Tx8(this.funct001288b4); + this.dicti2a[1214672u] = new MobUt.Tx8(this.funct001288d0); + this.dicti2a[1214680u] = new MobUt.Tx8(this.funct001288d8); + this.dicti2a[1214744u] = new MobUt.Tx8(this.funct00128918); + this.dicti2a[1214808u] = new MobUt.Tx8(this.funct00128958); + this.dicti2a[1214828u] = new MobUt.Tx8(this.funct0012896c); + this.dicti2a[1214852u] = new MobUt.Tx8(this.funct00128984); + this.dicti2a[1214876u] = new MobUt.Tx8(this.funct0012899c); + this.dicti2a[1214900u] = new MobUt.Tx8(this.funct001289b4); + this.dicti2a[1214932u] = new MobUt.Tx8(this.funct001289d4); + this.dicti2a[1214948u] = new MobUt.Tx8(this.funct001289e4); + this.dicti2a[1214976u] = new MobUt.Tx8(this.funct00128a00); + this.dicti2a[1215000u] = new MobUt.Tx8(this.funct00128a18); + this.dicti2a[1215024u] = new MobUt.Tx8(this.funct00128a30); + this.dicti2a[1215048u] = new MobUt.Tx8(this.funct00128a48); + this.dicti2a[1215076u] = new MobUt.Tx8(this.funct00128a64); + this.dicti2a[1215092u] = new MobUt.Tx8(this.funct00128a74); + this.dicti2a[1215132u] = new MobUt.Tx8(this.funct00128a9c); + this.dicti2a[1215168u] = new MobUt.Tx8(this.funct00128ac0); + this.dicti2a[1215204u] = new MobUt.Tx8(this.funct00128ae4); + this.dicti2a[1215220u] = new MobUt.Tx8(this.funct00128af4); + this.dicti2a[1215244u] = new MobUt.Tx8(this.funct00128b0c); + this.dicti2a[1215264u] = new MobUt.Tx8(this.funct00128b20); + this.dicti2a[1215276u] = new MobUt.Tx8(this.funct00128b2c); + this.dicti2a[1215376u] = new MobUt.Tx8(this.funct00128b90); + this.dicti2a[1215420u] = new MobUt.Tx8(this.funct00128bbc); + this.dicti2a[1215520u] = new MobUt.Tx8(this.funct00128c20); + this.dicti2a[1215608u] = new MobUt.Tx8(this.funct00128c78); + this.dicti2a[1215628u] = new MobUt.Tx8(this.funct00128c8c); + this.dicti2a[1215648u] = new MobUt.Tx8(this.funct00128ca0); + this.dicti2a[1215656u] = new MobUt.Tx8(this.funct00128ca8); + this.dicti2a[1215692u] = new MobUt.Tx8(this.funct00128ccc); + this.dicti2a[1215700u] = new MobUt.Tx8(this.funct00128cd4); + this.dicti2a[1215780u] = new MobUt.Tx8(this.funct00128d24); + this.dicti2a[1215788u] = new MobUt.Tx8(this.funct00128d2c); + this.dicti2a[1215796u] = new MobUt.Tx8(this.funct00128d34); + this.dicti2a[1215804u] = new MobUt.Tx8(this.funct00128d3c); + this.dicti2a[1215852u] = new MobUt.Tx8(this.funct00128d6c); + this.dicti2a[1215868u] = new MobUt.Tx8(this.funct00128d7c); + this.dicti2a[1215884u] = new MobUt.Tx8(this.funct00128d8c); + this.dicti2a[1215900u] = new MobUt.Tx8(this.funct00128d9c); + this.dicti2a[1215920u] = new MobUt.Tx8(this.funct00128db0); + this.dicti2a[1215928u] = new MobUt.Tx8(this.funct00128db8); + this.dicti2a[1215944u] = new MobUt.Tx8(this.funct00128dc8); + this.dicti2a[1215960u] = new MobUt.Tx8(this.funct00128dd8); + this.dicti2a[1215976u] = new MobUt.Tx8(this.funct00128de8); + this.dicti2a[1216032u] = new MobUt.Tx8(this.funct00128e20); + this.dicti2a[1216044u] = new MobUt.Tx8(this.funct00128e2c); + this.dicti2a[1216064u] = new MobUt.Tx8(this.funct00128e40); + this.dicti2a[1216136u] = new MobUt.Tx8(this.funct00128e88); + this.dicti2a[1216176u] = new MobUt.Tx8(this.funct00128eb0); + this.dicti2a[1216232u] = new MobUt.Tx8(this.funct00128ee8); + this.dicti2a[1216236u] = new MobUt.Tx8(this.funct00128eec); + this.dicti2a[1216356u] = new MobUt.Tx8(this.funct00128f64); + this.dicti2a[1216364u] = new MobUt.Tx8(this.funct00128f6c); + this.dicti2a[1216372u] = new MobUt.Tx8(this.funct00128f74); + this.dicti2a[1216384u] = new MobUt.Tx8(this.funct00128f80); + this.dicti2a[1216588u] = new MobUt.Tx8(this.funct0012904c); + this.dicti2a[1216596u] = new MobUt.Tx8(this.funct00129054); + this.dicti2a[1216616u] = new MobUt.Tx8(this.funct00129068); + this.dicti2a[1216628u] = new MobUt.Tx8(this.funct00129074); + this.dicti2a[1216636u] = new MobUt.Tx8(this.funct0012907c); + this.dicti2a[1216644u] = new MobUt.Tx8(this.funct00129084); + this.dicti2a[1216652u] = new MobUt.Tx8(this.funct0012908c); + this.dicti2a[1216672u] = new MobUt.Tx8(this.funct001290a0); + this.dicti2a[1216792u] = new MobUt.Tx8(this.funct00129118); + this.dicti2a[1216812u] = new MobUt.Tx8(this.funct0012912c); + this.dicti2a[1216836u] = new MobUt.Tx8(this.funct00129144); + this.dicti2a[1216852u] = new MobUt.Tx8(this.funct00129154); + this.dicti2a[1216884u] = new MobUt.Tx8(this.funct00129174); + this.dicti2a[1216892u] = new MobUt.Tx8(this.funct0012917c); + this.dicti2a[1216900u] = new MobUt.Tx8(this.funct00129184); + this.dicti2a[1217148u] = new MobUt.Tx8(this.funct0012927c); + this.dicti2a[1217156u] = new MobUt.Tx8(this.funct00129284); + this.dicti2a[1217176u] = new MobUt.Tx8(this.funct00129298); + this.dicti2a[1217184u] = new MobUt.Tx8(this.funct001292a0); + this.dicti2a[1217192u] = new MobUt.Tx8(this.funct001292a8); + this.dicti2a[1217212u] = new MobUt.Tx8(this.funct001292bc); + this.dicti2a[1217220u] = new MobUt.Tx8(this.funct001292c4); + this.dicti2a[1217228u] = new MobUt.Tx8(this.funct001292cc); + this.dicti2a[1217248u] = new MobUt.Tx8(this.funct001292e0); + this.dicti2a[1217256u] = new MobUt.Tx8(this.funct001292e8); + this.dicti2a[1217264u] = new MobUt.Tx8(this.funct001292f0); + this.dicti2a[1217284u] = new MobUt.Tx8(this.funct00129304); + this.dicti2a[1217392u] = new MobUt.Tx8(this.funct00129370); + this.dicti2a[1217408u] = new MobUt.Tx8(this.funct00129380); + this.dicti2a[1217416u] = new MobUt.Tx8(this.funct00129388); + this.dicti2a[1217424u] = new MobUt.Tx8(this.funct00129390); + this.dicti2a[1217444u] = new MobUt.Tx8(this.funct001293a4); + this.dicti2a[1217488u] = new MobUt.Tx8(this.funct001293d0); + this.dicti2a[1217496u] = new MobUt.Tx8(this.funct001293d8); + this.dicti2a[1217516u] = new MobUt.Tx8(this.funct001293ec); + this.dicti2a[1217692u] = new MobUt.Tx8(this.funct0012949c); + this.dicti2a[1217704u] = new MobUt.Tx8(this.funct001294a8); + this.dicti2a[1217712u] = new MobUt.Tx8(this.funct001294b0); + this.dicti2a[1217748u] = new MobUt.Tx8(this.funct001294d4); + this.dicti2a[1217752u] = new MobUt.Tx8(this.funct001294d8); + this.dicti2a[1217784u] = new MobUt.Tx8(this.funct001294f8); + this.dicti2a[1217796u] = new MobUt.Tx8(this.funct00129504); + this.dicti2a[1217812u] = new MobUt.Tx8(this.funct00129514); + this.dicti2a[1217820u] = new MobUt.Tx8(this.funct0012951c); + this.dicti2a[1217920u] = new MobUt.Tx8(this.funct00129580); + this.dicti2a[1217964u] = new MobUt.Tx8(this.funct001295ac); + this.dicti2a[1217980u] = new MobUt.Tx8(this.funct001295bc); + this.dicti2a[1217988u] = new MobUt.Tx8(this.funct001295c4); + this.dicti2a[1218016u] = new MobUt.Tx8(this.funct001295e0); + this.dicti2a[1218044u] = new MobUt.Tx8(this.funct001295fc); + this.dicti2a[1218100u] = new MobUt.Tx8(this.funct00129634); + this.dicti2a[1218120u] = new MobUt.Tx8(this.funct00129648); + this.dicti2a[1218128u] = new MobUt.Tx8(this.funct00129650); + this.dicti2a[1218156u] = new MobUt.Tx8(this.funct0012966c); + this.dicti2a[1218184u] = new MobUt.Tx8(this.funct00129688); + this.dicti2a[1218192u] = new MobUt.Tx8(this.funct00129690); + this.dicti2a[1218244u] = new MobUt.Tx8(this.funct001296c4); + this.dicti2a[1218264u] = new MobUt.Tx8(this.funct001296d8); + this.dicti2a[1218308u] = new MobUt.Tx8(this.funct00129704); + this.dicti2a[1218324u] = new MobUt.Tx8(this.funct00129714); + this.dicti2a[1219096u] = new MobUt.Tx8(this.funct00129a18); + this.dicti2a[1219268u] = new MobUt.Tx8(this.funct00129ac4); + this.dicti2a[1219288u] = new MobUt.Tx8(this.funct00129ad8); + this.dicti2a[1219320u] = new MobUt.Tx8(this.funct00129af8); + this.dicti2a[1219340u] = new MobUt.Tx8(this.funct00129b0c); + this.dicti2a[1219344u] = new MobUt.Tx8(this.funct00129b10); + this.dicti2a[1219360u] = new MobUt.Tx8(this.funct00129b20); + this.dicti2a[1219380u] = new MobUt.Tx8(this.funct00129b34); + this.dicti2a[1219384u] = new MobUt.Tx8(this.funct00129b38); + this.dicti2a[1219396u] = new MobUt.Tx8(this.funct00129b44); + this.dicti2a[1219416u] = new MobUt.Tx8(this.funct00129b58); + this.dicti2a[1219444u] = new MobUt.Tx8(this.funct00129b74); + this.dicti2a[1219464u] = new MobUt.Tx8(this.funct00129b88); + this.dicti2a[1219472u] = new MobUt.Tx8(this.funct00129b90); + this.dicti2a[1219476u] = new MobUt.Tx8(this.funct00129b94); + this.dicti2a[1219488u] = new MobUt.Tx8(this.funct00129ba0); + this.dicti2a[1219512u] = new MobUt.Tx8(this.funct00129bb8); + this.dicti2a[1219524u] = new MobUt.Tx8(this.funct00129bc4); + this.dicti2a[1219560u] = new MobUt.Tx8(this.funct00129be8); + this.dicti2a[1219576u] = new MobUt.Tx8(this.funct00129bf8); + this.dicti2a[1219580u] = new MobUt.Tx8(this.funct00129bfc); + this.dicti2a[1219588u] = new MobUt.Tx8(this.funct00129c04); + this.dicti2a[1219604u] = new MobUt.Tx8(this.funct00129c14); + this.dicti2a[1219628u] = new MobUt.Tx8(this.funct00129c2c); + this.dicti2a[1219640u] = new MobUt.Tx8(this.funct00129c38); + this.dicti2a[1219644u] = new MobUt.Tx8(this.funct00129c3c); + this.dicti2a[1219660u] = new MobUt.Tx8(this.funct00129c4c); + this.dicti2a[1219672u] = new MobUt.Tx8(this.funct00129c58); + this.dicti2a[1219676u] = new MobUt.Tx8(this.funct00129c5c); + this.dicti2a[1219688u] = new MobUt.Tx8(this.funct00129c68); + this.dicti2a[1219704u] = new MobUt.Tx8(this.funct00129c78); + this.dicti2a[1219716u] = new MobUt.Tx8(this.funct00129c84); + this.dicti2a[1219728u] = new MobUt.Tx8(this.funct00129c90); + this.dicti2a[1219732u] = new MobUt.Tx8(this.funct00129c94); + this.dicti2a[1219740u] = new MobUt.Tx8(this.funct00129c9c); + this.dicti2a[1219752u] = new MobUt.Tx8(this.funct00129ca8); + this.dicti2a[1219764u] = new MobUt.Tx8(this.funct00129cb4); + this.dicti2a[1219788u] = new MobUt.Tx8(this.funct00129ccc); + this.dicti2a[1219800u] = new MobUt.Tx8(this.funct00129cd8); + this.dicti2a[1219812u] = new MobUt.Tx8(this.funct00129ce4); + this.dicti2a[1219832u] = new MobUt.Tx8(this.funct00129cf8); + this.dicti2a[1219840u] = new MobUt.Tx8(this.funct00129d00); + this.dicti2a[1219868u] = new MobUt.Tx8(this.funct00129d1c); + this.dicti2a[1219892u] = new MobUt.Tx8(this.funct00129d34); + this.dicti2a[1219908u] = new MobUt.Tx8(this.funct00129d44); + this.dicti2a[1219916u] = new MobUt.Tx8(this.funct00129d4c); + this.dicti2a[1219976u] = new MobUt.Tx8(this.funct00129d88); + this.dicti2a[1219984u] = new MobUt.Tx8(this.funct00129d90); + this.dicti2a[1220040u] = new MobUt.Tx8(this.funct00129dc8); + this.dicti2a[1220048u] = new MobUt.Tx8(this.funct00129dd0); + this.dicti2a[1220088u] = new MobUt.Tx8(this.funct00129df8); + this.dicti2a[1220100u] = new MobUt.Tx8(this.funct00129e04); + this.dicti2a[1220112u] = new MobUt.Tx8(this.funct00129e10); + this.dicti2a[1220140u] = new MobUt.Tx8(this.funct00129e2c); + this.dicti2a[1220156u] = new MobUt.Tx8(this.funct00129e3c); + this.dicti2a[1220160u] = new MobUt.Tx8(this.funct00129e40); + this.dicti2a[1220180u] = new MobUt.Tx8(this.funct00129e54); + this.dicti2a[1220188u] = new MobUt.Tx8(this.funct00129e5c); + this.dicti2a[1220192u] = new MobUt.Tx8(this.funct00129e60); + this.dicti2a[1221784u] = new MobUt.Tx8(this.funct0012a498); + this.dicti2a[1221820u] = new MobUt.Tx8(this.funct0012a4bc); + this.dicti2a[1221824u] = new MobUt.Tx8(this.funct0012a4c0); + this.dicti2a[1223092u] = new MobUt.Tx8(this.funct0012a9b4); + this.dicti2a[1223100u] = new MobUt.Tx8(this.funct0012a9bc); + this.dicti2a[1223120u] = new MobUt.Tx8(this.funct0012a9d0); + this.dicti2a[1223156u] = new MobUt.Tx8(this.funct0012a9f4); + this.dicti2a[1223164u] = new MobUt.Tx8(this.funct0012a9fc); + this.dicti2a[1223172u] = new MobUt.Tx8(this.funct0012aa04); + this.dicti2a[1223196u] = new MobUt.Tx8(this.funct0012aa1c); + this.dicti2a[1223216u] = new MobUt.Tx8(this.funct0012aa30); + this.dicti2a[1223224u] = new MobUt.Tx8(this.funct0012aa38); + this.dicti2a[1223232u] = new MobUt.Tx8(this.funct0012aa40); + this.dicti2a[1223280u] = new MobUt.Tx8(this.funct0012aa70); + this.dicti2a[1223292u] = new MobUt.Tx8(this.funct0012aa7c); + this.dicti2a[1223348u] = new MobUt.Tx8(this.funct0012aab4); + this.dicti2a[1223380u] = new MobUt.Tx8(this.funct0012aad4); + this.dicti2a[1223560u] = new MobUt.Tx8(this.funct0012ab88); + this.dicti2a[1223580u] = new MobUt.Tx8(this.funct0012ab9c); + this.dicti2a[1223624u] = new MobUt.Tx8(this.funct0012abc8); + this.dicti2a[1223628u] = new MobUt.Tx8(this.funct0012abcc); + this.dicti2a[1223652u] = new MobUt.Tx8(this.funct0012abe4); + this.dicti2a[1223664u] = new MobUt.Tx8(this.funct0012abf0); + this.dicti2a[1223692u] = new MobUt.Tx8(this.funct0012ac0c); + this.dicti2a[1223728u] = new MobUt.Tx8(this.funct0012ac30); + this.dicti2a[1223740u] = new MobUt.Tx8(this.funct0012ac3c); + this.dicti2a[1223768u] = new MobUt.Tx8(this.funct0012ac58); + this.dicti2a[1223784u] = new MobUt.Tx8(this.funct0012ac68); + this.dicti2a[1223796u] = new MobUt.Tx8(this.funct0012ac74); + this.dicti2a[1223824u] = new MobUt.Tx8(this.funct0012ac90); + this.dicti2a[1223840u] = new MobUt.Tx8(this.funct0012aca0); + this.dicti2a[1223848u] = new MobUt.Tx8(this.funct0012aca8); + this.dicti2a[1223864u] = new MobUt.Tx8(this.funct0012acb8); + this.dicti2a[1223892u] = new MobUt.Tx8(this.funct0012acd4); + this.dicti2a[1223896u] = new MobUt.Tx8(this.funct0012acd8); + this.dicti2a[1223904u] = new MobUt.Tx8(this.funct0012ace0); + this.dicti2a[1223964u] = new MobUt.Tx8(this.funct0012ad1c); + this.dicti2a[1223992u] = new MobUt.Tx8(this.funct0012ad38); + this.dicti2a[1224032u] = new MobUt.Tx8(this.funct0012ad60); + this.dicti2a[1224052u] = new MobUt.Tx8(this.funct0012ad74); + this.dicti2a[1224192u] = new MobUt.Tx8(this.funct0012ae00); + this.dicti2a[1224204u] = new MobUt.Tx8(this.funct0012ae0c); + this.dicti2a[1224576u] = new MobUt.Tx8(this.funct0012af80); + this.dicti2a[1224960u] = new MobUt.Tx8(this.funct0012b100); + this.dicti2a[1224968u] = new MobUt.Tx8(this.funct0012b108); + this.dicti2a[1225048u] = new MobUt.Tx8(this.funct0012b158); + this.dicti2a[1225064u] = new MobUt.Tx8(this.funct0012b168); + this.dicti2a[1225072u] = new MobUt.Tx8(this.funct0012b170); + this.dicti2a[1225112u] = new MobUt.Tx8(this.funct0012b198); + this.dicti2a[1225120u] = new MobUt.Tx8(this.funct0012b1a0); + this.dicti2a[1225244u] = new MobUt.Tx8(this.funct0012b21c); + this.dicti2a[1225296u] = new MobUt.Tx8(this.funct0012b250); + this.dicti2a[1225304u] = new MobUt.Tx8(this.funct0012b258); + this.dicti2a[1225320u] = new MobUt.Tx8(this.funct0012b268); + this.dicti2a[1225372u] = new MobUt.Tx8(this.funct0012b29c); + this.dicti2a[1225380u] = new MobUt.Tx8(this.funct0012b2a4); + this.dicti2a[1225448u] = new MobUt.Tx8(this.funct0012b2e8); + this.dicti2a[1225456u] = new MobUt.Tx8(this.funct0012b2f0); + this.dicti2a[1225472u] = new MobUt.Tx8(this.funct0012b300); + this.dicti2a[1225500u] = new MobUt.Tx8(this.funct0012b31c); + this.dicti2a[1225508u] = new MobUt.Tx8(this.funct0012b324); + this.dicti2a[1225528u] = new MobUt.Tx8(this.funct0012b338); + this.dicti2a[1225548u] = new MobUt.Tx8(this.funct0012b34c); + this.dicti2a[1225552u] = new MobUt.Tx8(this.funct0012b350); + this.dicti2a[1225588u] = new MobUt.Tx8(this.funct0012b374); + this.dicti2a[1225596u] = new MobUt.Tx8(this.funct0012b37c); + this.dicti2a[1225724u] = new MobUt.Tx8(this.funct0012b3fc); + this.dicti2a[1225780u] = new MobUt.Tx8(this.funct0012b434); + this.dicti2a[1225788u] = new MobUt.Tx8(this.funct0012b43c); + this.dicti2a[1225812u] = new MobUt.Tx8(this.funct0012b454); + this.dicti2a[1225864u] = new MobUt.Tx8(this.funct0012b488); + this.dicti2a[1225872u] = new MobUt.Tx8(this.funct0012b490); + this.dicti2a[1225948u] = new MobUt.Tx8(this.funct0012b4dc); + this.dicti2a[1225956u] = new MobUt.Tx8(this.funct0012b4e4); + this.dicti2a[1225976u] = new MobUt.Tx8(this.funct0012b4f8); + this.dicti2a[1225984u] = new MobUt.Tx8(this.funct0012b500); + this.dicti2a[1226000u] = new MobUt.Tx8(this.funct0012b510); + this.dicti2a[1226008u] = new MobUt.Tx8(this.funct0012b518); + this.dicti2a[1226092u] = new MobUt.Tx8(this.funct0012b56c); + this.dicti2a[1226100u] = new MobUt.Tx8(this.funct0012b574); + this.dicti2a[1226124u] = new MobUt.Tx8(this.funct0012b58c); + this.dicti2a[1226132u] = new MobUt.Tx8(this.funct0012b594); + this.dicti2a[1226156u] = new MobUt.Tx8(this.funct0012b5ac); + this.dicti2a[1226164u] = new MobUt.Tx8(this.funct0012b5b4); + this.dicti2a[1226216u] = new MobUt.Tx8(this.funct0012b5e8); + this.dicti2a[1226244u] = new MobUt.Tx8(this.funct0012b604); + this.dicti2a[1226256u] = new MobUt.Tx8(this.funct0012b610); + this.dicti2a[1226272u] = new MobUt.Tx8(this.funct0012b620); + this.dicti2a[1226284u] = new MobUt.Tx8(this.funct0012b62c); + this.dicti2a[1226304u] = new MobUt.Tx8(this.funct0012b640); + this.dicti2a[1226316u] = new MobUt.Tx8(this.funct0012b64c); + this.dicti2a[1226328u] = new MobUt.Tx8(this.funct0012b658); + this.dicti2a[1226340u] = new MobUt.Tx8(this.funct0012b664); + this.dicti2a[1226356u] = new MobUt.Tx8(this.funct0012b674); + this.dicti2a[1226380u] = new MobUt.Tx8(this.funct0012b68c); + this.dicti2a[1226392u] = new MobUt.Tx8(this.funct0012b698); + this.dicti2a[1226408u] = new MobUt.Tx8(this.funct0012b6a8); + this.dicti2a[1226424u] = new MobUt.Tx8(this.funct0012b6b8); + this.dicti2a[1226440u] = new MobUt.Tx8(this.funct0012b6c8); + this.dicti2a[1226460u] = new MobUt.Tx8(this.funct0012b6dc); + this.dicti2a[1226664u] = new MobUt.Tx8(this.funct0012b7a8); + this.dicti2a[1226692u] = new MobUt.Tx8(this.funct0012b7c4); + this.dicti2a[1226712u] = new MobUt.Tx8(this.funct0012b7d8); + this.dicti2a[1226724u] = new MobUt.Tx8(this.funct0012b7e4); + this.dicti2a[1226764u] = new MobUt.Tx8(this.funct0012b80c); + this.dicti2a[1226784u] = new MobUt.Tx8(this.funct0012b820); + this.dicti2a[1226796u] = new MobUt.Tx8(this.funct0012b82c); + this.dicti2a[1226824u] = new MobUt.Tx8(this.funct0012b848); + this.dicti2a[1226832u] = new MobUt.Tx8(this.funct0012b850); + this.dicti2a[1226848u] = new MobUt.Tx8(this.funct0012b860); + this.dicti2a[1226856u] = new MobUt.Tx8(this.funct0012b868); + this.dicti2a[1226876u] = new MobUt.Tx8(this.funct0012b87c); + this.dicti2a[1226884u] = new MobUt.Tx8(this.funct0012b884); + this.dicti2a[1226900u] = new MobUt.Tx8(this.funct0012b894); + this.dicti2a[1226908u] = new MobUt.Tx8(this.funct0012b89c); + this.dicti2a[1226948u] = new MobUt.Tx8(this.funct0012b8c4); + this.dicti2a[1226976u] = new MobUt.Tx8(this.funct0012b8e0); + this.dicti2a[1227000u] = new MobUt.Tx8(this.funct0012b8f8); + this.dicti2a[1227012u] = new MobUt.Tx8(this.funct0012b904); + this.dicti2a[1227032u] = new MobUt.Tx8(this.funct0012b918); + this.dicti2a[1227056u] = new MobUt.Tx8(this.funct0012b930); + this.dicti2a[1227132u] = new MobUt.Tx8(this.funct0012b97c); + this.dicti2a[1227148u] = new MobUt.Tx8(this.funct0012b98c); + this.dicti2a[1227160u] = new MobUt.Tx8(this.funct0012b998); + this.dicti2a[1227184u] = new MobUt.Tx8(this.funct0012b9b0); + this.dicti2a[1227192u] = new MobUt.Tx8(this.funct0012b9b8); + this.dicti2a[1227220u] = new MobUt.Tx8(this.funct0012b9d4); + this.dicti2a[1227244u] = new MobUt.Tx8(this.funct0012b9ec); + this.dicti2a[1227272u] = new MobUt.Tx8(this.funct0012ba08); + this.dicti2a[1227284u] = new MobUt.Tx8(this.funct0012ba14); + this.dicti2a[1227292u] = new MobUt.Tx8(this.funct0012ba1c); + this.dicti2a[1227300u] = new MobUt.Tx8(this.funct0012ba24); + this.dicti2a[1227312u] = new MobUt.Tx8(this.funct0012ba30); + this.dicti2a[1227320u] = new MobUt.Tx8(this.funct0012ba38); + this.dicti2a[1227328u] = new MobUt.Tx8(this.funct0012ba40); + this.dicti2a[1227336u] = new MobUt.Tx8(this.funct0012ba48); + this.dicti2a[1227348u] = new MobUt.Tx8(this.funct0012ba54); + this.dicti2a[1227380u] = new MobUt.Tx8(this.funct0012ba74); + this.dicti2a[1227572u] = new MobUt.Tx8(this.funct0012bb34); + this.dicti2a[1227584u] = new MobUt.Tx8(this.funct0012bb40); + this.dicti2a[1227604u] = new MobUt.Tx8(this.funct0012bb54); + this.dicti2a[1227616u] = new MobUt.Tx8(this.funct0012bb60); + this.dicti2a[1227628u] = new MobUt.Tx8(this.funct0012bb6c); + this.dicti2a[1227712u] = new MobUt.Tx8(this.funct0012bbc0); + this.dicti2a[1227724u] = new MobUt.Tx8(this.funct0012bbcc); + this.dicti2a[1227736u] = new MobUt.Tx8(this.funct0012bbd8); + this.dicti2a[1227752u] = new MobUt.Tx8(this.funct0012bbe8); + this.dicti2a[1227760u] = new MobUt.Tx8(this.funct0012bbf0); + this.dicti2a[1227772u] = new MobUt.Tx8(this.funct0012bbfc); + this.dicti2a[1227792u] = new MobUt.Tx8(this.funct0012bc10); + this.dicti2a[1227800u] = new MobUt.Tx8(this.funct0012bc18); + this.dicti2a[1227812u] = new MobUt.Tx8(this.funct0012bc24); + this.dicti2a[1227864u] = new MobUt.Tx8(this.funct0012bc58); + this.dicti2a[1227872u] = new MobUt.Tx8(this.funct0012bc60); + this.dicti2a[1227940u] = new MobUt.Tx8(this.funct0012bca4); + this.dicti2a[1227948u] = new MobUt.Tx8(this.funct0012bcac); + this.dicti2a[1227964u] = new MobUt.Tx8(this.funct0012bcbc); + this.dicti2a[1227984u] = new MobUt.Tx8(this.funct0012bcd0); + this.dicti2a[1228000u] = new MobUt.Tx8(this.funct0012bce0); + this.dicti2a[1228008u] = new MobUt.Tx8(this.funct0012bce8); + this.dicti2a[1228020u] = new MobUt.Tx8(this.funct0012bcf4); + this.dicti2a[1228052u] = new MobUt.Tx8(this.funct0012bd14); + this.dicti2a[1228164u] = new MobUt.Tx8(this.funct0012bd84); + this.dicti2a[1228172u] = new MobUt.Tx8(this.funct0012bd8c); + this.dicti2a[1228304u] = new MobUt.Tx8(this.funct0012be10); + this.dicti2a[1228356u] = new MobUt.Tx8(this.funct0012be44); + this.dicti2a[1228364u] = new MobUt.Tx8(this.funct0012be4c); + this.dicti2a[1228380u] = new MobUt.Tx8(this.funct0012be5c); + this.dicti2a[1228404u] = new MobUt.Tx8(this.funct0012be74); + this.dicti2a[1228424u] = new MobUt.Tx8(this.funct0012be88); + this.dicti2a[1228432u] = new MobUt.Tx8(this.funct0012be90); + this.dicti2a[1228448u] = new MobUt.Tx8(this.funct0012bea0); + this.dicti2a[1228456u] = new MobUt.Tx8(this.funct0012bea8); + this.dicti2a[1228472u] = new MobUt.Tx8(this.funct0012beb8); + this.dicti2a[1228488u] = new MobUt.Tx8(this.funct0012bec8); + this.dicti2a[1228504u] = new MobUt.Tx8(this.funct0012bed8); + this.dicti2a[1228528u] = new MobUt.Tx8(this.funct0012bef0); + this.dicti2a[1228568u] = new MobUt.Tx8(this.funct0012bf18); + this.dicti2a[1228584u] = new MobUt.Tx8(this.funct0012bf28); + this.dicti2a[1228600u] = new MobUt.Tx8(this.funct0012bf38); + this.dicti2a[1228616u] = new MobUt.Tx8(this.funct0012bf48); + this.dicti2a[1228644u] = new MobUt.Tx8(this.funct0012bf64); + this.dicti2a[1228684u] = new MobUt.Tx8(this.funct0012bf8c); + this.dicti2a[1228696u] = new MobUt.Tx8(this.funct0012bf98); + this.dicti2a[1228712u] = new MobUt.Tx8(this.funct0012bfa8); + this.dicti2a[1228752u] = new MobUt.Tx8(this.funct0012bfd0); + this.dicti2a[1228812u] = new MobUt.Tx8(this.funct0012c00c); + this.dicti2a[1228856u] = new MobUt.Tx8(this.funct0012c038); + this.dicti2a[1228908u] = new MobUt.Tx8(this.funct0012c06c); + this.dicti2a[1228916u] = new MobUt.Tx8(this.funct0012c074); + this.dicti2a[1228924u] = new MobUt.Tx8(this.funct0012c07c); + this.dicti2a[1228932u] = new MobUt.Tx8(this.funct0012c084); + this.dicti2a[1228952u] = new MobUt.Tx8(this.funct0012c098); + this.dicti2a[1228960u] = new MobUt.Tx8(this.funct0012c0a0); + this.dicti2a[1228972u] = new MobUt.Tx8(this.funct0012c0ac); + this.dicti2a[1228992u] = new MobUt.Tx8(this.funct0012c0c0); + this.dicti2a[1229000u] = new MobUt.Tx8(this.funct0012c0c8); + this.dicti2a[1229016u] = new MobUt.Tx8(this.funct0012c0d8); + this.dicti2a[1229024u] = new MobUt.Tx8(this.funct0012c0e0); + this.dicti2a[1229152u] = new MobUt.Tx8(this.funct0012c160); + this.dicti2a[1229204u] = new MobUt.Tx8(this.funct0012c194); + this.dicti2a[1229212u] = new MobUt.Tx8(this.funct0012c19c); + this.dicti2a[1229228u] = new MobUt.Tx8(this.funct0012c1ac); + this.dicti2a[1229464u] = new MobUt.Tx8(this.funct0012c298); + this.dicti2a[1229492u] = new MobUt.Tx8(this.funct0012c2b4); + this.dicti2a[1229500u] = new MobUt.Tx8(this.funct0012c2bc); + this.dicti2a[1229620u] = new MobUt.Tx8(this.funct0012c334); + this.dicti2a[1229660u] = new MobUt.Tx8(this.funct0012c35c); + this.dicti2a[1229680u] = new MobUt.Tx8(this.funct0012c370); + this.dicti2a[1229696u] = new MobUt.Tx8(this.funct0012c380); + this.dicti2a[1229712u] = new MobUt.Tx8(this.funct0012c390); + this.dicti2a[1229732u] = new MobUt.Tx8(this.funct0012c3a4); + this.dicti2a[1229756u] = new MobUt.Tx8(this.funct0012c3bc); + this.dicti2a[1229772u] = new MobUt.Tx8(this.funct0012c3cc); + this.dicti2a[1229796u] = new MobUt.Tx8(this.funct0012c3e4); + this.dicti2a[1229816u] = new MobUt.Tx8(this.funct0012c3f8); + this.dicti2a[1229824u] = new MobUt.Tx8(this.funct0012c400); + this.dicti2a[1229832u] = new MobUt.Tx8(this.funct0012c408); + this.dicti2a[1229844u] = new MobUt.Tx8(this.funct0012c414); + this.dicti2a[1229864u] = new MobUt.Tx8(this.funct0012c428); + this.dicti2a[1229872u] = new MobUt.Tx8(this.funct0012c430); + this.dicti2a[1229900u] = new MobUt.Tx8(this.funct0012c44c); + this.dicti2a[1229908u] = new MobUt.Tx8(this.funct0012c454); + this.dicti2a[1229924u] = new MobUt.Tx8(this.funct0012c464); + this.dicti2a[1229928u] = new MobUt.Tx8(this.funct0012c468); + this.dicti2a[1229948u] = new MobUt.Tx8(this.funct0012c47c); + this.dicti2a[1229956u] = new MobUt.Tx8(this.funct0012c484); + this.dicti2a[1229972u] = new MobUt.Tx8(this.funct0012c494); + this.dicti2a[1229980u] = new MobUt.Tx8(this.funct0012c49c); + this.dicti2a[1229988u] = new MobUt.Tx8(this.funct0012c4a4); + this.dicti2a[1230008u] = new MobUt.Tx8(this.funct0012c4b8); + this.dicti2a[1230016u] = new MobUt.Tx8(this.funct0012c4c0); + this.dicti2a[1230032u] = new MobUt.Tx8(this.funct0012c4d0); + this.dicti2a[1230056u] = new MobUt.Tx8(this.funct0012c4e8); + this.dicti2a[1230068u] = new MobUt.Tx8(this.funct0012c4f4); + this.dicti2a[1230092u] = new MobUt.Tx8(this.funct0012c50c); + this.dicti2a[1230100u] = new MobUt.Tx8(this.funct0012c514); + this.dicti2a[1230220u] = new MobUt.Tx8(this.funct0012c58c); + this.dicti2a[1230260u] = new MobUt.Tx8(this.funct0012c5b4); + this.dicti2a[1230280u] = new MobUt.Tx8(this.funct0012c5c8); + this.dicti2a[1230308u] = new MobUt.Tx8(this.funct0012c5e4); + this.dicti2a[1230316u] = new MobUt.Tx8(this.funct0012c5ec); + this.dicti2a[1230436u] = new MobUt.Tx8(this.funct0012c664); + this.dicti2a[1230476u] = new MobUt.Tx8(this.funct0012c68c); + this.dicti2a[1230496u] = new MobUt.Tx8(this.funct0012c6a0); + this.dicti2a[1230516u] = new MobUt.Tx8(this.funct0012c6b4); + this.dicti2a[1230540u] = new MobUt.Tx8(this.funct0012c6cc); + this.dicti2a[1230556u] = new MobUt.Tx8(this.funct0012c6dc); + this.dicti2a[1230580u] = new MobUt.Tx8(this.funct0012c6f4); + this.dicti2a[1230608u] = new MobUt.Tx8(this.funct0012c710); + this.dicti2a[1230624u] = new MobUt.Tx8(this.funct0012c720); + this.dicti2a[1230648u] = new MobUt.Tx8(this.funct0012c738); + this.dicti2a[1230656u] = new MobUt.Tx8(this.funct0012c740); + this.dicti2a[1230668u] = new MobUt.Tx8(this.funct0012c74c); + this.dicti2a[1230700u] = new MobUt.Tx8(this.funct0012c76c); + this.dicti2a[1230736u] = new MobUt.Tx8(this.funct0012c790); + this.dicti2a[1230764u] = new MobUt.Tx8(this.funct0012c7ac); + this.dicti2a[1230852u] = new MobUt.Tx8(this.funct0012c804); + this.dicti2a[1230904u] = new MobUt.Tx8(this.funct0012c838); + this.dicti2a[1230912u] = new MobUt.Tx8(this.funct0012c840); + this.dicti2a[1230920u] = new MobUt.Tx8(this.funct0012c848); + this.dicti2a[1230936u] = new MobUt.Tx8(this.funct0012c858); + this.dicti2a[1230944u] = new MobUt.Tx8(this.funct0012c860); + this.dicti2a[1230976u] = new MobUt.Tx8(this.funct0012c880); + this.dicti2a[1231028u] = new MobUt.Tx8(this.funct0012c8b4); + this.dicti2a[1231044u] = new MobUt.Tx8(this.funct0012c8c4); + this.dicti2a[1231056u] = new MobUt.Tx8(this.funct0012c8d0); + this.dicti2a[1231072u] = new MobUt.Tx8(this.funct0012c8e0); + this.dicti2a[1231080u] = new MobUt.Tx8(this.funct0012c8e8); + this.dicti2a[1231088u] = new MobUt.Tx8(this.funct0012c8f0); + this.dicti2a[1231116u] = new MobUt.Tx8(this.funct0012c90c); + this.dicti2a[1231144u] = new MobUt.Tx8(this.funct0012c928); + this.dicti2a[1231228u] = new MobUt.Tx8(this.funct0012c97c); + this.dicti2a[1231232u] = new MobUt.Tx8(this.funct0012c980); + this.dicti2a[1231244u] = new MobUt.Tx8(this.funct0012c98c); + this.dicti2a[1231296u] = new MobUt.Tx8(this.funct0012c9c0); + this.dicti2a[1231308u] = new MobUt.Tx8(this.funct0012c9cc); + this.dicti2a[1231324u] = new MobUt.Tx8(this.funct0012c9dc); + this.dicti2a[1231344u] = new MobUt.Tx8(this.funct0012c9f0); + this.dicti2a[1231352u] = new MobUt.Tx8(this.funct0012c9f8); + this.dicti2a[1231404u] = new MobUt.Tx8(this.funct0012ca2c); + this.dicti2a[1231420u] = new MobUt.Tx8(this.funct0012ca3c); + this.dicti2a[1231440u] = new MobUt.Tx8(this.funct0012ca50); + this.dicti2a[1231456u] = new MobUt.Tx8(this.funct0012ca60); + this.dicti2a[1231464u] = new MobUt.Tx8(this.funct0012ca68); + this.dicti2a[1231496u] = new MobUt.Tx8(this.funct0012ca88); + this.dicti2a[1231520u] = new MobUt.Tx8(this.funct0012caa0); + this.dicti2a[1231528u] = new MobUt.Tx8(this.funct0012caa8); + this.dicti2a[1231540u] = new MobUt.Tx8(this.funct0012cab4); + this.dicti2a[1231580u] = new MobUt.Tx8(this.funct0012cadc); + this.dicti2a[1231600u] = new MobUt.Tx8(this.funct0012caf0); + this.dicti2a[1231620u] = new MobUt.Tx8(this.funct0012cb04); + this.dicti2a[1231628u] = new MobUt.Tx8(this.funct0012cb0c); + this.dicti2a[1231636u] = new MobUt.Tx8(this.funct0012cb14); + this.dicti2a[1231684u] = new MobUt.Tx8(this.funct0012cb44); + this.dicti2a[1231696u] = new MobUt.Tx8(this.funct0012cb50); + this.dicti2a[1231756u] = new MobUt.Tx8(this.funct0012cb8c); + this.dicti2a[1231788u] = new MobUt.Tx8(this.funct0012cbac); + this.dicti2a[1231968u] = new MobUt.Tx8(this.funct0012cc60); + this.dicti2a[1232004u] = new MobUt.Tx8(this.funct0012cc84); + this.dicti2a[1232016u] = new MobUt.Tx8(this.funct0012cc90); + this.dicti2a[1232028u] = new MobUt.Tx8(this.funct0012cc9c); + this.dicti2a[1232064u] = new MobUt.Tx8(this.funct0012ccc0); + this.dicti2a[1232144u] = new MobUt.Tx8(this.funct0012cd10); + this.dicti2a[1232164u] = new MobUt.Tx8(this.funct0012cd24); + this.dicti2a[1232172u] = new MobUt.Tx8(this.funct0012cd2c); + this.dicti2a[1232200u] = new MobUt.Tx8(this.funct0012cd48); + this.dicti2a[1232208u] = new MobUt.Tx8(this.funct0012cd50); + this.dicti2a[1232224u] = new MobUt.Tx8(this.funct0012cd60); + this.dicti2a[1232232u] = new MobUt.Tx8(this.funct0012cd68); + this.dicti2a[1232260u] = new MobUt.Tx8(this.funct0012cd84); + this.dicti2a[1232268u] = new MobUt.Tx8(this.funct0012cd8c); + this.dicti2a[1232284u] = new MobUt.Tx8(this.funct0012cd9c); + this.dicti2a[1232304u] = new MobUt.Tx8(this.funct0012cdb0); + this.dicti2a[1232328u] = new MobUt.Tx8(this.funct0012cdc8); + this.dicti2a[1232344u] = new MobUt.Tx8(this.funct0012cdd8); + this.dicti2a[1232348u] = new MobUt.Tx8(this.funct0012cddc); + this.dicti2a[1232364u] = new MobUt.Tx8(this.funct0012cdec); + this.dicti2a[1232372u] = new MobUt.Tx8(this.funct0012cdf4); + this.dicti2a[1232412u] = new MobUt.Tx8(this.funct0012ce1c); + this.dicti2a[1232420u] = new MobUt.Tx8(this.funct0012ce24); + this.dicti2a[1232544u] = new MobUt.Tx8(this.funct0012cea0); + this.dicti2a[1232596u] = new MobUt.Tx8(this.funct0012ced4); + this.dicti2a[1232604u] = new MobUt.Tx8(this.funct0012cedc); + this.dicti2a[1232620u] = new MobUt.Tx8(this.funct0012ceec); + this.dicti2a[1232672u] = new MobUt.Tx8(this.funct0012cf20); + this.dicti2a[1232680u] = new MobUt.Tx8(this.funct0012cf28); + this.dicti2a[1232748u] = new MobUt.Tx8(this.funct0012cf6c); + this.dicti2a[1232756u] = new MobUt.Tx8(this.funct0012cf74); + this.dicti2a[1232772u] = new MobUt.Tx8(this.funct0012cf84); + this.dicti2a[1232812u] = new MobUt.Tx8(this.funct0012cfac); + this.dicti2a[1232820u] = new MobUt.Tx8(this.funct0012cfb4); + this.dicti2a[1232840u] = new MobUt.Tx8(this.funct0012cfc8); + this.dicti2a[1232848u] = new MobUt.Tx8(this.funct0012cfd0); + this.dicti2a[1232868u] = new MobUt.Tx8(this.funct0012cfe4); + this.dicti2a[1232876u] = new MobUt.Tx8(this.funct0012cfec); + this.dicti2a[1232928u] = new MobUt.Tx8(this.funct0012d020); + this.dicti2a[1232956u] = new MobUt.Tx8(this.funct0012d03c); + this.dicti2a[1232976u] = new MobUt.Tx8(this.funct0012d050); + this.dicti2a[1232988u] = new MobUt.Tx8(this.funct0012d05c); + this.dicti2a[1233004u] = new MobUt.Tx8(this.funct0012d06c); + this.dicti2a[1233020u] = new MobUt.Tx8(this.funct0012d07c); + this.dicti2a[1233036u] = new MobUt.Tx8(this.funct0012d08c); + this.dicti2a[1233056u] = new MobUt.Tx8(this.funct0012d0a0); + this.dicti2a[1233112u] = new MobUt.Tx8(this.funct0012d0d8); + this.dicti2a[1233136u] = new MobUt.Tx8(this.funct0012d0f0); + this.dicti2a[1233156u] = new MobUt.Tx8(this.funct0012d104); + this.dicti2a[1233184u] = new MobUt.Tx8(this.funct0012d120); + this.dicti2a[1233196u] = new MobUt.Tx8(this.funct0012d12c); + this.dicti2a[1233220u] = new MobUt.Tx8(this.funct0012d144); + this.dicti2a[1233240u] = new MobUt.Tx8(this.funct0012d158); + this.dicti2a[1233248u] = new MobUt.Tx8(this.funct0012d160); + this.dicti2a[1233272u] = new MobUt.Tx8(this.funct0012d178); + this.dicti2a[1233280u] = new MobUt.Tx8(this.funct0012d180); + this.dicti2a[1233296u] = new MobUt.Tx8(this.funct0012d190); + this.dicti2a[1233304u] = new MobUt.Tx8(this.funct0012d198); + this.dicti2a[1233336u] = new MobUt.Tx8(this.funct0012d1b8); + this.dicti2a[1233360u] = new MobUt.Tx8(this.funct0012d1d0); + this.dicti2a[1233380u] = new MobUt.Tx8(this.funct0012d1e4); + this.dicti2a[1233408u] = new MobUt.Tx8(this.funct0012d200); + this.dicti2a[1233432u] = new MobUt.Tx8(this.funct0012d218); + this.dicti2a[1233460u] = new MobUt.Tx8(this.funct0012d234); + this.dicti2a[1233484u] = new MobUt.Tx8(this.funct0012d24c); + this.dicti2a[1233508u] = new MobUt.Tx8(this.funct0012d264); + this.dicti2a[1233608u] = new MobUt.Tx8(this.funct0012d2c8); + this.dicti2a[1233616u] = new MobUt.Tx8(this.funct0012d2d0); + this.dicti2a[1233644u] = new MobUt.Tx8(this.funct0012d2ec); + this.dicti2a[1233652u] = new MobUt.Tx8(this.funct0012d2f4); + this.dicti2a[1233680u] = new MobUt.Tx8(this.funct0012d310); + this.dicti2a[1233696u] = new MobUt.Tx8(this.funct0012d320); + this.dicti2a[1233724u] = new MobUt.Tx8(this.funct0012d33c); + this.dicti2a[1233748u] = new MobUt.Tx8(this.funct0012d354); + this.dicti2a[1233756u] = new MobUt.Tx8(this.funct0012d35c); + this.dicti2a[1233764u] = new MobUt.Tx8(this.funct0012d364); + this.dicti2a[1233780u] = new MobUt.Tx8(this.funct0012d374); + this.dicti2a[1233808u] = new MobUt.Tx8(this.funct0012d390); + this.dicti2a[1233820u] = new MobUt.Tx8(this.funct0012d39c); + this.dicti2a[1233844u] = new MobUt.Tx8(this.funct0012d3b4); + this.dicti2a[1233864u] = new MobUt.Tx8(this.funct0012d3c8); + this.dicti2a[1233888u] = new MobUt.Tx8(this.funct0012d3e0); + this.dicti2a[1233896u] = new MobUt.Tx8(this.funct0012d3e8); + this.dicti2a[1233936u] = new MobUt.Tx8(this.funct0012d410); + this.dicti2a[1233976u] = new MobUt.Tx8(this.funct0012d438); + this.dicti2a[1234000u] = new MobUt.Tx8(this.funct0012d450); + this.dicti2a[1234020u] = new MobUt.Tx8(this.funct0012d464); + this.dicti2a[1234028u] = new MobUt.Tx8(this.funct0012d46c); + this.dicti2a[1234068u] = new MobUt.Tx8(this.funct0012d494); + this.dicti2a[1234092u] = new MobUt.Tx8(this.funct0012d4ac); + this.dicti2a[1234112u] = new MobUt.Tx8(this.funct0012d4c0); + this.dicti2a[1234120u] = new MobUt.Tx8(this.funct0012d4c8); + this.dicti2a[1234132u] = new MobUt.Tx8(this.funct0012d4d4); + this.dicti2a[1234156u] = new MobUt.Tx8(this.funct0012d4ec); + this.dicti2a[1234164u] = new MobUt.Tx8(this.funct0012d4f4); + this.dicti2a[1317840u] = new MobUt.Tx8(this.funct00141bd0); + this.dicti2a[1317856u] = new MobUt.Tx8(this.funct00141be0); + this.dicti2a[1317864u] = new MobUt.Tx8(this.funct00141be8); + this.dicti2a[1317940u] = new MobUt.Tx8(this.funct00141c34); + this.dicti2a[1318520u] = new MobUt.Tx8(this.funct00141e78); + this.dicti2a[1318552u] = new MobUt.Tx8(this.funct00141e98); + this.dicti2a[1318636u] = new MobUt.Tx8(this.funct00141eec); + this.dicti2a[1318644u] = new MobUt.Tx8(this.funct00141ef4); + this.dicti2a[1318664u] = new MobUt.Tx8(this.funct00141f08); + this.dicti2a[1318668u] = new MobUt.Tx8(this.funct00141f0c); + this.dicti2a[1318688u] = new MobUt.Tx8(this.funct00141f20); + this.dicti2a[1318700u] = new MobUt.Tx8(this.funct00141f2c); + this.dicti2a[1318708u] = new MobUt.Tx8(this.funct00141f34); + this.dicti2a[1318728u] = new MobUt.Tx8(this.funct00141f48); + this.dicti2a[1318732u] = new MobUt.Tx8(this.funct00141f4c); + this.dicti2a[1318792u] = new MobUt.Tx8(this.funct00141f88); + this.dicti2a[1318804u] = new MobUt.Tx8(this.funct00141f94); + this.dicti2a[1318836u] = new MobUt.Tx8(this.funct00141fb4); + this.dicti2a[1318848u] = new MobUt.Tx8(this.funct00141fc0); + this.dicti2a[1318860u] = new MobUt.Tx8(this.funct00141fcc); + this.dicti2a[1318868u] = new MobUt.Tx8(this.funct00141fd4); + this.dicti2a[1318884u] = new MobUt.Tx8(this.funct00141fe4); + this.dicti2a[1318904u] = new MobUt.Tx8(this.funct00141ff8); + this.dicti2a[1318912u] = new MobUt.Tx8(this.funct00142000); + this.dicti2a[1318928u] = new MobUt.Tx8(this.funct00142010); + this.dicti2a[1318956u] = new MobUt.Tx8(this.funct0014202c); + this.dicti2a[1318972u] = new MobUt.Tx8(this.funct0014203c); + this.dicti2a[1318976u] = new MobUt.Tx8(this.funct00142040); + this.dicti2a[1318988u] = new MobUt.Tx8(this.funct0014204c); + this.dicti2a[1319004u] = new MobUt.Tx8(this.funct0014205c); + this.dicti2a[1319016u] = new MobUt.Tx8(this.funct00142068); + this.dicti2a[1319040u] = new MobUt.Tx8(this.funct00142080); + this.dicti2a[1319052u] = new MobUt.Tx8(this.funct0014208c); + this.dicti2a[1319056u] = new MobUt.Tx8(this.funct00142090); + this.dicti2a[1319100u] = new MobUt.Tx8(this.funct001420bc); + this.dicti2a[1319128u] = new MobUt.Tx8(this.funct001420d8); + this.dicti2a[1319220u] = new MobUt.Tx8(this.funct00142134); + this.dicti2a[1319232u] = new MobUt.Tx8(this.funct00142140); + this.dicti2a[1319272u] = new MobUt.Tx8(this.funct00142168); + this.dicti2a[1319316u] = new MobUt.Tx8(this.funct00142194); + this.dicti2a[1319432u] = new MobUt.Tx8(this.funct00142208); + this.dicti2a[1319448u] = new MobUt.Tx8(this.funct00142218); + this.dicti2a[1319504u] = new MobUt.Tx8(this.funct00142250); + this.dicti2a[1319712u] = new MobUt.Tx8(this.funct00142320); + this.dicti2a[1319724u] = new MobUt.Tx8(this.funct0014232c); + this.dicti2a[1319760u] = new MobUt.Tx8(this.funct00142350); + this.dicti2a[1319804u] = new MobUt.Tx8(this.funct0014237c); + this.dicti2a[1319812u] = new MobUt.Tx8(this.funct00142384); + this.dicti2a[1319820u] = new MobUt.Tx8(this.funct0014238c); + this.dicti2a[1319836u] = new MobUt.Tx8(this.funct0014239c); + this.dicti2a[1319852u] = new MobUt.Tx8(this.funct001423ac); + this.dicti2a[1319876u] = new MobUt.Tx8(this.funct001423c4); + this.dicti2a[1319896u] = new MobUt.Tx8(this.funct001423d8); + this.dicti2a[1319992u] = new MobUt.Tx8(this.funct00142438); + this.dicti2a[1326792u] = new MobUt.Tx8(this.funct00143ec8); + this.dicti2a[1326864u] = new MobUt.Tx8(this.funct00143f10); + this.dicti2a[1326892u] = new MobUt.Tx8(this.funct00143f2c); + this.dicti2a[1326916u] = new MobUt.Tx8(this.funct00143f44); + this.dicti2a[1329272u] = new MobUt.Tx8(this.funct00144878); + this.dicti2a[1329728u] = new MobUt.Tx8(this.funct00144a40); + this.dicti2a[1329756u] = new MobUt.Tx8(this.funct00144a5c); + this.dicti2a[1329780u] = new MobUt.Tx8(this.funct00144a74); + this.dicti2a[1329820u] = new MobUt.Tx8(this.funct00144a9c); + this.dicti2a[1329828u] = new MobUt.Tx8(this.funct00144aa4); + this.dicti2a[1329844u] = new MobUt.Tx8(this.funct00144ab4); + this.dicti2a[1331344u] = new MobUt.Tx8(this.funct00145090); + this.dicti2a[1331376u] = new MobUt.Tx8(this.funct001450b0); + this.dicti2a[1331428u] = new MobUt.Tx8(this.funct001450e4); + this.dicti2a[1331508u] = new MobUt.Tx8(this.funct00145134); + this.dicti2a[1331532u] = new MobUt.Tx8(this.funct0014514c); + this.dicti2a[1331612u] = new MobUt.Tx8(this.funct0014519c); + this.dicti2a[1331636u] = new MobUt.Tx8(this.funct001451b4); + this.dicti2a[1331716u] = new MobUt.Tx8(this.funct00145204); + this.dicti2a[1331740u] = new MobUt.Tx8(this.funct0014521c); + this.dicti2a[1331820u] = new MobUt.Tx8(this.funct0014526c); + this.dicti2a[1331844u] = new MobUt.Tx8(this.funct00145284); + this.dicti2a[1331924u] = new MobUt.Tx8(this.funct001452d4); + this.dicti2a[1331948u] = new MobUt.Tx8(this.funct001452ec); + this.dicti2a[1332028u] = new MobUt.Tx8(this.funct0014533c); + this.dicti2a[1333216u] = new MobUt.Tx8(this.funct001457e0); + this.dicti2a[1333236u] = new MobUt.Tx8(this.funct001457f4); + this.dicti2a[1333256u] = new MobUt.Tx8(this.funct00145808); + this.dicti2a[1333276u] = new MobUt.Tx8(this.funct0014581c); + this.dicti2a[1333296u] = new MobUt.Tx8(this.funct00145830); + this.dicti2a[1333316u] = new MobUt.Tx8(this.funct00145844); + this.dicti2a[1333332u] = new MobUt.Tx8(this.funct00145854); + this.dicti2a[1450744u] = new MobUt.Tx8(this.funct001622f8); + this.dicti2a[1450792u] = new MobUt.Tx8(this.funct00162328); + this.dicti2a[1450800u] = new MobUt.Tx8(this.funct00162330); + this.dicti2a[1450904u] = new MobUt.Tx8(this.funct00162398); + this.dicti2a[1450940u] = new MobUt.Tx8(this.funct001623bc); + this.dicti2a[1450980u] = new MobUt.Tx8(this.funct001623e4); + this.dicti2a[1451032u] = new MobUt.Tx8(this.funct00162418); + this.dicti2a[1451036u] = new MobUt.Tx8(this.funct0016241c); + this.dicti2a[1451044u] = new MobUt.Tx8(this.funct00162424); + this.dicti2a[1451052u] = new MobUt.Tx8(this.funct0016242c); + this.dicti2a[1451116u] = new MobUt.Tx8(this.funct0016246c); + this.dicti2a[1451632u] = new MobUt.Tx8(this.funct00162670); + this.dicti2a[1451696u] = new MobUt.Tx8(this.funct001626b0); + this.dicti2a[1451796u] = new MobUt.Tx8(this.funct00162714); + this.dicti2a[1451808u] = new MobUt.Tx8(this.funct00162720); + this.dicti2a[1451836u] = new MobUt.Tx8(this.funct0016273c); + this.dicti2a[1451868u] = new MobUt.Tx8(this.funct0016275c); + this.dicti2a[1451888u] = new MobUt.Tx8(this.funct00162770); + this.dicti2a[1451896u] = new MobUt.Tx8(this.funct00162778); + this.dicti2a[1465000u] = new MobUt.Tx8(this.funct00165aa8); + this.dicti2a[1465116u] = new MobUt.Tx8(this.funct00165b1c); + this.dicti2a[1465124u] = new MobUt.Tx8(this.funct00165b24); + this.dicti2a[1465312u] = new MobUt.Tx8(this.funct00165be0); + this.dicti2a[1465332u] = new MobUt.Tx8(this.funct00165bf4); + this.dicti2a[1465356u] = new MobUt.Tx8(this.funct00165c0c); + this.dicti2a[3123512u] = new MobUt.Tx8(this.funct002fa938); + this.dicti2a[3123608u] = new MobUt.Tx8(this.funct002fa998); + this.dicti2a[3123616u] = new MobUt.Tx8(this.funct002fa9a0); + this.dicti2a[3123620u] = new MobUt.Tx8(this.funct002fa9a4); + this.dicti2a[3123632u] = new MobUt.Tx8(this.funct002fa9b0); + this.dicti2a[3123660u] = new MobUt.Tx8(this.funct002fa9cc); + this.dicti2a[3123672u] = new MobUt.Tx8(this.funct002fa9d8); + this.dicti2a[3123680u] = new MobUt.Tx8(this.funct002fa9e0); + this.dicti2a[3123700u] = new MobUt.Tx8(this.funct002fa9f4); + this.dicti2a[3123748u] = new MobUt.Tx8(this.funct002faa24); + this.dicti2a[3123788u] = new MobUt.Tx8(this.funct002faa4c); + this.dicti2a[3123800u] = new MobUt.Tx8(this.funct002faa58); + this.dicti2a[3123828u] = new MobUt.Tx8(this.funct002faa74); + this.dicti2a[3123840u] = new MobUt.Tx8(this.funct002faa80); + this.dicti2a[3123848u] = new MobUt.Tx8(this.funct002faa88); + this.dicti2a[3123868u] = new MobUt.Tx8(this.funct002faa9c); + this.dicti2a[3123920u] = new MobUt.Tx8(this.funct002faad0); + this.dicti2a[3123960u] = new MobUt.Tx8(this.funct002faaf8); + this.dicti2a[3123968u] = new MobUt.Tx8(this.funct002fab00); + this.dicti2a[3123996u] = new MobUt.Tx8(this.funct002fab1c); + this.dicti2a[3124008u] = new MobUt.Tx8(this.funct002fab28); + this.dicti2a[3124016u] = new MobUt.Tx8(this.funct002fab30); + this.dicti2a[3124036u] = new MobUt.Tx8(this.funct002fab44); + this.dicti2a[3124088u] = new MobUt.Tx8(this.funct002fab78); + this.dicti2a[3124128u] = new MobUt.Tx8(this.funct002faba0); + this.dicti2a[3142160u] = new MobUt.Tx8(this.funct002ff210); + this.dicti2a[3142240u] = new MobUt.Tx8(this.funct002ff260); + this.dicti2a[3142264u] = new MobUt.Tx8(this.funct002ff278); + this.dicti2a[3142284u] = new MobUt.Tx8(this.funct002ff28c); + this.dicti2a[3142300u] = new MobUt.Tx8(this.funct002ff29c); + this.dicti2a[3142344u] = new MobUt.Tx8(this.funct002ff2c8); + this.dicti2a[3142348u] = new MobUt.Tx8(this.funct002ff2cc); + this.dicti2a[3142568u] = new MobUt.Tx8(this.funct002ff3a8); + this.dicti2a[3142584u] = new MobUt.Tx8(this.funct002ff3b8); + this.dicti2a[3142648u] = new MobUt.Tx8(this.funct002ff3f8); + this.dicti2a[3142656u] = new MobUt.Tx8(this.funct002ff400); + this.dicti2a[3142664u] = new MobUt.Tx8(this.funct002ff408); + this.dicti2a[3142684u] = new MobUt.Tx8(this.funct002ff41c); + this.dicti2a[3142704u] = new MobUt.Tx8(this.funct002ff430); + this.dicti2a[3142744u] = new MobUt.Tx8(this.funct002ff458); + this.dicti2a[3142764u] = new MobUt.Tx8(this.funct002ff46c); + this.dicti2a[3142788u] = new MobUt.Tx8(this.funct002ff484); + this.dicti2a[3142808u] = new MobUt.Tx8(this.funct002ff498); + this.dicti2a[3142852u] = new MobUt.Tx8(this.funct002ff4c4); + this.dicti2a[3143264u] = new MobUt.Tx8(this.funct002ff660); + this.dicti2a[3143848u] = new MobUt.Tx8(this.funct002ff8a8); + this.dicti2a[3143872u] = new MobUt.Tx8(this.funct002ff8c0); + this.dicti2a[3143896u] = new MobUt.Tx8(this.funct002ff8d8); + this.dicti2a[3145816u] = new MobUt.Tx8(this.funct00300058); + this.dicti2a[3145872u] = new MobUt.Tx8(this.funct00300090); + this.dicti2a[3145904u] = new MobUt.Tx8(this.funct003000b0); + this.dicti2a[3145908u] = new MobUt.Tx8(this.funct003000b4); + this.dicti2a[3145940u] = new MobUt.Tx8(this.funct003000d4); + this.dicti2a[3145948u] = new MobUt.Tx8(this.funct003000dc); + this.dicti2a[3145972u] = new MobUt.Tx8(this.funct003000f4); + this.dicti2a[3145988u] = new MobUt.Tx8(this.funct00300104); + this.dicti2a[3146004u] = new MobUt.Tx8(this.funct00300114); + this.dicti2a[3146044u] = new MobUt.Tx8(this.funct0030013c); + this.dicti2a[3146052u] = new MobUt.Tx8(this.funct00300144); + this.dicti2a[3146288u] = new MobUt.Tx8(this.funct00300230); + this.dicti2a[3146308u] = new MobUt.Tx8(this.funct00300244); + this.dicti2a[3146368u] = new MobUt.Tx8(this.funct00300280); + this.dicti2a[3146376u] = new MobUt.Tx8(this.funct00300288); + this.dicti2a[3146384u] = new MobUt.Tx8(this.funct00300290); + this.dicti2a[3146504u] = new MobUt.Tx8(this.funct00300308); + this.dicti2a[3146736u] = new MobUt.Tx8(this.funct003003f0); + this.dicti2a[3146784u] = new MobUt.Tx8(this.funct00300420); + this.dicti2a[3146800u] = new MobUt.Tx8(this.funct00300430); + this.dicti2a[3146832u] = new MobUt.Tx8(this.funct00300450); + this.dicti2a[3146848u] = new MobUt.Tx8(this.funct00300460); + this.dicti2a[3146860u] = new MobUt.Tx8(this.funct0030046c); + this.dicti2a[3146868u] = new MobUt.Tx8(this.funct00300474); + this.dicti2a[3146872u] = new MobUt.Tx8(this.funct00300478); + this.dicti2a[3146876u] = new MobUt.Tx8(this.funct0030047c); + this.dicti2a[3146880u] = new MobUt.Tx8(this.funct00300480); + this.dicti2a[3146896u] = new MobUt.Tx8(this.funct00300490); + this.dicti2a[3146916u] = new MobUt.Tx8(this.funct003004a4); + this.dicti2a[3146952u] = new MobUt.Tx8(this.funct003004c8); + this.dicti2a[3146972u] = new MobUt.Tx8(this.funct003004dc); + this.dicti2a[3147000u] = new MobUt.Tx8(this.funct003004f8); + this.dicti2a[3147008u] = new MobUt.Tx8(this.funct00300500); + this.dicti2a[3147016u] = new MobUt.Tx8(this.funct00300508); + this.dicti2a[3147036u] = new MobUt.Tx8(this.funct0030051c); + this.dicti2a[3147044u] = new MobUt.Tx8(this.funct00300524); + this.dicti2a[3147060u] = new MobUt.Tx8(this.funct00300534); + this.dicti2a[3147068u] = new MobUt.Tx8(this.funct0030053c); + this.dicti2a[3147080u] = new MobUt.Tx8(this.funct00300548); + this.dicti2a[3147112u] = new MobUt.Tx8(this.funct00300568); + this.dicti2a[3147120u] = new MobUt.Tx8(this.funct00300570); + this.dicti2a[3147156u] = new MobUt.Tx8(this.funct00300594); + this.dicti2a[3147192u] = new MobUt.Tx8(this.funct003005b8); + this.dicti2a[3147236u] = new MobUt.Tx8(this.funct003005e4); + this.dicti2a[3147244u] = new MobUt.Tx8(this.funct003005ec); + this.dicti2a[3147252u] = new MobUt.Tx8(this.funct003005f4); + this.dicti2a[3147272u] = new MobUt.Tx8(this.funct00300608); + this.dicti2a[3147292u] = new MobUt.Tx8(this.funct0030061c); + this.dicti2a[3147308u] = new MobUt.Tx8(this.funct0030062c); + this.dicti2a[3147360u] = new MobUt.Tx8(this.funct00300660); + this.dicti2a[3147364u] = new MobUt.Tx8(this.funct00300664); + this.dicti2a[3147472u] = new MobUt.Tx8(this.funct003006d0); + this.dicti2a[3147524u] = new MobUt.Tx8(this.funct00300704); + this.dicti2a[3147532u] = new MobUt.Tx8(this.funct0030070c); + this.dicti2a[3147600u] = new MobUt.Tx8(this.funct00300750); + this.dicti2a[3147612u] = new MobUt.Tx8(this.funct0030075c); + this.dicti2a[3147652u] = new MobUt.Tx8(this.funct00300784); + this.dicti2a[3147744u] = new MobUt.Tx8(this.funct003007e0); + this.dicti2a[3151872u] = new MobUt.Tx8(this.funct00301800); + this.dicti2a[3151908u] = new MobUt.Tx8(this.funct00301824); + this.dicti2a[3151936u] = new MobUt.Tx8(this.funct00301840); + this.dicti2a[3151944u] = new MobUt.Tx8(this.funct00301848); + this.dicti2a[3151988u] = new MobUt.Tx8(this.funct00301874); + this.dicti2a[3152004u] = new MobUt.Tx8(this.funct00301884); + this.dicti2a[3152020u] = new MobUt.Tx8(this.funct00301894); + this.dicti2a[3152028u] = new MobUt.Tx8(this.funct0030189c); + this.dicti2a[3152036u] = new MobUt.Tx8(this.funct003018a4); + this.dicti2a[3152060u] = new MobUt.Tx8(this.funct003018bc); + this.dicti2a[3152072u] = new MobUt.Tx8(this.funct003018c8); + this.dicti2a[3332304u] = new MobUt.Tx8(this.funct0032d8d0); + this.dicti2a[3332316u] = new MobUt.Tx8(this.funct0032d8dc); + this.dicti2a[3332452u] = new MobUt.Tx8(this.funct0032d964); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/EmuRunner/RelocMdlx.cs b/OpenKh.Kh2AnimEmu/Mset/EmuRunner/RelocMdlx.cs index 3dc38d5b5..5891108aa 100644 --- a/OpenKh.Kh2AnimEmu/Mset/EmuRunner/RelocMdlx.cs +++ b/OpenKh.Kh2AnimEmu/Mset/EmuRunner/RelocMdlx.cs @@ -1,242 +1,242 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; -using System.Diagnostics; - -namespace OpenKh.Kh2Anim.Mset.EmuRunner -{ - class RelocMset - { - MemoryStream os; - uint off; - uint reloc; - BinaryReader br; - BinaryWriter wr; - uint[] ps; - - public RelocMset(byte[] bin, uint off, uint reloc, uint[] ps) - { - os = new MemoryStream(bin, true); - this.off = off; - this.reloc = reloc; - br = new BinaryReader(os); - wr = new BinaryWriter(os); - this.ps = ps; - } - public void Run() - { - relocateAnimData(off); - } - - void relocateAnimData(uint off2) - { - os.Position = off2; - wr.Write(ps[0]); - wr.Write((uint)(off2 - off + reloc + 0x90U)); - wr.Write(ps[2]); - wr.Write(ps[3]); - wr.Write(ps[4]); - wr.Write(ps[5]); - - os.Position = off2 + 0x90U + 0x10U; - int c0 = br.ReadUInt16(); - int c1 = br.ReadUInt16(); - os.Position = off2 + 0x90U + 0x18U; - uint pos = br.ReadUInt32(); - - int ct = c1 - c0; - - uint off3 = off2 + 0x90U + pos; - - if (off3 < (uint)os.Length) - { - BSReloc.Run(os, off3, ct, c0); - } - } - } - class RelocMdlx - { - byte[] bin; - uint off; - uint reloc; - uint pos0, pos1, pos2, pos3; - MemoryStream os; - BinaryReader br; - BinaryWriter wr; - - public RelocMdlx(byte[] bin, int off, int reloc, uint pos0, uint pos1, uint pos2, uint pos3) - { - // pos0: 0x354398 --> ? - // pos1: P_EX +0x90 - // pos2: st - // pos3: 1 - this.bin = bin; - this.off = (uint)off; - this.reloc = (uint)reloc; - os = new MemoryStream(bin, true); - br = new BinaryReader(os); - wr = new BinaryWriter(os); - this.pos0 = pos0; - this.pos1 = pos1; - this.pos2 = pos2; - this.pos3 = pos3; - } - - public uint Run() - { - os.Position = off + 4; - int cnt = br.ReadInt32(); - UtReloc.Rel4(os, off + 8, reloc); - uint r = 0; - for (int c = 0; c < cnt; c++) - { - os.Position = off + 16 * (1 + c); - uint c00 = br.ReadUInt32(); - uint pos = UtReloc.Rel4(os, (uint)(off + 16 * (1 + c) + 8), reloc).oldVal; - if (c00 == 0x04) - r = ty04(pos); - } - return r; - } - - uint ty04(uint pos) - { - os.Position = off + pos; - wr.Write(pos0); - wr.Write(reloc + pos + 0x90U); - wr.Write(pos2); - wr.Write(pos3); - - os.Position = off + pos + 0x90U + 0x10U; - uint c10 = br.ReadUInt16(); - uint c12 = br.ReadUInt16(); - uint c14 = br.ReadUInt32(); - -#if true - BSReloc.Run(os, off + pos + 0x90U + c14, (int)c10, 0); -#else - List alc = new List(); - for (int t = 0; t < (int)c10; t++) { - os.Position = off + pos + 0x90U + c14 + 64 * t; - Corner o = new Corner(); - o.bi = br.ReadInt32(); - o.pi = br.ReadInt32(); - if (o.pi != -1) { - if (alc[o.pi].x3 == -1) { // no children yet - alc[o.pi].x3 = t; - } - else { // having children - int myx3 = alc[o.pi].x3; - alc[o.pi].x3 = t; - o.x1 = myx3; - } - } - alc.Add(o); - } - for (int t = 0; t < (int)c10; t++) - Debug.WriteLine(alc[t]); - for (int t = 0; t < (int)c10; t++) { - os.Position = off + pos + 0x90U + c14 + 64 * t; - Corner o = alc[t]; - os.Seek(+2, SeekOrigin.Current); - wr.Write((ushort)o.x1); - os.Seek(+2, SeekOrigin.Current); - wr.Write((ushort)o.x3); - } -#endif - - return reloc + pos; - } - -#if false - class Corner { - public int bi, pi; - public int x1 = -1, x3 = -1; - - public override string ToString() { - return base.ToString(); - //return string.Format("{0:X4} {1:X4} {2:X4} {3:X4}", (short)bi, (short)x1, (short)pi, (short)x3); - } - } -#endif - } - class BSReloc - { - class Corner - { - public int bi, pi; - public int x1 = -1, x3 = -1; - - public override string ToString() - { - return string.Format("{0:X4} {1:X4} {2:X4} {3:X4}", (short)bi, (short)x1, (short)pi, (short)x3); - } - } - - public static void Run(MemoryStream os, uint off, int ct, int delta) - { - BinaryReader br = new BinaryReader(os); - BinaryWriter wr = new BinaryWriter(os); - - List alc = new List(); - for (int t = 0; t < ct; t++) - { - os.Position = off + 64 * t; - Corner o = new Corner(); - o.bi = br.ReadInt32(); - o.pi = br.ReadInt32(); - if (o.pi != -1 && o.pi - delta >= 0) - { - if (alc[o.pi - delta].x3 == -1) - { // no children yet - alc[o.pi - delta].x3 = t + delta; - } - else - { // having children - int myx3 = alc[o.pi - delta].x3; - alc[o.pi - delta].x3 = t + delta; - o.x1 = myx3; - } - } - alc.Add(o); - } -#if false - for (int t = 0; t < ct; t++) - Debug.WriteLine(alc[t]); -#endif - for (int t = 0; t < ct; t++) - { - os.Position = off + 64 * t; - Corner o = alc[t]; - os.Seek(+2, SeekOrigin.Current); - wr.Write((ushort)o.x1); - os.Seek(+2, SeekOrigin.Current); - wr.Write((ushort)o.x3); - } - - } - } - class RelRes - { - public uint oldVal, newVal; - - public RelRes(uint oldVal, uint newVal) - { - this.oldVal = oldVal; - this.newVal = newVal; - } - } - class UtReloc - { - public static RelRes Rel4(MemoryStream os, uint off, uint reloc) - { - os.Position = off; - uint oldVal = new BinaryReader(os).ReadUInt32(); - uint newVal = oldVal + reloc; - os.Position = off; - new BinaryWriter(os).Write(newVal); - return new RelRes(oldVal, newVal); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Diagnostics; + +namespace OpenKh.Kh2Anim.Mset.EmuRunner +{ + class RelocMset + { + MemoryStream os; + uint off; + uint reloc; + BinaryReader br; + BinaryWriter wr; + uint[] ps; + + public RelocMset(byte[] bin, uint off, uint reloc, uint[] ps) + { + os = new MemoryStream(bin, true); + this.off = off; + this.reloc = reloc; + br = new BinaryReader(os); + wr = new BinaryWriter(os); + this.ps = ps; + } + public void Run() + { + relocateAnimData(off); + } + + void relocateAnimData(uint off2) + { + os.Position = off2; + wr.Write(ps[0]); + wr.Write((uint)(off2 - off + reloc + 0x90U)); + wr.Write(ps[2]); + wr.Write(ps[3]); + wr.Write(ps[4]); + wr.Write(ps[5]); + + os.Position = off2 + 0x90U + 0x10U; + int c0 = br.ReadUInt16(); + int c1 = br.ReadUInt16(); + os.Position = off2 + 0x90U + 0x18U; + uint pos = br.ReadUInt32(); + + int ct = c1 - c0; + + uint off3 = off2 + 0x90U + pos; + + if (off3 < (uint)os.Length) + { + BSReloc.Run(os, off3, ct, c0); + } + } + } + class RelocMdlx + { + byte[] bin; + uint off; + uint reloc; + uint pos0, pos1, pos2, pos3; + MemoryStream os; + BinaryReader br; + BinaryWriter wr; + + public RelocMdlx(byte[] bin, int off, int reloc, uint pos0, uint pos1, uint pos2, uint pos3) + { + // pos0: 0x354398 --> ? + // pos1: P_EX +0x90 + // pos2: st + // pos3: 1 + this.bin = bin; + this.off = (uint)off; + this.reloc = (uint)reloc; + os = new MemoryStream(bin, true); + br = new BinaryReader(os); + wr = new BinaryWriter(os); + this.pos0 = pos0; + this.pos1 = pos1; + this.pos2 = pos2; + this.pos3 = pos3; + } + + public uint Run() + { + os.Position = off + 4; + int cnt = br.ReadInt32(); + UtReloc.Rel4(os, off + 8, reloc); + uint r = 0; + for (int c = 0; c < cnt; c++) + { + os.Position = off + 16 * (1 + c); + uint c00 = br.ReadUInt32(); + uint pos = UtReloc.Rel4(os, (uint)(off + 16 * (1 + c) + 8), reloc).oldVal; + if (c00 == 0x04) + r = ty04(pos); + } + return r; + } + + uint ty04(uint pos) + { + os.Position = off + pos; + wr.Write(pos0); + wr.Write(reloc + pos + 0x90U); + wr.Write(pos2); + wr.Write(pos3); + + os.Position = off + pos + 0x90U + 0x10U; + uint c10 = br.ReadUInt16(); + uint c12 = br.ReadUInt16(); + uint c14 = br.ReadUInt32(); + +#if true + BSReloc.Run(os, off + pos + 0x90U + c14, (int)c10, 0); +#else + List alc = new List(); + for (int t = 0; t < (int)c10; t++) { + os.Position = off + pos + 0x90U + c14 + 64 * t; + Corner o = new Corner(); + o.bi = br.ReadInt32(); + o.pi = br.ReadInt32(); + if (o.pi != -1) { + if (alc[o.pi].x3 == -1) { // no children yet + alc[o.pi].x3 = t; + } + else { // having children + int myx3 = alc[o.pi].x3; + alc[o.pi].x3 = t; + o.x1 = myx3; + } + } + alc.Add(o); + } + for (int t = 0; t < (int)c10; t++) + Debug.WriteLine(alc[t]); + for (int t = 0; t < (int)c10; t++) { + os.Position = off + pos + 0x90U + c14 + 64 * t; + Corner o = alc[t]; + os.Seek(+2, SeekOrigin.Current); + wr.Write((ushort)o.x1); + os.Seek(+2, SeekOrigin.Current); + wr.Write((ushort)o.x3); + } +#endif + + return reloc + pos; + } + +#if false + class Corner { + public int bi, pi; + public int x1 = -1, x3 = -1; + + public override string ToString() { + return base.ToString(); + //return string.Format("{0:X4} {1:X4} {2:X4} {3:X4}", (short)bi, (short)x1, (short)pi, (short)x3); + } + } +#endif + } + class BSReloc + { + class Corner + { + public int bi, pi; + public int x1 = -1, x3 = -1; + + public override string ToString() + { + return string.Format("{0:X4} {1:X4} {2:X4} {3:X4}", (short)bi, (short)x1, (short)pi, (short)x3); + } + } + + public static void Run(MemoryStream os, uint off, int ct, int delta) + { + BinaryReader br = new BinaryReader(os); + BinaryWriter wr = new BinaryWriter(os); + + List alc = new List(); + for (int t = 0; t < ct; t++) + { + os.Position = off + 64 * t; + Corner o = new Corner(); + o.bi = br.ReadInt32(); + o.pi = br.ReadInt32(); + if (o.pi != -1 && o.pi - delta >= 0) + { + if (alc[o.pi - delta].x3 == -1) + { // no children yet + alc[o.pi - delta].x3 = t + delta; + } + else + { // having children + int myx3 = alc[o.pi - delta].x3; + alc[o.pi - delta].x3 = t + delta; + o.x1 = myx3; + } + } + alc.Add(o); + } +#if false + for (int t = 0; t < ct; t++) + Debug.WriteLine(alc[t]); +#endif + for (int t = 0; t < ct; t++) + { + os.Position = off + 64 * t; + Corner o = alc[t]; + os.Seek(+2, SeekOrigin.Current); + wr.Write((ushort)o.x1); + os.Seek(+2, SeekOrigin.Current); + wr.Write((ushort)o.x3); + } + + } + } + class RelRes + { + public uint oldVal, newVal; + + public RelRes(uint oldVal, uint newVal) + { + this.oldVal = oldVal; + this.newVal = newVal; + } + } + class UtReloc + { + public static RelRes Rel4(MemoryStream os, uint off, uint reloc) + { + os.Position = off; + uint oldVal = new BinaryReader(os).ReadUInt32(); + uint newVal = oldVal + reloc; + os.Position = off; + new BinaryWriter(os).Write(newVal); + return new RelRes(oldVal, newVal); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/Interfaces/IAnimMatricesProvider.cs b/OpenKh.Kh2AnimEmu/Mset/Interfaces/IAnimMatricesProvider.cs index 2182ce304..69f5a63e9 100644 --- a/OpenKh.Kh2AnimEmu/Mset/Interfaces/IAnimMatricesProvider.cs +++ b/OpenKh.Kh2AnimEmu/Mset/Interfaces/IAnimMatricesProvider.cs @@ -1,18 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Numerics; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset.Interfaces -{ - public interface IAnimMatricesProvider - { - Matrix4x4[] ProvideMatrices(double gameTimeDelta); - - float FrameLoop { get; } - float FrameEnd { get; } - float FramePerSecond { get; } - float FrameCount { get; } - int MatrixCount { get; } - } -} +using System; +using System.Collections.Generic; +using System.Numerics; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset.Interfaces +{ + public interface IAnimMatricesProvider + { + Matrix4x4[] ProvideMatrices(double gameTimeDelta); + + float FrameLoop { get; } + float FrameEnd { get; } + float FramePerSecond { get; } + float FrameCount { get; } + int MatrixCount { get; } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/MsetIndir.cs b/OpenKh.Kh2AnimEmu/Mset/MsetIndir.cs index 768c1c1ea..03dec81e6 100644 --- a/OpenKh.Kh2AnimEmu/Mset/MsetIndir.cs +++ b/OpenKh.Kh2AnimEmu/Mset/MsetIndir.cs @@ -1,31 +1,31 @@ -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - /// - /// mset indirection - /// - public class MsetIndir - { - private readonly IList entries; - - public MsetIndir(IList entries) - { - this.entries = entries; - } - - public AnbIndir GetAnb(int barEntryIndex) - { - var anbBar = entries - .Skip(barEntryIndex) - .First(it => it.Type == Bar.EntryType.Anb); - - return new AnbIndir(Bar.Read(anbBar.Stream)); - } - } -} +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + /// + /// mset indirection + /// + public class MsetIndir + { + private readonly IList entries; + + public MsetIndir(IList entries) + { + this.entries = entries; + } + + public AnbIndir GetAnb(int barEntryIndex) + { + var anbBar = entries + .Skip(barEntryIndex) + .First(it => it.Type == Bar.EntryType.Anb); + + return new AnbIndir(Bar.Read(anbBar.Stream)); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/PosTbl.cs b/OpenKh.Kh2AnimEmu/Mset/PosTbl.cs index 36d39ec23..346ab304e 100644 --- a/OpenKh.Kh2AnimEmu/Mset/PosTbl.cs +++ b/OpenKh.Kh2AnimEmu/Mset/PosTbl.cs @@ -1,76 +1,76 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - public class PosTbl - { - public int tbloff = 0x90; - - public int va0; - public int va2; // cnt t4 - public int va8; // off t5 (each 64 bytes) { cnt_t5 = va2 -va0 } - public int vac; // off t4 (each 4 bytes) - public int vb0; // cnt t11 - public int vb4; // off t1 (each 8 bytes) - public int vb8; // cnt t1 - public int vc0; // off t2 (each 6 bytes) - public int vc4; // cnt t2 - public int vc8; // off t2` (each 6 bytes) - public int vcc; // cnt t2` - public int vd0; // off t9 (each 8 bytes) - public int vd4; // off t11 (each 4 bytes) - public int vd8; // off t10 (each 4 bytes) - public int vdc; // off t12 (each 4 bytes) - public int ve0; // off t3 (each 12 bytes) - public int ve4; // cnt t3 - public int ve8; - public int vec; // off t8 (each 48 bytes) { cnt_t8 = cnt_t2` } - public int vf0; // off t7 (each 8 bytes) - public int vf4; // cnt t7 - public int vf8; // off t6 (each 12 bytes) - public int vfc; // cnt t6 - - public PosTbl(Stream si) - { - BinaryReader br = new BinaryReader(si); - int off = tbloff - 0x90; - - // Clone→ - si.Position = off + 0xA0; - va0 = br.ReadUInt16(); - va2 = br.ReadUInt16(); // cnt t4 - si.Position = off + 0xA8; - va8 = br.ReadInt32(); // off t5 (each 64 bytes) { cnt_t5 = va2 -va0 } - vac = br.ReadInt32(); // off t4 (each 4 bytes) - - si.Position = off + 0xB0; - vb0 = br.ReadInt32(); // cnt t11 - vb4 = br.ReadInt32(); // off t1 (each 8 bytes) - vb8 = br.ReadInt32(); // cnt t1 - si.Position = off + 0xC0; - vc0 = br.ReadInt32(); // off t2 (each 6 bytes) - vc4 = br.ReadInt32(); // cnt t2 - vc8 = br.ReadInt32(); // off t2` (each 6 bytes) - vcc = br.ReadInt32(); // cnt t2` - si.Position = off + 0xD0; - vd0 = br.ReadInt32(); // off t9 (each 8 bytes) - vd4 = br.ReadInt32(); // off t11 (each 4 bytes) - vd8 = br.ReadInt32(); // off t10 (each 4 bytes) - vdc = br.ReadInt32(); // off t12 (each 4 bytes) - si.Position = off + 0xE0; - ve0 = br.ReadInt32(); // off t3 (each 12 bytes) - ve4 = br.ReadInt32(); // cnt t3 - ve8 = br.ReadInt32(); - vec = br.ReadInt32(); // off t8 (each 48 bytes) { cnt_t8 = cnt_t2` } - si.Position = off + 0xF0; - vf0 = br.ReadInt32(); // off t7 (each 8 bytes) - vf4 = br.ReadInt32(); // cnt t7 - vf8 = br.ReadInt32(); // off t6 (each 12 bytes) - vfc = br.ReadInt32(); // cnt t6 - // ←Clone - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + public class PosTbl + { + public int tbloff = 0x90; + + public int va0; + public int va2; // cnt t4 + public int va8; // off t5 (each 64 bytes) { cnt_t5 = va2 -va0 } + public int vac; // off t4 (each 4 bytes) + public int vb0; // cnt t11 + public int vb4; // off t1 (each 8 bytes) + public int vb8; // cnt t1 + public int vc0; // off t2 (each 6 bytes) + public int vc4; // cnt t2 + public int vc8; // off t2` (each 6 bytes) + public int vcc; // cnt t2` + public int vd0; // off t9 (each 8 bytes) + public int vd4; // off t11 (each 4 bytes) + public int vd8; // off t10 (each 4 bytes) + public int vdc; // off t12 (each 4 bytes) + public int ve0; // off t3 (each 12 bytes) + public int ve4; // cnt t3 + public int ve8; + public int vec; // off t8 (each 48 bytes) { cnt_t8 = cnt_t2` } + public int vf0; // off t7 (each 8 bytes) + public int vf4; // cnt t7 + public int vf8; // off t6 (each 12 bytes) + public int vfc; // cnt t6 + + public PosTbl(Stream si) + { + BinaryReader br = new BinaryReader(si); + int off = tbloff - 0x90; + + // Clone→ + si.Position = off + 0xA0; + va0 = br.ReadUInt16(); + va2 = br.ReadUInt16(); // cnt t4 + si.Position = off + 0xA8; + va8 = br.ReadInt32(); // off t5 (each 64 bytes) { cnt_t5 = va2 -va0 } + vac = br.ReadInt32(); // off t4 (each 4 bytes) + + si.Position = off + 0xB0; + vb0 = br.ReadInt32(); // cnt t11 + vb4 = br.ReadInt32(); // off t1 (each 8 bytes) + vb8 = br.ReadInt32(); // cnt t1 + si.Position = off + 0xC0; + vc0 = br.ReadInt32(); // off t2 (each 6 bytes) + vc4 = br.ReadInt32(); // cnt t2 + vc8 = br.ReadInt32(); // off t2` (each 6 bytes) + vcc = br.ReadInt32(); // cnt t2` + si.Position = off + 0xD0; + vd0 = br.ReadInt32(); // off t9 (each 8 bytes) + vd4 = br.ReadInt32(); // off t11 (each 4 bytes) + vd8 = br.ReadInt32(); // off t10 (each 4 bytes) + vdc = br.ReadInt32(); // off t12 (each 4 bytes) + si.Position = off + 0xE0; + ve0 = br.ReadInt32(); // off t3 (each 12 bytes) + ve4 = br.ReadInt32(); // cnt t3 + ve8 = br.ReadInt32(); + vec = br.ReadInt32(); // off t8 (each 48 bytes) { cnt_t8 = cnt_t2` } + si.Position = off + 0xF0; + vf0 = br.ReadInt32(); // off t7 (each 8 bytes) + vf4 = br.ReadInt32(); // cnt t7 + vf8 = br.ReadInt32(); // off t6 (each 12 bytes) + vfc = br.ReadInt32(); // cnt t6 + // ←Clone + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/T1.cs b/OpenKh.Kh2AnimEmu/Mset/T1.cs index 7c10f2fea..2719a5b32 100644 --- a/OpenKh.Kh2AnimEmu/Mset/T1.cs +++ b/OpenKh.Kh2AnimEmu/Mset/T1.cs @@ -1,24 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - public class T1 - { - public int c00, c02; - public float c04; - - public T1(int c00, int c02, float c04) - { - this.c00 = c00; - this.c02 = c02; - this.c04 = c04; - } - - public override string ToString() - { - return string.Format("{0:X4} {1:X4} {2}", c00, c02, c04); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + public class T1 + { + public int c00, c02; + public float c04; + + public T1(int c00, int c02, float c04) + { + this.c00 = c00; + this.c02 = c02; + this.c04 = c04; + } + + public override string ToString() + { + return string.Format("{0:X4} {1:X4} {2}", c00, c02, c04); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/T2.cs b/OpenKh.Kh2AnimEmu/Mset/T2.cs index 9280ce20e..65e0fb45a 100644 --- a/OpenKh.Kh2AnimEmu/Mset/T2.cs +++ b/OpenKh.Kh2AnimEmu/Mset/T2.cs @@ -1,26 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - public class T2 - { - public int c00, c01, c02, c03, c04; - public List al9f = new List(); - - public T2(int c00, int c01, int c02, int c03, int c04) - { - this.c00 = c00; - this.c01 = c01; - this.c02 = c02; - this.c03 = c03; - this.c04 = c04; - } - - public override string ToString() - { - return string.Format("{0:X2} {1:X2} {2:X2} {3:X2} {4:X4}", c00, c01, c02, c03, c04); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + public class T2 + { + public int c00, c01, c02, c03, c04; + public List al9f = new List(); + + public T2(int c00, int c01, int c02, int c03, int c04) + { + this.c00 = c00; + this.c01 = c01; + this.c02 = c02; + this.c03 = c03; + this.c04 = c04; + } + + public override string ToString() + { + return string.Format("{0:X2} {1:X2} {2:X2} {3:X2} {4:X4}", c00, c01, c02, c03, c04); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/T3.cs b/OpenKh.Kh2AnimEmu/Mset/T3.cs index 919798344..6f6cf7d7d 100644 --- a/OpenKh.Kh2AnimEmu/Mset/T3.cs +++ b/OpenKh.Kh2AnimEmu/Mset/T3.cs @@ -1,27 +1,27 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - public class T3 - { - public int c00, c01, c02, c04, c06; - public uint c08; - - public T3(int c00, int c01, int c02, int c04, int c06, uint c08) - { - this.c00 = c00; - this.c01 = c01; - this.c02 = c02; - this.c04 = c04; - this.c06 = c06; - this.c08 = c08; - } - - public override string ToString() - { - return string.Format("{0:X2} {1:X2} {2:X4} {3:X4} {4:X4} {5:X8}", c00, c01, c02, c04, c06, c08); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + public class T3 + { + public int c00, c01, c02, c04, c06; + public uint c08; + + public T3(int c00, int c01, int c02, int c04, int c06, uint c08) + { + this.c00 = c00; + this.c01 = c01; + this.c02 = c02; + this.c04 = c04; + this.c06 = c06; + this.c08 = c08; + } + + public override string ToString() + { + return string.Format("{0:X2} {1:X2} {2:X4} {3:X4} {4:X4} {5:X8}", c00, c01, c02, c04, c06, c08); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/T4.cs b/OpenKh.Kh2AnimEmu/Mset/T4.cs index d62e619be..c3b1c0300 100644 --- a/OpenKh.Kh2AnimEmu/Mset/T4.cs +++ b/OpenKh.Kh2AnimEmu/Mset/T4.cs @@ -1,23 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - public class T4 - { - public int c00; - public int c02; - - public T4(int c00, int c02) - { - this.c00 = c00; - this.c02 = c02; - } - - public override string ToString() - { - return string.Format("{0:X4} {1:X4}", c00, c02); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + public class T4 + { + public int c00; + public int c02; + + public T4(int c00, int c02) + { + this.c00 = c00; + this.c02 = c02; + } + + public override string ToString() + { + return string.Format("{0:X4} {1:X4}", c00, c02); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/T9.cs b/OpenKh.Kh2AnimEmu/Mset/T9.cs index 1cfb606ca..e24fd2aa0 100644 --- a/OpenKh.Kh2AnimEmu/Mset/T9.cs +++ b/OpenKh.Kh2AnimEmu/Mset/T9.cs @@ -1,24 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - public class T9 - { - public int c00, c02, c04, c06; - - public T9(int c00, int c02, int c04, int c06) - { - this.c00 = c00; - this.c02 = c02; - this.c04 = c04; - this.c06 = c06; - } - - public override string ToString() - { - return string.Format("{0:X4} {1:X4} {2:X4} {3:X4}", c00, c02, c04, c06); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + public class T9 + { + public int c00, c02, c04, c06; + + public T9(int c00, int c02, int c04, int c06) + { + this.c00 = c00; + this.c02 = c02; + this.c04 = c04; + this.c06 = c06; + } + + public override string ToString() + { + return string.Format("{0:X4} {1:X4} {2:X4} {3:X4}", c00, c02, c04, c06); + } + } +} diff --git a/OpenKh.Kh2AnimEmu/Mset/T9f.cs b/OpenKh.Kh2AnimEmu/Mset/T9f.cs index 0c0b9fa07..47d753fd1 100644 --- a/OpenKh.Kh2AnimEmu/Mset/T9f.cs +++ b/OpenKh.Kh2AnimEmu/Mset/T9f.cs @@ -1,21 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Kh2Anim.Mset -{ - public class T9f - { - public int c00; - public float v0, v1, v2, v3; - - public T9f(int c00, float v0, float v1, float v2, float v3) - { - this.c00 = c00; - this.v0 = v0; - this.v1 = v1; - this.v2 = v2; - this.v3 = v3; - } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Kh2Anim.Mset +{ + public class T9f + { + public int c00; + public float v0, v1, v2, v3; + + public T9f(int c00, float v0, float v1, float v2, float v3) + { + this.c00 = c00; + this.v0 = v0; + this.v1 = v1; + this.v2 = v2; + this.v3 = v3; + } + } +} diff --git a/OpenKh.Patcher/Metadata.cs b/OpenKh.Patcher/Metadata.cs index 88971e0f7..b9b41af13 100644 --- a/OpenKh.Patcher/Metadata.cs +++ b/OpenKh.Patcher/Metadata.cs @@ -1,60 +1,60 @@ -using OpenKh.Kh2; -using System.Collections.Generic; -using System.IO; -using YamlDotNet.Serialization; -using YamlDotNet.Serialization.NamingConventions; - -namespace OpenKh.Patcher -{ - public class Metadata - { - public class Dependency - { - public string Name { get; set; } - } - - public string Title { get; set; } - public string OriginalAuthor { get; set; } - public string Description { get; set; } - public int Specifications { get; set; } - public List Dependencies { get; set; } - public List Assets { get; set; } - - private static readonly IDeserializer deserializer = - new DeserializerBuilder() - .IgnoreFields() - .IgnoreUnmatchedProperties() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build(); - private static readonly ISerializer serializer = - new SerializerBuilder() - .IgnoreFields() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build(); - - public static Metadata Read(Stream stream) => - deserializer.Deserialize(new StreamReader(stream)); - public void Write(Stream stream) => - serializer.Serialize(new StreamWriter(stream), this); - } - - public class AssetFile - { - public string Name { get; set; } - public string Method { get; set; } - public List Multi { get; set; } - public List Source { get; set; } - - public bool Required { get; set; } - public string Type { get; set; } - public Bar.MotionsetType MotionsetType { get; set; } - public string Language { get; set; } - public bool IsSwizzled { get; set; } - public int Index { get; set; } - } - - public class Multi - { - public string Name { get; set; } - } -} +using OpenKh.Kh2; +using System.Collections.Generic; +using System.IO; +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; + +namespace OpenKh.Patcher +{ + public class Metadata + { + public class Dependency + { + public string Name { get; set; } + } + + public string Title { get; set; } + public string OriginalAuthor { get; set; } + public string Description { get; set; } + public int Specifications { get; set; } + public List Dependencies { get; set; } + public List Assets { get; set; } + + private static readonly IDeserializer deserializer = + new DeserializerBuilder() + .IgnoreFields() + .IgnoreUnmatchedProperties() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build(); + private static readonly ISerializer serializer = + new SerializerBuilder() + .IgnoreFields() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build(); + + public static Metadata Read(Stream stream) => + deserializer.Deserialize(new StreamReader(stream)); + public void Write(Stream stream) => + serializer.Serialize(new StreamWriter(stream), this); + } + + public class AssetFile + { + public string Name { get; set; } + public string Method { get; set; } + public List Multi { get; set; } + public List Source { get; set; } + + public bool Required { get; set; } + public string Type { get; set; } + public Bar.MotionsetType MotionsetType { get; set; } + public string Language { get; set; } + public bool IsSwizzled { get; set; } + public int Index { get; set; } + } + + public class Multi + { + public string Name { get; set; } + } +} diff --git a/OpenKh.Patcher/PatcherException.cs b/OpenKh.Patcher/PatcherException.cs index d6c096f18..bd927203c 100644 --- a/OpenKh.Patcher/PatcherException.cs +++ b/OpenKh.Patcher/PatcherException.cs @@ -1,15 +1,15 @@ -using System; - -namespace OpenKh.Patcher -{ - public class PatcherException : AggregateException - { - public PatcherException(Metadata patch, Exception innerException) : - base($"The mod '{patch.Title}' generated an error.", innerException) - { - Patch = patch; - } - - public Metadata Patch { get; } - } -} +using System; + +namespace OpenKh.Patcher +{ + public class PatcherException : AggregateException + { + public PatcherException(Metadata patch, Exception innerException) : + base($"The mod '{patch.Title}' generated an error.", innerException) + { + Patch = patch; + } + + public Metadata Patch { get; } + } +} diff --git a/OpenKh.Patcher/PatcherProcessor.cs b/OpenKh.Patcher/PatcherProcessor.cs index 648f86624..e57d9e610 100644 --- a/OpenKh.Patcher/PatcherProcessor.cs +++ b/OpenKh.Patcher/PatcherProcessor.cs @@ -1,283 +1,283 @@ -using OpenKh.Common; -using OpenKh.Imaging; -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using YamlDotNet.Serialization; - -namespace OpenKh.Patcher -{ - public class PatcherProcessor - { - public class Context - { - public Metadata Metadata { get; set; } - public string OriginalAssetPath { get; } - public string SourceModAssetPath { get; set; } - public string DestinationPath { get; set; } - - public Context( - Metadata metadata, - string originalAssetPath, - string sourceModAssetPath, - string destinationPath) - { - Metadata = metadata; - OriginalAssetPath = originalAssetPath; - SourceModAssetPath = sourceModAssetPath; - DestinationPath = destinationPath; - } - - public string GetOriginalAssetPath(string path) => Path.Combine(OriginalAssetPath, path); - public string GetSourceModAssetPath(string path) => Path.Combine(SourceModAssetPath, path); - public string GetDestinationPath(string path) => Path.Combine(DestinationPath, path); - public void EnsureDirectoryExists(string fileName) => Directory.CreateDirectory(Path.GetDirectoryName(fileName)); - public void CopyOriginalFile(string fileName) - { - var dstFile = GetDestinationPath(fileName); - EnsureDirectoryExists(dstFile); - - if (!File.Exists(dstFile)) - { - var originalFile = GetOriginalAssetPath(fileName); - if (File.Exists(originalFile)) - File.Copy(originalFile, dstFile); - } - } - } - - public void Patch(string originalAssets, string outputDir, string modFilePath) - { - var metadata = File.OpenRead(modFilePath).Using(Metadata.Read); - var modBasePath = Path.GetDirectoryName(modFilePath); - Patch(originalAssets, outputDir, metadata, modBasePath); - } - - public void Patch(string originalAssets, string outputDir, Metadata metadata, string modBasePath) - { - var context = new Context(metadata, originalAssets, modBasePath, outputDir); - try - { - if (metadata.Assets == null) - throw new Exception("No assets found."); - - metadata.Assets.AsParallel().ForAll(assetFile => - { - var names = new List(); - names.Add(assetFile.Name); - if (assetFile.Multi != null) - names.AddRange(assetFile.Multi.Select(x => x.Name).Where(x => !string.IsNullOrEmpty(x))); - - foreach (var name in names) - { - if (assetFile.Required && !File.Exists(context.GetOriginalAssetPath(name))) - continue; - - context.CopyOriginalFile(name); - var dstFile = context.GetDestinationPath(name); - - using var stream = File.Open(dstFile, FileMode.OpenOrCreate, FileAccess.ReadWrite); - PatchFile(context, assetFile, stream); - } - }); - } - catch (Exception ex) - { - Log.Err($"Patcher failed: {ex.Message}"); - throw new PatcherException(metadata, ex); - } - } - - private static void PatchFile(Context context, AssetFile assetFile, Stream stream) - { - if (assetFile == null) - throw new Exception("Asset file is null."); - - switch (assetFile.Method) - { - case "copy": - CopyFile(context, assetFile, stream); - break; - case "bar": - case "binarc": - PatchBinarc(context, assetFile, stream); - break; - case "imd": - case "imgd": - CreateImageImd(context, assetFile.Source[0]).Write(stream); - break; - case "imz": - case "imgz": - PatchImageImz(context, assetFile, stream); - break; - case "fac": - Imgd.WriteAsFac(stream, assetFile.Source.Select(x => CreateImageImd(context, x))); - break; - case "kh2msg": - PatchKh2Msg(context, assetFile.Source, stream); - break; - case "areadatascript": - PatchAreaDataScript(context, assetFile.Source, stream); - break; - default: - Log.Warn($"Method '{assetFile.Method}' not recognized for '{assetFile.Name}'. Falling back to 'copy'"); - CopyFile(context, assetFile, stream); - break; - } - - stream.SetLength(stream.Position); - } - - private static void CopyFile(Context context, AssetFile assetFile, Stream stream) - { - if (assetFile.Source == null || assetFile.Source.Count == 0) - throw new Exception($"File '{assetFile.Name}' does not contain any source"); - - var srcFile = context.GetSourceModAssetPath(assetFile.Source[0].Name); - if (!File.Exists(srcFile)) - throw new FileNotFoundException($"The mod does not contain the file {assetFile.Source[0].Name}", srcFile); - - using var srcStream = File.OpenRead(srcFile); - srcStream.CopyTo(stream); - } - - private static void PatchBinarc(Context context, AssetFile assetFile, Stream stream) - { - var binarc = Bar.IsValid(stream) ? Bar.Read(stream) : - new Bar() - { - Motionset = assetFile.MotionsetType - }; - - foreach (var file in assetFile.Source) - { - if (!Enum.TryParse(file.Type, true, out var barEntryType)) - throw new Exception($"BinArc type {file.Type} not recognized"); - - var entry = binarc.FirstOrDefault(x => x.Name == file.Name && x.Type == barEntryType); - if (entry == null) - { - entry = new Bar.Entry - { - Name = file.Name, - Type = barEntryType, - Stream = new MemoryStream() - }; - binarc.Add(entry); - } - - PatchFile(context, file, entry.Stream); - } - - Bar.Write(stream.SetPosition(0), binarc); - foreach (var entry in binarc) - entry.Stream?.Dispose(); - } - - private static Imgd CreateImageImd(Context context, AssetFile source) - { - var srcFile = context.GetSourceModAssetPath(source.Name); - using var srcStream = File.OpenRead(srcFile); - if (PngImage.IsValid(srcStream)) - { - var png = PngImage.Read(srcStream); - return Imgd.Create(png.Size, png.PixelFormat, png.GetData(), png.GetClut(), source.IsSwizzled); - } - else if (Imgd.IsValid(srcStream)) - return Imgd.Read(srcStream); - - throw new Exception($"Image source '{source.Name}' not recognized"); - } - - private static void PatchImageImz(Context context, AssetFile assetFile, Stream stream) - { - var index = 0; - var images = Imgz.IsValid(stream) ? Imgz.Read(stream).ToList() : new List(); - foreach (var source in assetFile.Source) - { - if (source.Index > 0) - index = source.Index; - - var imd = CreateImageImd(context, source); - if (images.Count <= index) - images.Add(imd); - else - images[index] = imd; - - index++; - } - - Imgz.Write(stream.SetPosition(0), images); - } - - private static void PatchKh2Msg(Context context, List sources, Stream stream) - { - var msgs = Msg.IsValid(stream) ? Msg.Read(stream) : new List(); - - foreach (var source in sources) - { - if (string.IsNullOrEmpty(source.Language)) - throw new Exception($"No language specified in '{source.Name}'"); - - var content = File.ReadAllText(context.GetSourceModAssetPath(source.Name)); - var patchedMsgs = new Deserializer().Deserialize>>(content); - foreach (var msg in patchedMsgs) - { - if (!msg.TryGetValue("id", out var strId)) - throw new Exception($"Source '{source.Name}' contains a message without an ID"); - if (!ushort.TryParse(strId, out var id)) - { - if (strId.Length > 2 && strId[1] == 'x') - { - if (!ushort.TryParse(strId.Substring(2), NumberStyles.HexNumber, null, out id)) - throw new Exception($"Message ID '{strId} in '{source.Name}' must be between 0 and 65535"); - } - else - throw new Exception($"Message ID '{strId} in '{source.Name}' must be between 0 and 65535"); - } - if (!msg.TryGetValue(source.Language, out var text)) - continue; - - var encoder = source.Language switch - { - "jp" => Encoders.JapaneseSystem, - "tr" => Encoders.TurkishSystem, - _ => Encoders.InternationalSystem, - }; - - var data = encoder.Encode(MsgSerializer.DeserializeText(text ?? string.Empty).ToList()); - var originalMsg = msgs.FirstOrDefault(x => x.Id == id); - if (originalMsg == null) - msgs.Add(new Msg.Entry - { - Id = id, - Data = data - }); - else - originalMsg.Data = data; - } - } - - Msg.WriteOptimized(stream.SetPosition(0), msgs); - } - - private static void PatchAreaDataScript(Context context, List sources, Stream stream) - { - var scripts = Kh2.Ard.AreaDataScript.IsValid(stream) ? - Kh2.Ard.AreaDataScript.Read(stream).ToDictionary(x => x.ProgramId, x => x) : - new Dictionary(); - foreach (var source in sources) - { - var programsInput = File.ReadAllText(context.GetSourceModAssetPath(source.Name)); - foreach (var newScript in Kh2.Ard.AreaDataScript.Compile(programsInput)) - scripts[newScript.ProgramId] = newScript; - } - - Kh2.Ard.AreaDataScript.Write(stream.SetPosition(0), scripts.Values); - } - } -} +using OpenKh.Common; +using OpenKh.Imaging; +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using YamlDotNet.Serialization; + +namespace OpenKh.Patcher +{ + public class PatcherProcessor + { + public class Context + { + public Metadata Metadata { get; set; } + public string OriginalAssetPath { get; } + public string SourceModAssetPath { get; set; } + public string DestinationPath { get; set; } + + public Context( + Metadata metadata, + string originalAssetPath, + string sourceModAssetPath, + string destinationPath) + { + Metadata = metadata; + OriginalAssetPath = originalAssetPath; + SourceModAssetPath = sourceModAssetPath; + DestinationPath = destinationPath; + } + + public string GetOriginalAssetPath(string path) => Path.Combine(OriginalAssetPath, path); + public string GetSourceModAssetPath(string path) => Path.Combine(SourceModAssetPath, path); + public string GetDestinationPath(string path) => Path.Combine(DestinationPath, path); + public void EnsureDirectoryExists(string fileName) => Directory.CreateDirectory(Path.GetDirectoryName(fileName)); + public void CopyOriginalFile(string fileName) + { + var dstFile = GetDestinationPath(fileName); + EnsureDirectoryExists(dstFile); + + if (!File.Exists(dstFile)) + { + var originalFile = GetOriginalAssetPath(fileName); + if (File.Exists(originalFile)) + File.Copy(originalFile, dstFile); + } + } + } + + public void Patch(string originalAssets, string outputDir, string modFilePath) + { + var metadata = File.OpenRead(modFilePath).Using(Metadata.Read); + var modBasePath = Path.GetDirectoryName(modFilePath); + Patch(originalAssets, outputDir, metadata, modBasePath); + } + + public void Patch(string originalAssets, string outputDir, Metadata metadata, string modBasePath) + { + var context = new Context(metadata, originalAssets, modBasePath, outputDir); + try + { + if (metadata.Assets == null) + throw new Exception("No assets found."); + + metadata.Assets.AsParallel().ForAll(assetFile => + { + var names = new List(); + names.Add(assetFile.Name); + if (assetFile.Multi != null) + names.AddRange(assetFile.Multi.Select(x => x.Name).Where(x => !string.IsNullOrEmpty(x))); + + foreach (var name in names) + { + if (assetFile.Required && !File.Exists(context.GetOriginalAssetPath(name))) + continue; + + context.CopyOriginalFile(name); + var dstFile = context.GetDestinationPath(name); + + using var stream = File.Open(dstFile, FileMode.OpenOrCreate, FileAccess.ReadWrite); + PatchFile(context, assetFile, stream); + } + }); + } + catch (Exception ex) + { + Log.Err($"Patcher failed: {ex.Message}"); + throw new PatcherException(metadata, ex); + } + } + + private static void PatchFile(Context context, AssetFile assetFile, Stream stream) + { + if (assetFile == null) + throw new Exception("Asset file is null."); + + switch (assetFile.Method) + { + case "copy": + CopyFile(context, assetFile, stream); + break; + case "bar": + case "binarc": + PatchBinarc(context, assetFile, stream); + break; + case "imd": + case "imgd": + CreateImageImd(context, assetFile.Source[0]).Write(stream); + break; + case "imz": + case "imgz": + PatchImageImz(context, assetFile, stream); + break; + case "fac": + Imgd.WriteAsFac(stream, assetFile.Source.Select(x => CreateImageImd(context, x))); + break; + case "kh2msg": + PatchKh2Msg(context, assetFile.Source, stream); + break; + case "areadatascript": + PatchAreaDataScript(context, assetFile.Source, stream); + break; + default: + Log.Warn($"Method '{assetFile.Method}' not recognized for '{assetFile.Name}'. Falling back to 'copy'"); + CopyFile(context, assetFile, stream); + break; + } + + stream.SetLength(stream.Position); + } + + private static void CopyFile(Context context, AssetFile assetFile, Stream stream) + { + if (assetFile.Source == null || assetFile.Source.Count == 0) + throw new Exception($"File '{assetFile.Name}' does not contain any source"); + + var srcFile = context.GetSourceModAssetPath(assetFile.Source[0].Name); + if (!File.Exists(srcFile)) + throw new FileNotFoundException($"The mod does not contain the file {assetFile.Source[0].Name}", srcFile); + + using var srcStream = File.OpenRead(srcFile); + srcStream.CopyTo(stream); + } + + private static void PatchBinarc(Context context, AssetFile assetFile, Stream stream) + { + var binarc = Bar.IsValid(stream) ? Bar.Read(stream) : + new Bar() + { + Motionset = assetFile.MotionsetType + }; + + foreach (var file in assetFile.Source) + { + if (!Enum.TryParse(file.Type, true, out var barEntryType)) + throw new Exception($"BinArc type {file.Type} not recognized"); + + var entry = binarc.FirstOrDefault(x => x.Name == file.Name && x.Type == barEntryType); + if (entry == null) + { + entry = new Bar.Entry + { + Name = file.Name, + Type = barEntryType, + Stream = new MemoryStream() + }; + binarc.Add(entry); + } + + PatchFile(context, file, entry.Stream); + } + + Bar.Write(stream.SetPosition(0), binarc); + foreach (var entry in binarc) + entry.Stream?.Dispose(); + } + + private static Imgd CreateImageImd(Context context, AssetFile source) + { + var srcFile = context.GetSourceModAssetPath(source.Name); + using var srcStream = File.OpenRead(srcFile); + if (PngImage.IsValid(srcStream)) + { + var png = PngImage.Read(srcStream); + return Imgd.Create(png.Size, png.PixelFormat, png.GetData(), png.GetClut(), source.IsSwizzled); + } + else if (Imgd.IsValid(srcStream)) + return Imgd.Read(srcStream); + + throw new Exception($"Image source '{source.Name}' not recognized"); + } + + private static void PatchImageImz(Context context, AssetFile assetFile, Stream stream) + { + var index = 0; + var images = Imgz.IsValid(stream) ? Imgz.Read(stream).ToList() : new List(); + foreach (var source in assetFile.Source) + { + if (source.Index > 0) + index = source.Index; + + var imd = CreateImageImd(context, source); + if (images.Count <= index) + images.Add(imd); + else + images[index] = imd; + + index++; + } + + Imgz.Write(stream.SetPosition(0), images); + } + + private static void PatchKh2Msg(Context context, List sources, Stream stream) + { + var msgs = Msg.IsValid(stream) ? Msg.Read(stream) : new List(); + + foreach (var source in sources) + { + if (string.IsNullOrEmpty(source.Language)) + throw new Exception($"No language specified in '{source.Name}'"); + + var content = File.ReadAllText(context.GetSourceModAssetPath(source.Name)); + var patchedMsgs = new Deserializer().Deserialize>>(content); + foreach (var msg in patchedMsgs) + { + if (!msg.TryGetValue("id", out var strId)) + throw new Exception($"Source '{source.Name}' contains a message without an ID"); + if (!ushort.TryParse(strId, out var id)) + { + if (strId.Length > 2 && strId[1] == 'x') + { + if (!ushort.TryParse(strId.Substring(2), NumberStyles.HexNumber, null, out id)) + throw new Exception($"Message ID '{strId} in '{source.Name}' must be between 0 and 65535"); + } + else + throw new Exception($"Message ID '{strId} in '{source.Name}' must be between 0 and 65535"); + } + if (!msg.TryGetValue(source.Language, out var text)) + continue; + + var encoder = source.Language switch + { + "jp" => Encoders.JapaneseSystem, + "tr" => Encoders.TurkishSystem, + _ => Encoders.InternationalSystem, + }; + + var data = encoder.Encode(MsgSerializer.DeserializeText(text ?? string.Empty).ToList()); + var originalMsg = msgs.FirstOrDefault(x => x.Id == id); + if (originalMsg == null) + msgs.Add(new Msg.Entry + { + Id = id, + Data = data + }); + else + originalMsg.Data = data; + } + } + + Msg.WriteOptimized(stream.SetPosition(0), msgs); + } + + private static void PatchAreaDataScript(Context context, List sources, Stream stream) + { + var scripts = Kh2.Ard.AreaDataScript.IsValid(stream) ? + Kh2.Ard.AreaDataScript.Read(stream).ToDictionary(x => x.ProgramId, x => x) : + new Dictionary(); + foreach (var source in sources) + { + var programsInput = File.ReadAllText(context.GetSourceModAssetPath(source.Name)); + foreach (var newScript in Kh2.Ard.AreaDataScript.Compile(programsInput)) + scripts[newScript.ProgramId] = newScript; + } + + Kh2.Ard.AreaDataScript.Write(stream.SetPosition(0), scripts.Values); + } + } +} diff --git a/OpenKh.Ps2/VifUnpacker.cs b/OpenKh.Ps2/VifUnpacker.cs index 3c544259f..c655dbd40 100644 --- a/OpenKh.Ps2/VifUnpacker.cs +++ b/OpenKh.Ps2/VifUnpacker.cs @@ -1,358 +1,388 @@ -using OpenKh.Common; -using System; - -namespace OpenKh.Ps2 -{ - /// - /// EE_Users_Manual - /// 6.4 VIFcode Reference - /// - public class VifUnpacker - { - public enum State - { - End, - Run, - Interrupt, - Microprogram, - } - - public enum MaskType - { - Write, - Row, - Col, - Skip - } - - private struct VIFn_Cycle - { - public readonly byte CL; - public readonly byte WL; - - public bool IsSkippingWrite => CL >= WL; - public bool IsFillingWrite => CL < WL; - - public VIFn_Cycle(ushort immediate) - { - CL = (byte)(immediate & 0xFF); - WL = (byte)((immediate >> 8) & 0xFF); - } - } - - private struct VIFn_Mask - { - public VIFn_Mask(uint value) - { - Masks = new Vector4Mask[] - { - new Vector4Mask((value >> 0) & 0xff), - new Vector4Mask((value >> 8) & 0xff), - new Vector4Mask((value >> 16) & 0xff), - new Vector4Mask((value >> 24) & 0xff), - }; - } - - public Vector4Mask[] Masks { get; } - } - - private struct Vector4Mask - { - public Vector4Mask(uint value) - { - Mask = (byte)value; - } - - public byte Mask { get; } - - public MaskType X => (MaskType)((Mask >> 0) & 3); - public MaskType Y => (MaskType)((Mask >> 2) & 3); - public MaskType Z => (MaskType)((Mask >> 4) & 3); - public MaskType W => (MaskType)((Mask >> 6) & 3); - } - - private struct Opcode - { - private readonly uint _opcode; - - public ushort Immediate => (ushort)(_opcode & 0xffff); - public byte Num => (byte)((_opcode >> 16) & 0xff); - public byte Cmd => (byte)((_opcode >> 24) & 0x7f); - public bool Interrupt => _opcode >= 0x80000000; - - public bool IsUnpack => (Cmd & CmdMaskUnpack) == CmdMaskUnpack; - public uint UnpackAddress => _opcode & 0x1ff; - public bool UnpackIsUnsigned => (_opcode & 0x400) == 0; - public bool UnpackAddsTops => (_opcode & 0x800) != 0; - public uint UnpackVl => (_opcode >> 24) & 3; - public uint UnpackVn => (_opcode >> 26) & 3; - public bool UnpackMask => ((_opcode >> 28) & 1) != 0; - - public Opcode(uint opcode) - { - _opcode = opcode; - } - - public static Opcode Read(byte[] code, int pc) - { - var opcode = (uint)( - code[pc + 0] | - (code[pc + 1] << 8) | - (code[pc + 2] << 16) | - (code[pc + 3] << 24)); - - return new Opcode(opcode); - } - } - - private const int OpcodeAlignment = 0x4; - private const int VertexAlignment = 0x10; - - // Used to adjust the data alignment in the VIF packet - private const byte CmdNop = 0b0000000; - - // Writes the value of the immediate to VIFn_CYCLE register - private const byte CmdStcycl = 0b0000001; - - // Activates the microprogram - private const byte CmdMscal = 0b0010100; - - // Activates the microprogram - private const byte CmdMscnt = 0b0010111; - - // Sets the data mask pattern - private const byte CmdStmask = 0b0100000; - - // Sets the filling data for row registers - private const byte CmdStrow = 0b0110000; - - // Sets the filling data for column registers - private const byte CmdStcol = 0b0110001; - - // Transfer data to the VU Mem - private const byte CmdMaskUnpack = 0b1100000; - - private Func[] _readSigned; - private Func[] _readUnsigned; - private Action>[] _unpacker; - - private Vector4Mask DefaultMask = new Vector4Mask(0); - private readonly byte[] _code; - private readonly byte[] _mem = new byte[16 * 1024]; - private readonly uint[] _vifnCol; - private readonly uint[] _vifnRow; - private int _programCounter; - private VIFn_Cycle _vifnCycle; - private VIFn_Mask _vifnMask; - private int _destinationAddress; - private int _unpackMaskIndex; - private bool _enableMask; - - public VifUnpacker(byte[] code) - { - _code = code; - _programCounter = 0; - _vifnMask = new VIFn_Mask(0); - _vifnCol = new uint[4]; - _vifnRow = new uint[4]; - - _readSigned = new Func[] - { - ReadInt32, - ReadInt16, - ReadInt8, - ReadInt16, - }; - _readUnsigned = new Func[] - { - ReadUInt32, - ReadUInt16, - ReadUInt8, - ReadUInt16 - }; - _unpacker = new Action>[] - { - UnpackSingle, - UnpackVector2, - UnpackVector3, - UnpackVector4, - }; - } - - public byte[] Memory => _mem; - - public int Vif1_Tops { get; set; } - - private Vector4Mask NextMask() - { - if (_enableMask) - return _vifnMask.Masks[(_unpackMaskIndex++) & 3]; - - return DefaultMask; - } - - public State Run() - { - while (true) - { - var state = Step(); - if (state == State.End || - state == State.Microprogram) - return state; - } - } - - private State Step() - { - if (_programCounter >= _code.Length) - return State.End; - - var opcode = new Opcode(ReadUInt32()); - - if (opcode.IsUnpack) - { - Unpack(opcode); - } - else - { - switch (opcode.Cmd) - { - case CmdNop: - break; - case CmdStcycl: - // KH2 is not really using it.. so we are going to to the same. - _vifnCycle = new VIFn_Cycle(opcode.Immediate); - break; - case CmdMscal: - // opcode.Immediate needs to be used as execution address for the microprogram. - return State.Microprogram; - case CmdMscnt: - // The difference with Mscal is that the execution address will be the - // most recent end of the previous microcode execution. - return State.Microprogram; - case CmdStmask: - _vifnMask = new VIFn_Mask(ReadUInt32()); - break; - case CmdStrow: - _vifnRow[0] = ReadUInt32(); - _vifnRow[1] = ReadUInt32(); - _vifnRow[2] = ReadUInt32(); - _vifnRow[3] = ReadUInt32(); - break; - case CmdStcol: - _vifnCol[0] = ReadUInt32(); - _vifnCol[1] = ReadUInt32(); - _vifnCol[2] = ReadUInt32(); - _vifnCol[3] = ReadUInt32(); - break; - default: - throw new Exception($"VIF1 cmd {opcode.Cmd:X02}@{_programCounter:X} not implemented!"); - } - } - - return State.Run; - } - - private void Unpack(Opcode opcode) - { - _destinationAddress = (int)opcode.UnpackAddress; - //if (opcode.UnpackAddsTops) - _destinationAddress += Vif1_Tops; - _destinationAddress *= VertexAlignment; - _unpackMaskIndex = 0; - - var reader = opcode.UnpackIsUnsigned ? - _readUnsigned[opcode.UnpackVl] : - _readSigned[opcode.UnpackVl]; - var unpacker = _unpacker[opcode.UnpackVn]; - _enableMask = opcode.UnpackMask; - - for (var i = 0; i < opcode.Num; i++) - { - unpacker(reader); - } - - _programCounter = Helpers.Align(_programCounter, OpcodeAlignment); - } - - private uint ReadInt8() => (uint)(sbyte)_code[_programCounter++]; - private uint ReadUInt8() => _code[_programCounter++]; - private uint ReadInt16() => (uint)(short)( - _code[_programCounter++] | (_code[_programCounter++] << 8)); - private uint ReadUInt16() => (ushort)( - _code[_programCounter++] | (_code[_programCounter++] << 8)); - private uint ReadInt32() => (uint)( - _code[_programCounter++] | (_code[_programCounter++] << 8) | - (_code[_programCounter++] << 16) | (_code[_programCounter++] << 24)); - private uint ReadUInt32() => (uint)( - _code[_programCounter++] | (_code[_programCounter++] << 8) | - (_code[_programCounter++] << 16) | (_code[_programCounter++] << 24)); - - public void UnpackSingle(Func reader) - { - var currentMask = NextMask(); - var value = reader(); - - if (currentMask.X == MaskType.Write) Write(value); Next(); - if (currentMask.Y == MaskType.Write) Write(value); Next(); - if (currentMask.Z == MaskType.Write) Write(value); Next(); - if (currentMask.W == MaskType.Write) Write(value); Next(); - } - - public void UnpackVector2(Func reader) - { - var currentMask = NextMask(); - var x = reader(); - var y = reader(); - - if (currentMask.X == MaskType.Write) Write(x); Next(); - if (currentMask.Y == MaskType.Write) Write(y); Next(); - - // While PS2 docs says that the following two values will - // be indeterminate, PCSX2 seems to follow this exact - // logic. Probably to emulate an undefined behaviour. - // We are going to do the same, just in case. - if (currentMask.Z == MaskType.Write) Write(x); Next(); - if (currentMask.W == MaskType.Write) Write(y); Next(); - } - - private void UnpackVector3(Func reader) - { - var currentMask = NextMask(); - - if (currentMask.X == MaskType.Write) Write(reader()); Next(); - if (currentMask.Y == MaskType.Write) Write(reader()); Next(); - if (currentMask.Z == MaskType.Write) Write(reader()); Next(); - - // According to PCSX2, the following logic emulates the - // behaviour of the real hardware.. Time for some hacks! - if (currentMask.W == MaskType.Write) - { - var oldProgramCounter = _programCounter; - Write(reader()); // do not call Next() here! - _programCounter = oldProgramCounter; - } - - Next(); - } - - private void UnpackVector4(Func reader) - { - var currentMask = NextMask(); - - if (currentMask.X == MaskType.Write) Write(reader()); Next(); - if (currentMask.Y == MaskType.Write) Write(reader()); Next(); - if (currentMask.Z == MaskType.Write) Write(reader()); Next(); - if (currentMask.W == MaskType.Write) Write(reader()); Next(); - } - - private void Write(uint value) - { - _mem[_destinationAddress + 0] = (byte)(value & 0xff); - _mem[_destinationAddress + 1] = (byte)((value >> 8) & 0xff); - _mem[_destinationAddress + 2] = (byte)((value >> 16) & 0xff); - _mem[_destinationAddress + 3] = (byte)((value >> 24) & 0xff); - } - private void Next() => _destinationAddress += 4; - } -} +using OpenKh.Common; +using System; + +namespace OpenKh.Ps2 +{ + /// + /// EE_Users_Manual + /// 6.4 VIFcode Reference + /// + public class VifUnpacker + { + public enum State + { + End, + Run, + Interrupt, + Microprogram, + } + + public enum MaskType + { + Write, + Row, + Col, + Skip + } + + private struct VIFn_Cycle + { + public readonly byte CL; + public readonly byte WL; + + public bool IsSkippingWrite => CL >= WL; + public bool IsFillingWrite => CL < WL; + + public VIFn_Cycle(ushort immediate) + { + CL = (byte)(immediate & 0xFF); + WL = (byte)((immediate >> 8) & 0xFF); + } + } + + private struct VIFn_Mask + { + public VIFn_Mask(uint value) + { + Masks = new Vector4Mask[] + { + new Vector4Mask((value >> 0) & 0xff), + new Vector4Mask((value >> 8) & 0xff), + new Vector4Mask((value >> 16) & 0xff), + new Vector4Mask((value >> 24) & 0xff), + }; + } + + public Vector4Mask[] Masks { get; } + } + + private struct Vector4Mask + { + public Vector4Mask(uint value) + { + Mask = (byte)value; + } + + public byte Mask { get; } + + public MaskType X => (MaskType)((Mask >> 0) & 3); + public MaskType Y => (MaskType)((Mask >> 2) & 3); + public MaskType Z => (MaskType)((Mask >> 4) & 3); + public MaskType W => (MaskType)((Mask >> 6) & 3); + } + + private struct Opcode + { + private readonly uint _opcode; + + public ushort Immediate => (ushort)(_opcode & 0xffff); + public byte Num => (byte)((_opcode >> 16) & 0xff); + public byte Cmd => (byte)((_opcode >> 24) & 0x7f); + public bool Interrupt => _opcode >= 0x80000000; + + public bool IsUnpack => (Cmd & CmdMaskUnpack) == CmdMaskUnpack; + public uint UnpackAddress => _opcode & 0x1ff; + public bool UnpackIsUnsigned => (_opcode & 0x400) == 0; + public bool UnpackAddsTops => (_opcode & 0x800) != 0; + public uint UnpackVl => (_opcode >> 24) & 3; + public uint UnpackVn => (_opcode >> 26) & 3; + public bool UnpackMask => ((_opcode >> 28) & 1) != 0; + + public Opcode(uint opcode) + { + _opcode = opcode; + } + + public static Opcode Read(byte[] code, int pc) + { + var opcode = (uint)( + code[pc + 0] | + (code[pc + 1] << 8) | + (code[pc + 2] << 16) | + (code[pc + 3] << 24)); + + return new Opcode(opcode); + } + } + + private const int OpcodeAlignment = 0x4; + private const int VertexAlignment = 0x10; + + // Used to adjust the data alignment in the VIF packet + private const byte CmdNop = 0b0000000; + + // Writes the value of the immediate to VIFn_CYCLE register + private const byte CmdStcycl = 0b0000001; + + // Activates the microprogram + private const byte CmdMscal = 0b0010100; + + // Activates the microprogram + private const byte CmdMscnt = 0b0010111; + + // Sets the data mask pattern + private const byte CmdStmask = 0b0100000; + + // Sets the filling data for row registers + private const byte CmdStrow = 0b0110000; + + // Sets the filling data for column registers + private const byte CmdStcol = 0b0110001; + + // Transfer data to the VU Mem + private const byte CmdMaskUnpack = 0b1100000; + + private Func[] _readSigned; + private Func[] _readUnsigned; + private Action>[] _unpacker; + + private Vector4Mask DefaultMask = new Vector4Mask(0); + private readonly byte[] _code; + private readonly byte[] _mem = new byte[16 * 1024]; + private readonly uint[] _vifnCol; + private readonly uint[] _vifnRow; + private int _programCounter; + private VIFn_Cycle _vifnCycle; + private VIFn_Mask _vifnMask; + private int _destinationAddress; + private int _unpackMaskIndex; + private bool _enableMask; + + public VifUnpacker(byte[] code) + { + _code = code; + _programCounter = 0; + _vifnMask = new VIFn_Mask(0); + _vifnCol = new uint[4]; + _vifnRow = new uint[4]; + + _readSigned = new Func[] + { + ReadInt32, + ReadInt16, + ReadInt8, + ReadInt16, + }; + _readUnsigned = new Func[] + { + ReadUInt32, + ReadUInt16, + ReadUInt8, + ReadUInt16 + }; + _unpacker = new Action>[] + { + UnpackSingle, + UnpackVector2, + UnpackVector3, + UnpackVector4, + }; + } + + public byte[] Memory => _mem; + + public int Vif1_Tops { get; set; } + + private Vector4Mask NextMask() + { + if (_enableMask) + return _vifnMask.Masks[(_unpackMaskIndex++) & 3]; + + return DefaultMask; + } + + public State Run() + { + while (true) + { + var state = Step(); + if (state == State.End || + state == State.Microprogram) + return state; + } + } + + private State Step() + { + if (_programCounter >= _code.Length) + return State.End; + + var opcode = new Opcode(ReadUInt32()); + + if (opcode.IsUnpack) + { + Unpack(opcode); + } + else + { + switch (opcode.Cmd) + { + case CmdNop: + break; + case CmdStcycl: + // KH2 is not really using it.. so we are going to to the same. + _vifnCycle = new VIFn_Cycle(opcode.Immediate); + break; + case CmdMscal: + // opcode.Immediate needs to be used as execution address for the microprogram. + return State.Microprogram; + case CmdMscnt: + // The difference with Mscal is that the execution address will be the + // most recent end of the previous microcode execution. + return State.Microprogram; + case CmdStmask: + _vifnMask = new VIFn_Mask(ReadUInt32()); + break; + case CmdStrow: + _vifnRow[0] = ReadUInt32(); + _vifnRow[1] = ReadUInt32(); + _vifnRow[2] = ReadUInt32(); + _vifnRow[3] = ReadUInt32(); + break; + case CmdStcol: + _vifnCol[0] = ReadUInt32(); + _vifnCol[1] = ReadUInt32(); + _vifnCol[2] = ReadUInt32(); + _vifnCol[3] = ReadUInt32(); + break; + default: + throw new Exception($"VIF1 cmd {opcode.Cmd:X02}@{_programCounter:X} not implemented!"); + } + } + + return State.Run; + } + + private void Unpack(Opcode opcode) + { + _destinationAddress = (int)opcode.UnpackAddress; + //if (opcode.UnpackAddsTops) + _destinationAddress += Vif1_Tops; + _destinationAddress *= VertexAlignment; + _unpackMaskIndex = 0; + + var reader = opcode.UnpackIsUnsigned ? + _readUnsigned[opcode.UnpackVl] : + _readSigned[opcode.UnpackVl]; + var unpacker = _unpacker[opcode.UnpackVn]; + _enableMask = opcode.UnpackMask; + + for (var i = 0; i < opcode.Num; i++) + { + unpacker(reader); + } + + _programCounter = Helpers.Align(_programCounter, OpcodeAlignment); + } + + private uint ReadInt8() => (uint)(sbyte)_code[_programCounter++]; + private uint ReadUInt8() => _code[_programCounter++]; + private uint ReadInt16() => (uint)(short)( + _code[_programCounter++] | (_code[_programCounter++] << 8)); + private uint ReadUInt16() => (ushort)( + _code[_programCounter++] | (_code[_programCounter++] << 8)); + private uint ReadInt32() => (uint)( + _code[_programCounter++] | (_code[_programCounter++] << 8) | + (_code[_programCounter++] << 16) | (_code[_programCounter++] << 24)); + private uint ReadUInt32() => (uint)( + _code[_programCounter++] | (_code[_programCounter++] << 8) | + (_code[_programCounter++] << 16) | (_code[_programCounter++] << 24)); + + public void UnpackSingle(Func reader) + { + var currentMask = NextMask(); + var value = reader(); + + if (currentMask.X == MaskType.Write) + Write(value); + Next(); + if (currentMask.Y == MaskType.Write) + Write(value); + Next(); + if (currentMask.Z == MaskType.Write) + Write(value); + Next(); + if (currentMask.W == MaskType.Write) + Write(value); + Next(); + } + + public void UnpackVector2(Func reader) + { + var currentMask = NextMask(); + var x = reader(); + var y = reader(); + + if (currentMask.X == MaskType.Write) + Write(x); + Next(); + if (currentMask.Y == MaskType.Write) + Write(y); + Next(); + + // While PS2 docs says that the following two values will + // be indeterminate, PCSX2 seems to follow this exact + // logic. Probably to emulate an undefined behaviour. + // We are going to do the same, just in case. + if (currentMask.Z == MaskType.Write) + Write(x); + Next(); + if (currentMask.W == MaskType.Write) + Write(y); + Next(); + } + + private void UnpackVector3(Func reader) + { + var currentMask = NextMask(); + + if (currentMask.X == MaskType.Write) + Write(reader()); + Next(); + if (currentMask.Y == MaskType.Write) + Write(reader()); + Next(); + if (currentMask.Z == MaskType.Write) + Write(reader()); + Next(); + + // According to PCSX2, the following logic emulates the + // behaviour of the real hardware.. Time for some hacks! + if (currentMask.W == MaskType.Write) + { + var oldProgramCounter = _programCounter; + Write(reader()); // do not call Next() here! + _programCounter = oldProgramCounter; + } + + Next(); + } + + private void UnpackVector4(Func reader) + { + var currentMask = NextMask(); + + if (currentMask.X == MaskType.Write) + Write(reader()); + Next(); + if (currentMask.Y == MaskType.Write) + Write(reader()); + Next(); + if (currentMask.Z == MaskType.Write) + Write(reader()); + Next(); + if (currentMask.W == MaskType.Write) + Write(reader()); + Next(); + } + + private void Write(uint value) + { + _mem[_destinationAddress + 0] = (byte)(value & 0xff); + _mem[_destinationAddress + 1] = (byte)((value >> 8) & 0xff); + _mem[_destinationAddress + 2] = (byte)((value >> 16) & 0xff); + _mem[_destinationAddress + 3] = (byte)((value >> 24) & 0xff); + } + private void Next() => _destinationAddress += 4; + } +} diff --git a/OpenKh.Ps2/VpuPacket.cs b/OpenKh.Ps2/VpuPacket.cs index c4decac23..de1eb60a6 100644 --- a/OpenKh.Ps2/VpuPacket.cs +++ b/OpenKh.Ps2/VpuPacket.cs @@ -1,151 +1,151 @@ -using OpenKh.Common; -using System; -using System.IO; -using System.Linq; -using Xe.BinaryMapper; - -namespace OpenKh.Ps2 -{ - public class VpuPacket - { - public enum VertexFunction - { - DrawTriangleDoubleSided = 0x00, - Stock = 0x10, - DrawTriangle = 0x20, - DrawTriangleInverse = 0x30 - } - - public class VpuHeader - { - [Data] public int Type { get; set; } - [Data] public int Unknown04 { get; set; } - [Data] public int Unknown08 { get; set; } - [Data] public int Unknown0c { get; set; } - [Data] public int IndexCount { get; set; } - [Data] public int IndexLocation { get; set; } - [Data] public int UnkBoxLocation { get; set; } - [Data] public int Unknown1cLocation { get; set; } - [Data] public int ColorCount { get; set; } - [Data] public int ColorLocation { get; set; } - [Data] public int VertexMixerCount { get; set; } - [Data] public int VertexMixerOffset { get; set; } - [Data] public int VertexCount { get; set; } - [Data] public int VertexLocation { get; set; } - [Data] public int Unknown38 { get; set; } - [Data] public int UnkBoxCount { get; set; } - } - - public class VertexIndex - { - [Data] public int U { get; set; } - [Data] public int V { get; set; } - [Data] public int Index { get; set; } - [Data] public VertexFunction Function { get; set; } - - public override string ToString() => - $"{U / 4096.0f:F}, {V / 4096.0f:F}, {Index:X}, {Function}"; - } - - public class VertexColor - { - [Data] public int R { get; set; } - [Data] public int G { get; set; } - [Data] public int B { get; set; } - [Data] public int A { get; set; } - - public override string ToString() => - $"{R:X}, {G:X}, {B:X}, {A:X}"; - } - - public class VertexCoord - { - [Data] public float X { get; set; } - [Data] public float Y { get; set; } - [Data] public float Z { get; set; } - [Data] public float W { get; set; } - - public override string ToString() => - $"{X:F}, {Y:F}, {Z:F}, {W:F}"; - } - - public VertexIndex[] Indices { get; } - public VertexColor[] Colors { get; } - public VertexCoord[] Vertices { get; } - public int[] VertexRange { get; } - public int VertexWeightedCount { get; } - public int[][][] VertexWeightedIndices { get; } - - private VpuPacket(Stream stream) - { - var vpu = BinaryMapping.ReadObject(stream); - - VertexRange = Read(stream, vpu.UnkBoxLocation, vpu.UnkBoxCount, ReadInt32); - Indices = Read(stream, vpu.IndexLocation, vpu.IndexCount, ReadIndex); - Colors = Read(stream, vpu.ColorLocation, vpu.ColorCount, ReadColor); - Vertices = Read(stream, vpu.VertexLocation, vpu.VertexCount, ReadVertex); - - if (vpu.VertexMixerCount > 0) - { - var countPerAmount = Read(stream, vpu.VertexMixerOffset, vpu.VertexMixerCount, ReadInt32); - VertexWeightedCount = countPerAmount.Sum(); - - VertexWeightedIndices = countPerAmount - .Select((count, amount) => - { - stream.AlignPosition(0x10); - return Enumerable - .Range(0, count) - .Select(x => Enumerable.Range(0, amount + 1).Select(y => stream.ReadInt32()).ToArray()) - .ToArray(); - }) - .ToArray(); - - } - - //Debug.Assert(vpu.VertexCount == Box.Sum()); - } - - private static int ReadInt32(Stream stream) => stream.ReadInt32(); - - private static VertexIndex ReadIndex(Stream stream) => new VertexIndex - { - U = stream.ReadInt32(), - V = stream.ReadInt32(), - Index = stream.ReadInt32(), - Function = (VertexFunction)stream.ReadInt32() - }; - - private static VertexColor ReadColor(Stream stream) => new VertexColor - { - R = stream.ReadInt32(), - G = stream.ReadInt32(), - B = stream.ReadInt32(), - A = stream.ReadInt32(), - }; - - private static VertexCoord ReadVertex(Stream stream) => new VertexCoord - { - X = stream.ReadSingle(), - Y = stream.ReadSingle(), - Z = stream.ReadSingle(), - W = stream.ReadSingle(), - }; - - private static T[] Read(Stream stream, int offset, int count, Func func) - { - stream.SetPosition(offset * 0x10); - var array = new T[count]; - for (var i = 0; i < count; i++) - array[i] = func(stream); - - return array; - } - - public static VpuPacket Read(Stream stream) => - new VpuPacket(stream); - - public static VpuHeader Header(Stream stream) => - BinaryMapping.ReadObject(stream); - } -} +using OpenKh.Common; +using System; +using System.IO; +using System.Linq; +using Xe.BinaryMapper; + +namespace OpenKh.Ps2 +{ + public class VpuPacket + { + public enum VertexFunction + { + DrawTriangleDoubleSided = 0x00, + Stock = 0x10, + DrawTriangle = 0x20, + DrawTriangleInverse = 0x30 + } + + public class VpuHeader + { + [Data] public int Type { get; set; } + [Data] public int Unknown04 { get; set; } + [Data] public int Unknown08 { get; set; } + [Data] public int Unknown0c { get; set; } + [Data] public int IndexCount { get; set; } + [Data] public int IndexLocation { get; set; } + [Data] public int UnkBoxLocation { get; set; } + [Data] public int Unknown1cLocation { get; set; } + [Data] public int ColorCount { get; set; } + [Data] public int ColorLocation { get; set; } + [Data] public int VertexMixerCount { get; set; } + [Data] public int VertexMixerOffset { get; set; } + [Data] public int VertexCount { get; set; } + [Data] public int VertexLocation { get; set; } + [Data] public int Unknown38 { get; set; } + [Data] public int UnkBoxCount { get; set; } + } + + public class VertexIndex + { + [Data] public int U { get; set; } + [Data] public int V { get; set; } + [Data] public int Index { get; set; } + [Data] public VertexFunction Function { get; set; } + + public override string ToString() => + $"{U / 4096.0f:F}, {V / 4096.0f:F}, {Index:X}, {Function}"; + } + + public class VertexColor + { + [Data] public int R { get; set; } + [Data] public int G { get; set; } + [Data] public int B { get; set; } + [Data] public int A { get; set; } + + public override string ToString() => + $"{R:X}, {G:X}, {B:X}, {A:X}"; + } + + public class VertexCoord + { + [Data] public float X { get; set; } + [Data] public float Y { get; set; } + [Data] public float Z { get; set; } + [Data] public float W { get; set; } + + public override string ToString() => + $"{X:F}, {Y:F}, {Z:F}, {W:F}"; + } + + public VertexIndex[] Indices { get; } + public VertexColor[] Colors { get; } + public VertexCoord[] Vertices { get; } + public int[] VertexRange { get; } + public int VertexWeightedCount { get; } + public int[][][] VertexWeightedIndices { get; } + + private VpuPacket(Stream stream) + { + var vpu = BinaryMapping.ReadObject(stream); + + VertexRange = Read(stream, vpu.UnkBoxLocation, vpu.UnkBoxCount, ReadInt32); + Indices = Read(stream, vpu.IndexLocation, vpu.IndexCount, ReadIndex); + Colors = Read(stream, vpu.ColorLocation, vpu.ColorCount, ReadColor); + Vertices = Read(stream, vpu.VertexLocation, vpu.VertexCount, ReadVertex); + + if (vpu.VertexMixerCount > 0) + { + var countPerAmount = Read(stream, vpu.VertexMixerOffset, vpu.VertexMixerCount, ReadInt32); + VertexWeightedCount = countPerAmount.Sum(); + + VertexWeightedIndices = countPerAmount + .Select((count, amount) => + { + stream.AlignPosition(0x10); + return Enumerable + .Range(0, count) + .Select(x => Enumerable.Range(0, amount + 1).Select(y => stream.ReadInt32()).ToArray()) + .ToArray(); + }) + .ToArray(); + + } + + //Debug.Assert(vpu.VertexCount == Box.Sum()); + } + + private static int ReadInt32(Stream stream) => stream.ReadInt32(); + + private static VertexIndex ReadIndex(Stream stream) => new VertexIndex + { + U = stream.ReadInt32(), + V = stream.ReadInt32(), + Index = stream.ReadInt32(), + Function = (VertexFunction)stream.ReadInt32() + }; + + private static VertexColor ReadColor(Stream stream) => new VertexColor + { + R = stream.ReadInt32(), + G = stream.ReadInt32(), + B = stream.ReadInt32(), + A = stream.ReadInt32(), + }; + + private static VertexCoord ReadVertex(Stream stream) => new VertexCoord + { + X = stream.ReadSingle(), + Y = stream.ReadSingle(), + Z = stream.ReadSingle(), + W = stream.ReadSingle(), + }; + + private static T[] Read(Stream stream, int offset, int count, Func func) + { + stream.SetPosition(offset * 0x10); + var array = new T[count]; + for (var i = 0; i < count; i++) + array[i] = func(stream); + + return array; + } + + public static VpuPacket Read(Stream stream) => + new VpuPacket(stream); + + public static VpuHeader Header(Stream stream) => + BinaryMapping.ReadObject(stream); + } +} diff --git a/OpenKh.Ps2/VpuPacketExtensions.cs b/OpenKh.Ps2/VpuPacketExtensions.cs index 07b3bc79d..1c7eeb7d7 100644 --- a/OpenKh.Ps2/VpuPacketExtensions.cs +++ b/OpenKh.Ps2/VpuPacketExtensions.cs @@ -1,58 +1,58 @@ -using System.Linq; - -namespace OpenKh.Ps2 -{ - public class VertexBox - { - public int MatrixIndex { get; set; } - public int[] VertexIndices { get; set; } - } - - public class VertexIndexWeighted - { - public int MatrixIndex { get; set; } - public int VertexIndex { get; set; } - } - - public static class VpuPacketExtensions - { - public static VertexBox[] GetFromMatrixIndices(this VpuPacket vpu, int[] matrixIndices) - { - var matrixVertices = new VertexBox[vpu.VertexRange.Length]; - for (int i = 0, j = 0; i < vpu.VertexRange.Length; i++) - { - matrixVertices[i] = new VertexBox - { - MatrixIndex = matrixIndices[i], - VertexIndices = Enumerable.Range(j, vpu.VertexRange[i]).ToArray() - }; - j += vpu.VertexRange[i]; - } - - return matrixVertices; - } - - public static VertexIndexWeighted[][] GetWeightedVertices(this VpuPacket vpu, VertexBox[] vertices) - { - var flatVertices = vertices.SelectMany(x => x.VertexIndices, (x, vertexIndex) => new VertexIndexWeighted[] - { - new VertexIndexWeighted - { - MatrixIndex = x.MatrixIndex, - VertexIndex = vertexIndex - } - }).ToArray(); - - if ((vpu.VertexWeightedIndices?.Length ?? 0) == 0) - return flatVertices; - - var index = 0; - var outVertices = new VertexIndexWeighted[vpu.VertexWeightedCount][]; - foreach (var slice in vpu.VertexWeightedIndices) - foreach (var desc in slice) - outVertices[index++] = desc.Select(x => flatVertices[x][0]).ToArray(); - - return outVertices; - } - } -} +using System.Linq; + +namespace OpenKh.Ps2 +{ + public class VertexBox + { + public int MatrixIndex { get; set; } + public int[] VertexIndices { get; set; } + } + + public class VertexIndexWeighted + { + public int MatrixIndex { get; set; } + public int VertexIndex { get; set; } + } + + public static class VpuPacketExtensions + { + public static VertexBox[] GetFromMatrixIndices(this VpuPacket vpu, int[] matrixIndices) + { + var matrixVertices = new VertexBox[vpu.VertexRange.Length]; + for (int i = 0, j = 0; i < vpu.VertexRange.Length; i++) + { + matrixVertices[i] = new VertexBox + { + MatrixIndex = matrixIndices[i], + VertexIndices = Enumerable.Range(j, vpu.VertexRange[i]).ToArray() + }; + j += vpu.VertexRange[i]; + } + + return matrixVertices; + } + + public static VertexIndexWeighted[][] GetWeightedVertices(this VpuPacket vpu, VertexBox[] vertices) + { + var flatVertices = vertices.SelectMany(x => x.VertexIndices, (x, vertexIndex) => new VertexIndexWeighted[] + { + new VertexIndexWeighted + { + MatrixIndex = x.MatrixIndex, + VertexIndex = vertexIndex + } + }).ToArray(); + + if ((vpu.VertexWeightedIndices?.Length ?? 0) == 0) + return flatVertices; + + var index = 0; + var outVertices = new VertexIndexWeighted[vpu.VertexWeightedCount][]; + foreach (var slice in vpu.VertexWeightedIndices) + foreach (var desc in slice) + outVertices[index++] = desc.Select(x => flatVertices[x][0]).ToArray(); + + return outVertices; + } + } +} diff --git a/OpenKh.Research.Kh2Anim/Models/MotionExport.cs b/OpenKh.Research.Kh2Anim/Models/MotionExport.cs index 70f3d78a7..bab72f399 100644 --- a/OpenKh.Research.Kh2Anim/Models/MotionExport.cs +++ b/OpenKh.Research.Kh2Anim/Models/MotionExport.cs @@ -1,34 +1,34 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml.Serialization; - -namespace OpenKh.Research.Kh2Anim.Models -{ - [XmlRoot] - public class MotionExport - { - [XmlElement] - public FrameClass[] Frame; - - [XmlAttribute] - public float FrameLoop; - [XmlAttribute] - public float FrameEnd; - [XmlAttribute] - public float FramePerSecond; - [XmlAttribute] - public float FrameCount; - [XmlAttribute] - public int MatrixCount; - - public class FrameClass - { - [XmlAttribute] - public float Time; - - [XmlElement] - public string Matrices; - } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml.Serialization; + +namespace OpenKh.Research.Kh2Anim.Models +{ + [XmlRoot] + public class MotionExport + { + [XmlElement] + public FrameClass[] Frame; + + [XmlAttribute] + public float FrameLoop; + [XmlAttribute] + public float FrameEnd; + [XmlAttribute] + public float FramePerSecond; + [XmlAttribute] + public float FrameCount; + [XmlAttribute] + public int MatrixCount; + + public class FrameClass + { + [XmlAttribute] + public float Time; + + [XmlElement] + public string Matrices; + } + } +} diff --git a/OpenKh.Research.Kh2Anim/Program.cs b/OpenKh.Research.Kh2Anim/Program.cs index bf862db4f..14857f2bd 100644 --- a/OpenKh.Research.Kh2Anim/Program.cs +++ b/OpenKh.Research.Kh2Anim/Program.cs @@ -1,61 +1,61 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Common; -using OpenKh.Common.Exceptions; -using OpenKh.Kh2; -using OpenKh.Kh2Anim.Mset; -using OpenKh.Kh2Anim.Mset.Interfaces; -using OpenKh.Research.Kh2Anim.Models; -using OpenKh.Research.Kh2Anim.Subcommands; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Linq; -using System.Numerics; -using System.Reflection; -using System.Xml.Serialization; - -namespace OpenKh.Research.Kh2Anim -{ - [Command("OpenKh.Research.Kh2Anim")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - [Subcommand( - typeof(BakeCommand), - typeof(FryCommand), - typeof(SimpleMdlxCommand) - )] - class Program - { - static int Main(string[] args) - { - try - { - return CommandLineApplication.Execute(args); - } - catch (InvalidFileException e) - { - Console.WriteLine(e.Message); - return 3; - } - catch (FileNotFoundException e) - { - Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); - return 2; - } - catch (Exception e) - { - Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); - return -1; - } - } - - protected int OnExecute(CommandLineApplication app) - { - app.ShowHelp(); - return 1; - } - - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Common; +using OpenKh.Common.Exceptions; +using OpenKh.Kh2; +using OpenKh.Kh2Anim.Mset; +using OpenKh.Kh2Anim.Mset.Interfaces; +using OpenKh.Research.Kh2Anim.Models; +using OpenKh.Research.Kh2Anim.Subcommands; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; +using System.Numerics; +using System.Reflection; +using System.Xml.Serialization; + +namespace OpenKh.Research.Kh2Anim +{ + [Command("OpenKh.Research.Kh2Anim")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + [Subcommand( + typeof(BakeCommand), + typeof(FryCommand), + typeof(SimpleMdlxCommand) + )] + class Program + { + static int Main(string[] args) + { + try + { + return CommandLineApplication.Execute(args); + } + catch (InvalidFileException e) + { + Console.WriteLine(e.Message); + return 3; + } + catch (FileNotFoundException e) + { + Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit."); + return 2; + } + catch (Exception e) + { + Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}"); + return -1; + } + } + + protected int OnExecute(CommandLineApplication app) + { + app.ShowHelp(); + return 1; + } + + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + } +} diff --git a/OpenKh.Research.Kh2Anim/Subcommands/BakeCommand.cs b/OpenKh.Research.Kh2Anim/Subcommands/BakeCommand.cs index 134e41e00..e48f70ef8 100644 --- a/OpenKh.Research.Kh2Anim/Subcommands/BakeCommand.cs +++ b/OpenKh.Research.Kh2Anim/Subcommands/BakeCommand.cs @@ -1,159 +1,159 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Kh2Anim.Mset; -using OpenKh.Research.Kh2Anim.Models; -using OpenKh.Research.Kh2Anim.Utils; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Xml.Serialization; - -namespace OpenKh.Research.Kh2Anim.Subcommands -{ - [HelpOption] - [Command(Description = "Bake motion as Matrix4x4, and then write them into xml file")] - class BakeCommand - { - [Required] - [FileExists] - [Argument(0, Description = "Input file: model.mdlx")] - public string InputMdlx { get; set; } - - [Required] - [FileExists] - [Argument(1, Description = "Input file: model.{mset,anb}")] - public string InputAnim { get; set; } - - [Argument(2, Description = "XML Output dir")] - public string OutputDir { get; set; } - - [Option(CommandOptionType.SingleValue, Description = "Frames per second")] - public float FPS { get; set; } = 0; - - protected int OnExecute(CommandLineApplication app) - { - var mdlxBytes = File.ReadAllBytes(InputMdlx); - - OutputDir ??= Path.Combine(Path.GetDirectoryName(InputAnim), Path.GetFileNameWithoutExtension(InputAnim)); - - Directory.CreateDirectory(OutputDir); - - var unkBarEntries = File.OpenRead(InputAnim).Using(Bar.Read); - - ConvertAnbOrMsetIntoMset(unkBarEntries) - .ForEach( - wrapper => - { - var anbIndir = new AnbIndir(wrapper.BarEntries); - - if (!anbIndir.HasAnimationData) - { - return; - } - - var provider = anbIndir.GetAnimProvider( - new MemoryStream(mdlxBytes, false) - ); - - var xmlFile = Path.Combine(OutputDir, $"{wrapper.IndexInMset}.xml"); - - if (FPS == 0) - { - FPS = 30; - } - - var gameTimeDelta = 1 / FPS; - - var timeArray = Enumerable.Range(0, (int)(provider.FrameEnd * FPS)) - .Select(it => (float)(it * gameTimeDelta)); - - var export = new MotionExport - { - FrameCount = provider.FrameCount, - FrameEnd = provider.FrameEnd, - FrameLoop = provider.FrameLoop, - FramePerSecond = provider.FramePerSecond, - MatrixCount = provider.MatrixCount, - - Frame = timeArray - .Select( - time => - { - var matrixArray = provider.ProvideMatrices(gameTimeDelta); - return new MotionExport.FrameClass - { - Time = time, - Matrices = MatrixArrayToString(matrixArray), - }; - } - ) - .ToArray(), - }; - - File.Create(xmlFile).Using( - stream => new XmlSerializer(typeof(MotionExport)).Serialize(stream, export) - ); - } - ); - - return 0; - } - - private string MatrixArrayToString(Matrix4x4[] matrixArray) - { - return string.Join( - ",", - matrixArray - .Select( - matrix => string.Join( - " " - , $"{matrix.M11}" - , $"{matrix.M12}" - , $"{matrix.M13}" - , $"{matrix.M14}" - , $"{matrix.M21}" - , $"{matrix.M22}" - , $"{matrix.M23}" - , $"{matrix.M24}" - , $"{matrix.M31}" - , $"{matrix.M32}" - , $"{matrix.M33}" - , $"{matrix.M34}" - , $"{matrix.M41}" - , $"{matrix.M42}" - , $"{matrix.M43}" - , $"{matrix.M44}" - ) - ) - ); - } - - private static IEnumerable ConvertAnbOrMsetIntoMset(IEnumerable unkBarEntries) - { - return unkBarEntries.Any(entry => entry.Type == Bar.EntryType.Motion) - // Input is `.anb` - ? new AnbBarWrapper[] { - new AnbBarWrapper { - BarEntries = unkBarEntries.ToList(), - IndexInMset = 0, - } - } - // Input is `.mset` - : unkBarEntries - .Select( - (msetBarEntry, index) => new AnbBarWrapper - { - IndexInMset = index, - BarEntries = (msetBarEntry.Stream.Length != 0) - ? Bar.Read(msetBarEntry.Stream) - : new List() - } - ); - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Kh2Anim.Mset; +using OpenKh.Research.Kh2Anim.Models; +using OpenKh.Research.Kh2Anim.Utils; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Xml.Serialization; + +namespace OpenKh.Research.Kh2Anim.Subcommands +{ + [HelpOption] + [Command(Description = "Bake motion as Matrix4x4, and then write them into xml file")] + class BakeCommand + { + [Required] + [FileExists] + [Argument(0, Description = "Input file: model.mdlx")] + public string InputMdlx { get; set; } + + [Required] + [FileExists] + [Argument(1, Description = "Input file: model.{mset,anb}")] + public string InputAnim { get; set; } + + [Argument(2, Description = "XML Output dir")] + public string OutputDir { get; set; } + + [Option(CommandOptionType.SingleValue, Description = "Frames per second")] + public float FPS { get; set; } = 0; + + protected int OnExecute(CommandLineApplication app) + { + var mdlxBytes = File.ReadAllBytes(InputMdlx); + + OutputDir ??= Path.Combine(Path.GetDirectoryName(InputAnim), Path.GetFileNameWithoutExtension(InputAnim)); + + Directory.CreateDirectory(OutputDir); + + var unkBarEntries = File.OpenRead(InputAnim).Using(Bar.Read); + + ConvertAnbOrMsetIntoMset(unkBarEntries) + .ForEach( + wrapper => + { + var anbIndir = new AnbIndir(wrapper.BarEntries); + + if (!anbIndir.HasAnimationData) + { + return; + } + + var provider = anbIndir.GetAnimProvider( + new MemoryStream(mdlxBytes, false) + ); + + var xmlFile = Path.Combine(OutputDir, $"{wrapper.IndexInMset}.xml"); + + if (FPS == 0) + { + FPS = 30; + } + + var gameTimeDelta = 1 / FPS; + + var timeArray = Enumerable.Range(0, (int)(provider.FrameEnd * FPS)) + .Select(it => (float)(it * gameTimeDelta)); + + var export = new MotionExport + { + FrameCount = provider.FrameCount, + FrameEnd = provider.FrameEnd, + FrameLoop = provider.FrameLoop, + FramePerSecond = provider.FramePerSecond, + MatrixCount = provider.MatrixCount, + + Frame = timeArray + .Select( + time => + { + var matrixArray = provider.ProvideMatrices(gameTimeDelta); + return new MotionExport.FrameClass + { + Time = time, + Matrices = MatrixArrayToString(matrixArray), + }; + } + ) + .ToArray(), + }; + + File.Create(xmlFile).Using( + stream => new XmlSerializer(typeof(MotionExport)).Serialize(stream, export) + ); + } + ); + + return 0; + } + + private string MatrixArrayToString(Matrix4x4[] matrixArray) + { + return string.Join( + ",", + matrixArray + .Select( + matrix => string.Join( + " " + , $"{matrix.M11}" + , $"{matrix.M12}" + , $"{matrix.M13}" + , $"{matrix.M14}" + , $"{matrix.M21}" + , $"{matrix.M22}" + , $"{matrix.M23}" + , $"{matrix.M24}" + , $"{matrix.M31}" + , $"{matrix.M32}" + , $"{matrix.M33}" + , $"{matrix.M34}" + , $"{matrix.M41}" + , $"{matrix.M42}" + , $"{matrix.M43}" + , $"{matrix.M44}" + ) + ) + ); + } + + private static IEnumerable ConvertAnbOrMsetIntoMset(IEnumerable unkBarEntries) + { + return unkBarEntries.Any(entry => entry.Type == Bar.EntryType.Motion) + // Input is `.anb` + ? new AnbBarWrapper[] { + new AnbBarWrapper { + BarEntries = unkBarEntries.ToList(), + IndexInMset = 0, + } + } + // Input is `.mset` + : unkBarEntries + .Select( + (msetBarEntry, index) => new AnbBarWrapper + { + IndexInMset = index, + BarEntries = (msetBarEntry.Stream.Length != 0) + ? Bar.Read(msetBarEntry.Stream) + : new List() + } + ); + } + } +} diff --git a/OpenKh.Research.Kh2Anim/Subcommands/FryCommand.cs b/OpenKh.Research.Kh2Anim/Subcommands/FryCommand.cs index d1a6476c8..741473a34 100644 --- a/OpenKh.Research.Kh2Anim/Subcommands/FryCommand.cs +++ b/OpenKh.Research.Kh2Anim/Subcommands/FryCommand.cs @@ -1,217 +1,217 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Kh2; -using OpenKh.Kh2Anim.Mset; -using OpenKh.Kh2Anim.Mset.Interfaces; -using OpenKh.Research.Kh2Anim.Models; -using OpenKh.Research.Kh2Anim.TypeConverters; -using OpenKh.Research.Kh2Anim.Utils; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Text; -using static OpenKh.Kh2.Motion; - -namespace OpenKh.Research.Kh2Anim.Subcommands -{ - [HelpOption] - [Command(Description = "Fry fake motion")] - class FryCommand - { - [Option(CommandOptionType.SingleValue, ShortName = "o", Description = "Output file: model.mset")] - public string OutputMset { get; set; } - - [Option(CommandOptionType.SingleValue, ShortName = "l", Description = "Unknown")] - public float FrameLoop { get; set; } = 0; - - [Option(CommandOptionType.SingleValue, ShortName = "e", Description = "Unknown")] - public float FrameEnd { get; set; } = 100; - - [Option(CommandOptionType.SingleValue, ShortName = "c", Description = "Unknown")] - public float FrameCount { get; set; } = 0; - - [Option(CommandOptionType.SingleValue, ShortName = "a", Description = "Unknown")] - public int TotalFrameCount { get; set; } = 100; - - [Option(CommandOptionType.SingleValue, ShortName = "f", Description = "FPS")] - public float FramePerSecond { get; set; } = 1; - - [Option(CommandOptionType.MultipleValue, ShortName = "t", Description = "Interpolation,FrameTime,Value,TangentEaseIn,TangentEaseOut\n(Nearest|Linear|Hermite|Zero),0.00,0.00,0.00,0.00")] - public string[] Timeline { get; set; } - - [Option(CommandOptionType.SingleValue, ShortName = "p", Description = "Output gnuplot file set with this file path prefix")] - public string Prefix { get; set; } - - [Option(CommandOptionType.SingleValue, ShortName = "u", Description = "Unknown")] - public byte Pre { get; set; } = 0; - - [Option(CommandOptionType.SingleValue, ShortName = "v", Description = "Unknown")] - public byte Post { get; set; } = 0; - - [Option(CommandOptionType.SingleValue, ShortName = "n", Description = "StaticPose value")] - public float InitialValue { get; set; } = 0; - - [Option(CommandOptionType.SingleValue, ShortName = "m", Description = "The value directly set to matrix")] - public float MatrixValue { get; set; } = 0; - - protected int OnExecute(CommandLineApplication app) - { - FramePerSecond = Math.Max(1, FramePerSecond); - - if (Timeline == null || Timeline?.Length == 0) - { - Timeline = new string[] { $"Linear,{FrameLoop},0,0,0", $"Linear,{FrameEnd},100,0,0" }; - } - - var mdlxFile = MdlxMaker.CreateMdlxHaving2Bones(tx: MatrixValue); - - var motion = Motion.CreateInterpolatedFromScratch(); - var interpolated = motion.Interpolated; - interpolated.ModelBoneAnimation.Add( - new BoneAnimationTable - { - JointIndex = 1, - Channel = (byte)(6 | ((3 & Pre) << 4) | ((3 & Post) << 6)), - TimelineStartIndex = 0, - TimelineCount = Convert.ToByte(Timeline.Length), - } - ); - interpolated.BoneCount = 2; - interpolated.FrameCount = FrameCount; - interpolated.FrameEnd = FrameEnd; - interpolated.FrameLoop = FrameLoop; - interpolated.FramePerSecond = FramePerSecond; - interpolated.StaticPose.Add( - new Motion.StaticPoseTable - { - BoneIndex = 1, - Channel = 6, - Value = InitialValue, - } - ); - interpolated.Joints.Add(new JointTable { JointIndex = 0, }); - interpolated.Joints.Add(new JointTable { JointIndex = 1, }); - interpolated.TotalFrameCount = TotalFrameCount; - interpolated.Footer.Unknown = new int[9]; - - var converter = new TimelineTableConverter(); - - interpolated.Timeline.AddRange( - (Timeline ?? new string[0]) - .Select(text => converter.ConvertFromInvariantString(text)) - .Cast() - ); - - var motionBin = new MemoryStream(); - Motion.Write(motionBin, motion); - - motionBin.Position = 0; - - var anbFile = new MemoryStream(); - - var anbBarEntries = new Bar.Entry[] - { - new Bar.Entry - { - Type = Bar.EntryType.Motion, - Stream = motionBin, - Name = "A000", - }, - }; - - Bar.Write( - anbFile, - anbBarEntries - ); - - anbFile.Position = 0; - - var msetFile = new MemoryStream(); - - Bar.Write( - msetFile, - new Bar.Entry[] - { - new Bar.Entry - { - Type = Bar.EntryType.Anb, - Stream = anbFile, - Name = "A000", - }, - } - ); - - msetFile.Position = 0; - - if (!string.IsNullOrEmpty(OutputMset)) - { - File.WriteAllBytes(OutputMset, msetFile.ToArray()); - } - - motionBin.Position = 0; - - var animReader = new AnimReader(motionBin); - - mdlxFile.Position = 0; - - var outFiles = new Dictionary(); - - { - var dat = new StringWriter(); - var gnuplot = new StringWriter(); - gnuplot.WriteLine($"set terminal png"); - gnuplot.WriteLine($"set title '{Prefix}'"); - gnuplot.WriteLine($"set output '{Prefix}.png'"); - gnuplot.WriteLine($"plot '{Prefix}.dat' index 0 title 'out' with lines, \\"); - gnuplot.WriteLine($" '' index 1 title 'in' with points"); - - outFiles[$"{Prefix}.dat"] = dat; - outFiles[$"{Prefix}.txt"] = gnuplot; - - var provider = (IAnimMatricesProvider)new EmuBasedAnimMatricesProvider(animReader, mdlxFile, motionBin); - - dat.WriteLine("# X Y"); - - foreach (var x in Enumerable.Range(0, (int)((FrameEnd - FrameLoop + 1) * FramePerSecond))) - { - var matrices = provider.ProvideMatrices((x == 0) ? 0 : 1); - - var xVal = FrameLoop + (x / FramePerSecond); - var yVal = matrices[1].M41; - - dat.WriteLine($"{xVal} {yVal}"); - } - - dat.WriteLine(); - dat.WriteLine(); - - dat.WriteLine("# X Y"); - - interpolated.Timeline - .ForEach( - indir => - { - dat.WriteLine($"{indir.KeyFrame} {indir.Value}"); - } - ); - } - - if (!string.IsNullOrEmpty(Prefix)) - { - outFiles.ForEach( - pair => File.WriteAllText( - pair.Key, - "" + pair.Value, - new UTF8Encoding(encoderShouldEmitUTF8Identifier: false) - ) - ); - - Console.WriteLine($"Run: gnuplot {Prefix}.txt"); - } - - return 0; - } - - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Kh2; +using OpenKh.Kh2Anim.Mset; +using OpenKh.Kh2Anim.Mset.Interfaces; +using OpenKh.Research.Kh2Anim.Models; +using OpenKh.Research.Kh2Anim.TypeConverters; +using OpenKh.Research.Kh2Anim.Utils; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Text; +using static OpenKh.Kh2.Motion; + +namespace OpenKh.Research.Kh2Anim.Subcommands +{ + [HelpOption] + [Command(Description = "Fry fake motion")] + class FryCommand + { + [Option(CommandOptionType.SingleValue, ShortName = "o", Description = "Output file: model.mset")] + public string OutputMset { get; set; } + + [Option(CommandOptionType.SingleValue, ShortName = "l", Description = "Unknown")] + public float FrameLoop { get; set; } = 0; + + [Option(CommandOptionType.SingleValue, ShortName = "e", Description = "Unknown")] + public float FrameEnd { get; set; } = 100; + + [Option(CommandOptionType.SingleValue, ShortName = "c", Description = "Unknown")] + public float FrameCount { get; set; } = 0; + + [Option(CommandOptionType.SingleValue, ShortName = "a", Description = "Unknown")] + public int TotalFrameCount { get; set; } = 100; + + [Option(CommandOptionType.SingleValue, ShortName = "f", Description = "FPS")] + public float FramePerSecond { get; set; } = 1; + + [Option(CommandOptionType.MultipleValue, ShortName = "t", Description = "Interpolation,FrameTime,Value,TangentEaseIn,TangentEaseOut\n(Nearest|Linear|Hermite|Zero),0.00,0.00,0.00,0.00")] + public string[] Timeline { get; set; } + + [Option(CommandOptionType.SingleValue, ShortName = "p", Description = "Output gnuplot file set with this file path prefix")] + public string Prefix { get; set; } + + [Option(CommandOptionType.SingleValue, ShortName = "u", Description = "Unknown")] + public byte Pre { get; set; } = 0; + + [Option(CommandOptionType.SingleValue, ShortName = "v", Description = "Unknown")] + public byte Post { get; set; } = 0; + + [Option(CommandOptionType.SingleValue, ShortName = "n", Description = "StaticPose value")] + public float InitialValue { get; set; } = 0; + + [Option(CommandOptionType.SingleValue, ShortName = "m", Description = "The value directly set to matrix")] + public float MatrixValue { get; set; } = 0; + + protected int OnExecute(CommandLineApplication app) + { + FramePerSecond = Math.Max(1, FramePerSecond); + + if (Timeline == null || Timeline?.Length == 0) + { + Timeline = new string[] { $"Linear,{FrameLoop},0,0,0", $"Linear,{FrameEnd},100,0,0" }; + } + + var mdlxFile = MdlxMaker.CreateMdlxHaving2Bones(tx: MatrixValue); + + var motion = Motion.CreateInterpolatedFromScratch(); + var interpolated = motion.Interpolated; + interpolated.ModelBoneAnimation.Add( + new BoneAnimationTable + { + JointIndex = 1, + Channel = (byte)(6 | ((3 & Pre) << 4) | ((3 & Post) << 6)), + TimelineStartIndex = 0, + TimelineCount = Convert.ToByte(Timeline.Length), + } + ); + interpolated.BoneCount = 2; + interpolated.FrameCount = FrameCount; + interpolated.FrameEnd = FrameEnd; + interpolated.FrameLoop = FrameLoop; + interpolated.FramePerSecond = FramePerSecond; + interpolated.StaticPose.Add( + new Motion.StaticPoseTable + { + BoneIndex = 1, + Channel = 6, + Value = InitialValue, + } + ); + interpolated.Joints.Add(new JointTable { JointIndex = 0, }); + interpolated.Joints.Add(new JointTable { JointIndex = 1, }); + interpolated.TotalFrameCount = TotalFrameCount; + interpolated.Footer.Unknown = new int[9]; + + var converter = new TimelineTableConverter(); + + interpolated.Timeline.AddRange( + (Timeline ?? new string[0]) + .Select(text => converter.ConvertFromInvariantString(text)) + .Cast() + ); + + var motionBin = new MemoryStream(); + Motion.Write(motionBin, motion); + + motionBin.Position = 0; + + var anbFile = new MemoryStream(); + + var anbBarEntries = new Bar.Entry[] + { + new Bar.Entry + { + Type = Bar.EntryType.Motion, + Stream = motionBin, + Name = "A000", + }, + }; + + Bar.Write( + anbFile, + anbBarEntries + ); + + anbFile.Position = 0; + + var msetFile = new MemoryStream(); + + Bar.Write( + msetFile, + new Bar.Entry[] + { + new Bar.Entry + { + Type = Bar.EntryType.Anb, + Stream = anbFile, + Name = "A000", + }, + } + ); + + msetFile.Position = 0; + + if (!string.IsNullOrEmpty(OutputMset)) + { + File.WriteAllBytes(OutputMset, msetFile.ToArray()); + } + + motionBin.Position = 0; + + var animReader = new AnimReader(motionBin); + + mdlxFile.Position = 0; + + var outFiles = new Dictionary(); + + { + var dat = new StringWriter(); + var gnuplot = new StringWriter(); + gnuplot.WriteLine($"set terminal png"); + gnuplot.WriteLine($"set title '{Prefix}'"); + gnuplot.WriteLine($"set output '{Prefix}.png'"); + gnuplot.WriteLine($"plot '{Prefix}.dat' index 0 title 'out' with lines, \\"); + gnuplot.WriteLine($" '' index 1 title 'in' with points"); + + outFiles[$"{Prefix}.dat"] = dat; + outFiles[$"{Prefix}.txt"] = gnuplot; + + var provider = (IAnimMatricesProvider)new EmuBasedAnimMatricesProvider(animReader, mdlxFile, motionBin); + + dat.WriteLine("# X Y"); + + foreach (var x in Enumerable.Range(0, (int)((FrameEnd - FrameLoop + 1) * FramePerSecond))) + { + var matrices = provider.ProvideMatrices((x == 0) ? 0 : 1); + + var xVal = FrameLoop + (x / FramePerSecond); + var yVal = matrices[1].M41; + + dat.WriteLine($"{xVal} {yVal}"); + } + + dat.WriteLine(); + dat.WriteLine(); + + dat.WriteLine("# X Y"); + + interpolated.Timeline + .ForEach( + indir => + { + dat.WriteLine($"{indir.KeyFrame} {indir.Value}"); + } + ); + } + + if (!string.IsNullOrEmpty(Prefix)) + { + outFiles.ForEach( + pair => File.WriteAllText( + pair.Key, + "" + pair.Value, + new UTF8Encoding(encoderShouldEmitUTF8Identifier: false) + ) + ); + + Console.WriteLine($"Run: gnuplot {Prefix}.txt"); + } + + return 0; + } + + } +} diff --git a/OpenKh.Research.Kh2Anim/Subcommands/SimpleMdlxCommand.cs b/OpenKh.Research.Kh2Anim/Subcommands/SimpleMdlxCommand.cs index 6f629041c..c3aeb9825 100644 --- a/OpenKh.Research.Kh2Anim/Subcommands/SimpleMdlxCommand.cs +++ b/OpenKh.Research.Kh2Anim/Subcommands/SimpleMdlxCommand.cs @@ -1,25 +1,25 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Research.Kh2Anim.Utils; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Text; - -namespace OpenKh.Research.Kh2Anim.Subcommands -{ - [HelpOption] - [Command(Description = "Create mdlx having 2 bones")] - class SimpleMdlxCommand - { - [Required] - [Argument(0, Description = "Output file: model.mdlx")] - public string OutputMdlx { get; set; } - - protected int OnExecute(CommandLineApplication app) - { - File.WriteAllBytes(OutputMdlx, MdlxMaker.CreateMdlxHaving2Bones().ToArray()); - return 0; - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Research.Kh2Anim.Utils; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Text; + +namespace OpenKh.Research.Kh2Anim.Subcommands +{ + [HelpOption] + [Command(Description = "Create mdlx having 2 bones")] + class SimpleMdlxCommand + { + [Required] + [Argument(0, Description = "Output file: model.mdlx")] + public string OutputMdlx { get; set; } + + protected int OnExecute(CommandLineApplication app) + { + File.WriteAllBytes(OutputMdlx, MdlxMaker.CreateMdlxHaving2Bones().ToArray()); + return 0; + } + } +} diff --git a/OpenKh.Research.Kh2Anim/TypeConverters/TimelineTableConverter.cs b/OpenKh.Research.Kh2Anim/TypeConverters/TimelineTableConverter.cs index 99a33a4b6..8a1a8cd5d 100644 --- a/OpenKh.Research.Kh2Anim/TypeConverters/TimelineTableConverter.cs +++ b/OpenKh.Research.Kh2Anim/TypeConverters/TimelineTableConverter.cs @@ -1,37 +1,37 @@ -using OpenKh.Kh2; -using OpenKh.Research.Kh2Anim.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Globalization; -using System.Text; -using static OpenKh.Kh2.Motion; - -namespace OpenKh.Research.Kh2Anim.TypeConverters -{ - class TimelineTableConverter : TypeConverter - { - public TimelineTableConverter() - { - - } - - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) - { - return sourceType == typeof(string); - } - - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) - { - var tokens = (value + "").Split(','); - return new TimelineTable - { - Interpolation = (Interpolation)Enum.Parse(typeof(Interpolation), tokens[0], true), - KeyFrame = Convert.ToSingle(tokens[1]), - Value = Convert.ToSingle(tokens[2]), - TangentEaseIn = Convert.ToSingle(tokens[3]), - TangentEaseOut = Convert.ToSingle(tokens[4]), - }; - } - } -} +using OpenKh.Kh2; +using OpenKh.Research.Kh2Anim.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Globalization; +using System.Text; +using static OpenKh.Kh2.Motion; + +namespace OpenKh.Research.Kh2Anim.TypeConverters +{ + class TimelineTableConverter : TypeConverter + { + public TimelineTableConverter() + { + + } + + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + { + return sourceType == typeof(string); + } + + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + var tokens = (value + "").Split(','); + return new TimelineTable + { + Interpolation = (Interpolation)Enum.Parse(typeof(Interpolation), tokens[0], true), + KeyFrame = Convert.ToSingle(tokens[1]), + Value = Convert.ToSingle(tokens[2]), + TangentEaseIn = Convert.ToSingle(tokens[3]), + TangentEaseOut = Convert.ToSingle(tokens[4]), + }; + } + } +} diff --git a/OpenKh.Research.Kh2Anim/Utils/AnbBarWrapper.cs b/OpenKh.Research.Kh2Anim/Utils/AnbBarWrapper.cs index 10d50d6bc..783242e42 100644 --- a/OpenKh.Research.Kh2Anim/Utils/AnbBarWrapper.cs +++ b/OpenKh.Research.Kh2Anim/Utils/AnbBarWrapper.cs @@ -1,13 +1,13 @@ -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Research.Kh2Anim.Utils -{ - class AnbBarWrapper - { - public int IndexInMset { get; set; } - public List BarEntries { get; set; } - } -} +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Research.Kh2Anim.Utils +{ + class AnbBarWrapper + { + public int IndexInMset { get; set; } + public List BarEntries { get; set; } + } +} diff --git a/OpenKh.Research.Kh2Anim/Utils/MdlxMaker.cs b/OpenKh.Research.Kh2Anim/Utils/MdlxMaker.cs index dc452749c..1520324f4 100644 --- a/OpenKh.Research.Kh2Anim/Utils/MdlxMaker.cs +++ b/OpenKh.Research.Kh2Anim/Utils/MdlxMaker.cs @@ -1,61 +1,61 @@ -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace OpenKh.Research.Kh2Anim.Utils -{ - static class MdlxMaker - { - internal static MemoryStream CreateMdlxHaving2Bones(float tx = 0) - { - var model = Mdlx.CreateModelFromScratch(); - - model.SubModels[0].BoneCount = 2; - model.SubModels[0].Bones.Add( - new Mdlx.Bone - { - Index = 0, - Parent = -1, - ScaleX = 1, - ScaleY = 1, - ScaleZ = 1, - ScaleW = 1, - } - ); - model.SubModels[0].Bones.Add( - new Mdlx.Bone - { - Index = 1, - Parent = 0, - ScaleX = 1, - ScaleY = 1, - ScaleZ = 1, - ScaleW = 1, - TranslationX = tx, - } - ); - - var modelBin = new MemoryStream(); - model.Write(modelBin); - - var mdlxFile = new MemoryStream(); - - Bar.Write( - mdlxFile, - new Bar.Entry[] - { - new Bar.Entry - { - Type = Bar.EntryType.Model, - Stream = modelBin, - Name = "p_ex", - }, - } - ); - - return mdlxFile; - } - } -} +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace OpenKh.Research.Kh2Anim.Utils +{ + static class MdlxMaker + { + internal static MemoryStream CreateMdlxHaving2Bones(float tx = 0) + { + var model = Mdlx.CreateModelFromScratch(); + + model.SubModels[0].BoneCount = 2; + model.SubModels[0].Bones.Add( + new Mdlx.Bone + { + Index = 0, + Parent = -1, + ScaleX = 1, + ScaleY = 1, + ScaleZ = 1, + ScaleW = 1, + } + ); + model.SubModels[0].Bones.Add( + new Mdlx.Bone + { + Index = 1, + Parent = 0, + ScaleX = 1, + ScaleY = 1, + ScaleZ = 1, + ScaleW = 1, + TranslationX = tx, + } + ); + + var modelBin = new MemoryStream(); + model.Write(modelBin); + + var mdlxFile = new MemoryStream(); + + Bar.Write( + mdlxFile, + new Bar.Entry[] + { + new Bar.Entry + { + Type = Bar.EntryType.Model, + Stream = modelBin, + Name = "p_ex", + }, + } + ); + + return mdlxFile; + } + } +} diff --git a/OpenKh.Tests.Commands/FileDisposer.cs b/OpenKh.Tests.Commands/FileDisposer.cs index d4e8777ad..e68fbbb06 100644 --- a/OpenKh.Tests.Commands/FileDisposer.cs +++ b/OpenKh.Tests.Commands/FileDisposer.cs @@ -1,22 +1,22 @@ -using System.IO; -using System; - -namespace OpenKh.Tests.Commands -{ - internal class FileDisposer : IDisposable - { - private readonly string[] _fileNames; - - public FileDisposer(params string[] fileNames) - { - _fileNames = fileNames; - } - - public void Dispose() - { - foreach (var fileName in _fileNames) - if (File.Exists(fileName)) - File.Delete(fileName); - } - } -} +using System.IO; +using System; + +namespace OpenKh.Tests.Commands +{ + internal class FileDisposer : IDisposable + { + private readonly string[] _fileNames; + + public FileDisposer(params string[] fileNames) + { + _fileNames = fileNames; + } + + public void Dispose() + { + foreach (var fileName in _fileNames) + if (File.Exists(fileName)) + File.Delete(fileName); + } + } +} diff --git a/OpenKh.Tests.Commands/MapGenTest.cs b/OpenKh.Tests.Commands/MapGenTest.cs index 47fef7d87..d17bf9d94 100644 --- a/OpenKh.Tests.Commands/MapGenTest.cs +++ b/OpenKh.Tests.Commands/MapGenTest.cs @@ -1,57 +1,57 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.IO; -using System.Linq; -using Xunit; -using OpenKh.Command.MapGen.Utils; -using OpenKh.Command.DoctChanger.Utils; -using OpenKh.Command.CoctChanger.Utils; - -namespace OpenKh.Tests.Commands -{ - public class MapGenTest - { - [Theory] - [InlineData("res/mapgen/diagnoal/diagnoal.fbx")] - [InlineData("res/mapgen/multi-4bpp/multi-4bpp.fbx")] - [InlineData("res/mapgen/multi-8bpp/multi-8bpp.fbx")] - [InlineData("res/mapgen/terrain/terrain.fbx")] - public void TestMapGenUtil(string inputModel) - { - var outMap = Path.ChangeExtension(inputModel, ".map"); - using var disposer = new FileDisposer(outMap); - - new MapGenUtil().Run(inputModel, outMap); - - var barEntries = File.OpenRead(outMap).Using(Bar.Read); - - { - var doct = Doct.Read(barEntries.Single(it => it.Type == Bar.EntryType.DrawOctalTree).Stream); - var writer = new StringWriter(); - new DumpDoctUtil(doct, writer); - - var doctDumpFile = Path.ChangeExtension(inputModel, ".doct.dump"); - - Assert.Equal( - expected: File.ReadAllText(doctDumpFile), - actual: writer.ToString(), - ignoreLineEndingDifferences: true - ); - } - - { - var coct = Coct.Read(barEntries.Single(it => it.Type == Bar.EntryType.CollisionOctalTree).Stream); - var writer = new StringWriter(); - new DumpCoctUtil(coct, writer); - - var coctDumpFile = Path.ChangeExtension(inputModel, ".coct.dump"); - - Assert.Equal( - expected: File.ReadAllText(coctDumpFile), - actual: writer.ToString(), - ignoreLineEndingDifferences: true - ); - } - } - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.IO; +using System.Linq; +using Xunit; +using OpenKh.Command.MapGen.Utils; +using OpenKh.Command.DoctChanger.Utils; +using OpenKh.Command.CoctChanger.Utils; + +namespace OpenKh.Tests.Commands +{ + public class MapGenTest + { + [Theory] + [InlineData("res/mapgen/diagnoal/diagnoal.fbx")] + [InlineData("res/mapgen/multi-4bpp/multi-4bpp.fbx")] + [InlineData("res/mapgen/multi-8bpp/multi-8bpp.fbx")] + [InlineData("res/mapgen/terrain/terrain.fbx")] + public void TestMapGenUtil(string inputModel) + { + var outMap = Path.ChangeExtension(inputModel, ".map"); + using var disposer = new FileDisposer(outMap); + + new MapGenUtil().Run(inputModel, outMap); + + var barEntries = File.OpenRead(outMap).Using(Bar.Read); + + { + var doct = Doct.Read(barEntries.Single(it => it.Type == Bar.EntryType.DrawOctalTree).Stream); + var writer = new StringWriter(); + new DumpDoctUtil(doct, writer); + + var doctDumpFile = Path.ChangeExtension(inputModel, ".doct.dump"); + + Assert.Equal( + expected: File.ReadAllText(doctDumpFile), + actual: writer.ToString(), + ignoreLineEndingDifferences: true + ); + } + + { + var coct = Coct.Read(barEntries.Single(it => it.Type == Bar.EntryType.CollisionOctalTree).Stream); + var writer = new StringWriter(); + new DumpCoctUtil(coct, writer); + + var coctDumpFile = Path.ChangeExtension(inputModel, ".coct.dump"); + + Assert.Equal( + expected: File.ReadAllText(coctDumpFile), + actual: writer.ToString(), + ignoreLineEndingDifferences: true + ); + } + } + } +} diff --git a/OpenKh.Tests.Commands/TexFooterTests.cs b/OpenKh.Tests.Commands/TexFooterTests.cs index a64ab3f27..48b1fb2eb 100644 --- a/OpenKh.Tests.Commands/TexFooterTests.cs +++ b/OpenKh.Tests.Commands/TexFooterTests.cs @@ -1,69 +1,69 @@ -using OpenKh.Command.TexFooter.Subcommands; -using OpenKh.Common; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using Xunit; - -namespace OpenKh.Tests.Commands -{ - public class TexFooterTests - { - [Theory] - [InlineData("res/texfooter/clamp.map")] - [InlineData("res/texfooter/clamp-uvsc.map")] - [InlineData("res/texfooter/clamp-texa.map")] - public void ShouldWriteBackTheExactSameFile(string mapFile) - { - var baseDir = Environment.CurrentDirectory; - var outDir = Path.Combine( - baseDir, - nameof(TexFooterTests), - Path.GetFileName(mapFile).Replace('.', '_') - ); - Directory.CreateDirectory(outDir); - - var destWorkFile = Path.Combine(outDir, Path.GetFileName(mapFile)); - - File.Copy(mapFile, destWorkFile, true); - - var exportErrorCode = new ExportCommand - { - MapFile = destWorkFile, - } - .Execute(); - - if (exportErrorCode == 1) - { - // Having no texture data. - return; - } - - Assert.Equal( - expected: 0, - actual: exportErrorCode - ); - - Assert.Equal( - expected: 0, - actual: - new ImportCommand - { - MapFile = destWorkFile, - } - .Execute() - ); - - Assert.Equal( - expected: FromFile(mapFile), - actual: FromFile(destWorkFile) - ); - } - - private IEnumerable FromFile(string file) => File.ReadAllBytes(file); - } -} +using OpenKh.Command.TexFooter.Subcommands; +using OpenKh.Common; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using Xunit; + +namespace OpenKh.Tests.Commands +{ + public class TexFooterTests + { + [Theory] + [InlineData("res/texfooter/clamp.map")] + [InlineData("res/texfooter/clamp-uvsc.map")] + [InlineData("res/texfooter/clamp-texa.map")] + public void ShouldWriteBackTheExactSameFile(string mapFile) + { + var baseDir = Environment.CurrentDirectory; + var outDir = Path.Combine( + baseDir, + nameof(TexFooterTests), + Path.GetFileName(mapFile).Replace('.', '_') + ); + Directory.CreateDirectory(outDir); + + var destWorkFile = Path.Combine(outDir, Path.GetFileName(mapFile)); + + File.Copy(mapFile, destWorkFile, true); + + var exportErrorCode = new ExportCommand + { + MapFile = destWorkFile, + } + .Execute(); + + if (exportErrorCode == 1) + { + // Having no texture data. + return; + } + + Assert.Equal( + expected: 0, + actual: exportErrorCode + ); + + Assert.Equal( + expected: 0, + actual: + new ImportCommand + { + MapFile = destWorkFile, + } + .Execute() + ); + + Assert.Equal( + expected: FromFile(mapFile), + actual: FromFile(destWorkFile) + ); + } + + private IEnumerable FromFile(string file) => File.ReadAllBytes(file); + } +} diff --git a/OpenKh.Tests.Engine/AnimatedSequenceFactoryTests.cs b/OpenKh.Tests.Engine/AnimatedSequenceFactoryTests.cs index ddfc3ec47..678c8f610 100644 --- a/OpenKh.Tests.Engine/AnimatedSequenceFactoryTests.cs +++ b/OpenKh.Tests.Engine/AnimatedSequenceFactoryTests.cs @@ -1,411 +1,411 @@ -using NSubstitute; -using OpenKh.Engine; -using OpenKh.Engine.Renderers; -using OpenKh.Engine.Renders; -using OpenKh.Game; -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Engine -{ - public class AnimatedSequenceFactoryTests - { - private class MockMessageRenderer : IMessageRenderer - { - public bool HasBeenCalled { get; private set; } - public double LastPosX { get; private set; } - public double LastPosY { get; private set; } - public ColorF LastColor { get; private set; } - - public void Draw(DrawContext context, string message) => - throw new NotImplementedException(); - - public void Draw(DrawContext context, byte[] data) - { - if (context.IgnoreDraw) - { - context.Width = 20; - context.Height = 10; - } - else - { - HasBeenCalled = true; - LastPosX = context.x; - LastPosY = context.y; - LastColor = context.Color; - } - } - } - - public AnimatedSequenceFactoryTests() - { - - } - - [Theory] - [InlineData(0, 0, 0, 0, 0)] - [InlineData(0, 0, 10, 0, 0)] - [InlineData(20, 0, 10, AnimatedSequenceDesc.DefaultStacking, 0)] - [InlineData(0, 20, 10, 0, AnimatedSequenceDesc.DefaultStacking)] - [InlineData(30, 30, 15, AnimatedSequenceDesc.DefaultStacking, AnimatedSequenceDesc.DefaultStacking)] - [InlineData(30, 40, 15, AnimatedSequenceDesc.DefaultStacking, 20)] - [InlineData(-40, 30, 15, -20, AnimatedSequenceDesc.DefaultStacking)] - public void StackChildrenCorrectly( - int expectedThirdChildPosX, - int expectedThirdChildPosY, - int stackValue, - int stackWidth, - int stackHeight) - { - var sequence = new Sequence - { - AnimationGroups = new List - { - new Sequence.AnimationGroup - { - TextPositionX = stackValue, - Animations = new List - { - new Sequence.Animation - { - FrameEnd = 1000, - SpriteGroupIndex = 0, - } - } - } - }, - SpriteGroups = new List> - { - new List - { - new Sequence.SpritePart - { - SpriteIndex = 0, - Right = 10, - Bottom = 10, - } - } - }, - Sprites = new List - { - new Sequence.Sprite - { - - } - } - }; - - var drawing = Extensions.MockDrawing(); - var messageProvider = Substitute.For(); - var messageRenderer = Substitute.For(); - var messageEncode = Substitute.For(); - var spriteTexture = Substitute.For(); - var factory = new AnimatedSequenceFactory( - drawing, - messageProvider, - messageRenderer, - messageEncode, - sequence, - spriteTexture); - - var animationDescs = Enumerable.Range(0, 3) - .Select(x => new AnimatedSequenceDesc - { - StackIndex = x, - StackWidth = stackWidth, - StackHeight = stackHeight - }); - - var animation = factory.Create(animationDescs); - animation.Draw(0, 0); - - drawing.AssertAtLeastOneCall(); - drawing.AssertDraw(2, x => - { - Assert.Equal(expectedThirdChildPosX, x.Vec0.X); - Assert.Equal(expectedThirdChildPosY, x.Vec0.Y); - }); - } - - [Theory] - [InlineData(TextAnchor.BottomLeft, 0, 0)] - [InlineData(TextAnchor.BottomRight, -20, 0)] - [InlineData(TextAnchor.BottomCenter, -10, 0)] - [InlineData(TextAnchor.Center, -10, -5)] - [InlineData(TextAnchor.TopCenter, -10, -10)] - [InlineData(TextAnchor.TopLeft, 0, -10)] - public void AnchorTextCorrectly(TextAnchor anchor, int expectedX, int expectedY) - { - var sequence = new Sequence - { - AnimationGroups = new List - { - new Sequence.AnimationGroup - { - Animations = new List() - } - }, - SpriteGroups = new List>(), - Sprites = new List() - }; - - var drawing = Extensions.MockDrawing(); - var messageProvider = Substitute.For(); - var messageRenderer = new MockMessageRenderer(); - var messageEncode = Substitute.For(); - var spriteTexture = Substitute.For(); - var factory = new AnimatedSequenceFactory( - drawing, - messageProvider, - messageRenderer, - messageEncode, - sequence, - spriteTexture); - - messageEncode.Encode(Arg.Is>(x => true)) - .Returns(new byte[] { 0x21 }); - - var animation = factory.Create(new AnimatedSequenceDesc - { - TextAnchor = anchor, - MessageText = "test" - }); - - animation.Draw(0, 0); - - Assert.True(messageRenderer.HasBeenCalled); - Assert.Equal(expectedX, messageRenderer.LastPosX); - Assert.Equal(expectedY, messageRenderer.LastPosY); - } - - [Fact] - public void StackChildrenHorizontally() - { - var sequence = new Sequence - { - AnimationGroups = new List - { - new Sequence.AnimationGroup - { - LightPositionX = 100, - Animations = new List - { - new Sequence.Animation - { - FrameEnd = 100, - Flags = Sequence.IsActiveFlag, - } - } - } - }, - SpriteGroups = new List> - { - new List - { - new Sequence.SpritePart - { - Right = 50, - Bottom = 30, - } - } - }, - Sprites = new List() - { - new Sequence.Sprite() - } - }; - - var drawing = Extensions.MockDrawing(); - var messageProvider = Substitute.For(); - var messageRenderer = new MockMessageRenderer(); - var messageEncode = Substitute.For(); - var spriteTexture = Substitute.For(); - var factory = new AnimatedSequenceFactory( - drawing, - messageProvider, - messageRenderer, - messageEncode, - sequence, - spriteTexture); - - var animation = factory.Create(new AnimatedSequenceDesc - { - Flags = AnimationFlags.ChildStackHorizontally, - Children = Enumerable.Range(0, 3) - .Select(x => new AnimatedSequenceDesc()) - .ToList() - }); - - animation.Draw(0, 0); - - drawing.AssertAtLeastOneCall(); - drawing.AssertCallCount(4); - drawing.AssertDraw(3, x => - { - Assert.Equal(200, x.Vec0.X); - Assert.Equal(0, x.Vec0.Y); - }); - } - - [Theory] - [InlineData(AnimationFlags.None, 100, 4, 0, 0)] - [InlineData(AnimationFlags.StackNextChildHorizontally, 100, 4, 300, 0)] - [InlineData(AnimationFlags.StackNextChildVertically, 120, 4, 0, 360)] - public void StackItemsFromChildSize(AnimationFlags flags, int uiPadding, - int elementCount, int expectedLastPosX, int expectedLastPosY) - { - var sequence = new Sequence - { - AnimationGroups = new List - { - new Sequence.AnimationGroup - { - UiPadding = 0, - Animations = new List() - }, - new Sequence.AnimationGroup - { - UiPadding = uiPadding, - Animations = new List - { - new Sequence.Animation - { - FrameEnd = 100, - Flags = Sequence.IsActiveFlag, - } - } - }, - }, - SpriteGroups = new List> - { - new List - { - new Sequence.SpritePart - { - Right = 50, - Bottom = 30, - } - } - }, - Sprites = new List() - { - new Sequence.Sprite() - } - }; - - var drawing = Extensions.MockDrawing(); - var messageProvider = Substitute.For(); - var messageRenderer = new MockMessageRenderer(); - var messageEncode = Substitute.For(); - var spriteTexture = Substitute.For(); - var factory = new AnimatedSequenceFactory( - drawing, - messageProvider, - messageRenderer, - messageEncode, - sequence, - spriteTexture); - - var animation = factory.Create(new AnimatedSequenceDesc - { - SequenceIndexLoop = 0, - Flags = flags, - Children = Enumerable.Range(0, elementCount) - .Select(x => new AnimatedSequenceDesc - { - SequenceIndexLoop = 1, - }) - .ToList() - }); - - animation.Begin(); - animation.Draw(0, 0); - - drawing.AssertCallCount(4); - drawing.AssertDraw(3, x => - { - Assert.Equal(expectedLastPosX, x.Vec0.X); - Assert.Equal(expectedLastPosY, x.Vec0.Y); - }); - } - - [Fact] - public void DrawTextWithCorrectColor() - { - var colorTest = new ColorF(0.5f, 0.75f, 0.25f, 0.125f); - AssertDrawTextWithCorrectColor(colorTest, colorTest, AnimationFlags.None); - } - - [Fact] - public void DrawTextWithDefaultColor() - { - var colorTest = new ColorF(0.5f, 0.75f, 0.25f, 0.125f); - var expectedColor = new ColorF(1f, 1f, 1f, colorTest.A); - AssertDrawTextWithCorrectColor(expectedColor, colorTest, AnimationFlags.TextIgnoreColor); - } - - private void AssertDrawTextWithCorrectColor(ColorF expected, ColorF colorValue, AnimationFlags flags) - { - const float Divisor = 255f / 128f; - var sequence = new Sequence - { - AnimationGroups = new List - { - new Sequence.AnimationGroup - { - Animations = new List - { - new Sequence.Animation - { - FrameEnd = 100, - Flags = Sequence.IsActiveFlag, - ColorStart = (colorValue / Divisor).ToRgba(), - ColorEnd = (colorValue / Divisor).ToRgba(), - } - } - } - }, - SpriteGroups = new List> - { - new List() - }, - Sprites = new List() - }; - - var drawing = Extensions.MockDrawing(); - var messageProvider = Substitute.For(); - var messageRenderer = new MockMessageRenderer(); - var messageEncode = Substitute.For(); - var spriteTexture = Substitute.For(); - var factory = new AnimatedSequenceFactory( - drawing, - messageProvider, - messageRenderer, - messageEncode, - sequence, - spriteTexture); - - messageEncode.Encode(Arg.Is>(x => true)) - .Returns(new byte[] { 0x21 }); - - var animation = factory.Create(new AnimatedSequenceDesc - { - Flags = flags, - MessageText = "test" - }); - - animation.Draw(0, 0); - - expected = ColorF.FromRgba(expected.ToRgba()); - Assert.True(messageRenderer.HasBeenCalled); - Assert.Equal(expected.R, messageRenderer.LastColor.R, 2); - Assert.Equal(expected.G, messageRenderer.LastColor.G, 2); - Assert.Equal(expected.B, messageRenderer.LastColor.B, 2); - Assert.Equal(expected.A, messageRenderer.LastColor.A, 2); - } - } -} +using NSubstitute; +using OpenKh.Engine; +using OpenKh.Engine.Renderers; +using OpenKh.Engine.Renders; +using OpenKh.Game; +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Engine +{ + public class AnimatedSequenceFactoryTests + { + private class MockMessageRenderer : IMessageRenderer + { + public bool HasBeenCalled { get; private set; } + public double LastPosX { get; private set; } + public double LastPosY { get; private set; } + public ColorF LastColor { get; private set; } + + public void Draw(DrawContext context, string message) => + throw new NotImplementedException(); + + public void Draw(DrawContext context, byte[] data) + { + if (context.IgnoreDraw) + { + context.Width = 20; + context.Height = 10; + } + else + { + HasBeenCalled = true; + LastPosX = context.x; + LastPosY = context.y; + LastColor = context.Color; + } + } + } + + public AnimatedSequenceFactoryTests() + { + + } + + [Theory] + [InlineData(0, 0, 0, 0, 0)] + [InlineData(0, 0, 10, 0, 0)] + [InlineData(20, 0, 10, AnimatedSequenceDesc.DefaultStacking, 0)] + [InlineData(0, 20, 10, 0, AnimatedSequenceDesc.DefaultStacking)] + [InlineData(30, 30, 15, AnimatedSequenceDesc.DefaultStacking, AnimatedSequenceDesc.DefaultStacking)] + [InlineData(30, 40, 15, AnimatedSequenceDesc.DefaultStacking, 20)] + [InlineData(-40, 30, 15, -20, AnimatedSequenceDesc.DefaultStacking)] + public void StackChildrenCorrectly( + int expectedThirdChildPosX, + int expectedThirdChildPosY, + int stackValue, + int stackWidth, + int stackHeight) + { + var sequence = new Sequence + { + AnimationGroups = new List + { + new Sequence.AnimationGroup + { + TextPositionX = stackValue, + Animations = new List + { + new Sequence.Animation + { + FrameEnd = 1000, + SpriteGroupIndex = 0, + } + } + } + }, + SpriteGroups = new List> + { + new List + { + new Sequence.SpritePart + { + SpriteIndex = 0, + Right = 10, + Bottom = 10, + } + } + }, + Sprites = new List + { + new Sequence.Sprite + { + + } + } + }; + + var drawing = Extensions.MockDrawing(); + var messageProvider = Substitute.For(); + var messageRenderer = Substitute.For(); + var messageEncode = Substitute.For(); + var spriteTexture = Substitute.For(); + var factory = new AnimatedSequenceFactory( + drawing, + messageProvider, + messageRenderer, + messageEncode, + sequence, + spriteTexture); + + var animationDescs = Enumerable.Range(0, 3) + .Select(x => new AnimatedSequenceDesc + { + StackIndex = x, + StackWidth = stackWidth, + StackHeight = stackHeight + }); + + var animation = factory.Create(animationDescs); + animation.Draw(0, 0); + + drawing.AssertAtLeastOneCall(); + drawing.AssertDraw(2, x => + { + Assert.Equal(expectedThirdChildPosX, x.Vec0.X); + Assert.Equal(expectedThirdChildPosY, x.Vec0.Y); + }); + } + + [Theory] + [InlineData(TextAnchor.BottomLeft, 0, 0)] + [InlineData(TextAnchor.BottomRight, -20, 0)] + [InlineData(TextAnchor.BottomCenter, -10, 0)] + [InlineData(TextAnchor.Center, -10, -5)] + [InlineData(TextAnchor.TopCenter, -10, -10)] + [InlineData(TextAnchor.TopLeft, 0, -10)] + public void AnchorTextCorrectly(TextAnchor anchor, int expectedX, int expectedY) + { + var sequence = new Sequence + { + AnimationGroups = new List + { + new Sequence.AnimationGroup + { + Animations = new List() + } + }, + SpriteGroups = new List>(), + Sprites = new List() + }; + + var drawing = Extensions.MockDrawing(); + var messageProvider = Substitute.For(); + var messageRenderer = new MockMessageRenderer(); + var messageEncode = Substitute.For(); + var spriteTexture = Substitute.For(); + var factory = new AnimatedSequenceFactory( + drawing, + messageProvider, + messageRenderer, + messageEncode, + sequence, + spriteTexture); + + messageEncode.Encode(Arg.Is>(x => true)) + .Returns(new byte[] { 0x21 }); + + var animation = factory.Create(new AnimatedSequenceDesc + { + TextAnchor = anchor, + MessageText = "test" + }); + + animation.Draw(0, 0); + + Assert.True(messageRenderer.HasBeenCalled); + Assert.Equal(expectedX, messageRenderer.LastPosX); + Assert.Equal(expectedY, messageRenderer.LastPosY); + } + + [Fact] + public void StackChildrenHorizontally() + { + var sequence = new Sequence + { + AnimationGroups = new List + { + new Sequence.AnimationGroup + { + LightPositionX = 100, + Animations = new List + { + new Sequence.Animation + { + FrameEnd = 100, + Flags = Sequence.IsActiveFlag, + } + } + } + }, + SpriteGroups = new List> + { + new List + { + new Sequence.SpritePart + { + Right = 50, + Bottom = 30, + } + } + }, + Sprites = new List() + { + new Sequence.Sprite() + } + }; + + var drawing = Extensions.MockDrawing(); + var messageProvider = Substitute.For(); + var messageRenderer = new MockMessageRenderer(); + var messageEncode = Substitute.For(); + var spriteTexture = Substitute.For(); + var factory = new AnimatedSequenceFactory( + drawing, + messageProvider, + messageRenderer, + messageEncode, + sequence, + spriteTexture); + + var animation = factory.Create(new AnimatedSequenceDesc + { + Flags = AnimationFlags.ChildStackHorizontally, + Children = Enumerable.Range(0, 3) + .Select(x => new AnimatedSequenceDesc()) + .ToList() + }); + + animation.Draw(0, 0); + + drawing.AssertAtLeastOneCall(); + drawing.AssertCallCount(4); + drawing.AssertDraw(3, x => + { + Assert.Equal(200, x.Vec0.X); + Assert.Equal(0, x.Vec0.Y); + }); + } + + [Theory] + [InlineData(AnimationFlags.None, 100, 4, 0, 0)] + [InlineData(AnimationFlags.StackNextChildHorizontally, 100, 4, 300, 0)] + [InlineData(AnimationFlags.StackNextChildVertically, 120, 4, 0, 360)] + public void StackItemsFromChildSize(AnimationFlags flags, int uiPadding, + int elementCount, int expectedLastPosX, int expectedLastPosY) + { + var sequence = new Sequence + { + AnimationGroups = new List + { + new Sequence.AnimationGroup + { + UiPadding = 0, + Animations = new List() + }, + new Sequence.AnimationGroup + { + UiPadding = uiPadding, + Animations = new List + { + new Sequence.Animation + { + FrameEnd = 100, + Flags = Sequence.IsActiveFlag, + } + } + }, + }, + SpriteGroups = new List> + { + new List + { + new Sequence.SpritePart + { + Right = 50, + Bottom = 30, + } + } + }, + Sprites = new List() + { + new Sequence.Sprite() + } + }; + + var drawing = Extensions.MockDrawing(); + var messageProvider = Substitute.For(); + var messageRenderer = new MockMessageRenderer(); + var messageEncode = Substitute.For(); + var spriteTexture = Substitute.For(); + var factory = new AnimatedSequenceFactory( + drawing, + messageProvider, + messageRenderer, + messageEncode, + sequence, + spriteTexture); + + var animation = factory.Create(new AnimatedSequenceDesc + { + SequenceIndexLoop = 0, + Flags = flags, + Children = Enumerable.Range(0, elementCount) + .Select(x => new AnimatedSequenceDesc + { + SequenceIndexLoop = 1, + }) + .ToList() + }); + + animation.Begin(); + animation.Draw(0, 0); + + drawing.AssertCallCount(4); + drawing.AssertDraw(3, x => + { + Assert.Equal(expectedLastPosX, x.Vec0.X); + Assert.Equal(expectedLastPosY, x.Vec0.Y); + }); + } + + [Fact] + public void DrawTextWithCorrectColor() + { + var colorTest = new ColorF(0.5f, 0.75f, 0.25f, 0.125f); + AssertDrawTextWithCorrectColor(colorTest, colorTest, AnimationFlags.None); + } + + [Fact] + public void DrawTextWithDefaultColor() + { + var colorTest = new ColorF(0.5f, 0.75f, 0.25f, 0.125f); + var expectedColor = new ColorF(1f, 1f, 1f, colorTest.A); + AssertDrawTextWithCorrectColor(expectedColor, colorTest, AnimationFlags.TextIgnoreColor); + } + + private void AssertDrawTextWithCorrectColor(ColorF expected, ColorF colorValue, AnimationFlags flags) + { + const float Divisor = 255f / 128f; + var sequence = new Sequence + { + AnimationGroups = new List + { + new Sequence.AnimationGroup + { + Animations = new List + { + new Sequence.Animation + { + FrameEnd = 100, + Flags = Sequence.IsActiveFlag, + ColorStart = (colorValue / Divisor).ToRgba(), + ColorEnd = (colorValue / Divisor).ToRgba(), + } + } + } + }, + SpriteGroups = new List> + { + new List() + }, + Sprites = new List() + }; + + var drawing = Extensions.MockDrawing(); + var messageProvider = Substitute.For(); + var messageRenderer = new MockMessageRenderer(); + var messageEncode = Substitute.For(); + var spriteTexture = Substitute.For(); + var factory = new AnimatedSequenceFactory( + drawing, + messageProvider, + messageRenderer, + messageEncode, + sequence, + spriteTexture); + + messageEncode.Encode(Arg.Is>(x => true)) + .Returns(new byte[] { 0x21 }); + + var animation = factory.Create(new AnimatedSequenceDesc + { + Flags = flags, + MessageText = "test" + }); + + animation.Draw(0, 0); + + expected = ColorF.FromRgba(expected.ToRgba()); + Assert.True(messageRenderer.HasBeenCalled); + Assert.Equal(expected.R, messageRenderer.LastColor.R, 2); + Assert.Equal(expected.G, messageRenderer.LastColor.G, 2); + Assert.Equal(expected.B, messageRenderer.LastColor.B, 2); + Assert.Equal(expected.A, messageRenderer.LastColor.A, 2); + } + } +} diff --git a/OpenKh.Tests.Engine/CameraTests.cs b/OpenKh.Tests.Engine/CameraTests.cs index d3696ace3..6bbec3666 100644 --- a/OpenKh.Tests.Engine/CameraTests.cs +++ b/OpenKh.Tests.Engine/CameraTests.cs @@ -1,221 +1,221 @@ -using NSubstitute; -using OpenKh.Engine; -using System; -using System.Numerics; -using Xunit; - -namespace OpenKh.Tests.Engine -{ - public class CameraTests - { - [Theory] - [InlineData(512f, 384f, 1.5f, 1.073426127f, 1.431234717f)] - [InlineData(512f, 384f, 1.047197461f, 1.7320510149002075f, 2.309401512f)] - [InlineData(512f, 288f, 1.5f, 0.805069625377655f, 1.431234717f)] - [InlineData(512f, 288f, 1.047197461f, 1.299038291f, 2.309401512f)] - [InlineData(640f, 480f, 1.5f, 1.073426127f, 1.431234717f)] - [InlineData(1920f, 1080f, 1.047197461f, 1.299038291f, 2.309401512f)] - public void SetProjectionMatrixTest( - float width, float height, float fov, - float expectedM11, float expectedM22) - { - var camera = new Camera(); - camera.AspectRatio = width / height; - camera.FieldOfView = fov; - - AssertMatrix(new Matrix4x4( - expectedM11, 0, 0, 0, - 0, expectedM22, 0f, 0, - 0, 0f, -1f, -1f, - 0, 0, -1f, 0 - ), camera.Projection); - } - - [Fact] - public void SetWorldMatrixTest() - { - var camera = new Camera(); - camera.CameraPosition = new Vector3(0f, 251.1999969f, -920f); - camera.CameraLookAt = new Vector3(0f, 170f, -500f); - camera.CameraUp = new Vector3(0f, 1f, 0f); - - AssertMatrix(new Matrix4x4( - -1, 0, 0, 0, - 0, 0.9818192f, 0.189818367f, 0, - 0, 0.189818367f, -0.9818192f, 0, - 0, -72.00009f, -950.956f, 1 - ), camera.World); - } - - [Theory] - [InlineData(0f, 0f, 0f, 520f, -500f)] - [InlineData(420f, 0f, 0f, 251.19999f, -920f)] - [InlineData(420f, 1f, -353.4177246f, 251.199997f, -726.927002f)] - public void TargetCameraSetsPositionTest( - float radius, float yRotation, - float expectedX, float expectedY, float expectedZ) - { - var entity = Substitute.For(); - entity.Position.ReturnsForAnyArgs(new Vector3(0f, 0f, -500f)); - - var camera = new Camera(); - var targetCamera = new TargetCamera(camera) - { - Type = 0, - Radius = radius, - YRotation = yRotation, - BackYRotation = yRotation, - Interpolate = false, - }; - targetCamera.Update(entity, 0); - - var expected = new Vector3(expectedX, expectedY, expectedZ); - AssertVector3(expected, camera.CameraPosition); - } - - [Fact] - public void TargetCameraSetCorrectValuesToCamera() - { - var entity = Substitute.For(); - entity.Position.ReturnsForAnyArgs(new Vector3(0f, 150f, 0f)); - - var camera = new Camera(); - var targetCamera = new TargetCamera(camera) - { - Type = 0, - Radius = 420f, - YRotation = 0f, - BackYRotation = 0f, - Interpolate = false, - }; - targetCamera.Update(entity, 0); - - var expectedPosition = new Vector3(0f, 401.2f, -420); - var expectedLookAt = new Vector3(0f, 320f, 0f); - AssertVector3(expectedPosition, camera.CameraPosition); - AssertVector3(expectedLookAt, camera.CameraLookAt); - } - - [Theory] - [InlineData(Math.PI, Math.PI)] - [InlineData(0, 0)] - [InlineData(-Math.PI, Math.PI)] - [InlineData(1, -1)] - [InlineData(4, 2.2831852436065674f)] - public void TargetCameraRotatesInstantlyOnEntity( - float entityRotation, float expected) - { - var entity = Substitute.For(); - entity.Rotation.ReturnsForAnyArgs(new Vector3(0f, entityRotation, 0f)); - - var camera = new Camera(); - var targetCamera = new TargetCamera(camera) - { - Type = 0, - Radius = 420f, - YRotation = 0f, - BackYRotation = 0f, - Interpolate = false - }; - targetCamera.InstantlyRotateCameraToEntity(entity); - targetCamera.Update(entity, 0); - - Assert.Equal(expected, targetCamera.YRotation, 4); - } - - [Theory] - [InlineData(100f, 200f, 100f, 0)] - [InlineData(100f, 200f, 124.7499924f, 1)] - [InlineData(100f, 200f, 143.3124847f, 2)] - [InlineData(100f, 200f, 157.2343445f, 3)] - [InlineData(100f, 200f, 167.6757507f, 4)] - [InlineData(100f, 200f, 175.5068054f, 5)] - [InlineData(100f, 200f, 181.3800964f, 6)] - [InlineData(100f, 200f, 185.7850647f, 7)] - [InlineData(100f, 200f, 189.0887909f, 8)] - [InlineData(100f, 200f, 191.5665894f, 9)] - [InlineData(100f, 200f, 193.4249268f, 10)] - [InlineData(100f, 200f, 194.8186798f, 11)] - [InlineData(100f, 200f, 195.8639984f, 12)] - [InlineData(100f, 200f, 196.6479950f, 13)] - public void TargetCameraInterpolatesCorrectly( - float src, float dst, float expected, int frameIndex) - { - var entity = Substitute.For(); - entity.Position.ReturnsForAnyArgs(new Vector3(dst, -170f, -500f)); - - var camera = new Camera(); - var targetCamera = new TargetCamera(camera) - { - Type = 0, - Radius = 420f, - YRotation = 0f, - BackYRotation = 0f, - At = new Vector4(src, 0f, 500f, 1f), - AtTargetPrev = new Vector4(dst, 0f, 500f, 1f), - }; - - const double DeltaTime = 1.0 / 30.0; - while (frameIndex-- > 0) - targetCamera.Update(entity, DeltaTime); - - Assert.Equal(expected, targetCamera.At.X, 3); - } - - [Fact] - public void TargetCameraInterpolatesCorrectlyEdgeCase() - { - var entity = Substitute.For(); - entity.Position.ReturnsForAnyArgs(new Vector3(200, 300f, -400f)); - - var camera = new Camera(); - var targetCamera = new TargetCamera(camera) - { - Type = 0, - Radius = 420f, - YRotation = 0f, - BackYRotation = 0f, - At = new Vector4(100f, 300f, 500f, 1f), - AtTarget = new Vector4(200f, -470f, 500f, 1f), - AtTargetPrev = new Vector4(98f, -468f, 502f, 1f), - }; - - const int FrameCount = 10; - const double DeltaTime = 1.0 / 30.0; - for (var frame = 0; frame < FrameCount; frame++) - targetCamera.Update(entity, DeltaTime); - - var expected = new Vector4(194.24677f, -425.70007f, 405.75323f, 1); - Assert.Equal(expected, targetCamera.At); - } - - private void AssertVector3(Vector3 expected, Vector3 actual) - { - const int Precision = 3; - Assert.Equal(expected.X, actual.X, Precision); - Assert.Equal(expected.Y, actual.Y, Precision); - Assert.Equal(expected.Z, actual.Z, Precision); - } - - private void AssertMatrix(Matrix4x4 expected, Matrix4x4 actual) - { - const int Precision = 3; - Assert.Equal(expected.M11, actual.M11, Precision); - Assert.Equal(expected.M12, actual.M12, Precision); - Assert.Equal(expected.M13, actual.M13, Precision); - Assert.Equal(expected.M14, actual.M14, Precision); - Assert.Equal(expected.M21, actual.M21, Precision); - Assert.Equal(expected.M22, actual.M22, Precision); - Assert.Equal(expected.M23, actual.M23, Precision); - Assert.Equal(expected.M24, actual.M24, Precision); - Assert.Equal(expected.M31, actual.M31, Precision); - Assert.Equal(expected.M32, actual.M32, Precision); - Assert.Equal(expected.M33, actual.M33, Precision); - Assert.Equal(expected.M34, actual.M34, Precision); - Assert.Equal(expected.M41, actual.M41, Precision); - Assert.Equal(expected.M42, actual.M42, Precision); - Assert.Equal(expected.M43, actual.M43, Precision); - Assert.Equal(expected.M44, actual.M44, Precision); - } - } -} +using NSubstitute; +using OpenKh.Engine; +using System; +using System.Numerics; +using Xunit; + +namespace OpenKh.Tests.Engine +{ + public class CameraTests + { + [Theory] + [InlineData(512f, 384f, 1.5f, 1.073426127f, 1.431234717f)] + [InlineData(512f, 384f, 1.047197461f, 1.7320510149002075f, 2.309401512f)] + [InlineData(512f, 288f, 1.5f, 0.805069625377655f, 1.431234717f)] + [InlineData(512f, 288f, 1.047197461f, 1.299038291f, 2.309401512f)] + [InlineData(640f, 480f, 1.5f, 1.073426127f, 1.431234717f)] + [InlineData(1920f, 1080f, 1.047197461f, 1.299038291f, 2.309401512f)] + public void SetProjectionMatrixTest( + float width, float height, float fov, + float expectedM11, float expectedM22) + { + var camera = new Camera(); + camera.AspectRatio = width / height; + camera.FieldOfView = fov; + + AssertMatrix(new Matrix4x4( + expectedM11, 0, 0, 0, + 0, expectedM22, 0f, 0, + 0, 0f, -1f, -1f, + 0, 0, -1f, 0 + ), camera.Projection); + } + + [Fact] + public void SetWorldMatrixTest() + { + var camera = new Camera(); + camera.CameraPosition = new Vector3(0f, 251.1999969f, -920f); + camera.CameraLookAt = new Vector3(0f, 170f, -500f); + camera.CameraUp = new Vector3(0f, 1f, 0f); + + AssertMatrix(new Matrix4x4( + -1, 0, 0, 0, + 0, 0.9818192f, 0.189818367f, 0, + 0, 0.189818367f, -0.9818192f, 0, + 0, -72.00009f, -950.956f, 1 + ), camera.World); + } + + [Theory] + [InlineData(0f, 0f, 0f, 520f, -500f)] + [InlineData(420f, 0f, 0f, 251.19999f, -920f)] + [InlineData(420f, 1f, -353.4177246f, 251.199997f, -726.927002f)] + public void TargetCameraSetsPositionTest( + float radius, float yRotation, + float expectedX, float expectedY, float expectedZ) + { + var entity = Substitute.For(); + entity.Position.ReturnsForAnyArgs(new Vector3(0f, 0f, -500f)); + + var camera = new Camera(); + var targetCamera = new TargetCamera(camera) + { + Type = 0, + Radius = radius, + YRotation = yRotation, + BackYRotation = yRotation, + Interpolate = false, + }; + targetCamera.Update(entity, 0); + + var expected = new Vector3(expectedX, expectedY, expectedZ); + AssertVector3(expected, camera.CameraPosition); + } + + [Fact] + public void TargetCameraSetCorrectValuesToCamera() + { + var entity = Substitute.For(); + entity.Position.ReturnsForAnyArgs(new Vector3(0f, 150f, 0f)); + + var camera = new Camera(); + var targetCamera = new TargetCamera(camera) + { + Type = 0, + Radius = 420f, + YRotation = 0f, + BackYRotation = 0f, + Interpolate = false, + }; + targetCamera.Update(entity, 0); + + var expectedPosition = new Vector3(0f, 401.2f, -420); + var expectedLookAt = new Vector3(0f, 320f, 0f); + AssertVector3(expectedPosition, camera.CameraPosition); + AssertVector3(expectedLookAt, camera.CameraLookAt); + } + + [Theory] + [InlineData(Math.PI, Math.PI)] + [InlineData(0, 0)] + [InlineData(-Math.PI, Math.PI)] + [InlineData(1, -1)] + [InlineData(4, 2.2831852436065674f)] + public void TargetCameraRotatesInstantlyOnEntity( + float entityRotation, float expected) + { + var entity = Substitute.For(); + entity.Rotation.ReturnsForAnyArgs(new Vector3(0f, entityRotation, 0f)); + + var camera = new Camera(); + var targetCamera = new TargetCamera(camera) + { + Type = 0, + Radius = 420f, + YRotation = 0f, + BackYRotation = 0f, + Interpolate = false + }; + targetCamera.InstantlyRotateCameraToEntity(entity); + targetCamera.Update(entity, 0); + + Assert.Equal(expected, targetCamera.YRotation, 4); + } + + [Theory] + [InlineData(100f, 200f, 100f, 0)] + [InlineData(100f, 200f, 124.7499924f, 1)] + [InlineData(100f, 200f, 143.3124847f, 2)] + [InlineData(100f, 200f, 157.2343445f, 3)] + [InlineData(100f, 200f, 167.6757507f, 4)] + [InlineData(100f, 200f, 175.5068054f, 5)] + [InlineData(100f, 200f, 181.3800964f, 6)] + [InlineData(100f, 200f, 185.7850647f, 7)] + [InlineData(100f, 200f, 189.0887909f, 8)] + [InlineData(100f, 200f, 191.5665894f, 9)] + [InlineData(100f, 200f, 193.4249268f, 10)] + [InlineData(100f, 200f, 194.8186798f, 11)] + [InlineData(100f, 200f, 195.8639984f, 12)] + [InlineData(100f, 200f, 196.6479950f, 13)] + public void TargetCameraInterpolatesCorrectly( + float src, float dst, float expected, int frameIndex) + { + var entity = Substitute.For(); + entity.Position.ReturnsForAnyArgs(new Vector3(dst, -170f, -500f)); + + var camera = new Camera(); + var targetCamera = new TargetCamera(camera) + { + Type = 0, + Radius = 420f, + YRotation = 0f, + BackYRotation = 0f, + At = new Vector4(src, 0f, 500f, 1f), + AtTargetPrev = new Vector4(dst, 0f, 500f, 1f), + }; + + const double DeltaTime = 1.0 / 30.0; + while (frameIndex-- > 0) + targetCamera.Update(entity, DeltaTime); + + Assert.Equal(expected, targetCamera.At.X, 3); + } + + [Fact] + public void TargetCameraInterpolatesCorrectlyEdgeCase() + { + var entity = Substitute.For(); + entity.Position.ReturnsForAnyArgs(new Vector3(200, 300f, -400f)); + + var camera = new Camera(); + var targetCamera = new TargetCamera(camera) + { + Type = 0, + Radius = 420f, + YRotation = 0f, + BackYRotation = 0f, + At = new Vector4(100f, 300f, 500f, 1f), + AtTarget = new Vector4(200f, -470f, 500f, 1f), + AtTargetPrev = new Vector4(98f, -468f, 502f, 1f), + }; + + const int FrameCount = 10; + const double DeltaTime = 1.0 / 30.0; + for (var frame = 0; frame < FrameCount; frame++) + targetCamera.Update(entity, DeltaTime); + + var expected = new Vector4(194.24677f, -425.70007f, 405.75323f, 1); + Assert.Equal(expected, targetCamera.At); + } + + private void AssertVector3(Vector3 expected, Vector3 actual) + { + const int Precision = 3; + Assert.Equal(expected.X, actual.X, Precision); + Assert.Equal(expected.Y, actual.Y, Precision); + Assert.Equal(expected.Z, actual.Z, Precision); + } + + private void AssertMatrix(Matrix4x4 expected, Matrix4x4 actual) + { + const int Precision = 3; + Assert.Equal(expected.M11, actual.M11, Precision); + Assert.Equal(expected.M12, actual.M12, Precision); + Assert.Equal(expected.M13, actual.M13, Precision); + Assert.Equal(expected.M14, actual.M14, Precision); + Assert.Equal(expected.M21, actual.M21, Precision); + Assert.Equal(expected.M22, actual.M22, Precision); + Assert.Equal(expected.M23, actual.M23, Precision); + Assert.Equal(expected.M24, actual.M24, Precision); + Assert.Equal(expected.M31, actual.M31, Precision); + Assert.Equal(expected.M32, actual.M32, Precision); + Assert.Equal(expected.M33, actual.M33, Precision); + Assert.Equal(expected.M34, actual.M34, Precision); + Assert.Equal(expected.M41, actual.M41, Precision); + Assert.Equal(expected.M42, actual.M42, Precision); + Assert.Equal(expected.M43, actual.M43, Precision); + Assert.Equal(expected.M44, actual.M44, Precision); + } + } +} diff --git a/OpenKh.Tests.Engine/Extensions.cs b/OpenKh.Tests.Engine/Extensions.cs index 07c6e1e56..3174a6858 100644 --- a/OpenKh.Tests.Engine/Extensions.cs +++ b/OpenKh.Tests.Engine/Extensions.cs @@ -1,42 +1,42 @@ -using NSubstitute; -using OpenKh.Engine.Renders; -using System; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Engine -{ - public static class Extensions - { - public static ISpriteDrawing MockDrawing() => Substitute.For(); - - public static void AssertAtLeastOneCall(this ISpriteDrawing drawing) - { - if (!drawing.ReceivedCalls().Any()) - throw new Xunit.Sdk.XunitException("Expected at least draw but no draw has been performed."); - } - - public static void AssertNoCall(this ISpriteDrawing drawing) - { - if (drawing.ReceivedCalls().Any()) - throw new Xunit.Sdk.XunitException("Expected no draws but at least once has been performed."); - } - - public static void AssertCallCount(this ISpriteDrawing drawing, int count) - { - var actual = drawing.ReceivedCalls().Count(); - if (actual != count) - throw new Xunit.Sdk.XunitException($"Expected {count} draw counts, but got {actual}."); - } - - public static void AssertDraw(this ISpriteDrawing drawing, Action assertion) => - drawing.AssertDraw(0, assertion); - - public static void AssertDraw(this ISpriteDrawing drawing, int callIndex, Action assertion) - { - var call = drawing.ReceivedCalls().Skip(callIndex).FirstOrDefault(); - Assert.NotNull(call); - assertion(call.GetArguments()[0] as SpriteDrawingContext); - } - } -} +using NSubstitute; +using OpenKh.Engine.Renders; +using System; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Engine +{ + public static class Extensions + { + public static ISpriteDrawing MockDrawing() => Substitute.For(); + + public static void AssertAtLeastOneCall(this ISpriteDrawing drawing) + { + if (!drawing.ReceivedCalls().Any()) + throw new Xunit.Sdk.XunitException("Expected at least draw but no draw has been performed."); + } + + public static void AssertNoCall(this ISpriteDrawing drawing) + { + if (drawing.ReceivedCalls().Any()) + throw new Xunit.Sdk.XunitException("Expected no draws but at least once has been performed."); + } + + public static void AssertCallCount(this ISpriteDrawing drawing, int count) + { + var actual = drawing.ReceivedCalls().Count(); + if (actual != count) + throw new Xunit.Sdk.XunitException($"Expected {count} draw counts, but got {actual}."); + } + + public static void AssertDraw(this ISpriteDrawing drawing, Action assertion) => + drawing.AssertDraw(0, assertion); + + public static void AssertDraw(this ISpriteDrawing drawing, int callIndex, Action assertion) + { + var call = drawing.ReceivedCalls().Skip(callIndex).FirstOrDefault(); + Assert.NotNull(call); + assertion(call.GetArguments()[0] as SpriteDrawingContext); + } + } +} diff --git a/OpenKh.Tests.Engine/Kh2EventTests.cs b/OpenKh.Tests.Engine/Kh2EventTests.cs index e51e8d97e..b8727c358 100644 --- a/OpenKh.Tests.Engine/Kh2EventTests.cs +++ b/OpenKh.Tests.Engine/Kh2EventTests.cs @@ -1,437 +1,437 @@ -using NSubstitute; -using OpenKh.Game.Events; -using OpenKh.Game.Field; -using OpenKh.Game.Infrastructure; -using OpenKh.Kh2.Ard; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Engine -{ - public class Kh2EventTests - { - [Theory] - [InlineData(0, -309.26f, -2446.09f, -1473.91f)] - [InlineData(1, -309.26f, -2446.09f, -1473.91f)] - [InlineData(2, -307.93f, -2445.79f, -1473.73f)] - [InlineData(3, -304.03f, -2444.88f, -1473.18f)] - [InlineData(4, -297.68f, -2443.38f, -1472.28f)] - [InlineData(5, -289.03f, -2441.28f, -1471.01f)] - [InlineData(6, -278.22f, -2438.59f, -1469.39f)] - [InlineData(7, -265.37f, -2435.33f, -1467.42f)] - [InlineData(8, -250.63f, -2431.49f, -1465.11f)] - [InlineData(9, -234.12f, -2427.09f, -1462.45f)] - [InlineData(10, -216.00f, -2422.12f, -1459.45f)] - [InlineData(11, -196.38f, -2416.59f, -1456.12f)] - [InlineData(12, -175.41f, -2410.52f, -1452.45f)] - [InlineData(13, -153.22f, -2403.90f, -1448.46f)] - [InlineData(14, -129.95f, -2396.74f, -1444.13f)] - [InlineData(15, -105.73f, -2389.05f, -1439.49f)] - [InlineData(16, -80.70f, -2380.84f, -1434.52f)] - [InlineData(17, -55.00f, -2372.10f, -1429.24f)] - [InlineData(18, -28.76f, -2362.85f, -1423.65f)] - [InlineData(19, -2.11f, -2353.09f, -1417.75f)] - [InlineData(20, 24.81f, -2342.83f, -1411.54f)] - [InlineData(21, 51.86f, -2332.07f, -1405.03f)] - [InlineData(22, 78.90f, -2320.82f, -1398.22f)] - [InlineData(23, 105.81f, -2309.08f, -1391.12f)] - [InlineData(24, 132.44f, -2296.87f, -1383.73f)] - [InlineData(25, 158.66f, -2284.18f, -1376.04f)] - [InlineData(26, 184.34f, -2271.03f, -1368.08f)] - [InlineData(27, 209.34f, -2257.42f, -1359.83f)] - [InlineData(28, 233.52f, -2243.35f, -1351.30f)] - [InlineData(29, 256.74f, -2228.83f, -1342.50f)] - [InlineData(30, 278.88f, -2213.87f, -1333.43f)] - [InlineData(31, 299.80f, -2198.47f, -1324.08f)] - [InlineData(32, 319.35f, -2182.64f, -1314.48f)] - [InlineData(33, 337.42f, -2166.39f, -1304.61f)] - [InlineData(34, 353.85f, -2149.71f, -1294.49f)] - [InlineData(35, 368.51f, -2132.63f, -1284.11f)] - [InlineData(36, 381.27f, -2115.13f, -1273.49f)] - [InlineData(37, 392.00f, -2097.24f, -1262.61f)] - [InlineData(38, 400.55f, -2078.94f, -1251.49f)] - [InlineData(39, 406.79f, -2060.26f, -1240.14f)] - [InlineData(40, 410.59f, -2041.20f, -1228.54f)] - [InlineData(41, 411.81f, -2021.76f, -1216.71f)] - [InlineData(42, 410.06f, -2001.95f, -1204.65f)] - [InlineData(43, 405.21f, -1981.77f, -1192.37f)] - [InlineData(44, 397.45f, -1961.23f, -1179.86f)] - [InlineData(45, 386.95f, -1940.34f, -1167.14f)] - [InlineData(46, 373.90f, -1919.10f, -1154.19f)] - [InlineData(47, 358.49f, -1897.52f, -1141.04f)] - [InlineData(48, 340.89f, -1875.60f, -1127.67f)] - [InlineData(49, 321.28f, -1853.35f, -1114.10f)] - [InlineData(50, 299.86f, -1830.78f, -1100.33f)] - [InlineData(51, 276.80f, -1807.89f, -1086.35f)] - [InlineData(52, 252.29f, -1784.69f, -1072.18f)] - [InlineData(53, 226.504f, -1761.18f, -1057.82f)] - [InlineData(54, 199.63f, -1737.38f, -1043.28f)] - [InlineData(55, 171.86f, -1713.27f, -1028.54f)] - [InlineData(56, 143.36f, -1688.89f, -1013.63f)] - [InlineData(57, 114.32f, -1664.21f, -998.53f)] - [InlineData(58, 84.93f, -1639.27f, -983.26f)] - [InlineData(59, 55.36f, -1614.05f, -967.82f)] - [InlineData(60, 25.80f, -1588.56f, -952.21f)] - [InlineData(61, -3.57f, -1562.82f, -936.44f)] - [InlineData(62, -32.56f, -1536.83f, -920.51f)] - [InlineData(63, -60.99f, -1510.59f, -904.41f)] - [InlineData(64, -88.68f, -1484.11f, -888.16f)] - [InlineData(65, -115.45f, -1457.40f, -871.77f)] - [InlineData(66, -141.12f, -1430.45f, -855.22f)] - [InlineData(67, -165.49f, -1403.29f, -838.53f)] - [InlineData(68, -188.40f, -1375.90f, -821.70f)] - [InlineData(69, -209.64f, -1348.31f, -804.74f)] - [InlineData(70, -229.05f, -1320.51f, -787.64f)] - [InlineData(71, -246.44f, -1292.51f, -770.41f)] - [InlineData(72, -261.63f, -1264.32f, -753.05f)] - [InlineData(73, -274.43f, -1235.95f, -735.57f)] - [InlineData(74, -284.66f, -1207.39f, -717.97f)] - [InlineData(75, -292.14f, -1178.66f, -700.25f)] - [InlineData(76, -296.69f, -1149.75f, -682.42f)] - [InlineData(77, -298.12f, -1120.69f, -664.48f)] - [InlineData(78, -297.33f, -1091.47f, -646.43f)] - [InlineData(79, -295.19f, -1062.09f, -628.28f)] - [InlineData(80, -291.75f, -1032.58f, -610.04f)] - [InlineData(81, -287.08f, -1002.92f, -591.69f)] - [InlineData(82, -281.28f, -973.13f, -573.25f)] - [InlineData(83, -274.39f, -943.21f, -554.73f)] - [InlineData(84, -266.51f, -913.17f, -536.12f)] - [InlineData(85, -257.69f, -883.02f, -517.42f)] - [InlineData(86, -248.01f, -852.75f, -498.65f)] - [InlineData(87, -237.55f, -822.38f, -479.80f)] - [InlineData(88, -226.38f, -791.92f, -460.88f)] - [InlineData(89, -214.57f, -761.36f, -441.90f)] - [InlineData(90, -202.19f, -730.72f, -422.84f)] - [InlineData(91, -189.31f, -700.00f, -403.73f)] - [InlineData(92, -176.01f, -669.20f, -384.56f)] - [InlineData(93, -162.36f, -638.34f, -365.33f)] - [InlineData(94, -148.43f, -607.41f, -346.05f)] - [InlineData(95, -134.29f, -576.43f, -326.72f)] - [InlineData(96, -120.02f, -545.40f, -307.35f)] - [InlineData(97, -106.03f, -515.05f, -288.40f)] - [InlineData(98, -106.03f, -515.05f, -288.40f)] - [InlineData(99, -106.03f, -515.05f, -288.40f)] - public void InterpolateCameraTest(float time, float eyex, float eyey, float eyez) - { - var fakeField = Substitute.For(); - var eventPlayer = new EventPlayer(fakeField, new List - { - new Event.SetEndFrame - { - EndFrame = 100 - }, - new Event.SetupEvent(), - new Event.SetCameraData - { - CameraId = 0, - PositionX = CameraDataSingleValue(-309.26492f), - PositionY = CameraDataSingleValue(2446.094f), - PositionZ = CameraDataSingleValue(1473.9126f), - LookAtX = CameraDataSingleValue(0f), - LookAtY = CameraDataSingleValue(113.279144f), - LookAtZ = CameraDataSingleValue(20.983765f), - Roll = CameraDataSingleValue(0f), - FieldOfView = CameraDataSingleValue(48.41243f), - }, - new Event.SetCameraData - { - CameraId = 1, - PositionX = new List - { - CameraDataValue(-309.26492f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), - CameraDataValue(411.81467f, Kh2.Motion.Interpolation.Hermite, 341, -0.6224821f, -0.6224821f), - CameraDataValue(-298.11935f, Kh2.Motion.Interpolation.Hermite, 648, -0.8131355f, -0.8131355f), - CameraDataValue(-106.03006f, Kh2.Motion.Interpolation.Linear, 819, 860.1719f, 860.1719f), - CameraDataValue(-106.03006f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), - }, - PositionY = new List - { - CameraDataValue(2446.094f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), - CameraDataValue(515.0501f, Kh2.Motion.Interpolation.Linear, 819, -1865.6649f, -1865.6649f), - CameraDataValue(515.0501f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), - }, - PositionZ = new List - { - CameraDataValue(1473.9126f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), - CameraDataValue(288.39706f, Kh2.Motion.Interpolation.Linear, 819, -1165.8065f, -1165.8065f), - CameraDataValue(288.39706f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), - }, - LookAtX = new List - { - CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), - CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 341, 0f, 0f), - CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 648, 0f, 0f), - CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 819, 0f, 0f), - CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), - }, - LookAtY = new List - { - CameraDataValue(113.279144f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), - CameraDataValue(113.279144f, Kh2.Motion.Interpolation.Hermite, 341, 0f, 0f), - CameraDataValue(113.279144f, Kh2.Motion.Interpolation.Hermite, 648, 0f, 0f), - CameraDataValue(113.279144f, Kh2.Motion.Interpolation.Linear, 819, 0f, 0f), - CameraDataValue(113.279144f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), - }, - LookAtZ = new List - { - CameraDataValue(20.983765f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), - CameraDataValue(20.983765f, Kh2.Motion.Interpolation.Hermite, 341, 0f, 0f), - CameraDataValue(20.983765f, Kh2.Motion.Interpolation.Hermite, 648, 0f, 0f), - CameraDataValue(20.983765f, Kh2.Motion.Interpolation.Linear, 819, 0f, 0f), - CameraDataValue(20.983765f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), - }, - Roll = new List - { - CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), - CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 341, 0f, 0f), - CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 648, 0f, 0f), - CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 819, 0f, 0f), - CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), - }, - FieldOfView = new List - { - CameraDataValue(48.41243f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), - CameraDataValue(48.41243f, Kh2.Motion.Interpolation.Hermite, 341, 0f, 0f), - CameraDataValue(48.41243f, Kh2.Motion.Interpolation.Hermite, 648, 0f, 0f), - CameraDataValue(48.41243f, Kh2.Motion.Interpolation.Linear, 819, 0f, 0f), - CameraDataValue(48.41243f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), - }, - }, - new Event.SeqCamera - { - CameraId = 0, - FrameStart = 0, - FrameEnd = 100, - }, - new Event.SeqCamera - { - CameraId = 1, - FrameStart = 1, - FrameEnd = 101, - }, - }); - - eventPlayer.Initialize(); - eventPlayer.Update(1 / 60.0 * time); - - var setCameraCall = fakeField.ReceivedCalls().FirstOrDefault(); - Assert.NotNull(setCameraCall); - - var actualEye = (System.Numerics.Vector3)setCameraCall.GetArguments()[0]; - var actualCenter = (System.Numerics.Vector3)setCameraCall.GetArguments()[1]; - var actualFov = (float)setCameraCall.GetArguments()[2]; - var actualRoll = (float)setCameraCall.GetArguments()[3]; - Assert.Equal(eyex, actualEye.X, 0); - Assert.Equal(eyey, -actualEye.Y, 0); - Assert.Equal(eyez, -actualEye.Z, 0); - Assert.Equal(0, actualCenter.X, 0); - Assert.Equal(-113.28f, -actualCenter.Y, 0); - Assert.Equal(-20.98f, -actualCenter.Z, 0); - Assert.Equal(0f, actualRoll, 0); - Assert.Equal(48.41f, actualFov, 0); - } - - [Theory] - [InlineData(122, -123.61f, -122.43f)] - [InlineData(140, -123.68f, -122.80f)] - [InlineData(180, -126.95f, -125.76f)] - [InlineData(200, -129.38f, -128.20f)] - [InlineData(438, -176.39, -175.20)] - [InlineData(444, -177.35, -176.17)] - public void InterpolateCameraSecondTest(float time, float eyey, float centery) - { - var fakeField = Substitute.For(); - var eventPlayer = new EventPlayer(fakeField, new List - { - new Event.SetEndFrame - { - EndFrame = 300 - }, - new Event.SetupEvent(), - new Event.SetCameraData - { - CameraId = 0, - PositionX = CameraDataSingleValue(40.186035f), - PositionY = CameraDataSingleValue(271.22748f), - PositionZ = CameraDataSingleValue(527.7301f), - LookAtX = CameraDataSingleValue(-79.38527f), - LookAtY = CameraDataSingleValue(90.874115f), - LookAtZ = CameraDataSingleValue(-78.414696f), - Roll = CameraDataSingleValue(0f), - FieldOfView = CameraDataSingleValue(41.092915f), - }, - new Event.SetCameraData - { - CameraId = 1, - PositionX = new List - { - CameraDataValue(-317.25266f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), - CameraDataValue(-317.25266f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), - CameraDataValue(-317.25266f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), - }, - PositionY = new List - { - CameraDataValue(123.61203f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), - CameraDataValue(185.76723f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), - CameraDataValue(185.76723f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), - }, - PositionZ = new List - { - CameraDataValue(-79.360405f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), - CameraDataValue(-79.360405f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), - CameraDataValue(-79.360405f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), - }, - LookAtX = new List - { - CameraDataValue(-357.23502f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), - CameraDataValue(-357.23502f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), - CameraDataValue(-357.23502f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), - }, - LookAtY = new List - { - CameraDataValue(122.42929f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), - CameraDataValue(184.58449f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), - CameraDataValue(184.58449f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), - }, - LookAtZ = new List - { - CameraDataValue(-217.77927f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), - CameraDataValue(-217.77927f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), - CameraDataValue(-217.77927f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), - }, - Roll = new List - { - CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), - CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), - CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), - }, - FieldOfView = new List - { - CameraDataValue(42.026005f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), - CameraDataValue(42.026005f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), - CameraDataValue(42.026005f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), - }, - }, - new Event.SeqCamera - { - CameraId = 0, - FrameStart = 15, - FrameEnd = 75, - }, - new Event.SeqCamera - { - CameraId = 1, - FrameStart = 76, - FrameEnd = 286, - }, - }); - - eventPlayer.Initialize(); - eventPlayer.Update(1 / 60.0 * (time + 30f)); - - var setCameraCall = fakeField.ReceivedCalls().FirstOrDefault(); - Assert.NotNull(setCameraCall); - - var actualEye = (System.Numerics.Vector3)setCameraCall.GetArguments()[0]; - var actualCenter = (System.Numerics.Vector3)setCameraCall.GetArguments()[1]; - var actualFov = (float)setCameraCall.GetArguments()[2]; - var actualRoll = (float)setCameraCall.GetArguments()[3]; - Assert.Equal(-317.25266f, actualEye.X, 0); - Assert.Equal(eyey, -actualEye.Y, 0); - Assert.Equal(79.360405f, -actualEye.Z, 0); - Assert.Equal(-357.23502f, actualCenter.X, 0); - Assert.Equal(centery, -actualCenter.Y, 0); - Assert.Equal(217.77927f, -actualCenter.Z, 0); - Assert.Equal(0f, actualRoll, 0); - Assert.Equal(42.026005f, actualFov, 0); - } - - [Theory] - [InlineData(30, false)] - [InlineData(60, true)] - [InlineData(120, true)] - [InlineData(180, false)] - public void ActorSceneVisibility(float time, bool expectedActorVisibility) - { - const int ActorId = 0; - const int FrameActorAppear = 50; - const string MotionPath = "anm_ex/motion"; - - var fakeField = Substitute.For(); - var eventPlayer = new EventPlayer(fakeField, new List - { - new Event.SetEndFrame - { - EndFrame = 1000 - }, - new Event.ReadAssets - { - FrameStart = -32767, - FrameEnd = 0, - Unk06 = 0, - Set = new List - { - new Event.ReadActor - { - ObjectId = 123, - ActorId = ActorId, - Name = "main_actor" - }, - new Event.ReadMotion - { - ObjectId = 123, - ActorId = ActorId, - Name = MotionPath, - UnknownIndex = 1, - }, - } - }, - new Event.SetActor - { - ObjectEntry = 123, - ActorId = ActorId, - Name = "main_actor" - }, - new Event.SeqPlayAnimation - { - FrameStart = FrameActorAppear, - FrameEnd = 100, - ActorId = ActorId, - Path = MotionPath - }, - new Event.SeqActorLeave - { - Frame = 150, - ActorId = ActorId - } - }); - - bool? lastVisibility = null; - - fakeField.SetActorVisibility(Arg.Is(ActorId), Arg.Do(x => lastVisibility = x)); - eventPlayer.Initialize(); - for (var i = 0; i < time; i++) - eventPlayer.Update(1f / 30.0f); - - Assert.Equal(expectedActorVisibility, lastVisibility); - } - - private static Event.SetCameraData.CameraKeys CameraDataValue( - float value, Kh2.Motion.Interpolation interpolation, int keyFrame, float left, float right) => - new Event.SetCameraData.CameraKeys - { - Interpolation = interpolation, - KeyFrame = keyFrame, - Value = value, - TangentEaseIn = left, - TangentEaseOut = right - }; - - private static List CameraDataSingleValue(float value) => - new List() - { - CameraDataValue(value, Kh2.Motion.Interpolation.Hermite, 0, 0, 0) - }; - } -} +using NSubstitute; +using OpenKh.Game.Events; +using OpenKh.Game.Field; +using OpenKh.Game.Infrastructure; +using OpenKh.Kh2.Ard; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Engine +{ + public class Kh2EventTests + { + [Theory] + [InlineData(0, -309.26f, -2446.09f, -1473.91f)] + [InlineData(1, -309.26f, -2446.09f, -1473.91f)] + [InlineData(2, -307.93f, -2445.79f, -1473.73f)] + [InlineData(3, -304.03f, -2444.88f, -1473.18f)] + [InlineData(4, -297.68f, -2443.38f, -1472.28f)] + [InlineData(5, -289.03f, -2441.28f, -1471.01f)] + [InlineData(6, -278.22f, -2438.59f, -1469.39f)] + [InlineData(7, -265.37f, -2435.33f, -1467.42f)] + [InlineData(8, -250.63f, -2431.49f, -1465.11f)] + [InlineData(9, -234.12f, -2427.09f, -1462.45f)] + [InlineData(10, -216.00f, -2422.12f, -1459.45f)] + [InlineData(11, -196.38f, -2416.59f, -1456.12f)] + [InlineData(12, -175.41f, -2410.52f, -1452.45f)] + [InlineData(13, -153.22f, -2403.90f, -1448.46f)] + [InlineData(14, -129.95f, -2396.74f, -1444.13f)] + [InlineData(15, -105.73f, -2389.05f, -1439.49f)] + [InlineData(16, -80.70f, -2380.84f, -1434.52f)] + [InlineData(17, -55.00f, -2372.10f, -1429.24f)] + [InlineData(18, -28.76f, -2362.85f, -1423.65f)] + [InlineData(19, -2.11f, -2353.09f, -1417.75f)] + [InlineData(20, 24.81f, -2342.83f, -1411.54f)] + [InlineData(21, 51.86f, -2332.07f, -1405.03f)] + [InlineData(22, 78.90f, -2320.82f, -1398.22f)] + [InlineData(23, 105.81f, -2309.08f, -1391.12f)] + [InlineData(24, 132.44f, -2296.87f, -1383.73f)] + [InlineData(25, 158.66f, -2284.18f, -1376.04f)] + [InlineData(26, 184.34f, -2271.03f, -1368.08f)] + [InlineData(27, 209.34f, -2257.42f, -1359.83f)] + [InlineData(28, 233.52f, -2243.35f, -1351.30f)] + [InlineData(29, 256.74f, -2228.83f, -1342.50f)] + [InlineData(30, 278.88f, -2213.87f, -1333.43f)] + [InlineData(31, 299.80f, -2198.47f, -1324.08f)] + [InlineData(32, 319.35f, -2182.64f, -1314.48f)] + [InlineData(33, 337.42f, -2166.39f, -1304.61f)] + [InlineData(34, 353.85f, -2149.71f, -1294.49f)] + [InlineData(35, 368.51f, -2132.63f, -1284.11f)] + [InlineData(36, 381.27f, -2115.13f, -1273.49f)] + [InlineData(37, 392.00f, -2097.24f, -1262.61f)] + [InlineData(38, 400.55f, -2078.94f, -1251.49f)] + [InlineData(39, 406.79f, -2060.26f, -1240.14f)] + [InlineData(40, 410.59f, -2041.20f, -1228.54f)] + [InlineData(41, 411.81f, -2021.76f, -1216.71f)] + [InlineData(42, 410.06f, -2001.95f, -1204.65f)] + [InlineData(43, 405.21f, -1981.77f, -1192.37f)] + [InlineData(44, 397.45f, -1961.23f, -1179.86f)] + [InlineData(45, 386.95f, -1940.34f, -1167.14f)] + [InlineData(46, 373.90f, -1919.10f, -1154.19f)] + [InlineData(47, 358.49f, -1897.52f, -1141.04f)] + [InlineData(48, 340.89f, -1875.60f, -1127.67f)] + [InlineData(49, 321.28f, -1853.35f, -1114.10f)] + [InlineData(50, 299.86f, -1830.78f, -1100.33f)] + [InlineData(51, 276.80f, -1807.89f, -1086.35f)] + [InlineData(52, 252.29f, -1784.69f, -1072.18f)] + [InlineData(53, 226.504f, -1761.18f, -1057.82f)] + [InlineData(54, 199.63f, -1737.38f, -1043.28f)] + [InlineData(55, 171.86f, -1713.27f, -1028.54f)] + [InlineData(56, 143.36f, -1688.89f, -1013.63f)] + [InlineData(57, 114.32f, -1664.21f, -998.53f)] + [InlineData(58, 84.93f, -1639.27f, -983.26f)] + [InlineData(59, 55.36f, -1614.05f, -967.82f)] + [InlineData(60, 25.80f, -1588.56f, -952.21f)] + [InlineData(61, -3.57f, -1562.82f, -936.44f)] + [InlineData(62, -32.56f, -1536.83f, -920.51f)] + [InlineData(63, -60.99f, -1510.59f, -904.41f)] + [InlineData(64, -88.68f, -1484.11f, -888.16f)] + [InlineData(65, -115.45f, -1457.40f, -871.77f)] + [InlineData(66, -141.12f, -1430.45f, -855.22f)] + [InlineData(67, -165.49f, -1403.29f, -838.53f)] + [InlineData(68, -188.40f, -1375.90f, -821.70f)] + [InlineData(69, -209.64f, -1348.31f, -804.74f)] + [InlineData(70, -229.05f, -1320.51f, -787.64f)] + [InlineData(71, -246.44f, -1292.51f, -770.41f)] + [InlineData(72, -261.63f, -1264.32f, -753.05f)] + [InlineData(73, -274.43f, -1235.95f, -735.57f)] + [InlineData(74, -284.66f, -1207.39f, -717.97f)] + [InlineData(75, -292.14f, -1178.66f, -700.25f)] + [InlineData(76, -296.69f, -1149.75f, -682.42f)] + [InlineData(77, -298.12f, -1120.69f, -664.48f)] + [InlineData(78, -297.33f, -1091.47f, -646.43f)] + [InlineData(79, -295.19f, -1062.09f, -628.28f)] + [InlineData(80, -291.75f, -1032.58f, -610.04f)] + [InlineData(81, -287.08f, -1002.92f, -591.69f)] + [InlineData(82, -281.28f, -973.13f, -573.25f)] + [InlineData(83, -274.39f, -943.21f, -554.73f)] + [InlineData(84, -266.51f, -913.17f, -536.12f)] + [InlineData(85, -257.69f, -883.02f, -517.42f)] + [InlineData(86, -248.01f, -852.75f, -498.65f)] + [InlineData(87, -237.55f, -822.38f, -479.80f)] + [InlineData(88, -226.38f, -791.92f, -460.88f)] + [InlineData(89, -214.57f, -761.36f, -441.90f)] + [InlineData(90, -202.19f, -730.72f, -422.84f)] + [InlineData(91, -189.31f, -700.00f, -403.73f)] + [InlineData(92, -176.01f, -669.20f, -384.56f)] + [InlineData(93, -162.36f, -638.34f, -365.33f)] + [InlineData(94, -148.43f, -607.41f, -346.05f)] + [InlineData(95, -134.29f, -576.43f, -326.72f)] + [InlineData(96, -120.02f, -545.40f, -307.35f)] + [InlineData(97, -106.03f, -515.05f, -288.40f)] + [InlineData(98, -106.03f, -515.05f, -288.40f)] + [InlineData(99, -106.03f, -515.05f, -288.40f)] + public void InterpolateCameraTest(float time, float eyex, float eyey, float eyez) + { + var fakeField = Substitute.For(); + var eventPlayer = new EventPlayer(fakeField, new List + { + new Event.SetEndFrame + { + EndFrame = 100 + }, + new Event.SetupEvent(), + new Event.SetCameraData + { + CameraId = 0, + PositionX = CameraDataSingleValue(-309.26492f), + PositionY = CameraDataSingleValue(2446.094f), + PositionZ = CameraDataSingleValue(1473.9126f), + LookAtX = CameraDataSingleValue(0f), + LookAtY = CameraDataSingleValue(113.279144f), + LookAtZ = CameraDataSingleValue(20.983765f), + Roll = CameraDataSingleValue(0f), + FieldOfView = CameraDataSingleValue(48.41243f), + }, + new Event.SetCameraData + { + CameraId = 1, + PositionX = new List + { + CameraDataValue(-309.26492f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), + CameraDataValue(411.81467f, Kh2.Motion.Interpolation.Hermite, 341, -0.6224821f, -0.6224821f), + CameraDataValue(-298.11935f, Kh2.Motion.Interpolation.Hermite, 648, -0.8131355f, -0.8131355f), + CameraDataValue(-106.03006f, Kh2.Motion.Interpolation.Linear, 819, 860.1719f, 860.1719f), + CameraDataValue(-106.03006f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), + }, + PositionY = new List + { + CameraDataValue(2446.094f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), + CameraDataValue(515.0501f, Kh2.Motion.Interpolation.Linear, 819, -1865.6649f, -1865.6649f), + CameraDataValue(515.0501f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), + }, + PositionZ = new List + { + CameraDataValue(1473.9126f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), + CameraDataValue(288.39706f, Kh2.Motion.Interpolation.Linear, 819, -1165.8065f, -1165.8065f), + CameraDataValue(288.39706f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), + }, + LookAtX = new List + { + CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), + CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 341, 0f, 0f), + CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 648, 0f, 0f), + CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 819, 0f, 0f), + CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), + }, + LookAtY = new List + { + CameraDataValue(113.279144f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), + CameraDataValue(113.279144f, Kh2.Motion.Interpolation.Hermite, 341, 0f, 0f), + CameraDataValue(113.279144f, Kh2.Motion.Interpolation.Hermite, 648, 0f, 0f), + CameraDataValue(113.279144f, Kh2.Motion.Interpolation.Linear, 819, 0f, 0f), + CameraDataValue(113.279144f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), + }, + LookAtZ = new List + { + CameraDataValue(20.983765f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), + CameraDataValue(20.983765f, Kh2.Motion.Interpolation.Hermite, 341, 0f, 0f), + CameraDataValue(20.983765f, Kh2.Motion.Interpolation.Hermite, 648, 0f, 0f), + CameraDataValue(20.983765f, Kh2.Motion.Interpolation.Linear, 819, 0f, 0f), + CameraDataValue(20.983765f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), + }, + Roll = new List + { + CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), + CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 341, 0f, 0f), + CameraDataValue(0f, Kh2.Motion.Interpolation.Hermite, 648, 0f, 0f), + CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 819, 0f, 0f), + CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), + }, + FieldOfView = new List + { + CameraDataValue(48.41243f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), + CameraDataValue(48.41243f, Kh2.Motion.Interpolation.Hermite, 341, 0f, 0f), + CameraDataValue(48.41243f, Kh2.Motion.Interpolation.Hermite, 648, 0f, 0f), + CameraDataValue(48.41243f, Kh2.Motion.Interpolation.Linear, 819, 0f, 0f), + CameraDataValue(48.41243f, Kh2.Motion.Interpolation.Linear, 1024, 0f, 0f), + }, + }, + new Event.SeqCamera + { + CameraId = 0, + FrameStart = 0, + FrameEnd = 100, + }, + new Event.SeqCamera + { + CameraId = 1, + FrameStart = 1, + FrameEnd = 101, + }, + }); + + eventPlayer.Initialize(); + eventPlayer.Update(1 / 60.0 * time); + + var setCameraCall = fakeField.ReceivedCalls().FirstOrDefault(); + Assert.NotNull(setCameraCall); + + var actualEye = (System.Numerics.Vector3)setCameraCall.GetArguments()[0]; + var actualCenter = (System.Numerics.Vector3)setCameraCall.GetArguments()[1]; + var actualFov = (float)setCameraCall.GetArguments()[2]; + var actualRoll = (float)setCameraCall.GetArguments()[3]; + Assert.Equal(eyex, actualEye.X, 0); + Assert.Equal(eyey, -actualEye.Y, 0); + Assert.Equal(eyez, -actualEye.Z, 0); + Assert.Equal(0, actualCenter.X, 0); + Assert.Equal(-113.28f, -actualCenter.Y, 0); + Assert.Equal(-20.98f, -actualCenter.Z, 0); + Assert.Equal(0f, actualRoll, 0); + Assert.Equal(48.41f, actualFov, 0); + } + + [Theory] + [InlineData(122, -123.61f, -122.43f)] + [InlineData(140, -123.68f, -122.80f)] + [InlineData(180, -126.95f, -125.76f)] + [InlineData(200, -129.38f, -128.20f)] + [InlineData(438, -176.39, -175.20)] + [InlineData(444, -177.35, -176.17)] + public void InterpolateCameraSecondTest(float time, float eyey, float centery) + { + var fakeField = Substitute.For(); + var eventPlayer = new EventPlayer(fakeField, new List + { + new Event.SetEndFrame + { + EndFrame = 300 + }, + new Event.SetupEvent(), + new Event.SetCameraData + { + CameraId = 0, + PositionX = CameraDataSingleValue(40.186035f), + PositionY = CameraDataSingleValue(271.22748f), + PositionZ = CameraDataSingleValue(527.7301f), + LookAtX = CameraDataSingleValue(-79.38527f), + LookAtY = CameraDataSingleValue(90.874115f), + LookAtZ = CameraDataSingleValue(-78.414696f), + Roll = CameraDataSingleValue(0f), + FieldOfView = CameraDataSingleValue(41.092915f), + }, + new Event.SetCameraData + { + CameraId = 1, + PositionX = new List + { + CameraDataValue(-317.25266f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), + CameraDataValue(-317.25266f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), + CameraDataValue(-317.25266f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), + }, + PositionY = new List + { + CameraDataValue(123.61203f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), + CameraDataValue(185.76723f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), + CameraDataValue(185.76723f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), + }, + PositionZ = new List + { + CameraDataValue(-79.360405f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), + CameraDataValue(-79.360405f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), + CameraDataValue(-79.360405f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), + }, + LookAtX = new List + { + CameraDataValue(-357.23502f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), + CameraDataValue(-357.23502f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), + CameraDataValue(-357.23502f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), + }, + LookAtY = new List + { + CameraDataValue(122.42929f, Kh2.Motion.Interpolation.Hermite, 0, 0, 0), + CameraDataValue(184.58449f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), + CameraDataValue(184.58449f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), + }, + LookAtZ = new List + { + CameraDataValue(-217.77927f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), + CameraDataValue(-217.77927f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), + CameraDataValue(-217.77927f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), + }, + Roll = new List + { + CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), + CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), + CameraDataValue(0f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), + }, + FieldOfView = new List + { + CameraDataValue(42.026005f, Kh2.Motion.Interpolation.Linear, 0, 0f, 0f), + CameraDataValue(42.026005f, Kh2.Motion.Interpolation.Linear, 3584, 0f, 0f), + CameraDataValue(42.026005f, Kh2.Motion.Interpolation.Linear, 3754, 0f, 0f), + }, + }, + new Event.SeqCamera + { + CameraId = 0, + FrameStart = 15, + FrameEnd = 75, + }, + new Event.SeqCamera + { + CameraId = 1, + FrameStart = 76, + FrameEnd = 286, + }, + }); + + eventPlayer.Initialize(); + eventPlayer.Update(1 / 60.0 * (time + 30f)); + + var setCameraCall = fakeField.ReceivedCalls().FirstOrDefault(); + Assert.NotNull(setCameraCall); + + var actualEye = (System.Numerics.Vector3)setCameraCall.GetArguments()[0]; + var actualCenter = (System.Numerics.Vector3)setCameraCall.GetArguments()[1]; + var actualFov = (float)setCameraCall.GetArguments()[2]; + var actualRoll = (float)setCameraCall.GetArguments()[3]; + Assert.Equal(-317.25266f, actualEye.X, 0); + Assert.Equal(eyey, -actualEye.Y, 0); + Assert.Equal(79.360405f, -actualEye.Z, 0); + Assert.Equal(-357.23502f, actualCenter.X, 0); + Assert.Equal(centery, -actualCenter.Y, 0); + Assert.Equal(217.77927f, -actualCenter.Z, 0); + Assert.Equal(0f, actualRoll, 0); + Assert.Equal(42.026005f, actualFov, 0); + } + + [Theory] + [InlineData(30, false)] + [InlineData(60, true)] + [InlineData(120, true)] + [InlineData(180, false)] + public void ActorSceneVisibility(float time, bool expectedActorVisibility) + { + const int ActorId = 0; + const int FrameActorAppear = 50; + const string MotionPath = "anm_ex/motion"; + + var fakeField = Substitute.For(); + var eventPlayer = new EventPlayer(fakeField, new List + { + new Event.SetEndFrame + { + EndFrame = 1000 + }, + new Event.ReadAssets + { + FrameStart = -32767, + FrameEnd = 0, + Unk06 = 0, + Set = new List + { + new Event.ReadActor + { + ObjectId = 123, + ActorId = ActorId, + Name = "main_actor" + }, + new Event.ReadMotion + { + ObjectId = 123, + ActorId = ActorId, + Name = MotionPath, + UnknownIndex = 1, + }, + } + }, + new Event.SetActor + { + ObjectEntry = 123, + ActorId = ActorId, + Name = "main_actor" + }, + new Event.SeqPlayAnimation + { + FrameStart = FrameActorAppear, + FrameEnd = 100, + ActorId = ActorId, + Path = MotionPath + }, + new Event.SeqActorLeave + { + Frame = 150, + ActorId = ActorId + } + }); + + bool? lastVisibility = null; + + fakeField.SetActorVisibility(Arg.Is(ActorId), Arg.Do(x => lastVisibility = x)); + eventPlayer.Initialize(); + for (var i = 0; i < time; i++) + eventPlayer.Update(1f / 30.0f); + + Assert.Equal(expectedActorVisibility, lastVisibility); + } + + private static Event.SetCameraData.CameraKeys CameraDataValue( + float value, Kh2.Motion.Interpolation interpolation, int keyFrame, float left, float right) => + new Event.SetCameraData.CameraKeys + { + Interpolation = interpolation, + KeyFrame = keyFrame, + Value = value, + TangentEaseIn = left, + TangentEaseOut = right + }; + + private static List CameraDataSingleValue(float value) => + new List() + { + CameraDataValue(value, Kh2.Motion.Interpolation.Hermite, 0, 0, 0) + }; + } +} diff --git a/OpenKh.Tests.Engine/MdlxLoaderTests.cs b/OpenKh.Tests.Engine/MdlxLoaderTests.cs index 875d483fb..1d2b02d7f 100644 --- a/OpenKh.Tests.Engine/MdlxLoaderTests.cs +++ b/OpenKh.Tests.Engine/MdlxLoaderTests.cs @@ -1,115 +1,115 @@ -using OpenKh.Ps2; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Engine -{ - public class MdlxLoaderTests - { - [Fact] - public void NEW_ShouldGetImmutableMesh() - { - var alaxi = new int[] - { - 0x35, 0x2, 0x18, 0x29, 0x0c, 0x31, 0x3f, 0x14, 0x22, 0x16 - }; - - var data = File.ReadAllBytes("res/obj_vif_unpack.bin"); - var vpu = VpuPacket.Read(new MemoryStream(data)); - var immutableMesh = vpu.GetWeightedVertices(vpu.GetFromMatrixIndices(alaxi)); - var weightedVertices = immutableMesh - .Select(x => x.Select(y => new - { - y.MatrixIndex, - Vertex = vpu.Vertices[y.VertexIndex] - }).ToArray()) - .ToArray(); - - Assert.NotNull(immutableMesh); - Assert.Equal(0x4c, immutableMesh.Length); - Assert.Equal(0x4f, vpu.Indices.Length); - - Assert.Equal(0x35, weightedVertices[0][0].MatrixIndex); - AssertEqual(weightedVertices[0][0].Vertex, - 11.55658f, -10.695402f, -1.8525791f, 0); - - Assert.Equal(0x35, weightedVertices[1][0].MatrixIndex); - AssertEqual(weightedVertices[1][0].Vertex, - 12.341873f, -6.8589644f, -6.79047f, 0); - - Assert.Equal(0x16, weightedVertices[75][0].MatrixIndex); - AssertEqual(weightedVertices[75][0].Vertex, - -0.29302156f, -0.004016876f, 13.689127f, 0); - - AssertEqual(vpu.Indices[0], 0x10, 0x27, 0f, 0.26171875f); - AssertEqual(vpu.Indices[1], 0x10, 0x28, 0.02734375f, 0.24609375f); - AssertEqual(vpu.Indices[78], 0x30, 0x36, 0.5234375f, 0.49609375f); - } - - [Fact] - public void NEW_ShouldGetImmutableMeshHighDef() - { - var alaxi = new int[] - { - 0x43, 0x8c, 0xdb, 0xd9, 0x89, 0x42, 0x41, 0x02, 0xd7, 0xd3 - }; - - var data = File.ReadAllBytes("res/obj_vif_unpack_alt.bin"); - var vpu = VpuPacket.Read(new MemoryStream(data)); - var immutableMesh = vpu.GetWeightedVertices(vpu.GetFromMatrixIndices(alaxi)); - var weightedVertices = immutableMesh - .Select(x => x.Select(y => new - { - y.MatrixIndex, - Vertex = vpu.Vertices[y.VertexIndex] - }).ToArray()) - .ToArray(); - - Assert.NotNull(immutableMesh); - Assert.Equal(0x4a, immutableMesh.Length); - Assert.Equal(0x4f, vpu.Indices.Length); - - Assert.Equal(0x89, weightedVertices[0][0].MatrixIndex); - AssertEqual(weightedVertices[0][0].Vertex, - 6.9705353f, 0.5387306f, -4.146785f, 1f); - - Assert.Equal(0x89, weightedVertices[1][0].MatrixIndex); - AssertEqual(weightedVertices[1][0].Vertex, - 6.1054993f, 1.1867695f, -3.7489133f, 1f); - - Assert.Equal(0x8c, weightedVertices[73][0].MatrixIndex); - AssertEqual(weightedVertices[73][0].Vertex, - 9.300911f, -0.66315675f, -5.8931007f, 0.5f); - - Assert.Equal(0xd3, weightedVertices[73][1].MatrixIndex); - AssertEqual(weightedVertices[73][1].Vertex, - 3.4593887f, -1.39147f, -1.8666306f, 0.5f); - } - - private static void AssertEqual(VpuPacket.VertexIndex v, - int expectedVertexFlag, - int expectedIndexToVertexAssignment, - float expectedU, - float expectedV) - { - Assert.Equal(expectedVertexFlag, (int)v.Function); - Assert.Equal(expectedIndexToVertexAssignment, v.Index); - Assert.Equal(expectedU, v.U / 16 / 256.0f); - Assert.Equal(expectedV, v.V / 16 / 256.0f); - } - - private static void AssertEqual( - VpuPacket.VertexCoord v, - float expectedX, - float expectedY, - float expectedZ, - float expectedW) - { - Assert.Equal(expectedX, v.X); - Assert.Equal(expectedY, v.Y); - Assert.Equal(expectedZ, v.Z); - Assert.Equal(expectedW, v.W); - } - } -} +using OpenKh.Ps2; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Engine +{ + public class MdlxLoaderTests + { + [Fact] + public void NEW_ShouldGetImmutableMesh() + { + var alaxi = new int[] + { + 0x35, 0x2, 0x18, 0x29, 0x0c, 0x31, 0x3f, 0x14, 0x22, 0x16 + }; + + var data = File.ReadAllBytes("res/obj_vif_unpack.bin"); + var vpu = VpuPacket.Read(new MemoryStream(data)); + var immutableMesh = vpu.GetWeightedVertices(vpu.GetFromMatrixIndices(alaxi)); + var weightedVertices = immutableMesh + .Select(x => x.Select(y => new + { + y.MatrixIndex, + Vertex = vpu.Vertices[y.VertexIndex] + }).ToArray()) + .ToArray(); + + Assert.NotNull(immutableMesh); + Assert.Equal(0x4c, immutableMesh.Length); + Assert.Equal(0x4f, vpu.Indices.Length); + + Assert.Equal(0x35, weightedVertices[0][0].MatrixIndex); + AssertEqual(weightedVertices[0][0].Vertex, + 11.55658f, -10.695402f, -1.8525791f, 0); + + Assert.Equal(0x35, weightedVertices[1][0].MatrixIndex); + AssertEqual(weightedVertices[1][0].Vertex, + 12.341873f, -6.8589644f, -6.79047f, 0); + + Assert.Equal(0x16, weightedVertices[75][0].MatrixIndex); + AssertEqual(weightedVertices[75][0].Vertex, + -0.29302156f, -0.004016876f, 13.689127f, 0); + + AssertEqual(vpu.Indices[0], 0x10, 0x27, 0f, 0.26171875f); + AssertEqual(vpu.Indices[1], 0x10, 0x28, 0.02734375f, 0.24609375f); + AssertEqual(vpu.Indices[78], 0x30, 0x36, 0.5234375f, 0.49609375f); + } + + [Fact] + public void NEW_ShouldGetImmutableMeshHighDef() + { + var alaxi = new int[] + { + 0x43, 0x8c, 0xdb, 0xd9, 0x89, 0x42, 0x41, 0x02, 0xd7, 0xd3 + }; + + var data = File.ReadAllBytes("res/obj_vif_unpack_alt.bin"); + var vpu = VpuPacket.Read(new MemoryStream(data)); + var immutableMesh = vpu.GetWeightedVertices(vpu.GetFromMatrixIndices(alaxi)); + var weightedVertices = immutableMesh + .Select(x => x.Select(y => new + { + y.MatrixIndex, + Vertex = vpu.Vertices[y.VertexIndex] + }).ToArray()) + .ToArray(); + + Assert.NotNull(immutableMesh); + Assert.Equal(0x4a, immutableMesh.Length); + Assert.Equal(0x4f, vpu.Indices.Length); + + Assert.Equal(0x89, weightedVertices[0][0].MatrixIndex); + AssertEqual(weightedVertices[0][0].Vertex, + 6.9705353f, 0.5387306f, -4.146785f, 1f); + + Assert.Equal(0x89, weightedVertices[1][0].MatrixIndex); + AssertEqual(weightedVertices[1][0].Vertex, + 6.1054993f, 1.1867695f, -3.7489133f, 1f); + + Assert.Equal(0x8c, weightedVertices[73][0].MatrixIndex); + AssertEqual(weightedVertices[73][0].Vertex, + 9.300911f, -0.66315675f, -5.8931007f, 0.5f); + + Assert.Equal(0xd3, weightedVertices[73][1].MatrixIndex); + AssertEqual(weightedVertices[73][1].Vertex, + 3.4593887f, -1.39147f, -1.8666306f, 0.5f); + } + + private static void AssertEqual(VpuPacket.VertexIndex v, + int expectedVertexFlag, + int expectedIndexToVertexAssignment, + float expectedU, + float expectedV) + { + Assert.Equal(expectedVertexFlag, (int)v.Function); + Assert.Equal(expectedIndexToVertexAssignment, v.Index); + Assert.Equal(expectedU, v.U / 16 / 256.0f); + Assert.Equal(expectedV, v.V / 16 / 256.0f); + } + + private static void AssertEqual( + VpuPacket.VertexCoord v, + float expectedX, + float expectedY, + float expectedZ, + float expectedW) + { + Assert.Equal(expectedX, v.X); + Assert.Equal(expectedY, v.Y); + Assert.Equal(expectedZ, v.Z); + Assert.Equal(expectedW, v.W); + } + } +} diff --git a/OpenKh.Tests.Engine/SequenceRendererTest.cs b/OpenKh.Tests.Engine/SequenceRendererTest.cs index ae0226deb..6910e22a5 100644 --- a/OpenKh.Tests.Engine/SequenceRendererTest.cs +++ b/OpenKh.Tests.Engine/SequenceRendererTest.cs @@ -1,240 +1,240 @@ -using NSubstitute; -using OpenKh.Engine.Renderers; -using OpenKh.Engine.Renders; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Engine -{ - public class SequenceRendererTest - { - private const int AnimationFirstFrame = 0; - private const int AnimationLastFrame = 1000; - - [Theory] - [InlineData(0, 0, 0, 0, 0)] - [InlineData(0, 1000, 1, 0, 0)] - [InlineData(0, 1000, 1, 500, 500)] - [InlineData(0, 1000, 0, 500, 500)] - [InlineData(0, 1000, 0, 750, 854)] - public void TraslateXAnimationTest(int x0, int x1, int flags, int frameIndex, float expected) - { - var sequence = MockSequence(new Sequence.Animation - { - Flags = flags, - TranslateXStart = x0, - TranslateXEnd = x1, - FrameStart = AnimationFirstFrame, - FrameEnd = AnimationLastFrame, - ScaleStart = 1, - ScaleEnd = 1, - ScaleXStart = 1, - ScaleXEnd = 1, - ScaleYStart = 1, - ScaleYEnd = 1, - ColorStart = 0x80808080, - ColorEnd = 0x80808080, - }); - - var drawing = Extensions.MockDrawing(); - var renderer = new SequenceRenderer(sequence, drawing, null); - renderer.Draw(0, frameIndex, 0, 0); - - drawing.AssertDraw(x => - { - Assert.Equal(expected, x.Vec0.X, 0); - }); - } - - [Theory] - [InlineData(0, 0, 0, 0, 0)] - [InlineData(0, 1000, 1, 0, 0)] - [InlineData(0, 1000, 1, 500, 500)] - [InlineData(0, 1000, 0, 500, 500)] - [InlineData(0, 1000, 0, 750, 854)] - [InlineData(0, 1000, 0x4000, 500, 0)] - public void TraslateXBAnimationTest(int x0, int x1, int flags, int frameIndex, float expected) - { - var sequence = MockSequence(new Sequence.Animation - { - Flags = flags, - PivotXStart = x0, - PivotXEnd = x1, - FrameStart = AnimationFirstFrame, - FrameEnd = AnimationLastFrame, - ScaleStart = 1, - ScaleEnd = 1, - ScaleXStart = 1, - ScaleXEnd = 1, - ScaleYStart = 1, - ScaleYEnd = 1, - ColorStart = 0x80808080, - ColorEnd = 0x80808080, - }); - - var drawing = Extensions.MockDrawing(); - var renderer = new SequenceRenderer(sequence, drawing, null); - renderer.Draw(0, frameIndex, 0, 0); - - drawing.AssertDraw(x => - { - Assert.Equal(expected, x.Vec0.X, 0); - }); - } - - [Fact] - public void TranslateUsingXaAndXb() - { - var sequence = MockSequence(new Sequence.Animation - { - Flags = 0, - TranslateXStart = 200, - TranslateXEnd = 500, - PivotXStart = 150, - PivotXEnd = 400, - FrameStart = AnimationFirstFrame, - FrameEnd = AnimationLastFrame, - ScaleStart = 1, - ScaleEnd = 1, - ScaleXStart = 1, - ScaleXEnd = 1, - ScaleYStart = 1, - ScaleYEnd = 1, - ColorStart = 0x80808080, - ColorEnd = 0x80808080, - }); - - var drawing = Extensions.MockDrawing(); - var renderer = new SequenceRenderer(sequence, drawing, null); - renderer.Draw(0, 500, 0, 0); - - drawing.AssertDraw(x => - { - Assert.Equal(625, x.Vec0.X, 0); - }); - } - - [Theory] - [InlineData(false, 0, 0, AnimationLastFrame - 1, true)] - [InlineData(false, 0, 0, AnimationLastFrame + 1, false)] - [InlineData(false, 10, 100, AnimationLastFrame + 1, false)] - [InlineData(true, 10, 100, AnimationLastFrame + 1, true)] - [InlineData(true, 10, 1500, AnimationLastFrame + 1, false)] - [InlineData(true, 500, 1500, 1750, true)] - [InlineData(true, 500, 1500, 2250, false)] - [InlineData(true, 500, 1500, 2750, true)] - [InlineData(true, 500, 1500, 4250, false)] - [InlineData(true, 500, 1500, 4750, true)] - public void LoopCorrectly(bool loopEnabled, int loopStart, short loopEnd, short frameIndex, bool doesDrawAnyFrame) - { - var sequence = MockSequence(new Sequence.AnimationGroup - { - Animations = new List() - { - new Sequence.Animation - { - FrameStart = AnimationFirstFrame, - FrameEnd = AnimationLastFrame, - } - }, - DoNotLoop = (short)(loopEnabled ? 0 : 1), - LoopStart = loopStart, - LoopEnd = loopEnd - }); - - var drawing = Extensions.MockDrawing(); - var renderer = new SequenceRenderer(sequence, drawing, null); - renderer.Draw(0, frameIndex, 0, 0); - - if (doesDrawAnyFrame) - drawing.AssertAtLeastOneCall(); - else - drawing.AssertNoCall(); - } - - private static Sequence MockSequence(Sequence.Animation animation) => new Sequence - { - AnimationGroups = new List() - { - new Sequence.AnimationGroup - { - Animations = new List() - { - animation - }, - DoNotLoop = 1, - } - }, - SpriteGroups = new List>() - { - new List() - { - new Sequence.SpritePart - { - Left = 0, - Top = 0, - Right = 512, - Bottom = 512, - } - } - }, - Sprites = new List() - { - new Sequence.Sprite - { - Left = 0, - Top = 0, - Right = 512, - Bottom = 512, - UTranslation = 0, - VTranslation = 0, - ColorLeft = 0x80808080, - ColorTop = 0x80808080, - ColorRight = 0x80808080, - ColorBottom = 0x80808080, - } - } - }; - - private static Sequence MockSequence(Sequence.AnimationGroup animationGroup) => new Sequence - { - AnimationGroups = new List() - { - animationGroup, - }, - SpriteGroups = new List>() - { - new List() - { - new Sequence.SpritePart - { - Left = 0, - Top = 0, - Right = 512, - Bottom = 512, - } - } - }, - Sprites = new List() - { - new Sequence.Sprite - { - Left = 0, - Top = 0, - Right = 512, - Bottom = 512, - UTranslation = 0, - VTranslation = 0, - ColorLeft = 0x80808080, - ColorTop = 0x80808080, - ColorRight = 0x80808080, - ColorBottom = 0x80808080, - } - } - }; - } -} +using NSubstitute; +using OpenKh.Engine.Renderers; +using OpenKh.Engine.Renders; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Engine +{ + public class SequenceRendererTest + { + private const int AnimationFirstFrame = 0; + private const int AnimationLastFrame = 1000; + + [Theory] + [InlineData(0, 0, 0, 0, 0)] + [InlineData(0, 1000, 1, 0, 0)] + [InlineData(0, 1000, 1, 500, 500)] + [InlineData(0, 1000, 0, 500, 500)] + [InlineData(0, 1000, 0, 750, 854)] + public void TraslateXAnimationTest(int x0, int x1, int flags, int frameIndex, float expected) + { + var sequence = MockSequence(new Sequence.Animation + { + Flags = flags, + TranslateXStart = x0, + TranslateXEnd = x1, + FrameStart = AnimationFirstFrame, + FrameEnd = AnimationLastFrame, + ScaleStart = 1, + ScaleEnd = 1, + ScaleXStart = 1, + ScaleXEnd = 1, + ScaleYStart = 1, + ScaleYEnd = 1, + ColorStart = 0x80808080, + ColorEnd = 0x80808080, + }); + + var drawing = Extensions.MockDrawing(); + var renderer = new SequenceRenderer(sequence, drawing, null); + renderer.Draw(0, frameIndex, 0, 0); + + drawing.AssertDraw(x => + { + Assert.Equal(expected, x.Vec0.X, 0); + }); + } + + [Theory] + [InlineData(0, 0, 0, 0, 0)] + [InlineData(0, 1000, 1, 0, 0)] + [InlineData(0, 1000, 1, 500, 500)] + [InlineData(0, 1000, 0, 500, 500)] + [InlineData(0, 1000, 0, 750, 854)] + [InlineData(0, 1000, 0x4000, 500, 0)] + public void TraslateXBAnimationTest(int x0, int x1, int flags, int frameIndex, float expected) + { + var sequence = MockSequence(new Sequence.Animation + { + Flags = flags, + PivotXStart = x0, + PivotXEnd = x1, + FrameStart = AnimationFirstFrame, + FrameEnd = AnimationLastFrame, + ScaleStart = 1, + ScaleEnd = 1, + ScaleXStart = 1, + ScaleXEnd = 1, + ScaleYStart = 1, + ScaleYEnd = 1, + ColorStart = 0x80808080, + ColorEnd = 0x80808080, + }); + + var drawing = Extensions.MockDrawing(); + var renderer = new SequenceRenderer(sequence, drawing, null); + renderer.Draw(0, frameIndex, 0, 0); + + drawing.AssertDraw(x => + { + Assert.Equal(expected, x.Vec0.X, 0); + }); + } + + [Fact] + public void TranslateUsingXaAndXb() + { + var sequence = MockSequence(new Sequence.Animation + { + Flags = 0, + TranslateXStart = 200, + TranslateXEnd = 500, + PivotXStart = 150, + PivotXEnd = 400, + FrameStart = AnimationFirstFrame, + FrameEnd = AnimationLastFrame, + ScaleStart = 1, + ScaleEnd = 1, + ScaleXStart = 1, + ScaleXEnd = 1, + ScaleYStart = 1, + ScaleYEnd = 1, + ColorStart = 0x80808080, + ColorEnd = 0x80808080, + }); + + var drawing = Extensions.MockDrawing(); + var renderer = new SequenceRenderer(sequence, drawing, null); + renderer.Draw(0, 500, 0, 0); + + drawing.AssertDraw(x => + { + Assert.Equal(625, x.Vec0.X, 0); + }); + } + + [Theory] + [InlineData(false, 0, 0, AnimationLastFrame - 1, true)] + [InlineData(false, 0, 0, AnimationLastFrame + 1, false)] + [InlineData(false, 10, 100, AnimationLastFrame + 1, false)] + [InlineData(true, 10, 100, AnimationLastFrame + 1, true)] + [InlineData(true, 10, 1500, AnimationLastFrame + 1, false)] + [InlineData(true, 500, 1500, 1750, true)] + [InlineData(true, 500, 1500, 2250, false)] + [InlineData(true, 500, 1500, 2750, true)] + [InlineData(true, 500, 1500, 4250, false)] + [InlineData(true, 500, 1500, 4750, true)] + public void LoopCorrectly(bool loopEnabled, int loopStart, short loopEnd, short frameIndex, bool doesDrawAnyFrame) + { + var sequence = MockSequence(new Sequence.AnimationGroup + { + Animations = new List() + { + new Sequence.Animation + { + FrameStart = AnimationFirstFrame, + FrameEnd = AnimationLastFrame, + } + }, + DoNotLoop = (short)(loopEnabled ? 0 : 1), + LoopStart = loopStart, + LoopEnd = loopEnd + }); + + var drawing = Extensions.MockDrawing(); + var renderer = new SequenceRenderer(sequence, drawing, null); + renderer.Draw(0, frameIndex, 0, 0); + + if (doesDrawAnyFrame) + drawing.AssertAtLeastOneCall(); + else + drawing.AssertNoCall(); + } + + private static Sequence MockSequence(Sequence.Animation animation) => new Sequence + { + AnimationGroups = new List() + { + new Sequence.AnimationGroup + { + Animations = new List() + { + animation + }, + DoNotLoop = 1, + } + }, + SpriteGroups = new List>() + { + new List() + { + new Sequence.SpritePart + { + Left = 0, + Top = 0, + Right = 512, + Bottom = 512, + } + } + }, + Sprites = new List() + { + new Sequence.Sprite + { + Left = 0, + Top = 0, + Right = 512, + Bottom = 512, + UTranslation = 0, + VTranslation = 0, + ColorLeft = 0x80808080, + ColorTop = 0x80808080, + ColorRight = 0x80808080, + ColorBottom = 0x80808080, + } + } + }; + + private static Sequence MockSequence(Sequence.AnimationGroup animationGroup) => new Sequence + { + AnimationGroups = new List() + { + animationGroup, + }, + SpriteGroups = new List>() + { + new List() + { + new Sequence.SpritePart + { + Left = 0, + Top = 0, + Right = 512, + Bottom = 512, + } + } + }, + Sprites = new List() + { + new Sequence.Sprite + { + Left = 0, + Top = 0, + Right = 512, + Bottom = 512, + UTranslation = 0, + VTranslation = 0, + ColorLeft = 0x80808080, + ColorTop = 0x80808080, + ColorRight = 0x80808080, + ColorBottom = 0x80808080, + } + } + }; + } +} diff --git a/OpenKh.Tests/Bbs/ArcTests.cs b/OpenKh.Tests/Bbs/ArcTests.cs index 5ff9ea519..a3609dc85 100644 --- a/OpenKh.Tests/Bbs/ArcTests.cs +++ b/OpenKh.Tests/Bbs/ArcTests.cs @@ -1,120 +1,120 @@ -using OpenKh.Common; -using OpenKh.Bbs; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Bbs -{ - public class ArcTests - { - private static readonly string FileName = "Bbs/res/arctest.arc"; - - [Fact] - public void IsValidTest() - { - using (var stream = new MemoryStream()) - { - stream.WriteByte(0x41); - stream.WriteByte(0x52); - stream.WriteByte(0x43); - stream.WriteByte(0x00); - Assert.True(Arc.IsValid(stream)); - } - } - - [Fact] - public void IsNotValidWhenHeaderDoesNotMatchTest() - { - using (var stream = new MemoryStream()) - { - stream.WriteByte(1); - stream.WriteByte(2); - stream.WriteByte(3); - stream.WriteByte(4); - Assert.False(Arc.IsValid(stream)); - } - } - - [Fact] - public void IsNotValidWhenStreamIsNotLongEnoughTest() - { - using (var stream = new MemoryStream()) - { - stream.WriteByte(1); - stream.WriteByte(2); - stream.WriteByte(3); - Assert.False(Arc.IsValid(stream)); - } - } - - [Fact] - public void ReadCorrectAmountOfEntries() => File.OpenRead(FileName).Using(stream => - { - var entries = Arc.Read(stream); - Assert.Equal(3, entries.Count()); - }); - - [Fact] - public void ReadEntryNamesCorrectly() => File.OpenRead(FileName).Using(stream => - { - var entries = Arc.Read(stream).ToArray(); - Assert.Equal("TBoxDtTe.itb", entries[0].Name); - Assert.Equal("ColeDtTe.itc", entries[1].Name); - Assert.Equal("FileNameTest", entries[2].Name); - }); - - [Fact] - public void ReadEntryFullPathCorrectly() => File.OpenRead(FileName).Using(stream => - { - var entries = Arc.Read(stream).ToArray(); - Assert.Equal("TBoxDtTe.itb", entries[0].Path); - Assert.Equal("ColeDtTe.itc", entries[1].Path); - Assert.Equal("arc/effect/FileNameTest", entries[2].Path); - }); - - [Fact] - public void ReadEntryLengthCorrectly() => File.OpenRead(FileName).Using(stream => - { - var entries = Arc.Read(stream).ToArray(); - Assert.Equal(0x3ec, entries[0].Data.Length); - Assert.Equal(0xbc, entries[1].Data.Length); - }); - - [Fact] - public void ReadEntryContentCorrectly() => File.OpenRead(FileName).Using(stream => - { - var entries = Arc.Read(stream).ToArray(); - Assert.Equal(0x42, entries[0].Data[2]); - Assert.Equal(0x43, entries[1].Data[2]); - }); - - [Fact] - public void IsPointerFieldShouldBeCorrectlyPopulated() => File.OpenRead(FileName).Using(stream => - { - var entries = Arc.Read(stream).ToArray(); - Assert.False(entries[0].IsLink); - Assert.False(entries[1].IsLink); - Assert.True(entries[2].IsLink); - }); - - [Fact] - public void PointersShouldHaveNullData() => File.OpenRead(FileName).Using(stream => - { - var entries = Arc.Read(stream).ToArray(); - Assert.Null(entries[2].Data); - }); - - [Fact] - public void WritesBackCorrectly() => File.OpenRead(FileName).Using(stream => - Helpers.AssertStream(stream, x => - { - var entries = Arc.Read(stream); - - var outStream = new MemoryStream(); - entries.Write(outStream); - - return outStream; - })); - } -} +using OpenKh.Common; +using OpenKh.Bbs; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Bbs +{ + public class ArcTests + { + private static readonly string FileName = "Bbs/res/arctest.arc"; + + [Fact] + public void IsValidTest() + { + using (var stream = new MemoryStream()) + { + stream.WriteByte(0x41); + stream.WriteByte(0x52); + stream.WriteByte(0x43); + stream.WriteByte(0x00); + Assert.True(Arc.IsValid(stream)); + } + } + + [Fact] + public void IsNotValidWhenHeaderDoesNotMatchTest() + { + using (var stream = new MemoryStream()) + { + stream.WriteByte(1); + stream.WriteByte(2); + stream.WriteByte(3); + stream.WriteByte(4); + Assert.False(Arc.IsValid(stream)); + } + } + + [Fact] + public void IsNotValidWhenStreamIsNotLongEnoughTest() + { + using (var stream = new MemoryStream()) + { + stream.WriteByte(1); + stream.WriteByte(2); + stream.WriteByte(3); + Assert.False(Arc.IsValid(stream)); + } + } + + [Fact] + public void ReadCorrectAmountOfEntries() => File.OpenRead(FileName).Using(stream => + { + var entries = Arc.Read(stream); + Assert.Equal(3, entries.Count()); + }); + + [Fact] + public void ReadEntryNamesCorrectly() => File.OpenRead(FileName).Using(stream => + { + var entries = Arc.Read(stream).ToArray(); + Assert.Equal("TBoxDtTe.itb", entries[0].Name); + Assert.Equal("ColeDtTe.itc", entries[1].Name); + Assert.Equal("FileNameTest", entries[2].Name); + }); + + [Fact] + public void ReadEntryFullPathCorrectly() => File.OpenRead(FileName).Using(stream => + { + var entries = Arc.Read(stream).ToArray(); + Assert.Equal("TBoxDtTe.itb", entries[0].Path); + Assert.Equal("ColeDtTe.itc", entries[1].Path); + Assert.Equal("arc/effect/FileNameTest", entries[2].Path); + }); + + [Fact] + public void ReadEntryLengthCorrectly() => File.OpenRead(FileName).Using(stream => + { + var entries = Arc.Read(stream).ToArray(); + Assert.Equal(0x3ec, entries[0].Data.Length); + Assert.Equal(0xbc, entries[1].Data.Length); + }); + + [Fact] + public void ReadEntryContentCorrectly() => File.OpenRead(FileName).Using(stream => + { + var entries = Arc.Read(stream).ToArray(); + Assert.Equal(0x42, entries[0].Data[2]); + Assert.Equal(0x43, entries[1].Data[2]); + }); + + [Fact] + public void IsPointerFieldShouldBeCorrectlyPopulated() => File.OpenRead(FileName).Using(stream => + { + var entries = Arc.Read(stream).ToArray(); + Assert.False(entries[0].IsLink); + Assert.False(entries[1].IsLink); + Assert.True(entries[2].IsLink); + }); + + [Fact] + public void PointersShouldHaveNullData() => File.OpenRead(FileName).Using(stream => + { + var entries = Arc.Read(stream).ToArray(); + Assert.Null(entries[2].Data); + }); + + [Fact] + public void WritesBackCorrectly() => File.OpenRead(FileName).Using(stream => + Helpers.AssertStream(stream, x => + { + var entries = Arc.Read(stream); + + var outStream = new MemoryStream(); + entries.Write(outStream); + + return outStream; + })); + } +} diff --git a/OpenKh.Tests/Bbs/BbsaTests.cs b/OpenKh.Tests/Bbs/BbsaTests.cs index 65fe2b3f5..f9adfb4c0 100644 --- a/OpenKh.Tests/Bbs/BbsaTests.cs +++ b/OpenKh.Tests/Bbs/BbsaTests.cs @@ -1,75 +1,75 @@ -using OpenKh.Bbs; -using System.IO; -using OpenKh.Common; -using Xunit; - -namespace OpenKh.Tests.Bbs -{ - public class BbsaTests - { - [Theory] - [InlineData("COMMON", 0x1514B7D7)] - [InlineData("FONT", 0xE601E566)] - [InlineData("DI02EX", 1334999096)] - [InlineData("ARC/PRESET", 1037329268)] - [InlineData("MOVIE", 3926536415)] - [InlineData("OPD.PMF", 2028670912)] - public void ShouldCalculateTheCorrectHash(string text, uint expected) - { - Assert.Equal(expected, Bbsa.GetHash(text)); - } - - [Fact] - public void TestLba() - { - var a = 859218828; - var offset = a >> 12; - var size = a & 0xFFF; - - Assert.Equal(0x333CE - 100, offset); - Assert.Equal(0x38C, size); - } - - [Theory] - [InlineData(0x0050414D, "arc/map")] - [InlineData(0x4E455645, "arc/event")] - [InlineData(0x30004350, "arc/pc_terra")] - [InlineData(0x00000000, "arc_")] - [InlineData(0x80000000, "sound/bgm")] - [InlineData(0xc0000000, "lua")] - [InlineData(0x90000000, "sound/se/common")] - [InlineData(0x91000000, "sound/se/event/ex")] - [InlineData(0x91010000, "sound/se/event/dp")] - [InlineData(0x920a0000, "sound/se/footstep/di")] - [InlineData(0xd0000000, "message/jp/system")] - [InlineData(0xd1200000, "message/en/map")] - [InlineData(0xa1570000, "sound/voice/fr/event/jf")] - public void CalculateDirectoryFromHash(uint hash, string directory) - { - var actual = Bbsa.GetDirectoryName(hash); - - Assert.Equal(directory, actual); - } - - [Theory] - [InlineData(0x0050414D, "arc/map")] - [InlineData(0x4E455645, "arc/event")] - [InlineData(0x30004350, "arc/pc_terra")] - [InlineData(0x00000000, "arc_")] - [InlineData(0x80000000, "sound/bgm")] - [InlineData(0xc0000000, "lua")] - [InlineData(0x90000000, "sound/se/common")] - [InlineData(0x91000000, "sound/se/event/ex")] - [InlineData(0x91010000, "sound/se/event/dp")] - [InlineData(0x920a0000, "sound/se/footstep/di")] - [InlineData(0xd0000000, "message/jp/system")] - [InlineData(0xd1200000, "message/en/map")] - [InlineData(0xa1570000, "sound/voice/fr/event/jf")] - public void CalculateHashFromDirectory(uint hash, string directory) - { - var actual = Bbsa.GetDirectoryHash(directory); - - Assert.Equal(hash, actual); - } - } -} +using OpenKh.Bbs; +using System.IO; +using OpenKh.Common; +using Xunit; + +namespace OpenKh.Tests.Bbs +{ + public class BbsaTests + { + [Theory] + [InlineData("COMMON", 0x1514B7D7)] + [InlineData("FONT", 0xE601E566)] + [InlineData("DI02EX", 1334999096)] + [InlineData("ARC/PRESET", 1037329268)] + [InlineData("MOVIE", 3926536415)] + [InlineData("OPD.PMF", 2028670912)] + public void ShouldCalculateTheCorrectHash(string text, uint expected) + { + Assert.Equal(expected, Bbsa.GetHash(text)); + } + + [Fact] + public void TestLba() + { + var a = 859218828; + var offset = a >> 12; + var size = a & 0xFFF; + + Assert.Equal(0x333CE - 100, offset); + Assert.Equal(0x38C, size); + } + + [Theory] + [InlineData(0x0050414D, "arc/map")] + [InlineData(0x4E455645, "arc/event")] + [InlineData(0x30004350, "arc/pc_terra")] + [InlineData(0x00000000, "arc_")] + [InlineData(0x80000000, "sound/bgm")] + [InlineData(0xc0000000, "lua")] + [InlineData(0x90000000, "sound/se/common")] + [InlineData(0x91000000, "sound/se/event/ex")] + [InlineData(0x91010000, "sound/se/event/dp")] + [InlineData(0x920a0000, "sound/se/footstep/di")] + [InlineData(0xd0000000, "message/jp/system")] + [InlineData(0xd1200000, "message/en/map")] + [InlineData(0xa1570000, "sound/voice/fr/event/jf")] + public void CalculateDirectoryFromHash(uint hash, string directory) + { + var actual = Bbsa.GetDirectoryName(hash); + + Assert.Equal(directory, actual); + } + + [Theory] + [InlineData(0x0050414D, "arc/map")] + [InlineData(0x4E455645, "arc/event")] + [InlineData(0x30004350, "arc/pc_terra")] + [InlineData(0x00000000, "arc_")] + [InlineData(0x80000000, "sound/bgm")] + [InlineData(0xc0000000, "lua")] + [InlineData(0x90000000, "sound/se/common")] + [InlineData(0x91000000, "sound/se/event/ex")] + [InlineData(0x91010000, "sound/se/event/dp")] + [InlineData(0x920a0000, "sound/se/footstep/di")] + [InlineData(0xd0000000, "message/jp/system")] + [InlineData(0xd1200000, "message/en/map")] + [InlineData(0xa1570000, "sound/voice/fr/event/jf")] + public void CalculateHashFromDirectory(uint hash, string directory) + { + var actual = Bbsa.GetDirectoryHash(directory); + + Assert.Equal(hash, actual); + } + } +} diff --git a/OpenKh.Tests/Bbs/CtdEncodingTests.cs b/OpenKh.Tests/Bbs/CtdEncodingTests.cs index 9de770b13..0a2052d76 100644 --- a/OpenKh.Tests/Bbs/CtdEncodingTests.cs +++ b/OpenKh.Tests/Bbs/CtdEncodingTests.cs @@ -1,91 +1,91 @@ -using OpenKh.Bbs.Messages; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Bbs -{ - public class CtdEncodingTests - { - private readonly ICtdMessageDecode euDec = CtdEncoders.International; - private readonly ICtdMessageEncode euEnc = CtdEncoders.International; - private readonly ICtdMessageEncoder encoder = CtdEncoders.International; - - [Theory] - [InlineData(' ', 0x20)] - [InlineData('A', 0x41)] - [InlineData('~', 0x7e)] - public void InternationalEncodingSimpleTest(char ch, byte expected) - { - var actual = euEnc.FromText($"{ch}"); - Assert.Equal(expected, actual[0]); - } - - [Theory] - [InlineData('Ò', 0x99, 0x8f)] - [InlineData('ç', 0x99, 0x9f)] - [InlineData('ú', 0x99, 0xaf)] - public void InternationalEncodingExtTest(char ch, byte expected, byte expected2) - { - var actual = euEnc.FromText($"{ch}"); - Assert.Equal(expected, actual[0]); - Assert.Equal(expected2, actual[1]); - } - - [Theory] - [InlineData(' ', 0x20)] - [InlineData('A', 0x41)] - [InlineData('~', 0x7e)] - public void InternationalDecodingSimpleTest(char expected, byte ch) - { - string actual = euDec.ToText(new byte[] { ch }); - Assert.Equal(expected, actual[0]); - } - - [Theory] - [InlineData('Ò', 0x99, 0x8f)] - [InlineData('ç', 0x99, 0x9f)] - [InlineData('ú', 0x99, 0xaf)] - [InlineData('$', 0x81, 0x90)] - [InlineData('%', 0x81, 0x93)] - [InlineData('#', 0x81, 0x94)] - [InlineData('&', 0x81, 0x95)] - [InlineData('*', 0x81, 0x96)] - [InlineData('@', 0x81, 0x97)] - [InlineData('■', 0x81, 0xa1)] - public void InternationalDecodingExtTest(char expected, byte ch, byte ch2) - { - string actual = euDec.ToText(new byte[] { ch, ch2 }); - Assert.Equal(expected, actual[0]); - } - - [Theory] - [InlineData(0x8143, ',')] - [InlineData(0x8162, '|')] - [InlineData(0x8180, '÷')] - [InlineData(0x8190, '$')] - [InlineData(0x81a0, '□')] - [InlineData(0x81ab, '↓')] - [InlineData(0x81f4, '♪')] - public void UcsToTextTest(ushort ucs, char expected) - { - var byteSequence = encoder.FromUcs(new ushort[] { ucs }).ToArray(); - var text = encoder.ToText(byteSequence); - - Assert.NotEmpty(text); - Assert.Equal(expected, text[0]); - } - - [Theory] - [InlineData(0xf1, 0xae, "{:icon button-triangle}")] - [InlineData(0xf1, 0xb4, "{:icon button-l}")] - [InlineData(0xf1, 0xc5, "{:icon button-dpad-v}")] - [InlineData(0xf9, 0x41, "{:color default}")] - [InlineData(0xf9, 0x58, "{:color white}")] - [InlineData(0xf9, 0x59, "{:color yellow}")] - public void InternationalDecodingCommandTest(byte command, byte parameter, string expected) - { - string actual = euDec.ToText(new byte[] { command, parameter }); - Assert.Equal(expected, actual); - } - } -} +using OpenKh.Bbs.Messages; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Bbs +{ + public class CtdEncodingTests + { + private readonly ICtdMessageDecode euDec = CtdEncoders.International; + private readonly ICtdMessageEncode euEnc = CtdEncoders.International; + private readonly ICtdMessageEncoder encoder = CtdEncoders.International; + + [Theory] + [InlineData(' ', 0x20)] + [InlineData('A', 0x41)] + [InlineData('~', 0x7e)] + public void InternationalEncodingSimpleTest(char ch, byte expected) + { + var actual = euEnc.FromText($"{ch}"); + Assert.Equal(expected, actual[0]); + } + + [Theory] + [InlineData('Ò', 0x99, 0x8f)] + [InlineData('ç', 0x99, 0x9f)] + [InlineData('ú', 0x99, 0xaf)] + public void InternationalEncodingExtTest(char ch, byte expected, byte expected2) + { + var actual = euEnc.FromText($"{ch}"); + Assert.Equal(expected, actual[0]); + Assert.Equal(expected2, actual[1]); + } + + [Theory] + [InlineData(' ', 0x20)] + [InlineData('A', 0x41)] + [InlineData('~', 0x7e)] + public void InternationalDecodingSimpleTest(char expected, byte ch) + { + string actual = euDec.ToText(new byte[] { ch }); + Assert.Equal(expected, actual[0]); + } + + [Theory] + [InlineData('Ò', 0x99, 0x8f)] + [InlineData('ç', 0x99, 0x9f)] + [InlineData('ú', 0x99, 0xaf)] + [InlineData('$', 0x81, 0x90)] + [InlineData('%', 0x81, 0x93)] + [InlineData('#', 0x81, 0x94)] + [InlineData('&', 0x81, 0x95)] + [InlineData('*', 0x81, 0x96)] + [InlineData('@', 0x81, 0x97)] + [InlineData('■', 0x81, 0xa1)] + public void InternationalDecodingExtTest(char expected, byte ch, byte ch2) + { + string actual = euDec.ToText(new byte[] { ch, ch2 }); + Assert.Equal(expected, actual[0]); + } + + [Theory] + [InlineData(0x8143, ',')] + [InlineData(0x8162, '|')] + [InlineData(0x8180, '÷')] + [InlineData(0x8190, '$')] + [InlineData(0x81a0, '□')] + [InlineData(0x81ab, '↓')] + [InlineData(0x81f4, '♪')] + public void UcsToTextTest(ushort ucs, char expected) + { + var byteSequence = encoder.FromUcs(new ushort[] { ucs }).ToArray(); + var text = encoder.ToText(byteSequence); + + Assert.NotEmpty(text); + Assert.Equal(expected, text[0]); + } + + [Theory] + [InlineData(0xf1, 0xae, "{:icon button-triangle}")] + [InlineData(0xf1, 0xb4, "{:icon button-l}")] + [InlineData(0xf1, 0xc5, "{:icon button-dpad-v}")] + [InlineData(0xf9, 0x41, "{:color default}")] + [InlineData(0xf9, 0x58, "{:color white}")] + [InlineData(0xf9, 0x59, "{:color yellow}")] + public void InternationalDecodingCommandTest(byte command, byte parameter, string expected) + { + string actual = euDec.ToText(new byte[] { command, parameter }); + Assert.Equal(expected, actual); + } + } +} diff --git a/OpenKh.Tests/Bbs/CtdTests.cs b/OpenKh.Tests/Bbs/CtdTests.cs index bac6c891c..d555b81ed 100644 --- a/OpenKh.Tests/Bbs/CtdTests.cs +++ b/OpenKh.Tests/Bbs/CtdTests.cs @@ -1,87 +1,87 @@ -using OpenKh.Bbs; -using OpenKh.Common; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.Bbs -{ - public class CtdTests - { - private static readonly string FileName = "Bbs/res/ctdtest.ctd"; - - [Fact] - public void IsValidTest() - { - using var stream = new MemoryStream(); - stream.WriteByte(0x40); - stream.WriteByte(0x43); - stream.WriteByte(0x54); - stream.WriteByte(0x44); - stream.Position = 0; - Assert.True(Ctd.IsValid(stream)); - } - - [Fact] - public void IsNotValidTest() - { - using (var stream = new MemoryStream()) - { - stream.WriteByte(1); - stream.WriteByte(2); - stream.WriteByte(3); - stream.WriteByte(4); - stream.Position = 0; - Assert.False(Ctd.IsValid(stream)); - } - } - - [Fact] - public void ReadCorrectAmountOfEntry1() => File.OpenRead(FileName).Using(stream => - { - var ctd = Ctd.Read(stream); - Assert.Equal(41, ctd.Messages.Count); - }); - - [Fact] - public void ReadCorrectAmountOfEntry2() => File.OpenRead(FileName).Using(stream => - { - var ctd = Ctd.Read(stream); - Assert.Equal(14, ctd.Layouts.Count); - }); - - [Theory] - [InlineData(0, "Command Deck")] - [InlineData(1, "Action Commands")] - [InlineData(12345678, null)] - public void ReadStringCorrectly(int id, string expected) => File.OpenRead(FileName).Using(stream => - { - var ctd = Ctd.Read(stream); - var str = ctd.GetString(id); - - Assert.Equal(expected, str); - }); - - [Fact] - public void WritesBackCorrectly() => File.OpenRead(FileName).Using(stream => - Helpers.AssertStream(stream, x => - { - var ctd = Ctd.Read(stream); - - var outStream = new MemoryStream(); - ctd.Write(outStream); - - return outStream; - })); - - [Fact] - public void CreateEmptyCtdWithoutNullValues() - { - var ctd = new Ctd(); - Assert.NotNull(ctd.Messages); - Assert.NotNull(ctd.Layouts); - Assert.Empty(ctd.Messages); - Assert.Empty(ctd.Layouts); - Assert.Equal(0, ctd.Unknown); - } - } -} +using OpenKh.Bbs; +using OpenKh.Common; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.Bbs +{ + public class CtdTests + { + private static readonly string FileName = "Bbs/res/ctdtest.ctd"; + + [Fact] + public void IsValidTest() + { + using var stream = new MemoryStream(); + stream.WriteByte(0x40); + stream.WriteByte(0x43); + stream.WriteByte(0x54); + stream.WriteByte(0x44); + stream.Position = 0; + Assert.True(Ctd.IsValid(stream)); + } + + [Fact] + public void IsNotValidTest() + { + using (var stream = new MemoryStream()) + { + stream.WriteByte(1); + stream.WriteByte(2); + stream.WriteByte(3); + stream.WriteByte(4); + stream.Position = 0; + Assert.False(Ctd.IsValid(stream)); + } + } + + [Fact] + public void ReadCorrectAmountOfEntry1() => File.OpenRead(FileName).Using(stream => + { + var ctd = Ctd.Read(stream); + Assert.Equal(41, ctd.Messages.Count); + }); + + [Fact] + public void ReadCorrectAmountOfEntry2() => File.OpenRead(FileName).Using(stream => + { + var ctd = Ctd.Read(stream); + Assert.Equal(14, ctd.Layouts.Count); + }); + + [Theory] + [InlineData(0, "Command Deck")] + [InlineData(1, "Action Commands")] + [InlineData(12345678, null)] + public void ReadStringCorrectly(int id, string expected) => File.OpenRead(FileName).Using(stream => + { + var ctd = Ctd.Read(stream); + var str = ctd.GetString(id); + + Assert.Equal(expected, str); + }); + + [Fact] + public void WritesBackCorrectly() => File.OpenRead(FileName).Using(stream => + Helpers.AssertStream(stream, x => + { + var ctd = Ctd.Read(stream); + + var outStream = new MemoryStream(); + ctd.Write(outStream); + + return outStream; + })); + + [Fact] + public void CreateEmptyCtdWithoutNullValues() + { + var ctd = new Ctd(); + Assert.NotNull(ctd.Messages); + Assert.NotNull(ctd.Layouts); + Assert.Empty(ctd.Messages); + Assert.Empty(ctd.Layouts); + Assert.Equal(0, ctd.Unknown); + } + } +} diff --git a/OpenKh.Tests/Bbs/EventTableTests.cs b/OpenKh.Tests/Bbs/EventTableTests.cs index 2a1cf1279..91cd9c7f1 100644 --- a/OpenKh.Tests/Bbs/EventTableTests.cs +++ b/OpenKh.Tests/Bbs/EventTableTests.cs @@ -1,44 +1,44 @@ -using OpenKh.Bbs; -using OpenKh.Common; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.Bbs -{ - public class EventTableTests - { - private const string FilePath = "Bbs/res/event-table.bin"; - - [Fact] - public void ReadEntriesCountCorrectly() => File.OpenRead(FilePath).Using(stream => - { - var events = Event.Read(stream); - Assert.Equal(92, events.Count); - }); - - [Fact] - public void ParseSingleEntryCorrectly() => File.OpenRead(FilePath).Using(stream => - { - var events = Event.Read(stream); - var @event = events[22]; - Assert.Equal(534, @event.Id); - Assert.Equal(301, @event.EventIndex); - Assert.Equal(4, @event.World); - Assert.Equal(7, @event.Room); - Assert.Equal(61, @event.EventPtn); - Assert.Equal(0, @event.Opt); - }); - - [Fact] - public void WritesBackCorrectly() => File.OpenRead(FilePath).Using(stream => - Helpers.AssertStream(stream, x => - { - var events = Event.Read(stream); - - var outStream = new MemoryStream(); - Event.Write(outStream, events); - - return outStream; - })); - } -} +using OpenKh.Bbs; +using OpenKh.Common; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.Bbs +{ + public class EventTableTests + { + private const string FilePath = "Bbs/res/event-table.bin"; + + [Fact] + public void ReadEntriesCountCorrectly() => File.OpenRead(FilePath).Using(stream => + { + var events = Event.Read(stream); + Assert.Equal(92, events.Count); + }); + + [Fact] + public void ParseSingleEntryCorrectly() => File.OpenRead(FilePath).Using(stream => + { + var events = Event.Read(stream); + var @event = events[22]; + Assert.Equal(534, @event.Id); + Assert.Equal(301, @event.EventIndex); + Assert.Equal(4, @event.World); + Assert.Equal(7, @event.Room); + Assert.Equal(61, @event.EventPtn); + Assert.Equal(0, @event.Opt); + }); + + [Fact] + public void WritesBackCorrectly() => File.OpenRead(FilePath).Using(stream => + Helpers.AssertStream(stream, x => + { + var events = Event.Read(stream); + + var outStream = new MemoryStream(); + Event.Write(outStream, events); + + return outStream; + })); + } +} diff --git a/OpenKh.Tests/Bbs/FontTests.cs b/OpenKh.Tests/Bbs/FontTests.cs index bc63a94a9..0adf5cfd5 100644 --- a/OpenKh.Tests/Bbs/FontTests.cs +++ b/OpenKh.Tests/Bbs/FontTests.cs @@ -1,81 +1,81 @@ -using OpenKh.Bbs; -using OpenKh.Common; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Bbs -{ - public class FontTests - { - private static string InfFileName = "Bbs/res/font-test.inf"; - private static string Inf2FileName = "Bbs/res/font-test2.inf"; - private static byte[] FontCharacterInfo = new byte[] { 0x34, 0x12, 33, 0, 66, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 99 }; - - [Fact] - public void ReadFontInfo() => File.OpenRead(InfFileName).Using(stream => - { - var fontInfo = FontInfo.Read(stream); - - Assert.Equal(364, fontInfo.CharacterCount); - Assert.Equal(512, fontInfo.ImageWidth); - Assert.Equal(64, fontInfo.MaxImageHeight); - Assert.Equal(12, fontInfo.CharacterWidth); - Assert.Equal(12, fontInfo.CharacterHeight); - }); - - [Fact] - public void WriteBackFontInfo() => Helpers.AssertStream(File.OpenRead(InfFileName), stream => - { - var outStream = new MemoryStream(); - FontInfo.Read(stream).Write(outStream); - return outStream; - }); - - [Fact] - public void ReadFontIconInfo() => File.OpenRead(Inf2FileName).Using(stream => - { - var iconsInfo = FontIconInfo.Read(stream).ToArray(); - - Assert.Equal(21, iconsInfo.Length); - - var iconInfo = iconsInfo.Skip(1).First(); - Assert.Equal(61870, iconInfo.Key); - Assert.Equal(19, iconInfo.Left); - Assert.Equal(1, iconInfo.Top); - Assert.Equal(39, iconInfo.Right); - Assert.Equal(20, iconInfo.Bottom); - }); - - [Fact] - public void WriteBackFontIconInfo() => Helpers.AssertStream(File.OpenRead(Inf2FileName), stream => - { - var outStream = new MemoryStream(); - FontIconInfo.Write(outStream, FontIconInfo.Read(stream)); - return outStream; - }); - - [Fact] - public void ReadFontCharacterInfo() - { - var stream = new MemoryStream(FontCharacterInfo); - var info = OpenKh.Bbs.FontCharacterInfo.Read(stream); - - Assert.Equal(2, info.Length); - Assert.Equal(0x1234, info[0].Id); - Assert.Equal(33, info[0].PositionX); - Assert.Equal(66, info[0].PositionY); - Assert.Equal(2, info[0].Palette); - Assert.Equal(3, info[0].Width); - Assert.Equal(99, info[1].Width); - } - - [Fact] - public void WriteFontCharacterInfo() => Helpers.AssertStream(new MemoryStream(FontCharacterInfo), stream => - { - var outStream = new MemoryStream(); - OpenKh.Bbs.FontCharacterInfo.Write(outStream, OpenKh.Bbs.FontCharacterInfo.Read(stream)); - return outStream; - }); - } -} +using OpenKh.Bbs; +using OpenKh.Common; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Bbs +{ + public class FontTests + { + private static string InfFileName = "Bbs/res/font-test.inf"; + private static string Inf2FileName = "Bbs/res/font-test2.inf"; + private static byte[] FontCharacterInfo = new byte[] { 0x34, 0x12, 33, 0, 66, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 99 }; + + [Fact] + public void ReadFontInfo() => File.OpenRead(InfFileName).Using(stream => + { + var fontInfo = FontInfo.Read(stream); + + Assert.Equal(364, fontInfo.CharacterCount); + Assert.Equal(512, fontInfo.ImageWidth); + Assert.Equal(64, fontInfo.MaxImageHeight); + Assert.Equal(12, fontInfo.CharacterWidth); + Assert.Equal(12, fontInfo.CharacterHeight); + }); + + [Fact] + public void WriteBackFontInfo() => Helpers.AssertStream(File.OpenRead(InfFileName), stream => + { + var outStream = new MemoryStream(); + FontInfo.Read(stream).Write(outStream); + return outStream; + }); + + [Fact] + public void ReadFontIconInfo() => File.OpenRead(Inf2FileName).Using(stream => + { + var iconsInfo = FontIconInfo.Read(stream).ToArray(); + + Assert.Equal(21, iconsInfo.Length); + + var iconInfo = iconsInfo.Skip(1).First(); + Assert.Equal(61870, iconInfo.Key); + Assert.Equal(19, iconInfo.Left); + Assert.Equal(1, iconInfo.Top); + Assert.Equal(39, iconInfo.Right); + Assert.Equal(20, iconInfo.Bottom); + }); + + [Fact] + public void WriteBackFontIconInfo() => Helpers.AssertStream(File.OpenRead(Inf2FileName), stream => + { + var outStream = new MemoryStream(); + FontIconInfo.Write(outStream, FontIconInfo.Read(stream)); + return outStream; + }); + + [Fact] + public void ReadFontCharacterInfo() + { + var stream = new MemoryStream(FontCharacterInfo); + var info = OpenKh.Bbs.FontCharacterInfo.Read(stream); + + Assert.Equal(2, info.Length); + Assert.Equal(0x1234, info[0].Id); + Assert.Equal(33, info[0].PositionX); + Assert.Equal(66, info[0].PositionY); + Assert.Equal(2, info[0].Palette); + Assert.Equal(3, info[0].Width); + Assert.Equal(99, info[1].Width); + } + + [Fact] + public void WriteFontCharacterInfo() => Helpers.AssertStream(new MemoryStream(FontCharacterInfo), stream => + { + var outStream = new MemoryStream(); + OpenKh.Bbs.FontCharacterInfo.Write(outStream, OpenKh.Bbs.FontCharacterInfo.Read(stream)); + return outStream; + }); + } +} diff --git a/OpenKh.Tests/Bbs/PamTests.cs b/OpenKh.Tests/Bbs/PamTests.cs index c3b5fe2b5..1a9906aad 100644 --- a/OpenKh.Tests/Bbs/PamTests.cs +++ b/OpenKh.Tests/Bbs/PamTests.cs @@ -1,26 +1,26 @@ -using OpenKh.Common; -using OpenKh.Bbs; -using System.IO; -using Xunit; -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Tests.Bbs -{ - public class PamTests - { - private static readonly string FileName = "Bbs/res/test.pam"; - - [Fact] - public void ReadCorrectData() => File.OpenRead(FileName).Using(stream => - { - var TestPam = Pam.Read(stream); - Assert.Equal(0x4D4150, (int)TestPam.header.MagicCode); - Assert.Equal("OpenKHAnim", TestPam.animList[0].AnimEntry.AnimationName); - Assert.Equal(1.818989362888275E-14, TestPam.animList[0].BoneChannels[1].TranslationX.Header.MaxValue); - Assert.Equal(-0.027958117425441742, TestPam.animList[0].BoneChannels[2].TranslationX.Header.MaxValue); - Assert.Equal(0.17539772391319275, TestPam.animList[0].BoneChannels[52].RotationZ.Header.MaxValue); - }); - } -} +using OpenKh.Common; +using OpenKh.Bbs; +using System.IO; +using Xunit; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Tests.Bbs +{ + public class PamTests + { + private static readonly string FileName = "Bbs/res/test.pam"; + + [Fact] + public void ReadCorrectData() => File.OpenRead(FileName).Using(stream => + { + var TestPam = Pam.Read(stream); + Assert.Equal(0x4D4150, (int)TestPam.header.MagicCode); + Assert.Equal("OpenKHAnim", TestPam.animList[0].AnimEntry.AnimationName); + Assert.Equal(1.818989362888275E-14, TestPam.animList[0].BoneChannels[1].TranslationX.Header.MaxValue); + Assert.Equal(-0.027958117425441742, TestPam.animList[0].BoneChannels[2].TranslationX.Header.MaxValue); + Assert.Equal(0.17539772391319275, TestPam.animList[0].BoneChannels[52].RotationZ.Header.MaxValue); + }); + } +} diff --git a/OpenKh.Tests/Bbs/PmoTests.cs b/OpenKh.Tests/Bbs/PmoTests.cs index bcbe990d4..c02f36e09 100644 --- a/OpenKh.Tests/Bbs/PmoTests.cs +++ b/OpenKh.Tests/Bbs/PmoTests.cs @@ -1,82 +1,82 @@ -using OpenKh.Common; -using OpenKh.Bbs; -using System.IO; -using Xunit; -using System.Collections.Generic; -using System.Collections.Specialized; -using System; - -namespace OpenKh.Tests.Bbs -{ - public class PmoTests - { - private static readonly string FileName = "Bbs/res/bbs-dummy.pmo"; - - [Fact] - public void ReadCorrectHeader() => File.OpenRead(FileName).Using(stream => - { - var TestPmo = Pmo.Read(stream); - Assert.Equal(0x4F4D50, (int)TestPmo.header.MagicCode); - Assert.Equal(0, (int)TestPmo.header.SkeletonOffset); - Assert.Equal(0xC0, (int)TestPmo.header.MeshOffset0); - Assert.Equal(0, (int)TestPmo.header.MeshOffset1); - }); - - [Fact] - public void ReadCorrectTextureBlock() => File.OpenRead(FileName).Using(stream => - { - var TestPmo = Pmo.Read(stream); - Assert.Equal("Dummy_tex02", TestPmo.textureInfo[0].TextureName); - Assert.Equal(0x2300, (int)TestPmo.textureInfo[0].TextureOffset); - }); - - [Fact] - public void ReadCorrectMeshGroup() => File.OpenRead(FileName).Using(stream => - { - var TestPmo = Pmo.Read(stream); - - // mesh header 1 - Assert.Equal("544", TestPmo.Meshes[0].SectionInfo.VertexCount.ToString()); - Assert.Equal("16", TestPmo.Meshes[0].SectionInfo.TriangleStripCount.ToString()); - }); - - [Fact] - public void ReadBoneHeader() => File.OpenRead(FileName).Using(stream => - { - var TestPmo = Pmo.Read(stream); - if (TestPmo.header.SkeletonOffset == 0) - { - Assert.True(true); - } - else - { - Assert.Equal((uint)0x4e4f42, TestPmo.skeletonHeader.MagicValue); - Assert.Equal((uint)0x35, TestPmo.skeletonHeader.BoneCount); - } - }); - - [Fact] - public void WritesBackCorrectly() - { - Stream input = File.OpenRead(FileName); - var TestPmo = Pmo.Read(input); - Stream output = File.Open("Bbs/res/bbs-dummy_TEST.pmo", FileMode.Create); - Pmo.Write(output, TestPmo); - - input.Position = 0; - output.Position = 0; - - // Check all bytes. - for(int i = 0; i < output.Length; i++) - { - if (input.ReadByte() != output.ReadByte()) - { - long position = output.Position; - Assert.False(true); - } - } - - Assert.True(true); - } - } -} +using OpenKh.Common; +using OpenKh.Bbs; +using System.IO; +using Xunit; +using System.Collections.Generic; +using System.Collections.Specialized; +using System; + +namespace OpenKh.Tests.Bbs +{ + public class PmoTests + { + private static readonly string FileName = "Bbs/res/bbs-dummy.pmo"; + + [Fact] + public void ReadCorrectHeader() => File.OpenRead(FileName).Using(stream => + { + var TestPmo = Pmo.Read(stream); + Assert.Equal(0x4F4D50, (int)TestPmo.header.MagicCode); + Assert.Equal(0, (int)TestPmo.header.SkeletonOffset); + Assert.Equal(0xC0, (int)TestPmo.header.MeshOffset0); + Assert.Equal(0, (int)TestPmo.header.MeshOffset1); + }); + + [Fact] + public void ReadCorrectTextureBlock() => File.OpenRead(FileName).Using(stream => + { + var TestPmo = Pmo.Read(stream); + Assert.Equal("Dummy_tex02", TestPmo.textureInfo[0].TextureName); + Assert.Equal(0x2300, (int)TestPmo.textureInfo[0].TextureOffset); + }); + + [Fact] + public void ReadCorrectMeshGroup() => File.OpenRead(FileName).Using(stream => + { + var TestPmo = Pmo.Read(stream); + + // mesh header 1 + Assert.Equal("544", TestPmo.Meshes[0].SectionInfo.VertexCount.ToString()); + Assert.Equal("16", TestPmo.Meshes[0].SectionInfo.TriangleStripCount.ToString()); + }); + + [Fact] + public void ReadBoneHeader() => File.OpenRead(FileName).Using(stream => + { + var TestPmo = Pmo.Read(stream); + if (TestPmo.header.SkeletonOffset == 0) + { + Assert.True(true); + } + else + { + Assert.Equal((uint)0x4e4f42, TestPmo.skeletonHeader.MagicValue); + Assert.Equal((uint)0x35, TestPmo.skeletonHeader.BoneCount); + } + }); + + [Fact] + public void WritesBackCorrectly() + { + Stream input = File.OpenRead(FileName); + var TestPmo = Pmo.Read(input); + Stream output = File.Open("Bbs/res/bbs-dummy_TEST.pmo", FileMode.Create); + Pmo.Write(output, TestPmo); + + input.Position = 0; + output.Position = 0; + + // Check all bytes. + for (int i = 0; i < output.Length; i++) + { + if (input.ReadByte() != output.ReadByte()) + { + long position = output.Position; + Assert.False(true); + } + } + + Assert.True(true); + } + } +} diff --git a/OpenKh.Tests/Bbs/PmpTests.cs b/OpenKh.Tests/Bbs/PmpTests.cs index 7207a77af..93355d8d7 100644 --- a/OpenKh.Tests/Bbs/PmpTests.cs +++ b/OpenKh.Tests/Bbs/PmpTests.cs @@ -1,33 +1,33 @@ -using OpenKh.Common; -using OpenKh.Bbs; -using System.IO; -using Xunit; -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Tests.Bbs -{ - public class PmpTests - { - private static readonly string FileName = "Bbs/res/bbs-testmap.pmp"; - - [Fact] - public void ReadCorrectHeader() => File.OpenRead(FileName).Using(stream => - { - var TestPmo = Pmp.Read(stream); - Assert.Equal(0x504D50, (int)TestPmo.header.MagicCode); - Assert.Equal(1, TestPmo.header.ObjectCount); - }); - - [Fact] - public void WritesBackCorrectly() => File.OpenRead(FileName).Using(stream => - Helpers.AssertStream(stream, x => - { - var outStream = new MemoryStream(); - Pmp.Write(outStream, Pmp.Read(stream)); - - return outStream; - })); - } -} +using OpenKh.Common; +using OpenKh.Bbs; +using System.IO; +using Xunit; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Tests.Bbs +{ + public class PmpTests + { + private static readonly string FileName = "Bbs/res/bbs-testmap.pmp"; + + [Fact] + public void ReadCorrectHeader() => File.OpenRead(FileName).Using(stream => + { + var TestPmo = Pmp.Read(stream); + Assert.Equal(0x504D50, (int)TestPmo.header.MagicCode); + Assert.Equal(1, TestPmo.header.ObjectCount); + }); + + [Fact] + public void WritesBackCorrectly() => File.OpenRead(FileName).Using(stream => + Helpers.AssertStream(stream, x => + { + var outStream = new MemoryStream(); + Pmp.Write(outStream, Pmp.Read(stream)); + + return outStream; + })); + } +} diff --git a/OpenKh.Tests/Common/BitsUtilTest.cs b/OpenKh.Tests/Common/BitsUtilTest.cs index 769409130..7bc6142af 100644 --- a/OpenKh.Tests/Common/BitsUtilTest.cs +++ b/OpenKh.Tests/Common/BitsUtilTest.cs @@ -1,4 +1,4 @@ -using OpenKh.Common.Utils; +using OpenKh.Common.Utils; using System; using System.Collections.Generic; using System.Text; diff --git a/OpenKh.Tests/Common/HdAssetTests.cs b/OpenKh.Tests/Common/HdAssetTests.cs index 5c0e50c57..44497f33d 100644 --- a/OpenKh.Tests/Common/HdAssetTests.cs +++ b/OpenKh.Tests/Common/HdAssetTests.cs @@ -1,107 +1,107 @@ -using OpenKh.Common; -using OpenKh.Common.Archives; -using System; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Common -{ - public class HdAssetTests - { - [Fact] - public void WriteBackTheSameReadStream() => Helpers.UseAsset("ps4archive.bin", stream => - { - Helpers.AssertStream(stream, x => - { - var asset = HdAsset.Read(stream); - - var outStream = new MemoryStream(); - asset.Write(outStream); - - return outStream; - }); - }); - - [Fact] - public void CannotAssignNullMainStream() - { - Assert.Throws(() => new HdAsset().Stream = null); - } - - [Fact] - public void CannotAssignNullEntriesListStream() - { - Assert.Throws(() => new HdAsset().Entries = null); - } - - [Fact] - public void CannotAssignNullEntryStreamListStream() - { - Assert.Throws(() => new HdAsset.Entry - { - Stream = null - }); - } - - [Fact] - public void IsValid() => Helpers.UseAsset("ps4archive.bin", stream => - { - Assert.True(HdAsset.IsValid(stream)); - }); - - [Fact] - public void IsValidWhenTheMinimumNecessaryInformationAreThere() - { - var hdasset = new HdAsset(); - - using var stream = new MemoryStream(); - hdasset.Write(stream); - - Assert.True(HdAsset.IsValid(stream.SetPosition(0))); - } - - [Fact] - public void IsNotValidWhenTheHeaderSizeIsTooSmall() - { - var stream = new MemoryStream(new byte[15]); - Assert.False(HdAsset.IsValid(stream)); - } - - [Fact] - public void IsNotValidWhenTheInnerStreamLengthIsTooBig() - { - var hdasset = new HdAsset(); - hdasset.Stream = new MemoryStream(new byte[] { 2, 3, 4, 5, 6, 7, 8 }); - - using var stream = new MemoryStream(); - hdasset.Write(stream); - - stream.SetLength(stream.Length - 1); - - Assert.False(HdAsset.IsValid(stream.SetPosition(0))); - } - - [Fact] - public void IsNotValidIfThereAreTooManyHdAssets() - { - var hdasset = new HdAsset(); - hdasset.Stream = new MemoryStream(new byte[] { 2, 3, 4, 5, 6, 7, 8 }); - hdasset.Entries = Enumerable - .Range(0, 1024) - .Select(x => new HdAsset.Entry() - { - Name = "Test", - Stream = new MemoryStream() - }) - .ToList(); - - using var stream = new MemoryStream(); - hdasset.Write(stream); - - stream.SetLength(stream.Length - 1); - - Assert.False(HdAsset.IsValid(stream.SetPosition(0))); - } - } -} +using OpenKh.Common; +using OpenKh.Common.Archives; +using System; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Common +{ + public class HdAssetTests + { + [Fact] + public void WriteBackTheSameReadStream() => Helpers.UseAsset("ps4archive.bin", stream => + { + Helpers.AssertStream(stream, x => + { + var asset = HdAsset.Read(stream); + + var outStream = new MemoryStream(); + asset.Write(outStream); + + return outStream; + }); + }); + + [Fact] + public void CannotAssignNullMainStream() + { + Assert.Throws(() => new HdAsset().Stream = null); + } + + [Fact] + public void CannotAssignNullEntriesListStream() + { + Assert.Throws(() => new HdAsset().Entries = null); + } + + [Fact] + public void CannotAssignNullEntryStreamListStream() + { + Assert.Throws(() => new HdAsset.Entry + { + Stream = null + }); + } + + [Fact] + public void IsValid() => Helpers.UseAsset("ps4archive.bin", stream => + { + Assert.True(HdAsset.IsValid(stream)); + }); + + [Fact] + public void IsValidWhenTheMinimumNecessaryInformationAreThere() + { + var hdasset = new HdAsset(); + + using var stream = new MemoryStream(); + hdasset.Write(stream); + + Assert.True(HdAsset.IsValid(stream.SetPosition(0))); + } + + [Fact] + public void IsNotValidWhenTheHeaderSizeIsTooSmall() + { + var stream = new MemoryStream(new byte[15]); + Assert.False(HdAsset.IsValid(stream)); + } + + [Fact] + public void IsNotValidWhenTheInnerStreamLengthIsTooBig() + { + var hdasset = new HdAsset(); + hdasset.Stream = new MemoryStream(new byte[] { 2, 3, 4, 5, 6, 7, 8 }); + + using var stream = new MemoryStream(); + hdasset.Write(stream); + + stream.SetLength(stream.Length - 1); + + Assert.False(HdAsset.IsValid(stream.SetPosition(0))); + } + + [Fact] + public void IsNotValidIfThereAreTooManyHdAssets() + { + var hdasset = new HdAsset(); + hdasset.Stream = new MemoryStream(new byte[] { 2, 3, 4, 5, 6, 7, 8 }); + hdasset.Entries = Enumerable + .Range(0, 1024) + .Select(x => new HdAsset.Entry() + { + Name = "Test", + Stream = new MemoryStream() + }) + .ToList(); + + using var stream = new MemoryStream(); + hdasset.Write(stream); + + stream.SetLength(stream.Length - 1); + + Assert.False(HdAsset.IsValid(stream.SetPosition(0))); + } + } +} diff --git a/OpenKh.Tests/Helpers.cs b/OpenKh.Tests/Helpers.cs index 760edff9b..bb74d1179 100644 --- a/OpenKh.Tests/Helpers.cs +++ b/OpenKh.Tests/Helpers.cs @@ -1,159 +1,159 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System; -using System.IO; -using System.Linq; -using Xunit; -using Xunit.Sdk; - -namespace OpenKh.Tests -{ - internal class AssertBarException : XunitException - { - public AssertBarException(string barEntry, XunitException innerException) : - base($"Failed assertion for BAR {barEntry}", innerException) - { } - } - - public static class Helpers - { - public const string Kh2DataPath = ".tests/kh2_data/"; - - private class AssertFileNameException : XunitException - { - public AssertFileNameException(string fileName, Exception innerException) : - base($"Failed assertion for file ${fileName}", innerException) - { } - } - - public static void Dump(this Stream stream, string path) => - File.Create(path).Using(outStream => - { - stream.Position = 0; - stream.CopyTo(outStream); - }); - - public static void AssertStream(Stream expectedStream, Func funcGenerateNewStream) - { - var expectedData = expectedStream.ReadAllBytes(); - var actualStream = funcGenerateNewStream(new MemoryStream(expectedData)); - var actualData = actualStream.ReadAllBytes(); - - var length = Math.Min(expectedData.Length, actualData.Length); - for (var i = 0; i < length; i++) - { - var ch1 = expectedData[i]; - var ch2 = actualData[i]; - Assert.True(ch1 == ch2, $"Expected {ch1:X02} but found {ch2:X02} at {i:X}"); - } - - Assert.Equal(expectedData.Length, actualData.Length); - } - - public static void ForAllFiles(string gamePath, Action action) - { - Skip.IfNot(Directory.Exists(gamePath)); - - Directory.GetFiles(gamePath, "*", SearchOption.AllDirectories) - .AsParallel() - .ForAll(fileName => - { - try - { - action(fileName); - } - catch (Exception ex) - { - throw new AssertFileNameException(fileName, ex); - } - }); - } - - public static void ForBarEntries( - string fileName, - Func predicate, - Action action) - { - if (!File.OpenRead(fileName).Using(stream => Bar.IsValid(stream))) - return; - - foreach (var entry in File - .OpenRead(fileName) - .Using(stream => Bar.Read(stream)) - .Where(x => x.Index == 0) - .Where(predicate)) - { - try - { - action(fileName, entry); - } - catch (XunitException ex) - { - throw new AssertBarException(entry.Name, ex); - } - } - } - - public static void UseAsset(string assetName, Action action) => - File.OpenRead(Path.Combine($"Common/res/", assetName)).Using(x => action(x)); - - public static void Dump(this byte[] data, string path) => - new MemoryStream(data).Using(x => x.Dump(path)); - - public static T CreateDummyObject() - where T : class - { - var dummyByte = (byte)12; - var dummyShort = (short)123; - var dummyInt = 1234; - var dummyFloat = 12.5f; - var dummyString = "dumy"; - - var instance = Activator.CreateInstance(); - foreach (var property in typeof(T).GetProperties()) - { - var propType = property.PropertyType; - if (propType == typeof(byte)) - { - property.SetValue(instance, dummyByte); - dummyByte *= 2; - } - else if (propType == typeof(short)) - { - property.SetValue(instance, dummyShort); - dummyShort *= 2; - } - else if (propType == typeof(ushort)) - { - property.SetValue(instance, (ushort)dummyShort); - dummyShort *= 2; - } - else if (propType == typeof(int)) - { - property.SetValue(instance, dummyInt); - dummyInt *= 2; - } - else if (propType == typeof(uint)) - { - property.SetValue(instance, dummyInt); - dummyInt *= 2; - } - else if (propType == typeof(float)) - { - property.SetValue(instance, dummyFloat); - dummyFloat *= 2; - } - else if (propType == typeof(string)) - { - property.SetValue(instance, dummyString); - dummyString += dummyString; - } - else - throw new NotImplementedException( - $"Type {propType.FullName} can not be mocked."); - } - - return instance; - } - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System; +using System.IO; +using System.Linq; +using Xunit; +using Xunit.Sdk; + +namespace OpenKh.Tests +{ + internal class AssertBarException : XunitException + { + public AssertBarException(string barEntry, XunitException innerException) : + base($"Failed assertion for BAR {barEntry}", innerException) + { } + } + + public static class Helpers + { + public const string Kh2DataPath = ".tests/kh2_data/"; + + private class AssertFileNameException : XunitException + { + public AssertFileNameException(string fileName, Exception innerException) : + base($"Failed assertion for file ${fileName}", innerException) + { } + } + + public static void Dump(this Stream stream, string path) => + File.Create(path).Using(outStream => + { + stream.Position = 0; + stream.CopyTo(outStream); + }); + + public static void AssertStream(Stream expectedStream, Func funcGenerateNewStream) + { + var expectedData = expectedStream.ReadAllBytes(); + var actualStream = funcGenerateNewStream(new MemoryStream(expectedData)); + var actualData = actualStream.ReadAllBytes(); + + var length = Math.Min(expectedData.Length, actualData.Length); + for (var i = 0; i < length; i++) + { + var ch1 = expectedData[i]; + var ch2 = actualData[i]; + Assert.True(ch1 == ch2, $"Expected {ch1:X02} but found {ch2:X02} at {i:X}"); + } + + Assert.Equal(expectedData.Length, actualData.Length); + } + + public static void ForAllFiles(string gamePath, Action action) + { + Skip.IfNot(Directory.Exists(gamePath)); + + Directory.GetFiles(gamePath, "*", SearchOption.AllDirectories) + .AsParallel() + .ForAll(fileName => + { + try + { + action(fileName); + } + catch (Exception ex) + { + throw new AssertFileNameException(fileName, ex); + } + }); + } + + public static void ForBarEntries( + string fileName, + Func predicate, + Action action) + { + if (!File.OpenRead(fileName).Using(stream => Bar.IsValid(stream))) + return; + + foreach (var entry in File + .OpenRead(fileName) + .Using(stream => Bar.Read(stream)) + .Where(x => x.Index == 0) + .Where(predicate)) + { + try + { + action(fileName, entry); + } + catch (XunitException ex) + { + throw new AssertBarException(entry.Name, ex); + } + } + } + + public static void UseAsset(string assetName, Action action) => + File.OpenRead(Path.Combine($"Common/res/", assetName)).Using(x => action(x)); + + public static void Dump(this byte[] data, string path) => + new MemoryStream(data).Using(x => x.Dump(path)); + + public static T CreateDummyObject() + where T : class + { + var dummyByte = (byte)12; + var dummyShort = (short)123; + var dummyInt = 1234; + var dummyFloat = 12.5f; + var dummyString = "dumy"; + + var instance = Activator.CreateInstance(); + foreach (var property in typeof(T).GetProperties()) + { + var propType = property.PropertyType; + if (propType == typeof(byte)) + { + property.SetValue(instance, dummyByte); + dummyByte *= 2; + } + else if (propType == typeof(short)) + { + property.SetValue(instance, dummyShort); + dummyShort *= 2; + } + else if (propType == typeof(ushort)) + { + property.SetValue(instance, (ushort)dummyShort); + dummyShort *= 2; + } + else if (propType == typeof(int)) + { + property.SetValue(instance, dummyInt); + dummyInt *= 2; + } + else if (propType == typeof(uint)) + { + property.SetValue(instance, dummyInt); + dummyInt *= 2; + } + else if (propType == typeof(float)) + { + property.SetValue(instance, dummyFloat); + dummyFloat *= 2; + } + else if (propType == typeof(string)) + { + property.SetValue(instance, dummyString); + dummyString += dummyString; + } + else + throw new NotImplementedException( + $"Type {propType.FullName} can not be mocked."); + } + + return instance; + } + } +} diff --git a/OpenKh.Tests/Imaging/ImageDecodeTests.cs b/OpenKh.Tests/Imaging/ImageDecodeTests.cs index 9c18b9fb0..791aece02 100644 --- a/OpenKh.Tests/Imaging/ImageDecodeTests.cs +++ b/OpenKh.Tests/Imaging/ImageDecodeTests.cs @@ -1,119 +1,119 @@ -using OpenKh.Imaging; -using System.Drawing; -using Xunit; - -namespace OpenKh.Tests.Imaging -{ - public class ImageDecodeTests - { - public class Fake4bppImage : IImageRead - { - public Size Size => new Size(Width, Height); - public PixelFormat PixelFormat => PixelFormat.Indexed4; - public byte[] GetData() => Data4bpp; - public byte[] GetClut() => Clut4bpp; - } - - public const int Width = 16; - public const int Height = 16; - - public static readonly byte[] Data4bpp = new byte[Width * Height / 2] - { - 0x31, 0x33, 0x21, 0x33, 0x31, 0x23, 0x31, 0x33, 0x12, 0x13, 0x32, 0x22, 0x22, 0x33, 0x12, 0x13, - 0x31, 0x33, 0x21, 0x33, 0x31, 0x23, 0x31, 0x33, 0x33, 0x32, 0x13, 0x00, 0x03, 0x12, 0x33, 0x32, - 0x23, 0x21, 0x00, 0x33, 0x30, 0x01, 0x23, 0x21, 0x12, 0x13, 0x03, 0x44, 0x43, 0x03, 0x12, 0x13, - 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x32, 0x30, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x32, 0x30, - 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x32, 0x30, 0x12, 0x13, 0x03, 0x44, 0x43, 0x03, 0x12, 0x13, - 0x23, 0x21, 0x00, 0x33, 0x30, 0x01, 0x23, 0x21, 0x33, 0x32, 0x13, 0x00, 0x03, 0x12, 0x33, 0x32, - 0x31, 0x33, 0x21, 0x33, 0x31, 0x23, 0x31, 0x33, 0x12, 0x13, 0x32, 0x22, 0x22, 0x33, 0x12, 0x13, - 0x31, 0x33, 0x21, 0x33, 0x31, 0x23, 0x31, 0x33, 0x33, 0x32, 0x13, 0x00, 0x03, 0x12, 0x33, 0x32 - }; - - public static readonly byte[] Clut4bpp = new byte[] - { - 0x38, 0xB4, 0x4A, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xB9, 0x25, 0x22, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x24, 0x9F, 0xDA, 0xFF - }; - - public static readonly byte[] ExpectedFrom4bpp = new byte[Width * Height * 4] - { - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, - 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, - 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, - 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, - 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x80, 0x80, 0x80, 0xFF, - 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, - 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, - 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, - 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, - 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x80, 0x80, 0x80, 0xFF, - 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, - 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, - 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, - 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, - 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF - }; - - [Fact] - public void Decode4bppTest() - { - var actual = ImageDataHelpers.FromIndexed4ToBitmap32(Data4bpp, Clut4bpp, ImageDataHelpers.RGBA); - Assert.Equal(ExpectedFrom4bpp, actual); - } - - [Fact] - public void DecodeImage4bppTest() - { - Assert.Equal(ExpectedFrom4bpp, new Fake4bppImage().ToBgra32()); - } - } -} +using OpenKh.Imaging; +using System.Drawing; +using Xunit; + +namespace OpenKh.Tests.Imaging +{ + public class ImageDecodeTests + { + public class Fake4bppImage : IImageRead + { + public Size Size => new Size(Width, Height); + public PixelFormat PixelFormat => PixelFormat.Indexed4; + public byte[] GetData() => Data4bpp; + public byte[] GetClut() => Clut4bpp; + } + + public const int Width = 16; + public const int Height = 16; + + public static readonly byte[] Data4bpp = new byte[Width * Height / 2] + { + 0x31, 0x33, 0x21, 0x33, 0x31, 0x23, 0x31, 0x33, 0x12, 0x13, 0x32, 0x22, 0x22, 0x33, 0x12, 0x13, + 0x31, 0x33, 0x21, 0x33, 0x31, 0x23, 0x31, 0x33, 0x33, 0x32, 0x13, 0x00, 0x03, 0x12, 0x33, 0x32, + 0x23, 0x21, 0x00, 0x33, 0x30, 0x01, 0x23, 0x21, 0x12, 0x13, 0x03, 0x44, 0x43, 0x03, 0x12, 0x13, + 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x32, 0x30, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x32, 0x30, + 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x32, 0x30, 0x12, 0x13, 0x03, 0x44, 0x43, 0x03, 0x12, 0x13, + 0x23, 0x21, 0x00, 0x33, 0x30, 0x01, 0x23, 0x21, 0x33, 0x32, 0x13, 0x00, 0x03, 0x12, 0x33, 0x32, + 0x31, 0x33, 0x21, 0x33, 0x31, 0x23, 0x31, 0x33, 0x12, 0x13, 0x32, 0x22, 0x22, 0x33, 0x12, 0x13, + 0x31, 0x33, 0x21, 0x33, 0x31, 0x23, 0x31, 0x33, 0x33, 0x32, 0x13, 0x00, 0x03, 0x12, 0x33, 0x32 + }; + + public static readonly byte[] Clut4bpp = new byte[] + { + 0x38, 0xB4, 0x4A, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xB9, 0x25, 0x22, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x24, 0x9F, 0xDA, 0xFF + }; + + public static readonly byte[] ExpectedFrom4bpp = new byte[Width * Height * 4] + { + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, + 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, + 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, + 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, + 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x80, 0x80, 0x80, 0xFF, + 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, + 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, + 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, 0xDA, 0x9F, 0x24, 0xFF, + 0xDA, 0x9F, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, + 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x80, 0x80, 0x80, 0xFF, + 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, + 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, + 0x22, 0x25, 0xB9, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x22, 0x25, 0xB9, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF, + 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, 0x4A, 0xB4, 0x38, 0xFF, + 0x4A, 0xB4, 0x38, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0xFF, 0x22, 0x25, 0xB9, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22, 0x25, 0xB9, 0xFF + }; + + [Fact] + public void Decode4bppTest() + { + var actual = ImageDataHelpers.FromIndexed4ToBitmap32(Data4bpp, Clut4bpp, ImageDataHelpers.RGBA); + Assert.Equal(ExpectedFrom4bpp, actual); + } + + [Fact] + public void DecodeImage4bppTest() + { + Assert.Equal(ExpectedFrom4bpp, new Fake4bppImage().ToBgra32()); + } + } +} diff --git a/OpenKh.Tests/Imaging/PngTests.cs b/OpenKh.Tests/Imaging/PngTests.cs index 82c9ab4ce..9a6b20075 100644 --- a/OpenKh.Tests/Imaging/PngTests.cs +++ b/OpenKh.Tests/Imaging/PngTests.cs @@ -1,22 +1,22 @@ -using OpenKh.Common; -using OpenKh.Imaging; -using OpenKh.Kh2.Ard; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Imaging -{ - public class PngTests - { - [Theory] - [InlineData("4")] - [InlineData("8")] - [InlineData("24")] - [InlineData("32")] - public void ReadingTests(string prefix) - { - File.OpenRead($"Imaging/res/png/{prefix}.png").Using(PngImage.Read); - } - } -} +using OpenKh.Common; +using OpenKh.Imaging; +using OpenKh.Kh2.Ard; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Imaging +{ + public class PngTests + { + [Theory] + [InlineData("4")] + [InlineData("8")] + [InlineData("24")] + [InlineData("32")] + public void ReadingTests(string prefix) + { + File.OpenRead($"Imaging/res/png/{prefix}.png").Using(PngImage.Read); + } + } +} diff --git a/OpenKh.Tests/Imaging/Tm2Tests.cs b/OpenKh.Tests/Imaging/Tm2Tests.cs index c3e4c6097..6d43988b8 100644 --- a/OpenKh.Tests/Imaging/Tm2Tests.cs +++ b/OpenKh.Tests/Imaging/Tm2Tests.cs @@ -1,107 +1,107 @@ -using OpenKh.Common; -using OpenKh.Imaging; -using OpenKh.Kh2; -using System; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Imaging -{ - public class Tm2Tests - { - [Theory] - [InlineData(new byte[] { 0x54, 0x49, 0x4d, 0x32 }, 16, true)] - [InlineData(new byte[] { 0x54, 0x49, 0x4d, 0x31 }, 16, false)] - [InlineData(new byte[] { 0x54, 0x49, 0x4d, 0x32 }, 15, false)] - public void IsValidTest(byte[] header, int length, bool expected) => new MemoryStream() - .Using(stream => - { - stream.Write(header, 0, header.Length); - stream.SetLength(length); - - Assert.Equal(expected, Tm2.IsValid(stream)); - }); - - [Theory] - [InlineData("image-8bit-128-128", 128, 128, PixelFormat.Indexed8)] - [InlineData("image-8bit-512-272", 512, 272, PixelFormat.Indexed8)] - [InlineData("image-32bit-480-279", 480, 279, PixelFormat.Rgba8888)] - [InlineData("tt02.radar", 512, 512, PixelFormat.Indexed4)] - public void ReadImagePropertiesTest( - string fileName, - int width, - int height, - PixelFormat pixelFormat) => File.OpenRead($"Imaging/res/{fileName}.tm2").Using(stream => - { - var image = Tm2.Read(stream).Single(); - - Assert.Equal(width, image.Size.Width); - Assert.Equal(height, image.Size.Height); - Assert.Equal(pixelFormat, image.PixelFormat); - }); - - [Theory] - [InlineData("image-8bit-128-128")] - [InlineData("image-8bit-512-272")] - [InlineData("image-32bit-480-279")] - public void IsWritingBackCorrectly(string fileName) => File.OpenRead($"Imaging/res/{fileName}.tm2").Using(x => - Helpers.AssertStream(x, stream => - { - var images = Tm2.Read(stream); - - var newStream = new MemoryStream(); - Tm2.Write(newStream, images); - - return newStream; - })); - - /// - /// Scan and test all radar images. - /// - /// - /// Define your [InlineData] if you want to test this case against every asset map file. - /// - [Theory] - [InlineData("Imaging/res")] - //[InlineData(".tests/kh2_data/map/jp")] - public void ValidateAllKH2MapRadarImages(string mapFilesDir) - { - Directory.GetFiles(mapFilesDir, "*.map").ToList().ForEach( - file => - { - File.OpenRead(file).Using( - stream => - { - Bar.Read(stream) - // rada may be multiple occurrence like al06.map - .Where( - entry => true - && entry.Name == "rada" - && entry.Type == Bar.EntryType.Tim2 - ) - .ToList() - .ForEach( - entry => - { - Assert.True(Tm2.IsValid(entry.Stream), "Should be TM2"); - - var imageSet = Tm2.Read(entry.Stream); - - imageSet.ToList().ForEach( - texture => - { - // All radar images are 4-bpp - Assert.NotEmpty(texture.GetData()); - Assert.Equal(4 * 16, texture.GetClut().Length); - } - ); - } - ); - } - ); - } - ); - } - } -} +using OpenKh.Common; +using OpenKh.Imaging; +using OpenKh.Kh2; +using System; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Imaging +{ + public class Tm2Tests + { + [Theory] + [InlineData(new byte[] { 0x54, 0x49, 0x4d, 0x32 }, 16, true)] + [InlineData(new byte[] { 0x54, 0x49, 0x4d, 0x31 }, 16, false)] + [InlineData(new byte[] { 0x54, 0x49, 0x4d, 0x32 }, 15, false)] + public void IsValidTest(byte[] header, int length, bool expected) => new MemoryStream() + .Using(stream => + { + stream.Write(header, 0, header.Length); + stream.SetLength(length); + + Assert.Equal(expected, Tm2.IsValid(stream)); + }); + + [Theory] + [InlineData("image-8bit-128-128", 128, 128, PixelFormat.Indexed8)] + [InlineData("image-8bit-512-272", 512, 272, PixelFormat.Indexed8)] + [InlineData("image-32bit-480-279", 480, 279, PixelFormat.Rgba8888)] + [InlineData("tt02.radar", 512, 512, PixelFormat.Indexed4)] + public void ReadImagePropertiesTest( + string fileName, + int width, + int height, + PixelFormat pixelFormat) => File.OpenRead($"Imaging/res/{fileName}.tm2").Using(stream => + { + var image = Tm2.Read(stream).Single(); + + Assert.Equal(width, image.Size.Width); + Assert.Equal(height, image.Size.Height); + Assert.Equal(pixelFormat, image.PixelFormat); + }); + + [Theory] + [InlineData("image-8bit-128-128")] + [InlineData("image-8bit-512-272")] + [InlineData("image-32bit-480-279")] + public void IsWritingBackCorrectly(string fileName) => File.OpenRead($"Imaging/res/{fileName}.tm2").Using(x => + Helpers.AssertStream(x, stream => + { + var images = Tm2.Read(stream); + + var newStream = new MemoryStream(); + Tm2.Write(newStream, images); + + return newStream; + })); + + /// + /// Scan and test all radar images. + /// + /// + /// Define your [InlineData] if you want to test this case against every asset map file. + /// + [Theory] + [InlineData("Imaging/res")] + //[InlineData(".tests/kh2_data/map/jp")] + public void ValidateAllKH2MapRadarImages(string mapFilesDir) + { + Directory.GetFiles(mapFilesDir, "*.map").ToList().ForEach( + file => + { + File.OpenRead(file).Using( + stream => + { + Bar.Read(stream) + // rada may be multiple occurrence like al06.map + .Where( + entry => true + && entry.Name == "rada" + && entry.Type == Bar.EntryType.Tim2 + ) + .ToList() + .ForEach( + entry => + { + Assert.True(Tm2.IsValid(entry.Stream), "Should be TM2"); + + var imageSet = Tm2.Read(entry.Stream); + + imageSet.ToList().ForEach( + texture => + { + // All radar images are 4-bpp + Assert.NotEmpty(texture.GetData()); + Assert.Equal(4 * 16, texture.GetClut().Length); + } + ); + } + ); + } + ); + } + ); + } + } +} diff --git a/OpenKh.Tests/Kh1/Idx1Tests.cs b/OpenKh.Tests/Kh1/Idx1Tests.cs index 95e83ac62..64c445053 100644 --- a/OpenKh.Tests/Kh1/Idx1Tests.cs +++ b/OpenKh.Tests/Kh1/Idx1Tests.cs @@ -1,17 +1,17 @@ -using OpenKh.Kh1; -using Xunit; - -namespace OpenKh.Tests.Kh1 -{ - public class Idx1Tests - { - [Theory] - [InlineData("dc01.ard", 0x0007C3B4)] - [InlineData("title/copyright.tm2", 0x57D148F1)] - [InlineData("OpenKH is awesome!", 0xF2CBF18B)] - public void CalculateHash(string text, uint hash) - { - Assert.Equal(hash, Idx1.GetHash(text)); - } - } -} +using OpenKh.Kh1; +using Xunit; + +namespace OpenKh.Tests.Kh1 +{ + public class Idx1Tests + { + [Theory] + [InlineData("dc01.ard", 0x0007C3B4)] + [InlineData("title/copyright.tm2", 0x57D148F1)] + [InlineData("OpenKH is awesome!", 0xF2CBF18B)] + public void CalculateHash(string text, uint hash) + { + Assert.Equal(hash, Idx1.GetHash(text)); + } + } +} diff --git a/OpenKh.Tests/Kh1/KingdomArchiveTests.cs b/OpenKh.Tests/Kh1/KingdomArchiveTests.cs index 1fdfc5d9e..8e686bd1a 100644 --- a/OpenKh.Tests/Kh1/KingdomArchiveTests.cs +++ b/OpenKh.Tests/Kh1/KingdomArchiveTests.cs @@ -1,51 +1,51 @@ -using OpenKh.Common; -using OpenKh.Kh1; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.Kh1 -{ - public class KingdomArchiveTests - { - [Fact] - public void ReadCorrectly() - { - var files = File.OpenRead("Kh1/res/kh1archive.bin").Using(KingdomArchive.Read); - Assert.Equal(2, files.Count); - Assert.Equal(0x80, files[0].Length); - Assert.Equal(0x80, files[1].Length); - - Assert.Equal(0x11, files[0][0]); - Assert.Equal(0x22, files[0][1]); - - Assert.Equal((byte)'H', files[1][0]); - Assert.Equal((byte)'e', files[1][1]); - } - - [Fact] - public void WriteUsingByteList() => File.OpenRead("Kh1/res/kh1archive.bin").Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - KingdomArchive.Write(outStream, KingdomArchive.Read(inStream)); - - return outStream; - }); - }); - - [Fact] - public void WriteUsingStreamist() => File.OpenRead("Kh1/res/kh1archive.bin").Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - KingdomArchive.Write(outStream, - KingdomArchive.Read(inStream).Select(x => new MemoryStream(x)).ToList()); - - return outStream; - }); - }); - } -} +using OpenKh.Common; +using OpenKh.Kh1; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.Kh1 +{ + public class KingdomArchiveTests + { + [Fact] + public void ReadCorrectly() + { + var files = File.OpenRead("Kh1/res/kh1archive.bin").Using(KingdomArchive.Read); + Assert.Equal(2, files.Count); + Assert.Equal(0x80, files[0].Length); + Assert.Equal(0x80, files[1].Length); + + Assert.Equal(0x11, files[0][0]); + Assert.Equal(0x22, files[0][1]); + + Assert.Equal((byte)'H', files[1][0]); + Assert.Equal((byte)'e', files[1][1]); + } + + [Fact] + public void WriteUsingByteList() => File.OpenRead("Kh1/res/kh1archive.bin").Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + KingdomArchive.Write(outStream, KingdomArchive.Read(inStream)); + + return outStream; + }); + }); + + [Fact] + public void WriteUsingStreamist() => File.OpenRead("Kh1/res/kh1archive.bin").Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + KingdomArchive.Write(outStream, + KingdomArchive.Read(inStream).Select(x => new MemoryStream(x)).ToList()); + + return outStream; + }); + }); + } +} diff --git a/OpenKh.Tests/Patcher/MetadataTests.cs b/OpenKh.Tests/Patcher/MetadataTests.cs index cb4220b90..f4658c452 100644 --- a/OpenKh.Tests/Patcher/MetadataTests.cs +++ b/OpenKh.Tests/Patcher/MetadataTests.cs @@ -1,26 +1,26 @@ -using OpenKh.Common; -using OpenKh.Patcher; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.Patcher -{ - public class MetadataTests - { - [Fact] - public void ReadModMetadataTest() - { - var metadata = File.OpenRead("Patcher/res/sample-simple-mod.yml").Using(Metadata.Read); - - Assert.Equal("My awesome untitled mod", metadata.Title); - Assert.Equal(1, metadata.Specifications); - - Assert.Single(metadata.Dependencies); - Assert.Equal("openkh/is-awesome", metadata.Dependencies[0].Name); - - Assert.NotNull(metadata.Assets); - Assert.Single(metadata.Assets); - Assert.Equal("my/file/path.bin", metadata.Assets[0].Name); - } - } -} +using OpenKh.Common; +using OpenKh.Patcher; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.Patcher +{ + public class MetadataTests + { + [Fact] + public void ReadModMetadataTest() + { + var metadata = File.OpenRead("Patcher/res/sample-simple-mod.yml").Using(Metadata.Read); + + Assert.Equal("My awesome untitled mod", metadata.Title); + Assert.Equal(1, metadata.Specifications); + + Assert.Single(metadata.Dependencies); + Assert.Equal("openkh/is-awesome", metadata.Dependencies[0].Name); + + Assert.NotNull(metadata.Assets); + Assert.Single(metadata.Assets); + Assert.Equal("my/file/path.bin", metadata.Assets[0].Name); + } + } +} diff --git a/OpenKh.Tests/Patcher/PatcherTests.cs b/OpenKh.Tests/Patcher/PatcherTests.cs index f78400051..9e3ea10a3 100644 --- a/OpenKh.Tests/Patcher/PatcherTests.cs +++ b/OpenKh.Tests/Patcher/PatcherTests.cs @@ -1,603 +1,603 @@ -using OpenKh.Common; -using OpenKh.Imaging; -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using OpenKh.Patcher; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xunit; -using Xunit.Sdk; -using YamlDotNet.Serialization; - -namespace OpenKh.Tests.Patcher -{ - public class PatcherTests : IDisposable - { - private const string AssetsInputDir = "original_input"; - private const string ModInputDir = "mod_input"; - private const string ModOutputDir = "mod_output"; - - public PatcherTests() - { - Dispose(); - Directory.CreateDirectory(AssetsInputDir); - Directory.CreateDirectory(ModInputDir); - Directory.CreateDirectory(ModOutputDir); - } - - public void Dispose() - { - if (Directory.Exists(AssetsInputDir)) - Directory.Delete(AssetsInputDir, true); - if (Directory.Exists(ModInputDir)) - Directory.Delete(ModInputDir, true); - if (Directory.Exists(ModOutputDir)) - Directory.Delete(ModOutputDir, true); - } - - [Fact] - public void Kh2CopyBinariesTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "somedir/somefile.bin", - Method = "copy", - Source = new List - { - new AssetFile - { - Name = "somedir/somefile.bin" - } - } - } - } - }; - - CreateFile(ModInputDir, patch.Assets[0].Name).Dispose(); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - } - - [Fact] - public void Kh2CreateBinArcIfSourceDoesntExistsTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "somedir/somefile.bar", - Method = "binarc", - Source = new List - { - new AssetFile - { - Name = "abcd", - Type = "list", - Method = "copy", - Source = new List - { - new AssetFile - { - Name = "somedir/somefile/abcd.bin" - } - } - } - } - } - } - }; - - CreateFile(ModInputDir, "somedir/somefile/abcd.bin").Using(x => - { - x.WriteByte(0); - x.WriteByte(1); - x.WriteByte(2); - x.WriteByte(3); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - AssertBarFile("abcd", entry => - { - Assert.Equal(Bar.EntryType.List, entry.Type); - Assert.Equal(4, entry.Stream.Length); - Assert.Equal(0, entry.Stream.ReadByte()); - Assert.Equal(1, entry.Stream.ReadByte()); - Assert.Equal(2, entry.Stream.ReadByte()); - Assert.Equal(3, entry.Stream.ReadByte()); - }, ModOutputDir, patch.Assets[0].Name); - } - - [Fact] - public void Kh2MergeWithOriginalBinArcTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "somedir/somefile.bar", - Method = "binarc", - Source = new List - { - new AssetFile - { - Name = "abcd", - Type = "list", - Method = "copy", - Source = new List - { - new AssetFile - { - Name = "somedir/somefile/abcd.bin" - } - } - } - } - } - } - }; - - CreateFile(ModInputDir, "somedir/somefile/abcd.bin").Using(x => - { - x.WriteByte(0); - x.WriteByte(1); - x.WriteByte(2); - x.WriteByte(3); - }); - - CreateFile(AssetsInputDir, "somedir/somefile.bar").Using(x => - { - Bar.Write(x, new Bar - { - new Bar.Entry - { - Name = "nice", - Type = Bar.EntryType.Model, - Stream = new MemoryStream(new byte[] { 4, 5, 6, 7 }) - } - }); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - AssertBarFile("abcd", entry => - { - Assert.Equal(Bar.EntryType.List, entry.Type); - Assert.Equal(4, entry.Stream.Length); - Assert.Equal(0, entry.Stream.ReadByte()); - Assert.Equal(1, entry.Stream.ReadByte()); - Assert.Equal(2, entry.Stream.ReadByte()); - Assert.Equal(3, entry.Stream.ReadByte()); - }, ModOutputDir, patch.Assets[0].Name); - AssertBarFile("nice", entry => - { - Assert.Equal(Bar.EntryType.Model, entry.Type); - Assert.Equal(4, entry.Stream.Length); - Assert.Equal(4, entry.Stream.ReadByte()); - Assert.Equal(5, entry.Stream.ReadByte()); - Assert.Equal(6, entry.Stream.ReadByte()); - Assert.Equal(7, entry.Stream.ReadByte()); - }, ModOutputDir, patch.Assets[0].Name); - } - - [Fact] - public void Kh2CreateImgdTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "somedir/somefile.bar", - Method = "binarc", - Source = new List - { - new AssetFile - { - Name = "test", - Method = "imgd", - Type = "imgd", - Source = new List - { - new AssetFile - { - Name = "sample.png", - IsSwizzled = false - } - } - } - } - } - } - }; - - File.Copy("Imaging/res/png/32.png", Path.Combine(ModInputDir, "sample.png")); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - AssertBarFile("test", entry => - { - Assert.True(Imgd.IsValid(entry.Stream)); - }, ModOutputDir, patch.Assets[0].Name); - } - - [Fact] - public void Kh2MergeImzTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "out.imz", - Method = "imgz", - Source = new List - { - new AssetFile - { - Name = "test.imd", - Index = 1, - } - } - } - } - }; - - var tmpImd = Imgd.Create(new System.Drawing.Size(16, 16), PixelFormat.Indexed4, new byte[16 * 16 / 2], new byte[4], false); - var patchImd = Imgd.Create(new System.Drawing.Size(32, 16), PixelFormat.Indexed4, new byte[32 * 16 / 2], new byte[4], false); - CreateFile(AssetsInputDir, "out.imz").Using(x => - { - Imgz.Write(x, new Imgd[] - { - tmpImd, - tmpImd, - tmpImd, - }); - }); - CreateFile(ModInputDir, "test.imd").Using(patchImd.Write); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); - - AssertFileExists(ModOutputDir, "out.imz"); - File.OpenRead(Path.Combine(ModOutputDir, "out.imz")).Using(x => - { - var images = Imgz.Read(x).ToList(); - Assert.Equal(3, images.Count); - Assert.Equal(16, images[0].Size.Width); - Assert.Equal(32, images[1].Size.Width); - Assert.Equal(16, images[2].Size.Width); - }); - } - - [Fact] - public void Kh2MergeImzInsideBarTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "out.bar", - Method = "binarc", - Source = new List - { - new AssetFile - { - Name = "test", - Type = "imgz", - Method = "imgz", - Source = new List - { - new AssetFile - { - Name = "test.imd", - Index = 1 - } - }, - } - } - } - } - }; - - var tmpImd = Imgd.Create(new System.Drawing.Size(16, 16), PixelFormat.Indexed4, new byte[16 * 16 / 2], new byte[4], false); - var patchImd = Imgd.Create(new System.Drawing.Size(32, 16), PixelFormat.Indexed4, new byte[32 * 16 / 2], new byte[4], false); - CreateFile(AssetsInputDir, "out.bar").Using(x => - { - using var memoryStream = new MemoryStream(); - Imgz.Write(memoryStream, new Imgd[] - { - tmpImd, - tmpImd, - tmpImd, - }); - - Bar.Write(x, new Bar - { - new Bar.Entry - { - Name = "test", - Type = Bar.EntryType.Imgz, - Stream = memoryStream - } - }); - }); - CreateFile(ModInputDir, "test.imd").Using(patchImd.Write); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); - - AssertFileExists(ModOutputDir, "out.bar"); - AssertBarFile("test", x => - { - var images = Imgz.Read(x.Stream).ToList(); - Assert.Equal(3, images.Count); - Assert.Equal(16, images[0].Size.Width); - Assert.Equal(32, images[1].Size.Width); - Assert.Equal(16, images[2].Size.Width); - }, ModOutputDir, "out.bar"); - } - - [Fact] - public void MergeKh2MsgTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "msg/us/sys.msg", - Method = "kh2msg", - Source = new List - { - new AssetFile - { - Name = "sys.yml", - Language = "en", - } - } - }, - new AssetFile - { - Name = "msg/it/sys.msg", - Method = "kh2msg", - Source = new List - { - new AssetFile - { - Name = "sys.yml", - Language = "it", - } - } - }, - new AssetFile - { - Name = "msg/jp/sys.msg", - Method = "kh2msg", - Source = new List - { - new AssetFile - { - Name = "sys.yml", - Language = "jp", - } - } - } - } - }; - - Directory.CreateDirectory(Path.Combine(AssetsInputDir, "msg/us/")); - File.Create(Path.Combine(AssetsInputDir, "msg/us/sys.msg")).Using(stream => - { - Msg.Write(stream, new List - { - new Msg.Entry - { - Data = new byte[] { 1, 2, 3, 0 }, - Id = 123 - } - }); - }); - File.Create(Path.Combine(ModInputDir, "sys.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- id: 456"); - writer.WriteLine(" en: English"); - writer.WriteLine(" it: Italiano"); - writer.WriteLine(" jp: テスト"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); - - AssertFileExists(ModOutputDir, "msg/jp/sys.msg"); - File.OpenRead(Path.Combine(ModOutputDir, "msg/jp/sys.msg")).Using(stream => - { - var msg = Msg.Read(stream); - Assert.Single(msg); - Assert.Equal(456, msg[0].Id); - Assert.Equal("テスト", Encoders.JapaneseSystem.Decode(msg[0].Data).First().Text); - }); - - AssertFileExists(ModOutputDir, "msg/us/sys.msg"); - File.OpenRead(Path.Combine(ModOutputDir, "msg/us/sys.msg")).Using(stream => - { - var msg = Msg.Read(stream); - Assert.Equal(2, msg.Count); - Assert.Equal(123, msg[0].Id); - Assert.Equal(456, msg[1].Id); - Assert.Equal("English", Encoders.InternationalSystem.Decode(msg[1].Data).First().Text); - }); - - AssertFileExists(ModOutputDir, "msg/it/sys.msg"); - File.OpenRead(Path.Combine(ModOutputDir, "msg/it/sys.msg")).Using(stream => - { - var msg = Msg.Read(stream); - Assert.Single(msg); - Assert.Equal(456, msg[0].Id); - Assert.Equal("Italiano", Encoders.InternationalSystem.Decode(msg[0].Data).First().Text); - }); - } - - [Fact] - public void MergeKh2AreaDataScriptTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "map.script", - Method = "areadatascript", - Source = new List - { - new AssetFile - { - Name = "map.txt", - } - } - }, - } - }; - - File.Create(Path.Combine(AssetsInputDir, "map.script")).Using(stream => - { - var compiledProgram = Kh2.Ard.AreaDataScript.Compile("Program 1\nSpawn \"1111\""); - Kh2.Ard.AreaDataScript.Write(stream, compiledProgram); - }); - File.Create(Path.Combine(ModInputDir, "map.txt")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("Program 2"); - writer.WriteLine("Spawn \"2222\""); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); - - AssertFileExists(ModOutputDir, "map.script"); - File.OpenRead(Path.Combine(ModOutputDir, "map.script")).Using(stream => - { - var scripts = Kh2.Ard.AreaDataScript.Read(stream); - var decompiled = Kh2.Ard.AreaDataScript.Decompile(scripts); - decompiled.Contains("Program 1"); - decompiled.Contains("Spawn \"1111\""); - decompiled.Contains("Program 2"); - decompiled.Contains("Spawn \"2222\""); - }); - } - - [Fact] - public void ProcessMultipleTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "somedir/somefile.bar", - Method = "binarc", - Multi = new List - { - new Multi { Name = "somedir/another.bar" } - }, - Source = new List - { - new AssetFile - { - Name = "test", - Method = "imgd", - Type = "imgd", - Source = new List - { - new AssetFile - { - Name = "sample.png", - IsSwizzled = false - } - } - } - } - } - } - }; - - File.Copy("Imaging/res/png/32.png", Path.Combine(ModInputDir, "sample.png")); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - AssertBarFile("test", entry => - { - Assert.True(Imgd.IsValid(entry.Stream)); - }, ModOutputDir, patch.Assets[0].Name); - - AssertFileExists(ModOutputDir, patch.Assets[0].Multi[0].Name); - AssertBarFile("test", entry => - { - Assert.True(Imgd.IsValid(entry.Stream)); - }, ModOutputDir, patch.Assets[0].Multi[0].Name); - } - - private static void AssertFileExists(params string[] paths) - { - var filePath = Path.Join(paths); - if (File.Exists(filePath) == false) - throw new TrueException($"File not found '{filePath}'", false); - } - - private static void AssertBarFile(string name, Action assertion, params string[] paths) - { - var filePath = Path.Join(paths); - var entries = File.OpenRead(filePath).Using(x => - { - if (!Bar.IsValid(x)) - throw new TrueException($"Not a valid BinArc", false); - return Bar.Read(x); - }); - - var entry = entries.SingleOrDefault(x => x.Name == name); - if (entry == null) - throw new XunitException($"Entry '{name}' not found"); - - assertion(entry); - } - - private static Stream CreateFile(params string[] paths) - { - var filePath = Path.Join(paths); - var dirPath = Path.GetDirectoryName(filePath); - Directory.CreateDirectory(dirPath); - return File.Create(filePath); - } - } -} +using OpenKh.Common; +using OpenKh.Imaging; +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using OpenKh.Patcher; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xunit; +using Xunit.Sdk; +using YamlDotNet.Serialization; + +namespace OpenKh.Tests.Patcher +{ + public class PatcherTests : IDisposable + { + private const string AssetsInputDir = "original_input"; + private const string ModInputDir = "mod_input"; + private const string ModOutputDir = "mod_output"; + + public PatcherTests() + { + Dispose(); + Directory.CreateDirectory(AssetsInputDir); + Directory.CreateDirectory(ModInputDir); + Directory.CreateDirectory(ModOutputDir); + } + + public void Dispose() + { + if (Directory.Exists(AssetsInputDir)) + Directory.Delete(AssetsInputDir, true); + if (Directory.Exists(ModInputDir)) + Directory.Delete(ModInputDir, true); + if (Directory.Exists(ModOutputDir)) + Directory.Delete(ModOutputDir, true); + } + + [Fact] + public void Kh2CopyBinariesTest() + { + var patcher = new PatcherProcessor(); + var patch = new Metadata + { + Assets = new List + { + new AssetFile + { + Name = "somedir/somefile.bin", + Method = "copy", + Source = new List + { + new AssetFile + { + Name = "somedir/somefile.bin" + } + } + } + } + }; + + CreateFile(ModInputDir, patch.Assets[0].Name).Dispose(); + + patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); + + AssertFileExists(ModOutputDir, patch.Assets[0].Name); + } + + [Fact] + public void Kh2CreateBinArcIfSourceDoesntExistsTest() + { + var patcher = new PatcherProcessor(); + var patch = new Metadata + { + Assets = new List + { + new AssetFile + { + Name = "somedir/somefile.bar", + Method = "binarc", + Source = new List + { + new AssetFile + { + Name = "abcd", + Type = "list", + Method = "copy", + Source = new List + { + new AssetFile + { + Name = "somedir/somefile/abcd.bin" + } + } + } + } + } + } + }; + + CreateFile(ModInputDir, "somedir/somefile/abcd.bin").Using(x => + { + x.WriteByte(0); + x.WriteByte(1); + x.WriteByte(2); + x.WriteByte(3); + }); + + patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); + + AssertFileExists(ModOutputDir, patch.Assets[0].Name); + AssertBarFile("abcd", entry => + { + Assert.Equal(Bar.EntryType.List, entry.Type); + Assert.Equal(4, entry.Stream.Length); + Assert.Equal(0, entry.Stream.ReadByte()); + Assert.Equal(1, entry.Stream.ReadByte()); + Assert.Equal(2, entry.Stream.ReadByte()); + Assert.Equal(3, entry.Stream.ReadByte()); + }, ModOutputDir, patch.Assets[0].Name); + } + + [Fact] + public void Kh2MergeWithOriginalBinArcTest() + { + var patcher = new PatcherProcessor(); + var patch = new Metadata + { + Assets = new List + { + new AssetFile + { + Name = "somedir/somefile.bar", + Method = "binarc", + Source = new List + { + new AssetFile + { + Name = "abcd", + Type = "list", + Method = "copy", + Source = new List + { + new AssetFile + { + Name = "somedir/somefile/abcd.bin" + } + } + } + } + } + } + }; + + CreateFile(ModInputDir, "somedir/somefile/abcd.bin").Using(x => + { + x.WriteByte(0); + x.WriteByte(1); + x.WriteByte(2); + x.WriteByte(3); + }); + + CreateFile(AssetsInputDir, "somedir/somefile.bar").Using(x => + { + Bar.Write(x, new Bar + { + new Bar.Entry + { + Name = "nice", + Type = Bar.EntryType.Model, + Stream = new MemoryStream(new byte[] { 4, 5, 6, 7 }) + } + }); + }); + + patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); + + AssertFileExists(ModOutputDir, patch.Assets[0].Name); + AssertBarFile("abcd", entry => + { + Assert.Equal(Bar.EntryType.List, entry.Type); + Assert.Equal(4, entry.Stream.Length); + Assert.Equal(0, entry.Stream.ReadByte()); + Assert.Equal(1, entry.Stream.ReadByte()); + Assert.Equal(2, entry.Stream.ReadByte()); + Assert.Equal(3, entry.Stream.ReadByte()); + }, ModOutputDir, patch.Assets[0].Name); + AssertBarFile("nice", entry => + { + Assert.Equal(Bar.EntryType.Model, entry.Type); + Assert.Equal(4, entry.Stream.Length); + Assert.Equal(4, entry.Stream.ReadByte()); + Assert.Equal(5, entry.Stream.ReadByte()); + Assert.Equal(6, entry.Stream.ReadByte()); + Assert.Equal(7, entry.Stream.ReadByte()); + }, ModOutputDir, patch.Assets[0].Name); + } + + [Fact] + public void Kh2CreateImgdTest() + { + var patcher = new PatcherProcessor(); + var patch = new Metadata + { + Assets = new List + { + new AssetFile + { + Name = "somedir/somefile.bar", + Method = "binarc", + Source = new List + { + new AssetFile + { + Name = "test", + Method = "imgd", + Type = "imgd", + Source = new List + { + new AssetFile + { + Name = "sample.png", + IsSwizzled = false + } + } + } + } + } + } + }; + + File.Copy("Imaging/res/png/32.png", Path.Combine(ModInputDir, "sample.png")); + + patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); + + AssertFileExists(ModOutputDir, patch.Assets[0].Name); + AssertBarFile("test", entry => + { + Assert.True(Imgd.IsValid(entry.Stream)); + }, ModOutputDir, patch.Assets[0].Name); + } + + [Fact] + public void Kh2MergeImzTest() + { + var patcher = new PatcherProcessor(); + var patch = new Metadata + { + Assets = new List + { + new AssetFile + { + Name = "out.imz", + Method = "imgz", + Source = new List + { + new AssetFile + { + Name = "test.imd", + Index = 1, + } + } + } + } + }; + + var tmpImd = Imgd.Create(new System.Drawing.Size(16, 16), PixelFormat.Indexed4, new byte[16 * 16 / 2], new byte[4], false); + var patchImd = Imgd.Create(new System.Drawing.Size(32, 16), PixelFormat.Indexed4, new byte[32 * 16 / 2], new byte[4], false); + CreateFile(AssetsInputDir, "out.imz").Using(x => + { + Imgz.Write(x, new Imgd[] + { + tmpImd, + tmpImd, + tmpImd, + }); + }); + CreateFile(ModInputDir, "test.imd").Using(patchImd.Write); + + patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); + + AssertFileExists(ModOutputDir, "out.imz"); + File.OpenRead(Path.Combine(ModOutputDir, "out.imz")).Using(x => + { + var images = Imgz.Read(x).ToList(); + Assert.Equal(3, images.Count); + Assert.Equal(16, images[0].Size.Width); + Assert.Equal(32, images[1].Size.Width); + Assert.Equal(16, images[2].Size.Width); + }); + } + + [Fact] + public void Kh2MergeImzInsideBarTest() + { + var patcher = new PatcherProcessor(); + var patch = new Metadata + { + Assets = new List + { + new AssetFile + { + Name = "out.bar", + Method = "binarc", + Source = new List + { + new AssetFile + { + Name = "test", + Type = "imgz", + Method = "imgz", + Source = new List + { + new AssetFile + { + Name = "test.imd", + Index = 1 + } + }, + } + } + } + } + }; + + var tmpImd = Imgd.Create(new System.Drawing.Size(16, 16), PixelFormat.Indexed4, new byte[16 * 16 / 2], new byte[4], false); + var patchImd = Imgd.Create(new System.Drawing.Size(32, 16), PixelFormat.Indexed4, new byte[32 * 16 / 2], new byte[4], false); + CreateFile(AssetsInputDir, "out.bar").Using(x => + { + using var memoryStream = new MemoryStream(); + Imgz.Write(memoryStream, new Imgd[] + { + tmpImd, + tmpImd, + tmpImd, + }); + + Bar.Write(x, new Bar + { + new Bar.Entry + { + Name = "test", + Type = Bar.EntryType.Imgz, + Stream = memoryStream + } + }); + }); + CreateFile(ModInputDir, "test.imd").Using(patchImd.Write); + + patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); + + AssertFileExists(ModOutputDir, "out.bar"); + AssertBarFile("test", x => + { + var images = Imgz.Read(x.Stream).ToList(); + Assert.Equal(3, images.Count); + Assert.Equal(16, images[0].Size.Width); + Assert.Equal(32, images[1].Size.Width); + Assert.Equal(16, images[2].Size.Width); + }, ModOutputDir, "out.bar"); + } + + [Fact] + public void MergeKh2MsgTest() + { + var patcher = new PatcherProcessor(); + var patch = new Metadata + { + Assets = new List + { + new AssetFile + { + Name = "msg/us/sys.msg", + Method = "kh2msg", + Source = new List + { + new AssetFile + { + Name = "sys.yml", + Language = "en", + } + } + }, + new AssetFile + { + Name = "msg/it/sys.msg", + Method = "kh2msg", + Source = new List + { + new AssetFile + { + Name = "sys.yml", + Language = "it", + } + } + }, + new AssetFile + { + Name = "msg/jp/sys.msg", + Method = "kh2msg", + Source = new List + { + new AssetFile + { + Name = "sys.yml", + Language = "jp", + } + } + } + } + }; + + Directory.CreateDirectory(Path.Combine(AssetsInputDir, "msg/us/")); + File.Create(Path.Combine(AssetsInputDir, "msg/us/sys.msg")).Using(stream => + { + Msg.Write(stream, new List + { + new Msg.Entry + { + Data = new byte[] { 1, 2, 3, 0 }, + Id = 123 + } + }); + }); + File.Create(Path.Combine(ModInputDir, "sys.yml")).Using(stream => + { + var writer = new StreamWriter(stream); + writer.WriteLine("- id: 456"); + writer.WriteLine(" en: English"); + writer.WriteLine(" it: Italiano"); + writer.WriteLine(" jp: テスト"); + writer.Flush(); + }); + + patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); + + AssertFileExists(ModOutputDir, "msg/jp/sys.msg"); + File.OpenRead(Path.Combine(ModOutputDir, "msg/jp/sys.msg")).Using(stream => + { + var msg = Msg.Read(stream); + Assert.Single(msg); + Assert.Equal(456, msg[0].Id); + Assert.Equal("テスト", Encoders.JapaneseSystem.Decode(msg[0].Data).First().Text); + }); + + AssertFileExists(ModOutputDir, "msg/us/sys.msg"); + File.OpenRead(Path.Combine(ModOutputDir, "msg/us/sys.msg")).Using(stream => + { + var msg = Msg.Read(stream); + Assert.Equal(2, msg.Count); + Assert.Equal(123, msg[0].Id); + Assert.Equal(456, msg[1].Id); + Assert.Equal("English", Encoders.InternationalSystem.Decode(msg[1].Data).First().Text); + }); + + AssertFileExists(ModOutputDir, "msg/it/sys.msg"); + File.OpenRead(Path.Combine(ModOutputDir, "msg/it/sys.msg")).Using(stream => + { + var msg = Msg.Read(stream); + Assert.Single(msg); + Assert.Equal(456, msg[0].Id); + Assert.Equal("Italiano", Encoders.InternationalSystem.Decode(msg[0].Data).First().Text); + }); + } + + [Fact] + public void MergeKh2AreaDataScriptTest() + { + var patcher = new PatcherProcessor(); + var patch = new Metadata + { + Assets = new List + { + new AssetFile + { + Name = "map.script", + Method = "areadatascript", + Source = new List + { + new AssetFile + { + Name = "map.txt", + } + } + }, + } + }; + + File.Create(Path.Combine(AssetsInputDir, "map.script")).Using(stream => + { + var compiledProgram = Kh2.Ard.AreaDataScript.Compile("Program 1\nSpawn \"1111\""); + Kh2.Ard.AreaDataScript.Write(stream, compiledProgram); + }); + File.Create(Path.Combine(ModInputDir, "map.txt")).Using(stream => + { + var writer = new StreamWriter(stream); + writer.WriteLine("Program 2"); + writer.WriteLine("Spawn \"2222\""); + writer.Flush(); + }); + + patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); + + AssertFileExists(ModOutputDir, "map.script"); + File.OpenRead(Path.Combine(ModOutputDir, "map.script")).Using(stream => + { + var scripts = Kh2.Ard.AreaDataScript.Read(stream); + var decompiled = Kh2.Ard.AreaDataScript.Decompile(scripts); + decompiled.Contains("Program 1"); + decompiled.Contains("Spawn \"1111\""); + decompiled.Contains("Program 2"); + decompiled.Contains("Spawn \"2222\""); + }); + } + + [Fact] + public void ProcessMultipleTest() + { + var patcher = new PatcherProcessor(); + var patch = new Metadata + { + Assets = new List + { + new AssetFile + { + Name = "somedir/somefile.bar", + Method = "binarc", + Multi = new List + { + new Multi { Name = "somedir/another.bar" } + }, + Source = new List + { + new AssetFile + { + Name = "test", + Method = "imgd", + Type = "imgd", + Source = new List + { + new AssetFile + { + Name = "sample.png", + IsSwizzled = false + } + } + } + } + } + } + }; + + File.Copy("Imaging/res/png/32.png", Path.Combine(ModInputDir, "sample.png")); + + patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); + + AssertFileExists(ModOutputDir, patch.Assets[0].Name); + AssertBarFile("test", entry => + { + Assert.True(Imgd.IsValid(entry.Stream)); + }, ModOutputDir, patch.Assets[0].Name); + + AssertFileExists(ModOutputDir, patch.Assets[0].Multi[0].Name); + AssertBarFile("test", entry => + { + Assert.True(Imgd.IsValid(entry.Stream)); + }, ModOutputDir, patch.Assets[0].Multi[0].Name); + } + + private static void AssertFileExists(params string[] paths) + { + var filePath = Path.Join(paths); + if (File.Exists(filePath) == false) + throw new TrueException($"File not found '{filePath}'", false); + } + + private static void AssertBarFile(string name, Action assertion, params string[] paths) + { + var filePath = Path.Join(paths); + var entries = File.OpenRead(filePath).Using(x => + { + if (!Bar.IsValid(x)) + throw new TrueException($"Not a valid BinArc", false); + return Bar.Read(x); + }); + + var entry = entries.SingleOrDefault(x => x.Name == name); + if (entry == null) + throw new XunitException($"Entry '{name}' not found"); + + assertion(entry); + } + + private static Stream CreateFile(params string[] paths) + { + var filePath = Path.Join(paths); + var dirPath = Path.GetDirectoryName(filePath); + Directory.CreateDirectory(dirPath); + return File.Create(filePath); + } + } +} diff --git a/OpenKh.Tests/Ps2/VifTests.cs b/OpenKh.Tests/Ps2/VifTests.cs index 8a83598b1..c8429bb16 100644 --- a/OpenKh.Tests/Ps2/VifTests.cs +++ b/OpenKh.Tests/Ps2/VifTests.cs @@ -1,26 +1,26 @@ -using OpenKh.Common; -using OpenKh.Ps2; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.Ps2 -{ - public class VifTests - { - const string VifFileName = "./Ps2/res/VifPacked.bin"; - const string Vu1FileName = "./Ps2/res/Vu1memory.bin"; - - [Fact] - public void UnpackVifPacketToVu1() => File.OpenRead(Vu1FileName).Using(stream => - { - Helpers.AssertStream(stream, _ => - { - var vifContent = File.ReadAllBytes(VifFileName); - var vifEmulator = new VifUnpacker(vifContent); - vifEmulator.Run(); - - return new MemoryStream(vifEmulator.Memory); - }); - }); - } -} +using OpenKh.Common; +using OpenKh.Ps2; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.Ps2 +{ + public class VifTests + { + const string VifFileName = "./Ps2/res/VifPacked.bin"; + const string Vu1FileName = "./Ps2/res/Vu1memory.bin"; + + [Fact] + public void UnpackVifPacketToVu1() => File.OpenRead(Vu1FileName).Using(stream => + { + Helpers.AssertStream(stream, _ => + { + var vifContent = File.ReadAllBytes(VifFileName); + var vifEmulator = new VifUnpacker(vifContent); + vifEmulator.Run(); + + return new MemoryStream(vifEmulator.Memory); + }); + }); + } +} diff --git a/OpenKh.Tests/kh2/ArdTests.cs b/OpenKh.Tests/kh2/ArdTests.cs index f341acee1..842e47903 100644 --- a/OpenKh.Tests/kh2/ArdTests.cs +++ b/OpenKh.Tests/kh2/ArdTests.cs @@ -1,296 +1,296 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Kh2.Ard; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class ArdTests - { - public class SpawnScriptTests - { - private const string FileName = "kh2/res/map.spawnscript"; - private static readonly byte[] SampleScript = new byte[] - { - // Program header - 0x00, 0x00, 0x40, 0x00, - - // Opcode AreaSettings - 0x0C, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xFF, 0xFF, - - // ProgressFlag - 0x02, 0x00, 0x0A, 0x38, - - // Event - 0x00, 0x00, 0x02, 0x00, 0x31, 0x31, 0x30, 0x00, - - // Jump - 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0E, 0x00, - 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, - - // Party menu - 0x07, 0x00, 0x00, 0x00, - - // Progress flag - 0x02, 0x00, 0x34, 0x12, - - // UnkAreaSet05 - 0x05, 0x00, 0x22, 0x11, - - // AddInventory - 0x06, 0x00, 0x02, 0x00, - 0x9A, 0x02, 0x00, 0x00, - 0x09, 0x03, 0x00, 0x00, - - // End program - 0xFF, 0xFF, 0x00, 0x00, - }; - private const string SampleScriptDecompiled = - "Program 0x00\n" + - "AreaSettings 0 -1\n" + - "\tSetProgressFlag 0x380A\n" + - "\tSetEvent \"110\" Type 2\n" + - "\tSetJump Type 1 World NM Area 5 Entrance 0 LocalSet 0 FadeType 1\n" + - "\tSetPartyMenu 0\n" + - "\tSetProgressFlag 0x1234\n" + - "\tSetUnk05 0x1122\n" + - "\tSetInventory 666 777\n"; - - [Fact] - public void ReadTest() - { - var spawns = File.OpenRead(FileName).Using(AreaDataScript.Read); - var strProgram = spawns.First(x => x.ProgramId == 6).ToString(); - - Assert.Equal(31, spawns.Count); - } - - [Fact] - public void WriteTest() => File.OpenRead(FileName).Using(x => Helpers.AssertStream(x, stream => - { - var outStream = new MemoryStream(); - AreaDataScript.Write(outStream, AreaDataScript.Read(stream)); - - return outStream; - })); - - [Theory] - [InlineData("Spawn \"ABcd\"", 0, 0x64634241)] - [InlineData("MapVisibility 0xffffffff 0x00000001", 1, -1, 1)] - [InlineData("RandomSpawn \"0123\" \"4567\"", 2, 0x33323130, 0x37363534)] - [InlineData("CasualSpawn 123 \"666\"", 3, 123, 0x363636)] - [InlineData("Capacity 123", 4, 0x42F60000)] - [InlineData("AllocEnemy 123", 5, 123)] - [InlineData("Unk06 123", 6, 123)] - [InlineData("Unk07 123", 7, 123)] - [InlineData("SpawnAlt \"666\"", 9, 0x363636)] - [InlineData("Party NO_FRIEND", 15, 0)] - [InlineData("Party DEFAULT", 15, 1)] - [InlineData("Party W_FRIEND", 15, 2)] - [InlineData("Party W_FRIEND_IN", 15, 3)] - [InlineData("Party W_FRIEND_FIX", 15, 4)] - [InlineData("Party W_FRIEND_ONLY", 15, 5)] - [InlineData("Party DONALD_ONLY", 15, 6)] - [InlineData("Bgm 123 456", 16, 0x01c8007b)] - [InlineData("Bgm Default Default", 16, 0)] - [InlineData("StatusFlag3", 0x14)] - [InlineData("Mission 0x1234 \"OPENKH IS OUR MISSION!\"", 0x15, 0x1234, - 0x4E45504F, 0x4920484B, 1431248979, 1229791314, 1330205523, 8526, 0, 0)] - [InlineData("Layout \"OPENKH IS OUR MISSION!\"", 0x16, - 0x4E45504F, 0x4920484B, 1431248979, 1229791314, 1330205523, 8526, 0, 0)] - [InlineData("StatusFlag5", 0x17)] - [InlineData("BattleLevel 99", 0x1E, 99)] - [InlineData("Unk1f \"666\"", 0x1f, 0x363636)] - public void ParseScriptAsText(string expected, int operation, params int[] parameters) - { - const int ProgramId = 0; - - var writer = new BinaryWriter(new MemoryStream()); - writer.Write((short)ProgramId); - writer.Write((short)(parameters.Length * 4 + 8)); - writer.Write((short)operation); - writer.Write((short)parameters.Length); - foreach (var item in parameters) - writer.Write(item); - - writer.BaseStream.Position = 0; - writer.BaseStream.Flush(); - var command = AreaDataScript.Read(writer.BaseStream, ProgramId).First(); - - Assert.Equal(expected, command.ToString()); - } - - [Fact] - public void CreateProgramsCorrectly() - { - const string Input = @" -# This is a comment! - Program 123 # This is our program entry -StatusFlag3 - -Program 0x123 -StatusFlag5"; - var script = AreaDataScript.Compile(Input).ToArray(); - Assert.Equal(2, script.Length); - - Assert.Equal(123, script[0].ProgramId); - Assert.Single(script[0].Functions); - - Assert.Equal(0x123, script[1].ProgramId); - Assert.Single(script[1].Functions); - } - - [Theory] - [InlineData("Spawn \"ABcd\"")] - [InlineData("MapVisibility 0xffffffff 0x00000001")] - [InlineData("RandomSpawn \"0123\" \"4567\"")] - [InlineData("CasualSpawn 123 \"666\"")] - [InlineData("Capacity 123")] - [InlineData("AllocEnemy 123")] - [InlineData("Unk06 123")] - [InlineData("Unk07 123")] - [InlineData("SpawnAlt \"666\"")] - [InlineData("Party NO_FRIEND")] - [InlineData("Party DEFAULT")] - [InlineData("Party W_FRIEND")] - [InlineData("Party W_FRIEND_IN")] - [InlineData("Party W_FRIEND_FIX")] - [InlineData("Party W_FRIEND_ONLY")] - [InlineData("Party DONALD_ONLY")] - [InlineData("Bgm 123 456")] - [InlineData("Bgm Default Default")] - [InlineData("StatusFlag3")] - [InlineData("Mission 0x1234 \"OPENKH IS OUR MISSION!\"")] - [InlineData("Layout \"OPENKH IS OUR MISSION!\"")] - [InlineData("StatusFlag5")] - [InlineData("BattleLevel 99")] - [InlineData("Unk1f \"666\"")] - public void ParseTextAsScript(string input) - { - var code = $"Program 0x00\n{input}"; - var scripts = AreaDataScript.Compile(code).ToArray(); - Assert.Single(scripts); - - var decompiled = scripts.First().ToString(); - - Assert.Equal(code, decompiled); - } - - [Fact] - public void WriteAreaSettings() => - Helpers.AssertStream(new MemoryStream(SampleScript), stream => - { - var dstStream = new MemoryStream(); - var scripts = AreaDataScript.Read(stream); - AreaDataScript.Write(dstStream, scripts); - - return dstStream; - }); - - [Fact] - public void DecompileAreaSettings() - { - var scripts = AreaDataScript.Read(new MemoryStream(SampleScript)); - Assert.Equal(SampleScriptDecompiled, scripts.First().ToString()); - } - - [Fact] - public void CompileAreaSettings() => - Helpers.AssertStream(new MemoryStream(SampleScript), _ => - { - var dstStream = new MemoryStream(); - var scripts = AreaDataScript.Compile(SampleScriptDecompiled); - AreaDataScript.Write(dstStream, scripts); - - return dstStream; - }); - - - public static IEnumerable ScriptSource() - { - if (!Directory.Exists(Path.Combine(Helpers.Kh2DataPath, "ard"))) - { - yield return new object[] { "", "" }; - yield break; - } - - foreach (var fileName in Directory.GetFiles(Helpers.Kh2DataPath, "ard/*.ard", SearchOption.AllDirectories)) - { - if (!File.OpenRead(fileName).Using(Bar.IsValid)) - continue; - - yield return new object[] { fileName, "map" }; - yield return new object[] { fileName, "btl" }; - yield return new object[] { fileName, "evt" }; - } - } - - [SkippableTheory, MemberData(nameof(ScriptSource))] - public void Batch_WriteAllScripts(string ardFile, string scriptSet) - { - Skip.If(ardFile == string.Empty, "No ARD files found"); - - var binarcEntry = File.OpenRead(ardFile).Using(Bar.Read) - .FirstOrDefault(x => x.Name == scriptSet && x.Type == Bar.EntryType.AreaDataScript); - if (binarcEntry == null) - return; - - Helpers.AssertStream(binarcEntry.Stream, stream => - { - var memStream = new MemoryStream(); - AreaDataScript.Write(memStream, AreaDataScript.Read(stream)); - - return memStream; - }); - } - - [SkippableTheory, MemberData(nameof(ScriptSource))] - public void Batch_CompileAllScripts(string ardFile, string scriptSet) - { - Skip.If(ardFile == string.Empty, "No ARD files found"); - - var binarcEntry = File.OpenRead(ardFile).Using(Bar.Read) - .FirstOrDefault(x => x.Name == scriptSet && x.Type == Bar.EntryType.AreaDataScript); - if (binarcEntry == null) - return; - - var expected = AreaDataScript.Decompile(AreaDataScript.Read(binarcEntry.Stream)); - var actual = AreaDataScript.Decompile(AreaDataScript.Compile(expected)); - Assert.Equal(expected, actual); - } - } - - public class SpawnPointTests - { - const string FileNameM00 = "kh2/res/m_00.spawnpoint"; - const string FileNameM10 = "kh2/res/m_10.spawnpoint"; - const string FileNameY73 = "kh2/res/y73_.spawnpoint"; - - [Fact] - public void ReadM00Test() - { - var spawns = File.OpenRead(FileNameM00).Using(SpawnPoint.Read); - - Assert.Equal(4, spawns.Count); - Assert.Equal(3, spawns[0].Entities.Count); - Assert.Equal(0x236, spawns[0].Entities[0].ObjectId); - } - - [Theory] - [InlineData(FileNameM00)] - [InlineData(FileNameM10)] - [InlineData(FileNameY73)] - public void WriteTest(string fileName) => - File.OpenRead(fileName).Using(x => Helpers.AssertStream(x, stream => - { - var outStream = new MemoryStream(); - SpawnPoint.Write(outStream, SpawnPoint.Read(stream)); - - return outStream; - })); - } - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Kh2.Ard; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class ArdTests + { + public class SpawnScriptTests + { + private const string FileName = "kh2/res/map.spawnscript"; + private static readonly byte[] SampleScript = new byte[] + { + // Program header + 0x00, 0x00, 0x40, 0x00, + + // Opcode AreaSettings + 0x0C, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xFF, 0xFF, + + // ProgressFlag + 0x02, 0x00, 0x0A, 0x38, + + // Event + 0x00, 0x00, 0x02, 0x00, 0x31, 0x31, 0x30, 0x00, + + // Jump + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0E, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + + // Party menu + 0x07, 0x00, 0x00, 0x00, + + // Progress flag + 0x02, 0x00, 0x34, 0x12, + + // UnkAreaSet05 + 0x05, 0x00, 0x22, 0x11, + + // AddInventory + 0x06, 0x00, 0x02, 0x00, + 0x9A, 0x02, 0x00, 0x00, + 0x09, 0x03, 0x00, 0x00, + + // End program + 0xFF, 0xFF, 0x00, 0x00, + }; + private const string SampleScriptDecompiled = + "Program 0x00\n" + + "AreaSettings 0 -1\n" + + "\tSetProgressFlag 0x380A\n" + + "\tSetEvent \"110\" Type 2\n" + + "\tSetJump Type 1 World NM Area 5 Entrance 0 LocalSet 0 FadeType 1\n" + + "\tSetPartyMenu 0\n" + + "\tSetProgressFlag 0x1234\n" + + "\tSetUnk05 0x1122\n" + + "\tSetInventory 666 777\n"; + + [Fact] + public void ReadTest() + { + var spawns = File.OpenRead(FileName).Using(AreaDataScript.Read); + var strProgram = spawns.First(x => x.ProgramId == 6).ToString(); + + Assert.Equal(31, spawns.Count); + } + + [Fact] + public void WriteTest() => File.OpenRead(FileName).Using(x => Helpers.AssertStream(x, stream => + { + var outStream = new MemoryStream(); + AreaDataScript.Write(outStream, AreaDataScript.Read(stream)); + + return outStream; + })); + + [Theory] + [InlineData("Spawn \"ABcd\"", 0, 0x64634241)] + [InlineData("MapVisibility 0xffffffff 0x00000001", 1, -1, 1)] + [InlineData("RandomSpawn \"0123\" \"4567\"", 2, 0x33323130, 0x37363534)] + [InlineData("CasualSpawn 123 \"666\"", 3, 123, 0x363636)] + [InlineData("Capacity 123", 4, 0x42F60000)] + [InlineData("AllocEnemy 123", 5, 123)] + [InlineData("Unk06 123", 6, 123)] + [InlineData("Unk07 123", 7, 123)] + [InlineData("SpawnAlt \"666\"", 9, 0x363636)] + [InlineData("Party NO_FRIEND", 15, 0)] + [InlineData("Party DEFAULT", 15, 1)] + [InlineData("Party W_FRIEND", 15, 2)] + [InlineData("Party W_FRIEND_IN", 15, 3)] + [InlineData("Party W_FRIEND_FIX", 15, 4)] + [InlineData("Party W_FRIEND_ONLY", 15, 5)] + [InlineData("Party DONALD_ONLY", 15, 6)] + [InlineData("Bgm 123 456", 16, 0x01c8007b)] + [InlineData("Bgm Default Default", 16, 0)] + [InlineData("StatusFlag3", 0x14)] + [InlineData("Mission 0x1234 \"OPENKH IS OUR MISSION!\"", 0x15, 0x1234, + 0x4E45504F, 0x4920484B, 1431248979, 1229791314, 1330205523, 8526, 0, 0)] + [InlineData("Layout \"OPENKH IS OUR MISSION!\"", 0x16, + 0x4E45504F, 0x4920484B, 1431248979, 1229791314, 1330205523, 8526, 0, 0)] + [InlineData("StatusFlag5", 0x17)] + [InlineData("BattleLevel 99", 0x1E, 99)] + [InlineData("Unk1f \"666\"", 0x1f, 0x363636)] + public void ParseScriptAsText(string expected, int operation, params int[] parameters) + { + const int ProgramId = 0; + + var writer = new BinaryWriter(new MemoryStream()); + writer.Write((short)ProgramId); + writer.Write((short)(parameters.Length * 4 + 8)); + writer.Write((short)operation); + writer.Write((short)parameters.Length); + foreach (var item in parameters) + writer.Write(item); + + writer.BaseStream.Position = 0; + writer.BaseStream.Flush(); + var command = AreaDataScript.Read(writer.BaseStream, ProgramId).First(); + + Assert.Equal(expected, command.ToString()); + } + + [Fact] + public void CreateProgramsCorrectly() + { + const string Input = @" +# This is a comment! + Program 123 # This is our program entry +StatusFlag3 + +Program 0x123 +StatusFlag5"; + var script = AreaDataScript.Compile(Input).ToArray(); + Assert.Equal(2, script.Length); + + Assert.Equal(123, script[0].ProgramId); + Assert.Single(script[0].Functions); + + Assert.Equal(0x123, script[1].ProgramId); + Assert.Single(script[1].Functions); + } + + [Theory] + [InlineData("Spawn \"ABcd\"")] + [InlineData("MapVisibility 0xffffffff 0x00000001")] + [InlineData("RandomSpawn \"0123\" \"4567\"")] + [InlineData("CasualSpawn 123 \"666\"")] + [InlineData("Capacity 123")] + [InlineData("AllocEnemy 123")] + [InlineData("Unk06 123")] + [InlineData("Unk07 123")] + [InlineData("SpawnAlt \"666\"")] + [InlineData("Party NO_FRIEND")] + [InlineData("Party DEFAULT")] + [InlineData("Party W_FRIEND")] + [InlineData("Party W_FRIEND_IN")] + [InlineData("Party W_FRIEND_FIX")] + [InlineData("Party W_FRIEND_ONLY")] + [InlineData("Party DONALD_ONLY")] + [InlineData("Bgm 123 456")] + [InlineData("Bgm Default Default")] + [InlineData("StatusFlag3")] + [InlineData("Mission 0x1234 \"OPENKH IS OUR MISSION!\"")] + [InlineData("Layout \"OPENKH IS OUR MISSION!\"")] + [InlineData("StatusFlag5")] + [InlineData("BattleLevel 99")] + [InlineData("Unk1f \"666\"")] + public void ParseTextAsScript(string input) + { + var code = $"Program 0x00\n{input}"; + var scripts = AreaDataScript.Compile(code).ToArray(); + Assert.Single(scripts); + + var decompiled = scripts.First().ToString(); + + Assert.Equal(code, decompiled); + } + + [Fact] + public void WriteAreaSettings() => + Helpers.AssertStream(new MemoryStream(SampleScript), stream => + { + var dstStream = new MemoryStream(); + var scripts = AreaDataScript.Read(stream); + AreaDataScript.Write(dstStream, scripts); + + return dstStream; + }); + + [Fact] + public void DecompileAreaSettings() + { + var scripts = AreaDataScript.Read(new MemoryStream(SampleScript)); + Assert.Equal(SampleScriptDecompiled, scripts.First().ToString()); + } + + [Fact] + public void CompileAreaSettings() => + Helpers.AssertStream(new MemoryStream(SampleScript), _ => + { + var dstStream = new MemoryStream(); + var scripts = AreaDataScript.Compile(SampleScriptDecompiled); + AreaDataScript.Write(dstStream, scripts); + + return dstStream; + }); + + + public static IEnumerable ScriptSource() + { + if (!Directory.Exists(Path.Combine(Helpers.Kh2DataPath, "ard"))) + { + yield return new object[] { "", "" }; + yield break; + } + + foreach (var fileName in Directory.GetFiles(Helpers.Kh2DataPath, "ard/*.ard", SearchOption.AllDirectories)) + { + if (!File.OpenRead(fileName).Using(Bar.IsValid)) + continue; + + yield return new object[] { fileName, "map" }; + yield return new object[] { fileName, "btl" }; + yield return new object[] { fileName, "evt" }; + } + } + + [SkippableTheory, MemberData(nameof(ScriptSource))] + public void Batch_WriteAllScripts(string ardFile, string scriptSet) + { + Skip.If(ardFile == string.Empty, "No ARD files found"); + + var binarcEntry = File.OpenRead(ardFile).Using(Bar.Read) + .FirstOrDefault(x => x.Name == scriptSet && x.Type == Bar.EntryType.AreaDataScript); + if (binarcEntry == null) + return; + + Helpers.AssertStream(binarcEntry.Stream, stream => + { + var memStream = new MemoryStream(); + AreaDataScript.Write(memStream, AreaDataScript.Read(stream)); + + return memStream; + }); + } + + [SkippableTheory, MemberData(nameof(ScriptSource))] + public void Batch_CompileAllScripts(string ardFile, string scriptSet) + { + Skip.If(ardFile == string.Empty, "No ARD files found"); + + var binarcEntry = File.OpenRead(ardFile).Using(Bar.Read) + .FirstOrDefault(x => x.Name == scriptSet && x.Type == Bar.EntryType.AreaDataScript); + if (binarcEntry == null) + return; + + var expected = AreaDataScript.Decompile(AreaDataScript.Read(binarcEntry.Stream)); + var actual = AreaDataScript.Decompile(AreaDataScript.Compile(expected)); + Assert.Equal(expected, actual); + } + } + + public class SpawnPointTests + { + const string FileNameM00 = "kh2/res/m_00.spawnpoint"; + const string FileNameM10 = "kh2/res/m_10.spawnpoint"; + const string FileNameY73 = "kh2/res/y73_.spawnpoint"; + + [Fact] + public void ReadM00Test() + { + var spawns = File.OpenRead(FileNameM00).Using(SpawnPoint.Read); + + Assert.Equal(4, spawns.Count); + Assert.Equal(3, spawns[0].Entities.Count); + Assert.Equal(0x236, spawns[0].Entities[0].ObjectId); + } + + [Theory] + [InlineData(FileNameM00)] + [InlineData(FileNameM10)] + [InlineData(FileNameY73)] + public void WriteTest(string fileName) => + File.OpenRead(fileName).Using(x => Helpers.AssertStream(x, stream => + { + var outStream = new MemoryStream(); + SpawnPoint.Write(outStream, SpawnPoint.Read(stream)); + + return outStream; + })); + } + } +} diff --git a/OpenKh.Tests/kh2/BarTests.cs b/OpenKh.Tests/kh2/BarTests.cs index 993ab3bdb..4f895e021 100644 --- a/OpenKh.Tests/kh2/BarTests.cs +++ b/OpenKh.Tests/kh2/BarTests.cs @@ -1,197 +1,197 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class BarTests - { - private const string FilePath = "kh2/res/bar_test.bar"; - - [Fact] - public void IsValidTest() - { - using (var stream = new MemoryStream()) - { - stream.WriteByte(0x42); - stream.WriteByte(0x41); - stream.WriteByte(0x52); - stream.WriteByte(0x01); - stream.Position = 0; - Assert.True(Bar.IsValid(stream)); - } - } - - [Fact] - public void IsNotValidTest() - { - using (var stream = new MemoryStream()) - { - stream.WriteByte(1); - stream.WriteByte(2); - stream.WriteByte(3); - stream.WriteByte(4); - stream.Position = 0; - Assert.False(Bar.IsValid(stream)); - } - } - - [Fact] - public void IsReadingEntryCountCorrect() => - File.OpenRead(FilePath).Using(stream => - { - var entries = Bar.Read(stream); - Assert.Equal(7, entries.Count()); - }); - - [Fact] - public void IsReadingEntryNamesCorrectly() => - File.OpenRead(FilePath).Using(stream => - { - var entries = Bar.Read(stream); - Assert.Equal("s_da", entries[0].Name); - Assert.Equal("m_da", entries[1].Name); - Assert.Equal("l_da", entries[2].Name); - Assert.Equal("thru", entries[3].Name); - Assert.Equal("tack", entries[4].Name); - Assert.Equal("blow", entries[5].Name); - Assert.Equal("game", entries[6].Name); - }); - - [Fact] - public void IsReadingEntrySizesCorrectly() => - File.OpenRead(FilePath).Using(stream => - { - var entries = Bar.Read(stream); - Assert.Equal(40, entries[0].Stream.Length); - Assert.Equal(40, entries[1].Stream.Length); - Assert.Equal(48, entries[2].Stream.Length); - Assert.Equal(40, entries[3].Stream.Length); - Assert.Equal(56, entries[4].Stream.Length); - Assert.Equal(64, entries[5].Stream.Length); - Assert.Equal(56, entries[6].Stream.Length); - }); - - [Fact] - public void IsReadingEntryTypesCorrectly() => - File.OpenRead(FilePath).Using(stream => - { - var entries = Bar.Read(stream); - Assert.Equal(Bar.EntryType.Vibration, entries[0].Type); - Assert.Equal(Bar.EntryType.Vibration, entries[1].Type); - Assert.Equal(Bar.EntryType.Vibration, entries[2].Type); - Assert.Equal(Bar.EntryType.Vibration, entries[3].Type); - Assert.Equal(Bar.EntryType.Vibration, entries[4].Type); - Assert.Equal(Bar.EntryType.Vibration, entries[5].Type); - Assert.Equal(Bar.EntryType.Vibration, entries[6].Type); - }); - - [Fact] - public void IsReadingEntryIndexesCorrectly() => - File.OpenRead(FilePath).Using(stream => - { - var entries = Bar.Read(stream); - Assert.Equal(0, entries[0].Index); - Assert.Equal(0, entries[1].Index); - Assert.Equal(0, entries[2].Index); - Assert.Equal(0, entries[3].Index); - Assert.Equal(0, entries[4].Index); - Assert.Equal(0, entries[5].Index); - Assert.Equal(0, entries[6].Index); - }); - - [Fact] - public void IsReadingEntryDataCorrectly() => - File.OpenRead(FilePath).Using(stream => - { - var entries = Bar.Read(stream); - Assert.Equal(86, entries[0].Stream.ReadByte()); - Assert.Equal(86, entries[1].Stream.ReadByte()); - Assert.Equal(86, entries[2].Stream.ReadByte()); - Assert.Equal(86, entries[3].Stream.ReadByte()); - Assert.Equal(86, entries[4].Stream.ReadByte()); - Assert.Equal(86, entries[5].Stream.ReadByte()); - Assert.Equal(86, entries[6].Stream.ReadByte()); - }); - - [Fact] - public void IsReadingFromPcsx2Correctly() - { - const int MemoryAddress = 0x1c000; - const int DataLength = 0x10; - const int TagName = 0x30303030; - var expectedData = Enumerable.Range(0, DataLength).Select(x => (byte)x).ToArray(); - - using var writer = new BinaryWriter(new MemoryStream(0x20000)); - writer.BaseStream.Position = MemoryAddress; - writer.Write(0x01524142U); // header - writer.Write(1); // entry count - writer.Write(MemoryAddress); // where it is physically located in-memory - writer.Write(0); // default - writer.Write(123); // entry type - writer.Write(TagName); // entry name - writer.Write(MemoryAddress + 0x20); // entry address - writer.Write(DataLength); // entry size - writer.Write(expectedData); - - // Attempt to read BAR file from the given portion of memory - writer.BaseStream.Position = MemoryAddress; - Assert.True(Bar.IsValid(writer.BaseStream)); - var binarc = Bar.Read(writer.BaseStream); - Assert.Equal("0000", binarc[0].Name); - Assert.Equal(expectedData, binarc[0].Stream.ReadBytes()); - } - - [Fact] - public void IsWritingBackCorrectly() => - File.OpenRead(FilePath).Using(stream => - { - var expectedData = new byte[stream.Length]; - stream.Read(expectedData, 0, expectedData.Length); - - var entries = Bar.Read(new MemoryStream(expectedData)); - using (var dstStream = new MemoryStream(expectedData.Length)) - { - Bar.Write(dstStream, entries); - dstStream.Position = 0; - var actualData = new byte[dstStream.Length]; - dstStream.Read(actualData, 0, actualData.Length); - - Assert.Equal(expectedData.Length, actualData.Length); - Assert.Equal(expectedData, actualData); - } - }); - - [Theory] - [InlineData("TEST", "TEST")] - [InlineData("333", "333")] - [InlineData("22", "22")] - [InlineData("1", "1")] - [InlineData("666666", "6666")] - public void AlwaysReadCorrectName(string name, string expectedName) - { - var entries = new List - { - new Bar.Entry - { - Type = Bar.EntryType.Dummy, - Index = 0, - Name = name, - Stream = new MemoryStream() - } - }; - - using (var tmpStream = new MemoryStream()) - { - Bar.Write(tmpStream, entries); - tmpStream.Position = 0; - entries = Bar.Read(tmpStream); - } - - Assert.Equal(expectedName, entries[0].Name); - } - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class BarTests + { + private const string FilePath = "kh2/res/bar_test.bar"; + + [Fact] + public void IsValidTest() + { + using (var stream = new MemoryStream()) + { + stream.WriteByte(0x42); + stream.WriteByte(0x41); + stream.WriteByte(0x52); + stream.WriteByte(0x01); + stream.Position = 0; + Assert.True(Bar.IsValid(stream)); + } + } + + [Fact] + public void IsNotValidTest() + { + using (var stream = new MemoryStream()) + { + stream.WriteByte(1); + stream.WriteByte(2); + stream.WriteByte(3); + stream.WriteByte(4); + stream.Position = 0; + Assert.False(Bar.IsValid(stream)); + } + } + + [Fact] + public void IsReadingEntryCountCorrect() => + File.OpenRead(FilePath).Using(stream => + { + var entries = Bar.Read(stream); + Assert.Equal(7, entries.Count()); + }); + + [Fact] + public void IsReadingEntryNamesCorrectly() => + File.OpenRead(FilePath).Using(stream => + { + var entries = Bar.Read(stream); + Assert.Equal("s_da", entries[0].Name); + Assert.Equal("m_da", entries[1].Name); + Assert.Equal("l_da", entries[2].Name); + Assert.Equal("thru", entries[3].Name); + Assert.Equal("tack", entries[4].Name); + Assert.Equal("blow", entries[5].Name); + Assert.Equal("game", entries[6].Name); + }); + + [Fact] + public void IsReadingEntrySizesCorrectly() => + File.OpenRead(FilePath).Using(stream => + { + var entries = Bar.Read(stream); + Assert.Equal(40, entries[0].Stream.Length); + Assert.Equal(40, entries[1].Stream.Length); + Assert.Equal(48, entries[2].Stream.Length); + Assert.Equal(40, entries[3].Stream.Length); + Assert.Equal(56, entries[4].Stream.Length); + Assert.Equal(64, entries[5].Stream.Length); + Assert.Equal(56, entries[6].Stream.Length); + }); + + [Fact] + public void IsReadingEntryTypesCorrectly() => + File.OpenRead(FilePath).Using(stream => + { + var entries = Bar.Read(stream); + Assert.Equal(Bar.EntryType.Vibration, entries[0].Type); + Assert.Equal(Bar.EntryType.Vibration, entries[1].Type); + Assert.Equal(Bar.EntryType.Vibration, entries[2].Type); + Assert.Equal(Bar.EntryType.Vibration, entries[3].Type); + Assert.Equal(Bar.EntryType.Vibration, entries[4].Type); + Assert.Equal(Bar.EntryType.Vibration, entries[5].Type); + Assert.Equal(Bar.EntryType.Vibration, entries[6].Type); + }); + + [Fact] + public void IsReadingEntryIndexesCorrectly() => + File.OpenRead(FilePath).Using(stream => + { + var entries = Bar.Read(stream); + Assert.Equal(0, entries[0].Index); + Assert.Equal(0, entries[1].Index); + Assert.Equal(0, entries[2].Index); + Assert.Equal(0, entries[3].Index); + Assert.Equal(0, entries[4].Index); + Assert.Equal(0, entries[5].Index); + Assert.Equal(0, entries[6].Index); + }); + + [Fact] + public void IsReadingEntryDataCorrectly() => + File.OpenRead(FilePath).Using(stream => + { + var entries = Bar.Read(stream); + Assert.Equal(86, entries[0].Stream.ReadByte()); + Assert.Equal(86, entries[1].Stream.ReadByte()); + Assert.Equal(86, entries[2].Stream.ReadByte()); + Assert.Equal(86, entries[3].Stream.ReadByte()); + Assert.Equal(86, entries[4].Stream.ReadByte()); + Assert.Equal(86, entries[5].Stream.ReadByte()); + Assert.Equal(86, entries[6].Stream.ReadByte()); + }); + + [Fact] + public void IsReadingFromPcsx2Correctly() + { + const int MemoryAddress = 0x1c000; + const int DataLength = 0x10; + const int TagName = 0x30303030; + var expectedData = Enumerable.Range(0, DataLength).Select(x => (byte)x).ToArray(); + + using var writer = new BinaryWriter(new MemoryStream(0x20000)); + writer.BaseStream.Position = MemoryAddress; + writer.Write(0x01524142U); // header + writer.Write(1); // entry count + writer.Write(MemoryAddress); // where it is physically located in-memory + writer.Write(0); // default + writer.Write(123); // entry type + writer.Write(TagName); // entry name + writer.Write(MemoryAddress + 0x20); // entry address + writer.Write(DataLength); // entry size + writer.Write(expectedData); + + // Attempt to read BAR file from the given portion of memory + writer.BaseStream.Position = MemoryAddress; + Assert.True(Bar.IsValid(writer.BaseStream)); + var binarc = Bar.Read(writer.BaseStream); + Assert.Equal("0000", binarc[0].Name); + Assert.Equal(expectedData, binarc[0].Stream.ReadBytes()); + } + + [Fact] + public void IsWritingBackCorrectly() => + File.OpenRead(FilePath).Using(stream => + { + var expectedData = new byte[stream.Length]; + stream.Read(expectedData, 0, expectedData.Length); + + var entries = Bar.Read(new MemoryStream(expectedData)); + using (var dstStream = new MemoryStream(expectedData.Length)) + { + Bar.Write(dstStream, entries); + dstStream.Position = 0; + var actualData = new byte[dstStream.Length]; + dstStream.Read(actualData, 0, actualData.Length); + + Assert.Equal(expectedData.Length, actualData.Length); + Assert.Equal(expectedData, actualData); + } + }); + + [Theory] + [InlineData("TEST", "TEST")] + [InlineData("333", "333")] + [InlineData("22", "22")] + [InlineData("1", "1")] + [InlineData("666666", "6666")] + public void AlwaysReadCorrectName(string name, string expectedName) + { + var entries = new List + { + new Bar.Entry + { + Type = Bar.EntryType.Dummy, + Index = 0, + Name = name, + Stream = new MemoryStream() + } + }; + + using (var tmpStream = new MemoryStream()) + { + Bar.Write(tmpStream, entries); + tmpStream.Position = 0; + entries = Bar.Read(tmpStream); + } + + Assert.Equal(expectedName, entries[0].Name); + } + } +} diff --git a/OpenKh.Tests/kh2/BattleTests.cs b/OpenKh.Tests/kh2/BattleTests.cs index b6be138bf..09b1225cd 100644 --- a/OpenKh.Tests/kh2/BattleTests.cs +++ b/OpenKh.Tests/kh2/BattleTests.cs @@ -1,145 +1,145 @@ -using OpenKh.Common; -using OpenKh.Kh2.Battle; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class BattleTests - { - public class FmlvTests - { - [Fact] - public void CheckStandardNewImpl() => File.OpenRead(@"kh2/res/fmlv_de.bin").Using(stream => - { - var table = Fmlv.Read(stream); - - Assert.Equal(0x26, table.Count); - - Assert.Equal(6, table.GroupBy(x => x.FormId).ToList().Count); - - Assert.Equal(0x5A, table.FirstOrDefault(x => x.FormId == 2 && x.FormLevel == 4).Exp); - }); - - [Fact] - public void CheckFinalMixNewImpl() => File.OpenRead(@"kh2/res/fmlv_fm.bin").Using(stream => - { - var table = Fmlv.Read(stream); - - Assert.Equal(0x2D, table.Count); - - Assert.Equal(7, table.GroupBy(x => x.FormId).ToList().Count); - - Assert.Equal(0x4C, table.FirstOrDefault(x => x.FormId == 2 && x.FormLevel == 4).Exp); - }); - - [Theory] - [InlineData(@"kh2/res/fmlv_de.bin")] - [InlineData(@"kh2/res/fmlv_fm.bin")] - public void WriteTest(string fileName) => File.OpenRead(fileName).Using(stream => - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Fmlv.Write(outStream, Fmlv.Read(inStream)); - - return outStream; - }) - ); - } - - public class EnemyTest - { - [Fact] - public void ReadTest() => File.OpenRead(@"kh2/res/enmp.bin").Using(stream => - { - var table = Enmp.Read(stream); - - Assert.Equal(229, table.Count); - - var roxas = table.FirstOrDefault(enemy => enemy.Id == 242); - Assert.Equal(99, roxas.Level); - Assert.Equal(1750, roxas.Health[0]); - Assert.Equal(86, roxas.Unknown44); // 56 - Assert.Equal(28, roxas.Unknown46); - Assert.Equal(100, roxas.PhysicalWeakness); - Assert.Equal(25, roxas.FireWeakness); - Assert.Equal(25, roxas.IceWeakness); - Assert.Equal(25, roxas.ThunderWeakness); - Assert.Equal(25, roxas.DarkWeakness); - Assert.Equal(25, roxas.Unknown52); - Assert.Equal(100, roxas.ReflectWeakness); - }); - - [Fact] - public void WriteTest() => File.OpenRead(@"kh2/res/enmp.bin").Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Enmp.Write(outStream, Enmp.Read(inStream)); - return outStream; - }); - }); - } - - public class LvupTests - { - [Fact] - public void LvupTableTest() => File.OpenRead(@"kh2/res/lvup_fm.bin").Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Lvup.Read(inStream).Write(outStream); - return outStream; - }); - }); - - [Fact] - public void WriteTest() => File.OpenRead(@"kh2/res/lvup_fm.bin").Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Lvup.Read(inStream).Write(outStream); - return outStream; - }); - }); - } - - [Fact] - public void BonsTableTest() => File.OpenRead(@"kh2/res/bons_fm.bin").Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Bons.Write(outStream, Bons.Read(inStream)); - return outStream; - }); - }); - - [Fact] - public void PrztTableTest() => File.OpenRead(@"kh2/res/przt.bin").Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Przt.Write(outStream, Przt.Read(inStream)); - return outStream; - }); - }); - - [Fact] - public void VtblTableTest() => File.OpenRead(@"kh2/res/vtbl.bin").Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Vtbl.Write(outStream, Vtbl.Read(inStream)); - return outStream; - }); - }); - - } -} +using OpenKh.Common; +using OpenKh.Kh2.Battle; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class BattleTests + { + public class FmlvTests + { + [Fact] + public void CheckStandardNewImpl() => File.OpenRead(@"kh2/res/fmlv_de.bin").Using(stream => + { + var table = Fmlv.Read(stream); + + Assert.Equal(0x26, table.Count); + + Assert.Equal(6, table.GroupBy(x => x.FormId).ToList().Count); + + Assert.Equal(0x5A, table.FirstOrDefault(x => x.FormId == 2 && x.FormLevel == 4).Exp); + }); + + [Fact] + public void CheckFinalMixNewImpl() => File.OpenRead(@"kh2/res/fmlv_fm.bin").Using(stream => + { + var table = Fmlv.Read(stream); + + Assert.Equal(0x2D, table.Count); + + Assert.Equal(7, table.GroupBy(x => x.FormId).ToList().Count); + + Assert.Equal(0x4C, table.FirstOrDefault(x => x.FormId == 2 && x.FormLevel == 4).Exp); + }); + + [Theory] + [InlineData(@"kh2/res/fmlv_de.bin")] + [InlineData(@"kh2/res/fmlv_fm.bin")] + public void WriteTest(string fileName) => File.OpenRead(fileName).Using(stream => + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Fmlv.Write(outStream, Fmlv.Read(inStream)); + + return outStream; + }) + ); + } + + public class EnemyTest + { + [Fact] + public void ReadTest() => File.OpenRead(@"kh2/res/enmp.bin").Using(stream => + { + var table = Enmp.Read(stream); + + Assert.Equal(229, table.Count); + + var roxas = table.FirstOrDefault(enemy => enemy.Id == 242); + Assert.Equal(99, roxas.Level); + Assert.Equal(1750, roxas.Health[0]); + Assert.Equal(86, roxas.Unknown44); // 56 + Assert.Equal(28, roxas.Unknown46); + Assert.Equal(100, roxas.PhysicalWeakness); + Assert.Equal(25, roxas.FireWeakness); + Assert.Equal(25, roxas.IceWeakness); + Assert.Equal(25, roxas.ThunderWeakness); + Assert.Equal(25, roxas.DarkWeakness); + Assert.Equal(25, roxas.Unknown52); + Assert.Equal(100, roxas.ReflectWeakness); + }); + + [Fact] + public void WriteTest() => File.OpenRead(@"kh2/res/enmp.bin").Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Enmp.Write(outStream, Enmp.Read(inStream)); + return outStream; + }); + }); + } + + public class LvupTests + { + [Fact] + public void LvupTableTest() => File.OpenRead(@"kh2/res/lvup_fm.bin").Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Lvup.Read(inStream).Write(outStream); + return outStream; + }); + }); + + [Fact] + public void WriteTest() => File.OpenRead(@"kh2/res/lvup_fm.bin").Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Lvup.Read(inStream).Write(outStream); + return outStream; + }); + }); + } + + [Fact] + public void BonsTableTest() => File.OpenRead(@"kh2/res/bons_fm.bin").Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Bons.Write(outStream, Bons.Read(inStream)); + return outStream; + }); + }); + + [Fact] + public void PrztTableTest() => File.OpenRead(@"kh2/res/przt.bin").Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Przt.Write(outStream, Przt.Read(inStream)); + return outStream; + }); + }); + + [Fact] + public void VtblTableTest() => File.OpenRead(@"kh2/res/vtbl.bin").Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Vtbl.Write(outStream, Vtbl.Read(inStream)); + return outStream; + }); + }); + + } +} diff --git a/OpenKh.Tests/kh2/BobDescTests.cs b/OpenKh.Tests/kh2/BobDescTests.cs index 3fdfd8d70..aaf97aa2a 100644 --- a/OpenKh.Tests/kh2/BobDescTests.cs +++ b/OpenKh.Tests/kh2/BobDescTests.cs @@ -1,42 +1,42 @@ -using OpenKh.Common; -using OpenKh.Kh2.Models; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class BobDescTests - { - private const string FileName = "kh2/res/bobdesc.bin"; - - [Fact] - public void ReadCorrectValues() - { - var bobDesc = File.OpenRead(FileName).Using(BobDescriptor.Read); - - Assert.Equal(4, bobDesc.Count); - Assert.Equal(1100, bobDesc[0].PositionX); - Assert.Equal(0, bobDesc[0].PositionY); - Assert.Equal(0, bobDesc[0].PositionZ); - Assert.Equal(0, bobDesc[0].RotationX); - Assert.Equal(0, bobDesc[0].RotationY); - Assert.Equal(0, bobDesc[0].RotationZ); - Assert.Equal(1, bobDesc[0].ScalingX); - Assert.Equal(1, bobDesc[0].ScalingY); - Assert.Equal(1, bobDesc[0].ScalingZ); - Assert.Equal(0, bobDesc[0].BobIndex); - } - - [Fact] - public void WriteTest() => File.OpenRead(FileName).Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - BobDescriptor.Write(outStream, BobDescriptor.Read(inStream)); - - return outStream; - }); - }); - } -} +using OpenKh.Common; +using OpenKh.Kh2.Models; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class BobDescTests + { + private const string FileName = "kh2/res/bobdesc.bin"; + + [Fact] + public void ReadCorrectValues() + { + var bobDesc = File.OpenRead(FileName).Using(BobDescriptor.Read); + + Assert.Equal(4, bobDesc.Count); + Assert.Equal(1100, bobDesc[0].PositionX); + Assert.Equal(0, bobDesc[0].PositionY); + Assert.Equal(0, bobDesc[0].PositionZ); + Assert.Equal(0, bobDesc[0].RotationX); + Assert.Equal(0, bobDesc[0].RotationY); + Assert.Equal(0, bobDesc[0].RotationZ); + Assert.Equal(1, bobDesc[0].ScalingX); + Assert.Equal(1, bobDesc[0].ScalingY); + Assert.Equal(1, bobDesc[0].ScalingZ); + Assert.Equal(0, bobDesc[0].BobIndex); + } + + [Fact] + public void WriteTest() => File.OpenRead(FileName).Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + BobDescriptor.Write(outStream, BobDescriptor.Read(inStream)); + + return outStream; + }); + }); + } +} diff --git a/OpenKh.Tests/kh2/CollisionTests.cs b/OpenKh.Tests/kh2/CollisionTests.cs index d13d3e652..75f437d43 100644 --- a/OpenKh.Tests/kh2/CollisionTests.cs +++ b/OpenKh.Tests/kh2/CollisionTests.cs @@ -61,4 +61,4 @@ public void WriteCollision() => File.OpenRead(FileName).Using(x => // return outStream; // }); } -} +} diff --git a/OpenKh.Tests/kh2/DoctTest.cs b/OpenKh.Tests/kh2/DoctTest.cs index b72212a1f..936eae440 100644 --- a/OpenKh.Tests/kh2/DoctTest.cs +++ b/OpenKh.Tests/kh2/DoctTest.cs @@ -1,4 +1,4 @@ -using OpenKh.Kh2; +using OpenKh.Kh2; using System.IO; using Xunit; diff --git a/OpenKh.Tests/kh2/EventTests.cs b/OpenKh.Tests/kh2/EventTests.cs index ef034ee83..b94206910 100644 --- a/OpenKh.Tests/kh2/EventTests.cs +++ b/OpenKh.Tests/kh2/EventTests.cs @@ -1,349 +1,349 @@ -using OpenKh.Common; -using OpenKh.Kh2.Ard; -using System.Collections.Generic; -using System.IO; -using Xunit; -using Xunit.Sdk; - -namespace OpenKh.Tests.kh2 -{ - public class EventTests - { - [Fact] - public void ParseProject() => - AssertEvent(); - - [Fact] - public void ParseSetActor() => - AssertEvent(); - - [Fact] - public void ParseSeqActorPosition() => - AssertEvent(); - - [Fact] - public void ParseSetMap() => - AssertEvent(); - - [Fact] - public void ParseSeqCamera() => - AssertEvent(); - - [Fact] - public void ParseSetEndFrame() => - AssertEvent(); - - [Fact] - public void ParseSeqEffect() => - AssertEvent(); - - [Fact] - public void ParseAttachEffect() => - AssertEvent(); - - [Fact] - public void ParseUnk0C() => - AssertEvent(); - - [Fact] - public void ParseUnk0D() => - AssertEvent(new Event.Unk0D - { - StartFrame = 123, - EndFrame = 456, - Unk = new short[] - { - 11, 22, 33, 44 - } - }); - - [Fact] - public void ParseUnk0E() => - AssertEvent(); - - [Fact] - public void ParseSetupEvent() => - AssertEvent(); - - [Fact] - public void ParseEventStart() => - AssertEvent(); - - [Fact] - public void ParseSeqFade() => - AssertEvent(new Event.SeqFade - { - FrameIndex = 123, - Duration = 456, - Type = Event.SeqFade.FadeType.FromWhiteVariant - }); - - [Fact] - public void ParseSetCameraData() => - AssertEvent(new Event.SetCameraData - { - CameraId = 123, - PositionX = new List - { - new Event.SetCameraData.CameraKeys - { - Interpolation = Kh2.Motion.Interpolation.Hermite, - KeyFrame = 1234, - Value = 1, - TangentEaseIn = 3, - TangentEaseOut = 4 - }, - new Event.SetCameraData.CameraKeys - { - Interpolation = Kh2.Motion.Interpolation.Linear, - KeyFrame = 5678, - Value = 5, - TangentEaseIn = 7, - TangentEaseOut = 8 - }, - }, - PositionY = new List() - { - new Event.SetCameraData.CameraKeys - { - Interpolation = Kh2.Motion.Interpolation.Nearest, - KeyFrame = 32767, - Value = 11, - TangentEaseIn = 33, - TangentEaseOut = 44 - }, - }, - PositionZ = new List(), - LookAtX = new List(), - LookAtY = new List(), - LookAtZ = new List(), - FieldOfView = new List(), - Roll = new List(), - }); - - [Fact] - public void ParseEntryUnk14() => - AssertEvent(); - - [Fact] - public void ParseSeqSubtitle() => - AssertEvent(); - - [Fact] - public void ParseEntryUnk16() => - AssertEvent(); - - [Fact] - public void ParseEntryUnk17() => - AssertEvent(); - - [Fact] - public void ParseEntryUnk18() => - AssertEvent(); - - [Fact] - public void ParseSeqTextureAnim() => - AssertEvent(); - - [Fact] - public void ParseEntryUnk1A() => - AssertEvent(); - - [Fact] - public void ParseSeqCrossFade() => - AssertEvent(); - - [Fact] - public void ParseEntryUnk1D() => - AssertEvent(); - - [Fact] - public void ParseEntryUnk1E() => - AssertEvent(new Event.Unk1E - { - Id = 123, - UnkG = 456, - UnkH = 789, - Entries = new List() - { - Helpers.CreateDummyObject(), - Helpers.CreateDummyObject(), - Helpers.CreateDummyObject(), - Helpers.CreateDummyObject(), - Helpers.CreateDummyObject(), - Helpers.CreateDummyObject(), - Helpers.CreateDummyObject(), - } - }); - - [Fact] - public void ParseEntryUnk1F() => - AssertEvent(); - - [Fact] - public void ParseSeqGameSpeed() => - AssertEvent(); - - [Fact] - public void ParseEntryUnk22() => - AssertEvent(); - - [Fact] - public void ParseSeqVoices() => - AssertEvent(new Event.SeqVoices - { - Voices = new List - { - new Event.SeqVoices.Voice - { - FrameStart = 123, - Name = "first" - }, - new Event.SeqVoices.Voice - { - FrameStart = 456, - Name = "second" - }, - } - }); - - [Fact] - public void ParseReadAssets() => - AssertEvent(new Event.ReadAssets - { - FrameStart = 123, - FrameEnd = 456, - Unk06 = 789, - Set = new List - { - Helpers.CreateDummyObject(), - Helpers.CreateDummyObject(), - Helpers.CreateDummyObject(), - Helpers.CreateDummyObject(), - Helpers.CreateDummyObject(), - } - }); - - [Fact] - public void ParseReadAnimation() => - AssertEvent(); - - [Fact] - public void ParseReadAudio() => - AssertEvent(); - - [Fact] - public void ParseSetRumble() => - AssertEvent(); - - [Fact] - public void ParseEntryUnk2A() => - AssertEvent(); - - [Fact] - public void ParseSeqPlayAudio() => - AssertEvent(); - - [Fact] - public void ParseSeqPlayAnimation() => - AssertEvent(); - - [Fact] - public void ParseSeqDialog() => - AssertEvent(); - - [Fact] - public void ParseSeqPlayBgm() => - AssertEvent(); - - [Fact] - public void ParseReadBgm() => - AssertEvent(); - - [Fact] - public void ParseSetBgm() => - AssertEvent(); - - [Fact] - public void ParseEntryUnk36() => - AssertEvent(); - - [Fact] - public void ParseReadActor() => - AssertEvent(); - - [Fact] - public void ParseReadEffect() => - AssertEvent(); - - [Fact] - public void ParseSeqLayout() => - AssertEvent(); - - [Fact] - public void ParseReadLayout() => - AssertEvent(); - - [Fact] - public void ParseStopEffect() => - AssertEvent(); - - [Fact] - public void ParseRunMovie() => - AssertEvent(); - - [Fact] - public void ParseUnk42() => - AssertEvent(); - - [Fact] - public void ParseEntryUnk47() => - AssertEvent(); - - [Fact] - public void ParseHideObject() => - AssertEvent(); - - private static void AssertEvent() - where T : class, Event.IEventEntry => - AssertEvent(Helpers.CreateDummyObject()); - - private static void AssertEvent(T expected) - where T : class, Event.IEventEntry - { - using var stream = new MemoryStream(); - Event.Write(stream, new Event.IEventEntry[] - { - expected - }); - var actualLength = stream.Position - 2; - if ((actualLength % 2) == 1) - throw new AssertActualExpectedException( - actualLength + 1, actualLength, - "Offset is not aligned by 2"); - - stream.Position = 0; - var eventSet = Event.Read(stream); - var expectedLength = stream.Position; - - Assert.Single(eventSet); - Assert.IsType(eventSet[0]); - if (expectedLength != actualLength) - throw new AssertActualExpectedException( - expectedLength, actualLength, - "Stream length does not match"); - - var actual = eventSet[0]; - foreach (var property in typeof(T).GetProperties()) - { - var expectedValue = property.GetValue(expected); - var actualValue = property.GetValue(actual); - if (expectedValue.ToString() != - actualValue.ToString()) - throw new AssertActualExpectedException( - expectedValue, actualValue, - $"Different values for '{property.Name}'"); - } - } - } -} +using OpenKh.Common; +using OpenKh.Kh2.Ard; +using System.Collections.Generic; +using System.IO; +using Xunit; +using Xunit.Sdk; + +namespace OpenKh.Tests.kh2 +{ + public class EventTests + { + [Fact] + public void ParseProject() => + AssertEvent(); + + [Fact] + public void ParseSetActor() => + AssertEvent(); + + [Fact] + public void ParseSeqActorPosition() => + AssertEvent(); + + [Fact] + public void ParseSetMap() => + AssertEvent(); + + [Fact] + public void ParseSeqCamera() => + AssertEvent(); + + [Fact] + public void ParseSetEndFrame() => + AssertEvent(); + + [Fact] + public void ParseSeqEffect() => + AssertEvent(); + + [Fact] + public void ParseAttachEffect() => + AssertEvent(); + + [Fact] + public void ParseUnk0C() => + AssertEvent(); + + [Fact] + public void ParseUnk0D() => + AssertEvent(new Event.Unk0D + { + StartFrame = 123, + EndFrame = 456, + Unk = new short[] + { + 11, 22, 33, 44 + } + }); + + [Fact] + public void ParseUnk0E() => + AssertEvent(); + + [Fact] + public void ParseSetupEvent() => + AssertEvent(); + + [Fact] + public void ParseEventStart() => + AssertEvent(); + + [Fact] + public void ParseSeqFade() => + AssertEvent(new Event.SeqFade + { + FrameIndex = 123, + Duration = 456, + Type = Event.SeqFade.FadeType.FromWhiteVariant + }); + + [Fact] + public void ParseSetCameraData() => + AssertEvent(new Event.SetCameraData + { + CameraId = 123, + PositionX = new List + { + new Event.SetCameraData.CameraKeys + { + Interpolation = Kh2.Motion.Interpolation.Hermite, + KeyFrame = 1234, + Value = 1, + TangentEaseIn = 3, + TangentEaseOut = 4 + }, + new Event.SetCameraData.CameraKeys + { + Interpolation = Kh2.Motion.Interpolation.Linear, + KeyFrame = 5678, + Value = 5, + TangentEaseIn = 7, + TangentEaseOut = 8 + }, + }, + PositionY = new List() + { + new Event.SetCameraData.CameraKeys + { + Interpolation = Kh2.Motion.Interpolation.Nearest, + KeyFrame = 32767, + Value = 11, + TangentEaseIn = 33, + TangentEaseOut = 44 + }, + }, + PositionZ = new List(), + LookAtX = new List(), + LookAtY = new List(), + LookAtZ = new List(), + FieldOfView = new List(), + Roll = new List(), + }); + + [Fact] + public void ParseEntryUnk14() => + AssertEvent(); + + [Fact] + public void ParseSeqSubtitle() => + AssertEvent(); + + [Fact] + public void ParseEntryUnk16() => + AssertEvent(); + + [Fact] + public void ParseEntryUnk17() => + AssertEvent(); + + [Fact] + public void ParseEntryUnk18() => + AssertEvent(); + + [Fact] + public void ParseSeqTextureAnim() => + AssertEvent(); + + [Fact] + public void ParseEntryUnk1A() => + AssertEvent(); + + [Fact] + public void ParseSeqCrossFade() => + AssertEvent(); + + [Fact] + public void ParseEntryUnk1D() => + AssertEvent(); + + [Fact] + public void ParseEntryUnk1E() => + AssertEvent(new Event.Unk1E + { + Id = 123, + UnkG = 456, + UnkH = 789, + Entries = new List() + { + Helpers.CreateDummyObject(), + Helpers.CreateDummyObject(), + Helpers.CreateDummyObject(), + Helpers.CreateDummyObject(), + Helpers.CreateDummyObject(), + Helpers.CreateDummyObject(), + Helpers.CreateDummyObject(), + } + }); + + [Fact] + public void ParseEntryUnk1F() => + AssertEvent(); + + [Fact] + public void ParseSeqGameSpeed() => + AssertEvent(); + + [Fact] + public void ParseEntryUnk22() => + AssertEvent(); + + [Fact] + public void ParseSeqVoices() => + AssertEvent(new Event.SeqVoices + { + Voices = new List + { + new Event.SeqVoices.Voice + { + FrameStart = 123, + Name = "first" + }, + new Event.SeqVoices.Voice + { + FrameStart = 456, + Name = "second" + }, + } + }); + + [Fact] + public void ParseReadAssets() => + AssertEvent(new Event.ReadAssets + { + FrameStart = 123, + FrameEnd = 456, + Unk06 = 789, + Set = new List + { + Helpers.CreateDummyObject(), + Helpers.CreateDummyObject(), + Helpers.CreateDummyObject(), + Helpers.CreateDummyObject(), + Helpers.CreateDummyObject(), + } + }); + + [Fact] + public void ParseReadAnimation() => + AssertEvent(); + + [Fact] + public void ParseReadAudio() => + AssertEvent(); + + [Fact] + public void ParseSetRumble() => + AssertEvent(); + + [Fact] + public void ParseEntryUnk2A() => + AssertEvent(); + + [Fact] + public void ParseSeqPlayAudio() => + AssertEvent(); + + [Fact] + public void ParseSeqPlayAnimation() => + AssertEvent(); + + [Fact] + public void ParseSeqDialog() => + AssertEvent(); + + [Fact] + public void ParseSeqPlayBgm() => + AssertEvent(); + + [Fact] + public void ParseReadBgm() => + AssertEvent(); + + [Fact] + public void ParseSetBgm() => + AssertEvent(); + + [Fact] + public void ParseEntryUnk36() => + AssertEvent(); + + [Fact] + public void ParseReadActor() => + AssertEvent(); + + [Fact] + public void ParseReadEffect() => + AssertEvent(); + + [Fact] + public void ParseSeqLayout() => + AssertEvent(); + + [Fact] + public void ParseReadLayout() => + AssertEvent(); + + [Fact] + public void ParseStopEffect() => + AssertEvent(); + + [Fact] + public void ParseRunMovie() => + AssertEvent(); + + [Fact] + public void ParseUnk42() => + AssertEvent(); + + [Fact] + public void ParseEntryUnk47() => + AssertEvent(); + + [Fact] + public void ParseHideObject() => + AssertEvent(); + + private static void AssertEvent() + where T : class, Event.IEventEntry => + AssertEvent(Helpers.CreateDummyObject()); + + private static void AssertEvent(T expected) + where T : class, Event.IEventEntry + { + using var stream = new MemoryStream(); + Event.Write(stream, new Event.IEventEntry[] + { + expected + }); + var actualLength = stream.Position - 2; + if ((actualLength % 2) == 1) + throw new AssertActualExpectedException( + actualLength + 1, actualLength, + "Offset is not aligned by 2"); + + stream.Position = 0; + var eventSet = Event.Read(stream); + var expectedLength = stream.Position; + + Assert.Single(eventSet); + Assert.IsType(eventSet[0]); + if (expectedLength != actualLength) + throw new AssertActualExpectedException( + expectedLength, actualLength, + "Stream length does not match"); + + var actual = eventSet[0]; + foreach (var property in typeof(T).GetProperties()) + { + var expectedValue = property.GetValue(expected); + var actualValue = property.GetValue(actual); + if (expectedValue.ToString() != + actualValue.ToString()) + throw new AssertActualExpectedException( + expectedValue, actualValue, + $"Different values for '{property.Name}'"); + } + } + } +} diff --git a/OpenKh.Tests/kh2/FontContextTests.cs b/OpenKh.Tests/kh2/FontContextTests.cs index 178e84cf0..2ce050786 100644 --- a/OpenKh.Tests/kh2/FontContextTests.cs +++ b/OpenKh.Tests/kh2/FontContextTests.cs @@ -1,79 +1,79 @@ -using OpenKh.Imaging; -using OpenKh.Kh2; -using OpenKh.Kh2.Contextes; -using System; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class FontContextTests - { - [Fact] - public void LoadEnglishSystemFontTest() - { - LoadFontTest(512, 256, 4, "sys", x => x.ImageSystem); - LoadFontTest(512, 256, 4, "sys", x => x.ImageSystem2); - } - - [Fact] - public void LoadJapaneseSystemFontTest() - { - LoadFontTest(512, 512, 4, "sys", x => x.ImageSystem); - LoadFontTest(512, 512, 4, "sys", x => x.ImageSystem2); - } - - [Fact] - public void LoadEnglishEventFontTest() - { - LoadFontTest(512, 512, 4, "evt", x => x.ImageEvent); - LoadFontTest(512, 512, 4, "evt", x => x.ImageEvent2); - } - - [Fact] - public void LoadJapaneseEventFontTest() - { - LoadFontTest(512, 1024, 4, "evt", x => x.ImageEvent); - LoadFontTest(512, 1024, 4, "evt", x => x.ImageEvent2); - } - - [Fact] - public void LoadIconFontTest() => - LoadFontTest(256, 160, 8, "icon", x => x.ImageIcon); - - private static void LoadFontTest( - int expectedWidth, - int expectedHeight, - int bitsPerPixel, - string name, - Func getter) - { - var expectedLength = expectedWidth * expectedHeight * bitsPerPixel / 8; - - var fontContext = new FontContext(); - var entry = new Bar.Entry - { - Name = name, - Type = Bar.EntryType.RawBitmap, - Stream = CreateStream(expectedLength) - }; - - fontContext.Read(new Bar.Entry[] { entry }); - - var image = getter(fontContext); - Assert.NotNull(image); - Assert.Equal(expectedWidth, image.Size.Width); - Assert.Equal(expectedHeight, image.Size.Height); - Assert.Equal(expectedLength, entry.Stream.Position); - } - - private static Stream CreateStream(int length) - { - var stream = new MemoryStream(length); - stream.Write(new byte[length]); - stream.Position = 0; - - return stream; - } - } -} +using OpenKh.Imaging; +using OpenKh.Kh2; +using OpenKh.Kh2.Contextes; +using System; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class FontContextTests + { + [Fact] + public void LoadEnglishSystemFontTest() + { + LoadFontTest(512, 256, 4, "sys", x => x.ImageSystem); + LoadFontTest(512, 256, 4, "sys", x => x.ImageSystem2); + } + + [Fact] + public void LoadJapaneseSystemFontTest() + { + LoadFontTest(512, 512, 4, "sys", x => x.ImageSystem); + LoadFontTest(512, 512, 4, "sys", x => x.ImageSystem2); + } + + [Fact] + public void LoadEnglishEventFontTest() + { + LoadFontTest(512, 512, 4, "evt", x => x.ImageEvent); + LoadFontTest(512, 512, 4, "evt", x => x.ImageEvent2); + } + + [Fact] + public void LoadJapaneseEventFontTest() + { + LoadFontTest(512, 1024, 4, "evt", x => x.ImageEvent); + LoadFontTest(512, 1024, 4, "evt", x => x.ImageEvent2); + } + + [Fact] + public void LoadIconFontTest() => + LoadFontTest(256, 160, 8, "icon", x => x.ImageIcon); + + private static void LoadFontTest( + int expectedWidth, + int expectedHeight, + int bitsPerPixel, + string name, + Func getter) + { + var expectedLength = expectedWidth * expectedHeight * bitsPerPixel / 8; + + var fontContext = new FontContext(); + var entry = new Bar.Entry + { + Name = name, + Type = Bar.EntryType.RawBitmap, + Stream = CreateStream(expectedLength) + }; + + fontContext.Read(new Bar.Entry[] { entry }); + + var image = getter(fontContext); + Assert.NotNull(image); + Assert.Equal(expectedWidth, image.Size.Width); + Assert.Equal(expectedHeight, image.Size.Height); + Assert.Equal(expectedLength, entry.Stream.Position); + } + + private static Stream CreateStream(int length) + { + var stream = new MemoryStream(length); + stream.Write(new byte[length]); + stream.Position = 0; + + return stream; + } + } +} diff --git a/OpenKh.Tests/kh2/IdxTests.cs b/OpenKh.Tests/kh2/IdxTests.cs index dbde07b37..ef9b48def 100644 --- a/OpenKh.Tests/kh2/IdxTests.cs +++ b/OpenKh.Tests/kh2/IdxTests.cs @@ -1,107 +1,107 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class IdxTests - { - [Theory] - [InlineData("test", 0x338BCFAC)] - [InlineData("hello world!", 0xFD8495B7)] - [InlineData("00battle.bin", 0x2029C445)] - public void CalculateHash32(string text, uint hash) - { - Assert.Equal(hash, Idx.GetHash32(text)); - } - - [Theory] - [InlineData("test", 0xB82F)] - [InlineData("hello world!", 0x0907)] - public void CalculateHash16(string text, ushort hash) - { - Assert.Equal(hash, Idx.GetHash16(text)); - } - - [Fact] - public void ReadIdxEntry() - { - var entry = MockIdxEntry(1, 2, 3, 4, 5); - Assert.Equal(1U, entry.Hash32); - Assert.Equal(2, entry.Hash16); - Assert.Equal(3, entry.BlockLength); - Assert.Equal(4U, entry.Offset); - Assert.Equal(5, entry.Length); - } - - [Fact] - public void WriteIdxEntry() => Helpers.AssertStream(CreateMockIdxStream(1, 2, 3, 4, 5), stream => - { - var outStream = new MemoryStream(); - Idx.Write(outStream, Idx.Read(stream)); - - return outStream; - }); - - [Theory] - [InlineData(0x3fff, false, false)] - [InlineData(0x4000, true, false)] - [InlineData(0x8000, false, true)] - [InlineData(0xc000, true, true)] - public void ReadBlockDescriptionFlags(ushort blockDescriptor, bool expectedIsCompressed, bool expectedIsStreamed) - { - var entry = MockIdxEntry(0, 0, blockDescriptor, 0, 0); - Assert.Equal(expectedIsCompressed, entry.IsCompressed); - Assert.Equal(expectedIsStreamed, entry.IsStreamed); - } - - /// - /// This test addresses a rare bug regarding the file obj/B_LK120_RAW.mset, - /// where its block size is stored as 0x710 rather than 0x1710. - /// It is the only known file that have this behaviour. - /// - [Theory] - [InlineData(0x4710, 0x13EFFF0, 0x1710)] // the scenario on any KH2.IDX - [InlineData(0x0710, 0x13EFFF0, 0x0710)] // do not break other stuff - [InlineData(0x4710, 0xFFFFFF, 0x0710)] // do not break other stuff - [InlineData(0x5710, 0x13EFFF0, 0x1710)] // do not break it if it is fixed - public void IdxBlockSizeBugTest(ushort blockDescriptor, int uncompressedLength, int expectedBlockCount) - { - var entry = MockIdxEntry(0, 0, blockDescriptor, 0, uncompressedLength); - Assert.Equal(expectedBlockCount, (int)entry.BlockLength); - } - - [Theory] - [InlineData(0x2029C445, 0x176F, "00battle.bin")] - [InlineData(0x10303F6F, 0xF325, "obj/B_LK120_RAW.mset")] - [InlineData(0x01234567, 0xcdef, null)] - public void GiveRealNames(uint hash32, ushort hash16, string name) - { - Assert.Equal(name, IdxName.Lookup(hash32, hash16)); - } - - private static Stream CreateMockIdxStream(uint hash32, ushort hash16, ushort blockDescriptor, int offset, int length) - { - const int IdxFileCount = 1; - - var stream = new MemoryStream(0x14); - stream.Write(IdxFileCount); - stream.Write(hash32); - stream.Write(hash16); - stream.Write(blockDescriptor); - stream.Write(offset); - stream.Write(length); - - return stream.SetPosition(0); - } - - private static List MockIdx(uint hash32, ushort hash16, ushort blockDescriptor, int offset, int length) => - CreateMockIdxStream(hash32, hash16, blockDescriptor, offset, length).Using(Idx.Read); - - private static Idx.Entry MockIdxEntry(uint hash32, ushort hash16, ushort blockDescriptor, int offset, int length) => - MockIdx(hash32, hash16, blockDescriptor, offset, length).First(); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class IdxTests + { + [Theory] + [InlineData("test", 0x338BCFAC)] + [InlineData("hello world!", 0xFD8495B7)] + [InlineData("00battle.bin", 0x2029C445)] + public void CalculateHash32(string text, uint hash) + { + Assert.Equal(hash, Idx.GetHash32(text)); + } + + [Theory] + [InlineData("test", 0xB82F)] + [InlineData("hello world!", 0x0907)] + public void CalculateHash16(string text, ushort hash) + { + Assert.Equal(hash, Idx.GetHash16(text)); + } + + [Fact] + public void ReadIdxEntry() + { + var entry = MockIdxEntry(1, 2, 3, 4, 5); + Assert.Equal(1U, entry.Hash32); + Assert.Equal(2, entry.Hash16); + Assert.Equal(3, entry.BlockLength); + Assert.Equal(4U, entry.Offset); + Assert.Equal(5, entry.Length); + } + + [Fact] + public void WriteIdxEntry() => Helpers.AssertStream(CreateMockIdxStream(1, 2, 3, 4, 5), stream => + { + var outStream = new MemoryStream(); + Idx.Write(outStream, Idx.Read(stream)); + + return outStream; + }); + + [Theory] + [InlineData(0x3fff, false, false)] + [InlineData(0x4000, true, false)] + [InlineData(0x8000, false, true)] + [InlineData(0xc000, true, true)] + public void ReadBlockDescriptionFlags(ushort blockDescriptor, bool expectedIsCompressed, bool expectedIsStreamed) + { + var entry = MockIdxEntry(0, 0, blockDescriptor, 0, 0); + Assert.Equal(expectedIsCompressed, entry.IsCompressed); + Assert.Equal(expectedIsStreamed, entry.IsStreamed); + } + + /// + /// This test addresses a rare bug regarding the file obj/B_LK120_RAW.mset, + /// where its block size is stored as 0x710 rather than 0x1710. + /// It is the only known file that have this behaviour. + /// + [Theory] + [InlineData(0x4710, 0x13EFFF0, 0x1710)] // the scenario on any KH2.IDX + [InlineData(0x0710, 0x13EFFF0, 0x0710)] // do not break other stuff + [InlineData(0x4710, 0xFFFFFF, 0x0710)] // do not break other stuff + [InlineData(0x5710, 0x13EFFF0, 0x1710)] // do not break it if it is fixed + public void IdxBlockSizeBugTest(ushort blockDescriptor, int uncompressedLength, int expectedBlockCount) + { + var entry = MockIdxEntry(0, 0, blockDescriptor, 0, uncompressedLength); + Assert.Equal(expectedBlockCount, (int)entry.BlockLength); + } + + [Theory] + [InlineData(0x2029C445, 0x176F, "00battle.bin")] + [InlineData(0x10303F6F, 0xF325, "obj/B_LK120_RAW.mset")] + [InlineData(0x01234567, 0xcdef, null)] + public void GiveRealNames(uint hash32, ushort hash16, string name) + { + Assert.Equal(name, IdxName.Lookup(hash32, hash16)); + } + + private static Stream CreateMockIdxStream(uint hash32, ushort hash16, ushort blockDescriptor, int offset, int length) + { + const int IdxFileCount = 1; + + var stream = new MemoryStream(0x14); + stream.Write(IdxFileCount); + stream.Write(hash32); + stream.Write(hash16); + stream.Write(blockDescriptor); + stream.Write(offset); + stream.Write(length); + + return stream.SetPosition(0); + } + + private static List MockIdx(uint hash32, ushort hash16, ushort blockDescriptor, int offset, int length) => + CreateMockIdxStream(hash32, hash16, blockDescriptor, offset, length).Using(Idx.Read); + + private static Idx.Entry MockIdxEntry(uint hash32, ushort hash16, ushort blockDescriptor, int offset, int length) => + MockIdx(hash32, hash16, blockDescriptor, offset, length).First(); + } +} diff --git a/OpenKh.Tests/kh2/ImageReadExtensionsTests.cs b/OpenKh.Tests/kh2/ImageReadExtensionsTests.cs index 33251cdd6..fec9280d4 100644 --- a/OpenKh.Tests/kh2/ImageReadExtensionsTests.cs +++ b/OpenKh.Tests/kh2/ImageReadExtensionsTests.cs @@ -1,4 +1,4 @@ -using OpenKh.Common; +using OpenKh.Common; using OpenKh.Imaging; using OpenKh.Kh2; using OpenKh.Kh2.Extensions; diff --git a/OpenKh.Tests/kh2/ImgTests.cs b/OpenKh.Tests/kh2/ImgTests.cs index 0053c0494..c7aa6546a 100644 --- a/OpenKh.Tests/kh2/ImgTests.cs +++ b/OpenKh.Tests/kh2/ImgTests.cs @@ -1,136 +1,136 @@ -using OpenKh.Common; -using OpenKh.Imaging; -using OpenKh.Kh2; -using OpenKh.Tests.Imaging; -using System.IO; -using System.Linq; -using Xunit; -using Xunit.Abstractions; -using Xunit.Sdk; - -namespace OpenKh.Tests.kh2 -{ - public class ImgTests - { - private readonly ITestOutputHelper output; - - public ImgTests(ITestOutputHelper output) - { - this.output = output; - } - - [Theory] - [InlineData("50worldmap")] - [InlineData("sample2")] - public void TestDecompression(string fileName) - { - using (var fileCompressed = File.OpenRead($"kh2/res/{fileName}.cmp")) - { - using (var fileExpected = File.OpenRead($"kh2/res/{fileName}.dec")) - { - var decompressedStream = Img.Decompress(fileCompressed); - - int matched = 0; - for (int i = 0; i < decompressedStream.Length; i++) - { - int expected = fileExpected.ReadByte(); - int actual = decompressedStream[i]; - if (expected == actual) - matched++; - } - - Assert.Equal(fileExpected.Length, matched); - } - } - } - - [Theory] - [InlineData("50worldmap")] - [InlineData("sample2")] - public void CompressCorrectly(string fileName) => - File.OpenRead($"kh2/res/{fileName}.dec").Using(stream => - { - Helpers.AssertStream(stream, inStream => - new MemoryStream(Img.Decompress(Img.Compress(inStream.ReadAllBytes())))); - }); - - [Theory] - [InlineData("50worldmap", 0x16d)] - [InlineData("sample2", 0x4ac)] - public void CompressEquallyOrBetter(string fileName, int expectLength) => - File.OpenRead($"kh2/res/{fileName}.dec").Using(stream => - { - var compress = Img.Compress(stream.ReadAllBytes()); - if (compress.Length > expectLength) - { - throw new XunitException($"Compressed file is {compress.Length} byte, but the official one is {expectLength}.\n" + - "The compression algorithm is not performant enough."); - } - }); - - [Fact] - public void CompressCorrectlyWhenKeyIsFoundInTheData() => - new MemoryStream(Enumerable.Range(0, 0x100).Select(x => (byte)x).ToArray()).Using(stream => - { - Helpers.AssertStream(stream, inStream => - new MemoryStream(Img.Decompress(Img.Compress(inStream.ReadAllBytes())))); - }); - - [Fact] - public void CreateEmptyFileIfCompressedSourceIsEmpty() - { - var input = Enumerable.Range(0, 0x1000).Select(_ => (byte)0).ToArray(); - Assert.Empty(Img.Decompress(input)); - } - - [Fact] - public void CreateAndRead4bppSuccessfully() - { - var imgd = Imgd.Create( - new System.Drawing.Size(ImageDecodeTests.Width, ImageDecodeTests.Height), - PixelFormat.Indexed4, - ImageDecodeTests.Data4bpp, ImageDecodeTests.Clut4bpp, false); - - Assert.Equal(ImageDecodeTests.ExpectedFrom4bpp, imgd.ToBgra32()); - - using var stream = new MemoryStream(); - imgd.Write(stream); - imgd = Imgd.Read(stream.SetPosition(0)); - - Assert.Equal(ImageDecodeTests.ExpectedFrom4bpp, imgd.ToBgra32()); - } - - public void AlwaysCompressCorrectly() - { - using var imgStream = File.OpenRead("G:\\KH2.IMG"); - new Img(imgStream, File.OpenRead("G:\\KH2.IDX").Using(Idx.Read), true) - .Entries.ToList() - .Where(x => x.IsCompressed) - .Where(x => !x.IsStreamed) - .Select(x => new - { - Name = IdxName.Lookup(x), - Entry = x, - Data = imgStream - .SetPosition(x.Offset * 0x800) - .ReadBytes((x.BlockLength + 1) * 0x800) - }) - .ToList() - .AsParallel() - .WithDegreeOfParallelism(16) - .ForAll(x => - { - new MemoryStream(Img.Decompress(x.Data)).Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var compressedData = Img.Compress(inStream.ReadAllBytes()); - var decompressedData = Img.Decompress(compressedData); - - return new MemoryStream(decompressedData); - }); - }); - }); - } - } -} +using OpenKh.Common; +using OpenKh.Imaging; +using OpenKh.Kh2; +using OpenKh.Tests.Imaging; +using System.IO; +using System.Linq; +using Xunit; +using Xunit.Abstractions; +using Xunit.Sdk; + +namespace OpenKh.Tests.kh2 +{ + public class ImgTests + { + private readonly ITestOutputHelper output; + + public ImgTests(ITestOutputHelper output) + { + this.output = output; + } + + [Theory] + [InlineData("50worldmap")] + [InlineData("sample2")] + public void TestDecompression(string fileName) + { + using (var fileCompressed = File.OpenRead($"kh2/res/{fileName}.cmp")) + { + using (var fileExpected = File.OpenRead($"kh2/res/{fileName}.dec")) + { + var decompressedStream = Img.Decompress(fileCompressed); + + int matched = 0; + for (int i = 0; i < decompressedStream.Length; i++) + { + int expected = fileExpected.ReadByte(); + int actual = decompressedStream[i]; + if (expected == actual) + matched++; + } + + Assert.Equal(fileExpected.Length, matched); + } + } + } + + [Theory] + [InlineData("50worldmap")] + [InlineData("sample2")] + public void CompressCorrectly(string fileName) => + File.OpenRead($"kh2/res/{fileName}.dec").Using(stream => + { + Helpers.AssertStream(stream, inStream => + new MemoryStream(Img.Decompress(Img.Compress(inStream.ReadAllBytes())))); + }); + + [Theory] + [InlineData("50worldmap", 0x16d)] + [InlineData("sample2", 0x4ac)] + public void CompressEquallyOrBetter(string fileName, int expectLength) => + File.OpenRead($"kh2/res/{fileName}.dec").Using(stream => + { + var compress = Img.Compress(stream.ReadAllBytes()); + if (compress.Length > expectLength) + { + throw new XunitException($"Compressed file is {compress.Length} byte, but the official one is {expectLength}.\n" + + "The compression algorithm is not performant enough."); + } + }); + + [Fact] + public void CompressCorrectlyWhenKeyIsFoundInTheData() => + new MemoryStream(Enumerable.Range(0, 0x100).Select(x => (byte)x).ToArray()).Using(stream => + { + Helpers.AssertStream(stream, inStream => + new MemoryStream(Img.Decompress(Img.Compress(inStream.ReadAllBytes())))); + }); + + [Fact] + public void CreateEmptyFileIfCompressedSourceIsEmpty() + { + var input = Enumerable.Range(0, 0x1000).Select(_ => (byte)0).ToArray(); + Assert.Empty(Img.Decompress(input)); + } + + [Fact] + public void CreateAndRead4bppSuccessfully() + { + var imgd = Imgd.Create( + new System.Drawing.Size(ImageDecodeTests.Width, ImageDecodeTests.Height), + PixelFormat.Indexed4, + ImageDecodeTests.Data4bpp, ImageDecodeTests.Clut4bpp, false); + + Assert.Equal(ImageDecodeTests.ExpectedFrom4bpp, imgd.ToBgra32()); + + using var stream = new MemoryStream(); + imgd.Write(stream); + imgd = Imgd.Read(stream.SetPosition(0)); + + Assert.Equal(ImageDecodeTests.ExpectedFrom4bpp, imgd.ToBgra32()); + } + + public void AlwaysCompressCorrectly() + { + using var imgStream = File.OpenRead("G:\\KH2.IMG"); + new Img(imgStream, File.OpenRead("G:\\KH2.IDX").Using(Idx.Read), true) + .Entries.ToList() + .Where(x => x.IsCompressed) + .Where(x => !x.IsStreamed) + .Select(x => new + { + Name = IdxName.Lookup(x), + Entry = x, + Data = imgStream + .SetPosition(x.Offset * 0x800) + .ReadBytes((x.BlockLength + 1) * 0x800) + }) + .ToList() + .AsParallel() + .WithDegreeOfParallelism(16) + .ForAll(x => + { + new MemoryStream(Img.Decompress(x.Data)).Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var compressedData = Img.Compress(inStream.ReadAllBytes()); + var decompressedData = Img.Decompress(compressedData); + + return new MemoryStream(decompressedData); + }); + }); + }); + } + } +} diff --git a/OpenKh.Tests/kh2/ImgdTests.cs b/OpenKh.Tests/kh2/ImgdTests.cs index d58312e6d..d5851514d 100644 --- a/OpenKh.Tests/kh2/ImgdTests.cs +++ b/OpenKh.Tests/kh2/ImgdTests.cs @@ -1,241 +1,241 @@ -using OpenKh.Common; -using OpenKh.Imaging; -using OpenKh.Kh2; -using System; -using System.Drawing; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class ImgdTests - { - private const string FilePath = "kh2/res/image-8bit-128-128.imd"; - private const string FacFilePath = "kh2/res/image.fac"; - - [Fact] - public void IsValidTest() - { - using (var stream = new MemoryStream()) - { - stream.WriteByte(0x49); - stream.WriteByte(0x4d); - stream.WriteByte(0x47); - stream.WriteByte(0x44); - stream.SetLength(0x40); - stream.Position = 0; - Assert.True(Imgd.IsValid(stream)); - } - } - - [Fact] - public void ReadHeaderTest() => File.OpenRead(FilePath).Using(stream => - { - var image = Imgd.Read(stream); - Assert.Equal(128, image.Size.Width); - Assert.Equal(128, image.Size.Height); - Assert.Equal(PixelFormat.Indexed8, image.PixelFormat); - }); - - [Theory] - [InlineData("4bit-128-128")] - [InlineData("4bit-256-128")] - [InlineData("4bit-256-512")] - [InlineData("4bit-512-128")] - [InlineData("4bit-512-512")] - [InlineData("8bit-128-128")] - [InlineData("8bit-128-64")] - [InlineData("8bit-256-128")] - [InlineData("8bit-256-256")] - [InlineData("8bit-32-32")] - [InlineData("8bit-48-48")] - [InlineData("8bit-512-256")] - [InlineData("8bit-512-512")] - [InlineData("8bit-64-64")] - [InlineData("32bit-512-512")] - public void IsWritingBackCorrectly(string baseName) => - File.OpenRead($"kh2/res/image-{baseName}.imd").Using(stream => - { - var expectedData = new byte[stream.Length]; - stream.Read(expectedData, 0, expectedData.Length); - - var image = Imgd.Read(new MemoryStream(expectedData)); - using (var dstStream = new MemoryStream(expectedData.Length)) - { - image.Write(dstStream); - dstStream.Position = 0; - var actualData = new byte[dstStream.Length]; - dstStream.Read(actualData, 0, actualData.Length); - - Assert.Equal(expectedData.Length, actualData.Length); - Assert.Equal(expectedData, actualData); - } - }); - - [Theory] - [InlineData("4bit-128-128")] - [InlineData("4bit-256-128")] - [InlineData("4bit-256-512")] - [InlineData("4bit-512-128")] - [InlineData("4bit-512-512")] - [InlineData("8bit-128-128")] - [InlineData("8bit-128-64")] - [InlineData("8bit-256-128")] - [InlineData("8bit-256-256")] - [InlineData("8bit-32-32")] - [InlineData("8bit-48-48")] - [InlineData("8bit-512-256")] - [InlineData("8bit-512-512")] - [InlineData("8bit-64-64")] - public void IsCreatingCorrectlyTest(string baseName) => - File.OpenRead($"kh2/res/image-{baseName}.imd").Using(stream => - { - var expectedData = new byte[stream.Length]; - stream.Read(expectedData, 0, expectedData.Length); - - var image = Imgd.Read(new MemoryStream(expectedData)); - using (var dstStream = new MemoryStream(expectedData.Length)) - { - var newImage = Imgd.Create( - image.Size, - image.PixelFormat, - image.GetData(), - image.GetClut(), - image.IsSwizzled); - - Assert.Equal(image.GetClut(), newImage.GetClut()); - Assert.Equal(image.GetData(), newImage.GetData()); - - newImage.Write(dstStream); - dstStream.Position = 0; - var actualData = new byte[dstStream.Length]; - dstStream.Read(actualData, 0, actualData.Length); - - Assert.Equal(expectedData.Length, actualData.Length); - Assert.Equal(expectedData, actualData); - } - }); - - [Theory] - [InlineData(FilePath, false)] - [InlineData(FacFilePath, true)] - public void IsFac(string fileName, bool expected) => - Assert.Equal(expected, File.OpenRead(fileName).Using(stream => Imgd.IsFac(stream))); - - [Fact] - public void ReadAndWriteFac() => - File.OpenRead(FacFilePath) - .Using(x => Helpers.AssertStream(x, inStream => - { - var images = Imgd.ReadAsFac(inStream).ToList(); - Assert.Equal(3, images.Count); - - var outStream = new MemoryStream(); - Imgd.WriteAsFac(outStream, images); - - return outStream; - })); - - void CreateImgdAndComparePixelData( - byte[] pixelData, - Func imgdFactory - ) - { - var imgd = imgdFactory(pixelData); - - var temp = new MemoryStream(); - - imgd.Write(temp); - - temp.Position = 0; - - var loaded = Imgd.Read(temp); - - Assert.Equal( - pixelData, - loaded.GetData() - ); - } - - [Fact] - public void TestPixelOrder4() => CreateImgdAndComparePixelData( - new byte[] { 0x12, 0x34, }, - pixelData => Imgd.Create( - new System.Drawing.Size(2, 2), - PixelFormat.Indexed4, - pixelData, - new byte[4 * 16], - false - ) - ); - - [Fact] - public void TestPixelOrder4Swizzled() => CreateImgdAndComparePixelData( - new byte[] { 0x12, 0x34, } - .Concat(new byte[128 * 128 / 2 - 2]) - .ToArray(), - pixelData => Imgd.Create( - new System.Drawing.Size(128, 128), - PixelFormat.Indexed4, - pixelData, - new byte[4 * 16], - true - ) - ); - - [Fact] - public void TestPixelOrder8() => CreateImgdAndComparePixelData( - new byte[] { 0x12, 0x34, 0x56, 0x78, }, - pixelData => Imgd.Create( - new System.Drawing.Size(2, 2), - PixelFormat.Indexed8, - pixelData, - new byte[4 * 256], - false - ) - ); - - [Fact] - public void TestPixelOrder8Swizzled() => CreateImgdAndComparePixelData( - new byte[] { 0x12, 0x34, 0x56, 0x78, } - .Concat(new byte[128 * 64 - 4]) - .ToArray(), - pixelData => Imgd.Create( - new System.Drawing.Size(128, 64), - PixelFormat.Indexed8, - pixelData, - new byte[4 * 256], - true - ) - ); - - [Fact] - public void ReadRgba8888PixelOrder() - { - var imgd = File.OpenRead($"kh2/res/2x2x32.imd").Using(Imgd.Read); - Assert.Equal(new Size(2, 2), imgd.Size); - Assert.Equal(PixelFormat.Rgba8888, imgd.PixelFormat); - Assert.Equal( - new byte[] { - // GetData(): B, G, R, A - 0xFF, 0x7F, 0x27, 0xFF, - 0x22, 0xB1, 0x4C, 0xFF, - 0x00, 0xA2, 0xE8, 0xFF, - 0xFF, 0xF2, 0x00, 0xFF, - }, - imgd.GetData() - ); - Assert.Equal( - new byte[] { - // Data: R, G, B, A - 0x27, 0x7F, 0xFF, 0xFF, - 0x4C, 0xB1, 0x22, 0xFF, - 0xE8, 0xA2, 0x00, 0xFF, - 0x00, 0xF2, 0xFF, 0xFF, - }, - imgd.Data - ); - } - } -} +using OpenKh.Common; +using OpenKh.Imaging; +using OpenKh.Kh2; +using System; +using System.Drawing; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class ImgdTests + { + private const string FilePath = "kh2/res/image-8bit-128-128.imd"; + private const string FacFilePath = "kh2/res/image.fac"; + + [Fact] + public void IsValidTest() + { + using (var stream = new MemoryStream()) + { + stream.WriteByte(0x49); + stream.WriteByte(0x4d); + stream.WriteByte(0x47); + stream.WriteByte(0x44); + stream.SetLength(0x40); + stream.Position = 0; + Assert.True(Imgd.IsValid(stream)); + } + } + + [Fact] + public void ReadHeaderTest() => File.OpenRead(FilePath).Using(stream => + { + var image = Imgd.Read(stream); + Assert.Equal(128, image.Size.Width); + Assert.Equal(128, image.Size.Height); + Assert.Equal(PixelFormat.Indexed8, image.PixelFormat); + }); + + [Theory] + [InlineData("4bit-128-128")] + [InlineData("4bit-256-128")] + [InlineData("4bit-256-512")] + [InlineData("4bit-512-128")] + [InlineData("4bit-512-512")] + [InlineData("8bit-128-128")] + [InlineData("8bit-128-64")] + [InlineData("8bit-256-128")] + [InlineData("8bit-256-256")] + [InlineData("8bit-32-32")] + [InlineData("8bit-48-48")] + [InlineData("8bit-512-256")] + [InlineData("8bit-512-512")] + [InlineData("8bit-64-64")] + [InlineData("32bit-512-512")] + public void IsWritingBackCorrectly(string baseName) => + File.OpenRead($"kh2/res/image-{baseName}.imd").Using(stream => + { + var expectedData = new byte[stream.Length]; + stream.Read(expectedData, 0, expectedData.Length); + + var image = Imgd.Read(new MemoryStream(expectedData)); + using (var dstStream = new MemoryStream(expectedData.Length)) + { + image.Write(dstStream); + dstStream.Position = 0; + var actualData = new byte[dstStream.Length]; + dstStream.Read(actualData, 0, actualData.Length); + + Assert.Equal(expectedData.Length, actualData.Length); + Assert.Equal(expectedData, actualData); + } + }); + + [Theory] + [InlineData("4bit-128-128")] + [InlineData("4bit-256-128")] + [InlineData("4bit-256-512")] + [InlineData("4bit-512-128")] + [InlineData("4bit-512-512")] + [InlineData("8bit-128-128")] + [InlineData("8bit-128-64")] + [InlineData("8bit-256-128")] + [InlineData("8bit-256-256")] + [InlineData("8bit-32-32")] + [InlineData("8bit-48-48")] + [InlineData("8bit-512-256")] + [InlineData("8bit-512-512")] + [InlineData("8bit-64-64")] + public void IsCreatingCorrectlyTest(string baseName) => + File.OpenRead($"kh2/res/image-{baseName}.imd").Using(stream => + { + var expectedData = new byte[stream.Length]; + stream.Read(expectedData, 0, expectedData.Length); + + var image = Imgd.Read(new MemoryStream(expectedData)); + using (var dstStream = new MemoryStream(expectedData.Length)) + { + var newImage = Imgd.Create( + image.Size, + image.PixelFormat, + image.GetData(), + image.GetClut(), + image.IsSwizzled); + + Assert.Equal(image.GetClut(), newImage.GetClut()); + Assert.Equal(image.GetData(), newImage.GetData()); + + newImage.Write(dstStream); + dstStream.Position = 0; + var actualData = new byte[dstStream.Length]; + dstStream.Read(actualData, 0, actualData.Length); + + Assert.Equal(expectedData.Length, actualData.Length); + Assert.Equal(expectedData, actualData); + } + }); + + [Theory] + [InlineData(FilePath, false)] + [InlineData(FacFilePath, true)] + public void IsFac(string fileName, bool expected) => + Assert.Equal(expected, File.OpenRead(fileName).Using(stream => Imgd.IsFac(stream))); + + [Fact] + public void ReadAndWriteFac() => + File.OpenRead(FacFilePath) + .Using(x => Helpers.AssertStream(x, inStream => + { + var images = Imgd.ReadAsFac(inStream).ToList(); + Assert.Equal(3, images.Count); + + var outStream = new MemoryStream(); + Imgd.WriteAsFac(outStream, images); + + return outStream; + })); + + void CreateImgdAndComparePixelData( + byte[] pixelData, + Func imgdFactory + ) + { + var imgd = imgdFactory(pixelData); + + var temp = new MemoryStream(); + + imgd.Write(temp); + + temp.Position = 0; + + var loaded = Imgd.Read(temp); + + Assert.Equal( + pixelData, + loaded.GetData() + ); + } + + [Fact] + public void TestPixelOrder4() => CreateImgdAndComparePixelData( + new byte[] { 0x12, 0x34, }, + pixelData => Imgd.Create( + new System.Drawing.Size(2, 2), + PixelFormat.Indexed4, + pixelData, + new byte[4 * 16], + false + ) + ); + + [Fact] + public void TestPixelOrder4Swizzled() => CreateImgdAndComparePixelData( + new byte[] { 0x12, 0x34, } + .Concat(new byte[128 * 128 / 2 - 2]) + .ToArray(), + pixelData => Imgd.Create( + new System.Drawing.Size(128, 128), + PixelFormat.Indexed4, + pixelData, + new byte[4 * 16], + true + ) + ); + + [Fact] + public void TestPixelOrder8() => CreateImgdAndComparePixelData( + new byte[] { 0x12, 0x34, 0x56, 0x78, }, + pixelData => Imgd.Create( + new System.Drawing.Size(2, 2), + PixelFormat.Indexed8, + pixelData, + new byte[4 * 256], + false + ) + ); + + [Fact] + public void TestPixelOrder8Swizzled() => CreateImgdAndComparePixelData( + new byte[] { 0x12, 0x34, 0x56, 0x78, } + .Concat(new byte[128 * 64 - 4]) + .ToArray(), + pixelData => Imgd.Create( + new System.Drawing.Size(128, 64), + PixelFormat.Indexed8, + pixelData, + new byte[4 * 256], + true + ) + ); + + [Fact] + public void ReadRgba8888PixelOrder() + { + var imgd = File.OpenRead($"kh2/res/2x2x32.imd").Using(Imgd.Read); + Assert.Equal(new Size(2, 2), imgd.Size); + Assert.Equal(PixelFormat.Rgba8888, imgd.PixelFormat); + Assert.Equal( + new byte[] { + // GetData(): B, G, R, A + 0xFF, 0x7F, 0x27, 0xFF, + 0x22, 0xB1, 0x4C, 0xFF, + 0x00, 0xA2, 0xE8, 0xFF, + 0xFF, 0xF2, 0x00, 0xFF, + }, + imgd.GetData() + ); + Assert.Equal( + new byte[] { + // Data: R, G, B, A + 0x27, 0x7F, 0xFF, 0xFF, + 0x4C, 0xB1, 0x22, 0xFF, + 0xE8, 0xA2, 0x00, 0xFF, + 0x00, 0xF2, 0xFF, 0xFF, + }, + imgd.Data + ); + } + } +} diff --git a/OpenKh.Tests/kh2/ImgzTests.cs b/OpenKh.Tests/kh2/ImgzTests.cs index 029a52e11..1da5181b2 100644 --- a/OpenKh.Tests/kh2/ImgzTests.cs +++ b/OpenKh.Tests/kh2/ImgzTests.cs @@ -1,23 +1,23 @@ -using OpenKh.Kh2; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class ImgzTests - { - [Fact] - public void IsValidTest() - { - using (var stream = new MemoryStream()) - { - stream.WriteByte(0x49); - stream.WriteByte(0x4d); - stream.WriteByte(0x47); - stream.WriteByte(0x5a); - stream.Position = 0; - Assert.True(Imgz.IsValid(stream)); - } - } - } -} +using OpenKh.Kh2; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class ImgzTests + { + [Fact] + public void IsValidTest() + { + using (var stream = new MemoryStream()) + { + stream.WriteByte(0x49); + stream.WriteByte(0x4d); + stream.WriteByte(0x47); + stream.WriteByte(0x5a); + stream.Position = 0; + Assert.True(Imgz.IsValid(stream)); + } + } + } +} diff --git a/OpenKh.Tests/kh2/JigsawTests.cs b/OpenKh.Tests/kh2/JigsawTests.cs index 57ae0c7d3..e2b424148 100644 --- a/OpenKh.Tests/kh2/JigsawTests.cs +++ b/OpenKh.Tests/kh2/JigsawTests.cs @@ -1,30 +1,30 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class JigsawTests - { - private const string FileName = "kh2/res/15jigsaw.bin"; - - [Fact] - public void HasRightAmountOfEntries() => File.OpenRead(FileName).Using(stream => - { - Assert.Equal(0x9E, Jigsaw.Read(stream).Count); - }); - - [Fact] - public void WriteBackTheSameFile() => File.OpenRead(FileName).Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Jigsaw.Write(outStream, Jigsaw.Read(inStream)); - - return outStream; - }); - }); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class JigsawTests + { + private const string FileName = "kh2/res/15jigsaw.bin"; + + [Fact] + public void HasRightAmountOfEntries() => File.OpenRead(FileName).Using(stream => + { + Assert.Equal(0x9E, Jigsaw.Read(stream).Count); + }); + + [Fact] + public void WriteBackTheSameFile() => File.OpenRead(FileName).Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Jigsaw.Write(outStream, Jigsaw.Read(inStream)); + + return outStream; + }); + }); + } +} diff --git a/OpenKh.Tests/kh2/JiminyTests.cs b/OpenKh.Tests/kh2/JiminyTests.cs index 707ab808c..96c07f024 100644 --- a/OpenKh.Tests/kh2/JiminyTests.cs +++ b/OpenKh.Tests/kh2/JiminyTests.cs @@ -1,21 +1,21 @@ -using OpenKh.Common; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class JiminyTests - { - public class CharTests - { - [Fact] - public void CheckForLength() => File.OpenRead("kh2/res/char.jimidata").Using(stream => - { - var entries = Kh2.Jiminy.Char.Read(stream); - var grouped = entries.GroupBy(x => x.Unk10).ToList(); - Assert.Equal(0x152, entries.Count); - }); - } - } -} +using OpenKh.Common; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class JiminyTests + { + public class CharTests + { + [Fact] + public void CheckForLength() => File.OpenRead("kh2/res/char.jimidata").Using(stream => + { + var entries = Kh2.Jiminy.Char.Read(stream); + var grouped = entries.GroupBy(x => x.Unk10).ToList(); + Assert.Equal(0x152, entries.Count); + }); + } + } +} diff --git a/OpenKh.Tests/kh2/LayoutTests.cs b/OpenKh.Tests/kh2/LayoutTests.cs index a9a3522e5..fe3a73be3 100644 --- a/OpenKh.Tests/kh2/LayoutTests.cs +++ b/OpenKh.Tests/kh2/LayoutTests.cs @@ -1,96 +1,96 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class LayoutTests - { - private const string FilePath = "kh2/res/eh_l.layd"; - - [Fact] - public void IsValidTest() => new MemoryStream() - .Using(stream => - { - stream.WriteByte(0x4C); - stream.WriteByte(0x41); - stream.WriteByte(0x59); - stream.WriteByte(0x44); - stream.Write(new byte[28]); - stream.Position = 0; - Assert.True(Layout.IsValid(stream)); - Assert.Equal(0, stream.Position); - }); - - [Fact] - public void IsInvalidHeaderTest() => new MemoryStream() - .Using(stream => - { - stream.WriteByte(0x42); - stream.WriteByte(0x41); - stream.WriteByte(0x52); - stream.WriteByte(0x01); - stream.Write(new byte[28]); - stream.Position = 0; - Assert.False(Layout.IsValid(stream)); - Assert.Equal(0, stream.Position); - }); - - [Fact] - public void IsInvalidStreamLengthTest() => new MemoryStream() - .Using(stream => - { - stream.WriteByte(0x4C); - stream.WriteByte(0x41); - stream.WriteByte(0x59); - stream.WriteByte(0x44); - stream.Position = 0; - Assert.False(Layout.IsValid(stream)); - Assert.Equal(0, stream.Position); - }); - - [Fact] - public void ValidateLayoutHeader() => File.OpenRead(FilePath).Using(stream => - { - var layout = Layout.Read(stream); - Assert.Equal(32, layout.SequenceGroups.SelectMany(x => x.Sequences).Count()); - Assert.Equal(32, layout.SequenceGroups.Count); - Assert.Equal(5, layout.SequenceItems.Count); - }); - - [Fact] - public void ValidateL2() => File.OpenRead(FilePath).Using(stream => - { - var layout = Layout.Read(stream); - Assert.Equal(1, layout.SequenceGroups[0].Sequences.Count); - Assert.Equal(0, layout.SequenceGroups[0].Unknown04); - Assert.Equal(0, layout.SequenceGroups[0].Unknown08); - Assert.Equal(0, layout.SequenceGroups[0].Unknown0c); - Assert.Equal(0, layout.SequenceGroups[0].Unknown10); - Assert.Equal(1, layout.SequenceGroups[1].Sequences.Count); - Assert.Equal(0, layout.SequenceGroups[1].Unknown04); - Assert.Equal(0, layout.SequenceGroups[1].Unknown08); - Assert.Equal(0, layout.SequenceGroups[1].Unknown0c); - Assert.Equal(0, layout.SequenceGroups[1].Unknown10); - Assert.Equal(1, layout.SequenceGroups[2].Sequences.Count); - Assert.Equal(0, layout.SequenceGroups[2].Unknown04); - Assert.Equal(0, layout.SequenceGroups[2].Unknown08); - Assert.Equal(0, layout.SequenceGroups[2].Unknown0c); - Assert.Equal(0, layout.SequenceGroups[2].Unknown10); - }); - - [Fact] - public void WriteLayoutTest() => File.OpenRead(FilePath).Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Layout.Read(inStream).Write(outStream); - - return outStream; - }); - }); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class LayoutTests + { + private const string FilePath = "kh2/res/eh_l.layd"; + + [Fact] + public void IsValidTest() => new MemoryStream() + .Using(stream => + { + stream.WriteByte(0x4C); + stream.WriteByte(0x41); + stream.WriteByte(0x59); + stream.WriteByte(0x44); + stream.Write(new byte[28]); + stream.Position = 0; + Assert.True(Layout.IsValid(stream)); + Assert.Equal(0, stream.Position); + }); + + [Fact] + public void IsInvalidHeaderTest() => new MemoryStream() + .Using(stream => + { + stream.WriteByte(0x42); + stream.WriteByte(0x41); + stream.WriteByte(0x52); + stream.WriteByte(0x01); + stream.Write(new byte[28]); + stream.Position = 0; + Assert.False(Layout.IsValid(stream)); + Assert.Equal(0, stream.Position); + }); + + [Fact] + public void IsInvalidStreamLengthTest() => new MemoryStream() + .Using(stream => + { + stream.WriteByte(0x4C); + stream.WriteByte(0x41); + stream.WriteByte(0x59); + stream.WriteByte(0x44); + stream.Position = 0; + Assert.False(Layout.IsValid(stream)); + Assert.Equal(0, stream.Position); + }); + + [Fact] + public void ValidateLayoutHeader() => File.OpenRead(FilePath).Using(stream => + { + var layout = Layout.Read(stream); + Assert.Equal(32, layout.SequenceGroups.SelectMany(x => x.Sequences).Count()); + Assert.Equal(32, layout.SequenceGroups.Count); + Assert.Equal(5, layout.SequenceItems.Count); + }); + + [Fact] + public void ValidateL2() => File.OpenRead(FilePath).Using(stream => + { + var layout = Layout.Read(stream); + Assert.Equal(1, layout.SequenceGroups[0].Sequences.Count); + Assert.Equal(0, layout.SequenceGroups[0].Unknown04); + Assert.Equal(0, layout.SequenceGroups[0].Unknown08); + Assert.Equal(0, layout.SequenceGroups[0].Unknown0c); + Assert.Equal(0, layout.SequenceGroups[0].Unknown10); + Assert.Equal(1, layout.SequenceGroups[1].Sequences.Count); + Assert.Equal(0, layout.SequenceGroups[1].Unknown04); + Assert.Equal(0, layout.SequenceGroups[1].Unknown08); + Assert.Equal(0, layout.SequenceGroups[1].Unknown0c); + Assert.Equal(0, layout.SequenceGroups[1].Unknown10); + Assert.Equal(1, layout.SequenceGroups[2].Sequences.Count); + Assert.Equal(0, layout.SequenceGroups[2].Unknown04); + Assert.Equal(0, layout.SequenceGroups[2].Unknown08); + Assert.Equal(0, layout.SequenceGroups[2].Unknown0c); + Assert.Equal(0, layout.SequenceGroups[2].Unknown10); + }); + + [Fact] + public void WriteLayoutTest() => File.OpenRead(FilePath).Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Layout.Read(inStream).Write(outStream); + + return outStream; + }); + }); + } +} diff --git a/OpenKh.Tests/kh2/MdlxTests.cs b/OpenKh.Tests/kh2/MdlxTests.cs index 86c3fcd19..557612ff3 100644 --- a/OpenKh.Tests/kh2/MdlxTests.cs +++ b/OpenKh.Tests/kh2/MdlxTests.cs @@ -1,141 +1,141 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class MdlxTests - { - private const string FileName = "kh2/res/p_ex.vif"; - private const string MapFileName = "kh2/res/map.vif"; - - [Fact] - public void ShouldReadTheCorrectAmountOfSubModels() => File.OpenRead(FileName).Using(stream => - { - var model = Mdlx.Read(stream).SubModels; - - Assert.Equal(2, model.Count); - }); - - [Fact] - public void ShouldReadVifPackets() => File.OpenRead(FileName).Using(stream => - { - var dmaChain = Mdlx.Read(stream).SubModels[0].DmaChains; - Assert.Equal(26, dmaChain[0].DmaVifs.Count); - Assert.Equal(4, dmaChain.Count); - Assert.Equal(58, dmaChain.Sum(x => x.DmaVifs.Count)); - - var dmaVif = dmaChain[0].DmaVifs[0]; - Assert.Equal(0, dmaVif.TextureIndex); - Assert.Equal(10, dmaVif.Alaxi.Length); - Assert.Equal(53, dmaVif.Alaxi[0]); - Assert.Equal(22, dmaVif.Alaxi[9]); - Assert.Equal(1600, dmaVif.VifPacket.Length); - Assert.Equal(1, dmaVif.VifPacket[0]); - Assert.Equal(248, dmaVif.VifPacket[324]); - }); - - [Fact] - public void ShouldReadBones() => File.OpenRead(FileName).Using(stream => - { - var bones = Mdlx.Read(stream).SubModels[0].Bones; - Assert.Equal(228, bones.Count); - - var bone = bones[0]; - Assert.Equal(0, bone.Index); - Assert.Equal(-1, bone.Parent); - Assert.Equal(0, bone.Unk08); - Assert.Equal(3, bone.Unk0c); - Assert.Equal(1, bone.ScaleX); - Assert.Equal(0, bone.RotationX); - Assert.Equal(0, bone.TranslationX); - Assert.Equal(1, bone.ScaleY); - Assert.Equal(4.71, bone.RotationY, 2); - Assert.Equal(102.62, bone.TranslationY, 2); - Assert.Equal(1, bone.ScaleZ); - Assert.Equal(4.71, bone.RotationZ, 2); - Assert.Equal(0, bone.TranslationZ); - Assert.Equal(0, bone.ScaleW); - Assert.Equal(0, bone.RotationW); - Assert.Equal(0, bone.TranslationW); - }); - - [Fact] - public void ShouldWriteBackTheExactSameFile() => File.OpenRead(FileName).Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var mdlx = Mdlx.Read(inStream); - - var outStream = new MemoryStream(); - mdlx.Write(outStream); - - return outStream; - }); - }); - - [Fact] - public void ReadRemapTable() => File.OpenRead(MapFileName).Using(stream => - { - var remapTable = Mdlx.Read(stream).MapModel.DmaChainIndexRemapTable; - Assert.Equal(97, remapTable.Count); - - Assert.Equal(0, remapTable[0]); - Assert.Equal(1, remapTable[1]); - Assert.Equal(2, remapTable[2]); - Assert.Equal(96, remapTable[96]); - }); - - [Fact] - public void ReadRenderingGroup() => File.OpenRead(MapFileName).Using(stream => - { - var renderingGroup = Mdlx.Read(stream).MapModel.vifPacketRenderingGroup; - Assert.Equal(9, renderingGroup.Count); - - Assert.Equal(20, renderingGroup[0].Length); - Assert.Equal(1, renderingGroup[0][0]); - Assert.Equal(91, renderingGroup[0][19]); - - Assert.Equal(3, renderingGroup[8].Length); - Assert.Equal(30, renderingGroup[8][0]); - Assert.Equal(68, renderingGroup[8][2]); - }); - - [Fact] - public void ReadVifPackets() => File.OpenRead(MapFileName).Using(stream => - { - var alvifpkt = Mdlx.Read(stream).MapModel.VifPackets; - Assert.Equal(97, alvifpkt.Count); - - var packet1 = alvifpkt[0]; - Assert.Equal(1, packet1.TextureId); - Assert.Equal(1184, packet1.VifPacket.Length); - Assert.Equal(1, packet1.VifPacket[0]); - Assert.Equal(0, packet1.VifPacket[10]); - Assert.Equal(64, packet1.VifPacket[100]); - Assert.Equal(76, packet1.VifPacket[1170]); - - var packet2 = alvifpkt[96]; - Assert.Equal(2, packet2.TextureId); - Assert.Equal(960, packet2.VifPacket.Length); - Assert.Equal(1, packet2.VifPacket[0]); - Assert.Equal(117, packet2.VifPacket[500]); - }); - - [Fact] - public void WriteMapBack() => File.OpenRead(MapFileName).Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var mdlx = Mdlx.Read(inStream); - - var outStream = new MemoryStream(); - mdlx.Write(outStream); - - return outStream; - }); - }); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class MdlxTests + { + private const string FileName = "kh2/res/p_ex.vif"; + private const string MapFileName = "kh2/res/map.vif"; + + [Fact] + public void ShouldReadTheCorrectAmountOfSubModels() => File.OpenRead(FileName).Using(stream => + { + var model = Mdlx.Read(stream).SubModels; + + Assert.Equal(2, model.Count); + }); + + [Fact] + public void ShouldReadVifPackets() => File.OpenRead(FileName).Using(stream => + { + var dmaChain = Mdlx.Read(stream).SubModels[0].DmaChains; + Assert.Equal(26, dmaChain[0].DmaVifs.Count); + Assert.Equal(4, dmaChain.Count); + Assert.Equal(58, dmaChain.Sum(x => x.DmaVifs.Count)); + + var dmaVif = dmaChain[0].DmaVifs[0]; + Assert.Equal(0, dmaVif.TextureIndex); + Assert.Equal(10, dmaVif.Alaxi.Length); + Assert.Equal(53, dmaVif.Alaxi[0]); + Assert.Equal(22, dmaVif.Alaxi[9]); + Assert.Equal(1600, dmaVif.VifPacket.Length); + Assert.Equal(1, dmaVif.VifPacket[0]); + Assert.Equal(248, dmaVif.VifPacket[324]); + }); + + [Fact] + public void ShouldReadBones() => File.OpenRead(FileName).Using(stream => + { + var bones = Mdlx.Read(stream).SubModels[0].Bones; + Assert.Equal(228, bones.Count); + + var bone = bones[0]; + Assert.Equal(0, bone.Index); + Assert.Equal(-1, bone.Parent); + Assert.Equal(0, bone.Unk08); + Assert.Equal(3, bone.Unk0c); + Assert.Equal(1, bone.ScaleX); + Assert.Equal(0, bone.RotationX); + Assert.Equal(0, bone.TranslationX); + Assert.Equal(1, bone.ScaleY); + Assert.Equal(4.71, bone.RotationY, 2); + Assert.Equal(102.62, bone.TranslationY, 2); + Assert.Equal(1, bone.ScaleZ); + Assert.Equal(4.71, bone.RotationZ, 2); + Assert.Equal(0, bone.TranslationZ); + Assert.Equal(0, bone.ScaleW); + Assert.Equal(0, bone.RotationW); + Assert.Equal(0, bone.TranslationW); + }); + + [Fact] + public void ShouldWriteBackTheExactSameFile() => File.OpenRead(FileName).Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var mdlx = Mdlx.Read(inStream); + + var outStream = new MemoryStream(); + mdlx.Write(outStream); + + return outStream; + }); + }); + + [Fact] + public void ReadRemapTable() => File.OpenRead(MapFileName).Using(stream => + { + var remapTable = Mdlx.Read(stream).MapModel.DmaChainIndexRemapTable; + Assert.Equal(97, remapTable.Count); + + Assert.Equal(0, remapTable[0]); + Assert.Equal(1, remapTable[1]); + Assert.Equal(2, remapTable[2]); + Assert.Equal(96, remapTable[96]); + }); + + [Fact] + public void ReadRenderingGroup() => File.OpenRead(MapFileName).Using(stream => + { + var renderingGroup = Mdlx.Read(stream).MapModel.vifPacketRenderingGroup; + Assert.Equal(9, renderingGroup.Count); + + Assert.Equal(20, renderingGroup[0].Length); + Assert.Equal(1, renderingGroup[0][0]); + Assert.Equal(91, renderingGroup[0][19]); + + Assert.Equal(3, renderingGroup[8].Length); + Assert.Equal(30, renderingGroup[8][0]); + Assert.Equal(68, renderingGroup[8][2]); + }); + + [Fact] + public void ReadVifPackets() => File.OpenRead(MapFileName).Using(stream => + { + var alvifpkt = Mdlx.Read(stream).MapModel.VifPackets; + Assert.Equal(97, alvifpkt.Count); + + var packet1 = alvifpkt[0]; + Assert.Equal(1, packet1.TextureId); + Assert.Equal(1184, packet1.VifPacket.Length); + Assert.Equal(1, packet1.VifPacket[0]); + Assert.Equal(0, packet1.VifPacket[10]); + Assert.Equal(64, packet1.VifPacket[100]); + Assert.Equal(76, packet1.VifPacket[1170]); + + var packet2 = alvifpkt[96]; + Assert.Equal(2, packet2.TextureId); + Assert.Equal(960, packet2.VifPacket.Length); + Assert.Equal(1, packet2.VifPacket[0]); + Assert.Equal(117, packet2.VifPacket[500]); + }); + + [Fact] + public void WriteMapBack() => File.OpenRead(MapFileName).Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var mdlx = Mdlx.Read(inStream); + + var outStream = new MemoryStream(); + mdlx.Write(outStream); + + return outStream; + }); + }); + } +} diff --git a/OpenKh.Tests/kh2/ModelTextureTests.cs b/OpenKh.Tests/kh2/ModelTextureTests.cs index 0a5dfd60a..feda9f9f0 100644 --- a/OpenKh.Tests/kh2/ModelTextureTests.cs +++ b/OpenKh.Tests/kh2/ModelTextureTests.cs @@ -1,173 +1,173 @@ -using OpenKh.Common; -using OpenKh.Imaging; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class ModelTextureTests - { - private const string FileName1 = "kh2/res/model_texture1.tex"; - private const string FileName2 = "kh2/res/model_texture2.tex"; - - [Fact] - public void IsValidReturnsTrueWhenStreamContainsValidData() => File.OpenRead(FileName1).Using(stream => - { - Assert.True(ModelTexture.IsValid(stream)); - }); - - [Theory] - [InlineData(FileName1, 1)] - [InlineData(FileName2, 3)] - public void ReadCorrectAmountOfTextures(string fileName, int expectedCount) => File.OpenRead(fileName).Using(stream => - { - var modelTexture = ModelTexture.Read(stream); - - Assert.Equal(expectedCount, modelTexture.Images.Count); - }); - - [Fact] - public void CreateImagesWithTheCorrectInformation() => File.OpenRead(FileName2).Using(stream => - { - var modelTexture = ModelTexture.Read(stream); - - var image0 = modelTexture.Images[0]; - Assert.Equal(256, image0.Size.Width); - Assert.Equal(256, image0.Size.Height); - Assert.Equal(PixelFormat.Indexed8, image0.PixelFormat); - Assert.Equal(256 * 256, image0.GetData().Length); - - var image1 = modelTexture.Images[1]; - Assert.Equal(256, image1.Size.Width); - Assert.Equal(256, image1.Size.Height); - Assert.Equal(PixelFormat.Indexed8, image1.PixelFormat); - Assert.Equal(256 * 256, image1.GetData().Length); - - var image2 = modelTexture.Images[2]; - Assert.Equal(128, image2.Size.Width); - Assert.Equal(64, image2.Size.Height); - Assert.Equal(PixelFormat.Indexed8, image2.PixelFormat); - Assert.Equal(128 * 64, image2.GetData().Length); - }); - - [Theory] - [InlineData(FileName1)] - [InlineData(FileName2)] - public void WriteBackTheSameFile(string fileName) => File.OpenRead(fileName).Using(stream => Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - ModelTexture.Read(inStream).Write(outStream); - return outStream; - })); - - [Fact] - public void Read4bitPaletteCorrectly() => File.OpenRead(FileName1).Using(stream => - { - var clut = ModelTexture.Read(stream).Images.First().GetClut(); - - Assert.Equal(87, clut[0]); - Assert.Equal(98, clut[1]); - Assert.Equal(106, clut[2]); - Assert.Equal(255, clut[3]); - - Assert.Equal(95, clut[4]); - Assert.Equal(105, clut[5]); - Assert.Equal(114, clut[6]); - Assert.Equal(255, clut[7]); - - Assert.Equal(108, clut[16]); - Assert.Equal(118, clut[17]); - Assert.Equal(128, clut[18]); - Assert.Equal(255, clut[19]); - - Assert.Equal(134, clut[32]); - Assert.Equal(147, clut[33]); - Assert.Equal(158, clut[34]); - Assert.Equal(255, clut[35]); - }); - - [Fact] - public void Read8bitPaletteCorrectly() => File.OpenRead(FileName2).Using(stream => - { +using OpenKh.Common; +using OpenKh.Imaging; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class ModelTextureTests + { + private const string FileName1 = "kh2/res/model_texture1.tex"; + private const string FileName2 = "kh2/res/model_texture2.tex"; + + [Fact] + public void IsValidReturnsTrueWhenStreamContainsValidData() => File.OpenRead(FileName1).Using(stream => + { + Assert.True(ModelTexture.IsValid(stream)); + }); + + [Theory] + [InlineData(FileName1, 1)] + [InlineData(FileName2, 3)] + public void ReadCorrectAmountOfTextures(string fileName, int expectedCount) => File.OpenRead(fileName).Using(stream => + { + var modelTexture = ModelTexture.Read(stream); + + Assert.Equal(expectedCount, modelTexture.Images.Count); + }); + + [Fact] + public void CreateImagesWithTheCorrectInformation() => File.OpenRead(FileName2).Using(stream => + { + var modelTexture = ModelTexture.Read(stream); + + var image0 = modelTexture.Images[0]; + Assert.Equal(256, image0.Size.Width); + Assert.Equal(256, image0.Size.Height); + Assert.Equal(PixelFormat.Indexed8, image0.PixelFormat); + Assert.Equal(256 * 256, image0.GetData().Length); + + var image1 = modelTexture.Images[1]; + Assert.Equal(256, image1.Size.Width); + Assert.Equal(256, image1.Size.Height); + Assert.Equal(PixelFormat.Indexed8, image1.PixelFormat); + Assert.Equal(256 * 256, image1.GetData().Length); + + var image2 = modelTexture.Images[2]; + Assert.Equal(128, image2.Size.Width); + Assert.Equal(64, image2.Size.Height); + Assert.Equal(PixelFormat.Indexed8, image2.PixelFormat); + Assert.Equal(128 * 64, image2.GetData().Length); + }); + + [Theory] + [InlineData(FileName1)] + [InlineData(FileName2)] + public void WriteBackTheSameFile(string fileName) => File.OpenRead(fileName).Using(stream => Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + ModelTexture.Read(inStream).Write(outStream); + return outStream; + })); + + [Fact] + public void Read4bitPaletteCorrectly() => File.OpenRead(FileName1).Using(stream => + { + var clut = ModelTexture.Read(stream).Images.First().GetClut(); + + Assert.Equal(87, clut[0]); + Assert.Equal(98, clut[1]); + Assert.Equal(106, clut[2]); + Assert.Equal(255, clut[3]); + + Assert.Equal(95, clut[4]); + Assert.Equal(105, clut[5]); + Assert.Equal(114, clut[6]); + Assert.Equal(255, clut[7]); + + Assert.Equal(108, clut[16]); + Assert.Equal(118, clut[17]); + Assert.Equal(128, clut[18]); + Assert.Equal(255, clut[19]); + + Assert.Equal(134, clut[32]); + Assert.Equal(147, clut[33]); + Assert.Equal(158, clut[34]); + Assert.Equal(255, clut[35]); + }); + + [Fact] + public void Read8bitPaletteCorrectly() => File.OpenRead(FileName2).Using(stream => + { var images = ModelTexture.Read(stream).Images; - AssertPalette(images, 0, 0, 0, 0, 0); - AssertPalette(images, 0, 4, 10, 10, 10); - AssertPalette(images, 0, 8, 11, 15, 23); - AssertPalette(images, 0, 16, 23, 19, 29); - AssertPalette(images, 0, 32, 23, 35, 56); - AssertPalette(images, 0, 64, 57, 51, 71); - AssertPalette(images, 0, 128, 153, 96, 7); - - AssertPalette(images, 1, 3, 22, 18, 27); - }); - - [Theory] - [InlineData(0, 0, 0, 0x0)] - [InlineData(1, 0, 0, 0x4)] - [InlineData(2, 0, 0, 0x8)] - [InlineData(4, 0, 0, 0x10)] - [InlineData(7, 0, 0, 0x1c)] - [InlineData(8, 0, 0, 0x100)] - [InlineData(16, 0, 0, 0x20)] - [InlineData(32, 0, 0, 0x200)] - [InlineData(64, 0, 0, 0x400)] - [InlineData(0, 4, 0, 0x40)] - [InlineData(8, 4, 0, 0x140)] - [InlineData(16, 4, 0, 0x60)] - [InlineData(32, 4, 0, 0x240)] - [InlineData(0, 0x08, 0, 0x1000)] - [InlineData(0, 0x08, 1, 0x1020)] - [InlineData(0, 0x08, 2, 0x1200)] - [InlineData(0, 0x08, 3, 0x1220)] - [InlineData(0, 0x08, 4, 0x1400)] - [InlineData(0, 0x08, 8, 0x1800)] - [InlineData(0, 0x0c, 0, 0x1040)] - [InlineData(0, 0x10, 0, 0x80)] - [InlineData(0, 0x20, 0, 0x2000)] - public void PointerTest(int index, int cbp, int csa, int expectedPointer) - { - Assert.Equal(expectedPointer / 4, ModelTexture.GetClutPointer(index, cbp, csa)); - } - - private void AssertPalette(List textures, int imageIndex, int colorIndex, byte r, byte g, byte b) - { - var texture = textures[imageIndex]; - var clut = texture.GetClut(); - - try - { - Assert.Equal(r, clut[colorIndex * 4 + 0]); - Assert.Equal(g, clut[colorIndex * 4 + 1]); - Assert.Equal(b, clut[colorIndex * 4 + 2]); - } - catch - { - Console.WriteLine($"Error for texture {imageIndex}"); - throw; - } - } - - [Theory] - [InlineData("4bit-128-128")] - [InlineData("4bit-256-128")] - [InlineData("4bit-256-512")] - [InlineData("4bit-512-128")] - [InlineData("4bit-512-512")] - [InlineData("8bit-128-128")] - [InlineData("8bit-128-64")] - [InlineData("8bit-256-128")] - [InlineData("8bit-256-256")] - [InlineData("8bit-512-256")] - [InlineData("8bit-512-512")] + AssertPalette(images, 0, 0, 0, 0, 0); + AssertPalette(images, 0, 4, 10, 10, 10); + AssertPalette(images, 0, 8, 11, 15, 23); + AssertPalette(images, 0, 16, 23, 19, 29); + AssertPalette(images, 0, 32, 23, 35, 56); + AssertPalette(images, 0, 64, 57, 51, 71); + AssertPalette(images, 0, 128, 153, 96, 7); + + AssertPalette(images, 1, 3, 22, 18, 27); + }); + + [Theory] + [InlineData(0, 0, 0, 0x0)] + [InlineData(1, 0, 0, 0x4)] + [InlineData(2, 0, 0, 0x8)] + [InlineData(4, 0, 0, 0x10)] + [InlineData(7, 0, 0, 0x1c)] + [InlineData(8, 0, 0, 0x100)] + [InlineData(16, 0, 0, 0x20)] + [InlineData(32, 0, 0, 0x200)] + [InlineData(64, 0, 0, 0x400)] + [InlineData(0, 4, 0, 0x40)] + [InlineData(8, 4, 0, 0x140)] + [InlineData(16, 4, 0, 0x60)] + [InlineData(32, 4, 0, 0x240)] + [InlineData(0, 0x08, 0, 0x1000)] + [InlineData(0, 0x08, 1, 0x1020)] + [InlineData(0, 0x08, 2, 0x1200)] + [InlineData(0, 0x08, 3, 0x1220)] + [InlineData(0, 0x08, 4, 0x1400)] + [InlineData(0, 0x08, 8, 0x1800)] + [InlineData(0, 0x0c, 0, 0x1040)] + [InlineData(0, 0x10, 0, 0x80)] + [InlineData(0, 0x20, 0, 0x2000)] + public void PointerTest(int index, int cbp, int csa, int expectedPointer) + { + Assert.Equal(expectedPointer / 4, ModelTexture.GetClutPointer(index, cbp, csa)); + } + + private void AssertPalette(List textures, int imageIndex, int colorIndex, byte r, byte g, byte b) + { + var texture = textures[imageIndex]; + var clut = texture.GetClut(); + + try + { + Assert.Equal(r, clut[colorIndex * 4 + 0]); + Assert.Equal(g, clut[colorIndex * 4 + 1]); + Assert.Equal(b, clut[colorIndex * 4 + 2]); + } + catch + { + Console.WriteLine($"Error for texture {imageIndex}"); + throw; + } + } + + [Theory] + [InlineData("4bit-128-128")] + [InlineData("4bit-256-128")] + [InlineData("4bit-256-512")] + [InlineData("4bit-512-128")] + [InlineData("4bit-512-512")] + [InlineData("8bit-128-128")] + [InlineData("8bit-128-64")] + [InlineData("8bit-256-128")] + [InlineData("8bit-256-256")] + [InlineData("8bit-512-256")] + [InlineData("8bit-512-512")] public void CreateAndRead(string baseName) { var image = File.OpenRead($"kh2/res/image-{baseName}.imd").Using(s => Imgd.Read(s)); - + { var outStream = new MemoryStream(); { @@ -187,7 +187,7 @@ public void CreateAndRead(string baseName) Assert.Equal(image.GetData(), converted.GetData()); } } - + { var outStream = new MemoryStream(); { @@ -208,7 +208,7 @@ public void CreateAndRead(string baseName) } } } - + { var outStream = new MemoryStream(); { @@ -229,6 +229,6 @@ public void CreateAndRead(string baseName) } } } - } - } -} + } + } +} diff --git a/OpenKh.Tests/kh2/MotionSetTests.cs b/OpenKh.Tests/kh2/MotionSetTests.cs index c595ad033..4b45ff06c 100644 --- a/OpenKh.Tests/kh2/MotionSetTests.cs +++ b/OpenKh.Tests/kh2/MotionSetTests.cs @@ -1,122 +1,122 @@ -using OpenKh.Kh2; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class MotionSetTests - { - const int IDLE = 0; - const int WALK = 1; - const int RUN = 2; - const int FALL = 4; - const int NOT_EXISTING = 5; - - const bool ANIM = true; - const bool DUMMY = false; - - const bool IN_BATTLE = true; - const bool OUT_BATTLE = false; - const bool HAS_WEAPON = true; - const bool NO_WEAPON = false; - - - [Theory] - [InlineData(IDLE, IN_BATTLE, HAS_WEAPON, 0)] - [InlineData(IDLE, OUT_BATTLE, NO_WEAPON, 2)] - [InlineData(IDLE, OUT_BATTLE, HAS_WEAPON, 2)] - [InlineData(WALK, IN_BATTLE, HAS_WEAPON, 4)] - [InlineData(WALK, OUT_BATTLE, NO_WEAPON, 6)] - [InlineData(WALK, OUT_BATTLE, HAS_WEAPON, 7)] - [InlineData(RUN, IN_BATTLE, HAS_WEAPON, 8)] - [InlineData(RUN, OUT_BATTLE, NO_WEAPON, 10)] - [InlineData(RUN, OUT_BATTLE, HAS_WEAPON, 11)] - [InlineData(FALL, OUT_BATTLE, NO_WEAPON, 18)] - [InlineData(FALL, OUT_BATTLE, HAS_WEAPON, 18)] - [InlineData(FALL, IN_BATTLE, HAS_WEAPON, 18)] - [InlineData(NOT_EXISTING, IN_BATTLE, HAS_WEAPON, -1)] - [InlineData(NOT_EXISTING, IN_BATTLE, NO_WEAPON, -1)] - [InlineData(NOT_EXISTING, OUT_BATTLE, HAS_WEAPON, -1)] - [InlineData(NOT_EXISTING, OUT_BATTLE, NO_WEAPON, -1)] - public void GetValidMotionSetIndex( - int animId, - bool isBattle, - bool hasWeapon, - int expectedMsetId) - { - var fakeBar = GenerateFakeBar(new bool[] - { - // A000 - ANIM, - DUMMY, - ANIM, - DUMMY, - // A001 - ANIM, - DUMMY, - ANIM, - ANIM, - // A002 - ANIM, - DUMMY, - ANIM, - ANIM, - // A003 - DUMMY, - DUMMY, - ANIM, - DUMMY, - // A004 - DUMMY, - DUMMY, - ANIM, - DUMMY, - // A005 - DUMMY, - DUMMY, - DUMMY, - DUMMY, - }); - - var actualMsetId = MotionSet.GetMotionSetIndex( - fakeBar, (MotionSet.MotionName)animId, isBattle, hasWeapon); - - Assert.Equal(expectedMsetId, actualMsetId); - } - - [Theory] - [InlineData(IN_BATTLE, HAS_WEAPON, 0)] - [InlineData(IN_BATTLE, NO_WEAPON, 1)] - [InlineData(OUT_BATTLE, NO_WEAPON, 2)] - [InlineData(OUT_BATTLE, HAS_WEAPON, 3)] - public void GetAbsoluteMotionSetIndex( - bool isBattle, - bool hasWeapon, - int expectedMsetId) - { - var fakeBar = GenerateFakeBar(new bool[] - { - ANIM, - ANIM, - ANIM, - ANIM, - }); - - var actualMsetId = MotionSet.GetMotionSetIndex( - fakeBar, MotionSet.MotionName.IDLE, isBattle, hasWeapon); - - Assert.Equal(expectedMsetId, actualMsetId); - } - - private static List GenerateFakeBar(IEnumerable hasAnimationArray) => - hasAnimationArray.Select((hasAnimation, i) => new Bar.Entry - { - Index = 0, - Name = $"A{i/4:D03}", - Type = Bar.EntryType.Anb, - Stream = new MemoryStream(hasAnimation ? new byte[1] : new byte[0]) - }).ToList(); - } -} +using OpenKh.Kh2; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class MotionSetTests + { + const int IDLE = 0; + const int WALK = 1; + const int RUN = 2; + const int FALL = 4; + const int NOT_EXISTING = 5; + + const bool ANIM = true; + const bool DUMMY = false; + + const bool IN_BATTLE = true; + const bool OUT_BATTLE = false; + const bool HAS_WEAPON = true; + const bool NO_WEAPON = false; + + + [Theory] + [InlineData(IDLE, IN_BATTLE, HAS_WEAPON, 0)] + [InlineData(IDLE, OUT_BATTLE, NO_WEAPON, 2)] + [InlineData(IDLE, OUT_BATTLE, HAS_WEAPON, 2)] + [InlineData(WALK, IN_BATTLE, HAS_WEAPON, 4)] + [InlineData(WALK, OUT_BATTLE, NO_WEAPON, 6)] + [InlineData(WALK, OUT_BATTLE, HAS_WEAPON, 7)] + [InlineData(RUN, IN_BATTLE, HAS_WEAPON, 8)] + [InlineData(RUN, OUT_BATTLE, NO_WEAPON, 10)] + [InlineData(RUN, OUT_BATTLE, HAS_WEAPON, 11)] + [InlineData(FALL, OUT_BATTLE, NO_WEAPON, 18)] + [InlineData(FALL, OUT_BATTLE, HAS_WEAPON, 18)] + [InlineData(FALL, IN_BATTLE, HAS_WEAPON, 18)] + [InlineData(NOT_EXISTING, IN_BATTLE, HAS_WEAPON, -1)] + [InlineData(NOT_EXISTING, IN_BATTLE, NO_WEAPON, -1)] + [InlineData(NOT_EXISTING, OUT_BATTLE, HAS_WEAPON, -1)] + [InlineData(NOT_EXISTING, OUT_BATTLE, NO_WEAPON, -1)] + public void GetValidMotionSetIndex( + int animId, + bool isBattle, + bool hasWeapon, + int expectedMsetId) + { + var fakeBar = GenerateFakeBar(new bool[] + { + // A000 + ANIM, + DUMMY, + ANIM, + DUMMY, + // A001 + ANIM, + DUMMY, + ANIM, + ANIM, + // A002 + ANIM, + DUMMY, + ANIM, + ANIM, + // A003 + DUMMY, + DUMMY, + ANIM, + DUMMY, + // A004 + DUMMY, + DUMMY, + ANIM, + DUMMY, + // A005 + DUMMY, + DUMMY, + DUMMY, + DUMMY, + }); + + var actualMsetId = MotionSet.GetMotionSetIndex( + fakeBar, (MotionSet.MotionName)animId, isBattle, hasWeapon); + + Assert.Equal(expectedMsetId, actualMsetId); + } + + [Theory] + [InlineData(IN_BATTLE, HAS_WEAPON, 0)] + [InlineData(IN_BATTLE, NO_WEAPON, 1)] + [InlineData(OUT_BATTLE, NO_WEAPON, 2)] + [InlineData(OUT_BATTLE, HAS_WEAPON, 3)] + public void GetAbsoluteMotionSetIndex( + bool isBattle, + bool hasWeapon, + int expectedMsetId) + { + var fakeBar = GenerateFakeBar(new bool[] + { + ANIM, + ANIM, + ANIM, + ANIM, + }); + + var actualMsetId = MotionSet.GetMotionSetIndex( + fakeBar, MotionSet.MotionName.IDLE, isBattle, hasWeapon); + + Assert.Equal(expectedMsetId, actualMsetId); + } + + private static List GenerateFakeBar(IEnumerable hasAnimationArray) => + hasAnimationArray.Select((hasAnimation, i) => new Bar.Entry + { + Index = 0, + Name = $"A{i / 4:D03}", + Type = Bar.EntryType.Anb, + Stream = new MemoryStream(hasAnimation ? new byte[1] : new byte[0]) + }).ToList(); + } +} diff --git a/OpenKh.Tests/kh2/MotionTests.cs b/OpenKh.Tests/kh2/MotionTests.cs index 651753616..da6bd38a0 100644 --- a/OpenKh.Tests/kh2/MotionTests.cs +++ b/OpenKh.Tests/kh2/MotionTests.cs @@ -1,157 +1,157 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class MotionTests - { - private const string RawFileName = "./kh2/res/raw.motion"; - private const string InterpolatedFileName = "./kh2/res/interpolated.motion"; - - [Fact] - public void ReadRawMotion() - { - var motion = File.OpenRead(RawFileName).Using(Motion.Read); - - Assert.True(motion.IsRaw); - Assert.NotNull(motion.Raw); - Assert.Null(motion.Interpolated); - - Assert.Equal(30, motion.Raw.FramePerSecond); - } - - [Fact] - public void ReadInterpolatedMotion() - { - var motion = File.OpenRead(InterpolatedFileName).Using(Motion.Read); - - Assert.False(motion.IsRaw); - Assert.Null(motion.Raw); - Assert.NotNull(motion.Interpolated); - } - - [Theory] - [InlineData(RawFileName)] - [InlineData(InterpolatedFileName)] - public void WriteBackTheSameFile(string fileName) => - File.OpenRead(fileName).Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Motion.Write(outStream, Motion.Read(inStream)); - - return outStream; - }); - }); - - [SkippableFact] - public void Full_WriteBackTheSameFiles() => - Helpers.ForAllFiles(".tests/kh2_data", fileName => - { - Helpers.ForBarEntries(fileName, - x => x.Type == Bar.EntryType.Anb && x.Stream.Length > 0, (fileName, entry) => - { - if (!Bar.IsValid(entry.Stream)) - return; - - var motionEntry = Bar.Read(entry.Stream) - .FirstOrDefault(x => x.Type == Bar.EntryType.Motion); - if (motionEntry == null) - return; - - Helpers.AssertStream(motionEntry.Stream, inStream => - { - var outStream = new MemoryStream(); - Motion.Write(outStream, Motion.Read(inStream)); - - return outStream; - }); - }); - }); - - public class UseAssetAnbFiles - { - private static string KH2Dir = ".tests/kh2_data/"; - - public static IEnumerable Source() - { - foreach (var anbFile in Directory.GetFiles(KH2Dir, "anm/*.anb", SearchOption.AllDirectories)) - { - foreach (var entry in File.OpenRead(anbFile).Using(Bar.Read) - .Where(it => it.Type == Bar.EntryType.Motion) - ) - { - yield return new object[] { anbFile.Substring(KH2Dir.Length).Replace("\\", "/"), entry.Name }; - } - } - } - - //[Theory, MemberData(nameof(Source))] - public void MotionTests(string anbFile, string motionName) - { - var entry = File.OpenRead(Path.Combine(KH2Dir, anbFile)) - .Using(Bar.Read) - .SingleOrDefault(it => it.Name == motionName && it.Type == Bar.EntryType.Event); - - if (entry != null) - { - Motion.Read(entry.Stream); - } - } - } - - public class UseAssetMsetFiles - { - private static string KH2Dir = ".tests/kh2_data/"; - - public static IEnumerable Source() - { - foreach (var msetFile in Directory.GetFiles(KH2Dir, "obj/*.mset", SearchOption.AllDirectories)) - { - foreach (var (msetEntry, index) in File.OpenRead(msetFile).Using(Bar.Read) - .Select((msetEntry, index) => (msetEntry, index)) - .Where(pair => pair.msetEntry.Type == Bar.EntryType.Anb && pair.msetEntry.Stream.Length != 0) - ) - { - foreach (var anbEntry in Bar.Read(msetEntry.Stream) - .Where(it => it.Type == Bar.EntryType.Motion) - ) - { - if (anbEntry.Stream.Length != 0) - { - yield return new object[] { - msetFile.Substring(KH2Dir.Length).Replace("\\", "/"), - index, - }; - } - } - } - } - } - - //[Theory, MemberData(nameof(Source))] - public void MotionTests(string msetFile, int index) - { - var msetEntry = File.OpenRead(Path.Combine(KH2Dir, msetFile)) - .Using(Bar.Read) - .Skip(index) - .First(); - - Assert.Equal(Bar.EntryType.Anb, msetEntry.Type); - - if (msetEntry != null) - { - var anbEntry = Bar.Read(msetEntry.Stream) - .Single(it => it.Type == Bar.EntryType.Motion); - - Motion.Read(anbEntry.Stream); - } - } - } - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class MotionTests + { + private const string RawFileName = "./kh2/res/raw.motion"; + private const string InterpolatedFileName = "./kh2/res/interpolated.motion"; + + [Fact] + public void ReadRawMotion() + { + var motion = File.OpenRead(RawFileName).Using(Motion.Read); + + Assert.True(motion.IsRaw); + Assert.NotNull(motion.Raw); + Assert.Null(motion.Interpolated); + + Assert.Equal(30, motion.Raw.FramePerSecond); + } + + [Fact] + public void ReadInterpolatedMotion() + { + var motion = File.OpenRead(InterpolatedFileName).Using(Motion.Read); + + Assert.False(motion.IsRaw); + Assert.Null(motion.Raw); + Assert.NotNull(motion.Interpolated); + } + + [Theory] + [InlineData(RawFileName)] + [InlineData(InterpolatedFileName)] + public void WriteBackTheSameFile(string fileName) => + File.OpenRead(fileName).Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Motion.Write(outStream, Motion.Read(inStream)); + + return outStream; + }); + }); + + [SkippableFact] + public void Full_WriteBackTheSameFiles() => + Helpers.ForAllFiles(".tests/kh2_data", fileName => + { + Helpers.ForBarEntries(fileName, + x => x.Type == Bar.EntryType.Anb && x.Stream.Length > 0, (fileName, entry) => + { + if (!Bar.IsValid(entry.Stream)) + return; + + var motionEntry = Bar.Read(entry.Stream) + .FirstOrDefault(x => x.Type == Bar.EntryType.Motion); + if (motionEntry == null) + return; + + Helpers.AssertStream(motionEntry.Stream, inStream => + { + var outStream = new MemoryStream(); + Motion.Write(outStream, Motion.Read(inStream)); + + return outStream; + }); + }); + }); + + public class UseAssetAnbFiles + { + private static string KH2Dir = ".tests/kh2_data/"; + + public static IEnumerable Source() + { + foreach (var anbFile in Directory.GetFiles(KH2Dir, "anm/*.anb", SearchOption.AllDirectories)) + { + foreach (var entry in File.OpenRead(anbFile).Using(Bar.Read) + .Where(it => it.Type == Bar.EntryType.Motion) + ) + { + yield return new object[] { anbFile.Substring(KH2Dir.Length).Replace("\\", "/"), entry.Name }; + } + } + } + + //[Theory, MemberData(nameof(Source))] + public void MotionTests(string anbFile, string motionName) + { + var entry = File.OpenRead(Path.Combine(KH2Dir, anbFile)) + .Using(Bar.Read) + .SingleOrDefault(it => it.Name == motionName && it.Type == Bar.EntryType.Event); + + if (entry != null) + { + Motion.Read(entry.Stream); + } + } + } + + public class UseAssetMsetFiles + { + private static string KH2Dir = ".tests/kh2_data/"; + + public static IEnumerable Source() + { + foreach (var msetFile in Directory.GetFiles(KH2Dir, "obj/*.mset", SearchOption.AllDirectories)) + { + foreach (var (msetEntry, index) in File.OpenRead(msetFile).Using(Bar.Read) + .Select((msetEntry, index) => (msetEntry, index)) + .Where(pair => pair.msetEntry.Type == Bar.EntryType.Anb && pair.msetEntry.Stream.Length != 0) + ) + { + foreach (var anbEntry in Bar.Read(msetEntry.Stream) + .Where(it => it.Type == Bar.EntryType.Motion) + ) + { + if (anbEntry.Stream.Length != 0) + { + yield return new object[] { + msetFile.Substring(KH2Dir.Length).Replace("\\", "/"), + index, + }; + } + } + } + } + } + + //[Theory, MemberData(nameof(Source))] + public void MotionTests(string msetFile, int index) + { + var msetEntry = File.OpenRead(Path.Combine(KH2Dir, msetFile)) + .Using(Bar.Read) + .Skip(index) + .First(); + + Assert.Equal(Bar.EntryType.Anb, msetEntry.Type); + + if (msetEntry != null) + { + var anbEntry = Bar.Read(msetEntry.Stream) + .Single(it => it.Type == Bar.EntryType.Motion); + + Motion.Read(anbEntry.Stream); + } + } + } + } +} diff --git a/OpenKh.Tests/kh2/MsgEncoderTests.cs b/OpenKh.Tests/kh2/MsgEncoderTests.cs index 133a3d8dd..ad92b2308 100644 --- a/OpenKh.Tests/kh2/MsgEncoderTests.cs +++ b/OpenKh.Tests/kh2/MsgEncoderTests.cs @@ -1,338 +1,338 @@ -using OpenKh.Kh2.Messages; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class MsgEncoderTests - { - public enum EncoderType - { - InternationalSystem, - JapaneseEvent, - JapaneseSystem, - TurkishSystem - }; - - [Fact] - public void DecodeTextCorrectly() - { - var decoded = Encoders.InternationalSystem.Decode(new byte[] - { - 0x35, 0x9E, 0xA5, 0xA5, 0xA8, 0x01, 0xB0, 0xA8, 0xAB, 0xA5, 0x9D, 0x48, 0x00 - }); - - Assert.Equal(MessageCommand.PrintText, decoded[0].Command); - Assert.Equal("Hello world!", decoded[0].Text); - Assert.Equal(MessageCommand.End, decoded[1].Command); - } - - [Fact] - public void DecodeComplexTextCorrectly() - { - var decoded = Encoders.InternationalSystem.Decode(new byte[] - { - 0x90, 0x7a, 0x91, 0x00 - }); - - Assert.Equal(MessageCommand.PrintText, decoded[0].Command); - Assert.Equal("0", decoded[0].Text); - Assert.Equal(MessageCommand.PrintComplex, decoded[1].Command); - Assert.Equal("VII", decoded[1].Text); - Assert.Equal(MessageCommand.PrintText, decoded[2].Command); - Assert.Equal("1", decoded[2].Text); - Assert.Equal(MessageCommand.End, decoded[3].Command); - } - - [Fact] - public void DecodeIconCorrectly() - { - var decoded = Encoders.InternationalSystem.Decode(new byte[] - { - 0x09, 0x00, 0x09, 0x01, 0x00 - }); - - Assert.Equal(MessageCommand.PrintIcon, decoded[0].Command); - Assert.Equal(0, decoded[0].Data[0]); - Assert.Equal(MessageCommand.PrintIcon, decoded[1].Command); - Assert.Equal(1, decoded[1].Data[0]); - Assert.Equal(MessageCommand.End, decoded[2].Command); - } - - [Fact] - public void DecodeColorCommandCorrectly() - { - var decoded = Encoders.InternationalSystem.Decode(new byte[] - { - 0x07, 0x00, 0xFF, 0x00, 0x00, 0x00 - }); - - Assert.Equal(MessageCommand.Color, decoded[0].Command); - Assert.Equal(0, decoded[0].Data[0]); - Assert.Equal(0xFF, decoded[0].Data[1]); - Assert.Equal(0, decoded[0].Data[2]); - Assert.Equal(0, decoded[0].Data[3]); - Assert.Equal(MessageCommand.End, decoded[1].Command); - } - - [Theory] - [InlineData(0x03, "0123456789")] - [InlineData(0x04, "123456789")] - [InlineData(0x05, "6789")] - [InlineData(0x06, "123456789")] - [InlineData(0x07, "456789")] - [InlineData(0x08, "3456789")] - [InlineData(0x09, "123456789")] - [InlineData(0x0a, "123456789")] - [InlineData(0x0b, "123456789")] - [InlineData(0x0c, "123456789")] - [InlineData(0x0d, "0123456789")] - [InlineData(0x0e, "123456789")] - [InlineData(0x0f, "56789")] - //[InlineData(0x10, "")] - [InlineData(0x11, "456789")] - [InlineData(0x12, "23456789")] - [InlineData(0x13, "456789")] - [InlineData(0x14, "23456789")] - [InlineData(0x15, "23456789")] - [InlineData(0x16, "123456789")] - //[InlineData(0x17, "")] - [InlineData(0x18, "23456789")] - public void DecodeTheRightAmountOfCharacters(byte commandId, string expectedText) - { - var decoded = Encoders.InternationalSystem.Decode(new byte[] - { - commandId, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99 - }); - - Assert.Equal(expectedText, decoded[1].Text); - } - - [Theory] - [InlineData("I", 0x74)] - [InlineData("II", 0x75)] - [InlineData("III", 0x76)] - [InlineData("IV", 0x77)] - [InlineData("V", 0x78)] - [InlineData("VI", 0x79)] - [InlineData("♪", 0x8e)] - public void EncodeComplexTextCorrectly(string value, byte expected) - { - var actual = Encoders.InternationalSystem.Encode(new List - { - new MessageCommandModel - { - Command = MessageCommand.PrintComplex, - Text = value - } - })[0]; - - Assert.Equal(expected, actual); - } - - [Fact] - public void SimpleReEncodeTest() - { - var expected = new byte[] - { - 0x01, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, - 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, - }; - var decoded = Encoders.InternationalSystem.Decode(expected); - var encoded = Encoders.InternationalSystem.Encode(decoded); - - Assert.Equal(expected, encoded); - } - - [Theory] - [InlineData(0x02)] - [InlineData(0x03)] - [InlineData(0x04)] - [InlineData(0x05)] - [InlineData(0x06)] - [InlineData(0x07)] - [InlineData(0x08)] - [InlineData(0x09)] - [InlineData(0x0a)] - [InlineData(0x0b)] - [InlineData(0x0c)] - [InlineData(0x0d)] - [InlineData(0x0e)] - [InlineData(0x0f)] - //[InlineData(0x10)] - [InlineData(0x11)] - [InlineData(0x12)] - [InlineData(0x13)] - [InlineData(0x14)] - [InlineData(0x15)] - [InlineData(0x16)] - //[InlineData(0x17)] - [InlineData(0x18)] - public void AdvancedReEncodeTest(byte commandByte) - { - var expected = new byte[] - { - commandByte, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, - 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, - }; - var decoded = Encoders.InternationalSystem.Decode(expected); - var encoded = Encoders.InternationalSystem.Encode(decoded); - - Assert.Equal(expected, encoded); - } - - [Theory] - [InlineData(0x1a, 0x00, '珍')] - [InlineData(0x1b, 0x00, '何')] - [InlineData(0x1c, 0x00, '係')] - [InlineData(0x1e, 0x40, '外')] - [InlineData(0x1f, 0x00, '銅')] - [InlineData(0x1f, 0xc7, '念')] - [InlineData(0x1f, 0xc8, '還')] - [InlineData(0x1f, 0xDF, '夕')] - public void DecodeJapaneseSystemTextCorrectly(byte command, byte data, char expected) - { - var decoded = Encoders.JapaneseSystem.Decode(new byte[] { command, data }); - - Assert.NotEmpty(decoded); - Assert.Equal(expected, decoded.Single().Text.Single()); - } - - [Theory] - [InlineData("\x19\x0a\x19\x1e\x55", "ロビー")] - public void DecodeJapaneseSystemTextWordCorrectly(string data, string expected) - { - var decoded = Encoders.JapaneseSystem.Decode( - System.Text.Encoding.GetEncoding("latin1").GetBytes(data) - ); - - Assert.NotEmpty(decoded); - Assert.Equal(expected, decoded.Single().Text); - } - - [Theory] - [InlineData(0x84, 0x00, "III")] - [InlineData(0x85, 0x00, "VII")] - [InlineData(0x86, 0x00, "VIII")] - [InlineData(0x87, 0x00, "X")] - [InlineData(0x19, 0xb2, "XIII")] - [InlineData(0x1b, 0x54, "I")] - [InlineData(0x1b, 0x55, "II")] - [InlineData(0x1b, 0x56, "IV")] - [InlineData(0x1b, 0x57, "V")] - [InlineData(0x1b, 0x58, "VI")] - [InlineData(0x1b, 0x59, "IX")] - [InlineData(0x1e, 0x66, "IV")] - public void DecodeRomanNumbersFromJapaneseSystemTable(byte command, byte data, string expected) - { - var decoded = Encoders.JapaneseSystem.Decode(new byte[] { command, data }); - - Assert.NotEmpty(decoded); - Assert.Equal(MessageCommand.PrintComplex, decoded.First().Command); - Assert.Equal(expected, decoded.First().Text); - } - - [Theory] - [InlineData(0x84, 0x00, "III")] - [InlineData(0x85, 0x00, "VII")] - [InlineData(0x86, 0x00, "VIII")] - [InlineData(0x87, 0x00, "X")] - [InlineData(0x19, 0xb2, "XIII")] - [InlineData(0x1b, 0x54, "I")] - [InlineData(0x1b, 0x55, "II")] - [InlineData(0x1b, 0x56, "IV")] - [InlineData(0x1b, 0x57, "V")] - [InlineData(0x1b, 0x58, "VI")] - [InlineData(0x1b, 0x59, "IX")] - public void EncodeRomanNumbersForJapaneseSystemTable(byte command, byte data, string textSource) - { - var encoded = Encoders.JapaneseSystem.Encode(new List - { - new MessageCommandModel - { - Command = MessageCommand.PrintComplex, - Text = textSource - } - }); - - if (data == 0) - Assert.Equal(new byte[] { command }, encoded); - else - Assert.Equal(new byte[] { command, data }, encoded); - } - - [Theory] - [InlineData(EncoderType.InternationalSystem)] - [InlineData(EncoderType.JapaneseEvent)] - [InlineData(EncoderType.JapaneseSystem)] - [InlineData(EncoderType.TurkishSystem)] - public void EncodeNewLineCharacterCorrectly(EncoderType encoderType) - { - var encoder = new IMessageEncode[] - { - Encoders.InternationalSystem, - Encoders.JapaneseEvent, - Encoders.JapaneseSystem, - Encoders.TurkishSystem - }[(int)encoderType]; - - var encoded = encoder.Encode(new List - { - new MessageCommandModel - { - Command = MessageCommand.PrintText, - Text = "HE\nLLO", - } - }); - Assert.Equal(new byte[] { 0x35, 0x32, 0x02, 0x39, 0x39, 0x3C }, encoded); - } - - [Theory] - [InlineData(EncoderType.InternationalSystem)] - [InlineData(EncoderType.JapaneseEvent)] - [InlineData(EncoderType.JapaneseSystem)] - [InlineData(EncoderType.TurkishSystem)] - public void DecodeNewLineCharacterCorrectly(EncoderType encoderType) - { - var decoder = new IMessageDecode[] - { - Encoders.InternationalSystem, - Encoders.JapaneseEvent, - Encoders.JapaneseSystem, - Encoders.TurkishSystem - }[(int)encoderType]; - - var models = decoder.Decode(new byte[] { 0x35, 0x32, 0x02, 0x39, 0x39, 0x3C }); - Assert.Single(models); - Assert.Equal("HE\nLLO", models[0].Text); - } - - [Theory] - [InlineData(0x1a, 0x02, '納')] - [InlineData(0x1b, 0x00, '竜')] - [InlineData(0x1c, 0x00, '操')] - [InlineData(0x1d, 0x00, '猫')] - [InlineData(0x1f, 0x00, '漠')] - public void DecodeJapaneseEventTextCorrectly(byte command, byte data, char expected) - { - var decoded = Encoders.JapaneseEvent.Decode(new byte[] { command, data }); - - Assert.NotEmpty(decoded); - Assert.Equal(expected, decoded.Single().Text.Single()); - } - - [Theory] - [InlineData("\x19\x25\x55", "プー")] - [InlineData("\x19\x16\xe0\x01\xf8\x55\xf3\x66\x66", "ゼア ノート--")] - public void DecodeJapaneseEventTextWordCorrectly(string data, string expected) - { - var decoded = Encoders.JapaneseEvent.Decode( - System.Text.Encoding.GetEncoding("latin1").GetBytes(data) - ); - - Assert.NotEmpty(decoded); - Assert.Equal(expected, decoded.Single().Text); - } - } -} +using OpenKh.Kh2.Messages; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class MsgEncoderTests + { + public enum EncoderType + { + InternationalSystem, + JapaneseEvent, + JapaneseSystem, + TurkishSystem + }; + + [Fact] + public void DecodeTextCorrectly() + { + var decoded = Encoders.InternationalSystem.Decode(new byte[] + { + 0x35, 0x9E, 0xA5, 0xA5, 0xA8, 0x01, 0xB0, 0xA8, 0xAB, 0xA5, 0x9D, 0x48, 0x00 + }); + + Assert.Equal(MessageCommand.PrintText, decoded[0].Command); + Assert.Equal("Hello world!", decoded[0].Text); + Assert.Equal(MessageCommand.End, decoded[1].Command); + } + + [Fact] + public void DecodeComplexTextCorrectly() + { + var decoded = Encoders.InternationalSystem.Decode(new byte[] + { + 0x90, 0x7a, 0x91, 0x00 + }); + + Assert.Equal(MessageCommand.PrintText, decoded[0].Command); + Assert.Equal("0", decoded[0].Text); + Assert.Equal(MessageCommand.PrintComplex, decoded[1].Command); + Assert.Equal("VII", decoded[1].Text); + Assert.Equal(MessageCommand.PrintText, decoded[2].Command); + Assert.Equal("1", decoded[2].Text); + Assert.Equal(MessageCommand.End, decoded[3].Command); + } + + [Fact] + public void DecodeIconCorrectly() + { + var decoded = Encoders.InternationalSystem.Decode(new byte[] + { + 0x09, 0x00, 0x09, 0x01, 0x00 + }); + + Assert.Equal(MessageCommand.PrintIcon, decoded[0].Command); + Assert.Equal(0, decoded[0].Data[0]); + Assert.Equal(MessageCommand.PrintIcon, decoded[1].Command); + Assert.Equal(1, decoded[1].Data[0]); + Assert.Equal(MessageCommand.End, decoded[2].Command); + } + + [Fact] + public void DecodeColorCommandCorrectly() + { + var decoded = Encoders.InternationalSystem.Decode(new byte[] + { + 0x07, 0x00, 0xFF, 0x00, 0x00, 0x00 + }); + + Assert.Equal(MessageCommand.Color, decoded[0].Command); + Assert.Equal(0, decoded[0].Data[0]); + Assert.Equal(0xFF, decoded[0].Data[1]); + Assert.Equal(0, decoded[0].Data[2]); + Assert.Equal(0, decoded[0].Data[3]); + Assert.Equal(MessageCommand.End, decoded[1].Command); + } + + [Theory] + [InlineData(0x03, "0123456789")] + [InlineData(0x04, "123456789")] + [InlineData(0x05, "6789")] + [InlineData(0x06, "123456789")] + [InlineData(0x07, "456789")] + [InlineData(0x08, "3456789")] + [InlineData(0x09, "123456789")] + [InlineData(0x0a, "123456789")] + [InlineData(0x0b, "123456789")] + [InlineData(0x0c, "123456789")] + [InlineData(0x0d, "0123456789")] + [InlineData(0x0e, "123456789")] + [InlineData(0x0f, "56789")] + //[InlineData(0x10, "")] + [InlineData(0x11, "456789")] + [InlineData(0x12, "23456789")] + [InlineData(0x13, "456789")] + [InlineData(0x14, "23456789")] + [InlineData(0x15, "23456789")] + [InlineData(0x16, "123456789")] + //[InlineData(0x17, "")] + [InlineData(0x18, "23456789")] + public void DecodeTheRightAmountOfCharacters(byte commandId, string expectedText) + { + var decoded = Encoders.InternationalSystem.Decode(new byte[] + { + commandId, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99 + }); + + Assert.Equal(expectedText, decoded[1].Text); + } + + [Theory] + [InlineData("I", 0x74)] + [InlineData("II", 0x75)] + [InlineData("III", 0x76)] + [InlineData("IV", 0x77)] + [InlineData("V", 0x78)] + [InlineData("VI", 0x79)] + [InlineData("♪", 0x8e)] + public void EncodeComplexTextCorrectly(string value, byte expected) + { + var actual = Encoders.InternationalSystem.Encode(new List + { + new MessageCommandModel + { + Command = MessageCommand.PrintComplex, + Text = value + } + })[0]; + + Assert.Equal(expected, actual); + } + + [Fact] + public void SimpleReEncodeTest() + { + var expected = new byte[] + { + 0x01, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, + 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, + }; + var decoded = Encoders.InternationalSystem.Decode(expected); + var encoded = Encoders.InternationalSystem.Encode(decoded); + + Assert.Equal(expected, encoded); + } + + [Theory] + [InlineData(0x02)] + [InlineData(0x03)] + [InlineData(0x04)] + [InlineData(0x05)] + [InlineData(0x06)] + [InlineData(0x07)] + [InlineData(0x08)] + [InlineData(0x09)] + [InlineData(0x0a)] + [InlineData(0x0b)] + [InlineData(0x0c)] + [InlineData(0x0d)] + [InlineData(0x0e)] + [InlineData(0x0f)] + //[InlineData(0x10)] + [InlineData(0x11)] + [InlineData(0x12)] + [InlineData(0x13)] + [InlineData(0x14)] + [InlineData(0x15)] + [InlineData(0x16)] + //[InlineData(0x17)] + [InlineData(0x18)] + public void AdvancedReEncodeTest(byte commandByte) + { + var expected = new byte[] + { + commandByte, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, + 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, + }; + var decoded = Encoders.InternationalSystem.Decode(expected); + var encoded = Encoders.InternationalSystem.Encode(decoded); + + Assert.Equal(expected, encoded); + } + + [Theory] + [InlineData(0x1a, 0x00, '珍')] + [InlineData(0x1b, 0x00, '何')] + [InlineData(0x1c, 0x00, '係')] + [InlineData(0x1e, 0x40, '外')] + [InlineData(0x1f, 0x00, '銅')] + [InlineData(0x1f, 0xc7, '念')] + [InlineData(0x1f, 0xc8, '還')] + [InlineData(0x1f, 0xDF, '夕')] + public void DecodeJapaneseSystemTextCorrectly(byte command, byte data, char expected) + { + var decoded = Encoders.JapaneseSystem.Decode(new byte[] { command, data }); + + Assert.NotEmpty(decoded); + Assert.Equal(expected, decoded.Single().Text.Single()); + } + + [Theory] + [InlineData("\x19\x0a\x19\x1e\x55", "ロビー")] + public void DecodeJapaneseSystemTextWordCorrectly(string data, string expected) + { + var decoded = Encoders.JapaneseSystem.Decode( + System.Text.Encoding.GetEncoding("latin1").GetBytes(data) + ); + + Assert.NotEmpty(decoded); + Assert.Equal(expected, decoded.Single().Text); + } + + [Theory] + [InlineData(0x84, 0x00, "III")] + [InlineData(0x85, 0x00, "VII")] + [InlineData(0x86, 0x00, "VIII")] + [InlineData(0x87, 0x00, "X")] + [InlineData(0x19, 0xb2, "XIII")] + [InlineData(0x1b, 0x54, "I")] + [InlineData(0x1b, 0x55, "II")] + [InlineData(0x1b, 0x56, "IV")] + [InlineData(0x1b, 0x57, "V")] + [InlineData(0x1b, 0x58, "VI")] + [InlineData(0x1b, 0x59, "IX")] + [InlineData(0x1e, 0x66, "IV")] + public void DecodeRomanNumbersFromJapaneseSystemTable(byte command, byte data, string expected) + { + var decoded = Encoders.JapaneseSystem.Decode(new byte[] { command, data }); + + Assert.NotEmpty(decoded); + Assert.Equal(MessageCommand.PrintComplex, decoded.First().Command); + Assert.Equal(expected, decoded.First().Text); + } + + [Theory] + [InlineData(0x84, 0x00, "III")] + [InlineData(0x85, 0x00, "VII")] + [InlineData(0x86, 0x00, "VIII")] + [InlineData(0x87, 0x00, "X")] + [InlineData(0x19, 0xb2, "XIII")] + [InlineData(0x1b, 0x54, "I")] + [InlineData(0x1b, 0x55, "II")] + [InlineData(0x1b, 0x56, "IV")] + [InlineData(0x1b, 0x57, "V")] + [InlineData(0x1b, 0x58, "VI")] + [InlineData(0x1b, 0x59, "IX")] + public void EncodeRomanNumbersForJapaneseSystemTable(byte command, byte data, string textSource) + { + var encoded = Encoders.JapaneseSystem.Encode(new List + { + new MessageCommandModel + { + Command = MessageCommand.PrintComplex, + Text = textSource + } + }); + + if (data == 0) + Assert.Equal(new byte[] { command }, encoded); + else + Assert.Equal(new byte[] { command, data }, encoded); + } + + [Theory] + [InlineData(EncoderType.InternationalSystem)] + [InlineData(EncoderType.JapaneseEvent)] + [InlineData(EncoderType.JapaneseSystem)] + [InlineData(EncoderType.TurkishSystem)] + public void EncodeNewLineCharacterCorrectly(EncoderType encoderType) + { + var encoder = new IMessageEncode[] + { + Encoders.InternationalSystem, + Encoders.JapaneseEvent, + Encoders.JapaneseSystem, + Encoders.TurkishSystem + }[(int)encoderType]; + + var encoded = encoder.Encode(new List + { + new MessageCommandModel + { + Command = MessageCommand.PrintText, + Text = "HE\nLLO", + } + }); + Assert.Equal(new byte[] { 0x35, 0x32, 0x02, 0x39, 0x39, 0x3C }, encoded); + } + + [Theory] + [InlineData(EncoderType.InternationalSystem)] + [InlineData(EncoderType.JapaneseEvent)] + [InlineData(EncoderType.JapaneseSystem)] + [InlineData(EncoderType.TurkishSystem)] + public void DecodeNewLineCharacterCorrectly(EncoderType encoderType) + { + var decoder = new IMessageDecode[] + { + Encoders.InternationalSystem, + Encoders.JapaneseEvent, + Encoders.JapaneseSystem, + Encoders.TurkishSystem + }[(int)encoderType]; + + var models = decoder.Decode(new byte[] { 0x35, 0x32, 0x02, 0x39, 0x39, 0x3C }); + Assert.Single(models); + Assert.Equal("HE\nLLO", models[0].Text); + } + + [Theory] + [InlineData(0x1a, 0x02, '納')] + [InlineData(0x1b, 0x00, '竜')] + [InlineData(0x1c, 0x00, '操')] + [InlineData(0x1d, 0x00, '猫')] + [InlineData(0x1f, 0x00, '漠')] + public void DecodeJapaneseEventTextCorrectly(byte command, byte data, char expected) + { + var decoded = Encoders.JapaneseEvent.Decode(new byte[] { command, data }); + + Assert.NotEmpty(decoded); + Assert.Equal(expected, decoded.Single().Text.Single()); + } + + [Theory] + [InlineData("\x19\x25\x55", "プー")] + [InlineData("\x19\x16\xe0\x01\xf8\x55\xf3\x66\x66", "ゼア ノート--")] + public void DecodeJapaneseEventTextWordCorrectly(string data, string expected) + { + var decoded = Encoders.JapaneseEvent.Decode( + System.Text.Encoding.GetEncoding("latin1").GetBytes(data) + ); + + Assert.NotEmpty(decoded); + Assert.Equal(expected, decoded.Single().Text); + } + } +} diff --git a/OpenKh.Tests/kh2/MsgSerializerTests.cs b/OpenKh.Tests/kh2/MsgSerializerTests.cs index 20bbe4f1f..17f169700 100644 --- a/OpenKh.Tests/kh2/MsgSerializerTests.cs +++ b/OpenKh.Tests/kh2/MsgSerializerTests.cs @@ -1,253 +1,253 @@ -using OpenKh.Common.Exceptions; -using OpenKh.Kh2.Messages; -using System.IO; -using System.Linq; -using System.Xml.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class MsgSerializerTests - { - private const SaveOptions xmlFormatting = SaveOptions.DisableFormatting; - private const int MessageId = 12345; - - [Fact] - public void SerializePlainSimpleText() - { - var entry = new MessageCommandModel - { - Command = MessageCommand.PrintText, - Text = "Hello world!" - }; - - var element = MsgSerializer.SerializeText(new[] { entry }); - Assert.Equal(entry.Text, element); - } - - [Fact] - public void SerializePlainComplexText() - { - var entries = new[] - { - new MessageCommandModel - { - Command = MessageCommand.PrintText, - Text = "Hey " - }, - new MessageCommandModel - { - Command = MessageCommand.PrintComplex, - Text = "VII" - }, - new MessageCommandModel - { - Command = MessageCommand.PrintText, - Text = " complex!\n" - }, - }; - - var element = MsgSerializer.SerializeText(entries); - Assert.Equal("Hey {VII} complex!\n", element); - } - - [Fact] - public void SerializePlainCommand() - { - var entries = new[] - { - new MessageCommandModel - { - Command = MessageCommand.TextScale, - Data = new byte[] { 0x22 } - }, - }; - - var element = MsgSerializer.SerializeText(entries); - Assert.Equal("{:scale 34}", element); - } - - [Theory] - [InlineData("hello", new byte[] { 0xA1, 0x9E, 0xA5, 0xA5, 0xA8, 0x00 })] - [InlineData("7: {VII}", new byte[] { 0x97, 0x52, 0x01, 0x7A, 0x00 })] - [InlineData("{:reset}", new byte[] { 0x03, 0x00 })] - [InlineData("{:scale 22}hey{:reset}", new byte[] { 0x0A, 0x16, 0xA1, 0x9E, 0xB2, 0x03, 0x00 })] - public void DeserializePlainText(string value, byte[] expected) - { - var entries = MsgSerializer.DeserializeText(value); - using (var stream = new MemoryStream()) - { - var actual = Encoders.InternationalSystem.Encode(entries.ToList()); - Assert.Equal(expected, actual); - } - } - - [Theory] - [InlineData("hello", 2, "hello")] - [InlineData("hello{VII}", 3, "hello")] - [InlineData("{VII}world", 3, "world")] - [InlineData("hello{VII}world", 4, "hello;world")] - [InlineData("hello{:reset}world", 4, "hello;world")] - public void DeserializeCorrectNumberOfMsgEntries(string value, int expectedEntries, string expectedText) - { - var entries = MsgSerializer.DeserializeText(value).ToList(); - Assert.Equal(expectedEntries, entries.Count); - - var index = 0; - foreach (var word in expectedText.Split(';')) - { - if (entries[index].Command == MessageCommand.PrintText) - Assert.Equal(entries[index].Text, word); - index++; - } - } - - [Theory] - [InlineData("hello{:reset")] - [InlineData("hello{:reset hello")] - [InlineData("hello{")] - [InlineData("{hello")] - [InlineData("{")] - public void ThrowsExceptionForParseError(string value) - { - Assert.Throws(() => MsgSerializer.DeserializeText(value)); - } - - [Fact] - public void SerializeXmlSimpleText() - { - var entry = new MessageCommandModel - { - Command = MessageCommand.PrintText, - Text = "Hello world!" - }; - - var element = MsgSerializer.SerializeXEntries(MessageId, new[] { entry }); - var content = new XElement("message", - new XAttribute("id", MessageId), - new XElement("text", "Hello world!") - ); - Assert.Equal(content.ToString(xmlFormatting), element.ToString(xmlFormatting)); - } - - [Theory] - [InlineData(0, "item-consumable")] - [InlineData(1, "item-tent")] - [InlineData(2, "item-key")] - [InlineData(3, "ability-unequip")] - public void SerializeXmlIcon(byte id, string content) - { - var entry = new MessageCommandModel - { - Command = MessageCommand.PrintIcon, - Data = new[] { id } - }; - - var actual = MsgSerializer.SerializeXEntries(MessageId, new[] { entry }); - var expected = new XElement("message", - new XAttribute("id", MessageId), - new XElement("icon", new XAttribute("value", content)) - ); - Assert.Equal(expected.ToString(xmlFormatting), actual.ToString(xmlFormatting)); - } - - [Theory] - [InlineData(new byte[] { 0x11, 0x00, 0x00, 0x00, 0x00 }, "{:position 0,0}")] - [InlineData(new byte[] { 0x11, 0xff, 0xff, 0xff, 0x7f }, "{:position -1,32767}")] - public void SerializeTextPositionCommand(byte[] data, string expected) - { - var decoded = Encoders.InternationalSystem.Decode(data); - var actual = MsgSerializer.SerializeText(decoded); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(new byte[] { 0x11, 0x00, 0x00, 0x00, 0x00, 0x00 }, "{:position 0,0}")] - [InlineData(new byte[] { 0x11, 0xff, 0xff, 0xff, 0x7f, 0x00 }, "{:position -1,32767}")] - public void DeserializeTextPositionCommand(byte[] expected, string text) - { - var commands = MsgSerializer.DeserializeText(text).ToList(); - var actual = Encoders.InternationalSystem.Encode(commands); - Assert.Equal(expected, actual); - } - - [Fact] - public void DeserializeNewLine() - { - var commands = MsgSerializer.DeserializeText("hello\nworld!").ToArray(); - Assert.Equal(MessageCommand.PrintText, commands[0].Command); - Assert.Equal("hello\nworld!", commands[0].Text); - } - - [Fact] - public void DeserializeTabulation() - { - var commands = MsgSerializer.DeserializeText("hello\tworld!").ToArray(); - Assert.Equal(MessageCommand.PrintText, commands[0].Command); - Assert.Equal("hello", commands[0].Text); - Assert.Equal(MessageCommand.Tabulation, commands[1].Command); - Assert.Equal(MessageCommand.PrintText, commands[2].Command); - Assert.Equal("world!", commands[2].Text); - } - - [Theory] - [InlineData(new byte[] { 0x0b, 0x90 }, "{:width 144}")] - [InlineData(new byte[] { 0x0b, 0x50 }, "{:width 80}")] - public void SerializeTextScale(byte[] data, string expected) - { - var commands = Encoders.InternationalSystem.Decode(data); - var actual = MsgSerializer.SerializeText(commands); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData("{:width 144}", new byte[] { 0x0b, 0x90, 0x00 })] - [InlineData("{:width 80}", new byte[] { 0x0b, 0x50, 0x00 })] - public void DeserializeTextScale(string text, byte[] expected) - { - var commands = MsgSerializer.DeserializeText(text); - var actual = Encoders.InternationalSystem.Encode(commands.ToList()); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(new byte[] { 0x17, 0x0c, 0xdd }, "{:delayandfade 0C DD}")] - [InlineData(new byte[] { 0x17, 0x01, 0x02 }, "{:delayandfade 01 02}")] - public void SerializeDelayAndFade(byte[] data, string expected) - { - var commands = Encoders.InternationalSystem.Decode(data); - var actual = MsgSerializer.SerializeText(commands); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData("{:delayandfade 0C DD}", new byte[] { 0x17, 0x0c, 0xdd, 0x00 })] - [InlineData("{:delayandfade 01 02}", new byte[] { 0x17, 0x01, 0x02, 0x00 })] - public void DeserializeDelayAndFade(string text, byte[] expected) - { - var commands = MsgSerializer.DeserializeText(text); - var actual = Encoders.InternationalSystem.Encode(commands.ToList()); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(new byte[] { 0x71 }, "{:unk 71}")] - [InlineData(new byte[] { 0x72 }, "{:unk 72}")] - public void SerializeTextUnknown(byte[] data, string expected) - { - var commands = Encoders.InternationalSystem.Decode(data); - var actual = MsgSerializer.SerializeText(commands); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData("{:unk 71}", new byte[] { 0x71, 0x00 })] - [InlineData("{:unk 72}", new byte[] { 0x72, 0x00 })] - public void DeserializeTextUnknown(string text, byte[] expected) - { - var commands = MsgSerializer.DeserializeText(text); - var actual = Encoders.InternationalSystem.Encode(commands.ToList()); - Assert.Equal(expected, actual); - } - } -} +using OpenKh.Common.Exceptions; +using OpenKh.Kh2.Messages; +using System.IO; +using System.Linq; +using System.Xml.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class MsgSerializerTests + { + private const SaveOptions xmlFormatting = SaveOptions.DisableFormatting; + private const int MessageId = 12345; + + [Fact] + public void SerializePlainSimpleText() + { + var entry = new MessageCommandModel + { + Command = MessageCommand.PrintText, + Text = "Hello world!" + }; + + var element = MsgSerializer.SerializeText(new[] { entry }); + Assert.Equal(entry.Text, element); + } + + [Fact] + public void SerializePlainComplexText() + { + var entries = new[] + { + new MessageCommandModel + { + Command = MessageCommand.PrintText, + Text = "Hey " + }, + new MessageCommandModel + { + Command = MessageCommand.PrintComplex, + Text = "VII" + }, + new MessageCommandModel + { + Command = MessageCommand.PrintText, + Text = " complex!\n" + }, + }; + + var element = MsgSerializer.SerializeText(entries); + Assert.Equal("Hey {VII} complex!\n", element); + } + + [Fact] + public void SerializePlainCommand() + { + var entries = new[] + { + new MessageCommandModel + { + Command = MessageCommand.TextScale, + Data = new byte[] { 0x22 } + }, + }; + + var element = MsgSerializer.SerializeText(entries); + Assert.Equal("{:scale 34}", element); + } + + [Theory] + [InlineData("hello", new byte[] { 0xA1, 0x9E, 0xA5, 0xA5, 0xA8, 0x00 })] + [InlineData("7: {VII}", new byte[] { 0x97, 0x52, 0x01, 0x7A, 0x00 })] + [InlineData("{:reset}", new byte[] { 0x03, 0x00 })] + [InlineData("{:scale 22}hey{:reset}", new byte[] { 0x0A, 0x16, 0xA1, 0x9E, 0xB2, 0x03, 0x00 })] + public void DeserializePlainText(string value, byte[] expected) + { + var entries = MsgSerializer.DeserializeText(value); + using (var stream = new MemoryStream()) + { + var actual = Encoders.InternationalSystem.Encode(entries.ToList()); + Assert.Equal(expected, actual); + } + } + + [Theory] + [InlineData("hello", 2, "hello")] + [InlineData("hello{VII}", 3, "hello")] + [InlineData("{VII}world", 3, "world")] + [InlineData("hello{VII}world", 4, "hello;world")] + [InlineData("hello{:reset}world", 4, "hello;world")] + public void DeserializeCorrectNumberOfMsgEntries(string value, int expectedEntries, string expectedText) + { + var entries = MsgSerializer.DeserializeText(value).ToList(); + Assert.Equal(expectedEntries, entries.Count); + + var index = 0; + foreach (var word in expectedText.Split(';')) + { + if (entries[index].Command == MessageCommand.PrintText) + Assert.Equal(entries[index].Text, word); + index++; + } + } + + [Theory] + [InlineData("hello{:reset")] + [InlineData("hello{:reset hello")] + [InlineData("hello{")] + [InlineData("{hello")] + [InlineData("{")] + public void ThrowsExceptionForParseError(string value) + { + Assert.Throws(() => MsgSerializer.DeserializeText(value)); + } + + [Fact] + public void SerializeXmlSimpleText() + { + var entry = new MessageCommandModel + { + Command = MessageCommand.PrintText, + Text = "Hello world!" + }; + + var element = MsgSerializer.SerializeXEntries(MessageId, new[] { entry }); + var content = new XElement("message", + new XAttribute("id", MessageId), + new XElement("text", "Hello world!") + ); + Assert.Equal(content.ToString(xmlFormatting), element.ToString(xmlFormatting)); + } + + [Theory] + [InlineData(0, "item-consumable")] + [InlineData(1, "item-tent")] + [InlineData(2, "item-key")] + [InlineData(3, "ability-unequip")] + public void SerializeXmlIcon(byte id, string content) + { + var entry = new MessageCommandModel + { + Command = MessageCommand.PrintIcon, + Data = new[] { id } + }; + + var actual = MsgSerializer.SerializeXEntries(MessageId, new[] { entry }); + var expected = new XElement("message", + new XAttribute("id", MessageId), + new XElement("icon", new XAttribute("value", content)) + ); + Assert.Equal(expected.ToString(xmlFormatting), actual.ToString(xmlFormatting)); + } + + [Theory] + [InlineData(new byte[] { 0x11, 0x00, 0x00, 0x00, 0x00 }, "{:position 0,0}")] + [InlineData(new byte[] { 0x11, 0xff, 0xff, 0xff, 0x7f }, "{:position -1,32767}")] + public void SerializeTextPositionCommand(byte[] data, string expected) + { + var decoded = Encoders.InternationalSystem.Decode(data); + var actual = MsgSerializer.SerializeText(decoded); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(new byte[] { 0x11, 0x00, 0x00, 0x00, 0x00, 0x00 }, "{:position 0,0}")] + [InlineData(new byte[] { 0x11, 0xff, 0xff, 0xff, 0x7f, 0x00 }, "{:position -1,32767}")] + public void DeserializeTextPositionCommand(byte[] expected, string text) + { + var commands = MsgSerializer.DeserializeText(text).ToList(); + var actual = Encoders.InternationalSystem.Encode(commands); + Assert.Equal(expected, actual); + } + + [Fact] + public void DeserializeNewLine() + { + var commands = MsgSerializer.DeserializeText("hello\nworld!").ToArray(); + Assert.Equal(MessageCommand.PrintText, commands[0].Command); + Assert.Equal("hello\nworld!", commands[0].Text); + } + + [Fact] + public void DeserializeTabulation() + { + var commands = MsgSerializer.DeserializeText("hello\tworld!").ToArray(); + Assert.Equal(MessageCommand.PrintText, commands[0].Command); + Assert.Equal("hello", commands[0].Text); + Assert.Equal(MessageCommand.Tabulation, commands[1].Command); + Assert.Equal(MessageCommand.PrintText, commands[2].Command); + Assert.Equal("world!", commands[2].Text); + } + + [Theory] + [InlineData(new byte[] { 0x0b, 0x90 }, "{:width 144}")] + [InlineData(new byte[] { 0x0b, 0x50 }, "{:width 80}")] + public void SerializeTextScale(byte[] data, string expected) + { + var commands = Encoders.InternationalSystem.Decode(data); + var actual = MsgSerializer.SerializeText(commands); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("{:width 144}", new byte[] { 0x0b, 0x90, 0x00 })] + [InlineData("{:width 80}", new byte[] { 0x0b, 0x50, 0x00 })] + public void DeserializeTextScale(string text, byte[] expected) + { + var commands = MsgSerializer.DeserializeText(text); + var actual = Encoders.InternationalSystem.Encode(commands.ToList()); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(new byte[] { 0x17, 0x0c, 0xdd }, "{:delayandfade 0C DD}")] + [InlineData(new byte[] { 0x17, 0x01, 0x02 }, "{:delayandfade 01 02}")] + public void SerializeDelayAndFade(byte[] data, string expected) + { + var commands = Encoders.InternationalSystem.Decode(data); + var actual = MsgSerializer.SerializeText(commands); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("{:delayandfade 0C DD}", new byte[] { 0x17, 0x0c, 0xdd, 0x00 })] + [InlineData("{:delayandfade 01 02}", new byte[] { 0x17, 0x01, 0x02, 0x00 })] + public void DeserializeDelayAndFade(string text, byte[] expected) + { + var commands = MsgSerializer.DeserializeText(text); + var actual = Encoders.InternationalSystem.Encode(commands.ToList()); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(new byte[] { 0x71 }, "{:unk 71}")] + [InlineData(new byte[] { 0x72 }, "{:unk 72}")] + public void SerializeTextUnknown(byte[] data, string expected) + { + var commands = Encoders.InternationalSystem.Decode(data); + var actual = MsgSerializer.SerializeText(commands); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("{:unk 71}", new byte[] { 0x71, 0x00 })] + [InlineData("{:unk 72}", new byte[] { 0x72, 0x00 })] + public void DeserializeTextUnknown(string text, byte[] expected) + { + var commands = MsgSerializer.DeserializeText(text); + var actual = Encoders.InternationalSystem.Encode(commands.ToList()); + Assert.Equal(expected, actual); + } + } +} diff --git a/OpenKh.Tests/kh2/MsgTests.cs b/OpenKh.Tests/kh2/MsgTests.cs index 87257dd54..bda576fa7 100644 --- a/OpenKh.Tests/kh2/MsgTests.cs +++ b/OpenKh.Tests/kh2/MsgTests.cs @@ -1,189 +1,189 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.Collections.Generic; -using System.IO; -using Xunit; -using Xunit.Sdk; - -namespace OpenKh.Tests.kh2 -{ - public class MsgTests - { - private readonly string FilePath = "kh2/res/titl.bin"; - - [Fact] - public void IsValidTest() - { - using (var stream = new MemoryStream()) - { - stream.WriteByte(0x01); - stream.WriteByte(0x00); - stream.WriteByte(0x00); - stream.WriteByte(0x00); - stream.Position = 0; - Assert.True(Msg.IsValid(stream)); - } - } - - [Fact] - public void IsNotValidTest() - { - using (var stream = new MemoryStream()) - { - stream.WriteByte(0x02); - stream.WriteByte(0x00); - stream.WriteByte(0x00); - stream.WriteByte(0x00); - stream.Position = 0; - Assert.False(Msg.IsValid(stream)); - } - } - - [Fact] - public void OpenThrowsAnExceptionIfTheStreamIsNotValid() - { - using (var stream = new MemoryStream()) - { - stream.WriteByte(0x02); - stream.WriteByte(0x00); - stream.WriteByte(0x00); - stream.WriteByte(0x00); - stream.Position = 0; - Assert.Throws(() => Msg.Read(stream)); - } - } - - [Fact] - public void ReadsRightAmountOfEntries() => - File.OpenRead(FilePath).Using(stream => - { - var entries = Msg.Read(stream); - Assert.Equal(694, entries.Count); - }); - - [Fact] - public void ReadsIdCorrectly() => - File.OpenRead(FilePath).Using(stream => - { - var entries = Msg.Read(stream); - Assert.Equal(20233, entries[0].Id); - Assert.Equal(20234, entries[1].Id); - }); - - [Fact] - public void ReadsTextDataCorrectly() => - File.OpenRead(FilePath).Using(stream => - { - var entries = Msg.Read(stream); - Assert.Equal(19, entries[0].Data.Length); - Assert.Equal(7, entries[1].Data.Length); - }); - - [Fact] - public void WriteAndReadCorrecty() => - File.OpenRead(FilePath).Using(stream => - { - var expected = new BinaryReader(stream).ReadBytes((int)stream.Length); - var entries = Msg.Read(new MemoryStream(expected)); - byte[] actual; - - using (var outStream = new MemoryStream()) - { - Msg.Write(outStream, entries); - outStream.Position = 0; - actual = new BinaryReader(outStream).ReadBytes((int)outStream.Length); - } - - Assert.Equal(expected, actual); - }); - - [Fact] - public void WriteOptimized() - { - var stream = new MemoryStream(); - var msgSource = new List() - { - new Msg.Entry - { - Id = 100, - Data = new byte[] { 0x22, 0x23, 0x24, 0x00 } // this will be optimized with ID 101 - }, - new Msg.Entry - { - Id = 101, - Data = new byte[] { 0x20, 0x21, 0x22, 0x23, 0x24, 0x00 } - }, - new Msg.Entry - { - Id = 102, - Data = new byte[] { 0x23, 0x24, 0x25, 0x00 } - }, - }; - Msg.WriteOptimized(stream, msgSource); - - SkipHeader(stream); - AssertMsgLbaEntry(stream, 100, 34); - AssertMsgLbaEntry(stream, 101, 32); - AssertMsgLbaEntry(stream, 102, 38); - - stream.Position = 0; - var msg = Msg.Read(stream); - Assert.Equal(msgSource[0].Data, msg[0].Data); - Assert.Equal(msgSource[1].Data, msg[1].Data); - Assert.Equal(msgSource[2].Data, msg[2].Data); - } - - [Fact] - public void WriteOptimizedSecondScenario() - { - var stream = new MemoryStream(); - var msgSource = new List() - { - new Msg.Entry - { - Id = 100, - Data = new byte[] { 0x22, 0x23, 0x00 } - }, - new Msg.Entry - { - Id = 101, - Data = new byte[] { 0x22, 0x23, 0x00 } - }, - new Msg.Entry - { - Id = 102, - Data = new byte[] { 0x22, 0x23, 0x00 } - }, - }; - Msg.WriteOptimized(stream, msgSource); - - SkipHeader(stream); - AssertMsgLbaEntry(stream, 100, 32); - AssertMsgLbaEntry(stream, 101, 32); - AssertMsgLbaEntry(stream, 102, 32); - - stream.Position = 0; - var msg = Msg.Read(stream); - Assert.Equal(msgSource[0].Data, msg[0].Data); - Assert.Equal(msgSource[1].Data, msg[1].Data); - Assert.Equal(msgSource[2].Data, msg[2].Data); - } - - private void SkipHeader(Stream stream) - { - stream.Position = 8; - } - - private void AssertMsgLbaEntry(Stream stream, int expectedId, int expectedPosition) - { - var actualId = stream.ReadInt32(); - var actualOffset = stream.ReadInt32(); - - if (expectedId != actualId) - throw new EqualException(expectedId, actualId); - - if (expectedPosition != actualOffset) - throw new EqualException(expectedPosition, actualOffset); - } - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.Collections.Generic; +using System.IO; +using Xunit; +using Xunit.Sdk; + +namespace OpenKh.Tests.kh2 +{ + public class MsgTests + { + private readonly string FilePath = "kh2/res/titl.bin"; + + [Fact] + public void IsValidTest() + { + using (var stream = new MemoryStream()) + { + stream.WriteByte(0x01); + stream.WriteByte(0x00); + stream.WriteByte(0x00); + stream.WriteByte(0x00); + stream.Position = 0; + Assert.True(Msg.IsValid(stream)); + } + } + + [Fact] + public void IsNotValidTest() + { + using (var stream = new MemoryStream()) + { + stream.WriteByte(0x02); + stream.WriteByte(0x00); + stream.WriteByte(0x00); + stream.WriteByte(0x00); + stream.Position = 0; + Assert.False(Msg.IsValid(stream)); + } + } + + [Fact] + public void OpenThrowsAnExceptionIfTheStreamIsNotValid() + { + using (var stream = new MemoryStream()) + { + stream.WriteByte(0x02); + stream.WriteByte(0x00); + stream.WriteByte(0x00); + stream.WriteByte(0x00); + stream.Position = 0; + Assert.Throws(() => Msg.Read(stream)); + } + } + + [Fact] + public void ReadsRightAmountOfEntries() => + File.OpenRead(FilePath).Using(stream => + { + var entries = Msg.Read(stream); + Assert.Equal(694, entries.Count); + }); + + [Fact] + public void ReadsIdCorrectly() => + File.OpenRead(FilePath).Using(stream => + { + var entries = Msg.Read(stream); + Assert.Equal(20233, entries[0].Id); + Assert.Equal(20234, entries[1].Id); + }); + + [Fact] + public void ReadsTextDataCorrectly() => + File.OpenRead(FilePath).Using(stream => + { + var entries = Msg.Read(stream); + Assert.Equal(19, entries[0].Data.Length); + Assert.Equal(7, entries[1].Data.Length); + }); + + [Fact] + public void WriteAndReadCorrecty() => + File.OpenRead(FilePath).Using(stream => + { + var expected = new BinaryReader(stream).ReadBytes((int)stream.Length); + var entries = Msg.Read(new MemoryStream(expected)); + byte[] actual; + + using (var outStream = new MemoryStream()) + { + Msg.Write(outStream, entries); + outStream.Position = 0; + actual = new BinaryReader(outStream).ReadBytes((int)outStream.Length); + } + + Assert.Equal(expected, actual); + }); + + [Fact] + public void WriteOptimized() + { + var stream = new MemoryStream(); + var msgSource = new List() + { + new Msg.Entry + { + Id = 100, + Data = new byte[] { 0x22, 0x23, 0x24, 0x00 } // this will be optimized with ID 101 + }, + new Msg.Entry + { + Id = 101, + Data = new byte[] { 0x20, 0x21, 0x22, 0x23, 0x24, 0x00 } + }, + new Msg.Entry + { + Id = 102, + Data = new byte[] { 0x23, 0x24, 0x25, 0x00 } + }, + }; + Msg.WriteOptimized(stream, msgSource); + + SkipHeader(stream); + AssertMsgLbaEntry(stream, 100, 34); + AssertMsgLbaEntry(stream, 101, 32); + AssertMsgLbaEntry(stream, 102, 38); + + stream.Position = 0; + var msg = Msg.Read(stream); + Assert.Equal(msgSource[0].Data, msg[0].Data); + Assert.Equal(msgSource[1].Data, msg[1].Data); + Assert.Equal(msgSource[2].Data, msg[2].Data); + } + + [Fact] + public void WriteOptimizedSecondScenario() + { + var stream = new MemoryStream(); + var msgSource = new List() + { + new Msg.Entry + { + Id = 100, + Data = new byte[] { 0x22, 0x23, 0x00 } + }, + new Msg.Entry + { + Id = 101, + Data = new byte[] { 0x22, 0x23, 0x00 } + }, + new Msg.Entry + { + Id = 102, + Data = new byte[] { 0x22, 0x23, 0x00 } + }, + }; + Msg.WriteOptimized(stream, msgSource); + + SkipHeader(stream); + AssertMsgLbaEntry(stream, 100, 32); + AssertMsgLbaEntry(stream, 101, 32); + AssertMsgLbaEntry(stream, 102, 32); + + stream.Position = 0; + var msg = Msg.Read(stream); + Assert.Equal(msgSource[0].Data, msg[0].Data); + Assert.Equal(msgSource[1].Data, msg[1].Data); + Assert.Equal(msgSource[2].Data, msg[2].Data); + } + + private void SkipHeader(Stream stream) + { + stream.Position = 8; + } + + private void AssertMsgLbaEntry(Stream stream, int expectedId, int expectedPosition) + { + var actualId = stream.ReadInt32(); + var actualOffset = stream.ReadInt32(); + + if (expectedId != actualId) + throw new EqualException(expectedId, actualId); + + if (expectedPosition != actualOffset) + throw new EqualException(expectedPosition, actualOffset); + } + } +} diff --git a/OpenKh.Tests/kh2/ObjectCollisionTests.cs b/OpenKh.Tests/kh2/ObjectCollisionTests.cs index a29b718b7..b5d8ff335 100644 --- a/OpenKh.Tests/kh2/ObjectCollisionTests.cs +++ b/OpenKh.Tests/kh2/ObjectCollisionTests.cs @@ -1,28 +1,28 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class ObjectCollisionTests - { - private const string FileName = "kh2/res/object.knc"; - - [Fact] - public void ReadTest() - { - var list = File.OpenRead(FileName).Using(ObjectCollision.Read); - Assert.Equal(3, list.Count); - } - - [Fact] - public void WriteTest() => File.OpenRead(FileName).Using(x => Helpers.AssertStream(x, stream => - { - var outStream = new MemoryStream(); - ObjectCollision.Write(outStream, ObjectCollision.Read(stream)); - - return outStream; - })); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class ObjectCollisionTests + { + private const string FileName = "kh2/res/object.knc"; + + [Fact] + public void ReadTest() + { + var list = File.OpenRead(FileName).Using(ObjectCollision.Read); + Assert.Equal(3, list.Count); + } + + [Fact] + public void WriteTest() => File.OpenRead(FileName).Using(x => Helpers.AssertStream(x, stream => + { + var outStream = new MemoryStream(); + ObjectCollision.Write(outStream, ObjectCollision.Read(stream)); + + return outStream; + })); + } +} diff --git a/OpenKh.Tests/kh2/ObjentryTests.cs b/OpenKh.Tests/kh2/ObjentryTests.cs index 603d87496..4ad184455 100644 --- a/OpenKh.Tests/kh2/ObjentryTests.cs +++ b/OpenKh.Tests/kh2/ObjentryTests.cs @@ -1,38 +1,38 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class ObjentryTests - { - [Fact] - public void HasRightEntryCount() => File.OpenRead("kh2/res/00objentry.bin").Using(stream => - { - var table = Objentry.Read(stream); - Assert.Equal(0x076C, table.Count); - }); - - [Fact] - public void WriteBackTheSameFile() => File.OpenRead("kh2/res/00objentry.bin").Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Objentry.Write(outStream, Objentry.Read(inStream)); - - return outStream; - }); - }); - - [Fact] - public void GroupByUnknown02() => File.OpenRead("kh2/res/00objentry.bin").Using(stream => - { - var table = Objentry.Read(stream); - var grouped = table.GroupBy(x => x.SpawnObject4).ToList(); - Assert.Equal(0x076C, table.Count); - }); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class ObjentryTests + { + [Fact] + public void HasRightEntryCount() => File.OpenRead("kh2/res/00objentry.bin").Using(stream => + { + var table = Objentry.Read(stream); + Assert.Equal(0x076C, table.Count); + }); + + [Fact] + public void WriteBackTheSameFile() => File.OpenRead("kh2/res/00objentry.bin").Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Objentry.Write(outStream, Objentry.Read(inStream)); + + return outStream; + }); + }); + + [Fact] + public void GroupByUnknown02() => File.OpenRead("kh2/res/00objentry.bin").Using(stream => + { + var table = Objentry.Read(stream); + var grouped = table.GroupBy(x => x.SpawnObject4).ToList(); + Assert.Equal(0x076C, table.Count); + }); + } +} diff --git a/OpenKh.Tests/kh2/PlaceTests.cs b/OpenKh.Tests/kh2/PlaceTests.cs index 39389f23a..90c05b0ae 100644 --- a/OpenKh.Tests/kh2/PlaceTests.cs +++ b/OpenKh.Tests/kh2/PlaceTests.cs @@ -1,64 +1,64 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class PlaceTests - { - private const string PlaceFileName = "kh2/res/place.bin"; - private const string OldPlaceFileName = "kh2/res/00place.bin"; - - [Theory] - [InlineData(PlaceFileName)] - [InlineData(OldPlaceFileName)] - public void HasTheRightAmountOfWorlds(string fileName) => File.OpenRead(fileName).Using(stream => - { - Assert.Equal(19, Place.Read(stream).Count); - }); - - [Theory] - [InlineData(PlaceFileName)] - [InlineData(OldPlaceFileName)] - public void HasTheRightWorldNames(string fileName) => File.OpenRead(fileName).Using(stream => - { - var places = Place.Read(stream); - Assert.Contains(places, x => x.Key == "al"); - Assert.Contains(places, x => x.Key == "bb"); - Assert.Contains(places, x => x.Key == "wm"); - Assert.Contains(places, x => x.Key == "zz"); - }); - - [Theory] - [InlineData(PlaceFileName)] - [InlineData(OldPlaceFileName)] - public void HasWorldTheRightAmountOfPlaces(string fileName) => File.OpenRead(fileName).Using(stream => - { - Assert.Equal(16, Place.Read(stream)["bb"].Count); - }); - - [Fact] - public void ReadPlaceName() => File.OpenRead(OldPlaceFileName).Using(stream => - { - var places = Place.Read(stream)["bb"]; - Assert.Equal(18, places[0].Name.Length); - Assert.Equal(0x83, places[0].Name[0]); - Assert.Equal(0x8B, places[0].Name[17]); - }); - - [Theory] - [InlineData(PlaceFileName)] - [InlineData(OldPlaceFileName)] - public void WriteBackTheSameFile(string fileName) => File.OpenRead(fileName).Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - Place.Write(outStream, Place.Read(inStream)); - - return outStream; - }); - }); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class PlaceTests + { + private const string PlaceFileName = "kh2/res/place.bin"; + private const string OldPlaceFileName = "kh2/res/00place.bin"; + + [Theory] + [InlineData(PlaceFileName)] + [InlineData(OldPlaceFileName)] + public void HasTheRightAmountOfWorlds(string fileName) => File.OpenRead(fileName).Using(stream => + { + Assert.Equal(19, Place.Read(stream).Count); + }); + + [Theory] + [InlineData(PlaceFileName)] + [InlineData(OldPlaceFileName)] + public void HasTheRightWorldNames(string fileName) => File.OpenRead(fileName).Using(stream => + { + var places = Place.Read(stream); + Assert.Contains(places, x => x.Key == "al"); + Assert.Contains(places, x => x.Key == "bb"); + Assert.Contains(places, x => x.Key == "wm"); + Assert.Contains(places, x => x.Key == "zz"); + }); + + [Theory] + [InlineData(PlaceFileName)] + [InlineData(OldPlaceFileName)] + public void HasWorldTheRightAmountOfPlaces(string fileName) => File.OpenRead(fileName).Using(stream => + { + Assert.Equal(16, Place.Read(stream)["bb"].Count); + }); + + [Fact] + public void ReadPlaceName() => File.OpenRead(OldPlaceFileName).Using(stream => + { + var places = Place.Read(stream)["bb"]; + Assert.Equal(18, places[0].Name.Length); + Assert.Equal(0x83, places[0].Name[0]); + Assert.Equal(0x8B, places[0].Name[17]); + }); + + [Theory] + [InlineData(PlaceFileName)] + [InlineData(OldPlaceFileName)] + public void WriteBackTheSameFile(string fileName) => File.OpenRead(fileName).Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + Place.Write(outStream, Place.Read(inStream)); + + return outStream; + }); + }); + } +} diff --git a/OpenKh.Tests/kh2/SaveDataTests.cs b/OpenKh.Tests/kh2/SaveDataTests.cs index b346090b5..2bf7091ae 100644 --- a/OpenKh.Tests/kh2/SaveDataTests.cs +++ b/OpenKh.Tests/kh2/SaveDataTests.cs @@ -1,25 +1,25 @@ -using OpenKh.Common; -using OpenKh.Kh2.SaveData; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class SaveDataTests - { - [Theory] - [InlineData("kh2us")] - [InlineData("kh2fm")] - public void WriteSameFile(string name) => File - .OpenRead($"kh2/res/{name}.bin").Using(stream => - { - Helpers.AssertStream(stream, inStream => - { - var outStream = new MemoryStream(); - SaveDataFactory.Write(outStream, SaveDataFactory.Read(stream)); - - return outStream; - }); - }); - } -} +using OpenKh.Common; +using OpenKh.Kh2.SaveData; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class SaveDataTests + { + [Theory] + [InlineData("kh2us")] + [InlineData("kh2fm")] + public void WriteSameFile(string name) => File + .OpenRead($"kh2/res/{name}.bin").Using(stream => + { + Helpers.AssertStream(stream, inStream => + { + var outStream = new MemoryStream(); + SaveDataFactory.Write(outStream, SaveDataFactory.Read(stream)); + + return outStream; + }); + }); + } +} diff --git a/OpenKh.Tests/kh2/SequenceExtensionsTests.cs b/OpenKh.Tests/kh2/SequenceExtensionsTests.cs index af4c87be3..b40d16f29 100644 --- a/OpenKh.Tests/kh2/SequenceExtensionsTests.cs +++ b/OpenKh.Tests/kh2/SequenceExtensionsTests.cs @@ -1,71 +1,71 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class SequenceExtensionsTests - { - [Fact] - public void GetVisibilityRectangleForFrameExTest() - { - const int ExpectedX = 50; - const int ExpectedY = 70; - const int ExpectedWidth = 100; - const int ExpectedHeight = 200; - - var rect = new Sequence.SpritePart - { - Left = ExpectedX, - Top = ExpectedY, - Right = ExpectedX + ExpectedWidth, - Bottom = ExpectedY + ExpectedHeight - }.GetVisibilityRectangle(); - - Assert.Equal(ExpectedX, rect.X); - Assert.Equal(ExpectedY, rect.Y); - Assert.Equal(ExpectedWidth, rect.Width); - Assert.Equal(ExpectedHeight, rect.Height); - } - - [Theory] - [InlineData(0, 0, 0, 0, 0, 0)] - [InlineData(1, 0, 0, 0, 0, 0)] - [InlineData(0, 1, 10, 20, 20, 5)] - [InlineData(1, 1, 20, 20, 5, 5)] - [InlineData(3, 1, -20, 0, 20, 10)] - [InlineData(0, 2, 10, 20, 20, 5)] - [InlineData(2, 1, 10, 10, 20, 40)] - [InlineData(2, 2, -20, 0, 50, 50)] - [InlineData(2, 3, -20, 0, 50, 50)] - public void GetVisibilityRectangleForFrameGroupTest( - short frameExIndex, short frameExCount, - int expectedX, int expectedY, - int expectedWidth, int expectedHeight) - { - var sequence = new Sequence() - { - SpriteGroups = new List> - { - new List - { - new Sequence.SpritePart() { Left = 10, Top = 20, Right = 30, Bottom = 25 }, - new Sequence.SpritePart() { Left = 20, Top = 20, Right = 25, Bottom = 25 }, - new Sequence.SpritePart() { Left = 10, Top = 50, Right = 30, Bottom = 10 }, - new Sequence.SpritePart() { Left = -20, Top = 0, Right = 0, Bottom = 10 }, - new Sequence.SpritePart() { Left = 0, Top = 0, Right = 0, Bottom = 100 }, - }.Skip(frameExIndex).Take(frameExCount).ToList() - } - }; - - var rect = sequence.GetVisibilityRectangleForFrameGroup(0); - - Assert.Equal(expectedX, rect.X); - Assert.Equal(expectedY, rect.Y); - Assert.Equal(expectedWidth, rect.Width); - Assert.Equal(expectedHeight, rect.Height); - } - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class SequenceExtensionsTests + { + [Fact] + public void GetVisibilityRectangleForFrameExTest() + { + const int ExpectedX = 50; + const int ExpectedY = 70; + const int ExpectedWidth = 100; + const int ExpectedHeight = 200; + + var rect = new Sequence.SpritePart + { + Left = ExpectedX, + Top = ExpectedY, + Right = ExpectedX + ExpectedWidth, + Bottom = ExpectedY + ExpectedHeight + }.GetVisibilityRectangle(); + + Assert.Equal(ExpectedX, rect.X); + Assert.Equal(ExpectedY, rect.Y); + Assert.Equal(ExpectedWidth, rect.Width); + Assert.Equal(ExpectedHeight, rect.Height); + } + + [Theory] + [InlineData(0, 0, 0, 0, 0, 0)] + [InlineData(1, 0, 0, 0, 0, 0)] + [InlineData(0, 1, 10, 20, 20, 5)] + [InlineData(1, 1, 20, 20, 5, 5)] + [InlineData(3, 1, -20, 0, 20, 10)] + [InlineData(0, 2, 10, 20, 20, 5)] + [InlineData(2, 1, 10, 10, 20, 40)] + [InlineData(2, 2, -20, 0, 50, 50)] + [InlineData(2, 3, -20, 0, 50, 50)] + public void GetVisibilityRectangleForFrameGroupTest( + short frameExIndex, short frameExCount, + int expectedX, int expectedY, + int expectedWidth, int expectedHeight) + { + var sequence = new Sequence() + { + SpriteGroups = new List> + { + new List + { + new Sequence.SpritePart() { Left = 10, Top = 20, Right = 30, Bottom = 25 }, + new Sequence.SpritePart() { Left = 20, Top = 20, Right = 25, Bottom = 25 }, + new Sequence.SpritePart() { Left = 10, Top = 50, Right = 30, Bottom = 10 }, + new Sequence.SpritePart() { Left = -20, Top = 0, Right = 0, Bottom = 10 }, + new Sequence.SpritePart() { Left = 0, Top = 0, Right = 0, Bottom = 100 }, + }.Skip(frameExIndex).Take(frameExCount).ToList() + } + }; + + var rect = sequence.GetVisibilityRectangleForFrameGroup(0); + + Assert.Equal(expectedX, rect.X); + Assert.Equal(expectedY, rect.Y); + Assert.Equal(expectedWidth, rect.Width); + Assert.Equal(expectedHeight, rect.Height); + } + } +} diff --git a/OpenKh.Tests/kh2/SequenceTests.cs b/OpenKh.Tests/kh2/SequenceTests.cs index cbd9cac2e..354455249 100644 --- a/OpenKh.Tests/kh2/SequenceTests.cs +++ b/OpenKh.Tests/kh2/SequenceTests.cs @@ -1,93 +1,93 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System; -using System.IO; -using System.Linq; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class SequenceTests - { - private const string FilePath = "kh2/res/eh_l.layd"; - private const int Offset = 0x5B4; - private const int Length = 0x7D4; - - [Fact] - public void IsValidTest() => new MemoryStream() - .Using(stream => - { - stream.WriteByte(0x53); - stream.WriteByte(0x45); - stream.WriteByte(0x51); - stream.WriteByte(0x44); - stream.Write(new byte[44]); - stream.Position = 0; - Assert.True(Sequence.IsValid(stream)); - Assert.Equal(0, stream.Position); - }); - - [Fact] - public void IsInvalidHeaderTest() => new MemoryStream() - .Using(stream => - { - stream.WriteByte(0xCC); - stream.WriteByte(0xCC); - stream.WriteByte(0xCC); - stream.WriteByte(0xCC); - stream.Write(new byte[44]); - stream.Position = 0; - Assert.False(Sequence.IsValid(stream)); - Assert.Equal(0, stream.Position); - }); - - [Fact] - public void IsInvalidStreamLengthTest() => new MemoryStream() - .Using(stream => - { - stream.WriteByte(0x53); - stream.WriteByte(0x45); - stream.WriteByte(0x51); - stream.WriteByte(0x44); - stream.Position = 0; - Assert.False(Sequence.IsValid(stream)); - Assert.Equal(0, stream.Position); - }); - - [Fact] - public void ValidateSequenceHeader() => StartTest(stream => - { - var sequence = Sequence.Read(stream); - Assert.Equal(3, sequence.Sprites.Count); - Assert.Equal(15, sequence.SpriteGroups.Sum(x => x.Count)); - Assert.Equal(3, sequence.SpriteGroups.Count); - Assert.Equal(2, sequence.AnimationGroups.Count); - Assert.Equal(10, sequence.AnimationGroups.Sum(x => x.Animations.Count)); - }); - - [Fact] - public void WriteSequenceTest() => StartTest(stream => - { - var expected = new BinaryReader(stream).ReadBytes((int)stream.Length); - var sequence = new MemoryStream(expected).Using(x => Sequence.Read(x)); - new MemoryStream().Using(x => - { - sequence.Write(x); - x.Position = 0; - var actual = new BinaryReader(x).ReadBytes((int)x.Length); - - Assert.Equal(expected.Length, actual.Length); - for (var i = 0; i < expected.Length; i++) - { - var ch1 = expected[i]; - var ch2 = actual[i]; - Assert.True(ch1 == ch2, $"Expected {ch1:X02} but found {ch2:X02} at {i:X}"); - } - }); - }); - - private void StartTest(Action action) => - File.OpenRead(FilePath).Using(x => - action(new Xe.IO.SubStream(x, Offset, Length))); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System; +using System.IO; +using System.Linq; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class SequenceTests + { + private const string FilePath = "kh2/res/eh_l.layd"; + private const int Offset = 0x5B4; + private const int Length = 0x7D4; + + [Fact] + public void IsValidTest() => new MemoryStream() + .Using(stream => + { + stream.WriteByte(0x53); + stream.WriteByte(0x45); + stream.WriteByte(0x51); + stream.WriteByte(0x44); + stream.Write(new byte[44]); + stream.Position = 0; + Assert.True(Sequence.IsValid(stream)); + Assert.Equal(0, stream.Position); + }); + + [Fact] + public void IsInvalidHeaderTest() => new MemoryStream() + .Using(stream => + { + stream.WriteByte(0xCC); + stream.WriteByte(0xCC); + stream.WriteByte(0xCC); + stream.WriteByte(0xCC); + stream.Write(new byte[44]); + stream.Position = 0; + Assert.False(Sequence.IsValid(stream)); + Assert.Equal(0, stream.Position); + }); + + [Fact] + public void IsInvalidStreamLengthTest() => new MemoryStream() + .Using(stream => + { + stream.WriteByte(0x53); + stream.WriteByte(0x45); + stream.WriteByte(0x51); + stream.WriteByte(0x44); + stream.Position = 0; + Assert.False(Sequence.IsValid(stream)); + Assert.Equal(0, stream.Position); + }); + + [Fact] + public void ValidateSequenceHeader() => StartTest(stream => + { + var sequence = Sequence.Read(stream); + Assert.Equal(3, sequence.Sprites.Count); + Assert.Equal(15, sequence.SpriteGroups.Sum(x => x.Count)); + Assert.Equal(3, sequence.SpriteGroups.Count); + Assert.Equal(2, sequence.AnimationGroups.Count); + Assert.Equal(10, sequence.AnimationGroups.Sum(x => x.Animations.Count)); + }); + + [Fact] + public void WriteSequenceTest() => StartTest(stream => + { + var expected = new BinaryReader(stream).ReadBytes((int)stream.Length); + var sequence = new MemoryStream(expected).Using(x => Sequence.Read(x)); + new MemoryStream().Using(x => + { + sequence.Write(x); + x.Position = 0; + var actual = new BinaryReader(x).ReadBytes((int)x.Length); + + Assert.Equal(expected.Length, actual.Length); + for (var i = 0; i < expected.Length; i++) + { + var ch1 = expected[i]; + var ch2 = actual[i]; + Assert.True(ch1 == ch2, $"Expected {ch1:X02} but found {ch2:X02} at {i:X}"); + } + }); + }); + + private void StartTest(Action action) => + File.OpenRead(FilePath).Using(x => + action(new Xe.IO.SubStream(x, Offset, Length))); + } +} diff --git a/OpenKh.Tests/kh2/System03Tests.cs b/OpenKh.Tests/kh2/System03Tests.cs index 6959cc4a8..fa2312c2d 100644 --- a/OpenKh.Tests/kh2/System03Tests.cs +++ b/OpenKh.Tests/kh2/System03Tests.cs @@ -1,132 +1,132 @@ -using OpenKh.Common; -using OpenKh.Kh2.SystemData; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class System03Tests - { - public class ArifTests - { - [Fact] - public void CheckForLength() => File.OpenRead("kh2/res/arif.bin").Using(stream => - { - var worlds = Arif.Read(stream); - - Assert.Equal(19, worlds.Count); - Assert.Equal(64, worlds[0].Count); - Assert.Equal(2, worlds[1].Count); - Assert.Equal(42, worlds[2].Count); - }); - - [Fact] - public void ShouldWriteTheExactSameFile() => File.OpenRead("kh2/res/arif.bin").Using(stream => - { - Helpers.AssertStream(stream, x => - { - var outStream = new MemoryStream(); - Arif.Write(outStream, Arif.Read(x)); - - return outStream; - }); - }); - } - - public class FtstTests - { - [Fact] - public void CheckForLength() => File.OpenRead("kh2/res/ftst.bin").Using(stream => - { - var entries = Ftst.Read(stream); - Assert.Equal(8, entries.Count); - }); - - [Fact] - public void ShouldWriteTheExactSameFile() => File.OpenRead("kh2/res/ftst.bin").Using(stream => - { - Helpers.AssertStream(stream, x => - { - var outStream = new MemoryStream(); - Ftst.Write(outStream, Ftst.Read(x)); - - return outStream; - }); - }); - } - - public class ItemTests - { - [Fact] - public void CheckForLength() => File.OpenRead("kh2/res/item.bin").Using(stream => - { - var entries = Item.Read(stream); - Assert.Equal(535, entries.Items1.Count); - Assert.Equal(151, entries.Items2.Count); - }); - - [Fact] - public void ShouldWriteTheExactSameFile() => File.OpenRead("kh2/res/item.bin").Using(stream => - { - Helpers.AssertStream(stream, x => - { - var outStream = new MemoryStream(); - Item.Read(x).Write(outStream); - return outStream; - }); - }); - } - - public class MemtTests - { - private const string MemtVanilla = @"kh2/res/memt_eu.bin"; - private const string MemtFinalMix = @"kh2/res/memt_fm.bin"; - - [Theory] - [InlineData(MemtVanilla)] - [InlineData(MemtFinalMix)] - public void Read(string fileName) => File.OpenRead(fileName).Using(stream => - { - var table = Memt.Read(stream); - Assert.Equal(0x5, table.Entries.Count); - Assert.Equal(0x7, table.MemberIndexCollection.Length); - }); - - [Theory] - [InlineData(MemtVanilla)] - [InlineData(MemtFinalMix)] - public void Write(string fileName) => File.OpenRead(fileName).Using(stream => - { - Helpers.AssertStream(stream, x => - { - var outStream = new MemoryStream(); - Memt.Write(outStream, Memt.Read(x)); - - return outStream; - }); - }); - } - - public class TrsrTests - { - [Fact] - public void CheckNewTrsr() => File.OpenRead(@"kh2/res/trsr.bin").Using(stream => - { - var table = Trsr.Read(stream); - Assert.Equal(0x1AE, table.Count); - }); - - [Fact] - public void ShouldWriteTheExactSameFile() => File.OpenRead("kh2/res/trsr.bin").Using(stream => - { - Helpers.AssertStream(stream, x => - { - var outStream = new MemoryStream(); - Trsr.Write(outStream, Trsr.Read(x)); - - return outStream; - }); - }); - } - } -} +using OpenKh.Common; +using OpenKh.Kh2.SystemData; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class System03Tests + { + public class ArifTests + { + [Fact] + public void CheckForLength() => File.OpenRead("kh2/res/arif.bin").Using(stream => + { + var worlds = Arif.Read(stream); + + Assert.Equal(19, worlds.Count); + Assert.Equal(64, worlds[0].Count); + Assert.Equal(2, worlds[1].Count); + Assert.Equal(42, worlds[2].Count); + }); + + [Fact] + public void ShouldWriteTheExactSameFile() => File.OpenRead("kh2/res/arif.bin").Using(stream => + { + Helpers.AssertStream(stream, x => + { + var outStream = new MemoryStream(); + Arif.Write(outStream, Arif.Read(x)); + + return outStream; + }); + }); + } + + public class FtstTests + { + [Fact] + public void CheckForLength() => File.OpenRead("kh2/res/ftst.bin").Using(stream => + { + var entries = Ftst.Read(stream); + Assert.Equal(8, entries.Count); + }); + + [Fact] + public void ShouldWriteTheExactSameFile() => File.OpenRead("kh2/res/ftst.bin").Using(stream => + { + Helpers.AssertStream(stream, x => + { + var outStream = new MemoryStream(); + Ftst.Write(outStream, Ftst.Read(x)); + + return outStream; + }); + }); + } + + public class ItemTests + { + [Fact] + public void CheckForLength() => File.OpenRead("kh2/res/item.bin").Using(stream => + { + var entries = Item.Read(stream); + Assert.Equal(535, entries.Items1.Count); + Assert.Equal(151, entries.Items2.Count); + }); + + [Fact] + public void ShouldWriteTheExactSameFile() => File.OpenRead("kh2/res/item.bin").Using(stream => + { + Helpers.AssertStream(stream, x => + { + var outStream = new MemoryStream(); + Item.Read(x).Write(outStream); + return outStream; + }); + }); + } + + public class MemtTests + { + private const string MemtVanilla = @"kh2/res/memt_eu.bin"; + private const string MemtFinalMix = @"kh2/res/memt_fm.bin"; + + [Theory] + [InlineData(MemtVanilla)] + [InlineData(MemtFinalMix)] + public void Read(string fileName) => File.OpenRead(fileName).Using(stream => + { + var table = Memt.Read(stream); + Assert.Equal(0x5, table.Entries.Count); + Assert.Equal(0x7, table.MemberIndexCollection.Length); + }); + + [Theory] + [InlineData(MemtVanilla)] + [InlineData(MemtFinalMix)] + public void Write(string fileName) => File.OpenRead(fileName).Using(stream => + { + Helpers.AssertStream(stream, x => + { + var outStream = new MemoryStream(); + Memt.Write(outStream, Memt.Read(x)); + + return outStream; + }); + }); + } + + public class TrsrTests + { + [Fact] + public void CheckNewTrsr() => File.OpenRead(@"kh2/res/trsr.bin").Using(stream => + { + var table = Trsr.Read(stream); + Assert.Equal(0x1AE, table.Count); + }); + + [Fact] + public void ShouldWriteTheExactSameFile() => File.OpenRead("kh2/res/trsr.bin").Using(stream => + { + Helpers.AssertStream(stream, x => + { + var outStream = new MemoryStream(); + Trsr.Write(outStream, Trsr.Read(x)); + + return outStream; + }); + }); + } + } +} diff --git a/OpenKh.Tests/kh2/TextureFooterDataTests.cs b/OpenKh.Tests/kh2/TextureFooterDataTests.cs index b973f1cba..4464bd096 100644 --- a/OpenKh.Tests/kh2/TextureFooterDataTests.cs +++ b/OpenKh.Tests/kh2/TextureFooterDataTests.cs @@ -1,47 +1,47 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Kh2.TextureFooter; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class TextureFooterDataTests - { - [Theory] - [InlineData("kh2/res/dummy1.footer.bin", 2, 0)] - [InlineData("kh2/res/dummy2.footer.bin", 0, 1)] - public void ReadAndCheckSomeParams(string binFile, int numUvsc, int numTexa) - { - var footer = File.OpenRead(binFile).Using(TextureFooterData.Read); - Assert.Equal(numUvsc, footer.UvscList.Count); - Assert.Equal(numTexa, footer.TextureAnimationList.Count); - } - - [Fact] - public void CreateDummy() - { - { - var footer = new TextureFooterData(); - var stream = new MemoryStream(); - footer.Write(stream); - } - { - var footer = new TextureFooterData(); - footer.UvscList.Add(new UvScroll { }); - var stream = new MemoryStream(); - footer.Write(stream); - } - { - var footer = new TextureFooterData(); - footer.TextureAnimationList.Add(new TextureAnimation { }); - var stream = new MemoryStream(); - footer.Write(stream); - } - } - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Kh2.TextureFooter; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class TextureFooterDataTests + { + [Theory] + [InlineData("kh2/res/dummy1.footer.bin", 2, 0)] + [InlineData("kh2/res/dummy2.footer.bin", 0, 1)] + public void ReadAndCheckSomeParams(string binFile, int numUvsc, int numTexa) + { + var footer = File.OpenRead(binFile).Using(TextureFooterData.Read); + Assert.Equal(numUvsc, footer.UvscList.Count); + Assert.Equal(numTexa, footer.TextureAnimationList.Count); + } + + [Fact] + public void CreateDummy() + { + { + var footer = new TextureFooterData(); + var stream = new MemoryStream(); + footer.Write(stream); + } + { + var footer = new TextureFooterData(); + footer.UvscList.Add(new UvScroll { }); + var stream = new MemoryStream(); + footer.Write(stream); + } + { + var footer = new TextureFooterData(); + footer.TextureAnimationList.Add(new TextureAnimation { }); + var stream = new MemoryStream(); + footer.Write(stream); + } + } + } +} diff --git a/OpenKh.Tests/kh2/WorldPointsTests.cs b/OpenKh.Tests/kh2/WorldPointsTests.cs index 1db47d74d..dc282cd48 100644 --- a/OpenKh.Tests/kh2/WorldPointsTests.cs +++ b/OpenKh.Tests/kh2/WorldPointsTests.cs @@ -1,37 +1,37 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.IO; -using Xunit; - -namespace OpenKh.Tests.kh2 -{ - public class WorldPointsTests - { - private const string FileName = "kh2/res/00worldpoint.bin"; - - [Fact] - public void ReadTest() - { - var items = File.OpenRead(FileName).Using(WorldPoint.Read); - Assert.Equal(3, items.Count); - Assert.Equal(1, items[0].World); - Assert.Equal(1, items[0].Area); - Assert.Equal(99, items[0].Entrance); - Assert.Equal(1, items[1].World); - Assert.Equal(2, items[1].Area); - Assert.Equal(99, items[1].Entrance); - } - - [Fact] - public void WriteTest() => File.OpenRead(FileName).Using(stream => - { - Helpers.AssertStream(stream, x => - { - var outStream = new MemoryStream(); - WorldPoint.Write(outStream, WorldPoint.Read(x)); - - return outStream; - }); - }); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.IO; +using Xunit; + +namespace OpenKh.Tests.kh2 +{ + public class WorldPointsTests + { + private const string FileName = "kh2/res/00worldpoint.bin"; + + [Fact] + public void ReadTest() + { + var items = File.OpenRead(FileName).Using(WorldPoint.Read); + Assert.Equal(3, items.Count); + Assert.Equal(1, items[0].World); + Assert.Equal(1, items[0].Area); + Assert.Equal(99, items[0].Entrance); + Assert.Equal(1, items[1].World); + Assert.Equal(2, items[1].Area); + Assert.Equal(99, items[1].Entrance); + } + + [Fact] + public void WriteTest() => File.OpenRead(FileName).Using(stream => + { + Helpers.AssertStream(stream, x => + { + var outStream = new MemoryStream(); + WorldPoint.Write(outStream, WorldPoint.Read(x)); + + return outStream; + }); + }); + } +} diff --git a/OpenKh.Tools.BarEditor/App.xaml.cs b/OpenKh.Tools.BarEditor/App.xaml.cs index cbcad895f..8ae277179 100644 --- a/OpenKh.Tools.BarEditor/App.xaml.cs +++ b/OpenKh.Tools.BarEditor/App.xaml.cs @@ -1,12 +1,12 @@ -using System.Windows; - -namespace OpenKh.Tools.BarEditor -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - - } -} +using System.Windows; + +namespace OpenKh.Tools.BarEditor +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + + } +} diff --git a/OpenKh.Tools.BarEditor/Helpers.cs b/OpenKh.Tools.BarEditor/Helpers.cs index f668507c6..c4178fbe9 100644 --- a/OpenKh.Tools.BarEditor/Helpers.cs +++ b/OpenKh.Tools.BarEditor/Helpers.cs @@ -1,65 +1,65 @@ -using OpenKh.Kh2; -using System.Collections.Generic; -using static OpenKh.Kh2.Bar; - -namespace OpenKh.Tools.BarEditor -{ - public class Helpers - { - private static readonly string DefaultExtension = "bin"; - - private static readonly Dictionary SuggestedExtensions = - new Dictionary - { - [EntryType.Dummy] = "dummy", - [EntryType.Binary] = "bin", - [EntryType.List] = "list", - [EntryType.Bdx] = "bdx", - [EntryType.Model] = "model", - [EntryType.DrawOctalTree] = "ocd", - [EntryType.CollisionOctalTree] = "occ", - [EntryType.ModelTexture] = "texture", - [EntryType.Dpx] = "dpx", - [EntryType.Motion] = "motion", - [EntryType.Tim2] = "tm2", - [EntryType.CameraOctalTree] = "och", - [EntryType.AreaDataSpawn] = "spawn", - [EntryType.AreaDataScript] = "script", - [EntryType.FogColor] = "fog", - [EntryType.ColorOctalTree] = "ocl", - [EntryType.MotionTriggers] = "triggers", - [EntryType.Anb] = "anb", - [EntryType.Pax] = "pax", - [EntryType.MapCollision2] = "owa", - [EntryType.Motionset] = "mset", - [EntryType.BgObjPlacement] = "bop", - [EntryType.Event] = "event", - [EntryType.ModelCollision] = "coctmodel", - [EntryType.Imgd] = "imd", - [EntryType.Seqd] = "sqd", - [EntryType.Layout] = "lad", - [EntryType.Imgz] = "imz", - [EntryType.AnimationMap] = "mapanim", - [EntryType.Seb] = "seb", - [EntryType.Wd] = "wd", - [EntryType.Unknown33] = "unk33", - [EntryType.IopVoice] = "iopvoice", - [EntryType.RawBitmap] = "rgb", - [EntryType.MemoryCard] = "memcard", - [EntryType.WrappedCollisionData] = "coctwrapped", - [EntryType.Unknown39] = "unk39", - [EntryType.Unknown40] = "unk40", - [EntryType.Unknown41] = "unk41", - [EntryType.Minigame] = "minigame", - [EntryType.JimiData] = "jimidata", - [EntryType.Progress] = "progress", - [EntryType.Synthesis] = "synthesis", - [EntryType.BarUnknown] = "bar", - [EntryType.Vibration] = "vibration", - [EntryType.Vag] = "vag", - }; - - public static string GetSuggestedExtension(Bar.EntryType type) => - SuggestedExtensions.TryGetValue(type, out var ext) ? ext : DefaultExtension; - } -} +using OpenKh.Kh2; +using System.Collections.Generic; +using static OpenKh.Kh2.Bar; + +namespace OpenKh.Tools.BarEditor +{ + public class Helpers + { + private static readonly string DefaultExtension = "bin"; + + private static readonly Dictionary SuggestedExtensions = + new Dictionary + { + [EntryType.Dummy] = "dummy", + [EntryType.Binary] = "bin", + [EntryType.List] = "list", + [EntryType.Bdx] = "bdx", + [EntryType.Model] = "model", + [EntryType.DrawOctalTree] = "ocd", + [EntryType.CollisionOctalTree] = "occ", + [EntryType.ModelTexture] = "texture", + [EntryType.Dpx] = "dpx", + [EntryType.Motion] = "motion", + [EntryType.Tim2] = "tm2", + [EntryType.CameraOctalTree] = "och", + [EntryType.AreaDataSpawn] = "spawn", + [EntryType.AreaDataScript] = "script", + [EntryType.FogColor] = "fog", + [EntryType.ColorOctalTree] = "ocl", + [EntryType.MotionTriggers] = "triggers", + [EntryType.Anb] = "anb", + [EntryType.Pax] = "pax", + [EntryType.MapCollision2] = "owa", + [EntryType.Motionset] = "mset", + [EntryType.BgObjPlacement] = "bop", + [EntryType.Event] = "event", + [EntryType.ModelCollision] = "coctmodel", + [EntryType.Imgd] = "imd", + [EntryType.Seqd] = "sqd", + [EntryType.Layout] = "lad", + [EntryType.Imgz] = "imz", + [EntryType.AnimationMap] = "mapanim", + [EntryType.Seb] = "seb", + [EntryType.Wd] = "wd", + [EntryType.Unknown33] = "unk33", + [EntryType.IopVoice] = "iopvoice", + [EntryType.RawBitmap] = "rgb", + [EntryType.MemoryCard] = "memcard", + [EntryType.WrappedCollisionData] = "coctwrapped", + [EntryType.Unknown39] = "unk39", + [EntryType.Unknown40] = "unk40", + [EntryType.Unknown41] = "unk41", + [EntryType.Minigame] = "minigame", + [EntryType.JimiData] = "jimidata", + [EntryType.Progress] = "progress", + [EntryType.Synthesis] = "synthesis", + [EntryType.BarUnknown] = "bar", + [EntryType.Vibration] = "vibration", + [EntryType.Vag] = "vag", + }; + + public static string GetSuggestedExtension(Bar.EntryType type) => + SuggestedExtensions.TryGetValue(type, out var ext) ? ext : DefaultExtension; + } +} diff --git a/OpenKh.Tools.BarEditor/Interfaces/IViewSettings.cs b/OpenKh.Tools.BarEditor/Interfaces/IViewSettings.cs index 332353a76..00668f425 100644 --- a/OpenKh.Tools.BarEditor/Interfaces/IViewSettings.cs +++ b/OpenKh.Tools.BarEditor/Interfaces/IViewSettings.cs @@ -1,13 +1,13 @@ -using OpenKh.Tools.BarEditor.Models; - -namespace OpenKh.Tools.BarEditor.Interfaces -{ - public interface IViewSettings - { - bool IsPlayer { get; } - bool ShowSlotNumber { get; } - bool ShowMovesetName { get; } - - int GetSlotIndex(BarEntryModel item); - } -} +using OpenKh.Tools.BarEditor.Models; + +namespace OpenKh.Tools.BarEditor.Interfaces +{ + public interface IViewSettings + { + bool IsPlayer { get; } + bool ShowSlotNumber { get; } + bool ShowMovesetName { get; } + + int GetSlotIndex(BarEntryModel item); + } +} diff --git a/OpenKh.Tools.BarEditor/Models/BarEntryModel.cs b/OpenKh.Tools.BarEditor/Models/BarEntryModel.cs index 06f4dec16..f5255e5e9 100644 --- a/OpenKh.Tools.BarEditor/Models/BarEntryModel.cs +++ b/OpenKh.Tools.BarEditor/Models/BarEntryModel.cs @@ -1,117 +1,117 @@ -using OpenKh.Kh2; -using OpenKh.Tools.BarEditor.Interfaces; -using System.ComponentModel.DataAnnotations; -using System.Text; -using Xe.Tools; -using static OpenKh.Kh2.Bar; - -namespace OpenKh.Tools.BarEditor.Models -{ - public class BarEntryModel : BaseNotifyPropertyChanged - { - private readonly string[] MotionsetMode = new string[] - { - "BW", "B_", "__", "_W" - }; - private readonly IViewSettings _viewSettings; - - public BarEntryModel(Entry entry, IViewSettings viewSettings) - { - Entry = entry; - _viewSettings = viewSettings; - } - - public Entry Entry { get; } - - public EntryType Type - { - get => Entry.Type; - set - { - Entry.Type = value; - OnPropertyChanged(nameof(DisplayName)); - } - } - - public string DisplayName - { - get - { - var sb = new StringBuilder(0x30); - if (_viewSettings.ShowSlotNumber || _viewSettings.ShowMovesetName) - { - var slotIndex = _viewSettings.GetSlotIndex(this); - - if (_viewSettings.ShowSlotNumber) - sb.Append($"{slotIndex:D02} "); - - if (_viewSettings.ShowMovesetName) - { - var motionId = slotIndex; - if (_viewSettings.IsPlayer) - { - motionId /= 4; - sb.Append($"{MotionsetMode[slotIndex & 3]} "); - } - - sb.Append($"{(MotionSet.MotionName)motionId} {Tag}"); - return sb.ToString(); - } - } - - sb.Append($"{Tag} {Index} {Type}"); - return sb.ToString(); - } - } - - public short Index - { - get => (short)Entry.Index; - set - { - Entry.Index = value; - OnPropertyChanged(nameof(DisplayName)); - } - } - - [Required] - [StringLength(4, MinimumLength = 4, ErrorMessage = "Must be 4 characters long.")] - public string Tag - { - get => Entry.Name; - set - { - Entry.Name = value; - OnPropertyChanged(nameof(DisplayName)); - } - } - - public string Size - { - get - { - string unit = "byte"; - int divisor; - - if (Entry.Stream.Length >= 1024 * 1024) - { - unit = "MB"; - divisor = 1024 * 1024; - } - else if (Entry.Stream.Length >= 1024) - { - unit = "KB"; - divisor = 1024; - } - else - { - return $"{Entry.Stream.Length} {unit}"; - } - - return $"{(float)Entry.Stream.Length / divisor:0.00} {unit}"; - } - } - - internal void InvalidateTag() => OnPropertyChanged(nameof(DisplayName)); - } -} +using OpenKh.Kh2; +using OpenKh.Tools.BarEditor.Interfaces; +using System.ComponentModel.DataAnnotations; +using System.Text; +using Xe.Tools; +using static OpenKh.Kh2.Bar; + +namespace OpenKh.Tools.BarEditor.Models +{ + public class BarEntryModel : BaseNotifyPropertyChanged + { + private readonly string[] MotionsetMode = new string[] + { + "BW", "B_", "__", "_W" + }; + private readonly IViewSettings _viewSettings; + + public BarEntryModel(Entry entry, IViewSettings viewSettings) + { + Entry = entry; + _viewSettings = viewSettings; + } + + public Entry Entry { get; } + + public EntryType Type + { + get => Entry.Type; + set + { + Entry.Type = value; + OnPropertyChanged(nameof(DisplayName)); + } + } + + public string DisplayName + { + get + { + var sb = new StringBuilder(0x30); + if (_viewSettings.ShowSlotNumber || _viewSettings.ShowMovesetName) + { + var slotIndex = _viewSettings.GetSlotIndex(this); + + if (_viewSettings.ShowSlotNumber) + sb.Append($"{slotIndex:D02} "); + + if (_viewSettings.ShowMovesetName) + { + var motionId = slotIndex; + if (_viewSettings.IsPlayer) + { + motionId /= 4; + sb.Append($"{MotionsetMode[slotIndex & 3]} "); + } + + sb.Append($"{(MotionSet.MotionName)motionId} {Tag}"); + return sb.ToString(); + } + } + + sb.Append($"{Tag} {Index} {Type}"); + return sb.ToString(); + } + } + + public short Index + { + get => (short)Entry.Index; + set + { + Entry.Index = value; + OnPropertyChanged(nameof(DisplayName)); + } + } + + [Required] + [StringLength(4, MinimumLength = 4, ErrorMessage = "Must be 4 characters long.")] + public string Tag + { + get => Entry.Name; + set + { + Entry.Name = value; + OnPropertyChanged(nameof(DisplayName)); + } + } + + public string Size + { + get + { + string unit = "byte"; + int divisor; + + if (Entry.Stream.Length >= 1024 * 1024) + { + unit = "MB"; + divisor = 1024 * 1024; + } + else if (Entry.Stream.Length >= 1024) + { + unit = "KB"; + divisor = 1024; + } + else + { + return $"{Entry.Stream.Length} {unit}"; + } + + return $"{(float)Entry.Stream.Length / divisor:0.00} {unit}"; + } + } + + internal void InvalidateTag() => OnPropertyChanged(nameof(DisplayName)); + } +} diff --git a/OpenKh.Tools.BarEditor/Properties/AssemblyInfo.cs b/OpenKh.Tools.BarEditor/Properties/AssemblyInfo.cs index df263cb44..ed39486c6 100644 --- a/OpenKh.Tools.BarEditor/Properties/AssemblyInfo.cs +++ b/OpenKh.Tools.BarEditor/Properties/AssemblyInfo.cs @@ -1,29 +1,29 @@ -using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Windows; - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -//In order to begin building localizable applications, set -//CultureYouAreCodingWith in your .csproj file -//inside a . For example, if you are using US english -//in your source files, set the to en-US. Then uncomment -//the NeutralResourceLanguage attribute below. Update the "en-US" in -//the line below to match the UICulture setting in the project file. - -//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/OpenKh.Tools.BarEditor/Services/ToolsLoaderService.cs b/OpenKh.Tools.BarEditor/Services/ToolsLoaderService.cs index 7ef534edd..f05a5d463 100644 --- a/OpenKh.Tools.BarEditor/Services/ToolsLoaderService.cs +++ b/OpenKh.Tools.BarEditor/Services/ToolsLoaderService.cs @@ -1,61 +1,61 @@ -using OpenKh.Kh2; -using OpenKh.Tools.Common; -using System; -using System.IO; -using System.Linq; -using System.Windows; -using Xe.Tools; - -namespace OpenKh.Tools.BarEditor.Services -{ - public static class ToolsLoaderService - { - public static ToolInvokeDesc.ContentChangeInfo? OpenTool(string fileName, string temporaryFileName, Bar.Entry entry) - { - string name; - - switch (entry.Type) - { - // Disabling it, since it is veeeeeery buggy at the moment. - //case Bar.EntryType.Bar: - // name = "OpenKh.Tools.BarEditor"; - // break; - case Bar.EntryType.Imgd: - case Bar.EntryType.Imgz: - name = "OpenKh.Tools.ImageViewer"; - break; - case Bar.EntryType.Layout: - name = "OpenKh.Tools.LayoutViewer"; - break; - default: - throw new NotImplementedException($"Unable to find a tool for \"{entry.Type}\" files."); - } - - var toolModule = Plugins - .GetModules>(null, x => x.Contains(name) && Path.GetExtension(x) == ".dll") - .FirstOrDefault(); - - if (toolModule.Item1 == null || toolModule.Item2 == null) - { - MessageBox.Show($"Unable to find a tool module for the tool {name}.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - return null; - } - - var tool = Activator.CreateInstance(toolModule.Item2) as IToolModule; - - entry.Stream.Position = 0; - var toolInvokeDesc = new ToolInvokeDesc - { - Title = $"{entry.Name}@{Path.GetFileName(fileName)}", - ActualFileName = temporaryFileName, - SelectedEntry = entry, - ContentChange = ToolInvokeDesc.ContentChangeInfo.None - }; - - tool?.ShowDialog(toolInvokeDesc); - - return toolInvokeDesc.ContentChange; - } - - } -} +using OpenKh.Kh2; +using OpenKh.Tools.Common; +using System; +using System.IO; +using System.Linq; +using System.Windows; +using Xe.Tools; + +namespace OpenKh.Tools.BarEditor.Services +{ + public static class ToolsLoaderService + { + public static ToolInvokeDesc.ContentChangeInfo? OpenTool(string fileName, string temporaryFileName, Bar.Entry entry) + { + string name; + + switch (entry.Type) + { + // Disabling it, since it is veeeeeery buggy at the moment. + //case Bar.EntryType.Bar: + // name = "OpenKh.Tools.BarEditor"; + // break; + case Bar.EntryType.Imgd: + case Bar.EntryType.Imgz: + name = "OpenKh.Tools.ImageViewer"; + break; + case Bar.EntryType.Layout: + name = "OpenKh.Tools.LayoutViewer"; + break; + default: + throw new NotImplementedException($"Unable to find a tool for \"{entry.Type}\" files."); + } + + var toolModule = Plugins + .GetModules>(null, x => x.Contains(name) && Path.GetExtension(x) == ".dll") + .FirstOrDefault(); + + if (toolModule.Item1 == null || toolModule.Item2 == null) + { + MessageBox.Show($"Unable to find a tool module for the tool {name}.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return null; + } + + var tool = Activator.CreateInstance(toolModule.Item2) as IToolModule; + + entry.Stream.Position = 0; + var toolInvokeDesc = new ToolInvokeDesc + { + Title = $"{entry.Name}@{Path.GetFileName(fileName)}", + ActualFileName = temporaryFileName, + SelectedEntry = entry, + ContentChange = ToolInvokeDesc.ContentChangeInfo.None + }; + + tool?.ShowDialog(toolInvokeDesc); + + return toolInvokeDesc.ContentChange; + } + + } +} diff --git a/OpenKh.Tools.BarEditor/ToolModule.cs b/OpenKh.Tools.BarEditor/ToolModule.cs index 3733a7884..955da8026 100644 --- a/OpenKh.Tools.BarEditor/ToolModule.cs +++ b/OpenKh.Tools.BarEditor/ToolModule.cs @@ -1,11 +1,11 @@ -using OpenKh.Tools.BarEditor.Views; -using OpenKh.Tools.Common; -using Xe.Tools; - -namespace OpenKh.Tools.BarEditor -{ - public class ToolModule : IToolModule - { - public bool? ShowDialog(ToolInvokeDesc args) => new BarView(args).ShowDialog(); - } -} +using OpenKh.Tools.BarEditor.Views; +using OpenKh.Tools.Common; +using Xe.Tools; + +namespace OpenKh.Tools.BarEditor +{ + public class ToolModule : IToolModule + { + public bool? ShowDialog(ToolInvokeDesc args) => new BarView(args).ShowDialog(); + } +} diff --git a/OpenKh.Tools.BarEditor/ViewModels/BarViewModel.cs b/OpenKh.Tools.BarEditor/ViewModels/BarViewModel.cs index 38ee26fe4..eec1fb106 100644 --- a/OpenKh.Tools.BarEditor/ViewModels/BarViewModel.cs +++ b/OpenKh.Tools.BarEditor/ViewModels/BarViewModel.cs @@ -1,327 +1,327 @@ -using OpenKh.Kh2; -using OpenKh.Tools.BarEditor.Interfaces; -using OpenKh.Tools.BarEditor.Models; -using OpenKh.Tools.BarEditor.Services; -using OpenKh.Tools.Common; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Windows; -using Xe.Tools.Models; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.BarEditor.ViewModels -{ - public class BarViewModel : GenericListModel, IViewSettings - { - private static string ApplicationName = Utilities.GetApplicationName(); - private string _fileName; - private static readonly List Filters = FileDialogFilterComposer.Compose().AddAllFiles(); - private readonly ToolInvokeDesc _toolInvokeDesc; - private Bar.MotionsetType _motionsetType; - private bool _showSlotNumber; - private bool _showMovesetName; - - public static EnumModel MotionsetTypes { get; } = new EnumModel(); - - public string Title => $"{FileName ?? "untitled"} | {ApplicationName}"; - - public BarViewModel(ToolInvokeDesc desc) : this() - { - _toolInvokeDesc = desc; - OpenStream(desc.SelectedEntry.Stream); - - NewCommand = new RelayCommand(x => { }, x => false); - OpenCommand = new RelayCommand(x => { }, x => false); - SaveCommand = new RelayCommand(x => - { - var memoryStream = new MemoryStream(); - - Bar.Write(memoryStream, Items.Select(item => item.Entry), MotionsetType); - - var stream = _toolInvokeDesc.SelectedEntry.Stream; - - stream.Position = 0; - stream.SetLength(0); - memoryStream.Position = 0; - memoryStream.CopyTo(stream); - }); - SaveAsCommand = new RelayCommand(x => { }, x => false); - } - - public BarViewModel() : base(new BarEntryModel[0]) - { - Types = new EnumModel(); - - NewCommand = new RelayCommand(x => - { - FileName = "untitled.bar"; - Items.Clear(); - MotionsetType = 0; - }, x => true); - - OpenCommand = new RelayCommand(x => - { - FileDialog.OnOpen(fileName => - { - OpenFileName(fileName); - FileName = fileName; - }, Filters); - }, x => true); - - SaveCommand = new RelayCommand(x => - { - if (!string.IsNullOrEmpty(FileName)) - { - SaveToFile(FileName); - } - else - { - SaveAsCommand.Execute(x); - } - }, x => true); - - SaveAsCommand = new RelayCommand(x => - { - FileDialog.OnSave(fileName => - { - SaveToFile(fileName); - }, Filters, Path.GetFileName(FileName)); - }, x => true); - - ExitCommand = new RelayCommand(x => - { - Window.Close(); - }, x => true); - - AboutCommand = new RelayCommand(x => - { - new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); - }, x => true); - - OpenItemCommand = new RelayCommand(x => - { - try - { - var tempFileName = SaveToTempraryFile(); - switch (ToolsLoaderService.OpenTool(FileName, tempFileName, SelectedItem.Entry)) - { - case Common.ToolInvokeDesc.ContentChangeInfo.File: - ReloadFromTemporaryFile(tempFileName); - break; - } - } - catch (Exception e) - { - MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); - } - OnPropertyChanged(nameof(SelectedItem)); - }, x => true); - - ExportCommand = new RelayCommand(x => - { - var defaultFileName = GetSuggestedFileName(SelectedItem.Entry); - - FileDialog.OnSave(fileName => - { - using var fStream = File.OpenWrite(fileName); - SelectedItem.Entry.Stream.Position = 0; - SelectedItem.Entry.Stream.CopyTo(fStream); - }, Filters, defaultFileName); - }, x => IsItemSelected); - - ExportAllCommand = new RelayCommand(x => - { - FileDialog.OnFolder(folder => - { - foreach (var item in Items.Select(item => item.Entry)) - { - var fileName = GetSuggestedFileName(item); - using var fStream = File.OpenWrite(Path.Combine(folder, fileName)); - item.Stream.Position = 0; - item.Stream.CopyTo(fStream); - } - }); - }, x => true); - - ImportCommand = new RelayCommand(x => - { - FileDialog.OnOpen(fileName => - { - var fStream = File.OpenRead(fileName); - var memStream = new MemoryStream((int)fStream.Length); - fStream.CopyTo(memStream); - SelectedItem.Entry.Stream = memStream; - - OnPropertyChanged(nameof(SelectedItem)); - }, Filters); - }, x => IsItemSelected); - } - - public void OpenFileName(string fileName) - { - using var stream = File.Open(fileName, FileMode.Open); - OpenStream(stream); - } - - private void OpenStream(Stream stream) - { - Items.Clear(); - - var binarc = Bar.Read(stream); - ShowMovesetName = AutodetectMsetFile(binarc); - ShowSlotNumber = ShowMovesetName; - - MotionsetType = binarc.Motionset; - - foreach (var item in binarc) - { - Items.Add(new BarEntryModel(item, this)); - } - } - - private void SaveToFile(string fileName) - { - var memoryStream = new MemoryStream(); - Bar.Write(memoryStream, Items.Select(item => item.Entry), MotionsetType); - - using var stream = File.Open(fileName, FileMode.Create); - memoryStream.Position = 0; - memoryStream.CopyTo(stream); - } - - private string GetTemporaryFileName(string actualFileName) - { - return Path.GetTempFileName(); - } - - private string SaveToTempraryFile() - { - var tempFileName = GetTemporaryFileName(FileName); - SaveToFile(tempFileName); - - return tempFileName; - } - - private void ReloadFromTemporaryFile(string tempFileName) - { - OpenFileName(tempFileName); - } - - private static string GetSuggestedFileName(Bar.Entry item) => - $"{item.Name}_{item.Index}.{Helpers.GetSuggestedExtension(item.Type)}"; - - private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - - public string FileName - { - get => _fileName; - set - { - _fileName = value; - OnPropertyChanged(nameof(Title)); - } - } - - public Bar.MotionsetType MotionsetType - { - get => _motionsetType; - set - { - _motionsetType = value; - InvalidateBarEntryTags(); - OnPropertyChanged(nameof(MotionsetType)); - OnPropertyChanged(nameof(IsMsetInfoVisible)); - } - } - - public Visibility IsMsetInfoVisible => - MotionsetType == Bar.MotionsetType.Player && - ShowMovesetName == true ? Visibility.Visible : Visibility.Collapsed; - - public RelayCommand NewCommand { get; set; } - public RelayCommand OpenCommand { get; set; } - public RelayCommand SaveCommand { get; set; } - public RelayCommand SaveAsCommand { get; set; } - public RelayCommand ExitCommand { get; set; } - public RelayCommand AboutCommand { get; set; } - public RelayCommand ExportCommand { get; set; } - public RelayCommand ExportAllCommand { get; set; } - public RelayCommand ImportCommand { get; set; } - public RelayCommand OpenItemCommand { get; set; } - - public EnumModel Types { get; set; } - - public string ExportFileName => IsItemSelected ? - GetSuggestedFileName(SelectedItem.Entry) : string.Empty; - - public bool IsPlayer => MotionsetType != Bar.MotionsetType.Default; - - public bool ShowSlotNumber - { - get => _showSlotNumber; - set - { - _showSlotNumber = value; - InvalidateBarEntryTags(); - OnPropertyChanged(); - } - } - - public bool ShowMovesetName - { - get => _showMovesetName; - set - { - _showMovesetName = value; - InvalidateBarEntryTags(); - OnPropertyChanged(); - OnPropertyChanged(nameof(IsMsetInfoVisible)); - } - } - - public int GetSlotIndex(BarEntryModel item) => Items.IndexOf(item); - - private void InvalidateBarEntryTags() - { - foreach (var item in Items) - item.InvalidateTag(); - } - - protected override BarEntryModel OnNewItem() - { - return new BarEntryModel(new Bar.Entry() - { - Stream = new MemoryStream() - }, this); - } - - protected override void OnSelectedItem(BarEntryModel item) - { - base.OnSelectedItem(item); - - ExportCommand.CanExecute(SelectedItem); - ImportCommand.CanExecute(SelectedItem); - OpenItemCommand.CanExecute(SelectedItem); - - OnPropertyChanged(nameof(ExportFileName)); - } - - private static bool AutodetectMsetFile(Bar binarc) - { - // When the motionset type is not default, it's easy to assume it's a MSET. - if (binarc.Motionset != Bar.MotionsetType.Default) - return true; - - // When not, we need to make an assumption. For example a MSET usually - // contains a bunch of ANB. We can say that if we find mroe tha N ANB - // entries then it's a MSET. - const int AnbCountAssumption = 4; - return binarc.Count(x => x.Type == Bar.EntryType.Anb) >= AnbCountAssumption; - } - } -} +using OpenKh.Kh2; +using OpenKh.Tools.BarEditor.Interfaces; +using OpenKh.Tools.BarEditor.Models; +using OpenKh.Tools.BarEditor.Services; +using OpenKh.Tools.Common; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows; +using Xe.Tools.Models; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.BarEditor.ViewModels +{ + public class BarViewModel : GenericListModel, IViewSettings + { + private static string ApplicationName = Utilities.GetApplicationName(); + private string _fileName; + private static readonly List Filters = FileDialogFilterComposer.Compose().AddAllFiles(); + private readonly ToolInvokeDesc _toolInvokeDesc; + private Bar.MotionsetType _motionsetType; + private bool _showSlotNumber; + private bool _showMovesetName; + + public static EnumModel MotionsetTypes { get; } = new EnumModel(); + + public string Title => $"{FileName ?? "untitled"} | {ApplicationName}"; + + public BarViewModel(ToolInvokeDesc desc) : this() + { + _toolInvokeDesc = desc; + OpenStream(desc.SelectedEntry.Stream); + + NewCommand = new RelayCommand(x => { }, x => false); + OpenCommand = new RelayCommand(x => { }, x => false); + SaveCommand = new RelayCommand(x => + { + var memoryStream = new MemoryStream(); + + Bar.Write(memoryStream, Items.Select(item => item.Entry), MotionsetType); + + var stream = _toolInvokeDesc.SelectedEntry.Stream; + + stream.Position = 0; + stream.SetLength(0); + memoryStream.Position = 0; + memoryStream.CopyTo(stream); + }); + SaveAsCommand = new RelayCommand(x => { }, x => false); + } + + public BarViewModel() : base(new BarEntryModel[0]) + { + Types = new EnumModel(); + + NewCommand = new RelayCommand(x => + { + FileName = "untitled.bar"; + Items.Clear(); + MotionsetType = 0; + }, x => true); + + OpenCommand = new RelayCommand(x => + { + FileDialog.OnOpen(fileName => + { + OpenFileName(fileName); + FileName = fileName; + }, Filters); + }, x => true); + + SaveCommand = new RelayCommand(x => + { + if (!string.IsNullOrEmpty(FileName)) + { + SaveToFile(FileName); + } + else + { + SaveAsCommand.Execute(x); + } + }, x => true); + + SaveAsCommand = new RelayCommand(x => + { + FileDialog.OnSave(fileName => + { + SaveToFile(fileName); + }, Filters, Path.GetFileName(FileName)); + }, x => true); + + ExitCommand = new RelayCommand(x => + { + Window.Close(); + }, x => true); + + AboutCommand = new RelayCommand(x => + { + new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); + }, x => true); + + OpenItemCommand = new RelayCommand(x => + { + try + { + var tempFileName = SaveToTempraryFile(); + switch (ToolsLoaderService.OpenTool(FileName, tempFileName, SelectedItem.Entry)) + { + case Common.ToolInvokeDesc.ContentChangeInfo.File: + ReloadFromTemporaryFile(tempFileName); + break; + } + } + catch (Exception e) + { + MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + OnPropertyChanged(nameof(SelectedItem)); + }, x => true); + + ExportCommand = new RelayCommand(x => + { + var defaultFileName = GetSuggestedFileName(SelectedItem.Entry); + + FileDialog.OnSave(fileName => + { + using var fStream = File.OpenWrite(fileName); + SelectedItem.Entry.Stream.Position = 0; + SelectedItem.Entry.Stream.CopyTo(fStream); + }, Filters, defaultFileName); + }, x => IsItemSelected); + + ExportAllCommand = new RelayCommand(x => + { + FileDialog.OnFolder(folder => + { + foreach (var item in Items.Select(item => item.Entry)) + { + var fileName = GetSuggestedFileName(item); + using var fStream = File.OpenWrite(Path.Combine(folder, fileName)); + item.Stream.Position = 0; + item.Stream.CopyTo(fStream); + } + }); + }, x => true); + + ImportCommand = new RelayCommand(x => + { + FileDialog.OnOpen(fileName => + { + var fStream = File.OpenRead(fileName); + var memStream = new MemoryStream((int)fStream.Length); + fStream.CopyTo(memStream); + SelectedItem.Entry.Stream = memStream; + + OnPropertyChanged(nameof(SelectedItem)); + }, Filters); + }, x => IsItemSelected); + } + + public void OpenFileName(string fileName) + { + using var stream = File.Open(fileName, FileMode.Open); + OpenStream(stream); + } + + private void OpenStream(Stream stream) + { + Items.Clear(); + + var binarc = Bar.Read(stream); + ShowMovesetName = AutodetectMsetFile(binarc); + ShowSlotNumber = ShowMovesetName; + + MotionsetType = binarc.Motionset; + + foreach (var item in binarc) + { + Items.Add(new BarEntryModel(item, this)); + } + } + + private void SaveToFile(string fileName) + { + var memoryStream = new MemoryStream(); + Bar.Write(memoryStream, Items.Select(item => item.Entry), MotionsetType); + + using var stream = File.Open(fileName, FileMode.Create); + memoryStream.Position = 0; + memoryStream.CopyTo(stream); + } + + private string GetTemporaryFileName(string actualFileName) + { + return Path.GetTempFileName(); + } + + private string SaveToTempraryFile() + { + var tempFileName = GetTemporaryFileName(FileName); + SaveToFile(tempFileName); + + return tempFileName; + } + + private void ReloadFromTemporaryFile(string tempFileName) + { + OpenFileName(tempFileName); + } + + private static string GetSuggestedFileName(Bar.Entry item) => + $"{item.Name}_{item.Index}.{Helpers.GetSuggestedExtension(item.Type)}"; + + private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + + public string FileName + { + get => _fileName; + set + { + _fileName = value; + OnPropertyChanged(nameof(Title)); + } + } + + public Bar.MotionsetType MotionsetType + { + get => _motionsetType; + set + { + _motionsetType = value; + InvalidateBarEntryTags(); + OnPropertyChanged(nameof(MotionsetType)); + OnPropertyChanged(nameof(IsMsetInfoVisible)); + } + } + + public Visibility IsMsetInfoVisible => + MotionsetType == Bar.MotionsetType.Player && + ShowMovesetName == true ? Visibility.Visible : Visibility.Collapsed; + + public RelayCommand NewCommand { get; set; } + public RelayCommand OpenCommand { get; set; } + public RelayCommand SaveCommand { get; set; } + public RelayCommand SaveAsCommand { get; set; } + public RelayCommand ExitCommand { get; set; } + public RelayCommand AboutCommand { get; set; } + public RelayCommand ExportCommand { get; set; } + public RelayCommand ExportAllCommand { get; set; } + public RelayCommand ImportCommand { get; set; } + public RelayCommand OpenItemCommand { get; set; } + + public EnumModel Types { get; set; } + + public string ExportFileName => IsItemSelected ? + GetSuggestedFileName(SelectedItem.Entry) : string.Empty; + + public bool IsPlayer => MotionsetType != Bar.MotionsetType.Default; + + public bool ShowSlotNumber + { + get => _showSlotNumber; + set + { + _showSlotNumber = value; + InvalidateBarEntryTags(); + OnPropertyChanged(); + } + } + + public bool ShowMovesetName + { + get => _showMovesetName; + set + { + _showMovesetName = value; + InvalidateBarEntryTags(); + OnPropertyChanged(); + OnPropertyChanged(nameof(IsMsetInfoVisible)); + } + } + + public int GetSlotIndex(BarEntryModel item) => Items.IndexOf(item); + + private void InvalidateBarEntryTags() + { + foreach (var item in Items) + item.InvalidateTag(); + } + + protected override BarEntryModel OnNewItem() + { + return new BarEntryModel(new Bar.Entry() + { + Stream = new MemoryStream() + }, this); + } + + protected override void OnSelectedItem(BarEntryModel item) + { + base.OnSelectedItem(item); + + ExportCommand.CanExecute(SelectedItem); + ImportCommand.CanExecute(SelectedItem); + OpenItemCommand.CanExecute(SelectedItem); + + OnPropertyChanged(nameof(ExportFileName)); + } + + private static bool AutodetectMsetFile(Bar binarc) + { + // When the motionset type is not default, it's easy to assume it's a MSET. + if (binarc.Motionset != Bar.MotionsetType.Default) + return true; + + // When not, we need to make an assumption. For example a MSET usually + // contains a bunch of ANB. We can say that if we find mroe tha N ANB + // entries then it's a MSET. + const int AnbCountAssumption = 4; + return binarc.Count(x => x.Type == Bar.EntryType.Anb) >= AnbCountAssumption; + } + } +} diff --git a/OpenKh.Tools.BarEditor/Views/BarView.xaml.cs b/OpenKh.Tools.BarEditor/Views/BarView.xaml.cs index b870ea01a..9529a1867 100644 --- a/OpenKh.Tools.BarEditor/Views/BarView.xaml.cs +++ b/OpenKh.Tools.BarEditor/Views/BarView.xaml.cs @@ -1,50 +1,50 @@ -using OpenKh.Kh2; -using OpenKh.Tools.BarEditor.ViewModels; -using OpenKh.Tools.Common; -using System.Linq; -using System.Windows; -using System.Windows.Input; -using System.Windows.Markup; - -namespace OpenKh.Tools.BarEditor.Views -{ - /// - /// Interaction logic for BarView.xaml - /// - public partial class BarView : Window - { - public BarView() - { - InitializeComponent(); - DataContext = new BarViewModel(); - } - - public BarView(ToolInvokeDesc desc) : - base() - { - var vm = DataContext as BarViewModel; - DataContext = new BarViewModel(desc); - } - - private void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - var vm = DataContext as BarViewModel; - vm.OpenItemCommand.Execute(vm.SelectedItem); - } - - private void Window_Drop(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop)) - { - var files = e.Data.GetData(DataFormats.FileDrop) as string[]; - var fileName = files?.FirstOrDefault(); - if (string.IsNullOrEmpty(fileName)) - return; - - var vm = DataContext as BarViewModel; - vm.OpenFileName(fileName); - vm.FileName = fileName; - } - } - } -} +using OpenKh.Kh2; +using OpenKh.Tools.BarEditor.ViewModels; +using OpenKh.Tools.Common; +using System.Linq; +using System.Windows; +using System.Windows.Input; +using System.Windows.Markup; + +namespace OpenKh.Tools.BarEditor.Views +{ + /// + /// Interaction logic for BarView.xaml + /// + public partial class BarView : Window + { + public BarView() + { + InitializeComponent(); + DataContext = new BarViewModel(); + } + + public BarView(ToolInvokeDesc desc) : + base() + { + var vm = DataContext as BarViewModel; + DataContext = new BarViewModel(desc); + } + + private void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) + { + var vm = DataContext as BarViewModel; + vm.OpenItemCommand.Execute(vm.SelectedItem); + } + + private void Window_Drop(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + { + var files = e.Data.GetData(DataFormats.FileDrop) as string[]; + var fileName = files?.FirstOrDefault(); + if (string.IsNullOrEmpty(fileName)) + return; + + var vm = DataContext as BarViewModel; + vm.OpenFileName(fileName); + vm.FileName = fileName; + } + } + } +} diff --git a/OpenKh.Tools.BbsEventTableEditor/App.xaml.cs b/OpenKh.Tools.BbsEventTableEditor/App.xaml.cs index bde7278ef..0f836f48e 100644 --- a/OpenKh.Tools.BbsEventTableEditor/App.xaml.cs +++ b/OpenKh.Tools.BbsEventTableEditor/App.xaml.cs @@ -1,11 +1,11 @@ -using System.Windows; - -namespace OpenKh.Tools.BbsEventTableEditor -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} +using System.Windows; + +namespace OpenKh.Tools.BbsEventTableEditor +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/OpenKh.Tools.BbsEventTableEditor/ViewModels/EventViewModel.cs b/OpenKh.Tools.BbsEventTableEditor/ViewModels/EventViewModel.cs index b5dc52588..82594f186 100644 --- a/OpenKh.Tools.BbsEventTableEditor/ViewModels/EventViewModel.cs +++ b/OpenKh.Tools.BbsEventTableEditor/ViewModels/EventViewModel.cs @@ -1,125 +1,125 @@ -using OpenKh.Bbs; -using System; -using System.Collections.Generic; -using System.Linq; -using Xe.Tools; - -namespace OpenKh.Tools.BbsEventTableEditor.ViewModels -{ - public class EventViewModel : BaseNotifyPropertyChanged - { - private static readonly Dictionary _worlds = Constants.WorldNames - .Select((x, i) => new { Name = x, Id = i }) - .ToDictionary(x => (byte)x.Id, x => x.Name); - - public static Dictionary AsDictionary(string[] values) => - values.Select((value, index) => (value, index)).ToDictionary(x => x.index, x => x.value); - - private static readonly Dictionary[] _rooms = new[] - { - AsDictionary(Constants.Rooms_DP), - AsDictionary(Constants.Rooms_DP), - AsDictionary(Constants.Rooms_SW), - AsDictionary(Constants.Rooms_CD), - AsDictionary(Constants.Rooms_SB), - AsDictionary(Constants.Rooms_YT), - AsDictionary(Constants.Rooms_RG), - AsDictionary(Constants.Rooms_JB), - AsDictionary(Constants.Rooms_HE), - AsDictionary(Constants.Rooms_LS), - AsDictionary(Constants.Rooms_DI), - AsDictionary(Constants.Rooms_PP), - AsDictionary(Constants.Rooms_DC), - AsDictionary(Constants.Rooms_KG), - AsDictionary(Constants.Rooms_DP), - AsDictionary(Constants.Rooms_VS), - AsDictionary(Constants.Rooms_BD) - }; - - public EventViewModel(Event @event) - { - Event = @event; - } - - public Event Event { get; private set; } - - public IEnumerable> Worlds => _worlds; - public Dictionary Rooms => _rooms[World]; - - public ushort Id - { - get => Event.Id; - set - { - Event.Id = value; - OnPropertyChanged(nameof(Name)); - } - } - - public ushort EventIndex - { - get => Event.EventIndex; - set - { - Event.EventIndex = (byte)Math.Min(999, (int)value); - OnPropertyChanged(nameof(Name)); - OnPropertyChanged(nameof(EventPath)); - } - } - - public byte World - { - get => Event.World; - set - { - Event.World = (byte)Math.Min(Constants.Worlds.Length, value); - OnPropertyChanged(nameof(Name)); - OnPropertyChanged(nameof(EventPath)); - OnPropertyChanged(nameof(Rooms)); - } - } - - public byte Room - { - get => Event.Room; - set - { - Event.Room = (byte)Math.Min(99, (int)value); - OnPropertyChanged(nameof(Name)); - OnPropertyChanged(nameof(MapPath)); - OnPropertyChanged(nameof(Rooms)); - } - } - - public byte EventPtn - { - get => Event.EventPtn; - set - { - Event.EventPtn = value; - OnPropertyChanged(nameof(Name)); - } - } - - public byte Opt - { - get => Event.Opt; - set - { - Event.Opt = value; - OnPropertyChanged(nameof(Name)); - } - } - - private string WorldId => World >= 0 && World < Constants.Worlds.Length ? - Constants.Worlds[World] : "{invalid}"; - - public string Name => $"{Id} {WorldId.ToUpper()} {Room:D02} {EventIndex:D03}"; - - public string MapPath => $"arc/map/{WorldId}{Room:D02}.arc"; - - public string EventPath => $"event/{WorldId}/{WorldId}_{EventIndex:D03}.exa"; - - public override string ToString() => Name; - } -} +using OpenKh.Bbs; +using System; +using System.Collections.Generic; +using System.Linq; +using Xe.Tools; + +namespace OpenKh.Tools.BbsEventTableEditor.ViewModels +{ + public class EventViewModel : BaseNotifyPropertyChanged + { + private static readonly Dictionary _worlds = Constants.WorldNames + .Select((x, i) => new { Name = x, Id = i }) + .ToDictionary(x => (byte)x.Id, x => x.Name); + + public static Dictionary AsDictionary(string[] values) => + values.Select((value, index) => (value, index)).ToDictionary(x => x.index, x => x.value); + + private static readonly Dictionary[] _rooms = new[] + { + AsDictionary(Constants.Rooms_DP), + AsDictionary(Constants.Rooms_DP), + AsDictionary(Constants.Rooms_SW), + AsDictionary(Constants.Rooms_CD), + AsDictionary(Constants.Rooms_SB), + AsDictionary(Constants.Rooms_YT), + AsDictionary(Constants.Rooms_RG), + AsDictionary(Constants.Rooms_JB), + AsDictionary(Constants.Rooms_HE), + AsDictionary(Constants.Rooms_LS), + AsDictionary(Constants.Rooms_DI), + AsDictionary(Constants.Rooms_PP), + AsDictionary(Constants.Rooms_DC), + AsDictionary(Constants.Rooms_KG), + AsDictionary(Constants.Rooms_DP), + AsDictionary(Constants.Rooms_VS), + AsDictionary(Constants.Rooms_BD) + }; + + public EventViewModel(Event @event) + { + Event = @event; + } + + public Event Event { get; private set; } + + public IEnumerable> Worlds => _worlds; + public Dictionary Rooms => _rooms[World]; + + public ushort Id + { + get => Event.Id; + set + { + Event.Id = value; + OnPropertyChanged(nameof(Name)); + } + } + + public ushort EventIndex + { + get => Event.EventIndex; + set + { + Event.EventIndex = (byte)Math.Min(999, (int)value); + OnPropertyChanged(nameof(Name)); + OnPropertyChanged(nameof(EventPath)); + } + } + + public byte World + { + get => Event.World; + set + { + Event.World = (byte)Math.Min(Constants.Worlds.Length, value); + OnPropertyChanged(nameof(Name)); + OnPropertyChanged(nameof(EventPath)); + OnPropertyChanged(nameof(Rooms)); + } + } + + public byte Room + { + get => Event.Room; + set + { + Event.Room = (byte)Math.Min(99, (int)value); + OnPropertyChanged(nameof(Name)); + OnPropertyChanged(nameof(MapPath)); + OnPropertyChanged(nameof(Rooms)); + } + } + + public byte EventPtn + { + get => Event.EventPtn; + set + { + Event.EventPtn = value; + OnPropertyChanged(nameof(Name)); + } + } + + public byte Opt + { + get => Event.Opt; + set + { + Event.Opt = value; + OnPropertyChanged(nameof(Name)); + } + } + + private string WorldId => World >= 0 && World < Constants.Worlds.Length ? + Constants.Worlds[World] : "{invalid}"; + + public string Name => $"{Id} {WorldId.ToUpper()} {Room:D02} {EventIndex:D03}"; + + public string MapPath => $"arc/map/{WorldId}{Room:D02}.arc"; + + public string EventPath => $"event/{WorldId}/{WorldId}_{EventIndex:D03}.exa"; + + public override string ToString() => Name; + } +} diff --git a/OpenKh.Tools.BbsEventTableEditor/ViewModels/EventsViewModel.cs b/OpenKh.Tools.BbsEventTableEditor/ViewModels/EventsViewModel.cs index ae6a12488..a67e40911 100644 --- a/OpenKh.Tools.BbsEventTableEditor/ViewModels/EventsViewModel.cs +++ b/OpenKh.Tools.BbsEventTableEditor/ViewModels/EventsViewModel.cs @@ -1,34 +1,34 @@ -using OpenKh.Bbs; -using System.Collections.Generic; -using System.Linq; -using System.Windows; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.BbsEventTableEditor.ViewModels -{ - public class EventsViewModel : GenericListModel - { - public EventsViewModel() : - this(new Event[0]) - { } - - public EventsViewModel(IEnumerable events) : - base(events.Select(x => new EventViewModel(x))) - { - - } - - public Visibility GuideVisibility => IsItemSelected ? Visibility.Collapsed : Visibility.Visible; - public Visibility EditVisibility => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - - protected override void OnSelectedItem(EventViewModel item) - { - OnPropertyChanged(nameof(GuideVisibility)); - OnPropertyChanged(nameof(EditVisibility)); - base.OnSelectedItem(item); - } - - protected override EventViewModel OnNewItem() => - new EventViewModel(new Event()); - } -} +using OpenKh.Bbs; +using System.Collections.Generic; +using System.Linq; +using System.Windows; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.BbsEventTableEditor.ViewModels +{ + public class EventsViewModel : GenericListModel + { + public EventsViewModel() : + this(new Event[0]) + { } + + public EventsViewModel(IEnumerable events) : + base(events.Select(x => new EventViewModel(x))) + { + + } + + public Visibility GuideVisibility => IsItemSelected ? Visibility.Collapsed : Visibility.Visible; + public Visibility EditVisibility => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + + protected override void OnSelectedItem(EventViewModel item) + { + OnPropertyChanged(nameof(GuideVisibility)); + OnPropertyChanged(nameof(EditVisibility)); + base.OnSelectedItem(item); + } + + protected override EventViewModel OnNewItem() => + new EventViewModel(new Event()); + } +} diff --git a/OpenKh.Tools.BbsEventTableEditor/ViewModels/MainViewModel.cs b/OpenKh.Tools.BbsEventTableEditor/ViewModels/MainViewModel.cs index d9a70c78b..8dd538057 100644 --- a/OpenKh.Tools.BbsEventTableEditor/ViewModels/MainViewModel.cs +++ b/OpenKh.Tools.BbsEventTableEditor/ViewModels/MainViewModel.cs @@ -1,178 +1,178 @@ -using OpenKh.Bbs; -using OpenKh.Common; -using OpenKh.Tools.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Windows; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.BbsEventTableEditor.ViewModels -{ - public class MainViewModel : BaseNotifyPropertyChanged - { - private static string ApplicationName = Utilities.GetApplicationName(); - private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - private string _fileName; - private EventsViewModel _eventsViewModel; - - private static readonly List Filters = FileDialogFilterComposer.Compose().AddExtensions("Event table (EVENT_TE, EVENT_VE, EVENT_AQ)", "*").AddAllFiles(); - - public string Title => $"{Path.GetFileName(FileName) ?? "untitled"} | {ApplicationName}"; - - private string FileName - { - get => _fileName; - set - { - _fileName = value; - OnPropertyChanged(nameof(Title)); - } - } - - public RelayCommand OpenCommand { get; } - public RelayCommand SaveCommand { get; } - public RelayCommand SaveAsCommand { get; } - public RelayCommand ExitCommand { get; } - public RelayCommand ExportEventsListCommand { get; } - public RelayCommand ExportUsedEventsCommand { get; } - public RelayCommand ExportUsedMapsCommand { get; } - public RelayCommand AboutCommand { get; } - - public EventsViewModel EventsViewModel - { - get => _eventsViewModel; - private set { _eventsViewModel = value; OnPropertyChanged(); } - } - - public IEnumerable Events - { - get => EventsViewModel?.Items?.Select(x => x.Event) ?? new Event[0]; - set => EventsViewModel = new EventsViewModel(value); - } - - public MainViewModel() - { - OpenCommand = new RelayCommand(x => - { - FileDialog.OnOpen(fileName => - { - OpenFile(fileName); - }, Filters); - }, x => true); - - SaveCommand = new RelayCommand(x => - { - if (!string.IsNullOrEmpty(FileName)) - { - SaveFile(FileName, FileName); - } - else - { - SaveAsCommand.Execute(x); - } - }, x => true); - - SaveAsCommand = new RelayCommand(x => - { - FileDialog.OnSave(fileName => - { - SaveFile(FileName, fileName); - FileName = fileName; - }, Filters); - }, x => true); - - ExitCommand = new RelayCommand(x => - { - Window.Close(); - }, x => true); - - ExportEventsListCommand = new RelayCommand(x => - { - var defaultFileName = CreateExportFilePath("events_list.txt"); - - FileDialog.OnSave(fileName => - { - File.CreateText(fileName).Using(stream => - { - foreach (var item in Events) - { - stream.WriteLine($"ID {item.Id:X03} MAP {Constants.Worlds[item.World]}_{item.Room:D02} EVENT {item.EventIndex:D03}"); - } - }); - }, Filters, defaultFileName); - }, x => true); - - ExportUsedEventsCommand = new RelayCommand(x => - { - var defaultFileName = CreateExportFilePath("events_used.txt"); - - FileDialog.OnSave(fileName => - { - File.CreateText(fileName).Using(stream => - { - foreach (var item in Events) - { - stream.WriteLine($"event/{Constants.Worlds[item.World]}/{Constants.Worlds[item.World]}_{item.EventIndex:D03}.exa"); - } - }); - }, Filters, defaultFileName); - }, x => true); - - ExportUsedMapsCommand = new RelayCommand(x => - { - var defaultFileName = CreateExportFilePath("maps_used.txt"); - - FileDialog.OnSave(fileName => - { - File.CreateText(fileName).Using(stream => - { - foreach (var item in Events) - { - stream.WriteLine($"arc/map/{Constants.Worlds[item.World]}{item.Room:D02}.arc"); - } - }); - }, Filters, defaultFileName); - }, x => true); - - AboutCommand = new RelayCommand(x => - { - new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); - }, x => true); - - EventsViewModel = new EventsViewModel(); - } - - public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => - { - if (!Event.IsValid(stream)) - { - MessageBox.Show(Window, $"{Path.GetFileName(fileName)} is not a valid event file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - return false; - } - - Events = Event.Read(stream); - FileName = fileName; - return true; - }); - - public void SaveFile(string previousFileName, string fileName) - { - File.Create(fileName).Using(stream => - { - Event.Write(stream, Events); - }); - } - - private string CreateExportFilePath(string newFileName) - { - var dirName = Path.GetDirectoryName(FileName); - var fileName = Path.GetFileNameWithoutExtension(FileName); - - return Path.Combine(dirName, $"{fileName}_{newFileName}"); - } - } -} +using OpenKh.Bbs; +using OpenKh.Common; +using OpenKh.Tools.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.BbsEventTableEditor.ViewModels +{ + public class MainViewModel : BaseNotifyPropertyChanged + { + private static string ApplicationName = Utilities.GetApplicationName(); + private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + private string _fileName; + private EventsViewModel _eventsViewModel; + + private static readonly List Filters = FileDialogFilterComposer.Compose().AddExtensions("Event table (EVENT_TE, EVENT_VE, EVENT_AQ)", "*").AddAllFiles(); + + public string Title => $"{Path.GetFileName(FileName) ?? "untitled"} | {ApplicationName}"; + + private string FileName + { + get => _fileName; + set + { + _fileName = value; + OnPropertyChanged(nameof(Title)); + } + } + + public RelayCommand OpenCommand { get; } + public RelayCommand SaveCommand { get; } + public RelayCommand SaveAsCommand { get; } + public RelayCommand ExitCommand { get; } + public RelayCommand ExportEventsListCommand { get; } + public RelayCommand ExportUsedEventsCommand { get; } + public RelayCommand ExportUsedMapsCommand { get; } + public RelayCommand AboutCommand { get; } + + public EventsViewModel EventsViewModel + { + get => _eventsViewModel; + private set { _eventsViewModel = value; OnPropertyChanged(); } + } + + public IEnumerable Events + { + get => EventsViewModel?.Items?.Select(x => x.Event) ?? new Event[0]; + set => EventsViewModel = new EventsViewModel(value); + } + + public MainViewModel() + { + OpenCommand = new RelayCommand(x => + { + FileDialog.OnOpen(fileName => + { + OpenFile(fileName); + }, Filters); + }, x => true); + + SaveCommand = new RelayCommand(x => + { + if (!string.IsNullOrEmpty(FileName)) + { + SaveFile(FileName, FileName); + } + else + { + SaveAsCommand.Execute(x); + } + }, x => true); + + SaveAsCommand = new RelayCommand(x => + { + FileDialog.OnSave(fileName => + { + SaveFile(FileName, fileName); + FileName = fileName; + }, Filters); + }, x => true); + + ExitCommand = new RelayCommand(x => + { + Window.Close(); + }, x => true); + + ExportEventsListCommand = new RelayCommand(x => + { + var defaultFileName = CreateExportFilePath("events_list.txt"); + + FileDialog.OnSave(fileName => + { + File.CreateText(fileName).Using(stream => + { + foreach (var item in Events) + { + stream.WriteLine($"ID {item.Id:X03} MAP {Constants.Worlds[item.World]}_{item.Room:D02} EVENT {item.EventIndex:D03}"); + } + }); + }, Filters, defaultFileName); + }, x => true); + + ExportUsedEventsCommand = new RelayCommand(x => + { + var defaultFileName = CreateExportFilePath("events_used.txt"); + + FileDialog.OnSave(fileName => + { + File.CreateText(fileName).Using(stream => + { + foreach (var item in Events) + { + stream.WriteLine($"event/{Constants.Worlds[item.World]}/{Constants.Worlds[item.World]}_{item.EventIndex:D03}.exa"); + } + }); + }, Filters, defaultFileName); + }, x => true); + + ExportUsedMapsCommand = new RelayCommand(x => + { + var defaultFileName = CreateExportFilePath("maps_used.txt"); + + FileDialog.OnSave(fileName => + { + File.CreateText(fileName).Using(stream => + { + foreach (var item in Events) + { + stream.WriteLine($"arc/map/{Constants.Worlds[item.World]}{item.Room:D02}.arc"); + } + }); + }, Filters, defaultFileName); + }, x => true); + + AboutCommand = new RelayCommand(x => + { + new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); + }, x => true); + + EventsViewModel = new EventsViewModel(); + } + + public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => + { + if (!Event.IsValid(stream)) + { + MessageBox.Show(Window, $"{Path.GetFileName(fileName)} is not a valid event file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + Events = Event.Read(stream); + FileName = fileName; + return true; + }); + + public void SaveFile(string previousFileName, string fileName) + { + File.Create(fileName).Using(stream => + { + Event.Write(stream, Events); + }); + } + + private string CreateExportFilePath(string newFileName) + { + var dirName = Path.GetDirectoryName(FileName); + var fileName = Path.GetFileNameWithoutExtension(FileName); + + return Path.Combine(dirName, $"{fileName}_{newFileName}"); + } + } +} diff --git a/OpenKh.Tools.BbsEventTableEditor/Views/EventsView.xaml.cs b/OpenKh.Tools.BbsEventTableEditor/Views/EventsView.xaml.cs index 483ba8886..ad16d55cc 100644 --- a/OpenKh.Tools.BbsEventTableEditor/Views/EventsView.xaml.cs +++ b/OpenKh.Tools.BbsEventTableEditor/Views/EventsView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace OpenKh.Tools.BbsEventTableEditor.Views -{ - /// - /// Interaction logic for EventsView.xaml - /// - public partial class EventsView : UserControl - { - public EventsView() - { - InitializeComponent(); - } - } -} +using System.Windows.Controls; + +namespace OpenKh.Tools.BbsEventTableEditor.Views +{ + /// + /// Interaction logic for EventsView.xaml + /// + public partial class EventsView : UserControl + { + public EventsView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.BbsEventTableEditor/Views/MainWindow.xaml.cs b/OpenKh.Tools.BbsEventTableEditor/Views/MainWindow.xaml.cs index 84bc85597..a88a86d4c 100644 --- a/OpenKh.Tools.BbsEventTableEditor/Views/MainWindow.xaml.cs +++ b/OpenKh.Tools.BbsEventTableEditor/Views/MainWindow.xaml.cs @@ -1,17 +1,17 @@ -using OpenKh.Tools.BbsEventTableEditor.ViewModels; -using System.Windows; - -namespace OpenKh.Tools.BbsEventTableEditor.Views -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); - DataContext = new MainViewModel(); - } - } -} +using OpenKh.Tools.BbsEventTableEditor.ViewModels; +using System.Windows; + +namespace OpenKh.Tools.BbsEventTableEditor.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + DataContext = new MainViewModel(); + } + } +} diff --git a/OpenKh.Tools.BepEditor/BaseParameters.cs b/OpenKh.Tools.BepEditor/BaseParameters.cs index f64b2bbab..6c701d6be 100644 --- a/OpenKh.Tools.BepEditor/BaseParameters.cs +++ b/OpenKh.Tools.BepEditor/BaseParameters.cs @@ -1,18 +1,18 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; - -namespace OpenKh.Tools.BepEditor -{ - public partial class BaseParameters : UserControl - { - public BaseParameters() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace OpenKh.Tools.BepEditor +{ + public partial class BaseParameters : UserControl + { + public BaseParameters() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.BepEditor/DisappearParameters.cs b/OpenKh.Tools.BepEditor/DisappearParameters.cs index 6c984a092..2abcdf361 100644 --- a/OpenKh.Tools.BepEditor/DisappearParameters.cs +++ b/OpenKh.Tools.BepEditor/DisappearParameters.cs @@ -1,20 +1,20 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; -using OpenKh.Bbs; - -namespace OpenKh.Tools.BepEditor -{ - public partial class DisappearParameters : UserControl - { - public DisappearParameters() - { - InitializeComponent(); - WorldIDComboBox.DataSource = Constants.WorldNames; - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using OpenKh.Bbs; + +namespace OpenKh.Tools.BepEditor +{ + public partial class DisappearParameters : UserControl + { + public DisappearParameters() + { + InitializeComponent(); + WorldIDComboBox.DataSource = Constants.WorldNames; + } + } +} diff --git a/OpenKh.Tools.BepEditor/Form1.cs b/OpenKh.Tools.BepEditor/Form1.cs index b8d24dd29..026388f7c 100644 --- a/OpenKh.Tools.BepEditor/Form1.cs +++ b/OpenKh.Tools.BepEditor/Form1.cs @@ -1,117 +1,117 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.IO; -using OpenKh.Bbs; - -namespace OpenKh.Tools.BepEditor -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - - Bep bep = new Bep(); - Stream bepFile; - - private void UpdateParameters(Bep bep) - { - for(int i = 0; i < bep.baseParameters.Count; i++) - { - BaseParameters baseParam = new BaseParameters(); - baseParam.BaseParamGBox.Text = "Base Param " + (i+1); - baseParam.NumericBattleLevel.Value = bep.baseParameters[i].BattleLevel; - baseParam.NumericBaseAttack.Value = bep.baseParameters[i].BaseAttack; - baseParam.NumericDefense.Value = bep.baseParameters[i].Defense; - baseParam.NumericDamageCeiling.Value = bep.baseParameters[i].DamageCeiling; - baseParam.NumericDamageFloor.Value = bep.baseParameters[i].DamageFloor; - baseParam.NumericBaseHP.Value = bep.baseParameters[i].BaseHP; - baseParam.numericBaseEXP.Value = bep.baseParameters[i].BaseEXP; - BaseStatsLayout.Controls.Add(baseParam); - } - - for (int j = 0; j < bep.disappearParameters.Count; j++) - { - DisappearParameters baseParam = new DisappearParameters(); - baseParam.DisappearGBox.Text = "Disappear Param " + (j+1); - baseParam.WorldIDComboBox.SelectedIndex = bep.disappearParameters[j].WorldID; - baseParam.NumericRoomID.Value = bep.disappearParameters[j].RoomID; - baseParam.DistanceTextBox.Text = bep.disappearParameters[j].Distance.ToString(); - DisappearLayout.Controls.Add(baseParam); - } - } - - private void UpdateWriteInfo() - { - Bep.Header head = bep.header; - bep = new Bep(); - bep.header = head; - - foreach(BaseParameters baseParam in BaseStatsLayout.Controls) - { - Bep.BaseParameter param = new Bep.BaseParameter(); - param.BattleLevel = decimal.ToUInt16(baseParam.NumericBattleLevel.Value); - param.BaseAttack = decimal.ToUInt16(baseParam.NumericBaseAttack.Value); - param.Defense = decimal.ToUInt16(baseParam.NumericDefense.Value); - param.DamageCeiling = decimal.ToByte(baseParam.NumericDamageCeiling.Value); - param.DamageFloor = decimal.ToByte(baseParam.NumericDamageFloor.Value); - param.BaseHP = decimal.ToUInt32(baseParam.NumericBaseHP.Value); - param.BaseEXP = decimal.ToUInt32(baseParam.numericBaseEXP.Value); - bep.baseParameters.Add(param); - } - - foreach (DisappearParameters disappearParam in DisappearLayout.Controls) - { - Bep.DisappearParameter param = new Bep.DisappearParameter(); - param.WorldID = (ushort)disappearParam.WorldIDComboBox.SelectedIndex; - param.RoomID = decimal.ToUInt16(disappearParam.NumericRoomID.Value); - param.Distance = float.Parse(disappearParam.DistanceTextBox.Text); - bep.disappearParameters.Add(param); - } - } - - private void LoadBEP_Click(object sender, EventArgs e) - { - OpenFileDialog dialog = new OpenFileDialog(); - dialog.Filter = "Base Enemy Parameters files (*.bep)|*.bep|All files (*.*)|*.*"; - DialogResult result = dialog.ShowDialog(); - - if (result == DialogResult.OK) - { - BaseStatsLayout.Controls.Clear(); - DisappearLayout.Controls.Clear(); - if (bepFile != null) - bepFile.Close(); - bepFile = File.OpenRead(dialog.FileName); - bep = Bep.Read(bepFile); - UpdateParameters(bep); - SaveBEP.Enabled = true; - } - } - - private void SaveBEP_Click(object sender, EventArgs e) - { - SaveFileDialog dialog = new SaveFileDialog(); - dialog.Filter = "Base Enemy Parameters files (*.bep)|*.bep|All files (*.*)|*.*"; - DialogResult result = dialog.ShowDialog(); - - if (result == DialogResult.OK) - { - Stream bepOut = File.OpenWrite(dialog.FileName); - UpdateWriteInfo(); - Bep.Write(bepOut, bep); - bepOut.Close(); - } - - MessageBox.Show("File saved successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.IO; +using OpenKh.Bbs; + +namespace OpenKh.Tools.BepEditor +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + Bep bep = new Bep(); + Stream bepFile; + + private void UpdateParameters(Bep bep) + { + for (int i = 0; i < bep.baseParameters.Count; i++) + { + BaseParameters baseParam = new BaseParameters(); + baseParam.BaseParamGBox.Text = "Base Param " + (i + 1); + baseParam.NumericBattleLevel.Value = bep.baseParameters[i].BattleLevel; + baseParam.NumericBaseAttack.Value = bep.baseParameters[i].BaseAttack; + baseParam.NumericDefense.Value = bep.baseParameters[i].Defense; + baseParam.NumericDamageCeiling.Value = bep.baseParameters[i].DamageCeiling; + baseParam.NumericDamageFloor.Value = bep.baseParameters[i].DamageFloor; + baseParam.NumericBaseHP.Value = bep.baseParameters[i].BaseHP; + baseParam.numericBaseEXP.Value = bep.baseParameters[i].BaseEXP; + BaseStatsLayout.Controls.Add(baseParam); + } + + for (int j = 0; j < bep.disappearParameters.Count; j++) + { + DisappearParameters baseParam = new DisappearParameters(); + baseParam.DisappearGBox.Text = "Disappear Param " + (j + 1); + baseParam.WorldIDComboBox.SelectedIndex = bep.disappearParameters[j].WorldID; + baseParam.NumericRoomID.Value = bep.disappearParameters[j].RoomID; + baseParam.DistanceTextBox.Text = bep.disappearParameters[j].Distance.ToString(); + DisappearLayout.Controls.Add(baseParam); + } + } + + private void UpdateWriteInfo() + { + Bep.Header head = bep.header; + bep = new Bep(); + bep.header = head; + + foreach (BaseParameters baseParam in BaseStatsLayout.Controls) + { + Bep.BaseParameter param = new Bep.BaseParameter(); + param.BattleLevel = decimal.ToUInt16(baseParam.NumericBattleLevel.Value); + param.BaseAttack = decimal.ToUInt16(baseParam.NumericBaseAttack.Value); + param.Defense = decimal.ToUInt16(baseParam.NumericDefense.Value); + param.DamageCeiling = decimal.ToByte(baseParam.NumericDamageCeiling.Value); + param.DamageFloor = decimal.ToByte(baseParam.NumericDamageFloor.Value); + param.BaseHP = decimal.ToUInt32(baseParam.NumericBaseHP.Value); + param.BaseEXP = decimal.ToUInt32(baseParam.numericBaseEXP.Value); + bep.baseParameters.Add(param); + } + + foreach (DisappearParameters disappearParam in DisappearLayout.Controls) + { + Bep.DisappearParameter param = new Bep.DisappearParameter(); + param.WorldID = (ushort)disappearParam.WorldIDComboBox.SelectedIndex; + param.RoomID = decimal.ToUInt16(disappearParam.NumericRoomID.Value); + param.Distance = float.Parse(disappearParam.DistanceTextBox.Text); + bep.disappearParameters.Add(param); + } + } + + private void LoadBEP_Click(object sender, EventArgs e) + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Filter = "Base Enemy Parameters files (*.bep)|*.bep|All files (*.*)|*.*"; + DialogResult result = dialog.ShowDialog(); + + if (result == DialogResult.OK) + { + BaseStatsLayout.Controls.Clear(); + DisappearLayout.Controls.Clear(); + if (bepFile != null) + bepFile.Close(); + bepFile = File.OpenRead(dialog.FileName); + bep = Bep.Read(bepFile); + UpdateParameters(bep); + SaveBEP.Enabled = true; + } + } + + private void SaveBEP_Click(object sender, EventArgs e) + { + SaveFileDialog dialog = new SaveFileDialog(); + dialog.Filter = "Base Enemy Parameters files (*.bep)|*.bep|All files (*.*)|*.*"; + DialogResult result = dialog.ShowDialog(); + + if (result == DialogResult.OK) + { + Stream bepOut = File.OpenWrite(dialog.FileName); + UpdateWriteInfo(); + Bep.Write(bepOut, bep); + bepOut.Close(); + } + + MessageBox.Show("File saved successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } +} diff --git a/OpenKh.Tools.BepEditor/Program.cs b/OpenKh.Tools.BepEditor/Program.cs index 802387825..8ba73bbcc 100644 --- a/OpenKh.Tools.BepEditor/Program.cs +++ b/OpenKh.Tools.BepEditor/Program.cs @@ -1,23 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace OpenKh.Tools.BepEditor -{ - static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.SetHighDpiMode(HighDpiMode.SystemAware); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace OpenKh.Tools.BepEditor +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/OpenKh.Tools.Common.CustomImGui/IImGuiRenderer.cs b/OpenKh.Tools.Common.CustomImGui/IImGuiRenderer.cs index 0a3226354..401f971d3 100644 --- a/OpenKh.Tools.Common.CustomImGui/IImGuiRenderer.cs +++ b/OpenKh.Tools.Common.CustomImGui/IImGuiRenderer.cs @@ -1,7 +1,7 @@ -namespace OpenKh.Tools.Common.CustomImGui -{ - public interface IImGuiRenderer - { - void RebuildFontAtlas(); - } -} +namespace OpenKh.Tools.Common.CustomImGui +{ + public interface IImGuiRenderer + { + void RebuildFontAtlas(); + } +} diff --git a/OpenKh.Tools.Common.CustomImGui/ImGuiEx.cs b/OpenKh.Tools.Common.CustomImGui/ImGuiEx.cs index c221d92aa..27eead3c2 100644 --- a/OpenKh.Tools.Common.CustomImGui/ImGuiEx.cs +++ b/OpenKh.Tools.Common.CustomImGui/ImGuiEx.cs @@ -1,260 +1,260 @@ -using ImGuiNET; -using System; -using System.Linq; -using System.Numerics; -using System.Reflection.Metadata.Ecma335; - -namespace OpenKh.Tools.Common.CustomImGui -{ - public static class ImGuiEx - { - public struct GridElement - { - public string Name; - public float Size; - public float MaxSize; - public bool Border; - public Action Action; - - public GridElement(string name, float size, float maxSize, bool gridVisible, Action action) - { - Name = name; - Size = size; - MaxSize = maxSize; - Border = gridVisible; - Action = action; - } - } - - public const float FontSizeMultiplier = 96f / 72f; - - public unsafe static void SetWpfStyle() - { - ImGuiStyle* pStyle = ImGui.GetStyle(); - pStyle->FrameBorderSize = 1.0f; - pStyle->FramePadding = new Vector2(7, 5); - pStyle->ScrollbarRounding = 0.0f; - pStyle->ScrollbarSize = 20.0f; - pStyle->WindowRounding = 0.0f; - pStyle->TabRounding = 0.0f; - pStyle->TabBorderSize = 1.0f; - pStyle->WindowMenuButtonPosition = ImGuiDir.Right; - SetWpfDarkTheme(); - } - - private static unsafe void SetWpfLightTheme() - { - const uint Opacity = 0xffu << 24; - const uint Black = Opacity | 0x000000u; - const uint White = Opacity | 0xffffffu; - const uint ActionBg = Opacity | 0xddddddu; - const uint ActionActive = Opacity | 0xf6e5c4u; - const uint ActionHovered = Opacity | 0xfde6beu; - const uint SliderGrab = Opacity | 0xcdcdcdu; - const uint SliderGrabActive = Opacity | 0xa6a6a6u; - const uint SlideGrabHovered = Opacity | 0x606060u; - const uint MenuBg = Opacity | 0xf0f0f0u; - const uint MenuBgHovered = Opacity | 0xfcf3e9u; - - ImGui.PushStyleColor(ImGuiCol.Text, Black); - ImGui.PushStyleColor(ImGuiCol.WindowBg, White); - ImGui.PushStyleColor(ImGuiCol.MenuBarBg, MenuBg); - ImGui.PushStyleColor(ImGuiCol.FrameBg, White); - ImGui.PushStyleColor(ImGuiCol.FrameBgHovered, ActionHovered); - ImGui.PushStyleColor(ImGuiCol.FrameBgActive, ActionActive); - ImGui.PushStyleColor(ImGuiCol.PopupBg, White); - ImGui.PushStyleColor(ImGuiCol.Button, ActionBg); - ImGui.PushStyleColor(ImGuiCol.ButtonHovered, ActionHovered); - ImGui.PushStyleColor(ImGuiCol.ButtonActive, ActionActive); - ImGui.PushStyleColor(ImGuiCol.Header, ActionBg); - ImGui.PushStyleColor(ImGuiCol.HeaderHovered, ActionHovered); - ImGui.PushStyleColor(ImGuiCol.HeaderActive, ActionActive); - ImGui.PushStyleColor(ImGuiCol.CheckMark, Black); - ImGui.PushStyleColor(ImGuiCol.Tab, MenuBg); - ImGui.PushStyleColor(ImGuiCol.TabActive, White); - ImGui.PushStyleColor(ImGuiCol.TabHovered, MenuBgHovered); - ImGui.PushStyleColor(ImGuiCol.SliderGrab, SliderGrab); - ImGui.PushStyleColor(ImGuiCol.SliderGrabActive, SliderGrabActive); - ImGui.PushStyleColor(ImGuiCol.ScrollbarBg, MenuBg); - ImGui.PushStyleColor(ImGuiCol.ScrollbarGrab, SliderGrab); - ImGui.PushStyleColor(ImGuiCol.ScrollbarGrabActive, SliderGrabActive); - ImGui.PushStyleColor(ImGuiCol.ScrollbarGrabHovered, SlideGrabHovered); - ImGui.PushStyleColor(ImGuiCol.TitleBg, SliderGrab); - ImGui.PushStyleColor(ImGuiCol.TitleBgActive, White); - } - - private static unsafe void SetWpfDarkTheme() - { - const uint Opacity = 0xffu << 24; - const uint Black = Opacity | ~0x000000u; - const uint White = Opacity | ~0xffffffu; - const uint ActionBg = Opacity | ~0xddddddu; - const uint ActionActive = Opacity | ~0xf6e5c4u; - const uint ActionHovered = Opacity | ~0xfde6beu; - const uint SliderGrab = Opacity | ~0xcdcdcdu; - const uint SliderGrabActive = Opacity | ~0xa6a6a6u; - const uint SlideGrabHovered = Opacity | ~0x606060u; - const uint MenuBg = Opacity | ~0xf0f0f0u; - const uint MenuBgHovered = Opacity | ~0xfcf3e9u; - - ImGui.PushStyleColor(ImGuiCol.Text, Black); - ImGui.PushStyleColor(ImGuiCol.WindowBg, White); - ImGui.PushStyleColor(ImGuiCol.MenuBarBg, MenuBg); - ImGui.PushStyleColor(ImGuiCol.FrameBg, White); - ImGui.PushStyleColor(ImGuiCol.FrameBgHovered, ActionHovered); - ImGui.PushStyleColor(ImGuiCol.FrameBgActive, ActionActive); - ImGui.PushStyleColor(ImGuiCol.PopupBg, White); - ImGui.PushStyleColor(ImGuiCol.Button, ActionBg); - ImGui.PushStyleColor(ImGuiCol.ButtonHovered, ActionHovered); - ImGui.PushStyleColor(ImGuiCol.ButtonActive, ActionActive); - ImGui.PushStyleColor(ImGuiCol.Header, ActionBg); - ImGui.PushStyleColor(ImGuiCol.HeaderHovered, ActionHovered); - ImGui.PushStyleColor(ImGuiCol.HeaderActive, ActionActive); - ImGui.PushStyleColor(ImGuiCol.CheckMark, Black); - ImGui.PushStyleColor(ImGuiCol.Tab, MenuBg); - ImGui.PushStyleColor(ImGuiCol.TabActive, White); - ImGui.PushStyleColor(ImGuiCol.TabHovered, MenuBgHovered); - ImGui.PushStyleColor(ImGuiCol.SliderGrab, SliderGrab); - ImGui.PushStyleColor(ImGuiCol.SliderGrabActive, SliderGrabActive); - ImGui.PushStyleColor(ImGuiCol.ScrollbarBg, MenuBg); - ImGui.PushStyleColor(ImGuiCol.ScrollbarGrab, SliderGrab); - ImGui.PushStyleColor(ImGuiCol.ScrollbarGrabActive, SliderGrabActive); - ImGui.PushStyleColor(ImGuiCol.ScrollbarGrabHovered, SlideGrabHovered); - ImGui.PushStyleColor(ImGuiCol.TitleBg, SliderGrab); - ImGui.PushStyleColor(ImGuiCol.TitleBgActive, White); - } - - public static ImFontPtr OpenFont(IImGuiRenderer renderer, string internalFontName, float fontSize) - { - var font = ImGui.GetIO().Fonts.AddFontFromFileTTF(@$"C:\Windows\Fonts\{internalFontName}.ttf", fontSize); - renderer.RebuildFontAtlas(); - - return font; - } - - public static ImFontPtr OpenFontSegoeUi(IImGuiRenderer renderer, float fontSize = 16.0f) => - OpenFont(renderer, "segoeui", fontSize); - - public static bool MainWindow(Action action, bool noBackground = false) => - ForControl(() => - { - var ret = ImGui.Begin("MainWindow", - ImGuiWindowFlags.MenuBar | - ImGuiWindowFlags.NoDecoration | - ImGuiWindowFlags.NoCollapse | - ImGuiWindowFlags.NoMove | - (noBackground ? ImGuiWindowFlags.NoBackground : ImGuiWindowFlags.None)); - ImGui.SetWindowPos(new Vector2(0, 0)); - ImGui.SetWindowSize(ImGui.GetIO().DisplaySize); - return ret; - }, ImGui.End, action); - - public static bool ForControl(Func begin, Action end, Action action) - { - if (!begin()) - return false; - action(); - end(); - - return true; - } - - public static bool ForControl(Func begin, Action action) - { - if (!begin()) - return false; - action(); - - return true; - } - - public static bool ForMenuBar(Action action) => - ForControl(() => ImGui.BeginMenuBar(), ImGui.EndMenuBar, action); - - public static bool ForMenu(string name, Action action) => - ForControl(() => ImGui.BeginMenu(name), ImGui.EndMenu, action); - - public static bool ForMenuItem(string name, Action action, bool enabled = true) => - ForControl(() => ImGui.MenuItem(name, enabled), action); - - public static bool ForMenuItem(string name, string shortcut, Action action, bool enabled = true) => - ForControl(() => ImGui.MenuItem(name, shortcut, false, enabled), action); - - public static bool ForPopup(string name, Action action) => - ForControl(() => ImGui.BeginPopup(name), ImGui.EndPopup, action); - - public static bool ForTreeNode(string name, Action action) => - ForControl(() => ImGui.TreeNode(name), ImGui.TreePop, action); - - public static bool ForWindow(string name, Action action) => - ForControl(() => - { - var dummy = true; - ImGui.Begin(name, ref dummy); - return dummy; - }, ImGui.End, action); - - public static bool ForHeader(string name, Action action) => - ForControl(() => ImGui.CollapsingHeader(name), action); - - public static void ForEdit(string name, Func getter, Action setter) - { - var value = getter(); - if (ImGui.Checkbox(name, ref value)) - setter(value); - } - - public static void ForEdit(string name, Func getter, Action setter) => - ForEdit(name, () => (int)getter(), x => setter((byte)x)); - - public static void ForEdit(string name, Func getter, Action setter) => - ForEdit(name, () => (int)getter(), x => setter((short)x)); - - public static void ForEdit(string name, Func getter, Action setter) => - ForEdit(name, () => (int)getter(), x => setter((ushort)x)); - - public static void ForEdit(string name, Func getter, Action setter) - { - var value = getter(); - if (ImGui.DragInt(name, ref value)) - setter(value); - } - - public static void ForEdit(string name, Func getter, Action setter, float speed = 1f) - { - var value = getter(); - if (ImGui.DragFloat(name, ref value, speed)) - setter(value); - } - - public static void ForEdit2(string name, Func getter, Action setter, float speed = 1f) - { - var value = getter(); - if (ImGui.DragFloat2(name, ref value, speed)) - setter(value); - } - - public static void ForEdit3(string name, Func getter, Action setter, float speed = 1f) - { - var value = getter(); - if (ImGui.DragFloat3(name, ref value, speed)) - setter(value); - } - - public static void ForMenuCheck(string name, Func getter, Action setter) - { - var value = getter(); - if (ImGui.MenuItem(name, "", ref value)) - setter(value); - } - - public static bool ForChild(string name, float w, float h, bool border, Action action) - { - var ret = ImGui.BeginChild(name, new Vector2(w, h), border); - action(); - ImGui.EndChild(); - - return ret; - } - } -} +using ImGuiNET; +using System; +using System.Linq; +using System.Numerics; +using System.Reflection.Metadata.Ecma335; + +namespace OpenKh.Tools.Common.CustomImGui +{ + public static class ImGuiEx + { + public struct GridElement + { + public string Name; + public float Size; + public float MaxSize; + public bool Border; + public Action Action; + + public GridElement(string name, float size, float maxSize, bool gridVisible, Action action) + { + Name = name; + Size = size; + MaxSize = maxSize; + Border = gridVisible; + Action = action; + } + } + + public const float FontSizeMultiplier = 96f / 72f; + + public unsafe static void SetWpfStyle() + { + ImGuiStyle* pStyle = ImGui.GetStyle(); + pStyle->FrameBorderSize = 1.0f; + pStyle->FramePadding = new Vector2(7, 5); + pStyle->ScrollbarRounding = 0.0f; + pStyle->ScrollbarSize = 20.0f; + pStyle->WindowRounding = 0.0f; + pStyle->TabRounding = 0.0f; + pStyle->TabBorderSize = 1.0f; + pStyle->WindowMenuButtonPosition = ImGuiDir.Right; + SetWpfDarkTheme(); + } + + private static unsafe void SetWpfLightTheme() + { + const uint Opacity = 0xffu << 24; + const uint Black = Opacity | 0x000000u; + const uint White = Opacity | 0xffffffu; + const uint ActionBg = Opacity | 0xddddddu; + const uint ActionActive = Opacity | 0xf6e5c4u; + const uint ActionHovered = Opacity | 0xfde6beu; + const uint SliderGrab = Opacity | 0xcdcdcdu; + const uint SliderGrabActive = Opacity | 0xa6a6a6u; + const uint SlideGrabHovered = Opacity | 0x606060u; + const uint MenuBg = Opacity | 0xf0f0f0u; + const uint MenuBgHovered = Opacity | 0xfcf3e9u; + + ImGui.PushStyleColor(ImGuiCol.Text, Black); + ImGui.PushStyleColor(ImGuiCol.WindowBg, White); + ImGui.PushStyleColor(ImGuiCol.MenuBarBg, MenuBg); + ImGui.PushStyleColor(ImGuiCol.FrameBg, White); + ImGui.PushStyleColor(ImGuiCol.FrameBgHovered, ActionHovered); + ImGui.PushStyleColor(ImGuiCol.FrameBgActive, ActionActive); + ImGui.PushStyleColor(ImGuiCol.PopupBg, White); + ImGui.PushStyleColor(ImGuiCol.Button, ActionBg); + ImGui.PushStyleColor(ImGuiCol.ButtonHovered, ActionHovered); + ImGui.PushStyleColor(ImGuiCol.ButtonActive, ActionActive); + ImGui.PushStyleColor(ImGuiCol.Header, ActionBg); + ImGui.PushStyleColor(ImGuiCol.HeaderHovered, ActionHovered); + ImGui.PushStyleColor(ImGuiCol.HeaderActive, ActionActive); + ImGui.PushStyleColor(ImGuiCol.CheckMark, Black); + ImGui.PushStyleColor(ImGuiCol.Tab, MenuBg); + ImGui.PushStyleColor(ImGuiCol.TabActive, White); + ImGui.PushStyleColor(ImGuiCol.TabHovered, MenuBgHovered); + ImGui.PushStyleColor(ImGuiCol.SliderGrab, SliderGrab); + ImGui.PushStyleColor(ImGuiCol.SliderGrabActive, SliderGrabActive); + ImGui.PushStyleColor(ImGuiCol.ScrollbarBg, MenuBg); + ImGui.PushStyleColor(ImGuiCol.ScrollbarGrab, SliderGrab); + ImGui.PushStyleColor(ImGuiCol.ScrollbarGrabActive, SliderGrabActive); + ImGui.PushStyleColor(ImGuiCol.ScrollbarGrabHovered, SlideGrabHovered); + ImGui.PushStyleColor(ImGuiCol.TitleBg, SliderGrab); + ImGui.PushStyleColor(ImGuiCol.TitleBgActive, White); + } + + private static unsafe void SetWpfDarkTheme() + { + const uint Opacity = 0xffu << 24; + const uint Black = Opacity | ~0x000000u; + const uint White = Opacity | ~0xffffffu; + const uint ActionBg = Opacity | ~0xddddddu; + const uint ActionActive = Opacity | ~0xf6e5c4u; + const uint ActionHovered = Opacity | ~0xfde6beu; + const uint SliderGrab = Opacity | ~0xcdcdcdu; + const uint SliderGrabActive = Opacity | ~0xa6a6a6u; + const uint SlideGrabHovered = Opacity | ~0x606060u; + const uint MenuBg = Opacity | ~0xf0f0f0u; + const uint MenuBgHovered = Opacity | ~0xfcf3e9u; + + ImGui.PushStyleColor(ImGuiCol.Text, Black); + ImGui.PushStyleColor(ImGuiCol.WindowBg, White); + ImGui.PushStyleColor(ImGuiCol.MenuBarBg, MenuBg); + ImGui.PushStyleColor(ImGuiCol.FrameBg, White); + ImGui.PushStyleColor(ImGuiCol.FrameBgHovered, ActionHovered); + ImGui.PushStyleColor(ImGuiCol.FrameBgActive, ActionActive); + ImGui.PushStyleColor(ImGuiCol.PopupBg, White); + ImGui.PushStyleColor(ImGuiCol.Button, ActionBg); + ImGui.PushStyleColor(ImGuiCol.ButtonHovered, ActionHovered); + ImGui.PushStyleColor(ImGuiCol.ButtonActive, ActionActive); + ImGui.PushStyleColor(ImGuiCol.Header, ActionBg); + ImGui.PushStyleColor(ImGuiCol.HeaderHovered, ActionHovered); + ImGui.PushStyleColor(ImGuiCol.HeaderActive, ActionActive); + ImGui.PushStyleColor(ImGuiCol.CheckMark, Black); + ImGui.PushStyleColor(ImGuiCol.Tab, MenuBg); + ImGui.PushStyleColor(ImGuiCol.TabActive, White); + ImGui.PushStyleColor(ImGuiCol.TabHovered, MenuBgHovered); + ImGui.PushStyleColor(ImGuiCol.SliderGrab, SliderGrab); + ImGui.PushStyleColor(ImGuiCol.SliderGrabActive, SliderGrabActive); + ImGui.PushStyleColor(ImGuiCol.ScrollbarBg, MenuBg); + ImGui.PushStyleColor(ImGuiCol.ScrollbarGrab, SliderGrab); + ImGui.PushStyleColor(ImGuiCol.ScrollbarGrabActive, SliderGrabActive); + ImGui.PushStyleColor(ImGuiCol.ScrollbarGrabHovered, SlideGrabHovered); + ImGui.PushStyleColor(ImGuiCol.TitleBg, SliderGrab); + ImGui.PushStyleColor(ImGuiCol.TitleBgActive, White); + } + + public static ImFontPtr OpenFont(IImGuiRenderer renderer, string internalFontName, float fontSize) + { + var font = ImGui.GetIO().Fonts.AddFontFromFileTTF(@$"C:\Windows\Fonts\{internalFontName}.ttf", fontSize); + renderer.RebuildFontAtlas(); + + return font; + } + + public static ImFontPtr OpenFontSegoeUi(IImGuiRenderer renderer, float fontSize = 16.0f) => + OpenFont(renderer, "segoeui", fontSize); + + public static bool MainWindow(Action action, bool noBackground = false) => + ForControl(() => + { + var ret = ImGui.Begin("MainWindow", + ImGuiWindowFlags.MenuBar | + ImGuiWindowFlags.NoDecoration | + ImGuiWindowFlags.NoCollapse | + ImGuiWindowFlags.NoMove | + (noBackground ? ImGuiWindowFlags.NoBackground : ImGuiWindowFlags.None)); + ImGui.SetWindowPos(new Vector2(0, 0)); + ImGui.SetWindowSize(ImGui.GetIO().DisplaySize); + return ret; + }, ImGui.End, action); + + public static bool ForControl(Func begin, Action end, Action action) + { + if (!begin()) + return false; + action(); + end(); + + return true; + } + + public static bool ForControl(Func begin, Action action) + { + if (!begin()) + return false; + action(); + + return true; + } + + public static bool ForMenuBar(Action action) => + ForControl(() => ImGui.BeginMenuBar(), ImGui.EndMenuBar, action); + + public static bool ForMenu(string name, Action action) => + ForControl(() => ImGui.BeginMenu(name), ImGui.EndMenu, action); + + public static bool ForMenuItem(string name, Action action, bool enabled = true) => + ForControl(() => ImGui.MenuItem(name, enabled), action); + + public static bool ForMenuItem(string name, string shortcut, Action action, bool enabled = true) => + ForControl(() => ImGui.MenuItem(name, shortcut, false, enabled), action); + + public static bool ForPopup(string name, Action action) => + ForControl(() => ImGui.BeginPopup(name), ImGui.EndPopup, action); + + public static bool ForTreeNode(string name, Action action) => + ForControl(() => ImGui.TreeNode(name), ImGui.TreePop, action); + + public static bool ForWindow(string name, Action action) => + ForControl(() => + { + var dummy = true; + ImGui.Begin(name, ref dummy); + return dummy; + }, ImGui.End, action); + + public static bool ForHeader(string name, Action action) => + ForControl(() => ImGui.CollapsingHeader(name), action); + + public static void ForEdit(string name, Func getter, Action setter) + { + var value = getter(); + if (ImGui.Checkbox(name, ref value)) + setter(value); + } + + public static void ForEdit(string name, Func getter, Action setter) => + ForEdit(name, () => (int)getter(), x => setter((byte)x)); + + public static void ForEdit(string name, Func getter, Action setter) => + ForEdit(name, () => (int)getter(), x => setter((short)x)); + + public static void ForEdit(string name, Func getter, Action setter) => + ForEdit(name, () => (int)getter(), x => setter((ushort)x)); + + public static void ForEdit(string name, Func getter, Action setter) + { + var value = getter(); + if (ImGui.DragInt(name, ref value)) + setter(value); + } + + public static void ForEdit(string name, Func getter, Action setter, float speed = 1f) + { + var value = getter(); + if (ImGui.DragFloat(name, ref value, speed)) + setter(value); + } + + public static void ForEdit2(string name, Func getter, Action setter, float speed = 1f) + { + var value = getter(); + if (ImGui.DragFloat2(name, ref value, speed)) + setter(value); + } + + public static void ForEdit3(string name, Func getter, Action setter, float speed = 1f) + { + var value = getter(); + if (ImGui.DragFloat3(name, ref value, speed)) + setter(value); + } + + public static void ForMenuCheck(string name, Func getter, Action setter) + { + var value = getter(); + if (ImGui.MenuItem(name, "", ref value)) + setter(value); + } + + public static bool ForChild(string name, float w, float h, bool border, Action action) + { + var ret = ImGui.BeginChild(name, new Vector2(w, h), border); + action(); + ImGui.EndChild(); + + return ret; + } + } +} diff --git a/OpenKh.Tools.Common.CustomImGui/MonoGameImGui.cs b/OpenKh.Tools.Common.CustomImGui/MonoGameImGui.cs index 19c0739e9..91327fbbd 100644 --- a/OpenKh.Tools.Common.CustomImGui/MonoGameImGui.cs +++ b/OpenKh.Tools.Common.CustomImGui/MonoGameImGui.cs @@ -1,441 +1,441 @@ -using ImGuiNET; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; - -namespace OpenKh.Tools.Common.CustomImGui -{ - public class MonoGameImGui : IImGuiRenderer - { - public static class DrawVertDeclaration - { - public static readonly VertexDeclaration Declaration; - - public static readonly int Size; - - static DrawVertDeclaration() - { - unsafe - { Size = sizeof(ImDrawVert); } - - Declaration = new VertexDeclaration( - Size, - - // Position - new VertexElement(0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0), - - // UV - new VertexElement(8, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0), - - // Color - new VertexElement(16, VertexElementFormat.Color, VertexElementUsage.Color, 0) - ); - } - } - - private Game _game; - - // Graphics - private GraphicsDevice _graphicsDevice; - - private BasicEffect _effect; - private RasterizerState _rasterizerState; - - private byte[] _vertexData; - private VertexBuffer _vertexBuffer; - private int _vertexBufferSize; - - private byte[] _indexData; - private IndexBuffer _indexBuffer; - private int _indexBufferSize; - - // Textures - private Dictionary _loadedTextures; - - private int _textureId; - private IntPtr? _fontTextureId; - - // Input - private int _scrollWheelValue; - - private List _keys = new List(); - - public bool ImGuiWantCaptureKeyboard => ImGui.GetIO().WantCaptureKeyboard; - public bool ImGuiWantCaptureMouse => ImGui.GetIO().WantCaptureMouse; - public bool ImGuiWantTextInput => ImGui.GetIO().WantTextInput; - - public MonoGameImGui(Game game) - { - var context = ImGui.CreateContext(); - ImGui.SetCurrentContext(context); - ImGui.GetIO().ConfigFlags = - ImGuiConfigFlags.NavEnableKeyboard | - ImGuiConfigFlags.NavEnableSetMousePos; - - _game = game ?? throw new ArgumentNullException(nameof(game)); - _graphicsDevice = game.GraphicsDevice; - - _loadedTextures = new Dictionary(); - - _rasterizerState = new RasterizerState() - { - CullMode = CullMode.None, - DepthBias = 0, - FillMode = FillMode.Solid, - MultiSampleAntiAlias = false, - ScissorTestEnable = true, - SlopeScaleDepthBias = 0 - }; - - game.IsMouseVisible = true; - game.Window.AllowUserResizing = true; - game.Window.ClientSizeChanged += (o, e) => - { - ImGui.GetIO().DisplaySize = new System.Numerics.Vector2() - { - X = game.Window.ClientBounds.Width, - Y = game.Window.ClientBounds.Height - }; - }; - - SetupInput(); - } - - #region ImGuiRenderer - - /// - /// Creates a texture and loads the font data from ImGui. Should be called when the is initialized but before any rendering is done - /// - public virtual unsafe void RebuildFontAtlas() - { - // Get font texture from ImGui - var io = ImGui.GetIO(); - io.Fonts.GetTexDataAsRGBA32(out byte* pixelData, out int width, out int height, out int bytesPerPixel); - - // Copy the data to a managed array - var pixels = new byte[width * height * bytesPerPixel]; - unsafe - { Marshal.Copy(new IntPtr(pixelData), pixels, 0, pixels.Length); } - - // Create and register the texture as an XNA texture - var tex2d = new Texture2D(_graphicsDevice, width, height, false, SurfaceFormat.Color); - tex2d.SetData(pixels); - - // Should a texture already have been build previously, unbind it first so it can be deallocated - if (_fontTextureId.HasValue) - UnbindTexture(_fontTextureId.Value); - - // Bind the new texture to an ImGui-friendly id - _fontTextureId = BindTexture(tex2d); - - // Let ImGui know where to find the texture - io.Fonts.SetTexID(_fontTextureId.Value); - io.Fonts.ClearTexData(); // Clears CPU side texture data - } - - /// - /// Creates a pointer to a texture, which can be passed through ImGui calls such as . That pointer is then used by ImGui to let us know what texture to draw - /// - public virtual IntPtr BindTexture(Texture2D texture) - { - var id = new IntPtr(_textureId++); - - _loadedTextures.Add(id, texture); - - return id; - } - - /// - /// Removes a previously created texture pointer, releasing its reference and allowing it to be deallocated - /// - public virtual void UnbindTexture(IntPtr textureId) - { - _loadedTextures.Remove(textureId); - } - - /// - /// Removes a previously created texture pointer, releasing its reference and allowing it to be deallocated - /// - public virtual void RebindTexture(IntPtr textureId, Texture2D texture) - { - _loadedTextures[textureId] = texture; - } - - /// - /// Sets up ImGui for a new frame, should be called at frame start - /// - public virtual void BeforeLayout(GameTime gameTime) - { - ImGui.GetIO().DeltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; - UpdateInput(); - ImGui.NewFrame(); - } - - /// - /// Asks ImGui for the generated geometry data and sends it to the graphics pipeline, should be called after the UI is drawn using ImGui.** calls - /// - public virtual void AfterLayout() - { - ImGui.Render(); - - unsafe - { RenderDrawData(ImGui.GetDrawData()); } - } - - #endregion ImGuiRenderer - - #region Setup & Update - - /// - /// Maps ImGui keys to XNA keys. We use this later on to tell ImGui what keys were pressed - /// - protected virtual void SetupInput() - { - var io = ImGui.GetIO(); - - _keys.Add(io.KeyMap[(int)ImGuiKey.Tab] = (int)Keys.Tab); - _keys.Add(io.KeyMap[(int)ImGuiKey.LeftArrow] = (int)Keys.Left); - _keys.Add(io.KeyMap[(int)ImGuiKey.RightArrow] = (int)Keys.Right); - _keys.Add(io.KeyMap[(int)ImGuiKey.UpArrow] = (int)Keys.Up); - _keys.Add(io.KeyMap[(int)ImGuiKey.DownArrow] = (int)Keys.Down); - _keys.Add(io.KeyMap[(int)ImGuiKey.PageUp] = (int)Keys.PageUp); - _keys.Add(io.KeyMap[(int)ImGuiKey.PageDown] = (int)Keys.PageDown); - _keys.Add(io.KeyMap[(int)ImGuiKey.Home] = (int)Keys.Home); - _keys.Add(io.KeyMap[(int)ImGuiKey.End] = (int)Keys.End); - _keys.Add(io.KeyMap[(int)ImGuiKey.Delete] = (int)Keys.Delete); - _keys.Add(io.KeyMap[(int)ImGuiKey.Backspace] = (int)Keys.Back); - _keys.Add(io.KeyMap[(int)ImGuiKey.Enter] = (int)Keys.Enter); - _keys.Add(io.KeyMap[(int)ImGuiKey.Escape] = (int)Keys.Escape); - _keys.Add(io.KeyMap[(int)ImGuiKey.A] = (int)Keys.A); - _keys.Add(io.KeyMap[(int)ImGuiKey.C] = (int)Keys.C); - _keys.Add(io.KeyMap[(int)ImGuiKey.V] = (int)Keys.V); - _keys.Add(io.KeyMap[(int)ImGuiKey.X] = (int)Keys.X); - _keys.Add(io.KeyMap[(int)ImGuiKey.Y] = (int)Keys.Y); - _keys.Add(io.KeyMap[(int)ImGuiKey.Z] = (int)Keys.Z); - - // MonoGame-specific ////////////////////// - _game.Window.TextInput += (s, a) => - { - if (a.Character == '\t') - return; - - io.AddInputCharacter(a.Character); - }; - /////////////////////////////////////////// - - // FNA-specific /////////////////////////// - //TextInputEXT.TextInput += c => - //{ - // if (c == '\t') return; - - // ImGui.GetIO().AddInputCharacter(c); - //}; - /////////////////////////////////////////// - - ImGui.GetIO().Fonts.AddFontDefault(); - } - - /// - /// Updates the to the current matrices and texture - /// - protected virtual Effect UpdateEffect(Texture2D texture) - { - _effect ??= new BasicEffect(_graphicsDevice); - - var io = ImGui.GetIO(); - - // MonoGame-specific ////////////////////// - var offset = .5f; - /////////////////////////////////////////// - - // FNA-specific /////////////////////////// - //var offset = 0f; - /////////////////////////////////////////// - - _effect.World = Matrix.Identity; - _effect.View = Matrix.Identity; - _effect.Projection = Matrix.CreateOrthographicOffCenter(offset, io.DisplaySize.X + offset, io.DisplaySize.Y + offset, offset, -1f, 1f); - _effect.TextureEnabled = true; - _effect.Texture = texture; - _effect.VertexColorEnabled = true; - - return _effect; - } - - /// - /// Sends XNA input state to ImGui - /// - protected virtual void UpdateInput() - { - var io = ImGui.GetIO(); - - var mouse = Mouse.GetState(); - var keyboard = Keyboard.GetState(); - - for (int i = 0; i < _keys.Count; i++) - { - io.KeysDown[_keys[i]] = keyboard.IsKeyDown((Keys)_keys[i]); - } - - io.KeyShift = keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift); - io.KeyCtrl = keyboard.IsKeyDown(Keys.LeftControl) || keyboard.IsKeyDown(Keys.RightControl); - io.KeyAlt = keyboard.IsKeyDown(Keys.LeftAlt) || keyboard.IsKeyDown(Keys.RightAlt); - io.KeySuper = keyboard.IsKeyDown(Keys.LeftWindows) || keyboard.IsKeyDown(Keys.RightWindows); - - io.DisplaySize = new System.Numerics.Vector2(_graphicsDevice.PresentationParameters.BackBufferWidth, _graphicsDevice.PresentationParameters.BackBufferHeight); - io.DisplayFramebufferScale = new System.Numerics.Vector2(1f, 1f); - - io.MousePos = new System.Numerics.Vector2(mouse.X, mouse.Y); - - io.MouseDown[0] = mouse.LeftButton == ButtonState.Pressed; - io.MouseDown[1] = mouse.RightButton == ButtonState.Pressed; - io.MouseDown[2] = mouse.MiddleButton == ButtonState.Pressed; - - var scrollDelta = mouse.ScrollWheelValue - _scrollWheelValue; - io.MouseWheel = scrollDelta > 0 ? 1 : scrollDelta < 0 ? -1 : 0; - _scrollWheelValue = mouse.ScrollWheelValue; - } - - #endregion Setup & Update - - #region Internals - - /// - /// Gets the geometry as set up by ImGui and sends it to the graphics device - /// - private void RenderDrawData(ImDrawDataPtr drawData) - { - // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers - var lastViewport = _graphicsDevice.Viewport; - var lastScissorBox = _graphicsDevice.ScissorRectangle; - - _graphicsDevice.BlendFactor = Color.White; - _graphicsDevice.BlendState = BlendState.NonPremultiplied; - _graphicsDevice.RasterizerState = _rasterizerState; - _graphicsDevice.DepthStencilState = DepthStencilState.DepthRead; - - // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays) - drawData.ScaleClipRects(ImGui.GetIO().DisplayFramebufferScale); - - // Setup projection - _graphicsDevice.Viewport = new Viewport(0, 0, _graphicsDevice.PresentationParameters.BackBufferWidth, _graphicsDevice.PresentationParameters.BackBufferHeight); - - UpdateBuffers(drawData); - - RenderCommandLists(drawData); - - // Restore modified state - _graphicsDevice.Viewport = lastViewport; - _graphicsDevice.ScissorRectangle = lastScissorBox; - } - - private unsafe void UpdateBuffers(ImDrawDataPtr drawData) - { - if (drawData.TotalVtxCount == 0) - { - return; - } - - // Expand buffers if we need more room - if (drawData.TotalVtxCount > _vertexBufferSize) - { - _vertexBuffer?.Dispose(); - - _vertexBufferSize = (int)(drawData.TotalVtxCount * 1.5f); - _vertexBuffer = new VertexBuffer(_graphicsDevice, DrawVertDeclaration.Declaration, _vertexBufferSize, BufferUsage.None); - _vertexData = new byte[_vertexBufferSize * DrawVertDeclaration.Size]; - } - - if (drawData.TotalIdxCount > _indexBufferSize) - { - _indexBuffer?.Dispose(); - - _indexBufferSize = (int)(drawData.TotalIdxCount * 1.5f); - _indexBuffer = new IndexBuffer(_graphicsDevice, IndexElementSize.SixteenBits, _indexBufferSize, BufferUsage.None); - _indexData = new byte[_indexBufferSize * sizeof(ushort)]; - } - - // Copy ImGui's vertices and indices to a set of managed byte arrays - int vtxOffset = 0; - int idxOffset = 0; - - for (int n = 0; n < drawData.CmdListsCount; n++) - { - ImDrawListPtr cmdList = drawData.CmdListsRange[n]; - - fixed (void* vtxDstPtr = &_vertexData[vtxOffset * DrawVertDeclaration.Size]) - fixed (void* idxDstPtr = &_indexData[idxOffset * sizeof(ushort)]) - { - Buffer.MemoryCopy((void*)cmdList.VtxBuffer.Data, vtxDstPtr, _vertexData.Length, cmdList.VtxBuffer.Size * DrawVertDeclaration.Size); - Buffer.MemoryCopy((void*)cmdList.IdxBuffer.Data, idxDstPtr, _indexData.Length, cmdList.IdxBuffer.Size * sizeof(ushort)); - } - - vtxOffset += cmdList.VtxBuffer.Size; - idxOffset += cmdList.IdxBuffer.Size; - } - - // Copy the managed byte arrays to the gpu vertex- and index buffers - _vertexBuffer.SetData(_vertexData, 0, drawData.TotalVtxCount * DrawVertDeclaration.Size); - _indexBuffer.SetData(_indexData, 0, drawData.TotalIdxCount * sizeof(ushort)); - } - - private unsafe void RenderCommandLists(ImDrawDataPtr drawData) - { - _graphicsDevice.SetVertexBuffer(_vertexBuffer); - _graphicsDevice.Indices = _indexBuffer; - - int vtxOffset = 0; - int idxOffset = 0; - - for (int n = 0; n < drawData.CmdListsCount; n++) - { - ImDrawListPtr cmdList = drawData.CmdListsRange[n]; - - for (int cmdi = 0; cmdi < cmdList.CmdBuffer.Size; cmdi++) - { - ImDrawCmdPtr drawCmd = cmdList.CmdBuffer[cmdi]; - - if (!_loadedTextures.ContainsKey(drawCmd.TextureId)) - { - throw new InvalidOperationException($"Could not find a texture with id '{drawCmd.TextureId}', please check your bindings"); - } - - _graphicsDevice.ScissorRectangle = new Rectangle( - (int)drawCmd.ClipRect.X, - (int)drawCmd.ClipRect.Y, - (int)(drawCmd.ClipRect.Z - drawCmd.ClipRect.X), - (int)(drawCmd.ClipRect.W - drawCmd.ClipRect.Y) - ); - - var effect = UpdateEffect(_loadedTextures[drawCmd.TextureId]); - - foreach (var pass in effect.CurrentTechnique.Passes) - { - pass.Apply(); - -#pragma warning disable CS0618 // // FNA does not expose an alternative method. - _graphicsDevice.DrawIndexedPrimitives( - primitiveType: PrimitiveType.TriangleList, - baseVertex: vtxOffset, - minVertexIndex: 0, - numVertices: cmdList.VtxBuffer.Size, - startIndex: idxOffset, - primitiveCount: (int)drawCmd.ElemCount / 3 - ); -#pragma warning restore CS0618 - } - - idxOffset += (int)drawCmd.ElemCount; - } - - vtxOffset += cmdList.VtxBuffer.Size; - } - } - - #endregion Internals - } -} +using ImGuiNET; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; + +namespace OpenKh.Tools.Common.CustomImGui +{ + public class MonoGameImGui : IImGuiRenderer + { + public static class DrawVertDeclaration + { + public static readonly VertexDeclaration Declaration; + + public static readonly int Size; + + static DrawVertDeclaration() + { + unsafe + { Size = sizeof(ImDrawVert); } + + Declaration = new VertexDeclaration( + Size, + + // Position + new VertexElement(0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0), + + // UV + new VertexElement(8, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0), + + // Color + new VertexElement(16, VertexElementFormat.Color, VertexElementUsage.Color, 0) + ); + } + } + + private Game _game; + + // Graphics + private GraphicsDevice _graphicsDevice; + + private BasicEffect _effect; + private RasterizerState _rasterizerState; + + private byte[] _vertexData; + private VertexBuffer _vertexBuffer; + private int _vertexBufferSize; + + private byte[] _indexData; + private IndexBuffer _indexBuffer; + private int _indexBufferSize; + + // Textures + private Dictionary _loadedTextures; + + private int _textureId; + private IntPtr? _fontTextureId; + + // Input + private int _scrollWheelValue; + + private List _keys = new List(); + + public bool ImGuiWantCaptureKeyboard => ImGui.GetIO().WantCaptureKeyboard; + public bool ImGuiWantCaptureMouse => ImGui.GetIO().WantCaptureMouse; + public bool ImGuiWantTextInput => ImGui.GetIO().WantTextInput; + + public MonoGameImGui(Game game) + { + var context = ImGui.CreateContext(); + ImGui.SetCurrentContext(context); + ImGui.GetIO().ConfigFlags = + ImGuiConfigFlags.NavEnableKeyboard | + ImGuiConfigFlags.NavEnableSetMousePos; + + _game = game ?? throw new ArgumentNullException(nameof(game)); + _graphicsDevice = game.GraphicsDevice; + + _loadedTextures = new Dictionary(); + + _rasterizerState = new RasterizerState() + { + CullMode = CullMode.None, + DepthBias = 0, + FillMode = FillMode.Solid, + MultiSampleAntiAlias = false, + ScissorTestEnable = true, + SlopeScaleDepthBias = 0 + }; + + game.IsMouseVisible = true; + game.Window.AllowUserResizing = true; + game.Window.ClientSizeChanged += (o, e) => + { + ImGui.GetIO().DisplaySize = new System.Numerics.Vector2() + { + X = game.Window.ClientBounds.Width, + Y = game.Window.ClientBounds.Height + }; + }; + + SetupInput(); + } + + #region ImGuiRenderer + + /// + /// Creates a texture and loads the font data from ImGui. Should be called when the is initialized but before any rendering is done + /// + public virtual unsafe void RebuildFontAtlas() + { + // Get font texture from ImGui + var io = ImGui.GetIO(); + io.Fonts.GetTexDataAsRGBA32(out byte* pixelData, out int width, out int height, out int bytesPerPixel); + + // Copy the data to a managed array + var pixels = new byte[width * height * bytesPerPixel]; + unsafe + { Marshal.Copy(new IntPtr(pixelData), pixels, 0, pixels.Length); } + + // Create and register the texture as an XNA texture + var tex2d = new Texture2D(_graphicsDevice, width, height, false, SurfaceFormat.Color); + tex2d.SetData(pixels); + + // Should a texture already have been build previously, unbind it first so it can be deallocated + if (_fontTextureId.HasValue) + UnbindTexture(_fontTextureId.Value); + + // Bind the new texture to an ImGui-friendly id + _fontTextureId = BindTexture(tex2d); + + // Let ImGui know where to find the texture + io.Fonts.SetTexID(_fontTextureId.Value); + io.Fonts.ClearTexData(); // Clears CPU side texture data + } + + /// + /// Creates a pointer to a texture, which can be passed through ImGui calls such as . That pointer is then used by ImGui to let us know what texture to draw + /// + public virtual IntPtr BindTexture(Texture2D texture) + { + var id = new IntPtr(_textureId++); + + _loadedTextures.Add(id, texture); + + return id; + } + + /// + /// Removes a previously created texture pointer, releasing its reference and allowing it to be deallocated + /// + public virtual void UnbindTexture(IntPtr textureId) + { + _loadedTextures.Remove(textureId); + } + + /// + /// Removes a previously created texture pointer, releasing its reference and allowing it to be deallocated + /// + public virtual void RebindTexture(IntPtr textureId, Texture2D texture) + { + _loadedTextures[textureId] = texture; + } + + /// + /// Sets up ImGui for a new frame, should be called at frame start + /// + public virtual void BeforeLayout(GameTime gameTime) + { + ImGui.GetIO().DeltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; + UpdateInput(); + ImGui.NewFrame(); + } + + /// + /// Asks ImGui for the generated geometry data and sends it to the graphics pipeline, should be called after the UI is drawn using ImGui.** calls + /// + public virtual void AfterLayout() + { + ImGui.Render(); + + unsafe + { RenderDrawData(ImGui.GetDrawData()); } + } + + #endregion ImGuiRenderer + + #region Setup & Update + + /// + /// Maps ImGui keys to XNA keys. We use this later on to tell ImGui what keys were pressed + /// + protected virtual void SetupInput() + { + var io = ImGui.GetIO(); + + _keys.Add(io.KeyMap[(int)ImGuiKey.Tab] = (int)Keys.Tab); + _keys.Add(io.KeyMap[(int)ImGuiKey.LeftArrow] = (int)Keys.Left); + _keys.Add(io.KeyMap[(int)ImGuiKey.RightArrow] = (int)Keys.Right); + _keys.Add(io.KeyMap[(int)ImGuiKey.UpArrow] = (int)Keys.Up); + _keys.Add(io.KeyMap[(int)ImGuiKey.DownArrow] = (int)Keys.Down); + _keys.Add(io.KeyMap[(int)ImGuiKey.PageUp] = (int)Keys.PageUp); + _keys.Add(io.KeyMap[(int)ImGuiKey.PageDown] = (int)Keys.PageDown); + _keys.Add(io.KeyMap[(int)ImGuiKey.Home] = (int)Keys.Home); + _keys.Add(io.KeyMap[(int)ImGuiKey.End] = (int)Keys.End); + _keys.Add(io.KeyMap[(int)ImGuiKey.Delete] = (int)Keys.Delete); + _keys.Add(io.KeyMap[(int)ImGuiKey.Backspace] = (int)Keys.Back); + _keys.Add(io.KeyMap[(int)ImGuiKey.Enter] = (int)Keys.Enter); + _keys.Add(io.KeyMap[(int)ImGuiKey.Escape] = (int)Keys.Escape); + _keys.Add(io.KeyMap[(int)ImGuiKey.A] = (int)Keys.A); + _keys.Add(io.KeyMap[(int)ImGuiKey.C] = (int)Keys.C); + _keys.Add(io.KeyMap[(int)ImGuiKey.V] = (int)Keys.V); + _keys.Add(io.KeyMap[(int)ImGuiKey.X] = (int)Keys.X); + _keys.Add(io.KeyMap[(int)ImGuiKey.Y] = (int)Keys.Y); + _keys.Add(io.KeyMap[(int)ImGuiKey.Z] = (int)Keys.Z); + + // MonoGame-specific ////////////////////// + _game.Window.TextInput += (s, a) => + { + if (a.Character == '\t') + return; + + io.AddInputCharacter(a.Character); + }; + /////////////////////////////////////////// + + // FNA-specific /////////////////////////// + //TextInputEXT.TextInput += c => + //{ + // if (c == '\t') return; + + // ImGui.GetIO().AddInputCharacter(c); + //}; + /////////////////////////////////////////// + + ImGui.GetIO().Fonts.AddFontDefault(); + } + + /// + /// Updates the to the current matrices and texture + /// + protected virtual Effect UpdateEffect(Texture2D texture) + { + _effect ??= new BasicEffect(_graphicsDevice); + + var io = ImGui.GetIO(); + + // MonoGame-specific ////////////////////// + var offset = .5f; + /////////////////////////////////////////// + + // FNA-specific /////////////////////////// + //var offset = 0f; + /////////////////////////////////////////// + + _effect.World = Matrix.Identity; + _effect.View = Matrix.Identity; + _effect.Projection = Matrix.CreateOrthographicOffCenter(offset, io.DisplaySize.X + offset, io.DisplaySize.Y + offset, offset, -1f, 1f); + _effect.TextureEnabled = true; + _effect.Texture = texture; + _effect.VertexColorEnabled = true; + + return _effect; + } + + /// + /// Sends XNA input state to ImGui + /// + protected virtual void UpdateInput() + { + var io = ImGui.GetIO(); + + var mouse = Mouse.GetState(); + var keyboard = Keyboard.GetState(); + + for (int i = 0; i < _keys.Count; i++) + { + io.KeysDown[_keys[i]] = keyboard.IsKeyDown((Keys)_keys[i]); + } + + io.KeyShift = keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift); + io.KeyCtrl = keyboard.IsKeyDown(Keys.LeftControl) || keyboard.IsKeyDown(Keys.RightControl); + io.KeyAlt = keyboard.IsKeyDown(Keys.LeftAlt) || keyboard.IsKeyDown(Keys.RightAlt); + io.KeySuper = keyboard.IsKeyDown(Keys.LeftWindows) || keyboard.IsKeyDown(Keys.RightWindows); + + io.DisplaySize = new System.Numerics.Vector2(_graphicsDevice.PresentationParameters.BackBufferWidth, _graphicsDevice.PresentationParameters.BackBufferHeight); + io.DisplayFramebufferScale = new System.Numerics.Vector2(1f, 1f); + + io.MousePos = new System.Numerics.Vector2(mouse.X, mouse.Y); + + io.MouseDown[0] = mouse.LeftButton == ButtonState.Pressed; + io.MouseDown[1] = mouse.RightButton == ButtonState.Pressed; + io.MouseDown[2] = mouse.MiddleButton == ButtonState.Pressed; + + var scrollDelta = mouse.ScrollWheelValue - _scrollWheelValue; + io.MouseWheel = scrollDelta > 0 ? 1 : scrollDelta < 0 ? -1 : 0; + _scrollWheelValue = mouse.ScrollWheelValue; + } + + #endregion Setup & Update + + #region Internals + + /// + /// Gets the geometry as set up by ImGui and sends it to the graphics device + /// + private void RenderDrawData(ImDrawDataPtr drawData) + { + // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers + var lastViewport = _graphicsDevice.Viewport; + var lastScissorBox = _graphicsDevice.ScissorRectangle; + + _graphicsDevice.BlendFactor = Color.White; + _graphicsDevice.BlendState = BlendState.NonPremultiplied; + _graphicsDevice.RasterizerState = _rasterizerState; + _graphicsDevice.DepthStencilState = DepthStencilState.DepthRead; + + // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays) + drawData.ScaleClipRects(ImGui.GetIO().DisplayFramebufferScale); + + // Setup projection + _graphicsDevice.Viewport = new Viewport(0, 0, _graphicsDevice.PresentationParameters.BackBufferWidth, _graphicsDevice.PresentationParameters.BackBufferHeight); + + UpdateBuffers(drawData); + + RenderCommandLists(drawData); + + // Restore modified state + _graphicsDevice.Viewport = lastViewport; + _graphicsDevice.ScissorRectangle = lastScissorBox; + } + + private unsafe void UpdateBuffers(ImDrawDataPtr drawData) + { + if (drawData.TotalVtxCount == 0) + { + return; + } + + // Expand buffers if we need more room + if (drawData.TotalVtxCount > _vertexBufferSize) + { + _vertexBuffer?.Dispose(); + + _vertexBufferSize = (int)(drawData.TotalVtxCount * 1.5f); + _vertexBuffer = new VertexBuffer(_graphicsDevice, DrawVertDeclaration.Declaration, _vertexBufferSize, BufferUsage.None); + _vertexData = new byte[_vertexBufferSize * DrawVertDeclaration.Size]; + } + + if (drawData.TotalIdxCount > _indexBufferSize) + { + _indexBuffer?.Dispose(); + + _indexBufferSize = (int)(drawData.TotalIdxCount * 1.5f); + _indexBuffer = new IndexBuffer(_graphicsDevice, IndexElementSize.SixteenBits, _indexBufferSize, BufferUsage.None); + _indexData = new byte[_indexBufferSize * sizeof(ushort)]; + } + + // Copy ImGui's vertices and indices to a set of managed byte arrays + int vtxOffset = 0; + int idxOffset = 0; + + for (int n = 0; n < drawData.CmdListsCount; n++) + { + ImDrawListPtr cmdList = drawData.CmdListsRange[n]; + + fixed (void* vtxDstPtr = &_vertexData[vtxOffset * DrawVertDeclaration.Size]) + fixed (void* idxDstPtr = &_indexData[idxOffset * sizeof(ushort)]) + { + Buffer.MemoryCopy((void*)cmdList.VtxBuffer.Data, vtxDstPtr, _vertexData.Length, cmdList.VtxBuffer.Size * DrawVertDeclaration.Size); + Buffer.MemoryCopy((void*)cmdList.IdxBuffer.Data, idxDstPtr, _indexData.Length, cmdList.IdxBuffer.Size * sizeof(ushort)); + } + + vtxOffset += cmdList.VtxBuffer.Size; + idxOffset += cmdList.IdxBuffer.Size; + } + + // Copy the managed byte arrays to the gpu vertex- and index buffers + _vertexBuffer.SetData(_vertexData, 0, drawData.TotalVtxCount * DrawVertDeclaration.Size); + _indexBuffer.SetData(_indexData, 0, drawData.TotalIdxCount * sizeof(ushort)); + } + + private unsafe void RenderCommandLists(ImDrawDataPtr drawData) + { + _graphicsDevice.SetVertexBuffer(_vertexBuffer); + _graphicsDevice.Indices = _indexBuffer; + + int vtxOffset = 0; + int idxOffset = 0; + + for (int n = 0; n < drawData.CmdListsCount; n++) + { + ImDrawListPtr cmdList = drawData.CmdListsRange[n]; + + for (int cmdi = 0; cmdi < cmdList.CmdBuffer.Size; cmdi++) + { + ImDrawCmdPtr drawCmd = cmdList.CmdBuffer[cmdi]; + + if (!_loadedTextures.ContainsKey(drawCmd.TextureId)) + { + throw new InvalidOperationException($"Could not find a texture with id '{drawCmd.TextureId}', please check your bindings"); + } + + _graphicsDevice.ScissorRectangle = new Rectangle( + (int)drawCmd.ClipRect.X, + (int)drawCmd.ClipRect.Y, + (int)(drawCmd.ClipRect.Z - drawCmd.ClipRect.X), + (int)(drawCmd.ClipRect.W - drawCmd.ClipRect.Y) + ); + + var effect = UpdateEffect(_loadedTextures[drawCmd.TextureId]); + + foreach (var pass in effect.CurrentTechnique.Passes) + { + pass.Apply(); + +#pragma warning disable CS0618 // // FNA does not expose an alternative method. + _graphicsDevice.DrawIndexedPrimitives( + primitiveType: PrimitiveType.TriangleList, + baseVertex: vtxOffset, + minVertexIndex: 0, + numVertices: cmdList.VtxBuffer.Size, + startIndex: idxOffset, + primitiveCount: (int)drawCmd.ElemCount / 3 + ); +#pragma warning restore CS0618 + } + + idxOffset += (int)drawCmd.ElemCount; + } + + vtxOffset += cmdList.VtxBuffer.Size; + } + } + + #endregion Internals + } +} diff --git a/OpenKh.Tools.Common.CustomImGui/MonoGameImGuiBootstrap.cs b/OpenKh.Tools.Common.CustomImGui/MonoGameImGuiBootstrap.cs index c4f82ab62..8700ed76c 100644 --- a/OpenKh.Tools.Common.CustomImGui/MonoGameImGuiBootstrap.cs +++ b/OpenKh.Tools.Common.CustomImGui/MonoGameImGuiBootstrap.cs @@ -1,101 +1,101 @@ -using ImGuiNET; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; -using System.Diagnostics; -using System.Reflection; - -namespace OpenKh.Tools.Common.CustomImGui -{ - public class MonoGameImGuiBootstrap : Game - { - public static string ApplicationName = GetApplicationName(); - - private readonly Action _initFunc; - private MonoGameImGui _imGuiRenderer; - private ImFontPtr _imSegoeUiFont; - - public string Title - { - get => Window.Title; - set => Window.Title = value; - } - - public bool ImGuiWantCaptureKeyboard => _imGuiRenderer.ImGuiWantCaptureKeyboard; - public bool ImGuiWantCaptureMouse => _imGuiRenderer.ImGuiWantCaptureMouse; - public bool ImGuiWantTextInput => _imGuiRenderer.ImGuiWantTextInput; - - public Action MainLoop { get; set; } - - public GraphicsDeviceManager GraphicsDeviceManager { get; } - - public MonoGameImGuiBootstrap( - int initialWindowWidth, int initialWindowHeight, - Action initFunc) - { - GraphicsDeviceManager = new GraphicsDeviceManager(this) - { - PreferredBackBufferWidth = initialWindowWidth, - PreferredBackBufferHeight = initialWindowHeight - }; - - Content.RootDirectory = "Content"; - Title = ApplicationName; - _initFunc = initFunc; - } - - public IntPtr BindTexture(Texture2D texture) => - _imGuiRenderer.BindTexture(texture); - - public void UnbindTexture(IntPtr textureId) => - _imGuiRenderer.UnbindTexture(textureId); - - public void RebindTexture(IntPtr textureId, Texture2D texture) => - _imGuiRenderer.RebindTexture(textureId, texture); - - protected unsafe override void Initialize() - { - _imGuiRenderer = new MonoGameImGui(this); - ImGuiEx.SetWpfStyle(); - _imSegoeUiFont = ImGuiEx.OpenFontSegoeUi(_imGuiRenderer); - _initFunc?.Invoke(this); - - base.Initialize(); - } - - protected override void LoadContent() - { - // Use this.Content to load your game content here - } - - protected override void Draw(GameTime gameTime) - { - GraphicsDeviceManager.GraphicsDevice.Clear(Color.White); - - _imGuiRenderer.BeforeLayout(gameTime); - ImGui.PushFont(_imSegoeUiFont); - MainLoop?.Invoke(this); - ImGui.PopFont(); - _imGuiRenderer.AfterLayout(); - - base.Draw(gameTime); - } - - private static string GetApplicationName() - { - var assembly = Assembly.GetEntryAssembly(); - var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); - return fvi.ProductName; - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - _imSegoeUiFont.Destroy(); - } - - base.Dispose(disposing); - } - } -} +using ImGuiNET; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Diagnostics; +using System.Reflection; + +namespace OpenKh.Tools.Common.CustomImGui +{ + public class MonoGameImGuiBootstrap : Game + { + public static string ApplicationName = GetApplicationName(); + + private readonly Action _initFunc; + private MonoGameImGui _imGuiRenderer; + private ImFontPtr _imSegoeUiFont; + + public string Title + { + get => Window.Title; + set => Window.Title = value; + } + + public bool ImGuiWantCaptureKeyboard => _imGuiRenderer.ImGuiWantCaptureKeyboard; + public bool ImGuiWantCaptureMouse => _imGuiRenderer.ImGuiWantCaptureMouse; + public bool ImGuiWantTextInput => _imGuiRenderer.ImGuiWantTextInput; + + public Action MainLoop { get; set; } + + public GraphicsDeviceManager GraphicsDeviceManager { get; } + + public MonoGameImGuiBootstrap( + int initialWindowWidth, int initialWindowHeight, + Action initFunc) + { + GraphicsDeviceManager = new GraphicsDeviceManager(this) + { + PreferredBackBufferWidth = initialWindowWidth, + PreferredBackBufferHeight = initialWindowHeight + }; + + Content.RootDirectory = "Content"; + Title = ApplicationName; + _initFunc = initFunc; + } + + public IntPtr BindTexture(Texture2D texture) => + _imGuiRenderer.BindTexture(texture); + + public void UnbindTexture(IntPtr textureId) => + _imGuiRenderer.UnbindTexture(textureId); + + public void RebindTexture(IntPtr textureId, Texture2D texture) => + _imGuiRenderer.RebindTexture(textureId, texture); + + protected unsafe override void Initialize() + { + _imGuiRenderer = new MonoGameImGui(this); + ImGuiEx.SetWpfStyle(); + _imSegoeUiFont = ImGuiEx.OpenFontSegoeUi(_imGuiRenderer); + _initFunc?.Invoke(this); + + base.Initialize(); + } + + protected override void LoadContent() + { + // Use this.Content to load your game content here + } + + protected override void Draw(GameTime gameTime) + { + GraphicsDeviceManager.GraphicsDevice.Clear(Color.White); + + _imGuiRenderer.BeforeLayout(gameTime); + ImGui.PushFont(_imSegoeUiFont); + MainLoop?.Invoke(this); + ImGui.PopFont(); + _imGuiRenderer.AfterLayout(); + + base.Draw(gameTime); + } + + private static string GetApplicationName() + { + var assembly = Assembly.GetEntryAssembly(); + var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); + return fvi.ProductName; + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + _imSegoeUiFont.Destroy(); + } + + base.Dispose(disposing); + } + } +} diff --git a/OpenKh.Tools.Common/CommandHelpers.cs b/OpenKh.Tools.Common/CommandHelpers.cs index 5a2061ad8..58fbd3a53 100644 --- a/OpenKh.Tools.Common/CommandHelpers.cs +++ b/OpenKh.Tools.Common/CommandHelpers.cs @@ -1,16 +1,16 @@ -using System.Windows.Input; - -namespace OpenKh.Tools.Common -{ - public static class CommandHelpers - { - public static bool Invoke(this ICommand command, object parameter) - { - if (!(command?.CanExecute(parameter) ?? true)) - return false; - - command?.Execute(parameter); - return true; - } - } -} +using System.Windows.Input; + +namespace OpenKh.Tools.Common +{ + public static class CommandHelpers + { + public static bool Invoke(this ICommand command, object parameter) + { + if (!(command?.CanExecute(parameter) ?? true)) + return false; + + command?.Execute(parameter); + return true; + } + } +} diff --git a/OpenKh.Tools.Common/Constants.cs b/OpenKh.Tools.Common/Constants.cs index 5d22e03e6..9a1130ece 100644 --- a/OpenKh.Tools.Common/Constants.cs +++ b/OpenKh.Tools.Common/Constants.cs @@ -1,8 +1,8 @@ -namespace OpenKh.Tools.Common -{ - public static class ToolsConstants - { - public const uint Ps2MemoryLength = 32 * 1024 * 1024; - public const uint Pcsx2BaseAddress = 0x20000000; - } -} +namespace OpenKh.Tools.Common +{ + public static class ToolsConstants + { + public const uint Ps2MemoryLength = 32 * 1024 * 1024; + public const uint Pcsx2BaseAddress = 0x20000000; + } +} diff --git a/OpenKh.Tools.Common/Controls/DrawPanel.cs b/OpenKh.Tools.Common/Controls/DrawPanel.cs index d1bb08ac6..9eb873827 100644 --- a/OpenKh.Tools.Common/Controls/DrawPanel.cs +++ b/OpenKh.Tools.Common/Controls/DrawPanel.cs @@ -1,4 +1,4 @@ -using OpenKh.Engine.Renders; +using OpenKh.Engine.Renders; using System; using System.ComponentModel; using System.Runtime.InteropServices; @@ -24,7 +24,7 @@ private static void CopyMemory(IntPtr dest, IntPtr src, int count) public static readonly DependencyProperty DrawingProperty = - GetDependencyProperty(nameof(Drawing),(o, x) => o.SetDrawing(x)); + GetDependencyProperty(nameof(Drawing), (o, x) => o.SetDrawing(x)); public static readonly DependencyProperty DrawCreateCommandProperty = GetDependencyProperty(nameof(DrawCreate), (o, x) => o.drawCreateCommand = x); diff --git a/OpenKh.Tools.Common/Controls/KingdomTextArea.cs b/OpenKh.Tools.Common/Controls/KingdomTextArea.cs index a1740bd97..4b461d4be 100644 --- a/OpenKh.Tools.Common/Controls/KingdomTextArea.cs +++ b/OpenKh.Tools.Common/Controls/KingdomTextArea.cs @@ -1,119 +1,119 @@ -using OpenKh.Kh2.Messages; -using System.Collections.Generic; -using System.Drawing; -using System.Windows; -using OpenKh.Engine.Renders; - -namespace OpenKh.Tools.Common.Controls -{ - public class KingdomTextArea : DrawPanel - { - public static DependencyProperty ContextProperty = - DependencyPropertyUtils.GetDependencyProperty( - nameof(Context), (o, x) => o.SetContext(x)); - - public static DependencyProperty MessageCommandsProperty = - DependencyPropertyUtils.GetDependencyProperty>( - nameof(MessageCommands), (o, x) => o.SetTextCommands(x)); - - public static DependencyProperty BackgroundProperty = - DependencyPropertyUtils.GetDependencyProperty( - nameof(Background), (o, x) => { }); - - private Kh2MessageRenderer _messageRenderer; - - public RenderingMessageContext Context - { - get => GetValue(ContextProperty) as RenderingMessageContext; - set => SetValue(ContextProperty, value); - } - - public IEnumerable MessageCommands - { - get => GetValue(MessageCommandsProperty) as IEnumerable; - set => SetValue(MessageCommandsProperty, value); - } - - public System.Windows.Media.Color Background - { - get => (System.Windows.Media.Color)GetValue(BackgroundProperty); - set => SetValue(BackgroundProperty, value); - } - - protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize) - { - var drawContext = new DrawContext() - { - IgnoreDraw = true - }; - - Draw(drawContext, MessageCommands); - - return new System.Windows.Size(drawContext.Width, drawContext.Height); - } - - protected override void OnDrawCreate() - { - base.OnDrawCreate(); - } - - protected override void OnDrawDestroy() - { - base.OnDrawDestroy(); - } - - protected override void OnDrawBegin() - { - base.OnDrawBegin(); - - DrawBackground(); - - Draw(new DrawContext() - { - GlobalScale = 1.0 - }, MessageCommands); - Drawing.Flush(); - } - - protected override void OnDrawEnd() - { - base.OnDrawEnd(); - } - - protected void DrawBackground() - { - var backgroundColor = Background; - Drawing.Clear(ColorF.FromRgba(backgroundColor.R, backgroundColor.G, backgroundColor.B, backgroundColor.A)); - } - - protected void Draw(DrawContext drawContext, IEnumerable commands) - { - drawContext.WindowWidth = ActualWidth; - _messageRenderer?.Draw(drawContext, commands); - } - - private void SetContext(RenderingMessageContext context) - { - _messageRenderer = new Kh2MessageRenderer(Drawing, new RenderingMessageContext - { - Font = context.Font, - Font2 = context.Font2, - Icon = context.Icon, - FontSpacing = context.FontSpacing, - IconSpacing = context.IconSpacing, - Encoder = context.Encoder, - FontWidth = context.FontWidth, - FontHeight = context.FontHeight, - TableHeight = context.TableHeight, - }); - - InvalidateVisual(); - } - - private void SetTextCommands(IEnumerable textCommands) - { - InvalidateMeasure(); - InvalidateVisual(); - } - } -} +using OpenKh.Kh2.Messages; +using System.Collections.Generic; +using System.Drawing; +using System.Windows; +using OpenKh.Engine.Renders; + +namespace OpenKh.Tools.Common.Controls +{ + public class KingdomTextArea : DrawPanel + { + public static DependencyProperty ContextProperty = + DependencyPropertyUtils.GetDependencyProperty( + nameof(Context), (o, x) => o.SetContext(x)); + + public static DependencyProperty MessageCommandsProperty = + DependencyPropertyUtils.GetDependencyProperty>( + nameof(MessageCommands), (o, x) => o.SetTextCommands(x)); + + public static DependencyProperty BackgroundProperty = + DependencyPropertyUtils.GetDependencyProperty( + nameof(Background), (o, x) => { }); + + private Kh2MessageRenderer _messageRenderer; + + public RenderingMessageContext Context + { + get => GetValue(ContextProperty) as RenderingMessageContext; + set => SetValue(ContextProperty, value); + } + + public IEnumerable MessageCommands + { + get => GetValue(MessageCommandsProperty) as IEnumerable; + set => SetValue(MessageCommandsProperty, value); + } + + public System.Windows.Media.Color Background + { + get => (System.Windows.Media.Color)GetValue(BackgroundProperty); + set => SetValue(BackgroundProperty, value); + } + + protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize) + { + var drawContext = new DrawContext() + { + IgnoreDraw = true + }; + + Draw(drawContext, MessageCommands); + + return new System.Windows.Size(drawContext.Width, drawContext.Height); + } + + protected override void OnDrawCreate() + { + base.OnDrawCreate(); + } + + protected override void OnDrawDestroy() + { + base.OnDrawDestroy(); + } + + protected override void OnDrawBegin() + { + base.OnDrawBegin(); + + DrawBackground(); + + Draw(new DrawContext() + { + GlobalScale = 1.0 + }, MessageCommands); + Drawing.Flush(); + } + + protected override void OnDrawEnd() + { + base.OnDrawEnd(); + } + + protected void DrawBackground() + { + var backgroundColor = Background; + Drawing.Clear(ColorF.FromRgba(backgroundColor.R, backgroundColor.G, backgroundColor.B, backgroundColor.A)); + } + + protected void Draw(DrawContext drawContext, IEnumerable commands) + { + drawContext.WindowWidth = ActualWidth; + _messageRenderer?.Draw(drawContext, commands); + } + + private void SetContext(RenderingMessageContext context) + { + _messageRenderer = new Kh2MessageRenderer(Drawing, new RenderingMessageContext + { + Font = context.Font, + Font2 = context.Font2, + Icon = context.Icon, + FontSpacing = context.FontSpacing, + IconSpacing = context.IconSpacing, + Encoder = context.Encoder, + FontWidth = context.FontWidth, + FontHeight = context.FontHeight, + TableHeight = context.TableHeight, + }); + + InvalidateVisual(); + } + + private void SetTextCommands(IEnumerable textCommands) + { + InvalidateMeasure(); + InvalidateVisual(); + } + } +} diff --git a/OpenKh.Tools.Common/Controls/LayoutRendererPanel.cs b/OpenKh.Tools.Common/Controls/LayoutRendererPanel.cs index 16f50b467..79bf38367 100644 --- a/OpenKh.Tools.Common/Controls/LayoutRendererPanel.cs +++ b/OpenKh.Tools.Common/Controls/LayoutRendererPanel.cs @@ -1,172 +1,172 @@ -using OpenKh.Engine; -using OpenKh.Engine.Renderers; -using OpenKh.Engine.Renders; -using OpenKh.Kh2; -using System.Collections.Generic; -using System.Linq; -using System.Windows; -using static OpenKh.Tools.Common.DependencyPropertyUtils; - -namespace OpenKh.Tools.Common.Controls -{ - public class LayoutRendererPanel : DrawPanel - { - public static readonly DependencyProperty BackgroundProperty = - GetDependencyProperty(nameof(Background), System.Windows.Media.Colors.Magenta, (o, x) => o.SetBackgroundColor(x)); - - public static readonly DependencyProperty SelectedLayoutProperty = - GetDependencyProperty(nameof(SelectedLayout), null, (o, x) => o.TrySetLayout(), x => true); - - public static readonly DependencyProperty SelectedImagesProperty = - GetDependencyProperty>(nameof(SelectedImages), null, (o, x) => o.LoadImages(x), x => true); - - public static readonly DependencyProperty SelectedSequenceGroupIndexProperty = - GetDependencyProperty(nameof(SelectedSequenceGroupIndex), 0, (o, x) => o.SelectSequenceGroup(x), x => x >= 0); - - public static readonly DependencyProperty FrameIndexProperty = - GetDependencyProperty(nameof(FrameIndex), 0, (o, x) => o.SetFrameIndex(x), x => x >= 0); - - public static readonly DependencyProperty IsPlayingProperty = - GetDependencyProperty(nameof(IsPlaying), true, (o, x) => o.SetIsPlaying(x)); - - public static readonly DependencyProperty DebugLayoutRendererProperty = - GetDependencyProperty(nameof(DebugLayoutRenderer), null, (o, x) => o.SetDebugLayoutRenderer(x)); - - private ColorF _backgroundColor; - private IDebugLayoutRenderer _debugLayoutRenderer; - - public System.Windows.Media.Color Background - { - get => (System.Windows.Media.Color)GetValue(BackgroundProperty); - set => SetValue(BackgroundProperty, value); - } - - public int SelectedSequenceGroupIndex - { - get => (int)GetValue(SelectedSequenceGroupIndexProperty); - set => SetValue(SelectedSequenceGroupIndexProperty, value); - } - - public Layout SelectedLayout - { - get => (Layout)GetValue(SelectedLayoutProperty); - set => SetValue(SelectedLayoutProperty, value); - } - - public IEnumerable SelectedImages - { - get => (IEnumerable)GetValue(SelectedImagesProperty); - set => SetValue(SelectedImagesProperty, value); - } - - public int FrameIndex - { - get => (int)GetValue(FrameIndexProperty); - set => SetValue(FrameIndexProperty, value); - } - - public bool IsPlaying - { - get => (bool)GetValue(IsPlayingProperty); - set => SetValue(IsPlayingProperty, value); - } - - public IDebugLayoutRenderer DebugLayoutRenderer - { - get => (IDebugLayoutRenderer)GetValue(DebugLayoutRendererProperty); - set => SetValue(DebugLayoutRendererProperty, value); - } - - private ISpriteTexture[] surfaces; - private LayoutRenderer layoutRenderer; - - public LayoutRendererPanel() - { - SetBackgroundColor(Background); - } - - protected override void OnDrawCreate() - { - base.OnDrawCreate(); - } - - protected override void OnDrawDestroy() - { - DisposeAllSurfaces(); - base.OnDrawDestroy(); - } - - protected override void OnDrawBegin() - { - Drawing.Clear(_backgroundColor); - layoutRenderer?.Draw(); - - if (IsPlaying) - FrameIndex++; - - Drawing.Flush(); - base.OnDrawBegin(); - } - - protected override void OnDrawEnd() - { - base.OnDrawEnd(); - } - - private void SelectSequenceGroup(int index) - { - layoutRenderer.SelectedSequenceGroupIndex = index; - FrameIndex = 0; - } - - private void SetFrameIndex(int frameIndex) - { - if (layoutRenderer != null) - layoutRenderer.FrameIndex = frameIndex; - } - - private void SetIsPlaying(bool isPlaying) { } - - private void SetDebugLayoutRenderer(IDebugLayoutRenderer debugLayoutRenderer) - { - _debugLayoutRenderer = debugLayoutRenderer; - layoutRenderer?.SetDebugLayoutRenderer(debugLayoutRenderer); - } - - private void TrySetLayout() - { - if (SelectedLayout != null && surfaces != null) - { - layoutRenderer = new LayoutRenderer(SelectedLayout, Drawing, surfaces); - layoutRenderer.SetDebugLayoutRenderer(_debugLayoutRenderer); - } - else - layoutRenderer = null; - } - - private void SetBackgroundColor(System.Windows.Media.Color color) => - _backgroundColor = ColorF.FromRgba(color.R, color.G, color.B, color.A); - - private void LoadImages(IEnumerable images) - { - DisposeAllSurfaces(); - - surfaces = images - .Select(x => Drawing.CreateSpriteTexture(x)) - .ToArray(); - - TrySetLayout(); - } - - private void DisposeAllSurfaces() - { - if (surfaces == null) - return; - - foreach (var surface in surfaces) - surface.Dispose(); - - surfaces = null; - } - } -} +using OpenKh.Engine; +using OpenKh.Engine.Renderers; +using OpenKh.Engine.Renders; +using OpenKh.Kh2; +using System.Collections.Generic; +using System.Linq; +using System.Windows; +using static OpenKh.Tools.Common.DependencyPropertyUtils; + +namespace OpenKh.Tools.Common.Controls +{ + public class LayoutRendererPanel : DrawPanel + { + public static readonly DependencyProperty BackgroundProperty = + GetDependencyProperty(nameof(Background), System.Windows.Media.Colors.Magenta, (o, x) => o.SetBackgroundColor(x)); + + public static readonly DependencyProperty SelectedLayoutProperty = + GetDependencyProperty(nameof(SelectedLayout), null, (o, x) => o.TrySetLayout(), x => true); + + public static readonly DependencyProperty SelectedImagesProperty = + GetDependencyProperty>(nameof(SelectedImages), null, (o, x) => o.LoadImages(x), x => true); + + public static readonly DependencyProperty SelectedSequenceGroupIndexProperty = + GetDependencyProperty(nameof(SelectedSequenceGroupIndex), 0, (o, x) => o.SelectSequenceGroup(x), x => x >= 0); + + public static readonly DependencyProperty FrameIndexProperty = + GetDependencyProperty(nameof(FrameIndex), 0, (o, x) => o.SetFrameIndex(x), x => x >= 0); + + public static readonly DependencyProperty IsPlayingProperty = + GetDependencyProperty(nameof(IsPlaying), true, (o, x) => o.SetIsPlaying(x)); + + public static readonly DependencyProperty DebugLayoutRendererProperty = + GetDependencyProperty(nameof(DebugLayoutRenderer), null, (o, x) => o.SetDebugLayoutRenderer(x)); + + private ColorF _backgroundColor; + private IDebugLayoutRenderer _debugLayoutRenderer; + + public System.Windows.Media.Color Background + { + get => (System.Windows.Media.Color)GetValue(BackgroundProperty); + set => SetValue(BackgroundProperty, value); + } + + public int SelectedSequenceGroupIndex + { + get => (int)GetValue(SelectedSequenceGroupIndexProperty); + set => SetValue(SelectedSequenceGroupIndexProperty, value); + } + + public Layout SelectedLayout + { + get => (Layout)GetValue(SelectedLayoutProperty); + set => SetValue(SelectedLayoutProperty, value); + } + + public IEnumerable SelectedImages + { + get => (IEnumerable)GetValue(SelectedImagesProperty); + set => SetValue(SelectedImagesProperty, value); + } + + public int FrameIndex + { + get => (int)GetValue(FrameIndexProperty); + set => SetValue(FrameIndexProperty, value); + } + + public bool IsPlaying + { + get => (bool)GetValue(IsPlayingProperty); + set => SetValue(IsPlayingProperty, value); + } + + public IDebugLayoutRenderer DebugLayoutRenderer + { + get => (IDebugLayoutRenderer)GetValue(DebugLayoutRendererProperty); + set => SetValue(DebugLayoutRendererProperty, value); + } + + private ISpriteTexture[] surfaces; + private LayoutRenderer layoutRenderer; + + public LayoutRendererPanel() + { + SetBackgroundColor(Background); + } + + protected override void OnDrawCreate() + { + base.OnDrawCreate(); + } + + protected override void OnDrawDestroy() + { + DisposeAllSurfaces(); + base.OnDrawDestroy(); + } + + protected override void OnDrawBegin() + { + Drawing.Clear(_backgroundColor); + layoutRenderer?.Draw(); + + if (IsPlaying) + FrameIndex++; + + Drawing.Flush(); + base.OnDrawBegin(); + } + + protected override void OnDrawEnd() + { + base.OnDrawEnd(); + } + + private void SelectSequenceGroup(int index) + { + layoutRenderer.SelectedSequenceGroupIndex = index; + FrameIndex = 0; + } + + private void SetFrameIndex(int frameIndex) + { + if (layoutRenderer != null) + layoutRenderer.FrameIndex = frameIndex; + } + + private void SetIsPlaying(bool isPlaying) { } + + private void SetDebugLayoutRenderer(IDebugLayoutRenderer debugLayoutRenderer) + { + _debugLayoutRenderer = debugLayoutRenderer; + layoutRenderer?.SetDebugLayoutRenderer(debugLayoutRenderer); + } + + private void TrySetLayout() + { + if (SelectedLayout != null && surfaces != null) + { + layoutRenderer = new LayoutRenderer(SelectedLayout, Drawing, surfaces); + layoutRenderer.SetDebugLayoutRenderer(_debugLayoutRenderer); + } + else + layoutRenderer = null; + } + + private void SetBackgroundColor(System.Windows.Media.Color color) => + _backgroundColor = ColorF.FromRgba(color.R, color.G, color.B, color.A); + + private void LoadImages(IEnumerable images) + { + DisposeAllSurfaces(); + + surfaces = images + .Select(x => Drawing.CreateSpriteTexture(x)) + .ToArray(); + + TrySetLayout(); + } + + private void DisposeAllSurfaces() + { + if (surfaces == null) + return; + + foreach (var surface in surfaces) + surface.Dispose(); + + surfaces = null; + } + } +} diff --git a/OpenKh.Tools.Common/Controls/SequenceRendererPanel.cs b/OpenKh.Tools.Common/Controls/SequenceRendererPanel.cs index 99433f6fc..02a00a35d 100644 --- a/OpenKh.Tools.Common/Controls/SequenceRendererPanel.cs +++ b/OpenKh.Tools.Common/Controls/SequenceRendererPanel.cs @@ -1,153 +1,153 @@ -using OpenKh.Engine.Renderers; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using System.Drawing; -using System.Windows; -using static OpenKh.Tools.Common.DependencyPropertyUtils; -using OpenKh.Engine.Renders; - -namespace OpenKh.Tools.Common.Controls -{ - public class SequenceRendererPanel : DrawPanel - { - public static readonly DependencyProperty BackgroundProperty = - GetDependencyProperty(nameof(Background), System.Windows.Media.Colors.Magenta, (o, x) => o.SetBackgroundColor(x)); - - public static readonly DependencyProperty SelectedSequenceProperty = - GetDependencyProperty(nameof(SelectedSequence), null, (o, x) => o.TrySetSequence(), x => true); - - public static readonly DependencyProperty SelectedImagesProperty = - GetDependencyProperty(nameof(SelectedImage), null, (o, x) => o.LoadImage(x), x => true); - - public static readonly DependencyProperty SelectedSequenceGroupIndexProperty = - GetDependencyProperty(nameof(SelectedAnimationGroupIndex), 0, (o, x) => o.SelectSequenceGroup(x), x => x >= 0); - - public static readonly DependencyProperty FrameIndexProperty = - GetDependencyProperty(nameof(FrameIndex), 0, (o, x) => o.SetFrameIndex(x), x => x >= 0); - - public static readonly DependencyProperty AdjustPositionProperty = - GetDependencyProperty(nameof(AdjustPosition), false, (o, x) => { }); - - private ColorF _backgroundColor; - private Rectangle _sequenceVisibilyRectangle; - - public System.Windows.Media.Color Background - { - get => (System.Windows.Media.Color)GetValue(BackgroundProperty); - set => SetValue(BackgroundProperty, value); - } - - public int SelectedAnimationGroupIndex - { - get => (int)GetValue(SelectedSequenceGroupIndexProperty); - set - { - SetValue(SelectedSequenceGroupIndexProperty, value); - InvalidateMeasure(); - } - } - - public Sequence SelectedSequence - { - get => (Sequence)GetValue(SelectedSequenceProperty); - set - { - SetValue(SelectedSequenceProperty, value); - InvalidateMeasure(); - } - } - - public Imgd SelectedImage - { - get => (Imgd)GetValue(SelectedImagesProperty); - set => SetValue(SelectedImagesProperty, value); - } - - public int FrameIndex - { - get => (int)GetValue(FrameIndexProperty); - set => SetValue(FrameIndexProperty, value); - } - - public bool AdjustPosition - { - get => (bool)GetValue(AdjustPositionProperty); - set => SetValue(AdjustPositionProperty, value); - } - - private ISpriteTexture surface; - private SequenceRenderer sequenceRenderer; - - public SequenceRendererPanel() - { - SetBackgroundColor(Background); - } - - protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize) - { - var rect = SelectedSequence?.GetVisibilityRectangleFromAnimationGroup(SelectedSequence.AnimationGroups[SelectedAnimationGroupIndex]); - if (rect == null) - return base.MeasureOverride(availableSize); - - _sequenceVisibilyRectangle = rect.Value; - var size = _sequenceVisibilyRectangle.Size; - return new System.Windows.Size(size.Width, size.Height); - } - - protected override void OnDrawCreate() - { - base.OnDrawCreate(); - } - - protected override void OnDrawDestroy() - { - surface?.Dispose(); - base.OnDrawDestroy(); - } - - protected override void OnDrawBegin() - { - Drawing.Clear(_backgroundColor); - - var posX = AdjustPosition ? -_sequenceVisibilyRectangle.X : (float)(ActualWidth / 2); - var posY = AdjustPosition ? -_sequenceVisibilyRectangle.Y : (float)(ActualHeight / 2); - sequenceRenderer?.Draw(SelectedAnimationGroupIndex, FrameIndex, posX, posY); - FrameIndex++; - Drawing.Flush(); - base.OnDrawBegin(); - } - - protected override void OnDrawEnd() - { - base.OnDrawEnd(); - } - - private void SetBackgroundColor(System.Windows.Media.Color color) => - _backgroundColor = ColorF.FromRgba(color.R, color.G, color.B, color.A); - - private void SelectSequenceGroup(int index) - { - FrameIndex = 0; - } - - private void SetFrameIndex(int frameIndex) - { - } - - private void TrySetSequence() - { - if (SelectedSequence != null && surface != null) - sequenceRenderer = new SequenceRenderer(SelectedSequence, Drawing, surface); - else - sequenceRenderer = null; - } - - private void LoadImage(Imgd image) - { - surface?.Dispose(); - surface = Drawing?.CreateSpriteTexture(image); - - TrySetSequence(); - } - } -} +using OpenKh.Engine.Renderers; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using System.Drawing; +using System.Windows; +using static OpenKh.Tools.Common.DependencyPropertyUtils; +using OpenKh.Engine.Renders; + +namespace OpenKh.Tools.Common.Controls +{ + public class SequenceRendererPanel : DrawPanel + { + public static readonly DependencyProperty BackgroundProperty = + GetDependencyProperty(nameof(Background), System.Windows.Media.Colors.Magenta, (o, x) => o.SetBackgroundColor(x)); + + public static readonly DependencyProperty SelectedSequenceProperty = + GetDependencyProperty(nameof(SelectedSequence), null, (o, x) => o.TrySetSequence(), x => true); + + public static readonly DependencyProperty SelectedImagesProperty = + GetDependencyProperty(nameof(SelectedImage), null, (o, x) => o.LoadImage(x), x => true); + + public static readonly DependencyProperty SelectedSequenceGroupIndexProperty = + GetDependencyProperty(nameof(SelectedAnimationGroupIndex), 0, (o, x) => o.SelectSequenceGroup(x), x => x >= 0); + + public static readonly DependencyProperty FrameIndexProperty = + GetDependencyProperty(nameof(FrameIndex), 0, (o, x) => o.SetFrameIndex(x), x => x >= 0); + + public static readonly DependencyProperty AdjustPositionProperty = + GetDependencyProperty(nameof(AdjustPosition), false, (o, x) => { }); + + private ColorF _backgroundColor; + private Rectangle _sequenceVisibilyRectangle; + + public System.Windows.Media.Color Background + { + get => (System.Windows.Media.Color)GetValue(BackgroundProperty); + set => SetValue(BackgroundProperty, value); + } + + public int SelectedAnimationGroupIndex + { + get => (int)GetValue(SelectedSequenceGroupIndexProperty); + set + { + SetValue(SelectedSequenceGroupIndexProperty, value); + InvalidateMeasure(); + } + } + + public Sequence SelectedSequence + { + get => (Sequence)GetValue(SelectedSequenceProperty); + set + { + SetValue(SelectedSequenceProperty, value); + InvalidateMeasure(); + } + } + + public Imgd SelectedImage + { + get => (Imgd)GetValue(SelectedImagesProperty); + set => SetValue(SelectedImagesProperty, value); + } + + public int FrameIndex + { + get => (int)GetValue(FrameIndexProperty); + set => SetValue(FrameIndexProperty, value); + } + + public bool AdjustPosition + { + get => (bool)GetValue(AdjustPositionProperty); + set => SetValue(AdjustPositionProperty, value); + } + + private ISpriteTexture surface; + private SequenceRenderer sequenceRenderer; + + public SequenceRendererPanel() + { + SetBackgroundColor(Background); + } + + protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize) + { + var rect = SelectedSequence?.GetVisibilityRectangleFromAnimationGroup(SelectedSequence.AnimationGroups[SelectedAnimationGroupIndex]); + if (rect == null) + return base.MeasureOverride(availableSize); + + _sequenceVisibilyRectangle = rect.Value; + var size = _sequenceVisibilyRectangle.Size; + return new System.Windows.Size(size.Width, size.Height); + } + + protected override void OnDrawCreate() + { + base.OnDrawCreate(); + } + + protected override void OnDrawDestroy() + { + surface?.Dispose(); + base.OnDrawDestroy(); + } + + protected override void OnDrawBegin() + { + Drawing.Clear(_backgroundColor); + + var posX = AdjustPosition ? -_sequenceVisibilyRectangle.X : (float)(ActualWidth / 2); + var posY = AdjustPosition ? -_sequenceVisibilyRectangle.Y : (float)(ActualHeight / 2); + sequenceRenderer?.Draw(SelectedAnimationGroupIndex, FrameIndex, posX, posY); + FrameIndex++; + Drawing.Flush(); + base.OnDrawBegin(); + } + + protected override void OnDrawEnd() + { + base.OnDrawEnd(); + } + + private void SetBackgroundColor(System.Windows.Media.Color color) => + _backgroundColor = ColorF.FromRgba(color.R, color.G, color.B, color.A); + + private void SelectSequenceGroup(int index) + { + FrameIndex = 0; + } + + private void SetFrameIndex(int frameIndex) + { + } + + private void TrySetSequence() + { + if (SelectedSequence != null && surface != null) + sequenceRenderer = new SequenceRenderer(SelectedSequence, Drawing, surface); + else + sequenceRenderer = null; + } + + private void LoadImage(Imgd image) + { + surface?.Dispose(); + surface = Drawing?.CreateSpriteTexture(image); + + TrySetSequence(); + } + } +} diff --git a/OpenKh.Tools.Common/Controls/Timeline.xaml.cs b/OpenKh.Tools.Common/Controls/Timeline.xaml.cs index 644d55b12..868910420 100644 --- a/OpenKh.Tools.Common/Controls/Timeline.xaml.cs +++ b/OpenKh.Tools.Common/Controls/Timeline.xaml.cs @@ -1,73 +1,73 @@ -using System; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using static OpenKh.Tools.Common.DependencyPropertyUtils; - -namespace OpenKh.Tools.Common.Controls -{ - /// - /// Interaction logic for Timeline.xaml - /// - public partial class Timeline : UserControl - { - public static readonly DependencyProperty ValueProperty = - GetDependencyProperty(nameof(Value), (o, x) => o.SetValue(x)); - - public static readonly DependencyProperty MaxValueProperty = - GetDependencyProperty(nameof(MaxValue), (o, x) => o.SetMaxValue(x)); - - public double Value - { - get => (double)GetValue(ValueProperty); - set => SetValue(ValueProperty, value); - } - - public double MaxValue - { - get => (double)GetValue(MaxValueProperty); - set => SetValue(MaxValueProperty, value); - } - - public Timeline() - { - InitializeComponent(); - } - - private void SetValue(double x) - { - UpdateCursorPosition(); - } - - private void SetMaxValue(double x) - { - UpdateCursorPosition(); - } - - private void UpdateCursorPosition() - { - Canvas.SetLeft(cursor, Math.Min(Value, MaxValue) / MaxValue * ActualWidth); - } - - protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) - { - base.OnRenderSizeChanged(sizeInfo); - UpdateCursorPosition(); - } - - private void UserControl_MouseDown(object sender, MouseButtonEventArgs e) => - HandleMouse(sender, e); - - private void UserControl_MouseMove(object sender, MouseEventArgs e) => - HandleMouse(sender, e); - - private void HandleMouse(object sender, MouseEventArgs e) - { - if (e.LeftButton == MouseButtonState.Pressed) - { - var mousePosition = e.GetPosition(sender as FrameworkElement); - Value = mousePosition.X / ActualWidth * MaxValue; - } - } - } -} +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using static OpenKh.Tools.Common.DependencyPropertyUtils; + +namespace OpenKh.Tools.Common.Controls +{ + /// + /// Interaction logic for Timeline.xaml + /// + public partial class Timeline : UserControl + { + public static readonly DependencyProperty ValueProperty = + GetDependencyProperty(nameof(Value), (o, x) => o.SetValue(x)); + + public static readonly DependencyProperty MaxValueProperty = + GetDependencyProperty(nameof(MaxValue), (o, x) => o.SetMaxValue(x)); + + public double Value + { + get => (double)GetValue(ValueProperty); + set => SetValue(ValueProperty, value); + } + + public double MaxValue + { + get => (double)GetValue(MaxValueProperty); + set => SetValue(MaxValueProperty, value); + } + + public Timeline() + { + InitializeComponent(); + } + + private void SetValue(double x) + { + UpdateCursorPosition(); + } + + private void SetMaxValue(double x) + { + UpdateCursorPosition(); + } + + private void UpdateCursorPosition() + { + Canvas.SetLeft(cursor, Math.Min(Value, MaxValue) / MaxValue * ActualWidth); + } + + protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) + { + base.OnRenderSizeChanged(sizeInfo); + UpdateCursorPosition(); + } + + private void UserControl_MouseDown(object sender, MouseButtonEventArgs e) => + HandleMouse(sender, e); + + private void UserControl_MouseMove(object sender, MouseEventArgs e) => + HandleMouse(sender, e); + + private void HandleMouse(object sender, MouseEventArgs e) + { + if (e.LeftButton == MouseButtonState.Pressed) + { + var mousePosition = e.GetPosition(sender as FrameworkElement); + Value = mousePosition.X / ActualWidth * MaxValue; + } + } + } +} diff --git a/OpenKh.Tools.Common/DependencyPropertyUtils.cs b/OpenKh.Tools.Common/DependencyPropertyUtils.cs index 04ab2e04e..5a45450f5 100644 --- a/OpenKh.Tools.Common/DependencyPropertyUtils.cs +++ b/OpenKh.Tools.Common/DependencyPropertyUtils.cs @@ -1,39 +1,39 @@ -using System; -using System.Windows; - -namespace OpenKh.Tools.Common -{ - public static class DependencyPropertyUtils - { - public static DependencyProperty GetDependencyProperty( - string name, - Action setter, - Func validator = null) - where TClass : class => - GetDependencyProperty(name, default, setter); - - public static DependencyProperty GetDependencyProperty( - string name, - TValue defaultValue, - Action setter, - Func validator = null) - where TClass : class => DependencyProperty.Register( - name, - typeof(TValue), - typeof(TClass), - GetProperyMetadata(defaultValue, setter), - validator == null ? - GetValidateDefault(defaultValue == null) : - GetValidateWithFunc(validator, defaultValue == null)); - - public static PropertyMetadata GetProperyMetadata(TValue defalutValue, Action setter) - where TClass : class => new PropertyMetadata(defalutValue, GetProperyCallback(setter)); - public static PropertyChangedCallback GetProperyCallback(Action setter) - where TClass : class => new PropertyChangedCallback((d, e) => setter(d as TClass, (TValue)e.NewValue)); - - public static ValidateValueCallback GetValidateWithFunc(Func funcValidator, bool canBeNull) => - new ValidateValueCallback(x => (x == null && canBeNull) || (x is T value ? funcValidator(value) : false)); - public static ValidateValueCallback GetValidateDefault(bool canBeNull) => - new ValidateValueCallback(x => (x == null && canBeNull) || (x is T)); - } -} +using System; +using System.Windows; + +namespace OpenKh.Tools.Common +{ + public static class DependencyPropertyUtils + { + public static DependencyProperty GetDependencyProperty( + string name, + Action setter, + Func validator = null) + where TClass : class => + GetDependencyProperty(name, default, setter); + + public static DependencyProperty GetDependencyProperty( + string name, + TValue defaultValue, + Action setter, + Func validator = null) + where TClass : class => DependencyProperty.Register( + name, + typeof(TValue), + typeof(TClass), + GetProperyMetadata(defaultValue, setter), + validator == null ? + GetValidateDefault(defaultValue == null) : + GetValidateWithFunc(validator, defaultValue == null)); + + public static PropertyMetadata GetProperyMetadata(TValue defalutValue, Action setter) + where TClass : class => new PropertyMetadata(defalutValue, GetProperyCallback(setter)); + public static PropertyChangedCallback GetProperyCallback(Action setter) + where TClass : class => new PropertyChangedCallback((d, e) => setter(d as TClass, (TValue)e.NewValue)); + + public static ValidateValueCallback GetValidateWithFunc(Func funcValidator, bool canBeNull) => + new ValidateValueCallback(x => (x == null && canBeNull) || (x is T value ? funcValidator(value) : false)); + public static ValidateValueCallback GetValidateDefault(bool canBeNull) => + new ValidateValueCallback(x => (x == null && canBeNull) || (x is T)); + } +} diff --git a/OpenKh.Tools.Common/ImageReadExtensions.cs b/OpenKh.Tools.Common/ImageReadExtensions.cs index db7a7203b..0c24e66e6 100644 --- a/OpenKh.Tools.Common/ImageReadExtensions.cs +++ b/OpenKh.Tools.Common/ImageReadExtensions.cs @@ -1,18 +1,18 @@ -using OpenKh.Imaging; -using System.Windows.Media; -using System.Windows.Media.Imaging; - -namespace OpenKh.Tools.Common -{ - public static class ImageReadExtensions - { - public static BitmapSource GetBimapSource(this IImageRead imageRead) - { - const double dpi = 96.0; - - var size = imageRead.Size; - var data = imageRead.ToBgra32(); - return BitmapSource.Create(size.Width, size.Height, dpi, dpi, PixelFormats.Bgra32, null, data, size.Width * 4); - } - } -} +using OpenKh.Imaging; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace OpenKh.Tools.Common +{ + public static class ImageReadExtensions + { + public static BitmapSource GetBimapSource(this IImageRead imageRead) + { + const double dpi = 96.0; + + var size = imageRead.Size; + var data = imageRead.ToBgra32(); + return BitmapSource.Create(size.Width, size.Height, dpi, dpi, PixelFormats.Bgra32, null, data, size.Width * 4); + } + } +} diff --git a/OpenKh.Tools.Common/Imaging/GdiFormats.cs b/OpenKh.Tools.Common/Imaging/GdiFormats.cs index 2b54e6b3b..d8e3d373e 100644 --- a/OpenKh.Tools.Common/Imaging/GdiFormats.cs +++ b/OpenKh.Tools.Common/Imaging/GdiFormats.cs @@ -1,85 +1,85 @@ -using OpenKh.Imaging; -using System.Drawing.Imaging; -using System.IO; - -namespace OpenKh.Tools.Common.Imaging -{ - public static class Png - { - public static bool IsValid(Stream stream) - { - stream.Position = 0; - return stream.ReadByte() == 0x89 && - stream.ReadByte() == 0x50 && - stream.ReadByte() == 0x4e && - stream.ReadByte() == 0x47 && - stream.ReadByte() == 0x0d && - stream.ReadByte() == 0x0a && - stream.ReadByte() == 0x1a && - stream.ReadByte() == 0x0a; - } - - public static IImageRead Read(Stream stream) - { - stream.Position = 0; // IsValid advances 8 bytes - return new PngImage(stream); - } - - public static void Write(Stream stream, IImageRead image) - { - using (var bitmap = image.CreateBitmap()) - { - stream.Position = 0; - bitmap.Save(stream, ImageFormat.Png); - } - } - } - - public static class Bmp - { - public static bool IsValid(Stream stream) - { - stream.Position = 0; - return stream.ReadByte() == 0x42 && - stream.ReadByte() == 0x4d; - } - - public static IImageRead Read(Stream stream) => new GdiImage(stream); - - public static void Write(Stream stream, IImageRead image) - { - using (var bitmap = image.CreateBitmap()) - { - stream.Position = 0; - bitmap.Save(stream, ImageFormat.Bmp); - } - } - } - - public static class Tiff - { - public static bool IsValid(Stream stream) - { - stream.Position = 0; - if (stream.ReadByte() == 0x49 && stream.ReadByte() == 0x49) - return true; - - stream.Position = 0; - if (stream.ReadByte() == 0x4d && stream.ReadByte() == 0x4d) - return true; - - return false; - } - - public static IImageRead Read(Stream stream) => new GdiImage(stream); - - public static void Write(Stream stream, IImageRead image) - { - using (var bitmap = image.CreateBitmap()) - { - stream.Position = 0; - bitmap.Save(stream, ImageFormat.Tiff); - } - } - } -} +using OpenKh.Imaging; +using System.Drawing.Imaging; +using System.IO; + +namespace OpenKh.Tools.Common.Imaging +{ + public static class Png + { + public static bool IsValid(Stream stream) + { + stream.Position = 0; + return stream.ReadByte() == 0x89 && + stream.ReadByte() == 0x50 && + stream.ReadByte() == 0x4e && + stream.ReadByte() == 0x47 && + stream.ReadByte() == 0x0d && + stream.ReadByte() == 0x0a && + stream.ReadByte() == 0x1a && + stream.ReadByte() == 0x0a; + } + + public static IImageRead Read(Stream stream) + { + stream.Position = 0; // IsValid advances 8 bytes + return new PngImage(stream); + } + + public static void Write(Stream stream, IImageRead image) + { + using (var bitmap = image.CreateBitmap()) + { + stream.Position = 0; + bitmap.Save(stream, ImageFormat.Png); + } + } + } + + public static class Bmp + { + public static bool IsValid(Stream stream) + { + stream.Position = 0; + return stream.ReadByte() == 0x42 && + stream.ReadByte() == 0x4d; + } + + public static IImageRead Read(Stream stream) => new GdiImage(stream); + + public static void Write(Stream stream, IImageRead image) + { + using (var bitmap = image.CreateBitmap()) + { + stream.Position = 0; + bitmap.Save(stream, ImageFormat.Bmp); + } + } + } + + public static class Tiff + { + public static bool IsValid(Stream stream) + { + stream.Position = 0; + if (stream.ReadByte() == 0x49 && stream.ReadByte() == 0x49) + return true; + + stream.Position = 0; + if (stream.ReadByte() == 0x4d && stream.ReadByte() == 0x4d) + return true; + + return false; + } + + public static IImageRead Read(Stream stream) => new GdiImage(stream); + + public static void Write(Stream stream, IImageRead image) + { + using (var bitmap = image.CreateBitmap()) + { + stream.Position = 0; + bitmap.Save(stream, ImageFormat.Tiff); + } + } + } +} diff --git a/OpenKh.Tools.Common/Imaging/GdiImage.cs b/OpenKh.Tools.Common/Imaging/GdiImage.cs index cbee01239..39c2b115b 100644 --- a/OpenKh.Tools.Common/Imaging/GdiImage.cs +++ b/OpenKh.Tools.Common/Imaging/GdiImage.cs @@ -1,53 +1,53 @@ -using OpenKh.Imaging; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Runtime.InteropServices; - -namespace OpenKh.Tools.Common.Imaging -{ - internal class GdiImage : IImageRead - { - private readonly Bitmap _bitmap; - - public GdiImage(Stream stream) - { - stream.Position = 0; - _bitmap = new Bitmap(stream); - } - - public Size Size => _bitmap.Size; - - public OpenKh.Imaging.PixelFormat PixelFormat => _bitmap.PixelFormat.GetPixelFormat(); - - public byte[] GetClut() - { - var palette = _bitmap.Palette?.Entries ?? new Color[0]; - var clut = new byte[palette.Length * 4]; - - for (var i = 0; i < palette.Length; i++) - { - var color = palette[i]; - clut[i * 4 + 0] = color.R; - clut[i * 4 + 1] = color.G; - clut[i * 4 + 2] = color.B; - clut[i * 4 + 3] = color.A; - } - - return clut; - } - - public byte[] GetData() - { - var rect = new Rectangle(0, 0, _bitmap.Width, _bitmap.Height); - var bitmapData = _bitmap.LockBits(rect, ImageLockMode.ReadOnly, _bitmap.PixelFormat); - - var dstData = new byte[bitmapData.Stride * bitmapData.Height]; - Marshal.Copy(bitmapData.Scan0, dstData, 0, dstData.Length); - - _bitmap.UnlockBits(bitmapData); - - return dstData; - } - } -} +using OpenKh.Imaging; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Runtime.InteropServices; + +namespace OpenKh.Tools.Common.Imaging +{ + internal class GdiImage : IImageRead + { + private readonly Bitmap _bitmap; + + public GdiImage(Stream stream) + { + stream.Position = 0; + _bitmap = new Bitmap(stream); + } + + public Size Size => _bitmap.Size; + + public OpenKh.Imaging.PixelFormat PixelFormat => _bitmap.PixelFormat.GetPixelFormat(); + + public byte[] GetClut() + { + var palette = _bitmap.Palette?.Entries ?? new Color[0]; + var clut = new byte[palette.Length * 4]; + + for (var i = 0; i < palette.Length; i++) + { + var color = palette[i]; + clut[i * 4 + 0] = color.R; + clut[i * 4 + 1] = color.G; + clut[i * 4 + 2] = color.B; + clut[i * 4 + 3] = color.A; + } + + return clut; + } + + public byte[] GetData() + { + var rect = new Rectangle(0, 0, _bitmap.Width, _bitmap.Height); + var bitmapData = _bitmap.LockBits(rect, ImageLockMode.ReadOnly, _bitmap.PixelFormat); + + var dstData = new byte[bitmapData.Stride * bitmapData.Height]; + Marshal.Copy(bitmapData.Scan0, dstData, 0, dstData.Length); + + _bitmap.UnlockBits(bitmapData); + + return dstData; + } + } +} diff --git a/OpenKh.Tools.Common/Imaging/ImageExtensions.cs b/OpenKh.Tools.Common/Imaging/ImageExtensions.cs index dd28e262d..e05a85e1c 100644 --- a/OpenKh.Tools.Common/Imaging/ImageExtensions.cs +++ b/OpenKh.Tools.Common/Imaging/ImageExtensions.cs @@ -1,55 +1,55 @@ -using OpenKh.Imaging; -using System; -using System.Drawing; -using System.Drawing.Imaging; -using System.Runtime.InteropServices; - -namespace OpenKh.Tools.Common.Imaging -{ - public static class ImageExtensions - { - public static void SaveImage(this IImageRead imageRead, string fileName) - { - using (var gdiBitmap = imageRead.CreateBitmap()) - { - gdiBitmap.Save(fileName); - } - } - - public static Bitmap CreateBitmap(this IImageRead imageRead) - { - var drawingPixelFormat = imageRead.PixelFormat.GetDrawingPixelFormat(); - Bitmap bitmap = new Bitmap(imageRead.Size.Width, imageRead.Size.Height, drawingPixelFormat); - - var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); - var bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, drawingPixelFormat); - - var srcData = imageRead.GetData(); - var dstLength = Math.Min(srcData.Length, bitmapData.Stride * bitmapData.Height); - Marshal.Copy(srcData, 0, bitmapData.Scan0, dstLength); - - bitmap.UnlockBits(bitmapData); - - var isIndexed = imageRead.PixelFormat.IsIndexed(); - if (isIndexed) - { - var palette = bitmap.Palette; - var clut = imageRead.GetClut(); - var colorsCount = Math.Min(clut.Length / 4, palette.Entries.Length); - - for (var i = 0; i < colorsCount; i++) - { - palette.Entries[i] = Color.FromArgb( - clut[i * 4 + 3], - clut[i * 4 + 0], - clut[i * 4 + 1], - clut[i * 4 + 2]); - } - - bitmap.Palette = palette; - } - - return bitmap; - } - } -} +using OpenKh.Imaging; +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; + +namespace OpenKh.Tools.Common.Imaging +{ + public static class ImageExtensions + { + public static void SaveImage(this IImageRead imageRead, string fileName) + { + using (var gdiBitmap = imageRead.CreateBitmap()) + { + gdiBitmap.Save(fileName); + } + } + + public static Bitmap CreateBitmap(this IImageRead imageRead) + { + var drawingPixelFormat = imageRead.PixelFormat.GetDrawingPixelFormat(); + Bitmap bitmap = new Bitmap(imageRead.Size.Width, imageRead.Size.Height, drawingPixelFormat); + + var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); + var bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, drawingPixelFormat); + + var srcData = imageRead.GetData(); + var dstLength = Math.Min(srcData.Length, bitmapData.Stride * bitmapData.Height); + Marshal.Copy(srcData, 0, bitmapData.Scan0, dstLength); + + bitmap.UnlockBits(bitmapData); + + var isIndexed = imageRead.PixelFormat.IsIndexed(); + if (isIndexed) + { + var palette = bitmap.Palette; + var clut = imageRead.GetClut(); + var colorsCount = Math.Min(clut.Length / 4, palette.Entries.Length); + + for (var i = 0; i < colorsCount; i++) + { + palette.Entries[i] = Color.FromArgb( + clut[i * 4 + 3], + clut[i * 4 + 0], + clut[i * 4 + 1], + clut[i * 4 + 2]); + } + + bitmap.Palette = palette; + } + + return bitmap; + } + } +} diff --git a/OpenKh.Tools.Common/Imaging/PixelFormatExtensions.cs b/OpenKh.Tools.Common/Imaging/PixelFormatExtensions.cs index 2be61ca78..79015a942 100644 --- a/OpenKh.Tools.Common/Imaging/PixelFormatExtensions.cs +++ b/OpenKh.Tools.Common/Imaging/PixelFormatExtensions.cs @@ -1,51 +1,51 @@ -using System; - -namespace OpenKh.Imaging -{ - public static class PixelFormatExtensions - { - internal static System.Drawing.Imaging.PixelFormat GetDrawingPixelFormat(this PixelFormat pixelFormat) - { - switch (pixelFormat) - { - case PixelFormat.Indexed4: - return System.Drawing.Imaging.PixelFormat.Format4bppIndexed; - case PixelFormat.Indexed8: - return System.Drawing.Imaging.PixelFormat.Format8bppIndexed; - case PixelFormat.Rgba1555: - return System.Drawing.Imaging.PixelFormat.Format32bppArgb; - case PixelFormat.Rgb888: - return System.Drawing.Imaging.PixelFormat.Format24bppRgb; - case PixelFormat.Rgbx8888: - return System.Drawing.Imaging.PixelFormat.Format32bppRgb; - case PixelFormat.Rgba8888: - return System.Drawing.Imaging.PixelFormat.Format32bppArgb; - default: - throw new NotImplementedException( - $"The pixel format {pixelFormat} is not implemented."); - } - } - - internal static PixelFormat GetPixelFormat(this System.Drawing.Imaging.PixelFormat pixelFormat) - { - switch (pixelFormat) - { - case System.Drawing.Imaging.PixelFormat.Format4bppIndexed: - return PixelFormat.Indexed4; - case System.Drawing.Imaging.PixelFormat.Format8bppIndexed: - return PixelFormat.Indexed8; - case System.Drawing.Imaging.PixelFormat.Format24bppRgb: - return PixelFormat.Rgb888; - case System.Drawing.Imaging.PixelFormat.Format16bppArgb1555: - return PixelFormat.Rgba1555; - case System.Drawing.Imaging.PixelFormat.Format32bppArgb: - return PixelFormat.Rgba8888; - case System.Drawing.Imaging.PixelFormat.Format32bppRgb: - return PixelFormat.Rgbx8888; - default: - throw new NotImplementedException( - $"The pixel format {pixelFormat} is not implemented."); - } - } - } -} +using System; + +namespace OpenKh.Imaging +{ + public static class PixelFormatExtensions + { + internal static System.Drawing.Imaging.PixelFormat GetDrawingPixelFormat(this PixelFormat pixelFormat) + { + switch (pixelFormat) + { + case PixelFormat.Indexed4: + return System.Drawing.Imaging.PixelFormat.Format4bppIndexed; + case PixelFormat.Indexed8: + return System.Drawing.Imaging.PixelFormat.Format8bppIndexed; + case PixelFormat.Rgba1555: + return System.Drawing.Imaging.PixelFormat.Format32bppArgb; + case PixelFormat.Rgb888: + return System.Drawing.Imaging.PixelFormat.Format24bppRgb; + case PixelFormat.Rgbx8888: + return System.Drawing.Imaging.PixelFormat.Format32bppRgb; + case PixelFormat.Rgba8888: + return System.Drawing.Imaging.PixelFormat.Format32bppArgb; + default: + throw new NotImplementedException( + $"The pixel format {pixelFormat} is not implemented."); + } + } + + internal static PixelFormat GetPixelFormat(this System.Drawing.Imaging.PixelFormat pixelFormat) + { + switch (pixelFormat) + { + case System.Drawing.Imaging.PixelFormat.Format4bppIndexed: + return PixelFormat.Indexed4; + case System.Drawing.Imaging.PixelFormat.Format8bppIndexed: + return PixelFormat.Indexed8; + case System.Drawing.Imaging.PixelFormat.Format24bppRgb: + return PixelFormat.Rgb888; + case System.Drawing.Imaging.PixelFormat.Format16bppArgb1555: + return PixelFormat.Rgba1555; + case System.Drawing.Imaging.PixelFormat.Format32bppArgb: + return PixelFormat.Rgba8888; + case System.Drawing.Imaging.PixelFormat.Format32bppRgb: + return PixelFormat.Rgbx8888; + default: + throw new NotImplementedException( + $"The pixel format {pixelFormat} is not implemented."); + } + } + } +} diff --git a/OpenKh.Tools.Common/Kh2Utilities.cs b/OpenKh.Tools.Common/Kh2Utilities.cs index 18ff205fb..57e0fc87d 100644 --- a/OpenKh.Tools.Common/Kh2Utilities.cs +++ b/OpenKh.Tools.Common/Kh2Utilities.cs @@ -1,84 +1,86 @@ -using OpenKh.Kh2; -using OpenKh.Common; -using OpenKh.Common.Exceptions; -using System.Collections.Generic; -using System.IO; -using Xe.Tools.Wpf.Dialogs; -using System.Linq; -using System; - -namespace OpenKh.Tools.Common -{ - public class Kh2Utilities - { - private static readonly List IdxFilter = FileDialogFilterComposer.Compose() - .AddExtensions("KH2.IDX", "idx").AddAllFiles(); - - private static readonly List MsgFilter = FileDialogFilterComposer.Compose() - .AddExtensions("sys.bar", "bar", "msg", "bin").AddAllFiles(); - - public static bool? OpenMsgFromIdxDialog(Action> onSuccess) => - FileDialog.OnOpen(fileName => onSuccess(ReadMsgFromIdx(fileName)), IdxFilter); - - public static bool? OpenMsgFromBarDialog(Action> onSuccess) => - FileDialog.OnOpen(fileName => onSuccess(File.OpenRead(fileName).Using(ReadMsg)), MsgFilter); - - public static List ReadMsgFromIdx(string fileName) => File.OpenRead(fileName).Using(stream => - { - if (!Idx.IsValid(stream)) - throw new InvalidFileException(typeof(Idx)); - - var imgFileName = $"{Path.GetFileNameWithoutExtension(fileName)}.img"; - var imgFilePath = Path.Combine(Path.GetDirectoryName(fileName), imgFileName); - - if (!File.Exists(imgFilePath)) - throw new FileNotFoundException($"Unable to find {imgFileName} in the same directory of the IDX."); - - return File.OpenRead(imgFilePath).Using(imgStream => ReadMsgFromIdx(stream, imgStream)); - }); - - public static List ReadMsgFromIdx(Stream idxStream, Stream imgStream) - { - var img = new Img(imgStream, Idx.Read(idxStream), false); - foreach (var language in Constants.Regions) - { - var stream = img.FileOpen($"msg/{language}/sys.bar"); - if (stream != null) - return ReadMsgFromBar(stream); - } - - throw new FileNotFoundException($"Unable to find a 'sys.bar' between the supported languages."); - } - - public static List ReadMsg(Stream stream) - { - if (Bar.IsValid(stream)) return ReadMsgFromBar(stream); - else if (Msg.IsValid(stream)) return ReadMsgFromRawMsg(stream); - - throw new InvalidFileException(); - } - - public static List ReadMsgFromBar(Stream stream) - { - if (!Bar.IsValid(stream)) - throw new InvalidFileException(typeof(Bar)); - - var entries = Bar.Read(stream); - var entry = entries - .FirstOrDefault(x => x.Type == Bar.EntryType.List && x.Name == "sys"); - - if (entry == null) - throw new InvalidFileException(); - - return ReadMsgFromRawMsg(entry.Stream); - } - - public static List ReadMsgFromRawMsg(Stream stream) - { - if (!Msg.IsValid(stream)) - throw new InvalidFileException(); - - return Msg.Read(stream); - } - } -} +using OpenKh.Kh2; +using OpenKh.Common; +using OpenKh.Common.Exceptions; +using System.Collections.Generic; +using System.IO; +using Xe.Tools.Wpf.Dialogs; +using System.Linq; +using System; + +namespace OpenKh.Tools.Common +{ + public class Kh2Utilities + { + private static readonly List IdxFilter = FileDialogFilterComposer.Compose() + .AddExtensions("KH2.IDX", "idx").AddAllFiles(); + + private static readonly List MsgFilter = FileDialogFilterComposer.Compose() + .AddExtensions("sys.bar", "bar", "msg", "bin").AddAllFiles(); + + public static bool? OpenMsgFromIdxDialog(Action> onSuccess) => + FileDialog.OnOpen(fileName => onSuccess(ReadMsgFromIdx(fileName)), IdxFilter); + + public static bool? OpenMsgFromBarDialog(Action> onSuccess) => + FileDialog.OnOpen(fileName => onSuccess(File.OpenRead(fileName).Using(ReadMsg)), MsgFilter); + + public static List ReadMsgFromIdx(string fileName) => File.OpenRead(fileName).Using(stream => + { + if (!Idx.IsValid(stream)) + throw new InvalidFileException(typeof(Idx)); + + var imgFileName = $"{Path.GetFileNameWithoutExtension(fileName)}.img"; + var imgFilePath = Path.Combine(Path.GetDirectoryName(fileName), imgFileName); + + if (!File.Exists(imgFilePath)) + throw new FileNotFoundException($"Unable to find {imgFileName} in the same directory of the IDX."); + + return File.OpenRead(imgFilePath).Using(imgStream => ReadMsgFromIdx(stream, imgStream)); + }); + + public static List ReadMsgFromIdx(Stream idxStream, Stream imgStream) + { + var img = new Img(imgStream, Idx.Read(idxStream), false); + foreach (var language in Constants.Regions) + { + var stream = img.FileOpen($"msg/{language}/sys.bar"); + if (stream != null) + return ReadMsgFromBar(stream); + } + + throw new FileNotFoundException($"Unable to find a 'sys.bar' between the supported languages."); + } + + public static List ReadMsg(Stream stream) + { + if (Bar.IsValid(stream)) + return ReadMsgFromBar(stream); + else if (Msg.IsValid(stream)) + return ReadMsgFromRawMsg(stream); + + throw new InvalidFileException(); + } + + public static List ReadMsgFromBar(Stream stream) + { + if (!Bar.IsValid(stream)) + throw new InvalidFileException(typeof(Bar)); + + var entries = Bar.Read(stream); + var entry = entries + .FirstOrDefault(x => x.Type == Bar.EntryType.List && x.Name == "sys"); + + if (entry == null) + throw new InvalidFileException(); + + return ReadMsgFromRawMsg(entry.Stream); + } + + public static List ReadMsgFromRawMsg(Stream stream) + { + if (!Msg.IsValid(stream)) + throw new InvalidFileException(); + + return Msg.Read(stream); + } + } +} diff --git a/OpenKh.Tools.Common/MessageDialog.xaml.cs b/OpenKh.Tools.Common/MessageDialog.xaml.cs index 07edd893f..a36023e70 100644 --- a/OpenKh.Tools.Common/MessageDialog.xaml.cs +++ b/OpenKh.Tools.Common/MessageDialog.xaml.cs @@ -1,104 +1,104 @@ -using OpenKh.Common; -using System; -using System.ComponentModel; -using System.Diagnostics; -using System.Runtime.CompilerServices; -using System.Windows; -using System.Windows.Input; -using System.Windows.Media.Animation; -using System.Windows.Navigation; - -namespace OpenKh.Tools.Common -{ - /// - /// Interaction logic for MessageDialog.xaml - /// - public partial class MessageDialog : Window, INotifyPropertyChanged - { - private string message; - private string website1; - private string website2; - private string website3; - - public MessageDialog(string msginp, string lnk1 = null, string lnk2 = null, string lnk3 = null) - { - InitializeComponent(); - - message = msginp; - - website1 = lnk1; - website2 = lnk2; - website3 = lnk3; - - if (lnk1 == null) - webBox1.Visibility = Visibility.Collapsed; - if (lnk2 == null) - webBox2.Visibility = Visibility.Collapsed; - if (lnk3 == null) - webBox3.Visibility = Visibility.Collapsed; - - if (lnk1 == null && lnk2 == null && lnk3 == null) - webSep.Visibility = Visibility.Collapsed; - - DataContext = this; - MouseDown += (o, e) => - { - if (e.ChangedButton == MouseButton.Left) - DragMove(); - }; - } - - public event PropertyChangedEventHandler PropertyChanged; - - public string Message - { - get => message; - set => message = OnPropertyChanged(value); - } - - public string Website1 - { - get => website1; - set => website1 = OnPropertyChanged(value); - } - - public string Website2 - { - get => website2; - set => website2 = OnPropertyChanged(value); - } - - public string Website3 - { - get => website3; - set => website3 = OnPropertyChanged(value); - } - - private T OnPropertyChanged(T obj, [CallerMemberName] string propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - return obj; - } - - private void Window_Loaded(object sender, RoutedEventArgs e) - { - BeginAnimation(OpacityProperty, new DoubleAnimation() - { - From = 0.0, - To = 1.0, - EasingFunction = new CubicEase(), - Duration = new Duration(TimeSpan.FromSeconds(0.5)) - }); - } - - private void NavigateURL(object sender, RequestNavigateEventArgs e) => - new Process() - { - StartInfo = new ProcessStartInfo - { - UseShellExecute = true, - FileName = e.Uri.AbsoluteUri - } - }.Using(x => x.Start()); - } -} +using OpenKh.Common; +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Windows; +using System.Windows.Input; +using System.Windows.Media.Animation; +using System.Windows.Navigation; + +namespace OpenKh.Tools.Common +{ + /// + /// Interaction logic for MessageDialog.xaml + /// + public partial class MessageDialog : Window, INotifyPropertyChanged + { + private string message; + private string website1; + private string website2; + private string website3; + + public MessageDialog(string msginp, string lnk1 = null, string lnk2 = null, string lnk3 = null) + { + InitializeComponent(); + + message = msginp; + + website1 = lnk1; + website2 = lnk2; + website3 = lnk3; + + if (lnk1 == null) + webBox1.Visibility = Visibility.Collapsed; + if (lnk2 == null) + webBox2.Visibility = Visibility.Collapsed; + if (lnk3 == null) + webBox3.Visibility = Visibility.Collapsed; + + if (lnk1 == null && lnk2 == null && lnk3 == null) + webSep.Visibility = Visibility.Collapsed; + + DataContext = this; + MouseDown += (o, e) => + { + if (e.ChangedButton == MouseButton.Left) + DragMove(); + }; + } + + public event PropertyChangedEventHandler PropertyChanged; + + public string Message + { + get => message; + set => message = OnPropertyChanged(value); + } + + public string Website1 + { + get => website1; + set => website1 = OnPropertyChanged(value); + } + + public string Website2 + { + get => website2; + set => website2 = OnPropertyChanged(value); + } + + public string Website3 + { + get => website3; + set => website3 = OnPropertyChanged(value); + } + + private T OnPropertyChanged(T obj, [CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + return obj; + } + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + BeginAnimation(OpacityProperty, new DoubleAnimation() + { + From = 0.0, + To = 1.0, + EasingFunction = new CubicEase(), + Duration = new Duration(TimeSpan.FromSeconds(0.5)) + }); + } + + private void NavigateURL(object sender, RequestNavigateEventArgs e) => + new Process() + { + StartInfo = new ProcessStartInfo + { + UseShellExecute = true, + FileName = e.Uri.AbsoluteUri + } + }.Using(x => x.Start()); + } +} diff --git a/OpenKh.Tools.Common/Models/Kh2WorldsList.cs b/OpenKh.Tools.Common/Models/Kh2WorldsList.cs index 31b2c487d..af8983979 100644 --- a/OpenKh.Tools.Common/Models/Kh2WorldsList.cs +++ b/OpenKh.Tools.Common/Models/Kh2WorldsList.cs @@ -1,24 +1,24 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Xe.Tools.Models; -using OpenKh.Kh2; - -namespace OpenKh.Tools.Common.Models -{ - public class Kh2WorldsList : IEnumerable>, IEnumerable - { - private static List> _list = Enum.GetValues(typeof(World)) - .Cast() - .Select(e => new EnumItemModel() - { - Value = e, - Name = Constants.WorldNames[(int)e] - }) - .ToList(); - - public IEnumerator> GetEnumerator() => _list.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator(); - } -} +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Xe.Tools.Models; +using OpenKh.Kh2; + +namespace OpenKh.Tools.Common.Models +{ + public class Kh2WorldsList : IEnumerable>, IEnumerable + { + private static List> _list = Enum.GetValues(typeof(World)) + .Cast() + .Select(e => new EnumItemModel() + { + Value = e, + Name = Constants.WorldNames[(int)e] + }) + .ToList(); + + public IEnumerator> GetEnumerator() => _list.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator(); + } +} diff --git a/OpenKh.Tools.Common/Models/MyGenericListModel.cs b/OpenKh.Tools.Common/Models/MyGenericListModel.cs index c9b20f7e2..ef9aa5058 100644 --- a/OpenKh.Tools.Common/Models/MyGenericListModel.cs +++ b/OpenKh.Tools.Common/Models/MyGenericListModel.cs @@ -1,16 +1,16 @@ -using System.Collections; -using System.Collections.Generic; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.Common.Models -{ - public class MyGenericListModel : GenericListModel, IEnumerable - { - public MyGenericListModel(IEnumerable list) : base(list) - { - } - - IEnumerator IEnumerable.GetEnumerator() => Items.GetEnumerator(); - protected override T OnNewItem() => throw new System.NotImplementedException(); - } -} +using System.Collections; +using System.Collections.Generic; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.Common.Models +{ + public class MyGenericListModel : GenericListModel, IEnumerable + { + public MyGenericListModel(IEnumerable list) : base(list) + { + } + + IEnumerator IEnumerable.GetEnumerator() => Items.GetEnumerator(); + protected override T OnNewItem() => throw new System.NotImplementedException(); + } +} diff --git a/OpenKh.Tools.Common/ProcessStream.cs b/OpenKh.Tools.Common/ProcessStream.cs index 68ea526cc..ba6693058 100644 --- a/OpenKh.Tools.Common/ProcessStream.cs +++ b/OpenKh.Tools.Common/ProcessStream.cs @@ -1,150 +1,150 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; - -namespace OpenKh.Tools.Common -{ - public class ProcessStream : Stream - { - [DllImport("kernel32.dll")] - private static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId); - - [DllImport("kernel32.dll")] - private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out int BytesRead); - - [DllImport("kernel32.dll")] - static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int dwSize, out int lpNumberOfBytesWritten); - - - [DllImport("kernel32.dll")] - static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect); - - private Process _process; - private IntPtr _hProcess; - private long position; - - public ProcessStream(Process process, uint baseAddress, uint length) - { - OpenProcess(process); - BaseAddress = baseAddress; - Length = length; - } - - - public uint BaseAddress { get; } - public override bool CanRead => true; - - public override bool CanSeek => true; - - public override bool CanWrite => true; - - public override long Length { get; } - - public override long Position - { - get => position; - set => position = value; - } - - public override void Flush() - { - } - - public override int Read(byte[] buffer, int offset, int count) - { - int read; - var pos = (IntPtr)(BaseAddress + Position); - - if (offset == 0) - { - ReadProcessMemory(_hProcess, pos, buffer, count, out read); - } - else - { - byte[] data = new byte[count]; - ReadProcessMemory(_hProcess, pos, buffer, count, out read); - Array.Copy(data, 0, buffer, offset, read); - } - - Position += read; - - return read; - } - - public override long Seek(long offset, SeekOrigin origin) - { - switch (origin) - { - case SeekOrigin.Begin: - return Position = offset; - case SeekOrigin.Current: - return Position += offset; - case SeekOrigin.End: - return Position = Length + offset; - default: - return Position; - } - } - - public override void SetLength(long value) - { - } - - public override void Write(byte[] buffer, int offset, int count) - { - var pos = (IntPtr)(BaseAddress + Position); - - int written; - if (offset == 0) - { - WriteProcessMemory(_hProcess, pos, buffer, count, out written); - } - else - { - var data = new byte[count]; - Array.Copy(buffer, offset, data, 0, count); - WriteProcessMemory(_hProcess, pos, data, count, out written); - } - - Position += written; - } - - private void OpenProcess(Process process) - { - const int permissions = 0x001FFFFF; - _hProcess = OpenProcess(permissions, true, process.Id); - _process = process; - - var pos = (IntPtr)(BaseAddress + Position); - VirtualProtectEx(_hProcess, pos, (UIntPtr)Length, 0xFF, out var old); - } - - public static IEnumerable GetProcesses() => - Process.GetProcesses(); - - public static Process TryGetProcess(Func predicate, int timeout = 10000, int sleep = 100) - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - do - { - var process = GetProcesses().FirstOrDefault(predicate); - if (process != null) - return process; - - Thread.Sleep(sleep); - } while (stopwatch.ElapsedMilliseconds < timeout); - - return null; - } - - public static Task TryGetProcessAsync(Func predicate, int timeout = 10000, int sleep = 100) => - Task.Run(() => TryGetProcess(predicate, timeout, sleep)); - } -} \ No newline at end of file +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; + +namespace OpenKh.Tools.Common +{ + public class ProcessStream : Stream + { + [DllImport("kernel32.dll")] + private static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId); + + [DllImport("kernel32.dll")] + private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out int BytesRead); + + [DllImport("kernel32.dll")] + static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int dwSize, out int lpNumberOfBytesWritten); + + + [DllImport("kernel32.dll")] + static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect); + + private Process _process; + private IntPtr _hProcess; + private long position; + + public ProcessStream(Process process, uint baseAddress, uint length) + { + OpenProcess(process); + BaseAddress = baseAddress; + Length = length; + } + + + public uint BaseAddress { get; } + public override bool CanRead => true; + + public override bool CanSeek => true; + + public override bool CanWrite => true; + + public override long Length { get; } + + public override long Position + { + get => position; + set => position = value; + } + + public override void Flush() + { + } + + public override int Read(byte[] buffer, int offset, int count) + { + int read; + var pos = (IntPtr)(BaseAddress + Position); + + if (offset == 0) + { + ReadProcessMemory(_hProcess, pos, buffer, count, out read); + } + else + { + byte[] data = new byte[count]; + ReadProcessMemory(_hProcess, pos, buffer, count, out read); + Array.Copy(data, 0, buffer, offset, read); + } + + Position += read; + + return read; + } + + public override long Seek(long offset, SeekOrigin origin) + { + switch (origin) + { + case SeekOrigin.Begin: + return Position = offset; + case SeekOrigin.Current: + return Position += offset; + case SeekOrigin.End: + return Position = Length + offset; + default: + return Position; + } + } + + public override void SetLength(long value) + { + } + + public override void Write(byte[] buffer, int offset, int count) + { + var pos = (IntPtr)(BaseAddress + Position); + + int written; + if (offset == 0) + { + WriteProcessMemory(_hProcess, pos, buffer, count, out written); + } + else + { + var data = new byte[count]; + Array.Copy(buffer, offset, data, 0, count); + WriteProcessMemory(_hProcess, pos, data, count, out written); + } + + Position += written; + } + + private void OpenProcess(Process process) + { + const int permissions = 0x001FFFFF; + _hProcess = OpenProcess(permissions, true, process.Id); + _process = process; + + var pos = (IntPtr)(BaseAddress + Position); + VirtualProtectEx(_hProcess, pos, (UIntPtr)Length, 0xFF, out var old); + } + + public static IEnumerable GetProcesses() => + Process.GetProcesses(); + + public static Process TryGetProcess(Func predicate, int timeout = 10000, int sleep = 100) + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + do + { + var process = GetProcesses().FirstOrDefault(predicate); + if (process != null) + return process; + + Thread.Sleep(sleep); + } while (stopwatch.ElapsedMilliseconds < timeout); + + return null; + } + + public static Task TryGetProcessAsync(Func predicate, int timeout = 10000, int sleep = 100) => + Task.Run(() => TryGetProcess(predicate, timeout, sleep)); + } +} diff --git a/OpenKh.Tools.Common/RelayCommand.cs b/OpenKh.Tools.Common/RelayCommand.cs index 951f75b33..ac203eb5c 100644 --- a/OpenKh.Tools.Common/RelayCommand.cs +++ b/OpenKh.Tools.Common/RelayCommand.cs @@ -1,28 +1,28 @@ -using System; -using Xe.Tools.Wpf.Commands; - -namespace OpenKh.Tools.Common -{ - public class RelayCommand : RelayCommand - { - public RelayCommand(Action execute, - Func canExecute = null, - Action undo = null) : - base(x => execute((T)x), CanExecute(canExecute), Undo(undo)) - { } - - private static Func CanExecute(Func canExecute) - { - if (canExecute == null) - return null; - return x => canExecute((T)x); - } - - private static Action Undo(Action undo) - { - if (undo == null) - return null; - return x => undo((T)x); - } - } -} +using System; +using Xe.Tools.Wpf.Commands; + +namespace OpenKh.Tools.Common +{ + public class RelayCommand : RelayCommand + { + public RelayCommand(Action execute, + Func canExecute = null, + Action undo = null) : + base(x => execute((T)x), CanExecute(canExecute), Undo(undo)) + { } + + private static Func CanExecute(Func canExecute) + { + if (canExecute == null) + return null; + return x => canExecute((T)x); + } + + private static Action Undo(Action undo) + { + if (undo == null) + return null; + return x => undo((T)x); + } + } +} diff --git a/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Context.cs b/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Context.cs index 3eb3224b8..c79eb2bb5 100644 --- a/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Context.cs +++ b/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Context.cs @@ -1,262 +1,262 @@ -// MIT License -// -// Copyright(c) 2017 Luciano (Xeeynamo) Ciccariello -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -// Part of this software belongs to XeEngine toolset and United Lines Studio -// and it is currently used to create commercial games by Luciano Ciccariello. -// Please do not redistribuite this code under your own name, stole it or use -// it artfully, but instead support it and its author. Thank you. - -// Took from Xe.Drawing.Direct3D and transported to OpenKH under the same developer - -using OpenKh.Engine.Renders; -using SharpDX.D3DCompiler; -using SharpDX.Direct3D; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; - -namespace OpenKh.Tools.Common.Rendering -{ - using d3d = SharpDX.Direct3D11; - using dxgi = SharpDX.DXGI; - - public partial class SpriteDrawingDirect3D - { - private static readonly byte[] WhiteBitmap = Enumerable.Range(0, 2 * 2 * sizeof(int)).Select(x => byte.MaxValue).ToArray(); - - private readonly CDevice _device; - private readonly ISpriteTexture _defaultTexture; - - public SpriteDrawingDirect3D() - { - _device = new CDevice(); - _defaultTexture = CreateSpriteTexture(2, 2, WhiteBitmap); - } - - public d3d.Device1 Device => _device.Device; - public d3d.DeviceContext1 Context => _device.Context; - - private class CDevice : IDisposable - { - private static readonly d3d.InputElement[] InputElements = new d3d.InputElement[] - { - new d3d.InputElement("POSITION", 0, dxgi.Format.R32G32_Float, sizeof(float) * 0, 0, d3d.InputClassification.PerVertexData, 0), - new d3d.InputElement("TEXTURE", 0, dxgi.Format.R32G32_Float, sizeof(float) * 2, 0, d3d.InputClassification.PerVertexData, 0 ), - new d3d.InputElement("COLOR", 0, dxgi.Format.R32G32B32A32_Float, sizeof(float) * 4, 0, d3d.InputClassification.PerVertexData, 0 ), - }; - - private List _disposables = new List(); - - private d3d.Device d3dDevice; - private dxgi.Device dxgiDevice; - private dxgi.Device1 dxgiDevice1; - private dxgi.Adapter dxgiAdapter; - private dxgi.Factory dxgiFactory; - - private ShaderSignature inputSignature; - private d3d.VertexShader vertexShader; - private d3d.PixelShader pixelShader; - private d3d.InputLayout inputLayout; - - public d3d.Device1 Device { get; } - public d3d.DeviceContext1 Context => Device.ImmediateContext1; - - internal CDevice() - { - var flags = d3d.DeviceCreationFlags.BgraSupport; - - d3dDevice = new d3d.Device(DriverType.Hardware, flags); - Device = d3dDevice.QueryInterface(); - dxgiDevice = d3dDevice.QueryInterface(); - dxgiDevice1 = dxgiDevice.QueryInterface(); - dxgiAdapter = dxgiDevice.Adapter.QueryInterface(); - dxgiFactory = dxgiAdapter.GetParent(); - - CreateResources(); - } - - private void CreateResources() - { - //CreateDepthStencilState(); - CreateRasterizer(); - CreateBlend(); - CreateSamplers(); - //CreateWindowSizeDependentResources(new Size(1024, 1024)); - InitializeShaders(); - } - - private void CreateWindowSizeDependentResources(Size size) - { - var desc = new dxgi.SwapChainDescription - { - Usage = dxgi.Usage.RenderTargetOutput | dxgi.Usage.BackBuffer, - BufferCount = 2, - IsWindowed = true, - SwapEffect = dxgi.SwapEffect.Discard, - Flags = dxgi.SwapChainFlags.None - }; - - desc.ModeDescription.Width = size.Width; - desc.ModeDescription.Height = size.Height; - desc.ModeDescription.Format = dxgi.Format.R8G8B8A8_UNorm; - desc.ModeDescription.Scaling = dxgi.DisplayModeScaling.Stretched; - desc.ModeDescription.RefreshRate.Numerator = 0; - desc.ModeDescription.RefreshRate.Denominator = 0; - desc.ModeDescription.ScanlineOrdering = dxgi.DisplayModeScanlineOrder.Unspecified; - desc.SampleDescription.Count = 1; - desc.SampleDescription.Quality = 0; - - //_swapChain = new dxgi.SwapChain(dxgiFactory, d3dDevice, desc); - } - - private void CreateDepthStencilState() - { - var desc = new d3d.DepthStencilStateDescription - { - IsDepthEnabled = true, - DepthWriteMask = d3d.DepthWriteMask.All, - DepthComparison = d3d.Comparison.GreaterEqual, - IsStencilEnabled = false, - StencilReadMask = 0, - StencilWriteMask = 0 - }; - desc.FrontFace.FailOperation = d3d.StencilOperation.Keep; - desc.FrontFace.DepthFailOperation = d3d.StencilOperation.Keep; - desc.FrontFace.PassOperation = d3d.StencilOperation.Keep; - desc.FrontFace.Comparison = d3d.Comparison.Never; - desc.BackFace.FailOperation = d3d.StencilOperation.Keep; - desc.BackFace.DepthFailOperation = d3d.StencilOperation.Keep; - desc.BackFace.PassOperation = d3d.StencilOperation.Keep; - desc.BackFace.Comparison = d3d.Comparison.Never; - - var depthStencilState = new d3d.DepthStencilState(Device, desc); - _disposables.Add(depthStencilState); - Context.OutputMerger.DepthStencilState = depthStencilState; - } - - private void CreateRasterizer() - { - var desc = new d3d.RasterizerStateDescription() - { - FillMode = d3d.FillMode.Solid, - CullMode = d3d.CullMode.None, - IsFrontCounterClockwise = false, - IsDepthClipEnabled = true, - IsScissorEnabled = false - }; - - var rasterizerState = new d3d.RasterizerState(Device, desc); - _disposables.Add(rasterizerState); - Context.Rasterizer.State = rasterizerState; - } - - private void CreateBlend() - { - var desc = new d3d.BlendStateDescription() - { - AlphaToCoverageEnable = false, - IndependentBlendEnable = false - }; - SetRenderTargetlendProperties(ref desc.RenderTarget[0]); - - var blendState = new d3d.BlendState(Device, desc); - _disposables.Add(blendState); - Context.OutputMerger.BlendState = blendState; - } - - private void CreateSamplers() - { - var desc = new d3d.SamplerStateDescription() - { - Filter = d3d.Filter.MinMagMipPoint, - AddressU = d3d.TextureAddressMode.Clamp, - AddressV = d3d.TextureAddressMode.Clamp, - AddressW = d3d.TextureAddressMode.Clamp, - MipLodBias = 0.0f, - MaximumAnisotropy = 1, - ComparisonFunction = d3d.Comparison.Never, - BorderColor = new SharpDX.Mathematics.Interop.RawColor4(1.0f, 1.0f, 1.0f, 1.0f), - MinimumLod = -3.402823466e+38F, - MaximumLod = +3.402823466e+38F - }; - - var sampler = new d3d.SamplerState(Device, desc); - Context.PixelShader.SetSampler(0, sampler); - _disposables.Add(sampler); - } - - private void SetRenderTargetlendProperties(ref d3d.RenderTargetBlendDescription desc) - { - desc.IsBlendEnabled = true; - desc.SourceBlend = d3d.BlendOption.SourceAlpha; - desc.DestinationBlend = d3d.BlendOption.InverseSourceAlpha; - desc.BlendOperation = d3d.BlendOperation.Add; - desc.SourceAlphaBlend = d3d.BlendOption.SourceAlpha; - desc.DestinationAlphaBlend = d3d.BlendOption.DestinationAlpha; - desc.AlphaBlendOperation = d3d.BlendOperation.Add; - desc.RenderTargetWriteMask = d3d.ColorWriteMaskFlags.All; - } - - - private void InitializeShaders() - { - using (var vertexShaderByteCode = ShaderBytecode.Compile(VS, "main", "vs_4_0", ShaderFlags.Debug)) - { - vertexShader = new d3d.VertexShader(Device, vertexShaderByteCode); - inputSignature = ShaderSignature.GetInputSignature(vertexShaderByteCode); - Context.VertexShader.Set(vertexShader); - _disposables.Add(vertexShader); - } - using (var pixelShaderByteCode = ShaderBytecode.Compile(PS, "main", "ps_4_0", ShaderFlags.Debug)) - { - pixelShader = new d3d.PixelShader(Device, pixelShaderByteCode); - Context.PixelShader.Set(pixelShader); - _disposables.Add(pixelShader); - } - - Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; - inputLayout = new d3d.InputLayout(d3dDevice, inputSignature, InputElements); - Context.InputAssembler.InputLayout = inputLayout; - } - - private string GetBytecodeShader(string shaderSource) - { - using (var byteCode = ShaderBytecode.Compile(VS, "main", "vs_4_0", ShaderFlags.OptimizationLevel3)) - { - return string.Join(",", byteCode.Bytecode.Data.Select(x => $"{x.ToString("X02")}")); - } - } - public void Dispose() - { - foreach (var disposable in _disposables) - disposable.Dispose(); - dxgiFactory.Dispose(); - dxgiAdapter.Dispose(); - dxgiDevice1.Dispose(); - dxgiDevice.Dispose(); - Device.Dispose(); - d3dDevice.Dispose(); - } - } - } -} +// MIT License +// +// Copyright(c) 2017 Luciano (Xeeynamo) Ciccariello +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// Part of this software belongs to XeEngine toolset and United Lines Studio +// and it is currently used to create commercial games by Luciano Ciccariello. +// Please do not redistribuite this code under your own name, stole it or use +// it artfully, but instead support it and its author. Thank you. + +// Took from Xe.Drawing.Direct3D and transported to OpenKH under the same developer + +using OpenKh.Engine.Renders; +using SharpDX.D3DCompiler; +using SharpDX.Direct3D; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; + +namespace OpenKh.Tools.Common.Rendering +{ + using d3d = SharpDX.Direct3D11; + using dxgi = SharpDX.DXGI; + + public partial class SpriteDrawingDirect3D + { + private static readonly byte[] WhiteBitmap = Enumerable.Range(0, 2 * 2 * sizeof(int)).Select(x => byte.MaxValue).ToArray(); + + private readonly CDevice _device; + private readonly ISpriteTexture _defaultTexture; + + public SpriteDrawingDirect3D() + { + _device = new CDevice(); + _defaultTexture = CreateSpriteTexture(2, 2, WhiteBitmap); + } + + public d3d.Device1 Device => _device.Device; + public d3d.DeviceContext1 Context => _device.Context; + + private class CDevice : IDisposable + { + private static readonly d3d.InputElement[] InputElements = new d3d.InputElement[] + { + new d3d.InputElement("POSITION", 0, dxgi.Format.R32G32_Float, sizeof(float) * 0, 0, d3d.InputClassification.PerVertexData, 0), + new d3d.InputElement("TEXTURE", 0, dxgi.Format.R32G32_Float, sizeof(float) * 2, 0, d3d.InputClassification.PerVertexData, 0 ), + new d3d.InputElement("COLOR", 0, dxgi.Format.R32G32B32A32_Float, sizeof(float) * 4, 0, d3d.InputClassification.PerVertexData, 0 ), + }; + + private List _disposables = new List(); + + private d3d.Device d3dDevice; + private dxgi.Device dxgiDevice; + private dxgi.Device1 dxgiDevice1; + private dxgi.Adapter dxgiAdapter; + private dxgi.Factory dxgiFactory; + + private ShaderSignature inputSignature; + private d3d.VertexShader vertexShader; + private d3d.PixelShader pixelShader; + private d3d.InputLayout inputLayout; + + public d3d.Device1 Device { get; } + public d3d.DeviceContext1 Context => Device.ImmediateContext1; + + internal CDevice() + { + var flags = d3d.DeviceCreationFlags.BgraSupport; + + d3dDevice = new d3d.Device(DriverType.Hardware, flags); + Device = d3dDevice.QueryInterface(); + dxgiDevice = d3dDevice.QueryInterface(); + dxgiDevice1 = dxgiDevice.QueryInterface(); + dxgiAdapter = dxgiDevice.Adapter.QueryInterface(); + dxgiFactory = dxgiAdapter.GetParent(); + + CreateResources(); + } + + private void CreateResources() + { + //CreateDepthStencilState(); + CreateRasterizer(); + CreateBlend(); + CreateSamplers(); + //CreateWindowSizeDependentResources(new Size(1024, 1024)); + InitializeShaders(); + } + + private void CreateWindowSizeDependentResources(Size size) + { + var desc = new dxgi.SwapChainDescription + { + Usage = dxgi.Usage.RenderTargetOutput | dxgi.Usage.BackBuffer, + BufferCount = 2, + IsWindowed = true, + SwapEffect = dxgi.SwapEffect.Discard, + Flags = dxgi.SwapChainFlags.None + }; + + desc.ModeDescription.Width = size.Width; + desc.ModeDescription.Height = size.Height; + desc.ModeDescription.Format = dxgi.Format.R8G8B8A8_UNorm; + desc.ModeDescription.Scaling = dxgi.DisplayModeScaling.Stretched; + desc.ModeDescription.RefreshRate.Numerator = 0; + desc.ModeDescription.RefreshRate.Denominator = 0; + desc.ModeDescription.ScanlineOrdering = dxgi.DisplayModeScanlineOrder.Unspecified; + desc.SampleDescription.Count = 1; + desc.SampleDescription.Quality = 0; + + //_swapChain = new dxgi.SwapChain(dxgiFactory, d3dDevice, desc); + } + + private void CreateDepthStencilState() + { + var desc = new d3d.DepthStencilStateDescription + { + IsDepthEnabled = true, + DepthWriteMask = d3d.DepthWriteMask.All, + DepthComparison = d3d.Comparison.GreaterEqual, + IsStencilEnabled = false, + StencilReadMask = 0, + StencilWriteMask = 0 + }; + desc.FrontFace.FailOperation = d3d.StencilOperation.Keep; + desc.FrontFace.DepthFailOperation = d3d.StencilOperation.Keep; + desc.FrontFace.PassOperation = d3d.StencilOperation.Keep; + desc.FrontFace.Comparison = d3d.Comparison.Never; + desc.BackFace.FailOperation = d3d.StencilOperation.Keep; + desc.BackFace.DepthFailOperation = d3d.StencilOperation.Keep; + desc.BackFace.PassOperation = d3d.StencilOperation.Keep; + desc.BackFace.Comparison = d3d.Comparison.Never; + + var depthStencilState = new d3d.DepthStencilState(Device, desc); + _disposables.Add(depthStencilState); + Context.OutputMerger.DepthStencilState = depthStencilState; + } + + private void CreateRasterizer() + { + var desc = new d3d.RasterizerStateDescription() + { + FillMode = d3d.FillMode.Solid, + CullMode = d3d.CullMode.None, + IsFrontCounterClockwise = false, + IsDepthClipEnabled = true, + IsScissorEnabled = false + }; + + var rasterizerState = new d3d.RasterizerState(Device, desc); + _disposables.Add(rasterizerState); + Context.Rasterizer.State = rasterizerState; + } + + private void CreateBlend() + { + var desc = new d3d.BlendStateDescription() + { + AlphaToCoverageEnable = false, + IndependentBlendEnable = false + }; + SetRenderTargetlendProperties(ref desc.RenderTarget[0]); + + var blendState = new d3d.BlendState(Device, desc); + _disposables.Add(blendState); + Context.OutputMerger.BlendState = blendState; + } + + private void CreateSamplers() + { + var desc = new d3d.SamplerStateDescription() + { + Filter = d3d.Filter.MinMagMipPoint, + AddressU = d3d.TextureAddressMode.Clamp, + AddressV = d3d.TextureAddressMode.Clamp, + AddressW = d3d.TextureAddressMode.Clamp, + MipLodBias = 0.0f, + MaximumAnisotropy = 1, + ComparisonFunction = d3d.Comparison.Never, + BorderColor = new SharpDX.Mathematics.Interop.RawColor4(1.0f, 1.0f, 1.0f, 1.0f), + MinimumLod = -3.402823466e+38F, + MaximumLod = +3.402823466e+38F + }; + + var sampler = new d3d.SamplerState(Device, desc); + Context.PixelShader.SetSampler(0, sampler); + _disposables.Add(sampler); + } + + private void SetRenderTargetlendProperties(ref d3d.RenderTargetBlendDescription desc) + { + desc.IsBlendEnabled = true; + desc.SourceBlend = d3d.BlendOption.SourceAlpha; + desc.DestinationBlend = d3d.BlendOption.InverseSourceAlpha; + desc.BlendOperation = d3d.BlendOperation.Add; + desc.SourceAlphaBlend = d3d.BlendOption.SourceAlpha; + desc.DestinationAlphaBlend = d3d.BlendOption.DestinationAlpha; + desc.AlphaBlendOperation = d3d.BlendOperation.Add; + desc.RenderTargetWriteMask = d3d.ColorWriteMaskFlags.All; + } + + + private void InitializeShaders() + { + using (var vertexShaderByteCode = ShaderBytecode.Compile(VS, "main", "vs_4_0", ShaderFlags.Debug)) + { + vertexShader = new d3d.VertexShader(Device, vertexShaderByteCode); + inputSignature = ShaderSignature.GetInputSignature(vertexShaderByteCode); + Context.VertexShader.Set(vertexShader); + _disposables.Add(vertexShader); + } + using (var pixelShaderByteCode = ShaderBytecode.Compile(PS, "main", "ps_4_0", ShaderFlags.Debug)) + { + pixelShader = new d3d.PixelShader(Device, pixelShaderByteCode); + Context.PixelShader.Set(pixelShader); + _disposables.Add(pixelShader); + } + + Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; + inputLayout = new d3d.InputLayout(d3dDevice, inputSignature, InputElements); + Context.InputAssembler.InputLayout = inputLayout; + } + + private string GetBytecodeShader(string shaderSource) + { + using (var byteCode = ShaderBytecode.Compile(VS, "main", "vs_4_0", ShaderFlags.OptimizationLevel3)) + { + return string.Join(",", byteCode.Bytecode.Data.Select(x => $"{x.ToString("X02")}")); + } + } + public void Dispose() + { + foreach (var disposable in _disposables) + disposable.Dispose(); + dxgiFactory.Dispose(); + dxgiAdapter.Dispose(); + dxgiDevice1.Dispose(); + dxgiDevice.Dispose(); + Device.Dispose(); + d3dDevice.Dispose(); + } + } + } +} diff --git a/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Drawing.cs b/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Drawing.cs index 5077b3718..da2c47173 100644 --- a/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Drawing.cs +++ b/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Drawing.cs @@ -1,188 +1,188 @@ -// MIT License -// -// Copyright(c) 2017 Luciano (Xeeynamo) Ciccariello -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -// Part of this software belongs to XeEngine toolset and United Lines Studio -// and it is currently used to create commercial games by Luciano Ciccariello. -// Please do not redistribuite this code under your own name, stole it or use -// it artfully, but instead support it and its author. Thank you. - -// Took from Xe.Drawing.Direct3D and transported to OpenKH under the same developer - -namespace OpenKh.Tools.Common.Rendering -{ - using dx = SharpDX; - using d3d = SharpDX.Direct3D11; - using dxgi = SharpDX.DXGI; - using System.Drawing; - using System.Runtime.InteropServices; - using System; - using System.Security; - using OpenKh.Engine.Renders; - - public partial class SpriteDrawingDirect3D : ISpriteDrawing - { - [DllImport("msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false), SuppressUnmanagedCodeSecurity] - public static extern IntPtr CopyMemory(IntPtr dest, IntPtr src, ulong count); - - [StructLayout(LayoutKind.Sequential)] - private struct Vertex - { - public float X, Y; - public float U, V; - public ColorF Color; - } - - public void AppendSprite(SpriteDrawingContext context) - { - SetTextureToDraw(context.SpriteTexture ?? _defaultTexture); - var width = _currentTexture.Width; - var height = _currentTexture.Height; - var viewport = _viewportSize; - var index = RequestVertices(4); - var buffer = _dataBuffer; - - buffer[index++] = new Vertex() - { - X = context.Vec0.X / viewport.Width * +2.0f - 1.0f, - Y = context.Vec0.Y / viewport.Height * -2.0f + 1.0f, - U = (float)context.SourceLeft / width, - V = (float)context.SourceTop / height, - Color = context.Color0 - }; - buffer[index++] = new Vertex() - { - X = context.Vec1.X / viewport.Width * +2.0f - 1.0f, - Y = context.Vec1.Y / viewport.Height * -2.0f + 1.0f, - U = (float)context.SourceRight / width, - V = (float)context.SourceTop / height, - Color = context.Color1 - }; - buffer[index++] = new Vertex() - { - X = context.Vec2.X / viewport.Width * +2.0f - 1.0f, - Y = context.Vec2.Y / viewport.Height * -2.0f + 1.0f, - U = (float)context.SourceLeft / width, - V = (float)context.SourceBottom / height, - Color = context.Color2 - }; - buffer[index++] = new Vertex() - { - X = context.Vec3.X / viewport.Width * +2.0f - 1.0f, - Y = context.Vec3.Y / viewport.Height * -2.0f + 1.0f, - U = (float)context.SourceRight / width, - V = (float)context.SourceBottom / height, - Color = context.Color3 - }; - } - - private CSpriteTexture _currentTexture; - private void SetTextureToDraw(ISpriteTexture texture) - { - if (_currentTexture != texture) - { - Flush(); - - texture ??= _defaultTexture; - var internalTexture = texture as CSpriteTexture; - Context.PixelShader.SetShaderResource(0, internalTexture?.ShaderResourceView); - _currentTexture = internalTexture; - } - } - - private const int MaximumQuadsCount = 65536; - private d3d.Buffer _vertexBuffer; - private d3d.Buffer _indexBuffer; - private Vertex[] _dataBuffer = new Vertex[MaximumQuadsCount]; - private int _pendingVerticesCount; - - private int RequestVertices(int count) - { - if (_pendingVerticesCount + count >= MaximumQuadsCount) - { - Flush(); - } - - var index = _pendingVerticesCount; - _pendingVerticesCount += count; - - return index; - } - - public void Flush() - { - if (_pendingVerticesCount == 0) - return; - - if (_vertexBuffer == null) - { - var vertexBufferDesc = new d3d.BufferDescription() - { - SizeInBytes = MaximumQuadsCount * dx.Utilities.SizeOf(), - Usage = d3d.ResourceUsage.Dynamic, - BindFlags = d3d.BindFlags.VertexBuffer, - CpuAccessFlags = d3d.CpuAccessFlags.Write, - OptionFlags = 0, - StructureByteStride = 0 - }; - _vertexBuffer = d3d.Buffer.Create(Device, _dataBuffer, vertexBufferDesc); - Context.InputAssembler.SetVertexBuffers(0, new d3d.VertexBufferBinding(_vertexBuffer, dx.Utilities.SizeOf(), 0)); - - var indexBufferDesc = new d3d.BufferDescription() - { - SizeInBytes = MaximumQuadsCount * 6 * sizeof(ushort), - Usage = d3d.ResourceUsage.Immutable, - BindFlags = d3d.BindFlags.IndexBuffer, - CpuAccessFlags = d3d.CpuAccessFlags.None, - OptionFlags = 0, - StructureByteStride = 0 - }; - uint[] indices = new uint[MaximumQuadsCount * 6]; - for (uint i = 0, nx = 0x00000000; i < MaximumQuadsCount * 6; nx += 4) - { - indices[i++] = nx + 1; - indices[i++] = nx + 0; - indices[i++] = nx + 2; - indices[i++] = nx + 1; - indices[i++] = nx + 2; - indices[i++] = nx + 3; - } - _indexBuffer = d3d.Buffer.Create(Device, indices, indexBufferDesc); - Context.InputAssembler.SetIndexBuffer(_indexBuffer, dxgi.Format.R32_UInt, 0); - } - else - { - var size = _pendingVerticesCount * dx.Utilities.SizeOf(); - var dataBox = Context.MapSubresource(_vertexBuffer, 0, d3d.MapMode.WriteDiscard, d3d.MapFlags.None); - IntPtr addr = Marshal.UnsafeAddrOfPinnedArrayElement(_dataBuffer, 0); - CopyMemory(dataBox.DataPointer, addr, (ulong)size); - Context.UnmapSubresource(_vertexBuffer, 0); - } - - Context.DrawIndexed(_pendingVerticesCount / 4 * 6, 0, 0); - Context.Flush(); - _pendingVerticesCount = 0; - } - - private ColorF ToColorF(Color color) => - new ColorF(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f); - } -} +// MIT License +// +// Copyright(c) 2017 Luciano (Xeeynamo) Ciccariello +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// Part of this software belongs to XeEngine toolset and United Lines Studio +// and it is currently used to create commercial games by Luciano Ciccariello. +// Please do not redistribuite this code under your own name, stole it or use +// it artfully, but instead support it and its author. Thank you. + +// Took from Xe.Drawing.Direct3D and transported to OpenKH under the same developer + +namespace OpenKh.Tools.Common.Rendering +{ + using dx = SharpDX; + using d3d = SharpDX.Direct3D11; + using dxgi = SharpDX.DXGI; + using System.Drawing; + using System.Runtime.InteropServices; + using System; + using System.Security; + using OpenKh.Engine.Renders; + + public partial class SpriteDrawingDirect3D : ISpriteDrawing + { + [DllImport("msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false), SuppressUnmanagedCodeSecurity] + public static extern IntPtr CopyMemory(IntPtr dest, IntPtr src, ulong count); + + [StructLayout(LayoutKind.Sequential)] + private struct Vertex + { + public float X, Y; + public float U, V; + public ColorF Color; + } + + public void AppendSprite(SpriteDrawingContext context) + { + SetTextureToDraw(context.SpriteTexture ?? _defaultTexture); + var width = _currentTexture.Width; + var height = _currentTexture.Height; + var viewport = _viewportSize; + var index = RequestVertices(4); + var buffer = _dataBuffer; + + buffer[index++] = new Vertex() + { + X = context.Vec0.X / viewport.Width * +2.0f - 1.0f, + Y = context.Vec0.Y / viewport.Height * -2.0f + 1.0f, + U = (float)context.SourceLeft / width, + V = (float)context.SourceTop / height, + Color = context.Color0 + }; + buffer[index++] = new Vertex() + { + X = context.Vec1.X / viewport.Width * +2.0f - 1.0f, + Y = context.Vec1.Y / viewport.Height * -2.0f + 1.0f, + U = (float)context.SourceRight / width, + V = (float)context.SourceTop / height, + Color = context.Color1 + }; + buffer[index++] = new Vertex() + { + X = context.Vec2.X / viewport.Width * +2.0f - 1.0f, + Y = context.Vec2.Y / viewport.Height * -2.0f + 1.0f, + U = (float)context.SourceLeft / width, + V = (float)context.SourceBottom / height, + Color = context.Color2 + }; + buffer[index++] = new Vertex() + { + X = context.Vec3.X / viewport.Width * +2.0f - 1.0f, + Y = context.Vec3.Y / viewport.Height * -2.0f + 1.0f, + U = (float)context.SourceRight / width, + V = (float)context.SourceBottom / height, + Color = context.Color3 + }; + } + + private CSpriteTexture _currentTexture; + private void SetTextureToDraw(ISpriteTexture texture) + { + if (_currentTexture != texture) + { + Flush(); + + texture ??= _defaultTexture; + var internalTexture = texture as CSpriteTexture; + Context.PixelShader.SetShaderResource(0, internalTexture?.ShaderResourceView); + _currentTexture = internalTexture; + } + } + + private const int MaximumQuadsCount = 65536; + private d3d.Buffer _vertexBuffer; + private d3d.Buffer _indexBuffer; + private Vertex[] _dataBuffer = new Vertex[MaximumQuadsCount]; + private int _pendingVerticesCount; + + private int RequestVertices(int count) + { + if (_pendingVerticesCount + count >= MaximumQuadsCount) + { + Flush(); + } + + var index = _pendingVerticesCount; + _pendingVerticesCount += count; + + return index; + } + + public void Flush() + { + if (_pendingVerticesCount == 0) + return; + + if (_vertexBuffer == null) + { + var vertexBufferDesc = new d3d.BufferDescription() + { + SizeInBytes = MaximumQuadsCount * dx.Utilities.SizeOf(), + Usage = d3d.ResourceUsage.Dynamic, + BindFlags = d3d.BindFlags.VertexBuffer, + CpuAccessFlags = d3d.CpuAccessFlags.Write, + OptionFlags = 0, + StructureByteStride = 0 + }; + _vertexBuffer = d3d.Buffer.Create(Device, _dataBuffer, vertexBufferDesc); + Context.InputAssembler.SetVertexBuffers(0, new d3d.VertexBufferBinding(_vertexBuffer, dx.Utilities.SizeOf(), 0)); + + var indexBufferDesc = new d3d.BufferDescription() + { + SizeInBytes = MaximumQuadsCount * 6 * sizeof(ushort), + Usage = d3d.ResourceUsage.Immutable, + BindFlags = d3d.BindFlags.IndexBuffer, + CpuAccessFlags = d3d.CpuAccessFlags.None, + OptionFlags = 0, + StructureByteStride = 0 + }; + uint[] indices = new uint[MaximumQuadsCount * 6]; + for (uint i = 0, nx = 0x00000000; i < MaximumQuadsCount * 6; nx += 4) + { + indices[i++] = nx + 1; + indices[i++] = nx + 0; + indices[i++] = nx + 2; + indices[i++] = nx + 1; + indices[i++] = nx + 2; + indices[i++] = nx + 3; + } + _indexBuffer = d3d.Buffer.Create(Device, indices, indexBufferDesc); + Context.InputAssembler.SetIndexBuffer(_indexBuffer, dxgi.Format.R32_UInt, 0); + } + else + { + var size = _pendingVerticesCount * dx.Utilities.SizeOf(); + var dataBox = Context.MapSubresource(_vertexBuffer, 0, d3d.MapMode.WriteDiscard, d3d.MapFlags.None); + IntPtr addr = Marshal.UnsafeAddrOfPinnedArrayElement(_dataBuffer, 0); + CopyMemory(dataBox.DataPointer, addr, (ulong)size); + Context.UnmapSubresource(_vertexBuffer, 0); + } + + Context.DrawIndexed(_pendingVerticesCount / 4 * 6, 0, 0); + Context.Flush(); + _pendingVerticesCount = 0; + } + + private ColorF ToColorF(Color color) => + new ColorF(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f); + } +} diff --git a/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Sharders.cs b/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Sharders.cs index b91cb5260..f6ce0018a 100644 --- a/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Sharders.cs +++ b/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Sharders.cs @@ -1,101 +1,101 @@ -// MIT License -// -// Copyright(c) 2017 Luciano (Xeeynamo) Ciccariello -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -// Part of this software belongs to XeEngine toolset and United Lines Studio -// and it is currently used to create commercial games by Luciano Ciccariello. -// Please do not redistribuite this code under your own name, stole it or use -// it artfully, but instead support it and its author. Thank you. - -// Took from Xe.Drawing.Direct3D and transported to OpenKH under the same developer - - -namespace OpenKh.Tools.Common.Rendering -{ - public partial class SpriteDrawingDirect3D - { - private const string VS = -@"cbuffer MatrixBuffer : register(b0) -{ - matrix Matrix; - matrix dummy; -}; - -struct VertexIn -{ - float4 pos : POSITION; - float2 tex : TEXTURE; - float4 color : COLOR; -}; -struct VertexOut -{ - float4 pos : SV_POSITION; - float2 tex : TEXTURE; - float4 color : COLOR; -}; - -VertexOut main(const VertexIn vIn) -{ - VertexOut vOut; - //vOut.pos = mul(Matrix, vIn.pos); - vOut.pos = vIn.pos; - vOut.tex = vIn.tex; - vOut.color = vIn.color; - return vOut; -}"; - private const string PS = -@"struct PixelIn -{ - float4 pos : SV_POSITION; - float2 tex : TEXTURE; - float4 color : COLOR; -}; - -Texture2D tImage0; -SamplerState sampleImage0; -Texture2D tClut0; -SamplerState sampleClut0; - -float4 main(PixelIn pIn) : SV_TARGET -{ - float4 texColor = tImage0.Sample(sampleImage0, pIn.tex.xy); - float4 blendColor = pIn.color; - return texColor * blendColor; - /*float4 color = pIn.color; - if (pIn.tex.z < 0.50) - { - // Use palette W texture - float colorIndex = tImage0.Sample(sampleImage0, pIn.tex.xy).r; - color *= tClut0.Sample(sampleClut0, float2(colorIndex, pIn.tex.z * 2.0)); - } - else if (pIn.tex.z < 1.0) - { - // Only texture - color *= tImage0.Sample(sampleImage0, pIn.tex.xy); - } - else - { - // Do not use texture - } - return color;*/ -}"; - } -} +// MIT License +// +// Copyright(c) 2017 Luciano (Xeeynamo) Ciccariello +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// Part of this software belongs to XeEngine toolset and United Lines Studio +// and it is currently used to create commercial games by Luciano Ciccariello. +// Please do not redistribuite this code under your own name, stole it or use +// it artfully, but instead support it and its author. Thank you. + +// Took from Xe.Drawing.Direct3D and transported to OpenKH under the same developer + + +namespace OpenKh.Tools.Common.Rendering +{ + public partial class SpriteDrawingDirect3D + { + private const string VS = +@"cbuffer MatrixBuffer : register(b0) +{ + matrix Matrix; + matrix dummy; +}; + +struct VertexIn +{ + float4 pos : POSITION; + float2 tex : TEXTURE; + float4 color : COLOR; +}; +struct VertexOut +{ + float4 pos : SV_POSITION; + float2 tex : TEXTURE; + float4 color : COLOR; +}; + +VertexOut main(const VertexIn vIn) +{ + VertexOut vOut; + //vOut.pos = mul(Matrix, vIn.pos); + vOut.pos = vIn.pos; + vOut.tex = vIn.tex; + vOut.color = vIn.color; + return vOut; +}"; + private const string PS = +@"struct PixelIn +{ + float4 pos : SV_POSITION; + float2 tex : TEXTURE; + float4 color : COLOR; +}; + +Texture2D tImage0; +SamplerState sampleImage0; +Texture2D tClut0; +SamplerState sampleClut0; + +float4 main(PixelIn pIn) : SV_TARGET +{ + float4 texColor = tImage0.Sample(sampleImage0, pIn.tex.xy); + float4 blendColor = pIn.color; + return texColor * blendColor; + /*float4 color = pIn.color; + if (pIn.tex.z < 0.50) + { + // Use palette W texture + float colorIndex = tImage0.Sample(sampleImage0, pIn.tex.xy).r; + color *= tClut0.Sample(sampleClut0, float2(colorIndex, pIn.tex.z * 2.0)); + } + else if (pIn.tex.z < 1.0) + { + // Only texture + color *= tImage0.Sample(sampleImage0, pIn.tex.xy); + } + else + { + // Do not use texture + } + return color;*/ +}"; + } +} diff --git a/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Surface.cs b/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Surface.cs index ef948c24b..0ff351b28 100644 --- a/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Surface.cs +++ b/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.Surface.cs @@ -1,307 +1,307 @@ -// MIT License -// -// Copyright(c) 2017 Luciano (Xeeynamo) Ciccariello -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -// Part of this software belongs to XeEngine toolset and United Lines Studio -// and it is currently used to create commercial games by Luciano Ciccariello. -// Please do not redistribuite this code under your own name, stole it or use -// it artfully, but instead support it and its author. Thank you. - -// Took from Xe.Drawing.Direct3D and transported to OpenKH under the same developer - -using OpenKh.Engine.Renders; -using OpenKh.Imaging; -using SharpDX.D3DCompiler; -using SharpDX.IO; -using System; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; - -namespace OpenKh.Tools.Common.Rendering -{ - using d3d = SharpDX.Direct3D11; - using dxgi = SharpDX.DXGI; - using wic = SharpDX.WIC; - - public partial class SpriteDrawingDirect3D - { - private static class TextureLoader - { - /// - /// Loads a bitmap using WIC. - /// - /// - /// - /// - public static wic.BitmapSource LoadBitmap(wic.ImagingFactory2 factory, string filename) - { - var bitmapDecoder = new wic.BitmapDecoder( - factory, - filename, - wic.DecodeOptions.CacheOnDemand - ); - - var formatConverter = new wic.FormatConverter(factory); - - formatConverter.Initialize( - bitmapDecoder.GetFrame(0), - wic.PixelFormat.Format32bppPRGBA, - wic.BitmapDitherType.None, - null, - 0.0, - wic.BitmapPaletteType.Custom); - - return formatConverter; - } - - /// - /// Creates a from a WIC - /// - /// The Direct3D11 device - /// The WIC bitmap source - /// A Texture2D - public static d3d.Texture2D CreateTexture2DFromBitmap(d3d.Device device, - wic.BitmapSource bitmapSource, Color[] filterColors = null) - { - // Allocate DataStream to receive the WIC image pixels - int stride = bitmapSource.Size.Width * 4; - using (var buffer = new SharpDX.DataStream(bitmapSource.Size.Height * stride, true, true)) - { - // Copy the content of the WIC to the buffer - bitmapSource.CopyPixels(stride, buffer); - if (filterColors.Length > 0) - { - Xe.Tools.Utilities.BitmapUtility.MakeTransparent_Bgra32(buffer.DataPointer, stride, - bitmapSource.Size.Height, filterColors - .Select(x => new Xe.Graphics.Color() - { - a = x.A, - r = x.R, - g = x.G, - b = x.B - }) - .ToArray() - ); - } - return new d3d.Texture2D(device, new d3d.Texture2DDescription() - { - Width = bitmapSource.Size.Width, - Height = bitmapSource.Size.Height, - ArraySize = 1, - BindFlags = d3d.BindFlags.ShaderResource, - Usage = d3d.ResourceUsage.Immutable, - CpuAccessFlags = d3d.CpuAccessFlags.None, - Format = dxgi.Format.R8G8B8A8_UNorm, - MipLevels = 1, - OptionFlags = d3d.ResourceOptionFlags.None, - SampleDescription = new dxgi.SampleDescription(1, 0), - }, new SharpDX.DataRectangle(buffer.DataPointer, stride)); - } - } - } - - public class MappedResource : IMappedResource - { - public MappedResource(d3d.Texture2D texture) - { - var dataBox = texture.Device.ImmediateContext.MapSubresource(texture, 0, - d3d.MapMode.Read, d3d.MapFlags.None, out var DataStream); - Texture = texture; - Stride = dataBox.RowPitch; - Length = dataBox.SlicePitch; - Data = dataBox.DataPointer; - } - - public d3d.Texture2D Texture { get; } - - public SharpDX.DataStream DataStream { get; } - - public IntPtr Data { get; } - - public int Stride { get; } - - public int Length { get; } - - public void Dispose() - { - DataStream?.Dispose(); - Texture.Device.ImmediateContext.UnmapSubresource(Texture, 0); - } - } - - - private class CSpriteTexture : ISpriteTexture - { - private d3d.Texture2D _backTexture; - - internal d3d.Texture2D Texture { get; } - internal d3d.ShaderResourceView ShaderResourceView { get; } - - public int Width => Texture.Description.Width; - - public int Height => Texture.Description.Height; - - public Size Size => new Size(Width, Height); - - public CSpriteTexture(d3d.Texture2D texture, d3d.ShaderResourceView shaderResourceView) - { - Texture = texture; - ShaderResourceView = shaderResourceView; - } - - public void Dispose() - { - _backTexture?.Dispose(); - ShaderResourceView.Dispose(); - Texture.Dispose(); - } - - public IMappedResource Map() - { - if (_backTexture == null || - _backTexture.Description.Width != Texture.Description.Width || - _backTexture.Description.Height != Texture.Description.Height) - { - var desc = new d3d.Texture2DDescription - { - Width = Texture.Description.Width, - Height = Texture.Description.Height, - MipLevels = Texture.Description.MipLevels, - ArraySize = Texture.Description.ArraySize, - Format = Texture.Description.Format, - Usage = d3d.ResourceUsage.Staging, - BindFlags = d3d.BindFlags.None, - CpuAccessFlags = d3d.CpuAccessFlags.Read, - OptionFlags = d3d.ResourceOptionFlags.None, - SampleDescription = new dxgi.SampleDescription(1, 0) - }; - _backTexture?.Dispose(); - _backTexture = new d3d.Texture2D(Texture.Device, desc); - } - Texture.Device.ImmediateContext.CopyResource(Texture, _backTexture); - return new MappedResource(_backTexture); - } - - public void Save(string filename) - { - if (File.Exists(filename)) - File.Delete(filename); - - var imagingFactory = new wic.ImagingFactory2(); - var wicPixelFormat = wic.PixelFormat.Format32bppPBGRA; - - using (var mapped = Map()) - { - using (var stream = new wic.WICStream(imagingFactory, filename, NativeFileAccess.Write)) - { - using (var encoder = new wic.PngBitmapEncoder(imagingFactory)) - { - encoder.Initialize(stream); - using (var bitmapFrameEncode = new wic.BitmapFrameEncode(encoder)) - { - bitmapFrameEncode.Initialize(); - bitmapFrameEncode.SetSize(Width, Height); - bitmapFrameEncode.SetPixelFormat(ref wicPixelFormat); - bitmapFrameEncode.WritePixels(Height, new SharpDX.DataRectangle() - { - DataPointer = mapped.Data, - Pitch = mapped.Stride - }); - - bitmapFrameEncode.Commit(); - encoder.Commit(); - } - } - } - } - } - } - - public ISpriteTexture CreateSpriteTexture(IImageRead image) => - CreateSpriteTexture(image.Size.Width, image.Size.Height, image.ToBgra32()); - - public ISpriteTexture CreateSpriteTexture(int width, int height) - { - if (width <= 0 || width > 65536) - throw new ArgumentOutOfRangeException(nameof(width), "Must be between 1 and 65536"); - if (height <= 0 || height > 65536) - throw new ArgumentOutOfRangeException(nameof(height), "Must be between 1 and 65536"); - - var desc = new d3d.Texture2DDescription - { - Width = width, - Height = height, - MipLevels = 1, - ArraySize = 1, - Format = dxgi.Format.B8G8R8A8_UNorm, - CpuAccessFlags = d3d.CpuAccessFlags.None, - OptionFlags = d3d.ResourceOptionFlags.None, - SampleDescription = new dxgi.SampleDescription(1, 0) - }; - - desc.Usage = d3d.ResourceUsage.Default; - desc.BindFlags = d3d.BindFlags.ShaderResource | d3d.BindFlags.RenderTarget; - - var texture = new d3d.Texture2D(Device, desc); - var shaderResourceView = new d3d.ShaderResourceView(Device, texture); - return new CSpriteTexture(texture, shaderResourceView); - } - - public ISpriteTexture CreateSpriteTexture(string filename, Color[] filterColors = null) - { - var bitmap = TextureLoader.LoadBitmap(new wic.ImagingFactory2(), filename); - var texture = TextureLoader.CreateTexture2DFromBitmap(Device, bitmap, filterColors); - d3d.ShaderResourceView shaderResourceView = new d3d.ShaderResourceView(Device, texture); - return new CSpriteTexture(texture, shaderResourceView); - } - - public ISpriteTexture CreateSpriteTexture(int width, int height, byte[] data) - { - if (width <= 0 || width > 65536) - throw new ArgumentOutOfRangeException(nameof(width), "Must be between 1 and 65536"); - if (height <= 0 || height > 65536) - throw new ArgumentOutOfRangeException(nameof(height), "Must be between 1 and 65536"); - - var desc = new d3d.Texture2DDescription - { - Width = width, - Height = height, - MipLevels = 1, - ArraySize = 1, - Format = dxgi.Format.B8G8R8A8_UNorm, - CpuAccessFlags = d3d.CpuAccessFlags.None, - OptionFlags = d3d.ResourceOptionFlags.None, - SampleDescription = new dxgi.SampleDescription(1, 0) - }; - - desc.Usage = d3d.ResourceUsage.Immutable; - desc.BindFlags = d3d.BindFlags.ShaderResource; - - var srcDataPtr = Marshal.UnsafeAddrOfPinnedArrayElement(data, 0); - var dataSource = new SharpDX.DataRectangle(srcDataPtr, width * sizeof(int)); - var texture = new d3d.Texture2D(Device, desc, new[] { dataSource }); - var shaderResourceView = new d3d.ShaderResourceView(Device, texture); - return new CSpriteTexture(texture, shaderResourceView); - } - } -} +// MIT License +// +// Copyright(c) 2017 Luciano (Xeeynamo) Ciccariello +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// Part of this software belongs to XeEngine toolset and United Lines Studio +// and it is currently used to create commercial games by Luciano Ciccariello. +// Please do not redistribuite this code under your own name, stole it or use +// it artfully, but instead support it and its author. Thank you. + +// Took from Xe.Drawing.Direct3D and transported to OpenKH under the same developer + +using OpenKh.Engine.Renders; +using OpenKh.Imaging; +using SharpDX.D3DCompiler; +using SharpDX.IO; +using System; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; + +namespace OpenKh.Tools.Common.Rendering +{ + using d3d = SharpDX.Direct3D11; + using dxgi = SharpDX.DXGI; + using wic = SharpDX.WIC; + + public partial class SpriteDrawingDirect3D + { + private static class TextureLoader + { + /// + /// Loads a bitmap using WIC. + /// + /// + /// + /// + public static wic.BitmapSource LoadBitmap(wic.ImagingFactory2 factory, string filename) + { + var bitmapDecoder = new wic.BitmapDecoder( + factory, + filename, + wic.DecodeOptions.CacheOnDemand + ); + + var formatConverter = new wic.FormatConverter(factory); + + formatConverter.Initialize( + bitmapDecoder.GetFrame(0), + wic.PixelFormat.Format32bppPRGBA, + wic.BitmapDitherType.None, + null, + 0.0, + wic.BitmapPaletteType.Custom); + + return formatConverter; + } + + /// + /// Creates a from a WIC + /// + /// The Direct3D11 device + /// The WIC bitmap source + /// A Texture2D + public static d3d.Texture2D CreateTexture2DFromBitmap(d3d.Device device, + wic.BitmapSource bitmapSource, Color[] filterColors = null) + { + // Allocate DataStream to receive the WIC image pixels + int stride = bitmapSource.Size.Width * 4; + using (var buffer = new SharpDX.DataStream(bitmapSource.Size.Height * stride, true, true)) + { + // Copy the content of the WIC to the buffer + bitmapSource.CopyPixels(stride, buffer); + if (filterColors.Length > 0) + { + Xe.Tools.Utilities.BitmapUtility.MakeTransparent_Bgra32(buffer.DataPointer, stride, + bitmapSource.Size.Height, filterColors + .Select(x => new Xe.Graphics.Color() + { + a = x.A, + r = x.R, + g = x.G, + b = x.B + }) + .ToArray() + ); + } + return new d3d.Texture2D(device, new d3d.Texture2DDescription() + { + Width = bitmapSource.Size.Width, + Height = bitmapSource.Size.Height, + ArraySize = 1, + BindFlags = d3d.BindFlags.ShaderResource, + Usage = d3d.ResourceUsage.Immutable, + CpuAccessFlags = d3d.CpuAccessFlags.None, + Format = dxgi.Format.R8G8B8A8_UNorm, + MipLevels = 1, + OptionFlags = d3d.ResourceOptionFlags.None, + SampleDescription = new dxgi.SampleDescription(1, 0), + }, new SharpDX.DataRectangle(buffer.DataPointer, stride)); + } + } + } + + public class MappedResource : IMappedResource + { + public MappedResource(d3d.Texture2D texture) + { + var dataBox = texture.Device.ImmediateContext.MapSubresource(texture, 0, + d3d.MapMode.Read, d3d.MapFlags.None, out var DataStream); + Texture = texture; + Stride = dataBox.RowPitch; + Length = dataBox.SlicePitch; + Data = dataBox.DataPointer; + } + + public d3d.Texture2D Texture { get; } + + public SharpDX.DataStream DataStream { get; } + + public IntPtr Data { get; } + + public int Stride { get; } + + public int Length { get; } + + public void Dispose() + { + DataStream?.Dispose(); + Texture.Device.ImmediateContext.UnmapSubresource(Texture, 0); + } + } + + + private class CSpriteTexture : ISpriteTexture + { + private d3d.Texture2D _backTexture; + + internal d3d.Texture2D Texture { get; } + internal d3d.ShaderResourceView ShaderResourceView { get; } + + public int Width => Texture.Description.Width; + + public int Height => Texture.Description.Height; + + public Size Size => new Size(Width, Height); + + public CSpriteTexture(d3d.Texture2D texture, d3d.ShaderResourceView shaderResourceView) + { + Texture = texture; + ShaderResourceView = shaderResourceView; + } + + public void Dispose() + { + _backTexture?.Dispose(); + ShaderResourceView.Dispose(); + Texture.Dispose(); + } + + public IMappedResource Map() + { + if (_backTexture == null || + _backTexture.Description.Width != Texture.Description.Width || + _backTexture.Description.Height != Texture.Description.Height) + { + var desc = new d3d.Texture2DDescription + { + Width = Texture.Description.Width, + Height = Texture.Description.Height, + MipLevels = Texture.Description.MipLevels, + ArraySize = Texture.Description.ArraySize, + Format = Texture.Description.Format, + Usage = d3d.ResourceUsage.Staging, + BindFlags = d3d.BindFlags.None, + CpuAccessFlags = d3d.CpuAccessFlags.Read, + OptionFlags = d3d.ResourceOptionFlags.None, + SampleDescription = new dxgi.SampleDescription(1, 0) + }; + _backTexture?.Dispose(); + _backTexture = new d3d.Texture2D(Texture.Device, desc); + } + Texture.Device.ImmediateContext.CopyResource(Texture, _backTexture); + return new MappedResource(_backTexture); + } + + public void Save(string filename) + { + if (File.Exists(filename)) + File.Delete(filename); + + var imagingFactory = new wic.ImagingFactory2(); + var wicPixelFormat = wic.PixelFormat.Format32bppPBGRA; + + using (var mapped = Map()) + { + using (var stream = new wic.WICStream(imagingFactory, filename, NativeFileAccess.Write)) + { + using (var encoder = new wic.PngBitmapEncoder(imagingFactory)) + { + encoder.Initialize(stream); + using (var bitmapFrameEncode = new wic.BitmapFrameEncode(encoder)) + { + bitmapFrameEncode.Initialize(); + bitmapFrameEncode.SetSize(Width, Height); + bitmapFrameEncode.SetPixelFormat(ref wicPixelFormat); + bitmapFrameEncode.WritePixels(Height, new SharpDX.DataRectangle() + { + DataPointer = mapped.Data, + Pitch = mapped.Stride + }); + + bitmapFrameEncode.Commit(); + encoder.Commit(); + } + } + } + } + } + } + + public ISpriteTexture CreateSpriteTexture(IImageRead image) => + CreateSpriteTexture(image.Size.Width, image.Size.Height, image.ToBgra32()); + + public ISpriteTexture CreateSpriteTexture(int width, int height) + { + if (width <= 0 || width > 65536) + throw new ArgumentOutOfRangeException(nameof(width), "Must be between 1 and 65536"); + if (height <= 0 || height > 65536) + throw new ArgumentOutOfRangeException(nameof(height), "Must be between 1 and 65536"); + + var desc = new d3d.Texture2DDescription + { + Width = width, + Height = height, + MipLevels = 1, + ArraySize = 1, + Format = dxgi.Format.B8G8R8A8_UNorm, + CpuAccessFlags = d3d.CpuAccessFlags.None, + OptionFlags = d3d.ResourceOptionFlags.None, + SampleDescription = new dxgi.SampleDescription(1, 0) + }; + + desc.Usage = d3d.ResourceUsage.Default; + desc.BindFlags = d3d.BindFlags.ShaderResource | d3d.BindFlags.RenderTarget; + + var texture = new d3d.Texture2D(Device, desc); + var shaderResourceView = new d3d.ShaderResourceView(Device, texture); + return new CSpriteTexture(texture, shaderResourceView); + } + + public ISpriteTexture CreateSpriteTexture(string filename, Color[] filterColors = null) + { + var bitmap = TextureLoader.LoadBitmap(new wic.ImagingFactory2(), filename); + var texture = TextureLoader.CreateTexture2DFromBitmap(Device, bitmap, filterColors); + d3d.ShaderResourceView shaderResourceView = new d3d.ShaderResourceView(Device, texture); + return new CSpriteTexture(texture, shaderResourceView); + } + + public ISpriteTexture CreateSpriteTexture(int width, int height, byte[] data) + { + if (width <= 0 || width > 65536) + throw new ArgumentOutOfRangeException(nameof(width), "Must be between 1 and 65536"); + if (height <= 0 || height > 65536) + throw new ArgumentOutOfRangeException(nameof(height), "Must be between 1 and 65536"); + + var desc = new d3d.Texture2DDescription + { + Width = width, + Height = height, + MipLevels = 1, + ArraySize = 1, + Format = dxgi.Format.B8G8R8A8_UNorm, + CpuAccessFlags = d3d.CpuAccessFlags.None, + OptionFlags = d3d.ResourceOptionFlags.None, + SampleDescription = new dxgi.SampleDescription(1, 0) + }; + + desc.Usage = d3d.ResourceUsage.Immutable; + desc.BindFlags = d3d.BindFlags.ShaderResource; + + var srcDataPtr = Marshal.UnsafeAddrOfPinnedArrayElement(data, 0); + var dataSource = new SharpDX.DataRectangle(srcDataPtr, width * sizeof(int)); + var texture = new d3d.Texture2D(Device, desc, new[] { dataSource }); + var shaderResourceView = new d3d.ShaderResourceView(Device, texture); + return new CSpriteTexture(texture, shaderResourceView); + } + } +} diff --git a/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.cs b/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.cs index 8fc7f07eb..344125edb 100644 --- a/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.cs +++ b/OpenKh.Tools.Common/Rendering/SpriteDrawingDirect3D.cs @@ -1,99 +1,99 @@ -// MIT License -// -// Copyright(c) 2017 Luciano (Xeeynamo) Ciccariello -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -// Part of this software belongs to XeEngine toolset and United Lines Studio -// and it is currently used to create commercial games by Luciano Ciccariello. -// Please do not redistribuite this code under your own name, stole it or use -// it artfully, but instead support it and its author. Thank you. - -// Took from Xe.Drawing.Direct3D and transported to OpenKH under the same developer - -using OpenKh.Engine.Renders; -using System.Drawing; - -namespace OpenKh.Tools.Common.Rendering -{ - using dx = SharpDX; - using d3d = SharpDX.Direct3D11; - - public partial class SpriteDrawingDirect3D : ISpriteDrawing - { - private d3d.RenderTargetView _renderTarget; - private CSpriteTexture _dstSurface; - private SizeF _viewportSize; - - public ISpriteTexture DestinationTexture - { - get => _dstSurface; - set - { - if (value is CSpriteTexture surface) - { - _renderTarget?.Dispose(); - _renderTarget = new d3d.RenderTargetView(Device, surface.Texture); - Context.OutputMerger.SetRenderTargets(_renderTarget); - _dstSurface = surface; - - var viewport = new dx.Viewport(0, 0, surface.Width, surface.Height); - Context.Rasterizer.SetViewport(viewport); - _viewportSize = new SizeF(surface.Width, surface.Height); - } - else - { - _renderTarget?.Dispose(); - _renderTarget = null; - Context.OutputMerger.SetRenderTargets(_renderTarget); - } - } - } - - public void SetViewport(float left, float right, float top, float bottom) - { - Context.Rasterizer.SetViewport(left, top, left + right, top - bottom, 0.0f, 1.0f); - } - - internal void SetViewport(Size size) - { - Context.Rasterizer.SetViewport(0, 0, size.Width, size.Height, 0.0f, 1.0f); - } - - public void Clear(ColorF color) - { - if (_renderTarget != null) - { - Context.ClearRenderTargetView(_renderTarget, new SharpDX.Mathematics.Interop.RawColor4() - { - R = color.R, - G = color.G, - B = color.B, - A = color.A, - }); - } - } - - public void Dispose() - { - _renderTarget?.Dispose(); - _device.Dispose(); - } - } -} +// MIT License +// +// Copyright(c) 2017 Luciano (Xeeynamo) Ciccariello +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// Part of this software belongs to XeEngine toolset and United Lines Studio +// and it is currently used to create commercial games by Luciano Ciccariello. +// Please do not redistribuite this code under your own name, stole it or use +// it artfully, but instead support it and its author. Thank you. + +// Took from Xe.Drawing.Direct3D and transported to OpenKH under the same developer + +using OpenKh.Engine.Renders; +using System.Drawing; + +namespace OpenKh.Tools.Common.Rendering +{ + using dx = SharpDX; + using d3d = SharpDX.Direct3D11; + + public partial class SpriteDrawingDirect3D : ISpriteDrawing + { + private d3d.RenderTargetView _renderTarget; + private CSpriteTexture _dstSurface; + private SizeF _viewportSize; + + public ISpriteTexture DestinationTexture + { + get => _dstSurface; + set + { + if (value is CSpriteTexture surface) + { + _renderTarget?.Dispose(); + _renderTarget = new d3d.RenderTargetView(Device, surface.Texture); + Context.OutputMerger.SetRenderTargets(_renderTarget); + _dstSurface = surface; + + var viewport = new dx.Viewport(0, 0, surface.Width, surface.Height); + Context.Rasterizer.SetViewport(viewport); + _viewportSize = new SizeF(surface.Width, surface.Height); + } + else + { + _renderTarget?.Dispose(); + _renderTarget = null; + Context.OutputMerger.SetRenderTargets(_renderTarget); + } + } + } + + public void SetViewport(float left, float right, float top, float bottom) + { + Context.Rasterizer.SetViewport(left, top, left + right, top - bottom, 0.0f, 1.0f); + } + + internal void SetViewport(Size size) + { + Context.Rasterizer.SetViewport(0, 0, size.Width, size.Height, 0.0f, 1.0f); + } + + public void Clear(ColorF color) + { + if (_renderTarget != null) + { + Context.ClearRenderTargetView(_renderTarget, new SharpDX.Mathematics.Interop.RawColor4() + { + R = color.R, + G = color.G, + B = color.B, + A = color.A, + }); + } + } + + public void Dispose() + { + _renderTarget?.Dispose(); + _device.Dispose(); + } + } +} diff --git a/OpenKh.Tools.Common/ToolConstants.cs b/OpenKh.Tools.Common/ToolConstants.cs index f74bb3514..8aeef6fb1 100644 --- a/OpenKh.Tools.Common/ToolConstants.cs +++ b/OpenKh.Tools.Common/ToolConstants.cs @@ -1,8 +1,8 @@ -namespace OpenKh.Tools.Common -{ - public class ToolConstants - { - public const uint Ps2MemoryLength = 32 * 1024 * 1024; - public const uint Pcsx2BaseAddress = 0x20000000; - } -} +namespace OpenKh.Tools.Common +{ + public class ToolConstants + { + public const uint Ps2MemoryLength = 32 * 1024 * 1024; + public const uint Pcsx2BaseAddress = 0x20000000; + } +} diff --git a/OpenKh.Tools.Common/ToolInvokeDesc.cs b/OpenKh.Tools.Common/ToolInvokeDesc.cs index bee72007f..19daa2f8d 100644 --- a/OpenKh.Tools.Common/ToolInvokeDesc.cs +++ b/OpenKh.Tools.Common/ToolInvokeDesc.cs @@ -1,26 +1,26 @@ -using OpenKh.Kh2; - -namespace OpenKh.Tools.Common -{ - public class ToolInvokeDesc - { - public enum ContentChangeInfo - { - None, - File, - Entry - } - - public string Title { get; set; } - - public string ActualFileName { get; set; } - - public Bar.Entry SelectedEntry { get; set; } - - /// - /// Once the tool is closed, this field will say which input resource - /// has been modified. - /// - public ContentChangeInfo ContentChange { get; set; } - } -} +using OpenKh.Kh2; + +namespace OpenKh.Tools.Common +{ + public class ToolInvokeDesc + { + public enum ContentChangeInfo + { + None, + File, + Entry + } + + public string Title { get; set; } + + public string ActualFileName { get; set; } + + public Bar.Entry SelectedEntry { get; set; } + + /// + /// Once the tool is closed, this field will say which input resource + /// has been modified. + /// + public ContentChangeInfo ContentChange { get; set; } + } +} diff --git a/OpenKh.Tools.Common/Utilities.cs b/OpenKh.Tools.Common/Utilities.cs index ff4621690..f2e8ec742 100644 --- a/OpenKh.Tools.Common/Utilities.cs +++ b/OpenKh.Tools.Common/Utilities.cs @@ -1,51 +1,51 @@ -using System; -using System.Diagnostics; -using System.Linq; -using System.Reflection; -using System.Windows; - -namespace OpenKh.Tools.Common -{ - public static class Utilities - { - private static readonly Assembly RunningAssembly = Assembly.GetEntryAssembly(); - private static readonly AssemblyName RunningAssemblyName = RunningAssembly?.GetName(); - - public static readonly Action DefaultExceptionHandler = ex => - MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); - - public static Action ExceptionHandler = DefaultExceptionHandler; - - public static Window GetCurrentWindow() => - Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - - public static string GetApplicationName() - { - var fvi = FileVersionInfo.GetVersionInfo(RunningAssembly.Location); - return fvi.ProductName; - } - - public static string GetApplicationVersion() - { - var version = RunningAssemblyName?.Version; - if (version == null) - return "unknown"; - return $"{version.Major}.{version.Minor:D02}.{version.Build:D02}.{version.Revision}"; - } - - public static void Catch(Action action) - { - try - { - action(); - } - catch (Exception ex) - { - ExceptionHandler(ex); - } - } - - public static void ShowError(string message, string title = "Error") => - MessageBox.Show(GetCurrentWindow(), message, title, MessageBoxButton.OK, MessageBoxImage.Error); - } -} +using System; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Windows; + +namespace OpenKh.Tools.Common +{ + public static class Utilities + { + private static readonly Assembly RunningAssembly = Assembly.GetEntryAssembly(); + private static readonly AssemblyName RunningAssemblyName = RunningAssembly?.GetName(); + + public static readonly Action DefaultExceptionHandler = ex => + MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + + public static Action ExceptionHandler = DefaultExceptionHandler; + + public static Window GetCurrentWindow() => + Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + + public static string GetApplicationName() + { + var fvi = FileVersionInfo.GetVersionInfo(RunningAssembly.Location); + return fvi.ProductName; + } + + public static string GetApplicationVersion() + { + var version = RunningAssemblyName?.Version; + if (version == null) + return "unknown"; + return $"{version.Major}.{version.Minor:D02}.{version.Build:D02}.{version.Revision}"; + } + + public static void Catch(Action action) + { + try + { + action(); + } + catch (Exception ex) + { + ExceptionHandler(ex); + } + } + + public static void ShowError(string message, string title = "Error") => + MessageBox.Show(GetCurrentWindow(), message, title, MessageBoxButton.OK, MessageBoxImage.Error); + } +} diff --git a/OpenKh.Tools.CtdEditor/App.xaml.cs b/OpenKh.Tools.CtdEditor/App.xaml.cs index ab2e4e280..1b309a8e5 100644 --- a/OpenKh.Tools.CtdEditor/App.xaml.cs +++ b/OpenKh.Tools.CtdEditor/App.xaml.cs @@ -1,11 +1,11 @@ -using System.Windows; - -namespace OpenKh.Tools.CtdEditor -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} +using System.Windows; + +namespace OpenKh.Tools.CtdEditor +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/OpenKh.Tools.CtdEditor/Interfaces/CtdDrawHandler.cs b/OpenKh.Tools.CtdEditor/Interfaces/CtdDrawHandler.cs index 6ac09ac24..24db2e21b 100644 --- a/OpenKh.Tools.CtdEditor/Interfaces/CtdDrawHandler.cs +++ b/OpenKh.Tools.CtdEditor/Interfaces/CtdDrawHandler.cs @@ -1,91 +1,91 @@ -using OpenKh.Bbs; -using OpenKh.Bbs.Messages; -using OpenKh.Engine.Extensions; -using OpenKh.Engine.Renders; -using OpenKh.Tools.Common.Rendering; -using System.Drawing; -using System.Linq; - -namespace OpenKh.Tools.CtdEditor.Interfaces -{ - public class CtdDrawHandler : IDrawHandler - { - private const int PspScreenWidth = 480; - private const int PspScreenHeight = 272; - - public CtdDrawHandler() - { - DrawingContext = new SpriteDrawingDirect3D(); - } - - public ISpriteDrawing DrawingContext { get; } - - public void DrawHandler( - ICtdMessageEncoder encoder, - FontsArc.Font fontContext, - Ctd.Message message, - Ctd.Layout layout) - { - DrawPspScreen(); - DrawDialog(layout); - - int BeginX = layout.DialogX + layout.TextX; - int BeginY = layout.DialogY + layout.TextY; - var x = BeginX; - var y = BeginY; - var texture1 = DrawingContext.CreateSpriteTexture(fontContext.Image1); - var texture2 = DrawingContext.CreateSpriteTexture(fontContext.Image2); - foreach (var ch in encoder.ToUcs(message.Data)) - { - if (ch >= 0x20) - { - var chInfo = fontContext.CharactersInfo.FirstOrDefault(info => info.Id == ch); - if (chInfo == null) - { - if (ch == 0x20) - x += fontContext.Info.CharacterWidth / 2; - continue; - } - if (chInfo.Palette >= 2) - continue; - - var texture = chInfo.Palette == 0 ? texture1 : texture2; - var source = new Rectangle - { - X = chInfo.PositionX, - Y = chInfo.PositionY, - Width = chInfo.Width, - Height = fontContext.Info.CharacterHeight - }; - DrawingContext.AppendSprite(new SpriteDrawingContext() - .SpriteTexture(texture) - .Source(chInfo.PositionX, chInfo.PositionY, chInfo.Width, fontContext.Info.CharacterHeight) - .MatchSourceSize() - .Position(x, y)); - - x += source.Width + layout.HorizontalSpace; - } - else - { - switch (ch) - { - case 0x0a: // '\n' - x = BeginX; - y += 16 + layout.VerticalSpace; - break; - } - } - } - } - - private void DrawPspScreen() => - DrawingContext.FillRectangle(0, 0, PspScreenWidth, PspScreenHeight, ColorF.Black); - - private void DrawDialog(Ctd.Layout layout) => DrawingContext.DrawRectangle( - layout.DialogX - 1, - layout.DialogY - 1, - layout.DialogWidth + 1, - layout.DialogHeight + 1, - ColorF.FromRgba(Color.Cyan.ToArgb())); - } -} +using OpenKh.Bbs; +using OpenKh.Bbs.Messages; +using OpenKh.Engine.Extensions; +using OpenKh.Engine.Renders; +using OpenKh.Tools.Common.Rendering; +using System.Drawing; +using System.Linq; + +namespace OpenKh.Tools.CtdEditor.Interfaces +{ + public class CtdDrawHandler : IDrawHandler + { + private const int PspScreenWidth = 480; + private const int PspScreenHeight = 272; + + public CtdDrawHandler() + { + DrawingContext = new SpriteDrawingDirect3D(); + } + + public ISpriteDrawing DrawingContext { get; } + + public void DrawHandler( + ICtdMessageEncoder encoder, + FontsArc.Font fontContext, + Ctd.Message message, + Ctd.Layout layout) + { + DrawPspScreen(); + DrawDialog(layout); + + int BeginX = layout.DialogX + layout.TextX; + int BeginY = layout.DialogY + layout.TextY; + var x = BeginX; + var y = BeginY; + var texture1 = DrawingContext.CreateSpriteTexture(fontContext.Image1); + var texture2 = DrawingContext.CreateSpriteTexture(fontContext.Image2); + foreach (var ch in encoder.ToUcs(message.Data)) + { + if (ch >= 0x20) + { + var chInfo = fontContext.CharactersInfo.FirstOrDefault(info => info.Id == ch); + if (chInfo == null) + { + if (ch == 0x20) + x += fontContext.Info.CharacterWidth / 2; + continue; + } + if (chInfo.Palette >= 2) + continue; + + var texture = chInfo.Palette == 0 ? texture1 : texture2; + var source = new Rectangle + { + X = chInfo.PositionX, + Y = chInfo.PositionY, + Width = chInfo.Width, + Height = fontContext.Info.CharacterHeight + }; + DrawingContext.AppendSprite(new SpriteDrawingContext() + .SpriteTexture(texture) + .Source(chInfo.PositionX, chInfo.PositionY, chInfo.Width, fontContext.Info.CharacterHeight) + .MatchSourceSize() + .Position(x, y)); + + x += source.Width + layout.HorizontalSpace; + } + else + { + switch (ch) + { + case 0x0a: // '\n' + x = BeginX; + y += 16 + layout.VerticalSpace; + break; + } + } + } + } + + private void DrawPspScreen() => + DrawingContext.FillRectangle(0, 0, PspScreenWidth, PspScreenHeight, ColorF.Black); + + private void DrawDialog(Ctd.Layout layout) => DrawingContext.DrawRectangle( + layout.DialogX - 1, + layout.DialogY - 1, + layout.DialogWidth + 1, + layout.DialogHeight + 1, + ColorF.FromRgba(Color.Cyan.ToArgb())); + } +} diff --git a/OpenKh.Tools.CtdEditor/Interfaces/IDrawHandler.cs b/OpenKh.Tools.CtdEditor/Interfaces/IDrawHandler.cs index b68d76cd7..14ac4c87b 100644 --- a/OpenKh.Tools.CtdEditor/Interfaces/IDrawHandler.cs +++ b/OpenKh.Tools.CtdEditor/Interfaces/IDrawHandler.cs @@ -1,17 +1,17 @@ -using OpenKh.Bbs; -using OpenKh.Bbs.Messages; -using OpenKh.Engine.Renders; - -namespace OpenKh.Tools.CtdEditor.Interfaces -{ - public interface IDrawHandler - { - ISpriteDrawing DrawingContext { get; } - - void DrawHandler( - ICtdMessageEncoder encoder, - FontsArc.Font fontContext, - Ctd.Message message, - Ctd.Layout layout); - } -} +using OpenKh.Bbs; +using OpenKh.Bbs.Messages; +using OpenKh.Engine.Renders; + +namespace OpenKh.Tools.CtdEditor.Interfaces +{ + public interface IDrawHandler + { + ISpriteDrawing DrawingContext { get; } + + void DrawHandler( + ICtdMessageEncoder encoder, + FontsArc.Font fontContext, + Ctd.Message message, + Ctd.Layout layout); + } +} diff --git a/OpenKh.Tools.CtdEditor/ViewModels/CharacterViewModel.cs b/OpenKh.Tools.CtdEditor/ViewModels/CharacterViewModel.cs index 92e64d5bf..a362728d4 100644 --- a/OpenKh.Tools.CtdEditor/ViewModels/CharacterViewModel.cs +++ b/OpenKh.Tools.CtdEditor/ViewModels/CharacterViewModel.cs @@ -1,62 +1,62 @@ -using OpenKh.Bbs; -using System.Globalization; -using System.Linq; -using Xe.Tools; - -namespace OpenKh.Tools.CtdEditor.ViewModels -{ - public class CharacterViewModel : BaseNotifyPropertyChanged - { - private readonly FontCharacterInfo _info; - - public CharacterViewModel(FontCharacterInfo info) - { - _info = info; - } - - public string Id - { - get => $"{(_info.Id >> 8) & 0xff:X02} {_info.Id & 0xff:X02}"; - set - { - var digits = value - .Where(x => !char.IsWhiteSpace(x)) - .Select(x => int.Parse($"{x}", NumberStyles.HexNumber)) - .ToArray(); - var actualValue = digits[0] << 12 | - digits[1] << 8 | - digits[2] << 4 | - digits[3]; - - _info.Id = (ushort)actualValue; - OnPropertyChanged(nameof(Title)); - } - } - - public ushort PositionX - { - get => _info.PositionX; - set => _info.PositionX = value; - } - - public ushort PositionY - { - get => _info.PositionY; - set => _info.PositionY = value; - } - - public byte Palette - { - get => _info.Palette; - set => _info.Palette = value; - } - - public byte Width - { - get => _info.Width; - set => _info.Width = value; - } - - public string Title => Id; - } -} +using OpenKh.Bbs; +using System.Globalization; +using System.Linq; +using Xe.Tools; + +namespace OpenKh.Tools.CtdEditor.ViewModels +{ + public class CharacterViewModel : BaseNotifyPropertyChanged + { + private readonly FontCharacterInfo _info; + + public CharacterViewModel(FontCharacterInfo info) + { + _info = info; + } + + public string Id + { + get => $"{(_info.Id >> 8) & 0xff:X02} {_info.Id & 0xff:X02}"; + set + { + var digits = value + .Where(x => !char.IsWhiteSpace(x)) + .Select(x => int.Parse($"{x}", NumberStyles.HexNumber)) + .ToArray(); + var actualValue = digits[0] << 12 | + digits[1] << 8 | + digits[2] << 4 | + digits[3]; + + _info.Id = (ushort)actualValue; + OnPropertyChanged(nameof(Title)); + } + } + + public ushort PositionX + { + get => _info.PositionX; + set => _info.PositionX = value; + } + + public ushort PositionY + { + get => _info.PositionY; + set => _info.PositionY = value; + } + + public byte Palette + { + get => _info.Palette; + set => _info.Palette = value; + } + + public byte Width + { + get => _info.Width; + set => _info.Width = value; + } + + public string Title => Id; + } +} diff --git a/OpenKh.Tools.CtdEditor/ViewModels/CtdViewModel.cs b/OpenKh.Tools.CtdEditor/ViewModels/CtdViewModel.cs index 39d08858a..1d22f9a0e 100644 --- a/OpenKh.Tools.CtdEditor/ViewModels/CtdViewModel.cs +++ b/OpenKh.Tools.CtdEditor/ViewModels/CtdViewModel.cs @@ -1,93 +1,93 @@ -using OpenKh.Bbs; -using OpenKh.Tools.CtdEditor.Interfaces; -using System; -using System.Collections.Generic; -using System.Linq; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.CtdEditor.ViewModels -{ - public class CtdViewModel : GenericListModel - { - private string _searchTerm; - private readonly Ctd _ctd; - private readonly IDrawHandler _drawHandler; - private FontsArc _fonts; - - public Ctd Ctd - { - get - { - _ctd.Messages.Clear(); - _ctd.Messages.AddRange(Items.Select(x => x.Message)); - return _ctd; - } - } - - public FontsArc Fonts - { - get => _fonts; - set - { - _fonts = value; - } - } - - public string SearchTerm - { - get => _searchTerm; - set - { - _searchTerm = value; - PerformFiltering(); - } - } - - public CtdViewModel(IDrawHandler drawHandler) : - this(drawHandler, new Ctd()) - { - } - - public CtdViewModel(IDrawHandler drawHandler, Ctd ctd) : - this(drawHandler, ctd, ctd.Messages) - { - _drawHandler = drawHandler; - } - - private CtdViewModel(IDrawHandler drawHandler, Ctd ctd, IEnumerable messages) : - base(messages.Select(x => new MessageViewModel(drawHandler, ctd, x))) - { - _ctd = ctd; - } - - protected override void OnSelectedItem(MessageViewModel item) - { - if (item != null) - item.FontContext = Fonts?.FontMes; - - base.OnSelectedItem(item); - } - - protected override MessageViewModel OnNewItem() => - new MessageViewModel(_drawHandler, _ctd, new Ctd.Message - { - Id = (short)(Items.Max(x => x.Message.Id) + 1), - Data = new byte[0], - LayoutIndex = 0, - Unknown02 = _ctd.Unknown - }); - - private void PerformFiltering() - { - if (string.IsNullOrWhiteSpace(_searchTerm)) - Filter(FilterNone); - else - Filter(FilterTextAndId); - } - - private bool FilterNone(MessageViewModel arg) => true; - - private bool FilterTextAndId(MessageViewModel arg) => - $"{arg.Id.ToString()} {arg.Text}".ToLower().Contains(SearchTerm.ToLower()); - } -} +using OpenKh.Bbs; +using OpenKh.Tools.CtdEditor.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.CtdEditor.ViewModels +{ + public class CtdViewModel : GenericListModel + { + private string _searchTerm; + private readonly Ctd _ctd; + private readonly IDrawHandler _drawHandler; + private FontsArc _fonts; + + public Ctd Ctd + { + get + { + _ctd.Messages.Clear(); + _ctd.Messages.AddRange(Items.Select(x => x.Message)); + return _ctd; + } + } + + public FontsArc Fonts + { + get => _fonts; + set + { + _fonts = value; + } + } + + public string SearchTerm + { + get => _searchTerm; + set + { + _searchTerm = value; + PerformFiltering(); + } + } + + public CtdViewModel(IDrawHandler drawHandler) : + this(drawHandler, new Ctd()) + { + } + + public CtdViewModel(IDrawHandler drawHandler, Ctd ctd) : + this(drawHandler, ctd, ctd.Messages) + { + _drawHandler = drawHandler; + } + + private CtdViewModel(IDrawHandler drawHandler, Ctd ctd, IEnumerable messages) : + base(messages.Select(x => new MessageViewModel(drawHandler, ctd, x))) + { + _ctd = ctd; + } + + protected override void OnSelectedItem(MessageViewModel item) + { + if (item != null) + item.FontContext = Fonts?.FontMes; + + base.OnSelectedItem(item); + } + + protected override MessageViewModel OnNewItem() => + new MessageViewModel(_drawHandler, _ctd, new Ctd.Message + { + Id = (short)(Items.Max(x => x.Message.Id) + 1), + Data = new byte[0], + LayoutIndex = 0, + Unknown02 = _ctd.Unknown + }); + + private void PerformFiltering() + { + if (string.IsNullOrWhiteSpace(_searchTerm)) + Filter(FilterNone); + else + Filter(FilterTextAndId); + } + + private bool FilterNone(MessageViewModel arg) => true; + + private bool FilterTextAndId(MessageViewModel arg) => + $"{arg.Id.ToString()} {arg.Text}".ToLower().Contains(SearchTerm.ToLower()); + } +} diff --git a/OpenKh.Tools.CtdEditor/ViewModels/FontEditorViewModel.cs b/OpenKh.Tools.CtdEditor/ViewModels/FontEditorViewModel.cs index 72a4888e2..130ff9f69 100644 --- a/OpenKh.Tools.CtdEditor/ViewModels/FontEditorViewModel.cs +++ b/OpenKh.Tools.CtdEditor/ViewModels/FontEditorViewModel.cs @@ -1,138 +1,138 @@ -using OpenKh.Bbs; -using OpenKh.Engine.Renders; -using OpenKh.Tools.Common.Rendering; -using System; -using System.Collections.Generic; -using System.DirectoryServices; -using System.Drawing; -using System.Linq; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; - -namespace OpenKh.Tools.CtdEditor.ViewModels -{ - public class FontEditorViewModel : BaseNotifyPropertyChanged - { - private readonly FontsArc _fonts; - private CharacterViewModel[] _characters; - private FontEntryViewModel _selectedFont; - private CharacterViewModel _selectedCharacter; - private ISpriteTexture _surface1; - private ISpriteTexture _surface2; - private bool orderCharacters; - - public FontEditorViewModel(FontsArc fonts) - { - _fonts = fonts; - Fonts = new[] - { - new FontEntryViewModel(fonts.FontCmd), - new FontEntryViewModel(fonts.FontHelp), - new FontEntryViewModel(fonts.FontMenu), - new FontEntryViewModel(fonts.FontMes), - new FontEntryViewModel(fonts.FontNumeral) - }; - - DrawingContext = new SpriteDrawingDirect3D(); - DrawBegin = new RelayCommand(_ => - { - if (_selectedFont?.Font1 == null || - SelectedCharacter == null) - return; - - if (_surface1 == null) - CreateFontSurfaces(); - - if (_surface1 == null) - return; - - DrawingContext.Clear(new ColorF(0.0f, 0.0f, 0.0f, 1.0f)); - PrintCharacter(SelectedCharacter); - DrawingContext.Flush(); - }); - } - - public FontEntryViewModel[] Fonts { get; } - public FontEntryViewModel SelectedFont - { - get => _selectedFont; - set - { - _selectedFont = value; - _characters = _selectedFont.CharactersInfo.Select(x => new CharacterViewModel(x)).ToArray(); - - DestroyFontSurfaces(); - OnPropertyChanged(nameof(IsFontSeleted)); - OnPropertyChanged(nameof(Characters)); - } - } - public bool IsFontSeleted => SelectedFont != null; - - public IEnumerable Characters => - (OrderCharacters ? _characters?.OrderBy(x => x.Id) : _characters as IEnumerable) - ?? Array.Empty(); - - public CharacterViewModel SelectedCharacter - { - get => _selectedCharacter; - set - { - _selectedCharacter = value; - OnPropertyChanged(nameof(SelectedCharacter)); - OnPropertyChanged(nameof(IsCharacterSelected)); - } - } - public bool IsCharacterSelected => SelectedCharacter != null; - - public bool OrderCharacters - { - get => orderCharacters; - set - { - orderCharacters = value; - OnPropertyChanged(nameof(Characters)); - } - } - - public ISpriteDrawing DrawingContext { get; } - public RelayCommand DrawBegin { get; } - - private void CreateFontSurfaces() - { - _surface1 = DrawingContext.CreateSpriteTexture(_selectedFont.Font1); - _surface2 = DrawingContext.CreateSpriteTexture(_selectedFont.Font2); - } - - private void DestroyFontSurfaces() - { - _surface1?.Dispose(); - _surface2?.Dispose(); - - _surface1 = null; - _surface2 = null; - } - - private void PrintCharacter(CharacterViewModel characterViewModel) - { - ISpriteTexture surface; - - switch (characterViewModel.Palette) - { - case 0: - surface = _surface1; - break; - case 1: - surface = _surface2; - break; - default: - return; - } - - DrawingContext.AppendSprite(new SpriteDrawingContext() - .SpriteTexture(surface) - .Source(characterViewModel.PositionX, characterViewModel.PositionY, characterViewModel.Width, SelectedFont.Info.CharacterHeight) - .MatchSourceSize() - .ScaleSize(2)); - } - } -} +using OpenKh.Bbs; +using OpenKh.Engine.Renders; +using OpenKh.Tools.Common.Rendering; +using System; +using System.Collections.Generic; +using System.DirectoryServices; +using System.Drawing; +using System.Linq; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; + +namespace OpenKh.Tools.CtdEditor.ViewModels +{ + public class FontEditorViewModel : BaseNotifyPropertyChanged + { + private readonly FontsArc _fonts; + private CharacterViewModel[] _characters; + private FontEntryViewModel _selectedFont; + private CharacterViewModel _selectedCharacter; + private ISpriteTexture _surface1; + private ISpriteTexture _surface2; + private bool orderCharacters; + + public FontEditorViewModel(FontsArc fonts) + { + _fonts = fonts; + Fonts = new[] + { + new FontEntryViewModel(fonts.FontCmd), + new FontEntryViewModel(fonts.FontHelp), + new FontEntryViewModel(fonts.FontMenu), + new FontEntryViewModel(fonts.FontMes), + new FontEntryViewModel(fonts.FontNumeral) + }; + + DrawingContext = new SpriteDrawingDirect3D(); + DrawBegin = new RelayCommand(_ => + { + if (_selectedFont?.Font1 == null || + SelectedCharacter == null) + return; + + if (_surface1 == null) + CreateFontSurfaces(); + + if (_surface1 == null) + return; + + DrawingContext.Clear(new ColorF(0.0f, 0.0f, 0.0f, 1.0f)); + PrintCharacter(SelectedCharacter); + DrawingContext.Flush(); + }); + } + + public FontEntryViewModel[] Fonts { get; } + public FontEntryViewModel SelectedFont + { + get => _selectedFont; + set + { + _selectedFont = value; + _characters = _selectedFont.CharactersInfo.Select(x => new CharacterViewModel(x)).ToArray(); + + DestroyFontSurfaces(); + OnPropertyChanged(nameof(IsFontSeleted)); + OnPropertyChanged(nameof(Characters)); + } + } + public bool IsFontSeleted => SelectedFont != null; + + public IEnumerable Characters => + (OrderCharacters ? _characters?.OrderBy(x => x.Id) : _characters as IEnumerable) + ?? Array.Empty(); + + public CharacterViewModel SelectedCharacter + { + get => _selectedCharacter; + set + { + _selectedCharacter = value; + OnPropertyChanged(nameof(SelectedCharacter)); + OnPropertyChanged(nameof(IsCharacterSelected)); + } + } + public bool IsCharacterSelected => SelectedCharacter != null; + + public bool OrderCharacters + { + get => orderCharacters; + set + { + orderCharacters = value; + OnPropertyChanged(nameof(Characters)); + } + } + + public ISpriteDrawing DrawingContext { get; } + public RelayCommand DrawBegin { get; } + + private void CreateFontSurfaces() + { + _surface1 = DrawingContext.CreateSpriteTexture(_selectedFont.Font1); + _surface2 = DrawingContext.CreateSpriteTexture(_selectedFont.Font2); + } + + private void DestroyFontSurfaces() + { + _surface1?.Dispose(); + _surface2?.Dispose(); + + _surface1 = null; + _surface2 = null; + } + + private void PrintCharacter(CharacterViewModel characterViewModel) + { + ISpriteTexture surface; + + switch (characterViewModel.Palette) + { + case 0: + surface = _surface1; + break; + case 1: + surface = _surface2; + break; + default: + return; + } + + DrawingContext.AppendSprite(new SpriteDrawingContext() + .SpriteTexture(surface) + .Source(characterViewModel.PositionX, characterViewModel.PositionY, characterViewModel.Width, SelectedFont.Info.CharacterHeight) + .MatchSourceSize() + .ScaleSize(2)); + } + } +} diff --git a/OpenKh.Tools.CtdEditor/ViewModels/FontEntryViewModel.cs b/OpenKh.Tools.CtdEditor/ViewModels/FontEntryViewModel.cs index 5bab4df73..e50ef756d 100644 --- a/OpenKh.Tools.CtdEditor/ViewModels/FontEntryViewModel.cs +++ b/OpenKh.Tools.CtdEditor/ViewModels/FontEntryViewModel.cs @@ -1,21 +1,21 @@ -using OpenKh.Bbs; -using OpenKh.Imaging; - -namespace OpenKh.Tools.CtdEditor.ViewModels -{ - public class FontEntryViewModel - { - private readonly FontsArc.Font _font; - - public string Name => _font.Name; - public IImageRead Font1 => _font.Image1; - public IImageRead Font2 => _font.Image2; - public FontInfo Info => _font.Info; - public FontCharacterInfo[] CharactersInfo => _font.CharactersInfo; - - public FontEntryViewModel(FontsArc.Font font) - { - _font = font; - } - } -} +using OpenKh.Bbs; +using OpenKh.Imaging; + +namespace OpenKh.Tools.CtdEditor.ViewModels +{ + public class FontEntryViewModel + { + private readonly FontsArc.Font _font; + + public string Name => _font.Name; + public IImageRead Font1 => _font.Image1; + public IImageRead Font2 => _font.Image2; + public FontInfo Info => _font.Info; + public FontCharacterInfo[] CharactersInfo => _font.CharactersInfo; + + public FontEntryViewModel(FontsArc.Font font) + { + _font = font; + } + } +} diff --git a/OpenKh.Tools.CtdEditor/ViewModels/MainViewModel.cs b/OpenKh.Tools.CtdEditor/ViewModels/MainViewModel.cs index 29cd66793..3d15c5386 100644 --- a/OpenKh.Tools.CtdEditor/ViewModels/MainViewModel.cs +++ b/OpenKh.Tools.CtdEditor/ViewModels/MainViewModel.cs @@ -1,157 +1,157 @@ -using OpenKh.Bbs; -using OpenKh.Common; -using OpenKh.Tools.Common; -using OpenKh.Tools.CtdEditor.Interfaces; -using OpenKh.Tools.CtdEditor.Views; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Windows; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.CtdEditor.ViewModels -{ - public class MainViewModel : BaseNotifyPropertyChanged - { - private static string ApplicationName = Utilities.GetApplicationName(); - private static readonly IEnumerable CtdFilter = FileDialogFilterComposer.Compose() - .AddExtensions("CTD message", "ctd") - .AddAllFiles(); - private static readonly IEnumerable FontArcFilter = FileDialogFilterComposer.Compose() - .AddExtensions("Font archive", "arc") - .AddAllFiles(); - - private readonly CtdDrawHandler _drawHandler = new CtdDrawHandler(); - private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - private string _fileName; - private CtdViewModel _ctdViewModel; - private FontsArc _fonts; - - public string Title => $"{Path.GetFileName(FileName) ?? "untitled"} | {ApplicationName}"; - - private string FileName - { - get => _fileName; - set - { - _fileName = value; - OnPropertyChanged(nameof(Title)); - } - } - - public RelayCommand OpenCommand { get; } - public RelayCommand SaveCommand { get; } - public RelayCommand SaveAsCommand { get; } - public RelayCommand ExitCommand { get; } - public RelayCommand AboutCommand { get; } - - public RelayCommand OpenFontCommand { get; } - public RelayCommand OpenFontEditorCommand { get; } - - public CtdViewModel CtdViewModel - { - get => _ctdViewModel; - private set { _ctdViewModel = value; OnPropertyChanged(); } - } - - public Ctd Ctd - { - get => CtdViewModel?.Ctd; - set => CtdViewModel = new CtdViewModel(_drawHandler, value) - { - Fonts = _fonts - }; - } - - public FontsArc Fonts - { - get => _fonts; - set - { - _fonts = value; - CtdViewModel.Fonts = _fonts; - OnPropertyChanged(nameof(OpenFontEditorCommand)); - } - } - - public MainViewModel() - { - OpenCommand = new RelayCommand(x => - FileDialog.OnOpen(fileName => OpenFile(fileName), CtdFilter), x => true); - - SaveCommand = new RelayCommand(x => - { - if (!string.IsNullOrEmpty(FileName)) - { - SaveFile(FileName, FileName); - } - else - { - SaveAsCommand.Execute(x); - } - }, x => true); - - SaveAsCommand = new RelayCommand(x => - FileDialog.OnSave(fileName => SaveFile(FileName, fileName), CtdFilter), x => true); - - ExitCommand = new RelayCommand(x => - { - Window.Close(); - }, x => true); - - OpenFontCommand = new RelayCommand(x => - FileDialog.OnOpen(fileName => OpenFontFile(fileName), FontArcFilter), - x => CtdViewModel != null); - - OpenFontEditorCommand = new RelayCommand(x => - new FontWindow() - { - DataContext = new FontEditorViewModel(Fonts) - }.ShowDialog(), - x => Fonts != null); - - AboutCommand = new RelayCommand(x => - { - new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); - }, x => true); - - CtdViewModel = new CtdViewModel(_drawHandler); - } - - private bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => - { - if (!Ctd.IsValid(stream)) - { - MessageBox.Show(Window, $"{Path.GetFileName(fileName)} is not a valid CTD file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - return false; - } - - Ctd = Ctd.Read(stream); - FileName = fileName; - return true; - }); - - private void SaveFile(string previousFileName, string fileName) - { - File.Create(fileName).Using(stream => - { - Ctd.Write(stream); - }); - } - - private void OpenFontFile(string fileName) - { - Fonts = File.OpenRead(fileName).Using(stream => - { - if (!Arc.IsValid(stream)) - throw new Exception("Not a valid ARC file"); - - return FontsArc.Read(stream); - }); - } - } -} +using OpenKh.Bbs; +using OpenKh.Common; +using OpenKh.Tools.Common; +using OpenKh.Tools.CtdEditor.Interfaces; +using OpenKh.Tools.CtdEditor.Views; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.CtdEditor.ViewModels +{ + public class MainViewModel : BaseNotifyPropertyChanged + { + private static string ApplicationName = Utilities.GetApplicationName(); + private static readonly IEnumerable CtdFilter = FileDialogFilterComposer.Compose() + .AddExtensions("CTD message", "ctd") + .AddAllFiles(); + private static readonly IEnumerable FontArcFilter = FileDialogFilterComposer.Compose() + .AddExtensions("Font archive", "arc") + .AddAllFiles(); + + private readonly CtdDrawHandler _drawHandler = new CtdDrawHandler(); + private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + private string _fileName; + private CtdViewModel _ctdViewModel; + private FontsArc _fonts; + + public string Title => $"{Path.GetFileName(FileName) ?? "untitled"} | {ApplicationName}"; + + private string FileName + { + get => _fileName; + set + { + _fileName = value; + OnPropertyChanged(nameof(Title)); + } + } + + public RelayCommand OpenCommand { get; } + public RelayCommand SaveCommand { get; } + public RelayCommand SaveAsCommand { get; } + public RelayCommand ExitCommand { get; } + public RelayCommand AboutCommand { get; } + + public RelayCommand OpenFontCommand { get; } + public RelayCommand OpenFontEditorCommand { get; } + + public CtdViewModel CtdViewModel + { + get => _ctdViewModel; + private set { _ctdViewModel = value; OnPropertyChanged(); } + } + + public Ctd Ctd + { + get => CtdViewModel?.Ctd; + set => CtdViewModel = new CtdViewModel(_drawHandler, value) + { + Fonts = _fonts + }; + } + + public FontsArc Fonts + { + get => _fonts; + set + { + _fonts = value; + CtdViewModel.Fonts = _fonts; + OnPropertyChanged(nameof(OpenFontEditorCommand)); + } + } + + public MainViewModel() + { + OpenCommand = new RelayCommand(x => + FileDialog.OnOpen(fileName => OpenFile(fileName), CtdFilter), x => true); + + SaveCommand = new RelayCommand(x => + { + if (!string.IsNullOrEmpty(FileName)) + { + SaveFile(FileName, FileName); + } + else + { + SaveAsCommand.Execute(x); + } + }, x => true); + + SaveAsCommand = new RelayCommand(x => + FileDialog.OnSave(fileName => SaveFile(FileName, fileName), CtdFilter), x => true); + + ExitCommand = new RelayCommand(x => + { + Window.Close(); + }, x => true); + + OpenFontCommand = new RelayCommand(x => + FileDialog.OnOpen(fileName => OpenFontFile(fileName), FontArcFilter), + x => CtdViewModel != null); + + OpenFontEditorCommand = new RelayCommand(x => + new FontWindow() + { + DataContext = new FontEditorViewModel(Fonts) + }.ShowDialog(), + x => Fonts != null); + + AboutCommand = new RelayCommand(x => + { + new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); + }, x => true); + + CtdViewModel = new CtdViewModel(_drawHandler); + } + + private bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => + { + if (!Ctd.IsValid(stream)) + { + MessageBox.Show(Window, $"{Path.GetFileName(fileName)} is not a valid CTD file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + Ctd = Ctd.Read(stream); + FileName = fileName; + return true; + }); + + private void SaveFile(string previousFileName, string fileName) + { + File.Create(fileName).Using(stream => + { + Ctd.Write(stream); + }); + } + + private void OpenFontFile(string fileName) + { + Fonts = File.OpenRead(fileName).Using(stream => + { + if (!Arc.IsValid(stream)) + throw new Exception("Not a valid ARC file"); + + return FontsArc.Read(stream); + }); + } + } +} diff --git a/OpenKh.Tools.CtdEditor/ViewModels/MessageViewModel.cs b/OpenKh.Tools.CtdEditor/ViewModels/MessageViewModel.cs index 93fad8688..2dcd2b7ef 100644 --- a/OpenKh.Tools.CtdEditor/ViewModels/MessageViewModel.cs +++ b/OpenKh.Tools.CtdEditor/ViewModels/MessageViewModel.cs @@ -1,71 +1,71 @@ -using OpenKh.Bbs; -using OpenKh.Bbs.Messages; -using OpenKh.Engine.Renders; -using OpenKh.Tools.CtdEditor.Interfaces; -using System.Linq; -using Xe.Drawing; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; - -namespace OpenKh.Tools.CtdEditor.ViewModels -{ - public class MessageViewModel : BaseNotifyPropertyChanged - { - private readonly IDrawHandler _drawHandler; - private readonly Ctd _ctd; - - public MessageViewModel( - IDrawHandler drawHandler, - Ctd ctd, - Ctd.Message message) - { - _drawHandler = drawHandler; - _ctd = ctd; - Message = message; - - DrawHandler = new RelayCommand(_ => - { - if (FontContext == null) - return; - - var layout = _ctd.Layouts[Message.LayoutIndex]; - _drawHandler.DrawHandler(CtdEncoders.International, FontContext, Message, layout); - _drawHandler.DrawingContext.Flush(); - }); - } - - public Ctd.Message Message { get; } - - public short Id - { - get => Message.Id; - set - { - Message.Id = value; - OnPropertyChanged(nameof(Title)); - } - } - - public string Text - { - get => Message.Text; - set - { - Message.Text = value; - OnPropertyChanged(nameof(Title)); - OnPropertyChanged(nameof(TextDump)); - } - } - - public string TextDump => - string.Join(" ", Message.Data.Select(x => $"{x:X02}")); - - public string Title => $"{Id}: {Text}"; - - public ISpriteDrawing DrawingContext => _drawHandler.DrawingContext; - public RelayCommand DrawHandler { get; } - public FontsArc.Font FontContext { get; set; } - - public override string ToString() => Title; - } -} +using OpenKh.Bbs; +using OpenKh.Bbs.Messages; +using OpenKh.Engine.Renders; +using OpenKh.Tools.CtdEditor.Interfaces; +using System.Linq; +using Xe.Drawing; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; + +namespace OpenKh.Tools.CtdEditor.ViewModels +{ + public class MessageViewModel : BaseNotifyPropertyChanged + { + private readonly IDrawHandler _drawHandler; + private readonly Ctd _ctd; + + public MessageViewModel( + IDrawHandler drawHandler, + Ctd ctd, + Ctd.Message message) + { + _drawHandler = drawHandler; + _ctd = ctd; + Message = message; + + DrawHandler = new RelayCommand(_ => + { + if (FontContext == null) + return; + + var layout = _ctd.Layouts[Message.LayoutIndex]; + _drawHandler.DrawHandler(CtdEncoders.International, FontContext, Message, layout); + _drawHandler.DrawingContext.Flush(); + }); + } + + public Ctd.Message Message { get; } + + public short Id + { + get => Message.Id; + set + { + Message.Id = value; + OnPropertyChanged(nameof(Title)); + } + } + + public string Text + { + get => Message.Text; + set + { + Message.Text = value; + OnPropertyChanged(nameof(Title)); + OnPropertyChanged(nameof(TextDump)); + } + } + + public string TextDump => + string.Join(" ", Message.Data.Select(x => $"{x:X02}")); + + public string Title => $"{Id}: {Text}"; + + public ISpriteDrawing DrawingContext => _drawHandler.DrawingContext; + public RelayCommand DrawHandler { get; } + public FontsArc.Font FontContext { get; set; } + + public override string ToString() => Title; + } +} diff --git a/OpenKh.Tools.CtdEditor/Views/CtdView.xaml.cs b/OpenKh.Tools.CtdEditor/Views/CtdView.xaml.cs index 3654d98b5..31dc33be2 100644 --- a/OpenKh.Tools.CtdEditor/Views/CtdView.xaml.cs +++ b/OpenKh.Tools.CtdEditor/Views/CtdView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace OpenKh.Tools.CtdEditor.Views -{ - /// - /// Interaction logic for CtdView.xaml - /// - public partial class CtdView : UserControl - { - public CtdView() - { - InitializeComponent(); - } - } -} +using System.Windows.Controls; + +namespace OpenKh.Tools.CtdEditor.Views +{ + /// + /// Interaction logic for CtdView.xaml + /// + public partial class CtdView : UserControl + { + public CtdView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.CtdEditor/Views/FontWindow.xaml.cs b/OpenKh.Tools.CtdEditor/Views/FontWindow.xaml.cs index addfe54c2..dd4fa99dc 100644 --- a/OpenKh.Tools.CtdEditor/Views/FontWindow.xaml.cs +++ b/OpenKh.Tools.CtdEditor/Views/FontWindow.xaml.cs @@ -1,27 +1,27 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace OpenKh.Tools.CtdEditor.Views -{ - /// - /// Interaction logic for FontWindow.xaml - /// - public partial class FontWindow : Window - { - public FontWindow() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace OpenKh.Tools.CtdEditor.Views +{ + /// + /// Interaction logic for FontWindow.xaml + /// + public partial class FontWindow : Window + { + public FontWindow() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.CtdEditor/Views/MainWindow.xaml.cs b/OpenKh.Tools.CtdEditor/Views/MainWindow.xaml.cs index 6bb792371..2cf634403 100644 --- a/OpenKh.Tools.CtdEditor/Views/MainWindow.xaml.cs +++ b/OpenKh.Tools.CtdEditor/Views/MainWindow.xaml.cs @@ -1,17 +1,17 @@ -using OpenKh.Tools.CtdEditor.ViewModels; -using System.Windows; - -namespace OpenKh.Tools.CtdEditor.Views -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); - DataContext = new MainViewModel(); - } - } -} +using OpenKh.Tools.CtdEditor.ViewModels; +using System.Windows; + +namespace OpenKh.Tools.CtdEditor.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + DataContext = new MainViewModel(); + } + } +} diff --git a/OpenKh.Tools.DpdViewer/App.xaml.cs b/OpenKh.Tools.DpdViewer/App.xaml.cs index 9db5f3c07..97a5d1a35 100644 --- a/OpenKh.Tools.DpdViewer/App.xaml.cs +++ b/OpenKh.Tools.DpdViewer/App.xaml.cs @@ -1,11 +1,11 @@ -using System.Windows; - -namespace OpenKh.Tools.DpdViewer -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} +using System.Windows; + +namespace OpenKh.Tools.DpdViewer +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/OpenKh.Tools.DpdViewer/Models/TexturesModel.cs b/OpenKh.Tools.DpdViewer/Models/TexturesModel.cs index 104013806..ce242950a 100644 --- a/OpenKh.Tools.DpdViewer/Models/TexturesModel.cs +++ b/OpenKh.Tools.DpdViewer/Models/TexturesModel.cs @@ -1,22 +1,22 @@ -using OpenKh.Imaging; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using Xe.Tools; - -namespace OpenKh.Tools.DpdViewer.Models -{ - public class TextureModel : BaseNotifyPropertyChanged - { - public TextureModel(IImageRead image) - { - MasterImage = image; - } - - public IImageRead MasterImage { get; } - - public string DisplayName => $"{MasterImage.Size.Width}x{MasterImage.Size.Height}"; - - public BitmapSource Image => BitmapSource.Create(MasterImage.Size.Width, MasterImage.Size.Height, - 96.0, 96.0, PixelFormats.Bgra32, null, MasterImage.ToBgra32(), MasterImage.Size.Width * 4); - } -} +using OpenKh.Imaging; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using Xe.Tools; + +namespace OpenKh.Tools.DpdViewer.Models +{ + public class TextureModel : BaseNotifyPropertyChanged + { + public TextureModel(IImageRead image) + { + MasterImage = image; + } + + public IImageRead MasterImage { get; } + + public string DisplayName => $"{MasterImage.Size.Width}x{MasterImage.Size.Height}"; + + public BitmapSource Image => BitmapSource.Create(MasterImage.Size.Width, MasterImage.Size.Height, + 96.0, 96.0, PixelFormats.Bgra32, null, MasterImage.ToBgra32(), MasterImage.Size.Width * 4); + } +} diff --git a/OpenKh.Tools.DpdViewer/Properties/AssemblyInfo.cs b/OpenKh.Tools.DpdViewer/Properties/AssemblyInfo.cs index df263cb44..ed39486c6 100644 --- a/OpenKh.Tools.DpdViewer/Properties/AssemblyInfo.cs +++ b/OpenKh.Tools.DpdViewer/Properties/AssemblyInfo.cs @@ -1,29 +1,29 @@ -using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Windows; - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -//In order to begin building localizable applications, set -//CultureYouAreCodingWith in your .csproj file -//inside a . For example, if you are using US english -//in your source files, set the to en-US. Then uncomment -//the NeutralResourceLanguage attribute below. Update the "en-US" in -//the line below to match the UICulture setting in the project file. - -//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/OpenKh.Tools.DpdViewer/ViewModels/DpdViewModel.cs b/OpenKh.Tools.DpdViewer/ViewModels/DpdViewModel.cs index a0ac314d7..70a1ed2f6 100644 --- a/OpenKh.Tools.DpdViewer/ViewModels/DpdViewModel.cs +++ b/OpenKh.Tools.DpdViewer/ViewModels/DpdViewModel.cs @@ -1,101 +1,101 @@ -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Windows; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.DpdViewer.ViewModels -{ - public class DpdViewModel : BaseNotifyPropertyChanged - { - private Dpd dpd; - - private static readonly List Filters = FileDialogFilterComposer.Compose().AddExtensions("DPD effect", "dpd"); - - public DpdViewModel() - { - OpenCommand = new RelayCommand(x => - { - FileDialog.OnOpen(fileName => - { - using (var stream = File.OpenRead(fileName)) - { - FileName = fileName; - Dpd = new Dpd(stream); - - OnPropertyChanged(nameof(SaveCommand)); - OnPropertyChanged(nameof(SaveAsCommand)); - } - }, Filters); - }, x => true); - - SaveCommand = new RelayCommand(x => - { - if (!string.IsNullOrEmpty(FileName)) - { - using (var stream = File.Open(FileName, FileMode.Create)) - { - throw new NotImplementedException(); - } - } - else - { - SaveAsCommand.Execute(x); - } - }, x => true); - - SaveAsCommand = new RelayCommand(x => - { - FileDialog.OnSave(fileName => - { - using (var stream = File.Open(fileName, FileMode.Create)) - { - throw new NotImplementedException(); - } - }, Filters); - }, x => true); - - ExitCommand = new RelayCommand(x => - { - Window.Close(); - }, x => true); - - AboutCommand = new RelayCommand(x => - { - new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); - }, x => true); - } - - private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - - public string FileName { get; set; } - - public RelayCommand OpenCommand { get; set; } - - public RelayCommand SaveCommand { get; set; } - - public RelayCommand SaveAsCommand { get; set; } - - public RelayCommand ExitCommand { get; set; } - - public RelayCommand AboutCommand { get; set; } - - public Dpd Dpd - { - get => dpd; - set - { - dpd = value; - Textures = new TexturesViewModel(dpd.Textures); - OnPropertyChanged(nameof(Textures)); - } - } - - public TexturesViewModel Textures { get; private set; } - } -} +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.DpdViewer.ViewModels +{ + public class DpdViewModel : BaseNotifyPropertyChanged + { + private Dpd dpd; + + private static readonly List Filters = FileDialogFilterComposer.Compose().AddExtensions("DPD effect", "dpd"); + + public DpdViewModel() + { + OpenCommand = new RelayCommand(x => + { + FileDialog.OnOpen(fileName => + { + using (var stream = File.OpenRead(fileName)) + { + FileName = fileName; + Dpd = new Dpd(stream); + + OnPropertyChanged(nameof(SaveCommand)); + OnPropertyChanged(nameof(SaveAsCommand)); + } + }, Filters); + }, x => true); + + SaveCommand = new RelayCommand(x => + { + if (!string.IsNullOrEmpty(FileName)) + { + using (var stream = File.Open(FileName, FileMode.Create)) + { + throw new NotImplementedException(); + } + } + else + { + SaveAsCommand.Execute(x); + } + }, x => true); + + SaveAsCommand = new RelayCommand(x => + { + FileDialog.OnSave(fileName => + { + using (var stream = File.Open(fileName, FileMode.Create)) + { + throw new NotImplementedException(); + } + }, Filters); + }, x => true); + + ExitCommand = new RelayCommand(x => + { + Window.Close(); + }, x => true); + + AboutCommand = new RelayCommand(x => + { + new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); + }, x => true); + } + + private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + + public string FileName { get; set; } + + public RelayCommand OpenCommand { get; set; } + + public RelayCommand SaveCommand { get; set; } + + public RelayCommand SaveAsCommand { get; set; } + + public RelayCommand ExitCommand { get; set; } + + public RelayCommand AboutCommand { get; set; } + + public Dpd Dpd + { + get => dpd; + set + { + dpd = value; + Textures = new TexturesViewModel(dpd.Textures); + OnPropertyChanged(nameof(Textures)); + } + } + + public TexturesViewModel Textures { get; private set; } + } +} diff --git a/OpenKh.Tools.DpdViewer/ViewModels/TexturesViewModel.cs b/OpenKh.Tools.DpdViewer/ViewModels/TexturesViewModel.cs index 420301977..35d0b51f6 100644 --- a/OpenKh.Tools.DpdViewer/ViewModels/TexturesViewModel.cs +++ b/OpenKh.Tools.DpdViewer/ViewModels/TexturesViewModel.cs @@ -1,27 +1,27 @@ -using OpenKh.Kh2; -using OpenKh.Tools.DpdViewer.Models; -using System.Collections.Generic; -using System.Linq; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.DpdViewer.ViewModels -{ - public class TexturesViewModel : GenericListModel - { - public TexturesViewModel() : - this(null) - { } - - public TexturesViewModel(IEnumerable textures) : - //base(textures.Select(x => new TextureModel(x))) - base(null) - { - - } - - protected override TextureModel OnNewItem() - { - throw new System.NotImplementedException(); - } - } -} +using OpenKh.Kh2; +using OpenKh.Tools.DpdViewer.Models; +using System.Collections.Generic; +using System.Linq; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.DpdViewer.ViewModels +{ + public class TexturesViewModel : GenericListModel + { + public TexturesViewModel() : + this(null) + { } + + public TexturesViewModel(IEnumerable textures) : + //base(textures.Select(x => new TextureModel(x))) + base(null) + { + + } + + protected override TextureModel OnNewItem() + { + throw new System.NotImplementedException(); + } + } +} diff --git a/OpenKh.Tools.DpdViewer/Views/DpdView.xaml.cs b/OpenKh.Tools.DpdViewer/Views/DpdView.xaml.cs index 13c540c7d..63092ac34 100644 --- a/OpenKh.Tools.DpdViewer/Views/DpdView.xaml.cs +++ b/OpenKh.Tools.DpdViewer/Views/DpdView.xaml.cs @@ -1,29 +1,29 @@ -using OpenKh.Tools.DpdViewer.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace OpenKh.Tools.DpdViewer.Views -{ - /// - /// Interaction logic for DpdView.xaml - /// - public partial class DpdView : Window - { - public DpdView() - { - InitializeComponent(); - DataContext = new DpdViewModel(); - } - } -} +using OpenKh.Tools.DpdViewer.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace OpenKh.Tools.DpdViewer.Views +{ + /// + /// Interaction logic for DpdView.xaml + /// + public partial class DpdView : Window + { + public DpdView() + { + InitializeComponent(); + DataContext = new DpdViewModel(); + } + } +} diff --git a/OpenKh.Tools.DpdViewer/Views/TexturesView.xaml.cs b/OpenKh.Tools.DpdViewer/Views/TexturesView.xaml.cs index 4adee17e7..d715f4473 100644 --- a/OpenKh.Tools.DpdViewer/Views/TexturesView.xaml.cs +++ b/OpenKh.Tools.DpdViewer/Views/TexturesView.xaml.cs @@ -1,28 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace OpenKh.Tools.DpdViewer.Views -{ - /// - /// Interaction logic for TexturesView.xaml - /// - public partial class TexturesView : UserControl - { - public TexturesView() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace OpenKh.Tools.DpdViewer.Views +{ + /// + /// Interaction logic for TexturesView.xaml + /// + public partial class TexturesView : UserControl + { + public TexturesView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.EpdEditor/AddDropParam.cs b/OpenKh.Tools.EpdEditor/AddDropParam.cs index ad3e99e7f..e1c5cc1b3 100644 --- a/OpenKh.Tools.EpdEditor/AddDropParam.cs +++ b/OpenKh.Tools.EpdEditor/AddDropParam.cs @@ -1,27 +1,27 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; - -namespace OpenKh.Tools.EpdEditor -{ - public partial class AddDropParam : UserControl - { - public AddDropParam() - { - InitializeComponent(); - } - - private void AddDropControl_Click(object sender, EventArgs e) - { - DropControl cont = new DropControl(); - cont.DropGBox.Text = "Prize " + this.Parent.Controls.Count; - this.Parent.Controls.Add(cont); - this.Parent.Controls.Add(new AddDropParam()); - this.Parent.Controls.Remove(this); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace OpenKh.Tools.EpdEditor +{ + public partial class AddDropParam : UserControl + { + public AddDropParam() + { + InitializeComponent(); + } + + private void AddDropControl_Click(object sender, EventArgs e) + { + DropControl cont = new DropControl(); + cont.DropGBox.Text = "Prize " + this.Parent.Controls.Count; + this.Parent.Controls.Add(cont); + this.Parent.Controls.Add(new AddDropParam()); + this.Parent.Controls.Remove(this); + } + } +} diff --git a/OpenKh.Tools.EpdEditor/AddExtraParam.cs b/OpenKh.Tools.EpdEditor/AddExtraParam.cs index c29771bfc..1d6df85df 100644 --- a/OpenKh.Tools.EpdEditor/AddExtraParam.cs +++ b/OpenKh.Tools.EpdEditor/AddExtraParam.cs @@ -1,28 +1,28 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; - -namespace OpenKh.Tools.EpdEditor -{ - public partial class AddExtraParam : UserControl - { - public AddExtraParam() - { - InitializeComponent(); - } - - private void AddExtraControl_Click(object sender, EventArgs e) - { - ExtraControl cont = new ExtraControl(); - cont.ExtraParamGBox.Text = "Extra Param " + this.Parent.Controls.Count; - cont.ParameterName.Text = "Parameter" + this.Parent.Controls.Count; - this.Parent.Controls.Add(cont); - this.Parent.Controls.Add(new AddExtraParam()); - this.Parent.Controls.Remove(this); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace OpenKh.Tools.EpdEditor +{ + public partial class AddExtraParam : UserControl + { + public AddExtraParam() + { + InitializeComponent(); + } + + private void AddExtraControl_Click(object sender, EventArgs e) + { + ExtraControl cont = new ExtraControl(); + cont.ExtraParamGBox.Text = "Extra Param " + this.Parent.Controls.Count; + cont.ParameterName.Text = "Parameter" + this.Parent.Controls.Count; + this.Parent.Controls.Add(cont); + this.Parent.Controls.Add(new AddExtraParam()); + this.Parent.Controls.Remove(this); + } + } +} diff --git a/OpenKh.Tools.EpdEditor/AddTechParam.cs b/OpenKh.Tools.EpdEditor/AddTechParam.cs index d2d787db3..3805d651b 100644 --- a/OpenKh.Tools.EpdEditor/AddTechParam.cs +++ b/OpenKh.Tools.EpdEditor/AddTechParam.cs @@ -1,27 +1,27 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; - -namespace OpenKh.Tools.EpdEditor -{ - public partial class AddTechParam : UserControl - { - public AddTechParam() - { - InitializeComponent(); - } - - private void AddTechControlButton_Click(object sender, EventArgs e) - { - TechControl cont = new TechControl(); - cont.TechParamGBox.Text = "Parameter " + this.Parent.Controls.Count; - this.Parent.Controls.Add(cont); - this.Parent.Controls.Add(new AddTechParam()); - this.Parent.Controls.Remove(this); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace OpenKh.Tools.EpdEditor +{ + public partial class AddTechParam : UserControl + { + public AddTechParam() + { + InitializeComponent(); + } + + private void AddTechControlButton_Click(object sender, EventArgs e) + { + TechControl cont = new TechControl(); + cont.TechParamGBox.Text = "Parameter " + this.Parent.Controls.Count; + this.Parent.Controls.Add(cont); + this.Parent.Controls.Add(new AddTechParam()); + this.Parent.Controls.Remove(this); + } + } +} diff --git a/OpenKh.Tools.EpdEditor/DropControl.cs b/OpenKh.Tools.EpdEditor/DropControl.cs index 0fbc2377a..48d11ea84 100644 --- a/OpenKh.Tools.EpdEditor/DropControl.cs +++ b/OpenKh.Tools.EpdEditor/DropControl.cs @@ -1,18 +1,18 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; - -namespace OpenKh.Tools.EpdEditor -{ - public partial class DropControl : UserControl - { - public DropControl() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace OpenKh.Tools.EpdEditor +{ + public partial class DropControl : UserControl + { + public DropControl() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.EpdEditor/ExtraControl.cs b/OpenKh.Tools.EpdEditor/ExtraControl.cs index c3d932c9d..e5567a8fe 100644 --- a/OpenKh.Tools.EpdEditor/ExtraControl.cs +++ b/OpenKh.Tools.EpdEditor/ExtraControl.cs @@ -1,18 +1,18 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; - -namespace OpenKh.Tools.EpdEditor -{ - public partial class ExtraControl : UserControl - { - public ExtraControl() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace OpenKh.Tools.EpdEditor +{ + public partial class ExtraControl : UserControl + { + public ExtraControl() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.EpdEditor/MainForm.cs b/OpenKh.Tools.EpdEditor/MainForm.cs index 45b9dfdc3..5f6e09fd0 100644 --- a/OpenKh.Tools.EpdEditor/MainForm.cs +++ b/OpenKh.Tools.EpdEditor/MainForm.cs @@ -1,280 +1,281 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.IO; -using OpenKh.Bbs; - -namespace OpenKh.Tools.EpdEditor -{ - public partial class EPDForm : Form - { - public EPDForm() - { - InitializeComponent(); - } - - Epd epd = new Epd(); - Stream epdFile; - - private void UpdateEPDData() - { - // General Parameters - Epd.StatusAilment ailments = Epd.GetStatusAilment(epd); - StatusAilment_checkbox_01.Checked = ailments.bFly; - StatusAilment_checkbox_02.Checked = ailments.bSmallDamageReaction; - StatusAilment_checkbox_03.Checked = ailments.bSmallDamageReactionOnly; - StatusAilment_checkbox_04.Checked = ailments.bHitback; - StatusAilment_checkbox_05.Checked = ailments.bPoison; - StatusAilment_checkbox_06.Checked = ailments.bSlow; - StatusAilment_checkbox_07.Checked = ailments.bStop; - StatusAilment_checkbox_08.Checked = ailments.bBind; - StatusAilment_checkbox_09.Checked = ailments.bFaint; - StatusAilment_checkbox_10.Checked = ailments.bFreeze; - StatusAilment_checkbox_11.Checked = ailments.bBurn; - StatusAilment_checkbox_12.Checked = ailments.bConfuse; - StatusAilment_checkbox_13.Checked = ailments.bBlind; - StatusAilment_checkbox_14.Checked = ailments.bDeath; - StatusAilment_checkbox_15.Checked = ailments.bZeroGravity; - StatusAilment_checkbox_16.Checked = ailments.bMini; - StatusAilment_checkbox_17.Checked = ailments.bMagnet; - StatusAilment_checkbox_18.Checked = ailments.bDegen; - StatusAilment_checkbox_19.Checked = ailments.bSleep; - - MaxHealthBox.Text = epd.generalParameters.Health.ToString(); - SizeBox.Text = epd.generalParameters.Size.ToString(); - EXPMultiplierBox.Text = epd.generalParameters.ExperienceMultiplier.ToString(); - PhysicalDamageBox.Text = epd.generalParameters.PhysicalDamageMultiplier.ToString(); - FireDamageBox.Text = epd.generalParameters.FireDamageMultiplier.ToString(); - IceDamageBox.Text = epd.generalParameters.IceDamageMultiplier.ToString(); - ThunderDamageBox.Text = epd.generalParameters.ThunderDamageMultiplier.ToString(); - DarknessDamageBox.Text = epd.generalParameters.DarknessDamageMultiplier.ToString(); - SpecialDamageBox.Text = epd.generalParameters.NonElementalDamageMultiplier.ToString(); - - // Animations - int i = 0; - foreach(Control con in AnimationLayoutPanel.Controls) - { - con.Text = new String(epd.AnimationList[i]); - i++; - } - - // Other Parameters - NumericDamageCeiling.Value = epd.otherParameters.DamageCeiling; - NumericDamageFloor.Value = epd.otherParameters.DamageFloor; - NumericWeight.Text = epd.otherParameters.fWeight.ToString(); - - Epd.EffectivenessFlag flag = Epd.GetEffectivenessFlag(epd); - NumericPoison.Value = flag.Poison; - NumericStop.Value = flag.Stop; - NumericBind.Value = flag.Bind; - NumericFaint.Value = flag.Faint; - NumericBlind.Value = flag.Blind; - NumericMini.Value = flag.Mini; - - NumericPrizeboxProbability.Value = epd.otherParameters.PrizeBoxProbability; - - - // Technique Parameters - for (int t = 0; t < epd.techniqueParameters.Count; t++) - { - TechControl techCon = new TechControl(); - - techCon.TechParamGBox.Text = "Parameter " + (t+1); - techCon.TechniquePower.Text = epd.techniqueParameters[t].TechniquePowerCorrection.ToString(); - techCon.NumericTechniqueNumber.Value = epd.techniqueParameters[t].TechniqueNumber; - techCon.AttackKind.SelectedIndex = (epd.techniqueParameters[t].TechniqueKind > 0x38 ? 0 : epd.techniqueParameters[t].TechniqueKind); - techCon.AttackAttribute.SelectedIndex = epd.techniqueParameters[t].TechniqueAttribute % 8; - techCon.NumericSuccessRate.Value = epd.techniqueParameters[t].SuccessRate; - TechniqueLayout.Controls.Add(techCon); - } - - AddTechParam techParamPlus = new AddTechParam(); - TechniqueLayout.Controls.Add(techParamPlus); - - // Drop Parameters - for (int d = 0; d < epd.dropParameters.Count; d++) - { - DropControl dropCon = new DropControl(); - - dropCon.DropGBox.Text = "Drop Item " + (d+1); - dropCon.ItemComboBox.SelectedIndex = (int)epd.dropParameters[d].ItemIndex; - dropCon.NumericItemCount.Value = epd.dropParameters[d].ItemCount; - dropCon.NumericItemProbability.Value = epd.dropParameters[d].Probability; - DroppedLayout.Controls.Add(dropCon); - } - - AddDropParam dropParamPlus = new AddDropParam(); - DroppedLayout.Controls.Add(dropParamPlus); - - // Extra Parameters - for (int e = 0; e < epd.extraParameters.Count; e++) - { - ExtraControl extraCon = new ExtraControl(); - - extraCon.ExtraParamGBox.Text = "Extra Param " + (e+1); - extraCon.ParameterName.Text = epd.extraParameters[e].ParameterName; - extraCon.ParameterValue.Text = epd.extraParameters[e].ParameterValue.ToString(); - ExtraLayout.Controls.Add(extraCon); - } - - AddExtraParam extraParamPlus = new AddExtraParam(); - ExtraLayout.Controls.Add(extraParamPlus); - } - - private void UpdateWriteInfo() - { - Epd.Header head = epd.header; - epd = new Epd(); - - epd.header = head; - - // General Parameters - epd.generalParameters = new Epd.GeneralParameters(); - epd.generalParameters.StatusAilmentsFlag = - Epd.GetStatusAilmentFromStates( - StatusAilment_checkbox_01.Checked, StatusAilment_checkbox_02.Checked, StatusAilment_checkbox_03.Checked, StatusAilment_checkbox_04.Checked, StatusAilment_checkbox_05.Checked, - StatusAilment_checkbox_06.Checked, StatusAilment_checkbox_07.Checked, StatusAilment_checkbox_08.Checked, StatusAilment_checkbox_09.Checked, StatusAilment_checkbox_10.Checked, - StatusAilment_checkbox_11.Checked, StatusAilment_checkbox_12.Checked, StatusAilment_checkbox_13.Checked, StatusAilment_checkbox_14.Checked, StatusAilment_checkbox_15.Checked, - StatusAilment_checkbox_16.Checked, StatusAilment_checkbox_17.Checked, StatusAilment_checkbox_18.Checked, StatusAilment_checkbox_19.Checked); - epd.generalParameters.Health = float.Parse(MaxHealthBox.Text); - epd.generalParameters.ExperienceMultiplier = float.Parse(EXPMultiplierBox.Text); - epd.generalParameters.Size = uint.Parse(SizeBox.Text, System.Globalization.NumberStyles.Integer); - epd.generalParameters.PhysicalDamageMultiplier = float.Parse(PhysicalDamageBox.Text); - epd.generalParameters.FireDamageMultiplier = float.Parse(FireDamageBox.Text); - epd.generalParameters.IceDamageMultiplier = float.Parse(IceDamageBox.Text); - epd.generalParameters.ThunderDamageMultiplier = float.Parse(ThunderDamageBox.Text); - epd.generalParameters.DarknessDamageMultiplier = float.Parse(DarknessDamageBox.Text); - epd.generalParameters.NonElementalDamageMultiplier = float.Parse(SpecialDamageBox.Text); - - // Anim list - epd.AnimationList = new List(); - foreach(TextBox txt in AnimationLayoutPanel.Controls) - { - char[] arr = new char[4]; - if(txt.Text != "") - { - arr[0] = txt.Text.ToCharArray()[0]; - arr[1] = txt.Text.ToCharArray()[1]; - arr[2] = txt.Text.ToCharArray()[2]; - arr[3] = (char)0; - } - epd.AnimationList.Add(arr); - } - - // Other Parameters - epd.otherParameters = new Epd.OtherParameters(); - epd.otherParameters.DamageCeiling = Decimal.ToUInt16(NumericDamageCeiling.Value); - epd.otherParameters.DamageFloor = Decimal.ToUInt16(NumericDamageFloor.Value); - epd.otherParameters.fWeight = float.Parse(NumericWeight.Text); - epd.otherParameters.EffectivenessFlag = - Epd.GetEffectivenessFlagFromStates(decimal.ToUInt32(NumericPoison.Value), decimal.ToUInt32(NumericStop.Value), decimal.ToUInt32(NumericBind.Value), - decimal.ToUInt32(NumericFaint.Value), decimal.ToUInt32(NumericBlind.Value), decimal.ToUInt32(NumericMini.Value)); - epd.otherParameters.PrizeBoxProbability = decimal.ToSByte(NumericPrizeboxProbability.Value); - epd.otherParameters.padding = new byte[3]; - epd.otherParameters.TechniqueParameterCount = (uint)(TechniqueLayout.Controls.Count - 1 < 0 ? 0 : TechniqueLayout.Controls.Count - 1); - epd.otherParameters.TechniqueParameterOffset = 0xA8; - epd.otherParameters.DropItemsCount = (uint)(DroppedLayout.Controls.Count - 1 < 0 ? 0 : DroppedLayout.Controls.Count - 1); - epd.otherParameters.DropItemsOffset = 0xA8 + (epd.otherParameters.TechniqueParameterCount * 8); - epd.otherParameters.ExtraParametersCount = (uint)(ExtraLayout.Controls.Count - 1 < 0 ? 0 : ExtraLayout.Controls.Count - 1); - epd.otherParameters.ExtraParametersOffset = 0xA8 + ((epd.otherParameters.TechniqueParameterCount + epd.otherParameters.DropItemsCount) * 8); - - // Technique Parameters - epd.techniqueParameters = new List(); - try - { - foreach (TechControl tech in TechniqueLayout.Controls) - { - Epd.TechniqueParameters param = new Epd.TechniqueParameters(); - param.TechniquePowerCorrection = float.Parse(tech.TechniquePower.Text); - param.TechniqueNumber = decimal.ToByte(tech.NumericTechniqueNumber.Value); - param.TechniqueKind = (byte)tech.AttackKind.SelectedIndex; - param.TechniqueAttribute = (byte)tech.AttackAttribute.SelectedIndex; - param.SuccessRate = decimal.ToByte(tech.NumericSuccessRate.Value); - epd.techniqueParameters.Add(param); - } - } - catch (InvalidCastException) - { - Console.WriteLine("Cannot convert to this type."); - } - - // Drop Parameters - epd.dropParameters = new List(); - try - { - foreach (DropControl drop in DroppedLayout.Controls) - { - Epd.DropParameters param = new Epd.DropParameters(); - param.ItemIndex = (uint)drop.ItemComboBox.SelectedIndex; - param.ItemCount = decimal.ToUInt16(drop.NumericItemCount.Value); - param.Probability = decimal.ToUInt16(drop.NumericItemProbability.Value); - epd.dropParameters.Add(param); - } - } - catch (InvalidCastException) - { - Console.WriteLine("Cannot convert to this type."); - } - - // Extra Parameters - epd.extraParameters = new List(); - try - { - foreach (ExtraControl extra in ExtraLayout.Controls) - { - Epd.ExtraParameters param = new Epd.ExtraParameters(); - param.ParameterName = extra.ParameterName.Text; - param.ParameterValue = float.Parse(extra.ParameterValue.Text); - epd.extraParameters.Add(param); - } - } - catch (InvalidCastException) - { - Console.WriteLine("Cannot convert to this type."); - } - } - - private void LoadEPDButton_Click(object sender, EventArgs e) - { - OpenFileDialog dialog = new OpenFileDialog(); - dialog.Filter = "Enemy Parameter Data files (*.epd)|*.epd|All files (*.*)|*.*"; - DialogResult result = dialog.ShowDialog(); - - if(result == DialogResult.OK) - { - TechniqueLayout.Controls.Clear(); - DroppedLayout.Controls.Clear(); - ExtraLayout.Controls.Clear(); - if (epdFile != null) epdFile.Close(); - epdFile = File.OpenRead(dialog.FileName); - FileLoadedLabel.Text = "File currently loaded: " + dialog.FileName; - epd = Epd.Read(epdFile); - UpdateEPDData(); - SaveEPDButton.Enabled = true; - } - } - - private void SaveEPDButton_Click(object sender, EventArgs e) - { - SaveFileDialog dialog = new SaveFileDialog(); - dialog.Filter = "Enemy Parameter Data files (*.epd)|*.epd|All files (*.*)|*.*"; - DialogResult result = dialog.ShowDialog(); - - if (result == DialogResult.OK) - { - Stream epdOut = File.OpenWrite(dialog.FileName); - UpdateWriteInfo(); - Epd.Write(epdOut, epd); - epdOut.Close(); - } - - MessageBox.Show("File saved successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.IO; +using OpenKh.Bbs; + +namespace OpenKh.Tools.EpdEditor +{ + public partial class EPDForm : Form + { + public EPDForm() + { + InitializeComponent(); + } + + Epd epd = new Epd(); + Stream epdFile; + + private void UpdateEPDData() + { + // General Parameters + Epd.StatusAilment ailments = Epd.GetStatusAilment(epd); + StatusAilment_checkbox_01.Checked = ailments.bFly; + StatusAilment_checkbox_02.Checked = ailments.bSmallDamageReaction; + StatusAilment_checkbox_03.Checked = ailments.bSmallDamageReactionOnly; + StatusAilment_checkbox_04.Checked = ailments.bHitback; + StatusAilment_checkbox_05.Checked = ailments.bPoison; + StatusAilment_checkbox_06.Checked = ailments.bSlow; + StatusAilment_checkbox_07.Checked = ailments.bStop; + StatusAilment_checkbox_08.Checked = ailments.bBind; + StatusAilment_checkbox_09.Checked = ailments.bFaint; + StatusAilment_checkbox_10.Checked = ailments.bFreeze; + StatusAilment_checkbox_11.Checked = ailments.bBurn; + StatusAilment_checkbox_12.Checked = ailments.bConfuse; + StatusAilment_checkbox_13.Checked = ailments.bBlind; + StatusAilment_checkbox_14.Checked = ailments.bDeath; + StatusAilment_checkbox_15.Checked = ailments.bZeroGravity; + StatusAilment_checkbox_16.Checked = ailments.bMini; + StatusAilment_checkbox_17.Checked = ailments.bMagnet; + StatusAilment_checkbox_18.Checked = ailments.bDegen; + StatusAilment_checkbox_19.Checked = ailments.bSleep; + + MaxHealthBox.Text = epd.generalParameters.Health.ToString(); + SizeBox.Text = epd.generalParameters.Size.ToString(); + EXPMultiplierBox.Text = epd.generalParameters.ExperienceMultiplier.ToString(); + PhysicalDamageBox.Text = epd.generalParameters.PhysicalDamageMultiplier.ToString(); + FireDamageBox.Text = epd.generalParameters.FireDamageMultiplier.ToString(); + IceDamageBox.Text = epd.generalParameters.IceDamageMultiplier.ToString(); + ThunderDamageBox.Text = epd.generalParameters.ThunderDamageMultiplier.ToString(); + DarknessDamageBox.Text = epd.generalParameters.DarknessDamageMultiplier.ToString(); + SpecialDamageBox.Text = epd.generalParameters.NonElementalDamageMultiplier.ToString(); + + // Animations + int i = 0; + foreach (Control con in AnimationLayoutPanel.Controls) + { + con.Text = new String(epd.AnimationList[i]); + i++; + } + + // Other Parameters + NumericDamageCeiling.Value = epd.otherParameters.DamageCeiling; + NumericDamageFloor.Value = epd.otherParameters.DamageFloor; + NumericWeight.Text = epd.otherParameters.fWeight.ToString(); + + Epd.EffectivenessFlag flag = Epd.GetEffectivenessFlag(epd); + NumericPoison.Value = flag.Poison; + NumericStop.Value = flag.Stop; + NumericBind.Value = flag.Bind; + NumericFaint.Value = flag.Faint; + NumericBlind.Value = flag.Blind; + NumericMini.Value = flag.Mini; + + NumericPrizeboxProbability.Value = epd.otherParameters.PrizeBoxProbability; + + + // Technique Parameters + for (int t = 0; t < epd.techniqueParameters.Count; t++) + { + TechControl techCon = new TechControl(); + + techCon.TechParamGBox.Text = "Parameter " + (t + 1); + techCon.TechniquePower.Text = epd.techniqueParameters[t].TechniquePowerCorrection.ToString(); + techCon.NumericTechniqueNumber.Value = epd.techniqueParameters[t].TechniqueNumber; + techCon.AttackKind.SelectedIndex = (epd.techniqueParameters[t].TechniqueKind > 0x38 ? 0 : epd.techniqueParameters[t].TechniqueKind); + techCon.AttackAttribute.SelectedIndex = epd.techniqueParameters[t].TechniqueAttribute % 8; + techCon.NumericSuccessRate.Value = epd.techniqueParameters[t].SuccessRate; + TechniqueLayout.Controls.Add(techCon); + } + + AddTechParam techParamPlus = new AddTechParam(); + TechniqueLayout.Controls.Add(techParamPlus); + + // Drop Parameters + for (int d = 0; d < epd.dropParameters.Count; d++) + { + DropControl dropCon = new DropControl(); + + dropCon.DropGBox.Text = "Drop Item " + (d + 1); + dropCon.ItemComboBox.SelectedIndex = (int)epd.dropParameters[d].ItemIndex; + dropCon.NumericItemCount.Value = epd.dropParameters[d].ItemCount; + dropCon.NumericItemProbability.Value = epd.dropParameters[d].Probability; + DroppedLayout.Controls.Add(dropCon); + } + + AddDropParam dropParamPlus = new AddDropParam(); + DroppedLayout.Controls.Add(dropParamPlus); + + // Extra Parameters + for (int e = 0; e < epd.extraParameters.Count; e++) + { + ExtraControl extraCon = new ExtraControl(); + + extraCon.ExtraParamGBox.Text = "Extra Param " + (e + 1); + extraCon.ParameterName.Text = epd.extraParameters[e].ParameterName; + extraCon.ParameterValue.Text = epd.extraParameters[e].ParameterValue.ToString(); + ExtraLayout.Controls.Add(extraCon); + } + + AddExtraParam extraParamPlus = new AddExtraParam(); + ExtraLayout.Controls.Add(extraParamPlus); + } + + private void UpdateWriteInfo() + { + Epd.Header head = epd.header; + epd = new Epd(); + + epd.header = head; + + // General Parameters + epd.generalParameters = new Epd.GeneralParameters(); + epd.generalParameters.StatusAilmentsFlag = + Epd.GetStatusAilmentFromStates( + StatusAilment_checkbox_01.Checked, StatusAilment_checkbox_02.Checked, StatusAilment_checkbox_03.Checked, StatusAilment_checkbox_04.Checked, StatusAilment_checkbox_05.Checked, + StatusAilment_checkbox_06.Checked, StatusAilment_checkbox_07.Checked, StatusAilment_checkbox_08.Checked, StatusAilment_checkbox_09.Checked, StatusAilment_checkbox_10.Checked, + StatusAilment_checkbox_11.Checked, StatusAilment_checkbox_12.Checked, StatusAilment_checkbox_13.Checked, StatusAilment_checkbox_14.Checked, StatusAilment_checkbox_15.Checked, + StatusAilment_checkbox_16.Checked, StatusAilment_checkbox_17.Checked, StatusAilment_checkbox_18.Checked, StatusAilment_checkbox_19.Checked); + epd.generalParameters.Health = float.Parse(MaxHealthBox.Text); + epd.generalParameters.ExperienceMultiplier = float.Parse(EXPMultiplierBox.Text); + epd.generalParameters.Size = uint.Parse(SizeBox.Text, System.Globalization.NumberStyles.Integer); + epd.generalParameters.PhysicalDamageMultiplier = float.Parse(PhysicalDamageBox.Text); + epd.generalParameters.FireDamageMultiplier = float.Parse(FireDamageBox.Text); + epd.generalParameters.IceDamageMultiplier = float.Parse(IceDamageBox.Text); + epd.generalParameters.ThunderDamageMultiplier = float.Parse(ThunderDamageBox.Text); + epd.generalParameters.DarknessDamageMultiplier = float.Parse(DarknessDamageBox.Text); + epd.generalParameters.NonElementalDamageMultiplier = float.Parse(SpecialDamageBox.Text); + + // Anim list + epd.AnimationList = new List(); + foreach (TextBox txt in AnimationLayoutPanel.Controls) + { + char[] arr = new char[4]; + if (txt.Text != "") + { + arr[0] = txt.Text.ToCharArray()[0]; + arr[1] = txt.Text.ToCharArray()[1]; + arr[2] = txt.Text.ToCharArray()[2]; + arr[3] = (char)0; + } + epd.AnimationList.Add(arr); + } + + // Other Parameters + epd.otherParameters = new Epd.OtherParameters(); + epd.otherParameters.DamageCeiling = Decimal.ToUInt16(NumericDamageCeiling.Value); + epd.otherParameters.DamageFloor = Decimal.ToUInt16(NumericDamageFloor.Value); + epd.otherParameters.fWeight = float.Parse(NumericWeight.Text); + epd.otherParameters.EffectivenessFlag = + Epd.GetEffectivenessFlagFromStates(decimal.ToUInt32(NumericPoison.Value), decimal.ToUInt32(NumericStop.Value), decimal.ToUInt32(NumericBind.Value), + decimal.ToUInt32(NumericFaint.Value), decimal.ToUInt32(NumericBlind.Value), decimal.ToUInt32(NumericMini.Value)); + epd.otherParameters.PrizeBoxProbability = decimal.ToSByte(NumericPrizeboxProbability.Value); + epd.otherParameters.padding = new byte[3]; + epd.otherParameters.TechniqueParameterCount = (uint)(TechniqueLayout.Controls.Count - 1 < 0 ? 0 : TechniqueLayout.Controls.Count - 1); + epd.otherParameters.TechniqueParameterOffset = 0xA8; + epd.otherParameters.DropItemsCount = (uint)(DroppedLayout.Controls.Count - 1 < 0 ? 0 : DroppedLayout.Controls.Count - 1); + epd.otherParameters.DropItemsOffset = 0xA8 + (epd.otherParameters.TechniqueParameterCount * 8); + epd.otherParameters.ExtraParametersCount = (uint)(ExtraLayout.Controls.Count - 1 < 0 ? 0 : ExtraLayout.Controls.Count - 1); + epd.otherParameters.ExtraParametersOffset = 0xA8 + ((epd.otherParameters.TechniqueParameterCount + epd.otherParameters.DropItemsCount) * 8); + + // Technique Parameters + epd.techniqueParameters = new List(); + try + { + foreach (TechControl tech in TechniqueLayout.Controls) + { + Epd.TechniqueParameters param = new Epd.TechniqueParameters(); + param.TechniquePowerCorrection = float.Parse(tech.TechniquePower.Text); + param.TechniqueNumber = decimal.ToByte(tech.NumericTechniqueNumber.Value); + param.TechniqueKind = (byte)tech.AttackKind.SelectedIndex; + param.TechniqueAttribute = (byte)tech.AttackAttribute.SelectedIndex; + param.SuccessRate = decimal.ToByte(tech.NumericSuccessRate.Value); + epd.techniqueParameters.Add(param); + } + } + catch (InvalidCastException) + { + Console.WriteLine("Cannot convert to this type."); + } + + // Drop Parameters + epd.dropParameters = new List(); + try + { + foreach (DropControl drop in DroppedLayout.Controls) + { + Epd.DropParameters param = new Epd.DropParameters(); + param.ItemIndex = (uint)drop.ItemComboBox.SelectedIndex; + param.ItemCount = decimal.ToUInt16(drop.NumericItemCount.Value); + param.Probability = decimal.ToUInt16(drop.NumericItemProbability.Value); + epd.dropParameters.Add(param); + } + } + catch (InvalidCastException) + { + Console.WriteLine("Cannot convert to this type."); + } + + // Extra Parameters + epd.extraParameters = new List(); + try + { + foreach (ExtraControl extra in ExtraLayout.Controls) + { + Epd.ExtraParameters param = new Epd.ExtraParameters(); + param.ParameterName = extra.ParameterName.Text; + param.ParameterValue = float.Parse(extra.ParameterValue.Text); + epd.extraParameters.Add(param); + } + } + catch (InvalidCastException) + { + Console.WriteLine("Cannot convert to this type."); + } + } + + private void LoadEPDButton_Click(object sender, EventArgs e) + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Filter = "Enemy Parameter Data files (*.epd)|*.epd|All files (*.*)|*.*"; + DialogResult result = dialog.ShowDialog(); + + if (result == DialogResult.OK) + { + TechniqueLayout.Controls.Clear(); + DroppedLayout.Controls.Clear(); + ExtraLayout.Controls.Clear(); + if (epdFile != null) + epdFile.Close(); + epdFile = File.OpenRead(dialog.FileName); + FileLoadedLabel.Text = "File currently loaded: " + dialog.FileName; + epd = Epd.Read(epdFile); + UpdateEPDData(); + SaveEPDButton.Enabled = true; + } + } + + private void SaveEPDButton_Click(object sender, EventArgs e) + { + SaveFileDialog dialog = new SaveFileDialog(); + dialog.Filter = "Enemy Parameter Data files (*.epd)|*.epd|All files (*.*)|*.*"; + DialogResult result = dialog.ShowDialog(); + + if (result == DialogResult.OK) + { + Stream epdOut = File.OpenWrite(dialog.FileName); + UpdateWriteInfo(); + Epd.Write(epdOut, epd); + epdOut.Close(); + } + + MessageBox.Show("File saved successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } +} diff --git a/OpenKh.Tools.EpdEditor/Program.cs b/OpenKh.Tools.EpdEditor/Program.cs index 78d9c441f..cbb6c5b39 100644 --- a/OpenKh.Tools.EpdEditor/Program.cs +++ b/OpenKh.Tools.EpdEditor/Program.cs @@ -1,23 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace OpenKh.Tools.EpdEditor -{ - static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.SetHighDpiMode(HighDpiMode.SystemAware); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new EPDForm()); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace OpenKh.Tools.EpdEditor +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new EPDForm()); + } + } +} diff --git a/OpenKh.Tools.EpdEditor/TechControl.cs b/OpenKh.Tools.EpdEditor/TechControl.cs index f0c9e84cc..414910fa5 100644 --- a/OpenKh.Tools.EpdEditor/TechControl.cs +++ b/OpenKh.Tools.EpdEditor/TechControl.cs @@ -1,18 +1,18 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; - -namespace OpenKh.Tools.EpdEditor -{ - public partial class TechControl : UserControl - { - public TechControl() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace OpenKh.Tools.EpdEditor +{ + public partial class TechControl : UserControl + { + public TechControl() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.IdxImg/App.xaml.cs b/OpenKh.Tools.IdxImg/App.xaml.cs index fa2e6a1fe..7beaf894a 100644 --- a/OpenKh.Tools.IdxImg/App.xaml.cs +++ b/OpenKh.Tools.IdxImg/App.xaml.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; - -namespace OpenKh.Tools.IdxImg -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace OpenKh.Tools.IdxImg +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/OpenKh.Tools.IdxImg/AssemblyInfo.cs b/OpenKh.Tools.IdxImg/AssemblyInfo.cs index 8b5504ecf..74087a1fd 100644 --- a/OpenKh.Tools.IdxImg/AssemblyInfo.cs +++ b/OpenKh.Tools.IdxImg/AssemblyInfo.cs @@ -1,10 +1,10 @@ -using System.Windows; - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/OpenKh.Tools.IdxImg/Extensions.cs b/OpenKh.Tools.IdxImg/Extensions.cs index 97fc5192b..7dc78e54a 100644 --- a/OpenKh.Tools.IdxImg/Extensions.cs +++ b/OpenKh.Tools.IdxImg/Extensions.cs @@ -1,10 +1,10 @@ -using OpenKh.Kh2; - -namespace OpenKh.Tools.IdxImg -{ - public static class Extensions - { - public static string GetFullName(this Idx.Entry entry) => - IdxName.Lookup(entry) ?? $"@{entry.Hash32:X08}_{entry.Hash16}"; - } -} +using OpenKh.Kh2; + +namespace OpenKh.Tools.IdxImg +{ + public static class Extensions + { + public static string GetFullName(this Idx.Entry entry) => + IdxName.Lookup(entry) ?? $"@{entry.Hash32:X08}_{entry.Hash16}"; + } +} diff --git a/OpenKh.Tools.IdxImg/ExtractProcessor.cs b/OpenKh.Tools.IdxImg/ExtractProcessor.cs index 63ad9ded9..ce0823a77 100644 --- a/OpenKh.Tools.IdxImg/ExtractProcessor.cs +++ b/OpenKh.Tools.IdxImg/ExtractProcessor.cs @@ -1,31 +1,31 @@ -using OpenKh.Tools.IdxImg.Interfaces; -using OpenKh.Tools.IdxImg.Views; -using System; -using System.Threading; -using System.Threading.Tasks; -using System.Windows; - -namespace OpenKh.Tools.IdxImg -{ - public static class ExtractProcessor - { - public static Task ShowProgress(Action action) - { - using var cts = new CancellationTokenSource(); - var window = Application.Current.Dispatcher.Invoke(() => - new ExtractProgressWindow(cts) - { - Owner = Application.Current.MainWindow - }); - - var task = Task.Run(() => action(window), window.CancellationToken); - Application.Current.Dispatcher.Invoke(() => - window.ShowDialog()); - cts.Cancel(); - if (!task.IsCompleted) - task.Wait(); - - return task; - } - } -} +using OpenKh.Tools.IdxImg.Interfaces; +using OpenKh.Tools.IdxImg.Views; +using System; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; + +namespace OpenKh.Tools.IdxImg +{ + public static class ExtractProcessor + { + public static Task ShowProgress(Action action) + { + using var cts = new CancellationTokenSource(); + var window = Application.Current.Dispatcher.Invoke(() => + new ExtractProgressWindow(cts) + { + Owner = Application.Current.MainWindow + }); + + var task = Task.Run(() => action(window), window.CancellationToken); + Application.Current.Dispatcher.Invoke(() => + window.ShowDialog()); + cts.Cancel(); + if (!task.IsCompleted) + task.Wait(); + + return task; + } + } +} diff --git a/OpenKh.Tools.IdxImg/Interfaces/IExtractProgress.cs b/OpenKh.Tools.IdxImg/Interfaces/IExtractProgress.cs index 3edd4dc0b..1ac70c58f 100644 --- a/OpenKh.Tools.IdxImg/Interfaces/IExtractProgress.cs +++ b/OpenKh.Tools.IdxImg/Interfaces/IExtractProgress.cs @@ -1,10 +1,10 @@ -using System.Threading; - -namespace OpenKh.Tools.IdxImg.Interfaces -{ - public interface IExtractProgress - { - CancellationToken CancellationToken { get; } - void SetExtractedName(string name); - } -} +using System.Threading; + +namespace OpenKh.Tools.IdxImg.Interfaces +{ + public interface IExtractProgress + { + CancellationToken CancellationToken { get; } + void SetExtractedName(string name); + } +} diff --git a/OpenKh.Tools.IdxImg/Interfaces/IIdxManager.cs b/OpenKh.Tools.IdxImg/Interfaces/IIdxManager.cs index 9093116d4..201dfd449 100644 --- a/OpenKh.Tools.IdxImg/Interfaces/IIdxManager.cs +++ b/OpenKh.Tools.IdxImg/Interfaces/IIdxManager.cs @@ -1,11 +1,11 @@ -using OpenKh.Kh2; -using System.IO; - -namespace OpenKh.Tools.IdxImg.Interfaces -{ - interface IIdxManager - { - Stream OpenFileFromIdx(string fileName); - Stream OpenFileFromIdx(Idx.Entry entry); - } -} +using OpenKh.Kh2; +using System.IO; + +namespace OpenKh.Tools.IdxImg.Interfaces +{ + interface IIdxManager + { + Stream OpenFileFromIdx(string fileName); + Stream OpenFileFromIdx(Idx.Entry entry); + } +} diff --git a/OpenKh.Tools.IdxImg/Interfaces/ITreeSelectedItem.cs b/OpenKh.Tools.IdxImg/Interfaces/ITreeSelectedItem.cs index c8f86ab09..8b4c48812 100644 --- a/OpenKh.Tools.IdxImg/Interfaces/ITreeSelectedItem.cs +++ b/OpenKh.Tools.IdxImg/Interfaces/ITreeSelectedItem.cs @@ -1,7 +1,7 @@ -namespace OpenKh.Tools.IdxImg.Interfaces -{ - public interface ITreeSelectedItem - { - object TreeSelectedItem { get; set; } - } -} +namespace OpenKh.Tools.IdxImg.Interfaces +{ + public interface ITreeSelectedItem + { + object TreeSelectedItem { get; set; } + } +} diff --git a/OpenKh.Tools.IdxImg/MainWindow.xaml.cs b/OpenKh.Tools.IdxImg/MainWindow.xaml.cs index f8ac46c3f..4fb20151f 100644 --- a/OpenKh.Tools.IdxImg/MainWindow.xaml.cs +++ b/OpenKh.Tools.IdxImg/MainWindow.xaml.cs @@ -1,28 +1,28 @@ -using OpenKh.Tools.IdxImg.ViewModels; -using System.Windows; - -namespace OpenKh.Tools.IdxImg -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - internal IdxImgViewModel ViewModel - { - get => DataContext as IdxImgViewModel; - set => DataContext = value; - } - - public MainWindow() - { - InitializeComponent(); - ViewModel = new IdxImgViewModel(ItemPropertyContent); - } - - private void Window_Drop(object sender, DragEventArgs e) - { - - } - } -} +using OpenKh.Tools.IdxImg.ViewModels; +using System.Windows; + +namespace OpenKh.Tools.IdxImg +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + internal IdxImgViewModel ViewModel + { + get => DataContext as IdxImgViewModel; + set => DataContext = value; + } + + public MainWindow() + { + InitializeComponent(); + ViewModel = new IdxImgViewModel(ItemPropertyContent); + } + + private void Window_Drop(object sender, DragEventArgs e) + { + + } + } +} diff --git a/OpenKh.Tools.IdxImg/ViewModels/EntryParserModel.cs b/OpenKh.Tools.IdxImg/ViewModels/EntryParserModel.cs index f18348472..13fc875c2 100644 --- a/OpenKh.Tools.IdxImg/ViewModels/EntryParserModel.cs +++ b/OpenKh.Tools.IdxImg/ViewModels/EntryParserModel.cs @@ -1,60 +1,60 @@ -using OpenKh.Kh2; -using OpenKh.Tools.IdxImg.Interfaces; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Tools.IdxImg.ViewModels -{ - internal class EntryParserModel - { - internal EntryParserModel(Idx.Entry entry) - { - Entry = entry; - Path = entry.GetFullName(); - SplitPath = Path.Split('/'); - } - - public Idx.Entry Entry { get; } - public string Path { get; } - public string[] SplitPath { get; } - public string Name => SplitPath[^1]; - public bool IsIdx => IsLeaf(0) && - System.IO.Path.GetExtension(Name).ToLower() == ".idx"; - - public bool IsLeaf(int index) => SplitPath.Length == index + 1; - - public static IEnumerable GetEntries( - List entries, int depth, IIdxManager idxManager) - { - var dirs = entries - .Where(x => !x.IsLeaf(depth)) - .GroupBy(x => x.SplitPath[depth]) - .Select(x => new FolderViewModel(x.Key, depth + 1, x, idxManager)); - var files = - entries - .Where(x => x.IsLeaf(depth)) - .Select(x => new FileViewModel(x, idxManager)); - - var tree = dirs.Cast().Concat(files); - if (depth == 0) - tree = entries - .Where(x => x.IsIdx) - .Select(x => new IdxViewModel(x.Name, x.Entry, idxManager)) - .Cast() - .Concat(tree); - - return tree; - } - - public static IEnumerable GetChildren( - List idxEntries, IIdxManager idxManager) - { - var entries = idxEntries - .Select(x => new EntryParserModel(x)) - .OrderBy(x => x.Path) - .ToList(); - - return GetEntries(entries, 0, idxManager); - } - } -} +using OpenKh.Kh2; +using OpenKh.Tools.IdxImg.Interfaces; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Tools.IdxImg.ViewModels +{ + internal class EntryParserModel + { + internal EntryParserModel(Idx.Entry entry) + { + Entry = entry; + Path = entry.GetFullName(); + SplitPath = Path.Split('/'); + } + + public Idx.Entry Entry { get; } + public string Path { get; } + public string[] SplitPath { get; } + public string Name => SplitPath[^1]; + public bool IsIdx => IsLeaf(0) && + System.IO.Path.GetExtension(Name).ToLower() == ".idx"; + + public bool IsLeaf(int index) => SplitPath.Length == index + 1; + + public static IEnumerable GetEntries( + List entries, int depth, IIdxManager idxManager) + { + var dirs = entries + .Where(x => !x.IsLeaf(depth)) + .GroupBy(x => x.SplitPath[depth]) + .Select(x => new FolderViewModel(x.Key, depth + 1, x, idxManager)); + var files = + entries + .Where(x => x.IsLeaf(depth)) + .Select(x => new FileViewModel(x, idxManager)); + + var tree = dirs.Cast().Concat(files); + if (depth == 0) + tree = entries + .Where(x => x.IsIdx) + .Select(x => new IdxViewModel(x.Name, x.Entry, idxManager)) + .Cast() + .Concat(tree); + + return tree; + } + + public static IEnumerable GetChildren( + List idxEntries, IIdxManager idxManager) + { + var entries = idxEntries + .Select(x => new EntryParserModel(x)) + .OrderBy(x => x.Path) + .ToList(); + + return GetEntries(entries, 0, idxManager); + } + } +} diff --git a/OpenKh.Tools.IdxImg/ViewModels/EntryViewModel.cs b/OpenKh.Tools.IdxImg/ViewModels/EntryViewModel.cs index c9c5a4d14..786c3dab8 100644 --- a/OpenKh.Tools.IdxImg/ViewModels/EntryViewModel.cs +++ b/OpenKh.Tools.IdxImg/ViewModels/EntryViewModel.cs @@ -1,16 +1,16 @@ -using OpenKh.Tools.IdxImg.Interfaces; - -namespace OpenKh.Tools.IdxImg.ViewModels -{ - public abstract class EntryViewModel - { - public string Name { get; } - - internal EntryViewModel(string name) - { - Name = name; - } - - public abstract void Extract(string outputPath, IExtractProgress progress); - } -} +using OpenKh.Tools.IdxImg.Interfaces; + +namespace OpenKh.Tools.IdxImg.ViewModels +{ + public abstract class EntryViewModel + { + public string Name { get; } + + internal EntryViewModel(string name) + { + Name = name; + } + + public abstract void Extract(string outputPath, IExtractProgress progress); + } +} diff --git a/OpenKh.Tools.IdxImg/ViewModels/FileViewModel.cs b/OpenKh.Tools.IdxImg/ViewModels/FileViewModel.cs index 6128965d0..3e48eb729 100644 --- a/OpenKh.Tools.IdxImg/ViewModels/FileViewModel.cs +++ b/OpenKh.Tools.IdxImg/ViewModels/FileViewModel.cs @@ -1,55 +1,55 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Tools.IdxImg.Interfaces; -using System.IO; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.IdxImg.ViewModels -{ - public class FileViewModel : EntryViewModel - { - private readonly IIdxManager _idxManager; - - public Idx.Entry Entry { get; } - public string FullName => Entry.GetFullName(); - public bool IsCompressed - { - get => Entry.IsCompressed; - set { } - } - public bool IsStream - { - get => Entry.IsStreamed; - set { } - } - public long PhysicalOffset => Entry.Offset * Img.IsoBlockAlign; - public long PhysicalLength => (Entry.BlockLength + 1) * Img.IsoBlockAlign; - public long UncompressedLength => Entry.Length; - - internal FileViewModel(EntryParserModel entry, IIdxManager idxManager) : - base(entry.Name) - { - _idxManager = idxManager; - Entry = entry.Entry; - - ExportCommand = new RelayCommand(_ => - { - FileDialog.OnSave(ExtractForReal, - FileDialogFilterComposer.Compose().AddAllFiles(), Name); - }); - } - - public RelayCommand ExportCommand { get; } - public RelayCommand InjectCommand { get; } - public RelayCommand AppendCommand { get; } - public RelayCommand ImportCommand { get; } - - public override void Extract(string outputPath, IExtractProgress progress) => - ExtractForReal(Path.Combine(outputPath, Name)); - - private void ExtractForReal(string fileName) => - File.Create(fileName).Using(stream => - _idxManager.OpenFileFromIdx(Entry).CopyTo(stream)); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Tools.IdxImg.Interfaces; +using System.IO; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.IdxImg.ViewModels +{ + public class FileViewModel : EntryViewModel + { + private readonly IIdxManager _idxManager; + + public Idx.Entry Entry { get; } + public string FullName => Entry.GetFullName(); + public bool IsCompressed + { + get => Entry.IsCompressed; + set { } + } + public bool IsStream + { + get => Entry.IsStreamed; + set { } + } + public long PhysicalOffset => Entry.Offset * Img.IsoBlockAlign; + public long PhysicalLength => (Entry.BlockLength + 1) * Img.IsoBlockAlign; + public long UncompressedLength => Entry.Length; + + internal FileViewModel(EntryParserModel entry, IIdxManager idxManager) : + base(entry.Name) + { + _idxManager = idxManager; + Entry = entry.Entry; + + ExportCommand = new RelayCommand(_ => + { + FileDialog.OnSave(ExtractForReal, + FileDialogFilterComposer.Compose().AddAllFiles(), Name); + }); + } + + public RelayCommand ExportCommand { get; } + public RelayCommand InjectCommand { get; } + public RelayCommand AppendCommand { get; } + public RelayCommand ImportCommand { get; } + + public override void Extract(string outputPath, IExtractProgress progress) => + ExtractForReal(Path.Combine(outputPath, Name)); + + private void ExtractForReal(string fileName) => + File.Create(fileName).Using(stream => + _idxManager.OpenFileFromIdx(Entry).CopyTo(stream)); + } +} diff --git a/OpenKh.Tools.IdxImg/ViewModels/FolderViewModel.cs b/OpenKh.Tools.IdxImg/ViewModels/FolderViewModel.cs index 2e14b1729..d628e96d7 100644 --- a/OpenKh.Tools.IdxImg/ViewModels/FolderViewModel.cs +++ b/OpenKh.Tools.IdxImg/ViewModels/FolderViewModel.cs @@ -1,44 +1,44 @@ -using OpenKh.Tools.IdxImg.Interfaces; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.IdxImg.ViewModels -{ - public class FolderViewModel : NodeViewModel - { - private readonly IIdxManager _idxManager; - - internal FolderViewModel( - string name, int depth, IEnumerable entries, IIdxManager idxManager) : - base(name, EntryParserModel.GetEntries(entries.ToList(), depth, idxManager)) - { - _idxManager = idxManager; - ExportCommand = new RelayCommand(_ => - FileDialog.OnFolder(x => - Task.Run(() => - ExtractProcessor.ShowProgress(progress => - Extract(x, progress))))); - } - - public RelayCommand ExportCommand { get; } - - public override void Extract(string outputPath, IExtractProgress progress) - { - var childOutputPath = Path.Combine(outputPath, Name); - Directory.CreateDirectory(childOutputPath); - - foreach (var child in Children) - { - if (progress.CancellationToken.IsCancellationRequested) - break; - - progress.SetExtractedName(childOutputPath); - child.Extract(childOutputPath, progress); - } - } - } -} +using OpenKh.Tools.IdxImg.Interfaces; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.IdxImg.ViewModels +{ + public class FolderViewModel : NodeViewModel + { + private readonly IIdxManager _idxManager; + + internal FolderViewModel( + string name, int depth, IEnumerable entries, IIdxManager idxManager) : + base(name, EntryParserModel.GetEntries(entries.ToList(), depth, idxManager)) + { + _idxManager = idxManager; + ExportCommand = new RelayCommand(_ => + FileDialog.OnFolder(x => + Task.Run(() => + ExtractProcessor.ShowProgress(progress => + Extract(x, progress))))); + } + + public RelayCommand ExportCommand { get; } + + public override void Extract(string outputPath, IExtractProgress progress) + { + var childOutputPath = Path.Combine(outputPath, Name); + Directory.CreateDirectory(childOutputPath); + + foreach (var child in Children) + { + if (progress.CancellationToken.IsCancellationRequested) + break; + + progress.SetExtractedName(childOutputPath); + child.Extract(childOutputPath, progress); + } + } + } +} diff --git a/OpenKh.Tools.IdxImg/ViewModels/IdxImgViewModel.cs b/OpenKh.Tools.IdxImg/ViewModels/IdxImgViewModel.cs index cc35dc4b0..4ca9eac00 100644 --- a/OpenKh.Tools.IdxImg/ViewModels/IdxImgViewModel.cs +++ b/OpenKh.Tools.IdxImg/ViewModels/IdxImgViewModel.cs @@ -1,126 +1,126 @@ -using OpenKh.Kh2; -using OpenKh.Tools.IdxImg.Interfaces; -using OpenKh.Tools.IdxImg.Views; -using System; -using System.Collections.Generic; -using System.IO; -using System.Windows.Controls; -using forms = System.Windows.Forms; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; -using OpenKh.Tools.Common; - -namespace OpenKh.Tools.IdxImg.ViewModels -{ - class IdxImgViewModel : BaseNotifyPropertyChanged, IIdxManager, ITreeSelectedItem - { - private static readonly IEnumerable Filter = - FileDialogFilterComposer.Compose() - .AddExtensions("KH2.IDX or KH2.IMG from the ISO or game disc", "IDX", "IMG") - .AddAllFiles(); - private static readonly IEnumerable IdxFilter = - FileDialogFilterComposer.Compose() - .AddExtensions("KH2.IDX from the ISO or game disc", "IDX") - .AddAllFiles(); - private static readonly IEnumerable ImgFilter = - FileDialogFilterComposer.Compose() - .AddExtensions("KH2.IMG from the ISO or game disc", "IMG") - .AddAllFiles(); - private static string ApplicationName = Utilities.GetApplicationName(); - - public string Title => $"{_idxFileName ?? "no file loaded"} | {ApplicationName}"; - - private Panel _itemPropertyPanel; - private Stream _imgStream; - private Img _img; - private object _treeSelectedItem; - private string _idxFileName; - private string _imgFileName; - - public IdxImgViewModel(Panel itemPropertyPanel) - { - _itemPropertyPanel = itemPropertyPanel; - - OpenCommand = new RelayCommand(_ => - { - try - { - FileDialog.OnOpen(fileName => - { - var baseName = Path.Combine( - Path.GetDirectoryName(fileName), - Path.GetFileNameWithoutExtension(fileName)); - var idxFileName = baseName + ".idx"; - var imgFileName = baseName + ".img"; - if (!File.Exists(idxFileName)) - FileDialog.OnOpen(fileName => idxFileName = fileName, IdxFilter); - if (!File.Exists(imgFileName)) - FileDialog.OnOpen(fileName => imgFileName = fileName, ImgFilter); - OpenIdxImg(idxFileName, imgFileName); - - }, Filter, "KH2.IDX"); - } - catch (Exception ex) - { - forms.MessageBox.Show(ex.Message, "Error", - forms.MessageBoxButtons.OK, forms.MessageBoxIcon.Error); - } - }); - } - - public RelayCommand OpenCommand { get; } - - public List Root { get; private set; } - public object TreeSelectedItem - { - get => _treeSelectedItem; - set - { - _itemPropertyPanel.Children.Clear(); - - _treeSelectedItem = value; - var itemPropertyControl = _treeSelectedItem switch - { - FileViewModel _ => new FilePropertyView(), - _ => null, - }; - OnPropertyChanged(); - OnPropertyChanged(nameof(IsTreeItemSelected)); - - if (itemPropertyControl != null) - _itemPropertyPanel.Children.Add(itemPropertyControl); - } - } - public bool IsTreeItemSelected => TreeSelectedItem != null; - - public void OpenIdxImg(string idxFileName, string imgFileName) - { - using var idxStream = File.OpenRead(idxFileName); - if (!Idx.IsValid(idxStream)) - throw new ArgumentException($"The file '{idxFileName}' is not a valid IDX file."); - var idx = Idx.Read(idxStream); - - _imgStream?.Dispose(); - _imgStream = File.OpenRead(imgFileName); - _img = new Img(_imgStream, idx, false); - - Root = new List() - { - new RootViewModel(Path.GetFileName(idxFileName), idx, this) - }; - - _idxFileName = idxFileName; - _imgFileName = imgFileName; - - OnPropertyChanged(nameof(Root)); - OnPropertyChanged(nameof(Title)); - } - - public Stream OpenFileFromIdx(string fileName) => - _img.FileOpen(fileName); - - public Stream OpenFileFromIdx(Idx.Entry idxEntry) => - _img.FileOpen(idxEntry); - } -} +using OpenKh.Kh2; +using OpenKh.Tools.IdxImg.Interfaces; +using OpenKh.Tools.IdxImg.Views; +using System; +using System.Collections.Generic; +using System.IO; +using System.Windows.Controls; +using forms = System.Windows.Forms; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; +using OpenKh.Tools.Common; + +namespace OpenKh.Tools.IdxImg.ViewModels +{ + class IdxImgViewModel : BaseNotifyPropertyChanged, IIdxManager, ITreeSelectedItem + { + private static readonly IEnumerable Filter = + FileDialogFilterComposer.Compose() + .AddExtensions("KH2.IDX or KH2.IMG from the ISO or game disc", "IDX", "IMG") + .AddAllFiles(); + private static readonly IEnumerable IdxFilter = + FileDialogFilterComposer.Compose() + .AddExtensions("KH2.IDX from the ISO or game disc", "IDX") + .AddAllFiles(); + private static readonly IEnumerable ImgFilter = + FileDialogFilterComposer.Compose() + .AddExtensions("KH2.IMG from the ISO or game disc", "IMG") + .AddAllFiles(); + private static string ApplicationName = Utilities.GetApplicationName(); + + public string Title => $"{_idxFileName ?? "no file loaded"} | {ApplicationName}"; + + private Panel _itemPropertyPanel; + private Stream _imgStream; + private Img _img; + private object _treeSelectedItem; + private string _idxFileName; + private string _imgFileName; + + public IdxImgViewModel(Panel itemPropertyPanel) + { + _itemPropertyPanel = itemPropertyPanel; + + OpenCommand = new RelayCommand(_ => + { + try + { + FileDialog.OnOpen(fileName => + { + var baseName = Path.Combine( + Path.GetDirectoryName(fileName), + Path.GetFileNameWithoutExtension(fileName)); + var idxFileName = baseName + ".idx"; + var imgFileName = baseName + ".img"; + if (!File.Exists(idxFileName)) + FileDialog.OnOpen(fileName => idxFileName = fileName, IdxFilter); + if (!File.Exists(imgFileName)) + FileDialog.OnOpen(fileName => imgFileName = fileName, ImgFilter); + OpenIdxImg(idxFileName, imgFileName); + + }, Filter, "KH2.IDX"); + } + catch (Exception ex) + { + forms.MessageBox.Show(ex.Message, "Error", + forms.MessageBoxButtons.OK, forms.MessageBoxIcon.Error); + } + }); + } + + public RelayCommand OpenCommand { get; } + + public List Root { get; private set; } + public object TreeSelectedItem + { + get => _treeSelectedItem; + set + { + _itemPropertyPanel.Children.Clear(); + + _treeSelectedItem = value; + var itemPropertyControl = _treeSelectedItem switch + { + FileViewModel _ => new FilePropertyView(), + _ => null, + }; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsTreeItemSelected)); + + if (itemPropertyControl != null) + _itemPropertyPanel.Children.Add(itemPropertyControl); + } + } + public bool IsTreeItemSelected => TreeSelectedItem != null; + + public void OpenIdxImg(string idxFileName, string imgFileName) + { + using var idxStream = File.OpenRead(idxFileName); + if (!Idx.IsValid(idxStream)) + throw new ArgumentException($"The file '{idxFileName}' is not a valid IDX file."); + var idx = Idx.Read(idxStream); + + _imgStream?.Dispose(); + _imgStream = File.OpenRead(imgFileName); + _img = new Img(_imgStream, idx, false); + + Root = new List() + { + new RootViewModel(Path.GetFileName(idxFileName), idx, this) + }; + + _idxFileName = idxFileName; + _imgFileName = imgFileName; + + OnPropertyChanged(nameof(Root)); + OnPropertyChanged(nameof(Title)); + } + + public Stream OpenFileFromIdx(string fileName) => + _img.FileOpen(fileName); + + public Stream OpenFileFromIdx(Idx.Entry idxEntry) => + _img.FileOpen(idxEntry); + } +} diff --git a/OpenKh.Tools.IdxImg/ViewModels/IdxViewModel.cs b/OpenKh.Tools.IdxImg/ViewModels/IdxViewModel.cs index 2ff118506..d03071e69 100644 --- a/OpenKh.Tools.IdxImg/ViewModels/IdxViewModel.cs +++ b/OpenKh.Tools.IdxImg/ViewModels/IdxViewModel.cs @@ -1,64 +1,64 @@ -using OpenKh.Kh2; -using OpenKh.Tools.IdxImg.Interfaces; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.IdxImg.ViewModels -{ - public class IdxViewModel : NodeViewModel - { - private readonly IIdxManager _idxManager; - - internal IdxViewModel(string name, Idx.Entry entry, IIdxManager idxManager) : - base(name, GetChildren(name, idxManager)) - { - _idxManager = idxManager; - ExportCommand = new RelayCommand(_ => - FileDialog.OnFolder(x => - Task.Run(() => - ExtractProcessor.ShowProgress(progress => - Extract(x, progress))))); - } - - public string ShortName => Path.GetFileNameWithoutExtension(Name); - public RelayCommand ExportCommand { get; } - - private static IEnumerable GetChildren(string idxName, IIdxManager idxManager) - { - var idxStream = idxManager.OpenFileFromIdx(idxName); - if (idxStream == null) - return new EntryViewModel[0]; - - using (idxStream) - { - return EntryParserModel.GetChildren(Idx.Read(idxStream), idxManager); - } - } - - public override void Extract(string outputPath, IExtractProgress progress) - { - foreach (var child in Children) - { - if (progress.CancellationToken.IsCancellationRequested) - break; - - child.Extract(Path.Combine(outputPath, ShortName), progress); - } - } - - public void ExtractAndMerge(string outputPath, IExtractProgress progress) - { - foreach (var child in Children) - { - if (progress.CancellationToken.IsCancellationRequested) - break; - - child.Extract(outputPath, progress); - } - } - } -} +using OpenKh.Kh2; +using OpenKh.Tools.IdxImg.Interfaces; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.IdxImg.ViewModels +{ + public class IdxViewModel : NodeViewModel + { + private readonly IIdxManager _idxManager; + + internal IdxViewModel(string name, Idx.Entry entry, IIdxManager idxManager) : + base(name, GetChildren(name, idxManager)) + { + _idxManager = idxManager; + ExportCommand = new RelayCommand(_ => + FileDialog.OnFolder(x => + Task.Run(() => + ExtractProcessor.ShowProgress(progress => + Extract(x, progress))))); + } + + public string ShortName => Path.GetFileNameWithoutExtension(Name); + public RelayCommand ExportCommand { get; } + + private static IEnumerable GetChildren(string idxName, IIdxManager idxManager) + { + var idxStream = idxManager.OpenFileFromIdx(idxName); + if (idxStream == null) + return new EntryViewModel[0]; + + using (idxStream) + { + return EntryParserModel.GetChildren(Idx.Read(idxStream), idxManager); + } + } + + public override void Extract(string outputPath, IExtractProgress progress) + { + foreach (var child in Children) + { + if (progress.CancellationToken.IsCancellationRequested) + break; + + child.Extract(Path.Combine(outputPath, ShortName), progress); + } + } + + public void ExtractAndMerge(string outputPath, IExtractProgress progress) + { + foreach (var child in Children) + { + if (progress.CancellationToken.IsCancellationRequested) + break; + + child.Extract(outputPath, progress); + } + } + } +} diff --git a/OpenKh.Tools.IdxImg/ViewModels/NodeViewModel.cs b/OpenKh.Tools.IdxImg/ViewModels/NodeViewModel.cs index 8ef14b5a2..285e73631 100644 --- a/OpenKh.Tools.IdxImg/ViewModels/NodeViewModel.cs +++ b/OpenKh.Tools.IdxImg/ViewModels/NodeViewModel.cs @@ -1,16 +1,16 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; - -namespace OpenKh.Tools.IdxImg.ViewModels -{ - public abstract class NodeViewModel : EntryViewModel - { - public ObservableCollection Children { get; } - - public NodeViewModel(string name, IEnumerable entries) : - base(name) - { - Children = new ObservableCollection(entries); - } - } -} +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace OpenKh.Tools.IdxImg.ViewModels +{ + public abstract class NodeViewModel : EntryViewModel + { + public ObservableCollection Children { get; } + + public NodeViewModel(string name, IEnumerable entries) : + base(name) + { + Children = new ObservableCollection(entries); + } + } +} diff --git a/OpenKh.Tools.IdxImg/ViewModels/RootViewModel.cs b/OpenKh.Tools.IdxImg/ViewModels/RootViewModel.cs index 26d216132..ca8bc1f43 100644 --- a/OpenKh.Tools.IdxImg/ViewModels/RootViewModel.cs +++ b/OpenKh.Tools.IdxImg/ViewModels/RootViewModel.cs @@ -1,61 +1,61 @@ -using OpenKh.Kh2; -using OpenKh.Tools.IdxImg.Interfaces; -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.IdxImg.ViewModels -{ - class RootViewModel : NodeViewModel - { - private readonly IIdxManager _idxManager; - - public RootViewModel(string name, List entries, IIdxManager idxManager) : - base(name, EntryParserModel.GetChildren(entries, idxManager)) - { - _idxManager = idxManager; - ExportCommand = new RelayCommand(_ => - FileDialog.OnFolder(x => - Task.Run(() => - ExtractProcessor.ShowProgress(progress => - Extract(x, progress))))); - ExportAndMergeCommand = new RelayCommand(_ => - FileDialog.OnFolder(x => - Task.Run(() => - ExtractProcessor.ShowProgress(progress => - ExtractAndMerge(x, progress))))); - } - - public string ShortName => Path.GetFileNameWithoutExtension(Name); - public RelayCommand ExportCommand { get; } - public RelayCommand ExportAndMergeCommand { get; } - - public override void Extract(string outputPath, IExtractProgress progress) - { - foreach (var child in Children) - { - if (progress.CancellationToken.IsCancellationRequested) - break; - - child.Extract(Path.Combine(outputPath, ShortName), progress); - } - } - - public void ExtractAndMerge(string outputPath, IExtractProgress progress) - { - foreach (var child in Children) - { - if (progress.CancellationToken.IsCancellationRequested) - break; - - var childOutputPath = Path.Combine(outputPath, ShortName); - if (child is IdxViewModel idxVm) - idxVm.ExtractAndMerge(childOutputPath, progress); - else - child.Extract(childOutputPath, progress); - } - } - } -} +using OpenKh.Kh2; +using OpenKh.Tools.IdxImg.Interfaces; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.IdxImg.ViewModels +{ + class RootViewModel : NodeViewModel + { + private readonly IIdxManager _idxManager; + + public RootViewModel(string name, List entries, IIdxManager idxManager) : + base(name, EntryParserModel.GetChildren(entries, idxManager)) + { + _idxManager = idxManager; + ExportCommand = new RelayCommand(_ => + FileDialog.OnFolder(x => + Task.Run(() => + ExtractProcessor.ShowProgress(progress => + Extract(x, progress))))); + ExportAndMergeCommand = new RelayCommand(_ => + FileDialog.OnFolder(x => + Task.Run(() => + ExtractProcessor.ShowProgress(progress => + ExtractAndMerge(x, progress))))); + } + + public string ShortName => Path.GetFileNameWithoutExtension(Name); + public RelayCommand ExportCommand { get; } + public RelayCommand ExportAndMergeCommand { get; } + + public override void Extract(string outputPath, IExtractProgress progress) + { + foreach (var child in Children) + { + if (progress.CancellationToken.IsCancellationRequested) + break; + + child.Extract(Path.Combine(outputPath, ShortName), progress); + } + } + + public void ExtractAndMerge(string outputPath, IExtractProgress progress) + { + foreach (var child in Children) + { + if (progress.CancellationToken.IsCancellationRequested) + break; + + var childOutputPath = Path.Combine(outputPath, ShortName); + if (child is IdxViewModel idxVm) + idxVm.ExtractAndMerge(childOutputPath, progress); + else + child.Extract(childOutputPath, progress); + } + } + } +} diff --git a/OpenKh.Tools.IdxImg/Views/ExtractProgressWindow.xaml.cs b/OpenKh.Tools.IdxImg/Views/ExtractProgressWindow.xaml.cs index 938efc362..7252c1a07 100644 --- a/OpenKh.Tools.IdxImg/Views/ExtractProgressWindow.xaml.cs +++ b/OpenKh.Tools.IdxImg/Views/ExtractProgressWindow.xaml.cs @@ -1,38 +1,38 @@ -using OpenKh.Tools.IdxImg.Interfaces; -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Windows; - -namespace OpenKh.Tools.IdxImg.Views -{ - /// - /// Interaction logic for ExtractProgressWindow.xaml - /// - public partial class ExtractProgressWindow : Window, IExtractProgress, INotifyPropertyChanged - { - public ExtractProgressWindow(CancellationTokenSource cts) - { - InitializeComponent(); - DataContext = this; - CancellationToken = cts.Token; - } - - public CancellationToken CancellationToken { get; } - public string FileName { get; set; } - - public void SetExtractedName(string name) - { - FileName = name; - Application.Current.Dispatcher.Invoke(() => - OnPropertyChanged(nameof(FileName))); - } - - protected void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - - public event PropertyChangedEventHandler PropertyChanged; - } -} +using OpenKh.Tools.IdxImg.Interfaces; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Windows; + +namespace OpenKh.Tools.IdxImg.Views +{ + /// + /// Interaction logic for ExtractProgressWindow.xaml + /// + public partial class ExtractProgressWindow : Window, IExtractProgress, INotifyPropertyChanged + { + public ExtractProgressWindow(CancellationTokenSource cts) + { + InitializeComponent(); + DataContext = this; + CancellationToken = cts.Token; + } + + public CancellationToken CancellationToken { get; } + public string FileName { get; set; } + + public void SetExtractedName(string name) + { + FileName = name; + Application.Current.Dispatcher.Invoke(() => + OnPropertyChanged(nameof(FileName))); + } + + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public event PropertyChangedEventHandler PropertyChanged; + } +} diff --git a/OpenKh.Tools.IdxImg/Views/FilePropertyView.xaml.cs b/OpenKh.Tools.IdxImg/Views/FilePropertyView.xaml.cs index 6ebcd4cae..908221b0a 100644 --- a/OpenKh.Tools.IdxImg/Views/FilePropertyView.xaml.cs +++ b/OpenKh.Tools.IdxImg/Views/FilePropertyView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace OpenKh.Tools.IdxImg.Views -{ - /// - /// Interaction logic for FilePropertyView.xaml - /// - public partial class FilePropertyView : UserControl - { - public FilePropertyView() - { - InitializeComponent(); - } - } -} +using System.Windows.Controls; + +namespace OpenKh.Tools.IdxImg.Views +{ + /// + /// Interaction logic for FilePropertyView.xaml + /// + public partial class FilePropertyView : UserControl + { + public FilePropertyView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.IdxImg/Views/IdxTreeView.xaml.cs b/OpenKh.Tools.IdxImg/Views/IdxTreeView.xaml.cs index 3fd7d01c4..e510302d6 100644 --- a/OpenKh.Tools.IdxImg/Views/IdxTreeView.xaml.cs +++ b/OpenKh.Tools.IdxImg/Views/IdxTreeView.xaml.cs @@ -1,25 +1,25 @@ -using OpenKh.Tools.IdxImg.Interfaces; -using System.Windows; -using System.Windows.Controls; - -namespace OpenKh.Tools.IdxImg.Views -{ - /// - /// Interaction logic for IdxTreeView.xaml - /// - public partial class IdxTreeView : UserControl - { - public IdxTreeView() - { - InitializeComponent(); - } - - private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) - { - if (DataContext is ITreeSelectedItem treeSelectedItem) - { - treeSelectedItem.TreeSelectedItem = e.NewValue; - } - } - } -} +using OpenKh.Tools.IdxImg.Interfaces; +using System.Windows; +using System.Windows.Controls; + +namespace OpenKh.Tools.IdxImg.Views +{ + /// + /// Interaction logic for IdxTreeView.xaml + /// + public partial class IdxTreeView : UserControl + { + public IdxTreeView() + { + InitializeComponent(); + } + + private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) + { + if (DataContext is ITreeSelectedItem treeSelectedItem) + { + treeSelectedItem.TreeSelectedItem = e.NewValue; + } + } + } +} diff --git a/OpenKh.Tools.ImageViewer/App.xaml.cs b/OpenKh.Tools.ImageViewer/App.xaml.cs index 4acd4c8dd..235844a7b 100644 --- a/OpenKh.Tools.ImageViewer/App.xaml.cs +++ b/OpenKh.Tools.ImageViewer/App.xaml.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; - -namespace OpenKh.Tools.ImageViewer -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace OpenKh.Tools.ImageViewer +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/OpenKh.Tools.ImageViewer/ImageViewerModule.cs b/OpenKh.Tools.ImageViewer/ImageViewerModule.cs index 5176152b7..4b8f61600 100644 --- a/OpenKh.Tools.ImageViewer/ImageViewerModule.cs +++ b/OpenKh.Tools.ImageViewer/ImageViewerModule.cs @@ -1,14 +1,14 @@ -using OpenKh.Tools.Common; -using OpenKh.Tools.ImageViewer.Views; -using Xe.Tools; - -namespace OpenKh.Tools.ImageViewer -{ - public class ImageViewerModule : IToolModule - { - public bool? ShowDialog(ToolInvokeDesc desc) - { - return new MainWindow(desc).ShowDialog(); - } - } -} +using OpenKh.Tools.Common; +using OpenKh.Tools.ImageViewer.Views; +using Xe.Tools; + +namespace OpenKh.Tools.ImageViewer +{ + public class ImageViewerModule : IToolModule + { + public bool? ShowDialog(ToolInvokeDesc desc) + { + return new MainWindow(desc).ShowDialog(); + } + } +} diff --git a/OpenKh.Tools.ImageViewer/Services/IImageContainer.cs b/OpenKh.Tools.ImageViewer/Services/IImageContainer.cs index cacf01e2c..4fbadac0b 100644 --- a/OpenKh.Tools.ImageViewer/Services/IImageContainer.cs +++ b/OpenKh.Tools.ImageViewer/Services/IImageContainer.cs @@ -1,14 +1,14 @@ -using OpenKh.Imaging; -using System.Collections.Generic; - -namespace OpenKh.Tools.ImageViewer.Services -{ - public interface IImageContainer - { - int Count { get; } - - IEnumerable Images { get; } - - IImageRead GetImage(int index); - } -} +using OpenKh.Imaging; +using System.Collections.Generic; + +namespace OpenKh.Tools.ImageViewer.Services +{ + public interface IImageContainer + { + int Count { get; } + + IEnumerable Images { get; } + + IImageRead GetImage(int index); + } +} diff --git a/OpenKh.Tools.ImageViewer/Services/IImageFormat.cs b/OpenKh.Tools.ImageViewer/Services/IImageFormat.cs index 7383a1450..c4aa1d5aa 100644 --- a/OpenKh.Tools.ImageViewer/Services/IImageFormat.cs +++ b/OpenKh.Tools.ImageViewer/Services/IImageFormat.cs @@ -1,20 +1,20 @@ -using OpenKh.Imaging; -using System.IO; - -namespace OpenKh.Tools.ImageViewer.Services -{ - public interface IImageFormat - { - string Name { get; } - - string Extension { get; } - - bool IsContainer { get; } - - bool IsCreationSupported { get; } - - bool IsValid(Stream stream); - - T As() where T : IImageFormat; - } -} +using OpenKh.Imaging; +using System.IO; + +namespace OpenKh.Tools.ImageViewer.Services +{ + public interface IImageFormat + { + string Name { get; } + + string Extension { get; } + + bool IsContainer { get; } + + bool IsCreationSupported { get; } + + bool IsValid(Stream stream); + + T As() where T : IImageFormat; + } +} diff --git a/OpenKh.Tools.ImageViewer/Services/IImageFormatService.cs b/OpenKh.Tools.ImageViewer/Services/IImageFormatService.cs index 9eff2d71d..839f2fcb0 100644 --- a/OpenKh.Tools.ImageViewer/Services/IImageFormatService.cs +++ b/OpenKh.Tools.ImageViewer/Services/IImageFormatService.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using System.IO; - -namespace OpenKh.Tools.ImageViewer.Services -{ - public interface IImageFormatService - { - IEnumerable Formats { get; } - - IImageFormat GetFormatByFileName(string fileName); - - IImageFormat GetFormatByContent(Stream stream); - } -} +using System.Collections.Generic; +using System.IO; + +namespace OpenKh.Tools.ImageViewer.Services +{ + public interface IImageFormatService + { + IEnumerable Formats { get; } + + IImageFormat GetFormatByFileName(string fileName); + + IImageFormat GetFormatByContent(Stream stream); + } +} diff --git a/OpenKh.Tools.ImageViewer/Services/IImageMultiple.cs b/OpenKh.Tools.ImageViewer/Services/IImageMultiple.cs index bed1eebeb..b0073a826 100644 --- a/OpenKh.Tools.ImageViewer/Services/IImageMultiple.cs +++ b/OpenKh.Tools.ImageViewer/Services/IImageMultiple.cs @@ -1,11 +1,11 @@ -using System.IO; - -namespace OpenKh.Tools.ImageViewer.Services -{ - public interface IImageMultiple : IImageFormat - { - IImageContainer Read(Stream stream); - - void Write(Stream stream, IImageContainer image); - } -} +using System.IO; + +namespace OpenKh.Tools.ImageViewer.Services +{ + public interface IImageMultiple : IImageFormat + { + IImageContainer Read(Stream stream); + + void Write(Stream stream, IImageContainer image); + } +} diff --git a/OpenKh.Tools.ImageViewer/Services/IImageSingle.cs b/OpenKh.Tools.ImageViewer/Services/IImageSingle.cs index 521ed7b95..456c85318 100644 --- a/OpenKh.Tools.ImageViewer/Services/IImageSingle.cs +++ b/OpenKh.Tools.ImageViewer/Services/IImageSingle.cs @@ -1,12 +1,12 @@ -using OpenKh.Imaging; -using System.IO; - -namespace OpenKh.Tools.ImageViewer.Services -{ - public interface IImageSingle : IImageFormat - { - IImageRead Read(Stream stream); - - void Write(Stream stream, IImageRead image); - } -} +using OpenKh.Imaging; +using System.IO; + +namespace OpenKh.Tools.ImageViewer.Services +{ + public interface IImageSingle : IImageFormat + { + IImageRead Read(Stream stream); + + void Write(Stream stream, IImageRead image); + } +} diff --git a/OpenKh.Tools.ImageViewer/Services/ImageFormatService.GenericImageFormat.cs b/OpenKh.Tools.ImageViewer/Services/ImageFormatService.GenericImageFormat.cs index 8906e6459..487c95b17 100644 --- a/OpenKh.Tools.ImageViewer/Services/ImageFormatService.GenericImageFormat.cs +++ b/OpenKh.Tools.ImageViewer/Services/ImageFormatService.GenericImageFormat.cs @@ -1,35 +1,35 @@ -using System; -using System.IO; - -namespace OpenKh.Tools.ImageViewer.Services -{ - public partial class ImageFormatService - { - private class GenericImageFormat : IImageFormat - { - private readonly Func isValid; - - public GenericImageFormat( - string name, - string ext, - bool isContainer, - bool isCreationSupported, - Func isValid) - { - Name = name; - Extension = ext; - IsContainer = isContainer; - IsCreationSupported = isCreationSupported; - this.isValid = isValid; - } - - public string Name { get; } - public string Extension { get; } - public bool IsContainer { get; } - public bool IsCreationSupported { get; } - public T As() where T : IImageFormat => (T)(object)this; - - public bool IsValid(Stream stream) => isValid(stream); - } - } -} +using System; +using System.IO; + +namespace OpenKh.Tools.ImageViewer.Services +{ + public partial class ImageFormatService + { + private class GenericImageFormat : IImageFormat + { + private readonly Func isValid; + + public GenericImageFormat( + string name, + string ext, + bool isContainer, + bool isCreationSupported, + Func isValid) + { + Name = name; + Extension = ext; + IsContainer = isContainer; + IsCreationSupported = isCreationSupported; + this.isValid = isValid; + } + + public string Name { get; } + public string Extension { get; } + public bool IsContainer { get; } + public bool IsCreationSupported { get; } + public T As() where T : IImageFormat => (T)(object)this; + + public bool IsValid(Stream stream) => isValid(stream); + } + } +} diff --git a/OpenKh.Tools.ImageViewer/Services/ImageFormatService.ImageContainer.cs b/OpenKh.Tools.ImageViewer/Services/ImageFormatService.ImageContainer.cs index f0eb6fc8b..84263652b 100644 --- a/OpenKh.Tools.ImageViewer/Services/ImageFormatService.ImageContainer.cs +++ b/OpenKh.Tools.ImageViewer/Services/ImageFormatService.ImageContainer.cs @@ -1,23 +1,23 @@ -using OpenKh.Imaging; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Tools.ImageViewer.Services -{ - public partial class ImageFormatService - { - internal class ImageContainer : IImageContainer - { - private readonly IImageRead[] _images; - - public ImageContainer(IEnumerable images) - { - _images = images.ToArray(); - } - - public int Count => _images.Length; - public IEnumerable Images => _images; - public IImageRead GetImage(int index) => _images[index]; - } - } -} +using OpenKh.Imaging; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Tools.ImageViewer.Services +{ + public partial class ImageFormatService + { + internal class ImageContainer : IImageContainer + { + private readonly IImageRead[] _images; + + public ImageContainer(IEnumerable images) + { + _images = images.ToArray(); + } + + public int Count => _images.Length; + public IEnumerable Images => _images; + public IImageRead GetImage(int index) => _images[index]; + } + } +} diff --git a/OpenKh.Tools.ImageViewer/Services/ImageFormatService.MultipleImageFormat.cs b/OpenKh.Tools.ImageViewer/Services/ImageFormatService.MultipleImageFormat.cs index af5215280..7a9f4daf8 100644 --- a/OpenKh.Tools.ImageViewer/Services/ImageFormatService.MultipleImageFormat.cs +++ b/OpenKh.Tools.ImageViewer/Services/ImageFormatService.MultipleImageFormat.cs @@ -1,30 +1,30 @@ -using System; -using System.IO; - -namespace OpenKh.Tools.ImageViewer.Services -{ - public partial class ImageFormatService - { - private class MultipleImageFormat : GenericImageFormat, IImageMultiple - { - private readonly Func read; - private readonly Action write; - - public MultipleImageFormat( - string name, - string ext, - bool isCreationSupported, - Func isValid, - Func read, - Action write) : - base(name, ext, true, isCreationSupported, isValid) - { - this.read = read; - this.write = write; - } - - public IImageContainer Read(Stream stream) => read(stream); - public void Write(Stream stream, IImageContainer image) => write(stream, image); - } - } -} +using System; +using System.IO; + +namespace OpenKh.Tools.ImageViewer.Services +{ + public partial class ImageFormatService + { + private class MultipleImageFormat : GenericImageFormat, IImageMultiple + { + private readonly Func read; + private readonly Action write; + + public MultipleImageFormat( + string name, + string ext, + bool isCreationSupported, + Func isValid, + Func read, + Action write) : + base(name, ext, true, isCreationSupported, isValid) + { + this.read = read; + this.write = write; + } + + public IImageContainer Read(Stream stream) => read(stream); + public void Write(Stream stream, IImageContainer image) => write(stream, image); + } + } +} diff --git a/OpenKh.Tools.ImageViewer/Services/ImageFormatService.SingleImageFormat.cs b/OpenKh.Tools.ImageViewer/Services/ImageFormatService.SingleImageFormat.cs index 0d6a3a6a9..c5efab316 100644 --- a/OpenKh.Tools.ImageViewer/Services/ImageFormatService.SingleImageFormat.cs +++ b/OpenKh.Tools.ImageViewer/Services/ImageFormatService.SingleImageFormat.cs @@ -1,31 +1,31 @@ -using OpenKh.Imaging; -using System; -using System.IO; - -namespace OpenKh.Tools.ImageViewer.Services -{ - public partial class ImageFormatService - { - private class SingleImageFormat : GenericImageFormat, IImageSingle - { - private readonly Func read; - private readonly Action write; - - public SingleImageFormat( - string name, - string ext, - bool isCreationSupported, - Func isValid, - Func read, - Action write) : - base(name, ext, false, isCreationSupported, isValid) - { - this.read = read; - this.write = write; - } - - public IImageRead Read(Stream stream) => read(stream); - public void Write(Stream stream, IImageRead image) => write(stream, image); - } - } -} +using OpenKh.Imaging; +using System; +using System.IO; + +namespace OpenKh.Tools.ImageViewer.Services +{ + public partial class ImageFormatService + { + private class SingleImageFormat : GenericImageFormat, IImageSingle + { + private readonly Func read; + private readonly Action write; + + public SingleImageFormat( + string name, + string ext, + bool isCreationSupported, + Func isValid, + Func read, + Action write) : + base(name, ext, false, isCreationSupported, isValid) + { + this.read = read; + this.write = write; + } + + public IImageRead Read(Stream stream) => read(stream); + public void Write(Stream stream, IImageRead image) => write(stream, image); + } + } +} diff --git a/OpenKh.Tools.ImageViewer/Services/ImageFormatService.cs b/OpenKh.Tools.ImageViewer/Services/ImageFormatService.cs index 8b441fbad..f3a7a6cd0 100644 --- a/OpenKh.Tools.ImageViewer/Services/ImageFormatService.cs +++ b/OpenKh.Tools.ImageViewer/Services/ImageFormatService.cs @@ -1,104 +1,104 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using OpenKh.Bbs; -using OpenKh.Common; -using OpenKh.Imaging; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using OpenKh.Tools.Common.Imaging; - -namespace OpenKh.Tools.ImageViewer.Services -{ - public partial class ImageFormatService : IImageFormatService - { - private static readonly IImageFormat[] imageFormat; - - static ImageFormatService() - { - imageFormat = new IImageFormat[] - { - GetImageFormat("PNG", "png", true, Png.IsValid, Png.Read, (stream, image) => Png.Write(stream, image)), - GetImageFormat("BMP", "bmp", true, Bmp.IsValid, Bmp.Read, (stream, image) => Bmp.Write(stream, image)), - GetImageFormat("TIFF", "tiff", true, Tiff.IsValid, Tiff.Read, (stream, image) => Tiff.Write(stream, image)), - - GetImageFormat("FAC", "fac", true, Imgd.IsFac, s => Imgd.ReadAsFac(s), (stream, images) => - Imgd.WriteAsFac(stream, images.Select(x => x.AsImgd()))), - - GetImageFormat("IMGD", "imd", true, Imgd.IsValid, Imgd.Read, (stream, image) => image.AsImgd().Write(stream)), - - GetImageFormat("IMGZ", "imz", true, Imgz.IsValid, s => Imgz.Read(s), (stream, images) => - Imgz.Write(stream, images.Select(x => x.AsImgd()))), - - GetImageFormat("KH2 Font", "bar", true, IsKh2Font, ReadKh2Font, WriteKh2Font), - - GetImageFormat("Font ARC", "arc", false, FontsArc.IsValid, s => - { - var fonts = FontsArc.Read(s); - return new[] - { - fonts.FontCmd.Image1, - fonts.FontCmd.Image2, - fonts.FontHelp.Image1, - fonts.FontHelp.Image2, - fonts.FontMenu.Image1, - fonts.FontMenu.Image2, - fonts.FontMes.Image1, - fonts.FontMes.Image2, - fonts.FontNumeral.Image1, - fonts.FontNumeral.Image2, - fonts.FontIcon, - }; - }, (stream, images) => - throw new NotImplementedException()), - - GetImageFormat("TIM2", "tm2", false, Tm2.IsValid, s => Tm2.Read(s), (stream, images) => - throw new NotImplementedException()), - - GetImageFormat("KH2TIM", "tex", false, _ => true, - s => ModelTexture.Read(s).Images.Cast(), - (stream, images) => throw new NotImplementedException()), - }; - } - - public IEnumerable Formats => imageFormat; - - public IImageFormat GetFormatByContent(Stream stream) => - imageFormat.FirstOrDefault(x => x.IsValid(stream.SetPosition(0))); - - public IImageFormat GetFormatByFileName(string fileName) - { - var extension = Path.GetExtension(fileName); - var dotIndex = extension.IndexOf('.'); - if (dotIndex >= 0) - extension = extension.Substring(dotIndex + 1); - - return imageFormat.FirstOrDefault(x => string.Compare(x.Extension, extension, System.StringComparison.OrdinalIgnoreCase) == 0); - } - - private static IImageFormat GetImageFormat( - string name, - string extension, - bool isCreationSupported, - Func isValid, - Func read, - Action write) - { - return new SingleImageFormat(name, extension, isCreationSupported, isValid, read, write); - } - - private static IImageFormat GetImageFormat( - string name, - string extension, - bool isCreationSupported, - Func isValid, - Func> read, - Action> write) - { - return new MultipleImageFormat(name, extension, isCreationSupported, isValid, - stream => new ImageContainer(read(stream)), - (stream, container) => write(stream, container.Images)); - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using OpenKh.Bbs; +using OpenKh.Common; +using OpenKh.Imaging; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using OpenKh.Tools.Common.Imaging; + +namespace OpenKh.Tools.ImageViewer.Services +{ + public partial class ImageFormatService : IImageFormatService + { + private static readonly IImageFormat[] imageFormat; + + static ImageFormatService() + { + imageFormat = new IImageFormat[] + { + GetImageFormat("PNG", "png", true, Png.IsValid, Png.Read, (stream, image) => Png.Write(stream, image)), + GetImageFormat("BMP", "bmp", true, Bmp.IsValid, Bmp.Read, (stream, image) => Bmp.Write(stream, image)), + GetImageFormat("TIFF", "tiff", true, Tiff.IsValid, Tiff.Read, (stream, image) => Tiff.Write(stream, image)), + + GetImageFormat("FAC", "fac", true, Imgd.IsFac, s => Imgd.ReadAsFac(s), (stream, images) => + Imgd.WriteAsFac(stream, images.Select(x => x.AsImgd()))), + + GetImageFormat("IMGD", "imd", true, Imgd.IsValid, Imgd.Read, (stream, image) => image.AsImgd().Write(stream)), + + GetImageFormat("IMGZ", "imz", true, Imgz.IsValid, s => Imgz.Read(s), (stream, images) => + Imgz.Write(stream, images.Select(x => x.AsImgd()))), + + GetImageFormat("KH2 Font", "bar", true, IsKh2Font, ReadKh2Font, WriteKh2Font), + + GetImageFormat("Font ARC", "arc", false, FontsArc.IsValid, s => + { + var fonts = FontsArc.Read(s); + return new[] + { + fonts.FontCmd.Image1, + fonts.FontCmd.Image2, + fonts.FontHelp.Image1, + fonts.FontHelp.Image2, + fonts.FontMenu.Image1, + fonts.FontMenu.Image2, + fonts.FontMes.Image1, + fonts.FontMes.Image2, + fonts.FontNumeral.Image1, + fonts.FontNumeral.Image2, + fonts.FontIcon, + }; + }, (stream, images) => + throw new NotImplementedException()), + + GetImageFormat("TIM2", "tm2", false, Tm2.IsValid, s => Tm2.Read(s), (stream, images) => + throw new NotImplementedException()), + + GetImageFormat("KH2TIM", "tex", false, _ => true, + s => ModelTexture.Read(s).Images.Cast(), + (stream, images) => throw new NotImplementedException()), + }; + } + + public IEnumerable Formats => imageFormat; + + public IImageFormat GetFormatByContent(Stream stream) => + imageFormat.FirstOrDefault(x => x.IsValid(stream.SetPosition(0))); + + public IImageFormat GetFormatByFileName(string fileName) + { + var extension = Path.GetExtension(fileName); + var dotIndex = extension.IndexOf('.'); + if (dotIndex >= 0) + extension = extension.Substring(dotIndex + 1); + + return imageFormat.FirstOrDefault(x => string.Compare(x.Extension, extension, System.StringComparison.OrdinalIgnoreCase) == 0); + } + + private static IImageFormat GetImageFormat( + string name, + string extension, + bool isCreationSupported, + Func isValid, + Func read, + Action write) + { + return new SingleImageFormat(name, extension, isCreationSupported, isValid, read, write); + } + + private static IImageFormat GetImageFormat( + string name, + string extension, + bool isCreationSupported, + Func isValid, + Func> read, + Action> write) + { + return new MultipleImageFormat(name, extension, isCreationSupported, isValid, + stream => new ImageContainer(read(stream)), + (stream, container) => write(stream, container.Images)); + } + } +} diff --git a/OpenKh.Tools.ImageViewer/Services/ImageFormatSevice.Kh2Font.cs b/OpenKh.Tools.ImageViewer/Services/ImageFormatSevice.Kh2Font.cs index 3963e2d85..8a356a00a 100644 --- a/OpenKh.Tools.ImageViewer/Services/ImageFormatSevice.Kh2Font.cs +++ b/OpenKh.Tools.ImageViewer/Services/ImageFormatSevice.Kh2Font.cs @@ -1,44 +1,44 @@ -using OpenKh.Common; -using OpenKh.Imaging; -using OpenKh.Kh2; -using OpenKh.Kh2.Contextes; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Tools.ImageViewer.Services -{ - public partial class ImageFormatService - { - private static bool IsKh2Font(Stream inputStream) - { - if (!Bar.IsValid(inputStream.SetPosition(0))) - return false; - - return Bar.Read(inputStream.SetPosition(0)) - .Any(x => x.Type == Bar.EntryType.RawBitmap); - } - - private static IEnumerable ReadKh2Font(Stream inputStream) - { - var fontContext = new FontContext(); - fontContext.Read(Bar.Read(inputStream.SetPosition(0)) - .Where(x => x.Type == Bar.EntryType.RawBitmap)); - - return new[] - { - fontContext.ImageSystem, - fontContext.ImageSystem2, - fontContext.ImageEvent, - fontContext.ImageEvent2, - fontContext.ImageIcon - }.Where(x => x != null); - } - - private static void WriteKh2Font(Stream outputStream, IEnumerable images) - { - throw new NotImplementedException(); - } - } -} +using OpenKh.Common; +using OpenKh.Imaging; +using OpenKh.Kh2; +using OpenKh.Kh2.Contextes; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Tools.ImageViewer.Services +{ + public partial class ImageFormatService + { + private static bool IsKh2Font(Stream inputStream) + { + if (!Bar.IsValid(inputStream.SetPosition(0))) + return false; + + return Bar.Read(inputStream.SetPosition(0)) + .Any(x => x.Type == Bar.EntryType.RawBitmap); + } + + private static IEnumerable ReadKh2Font(Stream inputStream) + { + var fontContext = new FontContext(); + fontContext.Read(Bar.Read(inputStream.SetPosition(0)) + .Where(x => x.Type == Bar.EntryType.RawBitmap)); + + return new[] + { + fontContext.ImageSystem, + fontContext.ImageSystem2, + fontContext.ImageEvent, + fontContext.ImageEvent2, + fontContext.ImageIcon + }.Where(x => x != null); + } + + private static void WriteKh2Font(Stream outputStream, IEnumerable images) + { + throw new NotImplementedException(); + } + } +} diff --git a/OpenKh.Tools.ImageViewer/ViewModels/ImageContainerViewModel.cs b/OpenKh.Tools.ImageViewer/ViewModels/ImageContainerViewModel.cs index 610f61e9f..c6db9c9fe 100644 --- a/OpenKh.Tools.ImageViewer/ViewModels/ImageContainerViewModel.cs +++ b/OpenKh.Tools.ImageViewer/ViewModels/ImageContainerViewModel.cs @@ -1,29 +1,29 @@ -using OpenKh.Tools.ImageViewer.Services; -using System.Collections.Generic; -using System.Linq; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.ImageViewer.ViewModels -{ - public class ImageContainerViewModel : GenericListModel - { - private readonly IImageContainer imageContainer; - - public ImageContainerViewModel(IImageContainer imageContainer) : - this(imageContainer.Images.Select((image, index) => new ImageViewModel(image, index))) - { - this.imageContainer = imageContainer; - } - - private ImageContainerViewModel(IEnumerable imageViewModels) : - base(imageViewModels) - { - - } - - protected override ImageViewModel OnNewItem() - { - throw new System.NotImplementedException(); - } - } -} +using OpenKh.Tools.ImageViewer.Services; +using System.Collections.Generic; +using System.Linq; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.ImageViewer.ViewModels +{ + public class ImageContainerViewModel : GenericListModel + { + private readonly IImageContainer imageContainer; + + public ImageContainerViewModel(IImageContainer imageContainer) : + this(imageContainer.Images.Select((image, index) => new ImageViewModel(image, index))) + { + this.imageContainer = imageContainer; + } + + private ImageContainerViewModel(IEnumerable imageViewModels) : + base(imageViewModels) + { + + } + + protected override ImageViewModel OnNewItem() + { + throw new System.NotImplementedException(); + } + } +} diff --git a/OpenKh.Tools.ImageViewer/ViewModels/ImageViewModel.cs b/OpenKh.Tools.ImageViewer/ViewModels/ImageViewModel.cs index ffc108720..f67163d45 100644 --- a/OpenKh.Tools.ImageViewer/ViewModels/ImageViewModel.cs +++ b/OpenKh.Tools.ImageViewer/ViewModels/ImageViewModel.cs @@ -1,34 +1,34 @@ -using OpenKh.Imaging; -using OpenKh.Tools.Common; -using System.Windows.Media.Imaging; -using Xe.Tools; - -namespace OpenKh.Tools.ImageViewer.ViewModels -{ - public class ImageViewModel : BaseNotifyPropertyChanged - { - public ImageViewModel(IImageRead image, int index = -1) - { - Source = image; - Bitmap = Source.GetBimapSource(); - Index = index; - } - - public IImageRead Source { get; } - public BitmapSource Bitmap { get; } - public int Index { get; } - - public string Name => $"#{Index}"; - - public int Width => Source.Size.Width; - public int Height => Source.Size.Height; - - public string Size => $"{Width}x{Height}"; - public string Format => Source.PixelFormat.ToString(); - - public string ImageSize => Source != null ? $"{Source.Size.Width}x{Source.Size.Height}" : "-"; - public string ImageFormat => Source?.PixelFormat.ToString(); - - public override string ToString() => $"{Name} {Size} {Format}"; - } -} +using OpenKh.Imaging; +using OpenKh.Tools.Common; +using System.Windows.Media.Imaging; +using Xe.Tools; + +namespace OpenKh.Tools.ImageViewer.ViewModels +{ + public class ImageViewModel : BaseNotifyPropertyChanged + { + public ImageViewModel(IImageRead image, int index = -1) + { + Source = image; + Bitmap = Source.GetBimapSource(); + Index = index; + } + + public IImageRead Source { get; } + public BitmapSource Bitmap { get; } + public int Index { get; } + + public string Name => $"#{Index}"; + + public int Width => Source.Size.Width; + public int Height => Source.Size.Height; + + public string Size => $"{Width}x{Height}"; + public string Format => Source.PixelFormat.ToString(); + + public string ImageSize => Source != null ? $"{Source.Size.Width}x{Source.Size.Height}" : "-"; + public string ImageFormat => Source?.PixelFormat.ToString(); + + public override string ToString() => $"{Name} {Size} {Format}"; + } +} diff --git a/OpenKh.Tools.ImageViewer/ViewModels/ImageViewerViewModel.cs b/OpenKh.Tools.ImageViewer/ViewModels/ImageViewerViewModel.cs index 9227a4197..3b6fe511d 100644 --- a/OpenKh.Tools.ImageViewer/ViewModels/ImageViewerViewModel.cs +++ b/OpenKh.Tools.ImageViewer/ViewModels/ImageViewerViewModel.cs @@ -1,122 +1,122 @@ using OpenKh.Command.ImgTool.Utils; -using OpenKh.Common; +using OpenKh.Common; using OpenKh.Imaging; using OpenKh.Kh2; using OpenKh.Kh2.Utils; -using OpenKh.Tools.Common; +using OpenKh.Tools.Common; using OpenKh.Tools.Common.Imaging; -using OpenKh.Tools.ImageViewer.Services; -using System; -using System.Collections.Generic; +using OpenKh.Tools.ImageViewer.Services; +using System; +using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Windows; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.ImageViewer.ViewModels -{ - public class ImageViewerViewModel : BaseNotifyPropertyChanged - { - private const int ZoomLevelFit = -1; - private static readonly IImageFormatService _imageFormatService = new ImageFormatService(); - private static readonly List OpenFilters = FileDialogFilterComposer - .Compose() - .AddExtensions("All supported images", GetAllSupportedExtensions()) - .Concat(_imageFormatService.Formats.Select(x => FileDialogFilter.ByExtensions($"{x.Name} image", x.Extension))) - .ToList() - .AddAllFiles(); - - private static readonly List ExportToContainerFilters = FileDialogFilterComposer - .Compose() - .AddExtensions("All supported images for export", GetAllSupportedExtensions(x => x.IsCreationSupported && x.IsContainer)) - .Concat(_imageFormatService.Formats.Where(x => x.IsCreationSupported && x.IsContainer).Select(x => FileDialogFilter.ByExtensions($"{x.Name} image", x.Extension))) - .ToList() - .AddAllFiles(); - - private static readonly List ExportToSingleImageFilters = FileDialogFilterComposer - .Compose() - .AddExtensions("All supported images for export", GetAllSupportedExtensions(x => x.IsCreationSupported)) - .Concat(_imageFormatService.Formats.Where(x => x.IsCreationSupported).Select(x => FileDialogFilter.ByExtensions($"{x.Name} image", x.Extension))) - .ToList() - .AddAllFiles(); - - private static string ApplicationName = Utilities.GetApplicationName(); - private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - - public string Title - { - get - { - var fileName = IsTool ? _toolInvokeDesc.Title : (Path.GetFileName(FileName) ?? "untitled"); - - return $"{fileName} | {ApplicationName}"; - } - } - - public bool IsTool => _toolInvokeDesc != null; - - public ImageViewerViewModel() - { - OpenCommand = new RelayCommand(x => - { - FileDialog.OnOpen(fileName => - { - LoadImage(fileName); - }, OpenFilters); - }, x => !IsTool); - - SaveCommand = new RelayCommand(x => - { - if (IsTool) - { +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.ImageViewer.ViewModels +{ + public class ImageViewerViewModel : BaseNotifyPropertyChanged + { + private const int ZoomLevelFit = -1; + private static readonly IImageFormatService _imageFormatService = new ImageFormatService(); + private static readonly List OpenFilters = FileDialogFilterComposer + .Compose() + .AddExtensions("All supported images", GetAllSupportedExtensions()) + .Concat(_imageFormatService.Formats.Select(x => FileDialogFilter.ByExtensions($"{x.Name} image", x.Extension))) + .ToList() + .AddAllFiles(); + + private static readonly List ExportToContainerFilters = FileDialogFilterComposer + .Compose() + .AddExtensions("All supported images for export", GetAllSupportedExtensions(x => x.IsCreationSupported && x.IsContainer)) + .Concat(_imageFormatService.Formats.Where(x => x.IsCreationSupported && x.IsContainer).Select(x => FileDialogFilter.ByExtensions($"{x.Name} image", x.Extension))) + .ToList() + .AddAllFiles(); + + private static readonly List ExportToSingleImageFilters = FileDialogFilterComposer + .Compose() + .AddExtensions("All supported images for export", GetAllSupportedExtensions(x => x.IsCreationSupported)) + .Concat(_imageFormatService.Formats.Where(x => x.IsCreationSupported).Select(x => FileDialogFilter.ByExtensions($"{x.Name} image", x.Extension))) + .ToList() + .AddAllFiles(); + + private static string ApplicationName = Utilities.GetApplicationName(); + private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + + public string Title + { + get + { + var fileName = IsTool ? _toolInvokeDesc.Title : (Path.GetFileName(FileName) ?? "untitled"); + + return $"{fileName} | {ApplicationName}"; + } + } + + public bool IsTool => _toolInvokeDesc != null; + + public ImageViewerViewModel() + { + OpenCommand = new RelayCommand(x => + { + FileDialog.OnOpen(fileName => + { + LoadImage(fileName); + }, OpenFilters); + }, x => !IsTool); + + SaveCommand = new RelayCommand(x => + { + if (IsTool) + { // Clear current bar entry content before saving. _toolInvokeDesc.SelectedEntry.Stream.SetLength(0); - - Save(_toolInvokeDesc.SelectedEntry.Stream); - } - else if (!string.IsNullOrEmpty(FileName)) - { - using (var stream = File.Open(FileName, FileMode.Create)) - { - Save(stream); - } - } - else - { - SaveAsCommand.Execute(x); - } - }, x => ImageFormat != null); - - SaveAsCommand = new RelayCommand(x => - { - var filter = new List().AddExtensions($"{ImageFormat.Name} format", ImageFormat.Extension); - FileDialog.OnSave(fileName => - { - using (var stream = File.Open(fileName, FileMode.Create)) - { - Save(stream); - } - }, filter); - }, x => ImageFormat != null && !IsTool); - - ExitCommand = new RelayCommand(x => - { - Window.Close(); - }, x => true); - - AboutCommand = new RelayCommand(x => - { - new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); - }, x => true); - - ExportCurrentCommand = new RelayCommand(x => - { - var singleImage = Image?.Source; + + Save(_toolInvokeDesc.SelectedEntry.Stream); + } + else if (!string.IsNullOrEmpty(FileName)) + { + using (var stream = File.Open(FileName, FileMode.Create)) + { + Save(stream); + } + } + else + { + SaveAsCommand.Execute(x); + } + }, x => ImageFormat != null); + + SaveAsCommand = new RelayCommand(x => + { + var filter = new List().AddExtensions($"{ImageFormat.Name} format", ImageFormat.Extension); + FileDialog.OnSave(fileName => + { + using (var stream = File.Open(fileName, FileMode.Create)) + { + Save(stream); + } + }, filter); + }, x => ImageFormat != null && !IsTool); + + ExitCommand = new RelayCommand(x => + { + Window.Close(); + }, x => true); + + AboutCommand = new RelayCommand(x => + { + new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); + }, x => true); + + ExportCurrentCommand = new RelayCommand(x => + { + var singleImage = Image?.Source; if (singleImage != null) { FileDialog.OnSave(fileName => @@ -150,10 +150,10 @@ public ImageViewerViewModel() } ); }, ExportToSingleImageFilters); - } - }, x => true); - - ExportAllCommand = new RelayCommand(x => + } + }, x => true); + + ExportAllCommand = new RelayCommand(x => { var multiImages = GetImagesForExport(); if (multiImages.Any()) @@ -173,18 +173,18 @@ public ImageViewerViewModel() File.OpenWrite(fileName).Using(stream => imageFormat.As().Write(stream, imageContainer)); }, ExportToContainerFilters); - } - }, x => true); - - ImportCommand = new RelayCommand( - parameter => + } + }, x => true); + + ImportCommand = new RelayCommand( + parameter => { AddImage(Enum.Parse($"{parameter}")); }, - x => IsMultipleImageFormat - ); - - CreateNewImgzCommand = new RelayCommand( + x => IsMultipleImageFormat + ); + + CreateNewImgzCommand = new RelayCommand( x => { if (IsSingleImageFormat || IsMultipleImageFormat) @@ -208,10 +208,10 @@ public ImageViewerViewModel() }; } ); - } - ); - - ConvertToImgzCommand = new RelayCommand( + } + ); + + ConvertToImgzCommand = new RelayCommand( x => { FileName = null; @@ -226,19 +226,19 @@ public ImageViewerViewModel() }; } ); - }, - x => IsSingleImageFormat - ); - - InsertEmptyImageCommand = new RelayCommand( + }, + x => IsSingleImageFormat + ); + + InsertEmptyImageCommand = new RelayCommand( x => { AddEmptyImage(AddPosition.BeforeCurrent); - }, - x => IsMultipleImageFormat - ); - - RemoveImageCommand = new RelayCommand( + }, + x => IsMultipleImageFormat + ); + + RemoveImageCommand = new RelayCommand( x => { EditImageList( @@ -250,11 +250,11 @@ public ImageViewerViewModel() }; } ); - }, - x => IsMultipleImageFormat && ImageContainer.Count >= 1 - ); - - ConvertBitsPerPixelCommand = new RelayCommand( + }, + x => IsMultipleImageFormat && ImageContainer.Count >= 1 + ); + + ConvertBitsPerPixelCommand = new RelayCommand( parameter => { try @@ -287,13 +287,13 @@ public ImageViewerViewModel() } catch (Exception ex) { - MessageBox.Show($"{ex.Message}", - "Error", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show($"{ex.Message}", + "Error", MessageBoxButton.OK, MessageBoxImage.Error); } - }, - x => IsMultipleImageFormat && ImageContainer.Count >= 1 - ); - + }, + x => IsMultipleImageFormat && ImageContainer.Count >= 1 + ); + CheckQuant = new RelayCommand(x => { if (UsePngquant == true) @@ -310,182 +310,182 @@ public ImageViewerViewModel() OnPropertyChanged(nameof(UsePngquant)); } } - }); - - ZoomLevel = ZoomLevelFit; - } - - public bool IsMultipleImageFormat => _imageFormat != null ? _imageFormat.IsContainer : false; - public bool IsSingleImageFormat => _imageFormat != null ? !_imageFormat.IsContainer : false; - - public bool? UsePngquant { get; set; } - - - public ImageViewerViewModel(Stream stream) : - this() - { - LoadImage(stream); - } - - private string _fileName; - private IImageFormat _imageFormat; - private IImageContainer _imageContainer; - private double _zoomLevel; - private bool _zoomFit; - private ImageViewModel _imageViewModel; - private ImageContainerViewModel _imageContainerItems; - private ToolInvokeDesc _toolInvokeDesc; - - public string FileName - { - get => _fileName; - set - { - _fileName = value; - OnPropertyChanged(nameof(Title)); - } - } - - public RelayCommand OpenCommand { get; set; } - public RelayCommand CheckQuant { get; set; } - public RelayCommand SaveCommand { get; set; } - public RelayCommand SaveAsCommand { get; set; } - public RelayCommand ExitCommand { get; set; } - public RelayCommand AboutCommand { get; set; } - public RelayCommand ExportCurrentCommand { get; set; } - public RelayCommand ExportAllCommand { get; set; } + }); + + ZoomLevel = ZoomLevelFit; + } + + public bool IsMultipleImageFormat => _imageFormat != null ? _imageFormat.IsContainer : false; + public bool IsSingleImageFormat => _imageFormat != null ? !_imageFormat.IsContainer : false; + + public bool? UsePngquant { get; set; } + + + public ImageViewerViewModel(Stream stream) : + this() + { + LoadImage(stream); + } + + private string _fileName; + private IImageFormat _imageFormat; + private IImageContainer _imageContainer; + private double _zoomLevel; + private bool _zoomFit; + private ImageViewModel _imageViewModel; + private ImageContainerViewModel _imageContainerItems; + private ToolInvokeDesc _toolInvokeDesc; + + public string FileName + { + get => _fileName; + set + { + _fileName = value; + OnPropertyChanged(nameof(Title)); + } + } + + public RelayCommand OpenCommand { get; set; } + public RelayCommand CheckQuant { get; set; } + public RelayCommand SaveCommand { get; set; } + public RelayCommand SaveAsCommand { get; set; } + public RelayCommand ExitCommand { get; set; } + public RelayCommand AboutCommand { get; set; } + public RelayCommand ExportCurrentCommand { get; set; } + public RelayCommand ExportAllCommand { get; set; } public RelayCommand ImportCommand { get; set; } public RelayCommand CreateNewImgzCommand { get; } public RelayCommand ConvertToImgzCommand { get; private set; } public RelayCommand InsertEmptyImageCommand { get; private set; } public RelayCommand RemoveImageCommand { get; private set; } public RelayCommand ConvertBitsPerPixelCommand { get; private set; } - public IEnumerable> ZoomLevels { get; } = - new double[] - { - 0.25, 0.33, 0.5, 0.75, 1, 1.25, 1.50, 1.75, 2, 2.5, 3, 4, 6, 8, 12, 16, 1 - } - .Select(x => new KeyValuePair($"{x * 100.0}%", x)) - .Concat(new KeyValuePair[] - { - new KeyValuePair("Fit", ZoomLevelFit) - }) - .ToArray(); - - private IImageFormat ImageFormat - { - get => _imageFormat; - set - { - _imageFormat = value; - OnPropertyChanged(nameof(ImageType)); - OnPropertyChanged(nameof(ImageMultiple)); - OnPropertyChanged(nameof(ImageSelectionVisibility)); - OnPropertyChanged(nameof(SaveCommand)); - OnPropertyChanged(nameof(SaveAsCommand)); - } - } - - private IImageContainer ImageContainer - { - get => _imageContainer; - set - { - _imageContainer = value; - ImageContainerItems = new ImageContainerViewModel(_imageContainer); - } - } - - public ImageViewModel Image - { - get => _imageViewModel; - set - { - _imageViewModel = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(ImageZoomWidth)); - OnPropertyChanged(nameof(ImageZoomHeight)); - } - } - - public ImageContainerViewModel ImageContainerItems - { - get => _imageContainerItems; - set - { - _imageContainerItems = value; - OnPropertyChanged(); - } - } - - public string ImageType => _imageFormat?.Name ?? "Unknown"; - public string ImageMultiple => _imageFormat != null ? _imageFormat.IsContainer ? "Multiple" : "Single" : null; - public Visibility ImageSelectionVisibility => (_imageFormat?.IsContainer ?? false) ? Visibility.Visible : Visibility.Collapsed; - public double ZoomLevel - { - get => _zoomLevel; - set - { - _zoomLevel = value; - ZoomFit = _zoomLevel <= 0; - OnPropertyChanged(); - OnPropertyChanged(nameof(ImageZoomWidth)); - OnPropertyChanged(nameof(ImageZoomHeight)); - } - } - - public bool ZoomFit - { - get => _zoomFit; - set - { - _zoomFit = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(ImageFitVisibility)); - OnPropertyChanged(nameof(ImageCustomZoomVisibility)); - } - } - - public double ImageZoomWidth => (Image?.Width * ZoomLevel) ?? 0; - public double ImageZoomHeight => (Image?.Height * ZoomLevel) ?? 0; - - public Visibility ImageFitVisibility => ZoomFit ? Visibility.Visible : Visibility.Collapsed; - public Visibility ImageCustomZoomVisibility => ZoomFit ? Visibility.Collapsed : Visibility.Visible; - - public void LoadImage(ToolInvokeDesc toolInvokeDesc) - { - _toolInvokeDesc = toolInvokeDesc; - LoadImage(_toolInvokeDesc.SelectedEntry.Stream); - } - - public void LoadImage(string fileName) - { - using (var stream = File.OpenRead(fileName)) - { - LoadImage(stream); - FileName = fileName; - } - } - - private void LoadImage(Stream stream) - { - var imageFormat = _imageFormatService.GetFormatByContent(stream); - if (imageFormat == null) - throw new Exception("Image format not found for the given stream."); - - ImageFormat = imageFormat; - - if (ImageFormat.IsContainer) - { - ImageContainer = _imageFormat.As().Read(stream); - Image = ImageContainerItems.First(); - } - else - { - Image = new ImageViewModel(_imageFormat.As().Read(stream)); - } - } - + public IEnumerable> ZoomLevels { get; } = + new double[] + { + 0.25, 0.33, 0.5, 0.75, 1, 1.25, 1.50, 1.75, 2, 2.5, 3, 4, 6, 8, 12, 16, 1 + } + .Select(x => new KeyValuePair($"{x * 100.0}%", x)) + .Concat(new KeyValuePair[] + { + new KeyValuePair("Fit", ZoomLevelFit) + }) + .ToArray(); + + private IImageFormat ImageFormat + { + get => _imageFormat; + set + { + _imageFormat = value; + OnPropertyChanged(nameof(ImageType)); + OnPropertyChanged(nameof(ImageMultiple)); + OnPropertyChanged(nameof(ImageSelectionVisibility)); + OnPropertyChanged(nameof(SaveCommand)); + OnPropertyChanged(nameof(SaveAsCommand)); + } + } + + private IImageContainer ImageContainer + { + get => _imageContainer; + set + { + _imageContainer = value; + ImageContainerItems = new ImageContainerViewModel(_imageContainer); + } + } + + public ImageViewModel Image + { + get => _imageViewModel; + set + { + _imageViewModel = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(ImageZoomWidth)); + OnPropertyChanged(nameof(ImageZoomHeight)); + } + } + + public ImageContainerViewModel ImageContainerItems + { + get => _imageContainerItems; + set + { + _imageContainerItems = value; + OnPropertyChanged(); + } + } + + public string ImageType => _imageFormat?.Name ?? "Unknown"; + public string ImageMultiple => _imageFormat != null ? _imageFormat.IsContainer ? "Multiple" : "Single" : null; + public Visibility ImageSelectionVisibility => (_imageFormat?.IsContainer ?? false) ? Visibility.Visible : Visibility.Collapsed; + public double ZoomLevel + { + get => _zoomLevel; + set + { + _zoomLevel = value; + ZoomFit = _zoomLevel <= 0; + OnPropertyChanged(); + OnPropertyChanged(nameof(ImageZoomWidth)); + OnPropertyChanged(nameof(ImageZoomHeight)); + } + } + + public bool ZoomFit + { + get => _zoomFit; + set + { + _zoomFit = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(ImageFitVisibility)); + OnPropertyChanged(nameof(ImageCustomZoomVisibility)); + } + } + + public double ImageZoomWidth => (Image?.Width * ZoomLevel) ?? 0; + public double ImageZoomHeight => (Image?.Height * ZoomLevel) ?? 0; + + public Visibility ImageFitVisibility => ZoomFit ? Visibility.Visible : Visibility.Collapsed; + public Visibility ImageCustomZoomVisibility => ZoomFit ? Visibility.Collapsed : Visibility.Visible; + + public void LoadImage(ToolInvokeDesc toolInvokeDesc) + { + _toolInvokeDesc = toolInvokeDesc; + LoadImage(_toolInvokeDesc.SelectedEntry.Stream); + } + + public void LoadImage(string fileName) + { + using (var stream = File.OpenRead(fileName)) + { + LoadImage(stream); + FileName = fileName; + } + } + + private void LoadImage(Stream stream) + { + var imageFormat = _imageFormatService.GetFormatByContent(stream); + if (imageFormat == null) + throw new Exception("Image format not found for the given stream."); + + ImageFormat = imageFormat; + + if (ImageFormat.IsContainer) + { + ImageContainer = _imageFormat.As().Read(stream); + Image = ImageContainerItems.First(); + } + else + { + Image = new ImageViewModel(_imageFormat.As().Read(stream)); + } + } + private IImageRead CreateDummyImage() => Imgd.Create( new System.Drawing.Size(128, 128), @@ -528,18 +528,18 @@ private void EditImageList(Func, EditResult> editor) { Image = null; } - - ImageFormat = _imageFormatService.Formats.Single(it => it.Name == "IMGZ"); + + ImageFormat = _imageFormatService.Formats.Single(it => it.Name == "IMGZ"); } - + enum AddPosition { BeforeCurrent, ReplaceCurrent, AfterCurrent, Last, - } - + } + private void AddEmptyImage(AddPosition addPosition) { EditImageList( @@ -569,8 +569,8 @@ private void AddEmptyImage(AddPosition addPosition) }; } ); - } - + } + private void AddImage(AddPosition addPosition) { FileDialog.OnOpen(fileName => @@ -619,31 +619,31 @@ private void AddImage(AddPosition addPosition) }; } ); - } - }, OpenFilters); - } - - public void Save(Stream stream) => Save(stream, ImageFormat); - - public void Save(Stream stream, IImageFormat imageFormat) - { - if (imageFormat.IsContainer) - { - imageFormat.As().Write(stream, ImageContainer); - } - else - { - imageFormat.As().Write(stream, Image.Source); - } - } - - private static string GetAllSupportedExtensions(Func filter = null) - { - filter = filter ?? (it => true); - var extensions = _imageFormatService.Formats.Where(filter).Select(x => $"*.{x.Extension}"); - return string.Join(";", extensions).Substring(2); - } - + } + }, OpenFilters); + } + + public void Save(Stream stream) => Save(stream, ImageFormat); + + public void Save(Stream stream, IImageFormat imageFormat) + { + if (imageFormat.IsContainer) + { + imageFormat.As().Write(stream, ImageContainer); + } + else + { + imageFormat.As().Write(stream, Image.Source); + } + } + + private static string GetAllSupportedExtensions(Func filter = null) + { + filter = filter ?? (it => true); + var extensions = _imageFormatService.Formats.Where(filter).Select(x => $"*.{x.Extension}"); + return string.Join(";", extensions).Substring(2); + } + class RunCmd { private Process p; @@ -679,5 +679,5 @@ private IEnumerable GetImagesForExport() // no image loaded return new IImageRead[0]; } - } -} + } +} diff --git a/OpenKh.Tools.ImageViewer/Views/MainWindow.xaml.cs b/OpenKh.Tools.ImageViewer/Views/MainWindow.xaml.cs index 16a0f530d..48a456f91 100644 --- a/OpenKh.Tools.ImageViewer/Views/MainWindow.xaml.cs +++ b/OpenKh.Tools.ImageViewer/Views/MainWindow.xaml.cs @@ -1,39 +1,39 @@ -using OpenKh.Tools.Common; -using OpenKh.Tools.ImageViewer.ViewModels; -using System.Windows; -using System.Linq; - -namespace OpenKh.Tools.ImageViewer.Views -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); - DataContext = new ImageViewerViewModel(); - } - - public MainWindow(ToolInvokeDesc toolInvokeDesc) : this() - { - (DataContext as ImageViewerViewModel).LoadImage(toolInvokeDesc); - } - - private void DropAction(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop)) - { - var files = e.Data.GetData(DataFormats.FileDrop) as string[]; - var fileName = files?.FirstOrDefault(); - if (string.IsNullOrEmpty(fileName)) - return; - - var vm = DataContext as ImageViewerViewModel; - vm.LoadImage(fileName); - vm.FileName = fileName; - } - } - } -} +using OpenKh.Tools.Common; +using OpenKh.Tools.ImageViewer.ViewModels; +using System.Windows; +using System.Linq; + +namespace OpenKh.Tools.ImageViewer.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + DataContext = new ImageViewerViewModel(); + } + + public MainWindow(ToolInvokeDesc toolInvokeDesc) : this() + { + (DataContext as ImageViewerViewModel).LoadImage(toolInvokeDesc); + } + + private void DropAction(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + { + var files = e.Data.GetData(DataFormats.FileDrop) as string[]; + var fileName = files?.FirstOrDefault(); + if (string.IsNullOrEmpty(fileName)) + return; + + var vm = DataContext as ImageViewerViewModel; + vm.LoadImage(fileName); + vm.FileName = fileName; + } + } + } +} diff --git a/OpenKh.Tools.ItbEditor/ItbEntry.cs b/OpenKh.Tools.ItbEditor/ItbEntry.cs index 5564e8d08..0ae8493d1 100644 --- a/OpenKh.Tools.ItbEditor/ItbEntry.cs +++ b/OpenKh.Tools.ItbEditor/ItbEntry.cs @@ -1,37 +1,37 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; -using OpenKh.Bbs.SystemData; - -namespace OpenKh.Tools.ItbEditor -{ - public partial class ItbEntry : UserControl - { - public ItbEntry() - { - InitializeComponent(); - } - - private void ItemIDComboBox_SelectedIndexChanged(object sender, EventArgs e) - { - - } - - private void ItemKindComboBox_SelectedIndexChanged(object sender, EventArgs e) - { - switch (ItemKindComboBox.SelectedIndex) - { - case 0: - ItemIDComboBox.DataSource = Enum.GetValues(typeof(Item.Type)); - break; - case 1: - ItemIDComboBox.DataSource = Enum.GetValues(typeof(Command.Type)); - break; - } - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using OpenKh.Bbs.SystemData; + +namespace OpenKh.Tools.ItbEditor +{ + public partial class ItbEntry : UserControl + { + public ItbEntry() + { + InitializeComponent(); + } + + private void ItemIDComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void ItemKindComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + switch (ItemKindComboBox.SelectedIndex) + { + case 0: + ItemIDComboBox.DataSource = Enum.GetValues(typeof(Item.Type)); + break; + case 1: + ItemIDComboBox.DataSource = Enum.GetValues(typeof(Command.Type)); + break; + } + } + } +} diff --git a/OpenKh.Tools.ItbEditor/MainForm.cs b/OpenKh.Tools.ItbEditor/MainForm.cs index 50d263409..63fc3eb34 100644 --- a/OpenKh.Tools.ItbEditor/MainForm.cs +++ b/OpenKh.Tools.ItbEditor/MainForm.cs @@ -1,248 +1,248 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.IO; -using OpenKh.Bbs; -using OpenKh.Bbs.SystemData; - -namespace OpenKh.Tools.ItbEditor -{ - public partial class MainForm : Form - { - public MainForm() - { - InitializeComponent(); - } - - Itb itb = new Itb(); - Stream itbFile; - - private void UpdateParameters(Itb itb) - { - foreach(TabPage tCon in ItbTabControl.TabPages) - { - tCon.Controls[0].Controls.Clear(); - } - - for (int i = 0; i < itb.header.ItemsTotal; i++) - { - FlowLayoutPanel currentFPanel = new FlowLayoutPanel(); - switch (itb.AllITB[i].WorldID) - { - case 1: - currentFPanel = FlowDP; - break; - case 2: - currentFPanel = FlowSW; - break; - case 3: - currentFPanel = FlowCD; - break; - case 4: - currentFPanel = FlowSB; - break; - case 5: - currentFPanel = FlowYT; - break; - case 6: - currentFPanel = FlowRG; - break; - case 7: - currentFPanel = FlowJB; - break; - case 8: - currentFPanel = FlowHE; - break; - case 9: - currentFPanel = FlowLS; - break; - case 10: - currentFPanel = FlowDI; - break; - case 11: - currentFPanel = FlowPP; - break; - case 12: - currentFPanel = FlowDC; - break; - case 13: - currentFPanel = FlowKG; - break; - case 15: - currentFPanel = FlowVS; - break; - case 16: - currentFPanel = FlowBD; - break; - case 17: - currentFPanel = FlowWM; - break; - } - - ItbEntry itbEntry = new ItbEntry(); - itbEntry.ITB_GBox.Text = "ITB Entry " + (i + 1); - itbEntry.NumericTreasureBoxID.Value = itb.AllITB[i].TreasureBoxID; - itbEntry.ItemKindComboBox.SelectedIndex = itb.AllITB[i].ItemKind; - - switch (itbEntry.ItemKindComboBox.SelectedIndex) - { - case 0: - itbEntry.ItemIDComboBox.DataSource = Enum.GetValues(typeof(Item.Type)); - itbEntry.ItemIDComboBox.SelectedItem = (Item.Type)itb.AllITB[i].ItemID; - break; - case 1: - itbEntry.ItemIDComboBox.SelectedItem = (Command.Type)itb.AllITB[i].ItemID; - break; - } - - - itbEntry.NumericReportID.Value = itb.AllITB[i].ReportID; - currentFPanel.Controls.Add(itbEntry); - } - } - - private void UpdateWriteInfo() - { - for(int i = 0; i < itb.header.ItemsTotal; i++) - { - ushort TrsrID = itb.AllITB[i].TreasureBoxID; - - foreach(TabPage page in ItbTabControl.TabPages) - { - foreach(ItbEntry ent in page.Controls[0].Controls) - { - if(ent.NumericTreasureBoxID.Value == TrsrID) - { - itb.AllITB[i].ItemKind = (byte)ent.ItemKindComboBox.SelectedIndex; - - switch (itb.AllITB[i].ItemKind) - { - case 0: - Item.Type nItem = (Item.Type)ent.ItemIDComboBox.SelectedItem; - ushort ItemVal = (ushort)nItem; - itb.AllITB[i].ItemID = ItemVal; - break; - case 1: - Command.Type nCommand = (Command.Type)ent.ItemIDComboBox.SelectedItem; - ushort CommandVal = (ushort)nCommand; - itb.AllITB[i].ItemID = CommandVal; - break; - } - - itb.AllITB[i].ReportID = (byte)ent.NumericReportID.Value; - break; - } - } - } - } - } - - private void LoadITCButton_Click(object sender, EventArgs e) - { - OpenFileDialog dialog = new OpenFileDialog(); - dialog.Filter = "Item Treasure Box files (*.itb)|*.itb|All files (*.*)|*.*"; - DialogResult result = dialog.ShowDialog(); - - if (result == DialogResult.OK) - { - if (itbFile != null) - itbFile.Close(); - itbFile = File.OpenRead(dialog.FileName); - itb = Itb.Read(itbFile); - UpdateParameters(itb); - SaveITBButton.Enabled = true; - NewChestButton.Enabled = true; - } - } - - private void SaveITCButton_Click(object sender, EventArgs e) - { - SaveFileDialog dialog = new SaveFileDialog(); - dialog.Filter = "Item Treasure Box files (*.itb)|*.itb|All files (*.*)|*.*"; - DialogResult result = dialog.ShowDialog(); - - if (result == DialogResult.OK) - { - Stream itbOut = File.OpenWrite(dialog.FileName); - UpdateWriteInfo(); - Itb.Write(itbOut, itb); - itbOut.Close(); - } - - MessageBox.Show("File saved successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - - private void NewChestButton_Click(object sender, EventArgs e) - { - itb.header.ItemsTotal++; - - switch (ItbTabControl.SelectedIndex) - { - case 1: - itb.header.ItemCountDP++; - break; - case 2: - itb.header.ItemCountSW++; - break; - case 3: - itb.header.ItemCountCD++; - break; - case 4: - itb.header.ItemCountSB++; - break; - case 5: - itb.header.ItemCountYT++; - break; - case 6: - itb.header.ItemCountRG++; - break; - case 7: - itb.header.ItemCountJB++; - break; - case 8: - itb.header.ItemCountHE++; - break; - case 9: - itb.header.ItemCountLS++; - break; - case 10: - itb.header.ItemCountDI++; - break; - case 11: - itb.header.ItemCountPP++; - break; - case 12: - itb.header.ItemCountDC++; - break; - case 13: - itb.header.ItemCountKG++; - break; - case 14: - itb.header.ItemCountVS++; - break; - case 15: - itb.header.ItemCountBD++; - break; - case 16: - itb.header.ItemCountWM++; - break; - } - - ItbEntry itEntry = new ItbEntry(); - Itb.ITBData LastData = itb.AllITB[itb.AllITB.Count - 1]; - Itb.ITBData nData = new Itb.ITBData(); - itEntry.ITB_GBox.Text = "ITB Entry " + (LastData.TreasureBoxID + 1); - itEntry.NumericTreasureBoxID.Value = LastData.TreasureBoxID + 1; - nData.TreasureBoxID = LastData.TreasureBoxID; - nData.TreasureBoxID++; - ItbTabControl.SelectedTab.Controls[0].Controls.Add(itEntry); - itb.AllITB.Add(nData); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.IO; +using OpenKh.Bbs; +using OpenKh.Bbs.SystemData; + +namespace OpenKh.Tools.ItbEditor +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + } + + Itb itb = new Itb(); + Stream itbFile; + + private void UpdateParameters(Itb itb) + { + foreach (TabPage tCon in ItbTabControl.TabPages) + { + tCon.Controls[0].Controls.Clear(); + } + + for (int i = 0; i < itb.header.ItemsTotal; i++) + { + FlowLayoutPanel currentFPanel = new FlowLayoutPanel(); + switch (itb.AllITB[i].WorldID) + { + case 1: + currentFPanel = FlowDP; + break; + case 2: + currentFPanel = FlowSW; + break; + case 3: + currentFPanel = FlowCD; + break; + case 4: + currentFPanel = FlowSB; + break; + case 5: + currentFPanel = FlowYT; + break; + case 6: + currentFPanel = FlowRG; + break; + case 7: + currentFPanel = FlowJB; + break; + case 8: + currentFPanel = FlowHE; + break; + case 9: + currentFPanel = FlowLS; + break; + case 10: + currentFPanel = FlowDI; + break; + case 11: + currentFPanel = FlowPP; + break; + case 12: + currentFPanel = FlowDC; + break; + case 13: + currentFPanel = FlowKG; + break; + case 15: + currentFPanel = FlowVS; + break; + case 16: + currentFPanel = FlowBD; + break; + case 17: + currentFPanel = FlowWM; + break; + } + + ItbEntry itbEntry = new ItbEntry(); + itbEntry.ITB_GBox.Text = "ITB Entry " + (i + 1); + itbEntry.NumericTreasureBoxID.Value = itb.AllITB[i].TreasureBoxID; + itbEntry.ItemKindComboBox.SelectedIndex = itb.AllITB[i].ItemKind; + + switch (itbEntry.ItemKindComboBox.SelectedIndex) + { + case 0: + itbEntry.ItemIDComboBox.DataSource = Enum.GetValues(typeof(Item.Type)); + itbEntry.ItemIDComboBox.SelectedItem = (Item.Type)itb.AllITB[i].ItemID; + break; + case 1: + itbEntry.ItemIDComboBox.SelectedItem = (Command.Type)itb.AllITB[i].ItemID; + break; + } + + + itbEntry.NumericReportID.Value = itb.AllITB[i].ReportID; + currentFPanel.Controls.Add(itbEntry); + } + } + + private void UpdateWriteInfo() + { + for (int i = 0; i < itb.header.ItemsTotal; i++) + { + ushort TrsrID = itb.AllITB[i].TreasureBoxID; + + foreach (TabPage page in ItbTabControl.TabPages) + { + foreach (ItbEntry ent in page.Controls[0].Controls) + { + if (ent.NumericTreasureBoxID.Value == TrsrID) + { + itb.AllITB[i].ItemKind = (byte)ent.ItemKindComboBox.SelectedIndex; + + switch (itb.AllITB[i].ItemKind) + { + case 0: + Item.Type nItem = (Item.Type)ent.ItemIDComboBox.SelectedItem; + ushort ItemVal = (ushort)nItem; + itb.AllITB[i].ItemID = ItemVal; + break; + case 1: + Command.Type nCommand = (Command.Type)ent.ItemIDComboBox.SelectedItem; + ushort CommandVal = (ushort)nCommand; + itb.AllITB[i].ItemID = CommandVal; + break; + } + + itb.AllITB[i].ReportID = (byte)ent.NumericReportID.Value; + break; + } + } + } + } + } + + private void LoadITCButton_Click(object sender, EventArgs e) + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Filter = "Item Treasure Box files (*.itb)|*.itb|All files (*.*)|*.*"; + DialogResult result = dialog.ShowDialog(); + + if (result == DialogResult.OK) + { + if (itbFile != null) + itbFile.Close(); + itbFile = File.OpenRead(dialog.FileName); + itb = Itb.Read(itbFile); + UpdateParameters(itb); + SaveITBButton.Enabled = true; + NewChestButton.Enabled = true; + } + } + + private void SaveITCButton_Click(object sender, EventArgs e) + { + SaveFileDialog dialog = new SaveFileDialog(); + dialog.Filter = "Item Treasure Box files (*.itb)|*.itb|All files (*.*)|*.*"; + DialogResult result = dialog.ShowDialog(); + + if (result == DialogResult.OK) + { + Stream itbOut = File.OpenWrite(dialog.FileName); + UpdateWriteInfo(); + Itb.Write(itbOut, itb); + itbOut.Close(); + } + + MessageBox.Show("File saved successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void NewChestButton_Click(object sender, EventArgs e) + { + itb.header.ItemsTotal++; + + switch (ItbTabControl.SelectedIndex) + { + case 1: + itb.header.ItemCountDP++; + break; + case 2: + itb.header.ItemCountSW++; + break; + case 3: + itb.header.ItemCountCD++; + break; + case 4: + itb.header.ItemCountSB++; + break; + case 5: + itb.header.ItemCountYT++; + break; + case 6: + itb.header.ItemCountRG++; + break; + case 7: + itb.header.ItemCountJB++; + break; + case 8: + itb.header.ItemCountHE++; + break; + case 9: + itb.header.ItemCountLS++; + break; + case 10: + itb.header.ItemCountDI++; + break; + case 11: + itb.header.ItemCountPP++; + break; + case 12: + itb.header.ItemCountDC++; + break; + case 13: + itb.header.ItemCountKG++; + break; + case 14: + itb.header.ItemCountVS++; + break; + case 15: + itb.header.ItemCountBD++; + break; + case 16: + itb.header.ItemCountWM++; + break; + } + + ItbEntry itEntry = new ItbEntry(); + Itb.ITBData LastData = itb.AllITB[itb.AllITB.Count - 1]; + Itb.ITBData nData = new Itb.ITBData(); + itEntry.ITB_GBox.Text = "ITB Entry " + (LastData.TreasureBoxID + 1); + itEntry.NumericTreasureBoxID.Value = LastData.TreasureBoxID + 1; + nData.TreasureBoxID = LastData.TreasureBoxID; + nData.TreasureBoxID++; + ItbTabControl.SelectedTab.Controls[0].Controls.Add(itEntry); + itb.AllITB.Add(nData); + } + } +} diff --git a/OpenKh.Tools.ItbEditor/Program.cs b/OpenKh.Tools.ItbEditor/Program.cs index b766d3632..2605f427c 100644 --- a/OpenKh.Tools.ItbEditor/Program.cs +++ b/OpenKh.Tools.ItbEditor/Program.cs @@ -1,23 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace OpenKh.Tools.ItbEditor -{ - static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.SetHighDpiMode(HighDpiMode.SystemAware); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace OpenKh.Tools.ItbEditor +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/OpenKh.Tools.ItcEditor/ItcEntry.cs b/OpenKh.Tools.ItcEditor/ItcEntry.cs index fc80ba563..35b768756 100644 --- a/OpenKh.Tools.ItcEditor/ItcEntry.cs +++ b/OpenKh.Tools.ItcEditor/ItcEntry.cs @@ -1,26 +1,26 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; -using OpenKh.Bbs.SystemData; - -namespace OpenKh.Tools.ItcEditor -{ - public partial class ItcEntry : UserControl - { - public ItcEntry() - { - InitializeComponent(); - ItemIDComboBox.DataSource = Enum.GetValues(typeof(Item.Type)); - } - - private void ItemIDComboBox_SelectedIndexChanged(object sender, EventArgs e) - { - - } - - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using OpenKh.Bbs.SystemData; + +namespace OpenKh.Tools.ItcEditor +{ + public partial class ItcEntry : UserControl + { + public ItcEntry() + { + InitializeComponent(); + ItemIDComboBox.DataSource = Enum.GetValues(typeof(Item.Type)); + } + + private void ItemIDComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + } +} diff --git a/OpenKh.Tools.ItcEditor/MainForm.cs b/OpenKh.Tools.ItcEditor/MainForm.cs index 83bb990bf..199642382 100644 --- a/OpenKh.Tools.ItcEditor/MainForm.cs +++ b/OpenKh.Tools.ItcEditor/MainForm.cs @@ -1,152 +1,152 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.IO; -using OpenKh.Bbs; -using OpenKh.Bbs.SystemData; - -namespace OpenKh.Tools.ItcEditor -{ - public partial class MainForm : Form - { - public MainForm() - { - InitializeComponent(); - } - - Itc itc = new Itc(); - Stream itcFile; - - private void UpdateParameters(Itc itc) - { - foreach(TabPage tCon in ItcTabControl.TabPages) - { - tCon.Controls[0].Controls.Clear(); - } - - for (int i = 0; i < itc.header.ItemsTotal; i++) - { - FlowLayoutPanel currentFPanel = new FlowLayoutPanel(); - switch (itc.AllITC[i].WorldID) - { - case 1: - currentFPanel = FlowDP; - break; - case 2: - currentFPanel = FlowSW; - break; - case 3: - currentFPanel = FlowCD; - break; - case 4: - currentFPanel = FlowSB; - break; - case 5: - currentFPanel = FlowYT; - break; - case 6: - currentFPanel = FlowRG; - break; - case 7: - currentFPanel = FlowJB; - break; - case 8: - currentFPanel = FlowHE; - break; - case 9: - currentFPanel = FlowLS; - break; - case 10: - currentFPanel = FlowDI; - break; - case 11: - currentFPanel = FlowPP; - break; - case 12: - currentFPanel = FlowDC; - break; - case 13: - currentFPanel = FlowKG; - break; - case 15: - currentFPanel = FlowVS; - break; - case 16: - currentFPanel = FlowBD; - break; - case 17: - currentFPanel = FlowWM; - break; - } - - ItcEntry itcEntry = new ItcEntry(); - itcEntry.ITC_GBox.Text = "ITC Entry " + (i + 1); - itcEntry.NumericCollectionID.Value = itc.AllITC[i].CollectionID; - itcEntry.ItemIDComboBox.SelectedItem = (Item.Type)itc.AllITC[i].ItemID; - currentFPanel.Controls.Add(itcEntry); - } - } - - private void UpdateWriteInfo() - { - for(int i = 0; i < itc.header.ItemsTotal; i++) - { - ushort CollID = itc.AllITC[i].CollectionID; - - foreach(TabPage page in ItcTabControl.TabPages) - { - foreach(ItcEntry ent in page.Controls[0].Controls) - { - if(ent.NumericCollectionID.Value == CollID) - { - Item.Type nItem = (Item.Type)ent.ItemIDComboBox.SelectedItem; - ushort ItemVal = (ushort)nItem; - itc.AllITC[i].ItemID = ItemVal; - break; - } - } - } - } - } - - private void LoadITCButton_Click(object sender, EventArgs e) - { - OpenFileDialog dialog = new OpenFileDialog(); - dialog.Filter = "Item Collection files (*.itc)|*.itc|All files (*.*)|*.*"; - DialogResult result = dialog.ShowDialog(); - - if (result == DialogResult.OK) - { - if (itcFile != null) - itcFile.Close(); - itcFile = File.OpenRead(dialog.FileName); - itc = Itc.Read(itcFile); - UpdateParameters(itc); - SaveITCButton.Enabled = true; - } - } - - private void SaveITCButton_Click(object sender, EventArgs e) - { - SaveFileDialog dialog = new SaveFileDialog(); - dialog.Filter = "Item Collection files (*.itc)|*.itc|All files (*.*)|*.*"; - DialogResult result = dialog.ShowDialog(); - - if (result == DialogResult.OK) - { - Stream itcOut = File.OpenWrite(dialog.FileName); - UpdateWriteInfo(); - Itc.Write(itcOut, itc); - itcOut.Close(); - } - - MessageBox.Show("File saved successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.IO; +using OpenKh.Bbs; +using OpenKh.Bbs.SystemData; + +namespace OpenKh.Tools.ItcEditor +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + } + + Itc itc = new Itc(); + Stream itcFile; + + private void UpdateParameters(Itc itc) + { + foreach (TabPage tCon in ItcTabControl.TabPages) + { + tCon.Controls[0].Controls.Clear(); + } + + for (int i = 0; i < itc.header.ItemsTotal; i++) + { + FlowLayoutPanel currentFPanel = new FlowLayoutPanel(); + switch (itc.AllITC[i].WorldID) + { + case 1: + currentFPanel = FlowDP; + break; + case 2: + currentFPanel = FlowSW; + break; + case 3: + currentFPanel = FlowCD; + break; + case 4: + currentFPanel = FlowSB; + break; + case 5: + currentFPanel = FlowYT; + break; + case 6: + currentFPanel = FlowRG; + break; + case 7: + currentFPanel = FlowJB; + break; + case 8: + currentFPanel = FlowHE; + break; + case 9: + currentFPanel = FlowLS; + break; + case 10: + currentFPanel = FlowDI; + break; + case 11: + currentFPanel = FlowPP; + break; + case 12: + currentFPanel = FlowDC; + break; + case 13: + currentFPanel = FlowKG; + break; + case 15: + currentFPanel = FlowVS; + break; + case 16: + currentFPanel = FlowBD; + break; + case 17: + currentFPanel = FlowWM; + break; + } + + ItcEntry itcEntry = new ItcEntry(); + itcEntry.ITC_GBox.Text = "ITC Entry " + (i + 1); + itcEntry.NumericCollectionID.Value = itc.AllITC[i].CollectionID; + itcEntry.ItemIDComboBox.SelectedItem = (Item.Type)itc.AllITC[i].ItemID; + currentFPanel.Controls.Add(itcEntry); + } + } + + private void UpdateWriteInfo() + { + for (int i = 0; i < itc.header.ItemsTotal; i++) + { + ushort CollID = itc.AllITC[i].CollectionID; + + foreach (TabPage page in ItcTabControl.TabPages) + { + foreach (ItcEntry ent in page.Controls[0].Controls) + { + if (ent.NumericCollectionID.Value == CollID) + { + Item.Type nItem = (Item.Type)ent.ItemIDComboBox.SelectedItem; + ushort ItemVal = (ushort)nItem; + itc.AllITC[i].ItemID = ItemVal; + break; + } + } + } + } + } + + private void LoadITCButton_Click(object sender, EventArgs e) + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Filter = "Item Collection files (*.itc)|*.itc|All files (*.*)|*.*"; + DialogResult result = dialog.ShowDialog(); + + if (result == DialogResult.OK) + { + if (itcFile != null) + itcFile.Close(); + itcFile = File.OpenRead(dialog.FileName); + itc = Itc.Read(itcFile); + UpdateParameters(itc); + SaveITCButton.Enabled = true; + } + } + + private void SaveITCButton_Click(object sender, EventArgs e) + { + SaveFileDialog dialog = new SaveFileDialog(); + dialog.Filter = "Item Collection files (*.itc)|*.itc|All files (*.*)|*.*"; + DialogResult result = dialog.ShowDialog(); + + if (result == DialogResult.OK) + { + Stream itcOut = File.OpenWrite(dialog.FileName); + UpdateWriteInfo(); + Itc.Write(itcOut, itc); + itcOut.Close(); + } + + MessageBox.Show("File saved successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } +} diff --git a/OpenKh.Tools.ItcEditor/Program.cs b/OpenKh.Tools.ItcEditor/Program.cs index 56bd19dae..687c66438 100644 --- a/OpenKh.Tools.ItcEditor/Program.cs +++ b/OpenKh.Tools.ItcEditor/Program.cs @@ -1,23 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace OpenKh.Tools.ItcEditor -{ - static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.SetHighDpiMode(HighDpiMode.SystemAware); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace OpenKh.Tools.ItcEditor +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/App.xaml.cs b/OpenKh.Tools.Kh2BattleEditor/App.xaml.cs index dca5f2d7e..3b4ed0051 100644 --- a/OpenKh.Tools.Kh2BattleEditor/App.xaml.cs +++ b/OpenKh.Tools.Kh2BattleEditor/App.xaml.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; - -namespace OpenKh.Tools.Kh2BattleEditor -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace OpenKh.Tools.Kh2BattleEditor +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/Extensions/BarExtensions.cs b/OpenKh.Tools.Kh2BattleEditor/Extensions/BarExtensions.cs index 2bfff2b5c..5dfa3900c 100644 --- a/OpenKh.Tools.Kh2BattleEditor/Extensions/BarExtensions.cs +++ b/OpenKh.Tools.Kh2BattleEditor/Extensions/BarExtensions.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using OpenKh.Kh2; - -namespace OpenKh.Tools.Kh2BattleEditor.Extensions -{ - public static class BarExtensions - { - public static Stream GetBattleStream(this IEnumerable entries, string name) => - // TODO throws exception if that entry is not found - entries.First(x => x.Name == name && x.Index == 0 && x.Type == Bar.EntryType.List).Stream; - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using OpenKh.Kh2; + +namespace OpenKh.Tools.Kh2BattleEditor.Extensions +{ + public static class BarExtensions + { + public static Stream GetBattleStream(this IEnumerable entries, string name) => + // TODO throws exception if that entry is not found + entries.First(x => x.Name == name && x.Index == 0 && x.Type == Bar.EntryType.List).Stream; + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/Interfaces/IBattleGetChanges.cs b/OpenKh.Tools.Kh2BattleEditor/Interfaces/IBattleGetChanges.cs index 55cf048b4..c9d739211 100644 --- a/OpenKh.Tools.Kh2BattleEditor/Interfaces/IBattleGetChanges.cs +++ b/OpenKh.Tools.Kh2BattleEditor/Interfaces/IBattleGetChanges.cs @@ -1,11 +1,11 @@ -using System.IO; - -namespace OpenKh.Tools.Kh2BattleEditor.Interfaces -{ - public interface IBattleGetChanges - { - string EntryName { get; } - - Stream CreateStream(); - } -} +using System.IO; + +namespace OpenKh.Tools.Kh2BattleEditor.Interfaces +{ + public interface IBattleGetChanges + { + string EntryName { get; } + + Stream CreateStream(); + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/Services/CharacterNameProvider.cs b/OpenKh.Tools.Kh2BattleEditor/Services/CharacterNameProvider.cs index 673f30627..f6b5881fa 100644 --- a/OpenKh.Tools.Kh2BattleEditor/Services/CharacterNameProvider.cs +++ b/OpenKh.Tools.Kh2BattleEditor/Services/CharacterNameProvider.cs @@ -1,33 +1,33 @@ -using System.Collections.Generic; - -namespace OpenKh.Tools.Kh2BattleEditor.Services -{ - public static class CharacterNameProvider - { - private static readonly Dictionary _characterNames = new Dictionary - { - [0x01] = "Sora", - [0x02] = "Donald", - [0x03] = "Goofy", - [0x04] = "Mickey", - [0x05] = "Auron", - [0x06] = "Mulan", - [0x07] = "Aladdin", - [0x08] = "Jack Sparrow", - [0x09] = "Beast", - [0x0A] = "Jack", - [0x0B] = "Simba", - [0x0C] = "Tron", - [0x0D] = "Riku", - [0x0E] = "Roxas", - [0x0F] = "Ping", - }; - - public static string GetCharacterName(int id) - { - _characterNames.TryGetValue(id, out var name); - - return name; - } - } -} +using System.Collections.Generic; + +namespace OpenKh.Tools.Kh2BattleEditor.Services +{ + public static class CharacterNameProvider + { + private static readonly Dictionary _characterNames = new Dictionary + { + [0x01] = "Sora", + [0x02] = "Donald", + [0x03] = "Goofy", + [0x04] = "Mickey", + [0x05] = "Auron", + [0x06] = "Mulan", + [0x07] = "Aladdin", + [0x08] = "Jack Sparrow", + [0x09] = "Beast", + [0x0A] = "Jack", + [0x0B] = "Simba", + [0x0C] = "Tron", + [0x0D] = "Riku", + [0x0E] = "Roxas", + [0x0F] = "Ping", + }; + + public static string GetCharacterName(int id) + { + _characterNames.TryGetValue(id, out var name); + + return name; + } + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/Services/EnemyNameProvider.cs b/OpenKh.Tools.Kh2BattleEditor/Services/EnemyNameProvider.cs index a8d0d608d..5a17f1d6f 100644 --- a/OpenKh.Tools.Kh2BattleEditor/Services/EnemyNameProvider.cs +++ b/OpenKh.Tools.Kh2BattleEditor/Services/EnemyNameProvider.cs @@ -1,247 +1,247 @@ -using System.Collections.Generic; - -namespace OpenKh.Tools.Kh2BattleEditor.Services -{ - public static class EnemyNameProvider - { - private static readonly Dictionary _enemyNames = new Dictionary - { - [0] = "Silver Rock", - [1] = "Emerald Blues", - [2] = "Crimson Jazz", - [3] = "Air Pirate", - [4] = "Bulky Vendor", - [5] = "Fiery Globe", - [6] = "Icy Cube", - [7] = "Living Bone", - [8] = "Wight Knight", - [9] = "Neoshadow", - [10] = "Magnum Loader", - [11] = "Morning Star", - [12] = "Tornado Step", - [13] = "Crescendo", - [14] = "Creeper Plant", - [15] = "Lock", - [16] = "Shock", - [17] = "Barrel", - [18] = "Hades (Story bites)", - [19] = "Cerberus", - [20] = "Hydra", - [22] = "Dark Thorn", - [23] = "Shadow Stalker", - [24] = "Possessor", - [25] = "Storm Rider", - [26] = "Pete (Olympus)", - [27] = "Gargoyle Knight", - [28] = "Gargoyle Warrior", - [29] = "", - [30] = "", - [31] = "Shadow Stalker (Chandelier)", - [32] = "Shadow Stalker (Pillar)", - [33] = "Soldier", - [34] = "Shadow", - [35] = "Large Body", - [36] = "Armored Knight", - [37] = "Surveillance Robot", - [38] = "Rapid Thruster", - [39] = "Bolt Tower", - [40] = "", - [41] = "Dusk", - [42] = "", - [43] = "", - [44] = "Dragoon", - [45] = "Assassin", - [46] = "Samurai", - [47] = "Sniper", - [48] = "Dancer", - [49] = "Berserker", - [50] = "Gambler", - [51] = "Sorcerer", - [52] = "Creeper", - [53] = "Fat Bandit", - [54] = "", - [55] = "Rabid Dog", - [56] = "", - [57] = "Aeroplane", - [58] = "Minute Bomb", - [59] = "Hammer Frame", - [60] = "Assault Rider", - [61] = "Nightwalker", - [62] = "Fortuneteller", - [63] = "Luna Bandit", - [64] = "Hot Rod", - [65] = "Cannon Gun", - [66] = "Devastator", - [67] = "Lance Soldier", - [68] = "Driller Mole", - [69] = "", - [70] = "", - [71] = "Shan-Yu", - [72] = "", - [73] = "Beast", - [74] = "Thresholder", - [75] = "Oogie Boogie", - [78] = "Axel (Day 6)", - [79] = "Cornerstone cage", - [80] = "Shaman", - [81] = "Aerial Knocker", - [84] = "", - [85] = "", - [86] = "Twilight Thorn", - [87] = "Xaldin", - [88] = "Demyx", - [89] = "", - [90] = "Xemnas", - [91] = "Shenzi, Banzai and Ed", - [92] = "", - [93] = "", - [94] = "Scar", - [95] = "Groundshaker", - [98] = "Illuminator", - [99] = "Barbossa", - [100] = "Sark", - [101] = "Strafer", - [102] = "Hydra head", - [103] = "Undead Pirate A", - [104] = "Undead Pirate B", - [105] = "Undead Pirate C", - [106] = "Hostile Program", - [107] = "", - [108] = "", - [109] = "", - [110] = "", - [111] = "", - [112] = "", - [113] = "Captain Pete", - [114] = "Sark (Giant)", - [115] = "", - [119] = "Prison Keeper", - [120] = "The Experiment", - [121] = "", - [122] = "Volcanic Lord (Agrabah)", - [123] = "Blizzard Lord (Agrabah)", - [124] = "Grim Reaper 2", - [125] = "", - [126] = "Bookmaster", - [127] = "Pete (Boat)", - [128] = "", - [129] = "MCP barrier", - [130] = "Riku (Hooded)", - [131] = "", - [132] = "Water Clone", - [133] = "Xigbar", - [134] = "Saïx", - [135] = "Seifer (Struggle)", - [136] = "", - [137] = "", - [138] = "Jafar (Genie)", - [139] = "", - [140] = "Sephiroth", - [141] = "MCP", - [142] = "", - [143] = "", - [144] = "", - [145] = "Shadow Roxas", - [146] = "", - [147] = "", - [148] = "Axel (Day 4)", - [149] = "Toy Box / Graveyard", - [150] = "Hayner (Struggle)", - [152] = "", - [153] = "Xemnas Dragon - Core", - [154] = "Grim Reaper 1", - [155] = "", - [157] = "Fake Vivi (Struggle)", - [158] = "Setzer (Struggle)", - [160] = "Xemnas (Armored)", - [161] = "Luxord cards", - [162] = "Fake Vivi (Day 5)", - [163] = "Ghost of Scar", - [168] = "Bomb Bell B", - [169] = "", - [170] = "", - [171] = "", - [172] = "Xemnas Dragon (Multiple parts)", - [177] = "Hades (Hades cup - round 30)", - [178] = "Hercules (Cups)", - [179] = "Pete (Hades cup)", - [180] = "Squall / Leon (P&P cup)", - [181] = "Cloud (Hades cup - round 25)", - [182] = "Tifa (Hades cup - round 10)", - [183] = "Yuffie (P&P cup)", - [184] = "Squall / Leon (P&P+ cup)", - [185] = "Cloud (Hades cup - round 40)", - [186] = "", - [187] = "Yuffie (P&P+ cup)", - [188] = "Squall / Leon (Hades cup - round 40)", - [189] = "Cloud (Hades cup - round 49)", - [190] = "Tifa (Hades cup - round 49)", - [191] = "Yuffie (Hades cup - round 10)", - [192] = "Squall / Leon (Hades cup - round 49)", - [195] = "Yuffie (Hades cup - round 49)", - [196] = "Hades (Hades cup - round 50)", - [197] = "Volcanic Lord (Hades cup)", - [198] = "Blizzard Lord (Hades cup)", - [199] = "Cerberus (Cups)", - [200] = "Vexen Data", - [201] = "", - [202] = "", - [203] = "", - [205] = "", - [206] = "", - [207] = "", - [208] = "", - [209] = "", - [210] = "", - [211] = "", - [212] = "", - [213] = "Roxas", - [214] = "Lexaeus Data", - [215] = "Marluxia Data", - [216] = "Larxene Data", - [217] = "Zexion Data", - [218] = "Vexen - Antisora 1", - [219] = "Vexen - Antisora 2", - [220] = "Vexen - Antisora 3", - [221] = "Vexen - Antisora 4", - [222] = "Vexen - Antisora 5", - [223] = "Zexion Book Illusion", - [224] = "Zexion Book Trap", - [225] = "Beffudler", - [226] = "Camo Cannon", - [227] = "Aerial Viking", - [228] = "Aerial Champ", - [229] = "Spring Metal", - [230] = "Runemaster", - [231] = "Magic Phantom", - [232] = "Iron Hammer", - [233] = "Lance Warrior", - [234] = "Necromancer", - [235] = "Mad Ride", - [236] = "Reckless", - [237] = "", - [238] = "", - [239] = "Xemnas Data", - [240] = "Demyx Data", - [241] = "Demyx Data - Water clones", - [242] = "Roxas Data", - [243] = "Luxord Data", - [244] = "Lingering Will", - [245] = "Axel Data", - [246] = "Xaldin Data", - [247] = "", - [248] = "", - [249] = "", - [251] = "", - [252] = "Xigbar Data", - [253] = "Saïx Data" - }; - - public static string GetEnemyName(int id) - { - _enemyNames.TryGetValue(id, out var name); - - return name; - } - } -} +using System.Collections.Generic; + +namespace OpenKh.Tools.Kh2BattleEditor.Services +{ + public static class EnemyNameProvider + { + private static readonly Dictionary _enemyNames = new Dictionary + { + [0] = "Silver Rock", + [1] = "Emerald Blues", + [2] = "Crimson Jazz", + [3] = "Air Pirate", + [4] = "Bulky Vendor", + [5] = "Fiery Globe", + [6] = "Icy Cube", + [7] = "Living Bone", + [8] = "Wight Knight", + [9] = "Neoshadow", + [10] = "Magnum Loader", + [11] = "Morning Star", + [12] = "Tornado Step", + [13] = "Crescendo", + [14] = "Creeper Plant", + [15] = "Lock", + [16] = "Shock", + [17] = "Barrel", + [18] = "Hades (Story bites)", + [19] = "Cerberus", + [20] = "Hydra", + [22] = "Dark Thorn", + [23] = "Shadow Stalker", + [24] = "Possessor", + [25] = "Storm Rider", + [26] = "Pete (Olympus)", + [27] = "Gargoyle Knight", + [28] = "Gargoyle Warrior", + [29] = "", + [30] = "", + [31] = "Shadow Stalker (Chandelier)", + [32] = "Shadow Stalker (Pillar)", + [33] = "Soldier", + [34] = "Shadow", + [35] = "Large Body", + [36] = "Armored Knight", + [37] = "Surveillance Robot", + [38] = "Rapid Thruster", + [39] = "Bolt Tower", + [40] = "", + [41] = "Dusk", + [42] = "", + [43] = "", + [44] = "Dragoon", + [45] = "Assassin", + [46] = "Samurai", + [47] = "Sniper", + [48] = "Dancer", + [49] = "Berserker", + [50] = "Gambler", + [51] = "Sorcerer", + [52] = "Creeper", + [53] = "Fat Bandit", + [54] = "", + [55] = "Rabid Dog", + [56] = "", + [57] = "Aeroplane", + [58] = "Minute Bomb", + [59] = "Hammer Frame", + [60] = "Assault Rider", + [61] = "Nightwalker", + [62] = "Fortuneteller", + [63] = "Luna Bandit", + [64] = "Hot Rod", + [65] = "Cannon Gun", + [66] = "Devastator", + [67] = "Lance Soldier", + [68] = "Driller Mole", + [69] = "", + [70] = "", + [71] = "Shan-Yu", + [72] = "", + [73] = "Beast", + [74] = "Thresholder", + [75] = "Oogie Boogie", + [78] = "Axel (Day 6)", + [79] = "Cornerstone cage", + [80] = "Shaman", + [81] = "Aerial Knocker", + [84] = "", + [85] = "", + [86] = "Twilight Thorn", + [87] = "Xaldin", + [88] = "Demyx", + [89] = "", + [90] = "Xemnas", + [91] = "Shenzi, Banzai and Ed", + [92] = "", + [93] = "", + [94] = "Scar", + [95] = "Groundshaker", + [98] = "Illuminator", + [99] = "Barbossa", + [100] = "Sark", + [101] = "Strafer", + [102] = "Hydra head", + [103] = "Undead Pirate A", + [104] = "Undead Pirate B", + [105] = "Undead Pirate C", + [106] = "Hostile Program", + [107] = "", + [108] = "", + [109] = "", + [110] = "", + [111] = "", + [112] = "", + [113] = "Captain Pete", + [114] = "Sark (Giant)", + [115] = "", + [119] = "Prison Keeper", + [120] = "The Experiment", + [121] = "", + [122] = "Volcanic Lord (Agrabah)", + [123] = "Blizzard Lord (Agrabah)", + [124] = "Grim Reaper 2", + [125] = "", + [126] = "Bookmaster", + [127] = "Pete (Boat)", + [128] = "", + [129] = "MCP barrier", + [130] = "Riku (Hooded)", + [131] = "", + [132] = "Water Clone", + [133] = "Xigbar", + [134] = "Saïx", + [135] = "Seifer (Struggle)", + [136] = "", + [137] = "", + [138] = "Jafar (Genie)", + [139] = "", + [140] = "Sephiroth", + [141] = "MCP", + [142] = "", + [143] = "", + [144] = "", + [145] = "Shadow Roxas", + [146] = "", + [147] = "", + [148] = "Axel (Day 4)", + [149] = "Toy Box / Graveyard", + [150] = "Hayner (Struggle)", + [152] = "", + [153] = "Xemnas Dragon - Core", + [154] = "Grim Reaper 1", + [155] = "", + [157] = "Fake Vivi (Struggle)", + [158] = "Setzer (Struggle)", + [160] = "Xemnas (Armored)", + [161] = "Luxord cards", + [162] = "Fake Vivi (Day 5)", + [163] = "Ghost of Scar", + [168] = "Bomb Bell B", + [169] = "", + [170] = "", + [171] = "", + [172] = "Xemnas Dragon (Multiple parts)", + [177] = "Hades (Hades cup - round 30)", + [178] = "Hercules (Cups)", + [179] = "Pete (Hades cup)", + [180] = "Squall / Leon (P&P cup)", + [181] = "Cloud (Hades cup - round 25)", + [182] = "Tifa (Hades cup - round 10)", + [183] = "Yuffie (P&P cup)", + [184] = "Squall / Leon (P&P+ cup)", + [185] = "Cloud (Hades cup - round 40)", + [186] = "", + [187] = "Yuffie (P&P+ cup)", + [188] = "Squall / Leon (Hades cup - round 40)", + [189] = "Cloud (Hades cup - round 49)", + [190] = "Tifa (Hades cup - round 49)", + [191] = "Yuffie (Hades cup - round 10)", + [192] = "Squall / Leon (Hades cup - round 49)", + [195] = "Yuffie (Hades cup - round 49)", + [196] = "Hades (Hades cup - round 50)", + [197] = "Volcanic Lord (Hades cup)", + [198] = "Blizzard Lord (Hades cup)", + [199] = "Cerberus (Cups)", + [200] = "Vexen Data", + [201] = "", + [202] = "", + [203] = "", + [205] = "", + [206] = "", + [207] = "", + [208] = "", + [209] = "", + [210] = "", + [211] = "", + [212] = "", + [213] = "Roxas", + [214] = "Lexaeus Data", + [215] = "Marluxia Data", + [216] = "Larxene Data", + [217] = "Zexion Data", + [218] = "Vexen - Antisora 1", + [219] = "Vexen - Antisora 2", + [220] = "Vexen - Antisora 3", + [221] = "Vexen - Antisora 4", + [222] = "Vexen - Antisora 5", + [223] = "Zexion Book Illusion", + [224] = "Zexion Book Trap", + [225] = "Beffudler", + [226] = "Camo Cannon", + [227] = "Aerial Viking", + [228] = "Aerial Champ", + [229] = "Spring Metal", + [230] = "Runemaster", + [231] = "Magic Phantom", + [232] = "Iron Hammer", + [233] = "Lance Warrior", + [234] = "Necromancer", + [235] = "Mad Ride", + [236] = "Reckless", + [237] = "", + [238] = "", + [239] = "Xemnas Data", + [240] = "Demyx Data", + [241] = "Demyx Data - Water clones", + [242] = "Roxas Data", + [243] = "Luxord Data", + [244] = "Lingering Will", + [245] = "Axel Data", + [246] = "Xaldin Data", + [247] = "", + [248] = "", + [249] = "", + [251] = "", + [252] = "Xigbar Data", + [253] = "Saïx Data" + }; + + public static string GetEnemyName(int id) + { + _enemyNames.TryGetValue(id, out var name); + + return name; + } + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/Services/FormNameProvider.cs b/OpenKh.Tools.Kh2BattleEditor/Services/FormNameProvider.cs index a9589f440..aeb135710 100644 --- a/OpenKh.Tools.Kh2BattleEditor/Services/FormNameProvider.cs +++ b/OpenKh.Tools.Kh2BattleEditor/Services/FormNameProvider.cs @@ -1,39 +1,39 @@ -using System.Collections.Generic; - -namespace OpenKh.Tools.Kh2BattleEditor.Services -{ - public static class FormNameProvider - { - private static readonly Dictionary _formNamesVanilla = new Dictionary - { - [0x00] = "Summon", - [0x01] = "Valor", - [0x02] = "Wisdom", - [0x03] = "Master", - [0x04] = "Final", - [0x05] = "Anti", - }; - - private static readonly Dictionary _formNamesFm = new Dictionary - { - [0x00] = "Summon", - [0x01] = "Valor", - [0x02] = "Wisdom", - [0x03] = "Limit", - [0x04] = "Master", - [0x05] = "Final", - [0x06] = "Anti", - }; - - public static string GetFormName(int id, bool fm) - { - string name; - if (fm) - _formNamesFm.TryGetValue(id, out name); - else - _formNamesVanilla.TryGetValue(id, out name); - - return name; - } - } -} +using System.Collections.Generic; + +namespace OpenKh.Tools.Kh2BattleEditor.Services +{ + public static class FormNameProvider + { + private static readonly Dictionary _formNamesVanilla = new Dictionary + { + [0x00] = "Summon", + [0x01] = "Valor", + [0x02] = "Wisdom", + [0x03] = "Master", + [0x04] = "Final", + [0x05] = "Anti", + }; + + private static readonly Dictionary _formNamesFm = new Dictionary + { + [0x00] = "Summon", + [0x01] = "Valor", + [0x02] = "Wisdom", + [0x03] = "Limit", + [0x04] = "Master", + [0x05] = "Final", + [0x06] = "Anti", + }; + + public static string GetFormName(int id, bool fm) + { + string name; + if (fm) + _formNamesFm.TryGetValue(id, out name); + else + _formNamesVanilla.TryGetValue(id, out name); + + return name; + } + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/ViewModels/BonsViewModel.cs b/OpenKh.Tools.Kh2BattleEditor/ViewModels/BonsViewModel.cs index bd338a0af..388b21bcc 100644 --- a/OpenKh.Tools.Kh2BattleEditor/ViewModels/BonsViewModel.cs +++ b/OpenKh.Tools.Kh2BattleEditor/ViewModels/BonsViewModel.cs @@ -1,106 +1,106 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.Battle; -using OpenKh.Tools.Common.Models; -using OpenKh.Tools.Kh2BattleEditor.Extensions; -using OpenKh.Tools.Kh2BattleEditor.Interfaces; -using OpenKh.Tools.Kh2BattleEditor.Services; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Windows; - -namespace OpenKh.Tools.Kh2BattleEditor.ViewModels -{ - public class BonsViewModel : MyGenericListModel, IBattleGetChanges - { - public class BonsEntryViewModel - { - public Bons Bons { get; } - - public BonsEntryViewModel(Bons bons) - { - Bons = bons; - } - - public string Name => $"{Id} {CharacterNameProvider.GetCharacterName(Bons.CharacterId)}"; - - public string Id => $"{Bons.RewardId:X02}"; - - public byte RewardId { get => Bons.RewardId; set => Bons.RewardId = value; } - public byte CharacterId { get => Bons.CharacterId; set => Bons.CharacterId = value; } - public byte HpIncrease { get => Bons.HpIncrease; set => Bons.HpIncrease = value; } - public byte MpIncrease { get => Bons.MpIncrease; set => Bons.MpIncrease = value; } - public byte DriveGaugeUpgrade { get => Bons.DriveGaugeUpgrade; set => Bons.DriveGaugeUpgrade = value; } - public byte ItemSlotUpgrade { get => Bons.ItemSlotUpgrade; set => Bons.ItemSlotUpgrade = value; } - public byte AccessorySlotUpgrade { get => Bons.AccessorySlotUpgrade; set => Bons.AccessorySlotUpgrade = value; } - public byte ArmorSlotUpgrade { get => Bons.ArmorSlotUpgrade; set => Bons.ArmorSlotUpgrade = value; } - public short BonusItem1 { get => Bons.BonusItem1; set => Bons.BonusItem1 = value; } - public short BonusItem2 { get => Bons.BonusItem2; set => Bons.BonusItem2 = value; } - public int Unknown0c { get => Bons.Unknown0c; set => Bons.Unknown0c = value; } - - public override string ToString() => Name; - } - - private const string entryName = "bons"; - - private string _searchTerm; - - public BonsViewModel(IEnumerable entries) : - this(Bons.Read(entries.GetBattleStream(entryName))) - { } - - public BonsViewModel() : - this(new List()) - { } - - private BonsViewModel(IEnumerable items) : - base(items.Select(Map)) - { - } - public string EntryName => entryName; - - public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - - public string SearchTerm - { - get => _searchTerm; - set - { - _searchTerm = value; - PerformFiltering(); - } - } - - public Stream CreateStream() - { - var stream = new MemoryStream(); - Bons.Write(stream, UnfilteredItems.Select(x => x.Bons)); - - return stream; - } - protected override void OnSelectedItem(BonsEntryViewModel item) - { - base.OnSelectedItem(item); - - OnPropertyChanged(nameof(IsItemEditingVisible)); - OnPropertyChanged(nameof(IsItemEditMessageVisible)); - } - - private void PerformFiltering() - { - if (string.IsNullOrWhiteSpace(_searchTerm)) - Filter(FilterNone); - else - Filter(FilterByCharacter); - } - - private bool FilterNone(BonsEntryViewModel arg) => true; - - private bool FilterByCharacter(BonsEntryViewModel arg) => - arg.Name.ToUpper().Contains(SearchTerm.ToUpper()); - - private static BonsEntryViewModel Map(Bons item) => - new BonsEntryViewModel(item); - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.Battle; +using OpenKh.Tools.Common.Models; +using OpenKh.Tools.Kh2BattleEditor.Extensions; +using OpenKh.Tools.Kh2BattleEditor.Interfaces; +using OpenKh.Tools.Kh2BattleEditor.Services; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Windows; + +namespace OpenKh.Tools.Kh2BattleEditor.ViewModels +{ + public class BonsViewModel : MyGenericListModel, IBattleGetChanges + { + public class BonsEntryViewModel + { + public Bons Bons { get; } + + public BonsEntryViewModel(Bons bons) + { + Bons = bons; + } + + public string Name => $"{Id} {CharacterNameProvider.GetCharacterName(Bons.CharacterId)}"; + + public string Id => $"{Bons.RewardId:X02}"; + + public byte RewardId { get => Bons.RewardId; set => Bons.RewardId = value; } + public byte CharacterId { get => Bons.CharacterId; set => Bons.CharacterId = value; } + public byte HpIncrease { get => Bons.HpIncrease; set => Bons.HpIncrease = value; } + public byte MpIncrease { get => Bons.MpIncrease; set => Bons.MpIncrease = value; } + public byte DriveGaugeUpgrade { get => Bons.DriveGaugeUpgrade; set => Bons.DriveGaugeUpgrade = value; } + public byte ItemSlotUpgrade { get => Bons.ItemSlotUpgrade; set => Bons.ItemSlotUpgrade = value; } + public byte AccessorySlotUpgrade { get => Bons.AccessorySlotUpgrade; set => Bons.AccessorySlotUpgrade = value; } + public byte ArmorSlotUpgrade { get => Bons.ArmorSlotUpgrade; set => Bons.ArmorSlotUpgrade = value; } + public short BonusItem1 { get => Bons.BonusItem1; set => Bons.BonusItem1 = value; } + public short BonusItem2 { get => Bons.BonusItem2; set => Bons.BonusItem2 = value; } + public int Unknown0c { get => Bons.Unknown0c; set => Bons.Unknown0c = value; } + + public override string ToString() => Name; + } + + private const string entryName = "bons"; + + private string _searchTerm; + + public BonsViewModel(IEnumerable entries) : + this(Bons.Read(entries.GetBattleStream(entryName))) + { } + + public BonsViewModel() : + this(new List()) + { } + + private BonsViewModel(IEnumerable items) : + base(items.Select(Map)) + { + } + public string EntryName => entryName; + + public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + + public string SearchTerm + { + get => _searchTerm; + set + { + _searchTerm = value; + PerformFiltering(); + } + } + + public Stream CreateStream() + { + var stream = new MemoryStream(); + Bons.Write(stream, UnfilteredItems.Select(x => x.Bons)); + + return stream; + } + protected override void OnSelectedItem(BonsEntryViewModel item) + { + base.OnSelectedItem(item); + + OnPropertyChanged(nameof(IsItemEditingVisible)); + OnPropertyChanged(nameof(IsItemEditMessageVisible)); + } + + private void PerformFiltering() + { + if (string.IsNullOrWhiteSpace(_searchTerm)) + Filter(FilterNone); + else + Filter(FilterByCharacter); + } + + private bool FilterNone(BonsEntryViewModel arg) => true; + + private bool FilterByCharacter(BonsEntryViewModel arg) => + arg.Name.ToUpper().Contains(SearchTerm.ToUpper()); + + private static BonsEntryViewModel Map(Bons item) => + new BonsEntryViewModel(item); + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/ViewModels/EnmpViewModel.cs b/OpenKh.Tools.Kh2BattleEditor/ViewModels/EnmpViewModel.cs index 114aad143..f1f0b5ae6 100644 --- a/OpenKh.Tools.Kh2BattleEditor/ViewModels/EnmpViewModel.cs +++ b/OpenKh.Tools.Kh2BattleEditor/ViewModels/EnmpViewModel.cs @@ -1,111 +1,111 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Windows; -using OpenKh.Kh2; -using OpenKh.Kh2.Battle; -using OpenKh.Tools.Common.Models; -using OpenKh.Tools.Kh2BattleEditor.Extensions; -using OpenKh.Tools.Kh2BattleEditor.Interfaces; -using OpenKh.Tools.Kh2BattleEditor.Services; - -namespace OpenKh.Tools.Kh2BattleEditor.ViewModels -{ - public class EnmpViewModel : MyGenericListModel, IBattleGetChanges - { - public class EnmpEntryViewModel - { - public Enmp Enmp { get; } - - public EnmpEntryViewModel(Enmp enmp) - { - Enmp = enmp; - } - - public string Name => $"{Id} {EnemyNameProvider.GetEnemyName(Enmp.Id)}"; - - public string Id => $"{Enmp.Id:X02}"; - - public short Level { get => Enmp.Level; set => Enmp.Level = value; } - public short Health { get => Enmp.Health[0]; set => Enmp.Health[0] = value; } - public short Unknown44 { get => Enmp.Unknown44; set => Enmp.Unknown44 = value; } - public short Unknown46 { get => Enmp.Unknown46; set => Enmp.Unknown46 = value; } - public short PhysicalWeakness { get => Enmp.PhysicalWeakness; set => Enmp.PhysicalWeakness = value; } - public short FireWeakness { get => Enmp.FireWeakness; set => Enmp.FireWeakness = value; } - public short IceWeakness { get => Enmp.IceWeakness; set => Enmp.IceWeakness = value; } - public short ThunderWeakness { get => Enmp.ThunderWeakness; set => Enmp.ThunderWeakness = value; } - public short DarkWeakness { get => Enmp.DarkWeakness; set => Enmp.DarkWeakness = value; } - public short Unknown52 { get => Enmp.Unknown52; set => Enmp.Unknown52 = value; } - public short ReflectWeakness { get => Enmp.ReflectWeakness; set => Enmp.ReflectWeakness = value; } - public short Unknown56 { get => Enmp.Unknown56; set => Enmp.Unknown56 = value; } - public short Unknown58 { get => Enmp.Unknown58; set => Enmp.Unknown58 = value; } - public short Unknown5a { get => Enmp.Unknown5a; set => Enmp.Unknown5a = value; } - - public override string ToString() => Name; - } - - private const string entryName = "enmp"; - - private string _searchTerm; - - public EnmpViewModel(IEnumerable entries) : - this(Enmp.Read(entries.GetBattleStream(entryName))) - { } - - public EnmpViewModel() : - this(new List()) - { } - - private EnmpViewModel(IEnumerable items) : - base(items.Select(Map)) - { - } - - public string EntryName => entryName; - - public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - - public string SearchTerm - { - get => _searchTerm; - set - { - _searchTerm = value; - PerformFiltering(); - } - } - - public Stream CreateStream() - { - var stream = new MemoryStream(); - Enmp.Write(stream, UnfilteredItems.Select(x => x.Enmp)); - - return stream; - } - - protected override void OnSelectedItem(EnmpEntryViewModel item) - { - base.OnSelectedItem(item); - - OnPropertyChanged(nameof(IsItemEditingVisible)); - OnPropertyChanged(nameof(IsItemEditMessageVisible)); - } - - private void PerformFiltering() - { - if (string.IsNullOrWhiteSpace(_searchTerm)) - Filter(FilterNone); - else - Filter(FilterByEnemy); - } - - private bool FilterNone(EnmpEntryViewModel arg) => true; - - private bool FilterByEnemy(EnmpEntryViewModel arg) => - arg.Name.ToUpper().Contains(SearchTerm.ToUpper()); - - private static EnmpEntryViewModel Map(Enmp item) => - new EnmpEntryViewModel(item); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Windows; +using OpenKh.Kh2; +using OpenKh.Kh2.Battle; +using OpenKh.Tools.Common.Models; +using OpenKh.Tools.Kh2BattleEditor.Extensions; +using OpenKh.Tools.Kh2BattleEditor.Interfaces; +using OpenKh.Tools.Kh2BattleEditor.Services; + +namespace OpenKh.Tools.Kh2BattleEditor.ViewModels +{ + public class EnmpViewModel : MyGenericListModel, IBattleGetChanges + { + public class EnmpEntryViewModel + { + public Enmp Enmp { get; } + + public EnmpEntryViewModel(Enmp enmp) + { + Enmp = enmp; + } + + public string Name => $"{Id} {EnemyNameProvider.GetEnemyName(Enmp.Id)}"; + + public string Id => $"{Enmp.Id:X02}"; + + public short Level { get => Enmp.Level; set => Enmp.Level = value; } + public short Health { get => Enmp.Health[0]; set => Enmp.Health[0] = value; } + public short Unknown44 { get => Enmp.Unknown44; set => Enmp.Unknown44 = value; } + public short Unknown46 { get => Enmp.Unknown46; set => Enmp.Unknown46 = value; } + public short PhysicalWeakness { get => Enmp.PhysicalWeakness; set => Enmp.PhysicalWeakness = value; } + public short FireWeakness { get => Enmp.FireWeakness; set => Enmp.FireWeakness = value; } + public short IceWeakness { get => Enmp.IceWeakness; set => Enmp.IceWeakness = value; } + public short ThunderWeakness { get => Enmp.ThunderWeakness; set => Enmp.ThunderWeakness = value; } + public short DarkWeakness { get => Enmp.DarkWeakness; set => Enmp.DarkWeakness = value; } + public short Unknown52 { get => Enmp.Unknown52; set => Enmp.Unknown52 = value; } + public short ReflectWeakness { get => Enmp.ReflectWeakness; set => Enmp.ReflectWeakness = value; } + public short Unknown56 { get => Enmp.Unknown56; set => Enmp.Unknown56 = value; } + public short Unknown58 { get => Enmp.Unknown58; set => Enmp.Unknown58 = value; } + public short Unknown5a { get => Enmp.Unknown5a; set => Enmp.Unknown5a = value; } + + public override string ToString() => Name; + } + + private const string entryName = "enmp"; + + private string _searchTerm; + + public EnmpViewModel(IEnumerable entries) : + this(Enmp.Read(entries.GetBattleStream(entryName))) + { } + + public EnmpViewModel() : + this(new List()) + { } + + private EnmpViewModel(IEnumerable items) : + base(items.Select(Map)) + { + } + + public string EntryName => entryName; + + public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + + public string SearchTerm + { + get => _searchTerm; + set + { + _searchTerm = value; + PerformFiltering(); + } + } + + public Stream CreateStream() + { + var stream = new MemoryStream(); + Enmp.Write(stream, UnfilteredItems.Select(x => x.Enmp)); + + return stream; + } + + protected override void OnSelectedItem(EnmpEntryViewModel item) + { + base.OnSelectedItem(item); + + OnPropertyChanged(nameof(IsItemEditingVisible)); + OnPropertyChanged(nameof(IsItemEditMessageVisible)); + } + + private void PerformFiltering() + { + if (string.IsNullOrWhiteSpace(_searchTerm)) + Filter(FilterNone); + else + Filter(FilterByEnemy); + } + + private bool FilterNone(EnmpEntryViewModel arg) => true; + + private bool FilterByEnemy(EnmpEntryViewModel arg) => + arg.Name.ToUpper().Contains(SearchTerm.ToUpper()); + + private static EnmpEntryViewModel Map(Enmp item) => + new EnmpEntryViewModel(item); + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/ViewModels/FmlvViewModel.cs b/OpenKh.Tools.Kh2BattleEditor/ViewModels/FmlvViewModel.cs index ae34016c6..fe1a00f84 100644 --- a/OpenKh.Tools.Kh2BattleEditor/ViewModels/FmlvViewModel.cs +++ b/OpenKh.Tools.Kh2BattleEditor/ViewModels/FmlvViewModel.cs @@ -1,73 +1,73 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.Battle; -using OpenKh.Tools.Kh2BattleEditor.Extensions; -using OpenKh.Tools.Kh2BattleEditor.Interfaces; -using OpenKh.Tools.Kh2BattleEditor.Services; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.Kh2BattleEditor.ViewModels -{ - public class FmlvViewModel : GenericListModel, IBattleGetChanges - { - private const string entryName = "fmlv"; - - public string EntryName => entryName; - - public FmlvViewModel() : - this(new List()) - {} - - public FmlvViewModel(IEnumerable entries) : - this(Fmlv.Read(entries.GetBattleStream(entryName))) - {} - - - public FmlvViewModel(IEnumerable levels) : - this(levels, (levels.ToList().Count == 0x2D)) - {} - - public FmlvViewModel(IEnumerable list, bool isFinalMix) : - base(list.GroupBy(x => x.FormId).Select(x => new FmlvFormViewModel(x, isFinalMix))) - {} - - public Stream CreateStream() - { - var stream = new MemoryStream(); - Fmlv.Write(stream, UnfilteredItems.SelectMany(form => form).Select(x => x.Level).ToList()); - return stream; - } - } - - public class FmlvFormViewModel : GenericListModel - { - private readonly IGrouping fmlvGroup; - private readonly bool isFinalMix; - - public FmlvFormViewModel(IGrouping x, bool isFinalMix) : - base(x.Select(y => new FmlvLevelViewModel(y))) - - { - fmlvGroup = x; - this.isFinalMix = isFinalMix; - } - - public string Name => FormNameProvider.GetFormName(fmlvGroup.Key, isFinalMix); - - public class FmlvLevelViewModel - { - public Fmlv.Level Level { get; } - public FmlvLevelViewModel(Fmlv.Level level) - { - Level = level; - } - - public string Name => $"Level {Level.FormLevel}"; - public byte LevelGrowthAbility { get => Level.LevelGrowthAbility; set => Level.LevelGrowthAbility = value; } - public short Ability { get => Level.Ability; set => Level.Ability = value; } - public int Exp { get => Level.Exp; set => Level.Exp = value; } - } - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.Battle; +using OpenKh.Tools.Kh2BattleEditor.Extensions; +using OpenKh.Tools.Kh2BattleEditor.Interfaces; +using OpenKh.Tools.Kh2BattleEditor.Services; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.Kh2BattleEditor.ViewModels +{ + public class FmlvViewModel : GenericListModel, IBattleGetChanges + { + private const string entryName = "fmlv"; + + public string EntryName => entryName; + + public FmlvViewModel() : + this(new List()) + { } + + public FmlvViewModel(IEnumerable entries) : + this(Fmlv.Read(entries.GetBattleStream(entryName))) + { } + + + public FmlvViewModel(IEnumerable levels) : + this(levels, (levels.ToList().Count == 0x2D)) + { } + + public FmlvViewModel(IEnumerable list, bool isFinalMix) : + base(list.GroupBy(x => x.FormId).Select(x => new FmlvFormViewModel(x, isFinalMix))) + { } + + public Stream CreateStream() + { + var stream = new MemoryStream(); + Fmlv.Write(stream, UnfilteredItems.SelectMany(form => form).Select(x => x.Level).ToList()); + return stream; + } + } + + public class FmlvFormViewModel : GenericListModel + { + private readonly IGrouping fmlvGroup; + private readonly bool isFinalMix; + + public FmlvFormViewModel(IGrouping x, bool isFinalMix) : + base(x.Select(y => new FmlvLevelViewModel(y))) + + { + fmlvGroup = x; + this.isFinalMix = isFinalMix; + } + + public string Name => FormNameProvider.GetFormName(fmlvGroup.Key, isFinalMix); + + public class FmlvLevelViewModel + { + public Fmlv.Level Level { get; } + public FmlvLevelViewModel(Fmlv.Level level) + { + Level = level; + } + + public string Name => $"Level {Level.FormLevel}"; + public byte LevelGrowthAbility { get => Level.LevelGrowthAbility; set => Level.LevelGrowthAbility = value; } + public short Ability { get => Level.Ability; set => Level.Ability = value; } + public int Exp { get => Level.Exp; set => Level.Exp = value; } + } + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/ViewModels/LvupViewModel.cs b/OpenKh.Tools.Kh2BattleEditor/ViewModels/LvupViewModel.cs index bfac57a8e..9ca8411e2 100644 --- a/OpenKh.Tools.Kh2BattleEditor/ViewModels/LvupViewModel.cs +++ b/OpenKh.Tools.Kh2BattleEditor/ViewModels/LvupViewModel.cs @@ -1,98 +1,98 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.Battle; -using OpenKh.Tools.Kh2BattleEditor.Extensions; -using OpenKh.Tools.Kh2BattleEditor.Interfaces; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.Kh2BattleEditor.ViewModels -{ - public class LvupViewModel : GenericListModel, IBattleGetChanges - { - private const int DefaultType = 2; - private const string entryName = "lvup"; - private readonly Lvup _lvup; - public string EntryName => entryName; - - public LvupViewModel(IEnumerable entries) : - this(Lvup.Read(entries.GetBattleStream(entryName))) - { - } - - public LvupViewModel(Lvup Lvup) : - this(Lvup.Characters) - { - _lvup = Lvup; - } - - public LvupViewModel(IEnumerable characters) : - base(characters.Select((x, i) => new CharacterViewModel(x, i))) - { - } - - public LvupViewModel() : - this(new Lvup - { - MagicCode = DefaultType, - Count = 14, - Unknown08 = new byte[0x30], - Characters = new List() - }) - { - - } - - public Stream CreateStream() - { - var stream = new MemoryStream(); - new Lvup - { - MagicCode = _lvup.MagicCode, - Count = _lvup.Count, - Unknown08 = _lvup.Unknown08, - Characters = UnfilteredItems.Select(x => x.Character).ToList() - }.Write(stream); - - return stream; - } - - public class CharacterViewModel : GenericListModel - { - private readonly int _index; - public Lvup.PlayableCharacter Character { get; set; } - public string Name => ((Lvup.PlayableCharacterType)_index).ToString(); - - public CharacterViewModel(Lvup.PlayableCharacter character, int index) : - base(character.Levels.Select((x, i) => new LevelViewModel(x, i))) - { - _index = index; - Character = character; - } - - public class LevelViewModel - { - private readonly Lvup.PlayableCharacter.Level _level; - private readonly int _index; - - public string Name => $"Level {_index + 1}"; - - public LevelViewModel(Lvup.PlayableCharacter.Level level, int index) - { - _level = level; - _index = index; - } - - public int Exp { get => _level.Exp; set => _level.Exp = value; } - public byte Strength { get => _level.Strength; set => _level.Strength = value; } - public byte Magic { get => _level.Magic; set => _level.Magic = value; } - public byte Defense { get => _level.Defense; set => _level.Defense = value; } - public byte Ap { get => _level.Ap; set => _level.Ap = value; } - public short SwordAbility { get => _level.SwordAbility; set => _level.SwordAbility = value; } - public short ShieldAbility { get => _level.ShieldAbility; set => _level.ShieldAbility = value; } - public short StaffAbility { get => _level.StaffAbility; set => _level.StaffAbility = value; } - } - } - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.Battle; +using OpenKh.Tools.Kh2BattleEditor.Extensions; +using OpenKh.Tools.Kh2BattleEditor.Interfaces; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.Kh2BattleEditor.ViewModels +{ + public class LvupViewModel : GenericListModel, IBattleGetChanges + { + private const int DefaultType = 2; + private const string entryName = "lvup"; + private readonly Lvup _lvup; + public string EntryName => entryName; + + public LvupViewModel(IEnumerable entries) : + this(Lvup.Read(entries.GetBattleStream(entryName))) + { + } + + public LvupViewModel(Lvup Lvup) : + this(Lvup.Characters) + { + _lvup = Lvup; + } + + public LvupViewModel(IEnumerable characters) : + base(characters.Select((x, i) => new CharacterViewModel(x, i))) + { + } + + public LvupViewModel() : + this(new Lvup + { + MagicCode = DefaultType, + Count = 14, + Unknown08 = new byte[0x30], + Characters = new List() + }) + { + + } + + public Stream CreateStream() + { + var stream = new MemoryStream(); + new Lvup + { + MagicCode = _lvup.MagicCode, + Count = _lvup.Count, + Unknown08 = _lvup.Unknown08, + Characters = UnfilteredItems.Select(x => x.Character).ToList() + }.Write(stream); + + return stream; + } + + public class CharacterViewModel : GenericListModel + { + private readonly int _index; + public Lvup.PlayableCharacter Character { get; set; } + public string Name => ((Lvup.PlayableCharacterType)_index).ToString(); + + public CharacterViewModel(Lvup.PlayableCharacter character, int index) : + base(character.Levels.Select((x, i) => new LevelViewModel(x, i))) + { + _index = index; + Character = character; + } + + public class LevelViewModel + { + private readonly Lvup.PlayableCharacter.Level _level; + private readonly int _index; + + public string Name => $"Level {_index + 1}"; + + public LevelViewModel(Lvup.PlayableCharacter.Level level, int index) + { + _level = level; + _index = index; + } + + public int Exp { get => _level.Exp; set => _level.Exp = value; } + public byte Strength { get => _level.Strength; set => _level.Strength = value; } + public byte Magic { get => _level.Magic; set => _level.Magic = value; } + public byte Defense { get => _level.Defense; set => _level.Defense = value; } + public byte Ap { get => _level.Ap; set => _level.Ap = value; } + public short SwordAbility { get => _level.SwordAbility; set => _level.SwordAbility = value; } + public short ShieldAbility { get => _level.ShieldAbility; set => _level.ShieldAbility = value; } + public short StaffAbility { get => _level.StaffAbility; set => _level.StaffAbility = value; } + } + } + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/ViewModels/MainViewModel.cs b/OpenKh.Tools.Kh2BattleEditor/ViewModels/MainViewModel.cs index e8788e6a1..ee93de702 100644 --- a/OpenKh.Tools.Kh2BattleEditor/ViewModels/MainViewModel.cs +++ b/OpenKh.Tools.Kh2BattleEditor/ViewModels/MainViewModel.cs @@ -1,204 +1,204 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using OpenKh.Tools.Common; -using OpenKh.Tools.Kh2BattleEditor.Interfaces; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Windows; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.Kh2BattleEditor.ViewModels -{ - public class MainViewModel : BaseNotifyPropertyChanged - { - private static readonly string ApplicationName = Utilities.GetApplicationName(); - private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - private static readonly List BattleFilter = FileDialogFilterComposer.Compose() - .AddExtensions("00battle", "bin", "bar").AddAllFiles(); - private string _fileName; - private IEnumerable _battleItems; - private EnmpViewModel _enmp; - private FmlvViewModel _fmlv; - private BonsViewModel _bons; - private PrztViewModel _przt; - private LvupViewModel _lvup; - - public string Title => $"{FileName ?? "untitled"} | {ApplicationName}"; - - private string FileName - { - get => _fileName; - set - { - _fileName = value; - OnPropertyChanged(nameof(Title)); - } - } - - public RelayCommand OpenCommand { get; } - public RelayCommand SaveCommand { get; } - public RelayCommand SaveAsCommand { get; } - public RelayCommand ExitCommand { get; } - public RelayCommand AboutCommand { get; } - - public EnmpViewModel Enmp - { - get => _enmp; - private set { _enmp = value; OnPropertyChanged();} - } - - public FmlvViewModel Fmlv - { - get => _fmlv; - private set { _fmlv = value; OnPropertyChanged(); } - } - - public BonsViewModel Bons - { - get => _bons; - private set { _bons = value; OnPropertyChanged(); } - } - - public PrztViewModel Przt - { - get => _przt; - private set { _przt = value; OnPropertyChanged(); } - } - - public LvupViewModel Lvup - { - get => _lvup; - private set { _lvup = value; OnPropertyChanged(); } - } - - public MainViewModel() - { - OpenCommand = new RelayCommand(x => - { - FileDialog.OnOpen(fileName => - { - OpenFile(fileName); - }, BattleFilter); - }, x => true); - - SaveCommand = new RelayCommand(x => - { - if (!string.IsNullOrEmpty(FileName)) - { - SaveFile(FileName, FileName); - } - else - { - SaveAsCommand.Execute(x); - } - }, x => true); - - SaveAsCommand = new RelayCommand(x => - { - FileDialog.OnSave(fileName => - { - SaveFile(FileName, fileName); - FileName = fileName; - }, BattleFilter); - }, x => true); - - ExitCommand = new RelayCommand(x => - { - Window.Close(); - }, x => true); - - AboutCommand = new RelayCommand(x => - { - new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); - }, x => true); - - CreateBattleItems(); - } - - public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => - { - if (!Bar.IsValid(stream)) - { - MessageBox.Show(Window, $"{Path.GetFileName(fileName)} is not a valid BAR file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - return false; - } - - var items = Bar.Read(stream); - - if (!Is00battle(items)) - { - MessageBox.Show(Window, $"{Path.GetFileName(fileName)} does not appear to be a valid 00battle.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - return false; - } - - LoadBattleItems(items); - - FileName = fileName; - return true; - }); - - public void SaveFile(string previousFileName, string fileName) - { - File.Create(fileName).Using(stream => - { - SaveBattleItems(); - Bar.Write(stream, _battleItems); - }); - } - - private bool Is00battle(List items) => items.Any(x => new[] - { - "atkp", - "enmp", - "fmlv", - "lvpm", - "bons", - "przt", - "lvup", - }.Contains(x.Name)); - - private void CreateBattleItems() - { - _battleItems = new Bar.Entry[0]; - Enmp = GetDefaultBattleViewModelInstance(); - Fmlv = GetDefaultBattleViewModelInstance(); - Bons = GetDefaultBattleViewModelInstance(); - Przt = GetDefaultBattleViewModelInstance(); - Lvup = GetDefaultBattleViewModelInstance(); - } - - private void LoadBattleItems(IEnumerable entries) - { - _battleItems = entries; - Enmp = GetBattleViewModelInstance(_battleItems); - Fmlv = GetBattleViewModelInstance(_battleItems); - Bons = GetBattleViewModelInstance(_battleItems); - Przt = GetBattleViewModelInstance(_battleItems); - Lvup = GetBattleViewModelInstance(_battleItems); - } - - private void SaveBattleItems() - { - _battleItems = SaveBattleItem(_battleItems, Enmp); - _battleItems = SaveBattleItem(_battleItems, Fmlv); - _battleItems = SaveBattleItem(_battleItems, Bons); - _battleItems = SaveBattleItem(_battleItems, Przt); - _battleItems = SaveBattleItem(_battleItems, Lvup); - } - - private IEnumerable SaveBattleItem(IEnumerable entries, IBattleGetChanges battleGetChanges) => - entries.ForEntry(Bar.EntryType.List, battleGetChanges.EntryName, 0, entry => entry.Stream = battleGetChanges.CreateStream()); - - private T GetBattleViewModelInstance(IEnumerable entries) - where T : IBattleGetChanges => (T)Activator.CreateInstance(typeof(T), entries); - - private T GetDefaultBattleViewModelInstance() - where T : IBattleGetChanges => Activator.CreateInstance(); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using OpenKh.Tools.Common; +using OpenKh.Tools.Kh2BattleEditor.Interfaces; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.Kh2BattleEditor.ViewModels +{ + public class MainViewModel : BaseNotifyPropertyChanged + { + private static readonly string ApplicationName = Utilities.GetApplicationName(); + private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + private static readonly List BattleFilter = FileDialogFilterComposer.Compose() + .AddExtensions("00battle", "bin", "bar").AddAllFiles(); + private string _fileName; + private IEnumerable _battleItems; + private EnmpViewModel _enmp; + private FmlvViewModel _fmlv; + private BonsViewModel _bons; + private PrztViewModel _przt; + private LvupViewModel _lvup; + + public string Title => $"{FileName ?? "untitled"} | {ApplicationName}"; + + private string FileName + { + get => _fileName; + set + { + _fileName = value; + OnPropertyChanged(nameof(Title)); + } + } + + public RelayCommand OpenCommand { get; } + public RelayCommand SaveCommand { get; } + public RelayCommand SaveAsCommand { get; } + public RelayCommand ExitCommand { get; } + public RelayCommand AboutCommand { get; } + + public EnmpViewModel Enmp + { + get => _enmp; + private set { _enmp = value; OnPropertyChanged(); } + } + + public FmlvViewModel Fmlv + { + get => _fmlv; + private set { _fmlv = value; OnPropertyChanged(); } + } + + public BonsViewModel Bons + { + get => _bons; + private set { _bons = value; OnPropertyChanged(); } + } + + public PrztViewModel Przt + { + get => _przt; + private set { _przt = value; OnPropertyChanged(); } + } + + public LvupViewModel Lvup + { + get => _lvup; + private set { _lvup = value; OnPropertyChanged(); } + } + + public MainViewModel() + { + OpenCommand = new RelayCommand(x => + { + FileDialog.OnOpen(fileName => + { + OpenFile(fileName); + }, BattleFilter); + }, x => true); + + SaveCommand = new RelayCommand(x => + { + if (!string.IsNullOrEmpty(FileName)) + { + SaveFile(FileName, FileName); + } + else + { + SaveAsCommand.Execute(x); + } + }, x => true); + + SaveAsCommand = new RelayCommand(x => + { + FileDialog.OnSave(fileName => + { + SaveFile(FileName, fileName); + FileName = fileName; + }, BattleFilter); + }, x => true); + + ExitCommand = new RelayCommand(x => + { + Window.Close(); + }, x => true); + + AboutCommand = new RelayCommand(x => + { + new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); + }, x => true); + + CreateBattleItems(); + } + + public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => + { + if (!Bar.IsValid(stream)) + { + MessageBox.Show(Window, $"{Path.GetFileName(fileName)} is not a valid BAR file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + var items = Bar.Read(stream); + + if (!Is00battle(items)) + { + MessageBox.Show(Window, $"{Path.GetFileName(fileName)} does not appear to be a valid 00battle.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + LoadBattleItems(items); + + FileName = fileName; + return true; + }); + + public void SaveFile(string previousFileName, string fileName) + { + File.Create(fileName).Using(stream => + { + SaveBattleItems(); + Bar.Write(stream, _battleItems); + }); + } + + private bool Is00battle(List items) => items.Any(x => new[] + { + "atkp", + "enmp", + "fmlv", + "lvpm", + "bons", + "przt", + "lvup", + }.Contains(x.Name)); + + private void CreateBattleItems() + { + _battleItems = new Bar.Entry[0]; + Enmp = GetDefaultBattleViewModelInstance(); + Fmlv = GetDefaultBattleViewModelInstance(); + Bons = GetDefaultBattleViewModelInstance(); + Przt = GetDefaultBattleViewModelInstance(); + Lvup = GetDefaultBattleViewModelInstance(); + } + + private void LoadBattleItems(IEnumerable entries) + { + _battleItems = entries; + Enmp = GetBattleViewModelInstance(_battleItems); + Fmlv = GetBattleViewModelInstance(_battleItems); + Bons = GetBattleViewModelInstance(_battleItems); + Przt = GetBattleViewModelInstance(_battleItems); + Lvup = GetBattleViewModelInstance(_battleItems); + } + + private void SaveBattleItems() + { + _battleItems = SaveBattleItem(_battleItems, Enmp); + _battleItems = SaveBattleItem(_battleItems, Fmlv); + _battleItems = SaveBattleItem(_battleItems, Bons); + _battleItems = SaveBattleItem(_battleItems, Przt); + _battleItems = SaveBattleItem(_battleItems, Lvup); + } + + private IEnumerable SaveBattleItem(IEnumerable entries, IBattleGetChanges battleGetChanges) => + entries.ForEntry(Bar.EntryType.List, battleGetChanges.EntryName, 0, entry => entry.Stream = battleGetChanges.CreateStream()); + + private T GetBattleViewModelInstance(IEnumerable entries) + where T : IBattleGetChanges => (T)Activator.CreateInstance(typeof(T), entries); + + private T GetDefaultBattleViewModelInstance() + where T : IBattleGetChanges => Activator.CreateInstance(); + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/ViewModels/PrztViewModel.cs b/OpenKh.Tools.Kh2BattleEditor/ViewModels/PrztViewModel.cs index 8bcc222fe..6f609955b 100644 --- a/OpenKh.Tools.Kh2BattleEditor/ViewModels/PrztViewModel.cs +++ b/OpenKh.Tools.Kh2BattleEditor/ViewModels/PrztViewModel.cs @@ -1,110 +1,110 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.Battle; -using OpenKh.Tools.Kh2BattleEditor.Extensions; -using OpenKh.Tools.Kh2BattleEditor.Interfaces; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Windows; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.Kh2BattleEditor.ViewModels -{ - public class PrztViewModel : GenericListModel, IBattleGetChanges - { - public class PrztEntryViewModel - { - public Przt Przt { get; } - public PrztEntryViewModel(Przt przt) - { - Przt = przt; - } - public string Name => $"{Id}"; - public string Id => $"{Przt.Id:X02}"; - - public ushort DropId { get => Przt.Id; set => Przt.Id = value; } - public byte SmallHpOrbs { get => Przt.SmallHpOrbs; set => Przt.SmallHpOrbs = value; } - public byte BigHpOrbs { get => Przt.BigHpOrbs; set => Przt.BigHpOrbs = value; } - public byte BigMoneyOrbs { get => Przt.BigMoneyOrbs; set => Przt.BigMoneyOrbs = value; } - public byte MediumMoneyOrbs { get => Przt.MediumMoneyOrbs; set => Przt.MediumMoneyOrbs = value; } - public byte SmallMoneyOrbs { get => Przt.SmallMoneyOrbs; set => Przt.SmallMoneyOrbs = value; } - public byte SmallMpOrbs { get => Przt.SmallMpOrbs; set => Przt.SmallMpOrbs = value; } - public byte BigMpOrbs { get => Przt.BigMpOrbs; set => Przt.BigMpOrbs = value; } - public byte SmallDriveOrbs { get => Przt.SmallDriveOrbs; set => Przt.SmallDriveOrbs = value; } - public byte BigDriveOrbs { get => Przt.BigDriveOrbs; set => Przt.BigDriveOrbs = value; } - public byte Unknown0a { get => Przt.Unknown0a; set => Przt.Unknown0a = value; } - public ushort Item1 { get => Przt.Item1; set => Przt.Item1 = value; } - public short Item1Percentage { get => Przt.Item1Percentage; set => Przt.Item1Percentage = value; } - public ushort Item2 { get => Przt.Item2; set => Przt.Item2 = value; } - public short Item2Percentage { get => Przt.Item2Percentage; set => Przt.Item2Percentage = value; } - public ushort Item3 { get => Przt.Item3; set => Przt.Item3 = value; } - public short Item3Percentage { get => Przt.Item3Percentage; set => Przt.Item3Percentage = value; } - - public override string ToString() => Name; - } - - private const string entryName = "przt"; - - private string _searchTerm; - public string EntryName => entryName; - - public PrztViewModel(IEnumerable entries) : - this(Przt.Read(entries.GetBattleStream(entryName))) - { } - - public PrztViewModel() : - this(new List()) - { } - - private PrztViewModel(IEnumerable items) : - base(items.Select(Map)) - { - } - - public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - - public string SearchTerm - { - get => _searchTerm; - set - { - _searchTerm = value; - PerformFiltering(); - } - } - - - public Stream CreateStream() - { - var stream = new MemoryStream(); - Przt.Write(stream, UnfilteredItems.Select(x => x.Przt)); - - return stream; - } - - protected override void OnSelectedItem(PrztEntryViewModel item) - { - base.OnSelectedItem(item); - - OnPropertyChanged(nameof(IsItemEditingVisible)); - OnPropertyChanged(nameof(IsItemEditMessageVisible)); - } - - private void PerformFiltering() - { - if (string.IsNullOrWhiteSpace(_searchTerm)) - Filter(FilterNone); - else - Filter(FilterByEnemy); - } - - private bool FilterNone(PrztEntryViewModel arg) => true; - - private bool FilterByEnemy(PrztEntryViewModel arg) => - arg.Name.ToUpper().Contains(SearchTerm.ToUpper()); - - private static PrztEntryViewModel Map(Przt item) => - new PrztEntryViewModel(item); - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.Battle; +using OpenKh.Tools.Kh2BattleEditor.Extensions; +using OpenKh.Tools.Kh2BattleEditor.Interfaces; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Windows; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.Kh2BattleEditor.ViewModels +{ + public class PrztViewModel : GenericListModel, IBattleGetChanges + { + public class PrztEntryViewModel + { + public Przt Przt { get; } + public PrztEntryViewModel(Przt przt) + { + Przt = przt; + } + public string Name => $"{Id}"; + public string Id => $"{Przt.Id:X02}"; + + public ushort DropId { get => Przt.Id; set => Przt.Id = value; } + public byte SmallHpOrbs { get => Przt.SmallHpOrbs; set => Przt.SmallHpOrbs = value; } + public byte BigHpOrbs { get => Przt.BigHpOrbs; set => Przt.BigHpOrbs = value; } + public byte BigMoneyOrbs { get => Przt.BigMoneyOrbs; set => Przt.BigMoneyOrbs = value; } + public byte MediumMoneyOrbs { get => Przt.MediumMoneyOrbs; set => Przt.MediumMoneyOrbs = value; } + public byte SmallMoneyOrbs { get => Przt.SmallMoneyOrbs; set => Przt.SmallMoneyOrbs = value; } + public byte SmallMpOrbs { get => Przt.SmallMpOrbs; set => Przt.SmallMpOrbs = value; } + public byte BigMpOrbs { get => Przt.BigMpOrbs; set => Przt.BigMpOrbs = value; } + public byte SmallDriveOrbs { get => Przt.SmallDriveOrbs; set => Przt.SmallDriveOrbs = value; } + public byte BigDriveOrbs { get => Przt.BigDriveOrbs; set => Przt.BigDriveOrbs = value; } + public byte Unknown0a { get => Przt.Unknown0a; set => Przt.Unknown0a = value; } + public ushort Item1 { get => Przt.Item1; set => Przt.Item1 = value; } + public short Item1Percentage { get => Przt.Item1Percentage; set => Przt.Item1Percentage = value; } + public ushort Item2 { get => Przt.Item2; set => Przt.Item2 = value; } + public short Item2Percentage { get => Przt.Item2Percentage; set => Przt.Item2Percentage = value; } + public ushort Item3 { get => Przt.Item3; set => Przt.Item3 = value; } + public short Item3Percentage { get => Przt.Item3Percentage; set => Przt.Item3Percentage = value; } + + public override string ToString() => Name; + } + + private const string entryName = "przt"; + + private string _searchTerm; + public string EntryName => entryName; + + public PrztViewModel(IEnumerable entries) : + this(Przt.Read(entries.GetBattleStream(entryName))) + { } + + public PrztViewModel() : + this(new List()) + { } + + private PrztViewModel(IEnumerable items) : + base(items.Select(Map)) + { + } + + public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + + public string SearchTerm + { + get => _searchTerm; + set + { + _searchTerm = value; + PerformFiltering(); + } + } + + + public Stream CreateStream() + { + var stream = new MemoryStream(); + Przt.Write(stream, UnfilteredItems.Select(x => x.Przt)); + + return stream; + } + + protected override void OnSelectedItem(PrztEntryViewModel item) + { + base.OnSelectedItem(item); + + OnPropertyChanged(nameof(IsItemEditingVisible)); + OnPropertyChanged(nameof(IsItemEditMessageVisible)); + } + + private void PerformFiltering() + { + if (string.IsNullOrWhiteSpace(_searchTerm)) + Filter(FilterNone); + else + Filter(FilterByEnemy); + } + + private bool FilterNone(PrztEntryViewModel arg) => true; + + private bool FilterByEnemy(PrztEntryViewModel arg) => + arg.Name.ToUpper().Contains(SearchTerm.ToUpper()); + + private static PrztEntryViewModel Map(Przt item) => + new PrztEntryViewModel(item); + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/Views/BonsView.xaml.cs b/OpenKh.Tools.Kh2BattleEditor/Views/BonsView.xaml.cs index cd812dcd6..b9d77f63d 100644 --- a/OpenKh.Tools.Kh2BattleEditor/Views/BonsView.xaml.cs +++ b/OpenKh.Tools.Kh2BattleEditor/Views/BonsView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace OpenKh.Tools.Kh2BattleEditor.Views -{ - /// - /// Interaction logic for BonsView.xaml - /// - public partial class BonsView : UserControl - { - public BonsView() - { - InitializeComponent(); - } - } -} +using System.Windows.Controls; + +namespace OpenKh.Tools.Kh2BattleEditor.Views +{ + /// + /// Interaction logic for BonsView.xaml + /// + public partial class BonsView : UserControl + { + public BonsView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/Views/EnmpView.xaml.cs b/OpenKh.Tools.Kh2BattleEditor/Views/EnmpView.xaml.cs index 1fd3292af..a673dc4ba 100644 --- a/OpenKh.Tools.Kh2BattleEditor/Views/EnmpView.xaml.cs +++ b/OpenKh.Tools.Kh2BattleEditor/Views/EnmpView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace OpenKh.Tools.Kh2BattleEditor.Views -{ - /// - /// Interaction logic for EnmpView.xaml - /// - public partial class EnmpView : UserControl - { - public EnmpView() - { - InitializeComponent(); - } - } -} +using System.Windows.Controls; + +namespace OpenKh.Tools.Kh2BattleEditor.Views +{ + /// + /// Interaction logic for EnmpView.xaml + /// + public partial class EnmpView : UserControl + { + public EnmpView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/Views/FmlvView.xaml.cs b/OpenKh.Tools.Kh2BattleEditor/Views/FmlvView.xaml.cs index e449e474d..ed96d6c08 100644 --- a/OpenKh.Tools.Kh2BattleEditor/Views/FmlvView.xaml.cs +++ b/OpenKh.Tools.Kh2BattleEditor/Views/FmlvView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace OpenKh.Tools.Kh2BattleEditor.Views -{ - /// - /// Interaction logic for FmlvView.xaml - /// - public partial class FmlvView : UserControl - { - public FmlvView() - { - InitializeComponent(); - } - } -} \ No newline at end of file +using System.Windows.Controls; + +namespace OpenKh.Tools.Kh2BattleEditor.Views +{ + /// + /// Interaction logic for FmlvView.xaml + /// + public partial class FmlvView : UserControl + { + public FmlvView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/Views/LvupView.xaml.cs b/OpenKh.Tools.Kh2BattleEditor/Views/LvupView.xaml.cs index b747fd608..a051ea77e 100644 --- a/OpenKh.Tools.Kh2BattleEditor/Views/LvupView.xaml.cs +++ b/OpenKh.Tools.Kh2BattleEditor/Views/LvupView.xaml.cs @@ -1,28 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace OpenKh.Tools.Kh2BattleEditor.Views -{ - /// - /// Interaction logic for LvupView.xaml - /// - public partial class LvupView : UserControl - { - public LvupView() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace OpenKh.Tools.Kh2BattleEditor.Views +{ + /// + /// Interaction logic for LvupView.xaml + /// + public partial class LvupView : UserControl + { + public LvupView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/Views/MainWindow.xaml.cs b/OpenKh.Tools.Kh2BattleEditor/Views/MainWindow.xaml.cs index 52b2453fc..dde3182d5 100644 --- a/OpenKh.Tools.Kh2BattleEditor/Views/MainWindow.xaml.cs +++ b/OpenKh.Tools.Kh2BattleEditor/Views/MainWindow.xaml.cs @@ -1,17 +1,17 @@ -using System.Windows; -using OpenKh.Tools.Kh2BattleEditor.ViewModels; - -namespace OpenKh.Tools.Kh2BattleEditor.Views -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); - DataContext = new MainViewModel(); - } - } -} +using System.Windows; +using OpenKh.Tools.Kh2BattleEditor.ViewModels; + +namespace OpenKh.Tools.Kh2BattleEditor.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + DataContext = new MainViewModel(); + } + } +} diff --git a/OpenKh.Tools.Kh2BattleEditor/Views/PrztView.xaml.cs b/OpenKh.Tools.Kh2BattleEditor/Views/PrztView.xaml.cs index 66dfa00c3..0f45b5a53 100644 --- a/OpenKh.Tools.Kh2BattleEditor/Views/PrztView.xaml.cs +++ b/OpenKh.Tools.Kh2BattleEditor/Views/PrztView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace OpenKh.Tools.Kh2BattleEditor.Views -{ - /// - /// Interaction logic for PrztView.xaml - /// - public partial class PrztView : UserControl - { - public PrztView() - { - InitializeComponent(); - } - } -} +using System.Windows.Controls; + +namespace OpenKh.Tools.Kh2BattleEditor.Views +{ + /// + /// Interaction logic for PrztView.xaml + /// + public partial class PrztView : UserControl + { + public PrztView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/App.cs b/OpenKh.Tools.Kh2MapStudio/App.cs index 1c5a893c1..7cfdc8679 100644 --- a/OpenKh.Tools.Kh2MapStudio/App.cs +++ b/OpenKh.Tools.Kh2MapStudio/App.cs @@ -1,433 +1,433 @@ -using Assimp; -using ImGuiNET; -using Microsoft.Xna.Framework.Input; -using OpenKh.Kh2; -using OpenKh.Tools.Common.CustomImGui; -using OpenKh.Tools.Kh2MapStudio.Windows; -using System; -using System.Collections.Generic; -using System.IO; -using System.Numerics; -using System.Windows; -using Xe.Tools.Wpf.Dialogs; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; -using xna = Microsoft.Xna.Framework; - -namespace OpenKh.Tools.Kh2MapStudio -{ - class App : IDisposable - { - private static readonly List MapFilter = - FileDialogFilterComposer.Compose() - .AddExtensions("MAP file", "map") - .AddAllFiles(); - private static readonly List ArdFilter = - FileDialogFilterComposer.Compose() - .AddExtensions("ARD file", "ard") - .AddAllFiles(); - private static readonly List ModelFilter = - FileDialogFilterComposer.Compose() - .AddExtensions("glTF file (GL Transmission Format)", "gltf") - .AddExtensions("FBX file", "fbx") - .AddExtensions("DAE file (Collada) (might be unaccurate)", "dae") - .AddExtensions("OBJ file (Wavefront) (might lose some information)", "obj") - .AddAllFiles(); - - private readonly Vector4 BgUiColor = new Vector4(0.0f, 0.0f, 0.0f, 0.5f); - private readonly MonoGameImGuiBootstrap _bootstrap; - private bool _exitFlag = false; - - private readonly Dictionary _keyMapping = new Dictionary(); - private readonly MapRenderer _mapRenderer; - private string _gamePath; - private string _mapName; - private string _region; - private string _ardPath; - private string _mapPath; - private string _objPath; - private List _mapList = new List(); - private ObjEntryController _objEntryController; - - private xna.Point _previousMousePosition; - - public string Title - { - get - { - var mapName = _mapName != null ? $"{_mapName}@" : string.Empty; - return $"{mapName}{_gamePath ?? "unloaded"} | {MonoGameImGuiBootstrap.ApplicationName}"; - } - } - - private string GamePath - { - get => _gamePath; - set - { - _gamePath = value; - UpdateTitle(); - EnumerateMapList(); - - _objEntryController?.Dispose(); - _objEntryController = new ObjEntryController( - _bootstrap.GraphicsDevice, - _objPath, - Path.Combine(_gamePath, "00objentry.bin")); - _mapRenderer.ObjEntryController = _objEntryController; - - Settings.Default.GamePath = value; - Settings.Default.Save(); - - } - } - - private string MapName - { - get => _mapName; - set - { - _mapName = value; - UpdateTitle(); - - _mapRenderer.Close(); - _mapRenderer.OpenMap(Path.Combine(_mapPath, $"{_mapName}.map")); - _mapRenderer.OpenArd(Path.Combine(_ardPath, $"{_mapName}.ard")); - } - } - - private bool IsGameOpen => !string.IsNullOrEmpty(_gamePath); - private bool IsMapOpen => !string.IsNullOrEmpty(_mapName); - private bool IsOpen => IsGameOpen && IsMapOpen; - - public App(MonoGameImGuiBootstrap bootstrap, string gamePath = null) - { - _bootstrap = bootstrap; - _bootstrap.Title = Title; - _mapRenderer = new MapRenderer(bootstrap.Content, bootstrap.GraphicsDeviceManager); - AddKeyMapping(Keys.O, MenuFileOpen); - AddKeyMapping(Keys.S, MenuFileSave); - AddKeyMapping(Keys.Q, MenuFileUnload); - - if (string.IsNullOrEmpty(gamePath)) - gamePath = Settings.Default.GamePath; - - if (!string.IsNullOrEmpty(gamePath)) - OpenFolder(gamePath); - - ImGui.PushStyleColor(ImGuiCol.MenuBarBg, BgUiColor); - } - - public bool MainLoop() - { - _bootstrap.GraphicsDevice.Clear(xna.Color.CornflowerBlue); - ProcessKeyMapping(); - if (!_bootstrap.ImGuiWantTextInput) - ProcessKeyboardInput(Keyboard.GetState(), 1f / 60); - if (!_bootstrap.ImGuiWantCaptureMouse) - ProcessMouseInput(Mouse.GetState()); - - ImGui.PushStyleColor(ImGuiCol.WindowBg, BgUiColor); - ForControl(ImGui.BeginMainMenuBar, ImGui.EndMainMenuBar, MainMenu); - - MainWindow(); - - ForWindow("Tools", () => - { - if (EditorSettings.ViewCamera) - CameraWindow.Run(_mapRenderer.Camera); - if (EditorSettings.ViewLayerControl) - LayerControllerWindow.Run(_mapRenderer); - if (EditorSettings.ViewSpawnPoint) - SpawnPointWindow.Run(_mapRenderer); - if (EditorSettings.ViewMeshGroup) - MeshGroupWindow.Run(_mapRenderer.MapMeshGroups); - if (EditorSettings.ViewBobDescriptor) - BobDescriptorWindow.Run(_mapRenderer.BobDescriptors, _mapRenderer.BobMeshGroups.Count); - if (EditorSettings.ViewSpawnScriptMap) - SpawnScriptWindow.Run("map", _mapRenderer.SpawnScriptMap); - if (EditorSettings.ViewSpawnScriptBattle) - SpawnScriptWindow.Run("btl", _mapRenderer.SpawnScriptBattle); - if (EditorSettings.ViewSpawnScriptEvent) - SpawnScriptWindow.Run("evt", _mapRenderer.SpawnScriptEvent); - }); - - ImGui.PopStyleColor(); - - return _exitFlag; - } - - public void Dispose() - { - _objEntryController?.Dispose(); - } - - private void MainWindow() - { - if (!IsGameOpen) - { - ImGui.Text("Game content not loaded."); - return; - } - - ForControl(() => - { - var nextPos = ImGui.GetCursorPos(); - var ret = ImGui.Begin("MapList", - ImGuiWindowFlags.NoDecoration | - ImGuiWindowFlags.NoCollapse | - ImGuiWindowFlags.NoMove); - ImGui.SetWindowPos(nextPos); - ImGui.SetWindowSize(new Vector2(64, 0)); - return ret; - }, () => { }, () => - { - foreach (var map in _mapList) - { - if (ImGui.Selectable(map, MapName == map)) - { - MapName = map; - } - } - }); - ImGui.SameLine(); - - if (!IsMapOpen) - { - ImGui.Text("Please select a map to edit."); - return; - } - - _mapRenderer.Update(1f / 60); - _mapRenderer.Draw(); - } - - void MainMenu() - { - ForMenuBar(() => - { - ForMenu("File", () => - { - ForMenuItem("Open extracted game folder...", "CTRL+O", MenuFileOpen); - ForMenuItem("Unload current map+ard", "CTRL+Q", MenuFileUnload, IsOpen); - ForMenuItem("Import extern MAP file", MenuFileOpenMap, IsGameOpen); - ForMenuItem("Import extern ARD file", MenuFileOpenArd, IsGameOpen); - ForMenuItem("Save map+ard", "CTRL+S", MenuFileSave, IsOpen); - ForMenuItem("Save map as...", MenuFileSaveMapAs, IsOpen); - ForMenuItem("Save ard as...", MenuFileSaveArdAs, IsOpen); - ImGui.Separator(); - ForMenu("Export", () => - { - ForMenuItem("Map Collision", ExportMapCollision, _mapRenderer.ShowMapCollision.HasValue); - ForMenuItem("Camera Collision", ExportCameraCollision, _mapRenderer.ShowCameraCollision.HasValue); - ForMenuItem("Light Collision", ExportLightCollision, _mapRenderer.ShowLightCollision.HasValue); - }); - ImGui.Separator(); - ForMenu("Preferences", () => - { - ForEdit("Movement speed", () => EditorSettings.MoveSpeed, x => EditorSettings.MoveSpeed = x); - ForEdit("Movement speed (shift)", () => EditorSettings.MoveSpeedShift, x => EditorSettings.MoveSpeedShift = x); - }); - ImGui.Separator(); - ForMenuItem("Exit", MenuFileExit); - }); - ForMenu("View", () => - { - ForMenuCheck("Camera", () => EditorSettings.ViewCamera, x => EditorSettings.ViewCamera = x); - ForMenuCheck("Layer control", () => EditorSettings.ViewLayerControl, x => EditorSettings.ViewLayerControl = x); - ForMenuCheck("Spawn points", () => EditorSettings.ViewSpawnPoint, x => EditorSettings.ViewSpawnPoint = x); - ForMenuCheck("BOB descriptors", () => EditorSettings.ViewBobDescriptor, x => EditorSettings.ViewBobDescriptor = x); - ForMenuCheck("Mesh group", () => EditorSettings.ViewMeshGroup, x => EditorSettings.ViewMeshGroup = x); - ForMenuCheck("Spawn script MAP", () => EditorSettings.ViewSpawnScriptMap, x => EditorSettings.ViewSpawnScriptMap = x); - ForMenuCheck("Spawn script BTL", () => EditorSettings.ViewSpawnScriptBattle, x => EditorSettings.ViewSpawnScriptBattle = x); - ForMenuCheck("Spawn script EVT", () => EditorSettings.ViewSpawnScriptEvent, x => EditorSettings.ViewSpawnScriptEvent = x); - }); - ForMenu("Help", () => - { - ForMenuItem("About", ShowAboutDialog); - }); - }); - } - - private void MenuFileOpen() => FileDialog.OnFolder(OpenFolder); - private void MenuFileUnload() => _mapRenderer.Close(); - private void MenuFileOpenMap() => FileDialog.OnOpen(_mapRenderer.OpenMap, MapFilter); - private void MenuFileOpenArd() => FileDialog.OnOpen(_mapRenderer.OpenArd, ArdFilter); - - private void MenuFileSave() - { - _mapRenderer.SaveMap(Path.Combine(_mapPath, MapName + ".map")); - _mapRenderer.SaveArd(Path.Combine(_ardPath, MapName + ".ard")); - } - - private void MenuFileSaveMapAs() - { - var defaultName = MapName + ".map"; - FileDialog.OnSave(_mapRenderer.SaveMap, MapFilter, defaultName); - } - - private void MenuFileSaveArdAs() - { - var defaultName = MapName + ".ard"; - FileDialog.OnSave(_mapRenderer.SaveArd, ArdFilter, defaultName); - } - - private void ExportMapCollision() => FileDialog.OnSave(fileName => - { - ExportScene(fileName, _mapRenderer.MapCollision.Scene); - }, ModelFilter, $"{MapName}_map-collision.dae"); - - private void ExportCameraCollision() => FileDialog.OnSave(fileName => - { - ExportScene(fileName, _mapRenderer.CameraCollision.Scene); - }, ModelFilter, $"{MapName}_camera-collision.dae"); - - private void ExportLightCollision() => FileDialog.OnSave(fileName => - { - ExportScene(fileName, _mapRenderer.LightCollision.Scene); - }, ModelFilter, $"{MapName}_light-collision.dae"); - - private void MenuFileExit() => _exitFlag = true; - - public void OpenFolder(string gamePath) - { - try - { - if (!Directory.Exists(_ardPath = Path.Combine(gamePath, "ard")) || - !Directory.Exists(_mapPath = Path.Combine(gamePath, "map")) || - !Directory.Exists(_objPath = Path.Combine(gamePath, "obj"))) - throw new DirectoryNotFoundException( - "The specified directory must contain the full extracted copy of the game."); - - GamePath = gamePath; - } - catch (Exception ex) - { - ShowError(ex.Message); - } - } - - private void UpdateTitle() - { - _bootstrap.Title = Title; - } - - private void EnumerateMapList() - { - var mapFiles = Directory.GetFiles(_mapPath, "*.map"); - if (mapFiles.Length == 0) - { - foreach (var region in Constants.Regions) - { - var testPath = Path.Combine(_mapPath, region); - if (Directory.Exists(testPath)) - { - _mapPath = testPath; - _region = region; - break; - } - } - mapFiles = Directory.GetFiles(_mapPath, "*.map"); - } - - _mapList.Clear(); - foreach (var mapFile in mapFiles) - { - var mapName = Path.GetFileNameWithoutExtension(mapFile); - if (File.Exists(Path.Combine(_ardPath, $"{mapName}.ard"))) - _mapList.Add(mapName); - } - } - - private void AddKeyMapping(Keys key, Action action) - { - _keyMapping[key] = action; - } - - private void ProcessKeyMapping() - { - var k = Keyboard.GetState(); - if (k.IsKeyDown(Keys.LeftControl)) - { - var keys = k.GetPressedKeys(); - foreach (var key in keys) - { - if (_keyMapping.TryGetValue(key, out var action)) - action(); - } - } - } - - private void ProcessKeyboardInput(KeyboardState keyboard, float deltaTime) - { - var speed = (float)(deltaTime * EditorSettings.MoveSpeed); - var moveSpeed = speed; - if (keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift)) - moveSpeed = (float)(deltaTime * EditorSettings.MoveSpeedShift); - - var camera = _mapRenderer.Camera; - if (keyboard.IsKeyDown(Keys.W)) - camera.CameraPosition += Vector3.Multiply(camera.CameraLookAtX, moveSpeed * 5); - if (keyboard.IsKeyDown(Keys.S)) - camera.CameraPosition -= Vector3.Multiply(camera.CameraLookAtX, moveSpeed * 5); - if (keyboard.IsKeyDown(Keys.A)) - camera.CameraPosition -= Vector3.Multiply(camera.CameraLookAtY, moveSpeed * 5); - if (keyboard.IsKeyDown(Keys.D)) - camera.CameraPosition += Vector3.Multiply(camera.CameraLookAtY, moveSpeed * 5); - if (keyboard.IsKeyDown(Keys.Q)) - camera.CameraPosition += Vector3.Multiply(camera.CameraLookAtZ, moveSpeed * 5); - if (keyboard.IsKeyDown(Keys.E)) - camera.CameraPosition -= Vector3.Multiply(camera.CameraLookAtZ, moveSpeed * 5); - - if (keyboard.IsKeyDown(Keys.Up)) - camera.CameraRotationYawPitchRoll += new Vector3(0, 0, 1 * speed); - if (keyboard.IsKeyDown(Keys.Down)) - camera.CameraRotationYawPitchRoll -= new Vector3(0, 0, 1 * speed); - if (keyboard.IsKeyDown(Keys.Left)) - camera.CameraRotationYawPitchRoll += new Vector3(1 * speed, 0, 0); - if (keyboard.IsKeyDown(Keys.Right)) - camera.CameraRotationYawPitchRoll -= new Vector3(1 * speed, 0, 0); - } - - private void ProcessMouseInput(MouseState mouse) - { - const float Speed = 0.25f; - if (mouse.LeftButton == ButtonState.Pressed) - { - var camera = _mapRenderer.Camera; - var xSpeed = (_previousMousePosition.X - mouse.Position.X) * Speed; - var ySpeed = (_previousMousePosition.Y - mouse.Position.Y) * Speed; - camera.CameraRotationYawPitchRoll += new Vector3(1 * -xSpeed, 0, 0); - camera.CameraRotationYawPitchRoll += new Vector3(0, 0, 1 * ySpeed); - } - - _previousMousePosition = mouse.Position; - } - - private static void ExportScene(string fileName, Scene scene) - { - using var ctx = new AssimpContext(); - var extension = Path.GetExtension(fileName).ToLower(); - var exportFormat = ctx.GetSupportedExportFormats(); - foreach (var format in exportFormat) - { - if ($".{format.FileExtension}" == extension) - { - var material = new Material(); - material.Clear(); - - scene.Materials.Add(material); - ctx.ExportFile(scene, fileName, format.FormatId); - return; - } - } - - ShowError($"Unable to export with '{extension}' extension."); - } - - public static void ShowError(string message, string title = "Error") => - MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Error); - - private void ShowAboutDialog() => - MessageBox.Show("OpenKH is amazing."); - } -} +using Assimp; +using ImGuiNET; +using Microsoft.Xna.Framework.Input; +using OpenKh.Kh2; +using OpenKh.Tools.Common.CustomImGui; +using OpenKh.Tools.Kh2MapStudio.Windows; +using System; +using System.Collections.Generic; +using System.IO; +using System.Numerics; +using System.Windows; +using Xe.Tools.Wpf.Dialogs; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; +using xna = Microsoft.Xna.Framework; + +namespace OpenKh.Tools.Kh2MapStudio +{ + class App : IDisposable + { + private static readonly List MapFilter = + FileDialogFilterComposer.Compose() + .AddExtensions("MAP file", "map") + .AddAllFiles(); + private static readonly List ArdFilter = + FileDialogFilterComposer.Compose() + .AddExtensions("ARD file", "ard") + .AddAllFiles(); + private static readonly List ModelFilter = + FileDialogFilterComposer.Compose() + .AddExtensions("glTF file (GL Transmission Format)", "gltf") + .AddExtensions("FBX file", "fbx") + .AddExtensions("DAE file (Collada) (might be unaccurate)", "dae") + .AddExtensions("OBJ file (Wavefront) (might lose some information)", "obj") + .AddAllFiles(); + + private readonly Vector4 BgUiColor = new Vector4(0.0f, 0.0f, 0.0f, 0.5f); + private readonly MonoGameImGuiBootstrap _bootstrap; + private bool _exitFlag = false; + + private readonly Dictionary _keyMapping = new Dictionary(); + private readonly MapRenderer _mapRenderer; + private string _gamePath; + private string _mapName; + private string _region; + private string _ardPath; + private string _mapPath; + private string _objPath; + private List _mapList = new List(); + private ObjEntryController _objEntryController; + + private xna.Point _previousMousePosition; + + public string Title + { + get + { + var mapName = _mapName != null ? $"{_mapName}@" : string.Empty; + return $"{mapName}{_gamePath ?? "unloaded"} | {MonoGameImGuiBootstrap.ApplicationName}"; + } + } + + private string GamePath + { + get => _gamePath; + set + { + _gamePath = value; + UpdateTitle(); + EnumerateMapList(); + + _objEntryController?.Dispose(); + _objEntryController = new ObjEntryController( + _bootstrap.GraphicsDevice, + _objPath, + Path.Combine(_gamePath, "00objentry.bin")); + _mapRenderer.ObjEntryController = _objEntryController; + + Settings.Default.GamePath = value; + Settings.Default.Save(); + + } + } + + private string MapName + { + get => _mapName; + set + { + _mapName = value; + UpdateTitle(); + + _mapRenderer.Close(); + _mapRenderer.OpenMap(Path.Combine(_mapPath, $"{_mapName}.map")); + _mapRenderer.OpenArd(Path.Combine(_ardPath, $"{_mapName}.ard")); + } + } + + private bool IsGameOpen => !string.IsNullOrEmpty(_gamePath); + private bool IsMapOpen => !string.IsNullOrEmpty(_mapName); + private bool IsOpen => IsGameOpen && IsMapOpen; + + public App(MonoGameImGuiBootstrap bootstrap, string gamePath = null) + { + _bootstrap = bootstrap; + _bootstrap.Title = Title; + _mapRenderer = new MapRenderer(bootstrap.Content, bootstrap.GraphicsDeviceManager); + AddKeyMapping(Keys.O, MenuFileOpen); + AddKeyMapping(Keys.S, MenuFileSave); + AddKeyMapping(Keys.Q, MenuFileUnload); + + if (string.IsNullOrEmpty(gamePath)) + gamePath = Settings.Default.GamePath; + + if (!string.IsNullOrEmpty(gamePath)) + OpenFolder(gamePath); + + ImGui.PushStyleColor(ImGuiCol.MenuBarBg, BgUiColor); + } + + public bool MainLoop() + { + _bootstrap.GraphicsDevice.Clear(xna.Color.CornflowerBlue); + ProcessKeyMapping(); + if (!_bootstrap.ImGuiWantTextInput) + ProcessKeyboardInput(Keyboard.GetState(), 1f / 60); + if (!_bootstrap.ImGuiWantCaptureMouse) + ProcessMouseInput(Mouse.GetState()); + + ImGui.PushStyleColor(ImGuiCol.WindowBg, BgUiColor); + ForControl(ImGui.BeginMainMenuBar, ImGui.EndMainMenuBar, MainMenu); + + MainWindow(); + + ForWindow("Tools", () => + { + if (EditorSettings.ViewCamera) + CameraWindow.Run(_mapRenderer.Camera); + if (EditorSettings.ViewLayerControl) + LayerControllerWindow.Run(_mapRenderer); + if (EditorSettings.ViewSpawnPoint) + SpawnPointWindow.Run(_mapRenderer); + if (EditorSettings.ViewMeshGroup) + MeshGroupWindow.Run(_mapRenderer.MapMeshGroups); + if (EditorSettings.ViewBobDescriptor) + BobDescriptorWindow.Run(_mapRenderer.BobDescriptors, _mapRenderer.BobMeshGroups.Count); + if (EditorSettings.ViewSpawnScriptMap) + SpawnScriptWindow.Run("map", _mapRenderer.SpawnScriptMap); + if (EditorSettings.ViewSpawnScriptBattle) + SpawnScriptWindow.Run("btl", _mapRenderer.SpawnScriptBattle); + if (EditorSettings.ViewSpawnScriptEvent) + SpawnScriptWindow.Run("evt", _mapRenderer.SpawnScriptEvent); + }); + + ImGui.PopStyleColor(); + + return _exitFlag; + } + + public void Dispose() + { + _objEntryController?.Dispose(); + } + + private void MainWindow() + { + if (!IsGameOpen) + { + ImGui.Text("Game content not loaded."); + return; + } + + ForControl(() => + { + var nextPos = ImGui.GetCursorPos(); + var ret = ImGui.Begin("MapList", + ImGuiWindowFlags.NoDecoration | + ImGuiWindowFlags.NoCollapse | + ImGuiWindowFlags.NoMove); + ImGui.SetWindowPos(nextPos); + ImGui.SetWindowSize(new Vector2(64, 0)); + return ret; + }, () => { }, () => + { + foreach (var map in _mapList) + { + if (ImGui.Selectable(map, MapName == map)) + { + MapName = map; + } + } + }); + ImGui.SameLine(); + + if (!IsMapOpen) + { + ImGui.Text("Please select a map to edit."); + return; + } + + _mapRenderer.Update(1f / 60); + _mapRenderer.Draw(); + } + + void MainMenu() + { + ForMenuBar(() => + { + ForMenu("File", () => + { + ForMenuItem("Open extracted game folder...", "CTRL+O", MenuFileOpen); + ForMenuItem("Unload current map+ard", "CTRL+Q", MenuFileUnload, IsOpen); + ForMenuItem("Import extern MAP file", MenuFileOpenMap, IsGameOpen); + ForMenuItem("Import extern ARD file", MenuFileOpenArd, IsGameOpen); + ForMenuItem("Save map+ard", "CTRL+S", MenuFileSave, IsOpen); + ForMenuItem("Save map as...", MenuFileSaveMapAs, IsOpen); + ForMenuItem("Save ard as...", MenuFileSaveArdAs, IsOpen); + ImGui.Separator(); + ForMenu("Export", () => + { + ForMenuItem("Map Collision", ExportMapCollision, _mapRenderer.ShowMapCollision.HasValue); + ForMenuItem("Camera Collision", ExportCameraCollision, _mapRenderer.ShowCameraCollision.HasValue); + ForMenuItem("Light Collision", ExportLightCollision, _mapRenderer.ShowLightCollision.HasValue); + }); + ImGui.Separator(); + ForMenu("Preferences", () => + { + ForEdit("Movement speed", () => EditorSettings.MoveSpeed, x => EditorSettings.MoveSpeed = x); + ForEdit("Movement speed (shift)", () => EditorSettings.MoveSpeedShift, x => EditorSettings.MoveSpeedShift = x); + }); + ImGui.Separator(); + ForMenuItem("Exit", MenuFileExit); + }); + ForMenu("View", () => + { + ForMenuCheck("Camera", () => EditorSettings.ViewCamera, x => EditorSettings.ViewCamera = x); + ForMenuCheck("Layer control", () => EditorSettings.ViewLayerControl, x => EditorSettings.ViewLayerControl = x); + ForMenuCheck("Spawn points", () => EditorSettings.ViewSpawnPoint, x => EditorSettings.ViewSpawnPoint = x); + ForMenuCheck("BOB descriptors", () => EditorSettings.ViewBobDescriptor, x => EditorSettings.ViewBobDescriptor = x); + ForMenuCheck("Mesh group", () => EditorSettings.ViewMeshGroup, x => EditorSettings.ViewMeshGroup = x); + ForMenuCheck("Spawn script MAP", () => EditorSettings.ViewSpawnScriptMap, x => EditorSettings.ViewSpawnScriptMap = x); + ForMenuCheck("Spawn script BTL", () => EditorSettings.ViewSpawnScriptBattle, x => EditorSettings.ViewSpawnScriptBattle = x); + ForMenuCheck("Spawn script EVT", () => EditorSettings.ViewSpawnScriptEvent, x => EditorSettings.ViewSpawnScriptEvent = x); + }); + ForMenu("Help", () => + { + ForMenuItem("About", ShowAboutDialog); + }); + }); + } + + private void MenuFileOpen() => FileDialog.OnFolder(OpenFolder); + private void MenuFileUnload() => _mapRenderer.Close(); + private void MenuFileOpenMap() => FileDialog.OnOpen(_mapRenderer.OpenMap, MapFilter); + private void MenuFileOpenArd() => FileDialog.OnOpen(_mapRenderer.OpenArd, ArdFilter); + + private void MenuFileSave() + { + _mapRenderer.SaveMap(Path.Combine(_mapPath, MapName + ".map")); + _mapRenderer.SaveArd(Path.Combine(_ardPath, MapName + ".ard")); + } + + private void MenuFileSaveMapAs() + { + var defaultName = MapName + ".map"; + FileDialog.OnSave(_mapRenderer.SaveMap, MapFilter, defaultName); + } + + private void MenuFileSaveArdAs() + { + var defaultName = MapName + ".ard"; + FileDialog.OnSave(_mapRenderer.SaveArd, ArdFilter, defaultName); + } + + private void ExportMapCollision() => FileDialog.OnSave(fileName => + { + ExportScene(fileName, _mapRenderer.MapCollision.Scene); + }, ModelFilter, $"{MapName}_map-collision.dae"); + + private void ExportCameraCollision() => FileDialog.OnSave(fileName => + { + ExportScene(fileName, _mapRenderer.CameraCollision.Scene); + }, ModelFilter, $"{MapName}_camera-collision.dae"); + + private void ExportLightCollision() => FileDialog.OnSave(fileName => + { + ExportScene(fileName, _mapRenderer.LightCollision.Scene); + }, ModelFilter, $"{MapName}_light-collision.dae"); + + private void MenuFileExit() => _exitFlag = true; + + public void OpenFolder(string gamePath) + { + try + { + if (!Directory.Exists(_ardPath = Path.Combine(gamePath, "ard")) || + !Directory.Exists(_mapPath = Path.Combine(gamePath, "map")) || + !Directory.Exists(_objPath = Path.Combine(gamePath, "obj"))) + throw new DirectoryNotFoundException( + "The specified directory must contain the full extracted copy of the game."); + + GamePath = gamePath; + } + catch (Exception ex) + { + ShowError(ex.Message); + } + } + + private void UpdateTitle() + { + _bootstrap.Title = Title; + } + + private void EnumerateMapList() + { + var mapFiles = Directory.GetFiles(_mapPath, "*.map"); + if (mapFiles.Length == 0) + { + foreach (var region in Constants.Regions) + { + var testPath = Path.Combine(_mapPath, region); + if (Directory.Exists(testPath)) + { + _mapPath = testPath; + _region = region; + break; + } + } + mapFiles = Directory.GetFiles(_mapPath, "*.map"); + } + + _mapList.Clear(); + foreach (var mapFile in mapFiles) + { + var mapName = Path.GetFileNameWithoutExtension(mapFile); + if (File.Exists(Path.Combine(_ardPath, $"{mapName}.ard"))) + _mapList.Add(mapName); + } + } + + private void AddKeyMapping(Keys key, Action action) + { + _keyMapping[key] = action; + } + + private void ProcessKeyMapping() + { + var k = Keyboard.GetState(); + if (k.IsKeyDown(Keys.LeftControl)) + { + var keys = k.GetPressedKeys(); + foreach (var key in keys) + { + if (_keyMapping.TryGetValue(key, out var action)) + action(); + } + } + } + + private void ProcessKeyboardInput(KeyboardState keyboard, float deltaTime) + { + var speed = (float)(deltaTime * EditorSettings.MoveSpeed); + var moveSpeed = speed; + if (keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift)) + moveSpeed = (float)(deltaTime * EditorSettings.MoveSpeedShift); + + var camera = _mapRenderer.Camera; + if (keyboard.IsKeyDown(Keys.W)) + camera.CameraPosition += Vector3.Multiply(camera.CameraLookAtX, moveSpeed * 5); + if (keyboard.IsKeyDown(Keys.S)) + camera.CameraPosition -= Vector3.Multiply(camera.CameraLookAtX, moveSpeed * 5); + if (keyboard.IsKeyDown(Keys.A)) + camera.CameraPosition -= Vector3.Multiply(camera.CameraLookAtY, moveSpeed * 5); + if (keyboard.IsKeyDown(Keys.D)) + camera.CameraPosition += Vector3.Multiply(camera.CameraLookAtY, moveSpeed * 5); + if (keyboard.IsKeyDown(Keys.Q)) + camera.CameraPosition += Vector3.Multiply(camera.CameraLookAtZ, moveSpeed * 5); + if (keyboard.IsKeyDown(Keys.E)) + camera.CameraPosition -= Vector3.Multiply(camera.CameraLookAtZ, moveSpeed * 5); + + if (keyboard.IsKeyDown(Keys.Up)) + camera.CameraRotationYawPitchRoll += new Vector3(0, 0, 1 * speed); + if (keyboard.IsKeyDown(Keys.Down)) + camera.CameraRotationYawPitchRoll -= new Vector3(0, 0, 1 * speed); + if (keyboard.IsKeyDown(Keys.Left)) + camera.CameraRotationYawPitchRoll += new Vector3(1 * speed, 0, 0); + if (keyboard.IsKeyDown(Keys.Right)) + camera.CameraRotationYawPitchRoll -= new Vector3(1 * speed, 0, 0); + } + + private void ProcessMouseInput(MouseState mouse) + { + const float Speed = 0.25f; + if (mouse.LeftButton == ButtonState.Pressed) + { + var camera = _mapRenderer.Camera; + var xSpeed = (_previousMousePosition.X - mouse.Position.X) * Speed; + var ySpeed = (_previousMousePosition.Y - mouse.Position.Y) * Speed; + camera.CameraRotationYawPitchRoll += new Vector3(1 * -xSpeed, 0, 0); + camera.CameraRotationYawPitchRoll += new Vector3(0, 0, 1 * ySpeed); + } + + _previousMousePosition = mouse.Position; + } + + private static void ExportScene(string fileName, Scene scene) + { + using var ctx = new AssimpContext(); + var extension = Path.GetExtension(fileName).ToLower(); + var exportFormat = ctx.GetSupportedExportFormats(); + foreach (var format in exportFormat) + { + if ($".{format.FileExtension}" == extension) + { + var material = new Material(); + material.Clear(); + + scene.Materials.Add(material); + ctx.ExportFile(scene, fileName, format.FormatId); + return; + } + } + + ShowError($"Unable to export with '{extension}' extension."); + } + + public static void ShowError(string message, string title = "Error") => + MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Error); + + private void ShowAboutDialog() => + MessageBox.Show("OpenKH is amazing."); + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/EditorSettings.cs b/OpenKh.Tools.Kh2MapStudio/EditorSettings.cs index b387d331a..18b71cf18 100644 --- a/OpenKh.Tools.Kh2MapStudio/EditorSettings.cs +++ b/OpenKh.Tools.Kh2MapStudio/EditorSettings.cs @@ -1,105 +1,105 @@ -namespace OpenKh.Tools.Kh2MapStudio -{ - static class EditorSettings - { - public static float MoveSpeed - { - get => Settings.Default.MoveSpeed; - set - { - Settings.Default.MoveSpeed = value; - Settings.Default.Save(); - } - } - - public static float MoveSpeedShift - { - get => Settings.Default.MoveSpeedShift; - set - { - Settings.Default.MoveSpeedShift = value; - Settings.Default.Save(); - } - } - - public static bool ViewCamera - { - get => Settings.Default.ViewCamera; - set - { - Settings.Default.ViewCamera = value; - Settings.Default.Save(); - } - } - - public static bool ViewLayerControl - { - get => Settings.Default.ViewLayerControl; - set - { - Settings.Default.ViewLayerControl = value; - Settings.Default.Save(); - } - } - - public static bool ViewSpawnPoint - { - get => Settings.Default.ViewSpawnPoint; - set - { - Settings.Default.ViewSpawnPoint = value; - Settings.Default.Save(); - } - } - - public static bool ViewMeshGroup - { - get => Settings.Default.ViewMeshGroup; - set - { - Settings.Default.ViewMeshGroup = value; - Settings.Default.Save(); - } - } - - public static bool ViewBobDescriptor - { - get => Settings.Default.ViewBobDescriptors; - set - { - Settings.Default.ViewBobDescriptors = value; - Settings.Default.Save(); - } - } - - public static bool ViewSpawnScriptMap - { - get => Settings.Default.ViewSpawnScriptMap; - set - { - Settings.Default.ViewSpawnScriptMap = value; - Settings.Default.Save(); - } - } - - public static bool ViewSpawnScriptBattle - { - get => Settings.Default.ViewSpawnScriptBattle; - set - { - Settings.Default.ViewSpawnScriptBattle = value; - Settings.Default.Save(); - } - } - - public static bool ViewSpawnScriptEvent - { - get => Settings.Default.ViewSpawnScriptEvent; - set - { - Settings.Default.ViewSpawnScriptEvent = value; - Settings.Default.Save(); - } - } - } -} +namespace OpenKh.Tools.Kh2MapStudio +{ + static class EditorSettings + { + public static float MoveSpeed + { + get => Settings.Default.MoveSpeed; + set + { + Settings.Default.MoveSpeed = value; + Settings.Default.Save(); + } + } + + public static float MoveSpeedShift + { + get => Settings.Default.MoveSpeedShift; + set + { + Settings.Default.MoveSpeedShift = value; + Settings.Default.Save(); + } + } + + public static bool ViewCamera + { + get => Settings.Default.ViewCamera; + set + { + Settings.Default.ViewCamera = value; + Settings.Default.Save(); + } + } + + public static bool ViewLayerControl + { + get => Settings.Default.ViewLayerControl; + set + { + Settings.Default.ViewLayerControl = value; + Settings.Default.Save(); + } + } + + public static bool ViewSpawnPoint + { + get => Settings.Default.ViewSpawnPoint; + set + { + Settings.Default.ViewSpawnPoint = value; + Settings.Default.Save(); + } + } + + public static bool ViewMeshGroup + { + get => Settings.Default.ViewMeshGroup; + set + { + Settings.Default.ViewMeshGroup = value; + Settings.Default.Save(); + } + } + + public static bool ViewBobDescriptor + { + get => Settings.Default.ViewBobDescriptors; + set + { + Settings.Default.ViewBobDescriptors = value; + Settings.Default.Save(); + } + } + + public static bool ViewSpawnScriptMap + { + get => Settings.Default.ViewSpawnScriptMap; + set + { + Settings.Default.ViewSpawnScriptMap = value; + Settings.Default.Save(); + } + } + + public static bool ViewSpawnScriptBattle + { + get => Settings.Default.ViewSpawnScriptBattle; + set + { + Settings.Default.ViewSpawnScriptBattle = value; + Settings.Default.Save(); + } + } + + public static bool ViewSpawnScriptEvent + { + get => Settings.Default.ViewSpawnScriptEvent; + set + { + Settings.Default.ViewSpawnScriptEvent = value; + Settings.Default.Save(); + } + } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/ImGuiExHelpers.cs b/OpenKh.Tools.Kh2MapStudio/ImGuiExHelpers.cs index 1379625fc..e4a1b37b9 100644 --- a/OpenKh.Tools.Kh2MapStudio/ImGuiExHelpers.cs +++ b/OpenKh.Tools.Kh2MapStudio/ImGuiExHelpers.cs @@ -1,26 +1,26 @@ -using OpenKh.Tools.Common.CustomImGui; -using System; -using System.Numerics; -using xna = Microsoft.Xna.Framework; - -namespace OpenKh.Tools.Kh2MapStudio -{ - static class ImGuiExHelpers - { - public static void ForEdit2(string name, Func getter, Action setter, float speed = 1f) - { - var actualValue = getter(); - ImGuiEx.ForEdit2(name, - () => new Vector2(actualValue.X, actualValue.Y), - x => setter(new xna.Vector2(x.X, x.Y)), speed); - } - - public static void ForEdit3(string name, Func getter, Action setter, float speed = 1f) - { - var actualValue = getter(); - ImGuiEx.ForEdit3(name, - () => new Vector3(actualValue.X, actualValue.Y, actualValue.Z), - x => setter(new xna.Vector3(x.X, x.Y, x.Z)), speed); - } - } -} +using OpenKh.Tools.Common.CustomImGui; +using System; +using System.Numerics; +using xna = Microsoft.Xna.Framework; + +namespace OpenKh.Tools.Kh2MapStudio +{ + static class ImGuiExHelpers + { + public static void ForEdit2(string name, Func getter, Action setter, float speed = 1f) + { + var actualValue = getter(); + ImGuiEx.ForEdit2(name, + () => new Vector2(actualValue.X, actualValue.Y), + x => setter(new xna.Vector2(x.X, x.Y)), speed); + } + + public static void ForEdit3(string name, Func getter, Action setter, float speed = 1f) + { + var actualValue = getter(); + ImGuiEx.ForEdit3(name, + () => new Vector3(actualValue.X, actualValue.Y, actualValue.Z), + x => setter(new xna.Vector3(x.X, x.Y, x.Z)), speed); + } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Interfaces/ILayerController.cs b/OpenKh.Tools.Kh2MapStudio/Interfaces/ILayerController.cs index 8ca2339ea..9d0eb89b1 100644 --- a/OpenKh.Tools.Kh2MapStudio/Interfaces/ILayerController.cs +++ b/OpenKh.Tools.Kh2MapStudio/Interfaces/ILayerController.cs @@ -1,13 +1,13 @@ -namespace OpenKh.Tools.Kh2MapStudio.Interfaces -{ - interface ILayerController - { - bool? ShowMap { get; set; } - bool? ShowSk0 { get; set; } - bool? ShowSk1 { get; set; } - bool? ShowBobs { get; set; } - bool? ShowMapCollision { get; set; } - bool? ShowCameraCollision { get; set; } - bool? ShowLightCollision { get; set; } - } -} +namespace OpenKh.Tools.Kh2MapStudio.Interfaces +{ + interface ILayerController + { + bool? ShowMap { get; set; } + bool? ShowSk0 { get; set; } + bool? ShowSk1 { get; set; } + bool? ShowBobs { get; set; } + bool? ShowMapCollision { get; set; } + bool? ShowCameraCollision { get; set; } + bool? ShowLightCollision { get; set; } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Interfaces/IObjEntryController.cs b/OpenKh.Tools.Kh2MapStudio/Interfaces/IObjEntryController.cs index 403ad9e19..a10a21cdb 100644 --- a/OpenKh.Tools.Kh2MapStudio/Interfaces/IObjEntryController.cs +++ b/OpenKh.Tools.Kh2MapStudio/Interfaces/IObjEntryController.cs @@ -1,16 +1,16 @@ -using OpenKh.Engine.MonoGame; -using OpenKh.Kh2; -using System.Collections.Generic; - -namespace OpenKh.Tools.Kh2MapStudio.Interfaces -{ - interface IObjEntryController - { - IEnumerable ObjectEntries { get; } - - MeshGroup this[int objId] { get; } - MeshGroup this[string objName] { get; } - - string GetName(int objectId); - } -} +using OpenKh.Engine.MonoGame; +using OpenKh.Kh2; +using System.Collections.Generic; + +namespace OpenKh.Tools.Kh2MapStudio.Interfaces +{ + interface IObjEntryController + { + IEnumerable ObjectEntries { get; } + + MeshGroup this[int objId] { get; } + MeshGroup this[string objName] { get; } + + string GetName(int objectId); + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Interfaces/ISpawnPointController.cs b/OpenKh.Tools.Kh2MapStudio/Interfaces/ISpawnPointController.cs index 4019be4a1..e76f93612 100644 --- a/OpenKh.Tools.Kh2MapStudio/Interfaces/ISpawnPointController.cs +++ b/OpenKh.Tools.Kh2MapStudio/Interfaces/ISpawnPointController.cs @@ -1,12 +1,12 @@ -using OpenKh.Tools.Kh2MapStudio.Models; -using System.Collections.Generic; - -namespace OpenKh.Tools.Kh2MapStudio.Interfaces -{ - interface ISpawnPointController - { - List SpawnPoints { get; } - SpawnPointModel CurrentSpawnPoint { get; } - string SelectSpawnPoint { get; set; } - } -} +using OpenKh.Tools.Kh2MapStudio.Models; +using System.Collections.Generic; + +namespace OpenKh.Tools.Kh2MapStudio.Interfaces +{ + interface ISpawnPointController + { + List SpawnPoints { get; } + SpawnPointModel CurrentSpawnPoint { get; } + string SelectSpawnPoint { get; set; } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/MapRenderer.cs b/OpenKh.Tools.Kh2MapStudio/MapRenderer.cs index 7c09e9877..f23472edb 100644 --- a/OpenKh.Tools.Kh2MapStudio/MapRenderer.cs +++ b/OpenKh.Tools.Kh2MapStudio/MapRenderer.cs @@ -1,397 +1,397 @@ -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Common; -using OpenKh.Engine; -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Parsers; -using OpenKh.Kh2; -using OpenKh.Kh2.Ard; -using OpenKh.Kh2.Extensions; -using OpenKh.Kh2.Models; -using OpenKh.Tools.Kh2MapStudio.Interfaces; -using OpenKh.Tools.Kh2MapStudio.Models; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Numerics; -using xna = Microsoft.Xna.Framework; - -namespace OpenKh.Tools.Kh2MapStudio -{ - class MapRenderer : ILayerController, ISpawnPointController - { - private readonly static BlendState DefaultBlendState = new BlendState() - { - ColorSourceBlend = Blend.SourceAlpha, - AlphaSourceBlend = Blend.SourceAlpha, - ColorDestinationBlend = Blend.InverseSourceAlpha, - AlphaDestinationBlend = Blend.InverseSourceAlpha, - ColorBlendFunction = BlendFunction.Add, - AlphaBlendFunction = BlendFunction.Add, - BlendFactor = xna.Color.White, - MultiSampleMask = int.MaxValue, - IndependentBlendEnable = false - }; - - private readonly xna.GraphicsDeviceManager _graphicsManager; - private readonly GraphicsDevice _graphics; - private readonly KingdomShader _shader; - private readonly Texture2D _whiteTexture; - private bool _showBobs = true; - - public Camera Camera { get; } - - public IObjEntryController ObjEntryController { get; set; } - - public bool? ShowMap - { - get => MapMeshGroups.FirstOrDefault(x => x.Name == "MAP")?.IsVisible; - set - { - var mesh = MapMeshGroups.FirstOrDefault(x => x.Name == "MAP"); - if (mesh != null) - mesh.IsVisible = value ?? true; - } - } - - public bool? ShowSk0 - { - get => MapMeshGroups.FirstOrDefault(x => x.Name == "SK0")?.IsVisible; - set - { - var mesh = MapMeshGroups.FirstOrDefault(x => x.Name == "SK0"); - if (mesh != null) - mesh.IsVisible = value ?? true; - } - } - - public bool? ShowSk1 - { - get => MapMeshGroups.FirstOrDefault(x => x.Name == "SK1")?.IsVisible; - set - { - var mesh = MapMeshGroups.FirstOrDefault(x => x.Name == "SK1"); - if (mesh != null) - mesh.IsVisible = value ?? true; - } - } - - public bool? ShowBobs - { - get => BobDescriptors.Any() ? (bool?)_showBobs : null; - set => _showBobs = value ?? true; - } - - public bool? ShowMapCollision - { - get => MapCollision != null ? (bool?)MapCollision.IsVisible : null; - set => MapCollision.IsVisible = value ?? false; - } - - public bool? ShowCameraCollision - { - get => CameraCollision != null ? (bool?)CameraCollision.IsVisible : null; - set => CameraCollision.IsVisible = value ?? false; - } - - public bool? ShowLightCollision - { - get => LightCollision != null ? (bool?)LightCollision.IsVisible : null; - set => LightCollision.IsVisible = value ?? false; - } - - - internal List MapBarEntries { get; private set; } - internal List ArdBarEntries { get; private set; } - internal List MapMeshGroups { get; } - internal List BobMeshGroups { get; } - internal List BobDescriptors { get; } - internal CollisionModel MapCollision { get; set; } - internal CollisionModel CameraCollision { get; set; } - internal CollisionModel LightCollision { get; set; } - - public List SpawnPoints { get; private set; } - public SpawnPointModel CurrentSpawnPoint { get; private set; } - public string SelectSpawnPoint - { - get => CurrentSpawnPoint?.Name ?? string.Empty; - set => CurrentSpawnPoint = SpawnPoints.FirstOrDefault(x => x.Name == value); - } - - public SpawnScriptModel SpawnScriptMap { get; private set; } - public SpawnScriptModel SpawnScriptBattle { get; private set; } - public SpawnScriptModel SpawnScriptEvent { get; private set; } - - public MapRenderer(ContentManager content, xna.GraphicsDeviceManager graphics) - { - _graphicsManager = graphics; - _graphics = graphics.GraphicsDevice; - _shader = new KingdomShader(content); - MapMeshGroups = new List(); - BobMeshGroups = new List(); - BobDescriptors = new List(); - Camera = new Camera() - { - CameraPosition = new Vector3(0, 100, 200), - CameraRotationYawPitchRoll = new Vector3(90, 0, 10), - }; - - _whiteTexture = new Texture2D(_graphics, 2, 2); - _whiteTexture.SetData(Enumerable.Range(0, 2 * 2 * sizeof(int)).Select(_ => (byte)0xff).ToArray()); - } - - public void OpenMap(string fileName) - { - Close(); - MapBarEntries = File.OpenRead(fileName).Using(Bar.Read); - LoadMapComponent(MapBarEntries, "SK0"); - LoadMapComponent(MapBarEntries, "SK1"); - LoadMapComponent(MapBarEntries, "MAP"); - - var bobDescEntry = MapBarEntries - .Where(x => x.Name == "out" && x.Type == Bar.EntryType.BgObjPlacement) - .FirstOrDefault(); - if (bobDescEntry != null) - BobDescriptors.AddRange(BobDescriptor.Read(bobDescEntry.Stream)); - - var bobModel = MapBarEntries.Where(x => x.Name == "BOB" && x.Type == Bar.EntryType.Model).ToArray(); - var bobTexture = MapBarEntries.Where(x => x.Name == "BOB" && x.Type == Bar.EntryType.ModelTexture).ToArray(); - var bobCount = Math.Min(bobModel.Length, bobTexture.Length); - for (var i = 0; i < bobCount; i++) - { - var model = Mdlx.Read(bobModel[i].Stream); - var textures = ModelTexture.Read(bobTexture[i].Stream).Images; - BobMeshGroups.Add(new MeshGroupModel(_graphics, "BOB", model, textures, i)); - } - - var mapCollisionEntry = MapBarEntries - .Where(x => x.Name.StartsWith("ID_") && x.Type == Bar.EntryType.CollisionOctalTree) - .FirstOrDefault(); - if (mapCollisionEntry != null) - MapCollision = new CollisionModel(Coct.Read(mapCollisionEntry.Stream)); - - var cameraCollisionEntry = MapBarEntries - .Where(x => x.Name.StartsWith("CH_") && x.Type == Bar.EntryType.CameraOctalTree) - .FirstOrDefault(); - if (cameraCollisionEntry != null) - CameraCollision = new CollisionModel(Coct.Read(cameraCollisionEntry.Stream)); - - var lightCollisionEntry = MapBarEntries - .Where(x => x.Name == "COL_" && x.Type == Bar.EntryType.ColorOctalTree) - .FirstOrDefault(); - if (lightCollisionEntry != null) - LightCollision = new CollisionModel(Coct.Read(lightCollisionEntry.Stream)); - } - - public void SaveMap(string fileName) - { - var memStream = new MemoryStream(); - BobDescriptor.Write(memStream, BobDescriptors); - - MapBarEntries.AddOrReplace(new Bar.Entry - { - Name = "out", - Type = Bar.EntryType.BgObjPlacement, - Stream = memStream - }); - - File.Create(fileName).Using(stream => Bar.Write(stream, MapBarEntries)); - } - - public void OpenArd(string fileName) - { - ArdBarEntries = File.OpenRead(fileName).Using(Bar.Read); - SpawnPoints = ArdBarEntries - .Where(x => x.Type == Bar.EntryType.AreaDataSpawn && x.Stream.Length > 0) - .Select(x => - new SpawnPointModel(ObjEntryController, x.Name, SpawnPoint.Read(x.Stream.SetPosition(0)))) - .ToList(); - SelectSpawnPoint = "m_00"; - - SpawnScriptMap = SpawnScriptModel.Create(ArdBarEntries, "map"); - SpawnScriptBattle = SpawnScriptModel.Create(ArdBarEntries, "btl"); - SpawnScriptEvent = SpawnScriptModel.Create(ArdBarEntries, "evt"); - } - - public void SaveArd(string fileName) - { - foreach (var spawnPointModel in SpawnPoints) - { - var memStream = new MemoryStream(); - SpawnPoint.Write(memStream, spawnPointModel.SpawnPoints); - - ArdBarEntries.AddOrReplace(new Bar.Entry - { - Name = spawnPointModel.Name, - Type = Bar.EntryType.AreaDataSpawn, - Stream = memStream - }); - } - - SpawnScriptMap?.SaveToBar(ArdBarEntries); - SpawnScriptBattle?.SaveToBar(ArdBarEntries); - SpawnScriptEvent?.SaveToBar(ArdBarEntries); - - File.Create(fileName).Using(stream => Bar.Write(stream, ArdBarEntries)); - } - - public void Close() - { - foreach (var meshGroup in MapMeshGroups) - meshGroup?.Dispose(); - MapMeshGroups.Clear(); - - foreach (var meshGroup in BobMeshGroups) - meshGroup?.Dispose(); - BobMeshGroups.Clear(); - BobDescriptors.Clear(); - - MapCollision?.Dispose(); - CameraCollision?.Dispose(); - LightCollision?.Dispose(); - } - - public void Update(float deltaTime) - { - - } - - public void Draw() - { - var viewport = _graphics.Viewport; - Camera.AspectRatio = viewport.Width / (float)viewport.Height; - - _graphics.RasterizerState = new RasterizerState() - { - CullMode = CullMode.CullClockwiseFace - }; - _graphics.DepthStencilState = new DepthStencilState(); - _graphics.BlendState = DefaultBlendState; - - _shader.Pass(pass => - { - _shader.SetProjectionView(Camera.Projection); - _shader.SetWorldView(Camera.World); - _shader.SetModelViewIdentity(); - pass.Apply(); - - foreach (var mesh in MapMeshGroups.Where(x => x.IsVisible)) - RenderMeshNew(pass, mesh.MeshGroup, true); - foreach (var mesh in MapMeshGroups.Where(x => x.IsVisible)) - RenderMeshNew(pass, mesh.MeshGroup, false); - - _shader.SetRenderTexture(pass, _whiteTexture); - MapCollision?.Draw(_graphics); - CameraCollision.Draw(_graphics); - LightCollision?.Draw(_graphics); - - if (_showBobs) - { - foreach (var entity in BobDescriptors ?? new List()) - { - if (entity.BobIndex < 0 || entity.BobIndex >= BobMeshGroups.Count) - continue; - - _shader.SetModelView(Matrix4x4.CreateRotationX(entity.RotationX) * - Matrix4x4.CreateRotationY(entity.RotationY) * - Matrix4x4.CreateRotationZ(entity.RotationZ) * - Matrix4x4.CreateScale(entity.ScalingX, entity.ScalingY, entity.ScalingZ) * - Matrix4x4.CreateTranslation(entity.PositionX, -entity.PositionY, -entity.PositionZ)); - RenderMeshNew(pass, BobMeshGroups[entity.BobIndex].MeshGroup, true); - } - } - - if (CurrentSpawnPoint != null) - { - foreach (var spawnPoint in CurrentSpawnPoint.SpawnPoints) - { - foreach (var entity in spawnPoint.Entities) - { - _shader.SetModelView(Matrix4x4.CreateRotationX(entity.RotationX) * - Matrix4x4.CreateRotationY(entity.RotationY) * - Matrix4x4.CreateRotationZ(entity.RotationZ) * - Matrix4x4.CreateTranslation(entity.PositionX, -entity.PositionY, -entity.PositionZ)); - RenderMeshNew(pass, CurrentSpawnPoint.ObjEntryCtrl[entity.ObjectId], true); - } - - _graphics.RasterizerState = new RasterizerState() - { - CullMode = CullMode.None - }; - _shader.SetRenderTexture(pass, _whiteTexture); - foreach (var item in spawnPoint.EventActivators) - { - _shader.SetModelView(Matrix4x4.CreateRotationX(item.RotationX) * - Matrix4x4.CreateRotationY(item.RotationY) * - Matrix4x4.CreateRotationZ(item.RotationZ) * - Matrix4x4.CreateScale(item.ScaleX, item.ScaleY, item.ScaleZ) * - Matrix4x4.CreateTranslation(item.PositionX, -item.PositionY, -item.PositionZ)); - pass.Apply(); - - var color = new xna.Color(1f, 0f, 0f, .5f); - var vertices = new PositionColoredTextured[] - { - new PositionColoredTextured(-1, -1, -1, 0, 0, 1f, 0f, 0f, 1f), - new PositionColoredTextured(+1, -1, -1, 0, 0, 1f, 0f, 0f, 1f), - new PositionColoredTextured(+1, +1, -1, 0, 0, 1f, 0f, 0f, 1f), - new PositionColoredTextured(-1, +1, -1, 0, 0, 1f, 0f, 0f, 1f), - new PositionColoredTextured(-1, -1, +1, 0, 0, 1f, 0f, 0f, 1f), - new PositionColoredTextured(+1, -1, +1, 0, 0, 1f, 0f, 0f, 1f), - new PositionColoredTextured(+1, +1, +1, 0, 0, 1f, 0f, 0f, 1f), - new PositionColoredTextured(-1, +1, +1, 0, 0, 1f, 0f, 0f, 1f), - }; - var indices = new int[] - { - 0, 1, 3, 3, 1, 2, - 1, 5, 2, 2, 5, 6, - 5, 4, 6, 6, 4, 7, - 4, 0, 7, 7, 0, 3, - 3, 2, 7, 7, 2, 6, - 4, 5, 0, 0, 5, 1 - }; - _graphics.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, 8, indices, 0, 12, MeshLoader.PositionColoredTexturedVertexDeclaration); - } - } - } - }); - } - - private void RenderMeshNew(EffectPass pass, MeshGroup mesh, bool passRenderOpaque) - { - foreach (var meshDescriptor in mesh.MeshDescriptors) - { - if (meshDescriptor.IsOpaque != passRenderOpaque) - continue; - if (meshDescriptor.Indices.Length == 0) - continue; - - var textureIndex = meshDescriptor.TextureIndex & 0xffff; - if (textureIndex < mesh.Textures.Length) - _shader.SetRenderTexture(pass, mesh.Textures[textureIndex]); - - _graphics.DrawUserIndexedPrimitives( - PrimitiveType.TriangleList, - meshDescriptor.Vertices, - 0, - meshDescriptor.Vertices.Length, - meshDescriptor.Indices, - 0, - meshDescriptor.Indices.Length / 3, - MeshLoader.PositionColoredTexturedVertexDeclaration); - } - } - - private void LoadMapComponent(List entries, string componentName) - { - var modelEntry = entries.FirstOrDefault(x => x.Name == componentName && x.Type == Bar.EntryType.Model); - var textureEntry = entries.FirstOrDefault(x => x.Name == componentName && x.Type == Bar.EntryType.ModelTexture); - if (modelEntry == null || textureEntry == null) - return; - - var model = Mdlx.Read(modelEntry.Stream); - var textures = ModelTexture.Read(textureEntry.Stream).Images; - MapMeshGroups.Add(new MeshGroupModel(_graphics, componentName, model, textures, 0)); - } - } -} +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Common; +using OpenKh.Engine; +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Parsers; +using OpenKh.Kh2; +using OpenKh.Kh2.Ard; +using OpenKh.Kh2.Extensions; +using OpenKh.Kh2.Models; +using OpenKh.Tools.Kh2MapStudio.Interfaces; +using OpenKh.Tools.Kh2MapStudio.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Numerics; +using xna = Microsoft.Xna.Framework; + +namespace OpenKh.Tools.Kh2MapStudio +{ + class MapRenderer : ILayerController, ISpawnPointController + { + private readonly static BlendState DefaultBlendState = new BlendState() + { + ColorSourceBlend = Blend.SourceAlpha, + AlphaSourceBlend = Blend.SourceAlpha, + ColorDestinationBlend = Blend.InverseSourceAlpha, + AlphaDestinationBlend = Blend.InverseSourceAlpha, + ColorBlendFunction = BlendFunction.Add, + AlphaBlendFunction = BlendFunction.Add, + BlendFactor = xna.Color.White, + MultiSampleMask = int.MaxValue, + IndependentBlendEnable = false + }; + + private readonly xna.GraphicsDeviceManager _graphicsManager; + private readonly GraphicsDevice _graphics; + private readonly KingdomShader _shader; + private readonly Texture2D _whiteTexture; + private bool _showBobs = true; + + public Camera Camera { get; } + + public IObjEntryController ObjEntryController { get; set; } + + public bool? ShowMap + { + get => MapMeshGroups.FirstOrDefault(x => x.Name == "MAP")?.IsVisible; + set + { + var mesh = MapMeshGroups.FirstOrDefault(x => x.Name == "MAP"); + if (mesh != null) + mesh.IsVisible = value ?? true; + } + } + + public bool? ShowSk0 + { + get => MapMeshGroups.FirstOrDefault(x => x.Name == "SK0")?.IsVisible; + set + { + var mesh = MapMeshGroups.FirstOrDefault(x => x.Name == "SK0"); + if (mesh != null) + mesh.IsVisible = value ?? true; + } + } + + public bool? ShowSk1 + { + get => MapMeshGroups.FirstOrDefault(x => x.Name == "SK1")?.IsVisible; + set + { + var mesh = MapMeshGroups.FirstOrDefault(x => x.Name == "SK1"); + if (mesh != null) + mesh.IsVisible = value ?? true; + } + } + + public bool? ShowBobs + { + get => BobDescriptors.Any() ? (bool?)_showBobs : null; + set => _showBobs = value ?? true; + } + + public bool? ShowMapCollision + { + get => MapCollision != null ? (bool?)MapCollision.IsVisible : null; + set => MapCollision.IsVisible = value ?? false; + } + + public bool? ShowCameraCollision + { + get => CameraCollision != null ? (bool?)CameraCollision.IsVisible : null; + set => CameraCollision.IsVisible = value ?? false; + } + + public bool? ShowLightCollision + { + get => LightCollision != null ? (bool?)LightCollision.IsVisible : null; + set => LightCollision.IsVisible = value ?? false; + } + + + internal List MapBarEntries { get; private set; } + internal List ArdBarEntries { get; private set; } + internal List MapMeshGroups { get; } + internal List BobMeshGroups { get; } + internal List BobDescriptors { get; } + internal CollisionModel MapCollision { get; set; } + internal CollisionModel CameraCollision { get; set; } + internal CollisionModel LightCollision { get; set; } + + public List SpawnPoints { get; private set; } + public SpawnPointModel CurrentSpawnPoint { get; private set; } + public string SelectSpawnPoint + { + get => CurrentSpawnPoint?.Name ?? string.Empty; + set => CurrentSpawnPoint = SpawnPoints.FirstOrDefault(x => x.Name == value); + } + + public SpawnScriptModel SpawnScriptMap { get; private set; } + public SpawnScriptModel SpawnScriptBattle { get; private set; } + public SpawnScriptModel SpawnScriptEvent { get; private set; } + + public MapRenderer(ContentManager content, xna.GraphicsDeviceManager graphics) + { + _graphicsManager = graphics; + _graphics = graphics.GraphicsDevice; + _shader = new KingdomShader(content); + MapMeshGroups = new List(); + BobMeshGroups = new List(); + BobDescriptors = new List(); + Camera = new Camera() + { + CameraPosition = new Vector3(0, 100, 200), + CameraRotationYawPitchRoll = new Vector3(90, 0, 10), + }; + + _whiteTexture = new Texture2D(_graphics, 2, 2); + _whiteTexture.SetData(Enumerable.Range(0, 2 * 2 * sizeof(int)).Select(_ => (byte)0xff).ToArray()); + } + + public void OpenMap(string fileName) + { + Close(); + MapBarEntries = File.OpenRead(fileName).Using(Bar.Read); + LoadMapComponent(MapBarEntries, "SK0"); + LoadMapComponent(MapBarEntries, "SK1"); + LoadMapComponent(MapBarEntries, "MAP"); + + var bobDescEntry = MapBarEntries + .Where(x => x.Name == "out" && x.Type == Bar.EntryType.BgObjPlacement) + .FirstOrDefault(); + if (bobDescEntry != null) + BobDescriptors.AddRange(BobDescriptor.Read(bobDescEntry.Stream)); + + var bobModel = MapBarEntries.Where(x => x.Name == "BOB" && x.Type == Bar.EntryType.Model).ToArray(); + var bobTexture = MapBarEntries.Where(x => x.Name == "BOB" && x.Type == Bar.EntryType.ModelTexture).ToArray(); + var bobCount = Math.Min(bobModel.Length, bobTexture.Length); + for (var i = 0; i < bobCount; i++) + { + var model = Mdlx.Read(bobModel[i].Stream); + var textures = ModelTexture.Read(bobTexture[i].Stream).Images; + BobMeshGroups.Add(new MeshGroupModel(_graphics, "BOB", model, textures, i)); + } + + var mapCollisionEntry = MapBarEntries + .Where(x => x.Name.StartsWith("ID_") && x.Type == Bar.EntryType.CollisionOctalTree) + .FirstOrDefault(); + if (mapCollisionEntry != null) + MapCollision = new CollisionModel(Coct.Read(mapCollisionEntry.Stream)); + + var cameraCollisionEntry = MapBarEntries + .Where(x => x.Name.StartsWith("CH_") && x.Type == Bar.EntryType.CameraOctalTree) + .FirstOrDefault(); + if (cameraCollisionEntry != null) + CameraCollision = new CollisionModel(Coct.Read(cameraCollisionEntry.Stream)); + + var lightCollisionEntry = MapBarEntries + .Where(x => x.Name == "COL_" && x.Type == Bar.EntryType.ColorOctalTree) + .FirstOrDefault(); + if (lightCollisionEntry != null) + LightCollision = new CollisionModel(Coct.Read(lightCollisionEntry.Stream)); + } + + public void SaveMap(string fileName) + { + var memStream = new MemoryStream(); + BobDescriptor.Write(memStream, BobDescriptors); + + MapBarEntries.AddOrReplace(new Bar.Entry + { + Name = "out", + Type = Bar.EntryType.BgObjPlacement, + Stream = memStream + }); + + File.Create(fileName).Using(stream => Bar.Write(stream, MapBarEntries)); + } + + public void OpenArd(string fileName) + { + ArdBarEntries = File.OpenRead(fileName).Using(Bar.Read); + SpawnPoints = ArdBarEntries + .Where(x => x.Type == Bar.EntryType.AreaDataSpawn && x.Stream.Length > 0) + .Select(x => + new SpawnPointModel(ObjEntryController, x.Name, SpawnPoint.Read(x.Stream.SetPosition(0)))) + .ToList(); + SelectSpawnPoint = "m_00"; + + SpawnScriptMap = SpawnScriptModel.Create(ArdBarEntries, "map"); + SpawnScriptBattle = SpawnScriptModel.Create(ArdBarEntries, "btl"); + SpawnScriptEvent = SpawnScriptModel.Create(ArdBarEntries, "evt"); + } + + public void SaveArd(string fileName) + { + foreach (var spawnPointModel in SpawnPoints) + { + var memStream = new MemoryStream(); + SpawnPoint.Write(memStream, spawnPointModel.SpawnPoints); + + ArdBarEntries.AddOrReplace(new Bar.Entry + { + Name = spawnPointModel.Name, + Type = Bar.EntryType.AreaDataSpawn, + Stream = memStream + }); + } + + SpawnScriptMap?.SaveToBar(ArdBarEntries); + SpawnScriptBattle?.SaveToBar(ArdBarEntries); + SpawnScriptEvent?.SaveToBar(ArdBarEntries); + + File.Create(fileName).Using(stream => Bar.Write(stream, ArdBarEntries)); + } + + public void Close() + { + foreach (var meshGroup in MapMeshGroups) + meshGroup?.Dispose(); + MapMeshGroups.Clear(); + + foreach (var meshGroup in BobMeshGroups) + meshGroup?.Dispose(); + BobMeshGroups.Clear(); + BobDescriptors.Clear(); + + MapCollision?.Dispose(); + CameraCollision?.Dispose(); + LightCollision?.Dispose(); + } + + public void Update(float deltaTime) + { + + } + + public void Draw() + { + var viewport = _graphics.Viewport; + Camera.AspectRatio = viewport.Width / (float)viewport.Height; + + _graphics.RasterizerState = new RasterizerState() + { + CullMode = CullMode.CullClockwiseFace + }; + _graphics.DepthStencilState = new DepthStencilState(); + _graphics.BlendState = DefaultBlendState; + + _shader.Pass(pass => + { + _shader.SetProjectionView(Camera.Projection); + _shader.SetWorldView(Camera.World); + _shader.SetModelViewIdentity(); + pass.Apply(); + + foreach (var mesh in MapMeshGroups.Where(x => x.IsVisible)) + RenderMeshNew(pass, mesh.MeshGroup, true); + foreach (var mesh in MapMeshGroups.Where(x => x.IsVisible)) + RenderMeshNew(pass, mesh.MeshGroup, false); + + _shader.SetRenderTexture(pass, _whiteTexture); + MapCollision?.Draw(_graphics); + CameraCollision.Draw(_graphics); + LightCollision?.Draw(_graphics); + + if (_showBobs) + { + foreach (var entity in BobDescriptors ?? new List()) + { + if (entity.BobIndex < 0 || entity.BobIndex >= BobMeshGroups.Count) + continue; + + _shader.SetModelView(Matrix4x4.CreateRotationX(entity.RotationX) * + Matrix4x4.CreateRotationY(entity.RotationY) * + Matrix4x4.CreateRotationZ(entity.RotationZ) * + Matrix4x4.CreateScale(entity.ScalingX, entity.ScalingY, entity.ScalingZ) * + Matrix4x4.CreateTranslation(entity.PositionX, -entity.PositionY, -entity.PositionZ)); + RenderMeshNew(pass, BobMeshGroups[entity.BobIndex].MeshGroup, true); + } + } + + if (CurrentSpawnPoint != null) + { + foreach (var spawnPoint in CurrentSpawnPoint.SpawnPoints) + { + foreach (var entity in spawnPoint.Entities) + { + _shader.SetModelView(Matrix4x4.CreateRotationX(entity.RotationX) * + Matrix4x4.CreateRotationY(entity.RotationY) * + Matrix4x4.CreateRotationZ(entity.RotationZ) * + Matrix4x4.CreateTranslation(entity.PositionX, -entity.PositionY, -entity.PositionZ)); + RenderMeshNew(pass, CurrentSpawnPoint.ObjEntryCtrl[entity.ObjectId], true); + } + + _graphics.RasterizerState = new RasterizerState() + { + CullMode = CullMode.None + }; + _shader.SetRenderTexture(pass, _whiteTexture); + foreach (var item in spawnPoint.EventActivators) + { + _shader.SetModelView(Matrix4x4.CreateRotationX(item.RotationX) * + Matrix4x4.CreateRotationY(item.RotationY) * + Matrix4x4.CreateRotationZ(item.RotationZ) * + Matrix4x4.CreateScale(item.ScaleX, item.ScaleY, item.ScaleZ) * + Matrix4x4.CreateTranslation(item.PositionX, -item.PositionY, -item.PositionZ)); + pass.Apply(); + + var color = new xna.Color(1f, 0f, 0f, .5f); + var vertices = new PositionColoredTextured[] + { + new PositionColoredTextured(-1, -1, -1, 0, 0, 1f, 0f, 0f, 1f), + new PositionColoredTextured(+1, -1, -1, 0, 0, 1f, 0f, 0f, 1f), + new PositionColoredTextured(+1, +1, -1, 0, 0, 1f, 0f, 0f, 1f), + new PositionColoredTextured(-1, +1, -1, 0, 0, 1f, 0f, 0f, 1f), + new PositionColoredTextured(-1, -1, +1, 0, 0, 1f, 0f, 0f, 1f), + new PositionColoredTextured(+1, -1, +1, 0, 0, 1f, 0f, 0f, 1f), + new PositionColoredTextured(+1, +1, +1, 0, 0, 1f, 0f, 0f, 1f), + new PositionColoredTextured(-1, +1, +1, 0, 0, 1f, 0f, 0f, 1f), + }; + var indices = new int[] + { + 0, 1, 3, 3, 1, 2, + 1, 5, 2, 2, 5, 6, + 5, 4, 6, 6, 4, 7, + 4, 0, 7, 7, 0, 3, + 3, 2, 7, 7, 2, 6, + 4, 5, 0, 0, 5, 1 + }; + _graphics.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, 8, indices, 0, 12, MeshLoader.PositionColoredTexturedVertexDeclaration); + } + } + } + }); + } + + private void RenderMeshNew(EffectPass pass, MeshGroup mesh, bool passRenderOpaque) + { + foreach (var meshDescriptor in mesh.MeshDescriptors) + { + if (meshDescriptor.IsOpaque != passRenderOpaque) + continue; + if (meshDescriptor.Indices.Length == 0) + continue; + + var textureIndex = meshDescriptor.TextureIndex & 0xffff; + if (textureIndex < mesh.Textures.Length) + _shader.SetRenderTexture(pass, mesh.Textures[textureIndex]); + + _graphics.DrawUserIndexedPrimitives( + PrimitiveType.TriangleList, + meshDescriptor.Vertices, + 0, + meshDescriptor.Vertices.Length, + meshDescriptor.Indices, + 0, + meshDescriptor.Indices.Length / 3, + MeshLoader.PositionColoredTexturedVertexDeclaration); + } + } + + private void LoadMapComponent(List entries, string componentName) + { + var modelEntry = entries.FirstOrDefault(x => x.Name == componentName && x.Type == Bar.EntryType.Model); + var textureEntry = entries.FirstOrDefault(x => x.Name == componentName && x.Type == Bar.EntryType.ModelTexture); + if (modelEntry == null || textureEntry == null) + return; + + var model = Mdlx.Read(modelEntry.Stream); + var textures = ModelTexture.Read(textureEntry.Stream).Images; + MapMeshGroups.Add(new MeshGroupModel(_graphics, componentName, model, textures, 0)); + } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Models/CollisionModel.cs b/OpenKh.Tools.Kh2MapStudio/Models/CollisionModel.cs index 031423da4..e4edfbc8d 100644 --- a/OpenKh.Tools.Kh2MapStudio/Models/CollisionModel.cs +++ b/OpenKh.Tools.Kh2MapStudio/Models/CollisionModel.cs @@ -1,206 +1,206 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Tools.Kh2MapStudio.Models -{ - class CollisionModel : IDisposable - { - private static readonly Color[] ColorPalette = Enumerable - .Range(0, 40) - .Select(x => FromHue(x * 78.75f)) - .ToArray(); - - private static Color FromHue(float src_h) - { - float h = src_h * 2; - - int hi = (int)(h / 60.0f) % 6; - float f = (h / 60.0f) - hi; - float q = 1.0f - f; - - return hi switch - { - 1 => new Color(q, 1f, 0f), - 2 => new Color(0f, 1f, f), - 3 => new Color(0f, q, 1f), - 4 => new Color(f, 0f, 1f), - 5 => new Color(1f, 0f, q), - _ => new Color(1f, f, 0f), - }; - } - - private VertexBuffer _vertexBuffer; - - public CollisionModel(Coct coct) - { - Coct = coct; - } - - - public Coct Coct { get; } - - public Assimp.Scene Scene => GetScene(Coct); - - public bool IsVisible { get; set; } - - public void Dispose() - { - _vertexBuffer?.Dispose(); - } - - public void Draw(GraphicsDevice graphics) - { - if (!IsVisible) - return; - - _vertexBuffer?.Dispose(); - _vertexBuffer = null; - if (_vertexBuffer == null) - _vertexBuffer = CreateVertexBufferForCollision(graphics, Coct); - - graphics.SetVertexBuffer(_vertexBuffer); - graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, _vertexBuffer.VertexCount); - graphics.SetVertexBuffer(null); - } - - private static VertexBuffer CreateVertexBufferForCollision(GraphicsDevice graphics, Coct rawCoct) - { - var vb = new VertexBuffer( - graphics, - VertexPositionColorTexture.VertexDeclaration, - GetVertices(rawCoct).Count, - BufferUsage.WriteOnly); - vb.SetData(GetVertices(rawCoct).ToArray()); - - return vb; - } - - private static Assimp.Scene GetScene(Coct coct) - { - var color = new Color(1f, 1f, 1f, 1f); - var scene = new Assimp.Scene(); - scene.RootNode = new Assimp.Node("root"); - - for (int i = 0; i < coct.Nodes.Count; i++) - { - var j = 0; - var meshGroup = coct.Nodes[i]; - foreach (var mesh in meshGroup.Meshes) - { - var faceIndex = 0; - var sceneMesh = new Assimp.Mesh($"Mesh{i}_{j}", Assimp.PrimitiveType.Triangle); - - foreach (var item in mesh.Collisions) - { - var v1 = coct.VertexList[item.Vertex1]; - var v2 = coct.VertexList[item.Vertex2]; - var v3 = coct.VertexList[item.Vertex3]; - - List vertices; - if (item.Vertex4 >= 0) - { - var v4 = coct.VertexList[item.Vertex4]; - vertices = GenerateVertex( - color, - v1.X, v1.Y, v1.Z, - v2.X, v2.Y, v2.Z, - v3.X, v3.Y, v3.Z, - v1.X, v1.Y, v1.Z, - v3.X, v3.Y, v3.Z, - v4.X, v4.Y, v4.Z).ToList(); - sceneMesh.Faces.Add(new Assimp.Face(new int[] - { - faceIndex++, faceIndex++, faceIndex++, - faceIndex++, faceIndex++, faceIndex++ - })); - } - else - { - vertices = GenerateVertex( - color, - v1.X, v1.Y, v1.Z, - v2.X, v2.Y, v2.Z, - v3.X, v3.Y, v3.Z).ToList(); - sceneMesh.Faces.Add(new Assimp.Face(new int[] - { - faceIndex++, faceIndex++, faceIndex++ - })); - } - - sceneMesh.Vertices.AddRange(vertices - .Select(x => new Assimp.Vector3D - { - X = x.Position.X, - Y = x.Position.Y, - Z = x.Position.Z, - })); - } - - j++; - scene.Meshes.Add(sceneMesh); - } - } - - scene.RootNode.MeshIndices.AddRange(Enumerable.Range(0, scene.MeshCount)); - return scene; - } - - private static List GetVertices(Coct coct) - { - var vertices = new List(); - for (int i1 = 0; i1 < coct.Nodes.Count; i1++) - { - var meshGroup = coct.Nodes[i1]; - foreach (var mesh in meshGroup.Meshes) - { - foreach (var item in mesh.Collisions) - { - var color = ColorPalette[(int)Math.Abs((item.Plane.D * ColorPalette.Length)) % ColorPalette.Length]; - var v1 = coct.VertexList[item.Vertex1]; - var v2 = coct.VertexList[item.Vertex2]; - var v3 = coct.VertexList[item.Vertex3]; - - if (item.Vertex4 >= 0) - { - var v4 = coct.VertexList[item.Vertex4]; - vertices.AddRange(GenerateVertex( - color, - v1.X, v1.Y, v1.Z, - v2.X, v2.Y, v2.Z, - v3.X, v3.Y, v3.Z, - v1.X, v1.Y, v1.Z, - v3.X, v3.Y, v3.Z, - v4.X, v4.Y, v4.Z)); - } - else - { - vertices.AddRange(GenerateVertex( - color, - v1.X, v1.Y, v1.Z, - v2.X, v2.Y, v2.Z, - v3.X, v3.Y, v3.Z)); - } - } - } - } - - return vertices; - } - - private static IEnumerable GenerateVertex(Color color, params float[] n) - { - for (var i = 0; i < n.Length - 2; i += 3) - { - yield return new VertexPositionColorTexture - { - Position = new Vector3 { X = n[i], Y = -n[i + 1], Z = -n[i + 2] }, - Color = color - }; - } - } - } -} +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Tools.Kh2MapStudio.Models +{ + class CollisionModel : IDisposable + { + private static readonly Color[] ColorPalette = Enumerable + .Range(0, 40) + .Select(x => FromHue(x * 78.75f)) + .ToArray(); + + private static Color FromHue(float src_h) + { + float h = src_h * 2; + + int hi = (int)(h / 60.0f) % 6; + float f = (h / 60.0f) - hi; + float q = 1.0f - f; + + return hi switch + { + 1 => new Color(q, 1f, 0f), + 2 => new Color(0f, 1f, f), + 3 => new Color(0f, q, 1f), + 4 => new Color(f, 0f, 1f), + 5 => new Color(1f, 0f, q), + _ => new Color(1f, f, 0f), + }; + } + + private VertexBuffer _vertexBuffer; + + public CollisionModel(Coct coct) + { + Coct = coct; + } + + + public Coct Coct { get; } + + public Assimp.Scene Scene => GetScene(Coct); + + public bool IsVisible { get; set; } + + public void Dispose() + { + _vertexBuffer?.Dispose(); + } + + public void Draw(GraphicsDevice graphics) + { + if (!IsVisible) + return; + + _vertexBuffer?.Dispose(); + _vertexBuffer = null; + if (_vertexBuffer == null) + _vertexBuffer = CreateVertexBufferForCollision(graphics, Coct); + + graphics.SetVertexBuffer(_vertexBuffer); + graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, _vertexBuffer.VertexCount); + graphics.SetVertexBuffer(null); + } + + private static VertexBuffer CreateVertexBufferForCollision(GraphicsDevice graphics, Coct rawCoct) + { + var vb = new VertexBuffer( + graphics, + VertexPositionColorTexture.VertexDeclaration, + GetVertices(rawCoct).Count, + BufferUsage.WriteOnly); + vb.SetData(GetVertices(rawCoct).ToArray()); + + return vb; + } + + private static Assimp.Scene GetScene(Coct coct) + { + var color = new Color(1f, 1f, 1f, 1f); + var scene = new Assimp.Scene(); + scene.RootNode = new Assimp.Node("root"); + + for (int i = 0; i < coct.Nodes.Count; i++) + { + var j = 0; + var meshGroup = coct.Nodes[i]; + foreach (var mesh in meshGroup.Meshes) + { + var faceIndex = 0; + var sceneMesh = new Assimp.Mesh($"Mesh{i}_{j}", Assimp.PrimitiveType.Triangle); + + foreach (var item in mesh.Collisions) + { + var v1 = coct.VertexList[item.Vertex1]; + var v2 = coct.VertexList[item.Vertex2]; + var v3 = coct.VertexList[item.Vertex3]; + + List vertices; + if (item.Vertex4 >= 0) + { + var v4 = coct.VertexList[item.Vertex4]; + vertices = GenerateVertex( + color, + v1.X, v1.Y, v1.Z, + v2.X, v2.Y, v2.Z, + v3.X, v3.Y, v3.Z, + v1.X, v1.Y, v1.Z, + v3.X, v3.Y, v3.Z, + v4.X, v4.Y, v4.Z).ToList(); + sceneMesh.Faces.Add(new Assimp.Face(new int[] + { + faceIndex++, faceIndex++, faceIndex++, + faceIndex++, faceIndex++, faceIndex++ + })); + } + else + { + vertices = GenerateVertex( + color, + v1.X, v1.Y, v1.Z, + v2.X, v2.Y, v2.Z, + v3.X, v3.Y, v3.Z).ToList(); + sceneMesh.Faces.Add(new Assimp.Face(new int[] + { + faceIndex++, faceIndex++, faceIndex++ + })); + } + + sceneMesh.Vertices.AddRange(vertices + .Select(x => new Assimp.Vector3D + { + X = x.Position.X, + Y = x.Position.Y, + Z = x.Position.Z, + })); + } + + j++; + scene.Meshes.Add(sceneMesh); + } + } + + scene.RootNode.MeshIndices.AddRange(Enumerable.Range(0, scene.MeshCount)); + return scene; + } + + private static List GetVertices(Coct coct) + { + var vertices = new List(); + for (int i1 = 0; i1 < coct.Nodes.Count; i1++) + { + var meshGroup = coct.Nodes[i1]; + foreach (var mesh in meshGroup.Meshes) + { + foreach (var item in mesh.Collisions) + { + var color = ColorPalette[(int)Math.Abs((item.Plane.D * ColorPalette.Length)) % ColorPalette.Length]; + var v1 = coct.VertexList[item.Vertex1]; + var v2 = coct.VertexList[item.Vertex2]; + var v3 = coct.VertexList[item.Vertex3]; + + if (item.Vertex4 >= 0) + { + var v4 = coct.VertexList[item.Vertex4]; + vertices.AddRange(GenerateVertex( + color, + v1.X, v1.Y, v1.Z, + v2.X, v2.Y, v2.Z, + v3.X, v3.Y, v3.Z, + v1.X, v1.Y, v1.Z, + v3.X, v3.Y, v3.Z, + v4.X, v4.Y, v4.Z)); + } + else + { + vertices.AddRange(GenerateVertex( + color, + v1.X, v1.Y, v1.Z, + v2.X, v2.Y, v2.Z, + v3.X, v3.Y, v3.Z)); + } + } + } + } + + return vertices; + } + + private static IEnumerable GenerateVertex(Color color, params float[] n) + { + for (var i = 0; i < n.Length - 2; i += 3) + { + yield return new VertexPositionColorTexture + { + Position = new Vector3 { X = n[i], Y = -n[i + 1], Z = -n[i + 2] }, + Color = color + }; + } + } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Models/MeshGroupModel.cs b/OpenKh.Tools.Kh2MapStudio/Models/MeshGroupModel.cs index c6c5ffa9e..14fb7675a 100644 --- a/OpenKh.Tools.Kh2MapStudio/Models/MeshGroupModel.cs +++ b/OpenKh.Tools.Kh2MapStudio/Models/MeshGroupModel.cs @@ -1,64 +1,64 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Engine.MonoGame; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Tools.Kh2MapStudio.Models -{ - class MeshGroupModel : IDisposable - { - private readonly GraphicsDevice _graphics; - private KingdomTexture[] _kingdomTextures = new KingdomTexture[0]; - private readonly Mdlx _model; - - public MeshGroupModel(GraphicsDevice g, string name, - Mdlx map, List texture, int index) - { - _graphics = g; - _model = map; - Name = name; - Texture = texture; - Index = index; - IsVisible = true; - InvalidateTextures(); - Invalidate(); - } - - public string Name { get; } - public Mdlx.M4 Map => _model.MapModel; - public List Texture { get; } - public int Index { get; } - public MeshGroup MeshGroup { get; private set; } - public bool IsVisible { get; set; } - - public void Dispose() - { - foreach (var texture in _kingdomTextures) - texture?.Dispose(); - } - - public void InvalidateTextures() - { - foreach (var texture in _kingdomTextures) - texture?.Dispose(); - - _kingdomTextures = Texture? - .Select(texture => new KingdomTexture(texture, _graphics)) - .ToArray() ?? new KingdomTexture[0]; - - if (MeshGroup != null) - MeshGroup.Textures = _kingdomTextures; - } - - public void Invalidate() - { - MeshGroup = new MeshGroup - { - MeshDescriptors = MeshLoader.FromKH2(_model).MeshDescriptors, - Textures = _kingdomTextures - }; - } - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Engine.MonoGame; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Tools.Kh2MapStudio.Models +{ + class MeshGroupModel : IDisposable + { + private readonly GraphicsDevice _graphics; + private KingdomTexture[] _kingdomTextures = new KingdomTexture[0]; + private readonly Mdlx _model; + + public MeshGroupModel(GraphicsDevice g, string name, + Mdlx map, List texture, int index) + { + _graphics = g; + _model = map; + Name = name; + Texture = texture; + Index = index; + IsVisible = true; + InvalidateTextures(); + Invalidate(); + } + + public string Name { get; } + public Mdlx.M4 Map => _model.MapModel; + public List Texture { get; } + public int Index { get; } + public MeshGroup MeshGroup { get; private set; } + public bool IsVisible { get; set; } + + public void Dispose() + { + foreach (var texture in _kingdomTextures) + texture?.Dispose(); + } + + public void InvalidateTextures() + { + foreach (var texture in _kingdomTextures) + texture?.Dispose(); + + _kingdomTextures = Texture? + .Select(texture => new KingdomTexture(texture, _graphics)) + .ToArray() ?? new KingdomTexture[0]; + + if (MeshGroup != null) + MeshGroup.Textures = _kingdomTextures; + } + + public void Invalidate() + { + MeshGroup = new MeshGroup + { + MeshDescriptors = MeshLoader.FromKH2(_model).MeshDescriptors, + Textures = _kingdomTextures + }; + } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Models/SpawnPointModel.cs b/OpenKh.Tools.Kh2MapStudio/Models/SpawnPointModel.cs index 27981a50c..fc1a9fb3b 100644 --- a/OpenKh.Tools.Kh2MapStudio/Models/SpawnPointModel.cs +++ b/OpenKh.Tools.Kh2MapStudio/Models/SpawnPointModel.cs @@ -1,20 +1,20 @@ -using OpenKh.Kh2.Ard; -using OpenKh.Tools.Kh2MapStudio.Interfaces; -using System.Collections.Generic; - -namespace OpenKh.Tools.Kh2MapStudio.Models -{ - class SpawnPointModel - { - public SpawnPointModel(IObjEntryController objEntryCtrl, string name, List spawnPoints) - { - ObjEntryCtrl = objEntryCtrl; - Name = name; - SpawnPoints = spawnPoints; - } - - public IObjEntryController ObjEntryCtrl { get; } - public string Name { get; set; } - public List SpawnPoints { get; } - } -} +using OpenKh.Kh2.Ard; +using OpenKh.Tools.Kh2MapStudio.Interfaces; +using System.Collections.Generic; + +namespace OpenKh.Tools.Kh2MapStudio.Models +{ + class SpawnPointModel + { + public SpawnPointModel(IObjEntryController objEntryCtrl, string name, List spawnPoints) + { + ObjEntryCtrl = objEntryCtrl; + Name = name; + SpawnPoints = spawnPoints; + } + + public IObjEntryController ObjEntryCtrl { get; } + public string Name { get; set; } + public List SpawnPoints { get; } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Models/SpawnScriptModel.cs b/OpenKh.Tools.Kh2MapStudio/Models/SpawnScriptModel.cs index fd78c9a6a..5b5c6be79 100644 --- a/OpenKh.Tools.Kh2MapStudio/Models/SpawnScriptModel.cs +++ b/OpenKh.Tools.Kh2MapStudio/Models/SpawnScriptModel.cs @@ -1,65 +1,65 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.Ard; -using OpenKh.Kh2.Extensions; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Tools.Kh2MapStudio.Models -{ - class SpawnScriptModel - { - private readonly string _name; - private List _spawnScripts; - - SpawnScriptModel(string name, List spawnScripts) - { - _name = name; - _spawnScripts = spawnScripts; - Decompiled = AreaDataScript.Decompile(spawnScripts); - } - - public IEnumerable ProgramIds => _spawnScripts.Select(x => (int)x.ProgramId); - public string Decompiled { get; set; } - public bool IsError { get; set; } - public string LastError { get; set; } - - public void Compile() - { - try - { - IsError = false; - LastError = "Success!"; - _spawnScripts = AreaDataScript.Compile(Decompiled).ToList(); - } - catch (SpawnScriptParserException ex) - { - IsError = true; - LastError = ex.Message; - } - } - - public IEnumerable SaveToBar(IEnumerable entries) - { - var memStream = new MemoryStream(); - AreaDataScript.Write(memStream, _spawnScripts); - - return entries.AddOrReplace(new Bar.Entry - { - Name = _name, - Type = Bar.EntryType.AreaDataScript, - Stream = memStream - }); - } - - public static SpawnScriptModel Create(List entries, string name) - { - var entry = entries - .FirstOrDefault(x => x.Name == name && x.Type == Bar.EntryType.AreaDataScript); - if (entry == null) - return null; - - return new SpawnScriptModel(name, AreaDataScript.Read(entry.Stream)); - } - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.Ard; +using OpenKh.Kh2.Extensions; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Tools.Kh2MapStudio.Models +{ + class SpawnScriptModel + { + private readonly string _name; + private List _spawnScripts; + + SpawnScriptModel(string name, List spawnScripts) + { + _name = name; + _spawnScripts = spawnScripts; + Decompiled = AreaDataScript.Decompile(spawnScripts); + } + + public IEnumerable ProgramIds => _spawnScripts.Select(x => (int)x.ProgramId); + public string Decompiled { get; set; } + public bool IsError { get; set; } + public string LastError { get; set; } + + public void Compile() + { + try + { + IsError = false; + LastError = "Success!"; + _spawnScripts = AreaDataScript.Compile(Decompiled).ToList(); + } + catch (SpawnScriptParserException ex) + { + IsError = true; + LastError = ex.Message; + } + } + + public IEnumerable SaveToBar(IEnumerable entries) + { + var memStream = new MemoryStream(); + AreaDataScript.Write(memStream, _spawnScripts); + + return entries.AddOrReplace(new Bar.Entry + { + Name = _name, + Type = Bar.EntryType.AreaDataScript, + Stream = memStream + }); + } + + public static SpawnScriptModel Create(List entries, string name) + { + var entry = entries + .FirstOrDefault(x => x.Name == name && x.Type == Bar.EntryType.AreaDataScript); + if (entry == null) + return null; + + return new SpawnScriptModel(name, AreaDataScript.Read(entry.Stream)); + } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/ObjEntryController.cs b/OpenKh.Tools.Kh2MapStudio/ObjEntryController.cs index e4705fb80..236592f47 100644 --- a/OpenKh.Tools.Kh2MapStudio/ObjEntryController.cs +++ b/OpenKh.Tools.Kh2MapStudio/ObjEntryController.cs @@ -1,101 +1,101 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Common; -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Parsers; -using OpenKh.Kh2; -using OpenKh.Tools.Kh2MapStudio.Interfaces; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Tools.Kh2MapStudio -{ - class ObjEntryController : IObjEntryController, IDisposable - { - private static readonly MeshGroup EmptyMeshGroup = new MeshGroup - { - Textures = new KingdomTexture[0], - MeshDescriptors = new List(0) - }; - - private readonly Dictionary _meshGroups = new Dictionary(); - private readonly Dictionary _objEntryLookup; - private readonly Dictionary _objEntryLookupReversed; - private readonly GraphicsDevice _graphics; - private readonly string _objPath; - - public ObjEntryController(GraphicsDevice graphics, string objPath, string objEntryFileName) : - this(File.OpenRead(objEntryFileName).Using(Objentry.Read)) - { - _graphics = graphics; - _objPath = objPath; - } - - public ObjEntryController(List objEntries) - { - ObjectEntries = objEntries.OrderBy(x => x.ModelName).ToArray(); - _objEntryLookup = ObjectEntries - .ToDictionary(x => x.ModelName, x => (int)x.ObjectId); - _objEntryLookupReversed = ObjectEntries - .ToDictionary(x => (int)x.ObjectId, x => x.ModelName); - } - - public IEnumerable ObjectEntries { get; } - - public void Dispose() - { - foreach (var meshGroup in _meshGroups) - foreach (var texture in meshGroup.Value.Textures) - texture.Dispose(); - _meshGroups.Clear(); - } - - public string GetName(int objectId) => _objEntryLookupReversed[objectId]; - - public MeshGroup this[int objId] - { - get - { - if (_meshGroups.TryGetValue(objId, out var meshGroup)) - return meshGroup; - - var objEntryName = _objEntryLookupReversed[objId]; - - var modelPath = Path.Combine(_objPath, objEntryName); - var modelFileName = modelPath + ".mdlx"; - if (File.Exists(modelFileName)) - { - var mdlxEntries = File.OpenRead(modelFileName).Using(Bar.Read); - var modelEntry = mdlxEntries.FirstOrDefault(x => x.Type == Bar.EntryType.Model); - if (modelEntry != null) - { - var model = Mdlx.Read(modelEntry.Stream); - ModelTexture textures = null; - - var textureEntry = mdlxEntries.FirstOrDefault(x => x.Type == Bar.EntryType.ModelTexture); - if (textureEntry != null) - textures = ModelTexture.Read(textureEntry.Stream); - - var modelMotion = MeshLoader.FromKH2(model); - modelMotion.ApplyMotion(modelMotion.InitialPose); - meshGroup = new MeshGroup - { - MeshDescriptors = modelMotion.MeshDescriptors, - Textures = textures == null ? new IKingdomTexture[0] : textures.LoadTextures(_graphics).ToArray() - }; - } - else - meshGroup = EmptyMeshGroup; - } - else - meshGroup = EmptyMeshGroup; - - _meshGroups[objId] = meshGroup; - return meshGroup; - } - } - - public MeshGroup this[string objName] => this[_objEntryLookup[objName]]; - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Common; +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Parsers; +using OpenKh.Kh2; +using OpenKh.Tools.Kh2MapStudio.Interfaces; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Tools.Kh2MapStudio +{ + class ObjEntryController : IObjEntryController, IDisposable + { + private static readonly MeshGroup EmptyMeshGroup = new MeshGroup + { + Textures = new KingdomTexture[0], + MeshDescriptors = new List(0) + }; + + private readonly Dictionary _meshGroups = new Dictionary(); + private readonly Dictionary _objEntryLookup; + private readonly Dictionary _objEntryLookupReversed; + private readonly GraphicsDevice _graphics; + private readonly string _objPath; + + public ObjEntryController(GraphicsDevice graphics, string objPath, string objEntryFileName) : + this(File.OpenRead(objEntryFileName).Using(Objentry.Read)) + { + _graphics = graphics; + _objPath = objPath; + } + + public ObjEntryController(List objEntries) + { + ObjectEntries = objEntries.OrderBy(x => x.ModelName).ToArray(); + _objEntryLookup = ObjectEntries + .ToDictionary(x => x.ModelName, x => (int)x.ObjectId); + _objEntryLookupReversed = ObjectEntries + .ToDictionary(x => (int)x.ObjectId, x => x.ModelName); + } + + public IEnumerable ObjectEntries { get; } + + public void Dispose() + { + foreach (var meshGroup in _meshGroups) + foreach (var texture in meshGroup.Value.Textures) + texture.Dispose(); + _meshGroups.Clear(); + } + + public string GetName(int objectId) => _objEntryLookupReversed[objectId]; + + public MeshGroup this[int objId] + { + get + { + if (_meshGroups.TryGetValue(objId, out var meshGroup)) + return meshGroup; + + var objEntryName = _objEntryLookupReversed[objId]; + + var modelPath = Path.Combine(_objPath, objEntryName); + var modelFileName = modelPath + ".mdlx"; + if (File.Exists(modelFileName)) + { + var mdlxEntries = File.OpenRead(modelFileName).Using(Bar.Read); + var modelEntry = mdlxEntries.FirstOrDefault(x => x.Type == Bar.EntryType.Model); + if (modelEntry != null) + { + var model = Mdlx.Read(modelEntry.Stream); + ModelTexture textures = null; + + var textureEntry = mdlxEntries.FirstOrDefault(x => x.Type == Bar.EntryType.ModelTexture); + if (textureEntry != null) + textures = ModelTexture.Read(textureEntry.Stream); + + var modelMotion = MeshLoader.FromKH2(model); + modelMotion.ApplyMotion(modelMotion.InitialPose); + meshGroup = new MeshGroup + { + MeshDescriptors = modelMotion.MeshDescriptors, + Textures = textures == null ? new IKingdomTexture[0] : textures.LoadTextures(_graphics).ToArray() + }; + } + else + meshGroup = EmptyMeshGroup; + } + else + meshGroup = EmptyMeshGroup; + + _meshGroups[objId] = meshGroup; + return meshGroup; + } + } + + public MeshGroup this[string objName] => this[_objEntryLookup[objName]]; + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Program.cs b/OpenKh.Tools.Kh2MapStudio/Program.cs index 4c5d975ea..4cccdca80 100644 --- a/OpenKh.Tools.Kh2MapStudio/Program.cs +++ b/OpenKh.Tools.Kh2MapStudio/Program.cs @@ -1,69 +1,69 @@ -using McMaster.Extensions.CommandLineUtils; -using OpenKh.Tools.Common.CustomImGui; -using System; -using System.Reflection; - -namespace OpenKh.Tools.Kh2MapStudio -{ - [Command("OpenKh.Tools.Kh2MapStudio")] - [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] - class Program : IDisposable - { - [STAThread] - static int Main(string[] args) - { - return CommandLineApplication.Execute(args); - } - - protected int OnExecute(CommandLineApplication app) - { - Run(); - return 0; - } - - #region CommandLine - private static string GetVersion() - => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; - - [Argument(0, "KH2 GamePath")] - public string GamePath { get; } - #endregion - - const int InitialWindowWidth = 1000; - const int InitialWindowHeight = 800; - private readonly MonoGameImGuiBootstrap _bootstrap; - private App _app; - - public Program() - { - _bootstrap = new MonoGameImGuiBootstrap( - InitialWindowWidth, - InitialWindowHeight, - Initialize); - _bootstrap.MainLoop = MainLoop; - - - } - - private void Initialize(MonoGameImGuiBootstrap bootstrap) - { - _app = new App(bootstrap, GamePath); - } - - public void Run() - { - _bootstrap.Run(); - } - - private void MainLoop(MonoGameImGuiBootstrap obj) - { - if (_app.MainLoop()) - _bootstrap.Exit(); - } - - public void Dispose() - { - _bootstrap?.Dispose(); - } - } -} +using McMaster.Extensions.CommandLineUtils; +using OpenKh.Tools.Common.CustomImGui; +using System; +using System.Reflection; + +namespace OpenKh.Tools.Kh2MapStudio +{ + [Command("OpenKh.Tools.Kh2MapStudio")] + [VersionOptionFromMember("--version", MemberName = nameof(GetVersion))] + class Program : IDisposable + { + [STAThread] + static int Main(string[] args) + { + return CommandLineApplication.Execute(args); + } + + protected int OnExecute(CommandLineApplication app) + { + Run(); + return 0; + } + + #region CommandLine + private static string GetVersion() + => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + [Argument(0, "KH2 GamePath")] + public string GamePath { get; } + #endregion + + const int InitialWindowWidth = 1000; + const int InitialWindowHeight = 800; + private readonly MonoGameImGuiBootstrap _bootstrap; + private App _app; + + public Program() + { + _bootstrap = new MonoGameImGuiBootstrap( + InitialWindowWidth, + InitialWindowHeight, + Initialize); + _bootstrap.MainLoop = MainLoop; + + + } + + private void Initialize(MonoGameImGuiBootstrap bootstrap) + { + _app = new App(bootstrap, GamePath); + } + + public void Run() + { + _bootstrap.Run(); + } + + private void MainLoop(MonoGameImGuiBootstrap obj) + { + if (_app.MainLoop()) + _bootstrap.Exit(); + } + + public void Dispose() + { + _bootstrap?.Dispose(); + } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Windows/BobDescriptorWindow.cs b/OpenKh.Tools.Kh2MapStudio/Windows/BobDescriptorWindow.cs index 3d321c0f8..0859db030 100644 --- a/OpenKh.Tools.Kh2MapStudio/Windows/BobDescriptorWindow.cs +++ b/OpenKh.Tools.Kh2MapStudio/Windows/BobDescriptorWindow.cs @@ -1,89 +1,89 @@ -using ImGuiNET; -using Microsoft.Xna.Framework; -using OpenKh.Kh2.Models; -using System; -using System.Collections.Generic; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; -using static OpenKh.Tools.Kh2MapStudio.ImGuiExHelpers; - -namespace OpenKh.Tools.Kh2MapStudio.Windows -{ - public class BobDescriptorWindow - { - public static bool Run(List bobDescs, int bobCount) => ForHeader("BOB descriptors", () => - { - var bobToRemove = -1; - for (int i = 0; i < bobDescs.Count; i++) - { - var desc = bobDescs[i]; - if (ImGui.CollapsingHeader($"BOB descriptor##{i}")) - { - if (ImGui.BeginCombo("BOB model", bobCount > 0 ? - $"BOB #{desc.BobIndex}" : "No bob exists in this map")) - { - for (var j = 0; j < bobCount; j++) - { - if (ImGui.Selectable($"BOB #{j}", j == desc.BobIndex)) - desc.BobIndex = j; - } - ImGui.EndCombo(); - } - - ForEdit3("Position", - () => new Vector3(desc.PositionX, desc.PositionY, desc.PositionZ), - x => - { - desc.PositionX = x.X; - desc.PositionY = x.Y; - desc.PositionZ = x.Z; - }, 10f); - ForEdit3("Rotation", - () => new Vector3( - (float)(desc.RotationX * 180.0 / Math.PI), - (float)(desc.RotationY * 180.0 / Math.PI), - (float)(desc.RotationZ * 180.0 / Math.PI)), - x => - { - desc.RotationX = (float)(x.X * Math.PI / 180.0); - desc.RotationY = (float)(x.Y * Math.PI / 180.0); - desc.RotationZ = (float)(x.Z * Math.PI / 180.0); - }); - ForEdit3("Scaling", - () => new Vector3(desc.ScalingX, desc.ScalingY, desc.ScalingZ), - x => - { - desc.ScalingX = x.X; - desc.ScalingY = x.Y; - desc.ScalingZ = x.Z; - }, 0.01f); - - ForEdit("Unk28", () => desc.Unknown28, x => desc.Unknown28 = x); - ForEdit("Unk2c", () => desc.Unknown2c, x => desc.Unknown2c = x); - ForEdit("Unk30", () => desc.Unknown30, x => desc.Unknown30 = x); - ForEdit("Unk34", () => desc.Unknown34, x => desc.Unknown34 = x); - ForEdit("Unk38", () => desc.Unknown38, x => desc.Unknown38 = x); - ForEdit("Unk3c", () => desc.Unknown3c, x => desc.Unknown3c = x); - ForEdit("Unk40", () => desc.Unknown40, x => desc.Unknown40 = x); - ForEdit("Unk44", () => desc.Unknown44, x => desc.Unknown44 = x); - ForEdit("Unk48", () => desc.Unknown48, x => desc.Unknown48 = x); - ForEdit("Unk4c", () => desc.Unknown4c, x => desc.Unknown4c = x); - ForEdit("Unk50", () => desc.Unknown50, x => desc.Unknown50 = x); - ForEdit("Unk54", () => desc.Unknown54, x => desc.Unknown54 = x); - ForEdit("Unk58", () => desc.Unknown58, x => desc.Unknown58 = x); - ForEdit("Unk5c", () => desc.Unknown5c, x => desc.Unknown5c = x); - ForEdit("Unk60", () => desc.Unknown60, x => desc.Unknown60 = x); - ForEdit("Unk64", () => desc.Unknown64, x => desc.Unknown64 = x); - - if (ImGui.SmallButton("Remove this BOB descriptor")) - bobToRemove = i; - } - } - - if (bobToRemove >= 0) - bobDescs.RemoveAt(bobToRemove); - - if (ImGui.SmallButton("Add a new BOB descriptor")) - bobDescs.Add(new BobDescriptor()); - }); - } -} +using ImGuiNET; +using Microsoft.Xna.Framework; +using OpenKh.Kh2.Models; +using System; +using System.Collections.Generic; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; +using static OpenKh.Tools.Kh2MapStudio.ImGuiExHelpers; + +namespace OpenKh.Tools.Kh2MapStudio.Windows +{ + public class BobDescriptorWindow + { + public static bool Run(List bobDescs, int bobCount) => ForHeader("BOB descriptors", () => + { + var bobToRemove = -1; + for (int i = 0; i < bobDescs.Count; i++) + { + var desc = bobDescs[i]; + if (ImGui.CollapsingHeader($"BOB descriptor##{i}")) + { + if (ImGui.BeginCombo("BOB model", bobCount > 0 ? + $"BOB #{desc.BobIndex}" : "No bob exists in this map")) + { + for (var j = 0; j < bobCount; j++) + { + if (ImGui.Selectable($"BOB #{j}", j == desc.BobIndex)) + desc.BobIndex = j; + } + ImGui.EndCombo(); + } + + ForEdit3("Position", + () => new Vector3(desc.PositionX, desc.PositionY, desc.PositionZ), + x => + { + desc.PositionX = x.X; + desc.PositionY = x.Y; + desc.PositionZ = x.Z; + }, 10f); + ForEdit3("Rotation", + () => new Vector3( + (float)(desc.RotationX * 180.0 / Math.PI), + (float)(desc.RotationY * 180.0 / Math.PI), + (float)(desc.RotationZ * 180.0 / Math.PI)), + x => + { + desc.RotationX = (float)(x.X * Math.PI / 180.0); + desc.RotationY = (float)(x.Y * Math.PI / 180.0); + desc.RotationZ = (float)(x.Z * Math.PI / 180.0); + }); + ForEdit3("Scaling", + () => new Vector3(desc.ScalingX, desc.ScalingY, desc.ScalingZ), + x => + { + desc.ScalingX = x.X; + desc.ScalingY = x.Y; + desc.ScalingZ = x.Z; + }, 0.01f); + + ForEdit("Unk28", () => desc.Unknown28, x => desc.Unknown28 = x); + ForEdit("Unk2c", () => desc.Unknown2c, x => desc.Unknown2c = x); + ForEdit("Unk30", () => desc.Unknown30, x => desc.Unknown30 = x); + ForEdit("Unk34", () => desc.Unknown34, x => desc.Unknown34 = x); + ForEdit("Unk38", () => desc.Unknown38, x => desc.Unknown38 = x); + ForEdit("Unk3c", () => desc.Unknown3c, x => desc.Unknown3c = x); + ForEdit("Unk40", () => desc.Unknown40, x => desc.Unknown40 = x); + ForEdit("Unk44", () => desc.Unknown44, x => desc.Unknown44 = x); + ForEdit("Unk48", () => desc.Unknown48, x => desc.Unknown48 = x); + ForEdit("Unk4c", () => desc.Unknown4c, x => desc.Unknown4c = x); + ForEdit("Unk50", () => desc.Unknown50, x => desc.Unknown50 = x); + ForEdit("Unk54", () => desc.Unknown54, x => desc.Unknown54 = x); + ForEdit("Unk58", () => desc.Unknown58, x => desc.Unknown58 = x); + ForEdit("Unk5c", () => desc.Unknown5c, x => desc.Unknown5c = x); + ForEdit("Unk60", () => desc.Unknown60, x => desc.Unknown60 = x); + ForEdit("Unk64", () => desc.Unknown64, x => desc.Unknown64 = x); + + if (ImGui.SmallButton("Remove this BOB descriptor")) + bobToRemove = i; + } + } + + if (bobToRemove >= 0) + bobDescs.RemoveAt(bobToRemove); + + if (ImGui.SmallButton("Add a new BOB descriptor")) + bobDescs.Add(new BobDescriptor()); + }); + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Windows/CameraWindow.cs b/OpenKh.Tools.Kh2MapStudio/Windows/CameraWindow.cs index a0f7bef67..e394baba3 100644 --- a/OpenKh.Tools.Kh2MapStudio/Windows/CameraWindow.cs +++ b/OpenKh.Tools.Kh2MapStudio/Windows/CameraWindow.cs @@ -1,19 +1,19 @@ -using OpenKh.Engine; -using System.Numerics; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; -using static OpenKh.Tools.Kh2MapStudio.ImGuiExHelpers; - -namespace OpenKh.Tools.Kh2MapStudio.Windows -{ - static class CameraWindow - { - public static bool Run(Camera camera) => ForHeader("Camera", () => - { - ForEdit3("Position", () => camera.CameraPosition, x => camera.CameraPosition = x); - ForEdit2("Rotation", - () => new Vector2(-camera.CameraRotationYawPitchRoll.X, -camera.CameraRotationYawPitchRoll.Z), - x => camera.CameraRotationYawPitchRoll = new Vector3( - -x.X, camera.CameraRotationYawPitchRoll.Y, -x.Y)); - }); - } -} +using OpenKh.Engine; +using System.Numerics; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; +using static OpenKh.Tools.Kh2MapStudio.ImGuiExHelpers; + +namespace OpenKh.Tools.Kh2MapStudio.Windows +{ + static class CameraWindow + { + public static bool Run(Camera camera) => ForHeader("Camera", () => + { + ForEdit3("Position", () => camera.CameraPosition, x => camera.CameraPosition = x); + ForEdit2("Rotation", + () => new Vector2(-camera.CameraRotationYawPitchRoll.X, -camera.CameraRotationYawPitchRoll.Z), + x => camera.CameraRotationYawPitchRoll = new Vector3( + -x.X, camera.CameraRotationYawPitchRoll.Y, -x.Y)); + }); + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Windows/CollisionWindow.cs b/OpenKh.Tools.Kh2MapStudio/Windows/CollisionWindow.cs index 4a3b2df2a..4082638b8 100644 --- a/OpenKh.Tools.Kh2MapStudio/Windows/CollisionWindow.cs +++ b/OpenKh.Tools.Kh2MapStudio/Windows/CollisionWindow.cs @@ -1,55 +1,55 @@ -using ImGuiNET; -using OpenKh.Kh2; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; - -namespace OpenKh.Tools.Kh2MapStudio.Windows -{ - static class CollisionWindow - { - public static void Run(Coct coct) => ForHeader("Collision", () => - { - Node(coct, 0); - }); - - private static void Node(Coct coct, int index) - { - if (index == -1) - return; - ForTreeNode($"Node {index}", () => - { - var node = coct.Nodes[index]; - ImGui.Text($"Box {node.BoundingBox}"); - Node(coct, node.Child1); - Node(coct, node.Child2); - Node(coct, node.Child3); - Node(coct, node.Child4); - Node(coct, node.Child5); - Node(coct, node.Child6); - Node(coct, node.Child7); - Node(coct, node.Child8); - - foreach (var mesh in node.Meshes) - { - ForTreeNode($"Mesh {mesh.GetHashCode()}", () => - { - ImGui.Text($"Box {mesh.BoundingBox}"); - ImGui.Text($"Visibility {mesh.Visibility}"); - ImGui.Text($"Group {mesh.Group}"); - - foreach (var collision in mesh.Collisions) - { - ForTreeNode($"Collision {collision.GetHashCode()}", () => - { - ImGui.Text($"Ground {collision.Ground}"); - ImGui.Text($"Floor Level {collision.FloorLevel}"); - ImGui.Text($"Plane {collision.Plane}"); - ImGui.Text($"Bound Box {collision.BoundingBox}"); - ImGui.Text($"Flags {collision.Attributes:X08}"); - }); - } - }); - } - }); - } - } -} +using ImGuiNET; +using OpenKh.Kh2; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; + +namespace OpenKh.Tools.Kh2MapStudio.Windows +{ + static class CollisionWindow + { + public static void Run(Coct coct) => ForHeader("Collision", () => + { + Node(coct, 0); + }); + + private static void Node(Coct coct, int index) + { + if (index == -1) + return; + ForTreeNode($"Node {index}", () => + { + var node = coct.Nodes[index]; + ImGui.Text($"Box {node.BoundingBox}"); + Node(coct, node.Child1); + Node(coct, node.Child2); + Node(coct, node.Child3); + Node(coct, node.Child4); + Node(coct, node.Child5); + Node(coct, node.Child6); + Node(coct, node.Child7); + Node(coct, node.Child8); + + foreach (var mesh in node.Meshes) + { + ForTreeNode($"Mesh {mesh.GetHashCode()}", () => + { + ImGui.Text($"Box {mesh.BoundingBox}"); + ImGui.Text($"Visibility {mesh.Visibility}"); + ImGui.Text($"Group {mesh.Group}"); + + foreach (var collision in mesh.Collisions) + { + ForTreeNode($"Collision {collision.GetHashCode()}", () => + { + ImGui.Text($"Ground {collision.Ground}"); + ImGui.Text($"Floor Level {collision.FloorLevel}"); + ImGui.Text($"Plane {collision.Plane}"); + ImGui.Text($"Bound Box {collision.BoundingBox}"); + ImGui.Text($"Flags {collision.Attributes:X08}"); + }); + } + }); + } + }); + } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Windows/LayerControllerWindow.cs b/OpenKh.Tools.Kh2MapStudio/Windows/LayerControllerWindow.cs index 761606bb3..659022d4d 100644 --- a/OpenKh.Tools.Kh2MapStudio/Windows/LayerControllerWindow.cs +++ b/OpenKh.Tools.Kh2MapStudio/Windows/LayerControllerWindow.cs @@ -1,26 +1,26 @@ -using OpenKh.Tools.Kh2MapStudio.Interfaces; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; - -namespace OpenKh.Tools.Kh2MapStudio.Windows -{ - static class LayerControllerWindow - { - public static bool Run(ILayerController layerController) => ForHeader("Layer control", () => - { - if (layerController.ShowMap.HasValue) - ForEdit("Show MAP", () => layerController.ShowMap.Value, x => layerController.ShowMap = x); - if (layerController.ShowSk0.HasValue) - ForEdit("Show SK0", () => layerController.ShowSk0.Value, x => layerController.ShowSk0 = x); - if (layerController.ShowSk1.HasValue) - ForEdit("Show SK1", () => layerController.ShowSk1.Value, x => layerController.ShowSk1 = x); - if (layerController.ShowBobs.HasValue) - ForEdit("Show BOBs", () => layerController.ShowBobs.Value, x => layerController.ShowBobs = x); - if (layerController.ShowMapCollision.HasValue) - ForEdit("Show map collisions", () => layerController.ShowMapCollision.Value, x => layerController.ShowMapCollision = x); - if (layerController.ShowCameraCollision.HasValue) - ForEdit("Show camera collisions", () => layerController.ShowCameraCollision.Value, x => layerController.ShowCameraCollision = x); - if (layerController.ShowLightCollision.HasValue) - ForEdit("Show light collisions", () => layerController.ShowLightCollision.Value, x => layerController.ShowLightCollision = x); - }); - } -} +using OpenKh.Tools.Kh2MapStudio.Interfaces; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; + +namespace OpenKh.Tools.Kh2MapStudio.Windows +{ + static class LayerControllerWindow + { + public static bool Run(ILayerController layerController) => ForHeader("Layer control", () => + { + if (layerController.ShowMap.HasValue) + ForEdit("Show MAP", () => layerController.ShowMap.Value, x => layerController.ShowMap = x); + if (layerController.ShowSk0.HasValue) + ForEdit("Show SK0", () => layerController.ShowSk0.Value, x => layerController.ShowSk0 = x); + if (layerController.ShowSk1.HasValue) + ForEdit("Show SK1", () => layerController.ShowSk1.Value, x => layerController.ShowSk1 = x); + if (layerController.ShowBobs.HasValue) + ForEdit("Show BOBs", () => layerController.ShowBobs.Value, x => layerController.ShowBobs = x); + if (layerController.ShowMapCollision.HasValue) + ForEdit("Show map collisions", () => layerController.ShowMapCollision.Value, x => layerController.ShowMapCollision = x); + if (layerController.ShowCameraCollision.HasValue) + ForEdit("Show camera collisions", () => layerController.ShowCameraCollision.Value, x => layerController.ShowCameraCollision = x); + if (layerController.ShowLightCollision.HasValue) + ForEdit("Show light collisions", () => layerController.ShowLightCollision.Value, x => layerController.ShowLightCollision = x); + }); + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Windows/MeshGroupWindow.cs b/OpenKh.Tools.Kh2MapStudio/Windows/MeshGroupWindow.cs index e75af87a9..57b1c0791 100644 --- a/OpenKh.Tools.Kh2MapStudio/Windows/MeshGroupWindow.cs +++ b/OpenKh.Tools.Kh2MapStudio/Windows/MeshGroupWindow.cs @@ -1,60 +1,60 @@ -using ImGuiNET; -using OpenKh.Tools.Kh2MapStudio.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; - -namespace OpenKh.Tools.Kh2MapStudio.Windows -{ - class MeshGroupWindow - { - public static bool Run(List meshGroups) => ForHeader("Mesh groups", () => - { - for (var i = 0; i < meshGroups.Count; i++) - { - MeshGroupModel meshGroup = meshGroups[i]; - ForTreeNode(meshGroup.Name, () => MeshGroup(meshGroup, i)); - } - }); - - private static void MeshGroup(MeshGroupModel meshGroup, int index) - { - if (ImGui.SmallButton("Apply changes")) - meshGroup.Invalidate(); - - ForEdit("Unk04", () => meshGroup.Map.unk04, x => meshGroup.Map.unk04 = x); - ForEdit("Unk08", () => meshGroup.Map.unk08, x => meshGroup.Map.unk08 = x); - ForEdit("VA4", () => meshGroup.Map.va4, x => meshGroup.Map.va4 = x); - - for (var i = 0; i < meshGroup.Map.vifPacketRenderingGroup.Count; i++) - { - ForTreeNode($"Mesh Rendering Group {i}##{index}", () => - { - var group = meshGroup.Map.vifPacketRenderingGroup[i]; - for (var j = 0; j < group.Length; j++) - { - var meshIndex = group[j]; - ForTreeNode($"Index {j}, Mesh {meshIndex}##{index}", () => - { - var vifPacket = meshGroup.Map.VifPackets[meshIndex]; - ForEdit("Texture", () => vifPacket.TextureId, x => - { - vifPacket.TextureId = Math.Min(Math.Max(x, 0), meshGroup.Texture.Count - 1); - }); - ForEdit("Unk08", () => vifPacket.Unk08, x => vifPacket.Unk08 = x); - ForEdit("Unk0c", () => vifPacket.Unk0c, x => vifPacket.Unk0c = x); - ForEdit("Alpha flag", () => vifPacket.IsTransparentFlag, x => vifPacket.IsTransparentFlag = x); - ImGui.Text("DMA per VIF dump:"); - ImGui.Text(string.Join(",", vifPacket.DmaPerVif.Select(x => $"{x}"))); - }); - } - }); - } - - for (var i = 0; i < meshGroup.Map.VifPackets.Count; i++) - { - } - } - } -} +using ImGuiNET; +using OpenKh.Tools.Kh2MapStudio.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; + +namespace OpenKh.Tools.Kh2MapStudio.Windows +{ + class MeshGroupWindow + { + public static bool Run(List meshGroups) => ForHeader("Mesh groups", () => + { + for (var i = 0; i < meshGroups.Count; i++) + { + MeshGroupModel meshGroup = meshGroups[i]; + ForTreeNode(meshGroup.Name, () => MeshGroup(meshGroup, i)); + } + }); + + private static void MeshGroup(MeshGroupModel meshGroup, int index) + { + if (ImGui.SmallButton("Apply changes")) + meshGroup.Invalidate(); + + ForEdit("Unk04", () => meshGroup.Map.unk04, x => meshGroup.Map.unk04 = x); + ForEdit("Unk08", () => meshGroup.Map.unk08, x => meshGroup.Map.unk08 = x); + ForEdit("VA4", () => meshGroup.Map.va4, x => meshGroup.Map.va4 = x); + + for (var i = 0; i < meshGroup.Map.vifPacketRenderingGroup.Count; i++) + { + ForTreeNode($"Mesh Rendering Group {i}##{index}", () => + { + var group = meshGroup.Map.vifPacketRenderingGroup[i]; + for (var j = 0; j < group.Length; j++) + { + var meshIndex = group[j]; + ForTreeNode($"Index {j}, Mesh {meshIndex}##{index}", () => + { + var vifPacket = meshGroup.Map.VifPackets[meshIndex]; + ForEdit("Texture", () => vifPacket.TextureId, x => + { + vifPacket.TextureId = Math.Min(Math.Max(x, 0), meshGroup.Texture.Count - 1); + }); + ForEdit("Unk08", () => vifPacket.Unk08, x => vifPacket.Unk08 = x); + ForEdit("Unk0c", () => vifPacket.Unk0c, x => vifPacket.Unk0c = x); + ForEdit("Alpha flag", () => vifPacket.IsTransparentFlag, x => vifPacket.IsTransparentFlag = x); + ImGui.Text("DMA per VIF dump:"); + ImGui.Text(string.Join(",", vifPacket.DmaPerVif.Select(x => $"{x}"))); + }); + } + }); + } + + for (var i = 0; i < meshGroup.Map.VifPackets.Count; i++) + { + } + } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Windows/SpawnPointWindow.cs b/OpenKh.Tools.Kh2MapStudio/Windows/SpawnPointWindow.cs index 8ad881af5..59d22d74f 100644 --- a/OpenKh.Tools.Kh2MapStudio/Windows/SpawnPointWindow.cs +++ b/OpenKh.Tools.Kh2MapStudio/Windows/SpawnPointWindow.cs @@ -1,205 +1,205 @@ -using ImGuiNET; -using OpenKh.Kh2.Ard; -using OpenKh.Tools.Kh2MapStudio.Interfaces; -using OpenKh.Tools.Kh2MapStudio.Models; -using System; -using System.Linq; -using System.Numerics; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; - -namespace OpenKh.Tools.Kh2MapStudio.Windows -{ - static class SpawnPointWindow - { - private static string ObjectFilter = ""; - private static ISpawnPointController _ctrl; - - public static bool Run(ISpawnPointController ctrl) => ForHeader("Spawn point editor", () => - { - _ctrl = ctrl; - if (ImGui.BeginCombo("Spawn point", ctrl.SelectSpawnPoint)) - { - foreach (var spawnPoint in ctrl.SpawnPoints) - { - if (ImGui.Selectable(spawnPoint.Name, spawnPoint.Name == ctrl.SelectSpawnPoint)) - { - ctrl.SelectSpawnPoint = spawnPoint.Name; - } - } - - ImGui.EndCombo(); - } - - if (ctrl.CurrentSpawnPoint != null) - Run(ctrl.CurrentSpawnPoint); - }); - - private static void Run(SpawnPointModel model) - { - for (int i = 0; i < model.SpawnPoints.Count; i++) - { - var spawnGroup = model.SpawnPoints[i]; - if (ImGui.CollapsingHeader($"Spawn group #{i}")) - { - Run(spawnGroup, i); - } - } - } - - private static void Run(SpawnPoint point, int index) - { - ForEdit($"Type##{index}", () => point.Type, x => point.Type = x); - ForEdit($"Flag##{index}", () => point.Flag, x => point.Flag = x); - ForEdit($"Id##{index}", () => point.Id, x => point.Id = x); - ForEdit($"Unk20##{index}", () => point.Unk20, x => point.Unk20 = x); - ForEdit($"Unk24##{index}", () => point.Unk24, x => point.Unk24 = x); - - ImGui.Separator(); - ImGui.Text($"Map teleport##{index}"); - ForEdit($"Place##{index}", () => point.Teleport.Place, x => point.Teleport.Place = x); - ForEdit($"Door##{index}", () => point.Teleport.Door, x => point.Teleport.Door = x); - ForEdit($"World##{index}", () => point.Teleport.World, x => point.Teleport.World = x); - ForEdit($"Unknown##{index}", () => point.Teleport.Unknown, x => point.Teleport.Unknown = x); - ImGui.Separator(); - - for (var i = 0; i < point.Entities.Count; i++) - ForTreeNode($"Entity #{index}-{i}", () => Run(point.Entities[i], i)); - - for (var i = 0; i < point.EventActivators.Count; i++) - ForTreeNode($"Event activator #{index}-{i}", () => Run(point.EventActivators[i], i)); - - for (var i = 0; i < point.WalkPath.Count; i++) - ForTreeNode($"Walking path #{index}-{i}", () => Run(point.WalkPath[i], i)); - - for (var i = 0; i < point.ReturnParameters.Count; i++) - ForTreeNode($"Parameter #{index}-{i}", () => Run(point.ReturnParameters[i], i)); - - for (var i = 0; i < point.Signals.Count; i++) - ForTreeNode($"Signal #{index}-{i}", () => Run(point.Signals[i], i)); - } - - private static void Run(SpawnPoint.Entity entity, int index) - { - var objs = _ctrl.CurrentSpawnPoint.ObjEntryCtrl; - if (ImGui.BeginCombo($"Object##{index}", objs.GetName(entity.ObjectId))) - { - var filter = ObjectFilter; - if (ImGui.InputText($"Filter##{index}", ref filter, 16)) - ObjectFilter = filter; - - foreach (var obj in objs.ObjectEntries.Where(x => filter.Length == 0 || x.ModelName.Contains(filter))) - { - if (ImGui.Selectable(obj.ModelName, obj.ObjectId == entity.ObjectId)) - entity.ObjectId = (int)obj.ObjectId; - } - - ImGui.EndCombo(); - } - - ForEdit3($"Position##{index}", () => - new Vector3(entity.PositionX, entity.PositionY, entity.PositionZ), - x => - { - entity.PositionX = x.X; - entity.PositionY = x.Y; - entity.PositionZ = x.Z; - }); - - ForEdit3($"Rotation##{index}", () => - new Vector3( - (float)(entity.RotationX * 180f / Math.PI), - (float)(entity.RotationY * 180f / Math.PI), - (float)(entity.RotationZ * 180f / Math.PI)), - x => - { - entity.RotationX = (float)(x.X / 180f * Math.PI); - entity.RotationY = (float)(x.Y / 180f * Math.PI); - entity.RotationZ = (float)(x.Z / 180f * Math.PI); - }); - - ForEdit($"Spawn type##{index}", () => entity.SpawnType, x => entity.SpawnType = x); - ForEdit($"Spawn arg##{index}", () => entity.SpawnArgument, x => entity.SpawnArgument = x); - ForEdit($"Serial##{index}", () => entity.Serial, x => entity.Serial = x); - ForEdit($"Argument 1##{index}", () => entity.Argument1, x => entity.Argument1 = x); - ForEdit($"Argument 2##{index}", () => entity.Argument2, x => entity.Argument2 = x); - ForEdit($"Reaction command##{index}", () => entity.ReactionCommand, x => entity.ReactionCommand = x); - ForEdit($"Spawn delay##{index}", () => entity.SpawnDelay, x => entity.SpawnDelay = x); - ForEdit($"Command##{index}", () => entity.Command, x => entity.Command = x); - ForEdit($"Spawn range##{index}", () => entity.SpawnRange, x => entity.SpawnRange = x); - ForEdit($"Level##{index}", () => entity.Level, x => entity.Level = x); - ForEdit($"Medal##{index}", () => entity.Medal, x => entity.Medal = x); - } - - private static void Run(SpawnPoint.EventActivator item, int index) - { - ForEdit($"Shape##{index}", () => item.Shape, x => item.Shape = x); - ForEdit($"Option##{index}", () => item.Option, x => item.Option = x); - ForEdit($"Flags##{index}", () => item.Flags, x => item.Flags = x); - ForEdit($"Type##{index}", () => item.Type, x => item.Type = x); - ForEdit($"BG group ON##{index}", () => item.OnBgGroup, x => item.OnBgGroup = x); - ForEdit($"BG group OFF##{index}", () => item.OffBgGroup, x => item.OffBgGroup = x); - ForEdit3($"Position##{index}", () => - new Vector3(item.PositionX, item.PositionY, item.PositionZ), - x => - { - item.PositionX = x.X; - item.PositionY = x.Y; - item.PositionZ = x.Z; - }); - ForEdit3($"Scale##{index}", () => - new Vector3(item.ScaleX, item.ScaleY, item.ScaleZ), - x => - { - item.ScaleX = x.X; - item.ScaleY = x.Y; - item.ScaleZ = x.Z; - }, 1f); - - ForEdit3($"Rotation##{index}", () => - new Vector3( - (float)(item.RotationX * 180f / Math.PI), - (float)(item.RotationY * 180f / Math.PI), - (float)(item.RotationZ * 180f / Math.PI)), - x => - { - item.RotationX = (float)(x.X / 180f * Math.PI); - item.RotationY = (float)(x.Y / 180f * Math.PI); - item.RotationZ = (float)(x.Z / 180f * Math.PI); - }); - } - - private static void Run(SpawnPoint.WalkPathDesc item, int index) - { - ForEdit($"Serial##{index}", () => item.Serial, x => item.Serial = x); - ForEdit($"Flag##{index}", () => item.Flag, x => item.Flag = x); - ForEdit($"Id##{index}", () => item.Id, x => item.Id = x); - for (var i = 0; i < item.Positions.Count; i++) - { - var pos = item.Positions[i]; - ForEdit3($"Walk #{index}-{i}", () => - new Vector3(pos.X, pos.Y, pos.Z), - x => - { - pos.X = x.X; - pos.Y = x.Y; - pos.Z = x.Z; - }); - } - } - - private static void Run(SpawnPoint.ReturnParameter item, int index) - { - ForEdit($"Unk00##{index}", () => item.Id, x => item.Id = x); - ForEdit($"Unk01##{index}", () => item.Type, x => item.Type = x); - ForEdit($"Unk02##{index}", () => item.Rate, x => item.Rate = x); - ForEdit($"Unk03##{index}", () => item.EntryType, x => item.EntryType = x); - } - - private static void Run(SpawnPoint.Signal item, int index) - { - ForEdit($"Signal ID##{index}", () => item.SignalId, x => item.SignalId = x); - ForEdit($"Argument##{index}", () => item.Argument, x => item.Argument = x); - ForEdit($"Action##{index}", () => item.Action, x => item.Action = x); - } - } -} +using ImGuiNET; +using OpenKh.Kh2.Ard; +using OpenKh.Tools.Kh2MapStudio.Interfaces; +using OpenKh.Tools.Kh2MapStudio.Models; +using System; +using System.Linq; +using System.Numerics; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; + +namespace OpenKh.Tools.Kh2MapStudio.Windows +{ + static class SpawnPointWindow + { + private static string ObjectFilter = ""; + private static ISpawnPointController _ctrl; + + public static bool Run(ISpawnPointController ctrl) => ForHeader("Spawn point editor", () => + { + _ctrl = ctrl; + if (ImGui.BeginCombo("Spawn point", ctrl.SelectSpawnPoint)) + { + foreach (var spawnPoint in ctrl.SpawnPoints) + { + if (ImGui.Selectable(spawnPoint.Name, spawnPoint.Name == ctrl.SelectSpawnPoint)) + { + ctrl.SelectSpawnPoint = spawnPoint.Name; + } + } + + ImGui.EndCombo(); + } + + if (ctrl.CurrentSpawnPoint != null) + Run(ctrl.CurrentSpawnPoint); + }); + + private static void Run(SpawnPointModel model) + { + for (int i = 0; i < model.SpawnPoints.Count; i++) + { + var spawnGroup = model.SpawnPoints[i]; + if (ImGui.CollapsingHeader($"Spawn group #{i}")) + { + Run(spawnGroup, i); + } + } + } + + private static void Run(SpawnPoint point, int index) + { + ForEdit($"Type##{index}", () => point.Type, x => point.Type = x); + ForEdit($"Flag##{index}", () => point.Flag, x => point.Flag = x); + ForEdit($"Id##{index}", () => point.Id, x => point.Id = x); + ForEdit($"Unk20##{index}", () => point.Unk20, x => point.Unk20 = x); + ForEdit($"Unk24##{index}", () => point.Unk24, x => point.Unk24 = x); + + ImGui.Separator(); + ImGui.Text($"Map teleport##{index}"); + ForEdit($"Place##{index}", () => point.Teleport.Place, x => point.Teleport.Place = x); + ForEdit($"Door##{index}", () => point.Teleport.Door, x => point.Teleport.Door = x); + ForEdit($"World##{index}", () => point.Teleport.World, x => point.Teleport.World = x); + ForEdit($"Unknown##{index}", () => point.Teleport.Unknown, x => point.Teleport.Unknown = x); + ImGui.Separator(); + + for (var i = 0; i < point.Entities.Count; i++) + ForTreeNode($"Entity #{index}-{i}", () => Run(point.Entities[i], i)); + + for (var i = 0; i < point.EventActivators.Count; i++) + ForTreeNode($"Event activator #{index}-{i}", () => Run(point.EventActivators[i], i)); + + for (var i = 0; i < point.WalkPath.Count; i++) + ForTreeNode($"Walking path #{index}-{i}", () => Run(point.WalkPath[i], i)); + + for (var i = 0; i < point.ReturnParameters.Count; i++) + ForTreeNode($"Parameter #{index}-{i}", () => Run(point.ReturnParameters[i], i)); + + for (var i = 0; i < point.Signals.Count; i++) + ForTreeNode($"Signal #{index}-{i}", () => Run(point.Signals[i], i)); + } + + private static void Run(SpawnPoint.Entity entity, int index) + { + var objs = _ctrl.CurrentSpawnPoint.ObjEntryCtrl; + if (ImGui.BeginCombo($"Object##{index}", objs.GetName(entity.ObjectId))) + { + var filter = ObjectFilter; + if (ImGui.InputText($"Filter##{index}", ref filter, 16)) + ObjectFilter = filter; + + foreach (var obj in objs.ObjectEntries.Where(x => filter.Length == 0 || x.ModelName.Contains(filter))) + { + if (ImGui.Selectable(obj.ModelName, obj.ObjectId == entity.ObjectId)) + entity.ObjectId = (int)obj.ObjectId; + } + + ImGui.EndCombo(); + } + + ForEdit3($"Position##{index}", () => + new Vector3(entity.PositionX, entity.PositionY, entity.PositionZ), + x => + { + entity.PositionX = x.X; + entity.PositionY = x.Y; + entity.PositionZ = x.Z; + }); + + ForEdit3($"Rotation##{index}", () => + new Vector3( + (float)(entity.RotationX * 180f / Math.PI), + (float)(entity.RotationY * 180f / Math.PI), + (float)(entity.RotationZ * 180f / Math.PI)), + x => + { + entity.RotationX = (float)(x.X / 180f * Math.PI); + entity.RotationY = (float)(x.Y / 180f * Math.PI); + entity.RotationZ = (float)(x.Z / 180f * Math.PI); + }); + + ForEdit($"Spawn type##{index}", () => entity.SpawnType, x => entity.SpawnType = x); + ForEdit($"Spawn arg##{index}", () => entity.SpawnArgument, x => entity.SpawnArgument = x); + ForEdit($"Serial##{index}", () => entity.Serial, x => entity.Serial = x); + ForEdit($"Argument 1##{index}", () => entity.Argument1, x => entity.Argument1 = x); + ForEdit($"Argument 2##{index}", () => entity.Argument2, x => entity.Argument2 = x); + ForEdit($"Reaction command##{index}", () => entity.ReactionCommand, x => entity.ReactionCommand = x); + ForEdit($"Spawn delay##{index}", () => entity.SpawnDelay, x => entity.SpawnDelay = x); + ForEdit($"Command##{index}", () => entity.Command, x => entity.Command = x); + ForEdit($"Spawn range##{index}", () => entity.SpawnRange, x => entity.SpawnRange = x); + ForEdit($"Level##{index}", () => entity.Level, x => entity.Level = x); + ForEdit($"Medal##{index}", () => entity.Medal, x => entity.Medal = x); + } + + private static void Run(SpawnPoint.EventActivator item, int index) + { + ForEdit($"Shape##{index}", () => item.Shape, x => item.Shape = x); + ForEdit($"Option##{index}", () => item.Option, x => item.Option = x); + ForEdit($"Flags##{index}", () => item.Flags, x => item.Flags = x); + ForEdit($"Type##{index}", () => item.Type, x => item.Type = x); + ForEdit($"BG group ON##{index}", () => item.OnBgGroup, x => item.OnBgGroup = x); + ForEdit($"BG group OFF##{index}", () => item.OffBgGroup, x => item.OffBgGroup = x); + ForEdit3($"Position##{index}", () => + new Vector3(item.PositionX, item.PositionY, item.PositionZ), + x => + { + item.PositionX = x.X; + item.PositionY = x.Y; + item.PositionZ = x.Z; + }); + ForEdit3($"Scale##{index}", () => + new Vector3(item.ScaleX, item.ScaleY, item.ScaleZ), + x => + { + item.ScaleX = x.X; + item.ScaleY = x.Y; + item.ScaleZ = x.Z; + }, 1f); + + ForEdit3($"Rotation##{index}", () => + new Vector3( + (float)(item.RotationX * 180f / Math.PI), + (float)(item.RotationY * 180f / Math.PI), + (float)(item.RotationZ * 180f / Math.PI)), + x => + { + item.RotationX = (float)(x.X / 180f * Math.PI); + item.RotationY = (float)(x.Y / 180f * Math.PI); + item.RotationZ = (float)(x.Z / 180f * Math.PI); + }); + } + + private static void Run(SpawnPoint.WalkPathDesc item, int index) + { + ForEdit($"Serial##{index}", () => item.Serial, x => item.Serial = x); + ForEdit($"Flag##{index}", () => item.Flag, x => item.Flag = x); + ForEdit($"Id##{index}", () => item.Id, x => item.Id = x); + for (var i = 0; i < item.Positions.Count; i++) + { + var pos = item.Positions[i]; + ForEdit3($"Walk #{index}-{i}", () => + new Vector3(pos.X, pos.Y, pos.Z), + x => + { + pos.X = x.X; + pos.Y = x.Y; + pos.Z = x.Z; + }); + } + } + + private static void Run(SpawnPoint.ReturnParameter item, int index) + { + ForEdit($"Unk00##{index}", () => item.Id, x => item.Id = x); + ForEdit($"Unk01##{index}", () => item.Type, x => item.Type = x); + ForEdit($"Unk02##{index}", () => item.Rate, x => item.Rate = x); + ForEdit($"Unk03##{index}", () => item.EntryType, x => item.EntryType = x); + } + + private static void Run(SpawnPoint.Signal item, int index) + { + ForEdit($"Signal ID##{index}", () => item.SignalId, x => item.SignalId = x); + ForEdit($"Argument##{index}", () => item.Argument, x => item.Argument = x); + ForEdit($"Action##{index}", () => item.Action, x => item.Action = x); + } + } +} diff --git a/OpenKh.Tools.Kh2MapStudio/Windows/SpawnScriptWindow.cs b/OpenKh.Tools.Kh2MapStudio/Windows/SpawnScriptWindow.cs index 1949d4f93..75b91a701 100644 --- a/OpenKh.Tools.Kh2MapStudio/Windows/SpawnScriptWindow.cs +++ b/OpenKh.Tools.Kh2MapStudio/Windows/SpawnScriptWindow.cs @@ -1,32 +1,32 @@ -using ImGuiNET; -using OpenKh.Tools.Kh2MapStudio.Models; -using System.Numerics; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; - -namespace OpenKh.Tools.Kh2MapStudio.Windows -{ - static class SpawnScriptWindow - { - private static readonly Vector4 ErrorColor = new Vector4(1.0f, 0.0f, 0.0f, 1.0f); - private static readonly Vector4 SuccessColor = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); - - public static bool Run(string type, SpawnScriptModel model) => ForHeader($"Spawn Script compiler for {type}", () => - { - if (model == null) - { - ImGui.Text($"Unable to find for '{type}'."); - return; - } - - if (ImGui.Button($"Compile##{type}")) - model.Compile(); - - if (!string.IsNullOrEmpty(model.LastError)) - ImGui.TextColored(model.IsError ? ErrorColor : SuccessColor, model.LastError); - - var code = model.Decompiled; - if (ImGui.InputTextMultiline($"code##{type}", ref code, 0x100000, new Vector2(0, 0))) - model.Decompiled = code; - }); - } -} +using ImGuiNET; +using OpenKh.Tools.Kh2MapStudio.Models; +using System.Numerics; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; + +namespace OpenKh.Tools.Kh2MapStudio.Windows +{ + static class SpawnScriptWindow + { + private static readonly Vector4 ErrorColor = new Vector4(1.0f, 0.0f, 0.0f, 1.0f); + private static readonly Vector4 SuccessColor = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); + + public static bool Run(string type, SpawnScriptModel model) => ForHeader($"Spawn Script compiler for {type}", () => + { + if (model == null) + { + ImGui.Text($"Unable to find for '{type}'."); + return; + } + + if (ImGui.Button($"Compile##{type}")) + model.Compile(); + + if (!string.IsNullOrEmpty(model.LastError)) + ImGui.TextColored(model.IsError ? ErrorColor : SuccessColor, model.LastError); + + var code = model.Decompiled; + if (ImGui.InputTextMultiline($"code##{type}", ref code, 0x100000, new Vector2(0, 0))) + model.Decompiled = code; + }); + } +} diff --git a/OpenKh.Tools.Kh2PlaceEditor/App.xaml.cs b/OpenKh.Tools.Kh2PlaceEditor/App.xaml.cs index fa19854df..0db0ae80b 100644 --- a/OpenKh.Tools.Kh2PlaceEditor/App.xaml.cs +++ b/OpenKh.Tools.Kh2PlaceEditor/App.xaml.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; - -namespace OpenKh.Tools.Kh2PlaceEditor -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace OpenKh.Tools.Kh2PlaceEditor +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/OpenKh.Tools.Kh2PlaceEditor/Converters/EnumMatchToBooleanConverter.cs b/OpenKh.Tools.Kh2PlaceEditor/Converters/EnumMatchToBooleanConverter.cs index d2021bf8f..423c3c5e2 100644 --- a/OpenKh.Tools.Kh2PlaceEditor/Converters/EnumMatchToBooleanConverter.cs +++ b/OpenKh.Tools.Kh2PlaceEditor/Converters/EnumMatchToBooleanConverter.cs @@ -1,33 +1,33 @@ -using System; -using System.Globalization; -using System.Windows.Data; - -namespace OpenKh.Tools.Kh2PlaceEditor.Converters -{ - public class EnumMatchToBooleanConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value == null || parameter == null) - return false; - - string checkValue = value.ToString(); - string targetValue = parameter.ToString(); - return checkValue.Equals(targetValue, - StringComparison.InvariantCultureIgnoreCase); - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value == null || parameter == null) - return null; - - bool useValue = (bool)value; - string targetValue = parameter.ToString(); - if (useValue) - return Enum.Parse(targetType, targetValue); - - return null; - } - } -} +using System; +using System.Globalization; +using System.Windows.Data; + +namespace OpenKh.Tools.Kh2PlaceEditor.Converters +{ + public class EnumMatchToBooleanConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null || parameter == null) + return false; + + string checkValue = value.ToString(); + string targetValue = parameter.ToString(); + return checkValue.Equals(targetValue, + StringComparison.InvariantCultureIgnoreCase); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null || parameter == null) + return null; + + bool useValue = (bool)value; + string targetValue = parameter.ToString(); + if (useValue) + return Enum.Parse(targetType, targetValue); + + return null; + } + } +} diff --git a/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlaceEditorViewModel.cs b/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlaceEditorViewModel.cs index fe18b81f6..c9cc62ac9 100644 --- a/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlaceEditorViewModel.cs +++ b/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlaceEditorViewModel.cs @@ -1,168 +1,168 @@ -using OpenKh.Common; -using OpenKh.Engine; -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using OpenKh.Tools.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Windows; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.Kh2PlaceEditor.ViewModels -{ - public class PlaceEditorViewModel : BaseNotifyPropertyChanged - { - public enum EncodingType - { - European, - Japanese - } - - private static readonly List Filters = FileDialogFilterComposer.Compose().AddExtensions("00place.bin or place.bin", "bin").AddAllFiles(); - private static readonly List CsvFilter = FileDialogFilterComposer.Compose().AddExtensions("Map names as CSV", "csv"); - private static readonly string ApplicationName = Utilities.GetApplicationName(); - - private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - private readonly Kh2MessageProvider _messageProvider; - private string _fileName; - private EncodingType _encoding; - - public string Title => $"{FileName ?? "untitled"} | {ApplicationName}"; - - public PlacesViewModel Places { get; private set; } - - private string FileName - { - get => _fileName; - set - { - _fileName = value; - OnPropertyChanged(nameof(Title)); - } - } - - public RelayCommand OpenCommand { get; } - public RelayCommand SaveCommand { get; } - public RelayCommand SaveAsCommand { get; } - public RelayCommand ExportAsCsvCommand { get; } - public RelayCommand ExitCommand { get; } - public RelayCommand AboutCommand { get; } - public RelayCommand LoadSupportIdxCommand { get; } - public RelayCommand LoadSupportMsgCommand { get; } - - public EncodingType Encoding - { - get => _encoding; - set - { - switch (_encoding = value) - { - case EncodingType.European: - _messageProvider.Encoder = Encoders.InternationalSystem; - break; - case EncodingType.Japanese: - _messageProvider.Encoder = Encoders.JapaneseSystem; - break; - } - - Places.RefreshAllMessages(); - } - } - - public PlaceEditorViewModel() - { - OpenCommand = new RelayCommand(x => Utilities.Catch(() => - { - FileDialog.OnOpen(fileName => - { - OpenFile(fileName); - }, Filters); - }), x => true); - - SaveCommand = new RelayCommand(x => Utilities.Catch(() => - { - if (!string.IsNullOrEmpty(FileName)) - SaveFile(FileName, FileName); - else - SaveAsCommand.Execute(x); - }), x => true); - - SaveAsCommand = new RelayCommand(x => Utilities.Catch(() => - { - FileDialog.OnSave(fileName => - { - SaveFile(FileName, fileName); - FileName = fileName; - }, Filters); - }), x => true); - - ExitCommand = new RelayCommand(x => - { - Window.Close(); - }, x => true); - - AboutCommand = new RelayCommand(x => - { - new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); - }, x => true); - - ExportAsCsvCommand = new RelayCommand(_ => - { - FileDialog.OnSave(fileName => new StreamWriter(fileName, false, new UTF8Encoding(true)).Using(writer => - { - foreach (var place in Places?.Items?.Cast() ?? new PlaceViewModel[0]) - { - var row = new string[] - { - place.Map, - place.MessageId.ToString(), - place.Name, - place.Message - } - .Select(x => $"\"{x}\""); - - writer.WriteLine(string.Join(",", row)); - } - }) - , CsvFilter); - }); - - LoadSupportIdxCommand = new RelayCommand(_ => Utilities.Catch(() => - { - Kh2Utilities.OpenMsgFromIdxDialog(LoadMessages); - })); - LoadSupportMsgCommand = new RelayCommand(_ => Utilities.Catch(() => - { - Kh2Utilities.OpenMsgFromBarDialog(LoadMessages); - })); - - _messageProvider = new Kh2MessageProvider(); - } - - public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => - { - Places = new PlacesViewModel(_messageProvider, Place.Read(stream)); - FileName = fileName; - - OnPropertyChanged(nameof(Places)); - return true; - }); - - public void SaveFile(string previousFileName, string fileName) - { - using (var f = File.Create(fileName)) - Kh2.Place.Write(f, Places.Places); - } - - private void LoadMessages(List msgs) - { - _messageProvider.Load(msgs); - Places.RefreshAllMessages(); - } - } -} +using OpenKh.Common; +using OpenKh.Engine; +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using OpenKh.Tools.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Windows; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.Kh2PlaceEditor.ViewModels +{ + public class PlaceEditorViewModel : BaseNotifyPropertyChanged + { + public enum EncodingType + { + European, + Japanese + } + + private static readonly List Filters = FileDialogFilterComposer.Compose().AddExtensions("00place.bin or place.bin", "bin").AddAllFiles(); + private static readonly List CsvFilter = FileDialogFilterComposer.Compose().AddExtensions("Map names as CSV", "csv"); + private static readonly string ApplicationName = Utilities.GetApplicationName(); + + private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + private readonly Kh2MessageProvider _messageProvider; + private string _fileName; + private EncodingType _encoding; + + public string Title => $"{FileName ?? "untitled"} | {ApplicationName}"; + + public PlacesViewModel Places { get; private set; } + + private string FileName + { + get => _fileName; + set + { + _fileName = value; + OnPropertyChanged(nameof(Title)); + } + } + + public RelayCommand OpenCommand { get; } + public RelayCommand SaveCommand { get; } + public RelayCommand SaveAsCommand { get; } + public RelayCommand ExportAsCsvCommand { get; } + public RelayCommand ExitCommand { get; } + public RelayCommand AboutCommand { get; } + public RelayCommand LoadSupportIdxCommand { get; } + public RelayCommand LoadSupportMsgCommand { get; } + + public EncodingType Encoding + { + get => _encoding; + set + { + switch (_encoding = value) + { + case EncodingType.European: + _messageProvider.Encoder = Encoders.InternationalSystem; + break; + case EncodingType.Japanese: + _messageProvider.Encoder = Encoders.JapaneseSystem; + break; + } + + Places.RefreshAllMessages(); + } + } + + public PlaceEditorViewModel() + { + OpenCommand = new RelayCommand(x => Utilities.Catch(() => + { + FileDialog.OnOpen(fileName => + { + OpenFile(fileName); + }, Filters); + }), x => true); + + SaveCommand = new RelayCommand(x => Utilities.Catch(() => + { + if (!string.IsNullOrEmpty(FileName)) + SaveFile(FileName, FileName); + else + SaveAsCommand.Execute(x); + }), x => true); + + SaveAsCommand = new RelayCommand(x => Utilities.Catch(() => + { + FileDialog.OnSave(fileName => + { + SaveFile(FileName, fileName); + FileName = fileName; + }, Filters); + }), x => true); + + ExitCommand = new RelayCommand(x => + { + Window.Close(); + }, x => true); + + AboutCommand = new RelayCommand(x => + { + new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); + }, x => true); + + ExportAsCsvCommand = new RelayCommand(_ => + { + FileDialog.OnSave(fileName => new StreamWriter(fileName, false, new UTF8Encoding(true)).Using(writer => + { + foreach (var place in Places?.Items?.Cast() ?? new PlaceViewModel[0]) + { + var row = new string[] + { + place.Map, + place.MessageId.ToString(), + place.Name, + place.Message + } + .Select(x => $"\"{x}\""); + + writer.WriteLine(string.Join(",", row)); + } + }) + , CsvFilter); + }); + + LoadSupportIdxCommand = new RelayCommand(_ => Utilities.Catch(() => + { + Kh2Utilities.OpenMsgFromIdxDialog(LoadMessages); + })); + LoadSupportMsgCommand = new RelayCommand(_ => Utilities.Catch(() => + { + Kh2Utilities.OpenMsgFromBarDialog(LoadMessages); + })); + + _messageProvider = new Kh2MessageProvider(); + } + + public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => + { + Places = new PlacesViewModel(_messageProvider, Place.Read(stream)); + FileName = fileName; + + OnPropertyChanged(nameof(Places)); + return true; + }); + + public void SaveFile(string previousFileName, string fileName) + { + using (var f = File.Create(fileName)) + Kh2.Place.Write(f, Places.Places); + } + + private void LoadMessages(List msgs) + { + _messageProvider.Load(msgs); + Places.RefreshAllMessages(); + } + } +} diff --git a/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlaceViewModel.cs b/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlaceViewModel.cs index f2616200e..44ce9401e 100644 --- a/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlaceViewModel.cs +++ b/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlaceViewModel.cs @@ -1,61 +1,61 @@ -using OpenKh.Engine; -using OpenKh.Kh2; -using System.Text; -using Xe.Tools; - -namespace OpenKh.Tools.Kh2PlaceEditor.ViewModels -{ - public class PlaceViewModel : BaseNotifyPropertyChanged - { - private const int ShiftJisCodepage = 932; - private readonly Encoding Encoding = Encoding.GetEncoding(ShiftJisCodepage); - - private readonly IMessageProvider _messageProvider; - private readonly int _index; - - static PlaceViewModel() - { - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); - } - - public PlaceViewModel(IMessageProvider messageProvider, - string world, int index, Place place) - { - _messageProvider = messageProvider; - World = world; - _index = index; - Place = place; - } - - public string World { get; } - - public Place Place { get; } - - public string Map => $"{World}{_index:D02}"; - - public short MessageId - { - get => (short)(Place.MessageId & 0x7fff); - set - { - Place.MessageId = (ushort)(value | 0x8000); - OnPropertyChanged(nameof(Name)); - OnPropertyChanged(nameof(Message)); - } - } - - public string Name - { - get => Encoding.GetString(Place.Name); - set => Place.Name = Encoding.GetBytes(value); - } - - public string Message => _messageProvider.GetString(Place.MessageId); - - public void RefreshMessages() - { - OnPropertyChanged(nameof(Name)); - OnPropertyChanged(nameof(Message)); - } - } -} +using OpenKh.Engine; +using OpenKh.Kh2; +using System.Text; +using Xe.Tools; + +namespace OpenKh.Tools.Kh2PlaceEditor.ViewModels +{ + public class PlaceViewModel : BaseNotifyPropertyChanged + { + private const int ShiftJisCodepage = 932; + private readonly Encoding Encoding = Encoding.GetEncoding(ShiftJisCodepage); + + private readonly IMessageProvider _messageProvider; + private readonly int _index; + + static PlaceViewModel() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + } + + public PlaceViewModel(IMessageProvider messageProvider, + string world, int index, Place place) + { + _messageProvider = messageProvider; + World = world; + _index = index; + Place = place; + } + + public string World { get; } + + public Place Place { get; } + + public string Map => $"{World}{_index:D02}"; + + public short MessageId + { + get => (short)(Place.MessageId & 0x7fff); + set + { + Place.MessageId = (ushort)(value | 0x8000); + OnPropertyChanged(nameof(Name)); + OnPropertyChanged(nameof(Message)); + } + } + + public string Name + { + get => Encoding.GetString(Place.Name); + set => Place.Name = Encoding.GetBytes(value); + } + + public string Message => _messageProvider.GetString(Place.MessageId); + + public void RefreshMessages() + { + OnPropertyChanged(nameof(Name)); + OnPropertyChanged(nameof(Message)); + } + } +} diff --git a/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlacesViewModel.cs b/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlacesViewModel.cs index 781359ee8..b33673244 100644 --- a/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlacesViewModel.cs +++ b/OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlacesViewModel.cs @@ -1,45 +1,45 @@ -using OpenKh.Engine; -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.Kh2PlaceEditor.ViewModels -{ - public class PlacesViewModel - { - private readonly IMessageProvider _messageProvider; - - public PlacesViewModel(IMessageProvider messageProvider, Dictionary> places) - { - _messageProvider = messageProvider; - Items = new GenericListModel(places - .Select(x => new - { - World = x.Key, - Places = x.Value.Select((place, i) => new - { - Index = i, - Place = place - }) - }) - .SelectMany(x => x.Places, (x, place) => new PlaceViewModel(_messageProvider, x.World, place.Index, place.Place)) - ); - } - - - public GenericListModel Items { get; } - - public Dictionary> Places => Items - .GroupBy(x => x.World) - .ToDictionary(x => x.Key, x => x.Select(vm => vm.Place).ToList()); - - public void RefreshAllMessages() - { - foreach (var item in Items) - (item as PlaceViewModel)?.RefreshMessages(); - } - } -} +using OpenKh.Engine; +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.Kh2PlaceEditor.ViewModels +{ + public class PlacesViewModel + { + private readonly IMessageProvider _messageProvider; + + public PlacesViewModel(IMessageProvider messageProvider, Dictionary> places) + { + _messageProvider = messageProvider; + Items = new GenericListModel(places + .Select(x => new + { + World = x.Key, + Places = x.Value.Select((place, i) => new + { + Index = i, + Place = place + }) + }) + .SelectMany(x => x.Places, (x, place) => new PlaceViewModel(_messageProvider, x.World, place.Index, place.Place)) + ); + } + + + public GenericListModel Items { get; } + + public Dictionary> Places => Items + .GroupBy(x => x.World) + .ToDictionary(x => x.Key, x => x.Select(vm => vm.Place).ToList()); + + public void RefreshAllMessages() + { + foreach (var item in Items) + (item as PlaceViewModel)?.RefreshMessages(); + } + } +} diff --git a/OpenKh.Tools.Kh2PlaceEditor/Views/PlaceEditorWindow.xaml.cs b/OpenKh.Tools.Kh2PlaceEditor/Views/PlaceEditorWindow.xaml.cs index d6af38736..dea12e8cb 100644 --- a/OpenKh.Tools.Kh2PlaceEditor/Views/PlaceEditorWindow.xaml.cs +++ b/OpenKh.Tools.Kh2PlaceEditor/Views/PlaceEditorWindow.xaml.cs @@ -1,17 +1,17 @@ -using OpenKh.Tools.Kh2PlaceEditor.ViewModels; -using System.Windows; - -namespace OpenKh.Tools.Kh2PlaceEditor.Views -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class PlaceEditorWindow : Window - { - public PlaceEditorWindow() - { - InitializeComponent(); - DataContext = new PlaceEditorViewModel(); - } - } -} +using OpenKh.Tools.Kh2PlaceEditor.ViewModels; +using System.Windows; + +namespace OpenKh.Tools.Kh2PlaceEditor.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class PlaceEditorWindow : Window + { + public PlaceEditorWindow() + { + InitializeComponent(); + DataContext = new PlaceEditorViewModel(); + } + } +} diff --git a/OpenKh.Tools.Kh2PlaceEditor/Views/PlacesView.xaml.cs b/OpenKh.Tools.Kh2PlaceEditor/Views/PlacesView.xaml.cs index 62fa6aeb7..4bef6998b 100644 --- a/OpenKh.Tools.Kh2PlaceEditor/Views/PlacesView.xaml.cs +++ b/OpenKh.Tools.Kh2PlaceEditor/Views/PlacesView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace OpenKh.Tools.Kh2PlaceEditor.Views -{ - /// - /// Interaction logic for PlacesView.xaml - /// - public partial class PlacesView : UserControl - { - public PlacesView() - { - InitializeComponent(); - } - } -} +using System.Windows.Controls; + +namespace OpenKh.Tools.Kh2PlaceEditor.Views +{ + /// + /// Interaction logic for PlacesView.xaml + /// + public partial class PlacesView : UserControl + { + public PlacesView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/App.xaml.cs b/OpenKh.Tools.Kh2SystemEditor/App.xaml.cs index 2fecbb7a6..db1300e7e 100644 --- a/OpenKh.Tools.Kh2SystemEditor/App.xaml.cs +++ b/OpenKh.Tools.Kh2SystemEditor/App.xaml.cs @@ -1,11 +1,11 @@ -using System.Windows; - -namespace OpenKh.Tools.Kh2SystemEditor -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} +using System.Windows; + +namespace OpenKh.Tools.Kh2SystemEditor +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Attributes/ExportTargetAttribute.cs b/OpenKh.Tools.Kh2SystemEditor/Attributes/ExportTargetAttribute.cs index a533fb655..6ddab5ea1 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Attributes/ExportTargetAttribute.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Attributes/ExportTargetAttribute.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; diff --git a/OpenKh.Tools.Kh2SystemEditor/Converters/EnumMatchToBooleanConverter.cs b/OpenKh.Tools.Kh2SystemEditor/Converters/EnumMatchToBooleanConverter.cs index 84ca525ce..71d65509f 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Converters/EnumMatchToBooleanConverter.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Converters/EnumMatchToBooleanConverter.cs @@ -1,33 +1,33 @@ -using System; -using System.Globalization; -using System.Windows.Data; - -namespace OpenKh.Tools.Kh2SystemEditor.Converters -{ - public class EnumMatchToBooleanConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value == null || parameter == null) - return false; - - string checkValue = value.ToString(); - string targetValue = parameter.ToString(); - return checkValue.Equals(targetValue, - StringComparison.InvariantCultureIgnoreCase); - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value == null || parameter == null) - return null; - - bool useValue = (bool)value; - string targetValue = parameter.ToString(); - if (useValue) - return Enum.Parse(targetType, targetValue); - - return null; - } - } -} +using System; +using System.Globalization; +using System.Windows.Data; + +namespace OpenKh.Tools.Kh2SystemEditor.Converters +{ + public class EnumMatchToBooleanConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null || parameter == null) + return false; + + string checkValue = value.ToString(); + string targetValue = parameter.ToString(); + return checkValue.Equals(targetValue, + StringComparison.InvariantCultureIgnoreCase); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null || parameter == null) + return null; + + bool useValue = (bool)value; + string targetValue = parameter.ToString(); + if (useValue) + return Enum.Parse(targetType, targetValue); + + return null; + } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Extensions/BarExtensions.cs b/OpenKh.Tools.Kh2SystemEditor/Extensions/BarExtensions.cs index 7e26c467d..f558fd398 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Extensions/BarExtensions.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Extensions/BarExtensions.cs @@ -1,15 +1,15 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace OpenKh.Tools.Kh2SystemEditor.Extensions -{ - public static class BarExtensions - { - public static Stream GetBinaryStream(this IEnumerable entries, string name) => - // TODO throws exception if that entry is not found - entries.First(x => x.Name == name && x.Index == 0 && x.Type == Bar.EntryType.List).Stream.SetPosition(0); - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenKh.Tools.Kh2SystemEditor.Extensions +{ + public static class BarExtensions + { + public static Stream GetBinaryStream(this IEnumerable entries, string name) => + // TODO throws exception if that entry is not found + entries.First(x => x.Name == name && x.Index == 0 && x.Type == Bar.EntryType.List).Stream.SetPosition(0); + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Interfaces/IItemEntry.cs b/OpenKh.Tools.Kh2SystemEditor/Interfaces/IItemEntry.cs index 864690484..1def2e52a 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Interfaces/IItemEntry.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Interfaces/IItemEntry.cs @@ -1,8 +1,8 @@ -namespace OpenKh.Tools.Kh2SystemEditor.Interfaces -{ - public interface IItemEntry - { - ushort Id { get; } - string Name { get; } - } -} +namespace OpenKh.Tools.Kh2SystemEditor.Interfaces +{ + public interface IItemEntry + { + ushort Id { get; } + string Name { get; } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Interfaces/IItemProvider.cs b/OpenKh.Tools.Kh2SystemEditor/Interfaces/IItemProvider.cs index bbffdba46..3c6fbc716 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Interfaces/IItemProvider.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Interfaces/IItemProvider.cs @@ -1,13 +1,13 @@ -using System.Collections.Generic; - -namespace OpenKh.Tools.Kh2SystemEditor.Interfaces -{ - public interface IItemProvider - { - IEnumerable ItemEntries { get; } - - bool IsItemExists(int itemId); - string GetItemName(int itemId); - void InvalidateItemName(int itemId); - } -} +using System.Collections.Generic; + +namespace OpenKh.Tools.Kh2SystemEditor.Interfaces +{ + public interface IItemProvider + { + IEnumerable ItemEntries { get; } + + bool IsItemExists(int itemId); + string GetItemName(int itemId); + void InvalidateItemName(int itemId); + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Interfaces/IObjectProvider.cs b/OpenKh.Tools.Kh2SystemEditor/Interfaces/IObjectProvider.cs index 907c5ed68..8be5a972a 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Interfaces/IObjectProvider.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Interfaces/IObjectProvider.cs @@ -1,12 +1,12 @@ -using OpenKh.Tools.Kh2SystemEditor.Models; -using System.Collections.Generic; - -namespace OpenKh.Tools.Kh2SystemEditor.Interfaces -{ - public interface IObjectProvider - { - IList Objects { get; } - - string GetObjectName(int id); - } -} +using OpenKh.Tools.Kh2SystemEditor.Models; +using System.Collections.Generic; + +namespace OpenKh.Tools.Kh2SystemEditor.Interfaces +{ + public interface IObjectProvider + { + IList Objects { get; } + + string GetObjectName(int id); + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Interfaces/ISystemGetChanges.cs b/OpenKh.Tools.Kh2SystemEditor/Interfaces/ISystemGetChanges.cs index a006a2724..4aa0e1704 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Interfaces/ISystemGetChanges.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Interfaces/ISystemGetChanges.cs @@ -1,11 +1,11 @@ -using System.IO; - -namespace OpenKh.Tools.Kh2SystemEditor.Interfaces -{ - public interface ISystemGetChanges - { - string EntryName { get; } - - Stream CreateStream(); - } -} +using System.IO; + +namespace OpenKh.Tools.Kh2SystemEditor.Interfaces +{ + public interface ISystemGetChanges + { + string EntryName { get; } + + Stream CreateStream(); + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Models/Export/ItemExport.cs b/OpenKh.Tools.Kh2SystemEditor/Models/Export/ItemExport.cs index 20fcab707..a85359581 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Models/Export/ItemExport.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Models/Export/ItemExport.cs @@ -1,62 +1,62 @@ -using OpenKh.Engine; -using OpenKh.Kh2.SystemData; -using OpenKh.Tools.Kh2SystemEditor.Attributes; -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Tools.Kh2SystemEditor.Models.Export -{ - public class ItemExport - { - private readonly IMessageProvider _messageProvider; - - public Item.Entry Item { get; } - - public ItemExport(IMessageProvider messageProvider, Item.Entry item) - { - _messageProvider = messageProvider; - Item = item; - } - - - [ExportTarget] - public string Title => $"{Item.Id:X02} {_messageProvider.GetString(Item.Name)}"; - - [ExportTarget] - public ushort Id => Item.Id; - [ExportTarget] - public Item.Type Type => Item.Type; - [ExportTarget] - public byte Flag0 => Item.Flag0; - [ExportTarget] - public byte Flag1 => Item.Flag1; - [ExportTarget] - public Item.Rank Rank => Item.Rank; - [ExportTarget] - public ushort StatEntry => Item.StatEntry; - [ExportTarget] - public ushort NameId => Item.Name; - [ExportTarget] - public ushort DescriptionId => Item.Description; - [ExportTarget] - public ushort ShopBuy => Item.ShopBuy; - [ExportTarget] - public ushort ShopSell => Item.ShopSell; - [ExportTarget] - public ushort Command => Item.Command; - [ExportTarget] - public ushort Slot => Item.Slot; - [ExportTarget] - public short Picture => Item.Picture; - [ExportTarget] - public byte Icon1 => Item.Icon1; - [ExportTarget] - public byte Icon2 => Item.Icon1; - - [ExportTarget] - public string Name => _messageProvider.GetString(Item.Name); - [ExportTarget] - public string Description => _messageProvider.GetString(Item.Description); - } -} +using OpenKh.Engine; +using OpenKh.Kh2.SystemData; +using OpenKh.Tools.Kh2SystemEditor.Attributes; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Tools.Kh2SystemEditor.Models.Export +{ + public class ItemExport + { + private readonly IMessageProvider _messageProvider; + + public Item.Entry Item { get; } + + public ItemExport(IMessageProvider messageProvider, Item.Entry item) + { + _messageProvider = messageProvider; + Item = item; + } + + + [ExportTarget] + public string Title => $"{Item.Id:X02} {_messageProvider.GetString(Item.Name)}"; + + [ExportTarget] + public ushort Id => Item.Id; + [ExportTarget] + public Item.Type Type => Item.Type; + [ExportTarget] + public byte Flag0 => Item.Flag0; + [ExportTarget] + public byte Flag1 => Item.Flag1; + [ExportTarget] + public Item.Rank Rank => Item.Rank; + [ExportTarget] + public ushort StatEntry => Item.StatEntry; + [ExportTarget] + public ushort NameId => Item.Name; + [ExportTarget] + public ushort DescriptionId => Item.Description; + [ExportTarget] + public ushort ShopBuy => Item.ShopBuy; + [ExportTarget] + public ushort ShopSell => Item.ShopSell; + [ExportTarget] + public ushort Command => Item.Command; + [ExportTarget] + public ushort Slot => Item.Slot; + [ExportTarget] + public short Picture => Item.Picture; + [ExportTarget] + public byte Icon1 => Item.Icon1; + [ExportTarget] + public byte Icon2 => Item.Icon1; + + [ExportTarget] + public string Name => _messageProvider.GetString(Item.Name); + [ExportTarget] + public string Description => _messageProvider.GetString(Item.Description); + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Models/Export/TrsrExport.cs b/OpenKh.Tools.Kh2SystemEditor/Models/Export/TrsrExport.cs index f4e40983c..964793e0c 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Models/Export/TrsrExport.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Models/Export/TrsrExport.cs @@ -1,50 +1,50 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.SystemData; -using OpenKh.Tools.Kh2SystemEditor.Attributes; -using OpenKh.Tools.Kh2SystemEditor.Interfaces; -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenKh.Tools.Kh2SystemEditor.Models.Export -{ - public class TrsrExport - { - public TrsrExport(IItemProvider itemProvider, Trsr treasure) - { - ItemProvider = itemProvider; - Treasure = treasure; - } - - public Trsr Treasure { get; } - public IItemProvider ItemProvider { get; } - - [ExportTarget] - public string Title => $"{Treasure.Id:X03} {MapName} {ItemName}"; - - [ExportTarget] - public ushort Id => Treasure.Id; - - [ExportTarget] - public ushort ItemId => Treasure.ItemId; - [ExportTarget] - public Trsr.TrsrType Type => Treasure.Type; - [ExportTarget] - public World World => (World)Treasure.World; - [ExportTarget] - public byte Room => Treasure.Room; - [ExportTarget] - public byte RoomChestIndex => Treasure.RoomChestIndex; - [ExportTarget] - public short EventId => Treasure.EventId; - [ExportTarget] - public short OverallChestIndex => Treasure.OverallChestIndex; - - [ExportTarget] - public string IdText => $"{Id} (0x{Id:X})"; - [ExportTarget] - public string MapName => $"{Constants.WorldIds[(int)World]}_{Room:D02}"; - [ExportTarget] - public string ItemName => ItemProvider.GetItemName(ItemId); - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.SystemData; +using OpenKh.Tools.Kh2SystemEditor.Attributes; +using OpenKh.Tools.Kh2SystemEditor.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenKh.Tools.Kh2SystemEditor.Models.Export +{ + public class TrsrExport + { + public TrsrExport(IItemProvider itemProvider, Trsr treasure) + { + ItemProvider = itemProvider; + Treasure = treasure; + } + + public Trsr Treasure { get; } + public IItemProvider ItemProvider { get; } + + [ExportTarget] + public string Title => $"{Treasure.Id:X03} {MapName} {ItemName}"; + + [ExportTarget] + public ushort Id => Treasure.Id; + + [ExportTarget] + public ushort ItemId => Treasure.ItemId; + [ExportTarget] + public Trsr.TrsrType Type => Treasure.Type; + [ExportTarget] + public World World => (World)Treasure.World; + [ExportTarget] + public byte Room => Treasure.Room; + [ExportTarget] + public byte RoomChestIndex => Treasure.RoomChestIndex; + [ExportTarget] + public short EventId => Treasure.EventId; + [ExportTarget] + public short OverallChestIndex => Treasure.OverallChestIndex; + + [ExportTarget] + public string IdText => $"{Id} (0x{Id:X})"; + [ExportTarget] + public string MapName => $"{Constants.WorldIds[(int)World]}_{Room:D02}"; + [ExportTarget] + public string ItemName => ItemProvider.GetItemName(ItemId); + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Models/ObjectModel.cs b/OpenKh.Tools.Kh2SystemEditor/Models/ObjectModel.cs index f47708254..07ceae47f 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Models/ObjectModel.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Models/ObjectModel.cs @@ -1,14 +1,14 @@ -namespace OpenKh.Tools.Kh2SystemEditor.Models -{ - public class ObjectModel - { - public ObjectModel(int value, string name) - { - Name = name; - Value = (short)value; - } - - public string Name { get; } - public short Value { get; } - } -} +namespace OpenKh.Tools.Kh2SystemEditor.Models +{ + public class ObjectModel + { + public ObjectModel(int value, string name) + { + Name = name; + Value = (short)value; + } + + public string Name { get; } + public short Value { get; } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Utils/DictListWriteUtil.cs b/OpenKh.Tools.Kh2SystemEditor/Utils/DictListWriteUtil.cs index 8bbbcc03d..d68185001 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Utils/DictListWriteUtil.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Utils/DictListWriteUtil.cs @@ -94,11 +94,11 @@ internal static void Write(string fileName, IList> l sheet.CreateFreezePane(0, 1); File.Create(fileName).Using(book.Write); - } - else - { - throw new NotSupportedException(); + } + else + { + throw new NotSupportedException(); } } } -} \ No newline at end of file +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Utils/DictionalizeUtil.cs b/OpenKh.Tools.Kh2SystemEditor/Utils/DictionalizeUtil.cs index a370f9a3b..b167e56f4 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Utils/DictionalizeUtil.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Utils/DictionalizeUtil.cs @@ -1,4 +1,4 @@ -using OpenKh.Tools.Kh2SystemEditor.Attributes; +using OpenKh.Tools.Kh2SystemEditor.Attributes; using OpenKh.Tools.Kh2SystemEditor.ViewModels; using System; using System.Collections.Generic; diff --git a/OpenKh.Tools.Kh2SystemEditor/ViewModels/FtstViewModel.cs b/OpenKh.Tools.Kh2SystemEditor/ViewModels/FtstViewModel.cs index e1fbd1cda..ed55407a4 100644 --- a/OpenKh.Tools.Kh2SystemEditor/ViewModels/FtstViewModel.cs +++ b/OpenKh.Tools.Kh2SystemEditor/ViewModels/FtstViewModel.cs @@ -1,126 +1,126 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Windows.Forms; -using System.Windows.Input; -using System.Windows.Media; -using OpenKh.Kh2; -using OpenKh.Kh2.SystemData; -using OpenKh.Tools.Common; -using OpenKh.Tools.Common.Models; -using OpenKh.Tools.Kh2SystemEditor.Extensions; -using OpenKh.Tools.Kh2SystemEditor.Interfaces; -using Xe.Tools; - -namespace OpenKh.Tools.Kh2SystemEditor.ViewModels -{ - public class FtstViewModel : MyGenericListModel, ISystemGetChanges - { - public class ColorItem : BaseNotifyPropertyChanged - { - public Color? CurrentColor - { - get => ToColor(GetColor()); - set => SetColor(FromColor(value ?? Colors.Black)); - } - - internal Func GetColor; - internal Action SetColor; - - private static int FromColor(Color color) - { - var newColor = ((color.A + 1) / 2) << 24; - newColor |= color.R << 16; - newColor |= color.G << 8; - newColor |= color.B; - - return newColor; - } - private static Color ToColor(int color) - { - var ch1 = (byte)((color >> 16) & 0xFF); - var ch2 = (byte)((color >> 8) & 0xFF); - var ch3 = (byte)((color >> 0) & 0xFF); - var ch4 = (byte)(((color >> 24) & 0xFF) * 2 - 1); - return Color.FromArgb(ch4, ch1, ch2, ch3); - } - } - - public class Entry : BaseNotifyPropertyChanged - { - internal Entry(World world, int numColors, Func getter, Action setter) - { - World = world; - - for (var loop = 0; loop < numColors; loop++) - { - var colorIndex = loop; - - ColorItems.Add( - new ColorItem - { - GetColor = () => getter(colorIndex), - SetColor = (value) => setter(colorIndex, value) - } - ); - } - } - - public World World { get; } - - public string Name => Constants.WorldNames[(int)World]; - - public List ColorItems { get; } = new List(); - } - - private readonly List _entries = new List(); - - private const string _entryName = "ftst"; - - public string EntryName => _entryName; - - public IEnumerable Palette => _entries; - - public FtstViewModel() : - this(Enumerable.Range(0, Constants.PaletteCount).Select(x => new Ftst.Entry - { - Id = x, - Colors = new int[Constants.WorldCount] - })) - { } - - public FtstViewModel(IEnumerable entries) : - this(Ftst.Read(entries.GetBinaryStream(_entryName))) - { } - - public FtstViewModel(IEnumerable ftsts) : - base(new Entry[0]) - { - _entries.AddRange(ftsts); - - var maxCount = ftsts.Count(); - - for (var loop = 0; loop < Constants.WorldCount; loop++) - { - var worldIndex = loop; - - Items.Add( - new Entry( - (World)worldIndex, - maxCount, - (index) => _entries[index].Colors[worldIndex], - (index, value) => _entries[index].Colors[worldIndex] = value - ) - ); - } - } - - public Stream CreateStream() - { - var stream = new MemoryStream(); - Ftst.Write(stream, Palette.ToList()); - return stream; - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Windows.Forms; +using System.Windows.Input; +using System.Windows.Media; +using OpenKh.Kh2; +using OpenKh.Kh2.SystemData; +using OpenKh.Tools.Common; +using OpenKh.Tools.Common.Models; +using OpenKh.Tools.Kh2SystemEditor.Extensions; +using OpenKh.Tools.Kh2SystemEditor.Interfaces; +using Xe.Tools; + +namespace OpenKh.Tools.Kh2SystemEditor.ViewModels +{ + public class FtstViewModel : MyGenericListModel, ISystemGetChanges + { + public class ColorItem : BaseNotifyPropertyChanged + { + public Color? CurrentColor + { + get => ToColor(GetColor()); + set => SetColor(FromColor(value ?? Colors.Black)); + } + + internal Func GetColor; + internal Action SetColor; + + private static int FromColor(Color color) + { + var newColor = ((color.A + 1) / 2) << 24; + newColor |= color.R << 16; + newColor |= color.G << 8; + newColor |= color.B; + + return newColor; + } + private static Color ToColor(int color) + { + var ch1 = (byte)((color >> 16) & 0xFF); + var ch2 = (byte)((color >> 8) & 0xFF); + var ch3 = (byte)((color >> 0) & 0xFF); + var ch4 = (byte)(((color >> 24) & 0xFF) * 2 - 1); + return Color.FromArgb(ch4, ch1, ch2, ch3); + } + } + + public class Entry : BaseNotifyPropertyChanged + { + internal Entry(World world, int numColors, Func getter, Action setter) + { + World = world; + + for (var loop = 0; loop < numColors; loop++) + { + var colorIndex = loop; + + ColorItems.Add( + new ColorItem + { + GetColor = () => getter(colorIndex), + SetColor = (value) => setter(colorIndex, value) + } + ); + } + } + + public World World { get; } + + public string Name => Constants.WorldNames[(int)World]; + + public List ColorItems { get; } = new List(); + } + + private readonly List _entries = new List(); + + private const string _entryName = "ftst"; + + public string EntryName => _entryName; + + public IEnumerable Palette => _entries; + + public FtstViewModel() : + this(Enumerable.Range(0, Constants.PaletteCount).Select(x => new Ftst.Entry + { + Id = x, + Colors = new int[Constants.WorldCount] + })) + { } + + public FtstViewModel(IEnumerable entries) : + this(Ftst.Read(entries.GetBinaryStream(_entryName))) + { } + + public FtstViewModel(IEnumerable ftsts) : + base(new Entry[0]) + { + _entries.AddRange(ftsts); + + var maxCount = ftsts.Count(); + + for (var loop = 0; loop < Constants.WorldCount; loop++) + { + var worldIndex = loop; + + Items.Add( + new Entry( + (World)worldIndex, + maxCount, + (index) => _entries[index].Colors[worldIndex], + (index, value) => _entries[index].Colors[worldIndex] = value + ) + ); + } + } + + public Stream CreateStream() + { + var stream = new MemoryStream(); + Ftst.Write(stream, Palette.ToList()); + return stream; + } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/ViewModels/ItemViewModel.cs b/OpenKh.Tools.Kh2SystemEditor/ViewModels/ItemViewModel.cs index 27622590d..ebf5d9d68 100644 --- a/OpenKh.Tools.Kh2SystemEditor/ViewModels/ItemViewModel.cs +++ b/OpenKh.Tools.Kh2SystemEditor/ViewModels/ItemViewModel.cs @@ -1,191 +1,191 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Windows; -using OpenKh.Engine; -using OpenKh.Kh2; -using OpenKh.Kh2.SystemData; -using OpenKh.Tools.Common.Models; -using OpenKh.Tools.Kh2SystemEditor.Extensions; -using OpenKh.Tools.Kh2SystemEditor.Interfaces; -using Xe.Tools; -using Xe.Tools.Models; - -namespace OpenKh.Tools.Kh2SystemEditor.ViewModels -{ - public class ItemViewModel : MyGenericListModel, ISystemGetChanges, IItemProvider - { - public class Entry : BaseNotifyPropertyChanged, IItemEntry - { - private readonly IMessageProvider _messageProvider; - - public Entry(IMessageProvider messageProvider, Item.Entry item) - { - _messageProvider = messageProvider; - Item = item; - Types = new EnumModel(); - Ranks = new EnumModel(); - } - - public Item.Entry Item { get; } - - public string Title => $"{Item.Id:X02} {_messageProvider.GetString(Item.Name)}"; - - public ushort Id { get => Item.Id; set => Item.Id = value; } - public Item.Type Type { get => Item.Type; set => Item.Type = value; } - public byte Flag0 { get => Item.Flag0; set => Item.Flag0 = value; } - public byte Flag1 { get => Item.Flag1; set => Item.Flag1 = value; } - public Item.Rank Rank { get => Item.Rank; set => Item.Rank = value; } - public ushort StatEntry { get => Item.StatEntry; set => Item.StatEntry = value; } - public ushort NameId - { - get => Item.Name; - set - { - Item.Name = value; - OnPropertyChanged(nameof(Name)); - } - } - public ushort DescriptionId - { - get => Item.Description; - set - { - Item.Description = value; - OnPropertyChanged(nameof(Description)); - } - } - public ushort ShopBuy { get => Item.ShopBuy; set => Item.ShopBuy = value; } - public ushort ShopSell { get => Item.ShopSell; set => Item.ShopSell = value; } - public ushort Command { get => Item.Command; set => Item.Command = value; } - public ushort Slot { get => Item.Slot; set => Item.Slot = value; } - public short Picture { get => Item.Picture; set => Item.Picture = value; } - public byte Icon1 { get => Item.Icon1; set => Item.Icon1 = value; } - public byte Icon2 { get => Item.Icon1; set => Item.Icon1 = value; } - - public string IdText => $"{Id} (0x{Id:X})"; - public string Name { get => _messageProvider.GetString(Item.Name); set => _messageProvider.SetString(Item.Name, value); } - public string Description { get => _messageProvider.GetString(Item.Description); set => _messageProvider.SetString(Item.Description, value); } - public EnumModel Types { get; } - public EnumModel Ranks { get; } - - public override string ToString() => Title; - - public void RefreshMessages() - { - OnPropertyChanged(nameof(Title)); - OnPropertyChanged(nameof(Name)); - OnPropertyChanged(nameof(Description)); - } - } - - private const string entryName = "item"; - private readonly IMessageProvider _messageProvider; - private readonly List _item2; - private string _searchTerm; - - public ItemViewModel(IMessageProvider messageProvider, IEnumerable entries) : - this(messageProvider, Item.Read(entries.GetBinaryStream(entryName))) - { } - - public ItemViewModel(IMessageProvider messageProvider) : - this(messageProvider, new Item - { - Items1 = new List(), - Items2 = new List() - }) - { } - - private ItemViewModel(IMessageProvider messageProvider, Item item) : - this(messageProvider, item.Items1) - { - _messageProvider = messageProvider; - _item2 = item.Items2; - } - - private ItemViewModel(IMessageProvider messageProvider, IEnumerable items) : - base(items.Select(item => new Entry(messageProvider, item))) - { - } - - public string EntryName => entryName; - - public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - - - public string SearchTerm - { - get => _searchTerm; - set - { - _searchTerm = value; - PerformFiltering(); - } - } - - public Stream CreateStream() - { - var stream = new MemoryStream(); - new Item - { - Items1 = UnfilteredItems.Select(x => x.Item).ToList(), - Items2 = _item2 - }.Write(stream); - - return stream; - } - - public IEnumerable ItemEntries => this; - public bool IsItemExists(int itemId) => this.Any(x => x.Id == itemId); - public string GetItemName(int itemId) => this.FirstOrDefault(x => x.Id == itemId)?.Name; - public void InvalidateItemName(int itemId) - { - OnPropertyChanged(nameof(ItemEntries)); - } - - protected override void OnSelectedItem(Entry item) - { - base.OnSelectedItem(item); - - OnPropertyChanged(nameof(IsItemEditingVisible)); - OnPropertyChanged(nameof(IsItemEditMessageVisible)); - } - - protected override Entry OnNewItem() - { - ushort smallestUnusedId = 0; - foreach (var item in UnfilteredItems.OrderBy(x => x.Id)) - { - if (smallestUnusedId++ + 1 != item.Id) - break; - } - - return SelectedItem = new Entry(_messageProvider, new Item.Entry - { - Id = smallestUnusedId - }); - } - - private void PerformFiltering() - { - if (string.IsNullOrWhiteSpace(SearchTerm)) - Filter(FilterNone); - else - Filter(FilterByName); - } - - private bool FilterNone(Entry arg) => true; - - private bool FilterByName(Entry arg) => - arg.Title.ToUpper().Contains(SearchTerm.ToUpper()); - - public void RefreshAllMessages() - { - foreach (var item in Items) - { - item.RefreshMessages(); - } - } - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Windows; +using OpenKh.Engine; +using OpenKh.Kh2; +using OpenKh.Kh2.SystemData; +using OpenKh.Tools.Common.Models; +using OpenKh.Tools.Kh2SystemEditor.Extensions; +using OpenKh.Tools.Kh2SystemEditor.Interfaces; +using Xe.Tools; +using Xe.Tools.Models; + +namespace OpenKh.Tools.Kh2SystemEditor.ViewModels +{ + public class ItemViewModel : MyGenericListModel, ISystemGetChanges, IItemProvider + { + public class Entry : BaseNotifyPropertyChanged, IItemEntry + { + private readonly IMessageProvider _messageProvider; + + public Entry(IMessageProvider messageProvider, Item.Entry item) + { + _messageProvider = messageProvider; + Item = item; + Types = new EnumModel(); + Ranks = new EnumModel(); + } + + public Item.Entry Item { get; } + + public string Title => $"{Item.Id:X02} {_messageProvider.GetString(Item.Name)}"; + + public ushort Id { get => Item.Id; set => Item.Id = value; } + public Item.Type Type { get => Item.Type; set => Item.Type = value; } + public byte Flag0 { get => Item.Flag0; set => Item.Flag0 = value; } + public byte Flag1 { get => Item.Flag1; set => Item.Flag1 = value; } + public Item.Rank Rank { get => Item.Rank; set => Item.Rank = value; } + public ushort StatEntry { get => Item.StatEntry; set => Item.StatEntry = value; } + public ushort NameId + { + get => Item.Name; + set + { + Item.Name = value; + OnPropertyChanged(nameof(Name)); + } + } + public ushort DescriptionId + { + get => Item.Description; + set + { + Item.Description = value; + OnPropertyChanged(nameof(Description)); + } + } + public ushort ShopBuy { get => Item.ShopBuy; set => Item.ShopBuy = value; } + public ushort ShopSell { get => Item.ShopSell; set => Item.ShopSell = value; } + public ushort Command { get => Item.Command; set => Item.Command = value; } + public ushort Slot { get => Item.Slot; set => Item.Slot = value; } + public short Picture { get => Item.Picture; set => Item.Picture = value; } + public byte Icon1 { get => Item.Icon1; set => Item.Icon1 = value; } + public byte Icon2 { get => Item.Icon1; set => Item.Icon1 = value; } + + public string IdText => $"{Id} (0x{Id:X})"; + public string Name { get => _messageProvider.GetString(Item.Name); set => _messageProvider.SetString(Item.Name, value); } + public string Description { get => _messageProvider.GetString(Item.Description); set => _messageProvider.SetString(Item.Description, value); } + public EnumModel Types { get; } + public EnumModel Ranks { get; } + + public override string ToString() => Title; + + public void RefreshMessages() + { + OnPropertyChanged(nameof(Title)); + OnPropertyChanged(nameof(Name)); + OnPropertyChanged(nameof(Description)); + } + } + + private const string entryName = "item"; + private readonly IMessageProvider _messageProvider; + private readonly List _item2; + private string _searchTerm; + + public ItemViewModel(IMessageProvider messageProvider, IEnumerable entries) : + this(messageProvider, Item.Read(entries.GetBinaryStream(entryName))) + { } + + public ItemViewModel(IMessageProvider messageProvider) : + this(messageProvider, new Item + { + Items1 = new List(), + Items2 = new List() + }) + { } + + private ItemViewModel(IMessageProvider messageProvider, Item item) : + this(messageProvider, item.Items1) + { + _messageProvider = messageProvider; + _item2 = item.Items2; + } + + private ItemViewModel(IMessageProvider messageProvider, IEnumerable items) : + base(items.Select(item => new Entry(messageProvider, item))) + { + } + + public string EntryName => entryName; + + public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + + + public string SearchTerm + { + get => _searchTerm; + set + { + _searchTerm = value; + PerformFiltering(); + } + } + + public Stream CreateStream() + { + var stream = new MemoryStream(); + new Item + { + Items1 = UnfilteredItems.Select(x => x.Item).ToList(), + Items2 = _item2 + }.Write(stream); + + return stream; + } + + public IEnumerable ItemEntries => this; + public bool IsItemExists(int itemId) => this.Any(x => x.Id == itemId); + public string GetItemName(int itemId) => this.FirstOrDefault(x => x.Id == itemId)?.Name; + public void InvalidateItemName(int itemId) + { + OnPropertyChanged(nameof(ItemEntries)); + } + + protected override void OnSelectedItem(Entry item) + { + base.OnSelectedItem(item); + + OnPropertyChanged(nameof(IsItemEditingVisible)); + OnPropertyChanged(nameof(IsItemEditMessageVisible)); + } + + protected override Entry OnNewItem() + { + ushort smallestUnusedId = 0; + foreach (var item in UnfilteredItems.OrderBy(x => x.Id)) + { + if (smallestUnusedId++ + 1 != item.Id) + break; + } + + return SelectedItem = new Entry(_messageProvider, new Item.Entry + { + Id = smallestUnusedId + }); + } + + private void PerformFiltering() + { + if (string.IsNullOrWhiteSpace(SearchTerm)) + Filter(FilterNone); + else + Filter(FilterByName); + } + + private bool FilterNone(Entry arg) => true; + + private bool FilterByName(Entry arg) => + arg.Title.ToUpper().Contains(SearchTerm.ToUpper()); + + public void RefreshAllMessages() + { + foreach (var item in Items) + { + item.RefreshMessages(); + } + } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/ViewModels/MemtViewModel.cs b/OpenKh.Tools.Kh2SystemEditor/ViewModels/MemtViewModel.cs index 0731297d4..c7857bc3b 100644 --- a/OpenKh.Tools.Kh2SystemEditor/ViewModels/MemtViewModel.cs +++ b/OpenKh.Tools.Kh2SystemEditor/ViewModels/MemtViewModel.cs @@ -1,177 +1,177 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.SystemData; -using OpenKh.Tools.Common.Models; -using OpenKh.Tools.Kh2SystemEditor.Extensions; -using OpenKh.Tools.Kh2SystemEditor.Interfaces; -using OpenKh.Tools.Kh2SystemEditor.Models; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Xe.Tools; - -namespace OpenKh.Tools.Kh2SystemEditor.ViewModels -{ - public class MemtViewModel : MyGenericListModel, ISystemGetChanges - { - public class Entry : BaseNotifyPropertyChanged - { - private readonly int[] MemberLookupVanilla = - { - 0, 1, 2, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, -1, 13, 14, 15 - }; - private readonly int[] MemberLookupFinalMix = - { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 - }; - - private readonly Memt.IEntry _entry; - private readonly IObjectProvider _objectProvider; - private readonly int[] _memberLookup; - - internal Entry(Memt.IEntry entry, IObjectProvider objectProvider) - { - _entry = entry; - _objectProvider = objectProvider; - _memberLookup = entry switch - { - Memt.EntryVanilla _ => MemberLookupVanilla, - Memt.EntryFinalMix _ => MemberLookupFinalMix, - _ => MemberLookupFinalMix, - }; - - Worlds = new Kh2WorldsList(); - Worlds.First().Name = "Ignore"; - MemberEditEnabled = _memberLookup.Select(x => x >= 0).ToArray(); - } - - public string Title => WorldId == World.WorldZz ? "For any world" : - Worlds.FirstOrDefault(x => x.Value == WorldId)?.Name; - - public Kh2WorldsList Worlds { get; } - public IEnumerable Objects => _objectProvider.Objects; - public bool[] MemberEditEnabled { get; } - - public World WorldId - { - get => (World)_entry.WorldId; - set - { - _entry.WorldId = (short)value; - OnPropertyChanged(nameof(Title)); - } - } - - public short Unk06 { get => _entry.Unk06; set => _entry.Unk06 = value; } - public short Unk08 { get => (short)(_entry.Unk08 & 0xff); set => _entry.Unk08 = value; } - public short Unk0A { get => _entry.Unk0A; set => _entry.Unk0A = value; } - public short Unk0C { get => (short)(_entry.Unk0C & 0xff); set => _entry.Unk0C = value; } - public short Unk0E { get => _entry.Unk0E; set => _entry.Unk0E = value; } - public short[] Members { get => _entry.Members; set => _entry.Members = value; } - - public World FlagWorld - { - get => (World)(_entry.CheckStoryFlag >> 10); - set => _entry.CheckStoryFlag = (short)((_entry.CheckStoryFlag & 0x3FF) | ((int)value << 10)); - } - - public int FlagStory - { - get => _entry.CheckStoryFlag & 0x3ff; - set => _entry.CheckStoryFlag = (short)((_entry.CheckStoryFlag & ~0x3FF) | (value & 0x3ff)); - } - - public World FlagWorldNeg - { - get => (World)(_entry.CheckStoryFlagNegation >> 10); - set => _entry.CheckStoryFlagNegation = (short)((_entry.CheckStoryFlag & 0x3FF) | ((int)value << 10)); - } - - public int FlagStoryNeg - { - get => _entry.CheckStoryFlagNegation & 0x3ff; - set => _entry.CheckStoryFlagNegation = (short)((_entry.CheckStoryFlag & ~0x3FF) | (value & 0x3ff)); - } - - public short PLAYER { get => GetMember(0); set => SetMember(0, value); } - public short FRIEND_1 { get => GetMember(1); set => SetMember(1, value); } - public short FRIEND_2 { get => GetMember(2); set => SetMember(2, value); } - public short FRIEND_W { get => GetMember(3); set => SetMember(3, value); } - public short PLAYER_BTLF { get => GetMember(4); set => SetMember(4, value); } - public short PLAYER_MAGF { get => GetMember(5); set => SetMember(5, value); } - public short PLAYER_KH1F { get => GetMember(6); set => SetMember(6, value); } - public short PLAYER_TRIF { get => GetMember(7); set => SetMember(7, value); } - public short PLAYER_ULTF { get => GetMember(8); set => SetMember(8, value); } - public short PLAYER_HTLF { get => GetMember(9); set => SetMember(9, value); } - public short MICKEY { get => GetMember(10); set => SetMember(10, value); } - public short PLAYER_H { get => GetMember(11); set => SetMember(11, value); } - public short PLAYER_H_BTLF { get => GetMember(12); set => SetMember(12, value); } - public short PLAYER_H_MAGF { get => GetMember(13); set => SetMember(13, value); } - public short PLAYER_H_KH1F { get => GetMember(14); set => SetMember(14, value); } - public short PLAYER_H_TRIF { get => GetMember(15); set => SetMember(15, value); } - public short PLAYER_H_ULTF { get => GetMember(16); set => SetMember(16, value); } - public short PLAYER_H_HTLF { get => GetMember(17); set => SetMember(17, value); } - - private short GetMember(int index) - { - var actualIndex = _memberLookup[index]; - if (actualIndex == -1) - return -1; - return Members[actualIndex]; - } - - private void SetMember(int index, short value) - { - var actualIndex = _memberLookup[index]; - if (actualIndex == -1) - return; - Members[actualIndex] = value; - } - } - - private readonly Memt _memberTable; - private readonly List _entries = new List(); - private readonly IObjectProvider _objectProvider; - private const string _entryName = "memt"; - - public string EntryName => _entryName; - - public IEnumerable Members => _entries; - - public MemtViewModel(IObjectProvider objectProvider) : - this(objectProvider, new Memt()) - { } - - public MemtViewModel(IObjectProvider objectProvider, IEnumerable entries) : - this(objectProvider, Memt.Read(entries.GetBinaryStream(_entryName))) - { } - - public MemtViewModel(IObjectProvider objectProvider, Memt memberTable) : - base(memberTable.Entries.Select(x => new Entry(x, objectProvider))) - { - _objectProvider = objectProvider; - _memberTable = memberTable; - } - - protected override Entry OnNewItem() - { - var item = _entries.FirstOrDefault(); - if (item is Memt.EntryVanilla) - return new Entry(new Memt.EntryVanilla - { - Members = new short[Memt.MemberCountVanilla] - }, _objectProvider); - else - return new Entry(new Memt.EntryFinalMix - { - Members = new short[Memt.MemberCountFinalMix] - }, _objectProvider); - } - - public Stream CreateStream() - { - var stream = new MemoryStream(); - Memt.Write(stream, _memberTable); - return stream; - } - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.SystemData; +using OpenKh.Tools.Common.Models; +using OpenKh.Tools.Kh2SystemEditor.Extensions; +using OpenKh.Tools.Kh2SystemEditor.Interfaces; +using OpenKh.Tools.Kh2SystemEditor.Models; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Xe.Tools; + +namespace OpenKh.Tools.Kh2SystemEditor.ViewModels +{ + public class MemtViewModel : MyGenericListModel, ISystemGetChanges + { + public class Entry : BaseNotifyPropertyChanged + { + private readonly int[] MemberLookupVanilla = + { + 0, 1, 2, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, -1, 13, 14, 15 + }; + private readonly int[] MemberLookupFinalMix = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 + }; + + private readonly Memt.IEntry _entry; + private readonly IObjectProvider _objectProvider; + private readonly int[] _memberLookup; + + internal Entry(Memt.IEntry entry, IObjectProvider objectProvider) + { + _entry = entry; + _objectProvider = objectProvider; + _memberLookup = entry switch + { + Memt.EntryVanilla _ => MemberLookupVanilla, + Memt.EntryFinalMix _ => MemberLookupFinalMix, + _ => MemberLookupFinalMix, + }; + + Worlds = new Kh2WorldsList(); + Worlds.First().Name = "Ignore"; + MemberEditEnabled = _memberLookup.Select(x => x >= 0).ToArray(); + } + + public string Title => WorldId == World.WorldZz ? "For any world" : + Worlds.FirstOrDefault(x => x.Value == WorldId)?.Name; + + public Kh2WorldsList Worlds { get; } + public IEnumerable Objects => _objectProvider.Objects; + public bool[] MemberEditEnabled { get; } + + public World WorldId + { + get => (World)_entry.WorldId; + set + { + _entry.WorldId = (short)value; + OnPropertyChanged(nameof(Title)); + } + } + + public short Unk06 { get => _entry.Unk06; set => _entry.Unk06 = value; } + public short Unk08 { get => (short)(_entry.Unk08 & 0xff); set => _entry.Unk08 = value; } + public short Unk0A { get => _entry.Unk0A; set => _entry.Unk0A = value; } + public short Unk0C { get => (short)(_entry.Unk0C & 0xff); set => _entry.Unk0C = value; } + public short Unk0E { get => _entry.Unk0E; set => _entry.Unk0E = value; } + public short[] Members { get => _entry.Members; set => _entry.Members = value; } + + public World FlagWorld + { + get => (World)(_entry.CheckStoryFlag >> 10); + set => _entry.CheckStoryFlag = (short)((_entry.CheckStoryFlag & 0x3FF) | ((int)value << 10)); + } + + public int FlagStory + { + get => _entry.CheckStoryFlag & 0x3ff; + set => _entry.CheckStoryFlag = (short)((_entry.CheckStoryFlag & ~0x3FF) | (value & 0x3ff)); + } + + public World FlagWorldNeg + { + get => (World)(_entry.CheckStoryFlagNegation >> 10); + set => _entry.CheckStoryFlagNegation = (short)((_entry.CheckStoryFlag & 0x3FF) | ((int)value << 10)); + } + + public int FlagStoryNeg + { + get => _entry.CheckStoryFlagNegation & 0x3ff; + set => _entry.CheckStoryFlagNegation = (short)((_entry.CheckStoryFlag & ~0x3FF) | (value & 0x3ff)); + } + + public short PLAYER { get => GetMember(0); set => SetMember(0, value); } + public short FRIEND_1 { get => GetMember(1); set => SetMember(1, value); } + public short FRIEND_2 { get => GetMember(2); set => SetMember(2, value); } + public short FRIEND_W { get => GetMember(3); set => SetMember(3, value); } + public short PLAYER_BTLF { get => GetMember(4); set => SetMember(4, value); } + public short PLAYER_MAGF { get => GetMember(5); set => SetMember(5, value); } + public short PLAYER_KH1F { get => GetMember(6); set => SetMember(6, value); } + public short PLAYER_TRIF { get => GetMember(7); set => SetMember(7, value); } + public short PLAYER_ULTF { get => GetMember(8); set => SetMember(8, value); } + public short PLAYER_HTLF { get => GetMember(9); set => SetMember(9, value); } + public short MICKEY { get => GetMember(10); set => SetMember(10, value); } + public short PLAYER_H { get => GetMember(11); set => SetMember(11, value); } + public short PLAYER_H_BTLF { get => GetMember(12); set => SetMember(12, value); } + public short PLAYER_H_MAGF { get => GetMember(13); set => SetMember(13, value); } + public short PLAYER_H_KH1F { get => GetMember(14); set => SetMember(14, value); } + public short PLAYER_H_TRIF { get => GetMember(15); set => SetMember(15, value); } + public short PLAYER_H_ULTF { get => GetMember(16); set => SetMember(16, value); } + public short PLAYER_H_HTLF { get => GetMember(17); set => SetMember(17, value); } + + private short GetMember(int index) + { + var actualIndex = _memberLookup[index]; + if (actualIndex == -1) + return -1; + return Members[actualIndex]; + } + + private void SetMember(int index, short value) + { + var actualIndex = _memberLookup[index]; + if (actualIndex == -1) + return; + Members[actualIndex] = value; + } + } + + private readonly Memt _memberTable; + private readonly List _entries = new List(); + private readonly IObjectProvider _objectProvider; + private const string _entryName = "memt"; + + public string EntryName => _entryName; + + public IEnumerable Members => _entries; + + public MemtViewModel(IObjectProvider objectProvider) : + this(objectProvider, new Memt()) + { } + + public MemtViewModel(IObjectProvider objectProvider, IEnumerable entries) : + this(objectProvider, Memt.Read(entries.GetBinaryStream(_entryName))) + { } + + public MemtViewModel(IObjectProvider objectProvider, Memt memberTable) : + base(memberTable.Entries.Select(x => new Entry(x, objectProvider))) + { + _objectProvider = objectProvider; + _memberTable = memberTable; + } + + protected override Entry OnNewItem() + { + var item = _entries.FirstOrDefault(); + if (item is Memt.EntryVanilla) + return new Entry(new Memt.EntryVanilla + { + Members = new short[Memt.MemberCountVanilla] + }, _objectProvider); + else + return new Entry(new Memt.EntryFinalMix + { + Members = new short[Memt.MemberCountFinalMix] + }, _objectProvider); + } + + public Stream CreateStream() + { + var stream = new MemoryStream(); + Memt.Write(stream, _memberTable); + return stream; + } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/ViewModels/SystemEditorViewModel.cs b/OpenKh.Tools.Kh2SystemEditor/ViewModels/SystemEditorViewModel.cs index d6d88e158..1e01813b8 100644 --- a/OpenKh.Tools.Kh2SystemEditor/ViewModels/SystemEditorViewModel.cs +++ b/OpenKh.Tools.Kh2SystemEditor/ViewModels/SystemEditorViewModel.cs @@ -1,368 +1,368 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Windows; -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using OpenKh.Tools.Common; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; -using OpenKh.Tools.Kh2SystemEditor.Interfaces; -using OpenKh.Engine; -using OpenKh.Tools.Kh2SystemEditor.Utils; -using OpenKh.Kh2.Messages; -using OpenKh.Tools.Kh2SystemEditor.Models.Export; -using OpenKh.Tools.Kh2SystemEditor.Models; - -namespace OpenKh.Tools.Kh2SystemEditor.ViewModels -{ - public class SystemEditorViewModel : BaseNotifyPropertyChanged, IObjectProvider - { - public enum EncodingType - { - European, - Japanese - } - - private static string ApplicationName = Utilities.GetApplicationName(); - private static readonly List SystemFilter = FileDialogFilterComposer.Compose() - .AddExtensions("03system", "bin", "bar").AddAllFiles(); - private static readonly List IdxFilter = FileDialogFilterComposer.Compose() - .AddExtensions("KH2.IDX", "idx").AddAllFiles(); - private static readonly List MsgFilter = FileDialogFilterComposer.Compose() - .AddExtensions("sys.bar", "bar", "msg", "bin").AddAllFiles(); - private static readonly List TableExportFilter = FileDialogFilterComposer.Compose() - .AddExtensions("yml", "yml") - .AddExtensions("xlsx", "xlsx") - .AddAllFiles(); - - - private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - private string _fileName; - private EncodingType _encoding; - private IEnumerable _barItems; - private Kh2MessageProvider _messageProvider; - private ItemViewModel _item; - private TrsrViewModel _trsr; - private MemtViewModel _memt; - private FtstViewModel _ftst; - - public string Title => $"{FileName ?? "untitled"} | {ApplicationName}"; - - private string FileName - { - get => _fileName; - set - { - _fileName = value; - OnPropertyChanged(nameof(Title)); - } - } - - public RelayCommand OpenCommand { get; } - public RelayCommand SaveCommand { get; } - public RelayCommand SaveAsCommand { get; } - public RelayCommand ExportItemListCommand { get; } - public RelayCommand ExportTrsrListCommand { get; } - public RelayCommand ExitCommand { get; } - public RelayCommand AboutCommand { get; } - public RelayCommand LoadSupportIdxCommand { get; } - public RelayCommand LoadSupportMsgCommand { get; } - - public ItemViewModel Item - { - get => _item; - private set { _item = value; OnPropertyChanged(); } - } - - public TrsrViewModel Trsr - { - get => _trsr; - private set { _trsr = value; OnPropertyChanged(); } - } - - public MemtViewModel Memt - { - get => _memt; - private set { _memt = value; OnPropertyChanged(); } - } - - public FtstViewModel Ftst - { - get => _ftst; - private set { _ftst = value; OnPropertyChanged(); } - } - - public EncodingType Encoding - { - get => _encoding; - set - { - switch (_encoding = value) - { - case EncodingType.European: - _messageProvider.Encoder = Encoders.InternationalSystem; - break; - case EncodingType.Japanese: - _messageProvider.Encoder = Encoders.JapaneseSystem; - break; - } - - Item.RefreshAllMessages(); - Trsr.RefreshAllMessages(); - } - } - - public IList Objects { get; } = new List(); - private Dictionary _objectsDictionary; - - public SystemEditorViewModel() - { - OpenCommand = new RelayCommand(_ => FileDialog.OnOpen(fileName => OpenFile(fileName), SystemFilter, parent: Window)); - - SaveCommand = new RelayCommand(x => - { - if (!string.IsNullOrEmpty(FileName)) - { - SaveFile(FileName, FileName); - } - else - { - SaveAsCommand.Execute(x); - } - }, x => true); - - SaveAsCommand = new RelayCommand(_ => FileDialog.OnSave(fileName => - { - SaveFile(FileName, fileName); - FileName = fileName; - }, SystemFilter, defaultFileName: FileName, parent: Window)); - - ExportItemListCommand = new RelayCommand( - _ => FileDialog.OnSave( - fileName => - { - ExportTable( - fileName, - Item.Select(viewModel => new ItemExport(_messageProvider, viewModel.Item)) - ); - }, - TableExportFilter, - defaultFileName: "ItemList.yml", - parent: Window - ) - ); - - ExportTrsrListCommand = new RelayCommand( - _ => FileDialog.OnSave( - fileName => - { - ExportTable( - fileName, - Trsr.Select(viewModel => new TrsrExport(Item, viewModel.Treasure)) - ); - }, - TableExportFilter, - defaultFileName: "TrsrList.yml", - parent: Window - ) - ); - - ExitCommand = new RelayCommand(x => Window.Close()); - - AboutCommand = new RelayCommand(x => new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog()); - - LoadSupportIdxCommand = new RelayCommand(_ => Utilities.Catch(() => - { - Kh2Utilities.OpenMsgFromIdxDialog(s => - { - LoadMessages(s); - InvalidateViews(); - }); - })); - LoadSupportMsgCommand = new RelayCommand(_ => Utilities.Catch(() => - { - Kh2Utilities.OpenMsgFromBarDialog(s => - { - LoadMessages(s); - InvalidateViews(); - }); - })); - - _messageProvider = new Kh2MessageProvider(); - CreateSystem(); - } - - private void ExportTable(string fileName, IEnumerable list) - { - try - { - DictListWriteUtil.Write( - fileName, - DictionalizeUtil.ToDictList(list) - ); - } - catch (NotSupportedException) - { - MessageBox.Show("Export in this file format is not supported yet."); - } - } - - public void LoadSupportFiles(string basePath) - { - // Try to load MSG, giving priority to the English language - foreach (var region in Constants.Regions.OrderBy(x => x == "us" ? 0 : 1)) - { - var tryPath = Path.Combine(basePath, $"msg/{region}/sys.bar"); - if (File.Exists(tryPath)) - { - LoadMessages(File.OpenRead(tryPath).Using(Kh2Utilities.ReadMsgFromBar)); - break; - } - } - - var objEntryPath = Path.Combine(basePath, "00objentry.bin"); - if (File.Exists(objEntryPath)) - File.OpenRead(objEntryPath).Using(LoadObjEntry); - } - - private void LoadMessages(List msgs) - { - _messageProvider.Load(msgs); - switch (IsMsgJapanese(_messageProvider)) - { - case true: - Encoding = EncodingType.Japanese; - break; - case false: - Encoding = EncodingType.European; - break; - } - } - - private void LoadObjEntry(Stream stream) - { - var objEntry = Objentry.Read(stream); - Objects.Clear(); - Objects.Add(new ObjectModel(-1, "Disabled")); - Objects.Add(new ObjectModel(0, "Ignore")); - foreach (var obj in objEntry.OrderBy(x => - { - // Order the OBJ Entry list to improve performance - if (x.ModelName.StartsWith("P_")) - return 0; - if (x.ModelName == "WM_CURSOR") - return 1; - if (x.ModelName.StartsWith("N_")) - return 1; - return 3; - })) - Objects.Add(new ObjectModel((int)obj.ObjectId, obj.ModelName)); - _objectsDictionary = Objects.ToDictionary(x => x.Value, x => x.Name); - } - - private void InvalidateViews() - { - SaveSystem(); - LoadSystem(_barItems); - } - - public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => - { - if (!Bar.IsValid(stream)) - { - MessageBox.Show(Window, $"{Path.GetFileName(fileName)} is not a valid BAR file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - return false; - } - - var items = Bar.Read(stream); - - if (!Is03System(items)) - { - MessageBox.Show(Window, $"{Path.GetFileName(fileName)} does not appear to be a valid 03system.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - return false; - } - - LoadSupportFiles(Path.GetDirectoryName(fileName)); - LoadSystem(items); - - FileName = fileName; - return true; - }); - - public void SaveFile(string previousFileName, string fileName) - { - File.Create(fileName).Using(stream => - { - SaveSystem(); - Bar.Write(stream, _barItems); - }); - } - - private bool Is03System(List items) => items.Any(x => new[] - { - "item", - "trsr", - "ftst", - "memt", - }.Contains(x.Name)); - - private void CreateSystem() - { - _barItems = new Bar.Entry[0]; - Item = new ItemViewModel(_messageProvider); - Trsr = new TrsrViewModel(Item); - Memt = new MemtViewModel(this); - Ftst = new FtstViewModel(); - } - - private void LoadSystem(IEnumerable entries) - { - _barItems = entries; - Item = new ItemViewModel(_messageProvider, _barItems); - Trsr = new TrsrViewModel(Item, _barItems); - Memt = new MemtViewModel(this, _barItems); - Ftst = new FtstViewModel(_barItems); - } - - private void SaveSystem() - { - _barItems = SaveSystemEntry(_barItems, Item); - _barItems = SaveSystemEntry(_barItems, Trsr); - _barItems = SaveSystemEntry(_barItems, Memt); - _barItems = SaveSystemEntry(_barItems, Ftst); - } - - private IEnumerable SaveSystemEntry(IEnumerable entries, ISystemGetChanges battleGetChanges) => - entries.ForEntry(Bar.EntryType.List, battleGetChanges.EntryName, 0, entry => entry.Stream = battleGetChanges.CreateStream()); - - private T GetDefaultViewModelInstance() - where T : ISystemGetChanges => Activator.CreateInstance(); - - private static bool? IsMsgJapanese(Kh2MessageProvider messageProvider) - { - const ushort FakeTextId = 0x0ADC; - if (messageProvider == null) - return null; - - var data = messageProvider.GetMessage(FakeTextId); - if (data == null || data.Length == 0) - return null; - - return data.Length != 5; - } - - public string GetObjectName(int id) - { - if (_objectsDictionary == null) - return null; - if (!_objectsDictionary.TryGetValue((short)id, out var value)) - return null; - return value; - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows; +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using OpenKh.Tools.Common; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; +using OpenKh.Tools.Kh2SystemEditor.Interfaces; +using OpenKh.Engine; +using OpenKh.Tools.Kh2SystemEditor.Utils; +using OpenKh.Kh2.Messages; +using OpenKh.Tools.Kh2SystemEditor.Models.Export; +using OpenKh.Tools.Kh2SystemEditor.Models; + +namespace OpenKh.Tools.Kh2SystemEditor.ViewModels +{ + public class SystemEditorViewModel : BaseNotifyPropertyChanged, IObjectProvider + { + public enum EncodingType + { + European, + Japanese + } + + private static string ApplicationName = Utilities.GetApplicationName(); + private static readonly List SystemFilter = FileDialogFilterComposer.Compose() + .AddExtensions("03system", "bin", "bar").AddAllFiles(); + private static readonly List IdxFilter = FileDialogFilterComposer.Compose() + .AddExtensions("KH2.IDX", "idx").AddAllFiles(); + private static readonly List MsgFilter = FileDialogFilterComposer.Compose() + .AddExtensions("sys.bar", "bar", "msg", "bin").AddAllFiles(); + private static readonly List TableExportFilter = FileDialogFilterComposer.Compose() + .AddExtensions("yml", "yml") + .AddExtensions("xlsx", "xlsx") + .AddAllFiles(); + + + private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + private string _fileName; + private EncodingType _encoding; + private IEnumerable _barItems; + private Kh2MessageProvider _messageProvider; + private ItemViewModel _item; + private TrsrViewModel _trsr; + private MemtViewModel _memt; + private FtstViewModel _ftst; + + public string Title => $"{FileName ?? "untitled"} | {ApplicationName}"; + + private string FileName + { + get => _fileName; + set + { + _fileName = value; + OnPropertyChanged(nameof(Title)); + } + } + + public RelayCommand OpenCommand { get; } + public RelayCommand SaveCommand { get; } + public RelayCommand SaveAsCommand { get; } + public RelayCommand ExportItemListCommand { get; } + public RelayCommand ExportTrsrListCommand { get; } + public RelayCommand ExitCommand { get; } + public RelayCommand AboutCommand { get; } + public RelayCommand LoadSupportIdxCommand { get; } + public RelayCommand LoadSupportMsgCommand { get; } + + public ItemViewModel Item + { + get => _item; + private set { _item = value; OnPropertyChanged(); } + } + + public TrsrViewModel Trsr + { + get => _trsr; + private set { _trsr = value; OnPropertyChanged(); } + } + + public MemtViewModel Memt + { + get => _memt; + private set { _memt = value; OnPropertyChanged(); } + } + + public FtstViewModel Ftst + { + get => _ftst; + private set { _ftst = value; OnPropertyChanged(); } + } + + public EncodingType Encoding + { + get => _encoding; + set + { + switch (_encoding = value) + { + case EncodingType.European: + _messageProvider.Encoder = Encoders.InternationalSystem; + break; + case EncodingType.Japanese: + _messageProvider.Encoder = Encoders.JapaneseSystem; + break; + } + + Item.RefreshAllMessages(); + Trsr.RefreshAllMessages(); + } + } + + public IList Objects { get; } = new List(); + private Dictionary _objectsDictionary; + + public SystemEditorViewModel() + { + OpenCommand = new RelayCommand(_ => FileDialog.OnOpen(fileName => OpenFile(fileName), SystemFilter, parent: Window)); + + SaveCommand = new RelayCommand(x => + { + if (!string.IsNullOrEmpty(FileName)) + { + SaveFile(FileName, FileName); + } + else + { + SaveAsCommand.Execute(x); + } + }, x => true); + + SaveAsCommand = new RelayCommand(_ => FileDialog.OnSave(fileName => + { + SaveFile(FileName, fileName); + FileName = fileName; + }, SystemFilter, defaultFileName: FileName, parent: Window)); + + ExportItemListCommand = new RelayCommand( + _ => FileDialog.OnSave( + fileName => + { + ExportTable( + fileName, + Item.Select(viewModel => new ItemExport(_messageProvider, viewModel.Item)) + ); + }, + TableExportFilter, + defaultFileName: "ItemList.yml", + parent: Window + ) + ); + + ExportTrsrListCommand = new RelayCommand( + _ => FileDialog.OnSave( + fileName => + { + ExportTable( + fileName, + Trsr.Select(viewModel => new TrsrExport(Item, viewModel.Treasure)) + ); + }, + TableExportFilter, + defaultFileName: "TrsrList.yml", + parent: Window + ) + ); + + ExitCommand = new RelayCommand(x => Window.Close()); + + AboutCommand = new RelayCommand(x => new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog()); + + LoadSupportIdxCommand = new RelayCommand(_ => Utilities.Catch(() => + { + Kh2Utilities.OpenMsgFromIdxDialog(s => + { + LoadMessages(s); + InvalidateViews(); + }); + })); + LoadSupportMsgCommand = new RelayCommand(_ => Utilities.Catch(() => + { + Kh2Utilities.OpenMsgFromBarDialog(s => + { + LoadMessages(s); + InvalidateViews(); + }); + })); + + _messageProvider = new Kh2MessageProvider(); + CreateSystem(); + } + + private void ExportTable(string fileName, IEnumerable list) + { + try + { + DictListWriteUtil.Write( + fileName, + DictionalizeUtil.ToDictList(list) + ); + } + catch (NotSupportedException) + { + MessageBox.Show("Export in this file format is not supported yet."); + } + } + + public void LoadSupportFiles(string basePath) + { + // Try to load MSG, giving priority to the English language + foreach (var region in Constants.Regions.OrderBy(x => x == "us" ? 0 : 1)) + { + var tryPath = Path.Combine(basePath, $"msg/{region}/sys.bar"); + if (File.Exists(tryPath)) + { + LoadMessages(File.OpenRead(tryPath).Using(Kh2Utilities.ReadMsgFromBar)); + break; + } + } + + var objEntryPath = Path.Combine(basePath, "00objentry.bin"); + if (File.Exists(objEntryPath)) + File.OpenRead(objEntryPath).Using(LoadObjEntry); + } + + private void LoadMessages(List msgs) + { + _messageProvider.Load(msgs); + switch (IsMsgJapanese(_messageProvider)) + { + case true: + Encoding = EncodingType.Japanese; + break; + case false: + Encoding = EncodingType.European; + break; + } + } + + private void LoadObjEntry(Stream stream) + { + var objEntry = Objentry.Read(stream); + Objects.Clear(); + Objects.Add(new ObjectModel(-1, "Disabled")); + Objects.Add(new ObjectModel(0, "Ignore")); + foreach (var obj in objEntry.OrderBy(x => + { + // Order the OBJ Entry list to improve performance + if (x.ModelName.StartsWith("P_")) + return 0; + if (x.ModelName == "WM_CURSOR") + return 1; + if (x.ModelName.StartsWith("N_")) + return 1; + return 3; + })) + Objects.Add(new ObjectModel((int)obj.ObjectId, obj.ModelName)); + _objectsDictionary = Objects.ToDictionary(x => x.Value, x => x.Name); + } + + private void InvalidateViews() + { + SaveSystem(); + LoadSystem(_barItems); + } + + public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => + { + if (!Bar.IsValid(stream)) + { + MessageBox.Show(Window, $"{Path.GetFileName(fileName)} is not a valid BAR file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + var items = Bar.Read(stream); + + if (!Is03System(items)) + { + MessageBox.Show(Window, $"{Path.GetFileName(fileName)} does not appear to be a valid 03system.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + LoadSupportFiles(Path.GetDirectoryName(fileName)); + LoadSystem(items); + + FileName = fileName; + return true; + }); + + public void SaveFile(string previousFileName, string fileName) + { + File.Create(fileName).Using(stream => + { + SaveSystem(); + Bar.Write(stream, _barItems); + }); + } + + private bool Is03System(List items) => items.Any(x => new[] + { + "item", + "trsr", + "ftst", + "memt", + }.Contains(x.Name)); + + private void CreateSystem() + { + _barItems = new Bar.Entry[0]; + Item = new ItemViewModel(_messageProvider); + Trsr = new TrsrViewModel(Item); + Memt = new MemtViewModel(this); + Ftst = new FtstViewModel(); + } + + private void LoadSystem(IEnumerable entries) + { + _barItems = entries; + Item = new ItemViewModel(_messageProvider, _barItems); + Trsr = new TrsrViewModel(Item, _barItems); + Memt = new MemtViewModel(this, _barItems); + Ftst = new FtstViewModel(_barItems); + } + + private void SaveSystem() + { + _barItems = SaveSystemEntry(_barItems, Item); + _barItems = SaveSystemEntry(_barItems, Trsr); + _barItems = SaveSystemEntry(_barItems, Memt); + _barItems = SaveSystemEntry(_barItems, Ftst); + } + + private IEnumerable SaveSystemEntry(IEnumerable entries, ISystemGetChanges battleGetChanges) => + entries.ForEntry(Bar.EntryType.List, battleGetChanges.EntryName, 0, entry => entry.Stream = battleGetChanges.CreateStream()); + + private T GetDefaultViewModelInstance() + where T : ISystemGetChanges => Activator.CreateInstance(); + + private static bool? IsMsgJapanese(Kh2MessageProvider messageProvider) + { + const ushort FakeTextId = 0x0ADC; + if (messageProvider == null) + return null; + + var data = messageProvider.GetMessage(FakeTextId); + if (data == null || data.Length == 0) + return null; + + return data.Length != 5; + } + + public string GetObjectName(int id) + { + if (_objectsDictionary == null) + return null; + if (!_objectsDictionary.TryGetValue((short)id, out var value)) + return null; + return value; + } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/ViewModels/TrsrViewModel.cs b/OpenKh.Tools.Kh2SystemEditor/ViewModels/TrsrViewModel.cs index 3cd1959f7..a2989fbd0 100644 --- a/OpenKh.Tools.Kh2SystemEditor/ViewModels/TrsrViewModel.cs +++ b/OpenKh.Tools.Kh2SystemEditor/ViewModels/TrsrViewModel.cs @@ -1,176 +1,176 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Windows; -using OpenKh.Kh2; -using OpenKh.Kh2.SystemData; -using OpenKh.Tools.Common.Models; -using OpenKh.Tools.Kh2SystemEditor.Extensions; -using OpenKh.Tools.Kh2SystemEditor.Interfaces; -using Xe.Tools; -using Xe.Tools.Models; - -namespace OpenKh.Tools.Kh2SystemEditor.ViewModels -{ - public class TrsrViewModel : MyGenericListModel, ISystemGetChanges - { - public class Entry : BaseNotifyPropertyChanged - { - public Entry(IItemProvider itemProvider, Trsr treasure) - { - ItemProvider = itemProvider; - Treasure = treasure; - Worlds = new Kh2WorldsList(); - Types = new EnumModel(); - } - - public Trsr Treasure { get; } - public IItemProvider ItemProvider { get; } - - public string Title => $"{Treasure.Id:X03} {MapName} {ItemName}"; - public string Query => $"{Id} {Title} {Type} {World} {RoomChestIndex} {EventId}"; - - public ushort Id { get => Treasure.Id; set => Treasure.Id = value; } - - public ushort ItemId - { - get => Treasure.ItemId; - set - { - Treasure.ItemId = value; - OnPropertyChanged(nameof(Title)); - } - } - public Trsr.TrsrType Type { get => Treasure.Type; set => Treasure.Type = value; } - public World World - { - get => (World)Treasure.World; - set - { - Treasure.World = (byte)value; - OnPropertyChanged(nameof(Title)); - OnPropertyChanged(nameof(MapName)); - } - } - public byte Room - { - get => Treasure.Room; - set - { - Treasure.Room = value; - OnPropertyChanged(nameof(Title)); - OnPropertyChanged(nameof(MapName)); - } - } - public byte RoomChestIndex { get => Treasure.RoomChestIndex; set => Treasure.RoomChestIndex = value; } - public short EventId { get => Treasure.EventId; set => Treasure.EventId = value; } - public short OverallChestIndex { get => Treasure.OverallChestIndex; set => Treasure.OverallChestIndex = value; } - - public string IdText => $"{Id} (0x{Id:X})"; - public string MapName => $"{Constants.WorldIds[(int)World]}_{Room:D02}"; - public string ItemName => ItemProvider.GetItemName(ItemId); - - public Kh2WorldsList Worlds { get; } - public EnumModel Types { get; } - - public override string ToString() => Title; - - public void RefreshMessages() - { - OnPropertyChanged(nameof(Title)); - OnPropertyChanged(nameof(Query)); - OnPropertyChanged(nameof(IdText)); - OnPropertyChanged(nameof(MapName)); - OnPropertyChanged(nameof(ItemName)); - } - } - - private const string entryName = "trsr"; - private readonly IItemProvider _itemProvider; - private string _searchTerm; - - public TrsrViewModel(IItemProvider itemProvider, IEnumerable entries) : - this(itemProvider, Trsr.Read(entries.GetBinaryStream(entryName))) - { } - - public TrsrViewModel(IItemProvider itemProvider) : - this(itemProvider, new Trsr[0]) - { } - - private TrsrViewModel(IItemProvider itemProvider, IEnumerable items) : - base(items.Select(item => new Entry(itemProvider, item))) - { - _itemProvider = itemProvider; - } - - public string EntryName => entryName; - - public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - - public string SearchTerm - { - get => _searchTerm; - set - { - _searchTerm = value; - PerformFiltering(); - } - } - - public Stream CreateStream() - { - var stream = new MemoryStream(); - Trsr.Write(stream, UnfilteredItems.Select(x => x.Treasure)); - - return stream; - } - - protected override void OnSelectedItem(Entry item) - { - base.OnSelectedItem(item); - - OnPropertyChanged(nameof(IsItemEditingVisible)); - OnPropertyChanged(nameof(IsItemEditMessageVisible)); - } - - protected override Entry OnNewItem() - { - ushort smallestUnusedId = 0; - foreach (var item in UnfilteredItems.OrderBy(x => x.Id)) - { - if (smallestUnusedId++ + 1 != item.Id) - break; - } - - return SelectedItem = new Entry(_itemProvider, new Trsr - { - Id = smallestUnusedId - }); - } - - private void PerformFiltering() - { - if (string.IsNullOrWhiteSpace(SearchTerm)) - Filter(FilterNone); - else - Filter(FilterByName); - } - - private bool FilterNone(Entry arg) => true; - - private bool FilterByName(Entry arg) - { - var query = arg.Query.ToUpper(); - return SearchTerm.ToUpper().Split(new char[] { ',', ' ' }).All(term => query.Contains(term)); - } - - public void RefreshAllMessages() - { - foreach (var item in Items) - { - item.RefreshMessages(); - } - } - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Windows; +using OpenKh.Kh2; +using OpenKh.Kh2.SystemData; +using OpenKh.Tools.Common.Models; +using OpenKh.Tools.Kh2SystemEditor.Extensions; +using OpenKh.Tools.Kh2SystemEditor.Interfaces; +using Xe.Tools; +using Xe.Tools.Models; + +namespace OpenKh.Tools.Kh2SystemEditor.ViewModels +{ + public class TrsrViewModel : MyGenericListModel, ISystemGetChanges + { + public class Entry : BaseNotifyPropertyChanged + { + public Entry(IItemProvider itemProvider, Trsr treasure) + { + ItemProvider = itemProvider; + Treasure = treasure; + Worlds = new Kh2WorldsList(); + Types = new EnumModel(); + } + + public Trsr Treasure { get; } + public IItemProvider ItemProvider { get; } + + public string Title => $"{Treasure.Id:X03} {MapName} {ItemName}"; + public string Query => $"{Id} {Title} {Type} {World} {RoomChestIndex} {EventId}"; + + public ushort Id { get => Treasure.Id; set => Treasure.Id = value; } + + public ushort ItemId + { + get => Treasure.ItemId; + set + { + Treasure.ItemId = value; + OnPropertyChanged(nameof(Title)); + } + } + public Trsr.TrsrType Type { get => Treasure.Type; set => Treasure.Type = value; } + public World World + { + get => (World)Treasure.World; + set + { + Treasure.World = (byte)value; + OnPropertyChanged(nameof(Title)); + OnPropertyChanged(nameof(MapName)); + } + } + public byte Room + { + get => Treasure.Room; + set + { + Treasure.Room = value; + OnPropertyChanged(nameof(Title)); + OnPropertyChanged(nameof(MapName)); + } + } + public byte RoomChestIndex { get => Treasure.RoomChestIndex; set => Treasure.RoomChestIndex = value; } + public short EventId { get => Treasure.EventId; set => Treasure.EventId = value; } + public short OverallChestIndex { get => Treasure.OverallChestIndex; set => Treasure.OverallChestIndex = value; } + + public string IdText => $"{Id} (0x{Id:X})"; + public string MapName => $"{Constants.WorldIds[(int)World]}_{Room:D02}"; + public string ItemName => ItemProvider.GetItemName(ItemId); + + public Kh2WorldsList Worlds { get; } + public EnumModel Types { get; } + + public override string ToString() => Title; + + public void RefreshMessages() + { + OnPropertyChanged(nameof(Title)); + OnPropertyChanged(nameof(Query)); + OnPropertyChanged(nameof(IdText)); + OnPropertyChanged(nameof(MapName)); + OnPropertyChanged(nameof(ItemName)); + } + } + + private const string entryName = "trsr"; + private readonly IItemProvider _itemProvider; + private string _searchTerm; + + public TrsrViewModel(IItemProvider itemProvider, IEnumerable entries) : + this(itemProvider, Trsr.Read(entries.GetBinaryStream(entryName))) + { } + + public TrsrViewModel(IItemProvider itemProvider) : + this(itemProvider, new Trsr[0]) + { } + + private TrsrViewModel(IItemProvider itemProvider, IEnumerable items) : + base(items.Select(item => new Entry(itemProvider, item))) + { + _itemProvider = itemProvider; + } + + public string EntryName => entryName; + + public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + + public string SearchTerm + { + get => _searchTerm; + set + { + _searchTerm = value; + PerformFiltering(); + } + } + + public Stream CreateStream() + { + var stream = new MemoryStream(); + Trsr.Write(stream, UnfilteredItems.Select(x => x.Treasure)); + + return stream; + } + + protected override void OnSelectedItem(Entry item) + { + base.OnSelectedItem(item); + + OnPropertyChanged(nameof(IsItemEditingVisible)); + OnPropertyChanged(nameof(IsItemEditMessageVisible)); + } + + protected override Entry OnNewItem() + { + ushort smallestUnusedId = 0; + foreach (var item in UnfilteredItems.OrderBy(x => x.Id)) + { + if (smallestUnusedId++ + 1 != item.Id) + break; + } + + return SelectedItem = new Entry(_itemProvider, new Trsr + { + Id = smallestUnusedId + }); + } + + private void PerformFiltering() + { + if (string.IsNullOrWhiteSpace(SearchTerm)) + Filter(FilterNone); + else + Filter(FilterByName); + } + + private bool FilterNone(Entry arg) => true; + + private bool FilterByName(Entry arg) + { + var query = arg.Query.ToUpper(); + return SearchTerm.ToUpper().Split(new char[] { ',', ' ' }).All(term => query.Contains(term)); + } + + public void RefreshAllMessages() + { + foreach (var item in Items) + { + item.RefreshMessages(); + } + } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Views/FtstView.xaml.cs b/OpenKh.Tools.Kh2SystemEditor/Views/FtstView.xaml.cs index 9ca899f94..c96a4e133 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Views/FtstView.xaml.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Views/FtstView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace OpenKh.Tools.Kh2SystemEditor.Views -{ - /// - /// Interaction logic for FtstView.xaml - /// - public partial class FtstView : UserControl - { - public FtstView() - { - InitializeComponent(); - } - } -} +using System.Windows.Controls; + +namespace OpenKh.Tools.Kh2SystemEditor.Views +{ + /// + /// Interaction logic for FtstView.xaml + /// + public partial class FtstView : UserControl + { + public FtstView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Views/ItemView.xaml.cs b/OpenKh.Tools.Kh2SystemEditor/Views/ItemView.xaml.cs index 1619cde9f..26ccf13e5 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Views/ItemView.xaml.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Views/ItemView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace OpenKh.Tools.Kh2SystemEditor.Views -{ - /// - /// Interaction logic for ItemView.xaml - /// - public partial class ItemView : UserControl - { - public ItemView() - { - InitializeComponent(); - } - } -} +using System.Windows.Controls; + +namespace OpenKh.Tools.Kh2SystemEditor.Views +{ + /// + /// Interaction logic for ItemView.xaml + /// + public partial class ItemView : UserControl + { + public ItemView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Views/MemtView.xaml.cs b/OpenKh.Tools.Kh2SystemEditor/Views/MemtView.xaml.cs index a51ecd33b..4ad24be3d 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Views/MemtView.xaml.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Views/MemtView.xaml.cs @@ -1,26 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace OpenKh.Tools.Kh2SystemEditor.Views -{ - /// - /// Interaction logic for MemtView.xaml - /// - public partial class MemtView : UserControl - { - public MemtView() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace OpenKh.Tools.Kh2SystemEditor.Views +{ + /// + /// Interaction logic for MemtView.xaml + /// + public partial class MemtView : UserControl + { + public MemtView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Views/SystemEditorView.xaml.cs b/OpenKh.Tools.Kh2SystemEditor/Views/SystemEditorView.xaml.cs index 0ec366385..eb684224e 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Views/SystemEditorView.xaml.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Views/SystemEditorView.xaml.cs @@ -1,19 +1,19 @@ -using OpenKh.Common; -using OpenKh.Tools.Kh2SystemEditor.ViewModels; -using System.IO; -using System.Windows; - -namespace OpenKh.Tools.Kh2SystemEditor.Views -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class SystemEditorView : Window - { - public SystemEditorView() - { - InitializeComponent(); - DataContext = new SystemEditorViewModel(); - } - } -} +using OpenKh.Common; +using OpenKh.Tools.Kh2SystemEditor.ViewModels; +using System.IO; +using System.Windows; + +namespace OpenKh.Tools.Kh2SystemEditor.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class SystemEditorView : Window + { + public SystemEditorView() + { + InitializeComponent(); + DataContext = new SystemEditorViewModel(); + } + } +} diff --git a/OpenKh.Tools.Kh2SystemEditor/Views/TrsrView.xaml.cs b/OpenKh.Tools.Kh2SystemEditor/Views/TrsrView.xaml.cs index 9a2db444d..1fa24dfca 100644 --- a/OpenKh.Tools.Kh2SystemEditor/Views/TrsrView.xaml.cs +++ b/OpenKh.Tools.Kh2SystemEditor/Views/TrsrView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace OpenKh.Tools.Kh2SystemEditor.Views -{ - /// - /// Interaction logic for TrsrView.xaml - /// - public partial class TrsrView : UserControl - { - public TrsrView() - { - InitializeComponent(); - } - } -} +using System.Windows.Controls; + +namespace OpenKh.Tools.Kh2SystemEditor.Views +{ + /// + /// Interaction logic for TrsrView.xaml + /// + public partial class TrsrView : UserControl + { + public TrsrView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/App.xaml.cs b/OpenKh.Tools.Kh2TextEditor/App.xaml.cs index 87a298136..bf35ad155 100644 --- a/OpenKh.Tools.Kh2TextEditor/App.xaml.cs +++ b/OpenKh.Tools.Kh2TextEditor/App.xaml.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; - -namespace OpenKh.Tools.Kh2TextEditor -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace OpenKh.Tools.Kh2TextEditor +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Converters/EnumMatchToBooleanConverter.cs b/OpenKh.Tools.Kh2TextEditor/Converters/EnumMatchToBooleanConverter.cs index 6a60b5981..96788d044 100644 --- a/OpenKh.Tools.Kh2TextEditor/Converters/EnumMatchToBooleanConverter.cs +++ b/OpenKh.Tools.Kh2TextEditor/Converters/EnumMatchToBooleanConverter.cs @@ -1,33 +1,33 @@ -using System; -using System.Globalization; -using System.Windows.Data; - -namespace OpenKh.Tools.Kh2TextEditor.Converters -{ - public class EnumMatchToBooleanConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value == null || parameter == null) - return false; - - string checkValue = value.ToString(); - string targetValue = parameter.ToString(); - return checkValue.Equals(targetValue, - StringComparison.InvariantCultureIgnoreCase); - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value == null || parameter == null) - return null; - - bool useValue = (bool)value; - string targetValue = parameter.ToString(); - if (useValue) - return Enum.Parse(targetType, targetValue); - - return null; - } - } -} +using System; +using System.Globalization; +using System.Windows.Data; + +namespace OpenKh.Tools.Kh2TextEditor.Converters +{ + public class EnumMatchToBooleanConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null || parameter == null) + return false; + + string checkValue = value.ToString(); + string targetValue = parameter.ToString(); + return checkValue.Equals(targetValue, + StringComparison.InvariantCultureIgnoreCase); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null || parameter == null) + return null; + + bool useValue = (bool)value; + string targetValue = parameter.ToString(); + if (useValue) + return Enum.Parse(targetType, targetValue); + + return null; + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Interfaces/ICurrentMessageEncoder.cs b/OpenKh.Tools.Kh2TextEditor/Interfaces/ICurrentMessageEncoder.cs index baab490bc..4d54e3ed1 100644 --- a/OpenKh.Tools.Kh2TextEditor/Interfaces/ICurrentMessageEncoder.cs +++ b/OpenKh.Tools.Kh2TextEditor/Interfaces/ICurrentMessageEncoder.cs @@ -1,9 +1,9 @@ -using OpenKh.Kh2.Messages; - -namespace OpenKh.Tools.Kh2TextEditor.Interfaces -{ - public interface ICurrentMessageEncoder - { - IMessageEncoder CurrentMessageEncoder { get; } - } -} +using OpenKh.Kh2.Messages; + +namespace OpenKh.Tools.Kh2TextEditor.Interfaces +{ + public interface ICurrentMessageEncoder + { + IMessageEncoder CurrentMessageEncoder { get; } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Interfaces/IInvalidateErrorCount.cs b/OpenKh.Tools.Kh2TextEditor/Interfaces/IInvalidateErrorCount.cs index 8f471b4ca..ac3a290ae 100644 --- a/OpenKh.Tools.Kh2TextEditor/Interfaces/IInvalidateErrorCount.cs +++ b/OpenKh.Tools.Kh2TextEditor/Interfaces/IInvalidateErrorCount.cs @@ -1,7 +1,7 @@ -namespace OpenKh.Tools.Kh2TextEditor.Interfaces -{ - public interface IInvalidateErrorCount - { - void InvalidateErrorCount(); - } -} +namespace OpenKh.Tools.Kh2TextEditor.Interfaces +{ + public interface IInvalidateErrorCount + { + void InvalidateErrorCount(); + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Models/MessageModel.cs b/OpenKh.Tools.Kh2TextEditor/Models/MessageModel.cs index 32e7e3d17..8a492f3f8 100644 --- a/OpenKh.Tools.Kh2TextEditor/Models/MessageModel.cs +++ b/OpenKh.Tools.Kh2TextEditor/Models/MessageModel.cs @@ -1,118 +1,118 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using OpenKh.Tools.Kh2TextEditor.Interfaces; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Windows; -using Xe.Tools; - -namespace OpenKh.Tools.Kh2TextEditor.Models -{ - public class MessageModel : BaseNotifyPropertyChanged - { - private readonly ICurrentMessageEncoder _currentEncoder; - private readonly IInvalidateErrorCount _invalidateErrorCount; - private readonly Msg.Entry _entry; - private bool _doesNotContainErrors = true; - private string _lastError; - - public MessageModel(ICurrentMessageEncoder currentEncoder, IInvalidateErrorCount invalidateErrorCount, Msg.Entry entry) - { - _currentEncoder = currentEncoder; - _invalidateErrorCount = invalidateErrorCount; - _entry = entry; - } - - public int Id => _entry.Id; - - public string Text - { - get - { - try - { - var text = MsgSerializer.SerializeText(MessageCommands); - DoesNotContainErrors = DoesNotContainErrors && true; - return text; - } - catch (Exception ex) - { - DoesNotContainErrors = false; - LastError = ex.Message; - return ex.Message; - } - } - - set - { - try - { - MessageCommands = MsgSerializer.DeserializeText(value); - DoesNotContainErrors = true; - } - catch (Exception ex) - { - DoesNotContainErrors = false; - LastError = ex.Message; - } - - OnPropertyChanged(); - OnPropertyChanged(nameof(Title)); - } - } - - public IEnumerable MessageCommands - { - get => _currentEncoder.CurrentMessageEncoder.Decode(_entry.Data); - set - { - _entry.Data = _currentEncoder.CurrentMessageEncoder.Encode(value.ToList()); - OnPropertyChanged(); - } - } - - public string Title - { - get - { - const int MaxTitleLength = 100; - var title = $"{Id:X4}: {Text}"; - return title.Length > MaxTitleLength ? $"{title.Substring(0, MaxTitleLength)}..." : title; - } - } - - public bool DoesNotContainErrors - { - get => _doesNotContainErrors; - private set - { - var prevValue = _doesNotContainErrors; - _doesNotContainErrors = value; - - if (prevValue != value) - _invalidateErrorCount.InvalidateErrorCount(); - - OnPropertyChanged(nameof(IconErrorVisiblity)); - } - } - - public Visibility IconErrorVisiblity => DoesNotContainErrors ? Visibility.Collapsed : Visibility.Visible; - - public string LastError - { - get => _lastError; - private set - { - _lastError = value; - OnPropertyChanged(); - } - } - - public void InvalidateText() - { - OnPropertyChanged(nameof(Title)); - OnPropertyChanged(nameof(Text)); - } - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using OpenKh.Tools.Kh2TextEditor.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows; +using Xe.Tools; + +namespace OpenKh.Tools.Kh2TextEditor.Models +{ + public class MessageModel : BaseNotifyPropertyChanged + { + private readonly ICurrentMessageEncoder _currentEncoder; + private readonly IInvalidateErrorCount _invalidateErrorCount; + private readonly Msg.Entry _entry; + private bool _doesNotContainErrors = true; + private string _lastError; + + public MessageModel(ICurrentMessageEncoder currentEncoder, IInvalidateErrorCount invalidateErrorCount, Msg.Entry entry) + { + _currentEncoder = currentEncoder; + _invalidateErrorCount = invalidateErrorCount; + _entry = entry; + } + + public int Id => _entry.Id; + + public string Text + { + get + { + try + { + var text = MsgSerializer.SerializeText(MessageCommands); + DoesNotContainErrors = DoesNotContainErrors && true; + return text; + } + catch (Exception ex) + { + DoesNotContainErrors = false; + LastError = ex.Message; + return ex.Message; + } + } + + set + { + try + { + MessageCommands = MsgSerializer.DeserializeText(value); + DoesNotContainErrors = true; + } + catch (Exception ex) + { + DoesNotContainErrors = false; + LastError = ex.Message; + } + + OnPropertyChanged(); + OnPropertyChanged(nameof(Title)); + } + } + + public IEnumerable MessageCommands + { + get => _currentEncoder.CurrentMessageEncoder.Decode(_entry.Data); + set + { + _entry.Data = _currentEncoder.CurrentMessageEncoder.Encode(value.ToList()); + OnPropertyChanged(); + } + } + + public string Title + { + get + { + const int MaxTitleLength = 100; + var title = $"{Id:X4}: {Text}"; + return title.Length > MaxTitleLength ? $"{title.Substring(0, MaxTitleLength)}..." : title; + } + } + + public bool DoesNotContainErrors + { + get => _doesNotContainErrors; + private set + { + var prevValue = _doesNotContainErrors; + _doesNotContainErrors = value; + + if (prevValue != value) + _invalidateErrorCount.InvalidateErrorCount(); + + OnPropertyChanged(nameof(IconErrorVisiblity)); + } + } + + public Visibility IconErrorVisiblity => DoesNotContainErrors ? Visibility.Collapsed : Visibility.Visible; + + public string LastError + { + get => _lastError; + private set + { + _lastError = value; + OnPropertyChanged(); + } + } + + public void InvalidateText() + { + OnPropertyChanged(nameof(Title)); + OnPropertyChanged(nameof(Text)); + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Models/MessagesModel.cs b/OpenKh.Tools.Kh2TextEditor/Models/MessagesModel.cs index a60793dc7..f38d71e05 100644 --- a/OpenKh.Tools.Kh2TextEditor/Models/MessagesModel.cs +++ b/OpenKh.Tools.Kh2TextEditor/Models/MessagesModel.cs @@ -1,44 +1,44 @@ -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using OpenKh.Tools.Kh2TextEditor.Interfaces; -using System; -using System.Collections.Generic; -using System.Linq; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.Kh2TextEditor.Models -{ - public class MessagesModel : GenericListModel - { - private readonly ICurrentMessageEncoder _currentEncoder; - - public MessagesModel(ICurrentMessageEncoder currentEncoder, IInvalidateErrorCount invalidateErrorCount, IEnumerable messages) : - this(currentEncoder, messages.Select(x => new MessageModel(currentEncoder, invalidateErrorCount, x))) - { } - - public MessagesModel(ICurrentMessageEncoder currentEncoder, IEnumerable messages) : - base(messages) - { - _currentEncoder = currentEncoder; - } - - public MessageModel GetMessage(int id) => - Items.FirstOrDefault(x => x.Id == id); - - public void InvalidateText() - { - foreach (var item in Items) - item.InvalidateText(); - } - - protected override MessageModel OnNewItem() - { - throw new System.NotImplementedException(); - } - - internal void Filter(object p, object textFilter) - { - throw new NotImplementedException(); - } - } -} +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using OpenKh.Tools.Kh2TextEditor.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.Kh2TextEditor.Models +{ + public class MessagesModel : GenericListModel + { + private readonly ICurrentMessageEncoder _currentEncoder; + + public MessagesModel(ICurrentMessageEncoder currentEncoder, IInvalidateErrorCount invalidateErrorCount, IEnumerable messages) : + this(currentEncoder, messages.Select(x => new MessageModel(currentEncoder, invalidateErrorCount, x))) + { } + + public MessagesModel(ICurrentMessageEncoder currentEncoder, IEnumerable messages) : + base(messages) + { + _currentEncoder = currentEncoder; + } + + public MessageModel GetMessage(int id) => + Items.FirstOrDefault(x => x.Id == id); + + public void InvalidateText() + { + foreach (var item in Items) + item.InvalidateText(); + } + + protected override MessageModel OnNewItem() + { + throw new System.NotImplementedException(); + } + + internal void Filter(object p, object textFilter) + { + throw new NotImplementedException(); + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Models/TextAreaModel.cs b/OpenKh.Tools.Kh2TextEditor/Models/TextAreaModel.cs index f5f418412..0ecbcecc9 100644 --- a/OpenKh.Tools.Kh2TextEditor/Models/TextAreaModel.cs +++ b/OpenKh.Tools.Kh2TextEditor/Models/TextAreaModel.cs @@ -1,27 +1,27 @@ -using OpenKh.Kh2.Messages; -using System.Collections.Generic; -using Xe.Tools; - -namespace OpenKh.Tools.Kh2TextEditor.Models -{ - public class TextAreaModel : BaseNotifyPropertyChanged - { - private IEnumerable textCommands; - - public IEnumerable TextCommands - { - get => textCommands; - set - { - textCommands = value; - OnPropertyChanged(); - } - } - - public string Text - { - get => MsgSerializer.SerializeText(TextCommands); - set => TextCommands = MsgSerializer.DeserializeText(value); - } - } -} +using OpenKh.Kh2.Messages; +using System.Collections.Generic; +using Xe.Tools; + +namespace OpenKh.Tools.Kh2TextEditor.Models +{ + public class TextAreaModel : BaseNotifyPropertyChanged + { + private IEnumerable textCommands; + + public IEnumerable TextCommands + { + get => textCommands; + set + { + textCommands = value; + OnPropertyChanged(); + } + } + + public string Text + { + get => MsgSerializer.SerializeText(TextCommands); + set => TextCommands = MsgSerializer.DeserializeText(value); + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Services/ExchangeableMessage.cs b/OpenKh.Tools.Kh2TextEditor/Services/ExchangeableMessage.cs index 3c1aa6891..7ffaa9608 100644 --- a/OpenKh.Tools.Kh2TextEditor/Services/ExchangeableMessage.cs +++ b/OpenKh.Tools.Kh2TextEditor/Services/ExchangeableMessage.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Serialization; - -namespace OpenKh.Tools.Kh2TextEditor.Services -{ - public class ExchangeableMessage - { - [XmlElement] - public int Id { get; set; } - [XmlElement] - public string Text { get; set; } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace OpenKh.Tools.Kh2TextEditor.Services +{ + public class ExchangeableMessage + { + [XmlElement] + public int Id { get; set; } + [XmlElement] + public string Text { get; set; } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Services/ITextExporter.cs b/OpenKh.Tools.Kh2TextEditor/Services/ITextExporter.cs index eb5efe600..846993786 100644 --- a/OpenKh.Tools.Kh2TextEditor/Services/ITextExporter.cs +++ b/OpenKh.Tools.Kh2TextEditor/Services/ITextExporter.cs @@ -1,16 +1,16 @@ -using OpenKh.Tools.Kh2TextEditor.Models; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace OpenKh.Tools.Kh2TextEditor.Services -{ - public interface ITextExporter - { - void Export(IEnumerable messages, TextWriter writer); - (string, string[]) Filter(); - } -} +using OpenKh.Tools.Kh2TextEditor.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenKh.Tools.Kh2TextEditor.Services +{ + public interface ITextExporter + { + void Export(IEnumerable messages, TextWriter writer); + (string, string[]) Filter(); + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Services/ITextImporter.cs b/OpenKh.Tools.Kh2TextEditor/Services/ITextImporter.cs index 904ae8b74..9b22f9201 100644 --- a/OpenKh.Tools.Kh2TextEditor/Services/ITextImporter.cs +++ b/OpenKh.Tools.Kh2TextEditor/Services/ITextImporter.cs @@ -1,16 +1,16 @@ -using OpenKh.Tools.Kh2TextEditor.Models; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace OpenKh.Tools.Kh2TextEditor.Services -{ - public interface ITextImporter - { - IEnumerable Import(TextReader reader); - (string, string[]) Filter(); - } -} +using OpenKh.Tools.Kh2TextEditor.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenKh.Tools.Kh2TextEditor.Services +{ + public interface ITextImporter + { + IEnumerable Import(TextReader reader); + (string, string[]) Filter(); + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Services/PlainTextExporter.cs b/OpenKh.Tools.Kh2TextEditor/Services/PlainTextExporter.cs index f4993ab61..90d2bc16a 100644 --- a/OpenKh.Tools.Kh2TextEditor/Services/PlainTextExporter.cs +++ b/OpenKh.Tools.Kh2TextEditor/Services/PlainTextExporter.cs @@ -1,24 +1,24 @@ -using OpenKh.Tools.Kh2TextEditor.Models; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace OpenKh.Tools.Kh2TextEditor.Services -{ - class PlainTextExporter : ITextExporter - { - void ITextExporter.Export(IEnumerable messages, TextWriter writer) - { - foreach (var one in messages) - { - writer.WriteLine($"{one.Id}: {one.Text}"); - writer.WriteLine("---"); - } - } - - (string, string[]) ITextExporter.Filter() => ("Plain text", "txt".Split(';')); - } -} +using OpenKh.Tools.Kh2TextEditor.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenKh.Tools.Kh2TextEditor.Services +{ + class PlainTextExporter : ITextExporter + { + void ITextExporter.Export(IEnumerable messages, TextWriter writer) + { + foreach (var one in messages) + { + writer.WriteLine($"{one.Id}: {one.Text}"); + writer.WriteLine("---"); + } + } + + (string, string[]) ITextExporter.Filter() => ("Plain text", "txt".Split(';')); + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Services/TextExporters.cs b/OpenKh.Tools.Kh2TextEditor/Services/TextExporters.cs index 06162f7c2..44675d5c6 100644 --- a/OpenKh.Tools.Kh2TextEditor/Services/TextExporters.cs +++ b/OpenKh.Tools.Kh2TextEditor/Services/TextExporters.cs @@ -1,34 +1,34 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace OpenKh.Tools.Kh2TextEditor.Services -{ - public class TextExporters - { - public static IEnumerable GetAll() => new ITextExporter[] - { - new PlainTextExporter(), - new XmlTextExporter(), - new YamlTextExporter(), - }; - - public static ITextExporter FindFromFile(string fileName) - { - var selectedExtension = Path.GetExtension(fileName).TrimStart('.'); - var textExporters = GetAll(); - - return textExporters - .Where( - exporter => exporter.Filter().Item2 - .Any( - it => string.Compare(it, selectedExtension, true) == 0 - ) - ) - .FirstOrDefault() ?? textExporters.First(); // fallback - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenKh.Tools.Kh2TextEditor.Services +{ + public class TextExporters + { + public static IEnumerable GetAll() => new ITextExporter[] + { + new PlainTextExporter(), + new XmlTextExporter(), + new YamlTextExporter(), + }; + + public static ITextExporter FindFromFile(string fileName) + { + var selectedExtension = Path.GetExtension(fileName).TrimStart('.'); + var textExporters = GetAll(); + + return textExporters + .Where( + exporter => exporter.Filter().Item2 + .Any( + it => string.Compare(it, selectedExtension, true) == 0 + ) + ) + .FirstOrDefault() ?? textExporters.First(); // fallback + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Services/TextImporters.cs b/OpenKh.Tools.Kh2TextEditor/Services/TextImporters.cs index 881f18f5b..9deed1fd6 100644 --- a/OpenKh.Tools.Kh2TextEditor/Services/TextImporters.cs +++ b/OpenKh.Tools.Kh2TextEditor/Services/TextImporters.cs @@ -1,33 +1,33 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace OpenKh.Tools.Kh2TextEditor.Services -{ - public class TextImporters - { - public static IEnumerable GetAll() => new ITextImporter[] - { - new XmlTextImporter(), - new YamlTextImporter(), - }; - - public static ITextImporter FindFromFile(string fileName) - { - var selectedExtension = Path.GetExtension(fileName).TrimStart('.'); - var textExporters = GetAll(); - - return textExporters - .Where( - exporter => exporter.Filter().Item2 - .Any( - it => string.Compare(it, selectedExtension, true) == 0 - ) - ) - .FirstOrDefault(); - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenKh.Tools.Kh2TextEditor.Services +{ + public class TextImporters + { + public static IEnumerable GetAll() => new ITextImporter[] + { + new XmlTextImporter(), + new YamlTextImporter(), + }; + + public static ITextImporter FindFromFile(string fileName) + { + var selectedExtension = Path.GetExtension(fileName).TrimStart('.'); + var textExporters = GetAll(); + + return textExporters + .Where( + exporter => exporter.Filter().Item2 + .Any( + it => string.Compare(it, selectedExtension, true) == 0 + ) + ) + .FirstOrDefault(); + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Services/XmlTextExporter.cs b/OpenKh.Tools.Kh2TextEditor/Services/XmlTextExporter.cs index 798f204a6..874b62176 100644 --- a/OpenKh.Tools.Kh2TextEditor/Services/XmlTextExporter.cs +++ b/OpenKh.Tools.Kh2TextEditor/Services/XmlTextExporter.cs @@ -1,34 +1,34 @@ -using OpenKh.Tools.Kh2TextEditor.Models; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Serialization; - -namespace OpenKh.Tools.Kh2TextEditor.Services -{ - public class XmlTextExporter : ITextExporter - { - void ITextExporter.Export(IEnumerable messages, TextWriter writer) - { - new XmlSerializer(typeof(RootModel)).Serialize( - writer, - new RootModel - { - Message = messages.ToArray() - } - ); - } - - (string, string[]) ITextExporter.Filter() => ("XML", "xml".Split(';')); - - [XmlRoot("Messages")] - public class RootModel - { - [XmlElement] - public ExchangeableMessage[] Message { get; set; } - } - } -} +using OpenKh.Tools.Kh2TextEditor.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace OpenKh.Tools.Kh2TextEditor.Services +{ + public class XmlTextExporter : ITextExporter + { + void ITextExporter.Export(IEnumerable messages, TextWriter writer) + { + new XmlSerializer(typeof(RootModel)).Serialize( + writer, + new RootModel + { + Message = messages.ToArray() + } + ); + } + + (string, string[]) ITextExporter.Filter() => ("XML", "xml".Split(';')); + + [XmlRoot("Messages")] + public class RootModel + { + [XmlElement] + public ExchangeableMessage[] Message { get; set; } + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Services/XmlTextImporter.cs b/OpenKh.Tools.Kh2TextEditor/Services/XmlTextImporter.cs index a749d308f..97625b5da 100644 --- a/OpenKh.Tools.Kh2TextEditor/Services/XmlTextImporter.cs +++ b/OpenKh.Tools.Kh2TextEditor/Services/XmlTextImporter.cs @@ -1,29 +1,29 @@ -using OpenKh.Tools.Kh2TextEditor.Models; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Serialization; - -namespace OpenKh.Tools.Kh2TextEditor.Services -{ - public class XmlTextImporter : ITextImporter - { - (string, string[]) ITextImporter.Filter() => ("XML", "xml".Split(';')); - - IEnumerable ITextImporter.Import(TextReader reader) - { - var model = (RootModel)new XmlSerializer(typeof(RootModel)).Deserialize(reader); - return model.Message; - } - - [XmlRoot("Messages")] - public class RootModel - { - [XmlElement] - public ExchangeableMessage[] Message { get; set; } - } - } -} +using OpenKh.Tools.Kh2TextEditor.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace OpenKh.Tools.Kh2TextEditor.Services +{ + public class XmlTextImporter : ITextImporter + { + (string, string[]) ITextImporter.Filter() => ("XML", "xml".Split(';')); + + IEnumerable ITextImporter.Import(TextReader reader) + { + var model = (RootModel)new XmlSerializer(typeof(RootModel)).Deserialize(reader); + return model.Message; + } + + [XmlRoot("Messages")] + public class RootModel + { + [XmlElement] + public ExchangeableMessage[] Message { get; set; } + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Services/YamlTextExporter.cs b/OpenKh.Tools.Kh2TextEditor/Services/YamlTextExporter.cs index f98190600..85640f9ba 100644 --- a/OpenKh.Tools.Kh2TextEditor/Services/YamlTextExporter.cs +++ b/OpenKh.Tools.Kh2TextEditor/Services/YamlTextExporter.cs @@ -1,29 +1,29 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using YamlDotNet; -using YamlDotNet.Serialization.NamingConventions; - -namespace OpenKh.Tools.Kh2TextEditor.Services -{ - class YamlTextExporter : ITextExporter - { - void ITextExporter.Export(IEnumerable messages, TextWriter writer) - { - new YamlDotNet.Serialization.SerializerBuilder() - .IgnoreFields() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build() - .Serialize( - writer, - messages.Select(x => new - { - id = x.Id, - text = x.Text - }) - ); - } - - (string, string[]) ITextExporter.Filter() => ("YAML", "yml".Split(';')); - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using YamlDotNet; +using YamlDotNet.Serialization.NamingConventions; + +namespace OpenKh.Tools.Kh2TextEditor.Services +{ + class YamlTextExporter : ITextExporter + { + void ITextExporter.Export(IEnumerable messages, TextWriter writer) + { + new YamlDotNet.Serialization.SerializerBuilder() + .IgnoreFields() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build() + .Serialize( + writer, + messages.Select(x => new + { + id = x.Id, + text = x.Text + }) + ); + } + + (string, string[]) ITextExporter.Filter() => ("YAML", "yml".Split(';')); + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Services/YamlTextImporter.cs b/OpenKh.Tools.Kh2TextEditor/Services/YamlTextImporter.cs index b85aa5598..2c9b6174e 100644 --- a/OpenKh.Tools.Kh2TextEditor/Services/YamlTextImporter.cs +++ b/OpenKh.Tools.Kh2TextEditor/Services/YamlTextImporter.cs @@ -1,34 +1,34 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using YamlDotNet.Serialization.NamingConventions; - -namespace OpenKh.Tools.Kh2TextEditor.Services -{ - class YamlTextImporter : ITextImporter - { - (string, string[]) ITextImporter.Filter() => ("YAML", "yml".Split(';')); - - IEnumerable ITextImporter.Import(TextReader reader) - { - var messages = new YamlDotNet.Serialization.DeserializerBuilder() - .IgnoreFields() - .IgnoreUnmatchedProperties() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build() - .Deserialize(reader); - - return messages.Select(x => new ExchangeableMessage - { - Id = x.id, - Text = x.text - }); - } - - public class MessageModel - { - public int id { get; set; } - public string text { get; set; } - } - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using YamlDotNet.Serialization.NamingConventions; + +namespace OpenKh.Tools.Kh2TextEditor.Services +{ + class YamlTextImporter : ITextImporter + { + (string, string[]) ITextImporter.Filter() => ("YAML", "yml".Split(';')); + + IEnumerable ITextImporter.Import(TextReader reader) + { + var messages = new YamlDotNet.Serialization.DeserializerBuilder() + .IgnoreFields() + .IgnoreUnmatchedProperties() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build() + .Deserialize(reader); + + return messages.Select(x => new ExchangeableMessage + { + Id = x.id, + Text = x.text + }); + } + + public class MessageModel + { + public int id { get; set; } + public string text { get; set; } + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Types/EncodingType.cs b/OpenKh.Tools.Kh2TextEditor/Types/EncodingType.cs index 6d8ef72c2..a774d0046 100644 --- a/OpenKh.Tools.Kh2TextEditor/Types/EncodingType.cs +++ b/OpenKh.Tools.Kh2TextEditor/Types/EncodingType.cs @@ -1,9 +1,9 @@ -namespace OpenKh.Tools.Kh2TextEditor.Types -{ - public enum EncodingType - { - European, - Japanese, - Turkish - } -} +namespace OpenKh.Tools.Kh2TextEditor.Types +{ + public enum EncodingType + { + European, + Japanese, + Turkish + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Types/FontType.cs b/OpenKh.Tools.Kh2TextEditor/Types/FontType.cs index 545d0336c..1cef431c3 100644 --- a/OpenKh.Tools.Kh2TextEditor/Types/FontType.cs +++ b/OpenKh.Tools.Kh2TextEditor/Types/FontType.cs @@ -1,8 +1,8 @@ -namespace OpenKh.Tools.Kh2TextEditor.Types -{ - public enum FontType - { - System, - Event - } -} +namespace OpenKh.Tools.Kh2TextEditor.Types +{ + public enum FontType + { + System, + Event + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/ViewModels/MainViewModel.cs b/OpenKh.Tools.Kh2TextEditor/ViewModels/MainViewModel.cs index c21cd52ea..90e21c6ac 100644 --- a/OpenKh.Tools.Kh2TextEditor/ViewModels/MainViewModel.cs +++ b/OpenKh.Tools.Kh2TextEditor/ViewModels/MainViewModel.cs @@ -1,478 +1,478 @@ -using OpenKh.Tools.Common; -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Kh2.Contextes; -using OpenKh.Kh2.Extensions; -using OpenKh.Tools.Kh2TextEditor.Types; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Windows; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; -using OpenKh.Tools.Kh2TextEditor.Services; -using System.Text; -using OpenKh.Engine.Renders; -using OpenKh.Engine.Extensions; - -namespace OpenKh.Tools.Kh2TextEditor.ViewModels -{ - public class MainViewModel : BaseNotifyPropertyChanged - { - private const string DefaultName = "FAKE"; - private const string GuideUrl = "https://openkh.dev/kh2/tool/Kh2TextEditor/OpenKh.Tools.Kh2TextEditor"; - private static string ApplicationName = Utilities.GetApplicationName(); - private string _fileName; - private string _barEntryName; - private FontContext _fontContext = new FontContext(); - private FontType _fontType; - private EncodingType _encodingType; - - private static readonly List MessageFilters = FileDialogFilterComposer - .Compose() - .AddExtensions("Message files", "bar", "msg", "bin") - .AddAllFiles(); - - private static readonly List FontImageFilters = FileDialogFilterComposer - .Compose() - .AddExtensions("fontimage.bar", "bar") - .AddAllFiles(); - - private static readonly List FontInfoFilters = FileDialogFilterComposer - .Compose() - .AddExtensions("fontinfo.bar", "bar") - .AddAllFiles(); - - private static readonly List ExportFilters = FileDialogFilterComposer - .Compose() - .Concat(TextExporters.GetAll().Select(x => FileDialogFilter.ByExtensions(x.Filter().Item1, x.Filter().Item2))) - .ToList(); - - private static readonly List ImportFilters = FileDialogFilterComposer - .Compose() - .Concat(TextImporters.GetAll().Select(x => FileDialogFilter.ByExtensions(x.Filter().Item1, x.Filter().Item2))) - .ToList(); - - public string Title => $"{_barEntryName ?? DefaultName} | {FileName ?? "untitled"} | {ApplicationName}"; - - private string FileName - { - get => _fileName; - set - { - _fileName = value; - OnPropertyChanged(nameof(Title)); - } - } - - private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - public RelayCommand OpenCommand { get; } - public RelayCommand SaveCommand { get; } - public RelayCommand SaveAsCommand { get; } - public RelayCommand ExportMessageAsCommand { get; } - public RelayCommand ImportMessageFromCommand { get; } - - public RelayCommand ExitCommand { get; } - public RelayCommand GuideCommand { get; } - public RelayCommand AboutCommand { get; } - - public RelayCommand OpenFontImageCommand { get; } - public RelayCommand SaveFontImageCommand { get; } - public RelayCommand EditFontImageCommand { get; } - public RelayCommand OpenFontInfoCommand { get; } - public RelayCommand SaveFontInfoCommand { get; } - public RelayCommand EditFontInfoCommand { get; } - - public TextEditorViewModel TextEditor { get; private set; } - - public bool OptimizeOnSave { get; set; } - - public FontType FontType - { - get => _fontType; - set - { - _fontType = value; - InvalidateFontContext(); - } - } - - public EncodingType EncodingType - { - get => _encodingType; - set - { - _encodingType = value; - InvalidateFontContext(); - } - } - - public MainViewModel() - { - OpenCommand = new RelayCommand(x => - { - FileDialog.OnOpen(fileName => - { - OpenFile(fileName); - }, MessageFilters); - }, x => true); - - SaveCommand = new RelayCommand(x => - { - if (!string.IsNullOrEmpty(FileName)) - { - SaveFile(FileName, FileName); - } - else - { - SaveAsCommand.Execute(x); - } - }, x => true); - - SaveAsCommand = new RelayCommand(x => - { - FileDialog.OnSave(fileName => - { - SaveFile(FileName, fileName); - FileName = fileName; - }, MessageFilters); - }, x => true); - - ExportMessageAsCommand = new RelayCommand(x => - { - FileDialog.OnSave(fileName => - { - var selectedExtension = $"{Path.GetExtension(fileName).TrimStart('.')}"; - - ExportMessageAsFile( - fileName: fileName, - textExporter: TextExporters.FindFromFile(fileName) - ); - }, ExportFilters); - }, x => true); - - ImportMessageFromCommand = new RelayCommand(x => - { - FileDialog.OnOpen(fileName => - { - var selectedExtension = $"{Path.GetExtension(fileName).TrimStart('.')}"; - - var textImporter = TextImporters.FindFromFile(fileName); - if (textImporter != null) - { - ImportMessageFromFile( - fileName: fileName, - textImporter - ); - } - else - { - MessageBox.Show($"Failed to match text decoder for your file:\n{fileName}"); - } - }, ImportFilters); - }, x => true); - - ExitCommand = new RelayCommand(x => - { - Window.Close(); - }, x => true); - - OpenFontImageCommand = new RelayCommand(x => - { - FileDialog.OnOpen(fileName => - { - OpenFontImageFile(fileName); - }, FontImageFilters); - }, x => true); - - SaveFontImageCommand = new RelayCommand(x => - { - FileDialog.OnSave(fileName => - { - SaveFontImageFile(fileName); - }, FontImageFilters); - }, x => true); - - OpenFontInfoCommand = new RelayCommand(x => - { - FileDialog.OnOpen(fileName => - { - OpenFontInfoFile(fileName); - }, FontInfoFilters); - }, x => true); - - SaveFontInfoCommand = new RelayCommand(x => - { - FileDialog.OnSave(fileName => - { - SaveFontInfoFile(fileName); - }, FontInfoFilters); - }, x => true); - - GuideCommand = new RelayCommand(x => - { - Process.Start(new ProcessStartInfo(GuideUrl)); - }, x => true); - - AboutCommand = new RelayCommand(x => - { - new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); - }, x => true); - - TextEditor = new TextEditorViewModel(); - FontType = FontType.System; - } - - public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => - { - _barEntryName = null; - if (!TryReadMsg(stream) && !TryReadMsgAsBar(stream)) - { - MessageBox.Show(Window, "Invalid or not existing Message data found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - return false; - } - - if (_barEntryName == null) - { - _barEntryName = Path.GetFileNameWithoutExtension(fileName); - if (_barEntryName.Length > 4) - _barEntryName = _barEntryName.Substring(0, 4); - - _barEntryName = _barEntryName.ToLower(); - } - - FileName = fileName; - LoadSupportFiles(Path.GetDirectoryName(fileName)); - AutodetectRegion(); - - return true; - }); - - public void SaveFile(string previousFileName, string fileName) - { - if (File.Exists(previousFileName)) - { - bool isBar = false; - List entries; - - entries = File.OpenRead(previousFileName).Using(stream => - { - isBar = Bar.IsValid(stream); - return isBar ? Bar.Read(stream) : null; - }); - - if (isBar) - File.Create(fileName).Using(stream => WriteBar(entries, stream)); - else - File.Create(fileName).Using(WriteMsg); - } - else - { - File.Create(fileName).Using(WriteMsg); - } - } - - public void ExportMessageAsFile(string fileName, ITextExporter textExporter) - { - new StreamWriter(fileName, false, Encoding.UTF8).Using( - writer => textExporter.Export( - TextEditor.Messages - .Select( - source => new ExchangeableMessage - { - Id = source.Id, - Text = source.Text, - } - ), - writer - ) - ); - } - - public void ImportMessageFromFile(string fileName, ITextImporter textImporter) - { - var importedMessages = new StreamReader(fileName, Encoding.UTF8).Using( - reader => textImporter.Import(reader) - .ToArray() // make sure to import all messages from file before closing StreamReader! - ); - - foreach (var importMessage in importedMessages) - { - var found = TextEditor.Messages.SingleOrDefault(it => it.Id == importMessage.Id); - if (found != null) - { - found.Text = importMessage.Text; - } - } - } - - public void OpenFontImageFile(string fileName) => File.OpenRead(fileName).Using(stream => - { - if (Bar.IsValid(stream)) - { - _fontContext.Read(Bar.Read(stream)); - InvalidateFontContext(); - } - }); - - private void SaveFontImageFile(string fileName) - { - throw new NotImplementedException(); - } - - public void OpenFontInfoFile(string fileName) => File.OpenRead(fileName).Using(stream => - { - if (Bar.IsValid(stream)) - { - _fontContext.Read(Bar.Read(stream)); - InvalidateFontContext(); - } - }); - - private void SaveFontInfoFile(string fileName) - { - throw new NotImplementedException(); - } - - private void InvalidateFontContext() - { - RenderingMessageContext context; - - switch (EncodingType) - { - case EncodingType.European: - switch (FontType) - { - case FontType.System: - context = _fontContext.ToKh2EuSystemTextContext(); - break; - case FontType.Event: - context = _fontContext.ToKh2EuEventTextContext(); - break; - default: - context = null; - break; - } - break; - case EncodingType.Japanese: - switch (FontType) - { - case FontType.System: - context = _fontContext.ToKh2JpSystemTextContext(); - break; - case FontType.Event: - context = _fontContext.ToKh2JpEventTextContext(); - break; - default: - context = null; - break; - } - break; - case EncodingType.Turkish: - switch (FontType) - { - case FontType.System: - context = _fontContext.ToKh2TRSystemTextContext(); - break; - case FontType.Event: - context = _fontContext.ToKh2TREventTextContext(); - break; - default: - context = null; - break; - } - break; - default: - context = null; - break; - } - - TextEditor.TextContext = context; - } - - private bool TryReadMsg(Stream stream) - { - if (!Msg.IsValid(stream)) - return false; - - TextEditor.MessageEntries = Msg.Read(stream); - return true; - } - - private bool TryReadMsgAsBar(Stream stream) - { - if (!Bar.IsValid(stream)) - return false; - - var msgEntry = Bar.Read(stream) - .FirstOrDefault(x => x.Type == Bar.EntryType.List); - - if (msgEntry == null) - return false; - - _barEntryName = msgEntry.Name; - return TryReadMsg(msgEntry.Stream); - } - - private void WriteMsg(Stream stream) - { - if (OptimizeOnSave) - Msg.WriteOptimized(stream, TextEditor.MessageEntries); - else - Msg.Write(stream, TextEditor.MessageEntries); - stream.SetLength(stream.Position); - } - - private void WriteBar(List entries, Stream stream) - { - var newEntries = entries - .ForEntry(Bar.EntryType.List, _barEntryName, 0, entry => WriteMsg(entry.Stream)); - - Bar.Write(stream, newEntries); - } - - private void LoadSupportFiles(string basePath) - { - const string FontImageFileName = "fontimage.bar"; - var fontImageFileName = Path.Combine(basePath, FontImageFileName); - if (File.Exists(fontImageFileName)) - OpenFontImageFile(fontImageFileName); - - const string FontInfoFileName = "fontinfo.bar"; - var fontInfoFileName = Path.Combine(basePath, FontInfoFileName); - if (File.Exists(fontInfoFileName)) - OpenFontImageFile(fontInfoFileName); - } - - private void AutodetectRegion() - { - switch (IsMsgJapanese()) - { - case true: - EncodingType = EncodingType.Japanese; - break; - case false: - EncodingType = EncodingType.European; - break; - } - } - - private bool? IsMsgJapanese() - { - const ushort FakeTextId = 0x0ADC; - if (TextEditor?.MessageEntries == null) - return null; - - var messageEntry = TextEditor.MessageEntries.FirstOrDefault(x => x.Id == FakeTextId); - var data = messageEntry?.Data; - if (data == null || data.Length == 0) - return null; - - return data.Length != 5; - } - } -} +using OpenKh.Tools.Common; +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Kh2.Contextes; +using OpenKh.Kh2.Extensions; +using OpenKh.Tools.Kh2TextEditor.Types; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; +using OpenKh.Tools.Kh2TextEditor.Services; +using System.Text; +using OpenKh.Engine.Renders; +using OpenKh.Engine.Extensions; + +namespace OpenKh.Tools.Kh2TextEditor.ViewModels +{ + public class MainViewModel : BaseNotifyPropertyChanged + { + private const string DefaultName = "FAKE"; + private const string GuideUrl = "https://openkh.dev/kh2/tool/Kh2TextEditor/OpenKh.Tools.Kh2TextEditor"; + private static string ApplicationName = Utilities.GetApplicationName(); + private string _fileName; + private string _barEntryName; + private FontContext _fontContext = new FontContext(); + private FontType _fontType; + private EncodingType _encodingType; + + private static readonly List MessageFilters = FileDialogFilterComposer + .Compose() + .AddExtensions("Message files", "bar", "msg", "bin") + .AddAllFiles(); + + private static readonly List FontImageFilters = FileDialogFilterComposer + .Compose() + .AddExtensions("fontimage.bar", "bar") + .AddAllFiles(); + + private static readonly List FontInfoFilters = FileDialogFilterComposer + .Compose() + .AddExtensions("fontinfo.bar", "bar") + .AddAllFiles(); + + private static readonly List ExportFilters = FileDialogFilterComposer + .Compose() + .Concat(TextExporters.GetAll().Select(x => FileDialogFilter.ByExtensions(x.Filter().Item1, x.Filter().Item2))) + .ToList(); + + private static readonly List ImportFilters = FileDialogFilterComposer + .Compose() + .Concat(TextImporters.GetAll().Select(x => FileDialogFilter.ByExtensions(x.Filter().Item1, x.Filter().Item2))) + .ToList(); + + public string Title => $"{_barEntryName ?? DefaultName} | {FileName ?? "untitled"} | {ApplicationName}"; + + private string FileName + { + get => _fileName; + set + { + _fileName = value; + OnPropertyChanged(nameof(Title)); + } + } + + private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + public RelayCommand OpenCommand { get; } + public RelayCommand SaveCommand { get; } + public RelayCommand SaveAsCommand { get; } + public RelayCommand ExportMessageAsCommand { get; } + public RelayCommand ImportMessageFromCommand { get; } + + public RelayCommand ExitCommand { get; } + public RelayCommand GuideCommand { get; } + public RelayCommand AboutCommand { get; } + + public RelayCommand OpenFontImageCommand { get; } + public RelayCommand SaveFontImageCommand { get; } + public RelayCommand EditFontImageCommand { get; } + public RelayCommand OpenFontInfoCommand { get; } + public RelayCommand SaveFontInfoCommand { get; } + public RelayCommand EditFontInfoCommand { get; } + + public TextEditorViewModel TextEditor { get; private set; } + + public bool OptimizeOnSave { get; set; } + + public FontType FontType + { + get => _fontType; + set + { + _fontType = value; + InvalidateFontContext(); + } + } + + public EncodingType EncodingType + { + get => _encodingType; + set + { + _encodingType = value; + InvalidateFontContext(); + } + } + + public MainViewModel() + { + OpenCommand = new RelayCommand(x => + { + FileDialog.OnOpen(fileName => + { + OpenFile(fileName); + }, MessageFilters); + }, x => true); + + SaveCommand = new RelayCommand(x => + { + if (!string.IsNullOrEmpty(FileName)) + { + SaveFile(FileName, FileName); + } + else + { + SaveAsCommand.Execute(x); + } + }, x => true); + + SaveAsCommand = new RelayCommand(x => + { + FileDialog.OnSave(fileName => + { + SaveFile(FileName, fileName); + FileName = fileName; + }, MessageFilters); + }, x => true); + + ExportMessageAsCommand = new RelayCommand(x => + { + FileDialog.OnSave(fileName => + { + var selectedExtension = $"{Path.GetExtension(fileName).TrimStart('.')}"; + + ExportMessageAsFile( + fileName: fileName, + textExporter: TextExporters.FindFromFile(fileName) + ); + }, ExportFilters); + }, x => true); + + ImportMessageFromCommand = new RelayCommand(x => + { + FileDialog.OnOpen(fileName => + { + var selectedExtension = $"{Path.GetExtension(fileName).TrimStart('.')}"; + + var textImporter = TextImporters.FindFromFile(fileName); + if (textImporter != null) + { + ImportMessageFromFile( + fileName: fileName, + textImporter + ); + } + else + { + MessageBox.Show($"Failed to match text decoder for your file:\n{fileName}"); + } + }, ImportFilters); + }, x => true); + + ExitCommand = new RelayCommand(x => + { + Window.Close(); + }, x => true); + + OpenFontImageCommand = new RelayCommand(x => + { + FileDialog.OnOpen(fileName => + { + OpenFontImageFile(fileName); + }, FontImageFilters); + }, x => true); + + SaveFontImageCommand = new RelayCommand(x => + { + FileDialog.OnSave(fileName => + { + SaveFontImageFile(fileName); + }, FontImageFilters); + }, x => true); + + OpenFontInfoCommand = new RelayCommand(x => + { + FileDialog.OnOpen(fileName => + { + OpenFontInfoFile(fileName); + }, FontInfoFilters); + }, x => true); + + SaveFontInfoCommand = new RelayCommand(x => + { + FileDialog.OnSave(fileName => + { + SaveFontInfoFile(fileName); + }, FontInfoFilters); + }, x => true); + + GuideCommand = new RelayCommand(x => + { + Process.Start(new ProcessStartInfo(GuideUrl)); + }, x => true); + + AboutCommand = new RelayCommand(x => + { + new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); + }, x => true); + + TextEditor = new TextEditorViewModel(); + FontType = FontType.System; + } + + public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => + { + _barEntryName = null; + if (!TryReadMsg(stream) && !TryReadMsgAsBar(stream)) + { + MessageBox.Show(Window, "Invalid or not existing Message data found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + if (_barEntryName == null) + { + _barEntryName = Path.GetFileNameWithoutExtension(fileName); + if (_barEntryName.Length > 4) + _barEntryName = _barEntryName.Substring(0, 4); + + _barEntryName = _barEntryName.ToLower(); + } + + FileName = fileName; + LoadSupportFiles(Path.GetDirectoryName(fileName)); + AutodetectRegion(); + + return true; + }); + + public void SaveFile(string previousFileName, string fileName) + { + if (File.Exists(previousFileName)) + { + bool isBar = false; + List entries; + + entries = File.OpenRead(previousFileName).Using(stream => + { + isBar = Bar.IsValid(stream); + return isBar ? Bar.Read(stream) : null; + }); + + if (isBar) + File.Create(fileName).Using(stream => WriteBar(entries, stream)); + else + File.Create(fileName).Using(WriteMsg); + } + else + { + File.Create(fileName).Using(WriteMsg); + } + } + + public void ExportMessageAsFile(string fileName, ITextExporter textExporter) + { + new StreamWriter(fileName, false, Encoding.UTF8).Using( + writer => textExporter.Export( + TextEditor.Messages + .Select( + source => new ExchangeableMessage + { + Id = source.Id, + Text = source.Text, + } + ), + writer + ) + ); + } + + public void ImportMessageFromFile(string fileName, ITextImporter textImporter) + { + var importedMessages = new StreamReader(fileName, Encoding.UTF8).Using( + reader => textImporter.Import(reader) + .ToArray() // make sure to import all messages from file before closing StreamReader! + ); + + foreach (var importMessage in importedMessages) + { + var found = TextEditor.Messages.SingleOrDefault(it => it.Id == importMessage.Id); + if (found != null) + { + found.Text = importMessage.Text; + } + } + } + + public void OpenFontImageFile(string fileName) => File.OpenRead(fileName).Using(stream => + { + if (Bar.IsValid(stream)) + { + _fontContext.Read(Bar.Read(stream)); + InvalidateFontContext(); + } + }); + + private void SaveFontImageFile(string fileName) + { + throw new NotImplementedException(); + } + + public void OpenFontInfoFile(string fileName) => File.OpenRead(fileName).Using(stream => + { + if (Bar.IsValid(stream)) + { + _fontContext.Read(Bar.Read(stream)); + InvalidateFontContext(); + } + }); + + private void SaveFontInfoFile(string fileName) + { + throw new NotImplementedException(); + } + + private void InvalidateFontContext() + { + RenderingMessageContext context; + + switch (EncodingType) + { + case EncodingType.European: + switch (FontType) + { + case FontType.System: + context = _fontContext.ToKh2EuSystemTextContext(); + break; + case FontType.Event: + context = _fontContext.ToKh2EuEventTextContext(); + break; + default: + context = null; + break; + } + break; + case EncodingType.Japanese: + switch (FontType) + { + case FontType.System: + context = _fontContext.ToKh2JpSystemTextContext(); + break; + case FontType.Event: + context = _fontContext.ToKh2JpEventTextContext(); + break; + default: + context = null; + break; + } + break; + case EncodingType.Turkish: + switch (FontType) + { + case FontType.System: + context = _fontContext.ToKh2TRSystemTextContext(); + break; + case FontType.Event: + context = _fontContext.ToKh2TREventTextContext(); + break; + default: + context = null; + break; + } + break; + default: + context = null; + break; + } + + TextEditor.TextContext = context; + } + + private bool TryReadMsg(Stream stream) + { + if (!Msg.IsValid(stream)) + return false; + + TextEditor.MessageEntries = Msg.Read(stream); + return true; + } + + private bool TryReadMsgAsBar(Stream stream) + { + if (!Bar.IsValid(stream)) + return false; + + var msgEntry = Bar.Read(stream) + .FirstOrDefault(x => x.Type == Bar.EntryType.List); + + if (msgEntry == null) + return false; + + _barEntryName = msgEntry.Name; + return TryReadMsg(msgEntry.Stream); + } + + private void WriteMsg(Stream stream) + { + if (OptimizeOnSave) + Msg.WriteOptimized(stream, TextEditor.MessageEntries); + else + Msg.Write(stream, TextEditor.MessageEntries); + stream.SetLength(stream.Position); + } + + private void WriteBar(List entries, Stream stream) + { + var newEntries = entries + .ForEntry(Bar.EntryType.List, _barEntryName, 0, entry => WriteMsg(entry.Stream)); + + Bar.Write(stream, newEntries); + } + + private void LoadSupportFiles(string basePath) + { + const string FontImageFileName = "fontimage.bar"; + var fontImageFileName = Path.Combine(basePath, FontImageFileName); + if (File.Exists(fontImageFileName)) + OpenFontImageFile(fontImageFileName); + + const string FontInfoFileName = "fontinfo.bar"; + var fontInfoFileName = Path.Combine(basePath, FontInfoFileName); + if (File.Exists(fontInfoFileName)) + OpenFontImageFile(fontInfoFileName); + } + + private void AutodetectRegion() + { + switch (IsMsgJapanese()) + { + case true: + EncodingType = EncodingType.Japanese; + break; + case false: + EncodingType = EncodingType.European; + break; + } + } + + private bool? IsMsgJapanese() + { + const ushort FakeTextId = 0x0ADC; + if (TextEditor?.MessageEntries == null) + return null; + + var messageEntry = TextEditor.MessageEntries.FirstOrDefault(x => x.Id == FakeTextId); + var data = messageEntry?.Data; + if (data == null || data.Length == 0) + return null; + + return data.Length != 5; + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/ViewModels/TextEditorViewModel.cs b/OpenKh.Tools.Kh2TextEditor/ViewModels/TextEditorViewModel.cs index 77b082a47..b274f2b9c 100644 --- a/OpenKh.Tools.Kh2TextEditor/ViewModels/TextEditorViewModel.cs +++ b/OpenKh.Tools.Kh2TextEditor/ViewModels/TextEditorViewModel.cs @@ -1,230 +1,230 @@ -using OpenKh.Engine.Renders; -using OpenKh.Kh2; -using OpenKh.Kh2.Messages; -using OpenKh.Tools.Common.Rendering; -using OpenKh.Tools.Kh2TextEditor.Interfaces; -using OpenKh.Tools.Kh2TextEditor.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Windows; -using System.Windows.Controls; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; - -using ColorPickerWPF; -using System.Windows.Media; - -namespace OpenKh.Tools.Kh2TextEditor.ViewModels -{ - public class TextEditorViewModel : BaseNotifyPropertyChanged, ICurrentMessageEncoder, IInvalidateErrorCount - { - private MessagesModel _messages; - private List _msgs; - private IMessageEncoder _currentMessageEncoder; - private MessageModel _selectedItem; - private string _currentText; - private string _searchTerm; - private RenderingMessageContext textContext; - private bool _showErrors; - - public RelayCommand HandleAddition { get; } - public RelayCommand HandleRemoval { get; } - public RelayCommand HandleComm { get; } - public RelayCommand HandleIcon { get; } - - public List MessageEntries - { - get => _msgs; - set - { - _msgs = value; - ResetMessagesView(); - } - } - - public ISpriteDrawing Drawing { get; } - - public MessagesModel Messages - { - get => _messages; - set - { - _messages = value; - OnPropertyChanged(); - } - } - - public MessageModel SelectedItem - { - get => _selectedItem; - set - { - _selectedItem = value; - _currentText = _selectedItem?.Text; - OnPropertyChanged(); - OnPropertyChanged(nameof(Text)); - } - } - - - public string Text - { - get => _currentText; - set - { - var selectedItem = SelectedItem; - if (selectedItem == null) - return; - - _currentText = value; - selectedItem.Text = value; - OnPropertyChanged(); - } - } - - public string SearchTerm - { - get => _searchTerm; - set - { - _searchTerm = value; - PerformFiltering(); - } - } - - public RenderingMessageContext TextContext - { - get => textContext; - set - { - textContext = value; - OnPropertyChanged(); - - if (CurrentMessageEncoder != textContext.Encoder) - { - CurrentMessageEncoder = textContext.Encoder; - } - } - } - - public IMessageEncoder CurrentMessageEncoder - { - get => _currentMessageEncoder; - private set - { - _currentMessageEncoder = value; - _messages?.InvalidateText(); - OnPropertyChanged(nameof(SelectedItem)); - OnPropertyChanged(); - } - } - - public bool ShowErrors - { - get => _showErrors; - set - { - _showErrors = value; - PerformFiltering(); - } - } - - public int ErrorCount => _messages.Items.Count(x => !x.DoesNotContainErrors); - - public Visibility AnyErrorVisibility => ErrorCount == 0 ? Visibility.Collapsed : Visibility.Visible; - - public TextEditorViewModel() - { - Drawing = new SpriteDrawingDirect3D(); - CurrentMessageEncoder = Encoders.InternationalSystem; - _messages = new MessagesModel(this, this, new Msg.Entry[] { }); - - HandleRemoval = new RelayCommand(x => - { - MessageEntries.RemoveAll(x => x.Id == SelectedItem.Id); - ResetMessagesView(); - }); - - HandleAddition = new RelayCommand(x => - { - int _id = MessageEntries.Max(x => x.Id); - MessageEntries.Add(new Msg.Entry() { Id = _id + 1, Data = CurrentMessageEncoder.Encode(MsgSerializer.DeserializeText("FAKE").ToList()) }); - ResetMessagesView(); - }); - - HandleComm = new RelayCommand(x => - { - int _o = Convert.ToInt32(x); - - switch (_o) - { - case 0: - Text += "{:reset}"; - break; - case 1: - { - Color _color; - bool _ok = ColorPickerWindow.ShowDialog(out _color); - - if (_ok) - Text += "{:color " + string.Format("#{0}{1}{2}{3}", _color.R.ToString("X2"), _color.G.ToString("X2"), _color.B.ToString("X2"), _color.A.ToString("X2")) + "}"; - } - break; - case 2: - Text += "{:scale 16}"; - break; - case 3: - Text += "{:width 100}"; - break; - case 4: - Text += "{:clear}"; - break; - case 5: - Text += "{:position 0,0}"; - break; - } - }); - - HandleIcon = new RelayCommand(x => - { - Text += "{:icon " + x + "}"; - }); - } - - public void SelectMessage(int id) => SelectedItem = Messages.GetMessage(id); - - public void InvalidateErrorCount() - { - if (!_messages.Items.Any(x => !x.DoesNotContainErrors) && ShowErrors) - ShowErrors = false; - - OnPropertyChanged(nameof(ErrorCount)); - OnPropertyChanged(nameof(AnyErrorVisibility)); - } - - private void ResetMessagesView() - { - if (MessageEntries != null) - Messages = new MessagesModel(this, this, MessageEntries); - } - - private void PerformFiltering() - { - if (string.IsNullOrWhiteSpace(_searchTerm)) - _messages.Filter(x => Filter(x, FilterNone)); - else - _messages.Filter(x => Filter(x, FilterTextAndId)); - } - - private bool Filter(MessageModel arg, Func filter) => - FilterError(arg) && filter(arg); - - private bool FilterError(MessageModel arg) => !ShowErrors || (ShowErrors && arg.DoesNotContainErrors == false); - - private bool FilterNone(MessageModel arg) => true; - - private bool FilterTextAndId(MessageModel arg) => - arg.Title.ToLower().Contains(SearchTerm.ToLower()); - } -} +using OpenKh.Engine.Renders; +using OpenKh.Kh2; +using OpenKh.Kh2.Messages; +using OpenKh.Tools.Common.Rendering; +using OpenKh.Tools.Kh2TextEditor.Interfaces; +using OpenKh.Tools.Kh2TextEditor.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; + +using ColorPickerWPF; +using System.Windows.Media; + +namespace OpenKh.Tools.Kh2TextEditor.ViewModels +{ + public class TextEditorViewModel : BaseNotifyPropertyChanged, ICurrentMessageEncoder, IInvalidateErrorCount + { + private MessagesModel _messages; + private List _msgs; + private IMessageEncoder _currentMessageEncoder; + private MessageModel _selectedItem; + private string _currentText; + private string _searchTerm; + private RenderingMessageContext textContext; + private bool _showErrors; + + public RelayCommand HandleAddition { get; } + public RelayCommand HandleRemoval { get; } + public RelayCommand HandleComm { get; } + public RelayCommand HandleIcon { get; } + + public List MessageEntries + { + get => _msgs; + set + { + _msgs = value; + ResetMessagesView(); + } + } + + public ISpriteDrawing Drawing { get; } + + public MessagesModel Messages + { + get => _messages; + set + { + _messages = value; + OnPropertyChanged(); + } + } + + public MessageModel SelectedItem + { + get => _selectedItem; + set + { + _selectedItem = value; + _currentText = _selectedItem?.Text; + OnPropertyChanged(); + OnPropertyChanged(nameof(Text)); + } + } + + + public string Text + { + get => _currentText; + set + { + var selectedItem = SelectedItem; + if (selectedItem == null) + return; + + _currentText = value; + selectedItem.Text = value; + OnPropertyChanged(); + } + } + + public string SearchTerm + { + get => _searchTerm; + set + { + _searchTerm = value; + PerformFiltering(); + } + } + + public RenderingMessageContext TextContext + { + get => textContext; + set + { + textContext = value; + OnPropertyChanged(); + + if (CurrentMessageEncoder != textContext.Encoder) + { + CurrentMessageEncoder = textContext.Encoder; + } + } + } + + public IMessageEncoder CurrentMessageEncoder + { + get => _currentMessageEncoder; + private set + { + _currentMessageEncoder = value; + _messages?.InvalidateText(); + OnPropertyChanged(nameof(SelectedItem)); + OnPropertyChanged(); + } + } + + public bool ShowErrors + { + get => _showErrors; + set + { + _showErrors = value; + PerformFiltering(); + } + } + + public int ErrorCount => _messages.Items.Count(x => !x.DoesNotContainErrors); + + public Visibility AnyErrorVisibility => ErrorCount == 0 ? Visibility.Collapsed : Visibility.Visible; + + public TextEditorViewModel() + { + Drawing = new SpriteDrawingDirect3D(); + CurrentMessageEncoder = Encoders.InternationalSystem; + _messages = new MessagesModel(this, this, new Msg.Entry[] { }); + + HandleRemoval = new RelayCommand(x => + { + MessageEntries.RemoveAll(x => x.Id == SelectedItem.Id); + ResetMessagesView(); + }); + + HandleAddition = new RelayCommand(x => + { + int _id = MessageEntries.Max(x => x.Id); + MessageEntries.Add(new Msg.Entry() { Id = _id + 1, Data = CurrentMessageEncoder.Encode(MsgSerializer.DeserializeText("FAKE").ToList()) }); + ResetMessagesView(); + }); + + HandleComm = new RelayCommand(x => + { + int _o = Convert.ToInt32(x); + + switch (_o) + { + case 0: + Text += "{:reset}"; + break; + case 1: + { + Color _color; + bool _ok = ColorPickerWindow.ShowDialog(out _color); + + if (_ok) + Text += "{:color " + string.Format("#{0}{1}{2}{3}", _color.R.ToString("X2"), _color.G.ToString("X2"), _color.B.ToString("X2"), _color.A.ToString("X2")) + "}"; + } + break; + case 2: + Text += "{:scale 16}"; + break; + case 3: + Text += "{:width 100}"; + break; + case 4: + Text += "{:clear}"; + break; + case 5: + Text += "{:position 0,0}"; + break; + } + }); + + HandleIcon = new RelayCommand(x => + { + Text += "{:icon " + x + "}"; + }); + } + + public void SelectMessage(int id) => SelectedItem = Messages.GetMessage(id); + + public void InvalidateErrorCount() + { + if (!_messages.Items.Any(x => !x.DoesNotContainErrors) && ShowErrors) + ShowErrors = false; + + OnPropertyChanged(nameof(ErrorCount)); + OnPropertyChanged(nameof(AnyErrorVisibility)); + } + + private void ResetMessagesView() + { + if (MessageEntries != null) + Messages = new MessagesModel(this, this, MessageEntries); + } + + private void PerformFiltering() + { + if (string.IsNullOrWhiteSpace(_searchTerm)) + _messages.Filter(x => Filter(x, FilterNone)); + else + _messages.Filter(x => Filter(x, FilterTextAndId)); + } + + private bool Filter(MessageModel arg, Func filter) => + FilterError(arg) && filter(arg); + + private bool FilterError(MessageModel arg) => !ShowErrors || (ShowErrors && arg.DoesNotContainErrors == false); + + private bool FilterNone(MessageModel arg) => true; + + private bool FilterTextAndId(MessageModel arg) => + arg.Title.ToLower().Contains(SearchTerm.ToLower()); + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Views/MainWindow.xaml.cs b/OpenKh.Tools.Kh2TextEditor/Views/MainWindow.xaml.cs index 0f27d24ce..7bc6992c0 100644 --- a/OpenKh.Tools.Kh2TextEditor/Views/MainWindow.xaml.cs +++ b/OpenKh.Tools.Kh2TextEditor/Views/MainWindow.xaml.cs @@ -1,24 +1,24 @@ -using System; -using System.Windows; -using OpenKh.Tools.Kh2TextEditor.ViewModels; - -namespace OpenKh.Tools.Kh2TextEditor.Views -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - public MainWindow() - { - DataContext = new MainViewModel(); - - InitializeComponent(); - } - - protected override void OnInitialized(EventArgs e) - { - base.OnInitialized(e); - } - } -} +using System; +using System.Windows; +using OpenKh.Tools.Kh2TextEditor.ViewModels; + +namespace OpenKh.Tools.Kh2TextEditor.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + DataContext = new MainViewModel(); + + InitializeComponent(); + } + + protected override void OnInitialized(EventArgs e) + { + base.OnInitialized(e); + } + } +} diff --git a/OpenKh.Tools.Kh2TextEditor/Views/TextEditorView.xaml.cs b/OpenKh.Tools.Kh2TextEditor/Views/TextEditorView.xaml.cs index 414a24c91..4e82c3d21 100644 --- a/OpenKh.Tools.Kh2TextEditor/Views/TextEditorView.xaml.cs +++ b/OpenKh.Tools.Kh2TextEditor/Views/TextEditorView.xaml.cs @@ -1,28 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace OpenKh.Tools.Kh2TextEditor.Views -{ - /// - /// Interaction logic for TextEditorView.xaml - /// - public partial class TextEditorView : UserControl - { - public TextEditorView() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace OpenKh.Tools.Kh2TextEditor.Views +{ + /// + /// Interaction logic for TextEditorView.xaml + /// + public partial class TextEditorView : UserControl + { + public TextEditorView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.LayoutEditor/App.cs b/OpenKh.Tools.LayoutEditor/App.cs index 6f74d2b82..dbb7e352a 100644 --- a/OpenKh.Tools.LayoutEditor/App.cs +++ b/OpenKh.Tools.LayoutEditor/App.cs @@ -1,621 +1,621 @@ -using ImGuiNET; -using Microsoft.Xna.Framework.Input; -using OpenKh.Common; -using OpenKh.Engine.Renders; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using OpenKh.Tools.Common; -using OpenKh.Tools.Common.CustomImGui; -using OpenKh.Tools.LayoutEditor.Dialogs; -using OpenKh.Tools.LayoutEditor.Interfaces; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Numerics; -using System.Windows; -using Xe.Tools.Wpf.Dialogs; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; - -namespace OpenKh.Tools.LayoutEditor -{ - public class App : IEditorSettings, IDisposable - { - private static readonly List Filters = FileDialogFilterComposer - .Compose() - .AddPatterns("All supported files", "2ld;*.lad;*.2dd;*.map;P_*.a.*;00font.bar;10font.bar") - .AddExtensions("2LD Layout container file", "2ld", "lad") - .AddExtensions("2DD Sequence container file", "2dd") - .AddExtensions("MAP file", "map") - .AddExtensions("Character file", "a.*") - .AddPatterns("00font and 10font", "00font.bar", "10font.bar") - .AddAllFiles(); - private static readonly List ImzFilter = FileDialogFilterComposer - .Compose() - .AddExtensions("Image container IMGZ", "imz") - .AddAllFiles(); - private static readonly List ImdFilter = FileDialogFilterComposer - .Compose() - .AddExtensions("Image IMGD", "imd") - .AddAllFiles(); - private const string DefaultName = "FAKE"; - - private readonly MonoGameImGuiBootstrap _bootstrap; - private bool _exitFlag = false; - - private string _animationName; - private string _spriteName; - private string _fileName; - private ToolInvokeDesc _toolInvokeDesc; - private IApp _app; - - private bool _linkToPcsx2; - private ProcessStream _processStream; - private int _processOffset; - - private const string LinkToPcsx2ActionName = "Open file and link it to PCSX2"; - private const string ResourceSelectionDialogTitle = "Resource selection"; - private bool _isResourceSelectionDialogOpening; - private bool _isResourceSelectingLayout; - private ResourceSelectionDialog _resourceSelectionDialog; - private Dictionary _keyMapping = new Dictionary(); - - public event IEditorSettings.ChangeBackground OnChangeBackground; - - public string Title - { - get - { - var contentName = IsBar ? $"{AnimationName ?? DefaultName},{TextureName ?? DefaultName} | " : string.Empty; - var fileName = IsToolDesc ? _toolInvokeDesc.Title : (FileName ?? "untitled"); - if (_processStream != null) - fileName = $"{fileName}@pcsx2:{_processOffset}"; - - return $"{contentName}{fileName} | {MonoGameImGuiBootstrap.ApplicationName}"; - } - } - - private string FileName - { - get => _fileName; - set - { - _fileName = value; - UpdateTitle(); - } - } - - public bool IsToolDesc => _toolInvokeDesc != null; - public ISaveBar CurrentEditor { get; private set; } - - public bool IsBar { get; set; } - - public string AnimationName - { - get => _animationName; - set => _animationName = value.Length > 4 ? value.Substring(0, 4) : value; - } - - public string TextureName - { - get => _spriteName; - set => _spriteName = value.Length > 4 ? value.Substring(0, 4) : value; - } - - public bool CheckerboardBackground { get; set; } - public ColorF EditorBackground - { - get => new ColorF(Settings.Default.BgColorR, Settings.Default.BgColorG, - Settings.Default.BgColorB, 1f); - set - { - Settings.Default.BgColorR = value.R; - Settings.Default.BgColorG = value.G; - Settings.Default.BgColorB = value.B; - Settings.Default.Save(); - } - } - - public bool ShowViewportOriginal - { - get => Settings.Default.ShowViewportOriginal; - set - { - Settings.Default.ShowViewportOriginal = value; - Settings.Default.Save(); - } - } - - public bool ShowViewportRemix - { - get => Settings.Default.ShowViewportRemix; - set - { - Settings.Default.ShowViewportRemix = value; - Settings.Default.Save(); - } - } - - public bool IsViewportOnTop - { - get => Settings.Default.IsViewportOnTop; - set - { - Settings.Default.IsViewportOnTop = value; - Settings.Default.Save(); - } - } - - public App(MonoGameImGuiBootstrap bootstrap) - { - _bootstrap = bootstrap; - _bootstrap.Title = Title; - AddKeyMapping(Keys.O, MenuFileOpenWithoutPcsx2); - AddKeyMapping(Keys.L, MenuFileOpenPcsx2); - AddKeyMapping(Keys.S, MenuFileSave); - } - - public bool MainLoop() - { - ProcessKeyMapping(); - - bool dummy = true; - if (ImGui.BeginPopupModal(ResourceSelectionDialogTitle, ref dummy, - ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal | ImGuiWindowFlags.AlwaysAutoResize)) - { - _resourceSelectionDialog.Run(); - ImGui.EndPopup(); - - if (_resourceSelectionDialog.HasResourceBeenSelected) - { - if (_isResourceSelectingLayout) - OpenLayoutEditor(_resourceSelectionDialog.SelectedAnimation, - _resourceSelectionDialog.SelectedTexture); - else - OpenSequenceEditor(_resourceSelectionDialog.SelectedAnimation, - _resourceSelectionDialog.SelectedTexture); - } - } - - ImGuiEx.MainWindow(() => - { - MainMenu(); - MainWindow(); - }); - - if (_isResourceSelectionDialogOpening) - { - ImGui.OpenPopup(ResourceSelectionDialogTitle); - _isResourceSelectionDialogOpening = false; - } - - return _exitFlag; - } - - public void Dispose() - { - CloseProcessStream(); - } - - private void MainWindow() - { - if (_app != null) - { - _app.Run(); - } - else - { - ImGui.Text("No files loaded at the moment"); - } - } - - void MainMenu() - { - ForMenuBar(() => - { - ForMenu("File", () => - { - ForMenuItem("Open...", "CTRL+O", MenuFileOpenWithoutPcsx2); - ForMenuItem($"{LinkToPcsx2ActionName}...", "CTRL+L", MenuFileOpenPcsx2); - ForMenuItem("Save", "CTRL+S", MenuFileSave, CurrentEditor != null); - ForMenuItem("Save as...", MenuFileSaveAs, CurrentEditor != null); - ImGui.Separator(); - ForMenu("Preferences", () => - { - //var checkerboardBackground = CheckerboardBackground; - //if (ImGui.Checkbox("Checkerboard background", ref checkerboardBackground)) - //{ - // CheckerboardBackground = false; - // OnChangeBackground?.Invoke(this, this); - //} - - var editorBackground = new Vector3(EditorBackground.R, - EditorBackground.G, EditorBackground.B); - if (ImGui.ColorEdit3("Background color", ref editorBackground)) - { - EditorBackground = new ColorF(editorBackground.X, - editorBackground.Y, editorBackground.Z, 1f); - OnChangeBackground?.Invoke(this, this); - } - - ForMenuCheck("Show PS2 viewport", () => ShowViewportOriginal, x => ShowViewportOriginal = x); - ForMenuCheck("Show ReMIX viewport", () => ShowViewportRemix, x => ShowViewportRemix = x); - ForMenuCheck("Viewport always on top", () => IsViewportOnTop, x => IsViewportOnTop = x); - }); - ImGui.Separator(); - ForMenuItem("Exit", MenuFileExit); - }); - _app?.Menu(); - ForMenu("Help", () => - { - ForMenuItem("About", ShowAboutDialog); - }); - }); - } - - private void MenuFileOpen() - { - FileDialog.OnOpen(fileName => - { - OpenFile(fileName); - }, Filters); - } - - private void MenuFileOpenWithoutPcsx2() - { - _linkToPcsx2 = false; - CloseProcessStream(); - MenuFileOpen(); - } - - private void MenuFileOpenPcsx2() - { - CloseProcessStream(); - var processes = Process.GetProcessesByName("pcsx2"); - if (processes.Length == 0) - { - ShowLinkPcsx2ErrorProcessNotFound(); - return; - } - - _linkToPcsx2 = true; - MenuFileOpen(); - } - - private void MenuFileSave() - { - if (!string.IsNullOrEmpty(FileName)) - SaveFile(FileName, FileName); - else - MenuFileSaveAs(); - } - - private void MenuFileSaveAs() - { - FileDialog.OnSave(fileName => - { - SaveFile(FileName, fileName); - FileName = fileName; - }, Filters); - } - - private void MenuFileExit() => _exitFlag = true; - - public void OpenToolDesc(ToolInvokeDesc toolInvokeDesc) - { - _toolInvokeDesc = toolInvokeDesc; - OpenFile(_toolInvokeDesc.ActualFileName); - } - - public void OpenFile(string fileName, bool doNotShowLayoutSelectionDialog = false) - { - try - { - bool isSuccess; - if (File.OpenRead(fileName).Using(Layout.IsValid)) - { - IEnumerable imgd = null; - FileDialog.OnOpen(texFileName => - { - imgd = File.OpenRead(texFileName).Using(Imgz.Read); - }, ImzFilter); - - if (imgd != null) - { - using var layoutStream = File.OpenRead(fileName); - OpenLayoutEditor(layoutStream, imgd); - isSuccess = true; - IsBar = false; - } - else - isSuccess = false; - } - else if (File.OpenRead(fileName).Using(Sequence.IsValid)) - { - ShowError("SED files can not be opened directly."); - isSuccess = false; - IsBar = false; - } - else if (File.OpenRead(fileName).Using(Bar.IsValid)) - { - isSuccess = OpenBarContent(ReadBarEntriesFromFileName(fileName), doNotShowLayoutSelectionDialog); - IsBar = true; - } - else - { - ShowError("File not recognized."); - isSuccess = false; - } - - if (isSuccess) - FileName = fileName; - } - catch (Exception ex) - { - ShowError(ex.Message); - } - } - - public void SaveFile(string previousFileName, string fileName) - { - if (!IsBar) - { - var entry = CurrentEditor.SaveAnimation("dummy"); - using var stream = File.Create(fileName); - entry.Stream.SetPosition(0).CopyTo(stream); - } - else - { - SaveFileAsBar(previousFileName, fileName); - } - } - - public void SaveFileAsBar(string previousFileName, string fileName) - { - var existingEntries = File.Exists(previousFileName) ? - ReadBarEntriesFromFileName(previousFileName) : new List(); - - var animationEntry = CurrentEditor.SaveAnimation(AnimationName); - if (_processStream != null) - { - animationEntry.Stream.SetPosition(0); - _processStream.SetPosition(_processOffset); - animationEntry.Stream.CopyTo(_processStream); - animationEntry.Stream.SetPosition(0); - } - - var newEntries = existingEntries - .AddOrReplace(animationEntry) - .AddOrReplace(CurrentEditor.SaveTexture(TextureName)); - File.Create(fileName).Using(stream => Bar.Write(stream, newEntries)); - - if (IsToolDesc) - _toolInvokeDesc.ContentChange = ToolInvokeDesc.ContentChangeInfo.File; - } - - private static IEnumerable ReadBarEntriesFromFileName(string fileName) => - File.OpenRead(fileName).Using(stream => - { - if (!Bar.IsValid(stream)) - throw new InvalidDataException("Not a bar file"); - - return Bar.Read(stream); - }); - - private bool OpenBarContent(IEnumerable entries, bool doNotShowLayoutSelectionDialog = false) - { - var layoutEntries = entries.Count(x => x.Type == Bar.EntryType.Layout); - var sequenceEntries = entries.Count(x => x.Type == Bar.EntryType.Seqd); - - if (DoesContainSequenceAnimations(entries)) - return Open2dd(entries); - if (DoesContainLayoutAnimations(entries)) - return Open2ld(entries, doNotShowLayoutSelectionDialog); - - throw new Exception("The specified file does not contain any sequence or layout content to be played."); - } - - private bool Open2ld(IEnumerable entries, bool doNotShowLayoutSelectionDialog = false) - { - var layoutEntries = entries.Count(x => x.Type == Bar.EntryType.Layout); - int imagesEntries = entries.Count(x => x.Type == Bar.EntryType.Imgz); - - if (layoutEntries == 0) - throw new Exception("No layout found."); - if (imagesEntries == 0) - throw new Exception("No image container found."); - if (layoutEntries > 1 || imagesEntries > 1) - { - OpenResourceSelectionDialog(entries, Bar.EntryType.Layout, Bar.EntryType.Imgz); - return true; - } - - var layoutEntry = entries.First(x => x.Type == Bar.EntryType.Layout); - var textureContainerEntry = entries.First(x => x.Type == Bar.EntryType.Imgz); - OpenLayoutEditor(layoutEntry, textureContainerEntry); - return true; - } - - private bool Open2dd(IEnumerable entries) - { - var sequenceEntries = entries.Count(x => x.Type == Bar.EntryType.Seqd); - int imagesEntries = entries.Count(x => x.Type == Bar.EntryType.Imgd); - - if (sequenceEntries == 0) - throw new Exception("No sequence found."); - if (imagesEntries == 0) - throw new Exception("No image found."); - if (sequenceEntries > 1 || imagesEntries > 1) - { - OpenResourceSelectionDialog(entries, Bar.EntryType.Seqd, Bar.EntryType.Imgd); - return true; - } - - var sequenceEntry = entries.First(x => x.Type == Bar.EntryType.Seqd); - var textureEntry = entries.First(x => x.Type == Bar.EntryType.Imgd); - OpenSequenceEditor(sequenceEntry, textureEntry); - return true; - } - - private void OpenResourceSelectionDialog(IEnumerable entries, - Bar.EntryType animationType, Bar.EntryType textureType) - { - _resourceSelectionDialog = new ResourceSelectionDialog( - entries, animationType, textureType); - _isResourceSelectionDialogOpening = true; - _isResourceSelectingLayout = animationType == Bar.EntryType.Layout; - } - - private void OpenSequenceEditor(Bar.Entry sequenceEntry, Bar.Entry textureEntry) - { - AnimationName = sequenceEntry.Name; - TextureName = textureEntry.Name; - - if (_linkToPcsx2) - { - _linkToPcsx2 = false; - if (!LinkSeqdToPcs2(sequenceEntry.Stream)) - return; - } - - var app = new AppSequenceEditor(_bootstrap, - this, - Sequence.Read(sequenceEntry.Stream.SetPosition(0)), - Imgd.Read(textureEntry.Stream)); - _app = app; - CurrentEditor = app; - } - - private void OpenLayoutEditor(Bar.Entry layoutEntry, Bar.Entry textureContainerEntry) - { - AnimationName = layoutEntry.Name; - TextureName = textureContainerEntry.Name; - OpenLayoutEditor(layoutEntry.Stream, Imgz.Read(textureContainerEntry.Stream)); - } - - private void OpenLayoutEditor(Stream layoutStream, IEnumerable images) - { - if (_linkToPcsx2) - { - _linkToPcsx2 = false; - if (!LinkLaydToPcs2(layoutStream)) - return; - } - - var app = new AppLayoutEditor(_bootstrap, - this, - Layout.Read(layoutStream.SetPosition(0)), - images); - _app = app; - CurrentEditor = app; - } - - private void UpdateTitle() - { - _bootstrap.Title = Title; - } - - private void AddKeyMapping(Keys key, Action action) - { - _keyMapping[key] = action; - } - - private void ProcessKeyMapping() - { - var k = Keyboard.GetState(); - if (k.IsKeyDown(Keys.LeftControl)) - { - var keys = k.GetPressedKeys(); - foreach (var key in keys) - { - if (_keyMapping.TryGetValue(key, out var action)) - action(); - } - } - } - - //private void OpenLayout(LayoutEntryModel layoutEntryModel) - //{ - // AnimationName = layoutEntryModel.Layout.Name; - // SpriteName = layoutEntryModel.Images.Name; - - // var texturesViewModel = new TexturesViewModel(layoutEntryModel.Images.Value); - - // var layoutEditorViewModel = new LayoutEditorViewModel(this, this, EditorDebugRenderingService) - // { - // SequenceGroups = new SequenceGroupsViewModel(layoutEntryModel.Layout.Value, texturesViewModel, EditorDebugRenderingService), - // Layout = layoutEntryModel.Layout.Value, - // Images = layoutEntryModel.Images.Value - // }; - - // CurrentEditor = layoutEditorViewModel; - // OnControlChanged?.Invoke(new LayoutEditorView() - // { - // DataContext = layoutEditorViewModel - // }); - //} - - private bool LinkLaydToPcs2(Stream stream) => - LinkToPcs2(stream, Layout.MagicCodeValidator, 0x1c); - - private bool LinkSeqdToPcs2(Stream stream) => - LinkToPcs2(stream, Sequence.MagicCodeValidator, 0x2c); - - private bool LinkToPcs2(Stream stream, uint magicCode, int headerLength) - { - var process = Process.GetProcessesByName("pcsx2").FirstOrDefault(); - if (process == null) - { - ShowLinkPcsx2ErrorProcessNotFound(); - return false; - } - - var processStream = new ProcessStream(process, ToolConstants.Pcsx2BaseAddress, ToolConstants.Ps2MemoryLength); - var bufferedStream = new BufferedStream(processStream, 0x10000); - - var header = stream.SetPosition(sizeof(uint)).ReadBytes(headerLength); - while (bufferedStream.Position < bufferedStream.Length) - { - if (bufferedStream.ReadUInt32() == magicCode) - { - // header matches. Check if the rest of 0x2c SEQD header matches as well... - if (header.SequenceEqual(bufferedStream.ReadBytes(headerLength))) - { - _processStream = processStream; - _processOffset = (int)(bufferedStream.Position - headerLength - sizeof(uint)); - return true; - } - } - } - - ShowLinkPcsx2ErrorFileNotFound(); - CloseProcessStream(); - return false; - } - - private void CloseProcessStream() - { - _processStream?.Dispose(); - _processStream = null; - } - - private static bool DoesContainSequenceAnimations(IEnumerable entries) => - entries.Any(x => x.Type == Bar.EntryType.Seqd); - - private static bool DoesContainLayoutAnimations(IEnumerable entries) => - entries.Any(x => x.Type == Bar.EntryType.Layout); - - private static void ShowLinkPcsx2ErrorProcessNotFound() => - ShowError("No PCSX2 process found.\nPlease run PCSX2 with Kingdom Hearts II/Re:CoM first and try again.", LinkToPcsx2ActionName); - - private static void ShowLinkPcsx2ErrorFileNotFound() => - ShowError("The file you specified can not be found on the running game.", LinkToPcsx2ActionName); - - public static void ShowError(string message, string title = "Error") => - MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Error); - - private void ShowAboutDialog() => - MessageBox.Show("OpenKH is amazing."); - } -} +using ImGuiNET; +using Microsoft.Xna.Framework.Input; +using OpenKh.Common; +using OpenKh.Engine.Renders; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using OpenKh.Tools.Common; +using OpenKh.Tools.Common.CustomImGui; +using OpenKh.Tools.LayoutEditor.Dialogs; +using OpenKh.Tools.LayoutEditor.Interfaces; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Numerics; +using System.Windows; +using Xe.Tools.Wpf.Dialogs; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; + +namespace OpenKh.Tools.LayoutEditor +{ + public class App : IEditorSettings, IDisposable + { + private static readonly List Filters = FileDialogFilterComposer + .Compose() + .AddPatterns("All supported files", "2ld;*.lad;*.2dd;*.map;P_*.a.*;00font.bar;10font.bar") + .AddExtensions("2LD Layout container file", "2ld", "lad") + .AddExtensions("2DD Sequence container file", "2dd") + .AddExtensions("MAP file", "map") + .AddExtensions("Character file", "a.*") + .AddPatterns("00font and 10font", "00font.bar", "10font.bar") + .AddAllFiles(); + private static readonly List ImzFilter = FileDialogFilterComposer + .Compose() + .AddExtensions("Image container IMGZ", "imz") + .AddAllFiles(); + private static readonly List ImdFilter = FileDialogFilterComposer + .Compose() + .AddExtensions("Image IMGD", "imd") + .AddAllFiles(); + private const string DefaultName = "FAKE"; + + private readonly MonoGameImGuiBootstrap _bootstrap; + private bool _exitFlag = false; + + private string _animationName; + private string _spriteName; + private string _fileName; + private ToolInvokeDesc _toolInvokeDesc; + private IApp _app; + + private bool _linkToPcsx2; + private ProcessStream _processStream; + private int _processOffset; + + private const string LinkToPcsx2ActionName = "Open file and link it to PCSX2"; + private const string ResourceSelectionDialogTitle = "Resource selection"; + private bool _isResourceSelectionDialogOpening; + private bool _isResourceSelectingLayout; + private ResourceSelectionDialog _resourceSelectionDialog; + private Dictionary _keyMapping = new Dictionary(); + + public event IEditorSettings.ChangeBackground OnChangeBackground; + + public string Title + { + get + { + var contentName = IsBar ? $"{AnimationName ?? DefaultName},{TextureName ?? DefaultName} | " : string.Empty; + var fileName = IsToolDesc ? _toolInvokeDesc.Title : (FileName ?? "untitled"); + if (_processStream != null) + fileName = $"{fileName}@pcsx2:{_processOffset}"; + + return $"{contentName}{fileName} | {MonoGameImGuiBootstrap.ApplicationName}"; + } + } + + private string FileName + { + get => _fileName; + set + { + _fileName = value; + UpdateTitle(); + } + } + + public bool IsToolDesc => _toolInvokeDesc != null; + public ISaveBar CurrentEditor { get; private set; } + + public bool IsBar { get; set; } + + public string AnimationName + { + get => _animationName; + set => _animationName = value.Length > 4 ? value.Substring(0, 4) : value; + } + + public string TextureName + { + get => _spriteName; + set => _spriteName = value.Length > 4 ? value.Substring(0, 4) : value; + } + + public bool CheckerboardBackground { get; set; } + public ColorF EditorBackground + { + get => new ColorF(Settings.Default.BgColorR, Settings.Default.BgColorG, + Settings.Default.BgColorB, 1f); + set + { + Settings.Default.BgColorR = value.R; + Settings.Default.BgColorG = value.G; + Settings.Default.BgColorB = value.B; + Settings.Default.Save(); + } + } + + public bool ShowViewportOriginal + { + get => Settings.Default.ShowViewportOriginal; + set + { + Settings.Default.ShowViewportOriginal = value; + Settings.Default.Save(); + } + } + + public bool ShowViewportRemix + { + get => Settings.Default.ShowViewportRemix; + set + { + Settings.Default.ShowViewportRemix = value; + Settings.Default.Save(); + } + } + + public bool IsViewportOnTop + { + get => Settings.Default.IsViewportOnTop; + set + { + Settings.Default.IsViewportOnTop = value; + Settings.Default.Save(); + } + } + + public App(MonoGameImGuiBootstrap bootstrap) + { + _bootstrap = bootstrap; + _bootstrap.Title = Title; + AddKeyMapping(Keys.O, MenuFileOpenWithoutPcsx2); + AddKeyMapping(Keys.L, MenuFileOpenPcsx2); + AddKeyMapping(Keys.S, MenuFileSave); + } + + public bool MainLoop() + { + ProcessKeyMapping(); + + bool dummy = true; + if (ImGui.BeginPopupModal(ResourceSelectionDialogTitle, ref dummy, + ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal | ImGuiWindowFlags.AlwaysAutoResize)) + { + _resourceSelectionDialog.Run(); + ImGui.EndPopup(); + + if (_resourceSelectionDialog.HasResourceBeenSelected) + { + if (_isResourceSelectingLayout) + OpenLayoutEditor(_resourceSelectionDialog.SelectedAnimation, + _resourceSelectionDialog.SelectedTexture); + else + OpenSequenceEditor(_resourceSelectionDialog.SelectedAnimation, + _resourceSelectionDialog.SelectedTexture); + } + } + + ImGuiEx.MainWindow(() => + { + MainMenu(); + MainWindow(); + }); + + if (_isResourceSelectionDialogOpening) + { + ImGui.OpenPopup(ResourceSelectionDialogTitle); + _isResourceSelectionDialogOpening = false; + } + + return _exitFlag; + } + + public void Dispose() + { + CloseProcessStream(); + } + + private void MainWindow() + { + if (_app != null) + { + _app.Run(); + } + else + { + ImGui.Text("No files loaded at the moment"); + } + } + + void MainMenu() + { + ForMenuBar(() => + { + ForMenu("File", () => + { + ForMenuItem("Open...", "CTRL+O", MenuFileOpenWithoutPcsx2); + ForMenuItem($"{LinkToPcsx2ActionName}...", "CTRL+L", MenuFileOpenPcsx2); + ForMenuItem("Save", "CTRL+S", MenuFileSave, CurrentEditor != null); + ForMenuItem("Save as...", MenuFileSaveAs, CurrentEditor != null); + ImGui.Separator(); + ForMenu("Preferences", () => + { + //var checkerboardBackground = CheckerboardBackground; + //if (ImGui.Checkbox("Checkerboard background", ref checkerboardBackground)) + //{ + // CheckerboardBackground = false; + // OnChangeBackground?.Invoke(this, this); + //} + + var editorBackground = new Vector3(EditorBackground.R, + EditorBackground.G, EditorBackground.B); + if (ImGui.ColorEdit3("Background color", ref editorBackground)) + { + EditorBackground = new ColorF(editorBackground.X, + editorBackground.Y, editorBackground.Z, 1f); + OnChangeBackground?.Invoke(this, this); + } + + ForMenuCheck("Show PS2 viewport", () => ShowViewportOriginal, x => ShowViewportOriginal = x); + ForMenuCheck("Show ReMIX viewport", () => ShowViewportRemix, x => ShowViewportRemix = x); + ForMenuCheck("Viewport always on top", () => IsViewportOnTop, x => IsViewportOnTop = x); + }); + ImGui.Separator(); + ForMenuItem("Exit", MenuFileExit); + }); + _app?.Menu(); + ForMenu("Help", () => + { + ForMenuItem("About", ShowAboutDialog); + }); + }); + } + + private void MenuFileOpen() + { + FileDialog.OnOpen(fileName => + { + OpenFile(fileName); + }, Filters); + } + + private void MenuFileOpenWithoutPcsx2() + { + _linkToPcsx2 = false; + CloseProcessStream(); + MenuFileOpen(); + } + + private void MenuFileOpenPcsx2() + { + CloseProcessStream(); + var processes = Process.GetProcessesByName("pcsx2"); + if (processes.Length == 0) + { + ShowLinkPcsx2ErrorProcessNotFound(); + return; + } + + _linkToPcsx2 = true; + MenuFileOpen(); + } + + private void MenuFileSave() + { + if (!string.IsNullOrEmpty(FileName)) + SaveFile(FileName, FileName); + else + MenuFileSaveAs(); + } + + private void MenuFileSaveAs() + { + FileDialog.OnSave(fileName => + { + SaveFile(FileName, fileName); + FileName = fileName; + }, Filters); + } + + private void MenuFileExit() => _exitFlag = true; + + public void OpenToolDesc(ToolInvokeDesc toolInvokeDesc) + { + _toolInvokeDesc = toolInvokeDesc; + OpenFile(_toolInvokeDesc.ActualFileName); + } + + public void OpenFile(string fileName, bool doNotShowLayoutSelectionDialog = false) + { + try + { + bool isSuccess; + if (File.OpenRead(fileName).Using(Layout.IsValid)) + { + IEnumerable imgd = null; + FileDialog.OnOpen(texFileName => + { + imgd = File.OpenRead(texFileName).Using(Imgz.Read); + }, ImzFilter); + + if (imgd != null) + { + using var layoutStream = File.OpenRead(fileName); + OpenLayoutEditor(layoutStream, imgd); + isSuccess = true; + IsBar = false; + } + else + isSuccess = false; + } + else if (File.OpenRead(fileName).Using(Sequence.IsValid)) + { + ShowError("SED files can not be opened directly."); + isSuccess = false; + IsBar = false; + } + else if (File.OpenRead(fileName).Using(Bar.IsValid)) + { + isSuccess = OpenBarContent(ReadBarEntriesFromFileName(fileName), doNotShowLayoutSelectionDialog); + IsBar = true; + } + else + { + ShowError("File not recognized."); + isSuccess = false; + } + + if (isSuccess) + FileName = fileName; + } + catch (Exception ex) + { + ShowError(ex.Message); + } + } + + public void SaveFile(string previousFileName, string fileName) + { + if (!IsBar) + { + var entry = CurrentEditor.SaveAnimation("dummy"); + using var stream = File.Create(fileName); + entry.Stream.SetPosition(0).CopyTo(stream); + } + else + { + SaveFileAsBar(previousFileName, fileName); + } + } + + public void SaveFileAsBar(string previousFileName, string fileName) + { + var existingEntries = File.Exists(previousFileName) ? + ReadBarEntriesFromFileName(previousFileName) : new List(); + + var animationEntry = CurrentEditor.SaveAnimation(AnimationName); + if (_processStream != null) + { + animationEntry.Stream.SetPosition(0); + _processStream.SetPosition(_processOffset); + animationEntry.Stream.CopyTo(_processStream); + animationEntry.Stream.SetPosition(0); + } + + var newEntries = existingEntries + .AddOrReplace(animationEntry) + .AddOrReplace(CurrentEditor.SaveTexture(TextureName)); + File.Create(fileName).Using(stream => Bar.Write(stream, newEntries)); + + if (IsToolDesc) + _toolInvokeDesc.ContentChange = ToolInvokeDesc.ContentChangeInfo.File; + } + + private static IEnumerable ReadBarEntriesFromFileName(string fileName) => + File.OpenRead(fileName).Using(stream => + { + if (!Bar.IsValid(stream)) + throw new InvalidDataException("Not a bar file"); + + return Bar.Read(stream); + }); + + private bool OpenBarContent(IEnumerable entries, bool doNotShowLayoutSelectionDialog = false) + { + var layoutEntries = entries.Count(x => x.Type == Bar.EntryType.Layout); + var sequenceEntries = entries.Count(x => x.Type == Bar.EntryType.Seqd); + + if (DoesContainSequenceAnimations(entries)) + return Open2dd(entries); + if (DoesContainLayoutAnimations(entries)) + return Open2ld(entries, doNotShowLayoutSelectionDialog); + + throw new Exception("The specified file does not contain any sequence or layout content to be played."); + } + + private bool Open2ld(IEnumerable entries, bool doNotShowLayoutSelectionDialog = false) + { + var layoutEntries = entries.Count(x => x.Type == Bar.EntryType.Layout); + int imagesEntries = entries.Count(x => x.Type == Bar.EntryType.Imgz); + + if (layoutEntries == 0) + throw new Exception("No layout found."); + if (imagesEntries == 0) + throw new Exception("No image container found."); + if (layoutEntries > 1 || imagesEntries > 1) + { + OpenResourceSelectionDialog(entries, Bar.EntryType.Layout, Bar.EntryType.Imgz); + return true; + } + + var layoutEntry = entries.First(x => x.Type == Bar.EntryType.Layout); + var textureContainerEntry = entries.First(x => x.Type == Bar.EntryType.Imgz); + OpenLayoutEditor(layoutEntry, textureContainerEntry); + return true; + } + + private bool Open2dd(IEnumerable entries) + { + var sequenceEntries = entries.Count(x => x.Type == Bar.EntryType.Seqd); + int imagesEntries = entries.Count(x => x.Type == Bar.EntryType.Imgd); + + if (sequenceEntries == 0) + throw new Exception("No sequence found."); + if (imagesEntries == 0) + throw new Exception("No image found."); + if (sequenceEntries > 1 || imagesEntries > 1) + { + OpenResourceSelectionDialog(entries, Bar.EntryType.Seqd, Bar.EntryType.Imgd); + return true; + } + + var sequenceEntry = entries.First(x => x.Type == Bar.EntryType.Seqd); + var textureEntry = entries.First(x => x.Type == Bar.EntryType.Imgd); + OpenSequenceEditor(sequenceEntry, textureEntry); + return true; + } + + private void OpenResourceSelectionDialog(IEnumerable entries, + Bar.EntryType animationType, Bar.EntryType textureType) + { + _resourceSelectionDialog = new ResourceSelectionDialog( + entries, animationType, textureType); + _isResourceSelectionDialogOpening = true; + _isResourceSelectingLayout = animationType == Bar.EntryType.Layout; + } + + private void OpenSequenceEditor(Bar.Entry sequenceEntry, Bar.Entry textureEntry) + { + AnimationName = sequenceEntry.Name; + TextureName = textureEntry.Name; + + if (_linkToPcsx2) + { + _linkToPcsx2 = false; + if (!LinkSeqdToPcs2(sequenceEntry.Stream)) + return; + } + + var app = new AppSequenceEditor(_bootstrap, + this, + Sequence.Read(sequenceEntry.Stream.SetPosition(0)), + Imgd.Read(textureEntry.Stream)); + _app = app; + CurrentEditor = app; + } + + private void OpenLayoutEditor(Bar.Entry layoutEntry, Bar.Entry textureContainerEntry) + { + AnimationName = layoutEntry.Name; + TextureName = textureContainerEntry.Name; + OpenLayoutEditor(layoutEntry.Stream, Imgz.Read(textureContainerEntry.Stream)); + } + + private void OpenLayoutEditor(Stream layoutStream, IEnumerable images) + { + if (_linkToPcsx2) + { + _linkToPcsx2 = false; + if (!LinkLaydToPcs2(layoutStream)) + return; + } + + var app = new AppLayoutEditor(_bootstrap, + this, + Layout.Read(layoutStream.SetPosition(0)), + images); + _app = app; + CurrentEditor = app; + } + + private void UpdateTitle() + { + _bootstrap.Title = Title; + } + + private void AddKeyMapping(Keys key, Action action) + { + _keyMapping[key] = action; + } + + private void ProcessKeyMapping() + { + var k = Keyboard.GetState(); + if (k.IsKeyDown(Keys.LeftControl)) + { + var keys = k.GetPressedKeys(); + foreach (var key in keys) + { + if (_keyMapping.TryGetValue(key, out var action)) + action(); + } + } + } + + //private void OpenLayout(LayoutEntryModel layoutEntryModel) + //{ + // AnimationName = layoutEntryModel.Layout.Name; + // SpriteName = layoutEntryModel.Images.Name; + + // var texturesViewModel = new TexturesViewModel(layoutEntryModel.Images.Value); + + // var layoutEditorViewModel = new LayoutEditorViewModel(this, this, EditorDebugRenderingService) + // { + // SequenceGroups = new SequenceGroupsViewModel(layoutEntryModel.Layout.Value, texturesViewModel, EditorDebugRenderingService), + // Layout = layoutEntryModel.Layout.Value, + // Images = layoutEntryModel.Images.Value + // }; + + // CurrentEditor = layoutEditorViewModel; + // OnControlChanged?.Invoke(new LayoutEditorView() + // { + // DataContext = layoutEditorViewModel + // }); + //} + + private bool LinkLaydToPcs2(Stream stream) => + LinkToPcs2(stream, Layout.MagicCodeValidator, 0x1c); + + private bool LinkSeqdToPcs2(Stream stream) => + LinkToPcs2(stream, Sequence.MagicCodeValidator, 0x2c); + + private bool LinkToPcs2(Stream stream, uint magicCode, int headerLength) + { + var process = Process.GetProcessesByName("pcsx2").FirstOrDefault(); + if (process == null) + { + ShowLinkPcsx2ErrorProcessNotFound(); + return false; + } + + var processStream = new ProcessStream(process, ToolConstants.Pcsx2BaseAddress, ToolConstants.Ps2MemoryLength); + var bufferedStream = new BufferedStream(processStream, 0x10000); + + var header = stream.SetPosition(sizeof(uint)).ReadBytes(headerLength); + while (bufferedStream.Position < bufferedStream.Length) + { + if (bufferedStream.ReadUInt32() == magicCode) + { + // header matches. Check if the rest of 0x2c SEQD header matches as well... + if (header.SequenceEqual(bufferedStream.ReadBytes(headerLength))) + { + _processStream = processStream; + _processOffset = (int)(bufferedStream.Position - headerLength - sizeof(uint)); + return true; + } + } + } + + ShowLinkPcsx2ErrorFileNotFound(); + CloseProcessStream(); + return false; + } + + private void CloseProcessStream() + { + _processStream?.Dispose(); + _processStream = null; + } + + private static bool DoesContainSequenceAnimations(IEnumerable entries) => + entries.Any(x => x.Type == Bar.EntryType.Seqd); + + private static bool DoesContainLayoutAnimations(IEnumerable entries) => + entries.Any(x => x.Type == Bar.EntryType.Layout); + + private static void ShowLinkPcsx2ErrorProcessNotFound() => + ShowError("No PCSX2 process found.\nPlease run PCSX2 with Kingdom Hearts II/Re:CoM first and try again.", LinkToPcsx2ActionName); + + private static void ShowLinkPcsx2ErrorFileNotFound() => + ShowError("The file you specified can not be found on the running game.", LinkToPcsx2ActionName); + + public static void ShowError(string message, string title = "Error") => + MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Error); + + private void ShowAboutDialog() => + MessageBox.Show("OpenKH is amazing."); + } +} diff --git a/OpenKh.Tools.LayoutEditor/AppElementSelection.cs b/OpenKh.Tools.LayoutEditor/AppElementSelection.cs index b600d201b..e21708041 100644 --- a/OpenKh.Tools.LayoutEditor/AppElementSelection.cs +++ b/OpenKh.Tools.LayoutEditor/AppElementSelection.cs @@ -1,13 +1,13 @@ -using OpenKh.Kh2; -using System.Collections.Generic; - -namespace OpenKh.Tools.LayoutEditor -{ - public class AppElementSelection - { - public AppElementSelection(IEnumerable entries) - { - - } - } -} +using OpenKh.Kh2; +using System.Collections.Generic; + +namespace OpenKh.Tools.LayoutEditor +{ + public class AppElementSelection + { + public AppElementSelection(IEnumerable entries) + { + + } + } +} diff --git a/OpenKh.Tools.LayoutEditor/AppLayoutEditor.cs b/OpenKh.Tools.LayoutEditor/AppLayoutEditor.cs index 73864613b..197567d3a 100644 --- a/OpenKh.Tools.LayoutEditor/AppLayoutEditor.cs +++ b/OpenKh.Tools.LayoutEditor/AppLayoutEditor.cs @@ -1,323 +1,323 @@ -using ImGuiNET; -using OpenKh.Tools.LayoutEditor.Interfaces; -using System; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using System.IO; -using OpenKh.Tools.Common.CustomImGui; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Xna.Framework.Graphics; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; -using OpenKh.Engine.Extensions; -using OpenKh.Engine.Renders; -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Renderers; -using System.Numerics; - -namespace OpenKh.Tools.LayoutEditor -{ - public class AppLayoutEditor : IApp, ISaveBar, ITextureBinder, IDisposable - { - private const string SequenceEditorDialogName = "Sequence editor"; - private readonly MonoGameImGuiBootstrap _bootStrap; - private readonly IEditorSettings _settings; - private readonly Layout _layout; - private readonly List _images; - private readonly GraphicsDevice _graphics; - private readonly KingdomShader _shader; - private readonly MonoSpriteDrawing _drawing; - private readonly ISpriteTexture _destinationTexture; - private readonly IntPtr _destinationTextureId; - private readonly DefaultDebugLayoutRenderer _debugRender; - private readonly List _spriteTextures; - private readonly LayoutRenderer _renderer; - - private int _selectedLayoutIndex; - private int _animationFrameCurrent; - private bool _isOpeningSequenceEditor; - private AppSequenceEditor _sequenceEditor; - - public int SelectedLayoutIndex - { - get => _selectedLayoutIndex; - set - { - _selectedLayoutIndex = value; - _animationFrameCurrent = 0; - //_sequencerSelectedAnimation = 0; - // - //var animationGroup = _sequence.AnimationGroups[_selectedAnimGroup]; - //_animationFrameCount = SequenceExtensions.GetFrameLength(animationGroup); - //_debugSequenceRenderer.AnimationGroup = animationGroup; - //_sequencer.SelectedAnimationGroupIndex = value; - } - } - - public AppLayoutEditor( - MonoGameImGuiBootstrap bootstrap, - IEditorSettings settings, - Layout layout, - IEnumerable images) - { - _bootStrap = bootstrap; - _settings = settings; - _layout = layout; - _images = images.ToList(); - - _graphics = bootstrap.GraphicsDevice; - _shader = new KingdomShader(bootstrap.Content); - _drawing = new MonoSpriteDrawing(_graphics, _shader); - _destinationTexture = _drawing.CreateSpriteTexture(1024, 1024); - _destinationTextureId = this.BindTexture(_destinationTexture); - - _debugRender = new DefaultDebugLayoutRenderer(); - _spriteTextures = images.Select(x => _drawing.CreateSpriteTexture(x)).ToList(); - _renderer = new LayoutRenderer(_layout, _drawing, _spriteTextures); - } - - public void Menu() - { - } - - public bool Run() - { - const float PreviewWidthMul = 3f; - const float PreviewWidthMax = 512f; - const float EditorWidthMul = 2f; - const float EditorWidthMax = 512f; - const float TotalWidthMul = PreviewWidthMul + EditorWidthMul; - - var windowSize = ImGui.GetWindowSize(); - var previewWidth = Math.Min(windowSize.X / TotalWidthMul * PreviewWidthMul, PreviewWidthMax); - var editorWidth = Math.Min(windowSize.X / TotalWidthMul * EditorWidthMul, EditorWidthMax); - previewWidth = windowSize.X - editorWidth; - - ForChild(nameof(LayoutPreview), previewWidth, 0, false, LayoutPreview); - ImGui.SameLine(); - ForChild(nameof(LayoutEditing), editorWidth, 0, true, LayoutEditing); - - if (_sequenceEditor != null) - { - bool dummy = true; - if (ImGui.BeginPopupModal(SequenceEditorDialogName, ref dummy, - ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal | ImGuiWindowFlags.MenuBar)) - { - const float ChildWindowScale = 0.75f; - var RecommendedWidth = windowSize.X * ChildWindowScale; - var RecommendedHeight = windowSize.Y * ChildWindowScale; - var cursor = ImGui.GetCursorPos(); - ImGui.SetCursorPosX(RecommendedWidth); - ImGui.SetCursorPosY(RecommendedHeight); - ImGui.SetCursorPosX(cursor.X); - ImGui.SetCursorPosY(cursor.Y); - - ForMenuBar(_sequenceEditor.Menu); - _sequenceEditor.Run(); - - ImGui.EndPopup(); - } - } - - if (_isOpeningSequenceEditor) - { - _isOpeningSequenceEditor = false; - ImGui.OpenPopup(SequenceEditorDialogName); - } - - _animationFrameCurrent++; - return true; - } - - private void LayoutPreview() - { - if (ImGui.BeginCombo("", $"Layout Index {SelectedLayoutIndex}", - ImGuiComboFlags.PopupAlignLeft)) - { - for (int i = 0; i < _layout.SequenceGroups.Count; i++) - { - if (ImGui.Selectable($"Layout #{i}\n", - SelectedLayoutIndex == i)) - SelectedLayoutIndex = i; - } - ImGui.EndCombo(); - } - ImGui.SameLine(); - if (ImGui.Button("-", new Vector2(30, 0)) && SelectedLayoutIndex > 0) - SelectedLayoutIndex--; - ImGui.SameLine(); - if (ImGui.Button("+", new Vector2(30, 0)) && - SelectedLayoutIndex < _layout.SequenceGroups.Count - 1) - SelectedLayoutIndex++; - - Timeline(); - - ForChild("Preview", 0, 0, false, () => - { - const float PositionX = 128f; - const float PositionY = 32f; - const float ViewportWidth = 1024f; - const float ViewportHeight = 1024f; - var width = ImGui.GetWindowContentRegionWidth(); - var height = ImGui.GetWindowHeight(); - var backgroundColorInverse = new ColorF( - 1f - _settings.EditorBackground.R, - 1f - _settings.EditorBackground.G, - 1f - _settings.EditorBackground.B, - 1f); - - _drawing.DestinationTexture = _destinationTexture; - _drawing.Clear(_settings.EditorBackground); - _drawing.SetViewport(-PositionX, ViewportWidth - PositionX, -PositionY, ViewportHeight - PositionY); - - - _renderer.FrameIndex = _animationFrameCurrent; - _renderer.SelectedSequenceGroupIndex = SelectedLayoutIndex; - - if (!_settings.IsViewportOnTop) - DrawGameViewport(backgroundColorInverse); - _renderer.Draw(); - if (_settings.IsViewportOnTop) - DrawGameViewport(backgroundColorInverse); - - _drawing.Flush(); - _drawing.DestinationTexture = null; - - float maxU = 1f / ViewportWidth * width; - float maxV = 1f / ViewportHeight * height; - ImGui.Image(_destinationTextureId, new Vector2(width, height), - GetUv(_destinationTexture, 0, 0), new Vector2(maxU, maxV)); - }); - } - - private void DrawGameViewport(ColorF backgroundColorInverse) - { - const float OriginalViewportWidth = 512f; - const float RemixViewportWidth = 684f; - const float ViewportHeight = 416f; - - if (_settings.ShowViewportOriginal) - _drawing.DrawRectangle(-1, -1, OriginalViewportWidth + 2, ViewportHeight + 2, backgroundColorInverse); - - if (_settings.ShowViewportRemix) - _drawing.DrawRectangle( - -(RemixViewportWidth - OriginalViewportWidth) / 2 - 1, -1, - RemixViewportWidth + 2, ViewportHeight + 2, backgroundColorInverse); - - _drawing.Flush(); - } - - private unsafe void Timeline() - { - var frameCount = _layout.GetFrameLengthFromSequenceGroup(SelectedLayoutIndex); - - ImGui.SliderInt("Frame", ref _animationFrameCurrent, 0, frameCount, - $"%i/{frameCount}"); - } - - private void LayoutEditing() - { - var sequenceGroup = _layout.SequenceGroups[SelectedLayoutIndex]; - for (var i = 0; i < sequenceGroup.Sequences.Count; i++) - { - if (ImGui.CollapsingHeader($"Sequence property {i + 1}")) - { - SequencePropertyEdit(sequenceGroup.Sequences[i], i); - } - } - } - - private void SequencePropertyEdit(Layout.SequenceProperty sequenceProperty, int index) - { - var textureIndex = sequenceProperty.TextureIndex; - if (ImGui.DragInt($"Texture index##{index}", ref textureIndex)) - sequenceProperty.TextureIndex = Math.Min(Math.Max(textureIndex, 0), _images.Count - 1); - - var sequenceIndex = sequenceProperty.SequenceIndex; - if (ImGui.DragInt($"Sequence index##{index}", ref sequenceIndex)) - { - sequenceProperty.SequenceIndex = Math.Min(Math.Max(sequenceIndex, 0), _layout.SequenceItems.Count - 1); - var sequence = _layout.SequenceItems[sequenceProperty.SequenceIndex]; - sequenceProperty.AnimationGroup = Math.Min(Math.Max(sequenceProperty.AnimationGroup, 0), sequence.AnimationGroups.Count - 1); - - } - - var animGroupIndex = sequenceProperty.AnimationGroup; - if (ImGui.DragInt($"Animation group index##{index}", ref animGroupIndex)) - { - var sequence = _layout.SequenceItems[sequenceProperty.SequenceIndex]; - sequenceProperty.AnimationGroup = Math.Min(Math.Max(animGroupIndex, 0), sequence.AnimationGroups.Count - 1); - } - - var frameStart = sequenceProperty.ShowAtFrame; - if (ImGui.DragInt($"Show at frame##{index}", ref frameStart)) - sequenceProperty.ShowAtFrame = frameStart; - - var position = new int[] { sequenceProperty.PositionX, sequenceProperty.PositionY }; - if (ImGui.DragInt2($"Position##{index}", ref position[0])) - { - sequenceProperty.PositionX = position[0]; - sequenceProperty.PositionY = position[1]; - } - - if (ImGui.Button($"Modify inner sequence##{index}")) - OpenInnerSequence( - sequenceProperty.SequenceIndex, - sequenceProperty.TextureIndex, - sequenceProperty.AnimationGroup); - } - - private void OpenInnerSequence(int sequenceIndex, int textureIndex, int animationGroup) - { - _sequenceEditor?.Dispose(); - _sequenceEditor = new AppSequenceEditor(_bootStrap, _settings, - _layout.SequenceItems[sequenceIndex], - _images[textureIndex]); - _isOpeningSequenceEditor = true; - } - - public Bar.Entry SaveAnimation(string name) - { - var stream = new MemoryStream(); - _layout.Write(stream); - - return new Bar.Entry - { - Name = name, - Stream = stream, - Type = Bar.EntryType.Layout - }; - } - - public Bar.Entry SaveTexture(string name) - { - var stream = new MemoryStream(); - Imgz.Write(stream, _images); - - return new Bar.Entry - { - Name = name, - Stream = stream, - Type = Bar.EntryType.Imgz - }; - } - - public void Dispose() - { - _sequenceEditor?.Dispose(); - } - - public IntPtr BindTexture(Texture2D texture) => - _bootStrap.BindTexture(texture); - - public void UnbindTexture(IntPtr id) => - _bootStrap.UnbindTexture(id); - - public void RebindTexture(IntPtr id, Texture2D texture) => - _bootStrap.RebindTexture(id, texture); - - private static Vector2 GetUv(ISpriteTexture texture, int x, int y) => - new Vector2((float)x / texture.Width, (float)y / texture.Height); - - } -} +using ImGuiNET; +using OpenKh.Tools.LayoutEditor.Interfaces; +using System; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using System.IO; +using OpenKh.Tools.Common.CustomImGui; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework.Graphics; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; +using OpenKh.Engine.Extensions; +using OpenKh.Engine.Renders; +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Renderers; +using System.Numerics; + +namespace OpenKh.Tools.LayoutEditor +{ + public class AppLayoutEditor : IApp, ISaveBar, ITextureBinder, IDisposable + { + private const string SequenceEditorDialogName = "Sequence editor"; + private readonly MonoGameImGuiBootstrap _bootStrap; + private readonly IEditorSettings _settings; + private readonly Layout _layout; + private readonly List _images; + private readonly GraphicsDevice _graphics; + private readonly KingdomShader _shader; + private readonly MonoSpriteDrawing _drawing; + private readonly ISpriteTexture _destinationTexture; + private readonly IntPtr _destinationTextureId; + private readonly DefaultDebugLayoutRenderer _debugRender; + private readonly List _spriteTextures; + private readonly LayoutRenderer _renderer; + + private int _selectedLayoutIndex; + private int _animationFrameCurrent; + private bool _isOpeningSequenceEditor; + private AppSequenceEditor _sequenceEditor; + + public int SelectedLayoutIndex + { + get => _selectedLayoutIndex; + set + { + _selectedLayoutIndex = value; + _animationFrameCurrent = 0; + //_sequencerSelectedAnimation = 0; + // + //var animationGroup = _sequence.AnimationGroups[_selectedAnimGroup]; + //_animationFrameCount = SequenceExtensions.GetFrameLength(animationGroup); + //_debugSequenceRenderer.AnimationGroup = animationGroup; + //_sequencer.SelectedAnimationGroupIndex = value; + } + } + + public AppLayoutEditor( + MonoGameImGuiBootstrap bootstrap, + IEditorSettings settings, + Layout layout, + IEnumerable images) + { + _bootStrap = bootstrap; + _settings = settings; + _layout = layout; + _images = images.ToList(); + + _graphics = bootstrap.GraphicsDevice; + _shader = new KingdomShader(bootstrap.Content); + _drawing = new MonoSpriteDrawing(_graphics, _shader); + _destinationTexture = _drawing.CreateSpriteTexture(1024, 1024); + _destinationTextureId = this.BindTexture(_destinationTexture); + + _debugRender = new DefaultDebugLayoutRenderer(); + _spriteTextures = images.Select(x => _drawing.CreateSpriteTexture(x)).ToList(); + _renderer = new LayoutRenderer(_layout, _drawing, _spriteTextures); + } + + public void Menu() + { + } + + public bool Run() + { + const float PreviewWidthMul = 3f; + const float PreviewWidthMax = 512f; + const float EditorWidthMul = 2f; + const float EditorWidthMax = 512f; + const float TotalWidthMul = PreviewWidthMul + EditorWidthMul; + + var windowSize = ImGui.GetWindowSize(); + var previewWidth = Math.Min(windowSize.X / TotalWidthMul * PreviewWidthMul, PreviewWidthMax); + var editorWidth = Math.Min(windowSize.X / TotalWidthMul * EditorWidthMul, EditorWidthMax); + previewWidth = windowSize.X - editorWidth; + + ForChild(nameof(LayoutPreview), previewWidth, 0, false, LayoutPreview); + ImGui.SameLine(); + ForChild(nameof(LayoutEditing), editorWidth, 0, true, LayoutEditing); + + if (_sequenceEditor != null) + { + bool dummy = true; + if (ImGui.BeginPopupModal(SequenceEditorDialogName, ref dummy, + ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal | ImGuiWindowFlags.MenuBar)) + { + const float ChildWindowScale = 0.75f; + var RecommendedWidth = windowSize.X * ChildWindowScale; + var RecommendedHeight = windowSize.Y * ChildWindowScale; + var cursor = ImGui.GetCursorPos(); + ImGui.SetCursorPosX(RecommendedWidth); + ImGui.SetCursorPosY(RecommendedHeight); + ImGui.SetCursorPosX(cursor.X); + ImGui.SetCursorPosY(cursor.Y); + + ForMenuBar(_sequenceEditor.Menu); + _sequenceEditor.Run(); + + ImGui.EndPopup(); + } + } + + if (_isOpeningSequenceEditor) + { + _isOpeningSequenceEditor = false; + ImGui.OpenPopup(SequenceEditorDialogName); + } + + _animationFrameCurrent++; + return true; + } + + private void LayoutPreview() + { + if (ImGui.BeginCombo("", $"Layout Index {SelectedLayoutIndex}", + ImGuiComboFlags.PopupAlignLeft)) + { + for (int i = 0; i < _layout.SequenceGroups.Count; i++) + { + if (ImGui.Selectable($"Layout #{i}\n", + SelectedLayoutIndex == i)) + SelectedLayoutIndex = i; + } + ImGui.EndCombo(); + } + ImGui.SameLine(); + if (ImGui.Button("-", new Vector2(30, 0)) && SelectedLayoutIndex > 0) + SelectedLayoutIndex--; + ImGui.SameLine(); + if (ImGui.Button("+", new Vector2(30, 0)) && + SelectedLayoutIndex < _layout.SequenceGroups.Count - 1) + SelectedLayoutIndex++; + + Timeline(); + + ForChild("Preview", 0, 0, false, () => + { + const float PositionX = 128f; + const float PositionY = 32f; + const float ViewportWidth = 1024f; + const float ViewportHeight = 1024f; + var width = ImGui.GetWindowContentRegionWidth(); + var height = ImGui.GetWindowHeight(); + var backgroundColorInverse = new ColorF( + 1f - _settings.EditorBackground.R, + 1f - _settings.EditorBackground.G, + 1f - _settings.EditorBackground.B, + 1f); + + _drawing.DestinationTexture = _destinationTexture; + _drawing.Clear(_settings.EditorBackground); + _drawing.SetViewport(-PositionX, ViewportWidth - PositionX, -PositionY, ViewportHeight - PositionY); + + + _renderer.FrameIndex = _animationFrameCurrent; + _renderer.SelectedSequenceGroupIndex = SelectedLayoutIndex; + + if (!_settings.IsViewportOnTop) + DrawGameViewport(backgroundColorInverse); + _renderer.Draw(); + if (_settings.IsViewportOnTop) + DrawGameViewport(backgroundColorInverse); + + _drawing.Flush(); + _drawing.DestinationTexture = null; + + float maxU = 1f / ViewportWidth * width; + float maxV = 1f / ViewportHeight * height; + ImGui.Image(_destinationTextureId, new Vector2(width, height), + GetUv(_destinationTexture, 0, 0), new Vector2(maxU, maxV)); + }); + } + + private void DrawGameViewport(ColorF backgroundColorInverse) + { + const float OriginalViewportWidth = 512f; + const float RemixViewportWidth = 684f; + const float ViewportHeight = 416f; + + if (_settings.ShowViewportOriginal) + _drawing.DrawRectangle(-1, -1, OriginalViewportWidth + 2, ViewportHeight + 2, backgroundColorInverse); + + if (_settings.ShowViewportRemix) + _drawing.DrawRectangle( + -(RemixViewportWidth - OriginalViewportWidth) / 2 - 1, -1, + RemixViewportWidth + 2, ViewportHeight + 2, backgroundColorInverse); + + _drawing.Flush(); + } + + private unsafe void Timeline() + { + var frameCount = _layout.GetFrameLengthFromSequenceGroup(SelectedLayoutIndex); + + ImGui.SliderInt("Frame", ref _animationFrameCurrent, 0, frameCount, + $"%i/{frameCount}"); + } + + private void LayoutEditing() + { + var sequenceGroup = _layout.SequenceGroups[SelectedLayoutIndex]; + for (var i = 0; i < sequenceGroup.Sequences.Count; i++) + { + if (ImGui.CollapsingHeader($"Sequence property {i + 1}")) + { + SequencePropertyEdit(sequenceGroup.Sequences[i], i); + } + } + } + + private void SequencePropertyEdit(Layout.SequenceProperty sequenceProperty, int index) + { + var textureIndex = sequenceProperty.TextureIndex; + if (ImGui.DragInt($"Texture index##{index}", ref textureIndex)) + sequenceProperty.TextureIndex = Math.Min(Math.Max(textureIndex, 0), _images.Count - 1); + + var sequenceIndex = sequenceProperty.SequenceIndex; + if (ImGui.DragInt($"Sequence index##{index}", ref sequenceIndex)) + { + sequenceProperty.SequenceIndex = Math.Min(Math.Max(sequenceIndex, 0), _layout.SequenceItems.Count - 1); + var sequence = _layout.SequenceItems[sequenceProperty.SequenceIndex]; + sequenceProperty.AnimationGroup = Math.Min(Math.Max(sequenceProperty.AnimationGroup, 0), sequence.AnimationGroups.Count - 1); + + } + + var animGroupIndex = sequenceProperty.AnimationGroup; + if (ImGui.DragInt($"Animation group index##{index}", ref animGroupIndex)) + { + var sequence = _layout.SequenceItems[sequenceProperty.SequenceIndex]; + sequenceProperty.AnimationGroup = Math.Min(Math.Max(animGroupIndex, 0), sequence.AnimationGroups.Count - 1); + } + + var frameStart = sequenceProperty.ShowAtFrame; + if (ImGui.DragInt($"Show at frame##{index}", ref frameStart)) + sequenceProperty.ShowAtFrame = frameStart; + + var position = new int[] { sequenceProperty.PositionX, sequenceProperty.PositionY }; + if (ImGui.DragInt2($"Position##{index}", ref position[0])) + { + sequenceProperty.PositionX = position[0]; + sequenceProperty.PositionY = position[1]; + } + + if (ImGui.Button($"Modify inner sequence##{index}")) + OpenInnerSequence( + sequenceProperty.SequenceIndex, + sequenceProperty.TextureIndex, + sequenceProperty.AnimationGroup); + } + + private void OpenInnerSequence(int sequenceIndex, int textureIndex, int animationGroup) + { + _sequenceEditor?.Dispose(); + _sequenceEditor = new AppSequenceEditor(_bootStrap, _settings, + _layout.SequenceItems[sequenceIndex], + _images[textureIndex]); + _isOpeningSequenceEditor = true; + } + + public Bar.Entry SaveAnimation(string name) + { + var stream = new MemoryStream(); + _layout.Write(stream); + + return new Bar.Entry + { + Name = name, + Stream = stream, + Type = Bar.EntryType.Layout + }; + } + + public Bar.Entry SaveTexture(string name) + { + var stream = new MemoryStream(); + Imgz.Write(stream, _images); + + return new Bar.Entry + { + Name = name, + Stream = stream, + Type = Bar.EntryType.Imgz + }; + } + + public void Dispose() + { + _sequenceEditor?.Dispose(); + } + + public IntPtr BindTexture(Texture2D texture) => + _bootStrap.BindTexture(texture); + + public void UnbindTexture(IntPtr id) => + _bootStrap.UnbindTexture(id); + + public void RebindTexture(IntPtr id, Texture2D texture) => + _bootStrap.RebindTexture(id, texture); + + private static Vector2 GetUv(ISpriteTexture texture, int x, int y) => + new Vector2((float)x / texture.Width, (float)y / texture.Height); + + } +} diff --git a/OpenKh.Tools.LayoutEditor/AppSequenceEditor.cs b/OpenKh.Tools.LayoutEditor/AppSequenceEditor.cs index 1a439288e..1cb71e426 100644 --- a/OpenKh.Tools.LayoutEditor/AppSequenceEditor.cs +++ b/OpenKh.Tools.LayoutEditor/AppSequenceEditor.cs @@ -1,714 +1,714 @@ -using ImGuiNET; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using OpenKh.Tools.LayoutEditor.Interfaces; -using System.Numerics; -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Tools.Common.CustomImGui; -using OpenKh.Engine.Extensions; -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Renders; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; -using OpenKh.Engine.Renderers; -using System; -using System.Collections.Generic; -using System.Linq; -using OpenKh.Tools.LayoutEditor.Models; -using System.IO; -using OpenKh.Tools.LayoutEditor.Dialogs; -using OpenKh.Tools.LayoutEditor.Controls; - -namespace OpenKh.Tools.LayoutEditor -{ - public class AppSequenceEditor : IApp, ISaveBar, ITextureBinder, IDisposable - { - private readonly IEditorSettings _settings; - private readonly Sequence _sequence; - private readonly Imgd _image; - private readonly MonoGameImGuiBootstrap _bootStrap; - private readonly GraphicsDevice _graphics; - private readonly KingdomShader _shader; - private readonly MonoSpriteDrawing _drawing; - private readonly ISpriteTexture _atlasTexture; - private DebugSequenceRenderer _debugSequenceRenderer; - private readonly SequenceRenderer _renderer; - - private int _selectedSprite = 0; - private int _selectedSpriteGroup = 0; - private int _selectedAnimGroup; - private int _animationFrameCurrent; - private int _animationFrameCount; - private ISpriteTexture _destinationTexture; - private IntPtr _destinationTextureId; - private List _sprites; - private List _spriteGroups; - - private MySequencer _sequencer; - int _sequencerSelectedAnimation = 0; - int _sequencerFirstFrame = 0; - - private bool _isSpriteEditDialogOpen; - private SpriteEditDialog _spriteEditDialog; - private string SpriteEditDialogTitle => $"Sprite edit"; - - private bool _isSpriteGroupEditDialogOpen; - private SpriteGroupEditDialog _spriteGroupEditDialog; - private string SpriteGroupEditDialogTitle => $"Sprite group edit"; - - private Sequence.AnimationGroup SelectedAnimationGroup => - _debugSequenceRenderer.AnimationGroup; - - private bool CanAnimGroupHostChildAnims => SelectedAnimationGroup - .Animations.Any(x => (x.Flags & Sequence.IsActiveFlag) != 0); - - public int SelectedAnimGroup - { - get => _selectedAnimGroup; - set - { - _selectedAnimGroup = value; - _animationFrameCurrent = 0; - _sequencerSelectedAnimation = 0; - - var animationGroup = _sequence.AnimationGroups[_selectedAnimGroup]; - _animationFrameCount = SequenceExtensions.GetFrameLength(animationGroup); - _debugSequenceRenderer.AnimationGroup = animationGroup; - _sequencer.SelectedAnimationGroupIndex = value; - } - } - - public AppSequenceEditor( - MonoGameImGuiBootstrap bootstrap, - IEditorSettings settings, - Sequence sequence, - Imgd image) - { - _settings = settings; - _sequence = sequence; - _image = image; - - _bootStrap = bootstrap; - _graphics = bootstrap.GraphicsDevice; - _shader = new KingdomShader(bootstrap.Content); - _drawing = new MonoSpriteDrawing(_graphics, _shader); - _atlasTexture = _drawing.CreateSpriteTexture(_image); - _debugSequenceRenderer = new DebugSequenceRenderer(); - _renderer = new SequenceRenderer(_sequence, _drawing, _atlasTexture) - { - DebugSequenceRenderer = _debugSequenceRenderer - }; - - _destinationTexture = _drawing.CreateSpriteTexture(1024, 1024); - _destinationTextureId = this.BindTexture(_destinationTexture); - - _sprites = sequence.Sprites - .Select(x => AsSpriteModel(x)) - .ToList(); - _spriteGroups = sequence.SpriteGroups - .Select((_, i) => AsSpriteGroupModel(i)) - .ToList(); - - _sequencer = new MySequencer(sequence, _debugSequenceRenderer); - SelectedAnimGroup = 0; - } - - public void Menu() - { - ForMenu("Edit", () => - { - ForMenuItem("Sprite groups...", () => _isSpriteGroupEditDialogOpen = true); - ForMenuItem("Sprites...", () => _isSpriteEditDialogOpen = true); - }); - } - - public bool Run() - { - bool dummy = true; - if (ImGui.BeginPopupModal(SpriteEditDialogTitle, ref dummy, - ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal | ImGuiWindowFlags.AlwaysAutoResize)) - { - _spriteEditDialog.Run(); - ImGui.EndPopup(); - } - if (ImGui.BeginPopupModal(SpriteGroupEditDialogTitle, ref dummy, - ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal | ImGuiWindowFlags.AlwaysAutoResize)) - { - _spriteGroupEditDialog.Run(); - ImGui.EndPopup(); - } - - const float SpriteListWidthMul = 1f; - const float SpriteListWidthMax = 192f; - const float RightWidthMul = 1.5f; - const float RightWidthMax = 384f; - const float PreviewWidthMul = 2f; - const float TotalWidthMul = SpriteListWidthMul + RightWidthMul + PreviewWidthMul; - var windowSize = ImGui.GetWindowSize().X; - var spriteListWidth = Math.Min(windowSize / TotalWidthMul * SpriteListWidthMul, SpriteListWidthMax); - var rightWidth = Math.Min(windowSize / TotalWidthMul * RightWidthMul, RightWidthMax); - var previewWidth = windowSize - spriteListWidth - rightWidth; - - ForChild("SpriteGroupList", spriteListWidth, 0, true, DrawSpriteGroupList); - ImGui.SameLine(); - ForChild("Animation", previewWidth, 0, false, DrawAnimation); - ImGui.SameLine(); - ForChild("Right", rightWidth, 0, true, DrawRight); - - if (_isSpriteGroupEditDialogOpen) - { - ImGui.OpenPopup(SpriteGroupEditDialogTitle); - _isSpriteGroupEditDialogOpen = false; - _spriteGroupEditDialog = new SpriteGroupEditDialog( - _sequence, - _spriteGroups, - _selectedSpriteGroup, - _drawing, - _atlasTexture, - this, _settings); - } - - if (_isSpriteEditDialogOpen) - { - ImGui.OpenPopup(SpriteEditDialogTitle); - _isSpriteEditDialogOpen = false; - _spriteEditDialog = new SpriteEditDialog( - _sprites, - _selectedSprite, - _drawing, - _atlasTexture, - this, _settings); - } - - if (!_sequencer.IsPaused) - { - _animationFrameCurrent++; - if (_sequencer.ForceLoop && _animationFrameCurrent > SelectedAnimationGroup.GetFrameLength()) - _animationFrameCurrent = 0; - } - return true; - } - - private void DrawSpriteGroupList() - { - // Animate only the selected sprite - //if (_selectedSpriteGroup >= 0) - // _spriteGroups[_selectedSpriteGroup].Draw(0, 0); - - for (int i = 0; i < _spriteGroups.Count; i++) - { - var sprite = _spriteGroups[i]; - if (ImGui.Selectable($"##spriteGroup{i}", - _selectedSpriteGroup == i, - ImGuiSelectableFlags.None, - new Vector2(0, sprite.Height))) - _selectedSpriteGroup = i; - - ImGui.SameLine(); - ImGui.Image(sprite.TextureId, new Vector2(sprite.Width, sprite.Height)); - } - } - - private void DrawSpriteList() - { - // Animate only the selected sprite - if (_selectedSprite >= 0) - _sprites[_selectedSprite].Draw(0, 0); - - for (int i = 0; i < _sprites.Count; i++) - { - var sprite = _sprites[i]; - if (ImGui.Selectable($"##sprite{i}", - _selectedSprite == i, - ImGuiSelectableFlags.None, - new Vector2(0, sprite.Height))) - _selectedSprite = i; - - ImGui.SameLine(); - ImGui.Image(sprite.TextureId, new Vector2(sprite.Width, sprite.Height)); - } - } - - private void DrawAnimationGroupList() - { - for (int i = 0; i < _sequence.AnimationGroups.Count; i++) - { - if (ImGui.Selectable($"Animation Group {i}\n", - SelectedAnimGroup == i)) - SelectedAnimGroup = i; - } - } - - private unsafe void DrawAnimation() - { - const float TimelineControlWidth = 200f; - - AnimationGroupSelector(); - - if (ImGui.BeginChild("timeline", new Vector2(0, TimelineControlWidth))) - { - Timeline(); - ImGui.EndChild(); - } - - ForChild("Preview", 0, 0, false, () => - { - const float ViewportWidth = 1024f; - const float ViewportHeight = 1024f; - const float Infinite = 65536f; - var width = ImGui.GetWindowContentRegionWidth(); - var height = ImGui.GetWindowHeight(); - var originX = width / 4.0f; - var originY = height / 4.0f; - var backgroundColorInverse = new ColorF( - 1f - _settings.EditorBackground.R, - 1f - _settings.EditorBackground.G, - 1f - _settings.EditorBackground.B, - 1f); - - _drawing.DestinationTexture = _destinationTexture; - _drawing.Clear(_settings.EditorBackground); - _drawing.SetViewport(0, ViewportWidth, 0, ViewportHeight); - - // This draws the origin - _drawing.FillRectangle(originX - 1, 0, 1, Infinite, backgroundColorInverse); - _drawing.FillRectangle(0, originY - 1, Infinite, 1, backgroundColorInverse); - _drawing.Flush(); - - _renderer.Draw(_selectedAnimGroup, _animationFrameCurrent, originX, originY); - _drawing.Flush(); - _drawing.DestinationTexture = null; - - float maxU = 1f / ViewportWidth * width; - float maxV = 1f / ViewportHeight * height; - ImGui.Image(_destinationTextureId, new Vector2(width, height), - GetUv(_atlasTexture, 0, 0), new Vector2(maxU, maxV)); - }); - } - - private void DrawRight() - { - var animationGroup = _sequence.AnimationGroups[_selectedAnimGroup]; - if (ImGui.CollapsingHeader($"Properties")) - AnimationGroupEdit(animationGroup); - - for (var i = 0; i < animationGroup.Animations.Count; i++) - { - if (ImGui.CollapsingHeader($"Animation {i + 1}")) - { - AnimationEdit(animationGroup.Animations[i], i); - } - } - } - - public Bar.Entry SaveAnimation(string name) - { - var stream = new MemoryStream(); - _sequence.Write(stream); - - return new Bar.Entry - { - Name = name, - Stream = stream, - Type = Bar.EntryType.Seqd - }; - } - - public Bar.Entry SaveTexture(string name) - { - var stream = new MemoryStream(); - _image.Write(stream); - - return new Bar.Entry - { - Name = name, - Stream = stream, - Type = Bar.EntryType.Imgd - }; - } - - public void Dispose() - { - foreach (var sprite in _sprites) - sprite.Dispose(); - - _bootStrap.UnbindTexture(_destinationTextureId); - _destinationTexture.Dispose(); - } - - private void AnimationGroupEdit(Sequence.AnimationGroup animationGroup) - { - var canAnimationLoop = animationGroup.DoNotLoop == 0; - if (ImGui.Checkbox("Loop animation", ref canAnimationLoop)) - animationGroup.DoNotLoop = (short)(canAnimationLoop ? 0 : 1); - - int unknown06 = animationGroup.Unknown06; - if (ImGui.InputInt("Unknown06", ref unknown06)) - animationGroup.Unknown06 = (short)unknown06; - - var loopPair = new int[] { animationGroup.LoopStart, animationGroup.LoopEnd }; - if (ImGui.InputInt2("Loop frame", ref loopPair[0])) - { - animationGroup.LoopStart = loopPair[0]; - animationGroup.LoopEnd = loopPair[1]; - } - - if (CanAnimGroupHostChildAnims) - { - ImGui.Separator(); - ImGui.Text("Child animation properties"); - - int lightPosX = animationGroup.LightPositionX; - if (ImGui.InputInt("Light pos. X", ref lightPosX)) - animationGroup.LightPositionX = lightPosX; - - int textPosY = animationGroup.TextPositionY; - if (ImGui.InputInt("Text position Y", ref textPosY)) - animationGroup.TextPositionY = textPosY; - - int textScale = animationGroup.TextScale; - if (ImGui.InputInt("Text scale", ref textScale)) - animationGroup.TextScale = textScale; - - int uiPadding = animationGroup.UiPadding; - if (ImGui.InputInt("UI padding", ref uiPadding)) - animationGroup.UiPadding = uiPadding; - - int textPosX = animationGroup.TextPositionX; - if (ImGui.InputInt("Text position X", ref textPosX)) - animationGroup.TextPositionX = textPosX; - } - } - - private void AnimationEdit(Sequence.Animation animation, int index) - { - ImGuiFlagBox(animation, $"Is active##{index}", Sequence.IsActiveFlag, true); - ImGuiFlagBox(animation, $"Bilinear filtering##{index}", Sequence.DisableBilinearFlag, true); - ImGuiFlagBox(animation, $"Last cut##{index}", Sequence.LastCutFlag, true); - ImGuiFlagBox(animation, $"Translation##{index}", Sequence.TranslationDisableFlag, true); - ImGuiFlagBox(animation, $"Translation offset##{index}", Sequence.TranslationOffsetDisableFlag, true); - ImGuiFlagBox(animation, $"Position##{index}", Sequence.PositionDisableFlag, true); - ImGuiFlagBox(animation, $"Tag##{index}", Sequence.TagFlag, true); - - int interpolationMode = (animation.Flags & Sequence.DisableCurveFlag) != 0 ? 1 : 0; - if (ImGui.Combo($"Interpolation##{index}", ref interpolationMode, new string[] - { "Ease in/out", "Linear" }, 2)) - { - var flag = Sequence.DisableCurveFlag; - animation.Flags = (animation.Flags & ~flag) | (interpolationMode == 0 ? 0 : flag); - } - - var framePair = new int[] { animation.FrameStart, animation.FrameEnd }; - if (ImGui.DragInt2($"Frame lifespan##{index}", ref framePair[0])) - { - animation.FrameStart = framePair[0]; - animation.FrameEnd = framePair[1]; - } - - int spriteGroupIndex = animation.SpriteGroupIndex; - if (ImGui.InputInt($"Sprite group##{index}", ref spriteGroupIndex)) - animation.SpriteGroupIndex = Math.Min(Math.Max(spriteGroupIndex, 0), _sequence.SpriteGroups.Count - 1); - - if (ImGuiFlagBox(animation, $"Enable translation animation##{index}", Sequence.PivotDisableFlag)) - { - var xaPair = new int[] { animation.TranslateXStart, animation.TranslateXEnd }; - if (ImGui.DragInt2($"Translation X##{index}", ref xaPair[0])) - { - animation.TranslateXStart = xaPair[0]; - animation.TranslateXEnd = xaPair[1]; - } - - var yaPair = new int[] { animation.TranslateYStart, animation.TranslateYEnd }; - if (ImGui.DragInt2($"Translation Y##{index}", ref yaPair[0])) - { - animation.TranslateYStart = yaPair[0]; - animation.TranslateYEnd = yaPair[1]; - } - } - else - { - var xaPair = new int[] { animation.TranslateXStart, animation.TranslateYStart }; - if (ImGui.DragInt2($"Translation##{index}", ref xaPair[0])) - { - animation.TranslateXStart = xaPair[0]; - animation.TranslateYStart = xaPair[1]; - } - } - - if (ImGuiFlagBox(animation, $"Enable pivot translation##{index}", Sequence.PivotDisableFlag)) - { - if (ImGuiFlagBox(animation, $"Interpolate pivot##{index}", Sequence.RotationInterpolationFlag)) - { - var xbPair = new int[] { animation.PivotXStart, animation.PivotXEnd }; - if (ImGui.DragInt2($"Pivot X##{index}", ref xbPair[0])) - { - animation.PivotXStart = xbPair[0]; - animation.PivotXEnd = xbPair[1]; - } - - var ybPair = new int[] { animation.PivotYStart, animation.PivotYEnd }; - if (ImGui.DragInt2($"Pivot Y##{index}", ref ybPair[0])) - { - animation.PivotYStart = ybPair[0]; - animation.PivotYEnd = ybPair[1]; - } - } - else - { - var pivotX = animation.PivotXStart; - if (ImGui.DragInt($"Pivot X##{index}", ref pivotX)) - { - animation.PivotXStart = pivotX; - animation.PivotXEnd = pivotX; - } - - var pivotY = animation.PivotYStart; - if (ImGui.DragInt2($"Pivot Y##{index}", ref pivotY)) - { - animation.PivotYStart = pivotY; - animation.PivotYEnd = pivotY; - } - } - } - - if (ImGuiFlagBox(animation, $"Enable rotation##{index}", Sequence.RotationDisableFlag)) - { - var rotationStart = new Vector3( - (float)(animation.RotationXStart * 180f / Math.PI), - (float)(animation.RotationYStart * 180f / Math.PI), - (float)(animation.RotationZStart * 180f / Math.PI)); - var rotationEnd = new Vector3( - (float)(animation.RotationXEnd * 180f / Math.PI), - (float)(animation.RotationYEnd * 180f / Math.PI), - (float)(animation.RotationZEnd * 180f / Math.PI)); - - if (ImGuiFlagBox(animation, $"Interpolate rotation##{index}", Sequence.RotationInterpolationFlag)) - { - - if (ImGui.DragFloat3($"Rotation Start##{index}", ref rotationStart)) - { - animation.RotationXStart = (float)(rotationStart.X * Math.PI / 180f); - animation.RotationYStart = (float)(rotationStart.Y * Math.PI / 180f); - animation.RotationZStart = (float)(rotationStart.Z * Math.PI / 180f); - } - if (ImGui.DragFloat3($"Rotation End##{index}", ref rotationEnd)) - { - animation.RotationXEnd = (float)(rotationEnd.X * Math.PI / 180f); - animation.RotationYEnd = (float)(rotationEnd.Y * Math.PI / 180f); - animation.RotationZEnd = (float)(rotationEnd.Z * Math.PI / 180f); - } - } - else - { - if (ImGui.DragFloat3($"Rotation Start##{index}", ref rotationStart)) - { - animation.RotationXStart = (float)(rotationStart.X * Math.PI / 180f); - animation.RotationYStart = (float)(rotationStart.Y * Math.PI / 180f); - animation.RotationZStart = (float)(rotationStart.Z * Math.PI / 180f); - animation.RotationXEnd = animation.RotationXStart; - animation.RotationYEnd = animation.RotationYStart; - animation.RotationZEnd = animation.RotationZStart; - } - } - } - - if (ImGuiFlagBox(animation, $"Enable scaling##{index}", Sequence.ScalingDisableFlag)) - { - if (ImGuiFlagBox(animation, $"Scaling interpolation##{index}", Sequence.ScalingInterpolationFlag)) - { - var scalePair = new Vector2(animation.ScaleStart, animation.ScaleEnd); - if (ImGui.DragFloat2($"Scale##{index}", ref scalePair, 0.05f)) - { - animation.ScaleStart = scalePair.X; - animation.ScaleEnd = scalePair.Y; - } - - var scaleXPair = new Vector2(animation.ScaleXStart, animation.ScaleXEnd); - if (ImGui.DragFloat2($"Scale X##{index}", ref scaleXPair, 0.05f)) - { - animation.ScaleXStart = scaleXPair.X; - animation.ScaleXEnd = scaleXPair.Y; - } - - var scaleYPair = new Vector2(animation.ScaleYStart, animation.ScaleYEnd); - if (ImGui.DragFloat2($"Scale Y##{index}", ref scaleYPair, 0.05f)) - { - animation.ScaleYStart = scaleYPair.X; - animation.ScaleYEnd = scaleYPair.Y; - } - } - else - { - var scale = animation.ScaleStart; - if (ImGui.DragFloat($"Scale##{index}", ref scale, 0.05f)) - { - animation.ScaleStart = scale; - animation.ScaleEnd = scale; - } - - var scaleX = animation.ScaleXStart; - if (ImGui.DragFloat($"Scale X##{index}", ref scaleX, 0.05f)) - { - animation.ScaleXStart = scaleX; - animation.ScaleXEnd = scaleX; - } - - var scaleY = animation.ScaleYStart; - if (ImGui.DragFloat($"Scale Y##{index}", ref scaleY, 0.05f)) - { - animation.ScaleYStart = scaleY; - animation.ScaleYEnd = scaleY; - } - } - } - - var unk6xPair = new Vector4( - animation.CurveXStart, animation.CurveYStart, animation.CurveXEnd, animation.CurveYEnd); - if (ImGui.DragFloat4($"Curves##{index}", ref unk6xPair, 0.05f)) - { - animation.CurveXStart = unk6xPair.X; - animation.CurveYStart = unk6xPair.Y; - animation.CurveXEnd = unk6xPair.Z; - animation.CurveYEnd = unk6xPair.W; - } - - if (ImGuiFlagBox(animation, $"Enable bouncing##{index}", Sequence.BounceDisableFlag)) - { - ImGuiFlagBox(animation, $"Bounce delay##{index}", Sequence.BounceDelayFlag); - - if (ImGuiFlagBox(animation, $"Bouncing interpolation##{index}", Sequence.BounceInterpolationFlag)) - { - var bounceXPair = new Vector2(animation.BounceXStart, animation.BounceXEnd); - if (ImGui.DragFloat2($"Bounce X##{index}", ref bounceXPair)) - { - animation.BounceXStart = bounceXPair.X; - animation.BounceXEnd = bounceXPair.Y; - } - - var bounceYPair = new Vector2(animation.BounceYStart, animation.BounceYEnd); - if (ImGui.DragFloat2($"Bounce Y##{index}", ref bounceYPair)) - { - animation.BounceYStart = bounceYPair.X; - animation.BounceYEnd = bounceYPair.Y; - } - - var bounceCount = new int[] { animation.BounceXCount, animation.BounceYCount }; - if (ImGui.DragInt2($"Bounce count##{index}", ref bounceCount[0])) - { - animation.BounceXCount = (short)bounceCount[0]; - animation.BounceYCount = (short)bounceCount[1]; - } - } - else - { - var bounceXValue = animation.BounceXStart; - if (ImGui.DragFloat($"Bounce X##{index}", ref bounceXValue)) - { - animation.BounceXStart = bounceXValue; - animation.BounceXEnd = bounceXValue; - } - - var bounceYValue = animation.BounceYStart; - if (ImGui.DragFloat($"Bounce Y##{index}", ref bounceYValue)) - { - animation.BounceYStart = bounceYValue; - animation.BounceYEnd = bounceYValue; - } - - var bounceCount = new int[] { animation.BounceXCount, animation.BounceYCount }; - if (ImGui.DragInt2($"Bounce count##{index}", ref bounceCount[0])) - { - animation.BounceXCount = (short)bounceCount[0]; - animation.BounceYCount = (short)bounceCount[1]; - } - } - } - - int blendMode = animation.ColorBlend; - if (ImGui.Combo($"Blend mode##{index}", ref blendMode, new string[] - { "Normal", "Additive", "Subtractive" }, 3)) - animation.ColorBlend = blendMode; - - if (ImGuiFlagBox(animation, $"Enable color mask##{index}", Sequence.ColorMaskFlag)) - { - var colorStart = Utilities.ConvertColor(animation.ColorStart); - if (ImGui.ColorPicker4($"Mask start##{index}", ref colorStart)) - animation.ColorStart = Utilities.ConvertColor(colorStart); - - if (ImGuiFlagBox(animation, $"Enable color mask animation##{index}", Sequence.ColorInterpolationFlag)) - { - var colorEnd = Utilities.ConvertColor(animation.ColorEnd); - if (ImGui.ColorPicker4($"Mask end##{index}", ref colorEnd)) - animation.ColorEnd = Utilities.ConvertColor(colorEnd); - } - } - } - - private unsafe void AnimationGroupSelector() - { - if (ImGui.BeginCombo("", $"Animation Group {SelectedAnimGroup}", - ImGuiComboFlags.PopupAlignLeft)) - { - DrawAnimationGroupList(); - ImGui.EndCombo(); - } - ImGui.SameLine(); - if (ImGui.Button("-", new Vector2(30, 0)) && SelectedAnimGroup > 0) - SelectedAnimGroup--; - ImGui.SameLine(); - if (ImGui.Button("+", new Vector2(30, 0)) && - SelectedAnimGroup < _sequence.AnimationGroups.Count - 1) - SelectedAnimGroup++; - } - - private unsafe void Timeline() - { - if (SelectedAnimationGroup == null) - return; - - var frameIndex = _renderer.GetActualFrame(SelectedAnimationGroup, _animationFrameCurrent); - var frameIndexRef = _renderer.GetActualFrame(SelectedAnimationGroup, _animationFrameCurrent); - - ImGui.SliderInt("Frame", ref _animationFrameCurrent, 0, _animationFrameCount, - $"%i/{_animationFrameCount}"); - var isSequenceExpanded = true; - var isChanged = ImSequencer.Sequencer(_sequencer, ref frameIndexRef, ref isSequenceExpanded, ref _sequencerSelectedAnimation, ref _sequencerFirstFrame, - ImSequencer.SEQUENCER_OPTIONS.SEQUENCER_EDIT_STARTEND | - ImSequencer.SEQUENCER_OPTIONS.SEQUENCER_ADD | - ImSequencer.SEQUENCER_OPTIONS.SEQUENCER_DEL | - //ImSequencer.SEQUENCER_OPTIONS.SEQUENCER_COPYPASTE | - ImSequencer.SEQUENCER_OPTIONS.SEQUENCER_CHANGE_FRAME); - - if (frameIndex != frameIndexRef) - _animationFrameCurrent = frameIndexRef; - } - - private bool ImGuiFlagBox(Sequence.Animation animation, string label, int flag, bool negate = false) - { - var setFlag = negate ? 0 : flag; - var unsetFlag = negate ? flag : 0; - - bool isSet = (animation.Flags & flag) == unsetFlag; - if (ImGui.Checkbox(label, ref isSet)) - animation.Flags = (animation.Flags & ~flag) | (isSet ? unsetFlag : setFlag); - - return isSet; - } - - private SpriteModel AsSpriteModel(Sequence.Sprite sprite) => - new SpriteModel(sprite, _drawing, _atlasTexture, this, _settings); - private SpriteGroupModel AsSpriteGroupModel(int index) => - new SpriteGroupModel(_sequence, index, _drawing, _atlasTexture, this, _settings); - - private static Vector2 GetUv(ISpriteTexture texture, int x, int y) => - new Vector2((float)x / texture.Width, (float)y / texture.Height); - - public IntPtr BindTexture(Texture2D texture) => - _bootStrap.BindTexture(texture); - - public void UnbindTexture(IntPtr id) => - _bootStrap.UnbindTexture(id); - - public void RebindTexture(IntPtr id, Texture2D texture) => - _bootStrap.RebindTexture(id, texture); - } -} +using ImGuiNET; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using OpenKh.Tools.LayoutEditor.Interfaces; +using System.Numerics; +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Tools.Common.CustomImGui; +using OpenKh.Engine.Extensions; +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Renders; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; +using OpenKh.Engine.Renderers; +using System; +using System.Collections.Generic; +using System.Linq; +using OpenKh.Tools.LayoutEditor.Models; +using System.IO; +using OpenKh.Tools.LayoutEditor.Dialogs; +using OpenKh.Tools.LayoutEditor.Controls; + +namespace OpenKh.Tools.LayoutEditor +{ + public class AppSequenceEditor : IApp, ISaveBar, ITextureBinder, IDisposable + { + private readonly IEditorSettings _settings; + private readonly Sequence _sequence; + private readonly Imgd _image; + private readonly MonoGameImGuiBootstrap _bootStrap; + private readonly GraphicsDevice _graphics; + private readonly KingdomShader _shader; + private readonly MonoSpriteDrawing _drawing; + private readonly ISpriteTexture _atlasTexture; + private DebugSequenceRenderer _debugSequenceRenderer; + private readonly SequenceRenderer _renderer; + + private int _selectedSprite = 0; + private int _selectedSpriteGroup = 0; + private int _selectedAnimGroup; + private int _animationFrameCurrent; + private int _animationFrameCount; + private ISpriteTexture _destinationTexture; + private IntPtr _destinationTextureId; + private List _sprites; + private List _spriteGroups; + + private MySequencer _sequencer; + int _sequencerSelectedAnimation = 0; + int _sequencerFirstFrame = 0; + + private bool _isSpriteEditDialogOpen; + private SpriteEditDialog _spriteEditDialog; + private string SpriteEditDialogTitle => $"Sprite edit"; + + private bool _isSpriteGroupEditDialogOpen; + private SpriteGroupEditDialog _spriteGroupEditDialog; + private string SpriteGroupEditDialogTitle => $"Sprite group edit"; + + private Sequence.AnimationGroup SelectedAnimationGroup => + _debugSequenceRenderer.AnimationGroup; + + private bool CanAnimGroupHostChildAnims => SelectedAnimationGroup + .Animations.Any(x => (x.Flags & Sequence.IsActiveFlag) != 0); + + public int SelectedAnimGroup + { + get => _selectedAnimGroup; + set + { + _selectedAnimGroup = value; + _animationFrameCurrent = 0; + _sequencerSelectedAnimation = 0; + + var animationGroup = _sequence.AnimationGroups[_selectedAnimGroup]; + _animationFrameCount = SequenceExtensions.GetFrameLength(animationGroup); + _debugSequenceRenderer.AnimationGroup = animationGroup; + _sequencer.SelectedAnimationGroupIndex = value; + } + } + + public AppSequenceEditor( + MonoGameImGuiBootstrap bootstrap, + IEditorSettings settings, + Sequence sequence, + Imgd image) + { + _settings = settings; + _sequence = sequence; + _image = image; + + _bootStrap = bootstrap; + _graphics = bootstrap.GraphicsDevice; + _shader = new KingdomShader(bootstrap.Content); + _drawing = new MonoSpriteDrawing(_graphics, _shader); + _atlasTexture = _drawing.CreateSpriteTexture(_image); + _debugSequenceRenderer = new DebugSequenceRenderer(); + _renderer = new SequenceRenderer(_sequence, _drawing, _atlasTexture) + { + DebugSequenceRenderer = _debugSequenceRenderer + }; + + _destinationTexture = _drawing.CreateSpriteTexture(1024, 1024); + _destinationTextureId = this.BindTexture(_destinationTexture); + + _sprites = sequence.Sprites + .Select(x => AsSpriteModel(x)) + .ToList(); + _spriteGroups = sequence.SpriteGroups + .Select((_, i) => AsSpriteGroupModel(i)) + .ToList(); + + _sequencer = new MySequencer(sequence, _debugSequenceRenderer); + SelectedAnimGroup = 0; + } + + public void Menu() + { + ForMenu("Edit", () => + { + ForMenuItem("Sprite groups...", () => _isSpriteGroupEditDialogOpen = true); + ForMenuItem("Sprites...", () => _isSpriteEditDialogOpen = true); + }); + } + + public bool Run() + { + bool dummy = true; + if (ImGui.BeginPopupModal(SpriteEditDialogTitle, ref dummy, + ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal | ImGuiWindowFlags.AlwaysAutoResize)) + { + _spriteEditDialog.Run(); + ImGui.EndPopup(); + } + if (ImGui.BeginPopupModal(SpriteGroupEditDialogTitle, ref dummy, + ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal | ImGuiWindowFlags.AlwaysAutoResize)) + { + _spriteGroupEditDialog.Run(); + ImGui.EndPopup(); + } + + const float SpriteListWidthMul = 1f; + const float SpriteListWidthMax = 192f; + const float RightWidthMul = 1.5f; + const float RightWidthMax = 384f; + const float PreviewWidthMul = 2f; + const float TotalWidthMul = SpriteListWidthMul + RightWidthMul + PreviewWidthMul; + var windowSize = ImGui.GetWindowSize().X; + var spriteListWidth = Math.Min(windowSize / TotalWidthMul * SpriteListWidthMul, SpriteListWidthMax); + var rightWidth = Math.Min(windowSize / TotalWidthMul * RightWidthMul, RightWidthMax); + var previewWidth = windowSize - spriteListWidth - rightWidth; + + ForChild("SpriteGroupList", spriteListWidth, 0, true, DrawSpriteGroupList); + ImGui.SameLine(); + ForChild("Animation", previewWidth, 0, false, DrawAnimation); + ImGui.SameLine(); + ForChild("Right", rightWidth, 0, true, DrawRight); + + if (_isSpriteGroupEditDialogOpen) + { + ImGui.OpenPopup(SpriteGroupEditDialogTitle); + _isSpriteGroupEditDialogOpen = false; + _spriteGroupEditDialog = new SpriteGroupEditDialog( + _sequence, + _spriteGroups, + _selectedSpriteGroup, + _drawing, + _atlasTexture, + this, _settings); + } + + if (_isSpriteEditDialogOpen) + { + ImGui.OpenPopup(SpriteEditDialogTitle); + _isSpriteEditDialogOpen = false; + _spriteEditDialog = new SpriteEditDialog( + _sprites, + _selectedSprite, + _drawing, + _atlasTexture, + this, _settings); + } + + if (!_sequencer.IsPaused) + { + _animationFrameCurrent++; + if (_sequencer.ForceLoop && _animationFrameCurrent > SelectedAnimationGroup.GetFrameLength()) + _animationFrameCurrent = 0; + } + return true; + } + + private void DrawSpriteGroupList() + { + // Animate only the selected sprite + //if (_selectedSpriteGroup >= 0) + // _spriteGroups[_selectedSpriteGroup].Draw(0, 0); + + for (int i = 0; i < _spriteGroups.Count; i++) + { + var sprite = _spriteGroups[i]; + if (ImGui.Selectable($"##spriteGroup{i}", + _selectedSpriteGroup == i, + ImGuiSelectableFlags.None, + new Vector2(0, sprite.Height))) + _selectedSpriteGroup = i; + + ImGui.SameLine(); + ImGui.Image(sprite.TextureId, new Vector2(sprite.Width, sprite.Height)); + } + } + + private void DrawSpriteList() + { + // Animate only the selected sprite + if (_selectedSprite >= 0) + _sprites[_selectedSprite].Draw(0, 0); + + for (int i = 0; i < _sprites.Count; i++) + { + var sprite = _sprites[i]; + if (ImGui.Selectable($"##sprite{i}", + _selectedSprite == i, + ImGuiSelectableFlags.None, + new Vector2(0, sprite.Height))) + _selectedSprite = i; + + ImGui.SameLine(); + ImGui.Image(sprite.TextureId, new Vector2(sprite.Width, sprite.Height)); + } + } + + private void DrawAnimationGroupList() + { + for (int i = 0; i < _sequence.AnimationGroups.Count; i++) + { + if (ImGui.Selectable($"Animation Group {i}\n", + SelectedAnimGroup == i)) + SelectedAnimGroup = i; + } + } + + private unsafe void DrawAnimation() + { + const float TimelineControlWidth = 200f; + + AnimationGroupSelector(); + + if (ImGui.BeginChild("timeline", new Vector2(0, TimelineControlWidth))) + { + Timeline(); + ImGui.EndChild(); + } + + ForChild("Preview", 0, 0, false, () => + { + const float ViewportWidth = 1024f; + const float ViewportHeight = 1024f; + const float Infinite = 65536f; + var width = ImGui.GetWindowContentRegionWidth(); + var height = ImGui.GetWindowHeight(); + var originX = width / 4.0f; + var originY = height / 4.0f; + var backgroundColorInverse = new ColorF( + 1f - _settings.EditorBackground.R, + 1f - _settings.EditorBackground.G, + 1f - _settings.EditorBackground.B, + 1f); + + _drawing.DestinationTexture = _destinationTexture; + _drawing.Clear(_settings.EditorBackground); + _drawing.SetViewport(0, ViewportWidth, 0, ViewportHeight); + + // This draws the origin + _drawing.FillRectangle(originX - 1, 0, 1, Infinite, backgroundColorInverse); + _drawing.FillRectangle(0, originY - 1, Infinite, 1, backgroundColorInverse); + _drawing.Flush(); + + _renderer.Draw(_selectedAnimGroup, _animationFrameCurrent, originX, originY); + _drawing.Flush(); + _drawing.DestinationTexture = null; + + float maxU = 1f / ViewportWidth * width; + float maxV = 1f / ViewportHeight * height; + ImGui.Image(_destinationTextureId, new Vector2(width, height), + GetUv(_atlasTexture, 0, 0), new Vector2(maxU, maxV)); + }); + } + + private void DrawRight() + { + var animationGroup = _sequence.AnimationGroups[_selectedAnimGroup]; + if (ImGui.CollapsingHeader($"Properties")) + AnimationGroupEdit(animationGroup); + + for (var i = 0; i < animationGroup.Animations.Count; i++) + { + if (ImGui.CollapsingHeader($"Animation {i + 1}")) + { + AnimationEdit(animationGroup.Animations[i], i); + } + } + } + + public Bar.Entry SaveAnimation(string name) + { + var stream = new MemoryStream(); + _sequence.Write(stream); + + return new Bar.Entry + { + Name = name, + Stream = stream, + Type = Bar.EntryType.Seqd + }; + } + + public Bar.Entry SaveTexture(string name) + { + var stream = new MemoryStream(); + _image.Write(stream); + + return new Bar.Entry + { + Name = name, + Stream = stream, + Type = Bar.EntryType.Imgd + }; + } + + public void Dispose() + { + foreach (var sprite in _sprites) + sprite.Dispose(); + + _bootStrap.UnbindTexture(_destinationTextureId); + _destinationTexture.Dispose(); + } + + private void AnimationGroupEdit(Sequence.AnimationGroup animationGroup) + { + var canAnimationLoop = animationGroup.DoNotLoop == 0; + if (ImGui.Checkbox("Loop animation", ref canAnimationLoop)) + animationGroup.DoNotLoop = (short)(canAnimationLoop ? 0 : 1); + + int unknown06 = animationGroup.Unknown06; + if (ImGui.InputInt("Unknown06", ref unknown06)) + animationGroup.Unknown06 = (short)unknown06; + + var loopPair = new int[] { animationGroup.LoopStart, animationGroup.LoopEnd }; + if (ImGui.InputInt2("Loop frame", ref loopPair[0])) + { + animationGroup.LoopStart = loopPair[0]; + animationGroup.LoopEnd = loopPair[1]; + } + + if (CanAnimGroupHostChildAnims) + { + ImGui.Separator(); + ImGui.Text("Child animation properties"); + + int lightPosX = animationGroup.LightPositionX; + if (ImGui.InputInt("Light pos. X", ref lightPosX)) + animationGroup.LightPositionX = lightPosX; + + int textPosY = animationGroup.TextPositionY; + if (ImGui.InputInt("Text position Y", ref textPosY)) + animationGroup.TextPositionY = textPosY; + + int textScale = animationGroup.TextScale; + if (ImGui.InputInt("Text scale", ref textScale)) + animationGroup.TextScale = textScale; + + int uiPadding = animationGroup.UiPadding; + if (ImGui.InputInt("UI padding", ref uiPadding)) + animationGroup.UiPadding = uiPadding; + + int textPosX = animationGroup.TextPositionX; + if (ImGui.InputInt("Text position X", ref textPosX)) + animationGroup.TextPositionX = textPosX; + } + } + + private void AnimationEdit(Sequence.Animation animation, int index) + { + ImGuiFlagBox(animation, $"Is active##{index}", Sequence.IsActiveFlag, true); + ImGuiFlagBox(animation, $"Bilinear filtering##{index}", Sequence.DisableBilinearFlag, true); + ImGuiFlagBox(animation, $"Last cut##{index}", Sequence.LastCutFlag, true); + ImGuiFlagBox(animation, $"Translation##{index}", Sequence.TranslationDisableFlag, true); + ImGuiFlagBox(animation, $"Translation offset##{index}", Sequence.TranslationOffsetDisableFlag, true); + ImGuiFlagBox(animation, $"Position##{index}", Sequence.PositionDisableFlag, true); + ImGuiFlagBox(animation, $"Tag##{index}", Sequence.TagFlag, true); + + int interpolationMode = (animation.Flags & Sequence.DisableCurveFlag) != 0 ? 1 : 0; + if (ImGui.Combo($"Interpolation##{index}", ref interpolationMode, new string[] + { "Ease in/out", "Linear" }, 2)) + { + var flag = Sequence.DisableCurveFlag; + animation.Flags = (animation.Flags & ~flag) | (interpolationMode == 0 ? 0 : flag); + } + + var framePair = new int[] { animation.FrameStart, animation.FrameEnd }; + if (ImGui.DragInt2($"Frame lifespan##{index}", ref framePair[0])) + { + animation.FrameStart = framePair[0]; + animation.FrameEnd = framePair[1]; + } + + int spriteGroupIndex = animation.SpriteGroupIndex; + if (ImGui.InputInt($"Sprite group##{index}", ref spriteGroupIndex)) + animation.SpriteGroupIndex = Math.Min(Math.Max(spriteGroupIndex, 0), _sequence.SpriteGroups.Count - 1); + + if (ImGuiFlagBox(animation, $"Enable translation animation##{index}", Sequence.PivotDisableFlag)) + { + var xaPair = new int[] { animation.TranslateXStart, animation.TranslateXEnd }; + if (ImGui.DragInt2($"Translation X##{index}", ref xaPair[0])) + { + animation.TranslateXStart = xaPair[0]; + animation.TranslateXEnd = xaPair[1]; + } + + var yaPair = new int[] { animation.TranslateYStart, animation.TranslateYEnd }; + if (ImGui.DragInt2($"Translation Y##{index}", ref yaPair[0])) + { + animation.TranslateYStart = yaPair[0]; + animation.TranslateYEnd = yaPair[1]; + } + } + else + { + var xaPair = new int[] { animation.TranslateXStart, animation.TranslateYStart }; + if (ImGui.DragInt2($"Translation##{index}", ref xaPair[0])) + { + animation.TranslateXStart = xaPair[0]; + animation.TranslateYStart = xaPair[1]; + } + } + + if (ImGuiFlagBox(animation, $"Enable pivot translation##{index}", Sequence.PivotDisableFlag)) + { + if (ImGuiFlagBox(animation, $"Interpolate pivot##{index}", Sequence.RotationInterpolationFlag)) + { + var xbPair = new int[] { animation.PivotXStart, animation.PivotXEnd }; + if (ImGui.DragInt2($"Pivot X##{index}", ref xbPair[0])) + { + animation.PivotXStart = xbPair[0]; + animation.PivotXEnd = xbPair[1]; + } + + var ybPair = new int[] { animation.PivotYStart, animation.PivotYEnd }; + if (ImGui.DragInt2($"Pivot Y##{index}", ref ybPair[0])) + { + animation.PivotYStart = ybPair[0]; + animation.PivotYEnd = ybPair[1]; + } + } + else + { + var pivotX = animation.PivotXStart; + if (ImGui.DragInt($"Pivot X##{index}", ref pivotX)) + { + animation.PivotXStart = pivotX; + animation.PivotXEnd = pivotX; + } + + var pivotY = animation.PivotYStart; + if (ImGui.DragInt2($"Pivot Y##{index}", ref pivotY)) + { + animation.PivotYStart = pivotY; + animation.PivotYEnd = pivotY; + } + } + } + + if (ImGuiFlagBox(animation, $"Enable rotation##{index}", Sequence.RotationDisableFlag)) + { + var rotationStart = new Vector3( + (float)(animation.RotationXStart * 180f / Math.PI), + (float)(animation.RotationYStart * 180f / Math.PI), + (float)(animation.RotationZStart * 180f / Math.PI)); + var rotationEnd = new Vector3( + (float)(animation.RotationXEnd * 180f / Math.PI), + (float)(animation.RotationYEnd * 180f / Math.PI), + (float)(animation.RotationZEnd * 180f / Math.PI)); + + if (ImGuiFlagBox(animation, $"Interpolate rotation##{index}", Sequence.RotationInterpolationFlag)) + { + + if (ImGui.DragFloat3($"Rotation Start##{index}", ref rotationStart)) + { + animation.RotationXStart = (float)(rotationStart.X * Math.PI / 180f); + animation.RotationYStart = (float)(rotationStart.Y * Math.PI / 180f); + animation.RotationZStart = (float)(rotationStart.Z * Math.PI / 180f); + } + if (ImGui.DragFloat3($"Rotation End##{index}", ref rotationEnd)) + { + animation.RotationXEnd = (float)(rotationEnd.X * Math.PI / 180f); + animation.RotationYEnd = (float)(rotationEnd.Y * Math.PI / 180f); + animation.RotationZEnd = (float)(rotationEnd.Z * Math.PI / 180f); + } + } + else + { + if (ImGui.DragFloat3($"Rotation Start##{index}", ref rotationStart)) + { + animation.RotationXStart = (float)(rotationStart.X * Math.PI / 180f); + animation.RotationYStart = (float)(rotationStart.Y * Math.PI / 180f); + animation.RotationZStart = (float)(rotationStart.Z * Math.PI / 180f); + animation.RotationXEnd = animation.RotationXStart; + animation.RotationYEnd = animation.RotationYStart; + animation.RotationZEnd = animation.RotationZStart; + } + } + } + + if (ImGuiFlagBox(animation, $"Enable scaling##{index}", Sequence.ScalingDisableFlag)) + { + if (ImGuiFlagBox(animation, $"Scaling interpolation##{index}", Sequence.ScalingInterpolationFlag)) + { + var scalePair = new Vector2(animation.ScaleStart, animation.ScaleEnd); + if (ImGui.DragFloat2($"Scale##{index}", ref scalePair, 0.05f)) + { + animation.ScaleStart = scalePair.X; + animation.ScaleEnd = scalePair.Y; + } + + var scaleXPair = new Vector2(animation.ScaleXStart, animation.ScaleXEnd); + if (ImGui.DragFloat2($"Scale X##{index}", ref scaleXPair, 0.05f)) + { + animation.ScaleXStart = scaleXPair.X; + animation.ScaleXEnd = scaleXPair.Y; + } + + var scaleYPair = new Vector2(animation.ScaleYStart, animation.ScaleYEnd); + if (ImGui.DragFloat2($"Scale Y##{index}", ref scaleYPair, 0.05f)) + { + animation.ScaleYStart = scaleYPair.X; + animation.ScaleYEnd = scaleYPair.Y; + } + } + else + { + var scale = animation.ScaleStart; + if (ImGui.DragFloat($"Scale##{index}", ref scale, 0.05f)) + { + animation.ScaleStart = scale; + animation.ScaleEnd = scale; + } + + var scaleX = animation.ScaleXStart; + if (ImGui.DragFloat($"Scale X##{index}", ref scaleX, 0.05f)) + { + animation.ScaleXStart = scaleX; + animation.ScaleXEnd = scaleX; + } + + var scaleY = animation.ScaleYStart; + if (ImGui.DragFloat($"Scale Y##{index}", ref scaleY, 0.05f)) + { + animation.ScaleYStart = scaleY; + animation.ScaleYEnd = scaleY; + } + } + } + + var unk6xPair = new Vector4( + animation.CurveXStart, animation.CurveYStart, animation.CurveXEnd, animation.CurveYEnd); + if (ImGui.DragFloat4($"Curves##{index}", ref unk6xPair, 0.05f)) + { + animation.CurveXStart = unk6xPair.X; + animation.CurveYStart = unk6xPair.Y; + animation.CurveXEnd = unk6xPair.Z; + animation.CurveYEnd = unk6xPair.W; + } + + if (ImGuiFlagBox(animation, $"Enable bouncing##{index}", Sequence.BounceDisableFlag)) + { + ImGuiFlagBox(animation, $"Bounce delay##{index}", Sequence.BounceDelayFlag); + + if (ImGuiFlagBox(animation, $"Bouncing interpolation##{index}", Sequence.BounceInterpolationFlag)) + { + var bounceXPair = new Vector2(animation.BounceXStart, animation.BounceXEnd); + if (ImGui.DragFloat2($"Bounce X##{index}", ref bounceXPair)) + { + animation.BounceXStart = bounceXPair.X; + animation.BounceXEnd = bounceXPair.Y; + } + + var bounceYPair = new Vector2(animation.BounceYStart, animation.BounceYEnd); + if (ImGui.DragFloat2($"Bounce Y##{index}", ref bounceYPair)) + { + animation.BounceYStart = bounceYPair.X; + animation.BounceYEnd = bounceYPair.Y; + } + + var bounceCount = new int[] { animation.BounceXCount, animation.BounceYCount }; + if (ImGui.DragInt2($"Bounce count##{index}", ref bounceCount[0])) + { + animation.BounceXCount = (short)bounceCount[0]; + animation.BounceYCount = (short)bounceCount[1]; + } + } + else + { + var bounceXValue = animation.BounceXStart; + if (ImGui.DragFloat($"Bounce X##{index}", ref bounceXValue)) + { + animation.BounceXStart = bounceXValue; + animation.BounceXEnd = bounceXValue; + } + + var bounceYValue = animation.BounceYStart; + if (ImGui.DragFloat($"Bounce Y##{index}", ref bounceYValue)) + { + animation.BounceYStart = bounceYValue; + animation.BounceYEnd = bounceYValue; + } + + var bounceCount = new int[] { animation.BounceXCount, animation.BounceYCount }; + if (ImGui.DragInt2($"Bounce count##{index}", ref bounceCount[0])) + { + animation.BounceXCount = (short)bounceCount[0]; + animation.BounceYCount = (short)bounceCount[1]; + } + } + } + + int blendMode = animation.ColorBlend; + if (ImGui.Combo($"Blend mode##{index}", ref blendMode, new string[] + { "Normal", "Additive", "Subtractive" }, 3)) + animation.ColorBlend = blendMode; + + if (ImGuiFlagBox(animation, $"Enable color mask##{index}", Sequence.ColorMaskFlag)) + { + var colorStart = Utilities.ConvertColor(animation.ColorStart); + if (ImGui.ColorPicker4($"Mask start##{index}", ref colorStart)) + animation.ColorStart = Utilities.ConvertColor(colorStart); + + if (ImGuiFlagBox(animation, $"Enable color mask animation##{index}", Sequence.ColorInterpolationFlag)) + { + var colorEnd = Utilities.ConvertColor(animation.ColorEnd); + if (ImGui.ColorPicker4($"Mask end##{index}", ref colorEnd)) + animation.ColorEnd = Utilities.ConvertColor(colorEnd); + } + } + } + + private unsafe void AnimationGroupSelector() + { + if (ImGui.BeginCombo("", $"Animation Group {SelectedAnimGroup}", + ImGuiComboFlags.PopupAlignLeft)) + { + DrawAnimationGroupList(); + ImGui.EndCombo(); + } + ImGui.SameLine(); + if (ImGui.Button("-", new Vector2(30, 0)) && SelectedAnimGroup > 0) + SelectedAnimGroup--; + ImGui.SameLine(); + if (ImGui.Button("+", new Vector2(30, 0)) && + SelectedAnimGroup < _sequence.AnimationGroups.Count - 1) + SelectedAnimGroup++; + } + + private unsafe void Timeline() + { + if (SelectedAnimationGroup == null) + return; + + var frameIndex = _renderer.GetActualFrame(SelectedAnimationGroup, _animationFrameCurrent); + var frameIndexRef = _renderer.GetActualFrame(SelectedAnimationGroup, _animationFrameCurrent); + + ImGui.SliderInt("Frame", ref _animationFrameCurrent, 0, _animationFrameCount, + $"%i/{_animationFrameCount}"); + var isSequenceExpanded = true; + var isChanged = ImSequencer.Sequencer(_sequencer, ref frameIndexRef, ref isSequenceExpanded, ref _sequencerSelectedAnimation, ref _sequencerFirstFrame, + ImSequencer.SEQUENCER_OPTIONS.SEQUENCER_EDIT_STARTEND | + ImSequencer.SEQUENCER_OPTIONS.SEQUENCER_ADD | + ImSequencer.SEQUENCER_OPTIONS.SEQUENCER_DEL | + //ImSequencer.SEQUENCER_OPTIONS.SEQUENCER_COPYPASTE | + ImSequencer.SEQUENCER_OPTIONS.SEQUENCER_CHANGE_FRAME); + + if (frameIndex != frameIndexRef) + _animationFrameCurrent = frameIndexRef; + } + + private bool ImGuiFlagBox(Sequence.Animation animation, string label, int flag, bool negate = false) + { + var setFlag = negate ? 0 : flag; + var unsetFlag = negate ? flag : 0; + + bool isSet = (animation.Flags & flag) == unsetFlag; + if (ImGui.Checkbox(label, ref isSet)) + animation.Flags = (animation.Flags & ~flag) | (isSet ? unsetFlag : setFlag); + + return isSet; + } + + private SpriteModel AsSpriteModel(Sequence.Sprite sprite) => + new SpriteModel(sprite, _drawing, _atlasTexture, this, _settings); + private SpriteGroupModel AsSpriteGroupModel(int index) => + new SpriteGroupModel(_sequence, index, _drawing, _atlasTexture, this, _settings); + + private static Vector2 GetUv(ISpriteTexture texture, int x, int y) => + new Vector2((float)x / texture.Width, (float)y / texture.Height); + + public IntPtr BindTexture(Texture2D texture) => + _bootStrap.BindTexture(texture); + + public void UnbindTexture(IntPtr id) => + _bootStrap.UnbindTexture(id); + + public void RebindTexture(IntPtr id, Texture2D texture) => + _bootStrap.RebindTexture(id, texture); + } +} diff --git a/OpenKh.Tools.LayoutEditor/Controls/ImSequencer.cs b/OpenKh.Tools.LayoutEditor/Controls/ImSequencer.cs index 24a3ac1ce..e17dfaf77 100644 --- a/OpenKh.Tools.LayoutEditor/Controls/ImSequencer.cs +++ b/OpenKh.Tools.LayoutEditor/Controls/ImSequencer.cs @@ -1,899 +1,899 @@ -// The MIT License(MIT) -// -// Copyright(c) 2016 Cedric Guillemet -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -// This is a porting and modified version of ImSequencer from ImGuizmo repository. -// Please refer to https://github.com/CedricGuillemet/ImGuizmo for the original -// source code. - -using ImGuiNET; -using System; -using System.Collections.Generic; -using System.Numerics; - -namespace OpenKh.Tools.LayoutEditor.Controls -{ - public class ImRect - { - public Vector2 Min { get; } - public Vector2 Max { get; } - - public ImRect() - { - - } - - public ImRect(Vector2 a, Vector2 b) - { - Min = a; - Max = b; - } - - public bool Contains(Vector2 p) => - p.X >= Min.X && p.Y >= Min.Y && p.X < Max.X && p.Y < Max.Y; - } - - class ImSequencer - { - [Flags] - public enum SEQUENCER_OPTIONS - { - SEQUENCER_EDIT_NONE = 0, - SEQUENCER_EDIT_STARTEND = 1 << 1, - SEQUENCER_CHANGE_FRAME = 1 << 3, - SEQUENCER_ADD = 1 << 4, - SEQUENCER_DEL = 1 << 5, - SEQUENCER_COPYPASTE = 1 << 6, - SEQUENCER_EDIT_ALL = SEQUENCER_EDIT_STARTEND | SEQUENCER_CHANGE_FRAME - }; - - public interface IAnimation - { - int FrameStart { get; set; } - int FrameEnd { get; set; } - bool IsExpanded { get; set; } - string Name { get; } - uint Color { get; } - } - - public interface SequenceInterface - { - bool focused { get; set; } - int FrameMin { get; } - int FrameMax { get; } - bool IsPaused { get; set; } - int ItemCount { get; } - bool ForceLoop { get; set; } - - void BeginEdit(int index); - void EndEdit(); - int GetItemTypeCount(); - string GetItemTypeName(int typeIndex); - - IAnimation GetAnimation(int index); - void AddAnimation(); - void RemoveAnimation(int index); - void DuplicateAnimation(int index); - - bool IsFocus(int index); - void SetFocus(int index); - void ResetFocus(); - bool IsVisible(int index); - void SetVisibility(int index, bool isVisible); - - void Copy(); - void Paste(); - - int GetCustomHeight(int index); - void DoubleClick(int index); - void CustomDraw(int index, ImDrawListPtr draw_list, ImRect rc, ImRect legendRect, ImRect clippingRect, ImRect legendClippingRect); - void CustomDrawCompact(int index, ImDrawListPtr draw_list, ImRect rc, ImRect clippingRect); - } - - private class CustomDraw - { - public int index { get; set; } - public ImRect customRect { get; set; } - public ImRect legendRect { get; set; } - public ImRect clippingRect { get; set; } - public ImRect legendClippingRect { get; set; } - }; - - [Flags] - private enum AnimationBarPart - { - None, - SelectionLeft, - SelectionRight, - Bar = SelectionLeft | SelectionRight - } - - private const float AnimationBarSideSelectionWidth = 8f; - private const float MinBarWidth = 44f; - private const float FLT_EPSILON = 1.192092896e-07F; - private const uint ColorWhite = 0xffffffff; - private const int ButtonSize = 16; - private const int ButtonDistance = ButtonSize + 4; - - static float framePixelWidth = 10f; - static float framePixelWidthTarget = 10f; - static int movingEntry = -1; - static int movingPos = -1; - static AnimationBarPart movingPart = AnimationBarPart.None; - static bool MovingScrollBar = false; - static bool MovingCurrentFrame = false; - static bool panningView = false; - static Vector2 panningViewSource; - static int panningViewFrame; - static bool sizingRBar = false; - static bool sizingLBar = false; - - public static float Lerp(float min, float max, float t) => min * (1 - t) + max * t; - - private static bool SequencerAddDelButton(ImDrawListPtr draw_list, Vector2 pos, bool add = true) - { - var io = ImGui.GetIO(); - var delRect = new ImRect(pos, new Vector2(pos.X + ButtonSize, pos.Y + ButtonSize)); - var overDel = delRect.Contains(io.MousePos); - var delColor = overDel ? 0xFFAAAAAAu : 0x50000000u; - var midy = pos.Y + 16 / 2 - 0.5f; - var midx = pos.X + 16 / 2 - 0.5f; - - draw_list.AddRect(delRect.Min, delRect.Max, delColor, 4); - draw_list.AddLine(new Vector2(delRect.Min.X + 3, midy), new Vector2(delRect.Max.X - 3, midy), delColor, 2); - if (add) - draw_list.AddLine(new Vector2(midx, delRect.Min.Y + 3), new Vector2(midx, delRect.Max.Y - 3), delColor, 2); - - return overDel; - } - - private static bool SequencerButton( - ImDrawListPtr draw_list, - Vector2 pos, - char ch, - bool isSelected = false, - uint color = ColorWhite) - { - var io = ImGui.GetIO(); - var rect = new ImRect(pos, new Vector2(pos.X + 16, pos.Y + 16)); - var isMouseOver = rect.Contains(io.MousePos); - if (!isSelected) - color = isMouseOver ? 0xFFFFFFFFu : 0x50FFFFFFu; - - draw_list.AddRect(rect.Min, rect.Max, color, 4); - draw_list.AddText(new Vector2(pos.X + 4, pos.Y - 1), color, $"{ch}"); - - return isMouseOver; - } - - private static void Tooltip(string description) - { - if (!string.IsNullOrEmpty(description)) - { - bool isOpen = false; - ImGui.Begin("Child Tooltip?", ref isOpen, ImGuiWindowFlags.Tooltip | - ImGuiWindowFlags.NoTitleBar | - ImGuiWindowFlags.AlwaysUseWindowPadding | - ImGuiWindowFlags.AlwaysAutoResize | - ImGuiWindowFlags.NoResize); - ImGui.Text(description); - ImGui.EndChild(); - } - } - - public static bool Sequencer(SequenceInterface sequence, ref int currentFrame, ref bool expanded, ref int selectedEntry, ref int firstFrame, SEQUENCER_OPTIONS sequenceOptions) - { - var ret = false; - var io = ImGui.GetIO(); - var cx = (int)(io.MousePos.X); - var cy = (int)(io.MousePos.Y); - var legendWidth = 120; - - var deleteAnimationEntry = -1; - var duplicateAnimationEntry = -1; - var insertAnimationEntry = -1; - var ItemHeight = 20; - - var popupOpened = false; - var sequenceCount = sequence.ItemCount; - ImGui.BeginGroup(); - - var draw_list = ImGui.GetWindowDrawList(); - var canvas_pos = ImGui.GetCursorScreenPos(); // ImDrawList API uses screen coordinates! - var canvas_size = ImGui.GetContentRegionAvail(); // Resize canvas to what's available - int firstFrameUsed = firstFrame; - - int controlHeight = sequenceCount * ItemHeight; - for (int i = 0; i < sequenceCount; i++) - controlHeight += sequence.GetCustomHeight(i); - int frameCount = Math.Max(sequence.FrameMax - sequence.FrameMin, 1); - - // ImVector customDraws; - // ImVector compactCustomDraws; - var customDraws = new List(); - var compactCustomDraws = new List(); - // zoom in/out - int visibleFrameCount = (int)Math.Floor((canvas_size.X - legendWidth) / framePixelWidth); - float barWidthRatio = Math.Min(visibleFrameCount / (float)frameCount, 1f); - float barWidthInPixels = barWidthRatio * (canvas_size.X - legendWidth); - - var regionRect = new ImRect(canvas_pos, canvas_pos + canvas_size); - - if (ImGui.IsWindowFocused() && io.KeyAlt && io.MouseDown[2]) - { - if (!panningView) - { - panningViewSource = io.MousePos; - panningView = true; - panningViewFrame = firstFrame; - } - firstFrame = panningViewFrame - (int)((io.MousePos.X - panningViewSource.X) / framePixelWidth); - firstFrame = Math.Clamp(firstFrame, sequence.FrameMin, sequence.FrameMax - visibleFrameCount); - } - if (panningView && !io.MouseDown[2]) - { - panningView = false; - } - framePixelWidthTarget = Math.Clamp(framePixelWidthTarget, 0.1f, 50f); - - framePixelWidth = Lerp(framePixelWidth, framePixelWidthTarget, 0.33f); - - frameCount = sequence.FrameMax - sequence.FrameMin; - if (visibleFrameCount >= frameCount) - firstFrame = sequence.FrameMin; - - - // -- - if (!expanded) - { - ImGui.InvisibleButton("canvas", new Vector2(canvas_size.X - canvas_pos.X, (float)ItemHeight)); - draw_list.AddRectFilled(canvas_pos, new Vector2(canvas_size.X + canvas_pos.X, canvas_pos.Y + ItemHeight), 0xFF3D3837, 0); - - var tmps = $"{frameCount} Frames / {sequenceCount} entries"; - draw_list.AddText(new Vector2(canvas_pos.X + 26, canvas_pos.Y + 2), 0xFFFFFFFF, tmps); - } - else - { - bool hasScrollBar = true; - /* - int framesPixelWidth = int(frameCount * framePixelWidth); - if ((framesPixelWidth + legendWidth) >= canvas_size.X) - { - hasScrollBar = true; - } - */ - // test scroll area - var headerSize = new Vector2(canvas_size.X, (float)ItemHeight); - var scrollBarSize = new Vector2(canvas_size.X, 14f); - ImGui.InvisibleButton("topBar", headerSize); - draw_list.AddRectFilled(canvas_pos, canvas_pos + headerSize, 0xFFFF0000, 0); - Vector2 childFramePos = ImGui.GetCursorScreenPos(); - var childFrameSize = new Vector2(canvas_size.X, canvas_size.Y - 8f - headerSize.Y - (hasScrollBar ? scrollBarSize.Y : 0)); - ImGui.PushStyleColor(ImGuiCol.FrameBg, 0); - ImGui.BeginChildFrame(889, childFrameSize); - sequence.focused = ImGui.IsWindowFocused(); - ImGui.InvisibleButton("contentBar", new Vector2(canvas_size.X, (float)(controlHeight))); - Vector2 contentMin = ImGui.GetItemRectMin(); - Vector2 contentMax = ImGui.GetItemRectMax(); - var contentRect = new ImRect(contentMin, contentMax); - float contentHeight = contentMax.Y - contentMin.Y; - - // full background - draw_list.AddRectFilled(canvas_pos, canvas_pos + canvas_size, 0xFF242424, 0); - - // current frame top - var topRect = new ImRect(new Vector2(canvas_pos.X + legendWidth, canvas_pos.Y), new Vector2(canvas_pos.X + canvas_size.X, canvas_pos.Y + ItemHeight)); - - if (!MovingCurrentFrame && !MovingScrollBar && movingEntry == -1 && sequenceOptions.HasFlag(SEQUENCER_OPTIONS.SEQUENCER_CHANGE_FRAME) && currentFrame >= 0 && topRect.Contains(io.MousePos) && io.MouseDown[0]) - { - MovingCurrentFrame = true; - } - if (MovingCurrentFrame) - { - if (true) - { - currentFrame = (int)((io.MousePos.X - topRect.Min.X) / framePixelWidth) + firstFrameUsed; - if (currentFrame < sequence.FrameMin) - currentFrame = sequence.FrameMin; - if (currentFrame >= sequence.FrameMax) - currentFrame = sequence.FrameMax; - } - if (!io.MouseDown[0]) - MovingCurrentFrame = false; - } - - // Draw header controls on the left - draw_list.AddRectFilled(canvas_pos, new Vector2(canvas_size.X + canvas_pos.X, canvas_pos.Y + ItemHeight), 0xFF3D3837, 0); - if (sequenceOptions.HasFlag(SEQUENCER_OPTIONS.SEQUENCER_ADD)) - { - const uint PauseColor = 0xFFf1c40f; - const uint LoopColor = 0xFF0fc4f1; - - var nextButtonPosition = new Vector2(canvas_pos.X + legendWidth - ItemHeight, canvas_pos.Y + 2); - if (SequencerButton(draw_list, nextButtonPosition, 'P', sequence.IsPaused, PauseColor)) - { - Tooltip(sequence.IsPaused ? "Resume" : "Pause"); - if (io.MouseReleased[0]) - sequence.IsPaused = !sequence.IsPaused; - } - - nextButtonPosition.X -= ButtonDistance; - if (SequencerButton(draw_list, nextButtonPosition, 'L', sequence.ForceLoop, LoopColor)) - { - Tooltip("Force loop"); - if (io.MouseReleased[0]) - sequence.ForceLoop = !sequence.ForceLoop; - } - - nextButtonPosition.X -= ButtonDistance; - if (SequencerButton(draw_list, nextButtonPosition, 'A', false, ColorWhite)) - { - Tooltip("Add new animation"); - if (io.MouseReleased[0]) - insertAnimationEntry = sequence.ItemCount; - } - } - - //header frame number and lines - const int MinimumDistanceBetweenElements = 100; - int modFrameCount = 5; // after how many frames should print the frame number - int frameStep = 1; - while ((modFrameCount * framePixelWidth) < MinimumDistanceBetweenElements) - { - modFrameCount *= 2; - frameStep *= 2; - }; - - int halfModFrameCount = modFrameCount / 2; - - Action drawLine = (int i, int regionHeight) => - { - const uint TextColor = 0xFFBBBBBB; - - bool baseIndex = ((i % modFrameCount) == 0) || (i == sequence.FrameMax || i == sequence.FrameMin); - bool halfIndex = (i % halfModFrameCount) == 0; - int px = (int)canvas_pos.X + (int)(i * framePixelWidth) + legendWidth - (int)(firstFrameUsed * framePixelWidth); - int tiretStart = baseIndex ? 4 : (halfIndex ? 10 : 14); - int tiretEnd = baseIndex ? regionHeight : ItemHeight; - - if (px <= (canvas_size.X + canvas_pos.X) && px >= (canvas_pos.X + legendWidth)) - { - draw_list.AddLine(new Vector2((float)px, canvas_pos.Y + (float)tiretStart), new Vector2((float)px, canvas_pos.Y + (float)tiretEnd - 1), 0xFF606060, 1); - draw_list.AddLine(new Vector2((float)px, canvas_pos.Y + (float)ItemHeight), new Vector2((float)px, canvas_pos.Y + (float)regionHeight - 1), 0x30606060, 1); - } - - if (baseIndex && px >= (canvas_pos.X + legendWidth)) - draw_list.AddText(new Vector2((float)px + 3f, canvas_pos.Y), TextColor, $"{i}"); - }; - - for (int i = sequence.FrameMin; i <= sequence.FrameMax; i += frameStep) - { - drawLine(i, ItemHeight); - } - drawLine(sequence.FrameMin, ItemHeight); - drawLine(sequence.FrameMax, ItemHeight); - /* - draw_list.AddLine(canvas_pos, new Vector2(canvas_pos.X, canvas_pos.Y + controlHeight), 0xFF000000, 1); - draw_list.AddLine(new Vector2(canvas_pos.X, canvas_pos.Y + ItemHeight), new Vector2(canvas_size.X, canvas_pos.Y + ItemHeight), 0xFF000000, 1); - */ - - // clip content - draw_list.PushClipRect(childFramePos, childFramePos + childFrameSize); - - // draw item names in the legend rect on the left - for (int i = 0, customHeight = 0; i < sequenceCount; i++) - { - var animation = sequence.GetAnimation(i); - var tPos = new Vector2(contentMin.X + 3, contentMin.Y + i * ItemHeight + 2 + customHeight); - var tEndPos = new Vector2(contentMin.X + 3 + legendWidth, contentMin.Y + (i + 1) * ItemHeight + 2 + customHeight); - var canMouseClickOnRow = new ImRect(tPos, tEndPos).Contains(io.MousePos) && - io.MousePos.Y > childFramePos.Y && io.MousePos.Y <= childFramePos.Y + childFrameSize.Y && - ImGui.IsWindowFocused(); - if (canMouseClickOnRow && io.MouseDown[0] && ImGui.IsWindowHovered()) - selectedEntry = i; - - draw_list.AddText(tPos, 0xFFFFFFFF, animation.Name ?? $"#{i + 1}"); - - if (sequenceOptions.HasFlag(SEQUENCER_OPTIONS.SEQUENCER_DEL)) - { - var isAnimationVisible = sequence.IsVisible(i); - var buttonPos = new Vector2(contentMin.X + legendWidth - ButtonDistance + 2 - 10, tPos.Y + 2); - if (SequencerButton(draw_list, buttonPos, 'H', !isAnimationVisible, 0xff15208f) && canMouseClickOnRow) - { - Tooltip("Hide animation"); - if (io.MouseReleased[0]) - sequence.SetVisibility(i, !isAnimationVisible); - } - - var isFocused = sequence.IsFocus(i); - buttonPos.X -= ButtonDistance; - if (SequencerButton(draw_list, buttonPos, 'S', isFocused, 0xff69992f) && canMouseClickOnRow) - { - Tooltip("Display only this animation"); - if (io.MouseReleased[0]) - { - if (isFocused) - sequence.ResetFocus(); - else - sequence.SetFocus(i); - } - } - - buttonPos.X -= ButtonDistance; - if (SequencerButton(draw_list, buttonPos, 'D', false, ColorWhite) && canMouseClickOnRow) - { - Tooltip("Duplicate animation"); - if (io.MouseReleased[0]) - duplicateAnimationEntry = i; - } - - buttonPos.X -= ButtonDistance; - if (SequencerButton(draw_list, buttonPos, 'R', false, ColorWhite) && canMouseClickOnRow) - { - Tooltip("Remove animation"); - if (io.MouseReleased[0]) - deleteAnimationEntry = i; - } - } - customHeight += sequence.GetCustomHeight(i); - } - - // clipping rect so items bars are not visible in the legend on the left when scrolled - // - - // slots background - for (int i = 0, customHeight = 0; i < sequenceCount; i++) - { - // Draw as a zebra background - uint col = (i & 1) != 0 ? 0xFF3A3636 : 0xFF413D3D; - - var localCustomHeight = sequence.GetCustomHeight(i); - Vector2 pos = new Vector2(contentMin.X + legendWidth, contentMin.Y + ItemHeight * i + 1 + customHeight); - Vector2 sz = new Vector2(canvas_size.X + canvas_pos.X, pos.Y + ItemHeight - 1 + localCustomHeight); - if (!popupOpened && cy >= pos.Y && cy < pos.Y + (ItemHeight + localCustomHeight) && movingEntry == -1 && cx > contentMin.X && cx < contentMin.X + canvas_size.X) - { - col += 0x80201008; - pos.X -= legendWidth; - } - draw_list.AddRectFilled(pos, sz, col, 0); - customHeight += localCustomHeight; - } - - draw_list.PushClipRect(childFramePos + new Vector2((float)(legendWidth), 0f), childFramePos + childFrameSize); - - // vertical frame lines in content area - Action drawLineContent = (int i, int regionHeight) => - { - int px = (int)canvas_pos.X + (int)(i * framePixelWidth) + legendWidth - (int)(firstFrameUsed * framePixelWidth); - int tiretStart = (int)(contentMin.Y); - int tiretEnd = (int)(contentMax.Y); - - if (px <= (canvas_size.X + canvas_pos.X) && px >= (canvas_pos.X + legendWidth)) - { - //draw_list.AddLine(new Vector2((float)px, canvas_pos.Y + (float)tiretStart), new Vector2((float)px, canvas_pos.Y + (float)tiretEnd - 1), 0xFF606060, 1); - - draw_list.AddLine(new Vector2((float)(px), (float)(tiretStart)), new Vector2((float)(px), (float)(tiretEnd)), 0x30606060, 1); - } - }; - for (int i = sequence.FrameMin; i <= sequence.FrameMax; i += frameStep) - { - drawLineContent(i, (int)(contentHeight)); - } - drawLineContent(sequence.FrameMin, (int)(contentHeight)); - drawLineContent(sequence.FrameMax, (int)(contentHeight)); - - // selection - bool selected = (selectedEntry >= 0); - if (selected) - { - // draw background differently if selected - var customHeight = 0; - for (int i = 0; i < selectedEntry; i++) - customHeight += sequence.GetCustomHeight(i); - ; - draw_list.AddRectFilled( - new Vector2(contentMin.X, contentMin.Y + ItemHeight * selectedEntry + customHeight), - new Vector2(contentMin.X + canvas_size.X, contentMin.Y + ItemHeight * (selectedEntry + 1) + customHeight), - 0x801080FF, 1f); - } - - // slots - for (int i = 0, customHeight = 0; i < sequenceCount; i++) - { - var animation = sequence.GetAnimation(i); - var localCustomHeight = sequence.GetCustomHeight(i); - - Vector2 pos = new Vector2(contentMin.X + legendWidth - firstFrameUsed * framePixelWidth, contentMin.Y + ItemHeight * i + 1 + customHeight); - var slotP1 = new Vector2(pos.X + animation.FrameStart * framePixelWidth, pos.Y + 2); - var slotP2 = new Vector2(pos.X + animation.FrameEnd * framePixelWidth + framePixelWidth, pos.Y + ItemHeight - 2); - var slotP3 = new Vector2(pos.X + animation.FrameEnd * framePixelWidth + framePixelWidth, pos.Y + ItemHeight - 2 + localCustomHeight); - uint slotColor = animation.Color | 0xFF000000; - uint slotColorHalf = (animation.Color & 0xFFFFFF) | 0x40000000; - - if (slotP1.X <= (canvas_size.X + contentMin.X) && slotP2.X >= (contentMin.X + legendWidth)) - { - draw_list.AddRectFilled(slotP1, slotP3, slotColorHalf, 2); - draw_list.AddRectFilled(slotP1, slotP2, slotColor, 2); - } - if (new ImRect(slotP1, slotP2).Contains(io.MousePos) && io.MouseDoubleClicked[0]) - { - sequence.DoubleClick(i); - } - - var rects = new ImRect[] - { - new ImRect(slotP1, new Vector2(slotP1.X + AnimationBarSideSelectionWidth, slotP2.Y)), - new ImRect(new Vector2(slotP2.X - AnimationBarSideSelectionWidth, slotP1.Y), slotP2), - new ImRect(slotP1, slotP2) - }; - - var quadColor = new uint[] { 0xFFFFFFFF, 0xFFFFFFFF, slotColor + (selected ? 0u : 0x202020u) }; - if (movingEntry == -1 && (sequenceOptions.HasFlag(SEQUENCER_OPTIONS.SEQUENCER_EDIT_STARTEND))) // TODOFOCUS && backgroundRect.Contains(io.MousePos)) - { - const uint AnimationResizeHoverColor = 0xFFFFFFFFu; - uint AnimationBarHoverColor = slotColor + 0x202020; - - var animBarLeftRect = new ImRect(slotP1, new Vector2(slotP1.X + AnimationBarSideSelectionWidth, slotP2.Y)); - var animBarRightRect = new ImRect(new Vector2(slotP2.X - AnimationBarSideSelectionWidth, slotP1.Y), slotP2); - var animBarRect = new ImRect(slotP1, slotP2); - - var animationBarPartSelection = AnimationBarPart.None; - if (animBarLeftRect.Contains(io.MousePos)) - { - animationBarPartSelection = AnimationBarPart.SelectionLeft; - draw_list.AddRectFilled(animBarLeftRect.Min, animBarLeftRect.Max, AnimationResizeHoverColor, 2); - } - else if (animBarRightRect.Contains(io.MousePos)) - { - animationBarPartSelection = AnimationBarPart.SelectionRight; - draw_list.AddRectFilled(animBarRightRect.Min, animBarRightRect.Max, AnimationResizeHoverColor, 2); - } - else if (animBarRect.Contains(io.MousePos)) - { - animationBarPartSelection = AnimationBarPart.Bar; - draw_list.AddRectFilled(animBarRect.Min, animBarRect.Max, AnimationBarHoverColor, 2); - } - - if (ImGui.IsMouseClicked(0) && animationBarPartSelection != AnimationBarPart.None) - { - if (!new ImRect(childFramePos, childFramePos + childFrameSize).Contains(io.MousePos)) - continue; - - if (!MovingScrollBar && !MovingCurrentFrame) - { - movingEntry = i; - movingPos = cx; - movingPart = animationBarPartSelection; - sequence.BeginEdit(movingEntry); - break; - } - } - } - - // custom draw - if (localCustomHeight > 0) - { - var rp = new Vector2(canvas_pos.X, contentMin.Y + ItemHeight * i + 1 + customHeight); - var customRect = new ImRect(rp + new Vector2(legendWidth - (firstFrameUsed - sequence.FrameMin - 0.5f) * framePixelWidth, (float)(ItemHeight)), - rp + new Vector2(legendWidth + (sequence.FrameMax - firstFrameUsed - 0.5f + 2f) * framePixelWidth, (float)(localCustomHeight + ItemHeight))); - var clippingRect = new ImRect(rp + new Vector2((float)(legendWidth), (float)(ItemHeight)), rp + new Vector2(canvas_size.X, (float)(localCustomHeight + ItemHeight))); - - var legendRect = new ImRect(rp + new Vector2(0f, (float)(ItemHeight)), rp + new Vector2((float)(legendWidth), (float)(localCustomHeight))); - var legendClippingRect = new ImRect(canvas_pos + new Vector2(0f, (float)(ItemHeight)), canvas_pos + new Vector2((float)(legendWidth), (float)(localCustomHeight + ItemHeight))); - customDraws.Add(new CustomDraw - { - index = i, - customRect = customRect, - legendRect = legendRect, - clippingRect = clippingRect, - legendClippingRect = legendClippingRect - }); - } - else - { - var rp = new Vector2(canvas_pos.X, contentMin.Y + ItemHeight * i + customHeight); - var customRect = new ImRect(rp + new Vector2(legendWidth - (firstFrameUsed - sequence.FrameMin - 0.5f) * framePixelWidth, (float)(0f)), - rp + new Vector2(legendWidth + (sequence.FrameMax - firstFrameUsed - 0.5f + 2f) * framePixelWidth, (float)(ItemHeight))); - var clippingRect = new ImRect(rp + new Vector2((float)(legendWidth), (float)(0f)), rp + new Vector2(canvas_size.X, (float)(ItemHeight))); - - compactCustomDraws.Add(new CustomDraw - { - index = i, - customRect = customRect, - legendRect = new ImRect(), - clippingRect = clippingRect, - legendClippingRect = new ImRect() - }); - } - customHeight += localCustomHeight; - } - - - // moving - if (/*backgroundRect.Contains(io.MousePos) && */movingEntry >= 0) - { - ImGui.CaptureMouseFromApp(); - int diffFrame = (int)((cx - movingPos) / framePixelWidth); - if (Math.Abs(diffFrame) > 0) - { - var animation = sequence.GetAnimation(movingEntry); - selectedEntry = movingEntry; - if (movingPart.HasFlag(AnimationBarPart.SelectionLeft)) - animation.FrameStart += diffFrame; - if (movingPart.HasFlag(AnimationBarPart.SelectionRight)) - animation.FrameEnd += diffFrame; - if (animation.FrameStart < 0) - { - if (movingPart.HasFlag(AnimationBarPart.SelectionRight)) - animation.FrameEnd -= animation.FrameStart; - animation.FrameStart = 0; - } - if (movingPart.HasFlag(AnimationBarPart.SelectionLeft) && animation.FrameStart > animation.FrameEnd) - animation.FrameStart = animation.FrameEnd; - if (movingPart.HasFlag(AnimationBarPart.SelectionRight) && animation.FrameEnd < animation.FrameStart) - animation.FrameEnd = animation.FrameStart; - movingPos += (int)(diffFrame * framePixelWidth); - } - if (!io.MouseDown[0]) - { - // single select - if (/*diffFrame != 0 &&*/ movingPart != 0) - { - selectedEntry = movingEntry; - ret = true; - } - - movingEntry = -1; - sequence.EndEdit(); - } - } - - // cursor - if (currentFrame >= firstFrame && currentFrame <= sequence.FrameMax) - { - const float cursorWidth = 8f; - float cursorOffset = contentMin.X + legendWidth + (currentFrame - firstFrameUsed) * framePixelWidth + framePixelWidth / 2 - cursorWidth * 0.5f; - draw_list.AddLine(new Vector2(cursorOffset, canvas_pos.Y), new Vector2(cursorOffset, contentMax.Y), 0xA02A2AFF, cursorWidth); - draw_list.AddText(new Vector2(cursorOffset + 10, canvas_pos.Y + 2), 0xFF2A2AFF, $"{currentFrame}"); - } - - draw_list.PopClipRect(); - draw_list.PopClipRect(); - - foreach (var customDraw in customDraws) - sequence.CustomDraw(customDraw.index, draw_list, customDraw.customRect, customDraw.legendRect, customDraw.clippingRect, customDraw.legendClippingRect); - foreach (var customDraw in compactCustomDraws) - sequence.CustomDrawCompact(customDraw.index, draw_list, customDraw.customRect, customDraw.clippingRect); - - // copy paste - if (sequenceOptions.HasFlag(SEQUENCER_OPTIONS.SEQUENCER_COPYPASTE)) - { - var rectCopy = new ImRect(new Vector2(contentMin.X + 100, canvas_pos.Y + 2) - , new Vector2(contentMin.X + 100 + 30, canvas_pos.Y + ItemHeight - 2)); - bool inRectCopy = rectCopy.Contains(io.MousePos); - uint copyColor = inRectCopy ? 0xFF1080FF : 0xFF000000; - draw_list.AddText(rectCopy.Min, copyColor, "Copy"); - - var rectPaste = new ImRect(new Vector2(contentMin.X + 140, canvas_pos.Y + 2) - , new Vector2(contentMin.X + 140 + 30, canvas_pos.Y + ItemHeight - 2)); - bool inRectPaste = rectPaste.Contains(io.MousePos); - uint pasteColor = inRectPaste ? 0xFF1080FF : 0xFF000000; - draw_list.AddText(rectPaste.Min, pasteColor, "Paste"); - - if (inRectCopy && io.MouseReleased[0]) - { - sequence.Copy(); - } - if (inRectPaste && io.MouseReleased[0]) - { - sequence.Paste(); - } - } - // - - ImGui.EndChildFrame(); - ImGui.PopStyleColor(); - if (hasScrollBar) - { - ImGui.InvisibleButton("scrollBar", scrollBarSize); - Vector2 scrollBarMin = ImGui.GetItemRectMin(); - Vector2 scrollBarMax = ImGui.GetItemRectMax(); - - // ratio = number of frames visible in control / number to total frames - - float startFrameOffset = ((float)(firstFrameUsed - sequence.FrameMin) / (float)frameCount) * (canvas_size.X - legendWidth); - var scrollBarA = new Vector2(scrollBarMin.X + legendWidth, scrollBarMin.Y - 2); - var scrollBarB = new Vector2(scrollBarMin.X + canvas_size.X, scrollBarMax.Y - 1); - draw_list.AddRectFilled(scrollBarA, scrollBarB, 0xFF222222, 0); - - var scrollBarRect = new ImRect(scrollBarA, scrollBarB); - bool inScrollBar = scrollBarRect.Contains(io.MousePos); - - draw_list.AddRectFilled(scrollBarA, scrollBarB, 0xFF101010, 8); - - - var scrollBarC = new Vector2(scrollBarMin.X + legendWidth + startFrameOffset, scrollBarMin.Y); - var scrollBarD = new Vector2(scrollBarMin.X + legendWidth + barWidthInPixels + startFrameOffset, scrollBarMax.Y - 2); - draw_list.AddRectFilled(scrollBarC, scrollBarD, (inScrollBar || MovingScrollBar) ? 0xFF606060 : 0xFF505050, 6); - - float handleRadius = (scrollBarMax.Y - scrollBarMin.Y) / 2; - var barHandleLeft = new ImRect(scrollBarC, new Vector2(scrollBarC.X + 14, scrollBarD.Y)); - var barHandleRight = new ImRect(new Vector2(scrollBarD.X - 14, scrollBarC.Y), scrollBarD); - - bool onLeft = barHandleLeft.Contains(io.MousePos); - bool onRight = barHandleRight.Contains(io.MousePos); - - - draw_list.AddRectFilled(barHandleLeft.Min, barHandleLeft.Max, (onLeft || sizingLBar) ? 0xFFAAAAAA : 0xFF666666, 6); - draw_list.AddRectFilled(barHandleRight.Min, barHandleRight.Max, (onRight || sizingRBar) ? 0xFFAAAAAA : 0xFF666666, 6); - - var scrollBarThumb = new ImRect(scrollBarC, scrollBarD); - if (sizingRBar) - { - if (!io.MouseDown[0]) - { - sizingRBar = false; - } - else - { - // Resize scrollbar from the right - float barNewWidth = Math.Max(barWidthInPixels + io.MouseDelta.X, MinBarWidth); - float barRatio = barNewWidth / barWidthInPixels; - framePixelWidthTarget = framePixelWidth = framePixelWidth / barRatio; - int newVisibleFrameCount = (int)((canvas_size.X - legendWidth) / framePixelWidthTarget); - int lastFrame = firstFrame + newVisibleFrameCount; - if (lastFrame > sequence.FrameMax) - { - framePixelWidthTarget = framePixelWidth = (canvas_size.X - legendWidth) / (float)(sequence.FrameMax - firstFrame); - } - } - } - else if (sizingLBar) - { - if (!io.MouseDown[0]) - { - sizingLBar = false; - } - else - { - // Resize scrollbar from the left - if (Math.Abs(io.MouseDelta.X) > FLT_EPSILON) - { - float barNewWidth = Math.Max(barWidthInPixels - io.MouseDelta.X, MinBarWidth); - float barRatio = barNewWidth / barWidthInPixels; - float previousFramePixelWidthTarget = framePixelWidthTarget; - framePixelWidthTarget = framePixelWidth = framePixelWidth / barRatio; - int newVisibleFrameCount = (int)(visibleFrameCount / barRatio); - int newFirstFrame = firstFrame + newVisibleFrameCount - visibleFrameCount; - newFirstFrame = Math.Clamp(newFirstFrame, sequence.FrameMin, Math.Max(sequence.FrameMax - visibleFrameCount, sequence.FrameMin)); - if (newFirstFrame == firstFrame) - { - framePixelWidth = framePixelWidthTarget = previousFramePixelWidthTarget; - } - else - { - firstFrame = newFirstFrame; - } - } - } - } - else - { - if (MovingScrollBar) - { - if (!io.MouseDown[0]) - { - MovingScrollBar = false; - } - else - { - float framesPerPixelInBar = barWidthInPixels / (float)visibleFrameCount; - firstFrame = (int)((io.MousePos.X - panningViewSource.X) / framesPerPixelInBar) - panningViewFrame; - firstFrame = Math.Clamp(firstFrame, sequence.FrameMin, Math.Max(sequence.FrameMax - visibleFrameCount, sequence.FrameMin)); - } - } - else - { - if (scrollBarThumb.Contains(io.MousePos) && ImGui.IsMouseClicked(0) && !MovingCurrentFrame && movingEntry == -1) - { - MovingScrollBar = true; - panningViewSource = io.MousePos; - panningViewFrame = firstFrame; - } - if (!sizingRBar && onRight && ImGui.IsMouseClicked(0)) - sizingRBar = true; - if (!sizingLBar && onLeft && ImGui.IsMouseClicked(0)) - sizingLBar = true; - - } - } - } - } - - ImGui.EndGroup(); - - if (regionRect.Contains(io.MousePos)) - { - bool overCustomDraw = false; - foreach (var custom in customDraws) - { - if (custom.customRect.Contains(io.MousePos)) - { - overCustomDraw = true; - } - } - if (overCustomDraw) - { - } - else - { - //frameOverCursor = *firstFrame + (int)(visibleFrameCount * ((io.MousePos.X - (float)legendWidth - canvas_pos.X) / (canvas_size.X - legendWidth))); - ////frameOverCursor = max(min(*firstFrame - visibleFrameCount / 2, frameCount - visibleFrameCount), 0); - - ///**firstFrame -= frameOverCursor; - //*firstFrame *= framePixelWidthTarget / framePixelWidth; - //*firstFrame += frameOverCursor;*/ - //if (io.MouseWheel < -FLT_EPSILON) - //{ - // *firstFrame -= frameOverCursor; - // *firstFrame = int(*firstFrame * 1.1f); - // framePixelWidthTarget *= 0.9f; - // *firstFrame += frameOverCursor; - //} - - //if (io.MouseWheel > FLT_EPSILON) - //{ - // *firstFrame -= frameOverCursor; - // *firstFrame = int(*firstFrame * 0.9f); - // framePixelWidthTarget *= 1.1f; - // *firstFrame += frameOverCursor; - //} - } - } - - if (expanded) - { - bool overExpanded = SequencerAddDelButton(draw_list, new Vector2(canvas_pos.X + 2, canvas_pos.Y + 2), !expanded); - if (overExpanded && io.MouseReleased[0]) - expanded = !expanded; - } - - if (deleteAnimationEntry >= 0) - { - sequence.RemoveAnimation(deleteAnimationEntry); - if ((selectedEntry == deleteAnimationEntry || selectedEntry >= sequence.ItemCount)) - selectedEntry = -1; - } - - if (duplicateAnimationEntry >= 0) - { - sequence.DuplicateAnimation(duplicateAnimationEntry); - } - - if (insertAnimationEntry >= 0) - { - sequence.AddAnimation(); - } - - return ret; - } - } -} +// The MIT License(MIT) +// +// Copyright(c) 2016 Cedric Guillemet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// This is a porting and modified version of ImSequencer from ImGuizmo repository. +// Please refer to https://github.com/CedricGuillemet/ImGuizmo for the original +// source code. + +using ImGuiNET; +using System; +using System.Collections.Generic; +using System.Numerics; + +namespace OpenKh.Tools.LayoutEditor.Controls +{ + public class ImRect + { + public Vector2 Min { get; } + public Vector2 Max { get; } + + public ImRect() + { + + } + + public ImRect(Vector2 a, Vector2 b) + { + Min = a; + Max = b; + } + + public bool Contains(Vector2 p) => + p.X >= Min.X && p.Y >= Min.Y && p.X < Max.X && p.Y < Max.Y; + } + + class ImSequencer + { + [Flags] + public enum SEQUENCER_OPTIONS + { + SEQUENCER_EDIT_NONE = 0, + SEQUENCER_EDIT_STARTEND = 1 << 1, + SEQUENCER_CHANGE_FRAME = 1 << 3, + SEQUENCER_ADD = 1 << 4, + SEQUENCER_DEL = 1 << 5, + SEQUENCER_COPYPASTE = 1 << 6, + SEQUENCER_EDIT_ALL = SEQUENCER_EDIT_STARTEND | SEQUENCER_CHANGE_FRAME + }; + + public interface IAnimation + { + int FrameStart { get; set; } + int FrameEnd { get; set; } + bool IsExpanded { get; set; } + string Name { get; } + uint Color { get; } + } + + public interface SequenceInterface + { + bool focused { get; set; } + int FrameMin { get; } + int FrameMax { get; } + bool IsPaused { get; set; } + int ItemCount { get; } + bool ForceLoop { get; set; } + + void BeginEdit(int index); + void EndEdit(); + int GetItemTypeCount(); + string GetItemTypeName(int typeIndex); + + IAnimation GetAnimation(int index); + void AddAnimation(); + void RemoveAnimation(int index); + void DuplicateAnimation(int index); + + bool IsFocus(int index); + void SetFocus(int index); + void ResetFocus(); + bool IsVisible(int index); + void SetVisibility(int index, bool isVisible); + + void Copy(); + void Paste(); + + int GetCustomHeight(int index); + void DoubleClick(int index); + void CustomDraw(int index, ImDrawListPtr draw_list, ImRect rc, ImRect legendRect, ImRect clippingRect, ImRect legendClippingRect); + void CustomDrawCompact(int index, ImDrawListPtr draw_list, ImRect rc, ImRect clippingRect); + } + + private class CustomDraw + { + public int index { get; set; } + public ImRect customRect { get; set; } + public ImRect legendRect { get; set; } + public ImRect clippingRect { get; set; } + public ImRect legendClippingRect { get; set; } + }; + + [Flags] + private enum AnimationBarPart + { + None, + SelectionLeft, + SelectionRight, + Bar = SelectionLeft | SelectionRight + } + + private const float AnimationBarSideSelectionWidth = 8f; + private const float MinBarWidth = 44f; + private const float FLT_EPSILON = 1.192092896e-07F; + private const uint ColorWhite = 0xffffffff; + private const int ButtonSize = 16; + private const int ButtonDistance = ButtonSize + 4; + + static float framePixelWidth = 10f; + static float framePixelWidthTarget = 10f; + static int movingEntry = -1; + static int movingPos = -1; + static AnimationBarPart movingPart = AnimationBarPart.None; + static bool MovingScrollBar = false; + static bool MovingCurrentFrame = false; + static bool panningView = false; + static Vector2 panningViewSource; + static int panningViewFrame; + static bool sizingRBar = false; + static bool sizingLBar = false; + + public static float Lerp(float min, float max, float t) => min * (1 - t) + max * t; + + private static bool SequencerAddDelButton(ImDrawListPtr draw_list, Vector2 pos, bool add = true) + { + var io = ImGui.GetIO(); + var delRect = new ImRect(pos, new Vector2(pos.X + ButtonSize, pos.Y + ButtonSize)); + var overDel = delRect.Contains(io.MousePos); + var delColor = overDel ? 0xFFAAAAAAu : 0x50000000u; + var midy = pos.Y + 16 / 2 - 0.5f; + var midx = pos.X + 16 / 2 - 0.5f; + + draw_list.AddRect(delRect.Min, delRect.Max, delColor, 4); + draw_list.AddLine(new Vector2(delRect.Min.X + 3, midy), new Vector2(delRect.Max.X - 3, midy), delColor, 2); + if (add) + draw_list.AddLine(new Vector2(midx, delRect.Min.Y + 3), new Vector2(midx, delRect.Max.Y - 3), delColor, 2); + + return overDel; + } + + private static bool SequencerButton( + ImDrawListPtr draw_list, + Vector2 pos, + char ch, + bool isSelected = false, + uint color = ColorWhite) + { + var io = ImGui.GetIO(); + var rect = new ImRect(pos, new Vector2(pos.X + 16, pos.Y + 16)); + var isMouseOver = rect.Contains(io.MousePos); + if (!isSelected) + color = isMouseOver ? 0xFFFFFFFFu : 0x50FFFFFFu; + + draw_list.AddRect(rect.Min, rect.Max, color, 4); + draw_list.AddText(new Vector2(pos.X + 4, pos.Y - 1), color, $"{ch}"); + + return isMouseOver; + } + + private static void Tooltip(string description) + { + if (!string.IsNullOrEmpty(description)) + { + bool isOpen = false; + ImGui.Begin("Child Tooltip?", ref isOpen, ImGuiWindowFlags.Tooltip | + ImGuiWindowFlags.NoTitleBar | + ImGuiWindowFlags.AlwaysUseWindowPadding | + ImGuiWindowFlags.AlwaysAutoResize | + ImGuiWindowFlags.NoResize); + ImGui.Text(description); + ImGui.EndChild(); + } + } + + public static bool Sequencer(SequenceInterface sequence, ref int currentFrame, ref bool expanded, ref int selectedEntry, ref int firstFrame, SEQUENCER_OPTIONS sequenceOptions) + { + var ret = false; + var io = ImGui.GetIO(); + var cx = (int)(io.MousePos.X); + var cy = (int)(io.MousePos.Y); + var legendWidth = 120; + + var deleteAnimationEntry = -1; + var duplicateAnimationEntry = -1; + var insertAnimationEntry = -1; + var ItemHeight = 20; + + var popupOpened = false; + var sequenceCount = sequence.ItemCount; + ImGui.BeginGroup(); + + var draw_list = ImGui.GetWindowDrawList(); + var canvas_pos = ImGui.GetCursorScreenPos(); // ImDrawList API uses screen coordinates! + var canvas_size = ImGui.GetContentRegionAvail(); // Resize canvas to what's available + int firstFrameUsed = firstFrame; + + int controlHeight = sequenceCount * ItemHeight; + for (int i = 0; i < sequenceCount; i++) + controlHeight += sequence.GetCustomHeight(i); + int frameCount = Math.Max(sequence.FrameMax - sequence.FrameMin, 1); + + // ImVector customDraws; + // ImVector compactCustomDraws; + var customDraws = new List(); + var compactCustomDraws = new List(); + // zoom in/out + int visibleFrameCount = (int)Math.Floor((canvas_size.X - legendWidth) / framePixelWidth); + float barWidthRatio = Math.Min(visibleFrameCount / (float)frameCount, 1f); + float barWidthInPixels = barWidthRatio * (canvas_size.X - legendWidth); + + var regionRect = new ImRect(canvas_pos, canvas_pos + canvas_size); + + if (ImGui.IsWindowFocused() && io.KeyAlt && io.MouseDown[2]) + { + if (!panningView) + { + panningViewSource = io.MousePos; + panningView = true; + panningViewFrame = firstFrame; + } + firstFrame = panningViewFrame - (int)((io.MousePos.X - panningViewSource.X) / framePixelWidth); + firstFrame = Math.Clamp(firstFrame, sequence.FrameMin, sequence.FrameMax - visibleFrameCount); + } + if (panningView && !io.MouseDown[2]) + { + panningView = false; + } + framePixelWidthTarget = Math.Clamp(framePixelWidthTarget, 0.1f, 50f); + + framePixelWidth = Lerp(framePixelWidth, framePixelWidthTarget, 0.33f); + + frameCount = sequence.FrameMax - sequence.FrameMin; + if (visibleFrameCount >= frameCount) + firstFrame = sequence.FrameMin; + + + // -- + if (!expanded) + { + ImGui.InvisibleButton("canvas", new Vector2(canvas_size.X - canvas_pos.X, (float)ItemHeight)); + draw_list.AddRectFilled(canvas_pos, new Vector2(canvas_size.X + canvas_pos.X, canvas_pos.Y + ItemHeight), 0xFF3D3837, 0); + + var tmps = $"{frameCount} Frames / {sequenceCount} entries"; + draw_list.AddText(new Vector2(canvas_pos.X + 26, canvas_pos.Y + 2), 0xFFFFFFFF, tmps); + } + else + { + bool hasScrollBar = true; + /* + int framesPixelWidth = int(frameCount * framePixelWidth); + if ((framesPixelWidth + legendWidth) >= canvas_size.X) + { + hasScrollBar = true; + } + */ + // test scroll area + var headerSize = new Vector2(canvas_size.X, (float)ItemHeight); + var scrollBarSize = new Vector2(canvas_size.X, 14f); + ImGui.InvisibleButton("topBar", headerSize); + draw_list.AddRectFilled(canvas_pos, canvas_pos + headerSize, 0xFFFF0000, 0); + Vector2 childFramePos = ImGui.GetCursorScreenPos(); + var childFrameSize = new Vector2(canvas_size.X, canvas_size.Y - 8f - headerSize.Y - (hasScrollBar ? scrollBarSize.Y : 0)); + ImGui.PushStyleColor(ImGuiCol.FrameBg, 0); + ImGui.BeginChildFrame(889, childFrameSize); + sequence.focused = ImGui.IsWindowFocused(); + ImGui.InvisibleButton("contentBar", new Vector2(canvas_size.X, (float)(controlHeight))); + Vector2 contentMin = ImGui.GetItemRectMin(); + Vector2 contentMax = ImGui.GetItemRectMax(); + var contentRect = new ImRect(contentMin, contentMax); + float contentHeight = contentMax.Y - contentMin.Y; + + // full background + draw_list.AddRectFilled(canvas_pos, canvas_pos + canvas_size, 0xFF242424, 0); + + // current frame top + var topRect = new ImRect(new Vector2(canvas_pos.X + legendWidth, canvas_pos.Y), new Vector2(canvas_pos.X + canvas_size.X, canvas_pos.Y + ItemHeight)); + + if (!MovingCurrentFrame && !MovingScrollBar && movingEntry == -1 && sequenceOptions.HasFlag(SEQUENCER_OPTIONS.SEQUENCER_CHANGE_FRAME) && currentFrame >= 0 && topRect.Contains(io.MousePos) && io.MouseDown[0]) + { + MovingCurrentFrame = true; + } + if (MovingCurrentFrame) + { + if (true) + { + currentFrame = (int)((io.MousePos.X - topRect.Min.X) / framePixelWidth) + firstFrameUsed; + if (currentFrame < sequence.FrameMin) + currentFrame = sequence.FrameMin; + if (currentFrame >= sequence.FrameMax) + currentFrame = sequence.FrameMax; + } + if (!io.MouseDown[0]) + MovingCurrentFrame = false; + } + + // Draw header controls on the left + draw_list.AddRectFilled(canvas_pos, new Vector2(canvas_size.X + canvas_pos.X, canvas_pos.Y + ItemHeight), 0xFF3D3837, 0); + if (sequenceOptions.HasFlag(SEQUENCER_OPTIONS.SEQUENCER_ADD)) + { + const uint PauseColor = 0xFFf1c40f; + const uint LoopColor = 0xFF0fc4f1; + + var nextButtonPosition = new Vector2(canvas_pos.X + legendWidth - ItemHeight, canvas_pos.Y + 2); + if (SequencerButton(draw_list, nextButtonPosition, 'P', sequence.IsPaused, PauseColor)) + { + Tooltip(sequence.IsPaused ? "Resume" : "Pause"); + if (io.MouseReleased[0]) + sequence.IsPaused = !sequence.IsPaused; + } + + nextButtonPosition.X -= ButtonDistance; + if (SequencerButton(draw_list, nextButtonPosition, 'L', sequence.ForceLoop, LoopColor)) + { + Tooltip("Force loop"); + if (io.MouseReleased[0]) + sequence.ForceLoop = !sequence.ForceLoop; + } + + nextButtonPosition.X -= ButtonDistance; + if (SequencerButton(draw_list, nextButtonPosition, 'A', false, ColorWhite)) + { + Tooltip("Add new animation"); + if (io.MouseReleased[0]) + insertAnimationEntry = sequence.ItemCount; + } + } + + //header frame number and lines + const int MinimumDistanceBetweenElements = 100; + int modFrameCount = 5; // after how many frames should print the frame number + int frameStep = 1; + while ((modFrameCount * framePixelWidth) < MinimumDistanceBetweenElements) + { + modFrameCount *= 2; + frameStep *= 2; + }; + + int halfModFrameCount = modFrameCount / 2; + + Action drawLine = (int i, int regionHeight) => + { + const uint TextColor = 0xFFBBBBBB; + + bool baseIndex = ((i % modFrameCount) == 0) || (i == sequence.FrameMax || i == sequence.FrameMin); + bool halfIndex = (i % halfModFrameCount) == 0; + int px = (int)canvas_pos.X + (int)(i * framePixelWidth) + legendWidth - (int)(firstFrameUsed * framePixelWidth); + int tiretStart = baseIndex ? 4 : (halfIndex ? 10 : 14); + int tiretEnd = baseIndex ? regionHeight : ItemHeight; + + if (px <= (canvas_size.X + canvas_pos.X) && px >= (canvas_pos.X + legendWidth)) + { + draw_list.AddLine(new Vector2((float)px, canvas_pos.Y + (float)tiretStart), new Vector2((float)px, canvas_pos.Y + (float)tiretEnd - 1), 0xFF606060, 1); + draw_list.AddLine(new Vector2((float)px, canvas_pos.Y + (float)ItemHeight), new Vector2((float)px, canvas_pos.Y + (float)regionHeight - 1), 0x30606060, 1); + } + + if (baseIndex && px >= (canvas_pos.X + legendWidth)) + draw_list.AddText(new Vector2((float)px + 3f, canvas_pos.Y), TextColor, $"{i}"); + }; + + for (int i = sequence.FrameMin; i <= sequence.FrameMax; i += frameStep) + { + drawLine(i, ItemHeight); + } + drawLine(sequence.FrameMin, ItemHeight); + drawLine(sequence.FrameMax, ItemHeight); + /* + draw_list.AddLine(canvas_pos, new Vector2(canvas_pos.X, canvas_pos.Y + controlHeight), 0xFF000000, 1); + draw_list.AddLine(new Vector2(canvas_pos.X, canvas_pos.Y + ItemHeight), new Vector2(canvas_size.X, canvas_pos.Y + ItemHeight), 0xFF000000, 1); + */ + + // clip content + draw_list.PushClipRect(childFramePos, childFramePos + childFrameSize); + + // draw item names in the legend rect on the left + for (int i = 0, customHeight = 0; i < sequenceCount; i++) + { + var animation = sequence.GetAnimation(i); + var tPos = new Vector2(contentMin.X + 3, contentMin.Y + i * ItemHeight + 2 + customHeight); + var tEndPos = new Vector2(contentMin.X + 3 + legendWidth, contentMin.Y + (i + 1) * ItemHeight + 2 + customHeight); + var canMouseClickOnRow = new ImRect(tPos, tEndPos).Contains(io.MousePos) && + io.MousePos.Y > childFramePos.Y && io.MousePos.Y <= childFramePos.Y + childFrameSize.Y && + ImGui.IsWindowFocused(); + if (canMouseClickOnRow && io.MouseDown[0] && ImGui.IsWindowHovered()) + selectedEntry = i; + + draw_list.AddText(tPos, 0xFFFFFFFF, animation.Name ?? $"#{i + 1}"); + + if (sequenceOptions.HasFlag(SEQUENCER_OPTIONS.SEQUENCER_DEL)) + { + var isAnimationVisible = sequence.IsVisible(i); + var buttonPos = new Vector2(contentMin.X + legendWidth - ButtonDistance + 2 - 10, tPos.Y + 2); + if (SequencerButton(draw_list, buttonPos, 'H', !isAnimationVisible, 0xff15208f) && canMouseClickOnRow) + { + Tooltip("Hide animation"); + if (io.MouseReleased[0]) + sequence.SetVisibility(i, !isAnimationVisible); + } + + var isFocused = sequence.IsFocus(i); + buttonPos.X -= ButtonDistance; + if (SequencerButton(draw_list, buttonPos, 'S', isFocused, 0xff69992f) && canMouseClickOnRow) + { + Tooltip("Display only this animation"); + if (io.MouseReleased[0]) + { + if (isFocused) + sequence.ResetFocus(); + else + sequence.SetFocus(i); + } + } + + buttonPos.X -= ButtonDistance; + if (SequencerButton(draw_list, buttonPos, 'D', false, ColorWhite) && canMouseClickOnRow) + { + Tooltip("Duplicate animation"); + if (io.MouseReleased[0]) + duplicateAnimationEntry = i; + } + + buttonPos.X -= ButtonDistance; + if (SequencerButton(draw_list, buttonPos, 'R', false, ColorWhite) && canMouseClickOnRow) + { + Tooltip("Remove animation"); + if (io.MouseReleased[0]) + deleteAnimationEntry = i; + } + } + customHeight += sequence.GetCustomHeight(i); + } + + // clipping rect so items bars are not visible in the legend on the left when scrolled + // + + // slots background + for (int i = 0, customHeight = 0; i < sequenceCount; i++) + { + // Draw as a zebra background + uint col = (i & 1) != 0 ? 0xFF3A3636 : 0xFF413D3D; + + var localCustomHeight = sequence.GetCustomHeight(i); + Vector2 pos = new Vector2(contentMin.X + legendWidth, contentMin.Y + ItemHeight * i + 1 + customHeight); + Vector2 sz = new Vector2(canvas_size.X + canvas_pos.X, pos.Y + ItemHeight - 1 + localCustomHeight); + if (!popupOpened && cy >= pos.Y && cy < pos.Y + (ItemHeight + localCustomHeight) && movingEntry == -1 && cx > contentMin.X && cx < contentMin.X + canvas_size.X) + { + col += 0x80201008; + pos.X -= legendWidth; + } + draw_list.AddRectFilled(pos, sz, col, 0); + customHeight += localCustomHeight; + } + + draw_list.PushClipRect(childFramePos + new Vector2((float)(legendWidth), 0f), childFramePos + childFrameSize); + + // vertical frame lines in content area + Action drawLineContent = (int i, int regionHeight) => + { + int px = (int)canvas_pos.X + (int)(i * framePixelWidth) + legendWidth - (int)(firstFrameUsed * framePixelWidth); + int tiretStart = (int)(contentMin.Y); + int tiretEnd = (int)(contentMax.Y); + + if (px <= (canvas_size.X + canvas_pos.X) && px >= (canvas_pos.X + legendWidth)) + { + //draw_list.AddLine(new Vector2((float)px, canvas_pos.Y + (float)tiretStart), new Vector2((float)px, canvas_pos.Y + (float)tiretEnd - 1), 0xFF606060, 1); + + draw_list.AddLine(new Vector2((float)(px), (float)(tiretStart)), new Vector2((float)(px), (float)(tiretEnd)), 0x30606060, 1); + } + }; + for (int i = sequence.FrameMin; i <= sequence.FrameMax; i += frameStep) + { + drawLineContent(i, (int)(contentHeight)); + } + drawLineContent(sequence.FrameMin, (int)(contentHeight)); + drawLineContent(sequence.FrameMax, (int)(contentHeight)); + + // selection + bool selected = (selectedEntry >= 0); + if (selected) + { + // draw background differently if selected + var customHeight = 0; + for (int i = 0; i < selectedEntry; i++) + customHeight += sequence.GetCustomHeight(i); + ; + draw_list.AddRectFilled( + new Vector2(contentMin.X, contentMin.Y + ItemHeight * selectedEntry + customHeight), + new Vector2(contentMin.X + canvas_size.X, contentMin.Y + ItemHeight * (selectedEntry + 1) + customHeight), + 0x801080FF, 1f); + } + + // slots + for (int i = 0, customHeight = 0; i < sequenceCount; i++) + { + var animation = sequence.GetAnimation(i); + var localCustomHeight = sequence.GetCustomHeight(i); + + Vector2 pos = new Vector2(contentMin.X + legendWidth - firstFrameUsed * framePixelWidth, contentMin.Y + ItemHeight * i + 1 + customHeight); + var slotP1 = new Vector2(pos.X + animation.FrameStart * framePixelWidth, pos.Y + 2); + var slotP2 = new Vector2(pos.X + animation.FrameEnd * framePixelWidth + framePixelWidth, pos.Y + ItemHeight - 2); + var slotP3 = new Vector2(pos.X + animation.FrameEnd * framePixelWidth + framePixelWidth, pos.Y + ItemHeight - 2 + localCustomHeight); + uint slotColor = animation.Color | 0xFF000000; + uint slotColorHalf = (animation.Color & 0xFFFFFF) | 0x40000000; + + if (slotP1.X <= (canvas_size.X + contentMin.X) && slotP2.X >= (contentMin.X + legendWidth)) + { + draw_list.AddRectFilled(slotP1, slotP3, slotColorHalf, 2); + draw_list.AddRectFilled(slotP1, slotP2, slotColor, 2); + } + if (new ImRect(slotP1, slotP2).Contains(io.MousePos) && io.MouseDoubleClicked[0]) + { + sequence.DoubleClick(i); + } + + var rects = new ImRect[] + { + new ImRect(slotP1, new Vector2(slotP1.X + AnimationBarSideSelectionWidth, slotP2.Y)), + new ImRect(new Vector2(slotP2.X - AnimationBarSideSelectionWidth, slotP1.Y), slotP2), + new ImRect(slotP1, slotP2) + }; + + var quadColor = new uint[] { 0xFFFFFFFF, 0xFFFFFFFF, slotColor + (selected ? 0u : 0x202020u) }; + if (movingEntry == -1 && (sequenceOptions.HasFlag(SEQUENCER_OPTIONS.SEQUENCER_EDIT_STARTEND))) // TODOFOCUS && backgroundRect.Contains(io.MousePos)) + { + const uint AnimationResizeHoverColor = 0xFFFFFFFFu; + uint AnimationBarHoverColor = slotColor + 0x202020; + + var animBarLeftRect = new ImRect(slotP1, new Vector2(slotP1.X + AnimationBarSideSelectionWidth, slotP2.Y)); + var animBarRightRect = new ImRect(new Vector2(slotP2.X - AnimationBarSideSelectionWidth, slotP1.Y), slotP2); + var animBarRect = new ImRect(slotP1, slotP2); + + var animationBarPartSelection = AnimationBarPart.None; + if (animBarLeftRect.Contains(io.MousePos)) + { + animationBarPartSelection = AnimationBarPart.SelectionLeft; + draw_list.AddRectFilled(animBarLeftRect.Min, animBarLeftRect.Max, AnimationResizeHoverColor, 2); + } + else if (animBarRightRect.Contains(io.MousePos)) + { + animationBarPartSelection = AnimationBarPart.SelectionRight; + draw_list.AddRectFilled(animBarRightRect.Min, animBarRightRect.Max, AnimationResizeHoverColor, 2); + } + else if (animBarRect.Contains(io.MousePos)) + { + animationBarPartSelection = AnimationBarPart.Bar; + draw_list.AddRectFilled(animBarRect.Min, animBarRect.Max, AnimationBarHoverColor, 2); + } + + if (ImGui.IsMouseClicked(0) && animationBarPartSelection != AnimationBarPart.None) + { + if (!new ImRect(childFramePos, childFramePos + childFrameSize).Contains(io.MousePos)) + continue; + + if (!MovingScrollBar && !MovingCurrentFrame) + { + movingEntry = i; + movingPos = cx; + movingPart = animationBarPartSelection; + sequence.BeginEdit(movingEntry); + break; + } + } + } + + // custom draw + if (localCustomHeight > 0) + { + var rp = new Vector2(canvas_pos.X, contentMin.Y + ItemHeight * i + 1 + customHeight); + var customRect = new ImRect(rp + new Vector2(legendWidth - (firstFrameUsed - sequence.FrameMin - 0.5f) * framePixelWidth, (float)(ItemHeight)), + rp + new Vector2(legendWidth + (sequence.FrameMax - firstFrameUsed - 0.5f + 2f) * framePixelWidth, (float)(localCustomHeight + ItemHeight))); + var clippingRect = new ImRect(rp + new Vector2((float)(legendWidth), (float)(ItemHeight)), rp + new Vector2(canvas_size.X, (float)(localCustomHeight + ItemHeight))); + + var legendRect = new ImRect(rp + new Vector2(0f, (float)(ItemHeight)), rp + new Vector2((float)(legendWidth), (float)(localCustomHeight))); + var legendClippingRect = new ImRect(canvas_pos + new Vector2(0f, (float)(ItemHeight)), canvas_pos + new Vector2((float)(legendWidth), (float)(localCustomHeight + ItemHeight))); + customDraws.Add(new CustomDraw + { + index = i, + customRect = customRect, + legendRect = legendRect, + clippingRect = clippingRect, + legendClippingRect = legendClippingRect + }); + } + else + { + var rp = new Vector2(canvas_pos.X, contentMin.Y + ItemHeight * i + customHeight); + var customRect = new ImRect(rp + new Vector2(legendWidth - (firstFrameUsed - sequence.FrameMin - 0.5f) * framePixelWidth, (float)(0f)), + rp + new Vector2(legendWidth + (sequence.FrameMax - firstFrameUsed - 0.5f + 2f) * framePixelWidth, (float)(ItemHeight))); + var clippingRect = new ImRect(rp + new Vector2((float)(legendWidth), (float)(0f)), rp + new Vector2(canvas_size.X, (float)(ItemHeight))); + + compactCustomDraws.Add(new CustomDraw + { + index = i, + customRect = customRect, + legendRect = new ImRect(), + clippingRect = clippingRect, + legendClippingRect = new ImRect() + }); + } + customHeight += localCustomHeight; + } + + + // moving + if (/*backgroundRect.Contains(io.MousePos) && */movingEntry >= 0) + { + ImGui.CaptureMouseFromApp(); + int diffFrame = (int)((cx - movingPos) / framePixelWidth); + if (Math.Abs(diffFrame) > 0) + { + var animation = sequence.GetAnimation(movingEntry); + selectedEntry = movingEntry; + if (movingPart.HasFlag(AnimationBarPart.SelectionLeft)) + animation.FrameStart += diffFrame; + if (movingPart.HasFlag(AnimationBarPart.SelectionRight)) + animation.FrameEnd += diffFrame; + if (animation.FrameStart < 0) + { + if (movingPart.HasFlag(AnimationBarPart.SelectionRight)) + animation.FrameEnd -= animation.FrameStart; + animation.FrameStart = 0; + } + if (movingPart.HasFlag(AnimationBarPart.SelectionLeft) && animation.FrameStart > animation.FrameEnd) + animation.FrameStart = animation.FrameEnd; + if (movingPart.HasFlag(AnimationBarPart.SelectionRight) && animation.FrameEnd < animation.FrameStart) + animation.FrameEnd = animation.FrameStart; + movingPos += (int)(diffFrame * framePixelWidth); + } + if (!io.MouseDown[0]) + { + // single select + if (/*diffFrame != 0 &&*/ movingPart != 0) + { + selectedEntry = movingEntry; + ret = true; + } + + movingEntry = -1; + sequence.EndEdit(); + } + } + + // cursor + if (currentFrame >= firstFrame && currentFrame <= sequence.FrameMax) + { + const float cursorWidth = 8f; + float cursorOffset = contentMin.X + legendWidth + (currentFrame - firstFrameUsed) * framePixelWidth + framePixelWidth / 2 - cursorWidth * 0.5f; + draw_list.AddLine(new Vector2(cursorOffset, canvas_pos.Y), new Vector2(cursorOffset, contentMax.Y), 0xA02A2AFF, cursorWidth); + draw_list.AddText(new Vector2(cursorOffset + 10, canvas_pos.Y + 2), 0xFF2A2AFF, $"{currentFrame}"); + } + + draw_list.PopClipRect(); + draw_list.PopClipRect(); + + foreach (var customDraw in customDraws) + sequence.CustomDraw(customDraw.index, draw_list, customDraw.customRect, customDraw.legendRect, customDraw.clippingRect, customDraw.legendClippingRect); + foreach (var customDraw in compactCustomDraws) + sequence.CustomDrawCompact(customDraw.index, draw_list, customDraw.customRect, customDraw.clippingRect); + + // copy paste + if (sequenceOptions.HasFlag(SEQUENCER_OPTIONS.SEQUENCER_COPYPASTE)) + { + var rectCopy = new ImRect(new Vector2(contentMin.X + 100, canvas_pos.Y + 2) + , new Vector2(contentMin.X + 100 + 30, canvas_pos.Y + ItemHeight - 2)); + bool inRectCopy = rectCopy.Contains(io.MousePos); + uint copyColor = inRectCopy ? 0xFF1080FF : 0xFF000000; + draw_list.AddText(rectCopy.Min, copyColor, "Copy"); + + var rectPaste = new ImRect(new Vector2(contentMin.X + 140, canvas_pos.Y + 2) + , new Vector2(contentMin.X + 140 + 30, canvas_pos.Y + ItemHeight - 2)); + bool inRectPaste = rectPaste.Contains(io.MousePos); + uint pasteColor = inRectPaste ? 0xFF1080FF : 0xFF000000; + draw_list.AddText(rectPaste.Min, pasteColor, "Paste"); + + if (inRectCopy && io.MouseReleased[0]) + { + sequence.Copy(); + } + if (inRectPaste && io.MouseReleased[0]) + { + sequence.Paste(); + } + } + // + + ImGui.EndChildFrame(); + ImGui.PopStyleColor(); + if (hasScrollBar) + { + ImGui.InvisibleButton("scrollBar", scrollBarSize); + Vector2 scrollBarMin = ImGui.GetItemRectMin(); + Vector2 scrollBarMax = ImGui.GetItemRectMax(); + + // ratio = number of frames visible in control / number to total frames + + float startFrameOffset = ((float)(firstFrameUsed - sequence.FrameMin) / (float)frameCount) * (canvas_size.X - legendWidth); + var scrollBarA = new Vector2(scrollBarMin.X + legendWidth, scrollBarMin.Y - 2); + var scrollBarB = new Vector2(scrollBarMin.X + canvas_size.X, scrollBarMax.Y - 1); + draw_list.AddRectFilled(scrollBarA, scrollBarB, 0xFF222222, 0); + + var scrollBarRect = new ImRect(scrollBarA, scrollBarB); + bool inScrollBar = scrollBarRect.Contains(io.MousePos); + + draw_list.AddRectFilled(scrollBarA, scrollBarB, 0xFF101010, 8); + + + var scrollBarC = new Vector2(scrollBarMin.X + legendWidth + startFrameOffset, scrollBarMin.Y); + var scrollBarD = new Vector2(scrollBarMin.X + legendWidth + barWidthInPixels + startFrameOffset, scrollBarMax.Y - 2); + draw_list.AddRectFilled(scrollBarC, scrollBarD, (inScrollBar || MovingScrollBar) ? 0xFF606060 : 0xFF505050, 6); + + float handleRadius = (scrollBarMax.Y - scrollBarMin.Y) / 2; + var barHandleLeft = new ImRect(scrollBarC, new Vector2(scrollBarC.X + 14, scrollBarD.Y)); + var barHandleRight = new ImRect(new Vector2(scrollBarD.X - 14, scrollBarC.Y), scrollBarD); + + bool onLeft = barHandleLeft.Contains(io.MousePos); + bool onRight = barHandleRight.Contains(io.MousePos); + + + draw_list.AddRectFilled(barHandleLeft.Min, barHandleLeft.Max, (onLeft || sizingLBar) ? 0xFFAAAAAA : 0xFF666666, 6); + draw_list.AddRectFilled(barHandleRight.Min, barHandleRight.Max, (onRight || sizingRBar) ? 0xFFAAAAAA : 0xFF666666, 6); + + var scrollBarThumb = new ImRect(scrollBarC, scrollBarD); + if (sizingRBar) + { + if (!io.MouseDown[0]) + { + sizingRBar = false; + } + else + { + // Resize scrollbar from the right + float barNewWidth = Math.Max(barWidthInPixels + io.MouseDelta.X, MinBarWidth); + float barRatio = barNewWidth / barWidthInPixels; + framePixelWidthTarget = framePixelWidth = framePixelWidth / barRatio; + int newVisibleFrameCount = (int)((canvas_size.X - legendWidth) / framePixelWidthTarget); + int lastFrame = firstFrame + newVisibleFrameCount; + if (lastFrame > sequence.FrameMax) + { + framePixelWidthTarget = framePixelWidth = (canvas_size.X - legendWidth) / (float)(sequence.FrameMax - firstFrame); + } + } + } + else if (sizingLBar) + { + if (!io.MouseDown[0]) + { + sizingLBar = false; + } + else + { + // Resize scrollbar from the left + if (Math.Abs(io.MouseDelta.X) > FLT_EPSILON) + { + float barNewWidth = Math.Max(barWidthInPixels - io.MouseDelta.X, MinBarWidth); + float barRatio = barNewWidth / barWidthInPixels; + float previousFramePixelWidthTarget = framePixelWidthTarget; + framePixelWidthTarget = framePixelWidth = framePixelWidth / barRatio; + int newVisibleFrameCount = (int)(visibleFrameCount / barRatio); + int newFirstFrame = firstFrame + newVisibleFrameCount - visibleFrameCount; + newFirstFrame = Math.Clamp(newFirstFrame, sequence.FrameMin, Math.Max(sequence.FrameMax - visibleFrameCount, sequence.FrameMin)); + if (newFirstFrame == firstFrame) + { + framePixelWidth = framePixelWidthTarget = previousFramePixelWidthTarget; + } + else + { + firstFrame = newFirstFrame; + } + } + } + } + else + { + if (MovingScrollBar) + { + if (!io.MouseDown[0]) + { + MovingScrollBar = false; + } + else + { + float framesPerPixelInBar = barWidthInPixels / (float)visibleFrameCount; + firstFrame = (int)((io.MousePos.X - panningViewSource.X) / framesPerPixelInBar) - panningViewFrame; + firstFrame = Math.Clamp(firstFrame, sequence.FrameMin, Math.Max(sequence.FrameMax - visibleFrameCount, sequence.FrameMin)); + } + } + else + { + if (scrollBarThumb.Contains(io.MousePos) && ImGui.IsMouseClicked(0) && !MovingCurrentFrame && movingEntry == -1) + { + MovingScrollBar = true; + panningViewSource = io.MousePos; + panningViewFrame = firstFrame; + } + if (!sizingRBar && onRight && ImGui.IsMouseClicked(0)) + sizingRBar = true; + if (!sizingLBar && onLeft && ImGui.IsMouseClicked(0)) + sizingLBar = true; + + } + } + } + } + + ImGui.EndGroup(); + + if (regionRect.Contains(io.MousePos)) + { + bool overCustomDraw = false; + foreach (var custom in customDraws) + { + if (custom.customRect.Contains(io.MousePos)) + { + overCustomDraw = true; + } + } + if (overCustomDraw) + { + } + else + { + //frameOverCursor = *firstFrame + (int)(visibleFrameCount * ((io.MousePos.X - (float)legendWidth - canvas_pos.X) / (canvas_size.X - legendWidth))); + ////frameOverCursor = max(min(*firstFrame - visibleFrameCount / 2, frameCount - visibleFrameCount), 0); + + ///**firstFrame -= frameOverCursor; + //*firstFrame *= framePixelWidthTarget / framePixelWidth; + //*firstFrame += frameOverCursor;*/ + //if (io.MouseWheel < -FLT_EPSILON) + //{ + // *firstFrame -= frameOverCursor; + // *firstFrame = int(*firstFrame * 1.1f); + // framePixelWidthTarget *= 0.9f; + // *firstFrame += frameOverCursor; + //} + + //if (io.MouseWheel > FLT_EPSILON) + //{ + // *firstFrame -= frameOverCursor; + // *firstFrame = int(*firstFrame * 0.9f); + // framePixelWidthTarget *= 1.1f; + // *firstFrame += frameOverCursor; + //} + } + } + + if (expanded) + { + bool overExpanded = SequencerAddDelButton(draw_list, new Vector2(canvas_pos.X + 2, canvas_pos.Y + 2), !expanded); + if (overExpanded && io.MouseReleased[0]) + expanded = !expanded; + } + + if (deleteAnimationEntry >= 0) + { + sequence.RemoveAnimation(deleteAnimationEntry); + if ((selectedEntry == deleteAnimationEntry || selectedEntry >= sequence.ItemCount)) + selectedEntry = -1; + } + + if (duplicateAnimationEntry >= 0) + { + sequence.DuplicateAnimation(duplicateAnimationEntry); + } + + if (insertAnimationEntry >= 0) + { + sequence.AddAnimation(); + } + + return ret; + } + } +} diff --git a/OpenKh.Tools.LayoutEditor/Controls/MySequencer.cs b/OpenKh.Tools.LayoutEditor/Controls/MySequencer.cs index 5865f9ef2..016c3d7c6 100644 --- a/OpenKh.Tools.LayoutEditor/Controls/MySequencer.cs +++ b/OpenKh.Tools.LayoutEditor/Controls/MySequencer.cs @@ -1,211 +1,211 @@ -using ImGuiNET; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Tools.LayoutEditor.Controls -{ - class MySequencer : ImSequencer.SequenceInterface - { - static uint[] ColorType = new uint[] - { - 0xfff09124, 0xffdebd00, 0xff85cf44, 0xff4cc25f, - 0xff35ab84, 0xff25b3b8, 0xff4c9ef5, 0xff8282f5, - 0xffa874e8, 0xffdc57eb, 0xffeb5bad, - 0xff2491f0, 0xff00bdde, 0xff44cf85, 0xff5fc24c, - 0xff84ab35, 0xffb8b325, 0xfff59e4c, 0xfff58282, - 0xffe874a8, 0xffeb57dc, 0xffad5beb, - }; - - private class MySequenceItem : ImSequencer.IAnimation - { - private readonly Sequence.Animation _animation; - - public int FrameStart { get => _animation.FrameStart; set => _animation.FrameStart = value; } - public int FrameEnd { get => _animation.FrameEnd; set => _animation.FrameEnd = value; } - public bool IsExpanded { get; set; } - public string Name { get; set; } - public uint Color => ColorType[Type % ColorType.Length]; - public int Height => IsExpanded ? 300 : 0; - public int Type { get; set; } - - public MySequenceItem() : this(new Sequence.Animation()) - { } - - public MySequenceItem(Sequence.Animation animation) - { - _animation = animation; - } - }; - - private readonly Sequence _sequence; - private readonly DebugSequenceRenderer _debugSequenceRenderer; - private int _selectedAnimationGroup; - - private Sequence.AnimationGroup SelectedAnimationGroup => - _sequence.AnimationGroups[_selectedAnimationGroup]; - - public int SelectedAnimationGroupIndex - { - get => _selectedAnimationGroup; - set - { - _selectedAnimationGroup = value; - InvalidateAnimationList(); - } - } - - public int FrameMin { get; set; } - public int FrameMax { get; set; } - public int ItemCount => _animationList.Count; - public bool IsPaused { get; set; } - public bool ForceLoop { get; set; } - - public int GetItemTypeCount() => ColorType.Length; - public string GetItemTypeName(int typeIndex) => $"type {typeIndex}"; - - public ImSequencer.IAnimation GetAnimation(int index) - { - if (index >= 0 && index < _animationList.Count) - return _animationList[index]; - - return null; - } - - public void AddAnimation() - { - SelectedAnimationGroup.Animations.Add(new Sequence.Animation - { - FrameStart = 0, - FrameEnd = 50, - ScaleStart = 1, - ScaleEnd = 1, - ScaleXStart = 1, - ScaleXEnd = 1, - ScaleYStart = 1, - ScaleYEnd = 1, - ColorStart = 0x80808080u, - ColorEnd = 0x80808080u, - }); - InvalidateAnimationList(); - } - - public void RemoveAnimation(int index) - { - SelectedAnimationGroup.Animations.RemoveAt(index); - InvalidateAnimationList(); - } - - public void DuplicateAnimation(int index) - { - SelectedAnimationGroup.Animations.Add(SelectedAnimationGroup.Animations[index].Clone()); - InvalidateAnimationList(); - } - - public bool IsFocus(int index) => _debugSequenceRenderer.FocusOnAnimation == index; - public void SetFocus(int index) => _debugSequenceRenderer.FocusOnAnimation = index; - public void ResetFocus() => _debugSequenceRenderer.FocusOnAnimation = -1; - - public bool IsVisible(int index) => _debugSequenceRenderer.IsAnimationVisible(index); - public void SetVisibility(int index, bool isVisible) => _debugSequenceRenderer.ShowAnimation(index, isVisible); - - public int GetCustomHeight(int index) => _animationList.Skip(index).FirstOrDefault()?.Height ?? 0; - - public MySequencer(Sequence sequence, DebugSequenceRenderer debugSequenceRenderer) - { - _sequence = sequence; - _debugSequenceRenderer = debugSequenceRenderer; - - FrameMin = 0; - FrameMax = (int)(sequence.AnimationGroups.Max(x => x.GetFrameLength()) * 1.25); - _animationList = new List(); - } - - private List _animationList; - - public bool focused { get; set; } - - //RampEdit rampEdit; - - public void DoubleClick(int index) - { - if (_animationList[index].IsExpanded) - { - _animationList[index].IsExpanded = false; - return; - } - foreach (var item in _animationList) - item.IsExpanded = false; - _animationList[index].IsExpanded = !_animationList[index].IsExpanded; - } - - public void CustomDraw(int index, ImDrawListPtr draw_list, ImRect rc, ImRect legendRect, ImRect clippingRect, ImRect legendClippingRect) - { - var labels = new string[] { "Translation", "Rotation", "Scale" }; - - draw_list.PushClipRect(legendClippingRect.Min, legendClippingRect.Max, true); - //rampEdit.mMax = new Vector2(mFrameMax, 1f); - //rampEdit.mMin = new Vector2(mFrameMin, 0f); - //for (int i = 0; i < 3; i++) - //{ - // var pta = new Vector2(legendRect.Min.X + 30, legendRect.Min.Y + i * 14f); - // var ptb = new Vector2(legendRect.Max.X, legendRect.Min.Y + (i + 1) * 14f); - // draw_list.AddText(pta, rampEdit.mbVisible[i] ? 0xFFFFFFFF : 0x80FFFFFF, labels[i]); - // if (new ImRect(pta, ptb).Contains(ImGui.GetMousePos()) && ImGui.IsMouseClicked(0)) - // rampEdit.mbVisible[i] = !rampEdit.mbVisible[i]; - //} - draw_list.PopClipRect(); - - ImGui.SetCursorScreenPos(rc.Min); - //ImCurveEdit.Edit(rampEdit, rc.Max - rc.Min, 137 + index, clippingRect); - } - - public void CustomDrawCompact(int index, ImDrawListPtr draw_list, ImRect rc, ImRect clippingRect) - { - //rampEdit.mMax = new Vector2(mFrameMax, 1f); - //rampEdit.mMin = new Vector2(mFrameMin, 0f); - draw_list.PushClipRect(clippingRect.Min, clippingRect.Max, true); - //for (int i = 0; i < 3; i++) - //{ - // for (int j = 0; j < rampEdit.mPointCount[i]; j++) - // { - // float p = rampEdit.mPts[i][j].X; - // if (p < myItems[index].mFrameStart || p > myItems[index].mFrameEnd) - // continue; - // float r = (p - mFrameMin) / (float)(mFrameMax - mFrameMin); - // float x = ImSequencer.Lerp(rc.Min.X, rc.Max.X, r); - // draw_list.AddLine(new Vector2(x, rc.Min.Y + 6), new Vector2(x, rc.Max.Y - 4), 0xAA000000, 4.f); - // } - //} - draw_list.PopClipRect(); - } - - public void BeginEdit(int index) - { - } - - public void EndEdit() - { - } - - public void Copy() - { - } - - public void Paste() - { - } - - private void InvalidateAnimationList() - { - _animationList = SelectedAnimationGroup.Animations - .Select((x, index) => new MySequenceItem(x) - { - Type = index - }) - .ToList(); - } - }; -} +using ImGuiNET; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Tools.LayoutEditor.Controls +{ + class MySequencer : ImSequencer.SequenceInterface + { + static uint[] ColorType = new uint[] + { + 0xfff09124, 0xffdebd00, 0xff85cf44, 0xff4cc25f, + 0xff35ab84, 0xff25b3b8, 0xff4c9ef5, 0xff8282f5, + 0xffa874e8, 0xffdc57eb, 0xffeb5bad, + 0xff2491f0, 0xff00bdde, 0xff44cf85, 0xff5fc24c, + 0xff84ab35, 0xffb8b325, 0xfff59e4c, 0xfff58282, + 0xffe874a8, 0xffeb57dc, 0xffad5beb, + }; + + private class MySequenceItem : ImSequencer.IAnimation + { + private readonly Sequence.Animation _animation; + + public int FrameStart { get => _animation.FrameStart; set => _animation.FrameStart = value; } + public int FrameEnd { get => _animation.FrameEnd; set => _animation.FrameEnd = value; } + public bool IsExpanded { get; set; } + public string Name { get; set; } + public uint Color => ColorType[Type % ColorType.Length]; + public int Height => IsExpanded ? 300 : 0; + public int Type { get; set; } + + public MySequenceItem() : this(new Sequence.Animation()) + { } + + public MySequenceItem(Sequence.Animation animation) + { + _animation = animation; + } + }; + + private readonly Sequence _sequence; + private readonly DebugSequenceRenderer _debugSequenceRenderer; + private int _selectedAnimationGroup; + + private Sequence.AnimationGroup SelectedAnimationGroup => + _sequence.AnimationGroups[_selectedAnimationGroup]; + + public int SelectedAnimationGroupIndex + { + get => _selectedAnimationGroup; + set + { + _selectedAnimationGroup = value; + InvalidateAnimationList(); + } + } + + public int FrameMin { get; set; } + public int FrameMax { get; set; } + public int ItemCount => _animationList.Count; + public bool IsPaused { get; set; } + public bool ForceLoop { get; set; } + + public int GetItemTypeCount() => ColorType.Length; + public string GetItemTypeName(int typeIndex) => $"type {typeIndex}"; + + public ImSequencer.IAnimation GetAnimation(int index) + { + if (index >= 0 && index < _animationList.Count) + return _animationList[index]; + + return null; + } + + public void AddAnimation() + { + SelectedAnimationGroup.Animations.Add(new Sequence.Animation + { + FrameStart = 0, + FrameEnd = 50, + ScaleStart = 1, + ScaleEnd = 1, + ScaleXStart = 1, + ScaleXEnd = 1, + ScaleYStart = 1, + ScaleYEnd = 1, + ColorStart = 0x80808080u, + ColorEnd = 0x80808080u, + }); + InvalidateAnimationList(); + } + + public void RemoveAnimation(int index) + { + SelectedAnimationGroup.Animations.RemoveAt(index); + InvalidateAnimationList(); + } + + public void DuplicateAnimation(int index) + { + SelectedAnimationGroup.Animations.Add(SelectedAnimationGroup.Animations[index].Clone()); + InvalidateAnimationList(); + } + + public bool IsFocus(int index) => _debugSequenceRenderer.FocusOnAnimation == index; + public void SetFocus(int index) => _debugSequenceRenderer.FocusOnAnimation = index; + public void ResetFocus() => _debugSequenceRenderer.FocusOnAnimation = -1; + + public bool IsVisible(int index) => _debugSequenceRenderer.IsAnimationVisible(index); + public void SetVisibility(int index, bool isVisible) => _debugSequenceRenderer.ShowAnimation(index, isVisible); + + public int GetCustomHeight(int index) => _animationList.Skip(index).FirstOrDefault()?.Height ?? 0; + + public MySequencer(Sequence sequence, DebugSequenceRenderer debugSequenceRenderer) + { + _sequence = sequence; + _debugSequenceRenderer = debugSequenceRenderer; + + FrameMin = 0; + FrameMax = (int)(sequence.AnimationGroups.Max(x => x.GetFrameLength()) * 1.25); + _animationList = new List(); + } + + private List _animationList; + + public bool focused { get; set; } + + //RampEdit rampEdit; + + public void DoubleClick(int index) + { + if (_animationList[index].IsExpanded) + { + _animationList[index].IsExpanded = false; + return; + } + foreach (var item in _animationList) + item.IsExpanded = false; + _animationList[index].IsExpanded = !_animationList[index].IsExpanded; + } + + public void CustomDraw(int index, ImDrawListPtr draw_list, ImRect rc, ImRect legendRect, ImRect clippingRect, ImRect legendClippingRect) + { + var labels = new string[] { "Translation", "Rotation", "Scale" }; + + draw_list.PushClipRect(legendClippingRect.Min, legendClippingRect.Max, true); + //rampEdit.mMax = new Vector2(mFrameMax, 1f); + //rampEdit.mMin = new Vector2(mFrameMin, 0f); + //for (int i = 0; i < 3; i++) + //{ + // var pta = new Vector2(legendRect.Min.X + 30, legendRect.Min.Y + i * 14f); + // var ptb = new Vector2(legendRect.Max.X, legendRect.Min.Y + (i + 1) * 14f); + // draw_list.AddText(pta, rampEdit.mbVisible[i] ? 0xFFFFFFFF : 0x80FFFFFF, labels[i]); + // if (new ImRect(pta, ptb).Contains(ImGui.GetMousePos()) && ImGui.IsMouseClicked(0)) + // rampEdit.mbVisible[i] = !rampEdit.mbVisible[i]; + //} + draw_list.PopClipRect(); + + ImGui.SetCursorScreenPos(rc.Min); + //ImCurveEdit.Edit(rampEdit, rc.Max - rc.Min, 137 + index, clippingRect); + } + + public void CustomDrawCompact(int index, ImDrawListPtr draw_list, ImRect rc, ImRect clippingRect) + { + //rampEdit.mMax = new Vector2(mFrameMax, 1f); + //rampEdit.mMin = new Vector2(mFrameMin, 0f); + draw_list.PushClipRect(clippingRect.Min, clippingRect.Max, true); + //for (int i = 0; i < 3; i++) + //{ + // for (int j = 0; j < rampEdit.mPointCount[i]; j++) + // { + // float p = rampEdit.mPts[i][j].X; + // if (p < myItems[index].mFrameStart || p > myItems[index].mFrameEnd) + // continue; + // float r = (p - mFrameMin) / (float)(mFrameMax - mFrameMin); + // float x = ImSequencer.Lerp(rc.Min.X, rc.Max.X, r); + // draw_list.AddLine(new Vector2(x, rc.Min.Y + 6), new Vector2(x, rc.Max.Y - 4), 0xAA000000, 4.f); + // } + //} + draw_list.PopClipRect(); + } + + public void BeginEdit(int index) + { + } + + public void EndEdit() + { + } + + public void Copy() + { + } + + public void Paste() + { + } + + private void InvalidateAnimationList() + { + _animationList = SelectedAnimationGroup.Animations + .Select((x, index) => new MySequenceItem(x) + { + Type = index + }) + .ToList(); + } + }; +} diff --git a/OpenKh.Tools.LayoutEditor/DebugSequenceRenderer.cs b/OpenKh.Tools.LayoutEditor/DebugSequenceRenderer.cs index 8ad4f5770..24bbd9fc6 100644 --- a/OpenKh.Tools.LayoutEditor/DebugSequenceRenderer.cs +++ b/OpenKh.Tools.LayoutEditor/DebugSequenceRenderer.cs @@ -1,85 +1,85 @@ -using OpenKh.Engine.Renders; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; - -namespace OpenKh.Tools.LayoutEditor -{ - public class DebugSequenceRenderer : IDebugSequenceRenderer - { - [Flags] - private enum State - { - Default, - Hidden, - } - - private static readonly ColorF DefaultColor = ColorF.White; - private static readonly ColorF HideColor = new ColorF(0, 0, 0, 0); - private static readonly ColorF[] StateColors = new ColorF[] - { - DefaultColor, - HideColor, - }; - - private Sequence.AnimationGroup _animationGroup; - private State[] _animationStates = new State[0]; - - public int FocusOnAnimation { get; set; } = -1; - - public Sequence.AnimationGroup AnimationGroup - { - get => _animationGroup; - set - { - _animationGroup = value; - _animationStates = new State[_animationGroup.Animations.Count]; - FocusOnAnimation = -1; - } - } - - public bool IsAnimationVisible(int index) => !HasFlag(index, State.Hidden); - - public void ShowAnimation(int index, bool show) - { - if (show) - RemoveFlag(index, State.Hidden); - else - AddFlag(index, State.Hidden); - } - - public ColorF GetAnimationBlendColor(int index) - { - if (index < 0 || index >= _animationStates.Length) - return DefaultColor; - if (FocusOnAnimation < 0) - return StateColors[(int)_animationStates[index]]; - - return FocusOnAnimation == index ? DefaultColor : HideColor; - } - - private bool HasFlag(int index, State flag) - { - if (index < 0 || index >= _animationStates.Length) - return false; - - return _animationStates[index].HasFlag(flag); - } - - private void AddFlag(int index, State flag) - { - if (index < 0 || index >= _animationStates.Length) - return; - - _animationStates[index] |= flag; - } - - private void RemoveFlag(int index, State flag) - { - if (index < 0 || index >= _animationStates.Length) - return; - - _animationStates[index] &= ~flag; - } - } -} +using OpenKh.Engine.Renders; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; + +namespace OpenKh.Tools.LayoutEditor +{ + public class DebugSequenceRenderer : IDebugSequenceRenderer + { + [Flags] + private enum State + { + Default, + Hidden, + } + + private static readonly ColorF DefaultColor = ColorF.White; + private static readonly ColorF HideColor = new ColorF(0, 0, 0, 0); + private static readonly ColorF[] StateColors = new ColorF[] + { + DefaultColor, + HideColor, + }; + + private Sequence.AnimationGroup _animationGroup; + private State[] _animationStates = new State[0]; + + public int FocusOnAnimation { get; set; } = -1; + + public Sequence.AnimationGroup AnimationGroup + { + get => _animationGroup; + set + { + _animationGroup = value; + _animationStates = new State[_animationGroup.Animations.Count]; + FocusOnAnimation = -1; + } + } + + public bool IsAnimationVisible(int index) => !HasFlag(index, State.Hidden); + + public void ShowAnimation(int index, bool show) + { + if (show) + RemoveFlag(index, State.Hidden); + else + AddFlag(index, State.Hidden); + } + + public ColorF GetAnimationBlendColor(int index) + { + if (index < 0 || index >= _animationStates.Length) + return DefaultColor; + if (FocusOnAnimation < 0) + return StateColors[(int)_animationStates[index]]; + + return FocusOnAnimation == index ? DefaultColor : HideColor; + } + + private bool HasFlag(int index, State flag) + { + if (index < 0 || index >= _animationStates.Length) + return false; + + return _animationStates[index].HasFlag(flag); + } + + private void AddFlag(int index, State flag) + { + if (index < 0 || index >= _animationStates.Length) + return; + + _animationStates[index] |= flag; + } + + private void RemoveFlag(int index, State flag) + { + if (index < 0 || index >= _animationStates.Length) + return; + + _animationStates[index] &= ~flag; + } + } +} diff --git a/OpenKh.Tools.LayoutEditor/Dialogs/ResourceSelectionDialog.cs b/OpenKh.Tools.LayoutEditor/Dialogs/ResourceSelectionDialog.cs index 28b8f80e2..ae59323fd 100644 --- a/OpenKh.Tools.LayoutEditor/Dialogs/ResourceSelectionDialog.cs +++ b/OpenKh.Tools.LayoutEditor/Dialogs/ResourceSelectionDialog.cs @@ -1,74 +1,74 @@ -using ImGuiNET; -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Tools.LayoutEditor.Dialogs -{ - public class ResourceSelectionDialog : IDisposable - { - private readonly Bar.Entry[] _animations; - private readonly Bar.Entry[] _textures; - private int _selectedAnimIndex; - private int _selectedTextureIndex; - - public bool HasResourceBeenSelected { get; private set; } - public Bar.Entry SelectedAnimation { get; private set; } - public Bar.Entry SelectedTexture { get; private set; } - - public ResourceSelectionDialog( - IEnumerable entries, - Bar.EntryType animationType, - Bar.EntryType textureType) - { - _animations = entries - .Where(x => x.Type == animationType && x.Index == 0) - .ToArray(); - _textures = entries - .Where(x => x.Type == textureType && x.Index == 0) - .ToArray(); - } - - public void Run() - { - ImGui.Text("The selected file contains multiple elements."); - ImGui.Text("Please choose the appropiate sub-files you want to load."); - - ImGui.Columns(2, "resources", true); - ImGui.Text("Animation"); - for (var i = 0; i < _animations.Length; i++) - { - if (ImGui.Selectable($"{_animations[i].Name}##anm", - _selectedAnimIndex == i, - ImGuiSelectableFlags.DontClosePopups)) - _selectedAnimIndex = i; - } - - ImGui.NextColumn(); - ImGui.Text("Texture"); - for (var i = 0; i < _textures.Length; i++) - { - if (ImGui.Selectable($"{_textures[i].Name}##tex", - _selectedTextureIndex == i, - ImGuiSelectableFlags.DontClosePopups)) - _selectedTextureIndex = i; - } - - ImGui.Columns(1); - ImGui.Separator(); - if (ImGui.Button("Open")) - { - HasResourceBeenSelected = true; - SelectedAnimation = _animations[_selectedAnimIndex]; - SelectedTexture = _textures[_selectedTextureIndex]; - ImGui.CloseCurrentPopup(); - } - } - - public void Dispose() - { - - } - } -} +using ImGuiNET; +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Tools.LayoutEditor.Dialogs +{ + public class ResourceSelectionDialog : IDisposable + { + private readonly Bar.Entry[] _animations; + private readonly Bar.Entry[] _textures; + private int _selectedAnimIndex; + private int _selectedTextureIndex; + + public bool HasResourceBeenSelected { get; private set; } + public Bar.Entry SelectedAnimation { get; private set; } + public Bar.Entry SelectedTexture { get; private set; } + + public ResourceSelectionDialog( + IEnumerable entries, + Bar.EntryType animationType, + Bar.EntryType textureType) + { + _animations = entries + .Where(x => x.Type == animationType && x.Index == 0) + .ToArray(); + _textures = entries + .Where(x => x.Type == textureType && x.Index == 0) + .ToArray(); + } + + public void Run() + { + ImGui.Text("The selected file contains multiple elements."); + ImGui.Text("Please choose the appropiate sub-files you want to load."); + + ImGui.Columns(2, "resources", true); + ImGui.Text("Animation"); + for (var i = 0; i < _animations.Length; i++) + { + if (ImGui.Selectable($"{_animations[i].Name}##anm", + _selectedAnimIndex == i, + ImGuiSelectableFlags.DontClosePopups)) + _selectedAnimIndex = i; + } + + ImGui.NextColumn(); + ImGui.Text("Texture"); + for (var i = 0; i < _textures.Length; i++) + { + if (ImGui.Selectable($"{_textures[i].Name}##tex", + _selectedTextureIndex == i, + ImGuiSelectableFlags.DontClosePopups)) + _selectedTextureIndex = i; + } + + ImGui.Columns(1); + ImGui.Separator(); + if (ImGui.Button("Open")) + { + HasResourceBeenSelected = true; + SelectedAnimation = _animations[_selectedAnimIndex]; + SelectedTexture = _textures[_selectedTextureIndex]; + ImGui.CloseCurrentPopup(); + } + } + + public void Dispose() + { + + } + } +} diff --git a/OpenKh.Tools.LayoutEditor/Dialogs/SpriteEditDialog.cs b/OpenKh.Tools.LayoutEditor/Dialogs/SpriteEditDialog.cs index 67cb1c9d1..896f3dfc2 100644 --- a/OpenKh.Tools.LayoutEditor/Dialogs/SpriteEditDialog.cs +++ b/OpenKh.Tools.LayoutEditor/Dialogs/SpriteEditDialog.cs @@ -1,162 +1,162 @@ -using ImGuiNET; -using OpenKh.Engine.Extensions; -using OpenKh.Engine.Renders; -using OpenKh.Tools.LayoutEditor.Interfaces; -using OpenKh.Tools.LayoutEditor.Models; -using System; -using System.Collections.Generic; -using System.Numerics; - -namespace OpenKh.Tools.LayoutEditor.Dialogs -{ - class SpriteEditDialog : IDisposable - { - private readonly List _spriteModels; - private readonly ISpriteDrawing _spriteDrawing; - private readonly ISpriteTexture _atlasTexture; - private readonly ITextureBinder _textureBinder; - private readonly IEditorSettings _settings; - private readonly ISpriteTexture _cropAtlasTexture; - private readonly IntPtr _cropAtlasTextureId; - - private int _selectedSpriteModel; - private SpriteModel SpriteModel => _spriteModels[_selectedSpriteModel]; - - public SpriteEditDialog( - List spriteModels, - int selectedSpriteModel, - ISpriteDrawing spriteDrawing, - ISpriteTexture atlasTexture, - ITextureBinder textureBinder, - IEditorSettings settings) - { - _spriteModels = spriteModels; - _selectedSpriteModel = selectedSpriteModel; - _spriteDrawing = spriteDrawing; - _atlasTexture = atlasTexture; - _textureBinder = textureBinder; - _settings = settings; - _settings.OnChangeBackground += (o, e) => DrawCropAtlasTexture(); - - _cropAtlasTexture = _spriteDrawing.CreateSpriteTexture(atlasTexture.Width, atlasTexture.Height); - _cropAtlasTextureId = _textureBinder.BindTexture(_cropAtlasTexture); - DrawCropAtlasTexture(); - } - - public void Dispose() - { - if (_cropAtlasTextureId != IntPtr.Zero) - _textureBinder.UnbindTexture(_cropAtlasTextureId); - _cropAtlasTexture?.Dispose(); - } - - public void Run() - { - if (ImGui.InputInt("Selected sprite to edit", ref _selectedSpriteModel)) - { - _selectedSpriteModel = Math.Min(Math.Max(_selectedSpriteModel, 0), _spriteModels.Count - 1); - DrawCropAtlasTexture(); - } - - ImGui.Image(_cropAtlasTextureId, new Vector2(_atlasTexture.Width, _atlasTexture.Height)); - - var source = new int[] - { - SpriteModel.Sprite.Left, SpriteModel.Sprite.Top, - SpriteModel.Sprite.Right, SpriteModel.Sprite.Bottom - }; - - ImGui.Columns(4, "ltrb", false); - bool sourceChanged = ImGui.DragInt("UA", ref source[0]); - ImGui.NextColumn(); - sourceChanged |= ImGui.DragInt("VA", ref source[1]); - ImGui.NextColumn(); - sourceChanged |= ImGui.DragInt("UB", ref source[2]); - ImGui.NextColumn(); - sourceChanged |= ImGui.DragInt("VB", ref source[3]); - if (sourceChanged) - { - SpriteModel.Sprite.Left = source[0]; - SpriteModel.Sprite.Top = source[1]; - SpriteModel.Sprite.Right = source[2]; - SpriteModel.Sprite.Bottom = source[3]; - SpriteModel.SizeChanged(); - DrawCropAtlasTexture(); - } - ImGui.Columns(1); - - var colorTopLeft = Utilities.ConvertColor(SpriteModel.Sprite.ColorLeft); - if (ImGui.ColorEdit4("Top left", ref colorTopLeft)) - SpriteModel.Sprite.ColorLeft = Utilities.ConvertColor(colorTopLeft); - - var colorTopRight = Utilities.ConvertColor(SpriteModel.Sprite.ColorTop); - if (ImGui.ColorEdit4("Top right", ref colorTopRight)) - SpriteModel.Sprite.ColorTop = Utilities.ConvertColor(colorTopRight); - - var colorBottomLeft = Utilities.ConvertColor(SpriteModel.Sprite.ColorRight); - if (ImGui.ColorEdit4("Bottom left", ref colorBottomLeft)) - SpriteModel.Sprite.ColorRight = Utilities.ConvertColor(colorBottomLeft); - - var colorBottomRight = Utilities.ConvertColor(SpriteModel.Sprite.ColorBottom); - if (ImGui.ColorEdit4("Bottom right", ref colorBottomRight)) - SpriteModel.Sprite.ColorBottom = Utilities.ConvertColor(colorBottomRight); - - var uvAnim = new Vector2(SpriteModel.Sprite.UTranslation, SpriteModel.Sprite.VTranslation); - if (ImGui.DragFloat2("UV animation", ref uvAnim, 0.0001f)) - { - SpriteModel.Sprite.UTranslation = uvAnim.X; - SpriteModel.Sprite.VTranslation = uvAnim.Y; - } - - SpriteModel.Draw(0, 0); - ImGui.Image(SpriteModel.TextureId, SuggestSpriteSize()); - } - - private void DrawCropAtlasTexture() - { - var sLeft = SpriteModel.Sprite.Left; - var sTop = SpriteModel.Sprite.Top; - var sRight = SpriteModel.Sprite.Right; - var sBottom = SpriteModel.Sprite.Bottom; - var cropColor = _settings.EditorBackground; - cropColor.A = 0.75f; - var invertedCropColor = new ColorF( - 1f - cropColor.R, 1f - cropColor.G, - 1f - cropColor.G, 1.0f); - - var context = new SpriteDrawingContext() - .SpriteTexture(_atlasTexture) - .ColorDefault() - .SourceLTRB(0, 0, _cropAtlasTexture.Width, _cropAtlasTexture.Height) - .Position(0, 0) - .DestinationSize(_cropAtlasTexture.Width, _cropAtlasTexture.Height); - context.TextureWrapHorizontal(TextureWrapMode.Repeat, 0, _cropAtlasTexture.Width); - context.TextureWrapVertical(TextureWrapMode.Repeat, 0, _cropAtlasTexture.Height); - - _spriteDrawing.DestinationTexture = _cropAtlasTexture; - _spriteDrawing.SetViewport(0, _cropAtlasTexture.Width, 0, _cropAtlasTexture.Height); - _spriteDrawing.Clear(_settings.EditorBackground); - _spriteDrawing.AppendSprite(context); - - _spriteDrawing.FillRectangle(0, 0, _cropAtlasTexture.Width, sTop, cropColor); - _spriteDrawing.FillRectangle(0, sTop, sLeft, sBottom - sTop, cropColor); - _spriteDrawing.FillRectangle(sRight, sTop, _cropAtlasTexture.Width, sBottom - sTop, cropColor); - _spriteDrawing.FillRectangle(0, sBottom, _cropAtlasTexture.Width, _cropAtlasTexture.Height, cropColor); - _spriteDrawing.DrawRectangle(sLeft - 1, sTop - 1, - sRight - sLeft + 2, sBottom - sTop + 2, invertedCropColor); - - _spriteDrawing.Flush(); - _spriteDrawing.DestinationTexture = null; - } - - private Vector2 SuggestSpriteSize() - { - const int MaxZoomLevel = 8; - var zoomLevelX = _atlasTexture.Width / SpriteModel.Width; - var zoomLevelY = _atlasTexture.Height / SpriteModel.Height; - var zoomLevel = Math.Max(1, Math.Min(MaxZoomLevel, Math.Min(zoomLevelX, zoomLevelY))); - - return new Vector2(SpriteModel.Width * zoomLevel, SpriteModel.Height * zoomLevel); - } - } -} +using ImGuiNET; +using OpenKh.Engine.Extensions; +using OpenKh.Engine.Renders; +using OpenKh.Tools.LayoutEditor.Interfaces; +using OpenKh.Tools.LayoutEditor.Models; +using System; +using System.Collections.Generic; +using System.Numerics; + +namespace OpenKh.Tools.LayoutEditor.Dialogs +{ + class SpriteEditDialog : IDisposable + { + private readonly List _spriteModels; + private readonly ISpriteDrawing _spriteDrawing; + private readonly ISpriteTexture _atlasTexture; + private readonly ITextureBinder _textureBinder; + private readonly IEditorSettings _settings; + private readonly ISpriteTexture _cropAtlasTexture; + private readonly IntPtr _cropAtlasTextureId; + + private int _selectedSpriteModel; + private SpriteModel SpriteModel => _spriteModels[_selectedSpriteModel]; + + public SpriteEditDialog( + List spriteModels, + int selectedSpriteModel, + ISpriteDrawing spriteDrawing, + ISpriteTexture atlasTexture, + ITextureBinder textureBinder, + IEditorSettings settings) + { + _spriteModels = spriteModels; + _selectedSpriteModel = selectedSpriteModel; + _spriteDrawing = spriteDrawing; + _atlasTexture = atlasTexture; + _textureBinder = textureBinder; + _settings = settings; + _settings.OnChangeBackground += (o, e) => DrawCropAtlasTexture(); + + _cropAtlasTexture = _spriteDrawing.CreateSpriteTexture(atlasTexture.Width, atlasTexture.Height); + _cropAtlasTextureId = _textureBinder.BindTexture(_cropAtlasTexture); + DrawCropAtlasTexture(); + } + + public void Dispose() + { + if (_cropAtlasTextureId != IntPtr.Zero) + _textureBinder.UnbindTexture(_cropAtlasTextureId); + _cropAtlasTexture?.Dispose(); + } + + public void Run() + { + if (ImGui.InputInt("Selected sprite to edit", ref _selectedSpriteModel)) + { + _selectedSpriteModel = Math.Min(Math.Max(_selectedSpriteModel, 0), _spriteModels.Count - 1); + DrawCropAtlasTexture(); + } + + ImGui.Image(_cropAtlasTextureId, new Vector2(_atlasTexture.Width, _atlasTexture.Height)); + + var source = new int[] + { + SpriteModel.Sprite.Left, SpriteModel.Sprite.Top, + SpriteModel.Sprite.Right, SpriteModel.Sprite.Bottom + }; + + ImGui.Columns(4, "ltrb", false); + bool sourceChanged = ImGui.DragInt("UA", ref source[0]); + ImGui.NextColumn(); + sourceChanged |= ImGui.DragInt("VA", ref source[1]); + ImGui.NextColumn(); + sourceChanged |= ImGui.DragInt("UB", ref source[2]); + ImGui.NextColumn(); + sourceChanged |= ImGui.DragInt("VB", ref source[3]); + if (sourceChanged) + { + SpriteModel.Sprite.Left = source[0]; + SpriteModel.Sprite.Top = source[1]; + SpriteModel.Sprite.Right = source[2]; + SpriteModel.Sprite.Bottom = source[3]; + SpriteModel.SizeChanged(); + DrawCropAtlasTexture(); + } + ImGui.Columns(1); + + var colorTopLeft = Utilities.ConvertColor(SpriteModel.Sprite.ColorLeft); + if (ImGui.ColorEdit4("Top left", ref colorTopLeft)) + SpriteModel.Sprite.ColorLeft = Utilities.ConvertColor(colorTopLeft); + + var colorTopRight = Utilities.ConvertColor(SpriteModel.Sprite.ColorTop); + if (ImGui.ColorEdit4("Top right", ref colorTopRight)) + SpriteModel.Sprite.ColorTop = Utilities.ConvertColor(colorTopRight); + + var colorBottomLeft = Utilities.ConvertColor(SpriteModel.Sprite.ColorRight); + if (ImGui.ColorEdit4("Bottom left", ref colorBottomLeft)) + SpriteModel.Sprite.ColorRight = Utilities.ConvertColor(colorBottomLeft); + + var colorBottomRight = Utilities.ConvertColor(SpriteModel.Sprite.ColorBottom); + if (ImGui.ColorEdit4("Bottom right", ref colorBottomRight)) + SpriteModel.Sprite.ColorBottom = Utilities.ConvertColor(colorBottomRight); + + var uvAnim = new Vector2(SpriteModel.Sprite.UTranslation, SpriteModel.Sprite.VTranslation); + if (ImGui.DragFloat2("UV animation", ref uvAnim, 0.0001f)) + { + SpriteModel.Sprite.UTranslation = uvAnim.X; + SpriteModel.Sprite.VTranslation = uvAnim.Y; + } + + SpriteModel.Draw(0, 0); + ImGui.Image(SpriteModel.TextureId, SuggestSpriteSize()); + } + + private void DrawCropAtlasTexture() + { + var sLeft = SpriteModel.Sprite.Left; + var sTop = SpriteModel.Sprite.Top; + var sRight = SpriteModel.Sprite.Right; + var sBottom = SpriteModel.Sprite.Bottom; + var cropColor = _settings.EditorBackground; + cropColor.A = 0.75f; + var invertedCropColor = new ColorF( + 1f - cropColor.R, 1f - cropColor.G, + 1f - cropColor.G, 1.0f); + + var context = new SpriteDrawingContext() + .SpriteTexture(_atlasTexture) + .ColorDefault() + .SourceLTRB(0, 0, _cropAtlasTexture.Width, _cropAtlasTexture.Height) + .Position(0, 0) + .DestinationSize(_cropAtlasTexture.Width, _cropAtlasTexture.Height); + context.TextureWrapHorizontal(TextureWrapMode.Repeat, 0, _cropAtlasTexture.Width); + context.TextureWrapVertical(TextureWrapMode.Repeat, 0, _cropAtlasTexture.Height); + + _spriteDrawing.DestinationTexture = _cropAtlasTexture; + _spriteDrawing.SetViewport(0, _cropAtlasTexture.Width, 0, _cropAtlasTexture.Height); + _spriteDrawing.Clear(_settings.EditorBackground); + _spriteDrawing.AppendSprite(context); + + _spriteDrawing.FillRectangle(0, 0, _cropAtlasTexture.Width, sTop, cropColor); + _spriteDrawing.FillRectangle(0, sTop, sLeft, sBottom - sTop, cropColor); + _spriteDrawing.FillRectangle(sRight, sTop, _cropAtlasTexture.Width, sBottom - sTop, cropColor); + _spriteDrawing.FillRectangle(0, sBottom, _cropAtlasTexture.Width, _cropAtlasTexture.Height, cropColor); + _spriteDrawing.DrawRectangle(sLeft - 1, sTop - 1, + sRight - sLeft + 2, sBottom - sTop + 2, invertedCropColor); + + _spriteDrawing.Flush(); + _spriteDrawing.DestinationTexture = null; + } + + private Vector2 SuggestSpriteSize() + { + const int MaxZoomLevel = 8; + var zoomLevelX = _atlasTexture.Width / SpriteModel.Width; + var zoomLevelY = _atlasTexture.Height / SpriteModel.Height; + var zoomLevel = Math.Max(1, Math.Min(MaxZoomLevel, Math.Min(zoomLevelX, zoomLevelY))); + + return new Vector2(SpriteModel.Width * zoomLevel, SpriteModel.Height * zoomLevel); + } + } +} diff --git a/OpenKh.Tools.LayoutEditor/Dialogs/SpriteGroupEditDialog.cs b/OpenKh.Tools.LayoutEditor/Dialogs/SpriteGroupEditDialog.cs index 68fb392a8..7eded5c63 100644 --- a/OpenKh.Tools.LayoutEditor/Dialogs/SpriteGroupEditDialog.cs +++ b/OpenKh.Tools.LayoutEditor/Dialogs/SpriteGroupEditDialog.cs @@ -1,216 +1,216 @@ -using ImGuiNET; -using OpenKh.Engine.Extensions; -using OpenKh.Engine.Renders; -using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; -using OpenKh.Tools.LayoutEditor.Interfaces; -using OpenKh.Tools.LayoutEditor.Models; -using System; -using System.Numerics; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using System.Linq; -using System.Collections.Generic; - -namespace OpenKh.Tools.LayoutEditor.Dialogs -{ - class SpriteGroupEditDialog : IDisposable - { - private readonly Sequence _sequence; - private readonly List _spriteGroupModels; - private readonly ISpriteDrawing _spriteDrawing; - private readonly ISpriteTexture _atlasTexture; - private readonly ITextureBinder _textureBinder; - private readonly IEditorSettings _settings; - private bool _isPivotVisible = true; - - private int _selectedSpriteGroupModel; - private int _removeSpritePart = -1; - - private SpriteGroupModel SpriteGroupModel => _spriteGroupModels[_selectedSpriteGroupModel]; - - public SpriteGroupEditDialog( - Sequence sequence, - List spriteGroupModels, - int selectedSpriteGroupModel, - ISpriteDrawing spriteDrawing, - ISpriteTexture atlasTexture, - ITextureBinder textureBinder, - IEditorSettings settings) - { - _sequence = sequence; - _spriteGroupModels = spriteGroupModels; - _selectedSpriteGroupModel = selectedSpriteGroupModel; - _spriteDrawing = spriteDrawing; - _atlasTexture = atlasTexture; - _textureBinder = textureBinder; - _settings = settings; - } - - public void Dispose() - { - } - - public void Run() - { - const float PreviewWidthMul = 1f; - const float PreviewWidthMax = 512f; - const float EditorWidthMul = 0.5f; - const float EditorWidthMax = 256f; - const float TotalWidthMul = PreviewWidthMul + EditorWidthMul; - - var windowSize = ImGui.GetIO().DisplaySize.X; - var previewWidth = Math.Min(windowSize / TotalWidthMul * PreviewWidthMul, PreviewWidthMax); - var editorWidth = Math.Min(windowSize / TotalWidthMul * EditorWidthMul, EditorWidthMax); - - ForChild(nameof(SpriteGroupPreview), previewWidth, 512, true, SpriteGroupPreview); - ImGui.SameLine(); - ForChild(nameof(SptiteGroupEditor), editorWidth, 512, false, SptiteGroupEditor); - - if (_removeSpritePart >= 0) - { - SpriteGroupModel.SpriteGroup.RemoveAt(_removeSpritePart); - _removeSpritePart = -1; - } - } - - private void SpriteGroupPreview() - { - SpriteGroupModel.Draw(0, 0, PreDraw, PostDraw); - ImGui.Image(SpriteGroupModel.TextureId, SuggestSpriteSize()); - } - - private void PreDraw(ISpriteDrawing drawing) - { - DrawCenter(drawing, 1.0f); - } - - private void PostDraw(ISpriteDrawing drawing) - { - DrawCenter(drawing, 0.333f); - - //var backgroundColorInverse = new ColorF( - // 1f - _settings.EditorBackground.R, - // 1f - _settings.EditorBackground.G, - // 1f, - // 1f); - //drawing.FillRectangle(50, 0, 100, 100, backgroundColorInverse); - //drawing.Flush(); - } - - private void SptiteGroupEditor() - { - if (ImGui.InputInt("Selected", ref _selectedSpriteGroupModel)) - _selectedSpriteGroupModel = Math.Min(Math.Max(_selectedSpriteGroupModel, 0), _spriteGroupModels.Count - 1); - - ImGui.Checkbox("Show pivot", ref _isPivotVisible); - - var origin = GetOrigin(SpriteGroupModel); - var originValues = new int[] { origin.X, origin.Y }; - if (ImGui.DragInt2("Pivot", ref originValues[0])) - { - var diffX = originValues[0] - origin.X; - var diffY = originValues[1] - origin.Y; - foreach (var item in SpriteGroupModel.SpriteGroup) - { - item.Left -= diffX; - item.Right -= diffX; - item.Top -= diffY; - item.Bottom -= diffY; - } - } - - var size = SpriteGroupModel.SpriteGroup.GetVisibilityRectangleForFrameGroup(); - ImGui.Text($"Width: {size.Width}, Heigth: {size.Height}"); - if (ImGui.SmallButton("Add new sprite part")) - SpriteGroupModel.SpriteGroup.Add(new Sequence.SpritePart()); - - for (var i = 0; i < SpriteGroupModel.SpriteGroup.Count; i++) - { - if (ImGui.CollapsingHeader($"Sprite part {i + 1}")) - { - SpritePartEdit(SpriteGroupModel.SpriteGroup[i], i); - } - } - } - - private void SpritePartEdit(Sequence.SpritePart spritePart, int index) - { - var position = new int[] - { - spritePart.Left, - spritePart.Top - }; - var size = new int[] - { - spritePart.Right - spritePart.Left, - spritePart.Bottom - spritePart.Top - }; - - var spriteIndex = spritePart.SpriteIndex; - if (ImGui.InputInt($"Sprite index##{index}", ref spriteIndex)) - spritePart.SpriteIndex = Math.Min(Math.Max(spriteIndex, 0), _sequence.Sprites.Count - 1); - - if (ImGui.DragInt2($"Position##{index}", ref position[0])) - { - spritePart.Left = position[0]; - spritePart.Top = position[1]; - spritePart.Right = position[0] + size[0]; - spritePart.Bottom = position[1] + size[1]; - SpriteGroupModel.SizeChanged(); - } - if (ImGui.DragInt2($"Size##{index}", ref size[0])) - { - spritePart.Right = position[0] + size[0]; - spritePart.Bottom = position[1] + size[1]; - SpriteGroupModel.SizeChanged(); - } - if (ImGui.Button($"Make sprite pixel perfect##{index}")) - { - var innerSprite = _sequence.Sprites[spritePart.SpriteIndex]; - spritePart.Right = position[0] + Math.Abs(innerSprite.Left - innerSprite.Right); - spritePart.Bottom = position[1] + Math.Abs(innerSprite.Top - innerSprite.Bottom); - SpriteGroupModel.SizeChanged(); - } - - if (ImGui.SmallButton($"Remove from the sprite group##{index}")) - _removeSpritePart = index; - } - - private Vector2 SuggestSpriteSize() - { - const int MaxZoomLevel = 8; - var zoomLevelX = 512f / SpriteGroupModel.Width; - var zoomLevelY = 512f / SpriteGroupModel.Height; - var zoomLevel = Math.Max(1, Math.Min(MaxZoomLevel, Math.Min(zoomLevelX, zoomLevelY))); - - return new Vector2(SpriteGroupModel.Width * zoomLevel, SpriteGroupModel.Height * zoomLevel); - } - - private void DrawCenter(ISpriteDrawing drawing, float alpha) - { - if (!_isPivotVisible) - return; - - const float Infinite = 65535f; - var origin = GetOrigin(SpriteGroupModel); - var backgroundColorInverse = new ColorF( - 1f - _settings.EditorBackground.R, - 1f - _settings.EditorBackground.G, - 1f - _settings.EditorBackground.B, - alpha); - - drawing.FillRectangle(origin.X, 0, 1, Infinite, backgroundColorInverse); - drawing.FillRectangle(0, origin.Y, Infinite, 1, backgroundColorInverse); - drawing.Flush(); - } - - private static (int X, int Y) GetOrigin(SpriteGroupModel spriteGroupModel) - { - if (spriteGroupModel.SpriteGroup.Count == 0) - return (0, 0); - - return (-spriteGroupModel.SpriteGroup.Min(x => Math.Min(x.Left, x.Right)), - -spriteGroupModel.SpriteGroup.Min(x => Math.Min(x.Top, x.Bottom))); - } - } -} +using ImGuiNET; +using OpenKh.Engine.Extensions; +using OpenKh.Engine.Renders; +using static OpenKh.Tools.Common.CustomImGui.ImGuiEx; +using OpenKh.Tools.LayoutEditor.Interfaces; +using OpenKh.Tools.LayoutEditor.Models; +using System; +using System.Numerics; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using System.Linq; +using System.Collections.Generic; + +namespace OpenKh.Tools.LayoutEditor.Dialogs +{ + class SpriteGroupEditDialog : IDisposable + { + private readonly Sequence _sequence; + private readonly List _spriteGroupModels; + private readonly ISpriteDrawing _spriteDrawing; + private readonly ISpriteTexture _atlasTexture; + private readonly ITextureBinder _textureBinder; + private readonly IEditorSettings _settings; + private bool _isPivotVisible = true; + + private int _selectedSpriteGroupModel; + private int _removeSpritePart = -1; + + private SpriteGroupModel SpriteGroupModel => _spriteGroupModels[_selectedSpriteGroupModel]; + + public SpriteGroupEditDialog( + Sequence sequence, + List spriteGroupModels, + int selectedSpriteGroupModel, + ISpriteDrawing spriteDrawing, + ISpriteTexture atlasTexture, + ITextureBinder textureBinder, + IEditorSettings settings) + { + _sequence = sequence; + _spriteGroupModels = spriteGroupModels; + _selectedSpriteGroupModel = selectedSpriteGroupModel; + _spriteDrawing = spriteDrawing; + _atlasTexture = atlasTexture; + _textureBinder = textureBinder; + _settings = settings; + } + + public void Dispose() + { + } + + public void Run() + { + const float PreviewWidthMul = 1f; + const float PreviewWidthMax = 512f; + const float EditorWidthMul = 0.5f; + const float EditorWidthMax = 256f; + const float TotalWidthMul = PreviewWidthMul + EditorWidthMul; + + var windowSize = ImGui.GetIO().DisplaySize.X; + var previewWidth = Math.Min(windowSize / TotalWidthMul * PreviewWidthMul, PreviewWidthMax); + var editorWidth = Math.Min(windowSize / TotalWidthMul * EditorWidthMul, EditorWidthMax); + + ForChild(nameof(SpriteGroupPreview), previewWidth, 512, true, SpriteGroupPreview); + ImGui.SameLine(); + ForChild(nameof(SptiteGroupEditor), editorWidth, 512, false, SptiteGroupEditor); + + if (_removeSpritePart >= 0) + { + SpriteGroupModel.SpriteGroup.RemoveAt(_removeSpritePart); + _removeSpritePart = -1; + } + } + + private void SpriteGroupPreview() + { + SpriteGroupModel.Draw(0, 0, PreDraw, PostDraw); + ImGui.Image(SpriteGroupModel.TextureId, SuggestSpriteSize()); + } + + private void PreDraw(ISpriteDrawing drawing) + { + DrawCenter(drawing, 1.0f); + } + + private void PostDraw(ISpriteDrawing drawing) + { + DrawCenter(drawing, 0.333f); + + //var backgroundColorInverse = new ColorF( + // 1f - _settings.EditorBackground.R, + // 1f - _settings.EditorBackground.G, + // 1f, + // 1f); + //drawing.FillRectangle(50, 0, 100, 100, backgroundColorInverse); + //drawing.Flush(); + } + + private void SptiteGroupEditor() + { + if (ImGui.InputInt("Selected", ref _selectedSpriteGroupModel)) + _selectedSpriteGroupModel = Math.Min(Math.Max(_selectedSpriteGroupModel, 0), _spriteGroupModels.Count - 1); + + ImGui.Checkbox("Show pivot", ref _isPivotVisible); + + var origin = GetOrigin(SpriteGroupModel); + var originValues = new int[] { origin.X, origin.Y }; + if (ImGui.DragInt2("Pivot", ref originValues[0])) + { + var diffX = originValues[0] - origin.X; + var diffY = originValues[1] - origin.Y; + foreach (var item in SpriteGroupModel.SpriteGroup) + { + item.Left -= diffX; + item.Right -= diffX; + item.Top -= diffY; + item.Bottom -= diffY; + } + } + + var size = SpriteGroupModel.SpriteGroup.GetVisibilityRectangleForFrameGroup(); + ImGui.Text($"Width: {size.Width}, Heigth: {size.Height}"); + if (ImGui.SmallButton("Add new sprite part")) + SpriteGroupModel.SpriteGroup.Add(new Sequence.SpritePart()); + + for (var i = 0; i < SpriteGroupModel.SpriteGroup.Count; i++) + { + if (ImGui.CollapsingHeader($"Sprite part {i + 1}")) + { + SpritePartEdit(SpriteGroupModel.SpriteGroup[i], i); + } + } + } + + private void SpritePartEdit(Sequence.SpritePart spritePart, int index) + { + var position = new int[] + { + spritePart.Left, + spritePart.Top + }; + var size = new int[] + { + spritePart.Right - spritePart.Left, + spritePart.Bottom - spritePart.Top + }; + + var spriteIndex = spritePart.SpriteIndex; + if (ImGui.InputInt($"Sprite index##{index}", ref spriteIndex)) + spritePart.SpriteIndex = Math.Min(Math.Max(spriteIndex, 0), _sequence.Sprites.Count - 1); + + if (ImGui.DragInt2($"Position##{index}", ref position[0])) + { + spritePart.Left = position[0]; + spritePart.Top = position[1]; + spritePart.Right = position[0] + size[0]; + spritePart.Bottom = position[1] + size[1]; + SpriteGroupModel.SizeChanged(); + } + if (ImGui.DragInt2($"Size##{index}", ref size[0])) + { + spritePart.Right = position[0] + size[0]; + spritePart.Bottom = position[1] + size[1]; + SpriteGroupModel.SizeChanged(); + } + if (ImGui.Button($"Make sprite pixel perfect##{index}")) + { + var innerSprite = _sequence.Sprites[spritePart.SpriteIndex]; + spritePart.Right = position[0] + Math.Abs(innerSprite.Left - innerSprite.Right); + spritePart.Bottom = position[1] + Math.Abs(innerSprite.Top - innerSprite.Bottom); + SpriteGroupModel.SizeChanged(); + } + + if (ImGui.SmallButton($"Remove from the sprite group##{index}")) + _removeSpritePart = index; + } + + private Vector2 SuggestSpriteSize() + { + const int MaxZoomLevel = 8; + var zoomLevelX = 512f / SpriteGroupModel.Width; + var zoomLevelY = 512f / SpriteGroupModel.Height; + var zoomLevel = Math.Max(1, Math.Min(MaxZoomLevel, Math.Min(zoomLevelX, zoomLevelY))); + + return new Vector2(SpriteGroupModel.Width * zoomLevel, SpriteGroupModel.Height * zoomLevel); + } + + private void DrawCenter(ISpriteDrawing drawing, float alpha) + { + if (!_isPivotVisible) + return; + + const float Infinite = 65535f; + var origin = GetOrigin(SpriteGroupModel); + var backgroundColorInverse = new ColorF( + 1f - _settings.EditorBackground.R, + 1f - _settings.EditorBackground.G, + 1f - _settings.EditorBackground.B, + alpha); + + drawing.FillRectangle(origin.X, 0, 1, Infinite, backgroundColorInverse); + drawing.FillRectangle(0, origin.Y, Infinite, 1, backgroundColorInverse); + drawing.Flush(); + } + + private static (int X, int Y) GetOrigin(SpriteGroupModel spriteGroupModel) + { + if (spriteGroupModel.SpriteGroup.Count == 0) + return (0, 0); + + return (-spriteGroupModel.SpriteGroup.Min(x => Math.Min(x.Left, x.Right)), + -spriteGroupModel.SpriteGroup.Min(x => Math.Min(x.Top, x.Bottom))); + } + } +} diff --git a/OpenKh.Tools.LayoutEditor/Interfaces/IApp.cs b/OpenKh.Tools.LayoutEditor/Interfaces/IApp.cs index 83f8c2f8a..2081b9993 100644 --- a/OpenKh.Tools.LayoutEditor/Interfaces/IApp.cs +++ b/OpenKh.Tools.LayoutEditor/Interfaces/IApp.cs @@ -1,10 +1,10 @@ -using System; - -namespace OpenKh.Tools.LayoutEditor.Interfaces -{ - public interface IApp : IDisposable - { - void Menu(); - bool Run(); - } -} +using System; + +namespace OpenKh.Tools.LayoutEditor.Interfaces +{ + public interface IApp : IDisposable + { + void Menu(); + bool Run(); + } +} diff --git a/OpenKh.Tools.LayoutEditor/Interfaces/IEditorSettings.cs b/OpenKh.Tools.LayoutEditor/Interfaces/IEditorSettings.cs index 9661f1e17..ce9e81053 100644 --- a/OpenKh.Tools.LayoutEditor/Interfaces/IEditorSettings.cs +++ b/OpenKh.Tools.LayoutEditor/Interfaces/IEditorSettings.cs @@ -1,16 +1,16 @@ -using OpenKh.Engine.Renders; - -namespace OpenKh.Tools.LayoutEditor.Interfaces -{ - public interface IEditorSettings - { - delegate void ChangeBackground(object sender, IEditorSettings settings); - public event ChangeBackground OnChangeBackground; - - //public bool CheckerboardBackground { get; } - ColorF EditorBackground { get; } - bool ShowViewportOriginal { get; } - bool ShowViewportRemix { get; } - bool IsViewportOnTop { get; } - } -} +using OpenKh.Engine.Renders; + +namespace OpenKh.Tools.LayoutEditor.Interfaces +{ + public interface IEditorSettings + { + delegate void ChangeBackground(object sender, IEditorSettings settings); + public event ChangeBackground OnChangeBackground; + + //public bool CheckerboardBackground { get; } + ColorF EditorBackground { get; } + bool ShowViewportOriginal { get; } + bool ShowViewportRemix { get; } + bool IsViewportOnTop { get; } + } +} diff --git a/OpenKh.Tools.LayoutEditor/Interfaces/ISaveBar.cs b/OpenKh.Tools.LayoutEditor/Interfaces/ISaveBar.cs index b6b243543..44d324168 100644 --- a/OpenKh.Tools.LayoutEditor/Interfaces/ISaveBar.cs +++ b/OpenKh.Tools.LayoutEditor/Interfaces/ISaveBar.cs @@ -1,10 +1,10 @@ -using OpenKh.Kh2; - -namespace OpenKh.Tools.LayoutEditor.Interfaces -{ - public interface ISaveBar - { - Bar.Entry SaveAnimation(string name); - Bar.Entry SaveTexture(string name); - } -} +using OpenKh.Kh2; + +namespace OpenKh.Tools.LayoutEditor.Interfaces +{ + public interface ISaveBar + { + Bar.Entry SaveAnimation(string name); + Bar.Entry SaveTexture(string name); + } +} diff --git a/OpenKh.Tools.LayoutEditor/Interfaces/ITextureBinder.cs b/OpenKh.Tools.LayoutEditor/Interfaces/ITextureBinder.cs index 37f77cba7..34d0afde9 100644 --- a/OpenKh.Tools.LayoutEditor/Interfaces/ITextureBinder.cs +++ b/OpenKh.Tools.LayoutEditor/Interfaces/ITextureBinder.cs @@ -1,31 +1,31 @@ -using Microsoft.Xna.Framework.Graphics; -using OpenKh.Engine.MonoGame; -using OpenKh.Engine.Renders; -using System; - -namespace OpenKh.Tools.LayoutEditor.Interfaces -{ - public interface ITextureBinder - { - IntPtr BindTexture(Texture2D texture); - void UnbindTexture(IntPtr id); - void RebindTexture(IntPtr id, Texture2D texture); - } - - public static class TextureBuilderExtensions - { - public static IntPtr BindTexture( - this ITextureBinder textureBinder, ISpriteTexture spriteTexture) - { - var realSpriteTexture = (MonoSpriteDrawing.CSpriteTexture)spriteTexture; - return textureBinder.BindTexture(realSpriteTexture.Texture); - } - - public static void RebindTexture( - this ITextureBinder textureBinder, IntPtr id, ISpriteTexture spriteTexture) - { - var realSpriteTexture = (MonoSpriteDrawing.CSpriteTexture)spriteTexture; - textureBinder.RebindTexture(id, realSpriteTexture.Texture); - } - } -} +using Microsoft.Xna.Framework.Graphics; +using OpenKh.Engine.MonoGame; +using OpenKh.Engine.Renders; +using System; + +namespace OpenKh.Tools.LayoutEditor.Interfaces +{ + public interface ITextureBinder + { + IntPtr BindTexture(Texture2D texture); + void UnbindTexture(IntPtr id); + void RebindTexture(IntPtr id, Texture2D texture); + } + + public static class TextureBuilderExtensions + { + public static IntPtr BindTexture( + this ITextureBinder textureBinder, ISpriteTexture spriteTexture) + { + var realSpriteTexture = (MonoSpriteDrawing.CSpriteTexture)spriteTexture; + return textureBinder.BindTexture(realSpriteTexture.Texture); + } + + public static void RebindTexture( + this ITextureBinder textureBinder, IntPtr id, ISpriteTexture spriteTexture) + { + var realSpriteTexture = (MonoSpriteDrawing.CSpriteTexture)spriteTexture; + textureBinder.RebindTexture(id, realSpriteTexture.Texture); + } + } +} diff --git a/OpenKh.Tools.LayoutEditor/Models/SpriteGroupModel.cs b/OpenKh.Tools.LayoutEditor/Models/SpriteGroupModel.cs index a3cb71a1e..222bb6901 100644 --- a/OpenKh.Tools.LayoutEditor/Models/SpriteGroupModel.cs +++ b/OpenKh.Tools.LayoutEditor/Models/SpriteGroupModel.cs @@ -1,137 +1,137 @@ -using OpenKh.Engine.Renderers; -using OpenKh.Engine.Renders; -using OpenKh.Kh2; -using OpenKh.Kh2.Extensions; -using OpenKh.Tools.LayoutEditor.Interfaces; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenKh.Tools.LayoutEditor.Models -{ - public class SpriteGroupModel : IDisposable - { - private readonly ISpriteDrawing _drawing; - private readonly ITextureBinder _textureBinder; - private readonly IEditorSettings _settings; - private readonly Sequence _sequence; - private readonly Sequence _mockSequence; - private readonly SequenceRenderer _renderer; - private int _spriteGroupIndex; - private int _frameIndex; - private ISpriteTexture _spriteTexture; - - public List SpriteGroup => _sequence.SpriteGroups[_spriteGroupIndex]; - public IntPtr TextureId { get; set; } - public int Width { get; private set; } - public int Height { get; private set; } - - public SpriteGroupModel( - Sequence sequence, - int spriteGroupIndex, - ISpriteDrawing drawing, - ISpriteTexture atlasTexture, - ITextureBinder textureBinder, - IEditorSettings settings) - { - _drawing = drawing; - _textureBinder = textureBinder; - _settings = settings; - _sequence = sequence; - _spriteGroupIndex = spriteGroupIndex; - _mockSequence = MockSequence(); - _renderer = new SequenceRenderer(_mockSequence, drawing, atlasTexture); - - _settings.OnChangeBackground += (o, e) => Draw(0, 0); - SizeChanged(); - } - - public IntPtr Draw(float x, float y, Action pre = null, Action post = null) - { - _drawing.SetViewport(0, Width, 0, Height); - _drawing.DestinationTexture = _spriteTexture; - _drawing.Clear(_settings.EditorBackground); - pre?.Invoke(_drawing); - - int posX; - int posY; - if (SpriteGroup.Count > 0) - { - posX = -SpriteGroup.Min(x => Math.Min(x.Left, x.Right)); - posY = -SpriteGroup.Min(x => Math.Min(x.Top, x.Bottom)); - } - else - { - posX = 0; - posY = 0; - } - - - _renderer.Draw(0, _frameIndex++, posX + x, posY + y); - _drawing.Flush(); - - post?.Invoke(_drawing); - _drawing.DestinationTexture = null; - - return TextureId; - } - - public void SizeChanged() - { - var rect = SpriteGroup.GetVisibilityRectangleForFrameGroup(); - if (rect.Width == Width && rect.Height == Height) - return; - - Width = Math.Max(rect.Width, 1); - Height = Math.Max(rect.Height, 1); - - _spriteTexture?.Dispose(); - _spriteTexture = _drawing.CreateSpriteTexture(Width, Height); - - if (TextureId == IntPtr.Zero) - TextureId = _textureBinder.BindTexture(_spriteTexture); - else - _textureBinder.RebindTexture(TextureId, _spriteTexture); - - Draw(0, 0); - } - - public void Dispose() - { - if (TextureId != IntPtr.Zero) - _textureBinder.UnbindTexture(TextureId); - _spriteTexture?.Dispose(); - } - - private Sequence MockSequence() => new Sequence - { - AnimationGroups = new List - { - new Sequence.AnimationGroup - { - Animations = new List - { - new Sequence.Animation - { - SpriteGroupIndex = _spriteGroupIndex, - FrameStart = 0, - FrameEnd = 10, - ScaleStart = 1, - ScaleEnd = 1, - ScaleXStart = 1, - ScaleXEnd = 1, - ScaleYStart = 1, - ScaleYEnd = 1, - ColorStart = 0x80808080U, - ColorEnd = 0x80808080U, - } - }, - LoopStart = 0, - LoopEnd = 10, - } - }, - SpriteGroups = _sequence.SpriteGroups, - Sprites = _sequence.Sprites - }; - } -} +using OpenKh.Engine.Renderers; +using OpenKh.Engine.Renders; +using OpenKh.Kh2; +using OpenKh.Kh2.Extensions; +using OpenKh.Tools.LayoutEditor.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenKh.Tools.LayoutEditor.Models +{ + public class SpriteGroupModel : IDisposable + { + private readonly ISpriteDrawing _drawing; + private readonly ITextureBinder _textureBinder; + private readonly IEditorSettings _settings; + private readonly Sequence _sequence; + private readonly Sequence _mockSequence; + private readonly SequenceRenderer _renderer; + private int _spriteGroupIndex; + private int _frameIndex; + private ISpriteTexture _spriteTexture; + + public List SpriteGroup => _sequence.SpriteGroups[_spriteGroupIndex]; + public IntPtr TextureId { get; set; } + public int Width { get; private set; } + public int Height { get; private set; } + + public SpriteGroupModel( + Sequence sequence, + int spriteGroupIndex, + ISpriteDrawing drawing, + ISpriteTexture atlasTexture, + ITextureBinder textureBinder, + IEditorSettings settings) + { + _drawing = drawing; + _textureBinder = textureBinder; + _settings = settings; + _sequence = sequence; + _spriteGroupIndex = spriteGroupIndex; + _mockSequence = MockSequence(); + _renderer = new SequenceRenderer(_mockSequence, drawing, atlasTexture); + + _settings.OnChangeBackground += (o, e) => Draw(0, 0); + SizeChanged(); + } + + public IntPtr Draw(float x, float y, Action pre = null, Action post = null) + { + _drawing.SetViewport(0, Width, 0, Height); + _drawing.DestinationTexture = _spriteTexture; + _drawing.Clear(_settings.EditorBackground); + pre?.Invoke(_drawing); + + int posX; + int posY; + if (SpriteGroup.Count > 0) + { + posX = -SpriteGroup.Min(x => Math.Min(x.Left, x.Right)); + posY = -SpriteGroup.Min(x => Math.Min(x.Top, x.Bottom)); + } + else + { + posX = 0; + posY = 0; + } + + + _renderer.Draw(0, _frameIndex++, posX + x, posY + y); + _drawing.Flush(); + + post?.Invoke(_drawing); + _drawing.DestinationTexture = null; + + return TextureId; + } + + public void SizeChanged() + { + var rect = SpriteGroup.GetVisibilityRectangleForFrameGroup(); + if (rect.Width == Width && rect.Height == Height) + return; + + Width = Math.Max(rect.Width, 1); + Height = Math.Max(rect.Height, 1); + + _spriteTexture?.Dispose(); + _spriteTexture = _drawing.CreateSpriteTexture(Width, Height); + + if (TextureId == IntPtr.Zero) + TextureId = _textureBinder.BindTexture(_spriteTexture); + else + _textureBinder.RebindTexture(TextureId, _spriteTexture); + + Draw(0, 0); + } + + public void Dispose() + { + if (TextureId != IntPtr.Zero) + _textureBinder.UnbindTexture(TextureId); + _spriteTexture?.Dispose(); + } + + private Sequence MockSequence() => new Sequence + { + AnimationGroups = new List + { + new Sequence.AnimationGroup + { + Animations = new List + { + new Sequence.Animation + { + SpriteGroupIndex = _spriteGroupIndex, + FrameStart = 0, + FrameEnd = 10, + ScaleStart = 1, + ScaleEnd = 1, + ScaleXStart = 1, + ScaleXEnd = 1, + ScaleYStart = 1, + ScaleYEnd = 1, + ColorStart = 0x80808080U, + ColorEnd = 0x80808080U, + } + }, + LoopStart = 0, + LoopEnd = 10, + } + }, + SpriteGroups = _sequence.SpriteGroups, + Sprites = _sequence.Sprites + }; + } +} diff --git a/OpenKh.Tools.LayoutEditor/Models/SpriteModel.cs b/OpenKh.Tools.LayoutEditor/Models/SpriteModel.cs index 6d5c1139f..685c4b75b 100644 --- a/OpenKh.Tools.LayoutEditor/Models/SpriteModel.cs +++ b/OpenKh.Tools.LayoutEditor/Models/SpriteModel.cs @@ -1,133 +1,133 @@ -using OpenKh.Engine.Renderers; -using OpenKh.Engine.Renders; -using OpenKh.Kh2; -using OpenKh.Tools.LayoutEditor.Interfaces; -using System; -using System.Collections.Generic; - -namespace OpenKh.Tools.LayoutEditor.Models -{ - public class SpriteModel : IDisposable - { - private readonly ISpriteDrawing _drawing; - private readonly Sequence _sequence; - private readonly SequenceRenderer _renderer; - private readonly ITextureBinder _textureBinder; - private readonly IEditorSettings _settings; - private ISpriteTexture _spriteTexture; - private int _frameIndex; - - public Sequence.Sprite Sprite { get; } - public IntPtr TextureId { get; set; } - public int Width { get; private set; } - public int Height { get; private set; } - - public SpriteModel( - Sequence.Sprite sprite, - ISpriteDrawing drawing, - ISpriteTexture atlasTexture, - ITextureBinder textureBinder, - IEditorSettings settings) - { - Sprite = sprite; - - _drawing = drawing; - _sequence = MockSequence(); - _renderer = new SequenceRenderer(_sequence, drawing, atlasTexture); - _textureBinder = textureBinder; - _settings = settings; - _settings.OnChangeBackground += (o, e) => Draw(0, 0); - - SizeChanged(); - } - - public IntPtr Draw(float x, float y) - { - _drawing.SetViewport(0, Width, 0, Height); - _drawing.DestinationTexture = _spriteTexture; - _drawing.Clear(_settings.EditorBackground); - _renderer.Draw(0, _frameIndex++, x, y); - _drawing.Flush(); - _drawing.DestinationTexture = null; - - return TextureId; - } - - public void SizeChanged() - { - var newWidth = Math.Max(1, Math.Max(Sprite.Left, Sprite.Right) - - Math.Min(Sprite.Left, Sprite.Right)); - var newHeight = Math.Max(1, Math.Max(Sprite.Top, Sprite.Bottom) - - Math.Max(1, Math.Min(Sprite.Top, Sprite.Bottom))); - if (newWidth == Width && newHeight == Height) - return; - - if (TextureId != IntPtr.Zero) - _textureBinder.UnbindTexture(TextureId); - _spriteTexture?.Dispose(); - - Width = newWidth; - Height = newHeight; - _sequence.SpriteGroups[0][0].Right = Width; - _sequence.SpriteGroups[0][0].Bottom = Height; - _spriteTexture = _drawing.CreateSpriteTexture(Width, Height); - TextureId = _textureBinder.BindTexture(_spriteTexture); - - Draw(0, 0); - } - - public void Dispose() - { - if (TextureId != IntPtr.Zero) - _textureBinder.UnbindTexture(TextureId); - _spriteTexture?.Dispose(); - } - - private Sequence MockSequence() => new Sequence - { - AnimationGroups = new List - { - new Sequence.AnimationGroup - { - Animations = new List - { - new Sequence.Animation - { - SpriteGroupIndex = 0, - FrameStart = 0, - FrameEnd = 10, - ScaleStart = 1, - ScaleEnd = 1, - ScaleXStart = 1, - ScaleXEnd = 1, - ScaleYStart = 1, - ScaleYEnd = 1, - ColorStart = 0x80808080U, - ColorEnd = 0x80808080U, - } - }, - LoopStart = 0, - LoopEnd = 10, - } - }, - SpriteGroups = new List> - { - new List - { - new Sequence.SpritePart - { - Left = 0, - Top = 0, - Right = Width, - Bottom = Height, - SpriteIndex = 0 - } - } - }, - Sprites = new List - { - Sprite - } - }; - } -} +using OpenKh.Engine.Renderers; +using OpenKh.Engine.Renders; +using OpenKh.Kh2; +using OpenKh.Tools.LayoutEditor.Interfaces; +using System; +using System.Collections.Generic; + +namespace OpenKh.Tools.LayoutEditor.Models +{ + public class SpriteModel : IDisposable + { + private readonly ISpriteDrawing _drawing; + private readonly Sequence _sequence; + private readonly SequenceRenderer _renderer; + private readonly ITextureBinder _textureBinder; + private readonly IEditorSettings _settings; + private ISpriteTexture _spriteTexture; + private int _frameIndex; + + public Sequence.Sprite Sprite { get; } + public IntPtr TextureId { get; set; } + public int Width { get; private set; } + public int Height { get; private set; } + + public SpriteModel( + Sequence.Sprite sprite, + ISpriteDrawing drawing, + ISpriteTexture atlasTexture, + ITextureBinder textureBinder, + IEditorSettings settings) + { + Sprite = sprite; + + _drawing = drawing; + _sequence = MockSequence(); + _renderer = new SequenceRenderer(_sequence, drawing, atlasTexture); + _textureBinder = textureBinder; + _settings = settings; + _settings.OnChangeBackground += (o, e) => Draw(0, 0); + + SizeChanged(); + } + + public IntPtr Draw(float x, float y) + { + _drawing.SetViewport(0, Width, 0, Height); + _drawing.DestinationTexture = _spriteTexture; + _drawing.Clear(_settings.EditorBackground); + _renderer.Draw(0, _frameIndex++, x, y); + _drawing.Flush(); + _drawing.DestinationTexture = null; + + return TextureId; + } + + public void SizeChanged() + { + var newWidth = Math.Max(1, Math.Max(Sprite.Left, Sprite.Right) - + Math.Min(Sprite.Left, Sprite.Right)); + var newHeight = Math.Max(1, Math.Max(Sprite.Top, Sprite.Bottom) - + Math.Max(1, Math.Min(Sprite.Top, Sprite.Bottom))); + if (newWidth == Width && newHeight == Height) + return; + + if (TextureId != IntPtr.Zero) + _textureBinder.UnbindTexture(TextureId); + _spriteTexture?.Dispose(); + + Width = newWidth; + Height = newHeight; + _sequence.SpriteGroups[0][0].Right = Width; + _sequence.SpriteGroups[0][0].Bottom = Height; + _spriteTexture = _drawing.CreateSpriteTexture(Width, Height); + TextureId = _textureBinder.BindTexture(_spriteTexture); + + Draw(0, 0); + } + + public void Dispose() + { + if (TextureId != IntPtr.Zero) + _textureBinder.UnbindTexture(TextureId); + _spriteTexture?.Dispose(); + } + + private Sequence MockSequence() => new Sequence + { + AnimationGroups = new List + { + new Sequence.AnimationGroup + { + Animations = new List + { + new Sequence.Animation + { + SpriteGroupIndex = 0, + FrameStart = 0, + FrameEnd = 10, + ScaleStart = 1, + ScaleEnd = 1, + ScaleXStart = 1, + ScaleXEnd = 1, + ScaleYStart = 1, + ScaleYEnd = 1, + ColorStart = 0x80808080U, + ColorEnd = 0x80808080U, + } + }, + LoopStart = 0, + LoopEnd = 10, + } + }, + SpriteGroups = new List> + { + new List + { + new Sequence.SpritePart + { + Left = 0, + Top = 0, + Right = Width, + Bottom = Height, + SpriteIndex = 0 + } + } + }, + Sprites = new List + { + Sprite + } + }; + } +} diff --git a/OpenKh.Tools.LayoutEditor/Program.cs b/OpenKh.Tools.LayoutEditor/Program.cs index d8cce34e0..d96b9a2d6 100644 --- a/OpenKh.Tools.LayoutEditor/Program.cs +++ b/OpenKh.Tools.LayoutEditor/Program.cs @@ -1,50 +1,50 @@ -using OpenKh.Tools.Common.CustomImGui; -using System; - -namespace OpenKh.Tools.LayoutEditor -{ - class Program : IDisposable - { - [STAThread] - static void Main(string[] args) - { - using var program = new Program(args); - program.Run(); - } - - const int InitialWindowWidth = 1000; - const int InitialWindowHeight = 800; - private readonly MonoGameImGuiBootstrap _bootstrap; - private App _app; - - public Program(string[] args) - { - _bootstrap = new MonoGameImGuiBootstrap( - InitialWindowWidth, - InitialWindowHeight, - Initialize); - _bootstrap.MainLoop = MainLoop; - } - - private void Initialize(MonoGameImGuiBootstrap bootstrap) - { - _app = new App(bootstrap); - } - - public void Run() - { - _bootstrap.Run(); - } - - private void MainLoop(MonoGameImGuiBootstrap obj) - { - if (_app.MainLoop()) - _bootstrap.Exit(); - } - - public void Dispose() - { - _bootstrap?.Dispose(); - } - } -} +using OpenKh.Tools.Common.CustomImGui; +using System; + +namespace OpenKh.Tools.LayoutEditor +{ + class Program : IDisposable + { + [STAThread] + static void Main(string[] args) + { + using var program = new Program(args); + program.Run(); + } + + const int InitialWindowWidth = 1000; + const int InitialWindowHeight = 800; + private readonly MonoGameImGuiBootstrap _bootstrap; + private App _app; + + public Program(string[] args) + { + _bootstrap = new MonoGameImGuiBootstrap( + InitialWindowWidth, + InitialWindowHeight, + Initialize); + _bootstrap.MainLoop = MainLoop; + } + + private void Initialize(MonoGameImGuiBootstrap bootstrap) + { + _app = new App(bootstrap); + } + + public void Run() + { + _bootstrap.Run(); + } + + private void MainLoop(MonoGameImGuiBootstrap obj) + { + if (_app.MainLoop()) + _bootstrap.Exit(); + } + + public void Dispose() + { + _bootstrap?.Dispose(); + } + } +} diff --git a/OpenKh.Tools.LayoutEditor/Utilities.cs b/OpenKh.Tools.LayoutEditor/Utilities.cs index a5c8f332b..9cd6ecdcb 100644 --- a/OpenKh.Tools.LayoutEditor/Utilities.cs +++ b/OpenKh.Tools.LayoutEditor/Utilities.cs @@ -1,19 +1,19 @@ -using System.Numerics; - -namespace OpenKh.Tools.LayoutEditor -{ - public static class Utilities - { - public static Vector4 ConvertColor(uint color) => new Vector4( - ((color >> 0) & 0xFF) / 255.0f, - ((color >> 8) & 0xFF) / 255.0f, - ((color >> 16) & 0xFF) / 255.0f, - ((color >> 24) & 0xFF) / 255.0f); - - public static uint ConvertColor(Vector4 color) => - ((uint)(color.X * 255f) << 0) | - ((uint)(color.Y * 255f) << 8) | - ((uint)(color.Z * 255f) << 16) | - ((uint)(color.W * 255f) << 24); - } -} +using System.Numerics; + +namespace OpenKh.Tools.LayoutEditor +{ + public static class Utilities + { + public static Vector4 ConvertColor(uint color) => new Vector4( + ((color >> 0) & 0xFF) / 255.0f, + ((color >> 8) & 0xFF) / 255.0f, + ((color >> 16) & 0xFF) / 255.0f, + ((color >> 24) & 0xFF) / 255.0f); + + public static uint ConvertColor(Vector4 color) => + ((uint)(color.X * 255f) << 0) | + ((uint)(color.Y * 255f) << 8) | + ((uint)(color.Z * 255f) << 16) | + ((uint)(color.W * 255f) << 24); + } +} diff --git a/OpenKh.Tools.ModsManager/App.xaml.cs b/OpenKh.Tools.ModsManager/App.xaml.cs index 95780eb55..7ba875cc4 100644 --- a/OpenKh.Tools.ModsManager/App.xaml.cs +++ b/OpenKh.Tools.ModsManager/App.xaml.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; - -namespace OpenKh.Tools.ModsManager -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace OpenKh.Tools.ModsManager +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/OpenKh.Tools.ModsManager/AssemblyInfo.cs b/OpenKh.Tools.ModsManager/AssemblyInfo.cs index 8b5504ecf..74087a1fd 100644 --- a/OpenKh.Tools.ModsManager/AssemblyInfo.cs +++ b/OpenKh.Tools.ModsManager/AssemblyInfo.cs @@ -1,10 +1,10 @@ -using System.Windows; - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/OpenKh.Tools.ModsManager/Converters/RadioButtonToIntConverter.cs b/OpenKh.Tools.ModsManager/Converters/RadioButtonToIntConverter.cs index 6ea287b18..b90eda3de 100644 --- a/OpenKh.Tools.ModsManager/Converters/RadioButtonToIntConverter.cs +++ b/OpenKh.Tools.ModsManager/Converters/RadioButtonToIntConverter.cs @@ -1,19 +1,19 @@ -using System; -using System.Globalization; -using System.Windows.Data; - -namespace OpenKh.Tools.ModsManager.Converters -{ - public class RadioBoolToIntConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - return value.ToString() == parameter.ToString(); - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - return value?.Equals(true) == true ? parameter : Binding.DoNothing; - } - } -} +using System; +using System.Globalization; +using System.Windows.Data; + +namespace OpenKh.Tools.ModsManager.Converters +{ + public class RadioBoolToIntConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value.ToString() == parameter.ToString(); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return value?.Equals(true) == true ? parameter : Binding.DoNothing; + } + } +} diff --git a/OpenKh.Tools.ModsManager/Exceptions/Exceptions.cs b/OpenKh.Tools.ModsManager/Exceptions/Exceptions.cs index a0bf10994..0dd9bd795 100644 --- a/OpenKh.Tools.ModsManager/Exceptions/Exceptions.cs +++ b/OpenKh.Tools.ModsManager/Exceptions/Exceptions.cs @@ -1,37 +1,37 @@ -using System; - -namespace OpenKh.Tools.ModsManager.Exceptions -{ - public class ModAlreadyExistsExceptions : Exception - { - public string ModName { get; } - - public ModAlreadyExistsExceptions(string modName) : - base($"A mod with the name '{modName}' already exists. The installation will now stop.") - { - ModName = modName; - } - } - - public class ModNotValidException : Exception - { - public string ModName { get; } - - public ModNotValidException(string modName) : - base($"The mod '{modName}' does not contain a valid OpenKH compatible mod due to the missing 'mod.yml' file.") - { - ModName = modName; - } - } - - public class RepositoryNotFoundException : Exception - { - public string RepositoryName { get; set; } - - public RepositoryNotFoundException(string repositoryName) : - base($"Repository '{repositoryName}' not found.") - { - - } - } -} +using System; + +namespace OpenKh.Tools.ModsManager.Exceptions +{ + public class ModAlreadyExistsExceptions : Exception + { + public string ModName { get; } + + public ModAlreadyExistsExceptions(string modName) : + base($"A mod with the name '{modName}' already exists. The installation will now stop.") + { + ModName = modName; + } + } + + public class ModNotValidException : Exception + { + public string ModName { get; } + + public ModNotValidException(string modName) : + base($"The mod '{modName}' does not contain a valid OpenKH compatible mod due to the missing 'mod.yml' file.") + { + ModName = modName; + } + } + + public class RepositoryNotFoundException : Exception + { + public string RepositoryName { get; set; } + + public RepositoryNotFoundException(string repositoryName) : + base($"Repository '{repositoryName}' not found.") + { + + } + } +} diff --git a/OpenKh.Tools.ModsManager/Helpers.cs b/OpenKh.Tools.ModsManager/Helpers.cs index 10918112e..176fe56f0 100644 --- a/OpenKh.Tools.ModsManager/Helpers.cs +++ b/OpenKh.Tools.ModsManager/Helpers.cs @@ -1,50 +1,50 @@ -using OpenKh.Tools.ModsManager.Services; -using System; -using System.Windows; - -namespace OpenKh.Tools.ModsManager -{ - public static class Helpers - { - public static bool Question(string message, string title = null) => - MessageBox.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes; - - public static void Handle(Action action) - { - try - { - action(); - } - catch (Exception ex) - { - Handle(ex); - } - } - - public static T Handle(Func action) - { - try - { - return action(); - } - catch (Exception ex) - { - Handle(ex); - return default; - } - } - - public static void Handle(Exception ex) - { - switch (ex) - { - case RepositoryNotFoundException _: - MessageBox.Show(ex.Message, "Repository not found", MessageBoxButton.OK, MessageBoxImage.Error); - break; - default: - MessageBox.Show(ex.Message, "Generic error", MessageBoxButton.OK, MessageBoxImage.Error); - break; - } - } - } -} +using OpenKh.Tools.ModsManager.Services; +using System; +using System.Windows; + +namespace OpenKh.Tools.ModsManager +{ + public static class Helpers + { + public static bool Question(string message, string title = null) => + MessageBox.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes; + + public static void Handle(Action action) + { + try + { + action(); + } + catch (Exception ex) + { + Handle(ex); + } + } + + public static T Handle(Func action) + { + try + { + return action(); + } + catch (Exception ex) + { + Handle(ex); + return default; + } + } + + public static void Handle(Exception ex) + { + switch (ex) + { + case RepositoryNotFoundException _: + MessageBox.Show(ex.Message, "Repository not found", MessageBoxButton.OK, MessageBoxImage.Error); + break; + default: + MessageBox.Show(ex.Message, "Generic error", MessageBoxButton.OK, MessageBoxImage.Error); + break; + } + } + } +} diff --git a/OpenKh.Tools.ModsManager/Interfaces/IDebugging.cs b/OpenKh.Tools.ModsManager/Interfaces/IDebugging.cs index 6337619be..9e040a5fa 100644 --- a/OpenKh.Tools.ModsManager/Interfaces/IDebugging.cs +++ b/OpenKh.Tools.ModsManager/Interfaces/IDebugging.cs @@ -1,8 +1,8 @@ -namespace OpenKh.Tools.ModsManager.Interfaces -{ - public interface IDebugging - { - void HideDebugger(); - void Log(long ms, string tag, string str); - } -} +namespace OpenKh.Tools.ModsManager.Interfaces +{ + public interface IDebugging + { + void HideDebugger(); + void Log(long ms, string tag, string str); + } +} diff --git a/OpenKh.Tools.ModsManager/Interfaces/IOperationDispatcher.cs b/OpenKh.Tools.ModsManager/Interfaces/IOperationDispatcher.cs index 96ef2ec16..b27ebd9cc 100644 --- a/OpenKh.Tools.ModsManager/Interfaces/IOperationDispatcher.cs +++ b/OpenKh.Tools.ModsManager/Interfaces/IOperationDispatcher.cs @@ -1,10 +1,10 @@ -using System.IO; - -namespace OpenKh.Tools.ModsManager.Interfaces -{ - public interface IOperationDispatcher - { - int LoadFile(Stream outStream, string fileName); - int GetFileSize(string fileName); - } -} +using System.IO; + +namespace OpenKh.Tools.ModsManager.Interfaces +{ + public interface IOperationDispatcher + { + int LoadFile(Stream outStream, string fileName); + int GetFileSize(string fileName); + } +} diff --git a/OpenKh.Tools.ModsManager/Models/GameInfoModel.cs b/OpenKh.Tools.ModsManager/Models/GameInfoModel.cs index 7db79a6eb..ae2862630 100644 --- a/OpenKh.Tools.ModsManager/Models/GameInfoModel.cs +++ b/OpenKh.Tools.ModsManager/Models/GameInfoModel.cs @@ -1,17 +1,17 @@ -using System.Collections.Generic; - -namespace OpenKh.Tools.ModsManager.Models -{ - public record GameInfoModel - { - public string Id { get; init; } - public string Name { get; init; } - public List Detectors { get; init; } - } - - public record GameDetectorModel - { - public string FileName { get; init; } - public string ProductId { get; init; } - } -} +using System.Collections.Generic; + +namespace OpenKh.Tools.ModsManager.Models +{ + public record GameInfoModel + { + public string Id { get; init; } + public string Name { get; init; } + public List Detectors { get; init; } + } + + public record GameDetectorModel + { + public string FileName { get; init; } + public string ProductId { get; init; } + } +} diff --git a/OpenKh.Tools.ModsManager/Models/ModModel.cs b/OpenKh.Tools.ModsManager/Models/ModModel.cs index b51257a22..d5708ed6c 100644 --- a/OpenKh.Tools.ModsManager/Models/ModModel.cs +++ b/OpenKh.Tools.ModsManager/Models/ModModel.cs @@ -1,14 +1,14 @@ -using OpenKh.Patcher; - -namespace OpenKh.Tools.ModsManager.Models -{ - public class ModModel - { - public string Name { get; set; } - public string Path { get; set; } - public string IconImageSource { get; set; } - public string PreviewImageSource { get; set; } - public Metadata Metadata { get; set; } - public bool IsEnabled { get; set; } - } -} +using OpenKh.Patcher; + +namespace OpenKh.Tools.ModsManager.Models +{ + public class ModModel + { + public string Name { get; set; } + public string Path { get; set; } + public string IconImageSource { get; set; } + public string PreviewImageSource { get; set; } + public Metadata Metadata { get; set; } + public bool IsEnabled { get; set; } + } +} diff --git a/OpenKh.Tools.ModsManager/Models/ModUpdateModel.cs b/OpenKh.Tools.ModsManager/Models/ModUpdateModel.cs index feefc6953..a6e04109e 100644 --- a/OpenKh.Tools.ModsManager/Models/ModUpdateModel.cs +++ b/OpenKh.Tools.ModsManager/Models/ModUpdateModel.cs @@ -1,8 +1,8 @@ -namespace OpenKh.Tools.ModsManager.Models -{ - public class ModUpdateModel - { - public string Name { get; set; } - public int UpdateCount { get; set; } - } -} +namespace OpenKh.Tools.ModsManager.Models +{ + public class ModUpdateModel + { + public string Name { get; set; } + public int UpdateCount { get; set; } + } +} diff --git a/OpenKh.Tools.ModsManager/Services/ConfigurationService.cs b/OpenKh.Tools.ModsManager/Services/ConfigurationService.cs index 6589f2816..ac37b9665 100644 --- a/OpenKh.Tools.ModsManager/Services/ConfigurationService.cs +++ b/OpenKh.Tools.ModsManager/Services/ConfigurationService.cs @@ -1,195 +1,195 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net.Http; -using System.Threading.Tasks; -using YamlDotNet.Serialization; -using YamlDotNet.Serialization.NamingConventions; - -namespace OpenKh.Tools.ModsManager.Services -{ - public static class ConfigurationService - { - private class Config - { - private static readonly IDeserializer _deserializer = - new DeserializerBuilder() - .IgnoreFields() - .IgnoreUnmatchedProperties() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build(); - private static readonly ISerializer _serializer = - new SerializerBuilder() - .IgnoreFields() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build(); - - public bool IsFirstRunComplete { get; set; } - public string ModCollectionPath { get; internal set; } - public string GameModPath { get; internal set; } - public string GameDataPath { get; internal set; } - public int GameEdition { get; internal set; } - public string IsoLocation { get; internal set; } - public string OpenKhGameEngineLocation { get; internal set; } - public string Pcsx2Location { get; internal set; } - public string PcReleaseLocation { get; internal set; } - public int RegionId { get; internal set; } - - public void Save(string fileName) - { - using var writer = new StreamWriter(fileName); - _serializer.Serialize(writer, this); - } - - public static Config Open(string fileName) - { - if (!File.Exists(fileName)) - return new Config(); - - using var reader = new StreamReader(fileName); - return _deserializer.Deserialize(reader); - } - } - - private const string ConfigPath = "mods-manager.yml"; - private const string EnabledModsPath = "mods.txt"; - private static readonly Config _config = Config.Open(ConfigPath); - - static ConfigurationService() - { - if (!Directory.Exists(ModCollectionPath)) - Directory.CreateDirectory(ModCollectionPath); - - Task.Run(async () => - { - using var client = new HttpClient(); - var response = await client - .GetAsync("https://raw.githubusercontent.com/OpenKH/mods-manager-feed/main/featured.txt"); - FeaturedMods = (await response.Content.ReadAsStringAsync()) - .Split("\n") - .Where(x => !string.IsNullOrEmpty(x)) - .ToList(); - }); - - Task.Run(async () => - { - using var client = new HttpClient(); - var response = await client - .GetAsync("https://raw.githubusercontent.com/OpenKH/mods-manager-feed/main/deny.txt"); - BlacklistedMods = (await response.Content.ReadAsStringAsync()) - .Split("\n") - .Where(x => !string.IsNullOrEmpty(x)) - .ToList(); - }); - } - - public static ICollection EnabledMods - { - get => File.Exists(EnabledModsPath) ? File.ReadAllLines(EnabledModsPath) : new string[0]; - set => File.WriteAllLines(EnabledModsPath, value); - } - - public static ICollection FeaturedMods { get; private set; } - public static ICollection BlacklistedMods { get; private set; } - - public static bool IsFirstRunComplete - { - get => _config.IsFirstRunComplete; - set - { - _config.IsFirstRunComplete = value; - _config.Save(ConfigPath); - } - } - - public static string ModCollectionPath - { - get => _config.ModCollectionPath ?? Path.GetFullPath("mods"); - set - { - _config.ModCollectionPath = value; - _config.Save(ConfigPath); - } - } - - public static string GameModPath - { - get => _config.GameModPath ?? Path.GetFullPath("mod"); - set - { - _config.GameModPath = value; - _config.Save(ConfigPath); - } - } - - public static string GameDataLocation - { - get => _config.GameDataPath ?? Path.GetFullPath("data"); - set - { - _config.GameDataPath = value; - _config.Save(ConfigPath); - } - } - - public static int GameEdition - { - get => _config.GameEdition; - set - { - _config.GameEdition = value; - _config.Save(ConfigPath); - } - } - - public static string IsoLocation - { - get => _config.IsoLocation; - set - { - _config.IsoLocation = value; - _config.Save(ConfigPath); - } - } - - public static string OpenKhGameEngineLocation - { - get => _config.OpenKhGameEngineLocation ?? Path.GetFullPath("OpenKh.Game.exe"); - set - { - _config.OpenKhGameEngineLocation = value; - _config.Save(ConfigPath); - } - } - - public static string Pcsx2Location - { - get => _config.Pcsx2Location; - set - { - _config.Pcsx2Location = value; - _config.Save(ConfigPath); - } - } - - public static string PcReleaseLocation - { - get => _config.PcReleaseLocation; - set - { - _config.PcReleaseLocation = value; - _config.Save(ConfigPath); - } - } - - public static int RegionId - { - get => _config.RegionId; - set - { - _config.RegionId = value; - _config.Save(ConfigPath); - } - } - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; + +namespace OpenKh.Tools.ModsManager.Services +{ + public static class ConfigurationService + { + private class Config + { + private static readonly IDeserializer _deserializer = + new DeserializerBuilder() + .IgnoreFields() + .IgnoreUnmatchedProperties() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build(); + private static readonly ISerializer _serializer = + new SerializerBuilder() + .IgnoreFields() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build(); + + public bool IsFirstRunComplete { get; set; } + public string ModCollectionPath { get; internal set; } + public string GameModPath { get; internal set; } + public string GameDataPath { get; internal set; } + public int GameEdition { get; internal set; } + public string IsoLocation { get; internal set; } + public string OpenKhGameEngineLocation { get; internal set; } + public string Pcsx2Location { get; internal set; } + public string PcReleaseLocation { get; internal set; } + public int RegionId { get; internal set; } + + public void Save(string fileName) + { + using var writer = new StreamWriter(fileName); + _serializer.Serialize(writer, this); + } + + public static Config Open(string fileName) + { + if (!File.Exists(fileName)) + return new Config(); + + using var reader = new StreamReader(fileName); + return _deserializer.Deserialize(reader); + } + } + + private const string ConfigPath = "mods-manager.yml"; + private const string EnabledModsPath = "mods.txt"; + private static readonly Config _config = Config.Open(ConfigPath); + + static ConfigurationService() + { + if (!Directory.Exists(ModCollectionPath)) + Directory.CreateDirectory(ModCollectionPath); + + Task.Run(async () => + { + using var client = new HttpClient(); + var response = await client + .GetAsync("https://raw.githubusercontent.com/OpenKH/mods-manager-feed/main/featured.txt"); + FeaturedMods = (await response.Content.ReadAsStringAsync()) + .Split("\n") + .Where(x => !string.IsNullOrEmpty(x)) + .ToList(); + }); + + Task.Run(async () => + { + using var client = new HttpClient(); + var response = await client + .GetAsync("https://raw.githubusercontent.com/OpenKH/mods-manager-feed/main/deny.txt"); + BlacklistedMods = (await response.Content.ReadAsStringAsync()) + .Split("\n") + .Where(x => !string.IsNullOrEmpty(x)) + .ToList(); + }); + } + + public static ICollection EnabledMods + { + get => File.Exists(EnabledModsPath) ? File.ReadAllLines(EnabledModsPath) : new string[0]; + set => File.WriteAllLines(EnabledModsPath, value); + } + + public static ICollection FeaturedMods { get; private set; } + public static ICollection BlacklistedMods { get; private set; } + + public static bool IsFirstRunComplete + { + get => _config.IsFirstRunComplete; + set + { + _config.IsFirstRunComplete = value; + _config.Save(ConfigPath); + } + } + + public static string ModCollectionPath + { + get => _config.ModCollectionPath ?? Path.GetFullPath("mods"); + set + { + _config.ModCollectionPath = value; + _config.Save(ConfigPath); + } + } + + public static string GameModPath + { + get => _config.GameModPath ?? Path.GetFullPath("mod"); + set + { + _config.GameModPath = value; + _config.Save(ConfigPath); + } + } + + public static string GameDataLocation + { + get => _config.GameDataPath ?? Path.GetFullPath("data"); + set + { + _config.GameDataPath = value; + _config.Save(ConfigPath); + } + } + + public static int GameEdition + { + get => _config.GameEdition; + set + { + _config.GameEdition = value; + _config.Save(ConfigPath); + } + } + + public static string IsoLocation + { + get => _config.IsoLocation; + set + { + _config.IsoLocation = value; + _config.Save(ConfigPath); + } + } + + public static string OpenKhGameEngineLocation + { + get => _config.OpenKhGameEngineLocation ?? Path.GetFullPath("OpenKh.Game.exe"); + set + { + _config.OpenKhGameEngineLocation = value; + _config.Save(ConfigPath); + } + } + + public static string Pcsx2Location + { + get => _config.Pcsx2Location; + set + { + _config.Pcsx2Location = value; + _config.Save(ConfigPath); + } + } + + public static string PcReleaseLocation + { + get => _config.PcReleaseLocation; + set + { + _config.PcReleaseLocation = value; + _config.Save(ConfigPath); + } + } + + public static int RegionId + { + get => _config.RegionId; + set + { + _config.RegionId = value; + _config.Save(ConfigPath); + } + } + } +} diff --git a/OpenKh.Tools.ModsManager/Services/GameService.cs b/OpenKh.Tools.ModsManager/Services/GameService.cs index eb0f10f0d..78dee0ef1 100644 --- a/OpenKh.Tools.ModsManager/Services/GameService.cs +++ b/OpenKh.Tools.ModsManager/Services/GameService.cs @@ -1,56 +1,56 @@ -using OpenKh.Common; -using OpenKh.Tools.ModsManager.Models; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace OpenKh.Tools.ModsManager.Services -{ - public static class GameService - { - private const int BlockIso = 0x800; - private static readonly List Games = new() - { - new GameInfoModel() - { - Id = "kh2", - Name = "Kingdom Hearts II", - Detectors = new() - { - new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLPM_662.33;1" }, - new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLUS_210.05;1" }, - new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SCUS_210.05;1" }, - new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_541.44;1" }, - new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_542.32;1" }, - new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_542.33;1" }, - new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_542.34;1" }, - new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLPM_666.75;1" }, - } - }, - }; - - public static GameInfoModel DetectGameId(string isoFilePath) - { - using var stream = File.OpenRead(isoFilePath); - foreach (var game in Games) - { - foreach (var detector in game.Detectors) - { - var blockIndex = IsoUtility.GetFileOffset(stream, detector.FileName); - if (blockIndex < 0) - continue; - - var data = stream.SetPosition(blockIndex * BlockIso).ReadBytes(BlockIso); - var expectData = Encoding.UTF8.GetBytes(detector.ProductId); - if (string.Join(' ', data).Contains(string.Join(' ', expectData))) // TODO: inefficient, but it works lol - return game; - } - } - - return default; - } - - public static GameInfoModel Lookup(string gameId) => Games.FirstOrDefault(x => x.Id == gameId); - } -} +using OpenKh.Common; +using OpenKh.Tools.ModsManager.Models; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace OpenKh.Tools.ModsManager.Services +{ + public static class GameService + { + private const int BlockIso = 0x800; + private static readonly List Games = new() + { + new GameInfoModel() + { + Id = "kh2", + Name = "Kingdom Hearts II", + Detectors = new() + { + new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLPM_662.33;1" }, + new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLUS_210.05;1" }, + new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SCUS_210.05;1" }, + new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_541.44;1" }, + new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_542.32;1" }, + new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_542.33;1" }, + new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_542.34;1" }, + new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLPM_666.75;1" }, + } + }, + }; + + public static GameInfoModel DetectGameId(string isoFilePath) + { + using var stream = File.OpenRead(isoFilePath); + foreach (var game in Games) + { + foreach (var detector in game.Detectors) + { + var blockIndex = IsoUtility.GetFileOffset(stream, detector.FileName); + if (blockIndex < 0) + continue; + + var data = stream.SetPosition(blockIndex * BlockIso).ReadBytes(BlockIso); + var expectData = Encoding.UTF8.GetBytes(detector.ProductId); + if (string.Join(' ', data).Contains(string.Join(' ', expectData))) // TODO: inefficient, but it works lol + return game; + } + } + + return default; + } + + public static GameInfoModel Lookup(string gameId) => Games.FirstOrDefault(x => x.Id == gameId); + } +} diff --git a/OpenKh.Tools.ModsManager/Services/ModsService.cs b/OpenKh.Tools.ModsManager/Services/ModsService.cs index 464fbd779..e68025c69 100644 --- a/OpenKh.Tools.ModsManager/Services/ModsService.cs +++ b/OpenKh.Tools.ModsManager/Services/ModsService.cs @@ -1,283 +1,283 @@ -using LibGit2Sharp; -using OpenKh.Common; -using OpenKh.Patcher; -using OpenKh.Tools.ModsManager.Exceptions; -using OpenKh.Tools.ModsManager.Models; -using System; -using System.Collections.Generic; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Threading.Tasks; -using static OpenKh.Tools.ModsManager.Helpers; - -namespace OpenKh.Tools.ModsManager.Services -{ - public static class ModsService - { - private const string ModMetadata = "mod.yml"; - private const string DefaultGitBranch = "main"; - - public static IEnumerable Mods - { - get - { - var allMods = UnorderedMods.ToList(); - var enabledMods = EnabledMods.ToHashSet(); - var disabledMods = new List(allMods.Count); - foreach (var mod in allMods) - { - if (!enabledMods.Contains(mod)) - disabledMods.Add(mod); - } - - return enabledMods.Concat(disabledMods); - } - } - - public static IEnumerable UnorderedMods - { - get - { - var modsPath = ConfigurationService.ModCollectionPath; - foreach (var dir in Directory.GetDirectories(modsPath)) - { - var authorName = Path.GetFileName(dir); - foreach (var subdir in Directory.GetDirectories(dir)) - { - var repoName = Path.GetFileName(subdir); - if (File.Exists(Path.Combine(subdir, ModMetadata))) - yield return $"{authorName}/{repoName}"; - } - - if (File.Exists(Path.Combine(dir, ModMetadata))) - yield return authorName; - } - } - } - - public static IEnumerable EnabledMods - { - get - { - var mods = UnorderedMods.ToList(); - foreach (var mod in ConfigurationService.EnabledMods) - { - if (mods.Contains(mod)) - yield return mod; - } - } - } - - public static bool IsModBlocked(string repositoryName) => - ConfigurationService.BlacklistedMods.Any(x => x.Equals(repositoryName, StringComparison.InvariantCultureIgnoreCase)); - - public static bool IsUserBlocked(string repositoryName) => - IsModBlocked(Path.GetDirectoryName(repositoryName)); - - public static Task InstallMod( - string name, - bool isZipFile, - Action progressOutput = null, - Action progressNumber = null) - { - return isZipFile ? - Task.Run(() => InstallModFromZip(name, progressOutput, progressNumber)) : - InstallModFromGithub(name, progressOutput, progressNumber); - } - - public static void InstallModFromZip( - string fileName, - Action progressOutput = null, - Action progressNumber = null) - { - var modName = Path.GetFileNameWithoutExtension(fileName); - progressOutput?.Invoke($"Opening '{modName}' zip archive..."); - - using var zipFile = ZipFile.OpenRead(fileName); - var isValidMod = zipFile.GetEntry(ModMetadata) != null; - if (!isValidMod) - throw new ModNotValidException(modName); - - var modPath = GetModPath(modName); - if (Directory.Exists(modPath)) - throw new ModAlreadyExistsExceptions(modName); - Directory.CreateDirectory(modPath); - - var entryExtractCount = 0; - var entryCount = zipFile.Entries.Count; - foreach (var entry in zipFile.Entries.Where(x => (x.ExternalAttributes & 0x10) != 0x10)) - { - progressOutput?.Invoke($"Extracting '{entry.FullName}'..."); - progressNumber?.Invoke((float)entryExtractCount / entryCount); - var dstFileName = Path.Combine(modPath, entry.FullName); - var dstFilePath = Path.GetDirectoryName(dstFileName); - if (!Directory.Exists(dstFilePath)) - Directory.CreateDirectory(dstFilePath); - File.Create(dstFileName) - .Using(outStream => - { - using var zipStream = entry.Open(); - zipStream.CopyTo(outStream); - }); - - entryExtractCount++; - } - } - - public static async Task InstallModFromGithub( - string repositoryName, - Action progressOutput = null, - Action progressNumber = null) - { - var branchName = DefaultGitBranch; - progressOutput?.Invoke($"Fetching file {ModMetadata} from {branchName}"); - var isValidMod = await RepositoryService.IsFileExists(repositoryName, branchName, ModMetadata); - if (!isValidMod) - { - progressOutput?.Invoke($"{ModMetadata} not found, fetching default branch name"); - branchName = await RepositoryService.GetMainBranchFromRepository(repositoryName); - if (branchName == null) - throw new RepositoryNotFoundException(repositoryName); - - progressOutput?.Invoke($"Fetching file {ModMetadata} from {branchName}"); - isValidMod = await RepositoryService.IsFileExists(repositoryName, branchName, ModMetadata); - } - - if (!isValidMod) - throw new ModNotValidException(repositoryName); - - var modPath = GetModPath(repositoryName); - if (Directory.Exists(modPath)) - throw new ModAlreadyExistsExceptions(repositoryName); - Directory.CreateDirectory(modPath); - - progressOutput?.Invoke($"Mod found, initializing cloning process"); - await Task.Run(() => - { - var options = new CloneOptions - { - RecurseSubmodules = true, - OnProgress = (serverProgressOutput) => - { - progressOutput?.Invoke(serverProgressOutput); - return true; - }, - OnTransferProgress = (progress) => - { - var nProgress = (progress.IndexedObjects + progress.ReceivedObjects) / (progress.TotalObjects * 2); - progressNumber?.Invoke(nProgress); - return true; - } - }; - - Repository.Clone($"https://github.com/{repositoryName}", modPath, options); - }); - } - - public static string GetModPath(string author, string repo) => - Path.Combine(ConfigurationService.ModCollectionPath, author, repo); - - public static string GetModPath(string repositoryName) => - Path.Combine(ConfigurationService.ModCollectionPath, repositoryName); - - public static IEnumerable GetMods(IEnumerable modNames) - { - var enabledMods = ConfigurationService.EnabledMods; - foreach (var modName in modNames) - { - var modPath = GetModPath(modName); - yield return new ModModel - { - Name = modName, - Path = modPath, - IconImageSource = Path.Combine(modPath, "icon.png"), - PreviewImageSource = Path.Combine(modPath, "preview.png"), - Metadata = File.OpenRead(Path.Combine(modPath, ModMetadata)).Using(Metadata.Read), - IsEnabled = enabledMods.Contains(modName) - }; - } - } - - public static async IAsyncEnumerable FetchUpdates() - { - foreach (var modName in Mods) - { - var modPath = GetModPath(modName); - var updateCount = await RepositoryService.FetchUpdate(modPath); - if (updateCount > 0) - yield return new ModUpdateModel - { - Name = modName, - UpdateCount = updateCount - }; - } - } - - public static Task Update(string modName, - Action progressOutput = null, - Action progressNumber = null) => - RepositoryService.FetchAndResetUponOrigin(GetModPath(modName), progressOutput, progressNumber); - - public static Task RunPacherAsync() => Task.Run(() => Handle(() => - { - if (Directory.Exists(ConfigurationService.GameModPath)) - { - try - { - Directory.Delete(ConfigurationService.GameModPath, true); - } - catch (Exception ex) - { - Log.Warn("Unable to fully clean the mod directory:\n{0}", ex.Message); - } - } - Directory.CreateDirectory(ConfigurationService.GameModPath); - - var patcherProcessor = new PatcherProcessor(); - var modsList = GetMods(EnabledMods).ToList(); - for (var i = modsList.Count - 1; i >= 0; i--) - { - var mod = modsList[i]; - Log.Info($"Patching using {mod.Name} from {mod.Path}"); - - patcherProcessor.Patch( - ConfigurationService.GameDataLocation, - ConfigurationService.GameModPath, - mod.Metadata, - mod.Path); - } - - return true; - })); - - private static string GetSourceFromUrl(string url) - { - var projectNameIndex = url.LastIndexOf('/'); - if (projectNameIndex < 0) - return null; - var projectName = url.Substring(projectNameIndex + 1); - if (projectName.EndsWith(".git")) - projectName = projectName.Substring(0, projectName.Length - 4); - - var firstPart = url.Substring(0, projectNameIndex); - var authorNameIndex = firstPart.LastIndexOf('/'); - if (authorNameIndex < 0) - authorNameIndex = firstPart.LastIndexOf(':'); - if (authorNameIndex < 0) - return null; - var authorName = firstPart.Substring(authorNameIndex + 1); - - return $"{authorName}/{projectName}"; - } - - private static string GetSourceFromRepository(Repository repository) - { - if (repository == null) - return null; - - var remote = repository.Network.Remotes.FirstOrDefault(); - return remote != null ? GetSourceFromUrl(remote.Url) : null; - } - } -} +using LibGit2Sharp; +using OpenKh.Common; +using OpenKh.Patcher; +using OpenKh.Tools.ModsManager.Exceptions; +using OpenKh.Tools.ModsManager.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Threading.Tasks; +using static OpenKh.Tools.ModsManager.Helpers; + +namespace OpenKh.Tools.ModsManager.Services +{ + public static class ModsService + { + private const string ModMetadata = "mod.yml"; + private const string DefaultGitBranch = "main"; + + public static IEnumerable Mods + { + get + { + var allMods = UnorderedMods.ToList(); + var enabledMods = EnabledMods.ToHashSet(); + var disabledMods = new List(allMods.Count); + foreach (var mod in allMods) + { + if (!enabledMods.Contains(mod)) + disabledMods.Add(mod); + } + + return enabledMods.Concat(disabledMods); + } + } + + public static IEnumerable UnorderedMods + { + get + { + var modsPath = ConfigurationService.ModCollectionPath; + foreach (var dir in Directory.GetDirectories(modsPath)) + { + var authorName = Path.GetFileName(dir); + foreach (var subdir in Directory.GetDirectories(dir)) + { + var repoName = Path.GetFileName(subdir); + if (File.Exists(Path.Combine(subdir, ModMetadata))) + yield return $"{authorName}/{repoName}"; + } + + if (File.Exists(Path.Combine(dir, ModMetadata))) + yield return authorName; + } + } + } + + public static IEnumerable EnabledMods + { + get + { + var mods = UnorderedMods.ToList(); + foreach (var mod in ConfigurationService.EnabledMods) + { + if (mods.Contains(mod)) + yield return mod; + } + } + } + + public static bool IsModBlocked(string repositoryName) => + ConfigurationService.BlacklistedMods.Any(x => x.Equals(repositoryName, StringComparison.InvariantCultureIgnoreCase)); + + public static bool IsUserBlocked(string repositoryName) => + IsModBlocked(Path.GetDirectoryName(repositoryName)); + + public static Task InstallMod( + string name, + bool isZipFile, + Action progressOutput = null, + Action progressNumber = null) + { + return isZipFile ? + Task.Run(() => InstallModFromZip(name, progressOutput, progressNumber)) : + InstallModFromGithub(name, progressOutput, progressNumber); + } + + public static void InstallModFromZip( + string fileName, + Action progressOutput = null, + Action progressNumber = null) + { + var modName = Path.GetFileNameWithoutExtension(fileName); + progressOutput?.Invoke($"Opening '{modName}' zip archive..."); + + using var zipFile = ZipFile.OpenRead(fileName); + var isValidMod = zipFile.GetEntry(ModMetadata) != null; + if (!isValidMod) + throw new ModNotValidException(modName); + + var modPath = GetModPath(modName); + if (Directory.Exists(modPath)) + throw new ModAlreadyExistsExceptions(modName); + Directory.CreateDirectory(modPath); + + var entryExtractCount = 0; + var entryCount = zipFile.Entries.Count; + foreach (var entry in zipFile.Entries.Where(x => (x.ExternalAttributes & 0x10) != 0x10)) + { + progressOutput?.Invoke($"Extracting '{entry.FullName}'..."); + progressNumber?.Invoke((float)entryExtractCount / entryCount); + var dstFileName = Path.Combine(modPath, entry.FullName); + var dstFilePath = Path.GetDirectoryName(dstFileName); + if (!Directory.Exists(dstFilePath)) + Directory.CreateDirectory(dstFilePath); + File.Create(dstFileName) + .Using(outStream => + { + using var zipStream = entry.Open(); + zipStream.CopyTo(outStream); + }); + + entryExtractCount++; + } + } + + public static async Task InstallModFromGithub( + string repositoryName, + Action progressOutput = null, + Action progressNumber = null) + { + var branchName = DefaultGitBranch; + progressOutput?.Invoke($"Fetching file {ModMetadata} from {branchName}"); + var isValidMod = await RepositoryService.IsFileExists(repositoryName, branchName, ModMetadata); + if (!isValidMod) + { + progressOutput?.Invoke($"{ModMetadata} not found, fetching default branch name"); + branchName = await RepositoryService.GetMainBranchFromRepository(repositoryName); + if (branchName == null) + throw new RepositoryNotFoundException(repositoryName); + + progressOutput?.Invoke($"Fetching file {ModMetadata} from {branchName}"); + isValidMod = await RepositoryService.IsFileExists(repositoryName, branchName, ModMetadata); + } + + if (!isValidMod) + throw new ModNotValidException(repositoryName); + + var modPath = GetModPath(repositoryName); + if (Directory.Exists(modPath)) + throw new ModAlreadyExistsExceptions(repositoryName); + Directory.CreateDirectory(modPath); + + progressOutput?.Invoke($"Mod found, initializing cloning process"); + await Task.Run(() => + { + var options = new CloneOptions + { + RecurseSubmodules = true, + OnProgress = (serverProgressOutput) => + { + progressOutput?.Invoke(serverProgressOutput); + return true; + }, + OnTransferProgress = (progress) => + { + var nProgress = (progress.IndexedObjects + progress.ReceivedObjects) / (progress.TotalObjects * 2); + progressNumber?.Invoke(nProgress); + return true; + } + }; + + Repository.Clone($"https://github.com/{repositoryName}", modPath, options); + }); + } + + public static string GetModPath(string author, string repo) => + Path.Combine(ConfigurationService.ModCollectionPath, author, repo); + + public static string GetModPath(string repositoryName) => + Path.Combine(ConfigurationService.ModCollectionPath, repositoryName); + + public static IEnumerable GetMods(IEnumerable modNames) + { + var enabledMods = ConfigurationService.EnabledMods; + foreach (var modName in modNames) + { + var modPath = GetModPath(modName); + yield return new ModModel + { + Name = modName, + Path = modPath, + IconImageSource = Path.Combine(modPath, "icon.png"), + PreviewImageSource = Path.Combine(modPath, "preview.png"), + Metadata = File.OpenRead(Path.Combine(modPath, ModMetadata)).Using(Metadata.Read), + IsEnabled = enabledMods.Contains(modName) + }; + } + } + + public static async IAsyncEnumerable FetchUpdates() + { + foreach (var modName in Mods) + { + var modPath = GetModPath(modName); + var updateCount = await RepositoryService.FetchUpdate(modPath); + if (updateCount > 0) + yield return new ModUpdateModel + { + Name = modName, + UpdateCount = updateCount + }; + } + } + + public static Task Update(string modName, + Action progressOutput = null, + Action progressNumber = null) => + RepositoryService.FetchAndResetUponOrigin(GetModPath(modName), progressOutput, progressNumber); + + public static Task RunPacherAsync() => Task.Run(() => Handle(() => + { + if (Directory.Exists(ConfigurationService.GameModPath)) + { + try + { + Directory.Delete(ConfigurationService.GameModPath, true); + } + catch (Exception ex) + { + Log.Warn("Unable to fully clean the mod directory:\n{0}", ex.Message); + } + } + Directory.CreateDirectory(ConfigurationService.GameModPath); + + var patcherProcessor = new PatcherProcessor(); + var modsList = GetMods(EnabledMods).ToList(); + for (var i = modsList.Count - 1; i >= 0; i--) + { + var mod = modsList[i]; + Log.Info($"Patching using {mod.Name} from {mod.Path}"); + + patcherProcessor.Patch( + ConfigurationService.GameDataLocation, + ConfigurationService.GameModPath, + mod.Metadata, + mod.Path); + } + + return true; + })); + + private static string GetSourceFromUrl(string url) + { + var projectNameIndex = url.LastIndexOf('/'); + if (projectNameIndex < 0) + return null; + var projectName = url.Substring(projectNameIndex + 1); + if (projectName.EndsWith(".git")) + projectName = projectName.Substring(0, projectName.Length - 4); + + var firstPart = url.Substring(0, projectNameIndex); + var authorNameIndex = firstPart.LastIndexOf('/'); + if (authorNameIndex < 0) + authorNameIndex = firstPart.LastIndexOf(':'); + if (authorNameIndex < 0) + return null; + var authorName = firstPart.Substring(authorNameIndex + 1); + + return $"{authorName}/{projectName}"; + } + + private static string GetSourceFromRepository(Repository repository) + { + if (repository == null) + return null; + + var remote = repository.Network.Remotes.FirstOrDefault(); + return remote != null ? GetSourceFromUrl(remote.Url) : null; + } + } +} diff --git a/OpenKh.Tools.ModsManager/Services/OperationDispatcher.cs b/OpenKh.Tools.ModsManager/Services/OperationDispatcher.cs index 1745af362..cd38ce0fe 100644 --- a/OpenKh.Tools.ModsManager/Services/OperationDispatcher.cs +++ b/OpenKh.Tools.ModsManager/Services/OperationDispatcher.cs @@ -1,100 +1,100 @@ -using OpenKh.Common; -using OpenKh.Tools.ModsManager.Interfaces; -using System.Collections.Generic; -using System.IO; - -namespace OpenKh.Tools.ModsManager.Services -{ - public class OperationDispatcher : IOperationDispatcher - { - private static readonly string[] _regionFallback = new[] - { - "us", "fm", "jp", "uk", "it", "fr", "es", "de" - }; - - private static readonly HashSet _denyList = new HashSet - { - "ovl_title.x", - "ovl_shop.x", - "ovl_movie.x", - "ovl_gumibattle.x", - "ovl_gumimenu.x", - "ovl_gumimenu.x", - }; - - public int LoadFile(Stream outStream, string fileName) - { - if (GetFinalNamePath(fileName, out var finalFileName)) - { - Log.Info($"Load file {finalFileName}"); - return File.OpenRead(finalFileName).Using(x => - { - x.CopyTo(outStream, 512 * 1024); - return (int)x.Length; - }); - } - - Log.Warn($"File {fileName} not found, falling back"); - return 0; - } - - public int GetFileSize(string fileName) - { - if (GetFinalNamePath(fileName, out var finalFileName)) - return (int)new FileInfo(finalFileName).Length; - - return 0; - } - - private bool GetFinalNamePath(string fileName, out string finalFileName) - { - if (_denyList.Contains(fileName)) - { - finalFileName = null; - return false; - } - - finalFileName = Path.Combine(ConfigurationService.GameModPath, fileName); - if (File.Exists(finalFileName)) - return true; - - finalFileName = Path.Combine(ConfigurationService.GameDataLocation, fileName); - if (File.Exists(finalFileName)) - return true; - - var region = GetRegion(fileName); - if (region == null) - return false; - - foreach (var fallback in _regionFallback) - { - var temptativeRegionalFallbackFileName = fileName - .Replace($"/{region}/", $"/{fallback}/") - .Replace($".a.{region}", $".a.{fallback}") - .Replace($".apdx", $".a.{fallback}"); - finalFileName = Path.Combine(ConfigurationService.GameModPath, temptativeRegionalFallbackFileName); - if (File.Exists(finalFileName)) - return true; - - finalFileName = Path.Combine(ConfigurationService.GameDataLocation, temptativeRegionalFallbackFileName); - if (File.Exists(finalFileName)) - return true; - } - - finalFileName = null; - return false; - } - - private static string GetRegion(string fileName) - { - foreach (var region in Kh2.Constants.Regions) - { - if (fileName.Contains($"/{region}/") || - fileName.EndsWith($".a.{region}")) - return region; - } - - return null; - } - } -} +using OpenKh.Common; +using OpenKh.Tools.ModsManager.Interfaces; +using System.Collections.Generic; +using System.IO; + +namespace OpenKh.Tools.ModsManager.Services +{ + public class OperationDispatcher : IOperationDispatcher + { + private static readonly string[] _regionFallback = new[] + { + "us", "fm", "jp", "uk", "it", "fr", "es", "de" + }; + + private static readonly HashSet _denyList = new HashSet + { + "ovl_title.x", + "ovl_shop.x", + "ovl_movie.x", + "ovl_gumibattle.x", + "ovl_gumimenu.x", + "ovl_gumimenu.x", + }; + + public int LoadFile(Stream outStream, string fileName) + { + if (GetFinalNamePath(fileName, out var finalFileName)) + { + Log.Info($"Load file {finalFileName}"); + return File.OpenRead(finalFileName).Using(x => + { + x.CopyTo(outStream, 512 * 1024); + return (int)x.Length; + }); + } + + Log.Warn($"File {fileName} not found, falling back"); + return 0; + } + + public int GetFileSize(string fileName) + { + if (GetFinalNamePath(fileName, out var finalFileName)) + return (int)new FileInfo(finalFileName).Length; + + return 0; + } + + private bool GetFinalNamePath(string fileName, out string finalFileName) + { + if (_denyList.Contains(fileName)) + { + finalFileName = null; + return false; + } + + finalFileName = Path.Combine(ConfigurationService.GameModPath, fileName); + if (File.Exists(finalFileName)) + return true; + + finalFileName = Path.Combine(ConfigurationService.GameDataLocation, fileName); + if (File.Exists(finalFileName)) + return true; + + var region = GetRegion(fileName); + if (region == null) + return false; + + foreach (var fallback in _regionFallback) + { + var temptativeRegionalFallbackFileName = fileName + .Replace($"/{region}/", $"/{fallback}/") + .Replace($".a.{region}", $".a.{fallback}") + .Replace($".apdx", $".a.{fallback}"); + finalFileName = Path.Combine(ConfigurationService.GameModPath, temptativeRegionalFallbackFileName); + if (File.Exists(finalFileName)) + return true; + + finalFileName = Path.Combine(ConfigurationService.GameDataLocation, temptativeRegionalFallbackFileName); + if (File.Exists(finalFileName)) + return true; + } + + finalFileName = null; + return false; + } + + private static string GetRegion(string fileName) + { + foreach (var region in Kh2.Constants.Regions) + { + if (fileName.Contains($"/{region}/") || + fileName.EndsWith($".a.{region}")) + return region; + } + + return null; + } + } +} diff --git a/OpenKh.Tools.ModsManager/Services/Pcsx2Injector.cs b/OpenKh.Tools.ModsManager/Services/Pcsx2Injector.cs index 6937dd545..228520703 100644 --- a/OpenKh.Tools.ModsManager/Services/Pcsx2Injector.cs +++ b/OpenKh.Tools.ModsManager/Services/Pcsx2Injector.cs @@ -1,536 +1,536 @@ -using OpenKh.Common; -using OpenKh.Tools.Common; -using OpenKh.Tools.ModsManager.Interfaces; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace OpenKh.Tools.ModsManager.Services -{ - public class Pcsx2Injector - { - private class Offsets - { - public string GameName { get; init; } - public int LoadFile { get; init; } - public int GetFileSize { get; init; } - public int RegionInit { get; init; } - public int BufferPointer { get; init; } - public int RegionForce { get; init; } - public int RegionId { get; init; } - public int RegionPtr { get; init; } - public int LanguagePtr { get; init; } - } - - private class Patch - { - public string Game { get; init; } - public string Name { get; init; } - public int Address { get; init; } - public uint[] Pattern { get; init; } - public uint[] NewPattern { get; init; } - } - - private const string KH2FM = "SLPM_666.75;1"; - - private const uint Zero = 0x00; - private const uint AT = 0x01; - private const uint V0 = 0x02; - private const uint V1 = 0x03; - private const uint A0 = 0x04; - private const uint A1 = 0x05; - private const uint A2 = 0x06; - private const uint A3 = 0x07; - private const uint T0 = 0x08; - private const uint T1 = 0x09; - private const uint T2 = 0x0A; - private const uint T3 = 0x0B; - private const uint T4 = 0x0C; - private const uint T5 = 0x0D; - private const uint T6 = 0x0E; - private const uint T7 = 0x0F; - private const uint S0 = 0x10; - private const uint S1 = 0x11; - private const uint S2 = 0x12; - private const uint S3 = 0x13; - private const uint S4 = 0x14; - private const uint S5 = 0x15; - private const uint S6 = 0x16; - private const uint S7 = 0x17; - private const uint T8 = 0x18; - private const uint T9 = 0x19; - private const uint SP = 0x1D; - private const uint RA = 0x1F; - - private static uint NOP() => 0x00000000; - private static uint JR(uint reg) => 0x00000008U | (reg << 21); - private static uint SYSCALL() => 0x0000000C; - private static uint JAL(uint offset) => - 0x0C000000U | (offset / 4); - private static uint BLTZ(uint reg, short jump) => - 0x04000000U | (0 << 16) | (reg << 21) | (ushort)jump; - private static uint BGEZ(uint reg, short jump) => - 0x04000000U | (1 << 16) | (reg << 21) | (ushort)jump; - private static uint BLTZL(uint reg, short jump) => - 0x04000000U | (2 << 16) | (reg << 21) | (ushort)jump; - private static uint BGEZL(uint reg, short jump) => - 0x04000000U | (1 << 16) | (reg << 21) | (ushort)jump; - private static uint BEQ(uint left, uint right, short jump) => - 0x10000000U | (right << 16) | (left << 21) | (ushort)jump; - private static uint BNE(uint left, uint right, short jump) => - 0x14000000U | (right << 16) | (left << 21) | (ushort)jump; - private static uint ADDIU(uint dst, uint src, short value) => - 0x24000000U | (dst << 16) | (src << 21) | (ushort)value; - private static uint LUI(uint dst, ushort value) => - 0x3C000000U | (dst << 16) | value; - private static uint LW(uint dst, uint src, short offset) => - 0x8C000000U | (dst << 16) | (src << 21) | (ushort)offset; - private static uint SW(uint src, uint dst, short offset) => - 0xAC000000U | (src << 16) | (dst << 21) | (ushort)offset; - private static uint LD(uint src, uint dst, short offset) => - 0xDC000000U | (src << 16) | (dst << 21) | (ushort)offset; - private static uint SD(uint src, uint dst, short offset) => - 0xFC000000U | (src << 16) | (dst << 21) | (ushort)offset; - - - public enum Operation - { - HookExit, - LoadFile, - GetFileSize - } - - private const uint BaseHookPtr = 0xFFF00; - private const int HookStack = 0x0F; - private const int ParamOperator = -0x04; - private const int Param1 = -0x08; - private const int Param2 = -0x0C; - private const int Param3 = -0x10; - private const int Param4 = -0x14; - private const int ParamReturn = Param1; - - private static readonly uint[] LoadFileHook = new uint[] - { - // Input: - // T4 return program counter - // T5 Operation - // RA fallback program counter - // - // Work: - // T6 Hook stack - // V0 Return value - // V1 syscall parameter - // - LUI(T6, HookStack), - SW(A0, T6, Param1), - SW(A1, T6, Param2), - SW(T5, T6, ParamOperator), - LW(T5, T6, ParamOperator), - BNE(T5, (byte)Operation.HookExit, -2), - LW(V0, T6, ParamReturn), - BEQ(V0, Zero, 2), - NOP(), - ADDIU(RA, RA, 4), - ADDIU(SP, SP, -0x10), - SD(T4, SP, 0x08), - SD(S0, SP, 0x00), - JR(RA), - NOP(), - }; - - private static readonly uint[] GetFileSizeHook = new uint[] - { - // Input: - // A0 const char* fileName - // T4 return program counter - // T5 Operation - // RA fallback program counter - // - // Work: - // T6 Hook stack - // V0 Return value - // V1 syscall parameter - // - LUI(T6, HookStack), - SW(A0, T6, Param1), - SW(A1, T6, Param2), - SW(A2, T6, Param3), - SW(A3, T6, Param4), - SW(T5, T6, ParamOperator), - LW(T5, T6, ParamOperator), - BNE(T5, (byte)Operation.HookExit, -2), - LW(V0, T6, ParamReturn), - BEQ(V0, Zero, 2), - NOP(), - JR(T4), - NOP(), - ADDIU(SP, SP, -0x10), - SD(T4, SP, 0x08), - SD(S0, SP, 0x00), - JR(RA), - NOP(), - }; - - private static readonly uint[] RegionInitPatch = new uint[] - { - JR(RA), - NOP(), - }; - - private static readonly string[] MemoryCardPatch = new string[] - { - "SLPM", "666", "75", - "SLPM", "666", "75", - "SLPM", "666", "75", "666", "75", "75", "75", - }; - - private static readonly Offsets[] _offsets = new Offsets[] - { - new Offsets - { - GameName = "SLPM_662.33;1", - LoadFile = 0x167F20, - GetFileSize = 0x1AC698, - RegionInit = 0x105CA0, - BufferPointer = 0x35E680, - RegionForce = 0x37FCC8, - RegionId = 0x349514, - RegionPtr = 0x349510, - LanguagePtr = 0x349510, // same as Region - }, - new Offsets - { - GameName = "SLUS_210.05;1", - LoadFile = 0x167C50, - GetFileSize = 0x1AC760, - RegionInit = 0x105CB0, - BufferPointer = 0x35EE98, - RegionForce = 0x3806D8, - RegionId = 0x349D44, - RegionPtr = 0x349D40, - LanguagePtr = 0x349D40, // same as Region - }, - new Offsets - { - GameName = "SLES_541.14;1", - LoadFile = 0x167CA8, - GetFileSize = 0x1AC858, - RegionInit = 0x105CB0, - BufferPointer = 0x35F3A8, - RegionForce = 0x378378, - RegionId = 0x34A24C, - RegionPtr = 0x34A240, - LanguagePtr = 0x34A244, - }, - new Offsets - { - GameName = "SLES_542.32;1", - LoadFile = 0x167CA8, - GetFileSize = 0x1AC858, - RegionInit = 0x105CB0, - BufferPointer = 0x35F3A8, - RegionForce = 0x378378, - RegionId = 0x34A24C, - RegionPtr = 0x34A240, - LanguagePtr = 0x34A244, - }, - new Offsets - { - GameName = "SLES_542.33;1", - LoadFile = 0x167CA8, - GetFileSize = 0x1AC858, - RegionInit = 0x105CB0, - BufferPointer = 0x35F3A8, - RegionForce = 0x378378, - RegionId = 0x34A24C, - RegionPtr = 0x34A240, - LanguagePtr = 0x34A244, - }, - new Offsets - { - GameName = "SLES_542.34;1", - LoadFile = 0x167CA8, - GetFileSize = 0x1AC858, - RegionInit = 0x105CB0, - BufferPointer = 0x35F3A8, - RegionForce = 0x378378, - RegionId = 0x34A24C, - RegionPtr = 0x34A240, - LanguagePtr = 0x34A244, - }, - new Offsets - { - GameName = "SLES_542.35;1", - LoadFile = 0x167CA8, - GetFileSize = 0x1AC858, - RegionInit = 0x105CB0, - BufferPointer = 0x35F3A8, - RegionForce = 0x378378, - RegionId = 0x34A24C, - RegionPtr = 0x34A240, - LanguagePtr = 0x34A244, - }, - new Offsets - { - GameName = KH2FM, - LoadFile = 0x1682b8, - GetFileSize = 0x1AE1B0, - RegionInit = 0x105AF8, - BufferPointer = 0x350E88, - RegionForce = 0x369E98, - RegionId = 0x33CAFC, - RegionPtr = 0x33CAF0, - LanguagePtr = 0x33CAF4, - }, - }; - - private readonly IOperationDispatcher _operationDispatcher; - private const int OperationAddress = (HookStack << 16) - 4; - private CancellationTokenSource _cancellationTokenSource; - private CancellationToken _cancellationToken; - private Task _injectorTask; - private uint _hookPtr; - private uint _nextHookPtr; - private Offsets _myOffsets; - - public Pcsx2Injector(IOperationDispatcher operationDispatcher) - { - _operationDispatcher = operationDispatcher; - } - - public int RegionId { get; set; } - public string Region { get; set; } - public string Language { get; set; } - - public void Run(Process process, IDebugging debugging) - { - _cancellationTokenSource = new CancellationTokenSource(); - _cancellationToken = _cancellationTokenSource.Token; - _injectorTask = Task.Run(async () => - { - Log.Info("Waiting for the game to boot"); - var gameName = await Pcsx2MemoryService.GetPcsx2ApplicationName(process, _cancellationToken); - using var processStream = new ProcessStream(process, 0x20000000, 0x2000000); - - Log.Info("Injecting code"); - _myOffsets = _offsets.FirstOrDefault(x => x.GameName == gameName); - if (_myOffsets == null) - { - Log.Err($"Game {gameName} not recognized. Exiting from the injector service."); - return; - } - - WritePatch(processStream, _myOffsets); - - Log.Info("Executing the injector main loop"); - MainLoop(processStream, debugging); - debugging.HideDebugger(); - }, _cancellationToken); - } - - public void Stop() - { - try - { - _cancellationTokenSource?.Cancel(); - _injectorTask?.Wait(); - } - catch - { - - } - } - - private void MainLoop(Stream stream, IDebugging debugging) - { - var isProcessDead = false; - while (!_cancellationToken.IsCancellationRequested && !isProcessDead) - { - var operation = stream.SetPosition(OperationAddress).ReadInt32(); - if (stream.Position == OperationAddress) - break; // The emulator stopped its execution - - switch ((Operation)operation) - { - case Operation.LoadFile: - OperationCopyFile(stream); - break; - case Operation.GetFileSize: - OperationGetFileSize(stream); - break; - default: - break; - case Operation.HookExit: - Thread.Sleep(1); - continue; - } - - stream.SetPosition(OperationAddress).Write((int)Operation.HookExit); - } - } - - private void OperationCopyFile(Stream stream) - { - const int ParameterCount = 2; - stream.SetPosition(OperationAddress - ParameterCount * sizeof(uint)); - - var ptrMemDst = stream.ReadInt32(); - var ptrFileName = stream.ReadInt32(); - var fileName = ReadString(stream, ptrFileName); - if (string.IsNullOrEmpty(fileName)) - return; - - var returnValue = _operationDispatcher.LoadFile(stream.SetPosition(ptrMemDst), fileName); - stream.SetPosition(OperationAddress - 4).Write(returnValue); - } - - private void OperationGetFileSize(Stream stream) - { - const int ParameterCount = 1; - stream.SetPosition(OperationAddress - ParameterCount * sizeof(uint)); - - var ptrFileName = stream.ReadInt32(); - var fileName = ReadString(stream, ptrFileName); - if (string.IsNullOrEmpty(fileName)) - return; - - var returnValue = _operationDispatcher.GetFileSize(fileName); - stream.SetPosition(OperationAddress - 4).Write(returnValue); - } - - private void WritePatch(Stream stream, Offsets offsets) - { - ResetHooks(); - if (offsets != null) - { - if (offsets.LoadFile > 0) - { - Log.Info("Injecting {0} function", offsets.LoadFile); - WritePatch(stream, offsets.LoadFile, - ADDIU(T4, RA, 0), - JAL(WriteHook(stream, LoadFileHook)), - ADDIU(T5, Zero, (byte)Operation.LoadFile)); - } - - if (offsets.GetFileSize > 0) - { - Log.Info("Injecting {0} function", offsets.GetFileSize); - var subGetFileSizePtr = stream.SetPosition(offsets.GetFileSize + 8).ReadUInt32(); - WritePatch(stream, offsets.GetFileSize, - ADDIU(T4, RA, 0), - JAL(WriteHook(stream, GetFileSizeHook)), - ADDIU(T5, Zero, (byte)Operation.GetFileSize), - subGetFileSizePtr, - NOP(), - BEQ(V0, Zero, 2), - NOP(), - LW(V0, V0, 0x0C), - LD(RA, SP, 0x08), - JR(RA), - ADDIU(SP, SP, 0x10)); - } - - if (RegionId > 0) - { - Log.Info("Injecting {0} function", "RegionInit"); - WritePatch(stream, offsets.RegionInit, RegionInitPatch); - WritePatch(stream, offsets.RegionForce, Region); - WritePatch(stream, offsets.RegionForce + 8, Language); - WritePatch(stream, offsets.RegionId, RegionId); - WritePatch(stream, offsets.RegionPtr, offsets.RegionForce); - WritePatch(stream, offsets.LanguagePtr, offsets.RegionForce + 8); - - if (offsets.GameName == KH2FM) - PatchKh2FmPs2(stream); - } - } - } - - private void PatchKh2FmPs2(Stream stream) - { - // Always use "SLPM" for memory card regardless the region - WritePatch(stream, 0x240138, - ADDIU(V0, Zero, (int)Kh2.Constants.RegionId.FinalMix)); - - // Always use "BI" for memory card regardless the region - WritePatch(stream, 0x2402E8, - ADDIU(V0, Zero, (int)Kh2.Constants.RegionId.FinalMix), - NOP()); - - // Always use "KH2J" header for saves - WritePatch(stream, 0x105870, - LUI(V0, 0x4A32), - ADDIU(V0, V0, 0x484B), - JR(RA), - NOP()); - - // Fix weird game bug where KH2FM would crash on map change - // when the region is different from JP or FM. - WritePatch(stream, 0x015ABE8, ADDIU(V0, Zero, 1)); - } - - private void ResetHooks() => _nextHookPtr = BaseHookPtr; - - private uint WriteHook(Stream stream, params uint[] patch) - { - _hookPtr = _nextHookPtr; - _nextHookPtr += WritePatch(stream, _hookPtr, patch); - return _hookPtr; - } - - private uint WritePatch(Stream stream, long offset, params uint[] patch) - { - if (offset == 0) - return 0; - - stream.SetPosition(offset); - foreach (var word in patch) - stream.Write(word); - stream.Flush(); - return (uint)(patch.Length * sizeof(uint)); - } - - private void WritePatch(Stream stream, long offset, int patch) - { - if (offset == 0) - return; - stream.SetPosition(offset).Write(patch); - } - - private void WritePatch(Stream stream, long offset, string patch) - { - if (offset == 0) - return; - - stream.SetPosition(offset); - foreach (var ch in patch) - stream.Write((byte)ch); - } - - private static string ReadString(Stream stream, int ptr) - { - const int MaxFileNameLength = 0x30; - static bool IsValidFileName(string fileName) => fileName.Length >= 2 && - char.IsLetterOrDigit(fileName[0]) && char.IsLetterOrDigit(fileName[1]); - - var rawFileName = stream.SetPosition(ptr).ReadBytes(MaxFileNameLength); - var sbFileName = new StringBuilder(); - for (var i = 0; i < rawFileName.Length; i++) - { - var ch = (char)rawFileName[i]; - if (ch == '\0') - break; - sbFileName.Append(ch); - } - - var fileName = sbFileName.ToString(); - if (!IsValidFileName(fileName)) - return null; - - return fileName; - } - } -} +using OpenKh.Common; +using OpenKh.Tools.Common; +using OpenKh.Tools.ModsManager.Interfaces; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace OpenKh.Tools.ModsManager.Services +{ + public class Pcsx2Injector + { + private class Offsets + { + public string GameName { get; init; } + public int LoadFile { get; init; } + public int GetFileSize { get; init; } + public int RegionInit { get; init; } + public int BufferPointer { get; init; } + public int RegionForce { get; init; } + public int RegionId { get; init; } + public int RegionPtr { get; init; } + public int LanguagePtr { get; init; } + } + + private class Patch + { + public string Game { get; init; } + public string Name { get; init; } + public int Address { get; init; } + public uint[] Pattern { get; init; } + public uint[] NewPattern { get; init; } + } + + private const string KH2FM = "SLPM_666.75;1"; + + private const uint Zero = 0x00; + private const uint AT = 0x01; + private const uint V0 = 0x02; + private const uint V1 = 0x03; + private const uint A0 = 0x04; + private const uint A1 = 0x05; + private const uint A2 = 0x06; + private const uint A3 = 0x07; + private const uint T0 = 0x08; + private const uint T1 = 0x09; + private const uint T2 = 0x0A; + private const uint T3 = 0x0B; + private const uint T4 = 0x0C; + private const uint T5 = 0x0D; + private const uint T6 = 0x0E; + private const uint T7 = 0x0F; + private const uint S0 = 0x10; + private const uint S1 = 0x11; + private const uint S2 = 0x12; + private const uint S3 = 0x13; + private const uint S4 = 0x14; + private const uint S5 = 0x15; + private const uint S6 = 0x16; + private const uint S7 = 0x17; + private const uint T8 = 0x18; + private const uint T9 = 0x19; + private const uint SP = 0x1D; + private const uint RA = 0x1F; + + private static uint NOP() => 0x00000000; + private static uint JR(uint reg) => 0x00000008U | (reg << 21); + private static uint SYSCALL() => 0x0000000C; + private static uint JAL(uint offset) => + 0x0C000000U | (offset / 4); + private static uint BLTZ(uint reg, short jump) => + 0x04000000U | (0 << 16) | (reg << 21) | (ushort)jump; + private static uint BGEZ(uint reg, short jump) => + 0x04000000U | (1 << 16) | (reg << 21) | (ushort)jump; + private static uint BLTZL(uint reg, short jump) => + 0x04000000U | (2 << 16) | (reg << 21) | (ushort)jump; + private static uint BGEZL(uint reg, short jump) => + 0x04000000U | (1 << 16) | (reg << 21) | (ushort)jump; + private static uint BEQ(uint left, uint right, short jump) => + 0x10000000U | (right << 16) | (left << 21) | (ushort)jump; + private static uint BNE(uint left, uint right, short jump) => + 0x14000000U | (right << 16) | (left << 21) | (ushort)jump; + private static uint ADDIU(uint dst, uint src, short value) => + 0x24000000U | (dst << 16) | (src << 21) | (ushort)value; + private static uint LUI(uint dst, ushort value) => + 0x3C000000U | (dst << 16) | value; + private static uint LW(uint dst, uint src, short offset) => + 0x8C000000U | (dst << 16) | (src << 21) | (ushort)offset; + private static uint SW(uint src, uint dst, short offset) => + 0xAC000000U | (src << 16) | (dst << 21) | (ushort)offset; + private static uint LD(uint src, uint dst, short offset) => + 0xDC000000U | (src << 16) | (dst << 21) | (ushort)offset; + private static uint SD(uint src, uint dst, short offset) => + 0xFC000000U | (src << 16) | (dst << 21) | (ushort)offset; + + + public enum Operation + { + HookExit, + LoadFile, + GetFileSize + } + + private const uint BaseHookPtr = 0xFFF00; + private const int HookStack = 0x0F; + private const int ParamOperator = -0x04; + private const int Param1 = -0x08; + private const int Param2 = -0x0C; + private const int Param3 = -0x10; + private const int Param4 = -0x14; + private const int ParamReturn = Param1; + + private static readonly uint[] LoadFileHook = new uint[] + { + // Input: + // T4 return program counter + // T5 Operation + // RA fallback program counter + // + // Work: + // T6 Hook stack + // V0 Return value + // V1 syscall parameter + // + LUI(T6, HookStack), + SW(A0, T6, Param1), + SW(A1, T6, Param2), + SW(T5, T6, ParamOperator), + LW(T5, T6, ParamOperator), + BNE(T5, (byte)Operation.HookExit, -2), + LW(V0, T6, ParamReturn), + BEQ(V0, Zero, 2), + NOP(), + ADDIU(RA, RA, 4), + ADDIU(SP, SP, -0x10), + SD(T4, SP, 0x08), + SD(S0, SP, 0x00), + JR(RA), + NOP(), + }; + + private static readonly uint[] GetFileSizeHook = new uint[] + { + // Input: + // A0 const char* fileName + // T4 return program counter + // T5 Operation + // RA fallback program counter + // + // Work: + // T6 Hook stack + // V0 Return value + // V1 syscall parameter + // + LUI(T6, HookStack), + SW(A0, T6, Param1), + SW(A1, T6, Param2), + SW(A2, T6, Param3), + SW(A3, T6, Param4), + SW(T5, T6, ParamOperator), + LW(T5, T6, ParamOperator), + BNE(T5, (byte)Operation.HookExit, -2), + LW(V0, T6, ParamReturn), + BEQ(V0, Zero, 2), + NOP(), + JR(T4), + NOP(), + ADDIU(SP, SP, -0x10), + SD(T4, SP, 0x08), + SD(S0, SP, 0x00), + JR(RA), + NOP(), + }; + + private static readonly uint[] RegionInitPatch = new uint[] + { + JR(RA), + NOP(), + }; + + private static readonly string[] MemoryCardPatch = new string[] + { + "SLPM", "666", "75", + "SLPM", "666", "75", + "SLPM", "666", "75", "666", "75", "75", "75", + }; + + private static readonly Offsets[] _offsets = new Offsets[] + { + new Offsets + { + GameName = "SLPM_662.33;1", + LoadFile = 0x167F20, + GetFileSize = 0x1AC698, + RegionInit = 0x105CA0, + BufferPointer = 0x35E680, + RegionForce = 0x37FCC8, + RegionId = 0x349514, + RegionPtr = 0x349510, + LanguagePtr = 0x349510, // same as Region + }, + new Offsets + { + GameName = "SLUS_210.05;1", + LoadFile = 0x167C50, + GetFileSize = 0x1AC760, + RegionInit = 0x105CB0, + BufferPointer = 0x35EE98, + RegionForce = 0x3806D8, + RegionId = 0x349D44, + RegionPtr = 0x349D40, + LanguagePtr = 0x349D40, // same as Region + }, + new Offsets + { + GameName = "SLES_541.14;1", + LoadFile = 0x167CA8, + GetFileSize = 0x1AC858, + RegionInit = 0x105CB0, + BufferPointer = 0x35F3A8, + RegionForce = 0x378378, + RegionId = 0x34A24C, + RegionPtr = 0x34A240, + LanguagePtr = 0x34A244, + }, + new Offsets + { + GameName = "SLES_542.32;1", + LoadFile = 0x167CA8, + GetFileSize = 0x1AC858, + RegionInit = 0x105CB0, + BufferPointer = 0x35F3A8, + RegionForce = 0x378378, + RegionId = 0x34A24C, + RegionPtr = 0x34A240, + LanguagePtr = 0x34A244, + }, + new Offsets + { + GameName = "SLES_542.33;1", + LoadFile = 0x167CA8, + GetFileSize = 0x1AC858, + RegionInit = 0x105CB0, + BufferPointer = 0x35F3A8, + RegionForce = 0x378378, + RegionId = 0x34A24C, + RegionPtr = 0x34A240, + LanguagePtr = 0x34A244, + }, + new Offsets + { + GameName = "SLES_542.34;1", + LoadFile = 0x167CA8, + GetFileSize = 0x1AC858, + RegionInit = 0x105CB0, + BufferPointer = 0x35F3A8, + RegionForce = 0x378378, + RegionId = 0x34A24C, + RegionPtr = 0x34A240, + LanguagePtr = 0x34A244, + }, + new Offsets + { + GameName = "SLES_542.35;1", + LoadFile = 0x167CA8, + GetFileSize = 0x1AC858, + RegionInit = 0x105CB0, + BufferPointer = 0x35F3A8, + RegionForce = 0x378378, + RegionId = 0x34A24C, + RegionPtr = 0x34A240, + LanguagePtr = 0x34A244, + }, + new Offsets + { + GameName = KH2FM, + LoadFile = 0x1682b8, + GetFileSize = 0x1AE1B0, + RegionInit = 0x105AF8, + BufferPointer = 0x350E88, + RegionForce = 0x369E98, + RegionId = 0x33CAFC, + RegionPtr = 0x33CAF0, + LanguagePtr = 0x33CAF4, + }, + }; + + private readonly IOperationDispatcher _operationDispatcher; + private const int OperationAddress = (HookStack << 16) - 4; + private CancellationTokenSource _cancellationTokenSource; + private CancellationToken _cancellationToken; + private Task _injectorTask; + private uint _hookPtr; + private uint _nextHookPtr; + private Offsets _myOffsets; + + public Pcsx2Injector(IOperationDispatcher operationDispatcher) + { + _operationDispatcher = operationDispatcher; + } + + public int RegionId { get; set; } + public string Region { get; set; } + public string Language { get; set; } + + public void Run(Process process, IDebugging debugging) + { + _cancellationTokenSource = new CancellationTokenSource(); + _cancellationToken = _cancellationTokenSource.Token; + _injectorTask = Task.Run(async () => + { + Log.Info("Waiting for the game to boot"); + var gameName = await Pcsx2MemoryService.GetPcsx2ApplicationName(process, _cancellationToken); + using var processStream = new ProcessStream(process, 0x20000000, 0x2000000); + + Log.Info("Injecting code"); + _myOffsets = _offsets.FirstOrDefault(x => x.GameName == gameName); + if (_myOffsets == null) + { + Log.Err($"Game {gameName} not recognized. Exiting from the injector service."); + return; + } + + WritePatch(processStream, _myOffsets); + + Log.Info("Executing the injector main loop"); + MainLoop(processStream, debugging); + debugging.HideDebugger(); + }, _cancellationToken); + } + + public void Stop() + { + try + { + _cancellationTokenSource?.Cancel(); + _injectorTask?.Wait(); + } + catch + { + + } + } + + private void MainLoop(Stream stream, IDebugging debugging) + { + var isProcessDead = false; + while (!_cancellationToken.IsCancellationRequested && !isProcessDead) + { + var operation = stream.SetPosition(OperationAddress).ReadInt32(); + if (stream.Position == OperationAddress) + break; // The emulator stopped its execution + + switch ((Operation)operation) + { + case Operation.LoadFile: + OperationCopyFile(stream); + break; + case Operation.GetFileSize: + OperationGetFileSize(stream); + break; + default: + break; + case Operation.HookExit: + Thread.Sleep(1); + continue; + } + + stream.SetPosition(OperationAddress).Write((int)Operation.HookExit); + } + } + + private void OperationCopyFile(Stream stream) + { + const int ParameterCount = 2; + stream.SetPosition(OperationAddress - ParameterCount * sizeof(uint)); + + var ptrMemDst = stream.ReadInt32(); + var ptrFileName = stream.ReadInt32(); + var fileName = ReadString(stream, ptrFileName); + if (string.IsNullOrEmpty(fileName)) + return; + + var returnValue = _operationDispatcher.LoadFile(stream.SetPosition(ptrMemDst), fileName); + stream.SetPosition(OperationAddress - 4).Write(returnValue); + } + + private void OperationGetFileSize(Stream stream) + { + const int ParameterCount = 1; + stream.SetPosition(OperationAddress - ParameterCount * sizeof(uint)); + + var ptrFileName = stream.ReadInt32(); + var fileName = ReadString(stream, ptrFileName); + if (string.IsNullOrEmpty(fileName)) + return; + + var returnValue = _operationDispatcher.GetFileSize(fileName); + stream.SetPosition(OperationAddress - 4).Write(returnValue); + } + + private void WritePatch(Stream stream, Offsets offsets) + { + ResetHooks(); + if (offsets != null) + { + if (offsets.LoadFile > 0) + { + Log.Info("Injecting {0} function", offsets.LoadFile); + WritePatch(stream, offsets.LoadFile, + ADDIU(T4, RA, 0), + JAL(WriteHook(stream, LoadFileHook)), + ADDIU(T5, Zero, (byte)Operation.LoadFile)); + } + + if (offsets.GetFileSize > 0) + { + Log.Info("Injecting {0} function", offsets.GetFileSize); + var subGetFileSizePtr = stream.SetPosition(offsets.GetFileSize + 8).ReadUInt32(); + WritePatch(stream, offsets.GetFileSize, + ADDIU(T4, RA, 0), + JAL(WriteHook(stream, GetFileSizeHook)), + ADDIU(T5, Zero, (byte)Operation.GetFileSize), + subGetFileSizePtr, + NOP(), + BEQ(V0, Zero, 2), + NOP(), + LW(V0, V0, 0x0C), + LD(RA, SP, 0x08), + JR(RA), + ADDIU(SP, SP, 0x10)); + } + + if (RegionId > 0) + { + Log.Info("Injecting {0} function", "RegionInit"); + WritePatch(stream, offsets.RegionInit, RegionInitPatch); + WritePatch(stream, offsets.RegionForce, Region); + WritePatch(stream, offsets.RegionForce + 8, Language); + WritePatch(stream, offsets.RegionId, RegionId); + WritePatch(stream, offsets.RegionPtr, offsets.RegionForce); + WritePatch(stream, offsets.LanguagePtr, offsets.RegionForce + 8); + + if (offsets.GameName == KH2FM) + PatchKh2FmPs2(stream); + } + } + } + + private void PatchKh2FmPs2(Stream stream) + { + // Always use "SLPM" for memory card regardless the region + WritePatch(stream, 0x240138, + ADDIU(V0, Zero, (int)Kh2.Constants.RegionId.FinalMix)); + + // Always use "BI" for memory card regardless the region + WritePatch(stream, 0x2402E8, + ADDIU(V0, Zero, (int)Kh2.Constants.RegionId.FinalMix), + NOP()); + + // Always use "KH2J" header for saves + WritePatch(stream, 0x105870, + LUI(V0, 0x4A32), + ADDIU(V0, V0, 0x484B), + JR(RA), + NOP()); + + // Fix weird game bug where KH2FM would crash on map change + // when the region is different from JP or FM. + WritePatch(stream, 0x015ABE8, ADDIU(V0, Zero, 1)); + } + + private void ResetHooks() => _nextHookPtr = BaseHookPtr; + + private uint WriteHook(Stream stream, params uint[] patch) + { + _hookPtr = _nextHookPtr; + _nextHookPtr += WritePatch(stream, _hookPtr, patch); + return _hookPtr; + } + + private uint WritePatch(Stream stream, long offset, params uint[] patch) + { + if (offset == 0) + return 0; + + stream.SetPosition(offset); + foreach (var word in patch) + stream.Write(word); + stream.Flush(); + return (uint)(patch.Length * sizeof(uint)); + } + + private void WritePatch(Stream stream, long offset, int patch) + { + if (offset == 0) + return; + stream.SetPosition(offset).Write(patch); + } + + private void WritePatch(Stream stream, long offset, string patch) + { + if (offset == 0) + return; + + stream.SetPosition(offset); + foreach (var ch in patch) + stream.Write((byte)ch); + } + + private static string ReadString(Stream stream, int ptr) + { + const int MaxFileNameLength = 0x30; + static bool IsValidFileName(string fileName) => fileName.Length >= 2 && + char.IsLetterOrDigit(fileName[0]) && char.IsLetterOrDigit(fileName[1]); + + var rawFileName = stream.SetPosition(ptr).ReadBytes(MaxFileNameLength); + var sbFileName = new StringBuilder(); + for (var i = 0; i < rawFileName.Length; i++) + { + var ch = (char)rawFileName[i]; + if (ch == '\0') + break; + sbFileName.Append(ch); + } + + var fileName = sbFileName.ToString(); + if (!IsValidFileName(fileName)) + return null; + + return fileName; + } + } +} diff --git a/OpenKh.Tools.ModsManager/Services/Pcsx2MemoryService.cs b/OpenKh.Tools.ModsManager/Services/Pcsx2MemoryService.cs index 19abeed25..5a5a28fe0 100644 --- a/OpenKh.Tools.ModsManager/Services/Pcsx2MemoryService.cs +++ b/OpenKh.Tools.ModsManager/Services/Pcsx2MemoryService.cs @@ -1,166 +1,166 @@ -/* - Kingdom Save Editor - Copyright (C) 2020 Luciano Ciccariello - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -using OpenKh.Tools.Common; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace OpenKh.Tools.ModsManager.Services -{ - public static class Pcsx2MemoryService - { - private const uint Pcsx2EmulationBaseAddress = 0x20000000; - private const uint Pcsx2EmulationMemoryLength = 0x2000000; - private const uint BootFileMaximumStringLength = 0x20; - private static readonly uint[] PlayStation2BootFileOffsets = new uint[] - { - 0x12610, // Japan v1.00 - 0x15390, // American 1.60 - 0x15510, // Europe v1.60 - 0x155D0, // Europe v2.00 - 0x15B90, // Every other BIOS from v2.20 or above - }; - - private class GameEntry - { - public string BootFile { get; } - public long Offset { get; } - public int Length { get; } - - public GameEntry(string titleId, long offset, int length) - { - BootFile = titleId; - Offset = offset; - Length = length; - } - } - - private static GameEntry[] Games => new GameEntry[] - { - new GameEntry("SLPM_610.25;1", 0x203F1210, 0x16c00), // Kingdom Hearts I Premium Showcase - new GameEntry("SLPS_251.05;1", 0x203F2080, 0x16c00), // Kingdom Hearts I (JP) - new GameEntry("SLUS_203.70;1", 0x203F1C90, 0x16c00), // Kingdom Hearts I (US) - new GameEntry("SCUS_203.70;1", 0x203F1C90, 0x16c00), // Kingdom Hearts I (US) - new GameEntry("SLES_509.67;1", 0x203F22C0, 0x16c00), // Kingdom Hearts I (UK) - new GameEntry("SLES_509.68;1", 0x203F1AB0, 0x16c00), // Kingdom Hearts I (FR) - new GameEntry("SLES_509.69;1", 0x203F3CF0, 0x16c00), // Kingdom Hearts I (DE) - new GameEntry("SLES_509.70;1", 0x203F3900, 0x16c00), // Kingdom Hearts I (IT) - new GameEntry("SLES_509.71;1", 0x203F4620, 0x16c00), // Kingdom Hearts I (ES) - new GameEntry("SCES_509.67;1", 0x203F22C0, 0x16c00), // Kingdom Hearts I (UK) - new GameEntry("SCES_509.68;1", 0x203F1AB0, 0x16c00), // Kingdom Hearts I (FR) - new GameEntry("SCES_509.69;1", 0x203F3CF0, 0x16c00), // Kingdom Hearts I (DE) - new GameEntry("SCES_509.70;1", 0x203F3900, 0x16c00), // Kingdom Hearts I (IT) - new GameEntry("SCES_509.71;1", 0x203F4620, 0x16c00), // Kingdom Hearts I (ES) - new GameEntry("SLPS_251.97;1", 0x203F8380, 0x16c00), // Kingdom Hearts I: Final Mix - new GameEntry("SLPS_251.98;1", 0x203F8380, 0x16c00), // Kingdom Hearts I: Final Mix - - new GameEntry("SLPM_662.33;1", 0x2033DCE0, 0xb830), // Kingdom Hearts II (JP) - new GameEntry("SLUS_210.05;1", 0x2033E860, 0xb4e0), // Kingdom Hearts II (US) - new GameEntry("SCUS_210.05;1", 0x2033E860, 0xb4e0), // Kingdom Hearts II (US) - new GameEntry("SLES_541.44;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (UK) - new GameEntry("SLES_542.32;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (FR) - new GameEntry("SLES_542.33;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (DE) - new GameEntry("SLES_542.34;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (IT) - new GameEntry("SCES_542.35;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (ES) - new GameEntry("SCES_541.44;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (UK) - new GameEntry("SCES_542.32;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (FR) - new GameEntry("SCES_542.33;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (DE) - new GameEntry("SCES_542.34;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (IT) - new GameEntry("SCES_542.35;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (ES) - new GameEntry("SLPM_666.75;1", 0x2032BB30, 0x10fc0), // Kingdom Hearts II: Final Mix - }; - - public static async Task GetPcsx2ApplicationName(Process process, CancellationToken cancellationToken) - { - int byteReadCount; - var data = new byte[BootFileMaximumStringLength]; - - while (!cancellationToken.IsCancellationRequested) - { - foreach (var offsets in PlayStation2BootFileOffsets) - { - using (var searchStream = new ProcessStream(process, Pcsx2EmulationBaseAddress + offsets, 0x20)) - { - byteReadCount = searchStream.Read(data, 0, data.Length); - } - - var bootFile = Encoding.ASCII.GetString(data.TakeWhile(b => !b.Equals(0)).ToArray()); - - // Here the situation becomes weird. We can have 5 possible different scenario: - // 1. The emulator is not booted. so the selected portion of memory will be undefined. - // The task can wait for the user to load the game. - // We can impose a quite long sleep, since it takes time from user's interaction. - if (byteReadCount == 0) - { - await Task.Delay(100); - continue; - } - - // 2. The emulator is booted to the bios, which will return "SYS" - // or "LOGO". The task can wait for the BIOS to boot the game. - // The boot can happen at any time... or not happen at all. - if (bootFile == "SYS" || bootFile == "LOGO") - { - await Task.Delay(1); - continue; - } - - // 3. The game is booting, so the length of bootFile will be 0. - // The task can wait for the game to be booted. - // This operation is usually quite fast. - if (bootFile.Length == 0) - { - await Task.Delay(1); - continue; - } - - // 4. A random string can be found for a fracion of second. - // Since a game always starts with "SL" or "SC", prevents - // to consider that random string as something useful. - if (bootFile.StartsWith("SL") || bootFile.StartsWith("SC")) - return bootFile; - - await Task.Delay(1); - } - } - - return null; - } - - public static async Task CreateStreamFromPcsx2Process(Process process, CancellationToken cancellationToken) - { - while (!cancellationToken.IsCancellationRequested) - { - var bootFile = await GetPcsx2ApplicationName(process, cancellationToken); - if (cancellationToken.IsCancellationRequested) - return null; - - var game = Games.FirstOrDefault(x => x.BootFile == bootFile); - if (game == null) - return null; - - return new ProcessStream(process, (uint)game.Offset, (uint)game.Length); - } - - return null; - } - } -} +/* + Kingdom Save Editor + Copyright (C) 2020 Luciano Ciccariello + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using OpenKh.Tools.Common; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace OpenKh.Tools.ModsManager.Services +{ + public static class Pcsx2MemoryService + { + private const uint Pcsx2EmulationBaseAddress = 0x20000000; + private const uint Pcsx2EmulationMemoryLength = 0x2000000; + private const uint BootFileMaximumStringLength = 0x20; + private static readonly uint[] PlayStation2BootFileOffsets = new uint[] + { + 0x12610, // Japan v1.00 + 0x15390, // American 1.60 + 0x15510, // Europe v1.60 + 0x155D0, // Europe v2.00 + 0x15B90, // Every other BIOS from v2.20 or above + }; + + private class GameEntry + { + public string BootFile { get; } + public long Offset { get; } + public int Length { get; } + + public GameEntry(string titleId, long offset, int length) + { + BootFile = titleId; + Offset = offset; + Length = length; + } + } + + private static GameEntry[] Games => new GameEntry[] + { + new GameEntry("SLPM_610.25;1", 0x203F1210, 0x16c00), // Kingdom Hearts I Premium Showcase + new GameEntry("SLPS_251.05;1", 0x203F2080, 0x16c00), // Kingdom Hearts I (JP) + new GameEntry("SLUS_203.70;1", 0x203F1C90, 0x16c00), // Kingdom Hearts I (US) + new GameEntry("SCUS_203.70;1", 0x203F1C90, 0x16c00), // Kingdom Hearts I (US) + new GameEntry("SLES_509.67;1", 0x203F22C0, 0x16c00), // Kingdom Hearts I (UK) + new GameEntry("SLES_509.68;1", 0x203F1AB0, 0x16c00), // Kingdom Hearts I (FR) + new GameEntry("SLES_509.69;1", 0x203F3CF0, 0x16c00), // Kingdom Hearts I (DE) + new GameEntry("SLES_509.70;1", 0x203F3900, 0x16c00), // Kingdom Hearts I (IT) + new GameEntry("SLES_509.71;1", 0x203F4620, 0x16c00), // Kingdom Hearts I (ES) + new GameEntry("SCES_509.67;1", 0x203F22C0, 0x16c00), // Kingdom Hearts I (UK) + new GameEntry("SCES_509.68;1", 0x203F1AB0, 0x16c00), // Kingdom Hearts I (FR) + new GameEntry("SCES_509.69;1", 0x203F3CF0, 0x16c00), // Kingdom Hearts I (DE) + new GameEntry("SCES_509.70;1", 0x203F3900, 0x16c00), // Kingdom Hearts I (IT) + new GameEntry("SCES_509.71;1", 0x203F4620, 0x16c00), // Kingdom Hearts I (ES) + new GameEntry("SLPS_251.97;1", 0x203F8380, 0x16c00), // Kingdom Hearts I: Final Mix + new GameEntry("SLPS_251.98;1", 0x203F8380, 0x16c00), // Kingdom Hearts I: Final Mix + + new GameEntry("SLPM_662.33;1", 0x2033DCE0, 0xb830), // Kingdom Hearts II (JP) + new GameEntry("SLUS_210.05;1", 0x2033E860, 0xb4e0), // Kingdom Hearts II (US) + new GameEntry("SCUS_210.05;1", 0x2033E860, 0xb4e0), // Kingdom Hearts II (US) + new GameEntry("SLES_541.44;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (UK) + new GameEntry("SLES_542.32;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (FR) + new GameEntry("SLES_542.33;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (DE) + new GameEntry("SLES_542.34;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (IT) + new GameEntry("SCES_542.35;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (ES) + new GameEntry("SCES_541.44;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (UK) + new GameEntry("SCES_542.32;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (FR) + new GameEntry("SCES_542.33;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (DE) + new GameEntry("SCES_542.34;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (IT) + new GameEntry("SCES_542.35;1", 0x2033ED60, 0xb4e0), // Kingdom Hearts II (ES) + new GameEntry("SLPM_666.75;1", 0x2032BB30, 0x10fc0), // Kingdom Hearts II: Final Mix + }; + + public static async Task GetPcsx2ApplicationName(Process process, CancellationToken cancellationToken) + { + int byteReadCount; + var data = new byte[BootFileMaximumStringLength]; + + while (!cancellationToken.IsCancellationRequested) + { + foreach (var offsets in PlayStation2BootFileOffsets) + { + using (var searchStream = new ProcessStream(process, Pcsx2EmulationBaseAddress + offsets, 0x20)) + { + byteReadCount = searchStream.Read(data, 0, data.Length); + } + + var bootFile = Encoding.ASCII.GetString(data.TakeWhile(b => !b.Equals(0)).ToArray()); + + // Here the situation becomes weird. We can have 5 possible different scenario: + // 1. The emulator is not booted. so the selected portion of memory will be undefined. + // The task can wait for the user to load the game. + // We can impose a quite long sleep, since it takes time from user's interaction. + if (byteReadCount == 0) + { + await Task.Delay(100); + continue; + } + + // 2. The emulator is booted to the bios, which will return "SYS" + // or "LOGO". The task can wait for the BIOS to boot the game. + // The boot can happen at any time... or not happen at all. + if (bootFile == "SYS" || bootFile == "LOGO") + { + await Task.Delay(1); + continue; + } + + // 3. The game is booting, so the length of bootFile will be 0. + // The task can wait for the game to be booted. + // This operation is usually quite fast. + if (bootFile.Length == 0) + { + await Task.Delay(1); + continue; + } + + // 4. A random string can be found for a fracion of second. + // Since a game always starts with "SL" or "SC", prevents + // to consider that random string as something useful. + if (bootFile.StartsWith("SL") || bootFile.StartsWith("SC")) + return bootFile; + + await Task.Delay(1); + } + } + + return null; + } + + public static async Task CreateStreamFromPcsx2Process(Process process, CancellationToken cancellationToken) + { + while (!cancellationToken.IsCancellationRequested) + { + var bootFile = await GetPcsx2ApplicationName(process, cancellationToken); + if (cancellationToken.IsCancellationRequested) + return null; + + var game = Games.FirstOrDefault(x => x.BootFile == bootFile); + if (game == null) + return null; + + return new ProcessStream(process, (uint)game.Offset, (uint)game.Length); + } + + return null; + } + } +} diff --git a/OpenKh.Tools.ModsManager/Services/RepositoryService.cs b/OpenKh.Tools.ModsManager/Services/RepositoryService.cs index ea7b885cd..cf8e4621e 100644 --- a/OpenKh.Tools.ModsManager/Services/RepositoryService.cs +++ b/OpenKh.Tools.ModsManager/Services/RepositoryService.cs @@ -1,104 +1,104 @@ -using LibGit2Sharp; -using Newtonsoft.Json; -using System; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; - -namespace OpenKh.Tools.ModsManager.Services -{ - public class RepositoryNotFoundException : Exception - { - public RepositoryNotFoundException(string repositoryName) : - base($"There is no repository under the name of '{repositoryName}' in GitHub. Please be aware that the name is case sensitive.") - { - RepositoryName = repositoryName; - } - - public string RepositoryName { get; } - } - - public static class RepositoryService - { - private class ReposResponse - { - [JsonProperty("default_branch")] - public string DefaultBranch { get; set; } - } - - public static async Task GetMainBranchFromRepository(string repositoryName) - { - using var client = new HttpClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, $"https://api.github.com/repos/{repositoryName}"); - request.Headers.UserAgent.TryParseAdd("OpenKH Mods Manager/1.0"); - using var response = await client.SendAsync(request); - if (response.StatusCode != HttpStatusCode.OK) - throw new RepositoryNotFoundException(repositoryName); - - return JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync())?.DefaultBranch; - } - - public static Task IsFileExists(string repoName, string branch, string filePath) => - IsFileExists($"https://raw.githubusercontent.com/{repoName}/{branch}/{filePath}"); - - public static async Task IsFileExists(string url) - { - using var client = new HttpClient(); - using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); - return response.StatusCode == HttpStatusCode.OK; - } - - public static Task FetchUpdate(string path) => Task.Run(() => - { - if (!Repository.IsValid(path)) - return -1; - - using var repository = new Repository(path); - if (repository.Info.IsHeadDetached) - return -1; - - Fetch(repository); - return repository.Head.TrackingDetails.BehindBy ?? 0; - }); - - public static Task FetchAndResetUponOrigin(string path, - Action progressOutput = null, - Action progressNumber = null) => Task.Run(() => - { - if (!Repository.IsValid(path)) - return; - - using var repository = new Repository(path); - if (repository.Info.IsHeadDetached) - return; - - Fetch(repository); - repository.Reset(ResetMode.Hard, repository.Head.TrackedBranch.Tip, new CheckoutOptions - { - CheckoutModifiers = CheckoutModifiers.Force, - CheckoutNotifyFlags = CheckoutNotifyFlags.None, - OnCheckoutProgress = (string path, int completedSteps, int totalSteps) => - { - progressOutput?.Invoke(path); - var nProgress = (float)completedSteps / totalSteps; - progressNumber?.Invoke(nProgress); - } - }); - }); - - private static void Fetch(Repository repository) - { - if (string.IsNullOrEmpty(repository.Head.RemoteName)) - return; - - try - { - repository.Network.Fetch(repository.Head.RemoteName, new string[0]); - } - catch - { - - } - } - } -} +using LibGit2Sharp; +using Newtonsoft.Json; +using System; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; + +namespace OpenKh.Tools.ModsManager.Services +{ + public class RepositoryNotFoundException : Exception + { + public RepositoryNotFoundException(string repositoryName) : + base($"There is no repository under the name of '{repositoryName}' in GitHub. Please be aware that the name is case sensitive.") + { + RepositoryName = repositoryName; + } + + public string RepositoryName { get; } + } + + public static class RepositoryService + { + private class ReposResponse + { + [JsonProperty("default_branch")] + public string DefaultBranch { get; set; } + } + + public static async Task GetMainBranchFromRepository(string repositoryName) + { + using var client = new HttpClient(); + using var request = new HttpRequestMessage(HttpMethod.Get, $"https://api.github.com/repos/{repositoryName}"); + request.Headers.UserAgent.TryParseAdd("OpenKH Mods Manager/1.0"); + using var response = await client.SendAsync(request); + if (response.StatusCode != HttpStatusCode.OK) + throw new RepositoryNotFoundException(repositoryName); + + return JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync())?.DefaultBranch; + } + + public static Task IsFileExists(string repoName, string branch, string filePath) => + IsFileExists($"https://raw.githubusercontent.com/{repoName}/{branch}/{filePath}"); + + public static async Task IsFileExists(string url) + { + using var client = new HttpClient(); + using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); + return response.StatusCode == HttpStatusCode.OK; + } + + public static Task FetchUpdate(string path) => Task.Run(() => + { + if (!Repository.IsValid(path)) + return -1; + + using var repository = new Repository(path); + if (repository.Info.IsHeadDetached) + return -1; + + Fetch(repository); + return repository.Head.TrackingDetails.BehindBy ?? 0; + }); + + public static Task FetchAndResetUponOrigin(string path, + Action progressOutput = null, + Action progressNumber = null) => Task.Run(() => + { + if (!Repository.IsValid(path)) + return; + + using var repository = new Repository(path); + if (repository.Info.IsHeadDetached) + return; + + Fetch(repository); + repository.Reset(ResetMode.Hard, repository.Head.TrackedBranch.Tip, new CheckoutOptions + { + CheckoutModifiers = CheckoutModifiers.Force, + CheckoutNotifyFlags = CheckoutNotifyFlags.None, + OnCheckoutProgress = (string path, int completedSteps, int totalSteps) => + { + progressOutput?.Invoke(path); + var nProgress = (float)completedSteps / totalSteps; + progressNumber?.Invoke(nProgress); + } + }); + }); + + private static void Fetch(Repository repository) + { + if (string.IsNullOrEmpty(repository.Head.RemoteName)) + return; + + try + { + repository.Network.Fetch(repository.Head.RemoteName, new string[0]); + } + catch + { + + } + } + } +} diff --git a/OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs b/OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs index 331dde1ba..6976117fb 100644 --- a/OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs +++ b/OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs @@ -1,424 +1,424 @@ -using OpenKh.Common; -using OpenKh.Tools.Common; -using OpenKh.Tools.ModsManager.Models; -using OpenKh.Tools.ModsManager.Services; -using OpenKh.Tools.ModsManager.Views; -using System; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using System.Windows; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using static OpenKh.Tools.ModsManager.Helpers; - -namespace OpenKh.Tools.ModsManager.ViewModels -{ - public interface IChangeModEnableState - { - void ModEnableStateChanged(); - } - - public class MainViewModel : BaseNotifyPropertyChanged, IChangeModEnableState - { - private static Version _version = Assembly.GetEntryAssembly()?.GetName()?.Version; - private static string ApplicationName = Utilities.GetApplicationName(); - private static string ApplicationVersion = Utilities.GetApplicationVersion(); - private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - - private DebuggingWindow _debuggingWindow = new DebuggingWindow(); - private ModViewModel _selectedValue; - private Pcsx2Injector _pcsx2Injector; - private Process _runningProcess; - private bool _isBuilding; - - public string Title => ApplicationName; - public string CurrentVersion => ApplicationVersion; - public ObservableCollection ModsList { get; set; } - public RelayCommand ExitCommand { get; set; } - public RelayCommand AddModCommand { get; set; } - public RelayCommand RemoveModCommand { get; set; } - public RelayCommand OpenModFolderCommand { get; set; } - public RelayCommand MoveUp { get; set; } - public RelayCommand MoveDown { get; set; } - public RelayCommand BuildCommand { get; set; } - public RelayCommand RunCommand { get; set; } - public RelayCommand BuildAndRunCommand { get; set; } - public RelayCommand StopRunningInstanceCommand { get; set; } - public RelayCommand WizardCommand { get; set; } - public RelayCommand OpenLinkCommand { get; set; } - - public ModViewModel SelectedValue - { - get => _selectedValue; - set - { - _selectedValue = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(IsModSelected)); - OnPropertyChanged(nameof(IsModInfoVisible)); - OnPropertyChanged(nameof(IsModUnselectedMessageVisible)); - OnPropertyChanged(nameof(MoveUp)); - OnPropertyChanged(nameof(MoveDown)); - OnPropertyChanged(nameof(AddModCommand)); - OnPropertyChanged(nameof(RemoveModCommand)); - OnPropertyChanged(nameof(OpenModFolderCommand)); - } - } - - public bool IsModSelected => SelectedValue != null; - - public Visibility IsModInfoVisible => IsModSelected ? Visibility.Visible : Visibility.Collapsed; - public Visibility IsModUnselectedMessageVisible => !IsModSelected ? Visibility.Visible : Visibility.Collapsed; - - public bool IsBuilding - { - get => _isBuilding; - set - { - _isBuilding = value; - Application.Current.Dispatcher.Invoke(() => - { - OnPropertyChanged(nameof(BuildCommand)); - OnPropertyChanged(nameof(BuildAndRunCommand)); - }); - } - } - - public bool IsRunning => _runningProcess != null; - - public MainViewModel() - { - Log.OnLogDispatch += (long ms, string tag, string message) => - _debuggingWindow.Log(ms, tag, message); - - ReloadModsList(); - SelectedValue = ModsList.FirstOrDefault(); - - ExitCommand = new RelayCommand(_ => Window.Close()); - AddModCommand = new RelayCommand(_ => - { - var view = new InstallModView(); - if (view.ShowDialog() != true) - return; - - Task.Run(async () => - { - InstallModProgressWindow progressWindow = null; - try - { - var name = view.RepositoryName; - var isZipFile = view.IsZipFile; - progressWindow = Application.Current.Dispatcher.Invoke(() => - { - var progressWindow = new InstallModProgressWindow - { - ModName = isZipFile ? Path.GetFileName(name) : name, - ProgressText = "Initializing", - ShowActivated = true - }; - progressWindow.Show(); - return progressWindow; - }); - - await ModsService.InstallMod(name, isZipFile, progress => - { - Application.Current.Dispatcher.Invoke(() => progressWindow.ProgressText = progress); - }, nProgress => - { - Application.Current.Dispatcher.Invoke(() => progressWindow.ProgressValue = nProgress); - }); - - var actualName = isZipFile ? Path.GetFileNameWithoutExtension(name) : name; - var mod = ModsService.GetMods(new string[] { actualName }).First(); - Application.Current.Dispatcher.Invoke(() => - { - progressWindow.Close(); - ModsList.Insert(0, Map(mod)); - SelectedValue = ModsList[0]; - }); - } - catch (Exception ex) - { - Handle(ex); - } - finally - { - Application.Current.Dispatcher.Invoke(() => progressWindow?.Close()); - } - }); - }, _ => true); - RemoveModCommand = new RelayCommand(_ => - { - var mod = SelectedValue; - if (Question($"Do you want to delete the mod '{mod.Source}'?", $"Remove mod {mod.Source}")) - { - Handle(() => - { - foreach (var filePath in Directory.GetFiles(mod.Path, "*", SearchOption.AllDirectories)) - { - var attributes = File.GetAttributes(filePath); - if (attributes.HasFlag(FileAttributes.ReadOnly)) - File.SetAttributes(filePath, attributes & ~FileAttributes.ReadOnly); - } - - Directory.Delete(mod.Path, true); - ReloadModsList(); - }); - } - }, _ => IsModSelected); - OpenModFolderCommand = new RelayCommand(_ => - { - using var process = Process.Start(new ProcessStartInfo - { - FileName = SelectedValue.Path, - UseShellExecute = true - }); - }, _ => IsModSelected); - MoveUp = new RelayCommand(_ => MoveSelectedModUp(), _ => CanSelectedModMoveUp()); - MoveDown = new RelayCommand(_ => MoveSelectedModDown(), _ => CanSelectedModMoveDown()); - BuildCommand = new RelayCommand(async _ => - { - ResetLogWindow(); - await BuildPatches(); - CloseAllWindows(); - }, _ => !IsBuilding); - RunCommand = new RelayCommand(async _ => - { - CloseRunningProcess(); - ResetLogWindow(); - await RunGame(); - }); - BuildAndRunCommand = new RelayCommand(async _ => - { - CloseRunningProcess(); - ResetLogWindow(); - if (await BuildPatches()) - await RunGame(); - }, _ => !IsBuilding); - StopRunningInstanceCommand = new RelayCommand(_ => - { - CloseRunningProcess(); - ResetLogWindow(); - }, _ => IsRunning); - WizardCommand = new RelayCommand(_ => - { - var dialog = new SetupWizardWindow() - { - ConfigGameEdition = ConfigurationService.GameEdition, - ConfigGameDataLocation = ConfigurationService.GameDataLocation, - ConfigIsoLocation = ConfigurationService.IsoLocation, - ConfigOpenKhGameEngineLocation = ConfigurationService.OpenKhGameEngineLocation, - ConfigPcsx2Location = ConfigurationService.Pcsx2Location, - ConfigPcReleaseLocation = ConfigurationService.PcReleaseLocation, - ConfigRegionId = ConfigurationService.RegionId, - }; - if (dialog.ShowDialog() == true) - { - ConfigurationService.GameEdition = dialog.ConfigGameEdition; - ConfigurationService.GameDataLocation = dialog.ConfigGameDataLocation; - ConfigurationService.IsoLocation = dialog.ConfigIsoLocation; - ConfigurationService.OpenKhGameEngineLocation = dialog.ConfigOpenKhGameEngineLocation; - ConfigurationService.Pcsx2Location = dialog.ConfigPcsx2Location; - ConfigurationService.PcReleaseLocation = dialog.ConfigPcReleaseLocation; - ConfigurationService.RegionId = dialog.ConfigRegionId; - ConfigurationService.IsFirstRunComplete = true; - } - }); - OpenLinkCommand = new RelayCommand(url => Process.Start(new ProcessStartInfo(url as string) - { - UseShellExecute = true - })); - - _pcsx2Injector = new Pcsx2Injector(new OperationDispatcher()); - FetchUpdates(); - - if (!ConfigurationService.IsFirstRunComplete) - WizardCommand.Execute(null); - } - - public void CloseAllWindows() - { - CloseRunningProcess(); - Application.Current.Dispatcher.Invoke(_debuggingWindow.Close); - } - - public void CloseRunningProcess() - { - if (_runningProcess == null) - return; - - _pcsx2Injector.Stop(); - _runningProcess.CloseMainWindow(); - _runningProcess.Kill(); - _runningProcess.Dispose(); - _runningProcess = null; - OnPropertyChanged(nameof(StopRunningInstanceCommand)); - } - - private void ResetLogWindow() - { - if (_debuggingWindow != null) - Application.Current.Dispatcher.Invoke(_debuggingWindow.Close); - _debuggingWindow = new DebuggingWindow(); - Application.Current.Dispatcher.Invoke(_debuggingWindow.Show); - _debuggingWindow.ClearLogs(); - } - - private async Task BuildPatches() - { - IsBuilding = true; - var result = await ModsService.RunPacherAsync(); - IsBuilding = false; - - return result; - } - - private Task RunGame() - { - ProcessStartInfo processStartInfo; - bool isPcsx2 = false; - switch (ConfigurationService.GameEdition) - { - case 0: - Log.Info("Starting OpenKH Game Engine"); - processStartInfo = new ProcessStartInfo - { - FileName = ConfigurationService.OpenKhGameEngineLocation, - WorkingDirectory = Path.GetDirectoryName(ConfigurationService.OpenKhGameEngineLocation), - Arguments = $"--data \"{ConfigurationService.GameDataLocation}\" --modpath \"{ConfigurationService.GameModPath}\"", - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - }; - break; - case 1: - Log.Info("Starting PCSX2"); - _pcsx2Injector.RegionId = ConfigurationService.RegionId; - _pcsx2Injector.Region = Kh2.Constants.Regions[_pcsx2Injector.RegionId]; - _pcsx2Injector.Language = Kh2.Constants.Languages[_pcsx2Injector.RegionId]; - - processStartInfo = new ProcessStartInfo - { - FileName = ConfigurationService.Pcsx2Location, - WorkingDirectory = Path.GetDirectoryName(ConfigurationService.Pcsx2Location), - Arguments = $"\"{ConfigurationService.IsoLocation}\"", - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - }; - isPcsx2 = true; - break; - default: - processStartInfo = null; - break; - } - - if (processStartInfo == null || !File.Exists(processStartInfo.FileName)) - { - MessageBox.Show( - "Unable to locate the executable. Please run the Wizard by going to the Settings menu.", - "Run error", MessageBoxButton.OK, MessageBoxImage.Error); - CloseAllWindows(); - return Task.CompletedTask; - } - - _runningProcess = new Process() { StartInfo = processStartInfo }; - _runningProcess.OutputDataReceived += (sender, e) => CaptureLog(e.Data); - _runningProcess.ErrorDataReceived += (sender, e) => CaptureLog(e.Data); - _runningProcess.Start(); - _runningProcess.BeginOutputReadLine(); - _runningProcess.BeginErrorReadLine(); - if (isPcsx2) - _pcsx2Injector.Run(_runningProcess, _debuggingWindow); - - OnPropertyChanged(nameof(StopRunningInstanceCommand)); - return Task.Run(() => - { - _runningProcess.WaitForExit(); - CloseAllWindows(); - }); - } - - private void CaptureLog(string data) - { - if (data == null) - return; - else if (data.Contains("err", StringComparison.InvariantCultureIgnoreCase)) - Log.Err(data); - else if (data.Contains("wrn", StringComparison.InvariantCultureIgnoreCase)) - Log.Warn(data); - else if (data.Contains("warn", StringComparison.InvariantCultureIgnoreCase)) - Log.Warn(data); - else - Log.Info(data); - } - - private void ReloadModsList() - { - ModsList = new ObservableCollection( - ModsService.GetMods(ModsService.Mods).Select(Map)); - OnPropertyChanged(nameof(ModsList)); - } - - private ModViewModel Map(ModModel mod) => new ModViewModel(mod, this); - - public void ModEnableStateChanged() - { - ConfigurationService.EnabledMods = ModsList - .Where(x => x.Enabled) - .Select(x => x.Source) - .ToList(); - OnPropertyChanged(nameof(BuildAndRunCommand)); - } - - private void MoveSelectedModDown() - { - var selectedIndex = ModsList.IndexOf(SelectedValue); - if (selectedIndex < 0) - return; - - var item = ModsList[selectedIndex]; - ModsList.RemoveAt(selectedIndex); - ModsList.Insert(++selectedIndex, item); - SelectedValue = ModsList[selectedIndex]; - ModEnableStateChanged(); - } - - private void MoveSelectedModUp() - { - var selectedIndex = ModsList.IndexOf(SelectedValue); - if (selectedIndex < 0) - return; - - var item = ModsList[selectedIndex]; - ModsList.RemoveAt(selectedIndex); - ModsList.Insert(--selectedIndex, item); - SelectedValue = ModsList[selectedIndex]; - ModEnableStateChanged(); - } - - private bool CanSelectedModMoveDown() => - SelectedValue != null && ModsList.IndexOf(SelectedValue) < ModsList.Count - 1; - - private bool CanSelectedModMoveUp() => - SelectedValue != null && ModsList.IndexOf(SelectedValue) > 0; - - private async Task FetchUpdates() - { - await Task.Delay(50); // fixes a bug where the UI wanted to refresh too soon - await foreach (var modUpdate in ModsService.FetchUpdates()) - { - var mod = ModsList.FirstOrDefault(x => x.Source == modUpdate.Name); - if (mod == null) - continue; - - Application.Current.Dispatcher.Invoke(() => - mod.UpdateCount = modUpdate.UpdateCount); - } - } - } -} +using OpenKh.Common; +using OpenKh.Tools.Common; +using OpenKh.Tools.ModsManager.Models; +using OpenKh.Tools.ModsManager.Services; +using OpenKh.Tools.ModsManager.Views; +using System; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using System.Windows; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using static OpenKh.Tools.ModsManager.Helpers; + +namespace OpenKh.Tools.ModsManager.ViewModels +{ + public interface IChangeModEnableState + { + void ModEnableStateChanged(); + } + + public class MainViewModel : BaseNotifyPropertyChanged, IChangeModEnableState + { + private static Version _version = Assembly.GetEntryAssembly()?.GetName()?.Version; + private static string ApplicationName = Utilities.GetApplicationName(); + private static string ApplicationVersion = Utilities.GetApplicationVersion(); + private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + + private DebuggingWindow _debuggingWindow = new DebuggingWindow(); + private ModViewModel _selectedValue; + private Pcsx2Injector _pcsx2Injector; + private Process _runningProcess; + private bool _isBuilding; + + public string Title => ApplicationName; + public string CurrentVersion => ApplicationVersion; + public ObservableCollection ModsList { get; set; } + public RelayCommand ExitCommand { get; set; } + public RelayCommand AddModCommand { get; set; } + public RelayCommand RemoveModCommand { get; set; } + public RelayCommand OpenModFolderCommand { get; set; } + public RelayCommand MoveUp { get; set; } + public RelayCommand MoveDown { get; set; } + public RelayCommand BuildCommand { get; set; } + public RelayCommand RunCommand { get; set; } + public RelayCommand BuildAndRunCommand { get; set; } + public RelayCommand StopRunningInstanceCommand { get; set; } + public RelayCommand WizardCommand { get; set; } + public RelayCommand OpenLinkCommand { get; set; } + + public ModViewModel SelectedValue + { + get => _selectedValue; + set + { + _selectedValue = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsModSelected)); + OnPropertyChanged(nameof(IsModInfoVisible)); + OnPropertyChanged(nameof(IsModUnselectedMessageVisible)); + OnPropertyChanged(nameof(MoveUp)); + OnPropertyChanged(nameof(MoveDown)); + OnPropertyChanged(nameof(AddModCommand)); + OnPropertyChanged(nameof(RemoveModCommand)); + OnPropertyChanged(nameof(OpenModFolderCommand)); + } + } + + public bool IsModSelected => SelectedValue != null; + + public Visibility IsModInfoVisible => IsModSelected ? Visibility.Visible : Visibility.Collapsed; + public Visibility IsModUnselectedMessageVisible => !IsModSelected ? Visibility.Visible : Visibility.Collapsed; + + public bool IsBuilding + { + get => _isBuilding; + set + { + _isBuilding = value; + Application.Current.Dispatcher.Invoke(() => + { + OnPropertyChanged(nameof(BuildCommand)); + OnPropertyChanged(nameof(BuildAndRunCommand)); + }); + } + } + + public bool IsRunning => _runningProcess != null; + + public MainViewModel() + { + Log.OnLogDispatch += (long ms, string tag, string message) => + _debuggingWindow.Log(ms, tag, message); + + ReloadModsList(); + SelectedValue = ModsList.FirstOrDefault(); + + ExitCommand = new RelayCommand(_ => Window.Close()); + AddModCommand = new RelayCommand(_ => + { + var view = new InstallModView(); + if (view.ShowDialog() != true) + return; + + Task.Run(async () => + { + InstallModProgressWindow progressWindow = null; + try + { + var name = view.RepositoryName; + var isZipFile = view.IsZipFile; + progressWindow = Application.Current.Dispatcher.Invoke(() => + { + var progressWindow = new InstallModProgressWindow + { + ModName = isZipFile ? Path.GetFileName(name) : name, + ProgressText = "Initializing", + ShowActivated = true + }; + progressWindow.Show(); + return progressWindow; + }); + + await ModsService.InstallMod(name, isZipFile, progress => + { + Application.Current.Dispatcher.Invoke(() => progressWindow.ProgressText = progress); + }, nProgress => + { + Application.Current.Dispatcher.Invoke(() => progressWindow.ProgressValue = nProgress); + }); + + var actualName = isZipFile ? Path.GetFileNameWithoutExtension(name) : name; + var mod = ModsService.GetMods(new string[] { actualName }).First(); + Application.Current.Dispatcher.Invoke(() => + { + progressWindow.Close(); + ModsList.Insert(0, Map(mod)); + SelectedValue = ModsList[0]; + }); + } + catch (Exception ex) + { + Handle(ex); + } + finally + { + Application.Current.Dispatcher.Invoke(() => progressWindow?.Close()); + } + }); + }, _ => true); + RemoveModCommand = new RelayCommand(_ => + { + var mod = SelectedValue; + if (Question($"Do you want to delete the mod '{mod.Source}'?", $"Remove mod {mod.Source}")) + { + Handle(() => + { + foreach (var filePath in Directory.GetFiles(mod.Path, "*", SearchOption.AllDirectories)) + { + var attributes = File.GetAttributes(filePath); + if (attributes.HasFlag(FileAttributes.ReadOnly)) + File.SetAttributes(filePath, attributes & ~FileAttributes.ReadOnly); + } + + Directory.Delete(mod.Path, true); + ReloadModsList(); + }); + } + }, _ => IsModSelected); + OpenModFolderCommand = new RelayCommand(_ => + { + using var process = Process.Start(new ProcessStartInfo + { + FileName = SelectedValue.Path, + UseShellExecute = true + }); + }, _ => IsModSelected); + MoveUp = new RelayCommand(_ => MoveSelectedModUp(), _ => CanSelectedModMoveUp()); + MoveDown = new RelayCommand(_ => MoveSelectedModDown(), _ => CanSelectedModMoveDown()); + BuildCommand = new RelayCommand(async _ => + { + ResetLogWindow(); + await BuildPatches(); + CloseAllWindows(); + }, _ => !IsBuilding); + RunCommand = new RelayCommand(async _ => + { + CloseRunningProcess(); + ResetLogWindow(); + await RunGame(); + }); + BuildAndRunCommand = new RelayCommand(async _ => + { + CloseRunningProcess(); + ResetLogWindow(); + if (await BuildPatches()) + await RunGame(); + }, _ => !IsBuilding); + StopRunningInstanceCommand = new RelayCommand(_ => + { + CloseRunningProcess(); + ResetLogWindow(); + }, _ => IsRunning); + WizardCommand = new RelayCommand(_ => + { + var dialog = new SetupWizardWindow() + { + ConfigGameEdition = ConfigurationService.GameEdition, + ConfigGameDataLocation = ConfigurationService.GameDataLocation, + ConfigIsoLocation = ConfigurationService.IsoLocation, + ConfigOpenKhGameEngineLocation = ConfigurationService.OpenKhGameEngineLocation, + ConfigPcsx2Location = ConfigurationService.Pcsx2Location, + ConfigPcReleaseLocation = ConfigurationService.PcReleaseLocation, + ConfigRegionId = ConfigurationService.RegionId, + }; + if (dialog.ShowDialog() == true) + { + ConfigurationService.GameEdition = dialog.ConfigGameEdition; + ConfigurationService.GameDataLocation = dialog.ConfigGameDataLocation; + ConfigurationService.IsoLocation = dialog.ConfigIsoLocation; + ConfigurationService.OpenKhGameEngineLocation = dialog.ConfigOpenKhGameEngineLocation; + ConfigurationService.Pcsx2Location = dialog.ConfigPcsx2Location; + ConfigurationService.PcReleaseLocation = dialog.ConfigPcReleaseLocation; + ConfigurationService.RegionId = dialog.ConfigRegionId; + ConfigurationService.IsFirstRunComplete = true; + } + }); + OpenLinkCommand = new RelayCommand(url => Process.Start(new ProcessStartInfo(url as string) + { + UseShellExecute = true + })); + + _pcsx2Injector = new Pcsx2Injector(new OperationDispatcher()); + FetchUpdates(); + + if (!ConfigurationService.IsFirstRunComplete) + WizardCommand.Execute(null); + } + + public void CloseAllWindows() + { + CloseRunningProcess(); + Application.Current.Dispatcher.Invoke(_debuggingWindow.Close); + } + + public void CloseRunningProcess() + { + if (_runningProcess == null) + return; + + _pcsx2Injector.Stop(); + _runningProcess.CloseMainWindow(); + _runningProcess.Kill(); + _runningProcess.Dispose(); + _runningProcess = null; + OnPropertyChanged(nameof(StopRunningInstanceCommand)); + } + + private void ResetLogWindow() + { + if (_debuggingWindow != null) + Application.Current.Dispatcher.Invoke(_debuggingWindow.Close); + _debuggingWindow = new DebuggingWindow(); + Application.Current.Dispatcher.Invoke(_debuggingWindow.Show); + _debuggingWindow.ClearLogs(); + } + + private async Task BuildPatches() + { + IsBuilding = true; + var result = await ModsService.RunPacherAsync(); + IsBuilding = false; + + return result; + } + + private Task RunGame() + { + ProcessStartInfo processStartInfo; + bool isPcsx2 = false; + switch (ConfigurationService.GameEdition) + { + case 0: + Log.Info("Starting OpenKH Game Engine"); + processStartInfo = new ProcessStartInfo + { + FileName = ConfigurationService.OpenKhGameEngineLocation, + WorkingDirectory = Path.GetDirectoryName(ConfigurationService.OpenKhGameEngineLocation), + Arguments = $"--data \"{ConfigurationService.GameDataLocation}\" --modpath \"{ConfigurationService.GameModPath}\"", + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + }; + break; + case 1: + Log.Info("Starting PCSX2"); + _pcsx2Injector.RegionId = ConfigurationService.RegionId; + _pcsx2Injector.Region = Kh2.Constants.Regions[_pcsx2Injector.RegionId]; + _pcsx2Injector.Language = Kh2.Constants.Languages[_pcsx2Injector.RegionId]; + + processStartInfo = new ProcessStartInfo + { + FileName = ConfigurationService.Pcsx2Location, + WorkingDirectory = Path.GetDirectoryName(ConfigurationService.Pcsx2Location), + Arguments = $"\"{ConfigurationService.IsoLocation}\"", + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + }; + isPcsx2 = true; + break; + default: + processStartInfo = null; + break; + } + + if (processStartInfo == null || !File.Exists(processStartInfo.FileName)) + { + MessageBox.Show( + "Unable to locate the executable. Please run the Wizard by going to the Settings menu.", + "Run error", MessageBoxButton.OK, MessageBoxImage.Error); + CloseAllWindows(); + return Task.CompletedTask; + } + + _runningProcess = new Process() { StartInfo = processStartInfo }; + _runningProcess.OutputDataReceived += (sender, e) => CaptureLog(e.Data); + _runningProcess.ErrorDataReceived += (sender, e) => CaptureLog(e.Data); + _runningProcess.Start(); + _runningProcess.BeginOutputReadLine(); + _runningProcess.BeginErrorReadLine(); + if (isPcsx2) + _pcsx2Injector.Run(_runningProcess, _debuggingWindow); + + OnPropertyChanged(nameof(StopRunningInstanceCommand)); + return Task.Run(() => + { + _runningProcess.WaitForExit(); + CloseAllWindows(); + }); + } + + private void CaptureLog(string data) + { + if (data == null) + return; + else if (data.Contains("err", StringComparison.InvariantCultureIgnoreCase)) + Log.Err(data); + else if (data.Contains("wrn", StringComparison.InvariantCultureIgnoreCase)) + Log.Warn(data); + else if (data.Contains("warn", StringComparison.InvariantCultureIgnoreCase)) + Log.Warn(data); + else + Log.Info(data); + } + + private void ReloadModsList() + { + ModsList = new ObservableCollection( + ModsService.GetMods(ModsService.Mods).Select(Map)); + OnPropertyChanged(nameof(ModsList)); + } + + private ModViewModel Map(ModModel mod) => new ModViewModel(mod, this); + + public void ModEnableStateChanged() + { + ConfigurationService.EnabledMods = ModsList + .Where(x => x.Enabled) + .Select(x => x.Source) + .ToList(); + OnPropertyChanged(nameof(BuildAndRunCommand)); + } + + private void MoveSelectedModDown() + { + var selectedIndex = ModsList.IndexOf(SelectedValue); + if (selectedIndex < 0) + return; + + var item = ModsList[selectedIndex]; + ModsList.RemoveAt(selectedIndex); + ModsList.Insert(++selectedIndex, item); + SelectedValue = ModsList[selectedIndex]; + ModEnableStateChanged(); + } + + private void MoveSelectedModUp() + { + var selectedIndex = ModsList.IndexOf(SelectedValue); + if (selectedIndex < 0) + return; + + var item = ModsList[selectedIndex]; + ModsList.RemoveAt(selectedIndex); + ModsList.Insert(--selectedIndex, item); + SelectedValue = ModsList[selectedIndex]; + ModEnableStateChanged(); + } + + private bool CanSelectedModMoveDown() => + SelectedValue != null && ModsList.IndexOf(SelectedValue) < ModsList.Count - 1; + + private bool CanSelectedModMoveUp() => + SelectedValue != null && ModsList.IndexOf(SelectedValue) > 0; + + private async Task FetchUpdates() + { + await Task.Delay(50); // fixes a bug where the UI wanted to refresh too soon + await foreach (var modUpdate in ModsService.FetchUpdates()) + { + var mod = ModsList.FirstOrDefault(x => x.Source == modUpdate.Name); + if (mod == null) + continue; + + Application.Current.Dispatcher.Invoke(() => + mod.UpdateCount = modUpdate.UpdateCount); + } + } + } +} diff --git a/OpenKh.Tools.ModsManager/ViewModels/ModViewModel.cs b/OpenKh.Tools.ModsManager/ViewModels/ModViewModel.cs index 643935d82..f66061bb2 100644 --- a/OpenKh.Tools.ModsManager/ViewModels/ModViewModel.cs +++ b/OpenKh.Tools.ModsManager/ViewModels/ModViewModel.cs @@ -1,230 +1,230 @@ -using OpenKh.Tools.ModsManager.Models; -using OpenKh.Tools.ModsManager.Services; -using OpenKh.Tools.ModsManager.Views; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using static OpenKh.Tools.ModsManager.Helpers; - -namespace OpenKh.Tools.ModsManager.ViewModels -{ - public class ModViewModel : BaseNotifyPropertyChanged - { - private static readonly string FallbackImage = null; - private readonly ModModel _model; - private readonly IChangeModEnableState _changeModEnableState; - private int _updateCount; - - public ModViewModel(ModModel model, IChangeModEnableState changeModEnableState) - { - _model = model; - _changeModEnableState = changeModEnableState; - - var nameIndex = Source.IndexOf('/'); - if (nameIndex > 0) - { - Author = Source[0..nameIndex]; - Name = Source[(nameIndex + 1)..]; - } - else - { - Author = _model.Metadata.OriginalAuthor; - Name = Source; - } - - ReadMetadata(); - if (Title != null) - Name = Title; - - UpdateCommand = new RelayCommand(async _ => - { - InstallModProgressWindow progressWindow = null; - try - { - progressWindow = Application.Current.Dispatcher.Invoke(() => - { - var progressWindow = new InstallModProgressWindow - { - OperationName = "Updating", - ModName = Source, - ProgressText = "Initializing", - ShowActivated = true - }; - progressWindow.Show(); - return progressWindow; - }); - - await ModsService.Update(Source, progress => - { - Application.Current.Dispatcher.Invoke(() => progressWindow.ProgressText = progress); - }, nProgress => - { - Application.Current.Dispatcher.Invoke(() => progressWindow.ProgressValue = nProgress); - }); - - Application.Current.Dispatcher.Invoke(() => - { - progressWindow.ProgressText = "Reading latest changes"; - progressWindow.ProgressValue = 1f; - }); - - var mod = ModsService.GetMods(new string[] { Source }).First(); - ReadMetadata(); - - Application.Current.Dispatcher.Invoke(() => - { - progressWindow.Close(); - }); - } - catch (Exception ex) - { - Handle(ex); - } - finally - { - Application.Current.Dispatcher.Invoke(() => progressWindow?.Close()); - } - }); - } - - public RelayCommand UpdateCommand { get; } - - public bool Enabled - { - get => _model.IsEnabled; - set - { - _model.IsEnabled = value; - _changeModEnableState.ModEnableStateChanged(); - OnPropertyChanged(); - } - } - - public ImageSource IconImage { get; private set; } - public ImageSource PreviewImage { get; private set; } - public Visibility PreviewImageVisibility => PreviewImage != null ? Visibility.Visible : Visibility.Collapsed; - - public bool IsHosted => _model.Name.Contains('/'); - public string Path => _model.Path; - public Visibility SourceVisibility => IsHosted ? Visibility.Visible : Visibility.Collapsed; - public Visibility LocalVisibility => !IsHosted ? Visibility.Visible : Visibility.Collapsed; - - public string Title => _model?.Metadata?.Title ?? Name; - public string Name { get; } - public string Author { get; } - public string Source => _model.Name; - public string AuthorUrl => $"https://github.com/{Author}"; - public string SourceUrl => $"https://github.com/{Source}"; - public string ReportBugUrl => $"https://github.com/{Source}/issues"; - public string FilesToPatch => string.Join('\n', GetFilesToPatch()); - - public string Description => _model.Metadata.Description; - - public string Homepage - { - get - { - if (Source == null) - return null; - - var author = System.IO.Path.GetDirectoryName(Source); - var project = System.IO.Path.GetFileName(Source); - return $"https://{author}.github.io/{project}"; - } - } - - public int UpdateCount - { - get => _updateCount; - set - { - _updateCount = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(IsUpdateAvailable)); - OnPropertyChanged(nameof(UpdateVisibility)); - } - } - - public bool IsUpdateAvailable => UpdateCount > 0; - public Visibility UpdateVisibility => IsUpdateAvailable ? Visibility.Visible : Visibility.Collapsed; - - private IEnumerable GetFilesToPatch() - { - foreach (var asset in _model.Metadata.Assets) - { - yield return asset.Name; - if (asset.Multi != null) - { - foreach (var multiAsset in asset.Multi) - yield return multiAsset.Name; - } - } - } - - private void ReadMetadata() => Task.Run(() => - { - LoadImage(_model.IconImageSource, FallbackImage, image => - { - IconImage = image; - OnPropertyChanged(nameof(IconImage)); - }); - LoadImage(_model.PreviewImageSource, null, image => - { - PreviewImage = image; - OnPropertyChanged(nameof(PreviewImage)); - OnPropertyChanged(nameof(PreviewImageVisibility)); - }); - - Application.Current.Dispatcher.Invoke(() => - { - OnPropertyChanged(nameof(Title)); - OnPropertyChanged(nameof(Description)); - OnPropertyChanged(nameof(Homepage)); - OnPropertyChanged(nameof(FilesToPatch)); - UpdateCount = 0; - }); - }); - - private static void LoadImage(string source, string fallback, Action setter) - { - if (string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(fallback)) - { - LoadImage(fallback, null, setter); - return; - } - - try - { - if (!File.Exists(source)) - { - if (!string.IsNullOrEmpty(fallback)) - LoadImage(fallback, null, setter); - return; - } - - using (var fs = new FileStream(source, FileMode.Open)) - { - var bitmapImage = new BitmapImage(); - bitmapImage.BeginInit(); - bitmapImage.StreamSource = fs; - bitmapImage.CacheOption = BitmapCacheOption.OnLoad; - bitmapImage.EndInit(); - bitmapImage.Freeze(); - - Application.Current.Dispatcher.Invoke(() => setter(bitmapImage)); - } - } - catch - { - // Silently fail if the image can not be loaded - } - } - } -} +using OpenKh.Tools.ModsManager.Models; +using OpenKh.Tools.ModsManager.Services; +using OpenKh.Tools.ModsManager.Views; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using static OpenKh.Tools.ModsManager.Helpers; + +namespace OpenKh.Tools.ModsManager.ViewModels +{ + public class ModViewModel : BaseNotifyPropertyChanged + { + private static readonly string FallbackImage = null; + private readonly ModModel _model; + private readonly IChangeModEnableState _changeModEnableState; + private int _updateCount; + + public ModViewModel(ModModel model, IChangeModEnableState changeModEnableState) + { + _model = model; + _changeModEnableState = changeModEnableState; + + var nameIndex = Source.IndexOf('/'); + if (nameIndex > 0) + { + Author = Source[0..nameIndex]; + Name = Source[(nameIndex + 1)..]; + } + else + { + Author = _model.Metadata.OriginalAuthor; + Name = Source; + } + + ReadMetadata(); + if (Title != null) + Name = Title; + + UpdateCommand = new RelayCommand(async _ => + { + InstallModProgressWindow progressWindow = null; + try + { + progressWindow = Application.Current.Dispatcher.Invoke(() => + { + var progressWindow = new InstallModProgressWindow + { + OperationName = "Updating", + ModName = Source, + ProgressText = "Initializing", + ShowActivated = true + }; + progressWindow.Show(); + return progressWindow; + }); + + await ModsService.Update(Source, progress => + { + Application.Current.Dispatcher.Invoke(() => progressWindow.ProgressText = progress); + }, nProgress => + { + Application.Current.Dispatcher.Invoke(() => progressWindow.ProgressValue = nProgress); + }); + + Application.Current.Dispatcher.Invoke(() => + { + progressWindow.ProgressText = "Reading latest changes"; + progressWindow.ProgressValue = 1f; + }); + + var mod = ModsService.GetMods(new string[] { Source }).First(); + ReadMetadata(); + + Application.Current.Dispatcher.Invoke(() => + { + progressWindow.Close(); + }); + } + catch (Exception ex) + { + Handle(ex); + } + finally + { + Application.Current.Dispatcher.Invoke(() => progressWindow?.Close()); + } + }); + } + + public RelayCommand UpdateCommand { get; } + + public bool Enabled + { + get => _model.IsEnabled; + set + { + _model.IsEnabled = value; + _changeModEnableState.ModEnableStateChanged(); + OnPropertyChanged(); + } + } + + public ImageSource IconImage { get; private set; } + public ImageSource PreviewImage { get; private set; } + public Visibility PreviewImageVisibility => PreviewImage != null ? Visibility.Visible : Visibility.Collapsed; + + public bool IsHosted => _model.Name.Contains('/'); + public string Path => _model.Path; + public Visibility SourceVisibility => IsHosted ? Visibility.Visible : Visibility.Collapsed; + public Visibility LocalVisibility => !IsHosted ? Visibility.Visible : Visibility.Collapsed; + + public string Title => _model?.Metadata?.Title ?? Name; + public string Name { get; } + public string Author { get; } + public string Source => _model.Name; + public string AuthorUrl => $"https://github.com/{Author}"; + public string SourceUrl => $"https://github.com/{Source}"; + public string ReportBugUrl => $"https://github.com/{Source}/issues"; + public string FilesToPatch => string.Join('\n', GetFilesToPatch()); + + public string Description => _model.Metadata.Description; + + public string Homepage + { + get + { + if (Source == null) + return null; + + var author = System.IO.Path.GetDirectoryName(Source); + var project = System.IO.Path.GetFileName(Source); + return $"https://{author}.github.io/{project}"; + } + } + + public int UpdateCount + { + get => _updateCount; + set + { + _updateCount = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsUpdateAvailable)); + OnPropertyChanged(nameof(UpdateVisibility)); + } + } + + public bool IsUpdateAvailable => UpdateCount > 0; + public Visibility UpdateVisibility => IsUpdateAvailable ? Visibility.Visible : Visibility.Collapsed; + + private IEnumerable GetFilesToPatch() + { + foreach (var asset in _model.Metadata.Assets) + { + yield return asset.Name; + if (asset.Multi != null) + { + foreach (var multiAsset in asset.Multi) + yield return multiAsset.Name; + } + } + } + + private void ReadMetadata() => Task.Run(() => + { + LoadImage(_model.IconImageSource, FallbackImage, image => + { + IconImage = image; + OnPropertyChanged(nameof(IconImage)); + }); + LoadImage(_model.PreviewImageSource, null, image => + { + PreviewImage = image; + OnPropertyChanged(nameof(PreviewImage)); + OnPropertyChanged(nameof(PreviewImageVisibility)); + }); + + Application.Current.Dispatcher.Invoke(() => + { + OnPropertyChanged(nameof(Title)); + OnPropertyChanged(nameof(Description)); + OnPropertyChanged(nameof(Homepage)); + OnPropertyChanged(nameof(FilesToPatch)); + UpdateCount = 0; + }); + }); + + private static void LoadImage(string source, string fallback, Action setter) + { + if (string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(fallback)) + { + LoadImage(fallback, null, setter); + return; + } + + try + { + if (!File.Exists(source)) + { + if (!string.IsNullOrEmpty(fallback)) + LoadImage(fallback, null, setter); + return; + } + + using (var fs = new FileStream(source, FileMode.Open)) + { + var bitmapImage = new BitmapImage(); + bitmapImage.BeginInit(); + bitmapImage.StreamSource = fs; + bitmapImage.CacheOption = BitmapCacheOption.OnLoad; + bitmapImage.EndInit(); + bitmapImage.Freeze(); + + Application.Current.Dispatcher.Invoke(() => setter(bitmapImage)); + } + } + catch + { + // Silently fail if the image can not be loaded + } + } + } +} diff --git a/OpenKh.Tools.ModsManager/ViewModels/SetupWizardViewModel.cs b/OpenKh.Tools.ModsManager/ViewModels/SetupWizardViewModel.cs index c76d90bb7..8b8b9cb9c 100644 --- a/OpenKh.Tools.ModsManager/ViewModels/SetupWizardViewModel.cs +++ b/OpenKh.Tools.ModsManager/ViewModels/SetupWizardViewModel.cs @@ -1,252 +1,252 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Tools.Common; -using OpenKh.Tools.ModsManager.Services; -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; -using System.Windows; -using Xe.IO; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.ModsManager.ViewModels -{ - public class SetupWizardViewModel : BaseNotifyPropertyChanged - { - private const int BufferSize = 65536; - private static string ApplicationName = Utilities.GetApplicationName(); - private static List _isoFilter = FileDialogFilterComposer - .Compose() - .AddExtensions("PlayStation 2 game ISO", "iso"); - private static List _openkhGeFilter = FileDialogFilterComposer - .Compose() - .AddExtensions("OpenKH Game Engine executable", "*Game.exe"); - private static List _pcsx2Filter = FileDialogFilterComposer - .Compose() - .AddExtensions("PCSX2 emulator", "exe"); - - private int _gameEdition; - private string _isoLocation; - private string _openKhGameEngineLocation; - private string _pcsx2Location; - private string _pcReleaseLocation; - private string _gameDataLocation; - - public string Title => $"Set-up wizard | {ApplicationName}"; - - public RelayCommand SelectIsoCommand { get; } - public string GameId { get; set; } - public string GameName { get; set; } - public string IsoLocation - { - get => _isoLocation; - set - { - _isoLocation = value; - if (File.Exists(_isoLocation)) - { - var game = GameService.DetectGameId(_isoLocation); - GameId = game?.Id; - GameName = game?.Name; - } - else - { - GameId = null; - GameName = null; - } - - OnPropertyChanged(); - OnPropertyChanged(nameof(IsIsoSelected)); - OnPropertyChanged(nameof(GameId)); - OnPropertyChanged(nameof(GameName)); - OnPropertyChanged(nameof(GameRecognizedVisibility)); - OnPropertyChanged(nameof(GameNotRecognizedVisibility)); - OnPropertyChanged(nameof(IsGameRecognized)); - } - } - public bool IsIsoSelected => !string.IsNullOrEmpty(IsoLocation) && File.Exists(IsoLocation); - public bool IsGameRecognized => IsIsoSelected && GameId != null; - public Visibility GameRecognizedVisibility => IsIsoSelected && GameId != null ? Visibility.Visible : Visibility.Collapsed; - public Visibility GameNotRecognizedVisibility => IsIsoSelected && GameId == null ? Visibility.Visible : Visibility.Collapsed; - - public bool IsGameSelected - { - get - { - var location = GameEdition switch - { - 0 => OpenKhGameEngineLocation, - 1 => Pcsx2Location, - 2 => PcReleaseLocation, - _ => string.Empty, - }; - return !string.IsNullOrEmpty(location) && File.Exists(location); - } - } - public int GameEdition - { - get => _gameEdition; - set - { - _gameEdition = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(IsGameSelected)); - OnPropertyChanged(nameof(OpenKhGameEngineConfigVisibility)); - OnPropertyChanged(nameof(Pcsx2ConfigVisibility)); - OnPropertyChanged(nameof(PcReleaseConfigVisibility)); - } - } - - public RelayCommand SelectOpenKhGameEngineCommand { get; } - public Visibility OpenKhGameEngineConfigVisibility => GameEdition == 0 ? Visibility.Visible : Visibility.Collapsed; - public string OpenKhGameEngineLocation - { - get => _openKhGameEngineLocation; - set - { - _openKhGameEngineLocation = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(IsGameSelected)); - } - } - - public RelayCommand SelectPcsx2Command { get; } - public Visibility Pcsx2ConfigVisibility => GameEdition == 1 ? Visibility.Visible : Visibility.Collapsed; - public string Pcsx2Location - { - get => _pcsx2Location; - set - { - _pcsx2Location = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(IsGameSelected)); - } - } - - public RelayCommand SelectPcReleaseCommand { get; } - public Visibility PcReleaseConfigVisibility => GameEdition == 2 ? Visibility.Visible : Visibility.Collapsed; - public string PcReleaseLocation - { - get => _pcReleaseLocation; - set - { - _pcReleaseLocation = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(IsGameSelected)); - } - } - - public RelayCommand SelectGameDataLocationCommand { get; } - public string GameDataLocation - { - get => _gameDataLocation; - set - { - _gameDataLocation = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(IsGameDataFound)); - OnPropertyChanged(nameof(GameDataNotFoundVisibility)); - OnPropertyChanged(nameof(GameDataFoundVisibility)); - } - } - - public bool IsNotExtracting { get; private set; } - public bool IsGameDataFound => IsNotExtracting && File.Exists(Path.Combine(GameDataLocation ?? "", "00objentry.bin")); - public Visibility GameDataNotFoundVisibility => !IsGameDataFound ? Visibility.Visible : Visibility.Collapsed; - public Visibility GameDataFoundVisibility => IsGameDataFound ? Visibility.Visible : Visibility.Collapsed; - public Visibility ProgressBarVisibility => IsNotExtracting ? Visibility.Collapsed : Visibility.Visible; - public Visibility ExtractionCompleteVisibility => ExtractionProgress == 1f ? Visibility.Visible : Visibility.Collapsed; - public RelayCommand ExtractGameDataCommand { get; set; } - public float ExtractionProgress { get; set; } - - public int RegionId { get; set; } - - public SetupWizardViewModel() - { - IsNotExtracting = true; - SelectIsoCommand = new RelayCommand(_ => - FileDialog.OnOpen(fileName => IsoLocation = fileName, _isoFilter)); - SelectOpenKhGameEngineCommand = new RelayCommand(_ => - FileDialog.OnOpen(fileName => OpenKhGameEngineLocation = fileName, _openkhGeFilter)); - SelectPcsx2Command = new RelayCommand(_ => - FileDialog.OnOpen(fileName => Pcsx2Location = fileName, _pcsx2Filter)); - SelectGameDataLocationCommand = new RelayCommand(_ => - FileDialog.OnFolder(path => GameDataLocation = path)); - ExtractGameDataCommand = new RelayCommand(async _ => - await ExtractGameData(IsoLocation, GameDataLocation)); - } - - private async Task ExtractGameData(string isoLocation, string gameDataLocation) - { - var fileBlocks = File.OpenRead(isoLocation).Using(stream => - { - var bufferedStream = new BufferedStream(stream); - var idxBlock = IsoUtility.GetFileOffset(bufferedStream, "KH2.IDX;1"); - var imgBlock = IsoUtility.GetFileOffset(bufferedStream, "KH2.IMG;1"); - return (idxBlock, imgBlock); - }); - - if (fileBlocks.idxBlock == -1 || fileBlocks.imgBlock == -1) - { - MessageBox.Show( - $"Unable to find the files KH2.IDX and KH2.IMG in the ISO at '{isoLocation}'. The extraction will stop.", - "Extraction error", - MessageBoxButton.OK, - MessageBoxImage.Error); - return; - } - - IsNotExtracting = false; - ExtractionProgress = 0; - OnPropertyChanged(nameof(IsNotExtracting)); - OnPropertyChanged(nameof(IsGameDataFound)); - OnPropertyChanged(nameof(ProgressBarVisibility)); - OnPropertyChanged(nameof(ExtractionCompleteVisibility)); - OnPropertyChanged(nameof(ExtractionProgress)); - - await Task.Run(() => - { - using var isoStream = File.OpenRead(isoLocation); - - var idxOffset = fileBlocks.idxBlock * 0x800L; - var idx = Idx.Read(new SubStream(isoStream, idxOffset, isoStream.Length - idxOffset)); - - var imgOffset = fileBlocks.imgBlock * 0x800L; - var imgStream = new SubStream(isoStream, imgOffset, isoStream.Length - imgOffset); - var img = new Img(imgStream, idx, true); - - var fileCount = img.Entries.Count; - var fileProcessed = 0; - foreach (var fileEntry in img.Entries) - { - var fileName = IdxName.Lookup(fileEntry) ?? $"@{fileEntry.Hash32:08X}_{fileEntry.Hash16:04X}"; - using var stream = img.FileOpen(fileEntry); - var fileDestination = Path.Combine(gameDataLocation, fileName); - var directoryDestination = Path.GetDirectoryName(fileDestination); - if (!Directory.Exists(directoryDestination)) - Directory.CreateDirectory(directoryDestination); - File.Create(fileDestination).Using(dstStream => stream.CopyTo(dstStream, BufferSize)); - - fileProcessed++; - ExtractionProgress = (float)fileProcessed / fileCount; - OnPropertyChanged(nameof(ExtractionProgress)); - } - - Application.Current.Dispatcher.Invoke(() => - { - IsNotExtracting = true; - ExtractionProgress = 1.0f; - OnPropertyChanged(nameof(IsNotExtracting)); - OnPropertyChanged(nameof(IsGameDataFound)); - OnPropertyChanged(nameof(GameDataNotFoundVisibility)); - OnPropertyChanged(nameof(GameDataFoundVisibility)); - OnPropertyChanged(nameof(ProgressBarVisibility)); - OnPropertyChanged(nameof(ExtractionCompleteVisibility)); - OnPropertyChanged(nameof(ExtractionProgress)); - }); - }); - } - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Tools.Common; +using OpenKh.Tools.ModsManager.Services; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Windows; +using Xe.IO; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.ModsManager.ViewModels +{ + public class SetupWizardViewModel : BaseNotifyPropertyChanged + { + private const int BufferSize = 65536; + private static string ApplicationName = Utilities.GetApplicationName(); + private static List _isoFilter = FileDialogFilterComposer + .Compose() + .AddExtensions("PlayStation 2 game ISO", "iso"); + private static List _openkhGeFilter = FileDialogFilterComposer + .Compose() + .AddExtensions("OpenKH Game Engine executable", "*Game.exe"); + private static List _pcsx2Filter = FileDialogFilterComposer + .Compose() + .AddExtensions("PCSX2 emulator", "exe"); + + private int _gameEdition; + private string _isoLocation; + private string _openKhGameEngineLocation; + private string _pcsx2Location; + private string _pcReleaseLocation; + private string _gameDataLocation; + + public string Title => $"Set-up wizard | {ApplicationName}"; + + public RelayCommand SelectIsoCommand { get; } + public string GameId { get; set; } + public string GameName { get; set; } + public string IsoLocation + { + get => _isoLocation; + set + { + _isoLocation = value; + if (File.Exists(_isoLocation)) + { + var game = GameService.DetectGameId(_isoLocation); + GameId = game?.Id; + GameName = game?.Name; + } + else + { + GameId = null; + GameName = null; + } + + OnPropertyChanged(); + OnPropertyChanged(nameof(IsIsoSelected)); + OnPropertyChanged(nameof(GameId)); + OnPropertyChanged(nameof(GameName)); + OnPropertyChanged(nameof(GameRecognizedVisibility)); + OnPropertyChanged(nameof(GameNotRecognizedVisibility)); + OnPropertyChanged(nameof(IsGameRecognized)); + } + } + public bool IsIsoSelected => !string.IsNullOrEmpty(IsoLocation) && File.Exists(IsoLocation); + public bool IsGameRecognized => IsIsoSelected && GameId != null; + public Visibility GameRecognizedVisibility => IsIsoSelected && GameId != null ? Visibility.Visible : Visibility.Collapsed; + public Visibility GameNotRecognizedVisibility => IsIsoSelected && GameId == null ? Visibility.Visible : Visibility.Collapsed; + + public bool IsGameSelected + { + get + { + var location = GameEdition switch + { + 0 => OpenKhGameEngineLocation, + 1 => Pcsx2Location, + 2 => PcReleaseLocation, + _ => string.Empty, + }; + return !string.IsNullOrEmpty(location) && File.Exists(location); + } + } + public int GameEdition + { + get => _gameEdition; + set + { + _gameEdition = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsGameSelected)); + OnPropertyChanged(nameof(OpenKhGameEngineConfigVisibility)); + OnPropertyChanged(nameof(Pcsx2ConfigVisibility)); + OnPropertyChanged(nameof(PcReleaseConfigVisibility)); + } + } + + public RelayCommand SelectOpenKhGameEngineCommand { get; } + public Visibility OpenKhGameEngineConfigVisibility => GameEdition == 0 ? Visibility.Visible : Visibility.Collapsed; + public string OpenKhGameEngineLocation + { + get => _openKhGameEngineLocation; + set + { + _openKhGameEngineLocation = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsGameSelected)); + } + } + + public RelayCommand SelectPcsx2Command { get; } + public Visibility Pcsx2ConfigVisibility => GameEdition == 1 ? Visibility.Visible : Visibility.Collapsed; + public string Pcsx2Location + { + get => _pcsx2Location; + set + { + _pcsx2Location = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsGameSelected)); + } + } + + public RelayCommand SelectPcReleaseCommand { get; } + public Visibility PcReleaseConfigVisibility => GameEdition == 2 ? Visibility.Visible : Visibility.Collapsed; + public string PcReleaseLocation + { + get => _pcReleaseLocation; + set + { + _pcReleaseLocation = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsGameSelected)); + } + } + + public RelayCommand SelectGameDataLocationCommand { get; } + public string GameDataLocation + { + get => _gameDataLocation; + set + { + _gameDataLocation = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsGameDataFound)); + OnPropertyChanged(nameof(GameDataNotFoundVisibility)); + OnPropertyChanged(nameof(GameDataFoundVisibility)); + } + } + + public bool IsNotExtracting { get; private set; } + public bool IsGameDataFound => IsNotExtracting && File.Exists(Path.Combine(GameDataLocation ?? "", "00objentry.bin")); + public Visibility GameDataNotFoundVisibility => !IsGameDataFound ? Visibility.Visible : Visibility.Collapsed; + public Visibility GameDataFoundVisibility => IsGameDataFound ? Visibility.Visible : Visibility.Collapsed; + public Visibility ProgressBarVisibility => IsNotExtracting ? Visibility.Collapsed : Visibility.Visible; + public Visibility ExtractionCompleteVisibility => ExtractionProgress == 1f ? Visibility.Visible : Visibility.Collapsed; + public RelayCommand ExtractGameDataCommand { get; set; } + public float ExtractionProgress { get; set; } + + public int RegionId { get; set; } + + public SetupWizardViewModel() + { + IsNotExtracting = true; + SelectIsoCommand = new RelayCommand(_ => + FileDialog.OnOpen(fileName => IsoLocation = fileName, _isoFilter)); + SelectOpenKhGameEngineCommand = new RelayCommand(_ => + FileDialog.OnOpen(fileName => OpenKhGameEngineLocation = fileName, _openkhGeFilter)); + SelectPcsx2Command = new RelayCommand(_ => + FileDialog.OnOpen(fileName => Pcsx2Location = fileName, _pcsx2Filter)); + SelectGameDataLocationCommand = new RelayCommand(_ => + FileDialog.OnFolder(path => GameDataLocation = path)); + ExtractGameDataCommand = new RelayCommand(async _ => + await ExtractGameData(IsoLocation, GameDataLocation)); + } + + private async Task ExtractGameData(string isoLocation, string gameDataLocation) + { + var fileBlocks = File.OpenRead(isoLocation).Using(stream => + { + var bufferedStream = new BufferedStream(stream); + var idxBlock = IsoUtility.GetFileOffset(bufferedStream, "KH2.IDX;1"); + var imgBlock = IsoUtility.GetFileOffset(bufferedStream, "KH2.IMG;1"); + return (idxBlock, imgBlock); + }); + + if (fileBlocks.idxBlock == -1 || fileBlocks.imgBlock == -1) + { + MessageBox.Show( + $"Unable to find the files KH2.IDX and KH2.IMG in the ISO at '{isoLocation}'. The extraction will stop.", + "Extraction error", + MessageBoxButton.OK, + MessageBoxImage.Error); + return; + } + + IsNotExtracting = false; + ExtractionProgress = 0; + OnPropertyChanged(nameof(IsNotExtracting)); + OnPropertyChanged(nameof(IsGameDataFound)); + OnPropertyChanged(nameof(ProgressBarVisibility)); + OnPropertyChanged(nameof(ExtractionCompleteVisibility)); + OnPropertyChanged(nameof(ExtractionProgress)); + + await Task.Run(() => + { + using var isoStream = File.OpenRead(isoLocation); + + var idxOffset = fileBlocks.idxBlock * 0x800L; + var idx = Idx.Read(new SubStream(isoStream, idxOffset, isoStream.Length - idxOffset)); + + var imgOffset = fileBlocks.imgBlock * 0x800L; + var imgStream = new SubStream(isoStream, imgOffset, isoStream.Length - imgOffset); + var img = new Img(imgStream, idx, true); + + var fileCount = img.Entries.Count; + var fileProcessed = 0; + foreach (var fileEntry in img.Entries) + { + var fileName = IdxName.Lookup(fileEntry) ?? $"@{fileEntry.Hash32:08X}_{fileEntry.Hash16:04X}"; + using var stream = img.FileOpen(fileEntry); + var fileDestination = Path.Combine(gameDataLocation, fileName); + var directoryDestination = Path.GetDirectoryName(fileDestination); + if (!Directory.Exists(directoryDestination)) + Directory.CreateDirectory(directoryDestination); + File.Create(fileDestination).Using(dstStream => stream.CopyTo(dstStream, BufferSize)); + + fileProcessed++; + ExtractionProgress = (float)fileProcessed / fileCount; + OnPropertyChanged(nameof(ExtractionProgress)); + } + + Application.Current.Dispatcher.Invoke(() => + { + IsNotExtracting = true; + ExtractionProgress = 1.0f; + OnPropertyChanged(nameof(IsNotExtracting)); + OnPropertyChanged(nameof(IsGameDataFound)); + OnPropertyChanged(nameof(GameDataNotFoundVisibility)); + OnPropertyChanged(nameof(GameDataFoundVisibility)); + OnPropertyChanged(nameof(ProgressBarVisibility)); + OnPropertyChanged(nameof(ExtractionCompleteVisibility)); + OnPropertyChanged(nameof(ExtractionProgress)); + }); + }); + } + } +} diff --git a/OpenKh.Tools.ModsManager/Views/DebuggingWindow.xaml.cs b/OpenKh.Tools.ModsManager/Views/DebuggingWindow.xaml.cs index 077da66ca..d7a69b46a 100644 --- a/OpenKh.Tools.ModsManager/Views/DebuggingWindow.xaml.cs +++ b/OpenKh.Tools.ModsManager/Views/DebuggingWindow.xaml.cs @@ -1,67 +1,67 @@ -using OpenKh.Tools.ModsManager.Interfaces; -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Media; - -namespace OpenKh.Tools.ModsManager.Views -{ - /// - /// Interaction logic for DebuggingWindow.xaml - /// - public partial class DebuggingWindow : Window, IDebugging, INotifyPropertyChanged - { - private static readonly Brush[] _brushes = new Brush[] - { - new SolidColorBrush(Color.FromRgb(220, 223, 228)), - new SolidColorBrush(Color.FromRgb(229, 192, 123)), - new SolidColorBrush(Color.FromRgb(224, 108, 117)), - }; - - public DebuggingWindow() - { - InitializeComponent(); - DataContext = this; - } - - public void ClearLogs() - { - Application.Current.Dispatcher.Invoke(LogPanel.Children.Clear); - } - - public void HideDebugger() - { - Task.Run(() => Application.Current.Dispatcher.Invoke(Hide)); - } - - public void Log(long ms, string tag, string message) => Task.Run(() => - { - Application.Current.Dispatcher.Invoke(() => - { - var str = $"[{(ms / 1000):D3}.{(ms % 1000):D3}] {tag} {message}"; - var brush = tag switch - { - "INF" => _brushes[0], - "WRN" => _brushes[1], - "ERR" => _brushes[2], - _ => _brushes[0], - }; - LogPanel.Children.Insert(0, new TextBlock - { - Text = str, - Foreground = brush, - TextWrapping = TextWrapping.Wrap - }); - }); - }); - - protected void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - - public event PropertyChangedEventHandler PropertyChanged; - } -} +using OpenKh.Tools.ModsManager.Interfaces; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; + +namespace OpenKh.Tools.ModsManager.Views +{ + /// + /// Interaction logic for DebuggingWindow.xaml + /// + public partial class DebuggingWindow : Window, IDebugging, INotifyPropertyChanged + { + private static readonly Brush[] _brushes = new Brush[] + { + new SolidColorBrush(Color.FromRgb(220, 223, 228)), + new SolidColorBrush(Color.FromRgb(229, 192, 123)), + new SolidColorBrush(Color.FromRgb(224, 108, 117)), + }; + + public DebuggingWindow() + { + InitializeComponent(); + DataContext = this; + } + + public void ClearLogs() + { + Application.Current.Dispatcher.Invoke(LogPanel.Children.Clear); + } + + public void HideDebugger() + { + Task.Run(() => Application.Current.Dispatcher.Invoke(Hide)); + } + + public void Log(long ms, string tag, string message) => Task.Run(() => + { + Application.Current.Dispatcher.Invoke(() => + { + var str = $"[{(ms / 1000):D3}.{(ms % 1000):D3}] {tag} {message}"; + var brush = tag switch + { + "INF" => _brushes[0], + "WRN" => _brushes[1], + "ERR" => _brushes[2], + _ => _brushes[0], + }; + LogPanel.Children.Insert(0, new TextBlock + { + Text = str, + Foreground = brush, + TextWrapping = TextWrapping.Wrap + }); + }); + }); + + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public event PropertyChangedEventHandler PropertyChanged; + } +} diff --git a/OpenKh.Tools.ModsManager/Views/InstallModProgressWindow.xaml.cs b/OpenKh.Tools.ModsManager/Views/InstallModProgressWindow.xaml.cs index 75004fb30..91bcf687b 100644 --- a/OpenKh.Tools.ModsManager/Views/InstallModProgressWindow.xaml.cs +++ b/OpenKh.Tools.ModsManager/Views/InstallModProgressWindow.xaml.cs @@ -1,89 +1,89 @@ -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Windows; - -namespace OpenKh.Tools.ModsManager.Views -{ - /// - /// Interaction logic for InstallModProgressWindow.xaml - /// - public partial class InstallModProgressWindow : Window, INotifyPropertyChanged - { - private string _modName; - private string _progressText; - private bool _progressUnknown; - private float _progressValue; - private string _operationName = "Installing"; - - public InstallModProgressWindow() - { - InitializeComponent(); - DataContext = this; - Closed += (sender, args) => - { - if (args is CancelEventArgs cancelEventArgs) - cancelEventArgs.Cancel = true; - }; - } - - public string OperationName - { - get => _operationName; - set - { - _operationName = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(Title)); - } - } - - public string DialogTitle => $"{OperationName} mod..."; - - public string ModName - { - get => _modName; - set - { - _modName = value; - OnPropertyChanged(); - } - } - - public string ProgressText - { - get => _progressText; - set - { - _progressText = value; - OnPropertyChanged(); - } - } - - public bool ProgressUnknown - { - get => _progressUnknown; - private set - { - _progressUnknown = value; - OnPropertyChanged(); - } - } - - public float ProgressValue - { - get => _progressValue; - set - { - ProgressUnknown = false; - _progressValue = value; - OnPropertyChanged(); - } - } - - public event PropertyChangedEventHandler PropertyChanged; - protected void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - } -} +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Windows; + +namespace OpenKh.Tools.ModsManager.Views +{ + /// + /// Interaction logic for InstallModProgressWindow.xaml + /// + public partial class InstallModProgressWindow : Window, INotifyPropertyChanged + { + private string _modName; + private string _progressText; + private bool _progressUnknown; + private float _progressValue; + private string _operationName = "Installing"; + + public InstallModProgressWindow() + { + InitializeComponent(); + DataContext = this; + Closed += (sender, args) => + { + if (args is CancelEventArgs cancelEventArgs) + cancelEventArgs.Cancel = true; + }; + } + + public string OperationName + { + get => _operationName; + set + { + _operationName = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(Title)); + } + } + + public string DialogTitle => $"{OperationName} mod..."; + + public string ModName + { + get => _modName; + set + { + _modName = value; + OnPropertyChanged(); + } + } + + public string ProgressText + { + get => _progressText; + set + { + _progressText = value; + OnPropertyChanged(); + } + } + + public bool ProgressUnknown + { + get => _progressUnknown; + private set + { + _progressUnknown = value; + OnPropertyChanged(); + } + } + + public float ProgressValue + { + get => _progressValue; + set + { + ProgressUnknown = false; + _progressValue = value; + OnPropertyChanged(); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/OpenKh.Tools.ModsManager/Views/InstallModView.xaml.cs b/OpenKh.Tools.ModsManager/Views/InstallModView.xaml.cs index 5d6eac21c..95e8a319e 100644 --- a/OpenKh.Tools.ModsManager/Views/InstallModView.xaml.cs +++ b/OpenKh.Tools.ModsManager/Views/InstallModView.xaml.cs @@ -1,75 +1,75 @@ -using OpenKh.Tools.ModsManager.Services; -using System.Collections.Generic; -using System.Windows; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - -namespace OpenKh.Tools.ModsManager.Views -{ - /// - /// Interaction logic for InstallModView.xaml - /// - public partial class InstallModView : Window - { - private static readonly IEnumerable _zipFilter = FileDialogFilterComposer - .Compose() - .AddExtensions("OpenKH mod as ZIP file", "zip"); - - public RelayCommand CloseCommand { get; } - public string RepositoryName { get; set; } - public bool IsZipFile { get; private set; } - - public InstallModView() - { - InitializeComponent(); - DataContext = this; - - CloseCommand = new RelayCommand(_ => Close()); - } - - private void Install_Click(object sender, RoutedEventArgs e) - { - var isBlocked = false; - var blockedMessage = string.Empty; - if (ModsService.IsUserBlocked(RepositoryName)) - { - isBlocked = true; - blockedMessage = "The author of this mod violated OpenKH rules therefore we do not recommend their mods. Do you wish to install it anyway?"; - } - else if (ModsService.IsModBlocked(RepositoryName)) - { - isBlocked = true; - blockedMessage = "The selected mod violates OpenKH rules, therefore we do not recommend its installation. Do you wish to install it anyway?"; - } - - if (isBlocked) - { - var result = MessageBox.Show(blockedMessage, $"Warning on installing {RepositoryName}", MessageBoxButton.YesNo, MessageBoxImage.Warning); - DialogResult = result == MessageBoxResult.Yes; - } - else - DialogResult = true; - - Close(); - } - - private void InstallZip_Click(object sender, RoutedEventArgs e) - { - FileDialog.OnOpen(fileName => - { - IsZipFile = true; - RepositoryName = fileName; - DialogResult = true; - Close(); - }, _zipFilter); - } - - private void txtSourceModUrl_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) - { - if (e.Key == System.Windows.Input.Key.Enter) - Install_Click(sender, e); - - e.Handled = true; - } - } -} +using OpenKh.Tools.ModsManager.Services; +using System.Collections.Generic; +using System.Windows; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + +namespace OpenKh.Tools.ModsManager.Views +{ + /// + /// Interaction logic for InstallModView.xaml + /// + public partial class InstallModView : Window + { + private static readonly IEnumerable _zipFilter = FileDialogFilterComposer + .Compose() + .AddExtensions("OpenKH mod as ZIP file", "zip"); + + public RelayCommand CloseCommand { get; } + public string RepositoryName { get; set; } + public bool IsZipFile { get; private set; } + + public InstallModView() + { + InitializeComponent(); + DataContext = this; + + CloseCommand = new RelayCommand(_ => Close()); + } + + private void Install_Click(object sender, RoutedEventArgs e) + { + var isBlocked = false; + var blockedMessage = string.Empty; + if (ModsService.IsUserBlocked(RepositoryName)) + { + isBlocked = true; + blockedMessage = "The author of this mod violated OpenKH rules therefore we do not recommend their mods. Do you wish to install it anyway?"; + } + else if (ModsService.IsModBlocked(RepositoryName)) + { + isBlocked = true; + blockedMessage = "The selected mod violates OpenKH rules, therefore we do not recommend its installation. Do you wish to install it anyway?"; + } + + if (isBlocked) + { + var result = MessageBox.Show(blockedMessage, $"Warning on installing {RepositoryName}", MessageBoxButton.YesNo, MessageBoxImage.Warning); + DialogResult = result == MessageBoxResult.Yes; + } + else + DialogResult = true; + + Close(); + } + + private void InstallZip_Click(object sender, RoutedEventArgs e) + { + FileDialog.OnOpen(fileName => + { + IsZipFile = true; + RepositoryName = fileName; + DialogResult = true; + Close(); + }, _zipFilter); + } + + private void txtSourceModUrl_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) + { + if (e.Key == System.Windows.Input.Key.Enter) + Install_Click(sender, e); + + e.Handled = true; + } + } +} diff --git a/OpenKh.Tools.ModsManager/Views/MainWindow.xaml.cs b/OpenKh.Tools.ModsManager/Views/MainWindow.xaml.cs index 9d543a90f..9b1d1ab0c 100644 --- a/OpenKh.Tools.ModsManager/Views/MainWindow.xaml.cs +++ b/OpenKh.Tools.ModsManager/Views/MainWindow.xaml.cs @@ -1,24 +1,24 @@ -using OpenKh.Tools.ModsManager.ViewModels; -using System; -using System.Windows; - -namespace OpenKh.Tools.ModsManager.Views -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); - DataContext = new MainViewModel(); - } - - protected override void OnClosed(EventArgs e) - { - (DataContext as MainViewModel)?.CloseAllWindows(); - base.OnClosed(e); - } - } -} +using OpenKh.Tools.ModsManager.ViewModels; +using System; +using System.Windows; + +namespace OpenKh.Tools.ModsManager.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + DataContext = new MainViewModel(); + } + + protected override void OnClosed(EventArgs e) + { + (DataContext as MainViewModel)?.CloseAllWindows(); + base.OnClosed(e); + } + } +} diff --git a/OpenKh.Tools.ModsManager/Views/ModDetailsView.xaml.cs b/OpenKh.Tools.ModsManager/Views/ModDetailsView.xaml.cs index c2ae64ba8..10267ddd7 100644 --- a/OpenKh.Tools.ModsManager/Views/ModDetailsView.xaml.cs +++ b/OpenKh.Tools.ModsManager/Views/ModDetailsView.xaml.cs @@ -1,25 +1,25 @@ -using System.Diagnostics; -using System.Windows.Controls; -using System.Windows.Navigation; - -namespace OpenKh.Tools.ModsManager.Views -{ - /// - /// Interaction logic for ModDetailsView.xaml - /// - public partial class ModDetailsView : UserControl - { - public ModDetailsView() - { - InitializeComponent(); - } - - private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) - { - using var proc = new Process(); - proc.StartInfo.UseShellExecute = true; - proc.StartInfo.FileName = e.Uri.AbsoluteUri; - proc.Start(); - } - } -} +using System.Diagnostics; +using System.Windows.Controls; +using System.Windows.Navigation; + +namespace OpenKh.Tools.ModsManager.Views +{ + /// + /// Interaction logic for ModDetailsView.xaml + /// + public partial class ModDetailsView : UserControl + { + public ModDetailsView() + { + InitializeComponent(); + } + + private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) + { + using var proc = new Process(); + proc.StartInfo.UseShellExecute = true; + proc.StartInfo.FileName = e.Uri.AbsoluteUri; + proc.Start(); + } + } +} diff --git a/OpenKh.Tools.ModsManager/Views/ModManagerView.xaml.cs b/OpenKh.Tools.ModsManager/Views/ModManagerView.xaml.cs index 515be84f6..4cc26d2c2 100644 --- a/OpenKh.Tools.ModsManager/Views/ModManagerView.xaml.cs +++ b/OpenKh.Tools.ModsManager/Views/ModManagerView.xaml.cs @@ -1,25 +1,25 @@ -using OpenKh.Tools.ModsManager.ViewModels; -using System.Diagnostics; -using System.Windows.Controls; - -namespace OpenKh.Tools.ModsManager.Views -{ - /// - /// Interaction logic for ModManagerView.xaml - /// - public partial class ModManagerView : UserControl - { - public ModManagerView() - { - InitializeComponent(); - } - - private void ListBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) - { - if (e.Key == System.Windows.Input.Key.Delete) - (DataContext as MainViewModel).RemoveModCommand.Execute(null); - if (e.Key == System.Windows.Input.Key.Space) - (DataContext as MainViewModel).SelectedValue.Enabled = !(DataContext as MainViewModel).SelectedValue.Enabled; - } - } -} +using OpenKh.Tools.ModsManager.ViewModels; +using System.Diagnostics; +using System.Windows.Controls; + +namespace OpenKh.Tools.ModsManager.Views +{ + /// + /// Interaction logic for ModManagerView.xaml + /// + public partial class ModManagerView : UserControl + { + public ModManagerView() + { + InitializeComponent(); + } + + private void ListBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) + { + if (e.Key == System.Windows.Input.Key.Delete) + (DataContext as MainViewModel).RemoveModCommand.Execute(null); + if (e.Key == System.Windows.Input.Key.Space) + (DataContext as MainViewModel).SelectedValue.Enabled = !(DataContext as MainViewModel).SelectedValue.Enabled; + } + } +} diff --git a/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml.cs b/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml.cs index 29b45974e..f408eb08a 100644 --- a/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml.cs +++ b/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml.cs @@ -1,32 +1,32 @@ -using OpenKh.Tools.ModsManager.ViewModels; -using System.Windows; - -namespace OpenKh.Tools.ModsManager.Views -{ - /// - /// Interaction logic for SetupWizardWindow.xaml - /// - public partial class SetupWizardWindow : Window - { - private readonly SetupWizardViewModel _vm; - - public SetupWizardWindow() - { - InitializeComponent(); - DataContext = _vm = new SetupWizardViewModel(); - } - - public string ConfigIsoLocation { get => _vm.IsoLocation; set => _vm.IsoLocation = value; } - public int ConfigGameEdition { get => _vm.GameEdition; set => _vm.GameEdition = value; } - public string ConfigOpenKhGameEngineLocation { get => _vm.OpenKhGameEngineLocation; set => _vm.OpenKhGameEngineLocation = value; } - public string ConfigPcsx2Location { get => _vm.Pcsx2Location; set => _vm.Pcsx2Location = value; } - public string ConfigPcReleaseLocation { get => _vm.PcReleaseLocation; set => _vm.PcReleaseLocation = value; } - public string ConfigGameDataLocation { get => _vm.GameDataLocation; set => _vm.GameDataLocation = value; } - public int ConfigRegionId { get => _vm.RegionId; set => _vm.RegionId = value; } - - private void Wizard_Finish(object sender, Xceed.Wpf.Toolkit.Core.CancelRoutedEventArgs e) - { - DialogResult = true; - } - } -} +using OpenKh.Tools.ModsManager.ViewModels; +using System.Windows; + +namespace OpenKh.Tools.ModsManager.Views +{ + /// + /// Interaction logic for SetupWizardWindow.xaml + /// + public partial class SetupWizardWindow : Window + { + private readonly SetupWizardViewModel _vm; + + public SetupWizardWindow() + { + InitializeComponent(); + DataContext = _vm = new SetupWizardViewModel(); + } + + public string ConfigIsoLocation { get => _vm.IsoLocation; set => _vm.IsoLocation = value; } + public int ConfigGameEdition { get => _vm.GameEdition; set => _vm.GameEdition = value; } + public string ConfigOpenKhGameEngineLocation { get => _vm.OpenKhGameEngineLocation; set => _vm.OpenKhGameEngineLocation = value; } + public string ConfigPcsx2Location { get => _vm.Pcsx2Location; set => _vm.Pcsx2Location = value; } + public string ConfigPcReleaseLocation { get => _vm.PcReleaseLocation; set => _vm.PcReleaseLocation = value; } + public string ConfigGameDataLocation { get => _vm.GameDataLocation; set => _vm.GameDataLocation = value; } + public int ConfigRegionId { get => _vm.RegionId; set => _vm.RegionId = value; } + + private void Wizard_Finish(object sender, Xceed.Wpf.Toolkit.Core.CancelRoutedEventArgs e) + { + DialogResult = true; + } + } +} diff --git a/OpenKh.Tools.ObjentryEditor/App.xaml.cs b/OpenKh.Tools.ObjentryEditor/App.xaml.cs index d067fb4dc..8395e953e 100644 --- a/OpenKh.Tools.ObjentryEditor/App.xaml.cs +++ b/OpenKh.Tools.ObjentryEditor/App.xaml.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; - -namespace OpenKh.Tools.ObjentryEditor -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace OpenKh.Tools.ObjentryEditor +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/OpenKh.Tools.ObjentryEditor/Behavior/ScrollIntoViewBehavior.cs b/OpenKh.Tools.ObjentryEditor/Behavior/ScrollIntoViewBehavior.cs index e8ad1c5ac..aba4592bb 100644 --- a/OpenKh.Tools.ObjentryEditor/Behavior/ScrollIntoViewBehavior.cs +++ b/OpenKh.Tools.ObjentryEditor/Behavior/ScrollIntoViewBehavior.cs @@ -1,32 +1,32 @@ -//https://stackoverflow.com/questions/16866309/listbox-scroll-into-view-with-mvvm -using System.Collections.Specialized; -using System.Windows.Controls; -using System.Windows.Interactivity; - -namespace OpenKh.Tools.ObjentryEditor.Behavior -{ - public class ScrollIntoViewBehavior : Behavior - { - protected override void OnAttached() - { - ListBox listBox = AssociatedObject; - ((INotifyCollectionChanged)listBox.Items).CollectionChanged += OnListBox_CollectionChanged; - } - - protected override void OnDetaching() - { - ListBox listBox = AssociatedObject; - ((INotifyCollectionChanged)listBox.Items).CollectionChanged -= OnListBox_CollectionChanged; - } - - private void OnListBox_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - ListBox listBox = AssociatedObject; - if (e.Action == NotifyCollectionChangedAction.Add) - { - // scroll the new item into view - listBox.ScrollIntoView(e.NewItems[0]); - } - } - } -} +//https://stackoverflow.com/questions/16866309/listbox-scroll-into-view-with-mvvm +using System.Collections.Specialized; +using System.Windows.Controls; +using System.Windows.Interactivity; + +namespace OpenKh.Tools.ObjentryEditor.Behavior +{ + public class ScrollIntoViewBehavior : Behavior + { + protected override void OnAttached() + { + ListBox listBox = AssociatedObject; + ((INotifyCollectionChanged)listBox.Items).CollectionChanged += OnListBox_CollectionChanged; + } + + protected override void OnDetaching() + { + ListBox listBox = AssociatedObject; + ((INotifyCollectionChanged)listBox.Items).CollectionChanged -= OnListBox_CollectionChanged; + } + + private void OnListBox_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + ListBox listBox = AssociatedObject; + if (e.Action == NotifyCollectionChangedAction.Add) + { + // scroll the new item into view + listBox.ScrollIntoView(e.NewItems[0]); + } + } + } +} diff --git a/OpenKh.Tools.ObjentryEditor/Converters/EnumDescriptionConverter.cs b/OpenKh.Tools.ObjentryEditor/Converters/EnumDescriptionConverter.cs index 431c06a00..052029e0f 100644 --- a/OpenKh.Tools.ObjentryEditor/Converters/EnumDescriptionConverter.cs +++ b/OpenKh.Tools.ObjentryEditor/Converters/EnumDescriptionConverter.cs @@ -1,47 +1,47 @@ -using System; -using System.ComponentModel; -using System.Globalization; -using System.Reflection; -using System.Windows.Data; - -namespace OpenKh.Tools.ObjentryEditor.Converters -{ - public class EnumDescriptionConverter : IValueConverter - { - private string GetEnumDescription(Enum enumObj) - { - FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString()); - object[] attribArray = fieldInfo.GetCustomAttributes(false); - - if (attribArray.Length == 0) - return enumObj.ToString(); - else - { - DescriptionAttribute attrib = null; - - foreach (var att in attribArray) - { - if (att is DescriptionAttribute) - attrib = att as DescriptionAttribute; - } - - if (attrib != null) - return attrib.Description; - - return enumObj.ToString(); - } - } - - object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - Enum myEnum = (Enum)value; - string description = GetEnumDescription(myEnum); - return description; - } - - object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - return string.Empty; - } - } -} \ No newline at end of file +using System; +using System.ComponentModel; +using System.Globalization; +using System.Reflection; +using System.Windows.Data; + +namespace OpenKh.Tools.ObjentryEditor.Converters +{ + public class EnumDescriptionConverter : IValueConverter + { + private string GetEnumDescription(Enum enumObj) + { + FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString()); + object[] attribArray = fieldInfo.GetCustomAttributes(false); + + if (attribArray.Length == 0) + return enumObj.ToString(); + else + { + DescriptionAttribute attrib = null; + + foreach (var att in attribArray) + { + if (att is DescriptionAttribute) + attrib = att as DescriptionAttribute; + } + + if (attrib != null) + return attrib.Description; + + return enumObj.ToString(); + } + } + + object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + Enum myEnum = (Enum)value; + string description = GetEnumDescription(myEnum); + return description; + } + + object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return string.Empty; + } + } +} diff --git a/OpenKh.Tools.ObjentryEditor/ViewModels/MainViewModel.cs b/OpenKh.Tools.ObjentryEditor/ViewModels/MainViewModel.cs index f5e8ca15d..1d4df364f 100644 --- a/OpenKh.Tools.ObjentryEditor/ViewModels/MainViewModel.cs +++ b/OpenKh.Tools.ObjentryEditor/ViewModels/MainViewModel.cs @@ -1,104 +1,104 @@ -using OpenKh.Common; -using OpenKh.Kh2; -using OpenKh.Tools.Common; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Windows; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Dialogs; - - -namespace OpenKh.Tools.ObjentryEditor.ViewModels -{ - public class MainViewModel : BaseNotifyPropertyChanged - { - private static readonly string ApplicationName = Utilities.GetApplicationName(); - private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); - private string _fileName; - private static readonly List Filters = FileDialogFilterComposer.Compose().AddExtensions("00objentry.bin", "bin").AddAllFiles(); - - public string Title => $"{FileName ?? "untitled"} | {ApplicationName}"; - - public ObjentryViewModel Objentry { get; private set; } - - private string FileName - { - get => _fileName; - set - { - _fileName = value; - OnPropertyChanged(nameof(Title)); - } - } - - public RelayCommand OpenCommand { get; } - public RelayCommand SaveCommand { get; } - public RelayCommand SaveAsCommand { get; } - public RelayCommand ExitCommand { get; } - public RelayCommand AboutCommand { get; } - - public MainViewModel() - { - OpenCommand = new RelayCommand(x => - { - FileDialog.OnOpen(fileName => - { - OpenFile(fileName); - }, Filters); - }, x => true); - - SaveCommand = new RelayCommand(x => - { - if (!string.IsNullOrEmpty(FileName)) - { - SaveFile(FileName, FileName); - } - else - { - SaveAsCommand.Execute(x); - } - }, x => true); - - SaveAsCommand = new RelayCommand(x => - { - FileDialog.OnSave(fileName => - { - SaveFile(FileName, fileName); - FileName = fileName; - }, Filters); - }, x => true); - - ExitCommand = new RelayCommand(x => - { - Window.Close(); - }, x => true); - - AboutCommand = new RelayCommand(x => - { - new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); - }, x => true); - } - - public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => - { - Objentry = new ObjentryViewModel(Kh2.Objentry.Read(stream)); - OnPropertyChanged("Objentry"); - FileName = fileName; - return true; - }); - - public void SaveFile(string previousFileName, string fileName) - { - var search = Objentry.SearchTerm; - Objentry.SearchTerm = string.Empty; - - using (var f = File.Create(fileName)) - Kh2.Objentry.Write(f, Objentry.AsObjEntries()); - - Objentry.SearchTerm = search; - } - } -} +using OpenKh.Common; +using OpenKh.Kh2; +using OpenKh.Tools.Common; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Dialogs; + + +namespace OpenKh.Tools.ObjentryEditor.ViewModels +{ + public class MainViewModel : BaseNotifyPropertyChanged + { + private static readonly string ApplicationName = Utilities.GetApplicationName(); + private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); + private string _fileName; + private static readonly List Filters = FileDialogFilterComposer.Compose().AddExtensions("00objentry.bin", "bin").AddAllFiles(); + + public string Title => $"{FileName ?? "untitled"} | {ApplicationName}"; + + public ObjentryViewModel Objentry { get; private set; } + + private string FileName + { + get => _fileName; + set + { + _fileName = value; + OnPropertyChanged(nameof(Title)); + } + } + + public RelayCommand OpenCommand { get; } + public RelayCommand SaveCommand { get; } + public RelayCommand SaveAsCommand { get; } + public RelayCommand ExitCommand { get; } + public RelayCommand AboutCommand { get; } + + public MainViewModel() + { + OpenCommand = new RelayCommand(x => + { + FileDialog.OnOpen(fileName => + { + OpenFile(fileName); + }, Filters); + }, x => true); + + SaveCommand = new RelayCommand(x => + { + if (!string.IsNullOrEmpty(FileName)) + { + SaveFile(FileName, FileName); + } + else + { + SaveAsCommand.Execute(x); + } + }, x => true); + + SaveAsCommand = new RelayCommand(x => + { + FileDialog.OnSave(fileName => + { + SaveFile(FileName, fileName); + FileName = fileName; + }, Filters); + }, x => true); + + ExitCommand = new RelayCommand(x => + { + Window.Close(); + }, x => true); + + AboutCommand = new RelayCommand(x => + { + new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog(); + }, x => true); + } + + public bool OpenFile(string fileName) => File.OpenRead(fileName).Using(stream => + { + Objentry = new ObjentryViewModel(Kh2.Objentry.Read(stream)); + OnPropertyChanged("Objentry"); + FileName = fileName; + return true; + }); + + public void SaveFile(string previousFileName, string fileName) + { + var search = Objentry.SearchTerm; + Objentry.SearchTerm = string.Empty; + + using (var f = File.Create(fileName)) + Kh2.Objentry.Write(f, Objentry.AsObjEntries()); + + Objentry.SearchTerm = search; + } + } +} diff --git a/OpenKh.Tools.ObjentryEditor/ViewModels/ObjentryViewModel.cs b/OpenKh.Tools.ObjentryEditor/ViewModels/ObjentryViewModel.cs index 7b1f51e58..dcd1b502d 100644 --- a/OpenKh.Tools.ObjentryEditor/ViewModels/ObjentryViewModel.cs +++ b/OpenKh.Tools.ObjentryEditor/ViewModels/ObjentryViewModel.cs @@ -1,195 +1,195 @@ -using OpenKh.Kh2; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Windows; -using Xe.Tools; -using Xe.Tools.Models; -using Xe.Tools.Wpf.Commands; -using Xe.Tools.Wpf.Models; - -namespace OpenKh.Tools.ObjentryEditor.ViewModels -{ - public class ObjentryViewModel : GenericListModel - { - public class ObjentryEntryViewModel : BaseNotifyPropertyChanged - { - public Objentry Objentry { get; } - - public ObjentryEntryViewModel(Objentry objEntry) - { - Objentry = objEntry; - } - - public string Name => $"{Id} {ModelName}"; - - public string Id => $"{Objentry.ObjectId:X02}"; - - public uint ObjectId - { - get => Objentry.ObjectId; - set { Objentry.ObjectId = value; OnPropertyChanged(nameof(Name)); } - } - - public Objentry.Type ObjectType - { - get => Objentry.ObjectType; - set - { - Objentry.ObjectType = value; - OnPropertyChanged(nameof(ObjectType)); - } - } - public byte SubType { get => Objentry.SubType; set => Objentry.SubType = value; } - public byte DrawPriority { get => Objentry.DrawPriority; set => Objentry.DrawPriority = value; } - public byte WeaponJoint { get => Objentry.WeaponJoint; set => Objentry.WeaponJoint = value; } - public string ModelName { get => Objentry.ModelName; set => Objentry.ModelName = value; } - public string AnimationName { get => Objentry.AnimationName; set => Objentry.AnimationName = value; } - public ushort Flag { get => Objentry.Flag; set => Objentry.Flag = value; } - public byte TargetType { get => Objentry.TargetType; set => Objentry.TargetType = value; } - public ushort NeoStatus { get => Objentry.NeoStatus; set => Objentry.NeoStatus = value; } - public ushort NeoMoveset { get => Objentry.NeoMoveset; set => Objentry.NeoMoveset = value; } - public float Weight { get => Objentry.Weight; set => Objentry.Weight = value; } - public byte SpawnLimiter { get => Objentry.SpawnLimiter; set => Objentry.SpawnLimiter = value; } - public byte Page { get => Objentry.Page; set => Objentry.Page = value; } - public byte ShadowSize { get => Objentry.ShadowSize; set => Objentry.ShadowSize = value; } - public Objentry.CommandMenuOptions CommandMenuOption - { - get => Objentry.CommandMenuOption; - set - { - Objentry.CommandMenuOption = value; - OnPropertyChanged(nameof(CommandMenuOption)); - } - } - public ushort SpawnObject1 { get => Objentry.SpawnObject1; set => Objentry.SpawnObject1 = value; } - public ushort SpawnObject2 { get => Objentry.SpawnObject2; set => Objentry.SpawnObject2 = value; } - public ushort SpawnObject3 { get => Objentry.SpawnObject3; set => Objentry.SpawnObject3 = value; } - public ushort SpawnObject4 { get => Objentry.SpawnObject4; set => Objentry.SpawnObject4 = value; } - - public override string ToString() => Name; - } - - - private string _searchTerm; - - public EnumModel ObjEntryTypes { get; } - public EnumModel CommandMenuOptions { get; } - - public ObjentryViewModel(IEnumerable items) : - base(items.Select(Map)) - { - ObjEntryTypes = new EnumModel(); - CommandMenuOptions = new EnumModel(); - AddAndSelectCommand = new RelayCommand(x => - { - AddCommand.Execute(null); - SelectedIndex = Items.Count - 1; - }); - - CloneCommand = new RelayCommand(x => - { - var clonedItem = Clone(SelectedItem.Objentry); - Items.Add(new ObjentryEntryViewModel(clonedItem)); - OnPropertyChanged(nameof(Items)); - }, x => SelectedItem != null); - - ClearObject1 = new RelayCommand(x => - { - SelectedItem.SpawnObject1 = 0; - OnPropertyChanged(nameof(SelectedItem)); - }); - - ClearObject2 = new RelayCommand(x => - { - SelectedItem.SpawnObject2 = 0; - OnPropertyChanged(nameof(SelectedItem)); - }); - - ClearObject3 = new RelayCommand(x => - { - SelectedItem.SpawnObject3 = 0; - OnPropertyChanged(nameof(SelectedItem)); - }); - - ClearObject4 = new RelayCommand(x => - { - SelectedItem.SpawnObject4 = 0; - OnPropertyChanged(nameof(SelectedItem)); - }); - } - - public RelayCommand AddAndSelectCommand { get; set; } - public RelayCommand CloneCommand { get; set; } - - public RelayCommand ClearObject1 { get; set; } - public RelayCommand ClearObject2 { get; set; } - public RelayCommand ClearObject3 { get; set; } - public RelayCommand ClearObject4 { get; set; } - - public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; - - public string SearchTerm - { - get => _searchTerm; - set - { - _searchTerm = value; - PerformFiltering(); - } - } - - public IEnumerable AsObjEntries() => Items.Select(x => x.Objentry); - - protected override void OnSelectedItem(ObjentryEntryViewModel item) - { - base.OnSelectedItem(item); - - OnPropertyChanged(nameof(IsItemEditingVisible)); - OnPropertyChanged(nameof(IsItemEditMessageVisible)); - } - - private void PerformFiltering() - { - if (string.IsNullOrWhiteSpace(_searchTerm)) - Filter(FilterNone); - else - Filter(FilterByCharacter); - } - - protected override ObjentryEntryViewModel OnNewItem() - { - return new ObjentryEntryViewModel(new Objentry() - { - ObjectId = GetObjectIdForNewEntry() - }); - } - - private Objentry Clone(Objentry source) - { - var newObj = Activator.CreateInstance(); - foreach(var field in newObj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) - { - field.SetValue(newObj, field.GetValue(source)); - } - - newObj.ObjectId = GetObjectIdForNewEntry(); - return newObj; - } - - private ushort GetObjectIdForNewEntry() - { - return (ushort)(Items.LastOrDefault()?.ObjectId + 1 ?? 0); - } - - private bool FilterNone(ObjentryEntryViewModel arg) => true; - - private bool FilterByCharacter(ObjentryEntryViewModel arg) => - arg.Name.ToUpper().Contains(SearchTerm.ToUpper()); - - private static ObjentryEntryViewModel Map(Objentry item) => - new ObjentryEntryViewModel(item); - } -} +using OpenKh.Kh2; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Windows; +using Xe.Tools; +using Xe.Tools.Models; +using Xe.Tools.Wpf.Commands; +using Xe.Tools.Wpf.Models; + +namespace OpenKh.Tools.ObjentryEditor.ViewModels +{ + public class ObjentryViewModel : GenericListModel + { + public class ObjentryEntryViewModel : BaseNotifyPropertyChanged + { + public Objentry Objentry { get; } + + public ObjentryEntryViewModel(Objentry objEntry) + { + Objentry = objEntry; + } + + public string Name => $"{Id} {ModelName}"; + + public string Id => $"{Objentry.ObjectId:X02}"; + + public uint ObjectId + { + get => Objentry.ObjectId; + set { Objentry.ObjectId = value; OnPropertyChanged(nameof(Name)); } + } + + public Objentry.Type ObjectType + { + get => Objentry.ObjectType; + set + { + Objentry.ObjectType = value; + OnPropertyChanged(nameof(ObjectType)); + } + } + public byte SubType { get => Objentry.SubType; set => Objentry.SubType = value; } + public byte DrawPriority { get => Objentry.DrawPriority; set => Objentry.DrawPriority = value; } + public byte WeaponJoint { get => Objentry.WeaponJoint; set => Objentry.WeaponJoint = value; } + public string ModelName { get => Objentry.ModelName; set => Objentry.ModelName = value; } + public string AnimationName { get => Objentry.AnimationName; set => Objentry.AnimationName = value; } + public ushort Flag { get => Objentry.Flag; set => Objentry.Flag = value; } + public byte TargetType { get => Objentry.TargetType; set => Objentry.TargetType = value; } + public ushort NeoStatus { get => Objentry.NeoStatus; set => Objentry.NeoStatus = value; } + public ushort NeoMoveset { get => Objentry.NeoMoveset; set => Objentry.NeoMoveset = value; } + public float Weight { get => Objentry.Weight; set => Objentry.Weight = value; } + public byte SpawnLimiter { get => Objentry.SpawnLimiter; set => Objentry.SpawnLimiter = value; } + public byte Page { get => Objentry.Page; set => Objentry.Page = value; } + public byte ShadowSize { get => Objentry.ShadowSize; set => Objentry.ShadowSize = value; } + public Objentry.CommandMenuOptions CommandMenuOption + { + get => Objentry.CommandMenuOption; + set + { + Objentry.CommandMenuOption = value; + OnPropertyChanged(nameof(CommandMenuOption)); + } + } + public ushort SpawnObject1 { get => Objentry.SpawnObject1; set => Objentry.SpawnObject1 = value; } + public ushort SpawnObject2 { get => Objentry.SpawnObject2; set => Objentry.SpawnObject2 = value; } + public ushort SpawnObject3 { get => Objentry.SpawnObject3; set => Objentry.SpawnObject3 = value; } + public ushort SpawnObject4 { get => Objentry.SpawnObject4; set => Objentry.SpawnObject4 = value; } + + public override string ToString() => Name; + } + + + private string _searchTerm; + + public EnumModel ObjEntryTypes { get; } + public EnumModel CommandMenuOptions { get; } + + public ObjentryViewModel(IEnumerable items) : + base(items.Select(Map)) + { + ObjEntryTypes = new EnumModel(); + CommandMenuOptions = new EnumModel(); + AddAndSelectCommand = new RelayCommand(x => + { + AddCommand.Execute(null); + SelectedIndex = Items.Count - 1; + }); + + CloneCommand = new RelayCommand(x => + { + var clonedItem = Clone(SelectedItem.Objentry); + Items.Add(new ObjentryEntryViewModel(clonedItem)); + OnPropertyChanged(nameof(Items)); + }, x => SelectedItem != null); + + ClearObject1 = new RelayCommand(x => + { + SelectedItem.SpawnObject1 = 0; + OnPropertyChanged(nameof(SelectedItem)); + }); + + ClearObject2 = new RelayCommand(x => + { + SelectedItem.SpawnObject2 = 0; + OnPropertyChanged(nameof(SelectedItem)); + }); + + ClearObject3 = new RelayCommand(x => + { + SelectedItem.SpawnObject3 = 0; + OnPropertyChanged(nameof(SelectedItem)); + }); + + ClearObject4 = new RelayCommand(x => + { + SelectedItem.SpawnObject4 = 0; + OnPropertyChanged(nameof(SelectedItem)); + }); + } + + public RelayCommand AddAndSelectCommand { get; set; } + public RelayCommand CloneCommand { get; set; } + + public RelayCommand ClearObject1 { get; set; } + public RelayCommand ClearObject2 { get; set; } + public RelayCommand ClearObject3 { get; set; } + public RelayCommand ClearObject4 { get; set; } + + public Visibility IsItemEditingVisible => IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + public Visibility IsItemEditMessageVisible => !IsItemSelected ? Visibility.Visible : Visibility.Collapsed; + + public string SearchTerm + { + get => _searchTerm; + set + { + _searchTerm = value; + PerformFiltering(); + } + } + + public IEnumerable AsObjEntries() => Items.Select(x => x.Objentry); + + protected override void OnSelectedItem(ObjentryEntryViewModel item) + { + base.OnSelectedItem(item); + + OnPropertyChanged(nameof(IsItemEditingVisible)); + OnPropertyChanged(nameof(IsItemEditMessageVisible)); + } + + private void PerformFiltering() + { + if (string.IsNullOrWhiteSpace(_searchTerm)) + Filter(FilterNone); + else + Filter(FilterByCharacter); + } + + protected override ObjentryEntryViewModel OnNewItem() + { + return new ObjentryEntryViewModel(new Objentry() + { + ObjectId = GetObjectIdForNewEntry() + }); + } + + private Objentry Clone(Objentry source) + { + var newObj = Activator.CreateInstance(); + foreach (var field in newObj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) + { + field.SetValue(newObj, field.GetValue(source)); + } + + newObj.ObjectId = GetObjectIdForNewEntry(); + return newObj; + } + + private ushort GetObjectIdForNewEntry() + { + return (ushort)(Items.LastOrDefault()?.ObjectId + 1 ?? 0); + } + + private bool FilterNone(ObjentryEntryViewModel arg) => true; + + private bool FilterByCharacter(ObjentryEntryViewModel arg) => + arg.Name.ToUpper().Contains(SearchTerm.ToUpper()); + + private static ObjentryEntryViewModel Map(Objentry item) => + new ObjentryEntryViewModel(item); + } +} diff --git a/OpenKh.Tools.ObjentryEditor/Views/MainWindow.xaml.cs b/OpenKh.Tools.ObjentryEditor/Views/MainWindow.xaml.cs index 46b6ece97..945bb0e4e 100644 --- a/OpenKh.Tools.ObjentryEditor/Views/MainWindow.xaml.cs +++ b/OpenKh.Tools.ObjentryEditor/Views/MainWindow.xaml.cs @@ -1,17 +1,17 @@ -using OpenKh.Tools.ObjentryEditor.ViewModels; -using System.Windows; - -namespace OpenKh.Tools.ObjentryEditor -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); - DataContext = new MainViewModel(); - } - } -} +using OpenKh.Tools.ObjentryEditor.ViewModels; +using System.Windows; + +namespace OpenKh.Tools.ObjentryEditor +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + DataContext = new MainViewModel(); + } + } +} diff --git a/OpenKh.Tools.ObjentryEditor/Views/ObjentryView.xaml.cs b/OpenKh.Tools.ObjentryEditor/Views/ObjentryView.xaml.cs index 78d421d1b..3efbbc549 100644 --- a/OpenKh.Tools.ObjentryEditor/Views/ObjentryView.xaml.cs +++ b/OpenKh.Tools.ObjentryEditor/Views/ObjentryView.xaml.cs @@ -1,28 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace OpenKh.Tools.ObjentryEditor.Views -{ - /// - /// Interaction logic for ObjentryView.xaml - /// - public partial class ObjentryView : UserControl - { - public ObjentryView() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace OpenKh.Tools.ObjentryEditor.Views +{ + /// + /// Interaction logic for ObjentryView.xaml + /// + public partial class ObjentryView : UserControl + { + public ObjentryView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.WinShell.IMDUtilities/IMDConvert.cs b/OpenKh.WinShell.IMDUtilities/IMDConvert.cs index a82a604d3..23b70c630 100644 --- a/OpenKh.WinShell.IMDUtilities/IMDConvert.cs +++ b/OpenKh.WinShell.IMDUtilities/IMDConvert.cs @@ -1,59 +1,59 @@ -using System; -using System.IO; -using System.Drawing; -using System.Windows.Forms; -using System.Runtime.InteropServices; - -using SharpShell.Attributes; -using SharpShell.SharpContextMenu; - -using OpenKh.Kh2; -using OpenKh.Imaging; - -namespace OpenKh.WinShell.IMDUtilities -{ - [Obsolete] - [ComVisible(true)] - [COMServerAssociation(AssociationType.FileExtension, ".imd")] - public class IMDConvert : SharpContextMenu - { - protected override bool CanShowMenu() - { - return true; - } - - protected override ContextMenuStrip CreateMenu() - { - var menu = new ContextMenuStrip(); - - var itemConvert = new ToolStripMenuItem - { - Text = "Convert to PNG..." - }; - - itemConvert.Click += (sender, args) => ConvertPNG(); - - menu.Items.Add(itemConvert); - return menu; - } - - private void ConvertPNG() - { - foreach (var filePath in SelectedItemPaths) - { - using (FileStream _cStream = new FileStream(filePath, FileMode.Open)) - { - Imgd _tImage = Imgd.Read(_cStream); - - var size = _tImage.Size; - var data = _tImage.ToBgra32(); - - MarshalBitmap _tBitmap = new MarshalBitmap(size.Width, size.Height, data); - _tBitmap.Bitmap.Save(filePath.Replace(".imd", ".png")); - - _tBitmap.Dispose(); - } - } - } - } -} +using System; +using System.IO; +using System.Drawing; +using System.Windows.Forms; +using System.Runtime.InteropServices; + +using SharpShell.Attributes; +using SharpShell.SharpContextMenu; + +using OpenKh.Kh2; +using OpenKh.Imaging; + +namespace OpenKh.WinShell.IMDUtilities +{ + [Obsolete] + [ComVisible(true)] + [COMServerAssociation(AssociationType.FileExtension, ".imd")] + public class IMDConvert : SharpContextMenu + { + protected override bool CanShowMenu() + { + return true; + } + + protected override ContextMenuStrip CreateMenu() + { + var menu = new ContextMenuStrip(); + + var itemConvert = new ToolStripMenuItem + { + Text = "Convert to PNG..." + }; + + itemConvert.Click += (sender, args) => ConvertPNG(); + + menu.Items.Add(itemConvert); + return menu; + } + + private void ConvertPNG() + { + foreach (var filePath in SelectedItemPaths) + { + using (FileStream _cStream = new FileStream(filePath, FileMode.Open)) + { + Imgd _tImage = Imgd.Read(_cStream); + + var size = _tImage.Size; + var data = _tImage.ToBgra32(); + + MarshalBitmap _tBitmap = new MarshalBitmap(size.Width, size.Height, data); + _tBitmap.Bitmap.Save(filePath.Replace(".imd", ".png")); + + _tBitmap.Dispose(); + } + } + } + } +} diff --git a/OpenKh.WinShell.IMDUtilities/IMDThumbnail.cs b/OpenKh.WinShell.IMDUtilities/IMDThumbnail.cs index 916f64c44..7e8691e05 100644 --- a/OpenKh.WinShell.IMDUtilities/IMDThumbnail.cs +++ b/OpenKh.WinShell.IMDUtilities/IMDThumbnail.cs @@ -1,41 +1,41 @@ -using System; -using System.IO; -using System.Drawing; -using System.Runtime.InteropServices; - -using SharpShell.Attributes; -using SharpShell.SharpThumbnailHandler; - -using OpenKh.Kh2; -using OpenKh.Imaging; - -namespace OpenKh.WinShell.IMDUtilities -{ - [Obsolete] - [ComVisible(true)] - [COMServerAssociation(AssociationType.FileExtension, ".imd")] - public class IMDThumbnail : SharpThumbnailHandler - { - Lazy _tImage; - Lazy _rBitmap; - protected override Bitmap GetThumbnailImage(uint width) - { - using (MemoryStream _cStream = new MemoryStream()) - { - SelectedItemStream.CopyTo(_cStream); - SelectedItemStream.Dispose(); - - _tImage = new Lazy(() => Imgd.Read(_cStream)); - - var size = _tImage.Value.Size; - var data = _tImage.Value.ToBgra32(); - - using (MarshalBitmap _tBitmap = new MarshalBitmap(size.Width, size.Height, data)) - { - _rBitmap = new Lazy(() => new Bitmap(_tBitmap.Bitmap, (int)width, (int)width)); - return _rBitmap.Value; - } - } - } - } -} +using System; +using System.IO; +using System.Drawing; +using System.Runtime.InteropServices; + +using SharpShell.Attributes; +using SharpShell.SharpThumbnailHandler; + +using OpenKh.Kh2; +using OpenKh.Imaging; + +namespace OpenKh.WinShell.IMDUtilities +{ + [Obsolete] + [ComVisible(true)] + [COMServerAssociation(AssociationType.FileExtension, ".imd")] + public class IMDThumbnail : SharpThumbnailHandler + { + Lazy _tImage; + Lazy _rBitmap; + protected override Bitmap GetThumbnailImage(uint width) + { + using (MemoryStream _cStream = new MemoryStream()) + { + SelectedItemStream.CopyTo(_cStream); + SelectedItemStream.Dispose(); + + _tImage = new Lazy(() => Imgd.Read(_cStream)); + + var size = _tImage.Value.Size; + var data = _tImage.Value.ToBgra32(); + + using (MarshalBitmap _tBitmap = new MarshalBitmap(size.Width, size.Height, data)) + { + _rBitmap = new Lazy(() => new Bitmap(_tBitmap.Bitmap, (int)width, (int)width)); + return _rBitmap.Value; + } + } + } + } +} diff --git a/OpenKh.WinShell.IMDUtilities/MarshalBitmap.cs b/OpenKh.WinShell.IMDUtilities/MarshalBitmap.cs index ee8cb1bb0..992e2b07b 100644 --- a/OpenKh.WinShell.IMDUtilities/MarshalBitmap.cs +++ b/OpenKh.WinShell.IMDUtilities/MarshalBitmap.cs @@ -1,63 +1,63 @@ -using System; -using System.Drawing; -using System.Drawing.Imaging; -using System.Runtime.InteropServices; - -namespace OpenKh.WinShell.IMDUtilities -{ - public class MarshalBitmap : IDisposable - { - public Bitmap Bitmap { get; private set; } - public int[] Bits { get; private set; } - public bool Disposed { get; private set; } - public int Height { get; private set; } - public int Width { get; private set; } - private protected GCHandle BitsHandle { get; private set; } - - public MarshalBitmap(int width, int height) - { - Width = width; - Height = height; - Bits = new int[width * height]; - BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); - Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); - } - - public MarshalBitmap(int width, int height, byte[] bits) - { - Width = width; - Height = height; - - Bits = new int[width * height]; - - for (int i = 0; i < bits.Length; i += 4) - Bits[i / 4] = BitConverter.ToInt32(bits, i); - - BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); - Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); - } - - public MarshalBitmap(Bitmap Input) - { - BitmapData bitmapData = Input.LockBits(new Rectangle(default(Point), Input.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); - Width = Input.Width; - Height = Input.Height; - int num = bitmapData.Stride * Input.Height; - Bits = new int[num / 4]; - Marshal.Copy(bitmapData.Scan0, Bits, 0, num / 4); - Input.UnlockBits(bitmapData); - BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); - Bitmap = new Bitmap(Width, Height, Width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); - } - - public void Dispose() - { - if (!Disposed) - { - Disposed = true; - Bitmap.Dispose(); - BitsHandle.Free(); - } - } - } -} +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; + +namespace OpenKh.WinShell.IMDUtilities +{ + public class MarshalBitmap : IDisposable + { + public Bitmap Bitmap { get; private set; } + public int[] Bits { get; private set; } + public bool Disposed { get; private set; } + public int Height { get; private set; } + public int Width { get; private set; } + private protected GCHandle BitsHandle { get; private set; } + + public MarshalBitmap(int width, int height) + { + Width = width; + Height = height; + Bits = new int[width * height]; + BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); + Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); + } + + public MarshalBitmap(int width, int height, byte[] bits) + { + Width = width; + Height = height; + + Bits = new int[width * height]; + + for (int i = 0; i < bits.Length; i += 4) + Bits[i / 4] = BitConverter.ToInt32(bits, i); + + BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); + Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); + } + + public MarshalBitmap(Bitmap Input) + { + BitmapData bitmapData = Input.LockBits(new Rectangle(default(Point), Input.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); + Width = Input.Width; + Height = Input.Height; + int num = bitmapData.Stride * Input.Height; + Bits = new int[num / 4]; + Marshal.Copy(bitmapData.Scan0, Bits, 0, num / 4); + Input.UnlockBits(bitmapData); + BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); + Bitmap = new Bitmap(Width, Height, Width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); + } + + public void Dispose() + { + if (!Disposed) + { + Disposed = true; + Bitmap.Dispose(); + BitsHandle.Free(); + } + } + } +} diff --git a/OpenKh.WinShell.IMZUtilities/IMZExtract.cs b/OpenKh.WinShell.IMZUtilities/IMZExtract.cs index 1c70e66b0..0e07209f2 100644 --- a/OpenKh.WinShell.IMZUtilities/IMZExtract.cs +++ b/OpenKh.WinShell.IMZUtilities/IMZExtract.cs @@ -1,64 +1,64 @@ -using System; -using System.IO; -using System.Drawing; -using System.Windows.Forms; -using System.Runtime.InteropServices; - -using SharpShell.Attributes; -using SharpShell.SharpContextMenu; - -using OpenKh.Kh2; -using OpenKh.Imaging; - -namespace OpenKh.WinShell.IMZUtilities -{ - [Obsolete] - [ComVisible(true)] - [COMServerAssociation(AssociationType.FileExtension, ".imz")] - public class IMZExtract : SharpContextMenu - { - protected override bool CanShowMenu() - { - return true; - } - - protected override ContextMenuStrip CreateMenu() - { - var menu = new ContextMenuStrip(); - - var itemExtract = new ToolStripMenuItem { Text = "Extract IMGZ..." }; - itemExtract.Click += (sender, args) => ExtractFunction(); - - menu.Items.Add(itemExtract); - return menu; - } - - private void ExtractFunction() - { - foreach (var filePath in SelectedItemPaths) - { - using (FileStream _cStream = new FileStream(filePath, FileMode.Open)) - { - string _fPath = filePath.Replace(".imz", ""); - Imgz _tArchive = new Imgz(_cStream); - - Directory.CreateDirectory(_fPath); - int _i = 0; - - foreach (var _tImage in _tArchive.Images) - { - using (FileStream _tStream = new FileStream(_fPath + string.Format("\\{0}.imd", _i.ToString("000")), FileMode.OpenOrCreate)) - { - _tImage.Write(_tStream); - _tStream.Close(); - } - - _i++; - } - - _cStream.Close(); - } - } - } - } -} +using System; +using System.IO; +using System.Drawing; +using System.Windows.Forms; +using System.Runtime.InteropServices; + +using SharpShell.Attributes; +using SharpShell.SharpContextMenu; + +using OpenKh.Kh2; +using OpenKh.Imaging; + +namespace OpenKh.WinShell.IMZUtilities +{ + [Obsolete] + [ComVisible(true)] + [COMServerAssociation(AssociationType.FileExtension, ".imz")] + public class IMZExtract : SharpContextMenu + { + protected override bool CanShowMenu() + { + return true; + } + + protected override ContextMenuStrip CreateMenu() + { + var menu = new ContextMenuStrip(); + + var itemExtract = new ToolStripMenuItem { Text = "Extract IMGZ..." }; + itemExtract.Click += (sender, args) => ExtractFunction(); + + menu.Items.Add(itemExtract); + return menu; + } + + private void ExtractFunction() + { + foreach (var filePath in SelectedItemPaths) + { + using (FileStream _cStream = new FileStream(filePath, FileMode.Open)) + { + string _fPath = filePath.Replace(".imz", ""); + Imgz _tArchive = new Imgz(_cStream); + + Directory.CreateDirectory(_fPath); + int _i = 0; + + foreach (var _tImage in _tArchive.Images) + { + using (FileStream _tStream = new FileStream(_fPath + string.Format("\\{0}.imd", _i.ToString("000")), FileMode.OpenOrCreate)) + { + _tImage.Write(_tStream); + _tStream.Close(); + } + + _i++; + } + + _cStream.Close(); + } + } + } + } +} diff --git a/OpenKh.WinShell.IMZUtilities/IMZRepack.cs b/OpenKh.WinShell.IMZUtilities/IMZRepack.cs index 5717a8be8..058094a86 100644 --- a/OpenKh.WinShell.IMZUtilities/IMZRepack.cs +++ b/OpenKh.WinShell.IMZUtilities/IMZRepack.cs @@ -1,62 +1,62 @@ -using System; -using System.IO; -using System.Drawing; -using System.Windows.Forms; -using System.Runtime.InteropServices; - -using SharpShell.Attributes; -using SharpShell.SharpContextMenu; - -using OpenKh.Kh2; -using OpenKh.Imaging; -using System.Collections.Generic; - -namespace OpenKh.WinShell.IMZUtilities -{ - [Obsolete] - [ComVisible(true)] - [COMServerAssociation(AssociationType.FileExtension, ".imd")] - public class IMZRepack : SharpContextMenu - { - protected override bool CanShowMenu() - { - return true; - } - - protected override ContextMenuStrip CreateMenu() - { - var menu = new ContextMenuStrip(); - - var itemPack = new ToolStripMenuItem { Text = "Pack into IMGZ..." }; - itemPack.Click += (sender, args) => RepackFunction(); - - menu.Items.Add(itemPack); - return menu; - } - - private void RepackFunction() - { - List _tList = new List(); - string _rPath = ""; - - foreach (var filePath in SelectedItemPaths) - { - if (_rPath == "") - _rPath = Path.GetDirectoryName(filePath); - - using (FileStream _cStream = new FileStream(filePath, FileMode.Open)) - { - Imgd _tImage = Imgd.Read(_cStream); - _tList.Add(_tImage); - _cStream.Close(); - } - } - - using (FileStream _oStream = new FileStream(_rPath + "\\output.imz", FileMode.OpenOrCreate)) - { - Imgz.Write(_oStream, _tList.ToArray()); - _oStream.Close(); - } - } - } -} +using System; +using System.IO; +using System.Drawing; +using System.Windows.Forms; +using System.Runtime.InteropServices; + +using SharpShell.Attributes; +using SharpShell.SharpContextMenu; + +using OpenKh.Kh2; +using OpenKh.Imaging; +using System.Collections.Generic; + +namespace OpenKh.WinShell.IMZUtilities +{ + [Obsolete] + [ComVisible(true)] + [COMServerAssociation(AssociationType.FileExtension, ".imd")] + public class IMZRepack : SharpContextMenu + { + protected override bool CanShowMenu() + { + return true; + } + + protected override ContextMenuStrip CreateMenu() + { + var menu = new ContextMenuStrip(); + + var itemPack = new ToolStripMenuItem { Text = "Pack into IMGZ..." }; + itemPack.Click += (sender, args) => RepackFunction(); + + menu.Items.Add(itemPack); + return menu; + } + + private void RepackFunction() + { + List _tList = new List(); + string _rPath = ""; + + foreach (var filePath in SelectedItemPaths) + { + if (_rPath == "") + _rPath = Path.GetDirectoryName(filePath); + + using (FileStream _cStream = new FileStream(filePath, FileMode.Open)) + { + Imgd _tImage = Imgd.Read(_cStream); + _tList.Add(_tImage); + _cStream.Close(); + } + } + + using (FileStream _oStream = new FileStream(_rPath + "\\output.imz", FileMode.OpenOrCreate)) + { + Imgz.Write(_oStream, _tList.ToArray()); + _oStream.Close(); + } + } + } +} diff --git a/OpenKh.WinShell.IMZUtilities/MarshalBitmap.cs b/OpenKh.WinShell.IMZUtilities/MarshalBitmap.cs index dfcedc93f..8acd54364 100644 --- a/OpenKh.WinShell.IMZUtilities/MarshalBitmap.cs +++ b/OpenKh.WinShell.IMZUtilities/MarshalBitmap.cs @@ -1,63 +1,63 @@ -using System; -using System.Drawing; -using System.Drawing.Imaging; -using System.Runtime.InteropServices; - -namespace OpenKh.WinShell.IMZUtilities -{ - public class MarshalBitmap : IDisposable - { - public Bitmap Bitmap { get; private set; } - public int[] Bits { get; private set; } - public bool Disposed { get; private set; } - public int Height { get; private set; } - public int Width { get; private set; } - private protected GCHandle BitsHandle { get; private set; } - - public MarshalBitmap(int width, int height) - { - Width = width; - Height = height; - Bits = new int[width * height]; - BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); - Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); - } - - public MarshalBitmap(int width, int height, byte[] bits) - { - Width = width; - Height = height; - - Bits = new int[width * height]; - - for (int i = 0; i < bits.Length; i += 4) - Bits[i / 4] = BitConverter.ToInt32(bits, i); - - BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); - Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); - } - - public MarshalBitmap(Bitmap Input) - { - BitmapData bitmapData = Input.LockBits(new Rectangle(default(Point), Input.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); - Width = Input.Width; - Height = Input.Height; - int num = bitmapData.Stride * Input.Height; - Bits = new int[num / 4]; - Marshal.Copy(bitmapData.Scan0, Bits, 0, num / 4); - Input.UnlockBits(bitmapData); - BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); - Bitmap = new Bitmap(Width, Height, Width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); - } - - public void Dispose() - { - if (!Disposed) - { - Disposed = true; - Bitmap.Dispose(); - BitsHandle.Free(); - } - } - } -} +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; + +namespace OpenKh.WinShell.IMZUtilities +{ + public class MarshalBitmap : IDisposable + { + public Bitmap Bitmap { get; private set; } + public int[] Bits { get; private set; } + public bool Disposed { get; private set; } + public int Height { get; private set; } + public int Width { get; private set; } + private protected GCHandle BitsHandle { get; private set; } + + public MarshalBitmap(int width, int height) + { + Width = width; + Height = height; + Bits = new int[width * height]; + BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); + Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); + } + + public MarshalBitmap(int width, int height, byte[] bits) + { + Width = width; + Height = height; + + Bits = new int[width * height]; + + for (int i = 0; i < bits.Length; i += 4) + Bits[i / 4] = BitConverter.ToInt32(bits, i); + + BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); + Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); + } + + public MarshalBitmap(Bitmap Input) + { + BitmapData bitmapData = Input.LockBits(new Rectangle(default(Point), Input.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); + Width = Input.Width; + Height = Input.Height; + int num = bitmapData.Stride * Input.Height; + Bits = new int[num / 4]; + Marshal.Copy(bitmapData.Scan0, Bits, 0, num / 4); + Input.UnlockBits(bitmapData); + BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); + Bitmap = new Bitmap(Width, Height, Width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); + } + + public void Dispose() + { + if (!Disposed) + { + Disposed = true; + Bitmap.Dispose(); + BitsHandle.Free(); + } + } + } +} diff --git a/Playground/Program.cs b/Playground/Program.cs index 182554352..7a15daee7 100644 --- a/Playground/Program.cs +++ b/Playground/Program.cs @@ -1,56 +1,56 @@ -using OpenKh.Common; -using OpenKh.Kh1; -using OpenKh.Kh2; -using OpenKh.Bbs; -using OpenKh.Tools.Common; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; -using OpenKh.Tools.Common.Imaging; - -const string Input = @"D:\kh2\somefile.bar"; -const string Output = @"D:\kh2\modifiedfile.bar"; - -Console.WriteLine("Hello OpenKH!"); - -var idxs = File.OpenRead(@"E:\Hacking\KH1\KINGDOM.IDX").Using(Idx1.Read); -var names = Idx1Name.Lookup(idxs.OrderBy(x => x.IsoBlock)).OrderBy(x => x.Entry.Hash).ToList(); -File.WriteAllLines(@"D:\asd.txt", names.Select(x => x.ToString())); -var aaa = File - .ReadAllLines(Path.Combine(AppContext.BaseDirectory, "resources/kh1idx.txt")) - .Select(x => new - { - Name = x, - Hash = Idx1.GetHash(x) - }) - .GroupBy(x => x.Hash) - .Where(x => x.Count() > 1) - .Select(x => new - { - Name1 = x.First().Name, - Name2 = x.Skip(1).First().Name - }) - .ToList(); -idxs = idxs; -// Parse, modify and save a KH2 BinArc file: -//var binarc = File.OpenRead(Input).Using(Bar.Read); -//// perform here your changes -//File.Create(Output).Using(stream => Bar.Write(stream, binarc)); - -// Parse and convert all textures to PNG from a BBS 3D model using all CPUs: -//var pmo = File.OpenRead(Input).Using(Pmo.Read); -//pmo.texturesData -// .Select((texture, index) => new { texture, index }) -// .AsParallel() -// .ForAll(x => x.texture.SaveImage($"{pmo.textureInfo[x.index].TextureName}.png")); - -// Connect to PCSX2 and do live editing via code: -//var process = ProcessStream.TryGetProcess(x => x.ProcessName == "pcsx2"); -//using var stream = new ProcessStream(process, 0x20000000, 0x2000000); -//var gameSpeed = stream.SetPosition(0x349E0C).ReadFloat(); -//stream.SetPosition(0x349E0C).Write(gameSpeed); +using OpenKh.Common; +using OpenKh.Kh1; +using OpenKh.Kh2; +using OpenKh.Bbs; +using OpenKh.Tools.Common; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using OpenKh.Tools.Common.Imaging; + +const string Input = @"D:\kh2\somefile.bar"; +const string Output = @"D:\kh2\modifiedfile.bar"; + +Console.WriteLine("Hello OpenKH!"); + +var idxs = File.OpenRead(@"E:\Hacking\KH1\KINGDOM.IDX").Using(Idx1.Read); +var names = Idx1Name.Lookup(idxs.OrderBy(x => x.IsoBlock)).OrderBy(x => x.Entry.Hash).ToList(); +File.WriteAllLines(@"D:\asd.txt", names.Select(x => x.ToString())); +var aaa = File + .ReadAllLines(Path.Combine(AppContext.BaseDirectory, "resources/kh1idx.txt")) + .Select(x => new + { + Name = x, + Hash = Idx1.GetHash(x) + }) + .GroupBy(x => x.Hash) + .Where(x => x.Count() > 1) + .Select(x => new + { + Name1 = x.First().Name, + Name2 = x.Skip(1).First().Name + }) + .ToList(); +idxs = idxs; +// Parse, modify and save a KH2 BinArc file: +//var binarc = File.OpenRead(Input).Using(Bar.Read); +//// perform here your changes +//File.Create(Output).Using(stream => Bar.Write(stream, binarc)); + +// Parse and convert all textures to PNG from a BBS 3D model using all CPUs: +//var pmo = File.OpenRead(Input).Using(Pmo.Read); +//pmo.texturesData +// .Select((texture, index) => new { texture, index }) +// .AsParallel() +// .ForAll(x => x.texture.SaveImage($"{pmo.textureInfo[x.index].TextureName}.png")); + +// Connect to PCSX2 and do live editing via code: +//var process = ProcessStream.TryGetProcess(x => x.ProcessName == "pcsx2"); +//using var stream = new ProcessStream(process, 0x20000000, 0x2000000); +//var gameSpeed = stream.SetPosition(0x349E0C).ReadFloat(); +//stream.SetPosition(0x349E0C).Write(gameSpeed); diff --git a/Playground/Properties/AssemblyInfo.cs b/Playground/Properties/AssemblyInfo.cs index 1e5bd86bb..d863a77a1 100644 --- a/Playground/Properties/AssemblyInfo.cs +++ b/Playground/Properties/AssemblyInfo.cs @@ -1,11 +1,11 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("812e9c9b-c5aa-459b-9c30-fcae79a0b3b9")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("812e9c9b-c5aa-459b-9c30-fcae79a0b3b9")]