chore: initial commit

This commit is contained in:
2026-05-08 11:04:00 +08:00
commit f55d2a57c3
6278 changed files with 866081 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
using System.IO;
using UnityEditor;
using UnityEngine;
namespace Assets.PathBerserker2d.Scripts.PathBerserker2d.Upgrade
{
static class DeleteObsoleteFiles
{
static string[] obsoleteFiles = new string[] {
"Corgi.zip",
"Editor/PathBerserker2d-Editor.dll",
"Editor/ShowAssetIds.cs",
"Editor/FootStepSoundsInspector.cs",
"Scripts/PathBerserker2d.dll",
"Scripts/PathBerserker2d.xml",
"Scripts/TransformBasedMovement.cs",
"Scripts/Examples/AdjustRotation.cs",
"Scripts/Examples/CornerRotationSkipper.cs",
"Scripts/Examples/Elevator.cs",
"Scripts/Examples/Follower.cs",
"Scripts/Examples/FootStepSounds.cs",
"Scripts/Examples/GoalWalker.cs",
"Scripts/Examples/KeepGrounded.cs",
"Scripts/Examples/MouseWalker.cs",
"Scripts/Examples/MovingPlatform.cs",
"Scripts/Examples/MultiGoalWalker.cs",
"Scripts/Examples/PatrolWalker.cs",
"Scripts/Examples/RandomWalker.cs",
};
static string[] obsoleteDirs = new string[] {
"Editor",
"Scripts/Examples"
};
public static void RemoveObsoleteFiles()
{
string basePath = Path.Combine(Application.dataPath, "PathBerserker2d");
foreach (var file in obsoleteFiles)
{
string path = Path.Combine(basePath, file);
if (File.Exists(path))
{
File.Delete(path);
Debug.Log("Deleted " + path);
}
}
foreach (var dir in obsoleteDirs)
{
string path = Path.Combine(basePath, dir);
if (Directory.Exists(path) && !Directory.EnumerateFiles(path).GetEnumerator().MoveNext())
{
Directory.Delete(path);
}
}
AssetDatabase.Refresh();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3bbdff88e6872d74d9dd37db0b6e9c12
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,198 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Security.Cryptography;
namespace Assets.PathBerserker2d.Scripts.PathBerserker2d.Upgrade
{
// Taken from http://www.superstarcoders.com/blogs/posts/md4-hash-algorithm-in-c-sharp.aspx
// Probably not the best implementation of MD4, but it works.
public class MD4 : HashAlgorithm
{
private uint _a;
private uint _b;
private uint _c;
private uint _d;
private uint[] _x;
private int _bytesProcessed;
public MD4()
{
_x = new uint[16];
Initialize();
}
public override void Initialize()
{
_a = 0x67452301;
_b = 0xefcdab89;
_c = 0x98badcfe;
_d = 0x10325476;
_bytesProcessed = 0;
}
protected override void HashCore(byte[] array, int offset, int length)
{
ProcessMessage(Bytes(array, offset, length));
}
protected override byte[] HashFinal()
{
try
{
ProcessMessage(Padding());
return new[] { _a, _b, _c, _d }.SelectMany(word => Bytes(word)).ToArray();
}
finally
{
Initialize();
}
}
private void ProcessMessage(IEnumerable<byte> bytes)
{
foreach (byte b in bytes)
{
int c = _bytesProcessed & 63;
int i = c >> 2;
int s = (c & 3) << 3;
_x[i] = (_x[i] & ~((uint)255 << s)) | ((uint)b << s);
if (c == 63)
{
Process16WordBlock();
}
_bytesProcessed++;
}
}
private static IEnumerable<byte> Bytes(byte[] bytes, int offset, int length)
{
for (int i = offset; i < length; i++)
{
yield return bytes[i];
}
}
private IEnumerable<byte> Bytes(uint word)
{
yield return (byte)(word & 255);
yield return (byte)((word >> 8) & 255);
yield return (byte)((word >> 16) & 255);
yield return (byte)((word >> 24) & 255);
}
private IEnumerable<byte> Repeat(byte value, int count)
{
for (int i = 0; i < count; i++)
{
yield return value;
}
}
private IEnumerable<byte> Padding()
{
return Repeat(128, 1)
.Concat(Repeat(0, ((_bytesProcessed + 8) & 0x7fffffc0) + 55 - _bytesProcessed))
.Concat(Bytes((uint)_bytesProcessed << 3))
.Concat(Repeat(0, 4));
}
private void Process16WordBlock()
{
uint aa = _a;
uint bb = _b;
uint cc = _c;
uint dd = _d;
foreach (int k in new[] { 0, 4, 8, 12 })
{
aa = Round1Operation(aa, bb, cc, dd, _x[k], 3);
dd = Round1Operation(dd, aa, bb, cc, _x[k + 1], 7);
cc = Round1Operation(cc, dd, aa, bb, _x[k + 2], 11);
bb = Round1Operation(bb, cc, dd, aa, _x[k + 3], 19);
}
foreach (int k in new[] { 0, 1, 2, 3 })
{
aa = Round2Operation(aa, bb, cc, dd, _x[k], 3);
dd = Round2Operation(dd, aa, bb, cc, _x[k + 4], 5);
cc = Round2Operation(cc, dd, aa, bb, _x[k + 8], 9);
bb = Round2Operation(bb, cc, dd, aa, _x[k + 12], 13);
}
foreach (int k in new[] { 0, 2, 1, 3 })
{
aa = Round3Operation(aa, bb, cc, dd, _x[k], 3);
dd = Round3Operation(dd, aa, bb, cc, _x[k + 8], 9);
cc = Round3Operation(cc, dd, aa, bb, _x[k + 4], 11);
bb = Round3Operation(bb, cc, dd, aa, _x[k + 12], 15);
}
unchecked
{
_a += aa;
_b += bb;
_c += cc;
_d += dd;
}
}
private static uint ROL(uint value, int numberOfBits)
{
return (value << numberOfBits) | (value >> (32 - numberOfBits));
}
private static uint Round1Operation(uint a, uint b, uint c, uint d, uint xk, int s)
{
unchecked
{
return ROL(a + ((b & c) | (~b & d)) + xk, s);
}
}
private static uint Round2Operation(uint a, uint b, uint c, uint d, uint xk, int s)
{
unchecked
{
return ROL(a + ((b & c) | (b & d) | (c & d)) + xk + 0x5a827999, s);
}
}
private static uint Round3Operation(uint a, uint b, uint c, uint d, uint xk, int s)
{
unchecked
{
return ROL(a + (b ^ c ^ d) + xk + 0x6ed9eba1, s);
}
}
}
public static class FileIDUtil
{
public static int Compute(Type t)
{
string toBeHashed = "s\0\0\0" + t.Namespace + t.Name;
using (HashAlgorithm hash = new MD4())
{
byte[] hashed = hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(toBeHashed));
int result = 0;
for (int i = 3; i >= 0; --i)
{
result <<= 8;
result |= hashed[i];
}
return result;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3d2b504d66469914ea89897e98917234
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,127 @@
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
using System.Linq;
namespace Assets.PathBerserker2d.Scripts.PathBerserker2d.Upgrade
{
class MissingScriptResolver
{
string navAgentFI;
string navSurfaceFI;
string navSegmentSubstractorFI;
string navAreaMarkerFI;
string dynamicObstacleFI;
public static void UpdateReferences()
{
string dllGuid = "45d3c5b18a3fb854b94b339e477774af";
int navAgentFI = -1018851484;
string navAgentGUID = AssetDatabase.AssetPathToGUID("Assets/PathBerserker2d/Scripts/PathBerserker2d/NavAgent/NavAgent.cs");
int navSurfaceFI = -567900050;
string navSurfaceGUID = AssetDatabase.AssetPathToGUID("Assets/PathBerserker2d/Scripts/PathBerserker2d/NavSurface/NavSurface.cs");
int navLinkFI = -546232842;
string navLinkGUID = AssetDatabase.AssetPathToGUID("Assets/PathBerserker2d/Scripts/PathBerserker2d/NavObjects/NavLink.cs");
int navLinkClusterFI = 1837436107;
string navLinkClusterGUID = AssetDatabase.AssetPathToGUID("Assets/PathBerserker2d/Scripts/PathBerserker2d/NavObjects/NavLinkCluster.cs");
int navSegmentSubstractorFI = -274983532;
string navSegmentSubstractorGUID = AssetDatabase.AssetPathToGUID("Assets/PathBerserker2d/Scripts/PathBerserker2d/NavObjects/NavSegmentSubstractor.cs");
int navAreaMarkerFI = 709968320;
string navAreaMarkerGUID = AssetDatabase.AssetPathToGUID("Assets/PathBerserker2d/Scripts/PathBerserker2d/NavObjects/NavAreaMarker.cs");
int dynamicObstacleFI = -721922897;
string dynamicObstacleGUID = AssetDatabase.AssetPathToGUID("Assets/PathBerserker2d/Scripts/PathBerserker2d/NavObjects/DynamicObstacle.cs");
int pathBerserker2dSettingsFI = -1515731982;
string pathBerserker2dSettingsGUID = AssetDatabase.AssetPathToGUID("Assets/PathBerserker2d/Scripts/PathBerserker2d/PathBerserker2dSettings.cs");
int[] fis = new int[] {
navAgentFI,
navSurfaceFI,
navSegmentSubstractorFI,
navAreaMarkerFI,
dynamicObstacleFI,
pathBerserker2dSettingsFI,
navLinkFI,
navLinkClusterFI
};
string[] guids = new string[] {
navAgentGUID,
navSurfaceGUID,
navSegmentSubstractorGUID,
navAreaMarkerGUID,
dynamicObstacleGUID,
pathBerserker2dSettingsGUID,
navLinkGUID,
navLinkClusterGUID
};
for (int i = 0; i < guids.Length; i++)
{
if (guids[i] == null)
{
Debug.LogError("One or multiple cs files could not be found. Aborting upgrade. Please make sure that the Plugin files are in Assets/PathBerserker2d");
return;
}
}
// first patch settings
foreach (var metaFile in Directory.EnumerateFiles(System.IO.Path.Combine(Application.dataPath, "PathBerserker2d/Resources/"), "*.asset", SearchOption.AllDirectories))
{
FixFile(metaFile, fis, dllGuid, guids);
}
// patch everything else
foreach (var metaFile in Directory.EnumerateFiles(Application.dataPath, "*", SearchOption.AllDirectories).Where(f => f.EndsWith(".unity") || f.EndsWith(".prefab")))
{
FixFile(metaFile, fis, dllGuid, guids);
}
Debug.Log("Finished!");
}
private static void FixFile(string path, int[] fis, string dllGuid, string[] guids)
{
try
{
FileInfo file = new FileInfo(path);
bool isHidden = (file.Attributes & FileAttributes.Hidden) != 0;
file.Attributes &= ~FileAttributes.Hidden;
string prevText = File.ReadAllText(path);
string text = prevText;
for (int i = 0; i < fis.Length; i++)
{
text = text.Replace($"fileID: {fis[i]}, guid: {dllGuid}",
$"fileID: 11500000, guid: {guids[i]}");
}
File.WriteAllText(path, text);
if (isHidden)
file.Attributes |= FileAttributes.Hidden;
if (prevText != text)
{
Debug.Log("Updated " + path);
}
}
catch (UnauthorizedAccessException e)
{
Debug.LogError(e);
}
catch (IOException e)
{
Debug.LogError(e);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3ad6757722d743440857770a88e128cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
{
"name": "PathBerserker2d.Upgrade",
"references": [
"GUID:f483b8ed1e509354483048b0c7a56768"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: fd89c7216da4dd2478872203e056f46b
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,96 @@
using System;
using UnityEditor;
using UnityEngine;
namespace Assets.PathBerserker2d.Scripts.PathBerserker2d.Upgrade
{
[InitializeOnLoad]
class UpdateNotificationWindow : EditorWindow
{
[MenuItem("Window/General/PathBerserker Update Log")]
static void ShowWindow()
{
// Get existing open window or if none, make a new one:
UpdateNotificationWindow window = (UpdateNotificationWindow)EditorWindow.GetWindow(typeof(UpdateNotificationWindow));
window.Show();
}
static UpdateNotificationWindow()
{
EditorApplication.update += EditorUpdate;
}
static void EditorUpdate()
{
if (!EditorPrefs.GetBool("pathberserker.showedupgrader") && EditorPrefs.GetBool("pathberserker.showedupdate.1_4"))
{
ShowWindow();
EditorPrefs.SetBool("pathberserker.showedupgrader", true);
}
EditorPrefs.SetString("pathberserker.installed_version", AssemblyInfo.Version);
EditorApplication.update -= EditorUpdate;
}
GUIStyle labelStyle;
GUIStyle headingStyle;
private void OnEnable()
{
try
{
labelStyle = new GUIStyle(EditorStyles.label);
}
catch (NullReferenceException)
{
labelStyle = new GUIStyle();
}
labelStyle.normal.textColor = Color.white;
labelStyle.richText = true;
labelStyle.wordWrap = true;
headingStyle = new GUIStyle(labelStyle);
headingStyle.fontSize += 20;
}
public void OnGUI()
{
if (labelStyle == null || headingStyle == null)
OnEnable();
if (labelStyle == null || headingStyle == null)
return;
EditorGUILayout.LabelField("<color=orange>Pathberserker 2d - Upgrader</color>", headingStyle);
EditorGUILayout.LabelField(AssemblyInfo.Version, labelStyle);
EditorGUILayout.Space();
EditorGUILayout.LabelField("<i>This window can be reopened at 'Window/General/PathBerserker Update Log'</i>", labelStyle);
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.LabelField("<size=15><color=red>Important</color></size>", labelStyle);
EditorGUILayout.LabelField("All Dll files have been replaced with AssemblyDefinitions. <b>All references to MonoBehaviors that where previously located in a DLL are now broken!</b> This will lead to a lot of missing scripts in your project.", labelStyle);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Fear not. By clicking the button below an upgrade script runs, that should restore all those references. <b>It will directly modify your projects .meta files.</b>", labelStyle);
EditorGUILayout.Space();
EditorGUILayout.LabelField("<b>BE WARNED, this might cause damage</b>. You should backup your project before starting this process. This will not work, if you moved the plugin-files from its default directory.", labelStyle);
EditorGUILayout.Space();
if (GUILayout.Button("Perform Upgrade") && EditorUtility.DisplayDialog("Have you made a backup?", "This process may fail or do unexpected things. Don't blame me if it ends up destroying something. Make a backup.", "Yes, I have a backup."))
{
MissingScriptResolver.UpdateReferences();
}
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.LabelField("<b>If this is your first time installing this plugin, you don't have to do anything.</b>", labelStyle);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 39d4bf2bf4a69e34cb47809c0d366e36
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: