Skip to content

Commit

Permalink
fixup! C: ReplayController
Browse files Browse the repository at this point in the history
  • Loading branch information
way-zer committed May 1, 2024
1 parent 522924f commit 48e23e5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/src/mindustryX/features/ReplayController.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public static void stop(){
writes = null;
}

private static Net fakeServer = new Net(null){
@Override
public boolean server(){
return true;
}
};
public static void onClientPacket(Packet p){
if(!recording || p instanceof Streamable) return;
if(p instanceof Disconnect){
Expand All @@ -117,7 +123,10 @@ public static void onClientPacket(Packet p){
writes.f(Time.time - startTime);
writes.b(id);
tmpBuf.position(0);
var bak = net;
net = fakeServer;
p.write(tmpWr);
net = bak;
int l = tmpBuf.position();
writes.s(l);
writes.b(tmpBuf.array(), 0, l);
Expand Down Expand Up @@ -181,7 +190,6 @@ public static void startPlay(Fi input){
net.reset();
netClient.beginConnecting();
Reflect.set(net, "active", true);
Reflect.set(net, "server", true);

startTime = Time.time;
Threads.daemon("Replay Controller", () -> {
Expand All @@ -192,7 +200,7 @@ public static void startPlay(Fi input){
Packet p = Net.newPacket(reads.b());
p.read(reads, reads.us());
while(Time.time - startTime < nextTime)
Thread.yield();
Thread.sleep(1);
Core.app.post(() -> net.handleClientReceived(p));
}
}catch(Exception e){
Expand Down

0 comments on commit 48e23e5

Please sign in to comment.