Files
Pal3.Unity/README.en-US.md
Jiaqi Liu 5d0f564a00 Add a standalone battle editor and battle system for PAL3 and PAL3A (#99)
* build: migrate C# formatting and add offscreen editor test support

Host IMGUI tests on a detached panel without creating a native editor window.

* feat(core): decode native battle records, geometry and animation metadata

Read the two game variants’ battle tables and model data, with binary-reader and original-resource coverage.

* feat(battle): implement deterministic combat rules and action settlement

Implement actors, inventory, formation, action timing, status interruption, AI, stage ownership and deterministic replay. Keep the domain and its regression suite independent of Unity.

* feat(battle): project native HUD state and input commands

Add the presentation assembly and tests for command routing, lineup selection, floating numbers and stage messages.

* feat(rendering): add battle lighting, actor appearance and native shadows

Support baked and toon lighting, actor and weapon rendering, display refresh rate and resource ownership.

* feat(effects): drive battle effects through shared resource previews

Bind battle control nodes to action owners. Share preview lighting, geometry and effect resources with the existing Unity editors.

* refactor(game): isolate story battle targeting and actor lifetimes

Preserve scene ownership, bound story battle targeting and stop debug attacks when their actor leaves the scene.

* feat(editor): compile original game data into battle scenarios

Build per-variant animation and ability catalogs, encounter music, scene lighting profiles, random parties, equipment and test inventory from the original resources.

* feat(editor): play battle sessions with animated previews and synced media

Drive the preview scene, camera, effects, hit feedback, result choreography, music and movies from simulation snapshots and events.

* feat(editor): add the battle workbench, native HUD and input controls

Expose scenario authoring, replay, diagnostics, responsive command menus and mouse, touch and gamepad targeting. Include the editor workflow and HUD integration tests.
2026-11-21 22:28:47 +08:00

19 KiB
Raw Permalink Blame History

+

Pal3.Unity

The Legend of Sword and Fairy 3 & The Legend of Sword and Fairy 3 Gaiden: Wenqing Pian re-implementation using C#/Unity

简体中文 | English

Unity Version Releases Platform License Size

Intro

This is an open-source project that re-implements The Legend of Sword and Fairy 3 and The Legend of Sword and Fairy 3 Gaiden: Wenqing Pian using C#/Unity. The implementation involves rewriting of the game logic, loading and utilizing the original game assets, and recreating the original game's behavior and effects. Please refer to the source code to see how it is been made.

Note: The Legend of Sword and Fairy 3 and The Legend of Sword and Fairy 3 Gaiden: Wenqing Pian are original works of Softstar Technology (Shanghai) Co., Ltd., with copyrights belonging to Softstar Technology (Shanghai) Co., Ltd. and Softstar International Inc. (I might be wrong but please verify yourself). This project does not contain any game data from the original game. The project is under the GPL-3.0 license but is limited to the code of this project excluding Unity assets and other assets and plugins that I used and get from Unity Asset Store. Any textures, audio, video, or game data related to The Legend of Sword and Fairy 3 or The Legend of Sword and Fairy 3 Gaiden: Wenqing Pian are not covered by this license.

Latest PR build status

CI runs only on pull requests. Each badge shows the latest pull request build for that workflow; click it to view the corresponding PR build history.

Game Variant Windows Linux MacOS Android iOS
The Legend of Sword and Fairy 3 PR build status PR build status PR build status PR build status PR build status
The Legend of Sword and Fairy 3 Gaiden: Wenqing Pian PR build status PR build status PR build status PR build status PR build status

How to run the project

Open the project with the Unity version specified in ProjectVersion.txt. The project uses URP Forward+.

  • Since the project itself does not contain any game data from the original game, you will need a copy of the original game files for The Legend of Sword and Fairy 3 or The Legend of Sword and Fairy 3 Gaiden: Wenqing Pian (Link to the game on Steam: The Legend of Sword and Fairy 3 and The Legend of Sword and Fairy 3 Gaiden: Wenqing Pian).

  • Open Scenes/Game and press Play to run the game. Use PAL3 / PAL3A → Resource Browser to browse resources in Edit Mode.

  • The first time you open it, a folder selection window will automatically pop up. Please select the installation folder for The Legend of Sword and Fairy 3 (or The Legend of Sword and Fairy 3 Gaiden: Wenqing Pian) on your computer.

  • Since the original game's cutscene videos are in Bink format, which Unity does not natively support, please convert the videos to a format supported by Unity and place them in the movie folder at the game's root directory (most devices and platforms support mainstream formats like .mp4, while Linux only supports .webm format).

  • Linux users can use FFmpeg to convert videos to .webm format

    ffmpeg -i input.mp4 -c:v libvpx -b:v 3M -c:a libvorbis output.webm  // vp8 + vorbis
    

    To extract the original videos, open Resource Browser, index the original installation directory, search ext:bik, and choose Original → Export filtered…. Archive entries larger than 64 MiB require individual confirmation with Export original…. The archive directory structure is preserved.

Battle Editor

Open PAL3 / PAL3A → Battle Editor to test battles in an independent editor window, without entering Play Mode or loading the story. Select the game data directory in the canvas, then choose 创建随机战斗 (create a random battle) and 开始测试 (start test). Playback starts immediately; the toolbar provides pause, resume and restart controls. Use Switch Variant to change games.

Configure the battlefield, party, enemies, formations, equipment, skills, statuses and battle inventory. Save presets as BattleScenarioAsset assets; editable drafts remain separate from running snapshots. Both games support original battle rules and presentation, manual or AI control, settlement, stepping, input replay and JSON reports. Results do not update story progress or the regular inventory.

The battle core documents the C# rules and presenter. The editor composition guide covers the Unity adapter and resource ownership.

Editor resource browser

Open the dockable window through PAL3 / PAL3A → Resource Browser. Choose the data directory containing basedata/, select GBK (936) or Big5 (950), and click Index / Reload. Use Switch Variant to change games.

The data directory and its ancestors must not be symbolic links; select the link's real target path instead. Indexing also skips links inside the directory. This restriction keeps path aliases from bypassing original-data export protection.

  • Search paths with multiple terms, -exclusions, or ext:dds; filter by category/archive and navigate results with arrow keys.
  • Textures use Unity's native preview and channel controls, with PNG export. Models offer an isolated viewport, original/Toon rendering, animation playback and seeking, and texture dependency links.
  • SCN provides scene/NPC/object records, dependency links, and a static background with position markers. NAV provides layered walkability maps and tile details; LGT exposes light records.
  • SCE shows script blocks, commands, variables and dialogue. GDB provides searchable item, actor, skill and combo tables. Parsed resources support field inspection and JSON export; scripts support batch listings and dialogue export.
  • Text supports encoding detection, search, Undo and saving a copy. Audio uses native preview controls. Video uses Unity's platform decoder; BIK is extraction only. Unknown resources have a paged hex view.

Original data is read-only. Exports preserve hierarchy and never overwrite existing files. Choose Original / Script / Dialogue / Json before exporting filtered results; batch export is cancellable. Ordinary previews are limited to 64 MiB, text reads to 4 MiB, and in-window editing to 60,000 characters. Temporary media is extracted under workspace/ResourceBrowserMedia/ beside the project and cleaned up when switching resources or closing the window. Opening the window also removes temporary directories left by exited processes. Effect playback and override editing remain in Effect Editor. The old ResourceViewer scene has been removed.

How to run the game

  • In runtime, when the game is launched for the first time, it will search the Application.persistentDataPath directory or the StreamingAssets directory to detect whether the game data exists. If the original game data files cannot be detected on desktop clients, the game will pop up a folder selection window for you to select the root directory of the original game installation files on the current device.
  • If the previous step is unsuccessful, please copy the entire "The Legend of Sword and Fairy 3" (or "The Legend of Sword and Fairy 3 Gaiden: Wenqing Pian") original game installation directory to Application.persistentDataPath. Note: If you manually copy the game data to this directory, the folder name must be PAL3 for "The Legend of Sword and Fairy 3," and PAL3A for The Legend of Sword and Fairy 3 Gaiden: Wenqing Pian. For iOS devices, please use iTunes to share the folder with the game application (this location is where the persistentDataPath is located), or you can package the original game data into the StreamingAssets folder during compilation with Unity, so you don't have to pick a folder when deployed.

How to switch between two variants of the game

The version switching is implemented through Custom scripting symbols. PAL3 corresponds to The Legend of Sword and Fairy 3, and PAL3A corresponds to The Legend of Sword and Fairy 3 Gaiden: Wenqing Pian. I added a shortcut button in the Unity editor menu bar for one-click switching (Menu bar->Pal3->Switch Variant->PAL3A). After switching, the corresponding game folder will automatically change from PAL3 to PAL3A.

Screenshots with realtime lighting and toon shading enabled

PAL3 卡通渲染+光影 PAL3A 卡通渲染+光影 PAL3 卡通渲染+光追

About VFX and Toon Rendering

Both games default to Toon with real-time lighting on first launch. To switch to the original visual style in URP, change the visual style in game settings and restart. Both styles use shaders from this repository and load game data from the player’s local installation.

The visual effects settings provide independent switches for contact shadows, character lighting, enhanced night fire lighting, and fire shadows. Contact shadows and fire shadows default to enabled on desktop devices. Enhanced fire lighting combines warm lights with a cool ambient tone. Fire shadows also work in dark maze scenes. Desktop defaults to four shadowed fires. Set Settings.ToonFireShadowBudget to 0–4 in the debug console. The shadow atlas grows with the budget. Bloom has a separate switch and defaults to enabled only for the original style on desktop.

The screenshots above show the previous toon renderer. Supported story and scene effects in both games use the original data: effect groups, tasks, particles, textures, and models loaded from local CPK archives, rendered with this project's URP shaders and Unity components. Open PAL3 / PAL3A → Effect Editor in Unity to select a game, play effects, inspect objects, and edit group tasks and legacy particle curves. Save overrides to Assets/Resources/Effects/PAL3Overrides.asset or PAL3AOverrides.asset for use in the game. The resource browser links effect resources to Effect Editor. Group ID -1 supports transport points in both games.

The current inventory covers all 56 PAL3 and 93 PAL3A story and scene root groups using original data. Transport points reproduce the original disc, two light cones, and colors selected by scene parameters. SPar keyframes, paths, six controller slots, and material blending are implemented independently; raw SPar fields are read-only in the editor. Battle-specific types receive context from the independent battle session; missing resources and unsupported inputs produce diagnostics.

All implementation code, shaders, and build resources are included in this repository. The game reads the player's local original game data at runtime; that data is not distributed with this project.

Controls

  • Mouse and keyboard: Left mouse button to click and control character movement (arrow keys can also be used), A/D to control camera rotation, Spacebar to interact with nearby items or NPCs (also used as the jump button when available), M key to toggle the big map, U key or ESC key to open the story selection menu, Tab key to switch characters (in the maze).
  • Gamepad: Left joystick to control character movement, right joystick to control camera rotation, use gamepad south button to interact, menu and select buttons corresponding to the map and story selection menu, LB/RB to switch to the previous/next character (in the maze).
  • Touchscreen: Only enabled on handheld devices with a touch screen, virtual joystick for movement, interaction button for interaction.

Project State and Roadmap

The stories of both games are complete and can be played from start to finish; the story selection menu also provides shortcuts to preset story points. Most maze puzzles and story effects have been implemented. The independent Battle Editor provides battle configuration, execution, original rules and presentation, and replay testing for both games. Story-triggered battles, the regular inventory, full equipment management and progress/save writeback still need integration. Further work on mini-games, the main menu, other interfaces and mobile adaptation is planned separately.

How to Contribute?

After changing owned C# sources, use the .NET SDK pinned in global.json and run these commands from the project root:

dotnet run --project tools/CodeStyle --
dotnet run --project tools/CodeStyle -- --check

The formatter is a .NET tool and needs no Python, Unity installation or game data. It uses Roslyn, .editorconfig and pinned StyleCop layout rules for whitespace, separate statements and blank lines between members. It checks both PAL3 and PAL3A conditional branches. By default, it formats changed lines and deletion boundaries, preserving existing formatting elsewhere; explicit paths or --all check whole files. The Code style workflow runs dotnet test tools/CodeStyle.Tests and the same formatting check for pull requests. See the tool README for commands and scope. Run the relevant Unity tests after formatting; ShaderLab/HLSL still needs manual formatting and rendering validation.

Since the project is still in the early stages, many systems have not yet been implemented, thus I am temporarily not accepting large Pull Requests, especially feature ones. If you have good ideas, suggestions, or have discovered bugs, please feel free to submit an issue.

Why make this [TL;DR]

After learning Unity for a few weeks, I've been looking for a project to practice. As I surfing the Internet, I discovered the PAL3patch project created by zby and the OpenPAL3 project created by dontpanic92, which made the re-implementation of a remake for The Legend of Sword and Fairy 3 possible. As for why I chose C#/Unity, there are two reasons: First, Unity has excellent cross-platform support and packaging, and second, Unity provides native IDE support for Mac with M1/M2 chips (Why? I spend about half of my time coding on a Macbook). Although this project barely uses most of Unity's engine features, especially its editor features, since it's almost 100% code-based, it could theoretically be ported to other engines that support C# scripting with minimal effort.

Dependencies