forked from airumu/CrashEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShuffleScript.cs
93 lines (85 loc) · 3.01 KB
/
ShuffleScript.cs
1
2
3
4
5
6
7
8
9
10
11
12
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using Crash;
using System;
using System.Collections.Generic;
namespace CrashHacks.Scripts.Animation
{
public sealed class ShuffleScript : Script
{
private Random random;
public ShuffleScript()
{
this.random = new Random();
}
public override string Name
{
get { return "Randomly swap around object animations"; }
}
public override string Description
{
get { return base.Description; }
}
public override string Author
{
get { return "chekwob"; }
}
public override string Category
{
get { return "animation"; }
}
public override SupportLevel CheckCompatibility(GameVersion gameversion)
{
switch (gameversion)
{
case GameVersion.Crash2:
return SupportLevel.Supported;
case GameVersion.Crash3:
return SupportLevel.Unsupported;
default:
return SupportLevel.Untested;
}
}
public override void Run(object value,GameVersion gameversion)
{
if (value is NSF nsf)
{
List<AnimationEntry> entries = new List<AnimationEntry>();
foreach (Chunk chunk in nsf.Chunks)
{
if (chunk is EntryChunk)
{
EntryChunk entrychunk = (EntryChunk)chunk;
foreach (Entry entry in entrychunk.Entries)
{
if (entry is AnimationEntry anim)
{
entries.Add(anim);
}
}
}
}
List<AnimationEntry> sourceentries = new List<AnimationEntry>();
for (int i = 0;i < entries.Count;i++)
{
sourceentries.Insert(random.Next(i),new AnimationEntry(entries[i].Frames,entries[i].IsNew,entries[i].EID));
}
foreach (AnimationEntry entry in entries)
{
for (int i = 0;i < sourceentries.Count;i++)
{
AnimationEntry sourceentry = sourceentries[i];
if (sourceentry.Frames.Count == entry.Frames.Count && sourceentry.Save().Length <= entry.Save().Length)
{
entry.Frames.Clear();
foreach (Frame frame in sourceentry.Frames)
{
entry.Frames.Add(frame);
}
sourceentries.RemoveAt(i);
break;
}
}
}
}
}
}
}