File size: 16,205 Bytes
f63b467
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
import os

# --- CONFIGURATION ---
# New Folder Name matching the new branding
FOLDER_NAME = "SpeedoDude_CyberDeckDroid"
os.makedirs(FOLDER_NAME, exist_ok=True)

def write_file(filename, content):
    path = os.path.join(FOLDER_NAME, filename)
    with open(path, "w", encoding="utf-8") as f:
        f.write(content.strip())
    print(f"✅ Created: {path}")

# ==============================================================================
# 1. APP.PY (The Main Logic)
# ==============================================================================
app_code = r'''
import gradio as gr
import os
import json
import random
from huggingface_hub import InferenceClient

# --- CONFIGURATION ---
# Connects to Hugging Face's Free Inference API
# You must set 'HF_TOKEN' in your Space Settings (Variables and secrets)
HF_TOKEN = os.getenv("HF_TOKEN")

# --- BRANDING & ASSETS ---
COMPANY_NAME = "SpeedoDude"
APP_NAME = "CyberDeckDroid"
APP_TITLE = f"🌊 {COMPANY_NAME} {APP_NAME}"

DONATION_HTML = """
<div align="center">
  <p><b>Support {company} Development</b><br>
  {app_name} is free and open source. If this tool helped you, please consider donating!</p>
  <a href="https://www.patreon.com/YOUR_USERNAME" target="_blank">
    <img src="https://img.shields.io/badge/Support_on-Patreon-f96854?style=for-the-badge&logo=patreon&logoColor=white" alt="Support on Patreon"/>
  </a>
  <a href="https://ko-fi.com/YOUR_USERNAME" target="_blank">
    <img src="https://img.shields.io/badge/Buy_me_a-Coffee-ff5f5f?style=for-the-badge&logo=ko-fi&logoColor=white" alt="Buy me a Coffee"/>
  </a>
</div>
""".format(company=COMPANY_NAME, app_name=APP_NAME)

LEGAL_TEXT = f"""
### ⚠️ Legal Disclaimer & Terms
1. **Single-Player Only:** {APP_NAME} is strictly for offline, creative use. Do not use in multiplayer environments.
2. **Liability:** {COMPANY_NAME} is not responsible for account bans or data loss. Always backup your save files.
3. **Ownership:** Assets generated via the {COMPANY_NAME} Generator belong to you, the user.
"""

# ==============================================================================
# MODULE 1: THE GENERATOR (Assets & Textures)
# ==============================================================================
def generate_asset(prompt, style, asset_type):
    """
    Generates game textures/concepts using Stable Diffusion.
    """
    if not HF_TOKEN:
        return None, "⚠️ Error: HF_TOKEN secret is missing in Space Settings."
    
    # Model Selection: Stable Diffusion 2.1 is reliable and free on HF
    model_id = "stabilityai/stable-diffusion-2-1"
    client = InferenceClient(model_id, token=HF_TOKEN)
    
    # Optimized Prompt Engineering
    full_prompt = f"{prompt}, {style} style, {asset_type} game asset, high quality, 4k, flat lighting, seamless"
    
    try:
        image = client.text_to_image(full_prompt)
        output_path = "/tmp/speedodude_asset.png"
        image.save(output_path)
        return output_path, f"✅ Success! Generated: '{full_prompt}'"
    except Exception as e:
        return None, f"❌ Generation Error: {str(e)}"

# ==============================================================================
# MODULE 2: THE FABRICATOR (Save File Editor)
# ==============================================================================
def analyze_save_file(file_obj):
    """
    Reads a .json or .xml file and shows the structure.
    """
    if file_obj is None: return "Please upload a file first."
    
    try:
        with open(file_obj.name, 'r') as f:
            content = f.read()
            
        # Try parsing JSON
        try:
            data = json.loads(content)
            keys = list(data.keys())[:50] # Preview first 50 keys
            return f"📂 File Valid (JSON).\nFound Top-Level Keys:\n{keys}..."
        except json.JSONDecodeError:
            # Fallback for XML/Text (Basic preview)
            return f"📄 File Valid (Text/XML).\nPreview:\n{content[:500]}..."
            
    except Exception as e:
        return f"❌ Error reading file: {str(e)}"

def apply_hack(file_obj, key_to_find, new_value):
    """
    Recursively searches a JSON file for a specific key and updates it.
    """
    if file_obj is None: return None, "Upload a file first."
    
    try:
        with open(file_obj.name, 'r') as f:
            data = json.load(f)
        
        matches = 0
        
        def update_recursive(d, target_k, target_v):
            nonlocal matches
            for k in d:
                if k == target_k:
                    # Smart Type Conversion (Maintain Int/Float/String)
                    if isinstance(d[k], int):
                        d[k] = int(target_v)
                    elif isinstance(d[k], float):
                        d[k] = float(target_v)
                    else:
                        d[k] = str(target_v)
                    matches += 1
                elif isinstance(d[k], dict):
                    update_recursive(d[k], target_k, target_v)
                elif isinstance(d[k], list):
                    for item in d[k]:
                        if isinstance(item, dict):
                            update_recursive(item, target_k, target_v)

        update_recursive(data, key_to_find, new_value)
        
        if matches == 0:
            return None, f"⚠️ Key '{key_to_find}' not found in file."
            
        output_path = "/tmp/speedodude_modded.json"
        with open(output_path, 'w') as f:
            json.dump(data, f, indent=4)
            
        return output_path, f"✅ Success! Updated {matches} instance(s) of '{key_to_find}'."
    except Exception as e:
        return None, f"❌ Error: {str(e)}"

# ==============================================================================
# MODULE 3: THE ARCHITECT (Alchemist, Dojo, Director, Genesis)
# ==============================================================================
def generate_blueprint(blueprint_type, name, details):
    """
    Generates code snippets and configuration files for various game systems.
    Combines Alchemist (Items), Dojo (Combat), Director (Scenes), Genesis (Project).
    """
    name_clean = name.replace(" ", "")
    
    # --- ALCHEMIST (Custom Items) ---
    if blueprint_type == "Item Script (Unity C#)":
        return f"""// Generated by SpeedoDude Alchemist
using UnityEngine;

[CreateAssetMenu(fileName = "{name}", menuName = "SpeedoDude/Item")]
public class {name_clean} : ItemObject {{
    public string itemName = "{name}";
    [TextArea] public string description = "{details}";
    
    public override void OnUse(Character user) {{
        Debug.Log("Using {name}...");
        // Effect Logic: {details}
        // TODO: Implement specific stat changes here.
    }}
}}
"""

    # --- DOJO (Combat Logic) ---
    elif blueprint_type == "Combat Style (JSON)":
        data = {
            "style_name": name,
            "description": details,
            "creator": COMPANY_NAME,
            "moves": [
                {"name": "Light Attack", "damage": 10, "anim": f"{name}_Light.anim", "frame_data": 5},
                {"name": "Heavy Attack", "damage": 25, "anim": f"{name}_Heavy.anim", "frame_data": 15},
                {"name": "Special", "damage": 50, "effect": details}
            ]
        }
        return json.dumps(data, indent=4)

    # --- DIRECTOR (Scene Layout) ---
    elif blueprint_type == "Scene Layout (JSON)":
        return json.dumps({
            "scene_name": name,
            "theme": details,
            "lighting": {"ambient": "#1a1a1a", "sun_intensity": 0.8},
            "objects": [
                {"id": "player_start", "pos": [0, 1, 0]},
                {"id": "enemy_spawn", "pos": [10, 0, 5]},
                {"id": "prop_chest", "pos": [-5, 0, 2], "loot": "random"}
            ]
        }, indent=4)

    # --- GENESIS (Unreal Project Config) ---
    elif blueprint_type == "Unreal Project File (.uproject)":
        return json.dumps({
            "FileVersion": 3,
            "EngineAssociation": "5.3",
            "Category": "",
            "Description": f"{details} - Generated by {COMPANY_NAME} Genesis",
            "Modules": [
                {"Name": name_clean, "Type": "Runtime", "LoadingPhase": "Default"}
            ]
        }, indent=4)
        
    return "Error: Unknown Blueprint Type"

# ==============================================================================
# MAIN UI LAYOUT
# ==============================================================================
# Using 'Soft' theme with SpeedoDude colors
with gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan", secondary_hue="indigo"), title=APP_TITLE) as app:
    
    # --- HEADER ---
    gr.Markdown(f"# {APP_TITLE}")
    gr.Markdown(f"The ultimate cloud-based **{APP_NAME}** for single-player game modding.")
    gr.HTML(DONATION_HTML) # Inject Donation Badges
    
    # --- TABS ---
    with gr.Tabs():
        
        # TAB 1: GENERATOR
        with gr.TabItem("🎨 Generator"):
            gr.Markdown(f"### {COMPANY_NAME} Asset Factory")
            with gr.Row():
                gen_prompt = gr.Textbox(label="Prompt", placeholder="A rusty cyber-sword with glowing green edges")
                gen_style = gr.Dropdown(["Realistic", "Pixel Art", "Sci-Fi", "Fantasy", "Cartoon"], label="Style", value="Realistic")
                gen_type = gr.Dropdown(["Icon", "Texture", "Concept Art", "UI Element"], label="Type", value="Texture")
            
            gen_btn = gr.Button("Generate Asset", variant="primary")
            
            with gr.Row():
                gen_image = gr.Image(label="Result")
                gen_log = gr.Textbox(label="System Log")
            
            gen_btn.click(generate_asset, inputs=[gen_prompt, gen_style, gen_type], outputs=[gen_image, gen_log])

        # TAB 2: FABRICATOR
        with gr.TabItem("💾 Fabricator"):
            gr.Markdown(f"### {COMPANY_NAME} Save Editor")
            with gr.Row():
                file_input = gr.File(label="Upload Save (.json)")
                analyze_btn = gr.Button("Analyze File")
            
            file_info = gr.Textbox(label="File Structure Preview", lines=4)
            analyze_btn.click(analyze_save_file, inputs=file_input, outputs=file_info)
            
            gr.Markdown("---")
            gr.Markdown("### Apply Modification")
            with gr.Row():
                hack_key = gr.Textbox(label="Key to Change", placeholder="e.g., gold, health, xp")
                hack_val = gr.Textbox(label="New Value", placeholder="999999")
            
            hack_btn = gr.Button("Apply Hack", variant="stop")
            
            with gr.Row():
                hack_download = gr.File(label="Download Modded Save")
                hack_log = gr.Textbox(label="System Log")
            
            hack_btn.click(apply_hack, inputs=[file_input, hack_key, hack_val], outputs=[hack_download, hack_log])

        # TAB 3: ARCHITECT (Alchemist/Dojo/Director/Genesis)
        with gr.TabItem("📜 Architect"):
            gr.Markdown(f"### {COMPANY_NAME} Code Generator")
            gr.Markdown("Generate production-ready scripts for Unity/Unreal.")
            
            with gr.Row():
                arch_type = gr.Dropdown([
                    "Item Script (Unity C#)", 
                    "Combat Style (JSON)", 
                    "Scene Layout (JSON)", 
                    "Unreal Project File (.uproject)"
                ], label="Blueprint Type")
                
                arch_name = gr.Textbox(label="Name", placeholder="Excalibur / CyberArena")
            
            arch_details = gr.Textbox(label="Description / Effect / Theme", placeholder="High damage sword that heals on hit...")
            
            arch_btn = gr.Button("Generate Blueprint", variant="primary")
            arch_output = gr.Code(label="Generated Output", language="csharp")
            
            arch_btn.click(generate_blueprint, inputs=[arch_type, arch_name, arch_details], outputs=arch_output)

    # --- FOOTER ---
    gr.Markdown("---")
    gr.Markdown(LEGAL_TEXT)
    gr.Markdown(f"© 2025 {COMPANY_NAME}. All Rights Reserved.")

# ==============================================================================
# LAUNCHER (MCP ENABLED)
# ==============================================================================
if __name__ == "__main__":
    # mcp=True enables Claude/Cursor to control this app as a server
    app.launch(mcp=True)
'''
write_file("app.py", app_code)

# ==============================================================================
# 2. REQUIREMENTS.TXT
# ==============================================================================
req_code = """
gradio>=5.0.0
huggingface_hub
pillow
"""
write_file("requirements.txt", req_code)

# ==============================================================================
# 3. README.MD (Branded & Legal)
# ==============================================================================
readme_code = """
---
title: SpeedoDude CyberDeckDroid
emoji: 🌊
colorFrom: blue
colorTo: indigo
sdk: gradio
sdk_version: 5.0.0
app_file: app.py
pinned: false
license: mit
short_description: The official SpeedoDude™ CyberDeckDroid for AI game modding.
---

# 🌊 SpeedoDude CyberDeckDroid

<div align="center">
  <a href="https://www.patreon.com/YOUR_USERNAME">
    <img src="https://img.shields.io/badge/Support_on-Patreon-f96854?style=for-the-badge&logo=patreon&logoColor=white" alt="Support on Patreon"/>
  </a>
  <a href="https://ko-fi.com/YOUR_USERNAME">
    <img src="https://img.shields.io/badge/Buy_me_a-Coffee-ff5f5f?style=for-the-badge&logo=ko-fi&logoColor=white" alt="Buy me a Coffee"/>
  </a>
</div>
**CyberDeckDroid** is the premier open-source creative suite for next-gen game modding. Developed by **SpeedoDude**, this architect tool leverages advanced LLMs and Generative AI to help you build your dream game worlds.

## ✨ The SpeedoDude Toolset

* **🎨 SpeedoDude Generator:** Create unique, high-fidelity game textures, UI elements, and character skins using our tuned Stable Diffusion pipeline.
* **💾 SpeedoDude Fabricator:** The ultimate save-file surgeon. Analyze and modify `.json` / `.xml` data with surgical precision.
* **📜 SpeedoDude Architect:** Summon production-ready code. Generate boilerplate modding scripts (C#, Lua, JSON) for Unity and Unreal Engine instantly.
* **☁️ SpeedoDude Cloud:** All processing happens on our optimized cloud infrastructure—no heavy local GPU required.

---

## ⚠️ SpeedoDude Legal Disclaimers & Terms

By accessing the **SpeedoDude CyberDeckDroid**, you agree to the following terms. **SpeedoDude** prioritizes creative freedom and safe modding practices.

### 1. Single-Player & Creative Use Only
**SpeedoDude** tools are strictly designed for **offline, single-player** experiences.
* **DO NOT** use **CyberDeckDroid** in multiplayer, competitive, or online environments.
* **DO NOT** use **SpeedoDude** tools to bypass DRM, anti-cheat software, or paywalls.
* **SpeedoDude** and its developers condemn cheating in online ecosystems and accept no liability for users who violate third-party Terms of Service.

### 2. Limitation of Liability
The **SpeedoDude** software suite is provided "AS IS".
* **Account Safety:** **SpeedoDude** is not responsible for account bans, suspensions, or penalties resulting from the use of our tools.
* **Data Integrity:** Modifying game files carries inherent risks. **SpeedoDude** recommends backing up all save data before using the Fabricator.

### 3. Asset Ownership
* **Your Creations:** Any assets generated via the **SpeedoDude Generator** belong to you (the user), subject to the underlying model licenses. **SpeedoDude** claims no ownership over your creative output.

---

## 🛡️ Run Your Own SpeedoDude Instance

For maximum privacy and speed, we recommend duplicating the **SpeedoDude** space:

1.  Click the **Three Dots** menu (top right) -> **Duplicate this Space**.
2.  Add your own `HF_TOKEN` in the settings.
3.  Enjoy your private **SpeedoDude** studio.

---

## ⚖️ License

**SpeedoDude CyberDeckDroid** is licensed under the **MIT License**.