Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Replace calls to dsInterface with your own library
- private const int eventFlagPtr = 0x137D7D4;
- private static Dictionary<string, int> eventFlagGroups = new Dictionary<string, int>()
- {
- {"0", 0x00000},
- {"1", 0x00500},
- {"5", 0x05F00},
- {"6", 0x0B900},
- {"7", 0x11300},
- };
- private static Dictionary<string, int> eventFlagAreas = new Dictionary<string, int>()
- {
- {"000", 00},
- {"100", 01},
- {"101", 02},
- {"102", 03},
- {"110", 04},
- {"120", 05},
- {"121", 06},
- {"130", 07},
- {"131", 08},
- {"132", 09},
- {"140", 10},
- {"141", 11},
- {"150", 12},
- {"151", 13},
- {"160", 14},
- {"170", 15},
- {"180", 16},
- {"181", 17},
- };
- private bool getEventFlagAddress(int ID, out int address, out uint mask)
- {
- string idString = ID.ToString("D8");
- if (idString.Length == 8)
- {
- string group = idString.Substring(0, 1);
- string area = idString.Substring(1, 3);
- int section = Int32.Parse(idString.Substring(4, 1));
- int number = Int32.Parse(idString.Substring(5, 3));
- if (eventFlagGroups.ContainsKey(group) && eventFlagAreas.ContainsKey(area))
- {
- int offset = eventFlagGroups[group];
- offset += eventFlagAreas[area] * 0x500;
- offset += section * 128;
- offset += (number - (number % 32)) / 8;
- address = dsInterface.ReadInt32(eventFlagPtr);
- address = dsInterface.ReadInt32(address);
- address += offset;
- mask = 0x80000000 >> (number % 32);
- return true;
- }
- }
- address = 0;
- mask = 0;
- return false;
- }
- public bool ReadEventFlag(int ID)
- {
- if (getEventFlagAddress(ID, out int address, out uint mask))
- {
- uint flags = dsInterface.ReadUInt32(address);
- return (flags & mask) != 0;
- }
- else
- throw new ArgumentException("Unknown event flag ID: " + ID);
- }
- public void WriteEventFlag(int ID, bool value)
- {
- if (getEventFlagAddress(ID, out int address, out uint mask))
- {
- uint flags = dsInterface.ReadUInt32(address);
- if (value)
- flags |= mask;
- else
- flags &= ~mask;
- dsInterface.WriteUInt32(address, flags);
- }
- else
- throw new ArgumentException("Unknown event flag ID: " + ID);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement