Example #1
0
        public static StageInfo syncStages(StageInfo a, StageInfo b)
        {
            StageInfo merged = new StageInfo();

            IntPtr aPtr      = Marshal.AllocHGlobal(34);
            IntPtr bPtr      = Marshal.AllocHGlobal(34);
            IntPtr mergedPtr = Marshal.AllocHGlobal(34);

            Marshal.StructureToPtr <StageInfo>(a, aPtr, false);
            Marshal.StructureToPtr <StageInfo>(b, bPtr, false);

            byte[] aBuffer      = new byte[34];
            byte[] bBuffer      = new byte[34];
            byte[] mergedBuffer = new byte[34];

            Marshal.Copy(aPtr, aBuffer, 0, 34);
            Marshal.Copy(bPtr, bBuffer, 0, 34);

            for (int i = 0; i < 34; i++)
            {
                if (i != 32)  // don't OR keys
                {
                    mergedBuffer[i] = (byte)(aBuffer[i] | bBuffer[i]);
                }
            }

            Marshal.Copy(mergedBuffer, 0, mergedPtr, 34);
            merged = Marshal.PtrToStructure <StageInfo>(mergedPtr);

            return(merged);
        }
Example #2
0
 public void SetStageInfos(StageInfo[] infos) // may need to initialize these first
 {
     sea       = infos[0];
     sea_alt   = infos[1];
     ff        = infos[2];
     drc       = infos[3];
     fw        = infos[4];
     totg      = infos[5];
     earth     = infos[6];
     wind      = infos[7];
     ganon     = infos[8];
     hyrule    = infos[9];
     ships     = infos[10];
     interiors = infos[11];
     caves     = infos[12];
     caves_alt = infos[13];
     chuchu    = infos[14];
 }
Example #3
0
 public StageInfo[] GetStageInfos()
 {
     StageInfo[] infos = new StageInfo[15];
     infos[0]  = sea;
     infos[1]  = sea_alt;
     infos[2]  = ff;
     infos[3]  = drc;
     infos[4]  = fw;
     infos[5]  = totg;
     infos[6]  = earth;
     infos[7]  = wind;
     infos[8]  = ganon;
     infos[9]  = hyrule;
     infos[10] = ships;
     infos[11] = interiors;
     infos[12] = caves;
     infos[13] = caves_alt;
     infos[14] = chuchu;
     return(infos);
 }
Example #4
0
        public static WorldState syncWorldStates(WorldState a, WorldState b)
        {
            WorldState merged = new WorldState();

            StageInfo[] aStageInfos = a.GetStageInfos();
            StageInfo[] bStageInfos = b.GetStageInfos();
            StageInfo[] mergedInfos = new StageInfo[15];

            int curStageID = 0;

            // Are players in the same stage
            if (a.stageID == b.stageID)
            {
                merged.local = syncStages(a.local, b.local);
                // Handle keys....timestamp?
            }
            else
            {
                // Players are in different stages
                //
                // Sync Player A's local flags to Player B's permanent flags
                curStageID = (int)a.stageID;
                if ((curStageID < 15) && (curStageID >= 0))
                {
                    mergedInfos[curStageID] = syncStages(a.local, bStageInfos[curStageID]);
                }

                // Sync Player B's local flags to Player A's permanent flags
                curStageID = (int)b.stageID;
                if ((curStageID < 15) && (curStageID >= 0))
                {
                    mergedInfos[curStageID] = syncStages(b.local, aStageInfos[curStageID]);
                }
            }

            return(merged);
        }