8000 Add Cognitohazard Reflection (close #30) · object-Object/HexDebug@1703909 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1703909

Browse files
committed
Add Cognitohazard Reflection (close #30)
1 parent 33216e5 commit 1703909

File tree

7 files changed

+96
-1
lines changed

7 files changed

+96
-1
lines changed

Common/src/main/kotlin/gay/object/hexdebug/HexDebug.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ object HexDebug {
2525
HexDebugMenus,
2626
HexDebugActions,
2727
HexDebugContinuationTypes,
28+
HexDebugIotaTypes,
2829
)
2930
HexDebugNetworking.init()
3031
DebugAdapterManager.init()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package gay.`object`.hexdebug.casting.iotas
2+
3+
import at.petrak.hexcasting.api.casting.eval.CastResult
4+
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType
5+
import at.petrak.hexcasting.api.casting.eval.vm.CastingVM
6+
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
7+
import at.petrak.hexcasting.api.casting.iota.Iota
8+
import at.petrak.hexcasting.api.casting.iota.IotaType
9+
import at.petrak.hexcasting.api.utils.asTranslatedComponent
10+
import at.petrak.hexcasting.api.utils.black
11+
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
12+
import net.minecraft.nbt.CompoundTag
13+
import net.minecraft.nbt.Tag
14+
import net.minecraft.server.level.ServerLevel
15+
16+
/** An iota that terminates a debugging session if attempted to be executed. */
17+
class CognitohazardIota : Iota(TYPE, COGNITOHAZARD_SUBSTITUTE) {
18+
override fun isTruthy() = true
19+
20+
override fun toleratesOther(that: Iota) = typesMatch(this, that)
21+
22+
override fun serialize() = CompoundTag()
23+
24+
override fun execute(vm: CastingVM, world: ServerLevel, continuation: SpellContinuation): CastResult {
25+
// we shouldn't need any special handling in here, since the cognitohazard should be detected by the debugger before we get to this point
26+
return CastResult(
27+
this,
28+
continuation,
29+
null,
30+
listOf(),
31+
ResolvedPatternType.EVALUATED,
32+
HexEvalSounds.NOTHING,
33+
)
34+
}
35+
36+
override fun executable() = true
37+
38+
companion object {
39+
private val COGNITOHAZARD_SUBSTITUTE = Object()
40+
41+
val DISPLAY = "hexdebug.tooltip.cognitohazard_iota".asTranslatedComponent.black
42+
43+
val TYPE = object : IotaType<CognitohazardIota>() {
44+
override fun deserialize(tag: Tag, world: ServerLevel) = CognitohazardIota()
45+
46+
override fun display(tag: Tag) = DISPLAY
47+
48+
override fun color() = 0xff_000000.toInt()
49+
}
50+
}
51+
}

Common/src/main/kotlin/gay/object/hexdebug/debugger/HexDebugger.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import gay.`object`.hexdebug.adapter.LaunchArgs
1717
import gay.`object`.hexdebug.casting.eval.FrameBreakpoint
1818
import gay.`object`.hexdebug.casting.eval.IDebugCastEnv
1919
import gay.`object`.hexdebug.casting.eval.debugCastEnv
20+
import gay.`object`.hexdebug.casting.iotas.CognitohazardIota
2021
import gay.`object`.hexdebug.debugger.allocators.SourceAllocator
2122
import gay.`object`.hexdebug.debugger.allocators.VariablesAllocator
2223
import gay.`object`.hexdebug.utils.ceilToPow
@@ -63,6 +64,9 @@ class HexDebugger(
6364
private val breakpoints = mutableMapOf<Int, MutableMap<Int, SourceBreakpointMode>>() // source id -> line number
6465
private val exceptionBreakpoints = mutableSetOf<ExceptionBreakpointType>()
6566

67+
// this gets set to true by registerNewSource if a frame is loaded that contains a cognitohazard iota
68+
private var isPoisoned = false
69+
6670
private val initialSource = registerNewSource(iotas)!!
6771

6872
private var callStack = listOf<NotDone>()
@@ -114,6 +118,9 @@ class HexDebugger(
114118

115119
val source = sourceAllocator.add(unregisteredIotas)
116120
for ((index, iota) in unregisteredIotas.withIndex()) {
121+
if (iota is CognitohazardIota) {
122+
isPoisoned = true
123+
}
117124
iotaMetadata[iota] = IotaMetadata(source, index)
118125
}
119126
return source
@@ -511,7 +518,7 @@ class HexDebugger(
511518
val frame = continuation.frame
512519

513520
// TODO: there's probably a less hacky way to do this
514-
if (frame is FrameBreakpoint && frame.isFatal) {
521+
if (frame is FrameBreakpoint && frame.isFatal || isPoisoned) {
515522
continuation = Done
516523
break
517524
}

Common/src/main/kotlin/gay/object/hexdebug/registry/HexDebugActions.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ import at.petrak.hexcasting.common.items.magic.ItemPackagedHex
1010
import at.petrak.hexcasting.common.lib.HexRegistries
1111
import at.petrak.hexcasting.common.lib.hex.HexActions
1212
import gay.`object`.hexdebug.casting.actions.*
13+
import gay.`object`.hexdebug.casting.iotas.CognitohazardIota
1314

1415
object HexDebugActions : HexDebugRegistrar<ActionRegistryEntry>(HexRegistries.ACTION, { HexActions.REGISTRY }) {
16+
val COGNITOHAZARD = make("const/cognitohazard", HexDir.NORTH_WEST, "wdeaqqdqeedqadqeedqaeadeaqqeadeaqqdqdeaqqeaeedqaw") {
17+
Action.makeConstantOp(CognitohazardIota())
18+
}
1519
val IS_DEBUGGING = make("const/debugging", HexDir.EAST, "qqqqqewaa", OpIsDebugging)
1620
val NEXT_EVAL_INDEX = make("next_eval_index", HexDir.SOUTH_WEST, "dedqdeqwaa", OpNextEvalIndex)
1721

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package gay.`object`.hexdebug.registry
2+
3+
import at.petrak.hexcasting.api.casting.iota.IotaType
4+
import at.petrak.hexcasting.common.lib.HexRegistries
5+
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes
6+
import gay.`object`.hexdebug.casting.iotas.CognitohazardIota
7+
8+
object HexDebugIotaTypes : HexDebugRegistrar<IotaType<*>>(
9+
HexRegistries.IOTA_TYPE,
10+
{ HexIotaTypes.REGISTRY },
11+
) {
12+
val COGNITOHAZARD = register("cognitohazard") { CognitohazardIota.TYPE }
13+
}

Common/src/main/resources/assets/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/debugging.json5

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
output: "int or null",
1919
text: "hexdebug.category.patterns.entry.debugging.page.next_eval_index",
2020
},
21+
{
22+
type: "hexcasting:pattern",
23+
op_id: "hexdebug:const/cognitohazard",
24+
anchor: "hexdebug:const/cognitohazard",
25+
output: "cognitohazard",
26+
text: "hexdebug.category.patterns.entry.debugging.page.const/cognitohazard.1",
27+
},
28+
{
29+
type: "patchouli:text",
30+
text: "hexdebug.category.patterns.entry.debugging.page.const/cognitohazard.2",
31+
},
2132
{
2233
type: "hexcasting:pattern",
2334
op_id: "hexdebug:breakpoint/before",

Common/src/main/resources/assets/hexdebug/lang/en_us.flatten.json5

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"hexdebug:": {
9494
"const/debugging": "Debugger's Reflection",
9595
"next_eval_index": "Debug Locator's Reflection", // TODO: this name kinda sucks tbh
96+
"const/cognitohazard": "Cognitohazard Reflection",
9697
"breakpoint/": {
9798
before: "Set Breakpoint Before",
9899
after: "Set Breakpoint After"
@@ -101,6 +102,7 @@
101102
},
102103
"book.hexdebug:": {
103104
"next_eval_index": "Debug Locator's Rfln.",
105+
"const/cognitohazard": "Cognitohazard Rfln."
104106
},
105107
},
106108

@@ -120,6 +122,7 @@
120122
focus_holder: {
121123
item: "Item: %s",
122124
},
125+
cognitohazard_iota: "Cognitohazard",
123126
},
124127

125128
category: {
@@ -149,6 +152,11 @@
149152
page: {
150153
"const/debugging": "Adds $(thing)True/$ to the top of the stack if executed by a $(l:items/debugging#debugger)$(item)Debugger/$ or $(l:items/debugging#evaluator)$(item)Evaluator/$, or $(thing)False/$ otherwise.",
151154
"next_eval_index": "Adds the index of the next iota to be evaluated if executed by a $(l:items/debugging#debugger)$(item)Debugger/$ or $(l:items/debugging#evaluator)$(item)Evaluator/$, or $(l:casting/influences)$(thing)Null/$ otherwise.",
155+
"const/cognitohazard": {
156+
"1": "Adds a $(thing)Cognitohazard/$ to the top of the stack.",
157+
"2": "It seems certain $(l:items/debugging#evaluator)debugging tools/$ may pose a security risk for some $(l:patterns/meta#hexcasting:eval/cc)high-level techniques/$. To help combat this, I have created this pattern.$(br2)\
158+
When a $(thing)Cognitohazard/$ iota is executed normally, nothing happens. However, if one is present in a _Hex executed by a $(l:items/debugging#debugger)$(item)Debugger/$, it will cause the _Hex to terminate $(italic)immediately/$ - even before the $(thing)Cognitohazard/$ is actually executed.",
159+
},
152160
"breakpoint/": {
153161
before: "Pauses the $(l:items/debugging#debugger)$(item)Debugger/$ before executing this pattern.",
154162
after: "Pauses the $(l:items/debugging#debugger)$(item)Debugger/$ after executing this pattern (ie. before executing the next pattern).",

0 commit comments

Comments
 (0)
0