ArchiveSearch.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7. namespace FF8
  8. {
  9. class ArchiveSearch
  10. {
  11. public List<Tuple<string, string, long>> results = new List<Tuple<string, string, long>>();
  12. static readonly string[] ArchiveList = new string[]
  13. {
  14. Memory.Archives.A_MENU,
  15. Memory.Archives.A_MAIN,
  16. //Memory.Archives.A_FIELD,
  17. //Memory.Archives.A_MAGIC,
  18. //Memory.Archives.A_WORLD,
  19. //Memory.Archives.A_BATTLE,
  20. };
  21. public ArchiveSearch(FF8String searchstring)
  22. {
  23. byte[] s = searchstring;
  24. foreach (string a in ArchiveList)
  25. {
  26. ArchiveWorker aw = new ArchiveWorker(a);
  27. string[] lof = aw.GetListOfFiles();
  28. foreach(string f in lof)
  29. {
  30. byte[] bf = aw.GetBinaryFile(f);
  31. int i = 0;
  32. do
  33. {
  34. i = Array.FindIndex(bf, i, bf.Length - i, x => x == s[0]);
  35. if (i >= 0 && bf != null)
  36. {
  37. var full = bf.Skip(i).Take(s.Length).ToArray();
  38. if (full.SequenceEqual(s))
  39. {
  40. results.Add(new Tuple<string, string, long>(a, f, i));
  41. }
  42. i++;
  43. }
  44. }
  45. while (i > 0);
  46. //bf = bf.Reverse().ToArray();
  47. //i = 0;
  48. //do
  49. //{
  50. // i = Array.FindIndex(bf, i, bf.Length - i, x => x == s[0]);
  51. // if (i >= 0 && bf != null)
  52. // {
  53. // var full = bf.Skip(i).Take(s.Length).ToArray();
  54. // if (full.SequenceEqual(s))
  55. // {
  56. // results.Add(new Tuple<string, string, long>(a, f, i));
  57. // }
  58. // i++;
  59. // }
  60. //}
  61. //while (i > 0);
  62. //string decodedarchive = Memory.DirtyEncoding.GetString(aw.GetBinaryFile(f));
  63. //Regex r = new Regex(searchstring, RegexOptions.IgnoreCase);
  64. //Match m = r.Match(f);
  65. //if(m.Success)
  66. //{
  67. // results.Add(new Tuple<string, string, long>(a, f, m.Index));
  68. //}
  69. }
  70. }
  71. }
  72. }
  73. }