Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace GE64SaveEditor
- {
- public class GE64SaveGame
- {
- private Dictionary<Level, int> timeMapAgent;
- private Dictionary<Level, int> timeMapSAgent;
- private Dictionary<Level, int> timeMap00Agent;
- public bool isValid = false;
- public byte[] raw;
- public GE64SaveGame(string path)
- {
- raw = File.ReadAllBytes(path);
- uint m1 = BitConverter.ToUInt32(raw, 0);
- uint m2 = BitConverter.ToUInt32(raw, 0);
- if (m1 == 0x33382489 && m2 == 0x33382489 && raw.Length == 0x200)
- {
- isValid = true;
- timeMapAgent = new Dictionary<Level, int>();
- timeMapSAgent = new Dictionary<Level, int>();
- timeMap00Agent = new Dictionary<Level, int>();
- for (int i = 0; i < 20; i++)
- {
- timeMapAgent.Add((Level)i, 0x90 + i * 10);
- timeMapSAgent.Add((Level)i, 0x158 + i * 10);
- timeMap00Agent.Add((Level)i, 0x220 + i * 10);
- }
- }
- }
- public byte[] getSlotDataRaw(int slot)
- {
- MemoryStream m = new MemoryStream();
- m.Write(raw, 0x20 + slot * 0x60, 0x60);
- return m.ToArray();
- }
- public string getSlotDetails(int slot)
- {
- StringBuilder sb = new StringBuilder();
- byte[] data = getSlotDataRaw(slot);
- MemoryStream m = new MemoryStream();
- m.Write(data, 0, 8);
- byte[] hash = m.ToArray();
- sb.Append("Hash : ");
- foreach (byte b in hash)
- sb.Append(b.ToString("X2"));
- sb.AppendLine("\n");
- for (int i = 0; i < 20; i++)
- {
- Level l = (Level)i;
- sb.AppendLine(l.ToString());
- sb.AppendLine("Time Agent : " + toTime(ReadBits(data, timeMapAgent[l], 0xA)));
- sb.AppendLine("Time SAgent : " + toTime(ReadBits(data, timeMapSAgent[l], 0xA)));
- sb.AppendLine("Time 00Agent : " + toTime(ReadBits(data, timeMap00Agent[l], 0xA)));
- sb.AppendLine();
- }
- return sb.ToString();
- }
- public ushort ReadBits(byte[] buff, int pos, int len)
- {
- ushort result = 0;
- for (int i = 0; i < len; i++)
- {
- result = (ushort)(result << 1);
- if (getBit(buff, pos + i))
- result |= 1;
- }
- return result;
- }
- public bool getBit(byte[] buff, int pos)
- {
- byte b = buff[pos / 8];
- b = (byte)(b >> (7 - (pos % 8)));
- return (b & 1) == 1;
- }
- private string toTime(ushort sec)
- {
- if (sec == 0x3ff)
- return "--:--";
- else
- return (sec / 60) + ":" + (sec % 60).ToString("D2");
- }
- private enum Level
- {
- Dam,
- Facility,
- Runway,
- Surface1,
- Bunker1,
- Silo,
- Frigate,
- Surface2,
- Bunker2,
- Statue,
- Archives,
- Streets,
- Depot,
- Train,
- Jungle,
- Control,
- Caverns,
- Cradle,
- Aztec,
- Egypt
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement